Skip to main content

Boolean comparison of decision variable with parameter

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?.
  • Yuriy Zinchenko
    • Gurobi Staff Gurobi Staff

    Hello Mike,

     

    The modelling approach will depend on whether you want to minimize or maximize your objective.

    For example, if you want to maximize, with r fixed, and v's being non-negative, to build something like 

    > gb.quicksum(v[i]*x[i] if x[i] >= y[r][i] else 0 for i in range(10))

    or essentially, for simplicity dropping sub-index r, add terms of the form

    v[i]*x[i] if x[i] >= y[i]

    one can use the so-called semi-continuous variables construct, see here https://www.gurobi.com/documentation/9.0/refman/variables.html

     

    Then you can introduce an auxiliary semi-continuous z[i] with lower bound y[i] and upper bound GRB.INFINITY, unconditionally add the term

    (*) v[i] * z[i]

    to the objective, and add a constraint

    (**) x[i] >= z[i] 

    Note if x[i] ends up smaller than y[i], due to (**) and z[i] being semi-continuous, z will take value 0 making no contribution to the objective.  On the other hand, if x[i] ends up greater or equal than y[i], due to maximizing the objective and (**) you will essentially be adding v[i]*x[i] to the objective function.

     

    Hope this helps.

     

    0

Post is closed for comments.