Skip to content

Commit

Permalink
[Bridges] Fix ListOfVariablesWithAttributeSet (#2380)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Dec 29, 2023
1 parent ede6d1c commit 8662e97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
18 changes: 18 additions & 0 deletions test/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 0 additions & 5 deletions test/Bridges/lazy_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8662e97

Please sign in to comment.