Trying to implement and indicator constraint in Python + Gurobi where the indicator(LHS) is a sum of a binary decision variable.
Hi, I've would like to implement following in Python + Gurobi:
Y_i_d and U_d are binary decision variables:
Y_i_d = model.addVars(passengers, drivers, vtype=grb.GRB.BINARY, name = "Y")
U0_d = model.addVars( drivers, vtype=grb.GRB.BINARY, name = "U0")
U1_d = model.addVars( drivers, vtype=grb.GRB.BINARY, name = "U1")
U2_d = model.addVars( drivers, vtype=grb.GRB.BINARY, name = "U2")
U3_d = model.addVars( drivers, vtype=grb.GRB.BINARY, name = "U3")
and I'd like to have the following implication somehow:
model.addConstr((U0_d[d]+U1_d[d]+U2_d[d]+U3_d[d])==1)
model.addConstr( (grb.quicksum(Y_i_d[ i, d] for i in passengers) == 0) >> (U0_d[d] == 1))
model.addConstr( (grb.quicksum(Y_i_d[ i, d] for i in passengers) == 1) >> (U1_d[d] == 1))
model.addConstr( (grb.quicksum(Y_i_d[ i, d] for i in passengers) == 2) >> (U2_d[d] == 1))
model.addConstr( (grb.quicksum(Y_i_d[ i, d] for i in passengers) == 3) >> (U3_d[d] == 1))
However, this doesn't work because the indicator constraint declares the indicator variable as binary type. Is there a workaround for this? I have to use the U_d variables later on to define disjunctive constraints.
Thank you in advance!
Try writing the constraints backward: