# ILP constraint conditional on a value of a variable

If $$X_{ijklm}$$ are Boolean Variables, where $$i,j,k,l,m$$ range from $$1$$ to $$n$$, then write an ILP constraint to ensure that for each value of $$k$$, either all the $$jth$$ variables are set to $$0$$ or all the $$jth$$ variables are set to $$1$$ irrespective of the values of $$i,l$$ and $$m$$ and there exists at least one value of $$k$$ for which all the variables are set to 1.

For example, when $$k=1$$, ensure all variables where $$j=1,2,3 \ldots n$$ are set to either all 0 or all 1 irrespective of the values of $$i, l$$ and $$m$$. Similarly, when $$k=2$$, ensure all variables where $$j=1,2,3 \ldots n$$ are set to either all 0 or all 1 irrespective of the values of $$i, l$$ and $$m$$. Additionally, ensure that there exists at least one $$kth$$ index for which all variables are set to $$1$$.

As a concrete enumerated case, consider $$X_{ij1lm}$$, in which case $$k = 1$$, in such a scenario, the set of variables for different values of j are $$X_{i11lm}, X_{i21lm}, X_{i31lm}, \ldots, X_{in1lm}$$. Similarly for $$k = 2$$, the set of variables for different values of j are $$X_{i12lm}, X_{i22lm}, X_{i32lm}, \ldots, X_{in2lm}$$. The ILP constraint should ensure either all these variables are set to 0 or set to 1 and there exists at least one value of $$k$$ for which all the variables are set to 1.

• Why do you need I,l, and m if you are not going to use those degrees of freedom? Jul 14 at 13:50
• If you don’t want the variables to depend on $j$, just omit $j$ from the index. Jul 14 at 13:51
• i, l and m will be used in other constraints, this is just a part of the constraints. @RobPratt the value of the variables would depend on k, that is if k = 1, X_{i11lm}, X_{i21lm}, X_{i31lm} and so forth till X_{in1lm} are all either 1 or all 0 Jul 14 at 15:21
• @RobPratt I have edited the question with more examples to make it clearer. Jul 14 at 15:58

For each $$i,k,l,m$$, you want all $$X_{ijklm}$$ to take the same value for all $$j$$. Here are three alternative ways, in increasing order of efficiency:

1. Impose linear constraints $$X_{ijklm} = X_{ij'klm} \quad \text{for all i,k,l,m,j < j'}$$
2. Introduce a new variable $$Y_{iklm}$$ to represent the common value and impose linear constraints $$X_{ijklm} = Y_{iklm} \quad \text{for all i,j,k,l,m}$$
3. Omit the $$j$$ index and replace $$X_{ijklm}$$ with $$X_{iklm}$$

For the "there exists at least one value of $$k$$ for which all the variables are set to $$1$$" requirement, here are the corresponding constraints for the three alternative ways:

1. $$\sum_k X_{i1klm} \ge 1 \quad \text{for all i,l,m}$$
2. $$\sum_k Y_{iklm} \ge 1 \quad \text{for all i,l,m}$$
3. $$\sum_k X_{iklm} \ge 1 \quad \text{for all i,l,m}$$

$$\sum_{j} x_{iklm}^j =ny_{iklm} \ \ \forall i,l,m,k$$

$$1 \le \sum_k y_{iklm} \ \ \forall i,l,m$$

where $$y_{iklm}$$ is also binary