Skip to content

Commit

Permalink
Add compact method for multi-year (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawin authored Sep 16, 2024
1 parent fc4ac1b commit 360f8e2
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 104 deletions.
58 changes: 47 additions & 11 deletions src/constraints/capacity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ function add_capacity_constraints!(
flow,
Ai,
decommissionable_assets_using_simple_method,
decommissionable_assets_using_compact_method,
V_all,
Asb,
assets_investment,
accumulate_capacity_simple_method,
accumulate_capacity_compact_method,
accumulated_set_using_compact_method,
outgoing_flow_highest_out_resolution,
incoming_flow_highest_in_resolution,
)
compact_set_lookup = Dict(
(a, y, v) => idx for (idx, (a, y, v)) in enumerate(accumulated_set_using_compact_method)
)

## Expressions used by capacity constraints
# - Create capacity limit for outgoing flows
Expand All @@ -44,6 +51,7 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
Expand All @@ -52,19 +60,40 @@ function add_capacity_constraints!(
accumulate_capacity_simple_method[row.year, row.asset]
)
)
elseif row.asset decommissionable_assets_using_compact_method
@expression(
model,
graph[row.asset].capacity[row.year] * sum(
profile_aggregation(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
v,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * accumulate_capacity_compact_method[compact_set_lookup[(
row.asset,
row.year,
v,
)]] for v in V_all if
(row.asset, row.year, v) in accumulated_set_using_compact_method
)
)
else
@expression(
model,
profile_aggregation(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) *
graph[row.asset].capacity[row.year] *
graph[row.asset].initial_units[row.year]
graph[row.asset].initial_units[row.year][row.year]
)
end for row in eachrow(dataframes[:highest_out])
]
Expand All @@ -79,13 +108,14 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) *
(
graph[row.asset].capacity[row.year] *
graph[row.asset].initial_units[row.year] +
graph[row.asset].initial_units[row.year][row.year] +
graph[row.asset].investment_limit[row.year]
) *
(1 - row.is_charging)
Expand All @@ -97,13 +127,14 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) *
(
graph[row.asset].capacity[row.year] *
graph[row.asset].initial_units[row.year]
graph[row.asset].initial_units[row.year][row.year]
) *
(1 - row.is_charging)
)
Expand All @@ -119,13 +150,14 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * (
graph[row.asset].capacity[row.year] * (
graph[row.asset].initial_units[row.year] * (1 - row.is_charging) +
assets_investment[row.year, row.asset]
graph[row.asset].initial_units[row.year][row.year] *
(1 - row.is_charging) + assets_investment[row.year, row.asset]
)
)
)
Expand All @@ -142,12 +174,13 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * (
graph[row.asset].capacity[row.year] * (
graph[row.asset].initial_units[row.year] +
graph[row.asset].initial_units[row.year][row.year] +
assets_investment[row.year, row.asset]
)
)
Expand All @@ -159,12 +192,13 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) *
graph[row.asset].capacity[row.year] *
graph[row.asset].initial_units[row.year]
graph[row.asset].initial_units[row.year][row.year]
)
end for row in eachrow(dataframes[:highest_in])
]
Expand All @@ -179,13 +213,14 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) *
(
graph[row.asset].capacity[row.year] *
graph[row.asset].initial_units[row.year] +
graph[row.asset].initial_units[row.year][row.year] +
graph[row.asset].investment_limit[row.year]
) *
row.is_charging
Expand All @@ -197,13 +232,14 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) *
(
graph[row.asset].capacity[row.year] *
graph[row.asset].initial_units[row.year]
graph[row.asset].initial_units[row.year][row.year]
) *
row.is_charging
)
Expand All @@ -219,13 +255,13 @@ function add_capacity_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * (
graph[row.asset].capacity[row.year] * (
graph[row.asset].initial_units[row.year] * row.is_charging +
assets_investment[row.year, row.asset]
graph[row.asset].initial_units[row.year][row.year] * row.is_charging + assets_investment[row.year, row.asset]
)
)
)
Expand Down
1 change: 1 addition & 0 deletions src/constraints/consumer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function add_consumer_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("demand", row.rep_period),
row.timesteps_block,
1.0,
Expand Down
2 changes: 2 additions & 0 deletions src/constraints/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function add_energy_constraints!(model, graph, dataframes)
sum,
graph[row.asset].timeframe_profiles,
row.year,
row.year,
"max_energy",
row.periods_block,
1.0,
Expand All @@ -36,6 +37,7 @@ function add_energy_constraints!(model, graph, dataframes)
sum,
graph[row.asset].timeframe_profiles,
row.year,
row.year,
"min_energy",
row.periods_block,
1.0,
Expand Down
6 changes: 4 additions & 2 deletions src/constraints/ramping-and-unit-commitment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function add_ramping_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
Expand All @@ -54,7 +55,8 @@ function add_ramping_constraints!(
@constraint(
model,
row.units_on
graph[row.asset].initial_units[row.year] + assets_investment[row.year, row.asset],
graph[row.asset].initial_units[row.year][row.year] +
assets_investment[row.year, row.asset],
base_name = "limit_units_on_with_investment[$(row.asset),$(row.year),$(row.rep_period),$(row.timesteps_block)]"
) for row in eachrow(df_units_on) if row.asset in Ai[row.year]
]
Expand All @@ -63,7 +65,7 @@ function add_ramping_constraints!(
model[:limit_units_on_without_investment] = [
@constraint(
model,
row.units_on graph[row.asset].initial_units[row.year],
row.units_on graph[row.asset].initial_units[row.year][row.year],
base_name = "limit_units_on_without_investment[$(row.asset),$(row.year),$(row.rep_period),$(row.timesteps_block)]"
) for row in eachrow(df_units_on) if !(row.asset in Ai[row.year])
]
Expand Down
5 changes: 5 additions & 0 deletions src/constraints/storage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function add_storage_constraints!(
sum,
graph[a].rep_periods_profiles,
row.year,
row.year,
("inflows", rp),
row.timesteps_block,
0.0,
Expand All @@ -83,6 +84,7 @@ function add_storage_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("max-storage-level", row.rep_period),
row.timesteps_block,
1.0,
Expand All @@ -103,6 +105,7 @@ function add_storage_constraints!(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
row.year,
("min_storage_level", row.rep_period),
row.timesteps_block,
0.0,
Expand Down Expand Up @@ -166,6 +169,7 @@ function add_storage_constraints!(
Statistics.mean,
graph[row.asset].timeframe_profiles,
row.year,
row.year,
"max_storage_level",
row.periods_block,
1.0,
Expand All @@ -186,6 +190,7 @@ function add_storage_constraints!(
Statistics.mean,
graph[row.asset].timeframe_profiles,
row.year,
row.year,
"min_storage_level",
row.periods_block,
0.0,
Expand Down
4 changes: 4 additions & 0 deletions src/constraints/transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
Statistics.mean,
graph[row.from, row.to].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
Expand All @@ -34,6 +35,7 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
Statistics.mean,
graph[row.from, row.to].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
Expand All @@ -51,6 +53,7 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
Statistics.mean,
graph[row.from, row.to].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
Expand All @@ -67,6 +70,7 @@ function add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_inve
Statistics.mean,
graph[row.from, row.to].rep_periods_profiles,
row.year,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
Expand Down
Loading

0 comments on commit 360f8e2

Please sign in to comment.