Skip to content

Throw GetAttributeNotAllowed when ObjBound is GRB_INFINITY #627

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 2 commits into from
Mar 15, 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
3 changes: 3 additions & 0 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,9 @@ function MOI.get(model::Optimizer, attr::MOI.ObjectiveBound)
valueP = Ref{Cdouble}()
ret = GRBgetdblattr(model, "ObjBound", valueP)
_check_ret(model, ret)
if valueP[] == GRB_INFINITY
throw(MOI.GetAttributeNotAllowed((attr)))
end
return valueP[]
end

Expand Down
20 changes: 20 additions & 0 deletions test/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,26 @@ function test_multiple_solutions_when_dual_infeasible()
return
end

function test_objbound_errors_when_GRB_INFINITY()
if Gurobi._GUROBI_VERSION < v"11"
return
end
model = Gurobi.Optimizer(GRB_ENV)
MOI.set(model, MOI.Silent(), true)
x, _ = MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0))
y = MOI.add_variable(model)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
f = 1.0 * x * y - 1.0 * y * y
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.DUAL_INFEASIBLE
@test_throws(
MOI.GetAttributeNotAllowed{MOI.ObjectiveBound},
MOI.get(model, MOI.ObjectiveBound()),
)
return
end

end # TestMOIWrapper

TestMOIWrapper.runtests()
Loading