I have a bucket and list of items with a packsize where a packsize is a collection of units.
bckdf=pd.DataFrame.from_dict({0:{'Bucket_Type': 'Veg', 'Capacity':1000},
1:{'Bucket_Type': 'Non-Veg', 'Capacity':500}}).T
items=pd.DataFrame.from_dict({'item_no': {0: '123', 1: '456', 2: '789'},
'item_description': {0: 'Buffet Malabar Paratha 300 gm',
1: 'Mc Cain French Fries Value Pk 750 Gm',
2: 'Yummies Veg Sticks 320 gm Pouch'},
'volume': {0: 0.0714286, 1: 0.214286, 2: 0.0357143}})
I need to fit in minimum 900 units in the bucket, while ensuring that more or less equal number of packs are put in the bucket for each item. Everytime, i choose 1 pack, I use up volume of that pack which I formulated as a cost.
prob = LpProblem("LP_Problem", LpMaximize)
buckettype = bckdf[bckdf['Bucket_Type']=='Veg']['Bucket_Type']
capacity = bckdf.set_index(['Bucket_Type'])['Capacity'].to_dict()
itemlist=items['item_no']
combos = [(w,b) for w in buckettype for b in itemlist]
costs = makeDict((buckettype, itemlist),[items['volume']])
itemqtydict = LpVariable.dicts("Combo",(buckettype, itemlist), 0, None, LpInteger)
## Objective function
prob += lpSum([(itemqtydict[w][b]) for (w,b) in combos])
prob += lpSum([(itemqtydict[w][b])*costs[w][b] for (w,b) in combos])>=900
prob += lpSum([(itemqtydict[w][b])*costs[w][b] for (w,b) in combos])<=bckdf[bckdf['Bucket_Type']=='Veg']['Capacity'].values[0]
status=prob.solve(pulp.PULP_CBC_CMD(timeLimit=5,msg=1, gapRel=1))
How do I build in constraint where
more or less equal number of packs are put in the bucket
question from:
https://stackoverflow.com/questions/65661910/pulp-relative-allocation-constraint 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…