Skip to content

Commit

Permalink
[Bridges] fix supports for VariableIndex attributes (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 6, 2022
1 parent ef81067 commit 4d26244
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1347,30 +1347,15 @@ function MOI.supports(
attr::MOI.AbstractConstraintAttribute,
IndexType::Type{MOI.ConstraintIndex{F,S}},
) where {F,S}
is_variable_function = F == MOI.Utilities.variable_function_type(S)
# A `F`-in-`S` constraint could be added to the model either if it this
# constraint is not bridged or if variables constrained on creations to `S`
# are not bridged and `F` is `VariableIndex` or `VectorOfVariables`.
if !is_bridged(b, F, S) || (is_variable_function && !is_bridged(b, S))
if !MOI.supports(b.model, attr, IndexType)
return false
end
end
bridge = recursive_model(b)
# If variable bridged, get the indices from the variable bridges.
if is_variable_function && is_bridged(b, S) && is_variable_bridged(b, S)
if !MOI.supports(bridge, attr, Variable.concrete_bridge_type(b, S))
return false
end
end
# If constraint bridged, get the indices from the constraint bridges.
if is_bridged(b, F, S) ||
(is_variable_function && supports_constraint_bridges(b))
if !MOI.supports(bridge, attr, Constraint.concrete_bridge_type(b, F, S))
return false
end
if is_bridged(b, F, S)
bridge = Constraint.concrete_bridge_type(b, F, S)
return MOI.supports(recursive_model(b), attr, bridge)
elseif F == MOI.Utilities.variable_function_type(S) && is_bridged(b, S)
bridge = Variable.concrete_bridge_type(b, S)
return MOI.supports(recursive_model(b), attr, bridge)
else
return MOI.supports(b.model, attr, IndexType)
end
return true
end

function MOI.set(
Expand Down
26 changes: 26 additions & 0 deletions test/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,32 @@ function test_constant_modification_with_affine_variable_bridge()
@test MOI.get(model, obj) new_inner_obj
end

struct _IssueIpopt333 <: MOI.AbstractOptimizer end

function MOI.supports(
::_IssueIpopt333,
::MOI.ConstraintDualStart,
::Type{MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}}},
)
return true
end

function MOI.supports_constraint(
::_IssueIpopt333,
::Type{MOI.VariableIndex},
::Type{MOI.GreaterThan{Float64}},
)
return true
end

function test_IssueIpopt333_supports_ConstraintDualStart_VariableIndex()
model = MOI.Bridges.full_bridge_optimizer(_IssueIpopt333(), Float64)
attr = MOI.ConstraintDualStart()
IndexType = MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}}
@test MOI.supports(model, attr, IndexType)
return
end

end # module

TestBridgeOptimizer.runtests()

0 comments on commit 4d26244

Please sign in to comment.