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

Add vintage version for multi-year #741

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions src/constraints/capacity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_capacity_constraints!(model,
flow,
Ai,
Asb,
assets_investment,
assets_investment_accumulated,
outgoing_flow_highest_out_resolution,
incoming_flow_highest_in_resolution
)
Expand All @@ -24,7 +24,7 @@ function add_capacity_constraints!(
flow,
Ai,
Asb,
assets_investment,
assets_investment_accumulated,
outgoing_flow_highest_out_resolution,
incoming_flow_highest_in_resolution,
)
Expand All @@ -39,12 +39,14 @@ function add_capacity_constraints!(
profile_aggregation(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * (
graph[row.asset].initial_capacity +
graph[row.asset].capacity * assets_investment[row.asset]
graph[row.asset].initial_capacity[row.year] + # this does not matter for now
graph[row.asset].capacity[row.investment_year] *
assets_investment_accumulated[row.asset, row.year, row.investment_year]
)
)
else
Expand All @@ -53,10 +55,11 @@ function add_capacity_constraints!(
profile_aggregation(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * graph[row.asset].initial_capacity
) * graph[row.asset].initial_capacity[row.year]
)
end for row in eachrow(dataframes[:highest_out])
]
Expand All @@ -74,8 +77,11 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) *
(graph[row.asset].initial_capacity + graph[row.asset].investment_limit) *
(1 - row.is_charging)
(
graph[row.asset].initial_capacity[row.investment_year] +
graph[row.asset].investment_limit[row.investment_year]
) * # fix this
(1 - row.is_charging[row.year])
)
else
@expression(
Expand All @@ -87,7 +93,7 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) *
(graph[row.asset].initial_capacity) *
(graph[row.asset].initial_capacity[row.year]) * # check this,
(1 - row.is_charging)
)
end for row in eachrow(dataframes[:highest_out])
Expand All @@ -105,8 +111,10 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) * (
graph[row.asset].initial_capacity * (1 - row.is_charging) +
graph[row.asset].capacity * assets_investment[row.asset]
graph[row.asset].initial_capacity[row.investment_year] *
(1 - row.is_charging) +
graph[row.asset].capacity[row.investment_year] *
assets_investment_accumulated[row.asset, row.year, row.investment_year]
)
)
end for row in eachrow(dataframes[:highest_out])
Expand All @@ -125,8 +133,9 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) * (
graph[row.asset].initial_capacity +
graph[row.asset].capacity * assets_investment[row.asset]
graph[row.asset].initial_capacity[row.investment_year] +
graph[row.asset].capacity[row.investment_year] *
assets_investment_accumulated[row.asset, row.year, row.investment_year]
)
)
else
Expand All @@ -138,7 +147,7 @@ function add_capacity_constraints!(
("availability", row.rep_period),
row.timesteps_block,
1.0,
) * graph[row.asset].initial_capacity
) * graph[row.asset].initial_capacity[row.year]
)
end for row in eachrow(dataframes[:highest_in])
]
Expand All @@ -156,7 +165,10 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) *
(graph[row.asset].initial_capacity + graph[row.asset].investment_limit) *
(
graph[row.asset].initial_capacity[row.investment_year] +
graph[row.asset].investment_limit[row.investment_year]
) *
row.is_charging
)
else
Expand All @@ -169,7 +181,7 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) *
(graph[row.asset].initial_capacity) *
(graph[row.asset].initial_capacity[row.investment_year]) *
row.is_charging
)
end for row in eachrow(dataframes[:highest_in])
Expand All @@ -187,8 +199,9 @@ function add_capacity_constraints!(
row.timesteps_block,
1.0,
) * (
graph[row.asset].initial_capacity * row.is_charging +
graph[row.asset].capacity * assets_investment[row.asset]
graph[row.asset].initial_capacity[row.investment_year] * row.is_charging +
graph[row.asset].capacity[row.investment_year] *
assets_investment_accumulated[row.asset, row.year, row.investment_year]
)
)
end for row in eachrow(dataframes[:highest_in])
Expand All @@ -199,9 +212,9 @@ function add_capacity_constraints!(
model[:max_output_flows_limit] = [
@constraint(
model,
outgoing_flow_highest_out_resolution[row.index] ≤
assets_profile_times_capacity_out[row.index],
base_name = "max_output_flows_limit[$(row.asset),$(row.rep_period),$(row.timesteps_block)]"
outgoing_flow_highest_out_resolution[row.index] ≤ # this df has been changed to include years, so no need to change here.
assets_profile_times_capacity_out[row.index], # this df has been changed to include years, so no need to change here.
base_name = "max_output_flows_limit[$(row.asset), $(row.investment_year), $(row.year), $(row.rep_period),$(row.timesteps_block)]"
) for row in eachrow(dataframes[:highest_out]) if
row.asset ∉ Asb && outgoing_flow_highest_out_resolution[row.index] != 0
]
Expand Down Expand Up @@ -262,7 +275,7 @@ function add_capacity_constraints!(

# - Lower limit for flows that are not transport assets
for row in eachrow(df_flows)
if !graph[row.from, row.to].is_transport
if !graph[row.from, row.to].is_transport[row.year]
JuMP.set_lower_bound(flow[row.index], 0.0)
end
end
Expand Down
6 changes: 4 additions & 2 deletions src/constraints/consumer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ function add_consumer_constraints!(
profile_aggregation(
Statistics.mean,
graph[row.asset].rep_periods_profiles,
row.year,
("demand", row.rep_period),
row.timesteps_block,
1.0,
) * graph[row.asset].peak_demand in graph[row.asset].consumer_balance_sense,
base_name = "consumer_balance[$(row.asset),$(row.rep_period),$(row.timesteps_block)]"
) * graph[row.asset].peak_demand[row.year] in
graph[row.asset].consumer_balance_sense[row.year],
base_name = "consumer_balance[$(row.asset), $(row.year), $(row.rep_period),$(row.timesteps_block)]"
) for row in eachrow(df)
]
end
2 changes: 1 addition & 1 deletion src/constraints/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function add_conversion_constraints!(
model,
incoming_flow_lowest_resolution[row.index] ==
outgoing_flow_lowest_resolution[row.index],
base_name = "conversion_balance[$(row.asset),$(row.rep_period),$(row.timesteps_block)]"
base_name = "conversion_balance[$(row.asset), $(row.investment_year), $(row.year), $(row.rep_period),$(row.timesteps_block)]"
) for row in eachrow(df)
]
end
10 changes: 6 additions & 4 deletions src/constraints/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ function add_energy_constraints!(model, graph, dataframes)
profile_aggregation(
sum,
graph[row.asset].timeframe_profiles,
row.year,
"max_energy",
row.periods_block,
1.0,
) * (graph[row.asset].max_energy_timeframe_partition),
base_name = "max_energy_inter_rp_limit[$(row.asset),$(row.periods_block)]"
) * (graph[row.asset].max_energy_timeframe_partition[row.year]),
base_name = "max_energy_inter_rp_limit[$(row.asset), $(row.year), $(row.investment_year), $(row.periods_block)]"
) for row in eachrow(dataframes[:max_energy_inter_rp])
]

