-
Notifications
You must be signed in to change notification settings - Fork 94
[Bridges] pass variable names through ParameterToEqualToBridge #2821
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b468ce
[Bridges] pass variable names through ParameterToEqualToBridge
odow ae3fe04
Update
odow 7e3c6b3
Update src/Bridges/bridge_optimizer.jl
odow a248973
Update bridge_optimizer.jl
odow a72cc0c
Update src/Bridges/bridge_optimizer.jl
odow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1757,6 +1757,28 @@ function MOI.get( | |
end | ||
end | ||
|
||
function _get_variable_if_equivalent( | ||
b::AbstractBridgeOptimizer, | ||
x::MOI.VariableIndex, | ||
) | ||
return _get_variable_if_equivalent(bridged_variable_function(b, x), x) | ||
end | ||
|
||
_get_variable_if_equivalent(::AbstractBridgeOptimizer, ::Nothing) = nothing | ||
|
||
function _get_variable_if_equivalent( | ||
f::MOI.ScalarAffineFunction, | ||
x::MOI.VariableIndex, | ||
) | ||
if length(f.terms) == 1 | ||
term = only(f.terms) | ||
if isone(term.coefficient) | ||
return term.variable | ||
end | ||
end | ||
return nothing | ||
end | ||
|
||
function MOI.set( | ||
b::AbstractBridgeOptimizer, | ||
attr::MOI.VariableName, | ||
|
@@ -1766,6 +1788,11 @@ function MOI.set( | |
if is_bridged(b, vi) | ||
b.var_to_name[vi] = name | ||
b.name_to_var = nothing # Invalidate the name map. | ||
# Set the internal variable name iff the bridged variable is equivalent | ||
# to `y := 1 * x`. | ||
if (x = _get_variable_if_equivalent(b, vi)) !== nothing | ||
MOI.set(b.model, attr, x, name) | ||
end | ||
else | ||
MOI.set(b.model, attr, vi, name) | ||
end | ||
|
@@ -1839,6 +1866,9 @@ function MOI.get( | |
end | ||
vi_bridged = get(b.name_to_var, name, nothing) | ||
MOI.Utilities.throw_if_multiple_with_name(vi_bridged, name) | ||
if _get_variable_if_equivalent(b, vi_bridged) !== nothing | ||
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. What is this for ? 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. Maybe add a comment explaining |
||
return vi_bridged | ||
end | ||
return MOI.Utilities.check_type_and_multiple_names( | ||
MOI.VariableIndex, | ||
vi_bridged, | ||
|
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.