CS计算机代考程序代写 In [1]:

In [1]:
import simpy
import numpy as np
In [2]:
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[2]:
{‘arrival’: [0.037093016021343565,
0.590680886262285,
0.6558610738370955,
0.6971865265253847,
0.796634758364468],
‘depart’: [0.23709301602134358, 0.7906808862622849, 0.9906808862622849]}
In [3]:
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(service1(i ))

#regsitration
def service1(i ):
#requesting the server
rqt=receptionist.request()
#occupy/process the server request
yield rqt
yield env.timeout(0.2)
receptionist.release(rqt)
env.process(service2(i))

#Outcome[“depart”].append(env.now)

#seeing the doctor

def service2(i ):
#requesting the server
rqt=doctor.request()
#occupy/process the server request
yield rqt
yield env.timeout(0.2)
doctor.release(rqt)
Outcome[“depart”].append(env.now)

np.random.seed(10)
env=simpy.Environment()
receptionist=simpy.Resource(env,capacity=1)
doctor=simpy.Resource(env,capacity=1)

env.process(arrival())

T=1
env.run(until=T)
Outcome
Out[3]:
{‘arrival’: [0.037093016021343565,
0.590680886262285,
0.6558610738370955,
0.6971865265253847,
0.796634758364468],
‘depart’: [0.4370930160213436, 0.9906808862622849]}
In [4]:
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(service1(i ))

def service1(i ):
#regsitration

rqt=receptionist.request()
#occupy/process the server request
yield rqt
yield env.timeout(0.2)
receptionist.release(rqt)

#seeing the doctor
rqt=doctor.request()
#occupy/process the server request
yield rqt
yield env.timeout(0.2)
doctor.release(rqt)
Outcome[“depart”].append(env.now)

np.random.seed(10)
env=simpy.Environment()
receptionist=simpy.Resource(env,capacity=1)
doctor=simpy.Resource(env,capacity=1)

env.process(arrival())

T=1
env.run(until=T)
Outcome
Out[4]:
{‘arrival’: [0.037093016021343565,
0.590680886262285,
0.6558610738370955,
0.6971865265253847,
0.796634758364468],
‘depart’: [0.4370930160213436, 0.9906808862622849]}
In [5]:
#stop the system once everyone arrived before 1 departs
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
if env.now<=1: Outcome["arrival"].append(env.now) env.process(service1(i )) else: break def service1(i ): #regsitration rqt=receptionist.request() #occupy/process the server request yield rqt yield env.timeout(0.2) receptionist.release(rqt) #seeing the doctor rqt=doctor.request() #occupy/process the server request yield rqt yield env.timeout(0.2) doctor.release(rqt) Outcome["depart"].append(env.now) np.random.seed(10) env=simpy.Environment() receptionist=simpy.Resource(env,capacity=1) doctor=simpy.Resource(env,capacity=1) env.process(arrival()) env.run() Outcome Out[5]: {'arrival': [0.037093016021343565, 0.590680886262285, 0.6558610738370955, 0.6971865265253847, 0.796634758364468], 'depart': [0.4370930160213436, 0.9906808862622849, 1.1906808862622849, 1.3906808862622848, 1.5906808862622848]}