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
RFC: modifications #1351
RFC: modifications #1351
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1351 +/- ##
=========================================
+ Coverage 89.47% 89.6% +0.12%
=========================================
Files 27 27
Lines 3621 3790 +169
=========================================
+ Hits 3240 3396 +156
- Misses 381 394 +13
Continue to review full report at Codecov.
|
examples/basic.jl
Outdated
const MOI = MathOptInterface | ||
function setrhs(c, rhs) | ||
moi = c.m.moibackend | ||
MOI.set!(moi, MOI.ConstraintSet(), c.index, MOI.set_type(c.index)(rhs)) |
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 is cleaner to do index(c)
rather than c.index
Looks like the correct way to me :)
I'd say we define a
It would probably be simpler if we always stored the constant in the function for
By the way if we didn't have |
examples/basic.jl
Outdated
const MOI = MathOptInterface | ||
function setrhs(c, rhs) | ||
moi = c.m.moibackend | ||
MOI.set!(moi, MOI.ConstraintSet(), c.index, MOI.set_type(c.index)(rhs)) |
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.
The JuMP call should look at least like:
MOI.set!(m, MOI.ConstraintSet(), c, MOI.LessThan(rhs))
Users shouldn't need to extract the moibackend or the MOI index (even though it's easy).
examples/basic.jl
Outdated
const MOI = MathOptInterface | ||
function setrhs(c, rhs) | ||
moi = c.m.moibackend | ||
MOI.set!(moi, MOI.ConstraintSet(), c.index, MOI.set_type(c.index)(rhs)) |
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.
MOI.set_type(c.index)(rhs)
is confusing for an example. Just use a concrete type.
80584e1
to
26acb04
Compare
Oops. I managed to drop the old commit instead of reverting it. It was totally superseded by this anyway. |
I need this so I can go around changing right-hand sides and coefficients in the constraint matrix. I'm not sure what the best approach is. We either provide JuMP-specific functions (as done here), or somehow make the MOI modification layer accessible. |
src/constraints.jl
Outdated
Note that prior to this step, JuMP will move all variable terms onto the | ||
left-hand side, and all constant terms onto the right-hand side. For example, | ||
given a constraint `2x + 1 <= 2`, `JuMP.set_constant(c, 3)` will create the | ||
constraint `2x <= 3`, not `2x + 1 <= 3`. |
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.
This ambiguity could be resolved by providing add_to_rhs
instead of set_rhs
. What do you think?
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 seems safer to define add_constant
which is mathematically defined as adding a constant in the function side but which adds the opposite value in the rhs for scalar constraint.
set_rhs
is ambiguous for Interval and does not work for vector constraints.
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.
Revisiting #470 Maybe the simplest thing is to add an extra variable and then use JuMP.fix(x, value)
. It is a whole lot cleaner with less issues. In which case, this is just a documentation issue.
The issue with add_to_rhs
is that it makes sense, but how many people would actually use 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.
If you're not excited about add_to_rhs
we can drop RHS modifications from this PR. set_coefficient
looks fine.
src/constraints.jl
Outdated
|
||
Note that prior to this step, JuMP will move all variable terms onto the | ||
left-hand side, and all constant terms onto the right-hand side. For example, | ||
given a constraint `2x + 1 <= 2`, `JuMP.set_constant(c, 3)` will create the |
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.
Is is called set_constant
or set_rhs
?
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.
Oops, I changed back and forth a few times and missed this one.
src/constraints.jl
Outdated
Note that prior to this step, JuMP will move all variable terms onto the | ||
left-hand side, and all constant terms onto the right-hand side. For example, | ||
given a constraint `2x + 1 <= 2`, `JuMP.set_constant(c, 3)` will create the | ||
constraint `2x <= 3`, not `2x + 1 <= 3`. |
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 you're not excited about add_to_rhs
we can drop RHS modifications from this PR. set_coefficient
looks fine.
src/constraints.jl
Outdated
`JuMP.set_coefficient(c, x, 4)` will create the constraint `4x <= 2`. | ||
|
||
|
||
```jldoctest |
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.
Could you drop set_coefficient
somewhere in the docs so that the doctest gets run?
I have updated this to the new JuMP syntax.
TODO
We discussed having a proof of concept for JuMP-dev of constraint modification.Is this the right way to do it? I haven't delved into the new JuMP code at all so have no idea if this is the "correct" way to implement it or where it should live etc.
At the very least, it works!*
*Requires my PRs to LQOI, GLPK and MOI