Hello,
I am trying to solve an optimization problem. Due to the complexity of the objective function, it is not convenient to use solver packages. So I tried to solve the problem using brute-force algorithm.
I have a list f which include n elements. each element can take 10 different values. therefore there could be 10^n different f combinations. I would like to search optimal f out of this 10^n possible f combination.
I generated the following lines to do the task. first with itertools.product I generate a possible list, then check whether is it feasible of not. If this candidate f is feasible, calculate the revenue. after that if the revenue is greater than the previous optimal one, it assigns optimal f and rev pair.
the code worked well when n was small(like n=10 or n= 12). However now, I have to work with lists having 120 elements. Therefore there could be 10^120 different f combination. Iteration 10^120 times would take unacceptable duration(I guess weeks) which make it impossible to use. Is there any ways to make it more efficient and converge to a solution more quicker?
I am not expert in coding but use occasionally for my researches. Therefore I really appreciate any help.
I am trying to solve an optimization problem. Due to the complexity of the objective function, it is not convenient to use solver packages. So I tried to solve the problem using brute-force algorithm.
I have a list f which include n elements. each element can take 10 different values. therefore there could be 10^n different f combinations. I would like to search optimal f out of this 10^n possible f combination.
I generated the following lines to do the task. first with itertools.product I generate a possible list, then check whether is it feasible of not. If this candidate f is feasible, calculate the revenue. after that if the revenue is greater than the previous optimal one, it assigns optimal f and rev pair.
the code worked well when n was small(like n=10 or n= 12). However now, I have to work with lists having 120 elements. Therefore there could be 10^120 different f combination. Iteration 10^120 times would take unacceptable duration(I guess weeks) which make it impossible to use. Is there any ways to make it more efficient and converge to a solution more quicker?
I am not expert in coding but use occasionally for my researches. Therefore I really appreciate any help.
value_list=range(10) f_possible=120 my_iter=itertools.product(value_list,repeat=f_possible) #generates all possible lists 'f' having 120 elements, each element could have 10 different value, thus 10^120 different 'f' for f in my_iter: if check_feas(f) == 1: #ckecks feasibility of the list f rev=cal_rev(f) # calculates revenue is f is feasible if rev > rev_opt: rev_opt=rev fob=f