Conditional logic in linear expression
AnsweredHi,
I have an linear expression with conditional logic. Gurobi doesn't complain but is giving wrong results. The linear expression essentially converts into a constant value.
Cost = quicksum(data[t].cost for t in range(T) if quicksum(X[q] for q in data[t]) >= 1)
where X is a binary decision variable.
Is there any other way to express this.

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

Hi Michael,
Thanks for the idea. That worked nicely.
Ritesh
0
Please sign in to leave a comment.
Comments
2 comments