How Indicator constraint can be triggered with multiple variables in Gurobi?

Viewed 279

I am trying to write the constraint related to multiple variables. However, it shows error "Indicator constraints can only be triggered by a single binary variable at a given value". Can you help me fix this error? Thank you very much! The code is following:

mdl.addConstrs((x[i,j,k] - t[i,j,k] == 1) >> (d2[j,k] == d2[i,k] - d[i,j]) for i, j, k in arcos2 if i != 0 and j != 0)

Where:

  • x[i,j,k], t[i,j,k] are binary variables
  • d2[j,k], d2[i,k] are continuous variables
  • d[i,j] is a parameter
1 Answers

I think the error message is pretty clear. Define binary helper variables q[i,j,k] to represent x[i,j,k] - t[i,j,k]. Then:

for i, j, k in arcos2:
    if i != 0 and j != 0:
        mdl.addConstr(q[i,j,k] == x[i,j,k] - t[i,j,k])
        mdl.addConstr((q[i,j,k] == 1) >> (d2[j,k] == d2[i,k] - d[i,j]))
Related