-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributor.py
39 lines (29 loc) · 1.6 KB
/
distributor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Código responsável pela distribuição da produção das fábricas para os estoques:
# sejam estoques de fábricas ou centro de distribuições (CDDs)
def sendProduction(supplySites, depots):
for key in supplySites:
supplySite = supplySites[key]
for SKU in supplySite.availableToDeploy:
recipients = supplySite.recipients[SKU] # CDDs que estão na lista de envios da fábrica atual
availableToDeploy = supplySite.availableToDeploy[SKU]
depotsSortedByNeed = sortDepotsByNeed(recipients, depots, SKU)
priorityBasedDistribution(supplySite, SKU, availableToDeploy, depotsSortedByNeed)
# Ordena os depósitos de acordo com suas necessidades para o SKU, da maior para o menor
def sortDepotsByNeed(recipients, depots, SKU):
resultList = []
for depotCode in recipients:
resultList.append(depots[depotCode])
resultList.sort(key=lambda depot: depot.calculePriority(SKU), reverse=True)
return resultList
def priorityBasedDistribution(supplysite, SKU, availableToDeploy, depotsSortedByNeed):
while availableToDeploy > 0:
for depot in depotsSortedByNeed:
priority = depot.calculePriority(SKU)
hectolitersToSend = 1 * priority
if availableToDeploy < hectolitersToSend:
hectolitersToSend = availableToDeploy
sendFromTo(supplysite, depot, SKU, hectolitersToSend)
availableToDeploy -= hectolitersToSend
def sendFromTo(supplysite, depot, SKU, toSend):
supplysite.removeSKUsToDeploy(SKU, toSend)
depot.addSKUClosingStock(SKU, toSend)