Skip to main content

logical constraint

Answered

Comments

2 comments

  • Official comment
    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

    Yes, you can model logic like this using indicator constraints. For example, consider the conditional statement

    $$\begin{align*}x + y \geq 1 &\implies z \geq 1.\end{align*}$$

    First, we create a new binary variable \( w \). Then, the above is equivalent to

    $$\begin{align*} x + y \geq 1 &\implies w = 1 \\ w = 1 &\implies z \geq 1.\end{align*}$$

    Indicator constraints must be of the form

    $$\begin{align*}\textrm{binary variable equals } 0 \textrm{ or } 1 &\implies \textrm{some constraint.}\end{align*}$$

    So, we can re-write the first conditional statement \( x + y \geq 1 \implies w = 1 \) with its logically equivalent contrapositive: \( w = 0 \implies x + y < 1 \). Strict inequalities aren't allowed in a math programming framework, but we can closely approximate this constraint with \( x + y \leq 1 - \epsilon \) for some small \( \epsilon > 0 \). Note that we can use \( \epsilon = 1 \) if \( x \) and \( y \) are both integer variables.

    Altogether, we add the following two indicator constraints:

    $$\begin{align*} w = 0 &\implies x + y \leq 1 - \epsilon \\ w = 1 &\implies z \geq 1.\end{align*}$$

    Alternatively, you can model this logic yourself without using indicator constraints. E.g., if \( z \geq 0 \), then the conditional statement \( w = 1 \implies z \geq 1 \) is equivalent to \( z \geq w \).

    1

Post is closed for comments.