Skip to content

Commit e7285da

Browse files
committed
Use placeholder in needs_final_touch
1 parent f6f7974 commit e7285da

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/Bridges/bridge_optimizer.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,17 +1965,15 @@ function add_bridged_constraint(b, BridgeType, f, s)
19651965
# Okay, this part is a bit tricky. `Constraint.bridge_constraint` might add
19661966
# new constraints which also need `final_touch`. But we need the return
19671967
# value `bridge` to come _before_ them in the `needs_final_touch` vector.
1968-
# To make this happen, we remember how many bridges are already in the
1969-
# vector, and then we insert the bridge into the vector. This is an O(N)
1970-
# operation in the number of new bridges, but it's a pretty rare edge-case,
1971-
# and the number of new bridges should be small. (And most of the time, N=0,
1972-
# because most bridges that need final touch don't add any bridges that
1973-
# themselves need final touch. Good examples are the ToMILP bridges that
1974-
# need variable bounds.)
1975-
n_final_touch = length(map.needs_final_touch)
1968+
# To make this happen, we insert a placeholder before calling
1969+
# `bridge_constraint` and we replace it by the bridge afterwards.
1970+
if MOI.Bridges.needs_final_touch(bridge)
1971+
push!(map.needs_final_touch, nothing)
1972+
final_touch_idx = length(map.needs_final_touch)
1973+
end
19761974
bridge = Constraint.bridge_constraint(BridgeType, recursive_model(b), f, s)
19771975
if MOI.Bridges.needs_final_touch(bridge)
1978-
insert!(map.needs_final_touch, n_final_touch + 1, bridge)
1976+
map.needs_final_touch[final_touch_idx] = bridge
19791977
end
19801978
# `MOI.VectorOfVariables` constraint indices have negative indices
19811979
# to distinguish between the indices of the inner model.

0 commit comments

Comments
 (0)