定期从SimPy中的一个数据帧接收任务



我开始使用SimPy模拟制造环境。我有一个生成的DataFrame,其中包含一定数量的任务(每个任务的属性:ID、start_location、end_location,时间、距离(。

我想在SimPy中实现一个过程,将上述DataFrame的第一个任务(第一行(传递给模拟中的其他DataFrame。每个Tak应当在随机生成的时间CCD_ 1之后周期性地通过。之后应该执行。有人知道如何在SimPy环境中实现这一点吗?使用env.timeout(random.normalvariate(45s, 15s)函数有意义吗?如果是,具体的实施方法是什么?

我将感谢任何形式的帮助。

听起来需要一个主控制器sim进程,您可以将所有数据输入传递到该进程。然后,该控制器使用传入的数据来构建和管理sim。这是一个非常简单的例子,但我已经做了运输模拟,其中我的输入是地点、旅行时间和卡车时间表,包括出发地点、出发时间和目的地地点。控制器将创建位置,并用于根据需要安排创建和移动卡车。

"""
quick sim demo with a controler process that
works through a dataframe generating processes
that model what is being simulated
Programmer: Michael R. Gibbs
"""
from pkg_resources import Environment
import simpy
import random
import pandas as pd
def sim_process(env, id, dur):
"""
This would be one of several processes
that would make up the simulation
"""
print(f'{env.now} starting task {id}')
yield env.timeout(dur)
print(f'{env.now} finished task {id}')
def controlProcess(env, df):
"""
controls the simulation by reading
a dataframe and generating sim processes as needed.
This controler is building the sim.
This example just has one sim porcess, but can be
much more complicated
"""
# loop the dataframe and gen sim processes
for _, row in df.iterrows():
# wait
yield env.timeout(random.normalvariate(45, 15))
# not no yield here, create and move on
env.process(sim_process(env,row['id'], row['dur']))
# start up
# get dataframe
df = pd.DataFrame(
[
['task 1', 40],
['task 2', 50],
['task 3', 60],
['task 4', 40],
['task 5', 50],
['task 6', 60],
['task 7', 40],
['task 8', 50],
['task 9', 60],
['task 10', 40]
],
columns=['id','dur']
)
# boot sime
env = simpy.Environment()
env.process(controlProcess(env, df))
env.run(1000)

最新更新