Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cost Functions Refactor 2.1 #81

Merged
merged 11 commits into from
Apr 30, 2024
5 changes: 3 additions & 2 deletions src/definitions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const PACKAGE_DIR = joinpath(dirname(dirname(pathof(PowerSystemCaseBuilder))))
const DATA_DIR =
joinpath(LazyArtifacts.artifact"CaseData", "PowerSystemsTestData-3.0-alpha")
# const DATA_DIR =
# joinpath(LazyArtifacts.artifact"CaseData", "PowerSystemsTestData-3.0-alpha")
const DATA_DIR = get(ENV, "PSB_DATA_DIR", joinpath(dirname(PACKAGE_DIR), "PowerSystemsTestData")) # TODO remove before merging! Kludge to use custom test data until https://github.com/NREL-Sienna/PowerSystemCaseBuilder.jl/issues/54 gets resolved
GabrielKS marked this conversation as resolved.
Show resolved Hide resolved

const RTS_DIR = joinpath(LazyArtifacts.artifact"rts", "RTS-GMLC-0.2.2")

Expand Down
88 changes: 30 additions & 58 deletions src/library/psi_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function build_c_sys5_pjm(; kwargs...)
PrimeMovers.PVe,
(min = 0.0, max = 0.0),
1.0,
TwoPartCost(LinearFunctionData(0.0), 0.0),
RenewableGenerationCost(nothing),
100.0,
)
wind_device = PSY.RenewableDispatch(
Expand All @@ -32,7 +32,7 @@ function build_c_sys5_pjm(; kwargs...)
PrimeMovers.WT,
(min = 0.0, max = 0.0),
1.0,
TwoPartCost(LinearFunctionData(0.0), 0.0),
RenewableGenerationCost(nothing),
100.0,
)
PSY.add_component!(c_sys5, pv_device)
Expand Down Expand Up @@ -135,7 +135,7 @@ function build_c_sys5_pjm_rt(; kwargs...)
PrimeMovers.PVe,
(min = 0.0, max = 0.0),
1.0,
TwoPartCost(LinearFunctionData(0.0), 0.0),
RenewableGenerationCost(nothing),
100.0,
)
wind_device = PSY.RenewableDispatch(
Expand All @@ -148,7 +148,7 @@ function build_c_sys5_pjm_rt(; kwargs...)
PrimeMovers.WT,
(min = 0.0, max = 0.0),
1.0,
TwoPartCost(LinearFunctionData(0.0), 0.0),
RenewableGenerationCost(nothing),
100.0,
)
PSY.add_component!(c_sys5, pv_device)
Expand Down Expand Up @@ -290,14 +290,7 @@ function build_5_bus_hydro_uc_sys_targets(; kwargs...)
else
c_sys5_hy_uc = PSY.System(rawsys; sys_kwargs...)
end
cost = PSY.StorageManagementCost(;
variable = LinearFunctionData(0.15),
fixed = 0.0,
start_up = 0.0,
shut_down = 0.0,
energy_shortage_cost = 50.0,
energy_surplus_cost = 0.0,
)
cost = HydroGenerationCost(CostCurve(LinearCurve(0.15)), 0.0)
for hy in get_components(HydroEnergyReservoir, c_sys5_hy_uc)
set_operation_cost!(hy, cost)
end
Expand Down Expand Up @@ -349,14 +342,7 @@ function build_5_bus_hydro_ed_sys_targets(; kwargs...)
time_series_in_memory = true,
sys_kwargs...,
)
cost = PSY.StorageManagementCost(;
variable = LinearFunctionData(0.15),
fixed = 0.0,
start_up = 0.0,
shut_down = 0.0,
energy_shortage_cost = 50.0,
energy_surplus_cost = 0.0,
)
cost = HydroGenerationCost(CostCurve(LinearCurve(0.15)), 0.0)
for hy in get_components(HydroEnergyReservoir, c_sys5_hy_ed)
set_operation_cost!(hy, cost)
end
Expand Down Expand Up @@ -410,14 +396,7 @@ function build_5_bus_hydro_wk_sys_targets(; kwargs...)
time_series_in_memory = true,
sys_kwargs...,
)
cost = PSY.StorageManagementCost(;
variable = LinearFunctionData(0.15),
fixed = 0.0,
start_up = 0.0,
shut_down = 0.0,
energy_shortage_cost = 50.0,
energy_surplus_cost = 0.0,
)
cost = HydroGenerationCost(CostCurve(LinearCurve(0.15)), 0.0)
for hy in get_components(HydroEnergyReservoir, c_sys5_hy_wk)
set_operation_cost!(hy, cost)
end
Expand Down Expand Up @@ -658,14 +637,6 @@ function build_modified_RTS_GMLC_RT_sys_noForecast(; kwargs...)
return sys
end

