[Bridges] Remove the need of negative indices#3010
Draft
blegat wants to merge 3 commits into
Draft
Conversation
Introduce MOI.Bridges.reserve_variable_index(model) and reserve_constraint_index(model, F, S) so that bridge layers can allocate identities that don't collide with the inner model's namespace. The default reserve_variable_index adds a variable and immediately deletes it. The default reserve_constraint_index adds a dummy F-in-S constraint (building zero/empty function and a default S instance) and deletes it. For VariableIndex/VectorOfVariables constraints, dummy variables are also cleaned up. MOI models don't recycle deleted indices, so the returned index is guaranteed unique in the inner namespace. AbstractBridgeOptimizer cascades both calls down to b.model, so reservation propagates all the way to the leaf model. This is the foundation for stacking SingleBridgeOptimizers without a caching layer in between. No existing behavior is changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bridges use negative indices to distinguish some bridged constraints from the ones of the inner model. This prevents bridges to be stacked directly without a CachingOptimizer in between which is annoying when using
SingleBridgeOptimizerand complicates a lot #2986 (comment).Looking at it again, negative indices are only needed when variable bridges are used. For constraint-bridges, all constraints of the same types are either all bridged or not so there is no risk of clash between constraint indices.
With variable bridges, you may have clashes with the indices of the bridged variables with the ones of the inner model. Another example is in case the user creates a
VectorOfVariables-in-Sconstraints where one of the variable is bridged. After substitution, this becomes aVectorAffineFunction-in-Sso we need to bridge it with a functionize bridge so we need to create aVectorOfVariables-in-Sconstraint even if the user may support constraint of this type so that can cause clashes as well.We used to create negative indices for this but this PR takes a different approach.
The idea of Claude is to create a variable in the inner model and then delete it. I am not such a big fan though, maybe we should just have different index spaces for the inner and outer models completely.