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 is_solved_and_feasible #3668

Merged
merged 19 commits into from
Feb 14, 2024
Merged

Add is_solved_and_feasible #3668

merged 19 commits into from
Feb 14, 2024

Conversation

odow
Copy link
Member

@odow odow commented Feb 5, 2024

x-ref https://discourse.julialang.org/t/jump-behaviour-of-value-for-infeasible-models/109662/4

Perhaps one reason the question keeps coming up is that the docs don't actually uniformly implement the checks (because we "know" that HiGHS will find the right answer) 😄 I'll take the blame for that.

Copy link

codecov bot commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7181551) 98.32% compared to head (a9a9257) 98.33%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3668   +/-   ##
=======================================
  Coverage   98.32%   98.33%           
=======================================
  Files          43       43           
  Lines        5686     5696   +10     
=======================================
+ Hits         5591     5601   +10     
  Misses         95       95           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@odow
Copy link
Member Author

odow commented Feb 5, 2024

@odow
Copy link
Member Author

odow commented Feb 5, 2024

I think I like my suggestion from discourse:

"""
    has_solution(model::Model; dual::Bool = false)

Return `true` if the model has a feasible primal solution to return and the
solver terminated normally. If `dual`, additionally check that a feasible
dual solution is available.

If this function returns `false`, use [`termination_status`](@ref), [`result_count`](@ref),
[`primal_status`](@ref) and [`dual_status`](@ref) to understand what solutions
are available (if any).
"""
function has_solution(model::Model; dual::Bool = false)
    ret = termination_status(model) in (OPTIMAL, LOCALLY_SOLVED) &&
          primal_status(model) == FEASIBLE_POINT
    if dual
        ret &= dual_status(model) == FEASIBLE_POINT
    end
    return ret
end

Then these would all just become @assert has_solution(model) and @assert has_solution(model; dual = true).

We have has_values and has_duals, but they don't check the termination status.

Copy link

@gdalle gdalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very welcome addition! I would also add some details on the various problem statuses, as mentioned on discourse
https://discourse.julialang.org/t/jump-behaviour-of-value-for-infeasible-models/109662/6

docs/src/tutorials/linear/cannery.jl Outdated Show resolved Hide resolved
@odow odow changed the title [docs] check termination and primal status after optimize! Add has_optimal_solution Feb 6, 2024
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
@odow
Copy link
Member Author

odow commented Feb 6, 2024

@odow odow changed the title Add has_optimal_solution Add is_solved_and_feasible Feb 13, 2024
@odow
Copy link
Member Author

odow commented Feb 13, 2024

I've changed to is_solved_and_feasible

docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
docs/src/manual/solutions.md Outdated Show resolved Hide resolved
@odow odow merged commit 86b0ec8 into master Feb 14, 2024
10 of 11 checks passed
@odow odow deleted the od/doc-status branch February 14, 2024 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants