Constraint Implementation
回答済みHi. I am working on my thesis relating to the sports league scheduling issue and came across this constraint.

Any idea on how can I implement this? I am using Python for my development.
-
正式なコメント
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 should be able to model these constraints with the quicksum function.
It would look something like
[...]
model.addConstrs(
gp.quicksum(x[i,j,l] for j in T2[c] for l in range(k,k+intp[c]-1)) <= max[c]
for c in CA3HH for i in T1[c] for k in P if k <= abs(k) + 1 - intp[c]))Note that this is more a pseudo code, because I don't know any of your data structures. Also note that \(\texttt{range(k,k+intp[c]-1}\) does not contain the last entry \(\texttt{k+intp[c]-1}\), so if you need it, you should go for \(\texttt{range(k,k+intp[c]}\).
Best regards,
Jaromił0 -
Hi.
Thanks. It worked well. Furthermore, I came across this constraint:

How can you incorporate a quicksum with a GenConstrMax?
Thanks in advance
0 -
You can work in a similar way as above. However, when working with general constraints, you have to introduce auxiliary variables. This is because general constraints accept only single Var objects as input and require a Var object to define its output. In your case what you will have to model is similar to
\[\begin{align*}
z_{\min,l} &= k_{\min} - \sum_{j \in T_2} \sum_{s=l}^{l+k+1} x_{i,j,s}\\
z_{\max,l} &= \sum_{j \in T_2} \sum_{s=l}^{l+k+1} x_{i,j,s} - k_{\max}\\
w_l &= \max \{z_{\min,l}, z_{\max,l}, 0\} \\
d_i &= \sum_{l=1}^{|P|-k+1}w_l
\end{align*}\]
where \(z,w\) are auxiliary optimization variables (Var objects). I am not 100% sure about all the indices so you will have to figure this one out. You can model the \(\max\) functions by using the addGenConstrMax method.Best regards,
Jaromił0 -
Hi.
Thanks for this. I came across this constraint:

How can I implement this?
0 -
It is very similar to the first constraint you posted. Thus, you can use the quicksum function as discussed above.
Best regards,
Jaromił0 -
Thanks for your response. Furthermore, I have the following constraint:

How can I implement the k not using Gurobi?
0 -
What exactly do you mean by
How can I implement the k not using Gurobi?
You can define \(\bar{k}\) and use it in your constraints.
k_bar = ...
Are you sure that the sum you posted is correct? You don't use the \(k\) index used for \(k=\bar{k}\) but you use \(k\) for the constraint index \(k \in P\).
0 -
That is how it is defined, but it does not make sense now that I think of it. Thanks for your help
0 -
Hi.

How would this be implemented in Gurobi with python? Cause I got stuck while implementing
0 -
This has been already discussed above. You can use the quicksum function and the addGenConstrMax method.
0
投稿コメントは受け付けていません。
コメント
11件のコメント