diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index 1405be62ac..6052b9f5e2 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -894,6 +894,22 @@ function MOI.get( return unbridged_function(b, MOI.get(b.model, attr)) end +function MOI.get( + b::AbstractBridgeOptimizer, + attr::MOI.ListOfVariablesWithAttributeSet, +) + if Variable.has_bridges(Variable.bridges(b)) + # If there are variable bridges, `MOI.get(b.model, attr)` + # will return a list containing solver variables that do not + # correspond to any user variables. + # We choose the easy option of simply returning all variables + # for now. + return MOI.get(b, MOI.ListOfVariableIndices()) + else + return unbridged_function(b, MOI.get(b.model, attr)) + end +end + function MOI.get( b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraintsWithAttributeSet{F,S,MOI.ConstraintName}, diff --git a/test/Bridges/bridge_optimizer.jl b/test/Bridges/bridge_optimizer.jl index daf11fffe3..3b1548a018 100644 --- a/test/Bridges/bridge_optimizer.jl +++ b/test/Bridges/bridge_optimizer.jl @@ -1158,6 +1158,24 @@ function test_variable_bridge_constraint_attribute() return end +function test_ListOfVariablesWithAttributeSet(T = Float64) + uf = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}()) + model = MOI.Bridges.full_bridge_optimizer(uf, T) + x = MOI.add_variables(model, 2) + MOI.set(model, MOI.VariableName(), x[1], "x") + # Passed through to Model with no special support + attr = MOI.ListOfVariablesWithAttributeSet(MOI.VariableName()) + @test MOI.get(model, attr) == x + # Handled by UniversalFallback + attr = MOI.ListOfVariablesWithAttributeSet(MOI.VariablePrimalStart()) + # ... no attributes set + @test MOI.get(model, attr) == MOI.VariableIndex[] + # ... one attribute set + MOI.set(model, MOI.VariablePrimalStart(), x[2], 1.0) + @test MOI.get(model, attr) == [x[2]] + return +end + end # module TestBridgeOptimizer.runtests() diff --git a/test/Bridges/lazy_bridge_optimizer.jl b/test/Bridges/lazy_bridge_optimizer.jl index 9f68c34d7f..d4e72b45e7 100644 --- a/test/Bridges/lazy_bridge_optimizer.jl +++ b/test/Bridges/lazy_bridge_optimizer.jl @@ -328,11 +328,6 @@ function test_MOI_runtests_StandardSDPAModel() # fix would require that a bridge optimizer has a try-catch for this # error. "test_model_ScalarFunctionConstantNotZero", - # The error is: - # Cannot substitute `MOI.VariableIndex(1)` as it is bridged into `0.0 + 1.0 MOI.VariableIndex(-1)`. - # This seems okay. We can't get a list of variables if they are - # bridged. - "test_model_ListOfVariablesWithAttributeSet", ], ) return