Skip to content

Commit 5a66865

Browse files
authored
Merge pull request #30 from LAMPSPUC/fix/termination-status-check
Fix/termination status check
2 parents 7d08453 + f79566f commit 5a66865

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/ApplicationDrivenLearning.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,10 @@ and new constraint fixing to original forecast variables.
135135
function build_plan_model_forecast_params(model::Model)
136136
# adds parametrized forecast variables using MOI.Parameter
137137
forecast_size = size(model.forecast_vars)[1]
138-
model.plan_forecast_params = @variable(
139-
model.plan,
140-
_forecast[1:forecast_size] in MOI.Parameter.(zeros(forecast_size))
141-
)
142-
# fixes old and new prediction variables together
138+
model.plan_forecast_params = plan_forecast_vars(model)
143139
@constraint(
144140
model.plan,
145-
plan_forecast_fix,
146-
model.plan_forecast_params .== plan_forecast_vars(model)
141+
model.plan_forecast_params .∈ MOI.Parameter.(zeros(forecast_size))
147142
)
148143
end
149144

src/simulation.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,33 @@ function compute_single_step_cost(
33
y::Vector{<:Real},
44
yhat::Vector{<:Real},
55
)
6+
# set forecast params as prediction output
67
MOI.set.(model.plan, POI.ParameterValue(), model.plan_forecast_params, yhat)
8+
# optimize plan model
79
optimize!(model.plan)
8-
@assert termination_status(model.plan) == MOI.OPTIMAL "Optimization failed for PLAN model"
10+
# check for solution and fix assess policy vars
11+
try
12+
set_normalized_rhs.(
13+
model.assess[:assess_policy_fix],
14+
value.(plan_policy_vars(model)),
15+
)
16+
catch e
17+
println("Optimization failed for PLAN model.")
18+
throw(e)
19+
end
20+
# fix assess forecast vars on observer values
921
fix.(assess_forecast_vars(model), y; force = true)
10-
set_normalized_rhs.(
11-
model.assess[:assess_policy_fix],
12-
value.(plan_policy_vars(model)),
13-
)
22+
# optimize assess model
1423
optimize!(model.assess)
15-
@assert termination_status(model.assess) == MOI.OPTIMAL "Optimization failed for ASSESS model"
16-
return objective_value(model.assess)
24+
# check for optimization
25+
try
26+
return objective_value(model.assess)
27+
catch e
28+
println("Optimization failed for ASSESS model")
29+
throw(e)
30+
end
31+
# should never get here
32+
return 0
1733
end
1834

1935
"""

0 commit comments

Comments
 (0)