Suppose I have N lists (vectors) and I want to select x from them 1<x<[N](x not specified) so I get the maximum value of func (lists).
For example:
l1 = [3,4,7,-2]
l2 = [0.5,3,6,2.7]
l3 = [0,5,8,3.6]
mat = [l1, l2, l3]
result = maximize(func, mat)
def func(mat):
sum_list = list(mat[0])
for li in mat[1:]:
sum_list = map(operator.add, sum_list, li)
accum_min_lst = []
for i, val in enumerate(sum_list):
x = sum_list[:i + 1]
accum_min_lst.append(val - max(x))
return min(accum_min_lst)
Possible results:
[l1], [l2], [l3], [l1,l2], [l1,l3], [l2,l3], [l1,l2,l3]
If I write a naive solution and just run all the combinations, then it will be forever 2 ^ N.
I'm trying to find a solution using cvxpy or maybe scipy.optimize.minimize
but I find it difficult to figure out which function I need to use for my problem, I thought maybe I should try the evolutionary algorithm to find an approximate answer, Or maybe I have to use portfolio optimization .