-
Notifications
You must be signed in to change notification settings - Fork 97
[Bridges] add final_touch #1901
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
23578ac
Add final_touch for bridges
blegat ae76bc2
Fix
blegat e0b0a80
Style fixes
odow 0af6d10
Update reference.md
odow cb31388
Update bridge.jl
odow 4638842
Fix docs
odow 9eb7ae2
Fix semi_to_binary bridge
odow b1989e5
[Bridges] add CountDistinctToMILPBridge
odow 843afdc
Fix delete
odow d58e1b2
Fix upper bound on n
odow 0768638
Fix
odow cd74efc
[Bridges] add AllDifferentToCountDistinctBridge
odow 1a83d1f
Update CSP bridges to support affine functions
odow 6bec4ce
Fix Aqua
odow f0396d7
Fix test_cpsat_AllDifferent
odow fa4d12c
Fix null-solution in CountDistinctToMILPBridge
odow 2e59784
Fix tests
odow 8f788b7
Add to docs
odow 1d8ee78
Fix docstrings of bridges
odow c50be14
Switch to Bridges.final_touch
odow fd01b86
Remove AllDifferentToCountDistinctBridge
odow 3f984de
Simplify _get_bounds
odow 90f0902
Revert semi_to_binary
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
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
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 |
|---|---|---|
|
|
@@ -75,6 +75,19 @@ function bridge_constraint( | |
| f::MOI.VariableIndex, | ||
| s::S, | ||
| ) where {T<:Real,S<:Union{MOI.Semicontinuous{T},MOI.Semiinteger{T}}} | ||
| F = MOI.VariableIndex | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.GreaterThan{T}}(f.value)) | ||
| throw(MOI.LowerBoundAlreadySet{MOI.GreaterThan{T},S}(f)) | ||
| end | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.LessThan{T}}(f.value)) | ||
| throw(MOI.UpperBoundAlreadySet{MOI.LessThan{T},S}(f)) | ||
| end | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.EqualTo{T}}(f.value)) | ||
| throw(MOI.LowerBoundAlreadySet{MOI.EqualTo{T},S}(f)) | ||
| end | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.Interval{T}}(f.value)) | ||
| throw(MOI.LowerBoundAlreadySet{MOI.Interval{T},S}(f)) | ||
| end | ||
| binary, binary_con = MOI.add_constrained_variable(model, MOI.ZeroOne()) | ||
| # var - LB * bin >= 0 | ||
| lb = MOI.Utilities.operate(*, T, -s.lower, binary) | ||
|
|
@@ -327,3 +340,25 @@ function MOI.get( | |
| ) where {T,S} | ||
| return [b.lower_bound_index] | ||
| end | ||
|
|
||
| MOI.Bridges.needs_final_touch(b::SemiToBinaryBridge) = true | ||
|
|
||
| function MOI.Utilities.final_touch( | ||
| b::SemiToBinaryBridge{T,S}, | ||
| model::MOI.ModelLike, | ||
| ) where {T,S} | ||
| F, f = MOI.VariableIndex, b.variable | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.GreaterThan{T}}(f.value)) | ||
| throw(MOI.LowerBoundAlreadySet{S,MOI.GreaterThan{T}}(f)) | ||
|
||
| end | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.LessThan{T}}(f.value)) | ||
| throw(MOI.UpperBoundAlreadySet{S,MOI.LessThan{T}}(f)) | ||
| end | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.EqualTo{T}}(f.value)) | ||
| throw(MOI.LowerBoundAlreadySet{S,MOI.EqualTo{T}}(f)) | ||
| end | ||
| if MOI.is_valid(model, MOI.ConstraintIndex{F,MOI.Interval{T}}(f.value)) | ||
| throw(MOI.LowerBoundAlreadySet{S,MOI.Interval{T}}(f)) | ||
| end | ||
| return | ||
| end | ||
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
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
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
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
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.
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.
If I understand correctly, this is because
Semicontinuoussets bounds so it should be incompatible with existing bounds. In fact, if these bounds are removed beforeoptimize!we shouldn't throw so we should really usefinal_touchhere too. I guess it's another argument for removing these errors as suggested in #1879 (comment)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.
Maybe put that in another PR if it's not needed to pass the tests so that we can merge the rest
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.
It's going to be a nightmare now that bridges mess up with bounds if we keep this
MOI.LowerBoundAlreadySeterrors. The fact that bridges can modify these bounds due to the fact that the constraint indices can be inferred from the variable indices is another arguments that these can be muted from everywhere.