Adding conditional constraints to the model
AnsweredI have trouble with implementing the conditional constraint:
# when E_i[i] == m, we want to let G_i_m[i, m] == 1
# when E_i[i] != m, we want to let G_i_m[i, m] == 0
I got this error: gurobipy.GurobiError: Constraint comparison not implemented.
Is there any way to do so? Thanks for your help.
M = range(8) N = range(9) E_i = model.addVars(len(N), vtype=gp.GRB.INTEGER, name="E_i") G_i_m = model.addVars(len(N), len(M), vtype=gp.GRB.BINARY, name="G_i_m")
# when E_i[i] == m, we want to let G_i_m[i, m] == 1 # when E_i[i] != m, we want to let G_i_m[i, m] == 0 for i in N: for m in M: model.addConstr((E_i[i]  m == 0) >> G_i_m[i, m] >= 1, name="c0_0") model.addConstr((E_i[i]  m >= 1) >> G_i_m[i, m] == 0, name="c0_1") model.addConstr((E_i[i]  m <= 1) >> G_i_m[i, m] == 0, name="c0_2")
0

Hi Qiru,
as discussed here, indicator constraints require binary variables as indicator variables.
You may need to add an auxiliary binary variable to represent the relationship between \( E_i \) and \(m\), and then use that binary variable in your indicator constraints.
If you need more help / example, please let us know.
Best regards
Jonasz0
Please sign in to leave a comment.
Comments
1 comment