Expand All @@ -34,11 +35,12 @@ function add_energy_constraints!(model, graph, dataframes)
profile_aggregation(
sum,
graph[row.asset].timeframe_profiles,
row.year,
"min_energy",
row.periods_block,
1.0,
) * (graph[row.asset].min_energy_timeframe_partition),
base_name = "min_energy_inter_rp_limit[$(row.asset),$(row.periods_block)]"
) * (graph[row.asset].min_energy_timeframe_partition[row.year]),
base_name = "min_energy_inter_rp_limit[$(row.asset),$(row.year), $(row.investment_year),$(row.periods_block)]"
) for row in eachrow(dataframes[:min_energy_inter_rp])
]
end
2 changes: 1 addition & 1 deletion src/constraints/hub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function add_hub_constraints!(
model,
incoming_flow_highest_in_out_resolution[row.index] ==
outgoing_flow_highest_in_out_resolution[row.index],
base_name = "hub_balance[$(row.asset),$(row.rep_period),$(row.timesteps_block)]"
base_name = "hub_balance[$(row.asset), $(row.year). $(row.rep_period),$(row.timesteps_block)]"
) for row in eachrow(df)
]
end
57 changes: 28 additions & 29 deletions src/constraints/investment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,54 @@ Adds the investment constraints for all asset types and transport flows to the m

