@@ -269,29 +269,26 @@ function node(
269269 if iszero (inner_cost)
270270 return VariableNode (0 )
271271 end
272- # The inner model supports `S` but with a non-zero bridging cost.
273- # Create a leaf node whose distance is `inner_cost` so that bridges
274- # that emit constrained variables in `S` account for it.
275- cached = get (b. variable_node, (S,), nothing )
276- if cached != = nothing
277- return cached
278- end
279- new_node = add_node (b. graph, VariableNode)
280- b. variable_node[(S,)] = new_node
281- push! (b. variable_types, (S,))
282- b. graph. variable_dist[new_node. index] = inner_cost
283- return new_node
272+ else
273+ inner_cost = nothing
284274 end
285275 # If (S,) is stored in .variable_node, we've already added the node
286276 # previously.
287277 variable_node = get (b. variable_node, (S,), nothing )
288278 if variable_node != = nothing
279+ # The inner model supports `S` but with a non-zero bridging cost.
280+ # Create a leaf node whose distance is `inner_cost` so that bridges
281+ # that emit constrained variables in `S` account for it.
289282 return variable_node
290283 end
291284 # This is a new (S,). We need to add it to the graph.
292285 variable_node = add_node (b. graph, VariableNode)
293286 b. variable_node[(S,)] = variable_node
294287 push! (b. variable_types, (S,))
288+ if ! isnothing (inner_cost)
289+ b. graph. variable_dist[variable_node. index] = inner_cost
290+ return variable_node
291+ end
295292 F = MOI. Utilities. variable_function_type (S)
296293 if is_bridged (b, MOI. Reals)
297294 # The solver doesn't support adding free variables.
@@ -341,18 +338,8 @@ function node(
341338 if iszero (inner_cost)
342339 return ConstraintNode (0 )
343340 end
344- # The inner model supports `F`-in-`S` but with a non-zero bridging cost.
345- # Create a leaf node whose distance is `inner_cost` so that bridges
346- # that emit `F`-in-`S` constraints account for it.
347- cached = get (b. constraint_node, (F, S), nothing )
348- if cached != = nothing
349- return cached
350- end
351- new_node = add_node (b. graph, ConstraintNode)
352- b. constraint_node[(F, S)] = new_node
353- push! (b. constraint_types, (F, S))
354- b. graph. constraint_dist[new_node. index] = inner_cost
355- return new_node
341+ else
342+ inner_cost = nothing
356343 end
357344 # If (F, S) is stored in .constraint_node, we've already added the node
358345 # previously.
@@ -364,6 +351,13 @@ function node(
364351 constraint_node = add_node (b. graph, ConstraintNode)
365352 b. constraint_node[(F, S)] = constraint_node
366353 push! (b. constraint_types, (F, S))
354+ if ! isnothing (inner_cost)
355+ # The inner model supports `F`-in-`S` but with a non-zero bridging cost.
356+ # Create a leaf node whose distance is `inner_cost` so that bridges
357+ # that emit `F`-in-`S` constraints account for it.
358+ b. graph. constraint_dist[constraint_node. index] = inner_cost
359+ return constraint_node
360+ end
367361 for (i, BT) in enumerate (b. constraint_bridge_types)
368362 if MOI. supports_constraint (BT, F, S)
369363 edge = _edge (b, i, Constraint. concrete_bridge_type (BT, F, S)):: Edge
0 commit comments