Let $x \in \mathbb{R}^n$ be an optimization variable. Now, at a constraint, I would like to count how many times a value, say $2$, appears in $x$ decision.
I think we can have a binary variable $y_i$ indicating whether $x_i =2$. So, $x_i - 2 = 0$ should imply $y_i = 1$. But, anything except $0$ should imply $y_i = 0$. What is the easiest way for this?
Note: since we can subtract $2$ from each element of $x$, we are interested in the number of zeros in $x-2$. So, 'the number of zeros in a decision vector' constraint will also make it.
We may assume $x$ consists of elements $x_i< M$ for some constant $M$