gpt4 book ai didi

grid - 网格/仓库布局上离散事件模拟的可视化

转载 作者:行者123 更新时间:2023-12-01 20:20:10 26 4
gpt4 key购买 nike

我需要模拟一个仓库,其中有几辆自动驾驶车辆在给定的布局上移动,并具有简单的优先级规则。根据我的理解,这个问题可以通过离散事件模拟(DES)轻松解决,我会使用 SimPy为了这。

我看到的问题是,我似乎很难想象这些车辆的实际轨迹和相互作用。当然,我可以记录所有时期内所有车辆的所有位置,但是如何继续创建可视化呢?

最愚蠢的方法是创建一百万张图片,但必须有更好的方法。是否有任何库或工具可以通过在背景之前移动符号来可视化网格上对象的移动?

另一种选择是使用基于代理的方法和像 AnyLogic 这样的软件。 ,但这对我来说似乎更复杂,我想应用 DES 方法,最好使用开源软件。

最佳答案

我建议查看 tkinter 库。我们使用它来完成所有简单的可视化。

这是可以实现的动画类型的一个非常基本的示例,请原谅戏剧性的镜头:https://www.youtube.com/watch?v=xnZQ0f--Ink

这里是源代码,大致描述了您在上面看到的内容:https://github.com/harrymunro/Simulations/blob/master/termini_simulation_animation.py

这是动画组件的复制粘贴:

################ SET UP ANIMATION CANVAS #################
class Train:
def __init__(self, canvas, x1, y1, x2, y2, tag):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.canvas = canvas
self.train = canvas.create_rectangle(self.x1, self.y1, self.x2, self.y2, fill="red", tags = tag)
self.train_number = canvas.create_text(((self.x2 - self.x1)/2 + self.x1), ((self.y2 - self.y1)/2 + self.y1), text = tag)
self.canvas.update()

def move_train(self, deltax, deltay):
self.canvas.move(self.train, deltax, deltay)
self.canvas.move(self.train_number, deltax, deltay)
self.canvas.update()

def remove_train(self):
self.canvas.delete(self.train)
self.canvas.delete(self.train_number)
self.canvas.update()

class Clock:
def __init__(self, canvas, x1, y1, x2, y2, tag):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.canvas = canvas
self.train = canvas.create_rectangle(self.x1, self.y1, self.x2, self.y2, fill="#fff")
self.time = canvas.create_text(((self.x2 - self.x1)/2 + self.x1), ((self.y2 - self.y1)/2 + self.y1), text = "Time = "+str(tag)+"s")
self.canvas.update()

def tick(self, tag):
self.canvas.delete(self.time)
self.time = canvas.create_text(((self.x2 - self.x1)/2 + self.x1), ((self.y2 - self.y1)/2 + self.y1), text = "Time = "+str(tag)+"s")
self.canvas.update()


if show_animation == True:
animation = Tk()
#bitmap = BitmapImage(file="uxbridge.bmp")

im = PhotoImage(file="uxbridge_resized.gif")

canvas = Canvas(animation, width = 800, height = 400)
canvas.create_image(0,0, anchor=NW, image=im)
animation.title("Uxbridge Termini Simulation")

canvas.pack()

#### matplotlib plots


if show_animation == True and hide_plots == False:
f = plt.Figure(figsize=(5,4), dpi=100)

a1 = f.add_subplot(221) # mean headway
a2 = f.add_subplot(222) # TPH meter
a3 = f.add_subplot(223) # headway distribution
a4 = f.add_subplot(224) # train count

a1.plot()
a2.plot()
a3.plot()
a4.plot()

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

dataPlot = FigureCanvasTkAgg(f, master=animation)
dataPlot.show()
dataPlot.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
f.tight_layout()

canvas.pack()

# platforms
if show_animation == True:
canvas.create_rectangle(50, 100, 200, 150, fill = "yellow")
canvas.create_rectangle(50, 200, 200, 250, fill = "yellow")

canvas.create_line(50, 75, 200, 75, fill="green", width=3) # platform 4
canvas.create_line(50, 175, 200, 175, fill="green", width=3) # platform 2/3
canvas.create_line(50, 275, 200, 275, fill="green", width=3) # platform 1

canvas.create_text(125, 110, text = "Platform 4")
canvas.create_text(125, 140, text = "Platform 3")
canvas.create_text(125, 210, text = "Platform 2")
canvas.create_text(125, 240, text = "Platform 1")

# track
canvas.create_line(200, 75, 650, 75, fill="green", width=3) # platform 4 run out
canvas.create_line(200, 175, 650, 175, fill="green", width=3) # platform 2/3 run in
canvas.create_line(300, 175, 400, 75, fill="green", width=3)
canvas.create_line(450, 75, 600, 175, fill="green", width=3)
canvas.create_line(450, 175, 600, 75, fill="green", width=3)
canvas.create_line(200, 275, 300, 275, fill="green", width=3)
canvas.create_line(300, 275, 400, 175, fill="green", width=3)

############ END OF CANVAS #################

关于grid - 网格/仓库布局上离散事件模拟的可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43582088/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com