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

In [1]:
import simpy
import numpy as np
In [9]:
def arrival():
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 ))

def service(i ):
print(i,”arrival”, env.now)
#requesting the server
rqt=desk.request()
#occupy/process the server request
yield rqt
print(i, “start the service”, env.now)
yield env.timeout(0.4)
print(i, “end the service”, env.now)
desk.release(rqt)

np.random.seed(50)
env=simpy.Environment()
env.process(arrival())

desk=simpy.Resource(env)

T=1
env.run(until=T)

1 arrival 0.07040025968926293
1 start the service 0.07040025968926293
2 arrival 0.21820478201329913
3 arrival 0.3546682754338475
4 arrival 0.4472191063545232
1 end the service 0.47040025968926297
2 start the service 0.47040025968926297
5 arrival 0.544686570127387
6 arrival 0.545029735250476
7 arrival 0.6346302239701069
8 arrival 0.6605210290470429
9 arrival 0.6878941216959054
10 arrival 0.8050094041867255
2 end the service 0.870400259689263
3 start the service 0.870400259689263
11 arrival 0.9109847592802578
In [10]:
def arrival():
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 ))

def service(i ):

#requesting the server
#vip customer
if np.random.rand()>0.9:
rqt=desk.request(priority=0)
vip=”vip”
#regular customer
else:
rqt=desk.request(priority=1)
vip=”non-vip”
print(i,”arrival”, env.now, vip)
#occupy/process the server request
yield rqt
print(i, “start the service”, env.now, vip)
yield env.timeout(0.4)
print(i, “end the service”, env.now, vip)
desk.release(rqt)

np.random.seed(50)
env=simpy.Environment()
env.process(arrival())

desk=simpy.PriorityResource(env)

T=1
env.run(until=T)

1 arrival 0.07040025968926293 non-vip
1 start the service 0.07040025968926293 non-vip
2 arrival 0.21820478201329913 non-vip
3 arrival 0.3107556129339748 non-vip
4 arrival 0.31109877805706393 non-vip
5 arrival 0.33698958313399996 non-vip
6 arrival 0.4541048656248201 non-vip
1 end the service 0.47040025968926297 non-vip
2 start the service 0.47040025968926297 non-vip
7 arrival 0.5585841115044008 vip
8 arrival 0.5613556991258442 non-vip
9 arrival 0.6193452089941557 non-vip
10 arrival 0.6312010383818577 non-vip
11 arrival 0.7250834476572042 vip
12 arrival 0.7896900566570311 non-vip
13 arrival 0.8456613488404956 non-vip
2 end the service 0.870400259689263 non-vip
7 start the service 0.870400259689263 vip
In [57]:

In [0]: