Skip to content

Commit 16b2a2a

Browse files
committed
Update the storage constraint to use the rolling initial storage level
Update src/constraints/storage.jl to use the initial_storage_level stored in the rolling horizon. Add test for the rolling horizon objective values to control future changes. Part of #1365
1 parent 6bd675b commit 16b2a2a

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

src/constraints/storage.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,27 @@ export add_storage_constraints!
55
66
Adds the storage asset constraints to the model.
77
"""
8-
function add_storage_constraints!(connection, model, variables, expressions, constraints, profiles)
8+
function add_storage_constraints!(
9+
connection,
10+
model,
11+
variables,
12+
expressions,
13+
constraints,
14+
profiles;
15+
rolling_horizon = false,
16+
)
917
var_storage_level_rep_period = variables[:storage_level_rep_period]
1018
var_storage_level_over_clustered_year = variables[:storage_level_over_clustered_year]
1119

20+
rolling_horizon_lookup = if rolling_horizon
21+
Dict{Int,Int}(
22+
row.var_storage_id::Int => row.id::Int for
23+
row in DuckDB.query(connection, "FROM param_initial_storage_level")
24+
)
25+
else
26+
Dict{Int,Int}()
27+
end
28+
1229
## REP-PERIOD CONSTRAINTS (within a representative period)
1330
# - Balance constraint (using the lowest temporal resolution)
1431
let table_name = :balance_storage_rep_period, cons = constraints[table_name]
@@ -27,7 +44,12 @@ function add_storage_constraints!(connection, model, variables, expressions, con
2744
sum,
2845
0.0,
2946
)
30-
initial_storage_level = row.initial_storage_level::Union{Float64,Missing}
47+
initial_storage_level = if rolling_horizon && row.time_block_start == 1
48+
rolling_horizon_id = rolling_horizon_lookup[row.id]
49+
variables[:param_initial_storage_level].container[rolling_horizon_id]
50+
else
51+
row.initial_storage_level::Union{Float64,Missing}
52+
end
3153
storage_charging_efficiency = row.storage_charging_efficiency::Float64
3254
storage_discharging_efficiency = row.storage_discharging_efficiency::Float64
3355

src/create-model.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ function create_model(
186186
variables,
187187
expressions,
188188
constraints,
189-
profiles,
189+
profiles;
190+
rolling_horizon,
190191
)
191192

192193
@timeit to "add_hub_constraints!" add_hub_constraints!(model, constraints)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
EnergyProblem:
2+
- Solved using rolling horizon. Internal model info:
3+
- Number of variables: 337
4+
- Number of constraints for variable bounds: 337
5+
- Number of structural constraints: 384
6+
- Model solved!
7+
- Termination status: OPTIMAL
8+
- Objective value: NaN

test/test-case-studies.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ end
154154
TulipaEnergyModel.populate_with_defaults!(connection)
155155
energy_problem = TulipaEnergyModel.run_scenario(connection; show_log = false)
156156
@test energy_problem.objective_value 410873.9 rtol = 1e-5
157+
158+
# We only check the rolling horizon objectives since we cannot easily obtain
159+
# the objective of the full problem
160+
expected_objective_values =
161+
[103424.0, 120393.6, 109303.0, 108443.0, 122910.4, 137268.2, 118006.6]
162+
163+
energy_problem = TulipaEnergyModel.run_rolling_horizon(connection, 24, 48; show_log = false)
164+
for row in DuckDB.query(connection, "FROM rolling_horizon_window")
165+
@test row.objective_value expected_objective_values[row.id] rtol = 1e-5
166+
end
167+
168+
io = IOBuffer()
169+
print(io, energy_problem)
170+
@test split(String(take!(io))) ==
171+
split(read("io-outputs/energy-problem-rolling-horizon.txt", String))
157172
end
158173

159174
@testitem "Infeasible Case Study" setup = [CommonSetup] tags = [:case_study, :integration, :slow] begin

0 commit comments

Comments
 (0)