Skip to content

Commit

Permalink
refactor: enable BarHomogeneous on Numeric, load_shed on Infeasible
Browse files Browse the repository at this point in the history
  • Loading branch information
danielolsen committed Jun 4, 2020
1 parent f9b8320 commit a6d1b31
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/loop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ function interval_loop(env::Gurobi.Env, model_kwargs::Dict,
n_interval::Int, start_index::Int,
inputfolder::String, outputfolder::String)
# Bad (but known) statuses to match against
bad_statuses = (
JuMP.MOI.INFEASIBLE, JuMP.MOI.INFEASIBLE_OR_UNBOUNDED,
JuMP.MOI.NUMERICAL_ERROR, JuMP.MOI.OTHER_LIMIT,
)
numeric_statuses = (
JuMP.MOI.INFEASIBLE_OR_UNBOUNDED, JuMP.MOI.NUMERICAL_ERROR,
JuMP.MOI.OTHER_LIMIT)
infeasible_statuses = (
JuMP.MOI.INFEASIBLE, JuMP.MOI.INFEASIBLE_OR_UNBOUNDED)
# Constant parameters
case = model_kwargs["case"]
storage = model_kwargs["storage"]
Expand All @@ -34,6 +35,7 @@ function interval_loop(env::Gurobi.Env, model_kwargs::Dict,
# These must be declared global so that they persist through the loop.
global m, voi, pg0, storage_e0
@show ("load_shed_enabled" in keys(model_kwargs))
@show ("BarHomogeneous" in keys(solver_kwargs))
interval_start = start_index + (i - 1) * interval
interval_end = interval_start + interval - 1
model_kwargs["start_index"] = interval_start
Expand Down Expand Up @@ -112,22 +114,26 @@ function interval_loop(env::Gurobi.Env, model_kwargs::Dict,
f = JuMP.objective_value(m)
results = get_results(f, voi, model_kwargs["case"])
break
elseif !("load_shed_enabled" in keys(model_kwargs))
# is load shed not enabled, enable it and re-build the model
elseif (status in numeric_statuses
& !("BarHomogeneous" in keys(solver_kwargs)))
# if BarHomogeneous is not enabled, enable it and re-build
solver_kwargs["BarHomogeneous"] = 1
println("enable BarHomogeneous")
JuMP.set_parameter(m, "BarHomogeneous", 1)
elseif (status in numeric_statuses
& !("load_shed_enabled" in keys(model_kwargs)))
# if load shed not enabled, enable it and re-build the model
model_kwargs["load_shed_enabled"] = true
m_kwargs = (; (Symbol(k) => v for (k,v) in model_kwargs)...)
s_kwargs = (; (Symbol(k) => v for (k,v) in solver_kwargs)...)
println("rebuild with load shed")
m = JuMP.direct_model(Gurobi.Optimizer(env; s_kwargs...))
m, voi = _build_model(m; m_kwargs...)
elseif !("BarHomogeneous" in keys(solver_kwargs))
# if BarHomogeneous is not enabled, enable it and re-build
solver_kwargs["BarHomogeneous"] = 1
println("enable BarHomogeneous")
JuMP.set_parameter(m, "BarHomogeneous", 1)
else
# Something has gone very wrong
@show status
@show keys(model_kwargs)
@show keys(solver_kwargs)
@show JuMP.objective_value(m)
if (("load_shed_enabled" in keys(model_kwargs))
&& (model_kwargs["load_shed_enabled"] == true))
Expand Down

0 comments on commit a6d1b31

Please sign in to comment.