Skip to content

Commit fc150d2

Browse files
authored
Merge pull request #33 from LAMPSPUC/dev
Dev
2 parents 4ef0199 + ea7455e commit fc150d2

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ApplicationDrivenLearning"
22
uuid = "0856f1c8-ef17-4e14-9230-2773e47a789e"
3-
authors = ["Giovanni Amorin"]
4-
version = "0.1.0"
3+
authors = ["Giovanni Amorim", "Joaquim Garcia"]
4+
version = "0.1.1"
55

66
[deps]
77
BilevelJuMP = "485130c0-026e-11ea-0f1a-6992cd14145c"

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/jump.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ function JuMP.add_variable(
6464
name * "_assess",
6565
),
6666
)
67+
68+
# forecast variables can't have bounds
69+
if JuMP.has_lower_bound(forecast.plan)
70+
@warn "Forecast variable lower bound will be removed."
71+
JuMP.delete_lower_bound(forecast.plan)
72+
JuMP.delete_lower_bound(forecast.assess)
73+
end
74+
75+
if JuMP.has_upper_bound(forecast.plan)
76+
@warn "Forecast variable upper bound will be removed."
77+
JuMP.delete_upper_bound(forecast.plan)
78+
JuMP.delete_upper_bound(forecast.assess)
79+
end
80+
6781
push!(model.forecast_vars, forecast)
6882
return forecast
6983
end

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)