[英]How to start consecutive processes of different classes
我正在使用 Simpy 在 Pytohn 中编写代码,为了模拟,我想将所有元素放在单独的类中,例如机器、运输工具、仓库……我正在编写代码,但我不知道如何编写一个过程之后是另一个过程:我希望材料的到达是独立的,每“8.8”分钟就会产生一种材料并进入第一台机器“切割”。 在切割过程结束时,我希望它在运输中被拾取,并且 go 到另一台机器。 由于进程在不同的类中,我不知道如何称呼它们? 我附上代码:
import numpy as np
import simpy
import math
import random
ARR_RATE_403=8.88
MACHINES_CUT=1
WORKERS_T_1_2=1
MACHINES_WEL=1
T_CUT_403=0.92 # mins
DIST_1_2= 80 # meters
SPEED=30
T_WEL_403=2.197
T_SIM=100
cables=0
unit=0
viajes_1to2=0
class Cut_403:
def __init__(self, env, arrival_rate_403, cut_time_403, num_cut_machines):
self.env=env
self.arrival_rate=arrival_rate_403
self.cut_time=cut_time_403
self.cut_machines=simpy.Resource(env, num_cut_machines)
self.access_done=self.env.event()
self.cut_done=self.env.event()
self.action = env.process(self.generate_403())
self.unit=0
def generate_403(self):
while True:
yield self.env.timeout(self.arrival_rate)
self.unit += 1
self.env.process(self.cutting())
def cutting(self):
global wait_1, pasa_1, arrive_1
#pasa_1=0
#wait_1=0
print('(C) ---> Unit {} of 403 arrives to cutting at {:.2f} min'.format(self.unit, self.env.now))
arrive_1=self.env.now
with self.cut_machines.request() as req:
yield req
pasa_1=env.now
wait_1=pasa_1-arrive_1
print('(C) *** Unit {} of 403 having waited {:.2f} min, pass to cutting machine at {:.2f} minute'.format(self.unit, wait_1, self.env.now))
#yield self.access_done.succeed()
yield self.env.timeout(self.cut_time)
#yield self.access_done
#yield self.cut_done
print('(C) \O/ Unit {} cutted in {} min, at {:.2f}'.format(self.unit, self.cut_time, self.env.now))
#%%
class Transport_1to2_403:
def __init__(self, env, workers_1to2, distance, speed, unit):
self.env=env
self.workers=simpy.Resource(env, workers_1to2)
self.transp_time=distance/speed
self.unit=unit
def moving(self):
global wait_t, pasa_t, arrive_t
#wait_t=0
#pasa_t=0
print('(T) ... Unit {} of 403 having waited {:.2f} min, is taken for transport in cutting at {:.2f}'.format(self.unit, wait_t, self.env.now))
arrive_t=self.env.now
with self.workers.request() as req:
yield req
pasa_t=self.env.now
wait_t=pasa_t-arrive_t
yield self.env.timeout(self.transp_time)
#viajes_1to2 += 1
print('(T) ... Unit {} moved from cutting to welding in {:.2f} min, at {:.2f}'.format(self.unit, self.transp_time, self.env.now))
yield self.env.timeout(self.transp_time)
#viajes_1to2 += 1
print('(T) ... Worker come back to cutting from welding in {:.2f} min, at {:.2f}'.format(self.transp_time, self.env.now))
env = simpy.Environment() # Unique environment defined
cut=Cut_403(env, ARR_RATE_403, T_CUT_403, MACHINES_CUT)
trans=Transport_1to2_403(env, WORKERS_T_1_2, DIST_1_2, SPEED, unit) #doubt
env.run(until=T_SIM)
谢谢!
我想要的 output 是一个过程,其中每 8.8 分钟生成一次材料输入,它进入切割机(如果有空),完成后进入运输(如果操作员有空,因为他回去和第四),如果没有,它就在运输室等待(如果操作员有空,因为他来回),如果没有,它就在运输室等待(如果操作员有空)。
我建议仔细看看洗车的例子。 听起来您的材料具有到达时间间隔,然后通过“剪切”处理,然后“传输”并附有每个资源。 我在这里看不到它,但我建议创建第二个 class 用于传输。
此外,我还建议将 function 用于与洗车示例中的“汽车”类似的材料。 这样“材料”可以与“剪切”和“传输”交互,并且应该类似地传递给 object。https://simpy.readthedocs.io/en/latest/examples/carwash.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.