Adding conditional constraint based on index value
Answered
-
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. -
The first dimension of your variables \(x_W\) and \(x_{FM}\) depends on \(\texttt{J1,J2}\), respectively. Thus, if you set \(\texttt{J1,J2}\) equal to \(0\), the tupledicts \(x_W\) and \(x_{FM}\) will be empty.
Is it correct that the terms \(\texttt{NFRM,NW,J1,J2}\) all are constant values determined before solving and constructing the model?
Could you elaborate a bit more on what actually you are trying to achieve with your code snippet? A minimal working example would also help.
Best regards,
Jaromił0 -
0 -
I assume that NFM and NW are integer values \(\geq0\), correct? If yes, then you could add a constraint
\[\begin{align*}
x_W &\leq NW\\
x_{FM} &\leq NFM
\end{align*}\]This way, you force variables \(x_W, x_{FM}\) to \(0\) when the corresponding constant input is \(0\). You have to introduce this constraint for every variable depending on NW, NFM.
Best regards,
Jaromił0 -
Thank you so much for your guidance. That is right. NFM and NW are integer values ≥0.
When for example NW=0, since J1 is null I receive error for the following constraint:
x-W[j1,l1]<=x-W[j-1,l1]
Is it correct to change it to the following?
If NW!=0:
x-W[j1,l1]<=x-W[j-1,l1]
Regards,
Bahar
0 -
I don't know the structure of your code, but in general adding the \(\texttt{if NW!=0:}\) clause should work.
Best regards,
Jaromił0
Post is closed for comments.
Comments
6 comments