Skip to content
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
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