Skip to content

Fix MOI.TerminationStatus #307

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

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function allow_modification(o::Optimizer)
if SCIPgetStage(o) != SCIP_STAGE_PROBLEM
@SCIP_CALL SCIPfreeTransform(o)
end
o.scip_solve_status = _kSCIP_SOLVE_STATUS_NOT_CALLED
return nothing
end

Expand Down
9 changes: 6 additions & 3 deletions src/MOI_wrapper/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# results

term_status_map = Dict(
SCIP_STATUS_UNKNOWN => MOI.OPTIMIZE_NOT_CALLED,
const _TERMINATION_STATUS_MAP = Dict(
SCIP_STATUS_UNKNOWN => MOI.OTHER_ERROR,
SCIP_STATUS_USERINTERRUPT => MOI.INTERRUPTED,
SCIP_STATUS_NODELIMIT => MOI.NODE_LIMIT,
SCIP_STATUS_TOTALNODELIMIT => MOI.NODE_LIMIT,
Expand All @@ -25,7 +25,10 @@ term_status_map = Dict(
)

function MOI.get(o::Optimizer, ::MOI.TerminationStatus)
return term_status_map[SCIPgetStatus(o)]
if o.scip_solve_status == _kSCIP_SOLVE_STATUS_NOT_CALLED
return MOI.OPTIMIZE_NOT_CALLED
end
return _TERMINATION_STATUS_MAP[SCIPgetStatus(o)]
end

function MOI.get(o::Optimizer, attr::MOI.PrimalStatus)
Expand Down
2 changes: 1 addition & 1 deletion test/cutcallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import MathOptInterface as MOI
MOI.set(optimizer, MOI.UserCutCallback(), cutcallback)

# solve the problem
SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[])
MOI.optimize!(optimizer)

# The cut callback was called and obtaining the LP-solution worked.
@test calls >= 1
Expand Down
20 changes: 4 additions & 16 deletions test/sepa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ import MathOptInterface as MOI
SCIP.include_sepa(inner.scip[], inner.sepas, sepa)

# solve the problem
SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[])
MOI.optimize!(optimizer)

# the separator is called
@test sepa.called >= 1

# free the problem
finalize(inner)
end

# Test, whether adding cuts in `exec_lp` via `add_cut_sepa` works [1/2].
Expand Down Expand Up @@ -94,7 +91,7 @@ end
SCIP.include_sepa(inner.scip[], inner.sepas, sepa)

# solve the problem
SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[])
MOI.optimize!(optimizer)

# SCIP found the single remaining optimal solution
@test MOI.get(optimizer, MOI.TerminationStatus()) == MOI.OPTIMAL
Expand All @@ -105,9 +102,6 @@ end
rtol
@test MOI.get(optimizer, MOI.VariablePrimal(), y) ≈ 1.0 atol = atol rtol =
rtol

# free the problem
finalize(inner)
end

# Test, whether adding cuts in `exec_lp` via `add_cut_sepa` works [2/2].
Expand Down Expand Up @@ -152,7 +146,7 @@ end
SCIP.include_sepa(inner.scip[], inner.sepas, sepa)

# solve the problem
SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[])
MOI.optimize!(optimizer)

# SCIP found the single remaining optimal solution
@test MOI.get(optimizer, MOI.TerminationStatus()) == MOI.OPTIMAL
Expand All @@ -163,9 +157,6 @@ end
rtol
@test MOI.get(optimizer, MOI.VariablePrimal(), y) ≈ 0.0 atol = atol rtol =
rtol

# free the problem
finalize(inner)
end

# Test, whether we can cut the optimal solution.
Expand Down Expand Up @@ -210,7 +201,7 @@ end
SCIP.include_sepa(inner.scip[], inner.sepas, sepa)

# solve the problem
SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[])
MOI.optimize!(optimizer)

# SCIP found the non-optimal solution, that remains after the cut.
@test MOI.get(optimizer, MOI.TerminationStatus()) == MOI.OPTIMAL
Expand All @@ -221,7 +212,4 @@ end
rtol
@test MOI.get(optimizer, MOI.VariablePrimal(), y) ≈ 0.0 atol = atol rtol =
rtol

# free the problem
finalize(inner)
end
Loading