Skip to content

Commit

Permalink
Change core model for storage methods (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawin committed May 6, 2024
1 parent ac096f3 commit 9aa3270
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
47 changes: 39 additions & 8 deletions src/constraints/investment.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,64 @@
export add_investment_constraints!

"""
add_investment_constraints!(graph, Ai, Fi, assets_investment, flows_investment)
add_investment_constraints!(graph, Ai, Ase, Fi, assets_investment, assets_investment_energy, flows_investment)
Adds the investment constraints for all asset types and transport flows to the model
"""

function add_investment_constraints!(graph, Ai, Fi, assets_investment, flows_investment)
function add_investment_constraints!(
graph,
Ai,
Ase,
Fi,
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, a)
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)
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, u, v)
bound_value = _find_upper_bound(graph, Ai, Ase, u, v)
JuMP.set_upper_bound(flows_investment[(u, v)], bound_value)
end
end
end

function _find_upper_bound(graph, investments...)
bound_value = graph[investments...].investment_limit / graph[investments...].capacity
if graph[investments...].investment_integer
bound_value = floor(bound_value)
function _find_upper_bound(
graph,
asset_indices,
storage_asset_indices,
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 = 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
bound_value = floor(bound_value)
end
end
return bound_value
end
33 changes: 30 additions & 3 deletions src/create-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ function create_model(graph, representative_periods, dataframes, timeframe; writ
Ai = filter_assets(:investable, true)
Fi = filter_flows(:investable, true)

# Create subsets of assets by storage_method_energy
Ase = filter_assets(:storage_method_energy, true)

# Maximum timestep
Tmax = maximum(last(rp.timesteps) for rp in representative_periods)
expression_workspace = Vector{JuMP.AffExpr}(undef, Tmax)
Expand All @@ -323,6 +326,7 @@ function create_model(graph, representative_periods, dataframes, timeframe; writ
]
@variable(model, 0 assets_investment[Ai]) #number of installed asset units [N]
@variable(model, 0 flows_investment[Fi])
@variable(model, 0 assets_investment_energy[AseAi]) #number of installed asset units for storage energy [N]
storage_level_intra_rp =
model[:storage_level_intra_rp] = [
@variable(
Expand Down Expand Up @@ -352,11 +356,21 @@ function create_model(graph, representative_periods, dataframes, timeframe; writ
end
end

for a in Ase Ai
if graph[a].investment_integer_storage_energy
JuMP.set_integer(assets_investment_energy[a])
end
end

## Expressions
@expression(
model,
energy_limit[a AsAi],
graph[a].energy_to_power_ratio * graph[a].capacity * assets_investment[a]
if graph[a].storage_method_energy
graph[a].capacity_storage_energy * assets_investment_energy[a]
else
graph[a].energy_to_power_ratio * graph[a].capacity * assets_investment[a]
end
)

# Creating the incoming and outgoing flow expressions
Expand Down Expand Up @@ -452,7 +466,12 @@ function create_model(graph, representative_periods, dataframes, timeframe; writ
## Expressions for the objective function
assets_investment_cost = @expression(
model,
sum(graph[a].investment_cost * graph[a].capacity * assets_investment[a] for a in Ai)
sum(graph[a].investment_cost * graph[a].capacity * assets_investment[a] for a in Ai) +
sum(
graph[a].investment_cost_storage_energy *
graph[a].capacity_storage_energy *
assets_investment_energy[a] for a in Ase
)
)

flows_investment_cost = @expression(
Expand Down Expand Up @@ -532,7 +551,15 @@ function create_model(graph, representative_periods, dataframes, timeframe; writ

add_transport_constraints!(model, graph, df_flows, flow, Ft, flows_investment)

add_investment_constraints!(graph, Ai, Fi, assets_investment, flows_investment)
add_investment_constraints!(
graph,
Ai,
Ase,
Fi,
assets_investment,
assets_investment_energy,
flows_investment,
)

if write_lp_file
JuMP.write_to_file(model, "model.lp")
Expand Down

0 comments on commit 9aa3270

Please sign in to comment.