How would I specify a constraint so that the boolean 2-dimensional decision variable matrix has the following criteria:
- all the non-zero columns have to be identical
If the matrix was a numpy array, we would be able to use np.all, but I don't see an analogous cvxpy function.
import numpy as np
import cvxpy as cp
import cvxopt
util = np.array([[0.7, 0.95, 0.3, 3], [2, 1.05, 2.2, 5], [4, 1, 3, 6]])
dec_vars = cp.Variable(len(util), boolean = True)
zero_cat_vars = cp.Variable(util.shape[0], boolean = True)
# example of output
dev_vars_smp_output = np.array([[0, 0, 0, 0], [1, 0, 0, 1], [1, 0, 0, 1]])
zero_cat_constr = cp.sum(dec_vars, axis=1) >= 1 * zero_cat_vars
dec_vars_excl_zeros = dec_vars[:,~cp.all(dec_vars==0, axis=1)]
col_equal_constr = cp.sum(dec_vars_excl_zeros, axis=1) == dec_vars_excl_zeros.shape[1] * zero_cat_vars