メインコンテンツへスキップ

implement conditional constraint

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff Gurobi Staff
    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?.
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    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
  • David Mejía
    • Gurobi-versary
    • Conversationalist
    • Curious

    Hi Eli,

    Thank you so much for your help, that answered my question!

    0

投稿コメントは受け付けていません。