Debian Codegraph @

docs/source/Manuals/programs/levelinventory.py

raw symbols SCIP
1 from random import normalvariate, seed
2 from SimPy.Simulation import (Level, Process, activate, get, initialize, hold,
3 now, put, simulate)
4
5
6 class Deliver(Process):
7 def deliver(self): # an "offeror" PEM
8 while True:
9 lead = 10.0 # time between refills
10 delivery = 10.0 # amount in each refill
11 yield put, self, stock, delivery
12 print('at %6.4f, add %6.4f units, now amount = %6.4f' %
13 (now(), delivery, stock.amount))
14 yield hold, self, lead
15
16
17 class Demand(Process):
18 stockout = 0.0 # initialize initial stockout amount
19
20 def demand(self): # a "requester" PEM
21 day = 1.0 # set time-step to one day
22 while True:
23 yield hold, self, day
24 dd = normalvariate(1.20, 0.20) # today's random demand
25 ds = dd - stock.amount
26 # excess of demand over current stock amount
27 if dd > stock.amount: # can't supply requested amount
28 yield get, self, stock, stock.amount
29 # supply all available amount
30 self.stockout += ds
31 # add unsupplied demand to self.stockout
32 print('day %6.4f, demand = %6.4f, shortfall = %6.4f' %
33 (now(), dd, -ds))
34 else: # can supply requested amount
35 yield get, self, stock, dd
36 print('day %6.4f, supplied %6.4f, now amount = %6.4f' %
37 (now(), dd, stock.amount))
38
39
40 stock = Level(monitored=True) # 'unbounded' capacity and other defaults
41
42 seed(99999)
43 initialize()
44
45 offeror = Deliver()
46 activate(offeror, offeror.deliver())
47 requester = Demand()
48 activate(requester, requester.demand())
49
50 simulate(until=49.9)
51
52 result = (stock.bufferMon.mean(), requester.stockout)
53 print('')
54 print('Summary of results through end of day %6.4f:' % int(now()))
55 print('average stock = %6.4f, cumulative stockout = %6.4f' % result)