-
Notifications
You must be signed in to change notification settings - Fork 101
[Bridges] fix support for nested final_touch bridges #3027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1961,14 +1961,27 @@ function MOI.supports_constraint( | |
| end | ||
|
|
||
| function add_bridged_constraint(b, BridgeType, f, s) | ||
| map = Constraint.bridges(b)::Constraint.Map | ||
| # Okay, this part is a bit tricky. `Constraint.bridge_constraint` might add | ||
| # new constraints which also need `final_touch`. But we need the return | ||
| # value `bridge` to come _before_ them in the `needs_final_touch` vector. | ||
| # To make this happen, we remember how many bridges are already in the | ||
| # vector, and then we insert the bridge into the vector. This is an O(N) | ||
| # operation in the number of new bridges, but it's a pretty rare edge-case, | ||
| # and the number of new bridges should be small. (And in most common bridges | ||
| # that need final touch, like the ToMILP bridges, N=0.) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don’t add any bridges that themselves need final touch |
||
| n_final_touch = length(map.needs_final_touch) | ||
| bridge = Constraint.bridge_constraint(BridgeType, recursive_model(b), f, s) | ||
| if MOI.Bridges.needs_final_touch(bridge) | ||
| insert!(map.needs_final_touch, n_final_touch + 1, bridge) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer doing these things in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to make a PR with some changes. This seemed simplest place to put it for me but I might be missing something. |
||
| end | ||
| # `MOI.VectorOfVariables` constraint indices have negative indices | ||
| # to distinguish between the indices of the inner model. | ||
| # However, they can clash between the indices created by the variable | ||
| # so we use the last argument to inform the constraint bridge mapping about | ||
| # indices already taken by variable bridges. | ||
| ci = Constraint.add_key_for_bridge( | ||
| Constraint.bridges(b)::Constraint.Map, | ||
| map, | ||
| bridge, | ||
| f, | ||
| s, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's a
Vector{Any, can't we just dopush!(map.needs_final_touch, nothing)here and then replace it ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we might not need to