From f3ccb6ac4e14df47dff5f8bd37ae3c4c2b29dfe3 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 6 Sep 2022 10:13:18 +1200 Subject: [PATCH 1/3] [Bridges] fix supports for VariableIndex attributes --- src/Bridges/bridge_optimizer.jl | 4 +--- test/Bridges/bridge_optimizer.jl | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index 23b155a402..77fcbc5e4f 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -1352,9 +1352,7 @@ function MOI.supports( # 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 + return MOI.supports(b.model, attr, IndexType) end bridge = recursive_model(b) # If variable bridged, get the indices from the variable bridges. diff --git a/test/Bridges/bridge_optimizer.jl b/test/Bridges/bridge_optimizer.jl index 17e07911d3..227a2c6056 100644 --- a/test/Bridges/bridge_optimizer.jl +++ b/test/Bridges/bridge_optimizer.jl @@ -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() From 8bd66a64e595c6e22a076519f76207bb44b1278f Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 6 Sep 2022 10:44:25 +1200 Subject: [PATCH 2/3] Another fix --- src/Bridges/bridge_optimizer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index 77fcbc5e4f..f1f8a6f631 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -1351,7 +1351,7 @@ function MOI.supports( # 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 !is_bridged(b, F, S) && (is_variable_function && !is_bridged(b, S)) return MOI.supports(b.model, attr, IndexType) end bridge = recursive_model(b) From fb25093252a7500ce2e1cff4ba19dc69b1f23018 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 6 Sep 2022 12:00:45 +1200 Subject: [PATCH 3/3] Simplification --- src/Bridges/bridge_optimizer.jl | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index f1f8a6f631..48e3d19319 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -1347,28 +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 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 - 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 - end - return true end function MOI.set(