Skip to content

Commit 4ccc019

Browse files
authored
[Bridges] support debugging variable bridges with AbstractScalarSet (#2107)
1 parent 934fdd1 commit 4ccc019

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/Bridges/debug.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,21 @@ function _print_variable_tree(io, b, S::Type{<:MOI.AbstractVectorSet}, offset)
659659
end
660660
return
661661
end
662+
663+
function _print_variable_tree(io, b, S::Type{<:MOI.AbstractScalarSet}, offset)
664+
if !MOI.Bridges.is_bridged(b, S)
665+
print(io, offset, " * ")
666+
_print_supported(io, "Supported variable: $S\n")
667+
return
668+
end
669+
indices = MOI.get(b, MOI.ListOfConstraintIndices{MOI.VariableIndex,S}())
670+
if length(indices) > 0
671+
@assert MOI.Bridges.is_bridged(b, MOI.VariableIndex, S)
672+
ci = first(indices)
673+
x = MOI.get(b, MOI.ConstraintFunction(), ci)
674+
if haskey(b.variable_map, x)
675+
_print_variable(io, b, S, x, offset)
676+
end
677+
end
678+
return
679+
end

test/Bridges/debug.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,41 @@ function test_print_active_bridges()
133133
return
134134
end
135135

136+
MOI.Utilities.@model(
137+
ParameterModel,
138+
(),
139+
(MOI.EqualTo,),
140+
(),
141+
(),
142+
(),
143+
(MOI.ScalarAffineFunction,),
144+
(),
145+
()
146+
)
147+
148+
function MOI.supports_constraint(
149+
::ParameterModel,
150+
::Type{MOI.VariableIndex},
151+
::Type{<:MOI.Parameter},
152+
)
153+
return false
154+
end
155+
156+
function test_print_active_bridges_parameter()
157+
inner = ParameterModel{Float64}()
158+
model = MOI.Bridges.full_bridge_optimizer(inner, Float64)
159+
p, _ = MOI.add_constrained_variable(model, MOI.Parameter(2.5))
160+
@test sprint(MOI.Bridges.print_active_bridges, model) === """
161+
* Supported objective: MOI.ScalarAffineFunction{Float64}
162+
* Unsupported variable: MOI.Parameter{Float64}
163+
| bridged by:
164+
| MOIB.Variable.ParameterToEqualToBridge{Float64}
165+
| introduces:
166+
| * Supported variable: MOI.EqualTo{Float64}
167+
"""
168+
return
169+
end
170+
136171
end
137172

138173
TestBridgesDebug.runtests()

0 commit comments

Comments
 (0)