implement conditional constraint
回答済みHi,
I´ve been trying to implement this constraint:
if a >=1 then b=1 else b =0
a is a continuous variable
b is a binary variable
I´ve seen people using the big M to express this, but I can´t get to work properly.
Thanks
-
正式なコメント
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 David,
This sounds pretty similar to another forum post. There's example code in that thread for implementing a similar logical constraint in Python using indicator constraints.
Assuming \( a \) is bounded, we can model this on our own. Let \( a \in [\ell, u] \). Given a sufficiently small \( \epsilon > 0 \), we can (approximately) model \( a \geq 1 \iff b = 1\) with the following constraints:
$$\begin{align*}a &\leq 1 - \epsilon + (u - 1 + \epsilon)b \\ a &\geq b + \ell(1 - b).\end{align*}$$
- If \( b = 0 \), the first constraint gives us \( a \leq 1 - \epsilon \). The second constraint collapses to \(a \geq \ell\) and thus does not affect the model.
- If \( b = 1 \), the first constraint becomes \( a \leq u \), which does not affect the model. The second constraint becomes \( a \geq 1 \).
Does this answer your question?
Thanks,
Eli
0 -
Hi Eli,
Thank you so much for your help, that answered my question!
0
投稿コメントは受け付けていません。
コメント
3件のコメント