-
Notifications
You must be signed in to change notification settings - Fork 98
add_constrained_variable with 2 sets #2574
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 2 commits
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 |
|---|---|---|
|
|
@@ -124,6 +124,65 @@ function add_constrained_variable(model::ModelLike, set::AbstractScalarSet) | |
| return variable, constraint | ||
| end | ||
|
|
||
| """ | ||
| add_constrained_variable( | ||
| model::ModelLike, | ||
| set::Tuple{<:GreaterThan,<:LessThan}, | ||
| ) | ||
|
|
||
| A special-case method to add a scalar variable with a lower and upper bound. | ||
|
|
||
| This method should be implemented by optimizers which have native support for | ||
| adding a variable with bounds and which cannot performantly modify the variable | ||
| bounds after creation. | ||
|
|
||
| ## Example | ||
|
|
||
| ```jldoctest | ||
| julia> import MathOptInterface as MOI | ||
|
|
||
| julia> model = MOI.Utilities.Model{Float64}(); | ||
|
|
||
| julia> set = (MOI.GreaterThan(1.0), MOI.LessThan(2.0)); | ||
|
|
||
| julia> x, (c_l, c_u) = MOI.add_constrained_variable(model, set); | ||
|
|
||
| julia> c_l | ||
| MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.GreaterThan{Float64}}(1) | ||
|
|
||
| julia> c_u | ||
| MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.LessThan{Float64}}(1) | ||
|
|
||
| julia> print(model) | ||
| Feasibility | ||
|
|
||
| Subject to: | ||
|
|
||
| VariableIndex-in-GreaterThan{Float64} | ||
| v[1] >= 1.0 | ||
|
|
||
| VariableIndex-in-LessThan{Float64} | ||
| v[1] <= 2.0 | ||
| ``` | ||
| """ | ||
| function add_constrained_variable( | ||
| model::ModelLike, | ||
| set::Tuple{<:GreaterThan,<:LessThan}, | ||
|
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. @blegat are you okay with this signature?
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 have a small preference for two separate arguments rather than the tuple. But if you both prefer the Tuple, let's do it!
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 feel like the two separate arguments just opens the door too much. This feels more like a "set" composed of a tuple. Rather than a completely new method. It's more logically consistent with the rest of the API. And the output of the constraint index matches the input of the set. Tuple->Tuple.
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 also think restricting to this one special case is a good start. We can always relax later if it turns out to be a good idea. But this is really the only case where we've had the need, and it's been years since we started MOI...
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. Fair enough, lets go for it.
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 continued to think about this all day, and I didn't come up with a reason not to do this.
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.
I agree, otherwise |
||
| ) | ||
| set_1, set_2 = set | ||
| x, c_1 = add_constrained_variable(model, set_1) | ||
| c_2 = add_constraint(model, x, set_2) | ||
| return x, (c_1, c_2) | ||
| end | ||
|
|
||
| function supports_add_constrained_variable( | ||
| model::ModelLike, | ||
| ::Type{Tuple{L,U}}, | ||
| ) where {L<:GreaterThan,U<:LessThan} | ||
| return supports_add_constrained_variable(model, L) && | ||
| supports_constraint(model, VariableIndex, U) | ||
| end | ||
|
|
||
| """ | ||
| supports_add_constrained_variables( | ||
| model::ModelLike, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.