Skip to content

Commit 8662e97

Browse files
authored
[Bridges] Fix ListOfVariablesWithAttributeSet (#2380)
1 parent ede6d1c commit 8662e97

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/Bridges/bridge_optimizer.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,22 @@ function MOI.get(
894894
return unbridged_function(b, MOI.get(b.model, attr))
895895
end
896896

897+
function MOI.get(
898+
b::AbstractBridgeOptimizer,
899+
attr::MOI.ListOfVariablesWithAttributeSet,
900+
)
901+
if Variable.has_bridges(Variable.bridges(b))
902+
# If there are variable bridges, `MOI.get(b.model, attr)`
903+
# will return a list containing solver variables that do not
904+
# correspond to any user variables.
905+
# We choose the easy option of simply returning all variables
906+
# for now.
907+
return MOI.get(b, MOI.ListOfVariableIndices())
908+
else
909+
return unbridged_function(b, MOI.get(b.model, attr))
910+
end
911+
end
912+
897913
function MOI.get(
898914
b::AbstractBridgeOptimizer,
899915
attr::MOI.ListOfConstraintsWithAttributeSet{F,S,MOI.ConstraintName},

test/Bridges/bridge_optimizer.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,24 @@ function test_variable_bridge_constraint_attribute()
11581158
return
11591159
end
11601160

1161+
function test_ListOfVariablesWithAttributeSet(T = Float64)
1162+
uf = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}())
1163+
model = MOI.Bridges.full_bridge_optimizer(uf, T)
1164+
x = MOI.add_variables(model, 2)
1165+
MOI.set(model, MOI.VariableName(), x[1], "x")
1166+
# Passed through to Model with no special support
1167+
attr = MOI.ListOfVariablesWithAttributeSet(MOI.VariableName())
1168+
@test MOI.get(model, attr) == x
1169+
# Handled by UniversalFallback
1170+
attr = MOI.ListOfVariablesWithAttributeSet(MOI.VariablePrimalStart())
1171+
# ... no attributes set
1172+
@test MOI.get(model, attr) == MOI.VariableIndex[]
1173+
# ... one attribute set
1174+
MOI.set(model, MOI.VariablePrimalStart(), x[2], 1.0)
1175+
@test MOI.get(model, attr) == [x[2]]
1176+
return
1177+
end
1178+
11611179
end # module
11621180

11631181
TestBridgeOptimizer.runtests()

test/Bridges/lazy_bridge_optimizer.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,6 @@ function test_MOI_runtests_StandardSDPAModel()
328328
# fix would require that a bridge optimizer has a try-catch for this
329329
# error.
330330
"test_model_ScalarFunctionConstantNotZero",
331-
# The error is:
332-
# Cannot substitute `MOI.VariableIndex(1)` as it is bridged into `0.0 + 1.0 MOI.VariableIndex(-1)`.
333-
# This seems okay. We can't get a list of variables if they are
334-
# bridged.
335-
"test_model_ListOfVariablesWithAttributeSet",
336331
],
337332
)
338333
return

0 commit comments

Comments
 (0)