How to take the remainder of the variables in gurobi?
AnsweredHi,I want to take the remainder of the variable.
for k in orders:
m.addConstr(t[k.no] % 7 + 1 == k.rk % 7)
t is the decision variable.
But it returns the following error
TypeError: unsupported operand type(s) for %: 'Var' and 'int'
Is there any way to solve this problem?
thanks a lot.
Yu
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
You could try expressing each of the affected t variables as \(t = 7*a + b\), with \(a, b\) being integers and \(b \in [0,6]\) Then, \(b\) is your reminder and you can use it in the constraint you showed.
Hope this helps.
Best regards,
Jonasz0 -
Sorry, I didn't describe the problem I encountered clearly. I would like to solve the following problem,

Cargo k starts shipping at time

and arrives at time
. The start time is known (
represents the day of the week, Monday, Tuesday, etc.) and the arrival time
is the decision variable (determined by the chosen path,
).
I want
and
to be the same, e.g. both on Monday or both on Tuesday.For example,
=1 (ship on Monday),
=35 (arrive in 35 days), and 35 days is also a Monday.Best regards,
Yu
0 -
Hi Jonasz,
I'm sorry I didn't think carefully about the method you proposed, and I did the calculation again using your method. It worked.
Thank you very much!
Yu
0 -
One more piece of advice, Yu: You can use LaTeX directly in our Community Forum as explained here: Posting to the Community Forum
This is a lot less work than copy-pasting mathematical notation as images.
Cheers,
Matthias0 -
Hi Matthias,
Thanks, this is very helpful to me.
Best regards,
Yu
0
Post is closed for comments.
Comments
6 comments