How to round up in gurobi python?
OngoingI am working on a math. model and I use python to solve it.
I have 4 sets
1. Trucks=[1:263]
2. Slots=[0:23]
3. Companies=[0:3]
4. Blocks=[0:7]
And two binary decision variables X
and Y
and one binary dependent decision variable Z (Z=X+Y)
.
I want to add the continuoustime parameters (tp+twg)
to the index s
(which is an integer) to make the truck access the terminal in the time slot after (tp+twg)
. So I have to round the value of (s+tp+twg)
to the next time slot. I used the function below math.ceil()
but I got an error in time slot 23. Gurobi can't calculate the value of (0,0,1,24) because the upper limit of the set S is 23. S refers to the time slot at which the truck will access the terminal in X and Y. In Z, it refers to the time slot at which the truck will arrive at the terminal gate. How can I fix that?
for i in Trucks:
for k in Companies:
for b in Blocks:
for s in Slots:
if 0 <= s < 23:
cont_9=m.addConstr(X[i,k,b, math.ceil(s+tp[s]+twg[s])]+Y[i,k,b, math.ceil(s+tp[s]+twg[s])] <= Z[i,k,b,s])

Hi,
What values can your continuoustime parameters take? Is it possible that \(\texttt{tp[s]+twg[s]}\geq 2\) for some \(s\)? If yes, then you have to somehow limit \(s\) even further to, e.g., \(\texttt{0 <= s <= 20}\).
A different approach would be to compute the value of \(\texttt{math.ceil(s+p[s]+twg[s])}\) before adding the constraint and then adjust it appropriately such that it fits within the slot bounds.
Best regards,
Jaromił0 
This is a crosspost from https://stackoverflow.com/questions/63775312/howtoroundupingurobipython
0
Please sign in to leave a comment.
Comments
2 comments