-4
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ a, b, y, z are continuous variables (float) And x will be an integer $\endgroup$ – deepan May 22 at 11:15
5
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ Thank you. Let me try that. $\endgroup$ – deepan May 22 at 17:37
  • 1
    $\begingroup$ 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})$. $\endgroup$ – RobPratt May 22 at 19:00
  • 1
    $\begingroup$ Absolutely, fixed. $\endgroup$ – Johan Löfberg May 22 at 21:34
  • $\begingroup$ solved it, thank you $\endgroup$ – deepan May 23 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.