Issue while modelling indicator constraints
回答済みI 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
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
- not-equal constraints are not supported
So, you need to reformulate your expression. For example, c != k could be expressed as |c-k| >= 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.,
投稿コメントは受け付けていません。
コメント
2件のコメント