How to formulate multiple conditional logical (AND and OR) constraints
AnsweredI am wondering what would be the efficient way of formulating the following constraint in (Python) Gurobi:
# The big-Mx_i (i=1,...,n), eta, and gamma are binary variables and px_i (i=1,...,n) are integer variables.
M = 10**9
# Constraints
for i in range(n):
for k inrange(n):
if (i!=k) and (x[i]==1) and (x[k]==1):
# OR constraints already linearized via Big-M
px[i] - px[k] +M*eta <= M-l[i]
px[k] - px[i] -M*eta <= -l[k]
0
-
Hi,
You can define an auxiliary variable \(z_{ik} = x_i \land x_k\, ~~ \forall i, k\). The logical And constraints can be implemented using the Model.addGenConstrAnd() method in Gurobi Python API.
You can then use the Model.addGenConstrIndicator() method to implement the following two constraints for all \(i\) and \(k\) indices where \(i \neq k\):
- \(\mbox{if}~ z_{ik} = 1 \rightarrow px_i - px_k + M \eta \leq M - l_i\)
- \(\mbox{if}~ z_{ik} = 1 \rightarrow px_i - px_k - M \eta \leq - l_k\)
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
1 comment