Skip to content

Commit

Permalink
use while loop to re-try to solve
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Feb 9, 2024
1 parent b5b6cf2 commit fff6433
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,23 +671,34 @@ function solve_impl!(container::OptimizationContainer, system::PSY.System)
optimizer_stats = get_optimizer_stats(container)

jump_model = get_jump_model(container)
_,
optimizer_stats.timed_solve_time,
optimizer_stats.solve_bytes_alloc,
optimizer_stats.sec_in_gc = @timed JuMP.optimize!(jump_model)
model_status = JuMP.primal_status(jump_model)
if model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
@error "Optimizer returned $model_status trying again"
JuMP.optimize!(jump_model)

model_status = MOI.NO_SOLUTION::MOI.ResultStatusCode
conflict_status = MOI.COMPUTE_CONFLICT_NOT_CALLED

MAX_TRIES = 2
try_count = 0
while model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
_,
optimizer_stats.timed_solve_time,
optimizer_stats.solve_bytes_alloc,
optimizer_stats.sec_in_gc = @timed JuMP.optimize!(jump_model)
model_status = JuMP.primal_status(jump_model)
end

if model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
@error "Optimizer returned $model_status getting conflict"
if get_calculate_conflict(get_settings(container))
compute_conflict!(container)
@error "Optimizer returned $model_status computing conflict"
conflict_status = compute_conflict!(container)
if conflict_status == MOI.CONFLICT_FOUND
return RunStatus.FAILED
end
else
@error "Optimizer returned $model_status trying again"
end

try_count += 1
if try_count > MAX_TRIES
@error "Optimizer returned $model_status after $try_count solve tries"
return RunStatus.FAILED
end
return RunStatus.FAILED
end

status = RunStatus.SUCCESSFUL
Expand All @@ -712,8 +723,7 @@ function compute_conflict!(container::OptimizationContainer)
JuMP.compute_conflict!(jump_model)
if MOI.get(jump_model, MOI.ConflictStatus()) != MOI.CONFLICT_FOUND
@error "No conflict could be found for the model. $(MOI.get(jump_model, MOI.ConflictStatus()))"

return
return MOI.get(jump_model, MOI.ConflictStatus())
end

for (key, field_container) in get_constraints(container)
Expand All @@ -726,6 +736,8 @@ function compute_conflict!(container::OptimizationContainer)
end
end
@error "$(conflict)"

return MOI.get(jump_model, MOI.ConflictStatus())
catch e
jump_model.is_model_dirty = true
if isa(e, MethodError)
Expand All @@ -735,7 +747,7 @@ function compute_conflict!(container::OptimizationContainer)
end
end

return
return MOI.NO_CONFLICT_EXISTS
end

function write_optimizer_stats!(container::OptimizationContainer)
Expand Down

0 comments on commit fff6433

Please sign in to comment.