Open rogeriobiondi opened 4 months ago
hi, i also met the error, did you find the solution? @rogeriobiondi
No, pulp doesn't allow the use of modulo operator %
in constraint like that.
Modulo is not linear function, so in some ways this is the expected response for a linear programming model. Since x
is an integer, though, you can represent a modulo constraint by introducing a new variable q
so that x - q*100 == 0
, like so:
>>> from pulp import *
>>> x = LpVariable("x", 100, 200, cat="Integer")
>>> y = LpVariable("y", 100, 200, cat="Integer")
>>> prob = LpProblem("moduloExample", LpMaximize)
>>> prob += x+y<=399
>>> modulus = 100
>>> q = LpVariable("q",0,modulus-1, "Integer") # helper variable
>>> prob += x - modulus * q == 0
>>> status = prob.solve(PULP_CBC_CMD(msg=0))
>>> LpStatus[status]
1
>>> value(x)
100.0
>>> value(y)
100.0
>>> value(q)
1.0
After studying a little in the OR books, I found this exact reason: the possible solution space will be bounded by the restrictions, and they must be all linear equations. So I had to rethink the problem and adapt it to the technique.
What is your question
Hello, is it possible using the modulus operator in a constraint?
For example
I'm getting an invalid operator:
I would want that the variable q1 would be a multiple of 100.
Thank you very much.