In [4]:
import numpy as np
import simpy
import matplotlib.pyplot as plt
%matplotlib inline
In [5]:
def arrival(env,desk,Outputs):
lmbda=10
i=0
while True:
inter_arrival=-1/lmbda*np.log(np.random.rand())
yield env.timeout(inter_arrival)
#one new arrival
i+=1
#this id will be shared with the serivce process
env.process(service(i ,env ,desk,Outputs))
def service(i,env ,desk,Outputs):
#requesting the server
if np.random.rand()>0.9:
VIP=1
rqt=desk.request(priority=0)
else:
VIP=0
rqt=desk.request(priority=1)
Outputs[“VIP”].append(VIP)
Outputs[“arrivals”].append(env.now)
yield rqt
yield env.timeout(0.4)
desk.release(rqt)
Outputs[“departures”].append(env.now)
Outputs[“Depart_ID”].append(i)
np.random.seed(50)
def system_sim():
env=simpy.Environment()
Outputs={“arrivals”:[], “departures”:[], “VIP”:[], “Depart_ID”:[]}
desk=simpy.PriorityResource(env,capacity=10)
env.process(arrival(env,desk,Outputs))
T=5
env.run(until=T)
return len(Outputs[“Depart_ID”])
system_sim()
Out[5]:
51
In [6]:
number_received_s=np.array([system_sim() for i in range(1000)])
vals, counts=np.unique(number_received_s,return_counts=True)
vals,counts
Out[6]:
(array([27, 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, 64, 65, 67, 68]),
array([ 1, 5, 1, 9, 4, 11, 8, 22, 13, 22, 31, 37, 43, 49, 43, 51, 46,
56, 60, 57, 47, 62, 53, 42, 39, 36, 25, 22, 23, 15, 14, 17, 13, 7,
7, 3, 3, 1, 2]))
In [7]:
In [8]:
In [9]:
In [10]: