Skip to content
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

Merged
merged 3 commits into from Oct 15, 2018
Merged

RFC: modifications #1351

merged 3 commits into from Oct 15, 2018

Conversation

odow
Copy link
Member

@odow odow commented Jun 19, 2018

I have updated this to the new JuMP syntax.

TODO

  • docs

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

@codecov
Copy link

codecov bot commented Jun 19, 2018

Codecov Report

Merging #1351 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/constraints.jl 95.12% <100%> (+0.25%) ⬆️
src/macros.jl 88.38% <0%> (+1.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 906e982...0532ed9. Read the comment docs.

const MOI = MathOptInterface
function setrhs(c, rhs)
moi = c.m.moibackend
MOI.set!(moi, MOI.ConstraintSet(), c.index, MOI.set_type(c.index)(rhs))
Copy link
Member

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

@blegat
Copy link
Member

blegat commented Jun 19, 2018

have no idea if this is the "correct" way to implement it

Looks like the correct way to me :)

where it should live

I'd say we define a setconstant function in JuMP.

  • For ScalarAffineFunction-in-* and VectorAffineFunction-in-*, it modifies the constant of the function
  • For *-in-GreaterThan, *-in-LessThan and *-in-EqualTo, it modifies the constant in the set
  • For ScalarAffineFunction-in-GreaterThan, ... there is an ambiguity which needs to be resolved by modifying the constant in the set.

It would probably be simpler if we always stored the constant in the function for GreaterThan, .. sets except for SingleVariable, that way we would have had the simpler rule

  • For ScalarAffineFunction-in-* and VectorAffineFunction-in-*, it modifies the constant of the function
  • For SingleVariable-in-GreaterThan, SingleVariable-in-LessThan and SingleVariable-in-EqualTo, it modifies the constant in the set

By the way if we didn't have SingleVariable we wouldn't have needed a field in these sets and could have simply defined GreaterThanZero, ...
I am not suggesting to remove SingleVariable but simply wondering if we shouldn't have always stored the constant in the function when the function supports constants and when the function does not support it, it should be stored in the set.

const MOI = MathOptInterface
function setrhs(c, rhs)
moi = c.m.moibackend
MOI.set!(moi, MOI.ConstraintSet(), c.index, MOI.set_type(c.index)(rhs))
Copy link
Member

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).

const MOI = MathOptInterface
function setrhs(c, rhs)
moi = c.m.moibackend
MOI.set!(moi, MOI.ConstraintSet(), c.index, MOI.set_type(c.index)(rhs))
Copy link
Member

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.

@odow
Copy link
Member Author

odow commented Oct 12, 2018

Oops. I managed to drop the old commit instead of reverting it. It was totally superseded by this anyway.

@odow odow changed the title Proof of Concept: modifications RFC: modifications Oct 12, 2018
@odow
Copy link
Member Author

odow commented Oct 12, 2018

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.

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`.
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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 Show resolved Hide resolved

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
Copy link
Member

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 ?

Copy link
Member Author

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.

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`.
Copy link
Member

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.

`JuMP.set_coefficient(c, x, 4)` will create the constraint `4x <= 2`.


```jldoctest
Copy link
Member

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?

@odow odow merged commit 37eb05c into master Oct 15, 2018
@odow odow mentioned this pull request Nov 7, 2018
@odow odow deleted the odow/modifications branch December 30, 2018 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants