[英]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.