Skip to content

Commit 4d26244

Browse files
authored
[Bridges] fix supports for VariableIndex attributes (#1991)
1 parent ef81067 commit 4d26244

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/Bridges/bridge_optimizer.jl

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,30 +1347,15 @@ function MOI.supports(
13471347
attr::MOI.AbstractConstraintAttribute,
13481348
IndexType::Type{MOI.ConstraintIndex{F,S}},
13491349
) where {F,S}
1350-
is_variable_function = F == MOI.Utilities.variable_function_type(S)
1351-
# A `F`-in-`S` constraint could be added to the model either if it this
1352-
# constraint is not bridged or if variables constrained on creations to `S`
1353-
# are not bridged and `F` is `VariableIndex` or `VectorOfVariables`.
1354-
if !is_bridged(b, F, S) || (is_variable_function && !is_bridged(b, S))
1355-
if !MOI.supports(b.model, attr, IndexType)
1356-
return false
1357-
end
1358-
end
1359-
bridge = recursive_model(b)
1360-
# If variable bridged, get the indices from the variable bridges.
1361-
if is_variable_function && is_bridged(b, S) && is_variable_bridged(b, S)
1362-
if !MOI.supports(bridge, attr, Variable.concrete_bridge_type(b, S))
1363-
return false
1364-
end
1365-
end
1366-
# If constraint bridged, get the indices from the constraint bridges.
1367-
if is_bridged(b, F, S) ||
1368-
(is_variable_function && supports_constraint_bridges(b))
1369-
if !MOI.supports(bridge, attr, Constraint.concrete_bridge_type(b, F, S))
1370-
return false
1371-
end
1350+
if is_bridged(b, F, S)
1351+
bridge = Constraint.concrete_bridge_type(b, F, S)
1352+
return MOI.supports(recursive_model(b), attr, bridge)
1353+
elseif F == MOI.Utilities.variable_function_type(S) && is_bridged(b, S)
1354+
bridge = Variable.concrete_bridge_type(b, S)
1355+
return MOI.supports(recursive_model(b), attr, bridge)
1356+
else
1357+
return MOI.supports(b.model, attr, IndexType)
13721358
end
1373-
return true
13741359
end
13751360

13761361
function MOI.set(

test/Bridges/bridge_optimizer.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,32 @@ function test_constant_modification_with_affine_variable_bridge()
821821
@test MOI.get(model, obj) new_inner_obj
822822
end
823823

824+
struct _IssueIpopt333 <: MOI.AbstractOptimizer end
825+
826+
function MOI.supports(
827+
::_IssueIpopt333,
828+
::MOI.ConstraintDualStart,
829+
::Type{MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}}},
830+
)
831+
return true
832+
end
833+
834+
function MOI.supports_constraint(
835+
::_IssueIpopt333,
836+
::Type{MOI.VariableIndex},
837+
::Type{MOI.GreaterThan{Float64}},
838+
)
839+
return true
840+
end
841+
842+
function test_IssueIpopt333_supports_ConstraintDualStart_VariableIndex()
843+
model = MOI.Bridges.full_bridge_optimizer(_IssueIpopt333(), Float64)
844+
attr = MOI.ConstraintDualStart()
845+
IndexType = MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}}
846+
@test MOI.supports(model, attr, IndexType)
847+
return
848+
end
849+
824850
end # module
825851

826852
TestBridgeOptimizer.runtests()

0 commit comments

Comments
 (0)