function build_modified_tamu_ercot_da_sys(; kwargs...)
sys_kwargs = filter_kwargs(; kwargs...)
data_dir = get_raw_data(; kwargs...)
system_path = joinpath(data_dir, "DA_sys.json")
sys = System(system_path; sys_kwargs...)
return sys
end

function build_two_zone_5_bus(; kwargs...)
## System with 10 buses ######################################################
"""
Expand Down Expand Up @@ -861,8 +832,9 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -0.30, max = 0.30),
ramp_limits = nothing,
time_limits = nothing,
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 14.0, 0.0),
# Arguments
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 14.0, 0.0)),
0.0,
4.0,
2.0,
Expand All @@ -883,8 +855,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -1.275, max = 1.275),
ramp_limits = (up = 0.02 * 2.2125, down = 0.02 * 2.2125),
time_limits = (up = 2.0, down = 1.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 15.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 15.0, 0.0)),
0.0,
1.5,
0.75,
Expand All @@ -905,8 +877,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -3.90, max = 3.90),
ramp_limits = (up = 0.012 * 5.2, down = 0.012 * 5.2),
time_limits = (up = 3.0, down = 2.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 30.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 30.0, 0.0)),
0.0,
3.0,
1.5,
Expand All @@ -927,8 +899,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -1.5, max = 1.5),
ramp_limits = (up = 0.015 * 2.5, down = 0.015 * 2.5),
time_limits = (up = 2.0, down = 1.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 40.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 40.0, 0.0)),
0.0,
4.0,
2.0,
Expand All @@ -949,8 +921,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -4.50, max = 4.50),
ramp_limits = (up = 0.015 * 7.5, down = 0.015 * 7.5),
time_limits = (up = 5.0, down = 3.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 10.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 10.0, 0.0)),
0.0,
1.5,
0.75,
Expand All @@ -971,8 +943,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -0.30, max = 0.30),
ramp_limits = nothing,
time_limits = nothing,
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 14.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 14.0, 0.0)),
0.0,
4.0,
2.0,
Expand All @@ -993,8 +965,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -1.275, max = 1.275),
ramp_limits = (up = 0.02 * 2.2125, down = 0.02 * 2.2125),
time_limits = (up = 2.0, down = 1.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 15.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 15.0, 0.0)),
0.0,
1.5,
0.75,
Expand All @@ -1015,8 +987,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -3.90, max = 3.90),
ramp_limits = (up = 0.012 * 5.2, down = 0.012 * 5.2),
time_limits = (up = 3.0, down = 2.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 30.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 30.0, 0.0)),
0.0,
3.0,
1.5,
Expand All @@ -1037,8 +1009,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -1.5, max = 1.5),
ramp_limits = (up = 0.015 * 2.5, down = 0.015 * 2.5),
time_limits = (up = 2.0, down = 1.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 40.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 40.0, 0.0)),
0.0,
4.0,
2.0,
Expand All @@ -1059,8 +1031,8 @@ function build_two_zone_5_bus(; kwargs...)
reactive_power_limits = (min = -4.50, max = 4.50),
ramp_limits = (up = 0.015 * 7.5, down = 0.015 * 7.5),
time_limits = (up = 5.0, down = 3.0),
operation_cost = ThreePartCost(
QuadraticFunctionData(0.0, 10.0, 0.0),
operation_cost = ThermalGenerationCost(
CostCurve(QuadraticCurve(0.0, 10.0, 0.0)),
0.0,
1.5,
0.75,
Expand Down Expand Up @@ -1459,7 +1431,7 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line
main_sys,
)
noise_values = rand(MersenneTwister(COST_PERTURBATION_NOISE_SEED), 1_000_000)
old_pwl_array = get_variable(get_operation_cost(g)) |> get_points
old_pwl_array = get_points(get_value_curve(get_variable(get_operation_cost(g))))
new_pwl_array = similar(old_pwl_array)
for (ix, (x, y)) in enumerate(old_pwl_array)
if ix ∈ [1, length(old_pwl_array)]
Expand Down Expand Up @@ -1487,7 +1459,7 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line
end
end
end
set_variable!(get_operation_cost(g), PiecewiseLinearPointData(new_pwl_array))
set_variable!(get_operation_cost(g), CostCurve(PiecewisePointCurve(new_pwl_array)))
end

# set service participation
Expand Down
Loading
Loading