Skip to content
Discussion options

You must be logged in to vote

My advice would be to treat the constraint as immutable, if you need to change it you can do:

x = LpVariable("x")
y = LpVariable("y")
constraint = x + y <= 5
constraint2 = constraint + x
assert str(constraint2) == str(2*x + y <= 5)
assert constraint is not constraint2
assert constraint.expr is not constraint2.expr

If you really want to modify the constraint with addterm, just access the underlying LpAffineExpression:

constraint = x + y <= 5
constraint.expr.addterm(x, 1)
assert str(constraint2) == str(2*x + y <= 5)

addterm really seems like an implementation detail, so really should be avoided. For example, LpAffineExpression.addInPlace is much more flexible. Also addInPlace is implement…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by simon-b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants