-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdark_store.py
More file actions
21 lines (21 loc) · 1.24 KB
/
dark_store.py
File metadata and controls
21 lines (21 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
def allocate_dark_stores(stores, products, demand_forecast):
allocations={}
for store in stores:
store_alloc={}
remaining_cap=store["capacity_units"]
ranked=sorted(products,key=lambda p:-demand_forecast.get((store["name"],p["sku"]),0)*p["margin"])
for prod in ranked:
demand=demand_forecast.get((store["name"],prod["sku"]),0)
qty=min(int(demand*1.5+5),remaining_cap,prod.get("max_per_store",100))
if qty>0:
store_alloc[prod["sku"]]=qty; remaining_cap-=qty
if remaining_cap<=0: break
allocations[store["name"]]={"products":store_alloc,"utilization":round((store["capacity_units"]-remaining_cap)/store["capacity_units"]*100,1)}
return allocations
if __name__=="__main__":
stores=[{"name":"DS-North","capacity_units":500},{"name":"DS-South","capacity_units":400}]
products=[{"sku":"SKU-A","margin":5},{"sku":"SKU-B","margin":8},{"sku":"SKU-C","margin":3}]
forecast={("DS-North","SKU-A"):30,("DS-North","SKU-B"):50,("DS-North","SKU-C"):20,
("DS-South","SKU-A"):40,("DS-South","SKU-B"):25,("DS-South","SKU-C"):35}
for store,data in allocate_dark_stores(stores,products,forecast).items(): print(f"{store}: {data}")