We have N shoppers with 100$ each and a list of M items that each cost [0-50$] (integer only) .
We need to buy all the items with the following requirements -
Examples
5 items costing [10,20,20,5,10]
Solution = 1 shopper who buys all the items. Only use 1 shopper since total is $65 < $100 budget for a single shopper.
5 items costing [50,15,30,30,10]
Solution = Shopper 1 buys [50,15]
and shopper 2 buys [30,30,10]
We need to use 2 shoppers since total is > 100 & assign them so that the difference between the shoppers is minimal (only $5 here).
Pseudo code :
For n_shoppers in range(1,N) :
subject to constraints
Break the loop as soon as the problem can be solved with a n_shoppers
subset of the total shoppers (and thereby we have the minimum number of shoppers required, and the best assignments)
This is really slow and inefficient - any suggestions on how I can frame this problem better? I'm currently solving it using CVXPY.
One way is as follows.
min UP-LO, UP>= shopper[i], LO <= shopper[i]
).