Skip to content

Commit 103d44a

Browse files
authored
Fix MOI.supports for MOI.ConstraintName of quadratic constraints (#186)
1 parent 87406b4 commit 103d44a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/MOI_wrapper.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,19 @@ function MOI.supports(
406406
return MOI.supports(model.optimizer, attr, tp)
407407
end
408408

409+
function MOI.supports(
410+
model::Optimizer,
411+
attr::MOI.ConstraintName,
412+
::Type{MOI.ConstraintIndex{F,S}},
413+
) where {T,F<:MOI.ScalarQuadraticFunction{T},S}
414+
G = MOI.ScalarAffineFunction{T}
415+
# We can't tell at type-time whether the constraints will be quadratic or
416+
# lowered to affine, so we return the conservative choice for supports of
417+
# needing to support names for both quadratic and affine constraints.
418+
return MOI.supports(model.optimizer, attr, MOI.ConstraintIndex{F,S}) &&
419+
MOI.supports(model.optimizer, attr, MOI.ConstraintIndex{G,S})
420+
end
421+
409422
function MOI.set(
410423
model::Optimizer,
411424
attr::MOI.ConstraintName,

test/moi_tests.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,3 +1982,26 @@ function test_no_quadratic_terms()
19821982
@test MOI.get(optimizer, MOI.ConstraintDual(), c) -1 atol = ATOL
19831983
return
19841984
end
1985+
1986+
MOI.Utilities.@model(
1987+
Model185,
1988+
(),
1989+
(MOI.EqualTo,),
1990+
(),
1991+
(),
1992+
(),
1993+
(MOI.ScalarAffineFunction,),
1994+
(),
1995+
()
1996+
);
1997+
1998+
function test_issue_185()
1999+
inner = Model185{Float64}()
2000+
mock = MOI.Utilities.MockOptimizer(inner; supports_names = false)
2001+
model = POI.Optimizer(MOI.Bridges.full_bridge_optimizer(mock, Float64))
2002+
for F in (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction)
2003+
C = MOI.ConstraintIndex{F{Float64},MOI.EqualTo{Float64}}
2004+
@test !MOI.supports(model, MOI.ConstraintName(), C)
2005+
end
2006+
return
2007+
end

0 commit comments

Comments
 (0)