If I have the following objective function:
$$\min X_1 + X_2 + X_3 + X_4$$
How could I ensure that the variables $X_1, X_2, X_3$ and $X_4$ either have the value of 0 or they could have a random other value but only that value. So in total 2 different values may be assigned to the variables 0 or another value. It is difficult to formulate it well I think this example will make more sense:
The following solution is feasible: $X_1 = -5$ $X_2 = 0$ $X_3 = -5$ $X_4 = -5$ Every solution with maximal 2 different values in which 0 is one of these values should be feasible. The other value that should be assigned is not known beforehand.
Let $y$ be that unknown value, and introduce it as a variable in your optimization program.
You can introduce constraints $x_i (x_i - y) = 0$ which will force $x_i=0$ or $x_i=y$. Note this makes your problem nonlinear. Is this ok or you are interested in linear solution only?