Skip to content

Commit ce92e06

Browse files
authored
Throw GetAttributeNotAllowed when ObjBound is GRB_INFINITY (#627)
1 parent 96cf921 commit ce92e06

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/MOI_wrapper/MOI_wrapper.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,6 +3320,9 @@ function MOI.get(model::Optimizer, attr::MOI.ObjectiveBound)
33203320
valueP = Ref{Cdouble}()
33213321
ret = GRBgetdblattr(model, "ObjBound", valueP)
33223322
_check_ret(model, ret)
3323+
if valueP[] == GRB_INFINITY
3324+
throw(MOI.GetAttributeNotAllowed((attr)))
3325+
end
33233326
return valueP[]
33243327
end
33253328

test/MOI/MOI_wrapper.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,26 @@ function test_multiple_solutions_when_dual_infeasible()
16181618
return
16191619
end
16201620

1621+
function test_objbound_errors_when_GRB_INFINITY()
1622+
if Gurobi._GUROBI_VERSION < v"11"
1623+
return
1624+
end
1625+
model = Gurobi.Optimizer(GRB_ENV)
1626+
MOI.set(model, MOI.Silent(), true)
1627+
x, _ = MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0))
1628+
y = MOI.add_variable(model)
1629+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1630+
f = 1.0 * x * y - 1.0 * y * y
1631+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
1632+
MOI.optimize!(model)
1633+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.DUAL_INFEASIBLE
1634+
@test_throws(
1635+
MOI.GetAttributeNotAllowed{MOI.ObjectiveBound},
1636+
MOI.get(model, MOI.ObjectiveBound()),
1637+
)
1638+
return
1639+
end
1640+
16211641
end # TestMOIWrapper
16221642

16231643
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)