-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
Using modulus operator in Constraint #762
Comments
hi, i also met the error, did you find the solution? @rogeriobiondi |
No, pulp doesn't allow the use of modulo operator Modulo is not linear function, so in some ways this is the expected response for a linear programming model. Since >>> 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.
The text was updated successfully, but these errors were encountered: