Modelling with gurobipy
Awaiting user inputHi,
I would like to model the following constraint with gurobipy :
time_R = [2 for i in full_R]
time_L = [(0,2) for i in full_L]
w_L = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19]]
w_R = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19]]
L = [[0, 1], [4, 6, 7], [8, 9, 10, 11], [14, 15], [16, 17, 18]]
R = [[0, 1, 3], [6, 7], [8, 9, 10], [12, 13, 14, 15], [16, 17, 18, 19]]
for l in L[t]:
for r in R[t]:
for i in w_R:
for j in w_L:
if r in i and l in j:
assignment_problem += x[r, l] <= max(0, (
(w_R.index(i) + time_R[r]) - (w_L.index(j) + time_L[l][0])) + 1)
Thanks a lot for your help
-
Official comment
This post is more than two 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. -
Hi Emma,
Could you please elaborate on what exactly are you trying to model? Given your code, you are trying to model
\[\begin{align*}
\sum_{l,r,i,j} \left( x_{r,l} \leq \max\{0, w_i + time_r - w_j - time_{l,0} +1\}\right)
\end{align*}\]You cannot sum over inequalities.
In order to use the max operator, you have to use the addGenConstrMax method which accepts only single optimization variables or constants. This means that for every \(\max\) term, you have to introduce 2 auxiliary variables \(q_{i,r,j,l}, p_{i,r,j,l}\) and model the constraints
\[\begin{align*}
p_{i,r,j,l} &= w_i + time_r - w_j - time_{l,0} +1\\
q_{i,r,j,l} &= \max\{0, p_{i,r,j,l}\}
\end{align*}\]Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments