Skip to content

[Bridges] fix supports for VariableIndex attributes #1991

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 3 commits into from
Sep 6, 2022
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
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()