Multiple If else constraints in Mixed integer programming

How to formulate the following as constraints in MILP?

a[0][0] = y, if x[0]= 0,

a[0][0] = 0, if x[0] != 0, . .

. .

a[i][j] = b[i][j-1] + y, if x[j]=i,

a[i][j] = a[i][j-1], if x[j] != i, ... . . .

b[0][0] = z[0], if x[0] =0,

b[0][0] = 0, if x[0] != 0, . . . . .

b[i][j] = b[i][j-1] + z[i], if x[j] = i,

b[i][j] = b[i][j-1], if x[j] != i, .....

Suggest answers based on optimization or coding , both will help. How to use Piece-wise constraint or logical based constraint for this MILP?

• a, b, y, z are continuous variables (float) And x will be an integer May 22 at 11:15

You just seem to have hidden a long list of constraints of the form $$(x_i=j) \Rightarrow \text{equalities}_{ij}$$

Introduce a binary matrix $$C_{ij}$$ with $$\sum_j C_{ij}= 1$$ and $$C_{ij} \Rightarrow \{x_{i} = j, \text{equalities}_{ij}\}$$

To model the binary implication you can use big-M modelling, e.g. $$-M(1- C_{ij})\leq x_{i} - j\leq M (1-C_{ij})$$ and similar for all the other equalities.

The big-M model for $$x_i$$ can be replaced with $$x_i=\sum_j C_{ij} j$$ to reduce the model slightly.

• Thank you. Let me try that. May 22 at 17:37
• Nothing forces $C$ to be nonzero. You need to impose $\sum_j C_{ij}=1$ for all $i$. Also, the big-M constraints should instead have $M(1-C_{ij})$. May 22 at 19:00
• Absolutely, fixed. May 22 at 21:34
• solved it, thank you May 23 at 6:55