0

I am trying to model a conditional constraint in Guuobi python:

if a>= b then c == 1, otherwise c == 0

a and c are both model variables and c is binary

I have the following code based on How do I model conditional statements in Gurobi?but something is not correct as I cannot obtain the optimal answer. My code is:

Constraint4 = LP.addConstrs((a[i,j] >= b[j] + eps - M * (1 - c[i,j])
                             for j in items
                             for i in months
                             if i == months[2]), name="BigM1")

Constraint5 = LP.addConstrs((a[i,j] <= b[j] + M * c[i,j]
                             for j in items
                             for i in months
                             if i == months[2]), name="BigM2") 
Marian
  • 11
  • 2

1 Answers1

0

I think you are missing index of b. It should be also index to j.

Constraint4 = LP.addConstrs((a[i,j] >= b[i,j] + eps - M * (1 - c[i,j])
                             for j in items
                             for i in months
                             if i == months[2]), name="BigM1")

Constraint5 = LP.addConstrs((a[i,j] <= b[i, j] + M * c[i,j]
                             for j in items
                             for i in months
                             if i == months[2]), name="BigM2")