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

In [224]:
import numpy as np
import simpy
import copy
In [225]:
def arrival(env,server,Rd,Output,st):
lmbda=7
for i in range(10):
inter_arrival=-1/lmbda*np.log(Rd.rand())
yield env.timeout(inter_arrival)
Output[“arrival”].append(env.now)
env.process(service(env,server,Rd,Output,st))

def service(env,server,Rd,Output,st):
rqt=server.request()
yield rqt
service_t=env.timeout(st)
yield service_t
server.release(rqt)
Output[“depart”].append(env.now)

def system(st,Rd):
env=simpy.Environment()
server=simpy.Resource(env,capacity=1)
Output={“arrival”:[],”depart”:[]}
env.process(arrival(env,server,Rd,Output,st))
env.run()
return np.mean(np.array(Output[“depart”])-np.array(Output[“arrival”]))

#no common random variable
def system_diff():
return system(0.2,np.random.RandomState())-system(0.1,np.random.RandomState())
diffs=[system_diff() for i in range(100)]
np.mean(diffs),np.std(diffs,ddof=1)/100**0.5
Out[225]:
(0.38248605607104863, 0.015852303414904435)
In [226]:
# common random variable
def system_diff():
R1=np.random.RandomState()
R2=copy.copy(R1)
return system(0.2,R1)-system(0.1,R2)
diffs=[system_diff() for i in range(100)]
np.mean(diffs),np.std(diffs,ddof=1)/100**0.5
Out[226]:
(0.3591806292655077, 0.011823157546275938)
In [227]:

In [228]:

In [229]: