Skip to content

Commit 042167d

Browse files
authored
Refactor Bridges debug (#1151)
1 parent 67dd9dd commit 042167d

3 files changed

Lines changed: 179 additions & 174 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ os:
66
# - osx
77
julia:
88
- 1.0
9-
- 1.4
9+
- 1
1010
notifications:
1111
email: false
1212
git:

src/Bridges/debug.jl

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ function print_node(io::IO, b::LazyBridgeOptimizer, node::ObjectiveNode)
1010
F, = b.objective_types[node.index]
1111
MOIU.print_with_acronym(io, "|$(node.index)| objective function of type `$F` is")
1212
end
13-
function print_node_info(io::IO, b::LazyBridgeOptimizer, node::AbstractNode)
13+
function print_node_info(
14+
io::IO, b::LazyBridgeOptimizer, node::AbstractNode;
15+
debug_unsupported = false
16+
)
1417
print(io, " ")
1518
print_node(io, b, node)
1619
d = _dist(b.graph, node)
1720
if d == INFINITY
18-
print(io, " not supported\n")
21+
print(io, " not supported")
22+
if debug_unsupported
23+
print(io, " because")
24+
print_unsupported(io, b, node)
25+
else
26+
println(io)
27+
end
1928
else
2029
index = bridge_index(b.graph, node)
2130
if iszero(index) || (node isa VariableNode && !is_variable_edge_best(b.graph, node))
@@ -28,44 +37,47 @@ function print_node_info(io::IO, b::LazyBridgeOptimizer, node::AbstractNode)
2837
end
2938
end
3039
end
31-
print_graph(b::LazyBridgeOptimizer) = print_graph(Base.stdout, b)
32-
function print_graph(io::IO, b::LazyBridgeOptimizer)
40+
print_graph(b::LazyBridgeOptimizer; kws...) = print_graph(Base.stdout, b; kws...)
41+
function print_graph(io::IO, b::LazyBridgeOptimizer; kws...)
3342
println(io, b.graph)
34-
for node in variable_nodes(b.graph)
35-
print_node_info(io, b, node)
43+
print_nodes(io, b, variable_nodes(b.graph), constraint_nodes(b.graph), objective_nodes(b.graph); kws...)
44+
end
45+
function print_nodes(io::IO, b::LazyBridgeOptimizer, variable_nodes, constraint_nodes, objective_nodes; kws...)
46+
for node in variable_nodes
47+
print_node_info(io, b, node; kws...)
3648
end
37-
for node in constraint_nodes(b.graph)
38-
print_node_info(io, b, node)
49+
for node in constraint_nodes
50+
print_node_info(io, b, node; kws...)
3951
end
40-
for node in objective_nodes(b.graph)
41-
print_node_info(io, b, node)
52+
for node in objective_nodes
53+
print_node_info(io, b, node; kws...)
4254
end
4355
end
4456

45-
function print_unsupported(io::IO, b::LazyBridgeOptimizer, node::AbstractNode)
57+
function print_if_unsupported(io::IO, b::LazyBridgeOptimizer, node::AbstractNode)
4658
if _dist(b.graph, node) != INFINITY
4759
return
4860
end
49-
print(io, " ")
61+
print(io, " ")
5062
print_node(io, b, node)
5163
print(io, " not supported\n")
5264
end
5365
function print_unsupported(io::IO, b::LazyBridgeOptimizer, edge::Edge)
5466
for node in edge.added_variables
55-
print_unsupported(io, b, node)
67+
print_if_unsupported(io, b, node)
5668
end
5769
for node in edge.added_constraints
58-
print_unsupported(io, b, node)
70+
print_if_unsupported(io, b, node)
5971
end
6072
end
6173
function print_unsupported(io::IO, b::LazyBridgeOptimizer, edge::ObjectiveEdge)
6274
for node in edge.added_variables
63-
print_unsupported(io, b, node)
75+
print_if_unsupported(io, b, node)
6476
end
6577
for node in edge.added_constraints
66-
print_unsupported(io, b, node)
78+
print_if_unsupported(io, b, node)
6779
end
68-
print_unsupported(io, b, edge.added_objective)
80+
print_if_unsupported(io, b, edge.added_objective)
6981
end
7082
function print_unsupported(io::IO, b::LazyBridgeOptimizer, edges::Vector, index_to_bridge::Function)
7183
no_bridge = true
@@ -74,7 +86,7 @@ function print_unsupported(io::IO, b::LazyBridgeOptimizer, edges::Vector, index_
7486
println(io, ":")
7587
no_bridge = false
7688
end
77-
MOIU.print_with_acronym(io, " Cannot use `$(index_to_bridge(edge.bridge_index))` because:\n")
89+
MOIU.print_with_acronym(io, " Cannot use `$(index_to_bridge(edge.bridge_index))` because:\n")
7890
print_unsupported(io, b, edge)
7991
end
8092
if no_bridge
@@ -90,34 +102,26 @@ end
90102
function _bridge_type(b::LazyBridgeOptimizer, node::ObjectiveNode, bridge_index::Int)
91103
return Objective.concrete_bridge_type(b.objective_bridge_types[bridge_index], b.objective_types[node.index]...)
92104
end
93-
function print_unsupported(io::IO, b::LazyBridgeOptimizer, variables, constraints, objectives)
94-
for node in variables
95-
print_node(io, b, node)
96-
print(io, " not supported because")
97-
print_unsupported(io, b, b.graph.variable_edges[node.index],
98-
bridge_index -> _bridge_type(b, node, bridge_index))
99-
print(io, " Cannot add free variables and then constrain them because")
100-
constraint_node = b.graph.variable_constraint_node[node.index]
101-
if constraint_node.index == -1
102-
println(io, " free variables are bridged but no functionize bridge was added.")
103-
else
104-
println(io, ":")
105-
print_unsupported(io, b, constraint_node)
106-
end
107-
end
108-
for node in constraints
109-
print_node(io, b, node)
110-
print(io, " not supported because")
111-
print_unsupported(io, b, b.graph.constraint_edges[node.index],
112-
bridge_index -> _bridge_type(b, node, bridge_index))
113-
end
114-
for node in objectives
115-
print_node(io, b, node)
116-
print(io, " not supported because")
117-
print_unsupported(io, b, b.graph.objective_edges[node.index],
118-
bridge_index -> _bridge_type(b, node, bridge_index))
105+
function print_unsupported(io::IO, b::LazyBridgeOptimizer, node::VariableNode)
106+
print_unsupported(io, b, b.graph.variable_edges[node.index],
107+
bridge_index -> _bridge_type(b, node, bridge_index))
108+
print(io, " Cannot add free variables and then constrain them because")
109+
constraint_node = b.graph.variable_constraint_node[node.index]
110+
if constraint_node.index == -1
111+
println(io, " free variables are bridged but no functionize bridge was added.")
112+
else
113+
println(io, ":")
114+
print_if_unsupported(io, b, constraint_node)
119115
end
120116
end
117+
function print_unsupported(io::IO, b::LazyBridgeOptimizer, node::ConstraintNode)
118+
print_unsupported(io, b, b.graph.constraint_edges[node.index],
119+
bridge_index -> _bridge_type(b, node, bridge_index))
120+
end
121+
function print_unsupported(io::IO, b::LazyBridgeOptimizer, node::ObjectiveNode)
122+
print_unsupported(io, b, b.graph.objective_edges[node.index],
123+
bridge_index -> _bridge_type(b, node, bridge_index))
124+
end
121125

122126
function add_unsupported(graph::Graph, edges::Vector{Edge},
123127
variables, constraints, objectives)
@@ -180,7 +184,8 @@ function debug_unsupported(io::IO, b::LazyBridgeOptimizer, node::AbstractNode)
180184
constraints = Set{ConstraintNode}()
181185
objectives = Set{ObjectiveNode}()
182186
add_unsupported(b.graph, node, variables, constraints, objectives)
183-
print_unsupported(io, b, _sort(variables), _sort(constraints), _sort(objectives))
187+
print_nodes(io, b, _sort(variables), _sort(constraints), _sort(objectives),
188+
debug_unsupported = true)
184189
end
185190

186191
const UNSUPPORTED_MESSAGE = " are not supported and cannot be bridged into supported" *

0 commit comments

Comments
 (0)