Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add xpress patch #1051

Merged
merged 11 commits into from
Feb 9, 2024
1 change: 1 addition & 0 deletions src/core/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const NO_SERVICE_NAME_PROVIDED = ""
const CONTAINER_KEY_EMPTY_META = ""
const UPPER_BOUND = "ub"
const LOWER_BOUND = "lb"
const MAX_OPTIMIZE_TRIES = 2

# File Names definitions
const PROBLEM_SERIALIZATION_FILENAME = "operation_problem.bin"
Expand Down
52 changes: 39 additions & 13 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,35 @@
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"
if get_calculate_conflict(get_settings(container))
compute_conflict!(container)

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

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)

if model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
if get_calculate_conflict(get_settings(container))
@warn "Optimizer returned $model_status computing conflict"
conflict_status = compute_conflict!(container)
if conflict_status == MOI.CONFLICT_FOUND
return RunStatus.FAILED

Check warning on line 691 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L687-L691

Added lines #L687 - L691 were not covered by tests
end
else
@warn "Optimizer returned $model_status trying optimize! again"

Check warning on line 694 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L694

Added line #L694 was not covered by tests
end

try_count += 1
if try_count > MAX_OPTIMIZE_TRIES
@error "Optimizer returned $model_status after $MAX_OPTIMIZE_TRIES optimize! attempts"
return RunStatus.FAILED

Check warning on line 700 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L697-L700

Added lines #L697 - L700 were not covered by tests
end
end
return RunStatus.FAILED
end

status = RunStatus.SUCCESSFUL
Expand All @@ -699,13 +717,19 @@

function compute_conflict!(container::OptimizationContainer)
jump_model = get_jump_model(container)
settings = get_settings(container)

Check warning on line 720 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L720

Added line #L720 was not covered by tests
JuMP.unset_silent(jump_model)
jump_model.is_model_dirty = false
conflict = container.infeasibility_conflict
try
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()))"
conflict_status = MOI.get(jump_model, MOI.ConflictStatus())
if conflict_status != MOI.CONFLICT_FOUND
@error "No conflict could be found for the model. Status: $conflict_status"
if !get_optimizer_solve_log_print(settings)
JuMP.set_silent(jump_model)

Check warning on line 730 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L726-L730

Added lines #L726 - L730 were not covered by tests
end
return conflict_status

Check warning on line 732 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L732

Added line #L732 was not covered by tests
end

for (key, field_container) in get_constraints(container)
Expand All @@ -718,6 +742,8 @@
end
end
@error "$(conflict)"

return conflict_status

Check warning on line 746 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L746

Added line #L746 was not covered by tests
catch e
jump_model.is_model_dirty = true
if isa(e, MethodError)
Expand All @@ -727,7 +753,7 @@
end
end

return
return MOI.NO_CONFLICT_EXISTS

Check warning on line 756 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L756

Added line #L756 was not covered by tests
end

function write_optimizer_stats!(container::OptimizationContainer)
Expand Down
2 changes: 2 additions & 0 deletions src/core/optimizer_stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mutable struct OptimizerStats
has_duals::Bool
# Candidate solution
objective_bound::Union{Missing, Float64}
relative_gap::Union{Missing, Float64}
# Use missing instead of nothing so that CSV writting doesn't fail
dual_objective_value::Union{Missing, Float64}
# Work counters
Expand Down Expand Up @@ -37,6 +38,7 @@ function OptimizerStats()
false,
missing,
missing,
missing,
NaN,
missing,
missing,
Expand Down
1 change: 0 additions & 1 deletion src/operation/decision_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ function solve!(
@info "\n$(RUN_OPERATION_MODEL_TIMER)\n"
catch e
@error "Decision Problem solve failed" exception = (e, catch_backtrace())
# TODO: Run IIS here if the solve called failed
set_run_status!(model, RunStatus.FAILED)
end
end
Expand Down
4 changes: 4 additions & 0 deletions src/operation/operation_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
settings = get_settings(model)
model_name = get_name(model)
ts = get_current_timestamp(model)
output_dir = get_output_dir(model)
infeasible_opt_path = joinpath(output_dir, "infeasible_$(model_name)_$(ts).json")
serialize_optimization_model(container, infeasible_opt_path)
@error("Infeasible Problem Serialized at $(infeasible_opt_path)")

Check warning on line 94 in src/operation/operation_model_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/operation/operation_model_interface.jl#L91-L94

Added lines #L91 - L94 were not covered by tests
if !get_allow_fails(settings)
error("Solving model $(model_name) failed at $(ts)")
else
Expand Down
1 change: 1 addition & 0 deletions src/utils/jump_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ function _summary_to_dict!(optimizer_stats::OptimizerStats, jump_model::JuMP.Mod
:objective_bound, # Union{Missing,Float64}
:dual_objective_value, # Union{Missing,Float64}
# Work counters
:relative_gap, # Union{Missing,Int}
:barrier_iterations, # Union{Missing,Int}
:simplex_iterations, # Union{Missing,Int}
:node_count, # Union{Missing,Int}
Expand Down
Loading