-
Notifications
You must be signed in to change notification settings - Fork 0
/
process simulation.py
69 lines (68 loc) · 1.92 KB
/
process simulation.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
68
69
import random, sys
r=None
w=None
k=None
m=None
inv=None
day=1
rnd=random.Random(98765)
class orderclass:
queue=[]
qlen=0
nshipped=0
towait=0
nshipedq=0
towaitq=0
qleftoverfromlastnight=False
def _init_(self,nw):
self.numpending=nw
self.dayorderreceived=g.day
self.arrivedtoq=orderclass,qleftoverfromlastnight
orderclass.queue.append(self)
orderclass.qlen+=1
def simdaytime():
orderclass.qleftoverfromlastnight=len(orderclass.queue) > 0
numneworders=g.rnd.randit(0,g.k)
for o in range(numneworders):
nwidgets=g.rnd.randit(1,g.m)
neworder=orderclass(nwidgets)
while True:
if orderclass.queue==[]:
return
o=orderclass.queue[0]
if o.numpending<=g.inv:
partfill=False
orderclass.queue.remove(o)
orderclass.qlen-=1
sendtoday=o.numpending
g.inv-=sendtoday
else:
partfill=True
sendtoday=g.inv
o.numpending-=g.inv
g.inv=0
orderclass.nshipped+=sendtoday
waittime=g.day-o.dayorderreceived
orderclass.towait+=sendtoday*waittime
if o.arrivedtoq:
orderclass.nshipedq+=sendtoday
orderclass.towaitq+=sendtoday*waittime
if partfill:
return
simdaytime=staticmethod(simdaytime)
def simevening():
if g.inv+g.r<=g.w:g.inv+=g.r
else:
g.inv=g.w
simevening=staticmethod(simevening)
def mai():
g.r=int(sys.argv[1])
g.w=int(sys.argv[2])
g.k=int(sys.argv[3])
g.m=int(sys.argv[4])
g.inv=int(sys.argv[5])
ndays=int(sys.argv[6])
for g.day in range(ndays):
orderclass.simdaytime()
orderclass.simevening()
print(orderclass.towait/float(orderclass.nshipped))