Skip to content

Commit

Permalink
Fix handling of solution statuses for multiple results (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Feb 7, 2021
1 parent be9a745 commit 812ffd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Gurobi"
uuid = "2e9cd046-0924-5485-92f1-d5272153d98b"
repo = "https://github.com/jump-dev/Gurobi.jl"
version = "0.9.8"
version = "0.9.9"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
13 changes: 8 additions & 5 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2474,21 +2474,22 @@ end

function MOI.get(model::Optimizer, attr::MOI.PrimalStatus)
_throw_if_optimize_in_progress(model, attr)
if attr.N != 1
return MOI.NO_SOLUTION
end
term = MOI.get(model, MOI.TerminationStatus())
if term == MOI.DUAL_INFEASIBLE || term == MOI.INFEASIBLE_OR_UNBOUNDED
if _has_primal_ray(model)
if attr.N != 1
return MOI.NO_SOLUTION
elseif _has_primal_ray(model)
return MOI.INFEASIBILITY_CERTIFICATE
else
return MOI.NO_SOLUTION
end
end
# Check SolCount explicitly instead of ResultCount to avoid returning 1 when
# there is a certiticate.
valueP = Ref{Cint}()
ret = GRBgetintattr(model, "SolCount", valueP)
_check_ret(model, ret)
return valueP[] > 0 ? MOI.FEASIBLE_POINT : MOI.NO_SOLUTION
return 1 <= attr.N <= valueP[] ? MOI.FEASIBLE_POINT : MOI.NO_SOLUTION
end

function _has_dual_ray(model::Optimizer)
Expand Down Expand Up @@ -2519,6 +2520,8 @@ function MOI.get(model::Optimizer, attr::MOI.DualStatus)
return MOI.NO_SOLUTION
end
end
# Check SolCount explicitly instead of ResultCount to avoid returning 1 when
# there is a certiticate.
valueP = Ref{Cint}()
ret = GRBgetintattr(model, "SolCount", valueP)
_check_ret(model, ret)
Expand Down
4 changes: 4 additions & 0 deletions test/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,8 @@ function test_multiple_solutions()
MOI.ResultIndexBoundsError,
MOI.get(model, MOI.ObjectiveValue(n)),
)
@test MOI.get(model, MOI.PrimalStatus(n)) == MOI.NO_SOLUTION
@test MOI.get(model, MOI.DualStatus(n)) == MOI.NO_SOLUTION
end
for n = 1:RC
xn = MOI.get(model, MOI.VariablePrimal(n), x)
Expand All @@ -1581,6 +1583,8 @@ function test_multiple_solutions()
item_values' * xn,
atol=1e-6,
)
@test MOI.get(model, MOI.PrimalStatus(n)) == MOI.FEASIBLE_POINT
@test MOI.get(model, MOI.DualStatus(n)) == MOI.NO_SOLUTION
end
end

Expand Down

3 comments on commit 812ffd3

@odow
Copy link
Member Author

@odow odow commented on 812ffd3 Feb 7, 2021

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/29582

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.9 -m "<description of version>" 812ffd313a6152681a8813481de7008faf3bddd3
git push origin v0.9.9

@henriquebecker91
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to set the Gurobi.jl version used in my environment to this specific commit and then noticed that you have already provided a new version with my changes. Thanks for being so agile.

Please sign in to comment.