function add_investment_constraints!(
graph,
Ai,
Ase,
Fi,
Y,
Ai_y,
Ase_y,
Fi_y,
assets_investment,
assets_investment_energy,
flows_investment,
)

# - Maximum (i.e., potential) investment limit for assets
for a in Ai
if graph[a].capacity > 0 && !ismissing(graph[a].investment_limit)
bound_value = _find_upper_bound(graph, Ai, Ase, a)
JuMP.set_upper_bound(assets_investment[a], bound_value)
end
if (a in Ase) && # for a in Ase, i.e., storage assets with energy method
graph[a].capacity_storage_energy > 0 &&
!ismissing(graph[a].investment_limit_storage_energy)
bound_value = _find_upper_bound(graph, Ai, Ase, a; is_bound_for_energy = true)
JuMP.set_upper_bound(assets_investment_energy[a], bound_value)
for y in Y
for a in Ai_y[y]
if graph[a].capacity[y] > 0 && !ismissing(graph[a].investment_limit[y])
bound_value = _find_upper_bound(graph, y, a)
JuMP.set_upper_bound(assets_investment[y, a], bound_value)
end
if (a in Ase_y[y]) && # for a in Ase, i.e., storage assets with energy method
graph[a].capacity_storage_energy[y] > 0 &&
!ismissing(graph[a].investment_limit_storage_energy[y])
bound_value = _find_upper_bound(graph, y, a; is_bound_for_energy = true)
JuMP.set_upper_bound(assets_investment_energy[y, a], bound_value)
end
end
end

# - Maximum (i.e., potential) investment limit for flows
for (u, v) in Fi
if graph[u, v].capacity > 0 && !ismissing(graph[u, v].investment_limit)
bound_value = _find_upper_bound(graph, Ai, Ase, u, v)
JuMP.set_upper_bound(flows_investment[(u, v)], bound_value)
for y in Y
for (u, v) in Fi_y[y]
if graph[u, v].capacity[y] > 0 && !ismissing(graph[u, v].investment_limit[y])
bound_value = _find_upper_bound(graph, y, u, v)
JuMP.set_upper_bound(flows_investment[y, (u, v)], bound_value)
end
end
end
end

function _find_upper_bound(
graph,
asset_indices,
storage_asset_indices,
investments...;
is_bound_for_energy = false,
)
function _find_upper_bound(graph, year, investments...; is_bound_for_energy = false)
graph_investment = graph[investments...]
if !is_bound_for_energy
bound_value = graph_investment.investment_limit / graph_investment.capacity
if graph_investment.investment_integer
bound_value = graph_investment.investment_limit[year] / graph_investment.capacity[year]
if graph_investment.investment_integer[year]
bound_value = floor(bound_value)
end
else
bound_value =
graph_investment.investment_limit_storage_energy /
graph_investment.capacity_storage_energy
if graph_investment.investment_integer_storage_energy
graph_investment.investment_limit_storage_energy[year] /
graph_investment.capacity_storage_energy[year]
if graph_investment.investment_integer_storage_energy[year]
bound_value = floor(bound_value)
end
end
Expand Down
Loading
Loading