I have the following decision variables:
$a_i, x_i^t$ and $x_i^0$ are binary variables.
I want to realize the following four conditions:
- if $a_i = 1, \sum_{t=0}^n x_i^t = 0$, then $x_i^0 = 0$;
- if $a_i = 1, \sum_{t=0}^n x_i^t = 1$, then $x_i^0 = 1$;
- if $a_i = 0, \sum_{t=0}^n x_i^t = 0$, then $x_i^0 = 0$;
- if $a_i = 0, \sum_{t=0}^n x_i^t = 1$, then $x_i^0 = 0$ or $1$;
There is another necessary constraint: $$\sum_{t=0}^n x_i^t \leq 1$$
Can anyone help me?
Thank you.
While it's not completely necessary, I will define $X_i = \sum_{t = 0}^n x_i^t$. We'll also note that $X_i = 0$ if and only if all of the $x_i^t = 0$, and $X_i = 1$ if and only if exactly one of the $x_i^t = 1$.
To linearise the first condition, we want to create a constraint that looks like
$$x_i^0 \leq P(a_i, X_i)$$
where $P$ is some linear function that is equal to zero when $a_i = 1$ and $X_i = 0$, and bigger than or equal to 1 otherwise. So an easy choice is:
$$x_i^0 \leq (1 - a_i) + X_i$$
You can do something very similar for the third constraint.
If you have another constraint that means that $X_i$ can never be greater than 1, then you can do exactly the same thing for the second constraint as well. However, if such a constraint doesn't exist then you would need to be a bit more careful if you need to test for exactly the situation where $a_i = 1$ and $X_i = 1$ (and in fact you might need to create a number of constraints to test for the individual cases where each single $x_i^t = 1$).