Let's suppose we have X=variable(n, boolean=True)
and an array B of length n containing repeated integers.
I want to write a constraint so that the element by element multiplication of the solution of X by B is an Array containing as elements 0 or a single value p, with p being an element of B.
Example of a solution with
B=[2,3,4,3,3,2,2,3,5,4,7,7,2]
would be
X1=[0,1,0,1,1,0,0,0,0,0,0,0,0]
Or
X2=[1,0,0,0,0,0,1,0,0,0,0,0,1]
But not
X3=[0,0,1,1,0,0,1,0,0,0,0,0,1]
I tried to set as constraint, using numpy
along with cvxpy
constr=[cvxpy.sum(np.multiply(X,B))/sum(X)==max(np.multiply(X,B))]
But I can't solve the problem I create using the constraint above