I am trying to obtain all the combinations of values in a list, for which the sum of the corresponding values in another list do not exceed a certain limit. As an example, I have certain jobs that I want to produce in a batch, but that batch has a limited capacity, meaning that only certain combinations of jobs can be put together so that their size don't exceed the capacity of the batch.
Imagining I have jobs defined as job 1, job 3, and job 5, I have the following list:
jobs = [1,3,5]
If job 1 has size 1, job 3 has size 3, and job 5 has size 2, I have the following list:
jobSize = [1,3,2]
If my batch has maximum capacity of 5, this means the desired output is the following:
combinations = [(1),(3),(5),(1,3),(1,5),(3,5)]
#here I use the name/number of the jobs, and (1,3,5) not included cause total size of 5 is exceeded
From what I have seen, something similar (not exactly the same) is possible to do using combinations from itertools, like explained here Powersets in Python using itertools or here How to get all possible combinations of a list’s elements?, but this is definitely not as efficient as I would like.
I also tried something with itertools.product and np.where, like explained here Python Numpy: All combinations from array or scalar by Corralien, but once again, this is not exactly what I need, and requires a lot of post-processing operations, ending up being too slow.
My idea is that this is possible to do somehow with numpy arrays, because it is the only way I can see this being fast. Does anyone have any idea?