Boolean comparison of decision variable with parameter


1 comment

  • Yuriy Zinchenko

    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


    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.


    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk