Issue while modelling indicator constraints
AnsweredI am trying to model the following constraint.
where x_ij is binary Decision variable, c_j is continuous decision variable, and k_i is parameter. K is set for the parameter k_i values K ={k_1,......, k_n}
# Indicator constraints for c[j] = K[i] implies z[i, j] = 1 for i in range(len(K)): for j in range(m): model.addConstr(c[j]  M[i] == 0 >> z[i, j] == 1, name='indi_constr_1') # Indicator constraints for c[j] != M[i] implies z[i, j] = 0 model.addConstr(c[j]  M[i] != 0 >> z[i, j] == 0, name='indi_constr_2') # Link z variables to x variables for i in range(len(K)): for j in range(m): model.addConstr(z[i, j] == x[i, j], name="indi_constr_3")
For these constraints, I am getting the following error.
line 48, in <module> model.addConstr(c[j]  M[i] == 0 >> z[i, j] == 1, name=f"indicator_constraint_cj_mi_{i}_{j}") TypeError: unsupported operand type(s) for >>: 'int' and 'Var'
Any help would be much appreciated.
0

There are several issues in your formulation
 The expressions in the indicator constraints (see Model.addGenConstrIndicator() ) need brackets, e.g.,
model.addConstr((x7 == 1) >> (x1 + 2*x2 + x4 == 1.0))
 The indicator variable needs to be binary
 notequal constraints are not supported
So, you need to reformulate your expression. For example, c != k could be expressed as ck >= eps.
Note, to use Model.addGenConstrAbs() you will need helper variables.
The following articles might be helpful0  The expressions in the indicator constraints (see Model.addGenConstrIndicator() ) need brackets, e.g.,
Please sign in to leave a comment.
Comments
1 comment