-
Notifications
You must be signed in to change notification settings - Fork 1
/
factory.py
67 lines (50 loc) · 2.42 KB
/
factory.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from Settings import (CUSTOMER_INITIAL_ORDERS, TARGET_STOCK)
from SupplyChainActor import SupplyChainActor
from SupplyChainQueue import SupplyChainQueue
class Factory(SupplyChainActor):
def __init__(self, incomingOrdersQueue, outgoingOrdersQueue, incomingDeliveriesQueue, outgoingDeliveriesQueue, productionDelayWeeks):
# Initializes the Factory object in its initial state
# by calling parent constructor and setting the
# retailer's customer.
super().__init__(incomingOrdersQueue, outgoingOrdersQueue, incomingDeliveriesQueue, outgoingDeliveriesQueue)
self.BeerProductionDelayQueue = SupplyChainQueue(productionDelayWeeks)
#We assume that the factory already has some runs in production. This is in the rules, and ensures initial stability.
self.BeerProductionDelayQueue.PushEnvelope(CUSTOMER_INITIAL_ORDERS)
self.BeerProductionDelayQueue.PushEnvelope(CUSTOMER_INITIAL_ORDERS)
return
def ProduceBeer(self, weekNum):
if weekNum <= 4:
amountToOrder = 4
#After first few weeks, the actor chooses the order. We use "anchor and maintain" strategy.
else:
#We want to cover any outflows
amountToOrder = 0.5 * self.currentOrders
if (TARGET_STOCK - self.currentStock) > 0:
amountToOrder += TARGET_STOCK - self.currentStock
self.BeerProductionDelayQueue.PushEnvelope(amountToOrder)
self.lastOrderQuantity = amountToOrder
return
def FinishProduction(self):
# Updates currentStock to reflect the beer
# that the factory just brewed.
# -------------------------------------------------------
amountProduced = self.BeerProductionDelayQueue.PopEnvelope()
if amountProduced > 0:
self.currentStock += amountProduced
return
def TakeTurn(self, weekNum):
#The steps for taking a turn are as follows:
#PREVIOUS PRODUCTION RUNS FINISH BREWING.
self.FinishProduction()
#RECEIVE NEW ORDER FROM DISTRIBUTOR
self.ReceiveIncomingOrders() #This also advances the queue!
#PREPARE DELIVERY
if weekNum <= 4:
self.PlaceOutgoingDelivery(4)
else:
self.PlaceOutgoingDelivery(self.CalcBeerToDeliver())
#PRODUCE BEER
self.ProduceBeer(weekNum)
#UPDATE COSTS
self.costsIncurred += self.CalcCostForTurn()
return