In [5]:
import simpy
import numpy as np
In [6]:
Outcome={“arrival”:[],”depart”:[]}
def arrival():
lmbda=7
i=0
while True:
inter_arrival=-1/lmbda*np.log(np.random.rand())
yield env.timeout(inter_arrival)
i=i+1
Outcome[“arrival”].append(env.now)
env.process(service(i ))
def service(i ):
#requesting the server
rqt=desk.request()
#occupy/process the server request
yield rqt
yield env.timeout(0.2)
desk.release(rqt)
Outcome[“depart”].append(env.now)
np.random.seed(10)
env=simpy.Environment()
desk=simpy.Resource(env)
env.process(arrival())
T=1
env.run(until=T)
Outcome
Out[6]:
{‘arrival’: [0.037093016021343565,
0.590680886262285,
0.6558610738370955,
0.6971865265253847,
0.796634758364468],
‘depart’: [0.23709301602134358, 0.7906808862622849, 0.9906808862622849]}
In [7]:
Outcome={“arrival”:[],”depart”:[]}
def arrival():
lmbda=7
i=0
while True:
inter_arrival=-1/lmbda*np.log(np.random.rand())
yield env.timeout(inter_arrival)
i=i+1
Outcome[“arrival”].append(env.now)
env.process(service(i ))
def service(i ):
#requesting the server
Ql1=len(desk1.users)+len(desk1.queue)
Ql2=len(desk2.users)+len(desk2.queue)
#customer go with server 2 because fewer people are waiting for server 2
if Ql1>Ql2:
rqt2=desk2.request()
yield rqt2
yield env.timeout(0.2)
desk2.release(rqt2)
else:
rqt1=desk1.request()
yield rqt1
yield env.timeout(0.2)
desk1.release(rqt1)
#occupy/process the server request
desk.release(rqt)
Outcome[“depart”].append(env.now)
np.random.seed(10)
env=simpy.Environment()
desk1=simpy.Resource(env)
desk2=simpy.Resource(env)
env.process(arrival())
T=1
env.run(until=T)
Outcome
Out[7]:
{‘arrival’: [0.037093016021343565,
0.590680886262285,
0.6320063389505743,
0.8452290651062512],
‘depart’: [0.23709301602134358, 0.7906808862622849, 0.8320063389505743]}
In [0]:
In [0]: