Skip to content

Commit 9ed00ed

Browse files
authored
[Bridges] fix bug in print_active_bridges (#2135)
1 parent 72dbc0a commit 9ed00ed

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

src/Bridges/debug.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -721,15 +721,25 @@ function print_active_bridges(
721721
_print_supported(io, "Supported variable: $S\n")
722722
return
723723
end
724-
index = MOI.Bridges.bridge_index(b.graph, b.variable_node[(S,)])
725-
B = b.variable_bridge_types[index]
726-
BT = MOI.Bridges.Variable.concrete_bridge_type(B, S)
727-
print(io, offset, " * ")
728-
_print_unsupported(io, "Unsupported variable: $S\n")
729-
println(io, offset, " | bridged by:")
730-
print(io, offset, " | ")
731-
MOI.Utilities.print_with_acronym(io, "$BT\n")
732-
println(io, offset, " | may introduce:")
733-
_print_bridge(io, b, BT, offset)
724+
if MOI.Bridges.is_variable_edge_best(b.graph, b.variable_node[(S,)])
725+
index = MOI.Bridges.bridge_index(b.graph, b.variable_node[(S,)])
726+
B = b.variable_bridge_types[index]
727+
BT = MOI.Bridges.Variable.concrete_bridge_type(B, S)
728+
print(io, offset, " * ")
729+
_print_unsupported(io, "Unsupported variable: $S\n")
730+
println(io, offset, " | bridged by:")
731+
print(io, offset, " | ")
732+
MOI.Utilities.print_with_acronym(io, "$BT\n")
733+
println(io, offset, " | may introduce:")
734+
_print_bridge(io, b, BT, offset)
735+
else
736+
print(io, offset, " * ")
737+
_print_unsupported(io, "Unsupported variable: $S\n")
738+
println(io, offset, " | adding as constraint:")
739+
offset = offset * " | "
740+
MOI.Bridges.print_active_bridges(io, b, MOI.Reals, offset)
741+
F = MOI.Utilities.variable_function_type(S)
742+
MOI.Bridges.print_active_bridges(io, b, F, S, offset)
743+
end
734744
return
735745
end

test/Bridges/debug.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,43 @@ function test_print_active_bridges_variable_unsupported()
277277
return
278278
end
279279

280+
MOI.Utilities.@model(
281+
ConstraintModel,
282+
(MOI.ZeroOne, MOI.Integer),
283+
(MOI.GreaterThan, MOI.LessThan, MOI.EqualTo),
284+
(),
285+
(),
286+
(),
287+
(MOI.ScalarAffineFunction,),
288+
(),
289+
()
290+
)
291+
292+
function test_print_active_bridges_variable_bridged_with_constraint()
293+
model =
294+
MOI.Bridges.full_bridge_optimizer(ConstraintModel{Float64}(), Float64)
295+
content = """
296+
* Unsupported variable: MOI.AllDifferent
297+
| adding as constraint:
298+
| * Supported variable: MOI.Reals
299+
| * Unsupported constraint: MOI.VectorOfVariables-in-MOI.AllDifferent
300+
| | bridged by:
301+
| | MOIB.Constraint.AllDifferentToCountDistinctBridge{Float64, MOI.VectorOfVariables}
302+
| | may introduce:
303+
| | * Unsupported constraint: MOI.VectorOfVariables-in-MOI.CountDistinct
304+
| | | bridged by:
305+
| | | MOIB.Constraint.CountDistinctToMILPBridge{Float64, MOI.VectorOfVariables}
306+
| | | may introduce:
307+
| | | * Supported constraint: MOI.ScalarAffineFunction{Float64}-in-MOI.EqualTo{Float64}
308+
| | | * Supported constraint: MOI.ScalarAffineFunction{Float64}-in-MOI.LessThan{Float64}
309+
| | | * Supported variable: MOI.ZeroOne
310+
| | * Supported variable: MOI.EqualTo{Float64}
311+
"""
312+
S = MOI.AllDifferent
313+
@test sprint(MOI.Bridges.print_active_bridges, model, S) === content
314+
return
315+
end
316+
280317
end
281318

282319
TestBridgesDebug.runtests()

0 commit comments

Comments
 (0)