import pymprog from random import randint # indices customers = range(100) promos = range(10) c_p = pymprog.iprod(customers, promos) # data CLV = [randint(0, 1000) for c in customers] S = [[randint(0,1)*randint(0,1) for p in promos] for c in customers] C = [randint(10, 200) for p in promos] BUDGET = 5000 # model m = pymprog.model('clv') y = m.var(customers, 'y', bool) x = m.var(c_p, 'x', bool) z = m.var(promos, 'z', bool) m.max(sum(CLV[c]*y[c] for c in customers) - sum(C[p]*sum(x[c,p] for c in customers) for p in promos) - sum(CP[p]*z[c] for p in promos)) m.st(sum(x[c,p]*C[p] for c, p in c_p)<=BUDGET) m.st([([y[c] <= sum(x[c,p]*S[c][p] for p in promos)) for c in customers]) m.st([(z[c] <= sum(x[c,p] for c in customers) for p in promos]) m.solve() print x print y