From 0fe4d8fb5821d55492755b8c48f4ac5ea496657b Mon Sep 17 00:00:00 2001 From: Ni Wang <125902905+gnawin@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:19:00 +0200 Subject: [PATCH] Add an expression that covers both simple and compact methods (#800) --- src/constraints/capacity.jl | 15 +++--- src/create-model.jl | 46 +++++++++++++------ .../graph-assets-data.csv | 6 +-- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/constraints/capacity.jl b/src/constraints/capacity.jl index dfb3b166..b3fb1502 100644 --- a/src/constraints/capacity.jl +++ b/src/constraints/capacity.jl @@ -10,7 +10,7 @@ add_capacity_constraints!(model, investable_assets_using_simple_method, Asb, assets_investment, - accumulate_capacity_simple_method, + accumulated_units_simple_method, outgoing_flow_highest_out_resolution, incoming_flow_highest_in_resolution ) @@ -28,17 +28,15 @@ function add_capacity_constraints!( decommissionable_assets_using_simple_method, decommissionable_assets_using_compact_method, V_all, + accumulated_set_using_compact_method_lookup, Asb, assets_investment, - accumulate_capacity_simple_method, - accumulate_capacity_compact_method, + accumulated_units_simple_method, + accumulated_units_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 @@ -57,7 +55,7 @@ function add_capacity_constraints!( 1.0, ) * ( graph[row.asset].capacity * - accumulate_capacity_simple_method[row.year, row.asset] + accumulated_units_simple_method[row.year, row.asset] ) ) elseif row.asset ∈ decommissionable_assets_using_compact_method @@ -72,7 +70,8 @@ function add_capacity_constraints!( ("availability", row.rep_period), row.timesteps_block, 1.0, - ) * accumulate_capacity_compact_method[compact_set_lookup[( + ) * + accumulated_units_compact_method[accumulated_set_using_compact_method_lookup[( row.asset, row.year, v, diff --git a/src/create-model.jl b/src/create-model.jl index 900e139a..d4fdfcc8 100644 --- a/src/create-model.jl +++ b/src/create-model.jl @@ -661,6 +661,12 @@ function create_model( )) ] + # Create a lookup set for compact method + accumulated_set_using_compact_method_lookup = Dict( + (a, y, v) => idx for + (idx, (a, y, v)) in enumerate(accumulated_set_using_compact_method) + ) + # Create subsets of storage assets Ase = Dict(y => As ∩ filter_graph(graph, A, true, :storage_method_energy, y) for y in Y) Asb = Dict( @@ -984,11 +990,8 @@ function create_model( @timeit to "multi-year investment" begin @expression( model, - accumulate_capacity_simple_method[ - y ∈ Y, - a ∈ decommissionable_assets_using_simple_method, - ], - graph[a].initial_units[y][y] + sum( + accumulated_units_simple_method[y ∈ Y, a ∈ decommissionable_assets_using_simple_method], + sum(values(graph[a].initial_units[y])) + sum( assets_investment[yy, a] for yy in Y if a ∈ investable_assets_using_simple_method[yy] && starting_year_using_simple_method[(y, a)] ≤ yy ≤ y @@ -999,8 +1002,8 @@ function create_model( ) cond1(a, y, v) = a in existing_assets_by_year_using_compact_method[v] cond2(a, y, v) = v in Y && a in investable_assets_using_compact_method[v] - accumulate_capacity_compact_method = - model[:accumulate_capacity_compact_method] = JuMP.AffExpr[ + accumulated_units_compact_method = + model[:accumulated_units_compact_method] = JuMP.AffExpr[ if cond1(a, y, v) && cond2(a, y, v) @expression( model, @@ -1029,6 +1032,24 @@ 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 ∈ decommissionable_assets_using_simple_method∪decommissionable_assets_using_compact_method, + ], + if a in decommissionable_assets_using_simple_method + accumulated_units_simple_method[y, a] + else + 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 + ) + end + ) end ## Expressions for the objective function @@ -1044,13 +1065,11 @@ function create_model( assets_fixed_cost = @expression( model, sum( - graph[a].fixed_cost[y] * - graph[a].capacity * - accumulate_capacity_simple_method[y, a] for y in Y for + graph[a].fixed_cost[y] * graph[a].capacity * accumulated_units_simple_method[y, a] for y in Y for a in decommissionable_assets_using_simple_method ) + sum( graph[a].fixed_cost[v] * graph[a].capacity * accm for (accm, (a, y, v)) in - zip(accumulate_capacity_compact_method, accumulated_set_using_compact_method) + zip(accumulated_units_compact_method, accumulated_set_using_compact_method) ) ) @@ -1115,10 +1134,11 @@ function create_model( decommissionable_assets_using_simple_method, decommissionable_assets_using_compact_method, V_all, + accumulated_set_using_compact_method_lookup, Asb, assets_investment, - accumulate_capacity_simple_method, - accumulate_capacity_compact_method, + accumulated_units_simple_method, + accumulated_units_compact_method, accumulated_set_using_compact_method, outgoing_flow_highest_out_resolution, incoming_flow_highest_in_resolution, diff --git a/test/inputs/Multi-year Investments/graph-assets-data.csv b/test/inputs/Multi-year Investments/graph-assets-data.csv index 896fea72..48d4968c 100644 --- a/test/inputs/Multi-year Investments/graph-assets-data.csv +++ b/test/inputs/Multi-year Investments/graph-assets-data.csv @@ -1,8 +1,8 @@ ,{producer;consumer},{group name},{none;simple;compact},MW,year, name,type,group,investment_method,capacity,technical_lifetime,discount_rate -ocgt,producer,,compact,100,15,0.05 -ccgt,producer,,compact,400,25,0.05 +ocgt,producer,,simple,100,15,0.05 +ccgt,producer,,simple,400,25,0.05 wind,producer,,compact,50,30,0.05 -solar,producer,,compact,10,15,0.05 +solar,producer,,simple,10,15,0.05 ens,producer,,none,1115,15,0.05 demand,consumer,,none,0,15,0.05