How do I add the following Constraint in Guroby?
Answered
For me, it is showing an error saying divisor must be a constant. I tried to do that as follows:
But this solution is manipulating the output values. How do I Write the constraint as it is?
-
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 why not try our AI Gurobot?. -
Hi,
Is \(b_{i,j}\) an optimization variable? Did you have a look at How do I divide by a variable in Gurobi?
Could you elaborate what exactly you mean by "manipulating the output values"?
Best regards,
Jaromił0 -
Yes, Jaromił Najman Sure!
So
The variable in the denominator (tr ij )is an integer type
xijt is a binary variable.
yij is again integer type.
The integers are to be controlled by the binary variable. But because I changed the equation, what happens is trij takes the value 0 irrespective of the value of xijt. Where as both should be zero according to the first constraint.
I would also suggest helping me write it as:
0 -
Hi,
Thank you for the clarification.
So what you are trying to model is
\[ \frac{y_{ij}}{tr_{ij}} \leq p_{ijt} x_{ijt} \quad(1)\]
where \(p_{ijt}\) is some constant value and the other variables are as you described.
Since \(tr_{ij}\) is in the denominator, you should explicitly set its lower bound to 1 to not allow division by zero.
Inequality \((1)\) forces \(y_{ij} = 0\) if \(x_{ijt}=0\) and sets its upper bound to \(p_{ijt}\) otherwise. Note that \(tr_{ij}\) can attain any value \(\geq 1\) if \(x_{ijt}=0\) and is only limited if \(x_{ijt}=1\). You can formulate this relationship via
\[ \begin{align}
y_{ij} &\leq p_{ijt} x_{ijt}\\
y_{ij} & \leq p_{ijt} tr_{ij}
\end{align}\]Best regards,
Jaromił0 -
Thank You for your assistance Jaromił Najman. But the upper bound of the yij is not Pijt in the first place. If you look at inequality (1) of your last comment, then you can find that yij is divided by trij... so yij is actually way more than Pijt.
Actually yij is the total volume to be transported. Pijt is the capacity and trij is the number of trips..
So can I go like as following?
\(y_{ij}≤(p_{ijt})*(x_{ijt})*(tr_{ij})\)
\(y_{ij}≤(p_{ijt})*(tr_{ij})\)
0 -
Hi,
But the upper bound of the yij is not Pijt in the first place. If you look at inequality (1) of your last comment, then you can find that yij is divided by trij... so yij is actually way more than Pijt.
Yes, you are correct. You can then use your formulation. I was trying to avoid the bilinear term \(x_{ijt} tr_{ij}\). That's why I assumed that \(y_{ij}\) is bounded by \(p_{ijt}\). Luckily the bilinear multiplication of a binary and an integer variable can be linearized.
Best regards,
Jaromił0
Post is closed for comments.
Comments
6 comments