I am trying to recreate an integer linear optimization problem using cvxpy that I have outlined in Excel - . Note that this is a dummy example, the actual dataset will have thousands of variables. Please ignore the solution in cell K5 of the spreadsheet, as Excel Solver isn't able to provide integer solutions.
Consider that the 9 variables are split into 3 buckets. Note my goal with constraints 1-3 is that either there are at least 2 out of 3 1's for a bucket of variables, or all of the values are 0. For example, a,b,c should be either 1,1,1 or 1, 1, 0 or 1,0,1 or 0, 1, 1, or 0, 0, 0.
import numpy as np
import cvxpy as cp
import cvxopt
coefs= np.array([0.7, 0.95, 0.3, 2, 1.05, 2.2, 4, 1, 3])
dec_vars = cp.Variable(len(coefs), boolean = True)
constr1 = np.array([1,1,1,0,0,0,0,0,0]) @ dec_vars == 2 * max(dec_vars[0:3])
constr2 = np.array([0,0,0,1,1,1,0,0,0]) @ dec_vars == 2 * max(dec_vars[3:6])
constr3 = np.array([0,0,0,0,0,0,1,1,1]) @ dec_vars == 2 * max(dec_vars[6:9])
constr4 = np.ones(len(coefs)) @ dec_vars >= 2
When I run up to here, I get a
NotImplementedError: Strict inequalities are not allowed.
error