If I have a set of binary variables that indicate whether something is active or not (in my case this is for employee scheduling) like so:
$$x_1E_1 + x_2E_1 + x_3E_1 + x_4E_1 $$
where $x_i$ is a binary variable which indicates whether employee $E_1$ is working at hour $i$
How can I deny certain patterns from occurring?
For example: Say I want to negate this pattern: $p = [0, 1, 0, 0]$
So I do not want this outcome:
$$0E_1 + 1E_1 + 0E_1 + 0E_1 $$
My approach was to add this constraint:
$$(\sum_{i=1}^n \lvert x_i - p_i\rvert) \ge 1$$
In this way, we iterate through all employees and take the difference of their activity variable, and the pattern variable. If it is a perfect match $\lvert x_i - p_i\rvert$ will be equal to $0$ for all $i$. It is okay if the difference is 0 for just 1 $i$, which is why we take the summation and have that be greater than or equal to 0.
I am aware of the absolute value trick to convert an absolute value into a linear problem as shown here. However, this answer constrains the model for all $i$, where I want to take the sum of my differences and constrain that.
However, upon trying this in Pyomo, I am getting infeasible errors. Is there a way that is is normally done?
Please note that the above is just an example, in reality, I will have many more employees and the pattern length will not be equal to the number of hours. To solve this problem, I'm chunking my array of activity variables and sliding my pattern across them.
Basically I'm trying to create a pattern-matching algorithm that excludes certain patterns of binary variables from the solution set.