Skip to main content

Conditional logic in linear expression

Answered

Comments

2 comments

  • Official comment
    Michael Winkler
    Gurobi Staff Gurobi Staff

    Hi Ritesh,

     

    you cannot directly model constraints conditionally on the result of another constraint.

    Lets assume that you want to minimize your Cost. Then what you could do is add constraints for each t in T quicksum(X[q] for q in data[t]) - |data[t]|*y[t] <= 0 (|data[t]| being the cardinality of elements in data[t], y[t] an additional binary).

    Then you objective function would be to minimize quicksum(data[t].cost * y[t] for t in range(T)). (Then the objective would always push y[t] down to zero if non of the X[q] with q in data[t] are one in a solution.)

     

    Best,

    Michael

  • Ritesh Agrawal
    Gurobi-versary
    First Question
    First Comment

    Hi Michael,

     

    Thanks for the idea. That worked nicely. 

     

    Ritesh

    0

Please sign in to leave a comment.