Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 26, 2025
1 parent ce68740 commit 0ad1cc9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/optimizer_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,16 @@ Stacktrace:
[...]
```
"""
function assert_is_solved_and_feasible(model::GenericModel; kwargs...)
if !is_solved_and_feasible(model; kwargs...)
function assert_is_solved_and_feasible(
model::GenericModel;
result::Int = 1,
kwargs...,
)
if !is_solved_and_feasible(model; result, kwargs...)
error(
"The model was not solved correctly. Here is a summary of the " *
"solution to help debug why this happened:\n\n" *
string(solution_summary(model)),
string(solution_summary(model; result)),
)
end
return
Expand Down
40 changes: 39 additions & 1 deletion test/test_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1323,9 +1323,47 @@ function test_assert_is_solved_and_feasible()
MOI.set(mock, MOI.RawStatusString(), "failed")
@test assert_is_solved_and_feasible(model) === nothing
@test_throws(
ErrorException,
ErrorException(
"""
The model was not solved correctly. Here is a summary of the solution to help debug why this happened:
* Solver : Mock
* Status
Result count : 1
Termination status : OPTIMAL
Message from the solver:
"failed"
* Candidate solution (result #1)
Primal status : FEASIBLE_POINT
Dual status : NO_SOLUTION
Objective value : 0.00000e+00
Dual objective value : 0.00000e+00
* Work counters
""",
),
assert_is_solved_and_feasible(model; dual = true),
)
@test_throws(
ErrorException(
"""
The model was not solved correctly. Here is a summary of the solution to help debug why this happened:
* Solver : Mock
* Status
Result count : 1
Termination status : OPTIMAL
* Candidate solution (result #2)
Primal status : NO_SOLUTION
Dual status : NO_SOLUTION
""",
),
assert_is_solved_and_feasible(model; dual = true, result = 2),
)
return
end

Expand Down

0 comments on commit 0ad1cc9

Please sign in to comment.