diff --git a/src/constraints/capacity.jl b/src/constraints/capacity.jl index 5eecdce9..dccd61ab 100644 --- a/src/constraints/capacity.jl +++ b/src/constraints/capacity.jl @@ -1,19 +1,7 @@ export add_capacity_constraints! """ -add_capacity_constraints!(model, - graph, - dataframes, - df_flows, - flow, - Ai, - investable_assets_using_simple_method, - Asb, - assets_investment, - accumulated_units, - outgoing_flow_highest_out_resolution, - incoming_flow_highest_in_resolution - ) +add_capacity_constraints!(model, graph,...) Adds the capacity constraints for all asset types to the model """ @@ -28,6 +16,7 @@ function add_capacity_constraints!( decommissionable_assets_using_simple_method, decommissionable_assets_using_compact_method, V_all, + accumulated_units_lookup, accumulated_set_using_compact_method_lookup, Asb, assets_investment, @@ -76,7 +65,7 @@ function add_capacity_constraints!( 1.0, ) * graph[row.asset].capacity * - accumulated_units[row.year, row.asset] + accumulated_units[accumulated_units_lookup[(row.asset, row.year)]] ) end for row in eachrow(dataframes[:highest_out]) ] diff --git a/src/constraints/ramping-and-unit-commitment.jl b/src/constraints/ramping-and-unit-commitment.jl index bc545cea..48191ebe 100644 --- a/src/constraints/ramping-and-unit-commitment.jl +++ b/src/constraints/ramping-and-unit-commitment.jl @@ -1,7 +1,7 @@ export add_ramping_and_unit_commitment_constraints! """ - add_ramping_and_unit_commitment_constraints!(graph, ...) + add_ramping_and_unit_commitment_constraints!(model, graph, ...) Adds the ramping constraints for producer and conversion assets where ramping = true in assets_data """ @@ -12,6 +12,7 @@ function add_ramping_constraints!( df_units_on, df_highest_out, outgoing_flow_highest_out_resolution, + accumulated_units_lookup, accumulated_units, Ai, Auc, @@ -54,7 +55,7 @@ function add_ramping_constraints!( model[:limit_units_on] = [ @constraint( model, - row.units_on ≤ accumulated_units[row.year, row.asset], + row.units_on ≤ accumulated_units[accumulated_units_lookup[(row.asset, row.year)]], base_name = "limit_units_on[$(row.asset),$(row.year),$(row.rep_period),$(row.timesteps_block)]" ) for row in eachrow(df_units_on) ] diff --git a/src/create-model.jl b/src/create-model.jl index 35891902..b74fcdcc 100644 --- a/src/create-model.jl +++ b/src/create-model.jl @@ -1032,23 +1032,31 @@ function create_model( @expression(model, 0.0) end for (a, y, v) in accumulated_set_using_compact_method ] - @expression( - model, - accumulated_units[y ∈ Y, a ∈ A], - if a in decommissionable_assets_using_simple_method - accumulated_units_simple_method[y, a] - elseif a in decommissionable_assets_using_compact_method - sum( - accumulated_units_compact_method[accumulated_set_using_compact_method_lookup[( - a, - y, - v, - )]] for v in V_all if (a, y, v) in accumulated_set_using_compact_method - ) - else - sum(values(graph[a].initial_units[y])) - end - ) + + # Create a lookup set for accumulated units + accumulated_units_lookup = + Dict((a, y) => idx for (idx, (a, y)) in enumerate((aa, yy) for aa in A for yy in Y)) + + accumulated_units = + model[:accumulated_units] = JuMP.AffExpr[ + if a in decommissionable_assets_using_simple_method + @expression(model, accumulated_units_simple_method[y, a]) + elseif a in decommissionable_assets_using_compact_method + @expression( + model, + sum( + accumulated_units_compact_method[accumulated_set_using_compact_method_lookup[( + a, + y, + v, + )]] for + v in V_all if (a, y, v) in accumulated_set_using_compact_method + ) + ) + else + @expression(model, sum(values(graph[a].initial_units[y]))) + end for a in A for y in Y + ] end ## Expressions for the objective function @@ -1133,6 +1141,7 @@ function create_model( decommissionable_assets_using_simple_method, decommissionable_assets_using_compact_method, V_all, + accumulated_units_lookup, accumulated_set_using_compact_method_lookup, Asb, assets_investment, @@ -1223,6 +1232,7 @@ function create_model( df_units_on, dataframes[:highest_out], outgoing_flow_highest_out_resolution, + accumulated_units_lookup, accumulated_units, Ai, Auc,