我正在为一个大型仓库操作建模(请参见下图)。
我已经在每个面片(绿点)上实现了一个顶点并将其链接起来,这样我就可以计算出从每个顶点到所有其他顶点的最短路径(使用dijkstra算法),并存储在每个顶点的表(字典)中。此过程在设置阶段完成,非常耗时。然后,黄色库存单元(矩形)将发出完成任务的需求请求。
叉车(有些在路上)假设不忙时停留在顶点(节点)之一上。收到需求请求时,它将要求其当前的固定顶点(节点)获取要到达的库存单元的starting_node和end_node。然后,叉车要求starting_node从其表中获取最短路径,以获取最短路径(节点组合)并驶向end_node(黄色单元格)。
目前,黄色牢房只是在仓库中随机挑选免费的叉车。作为进一步的发展,我想添加一个功能,该功能允许黄色单元格根据实际距离(而不是Netlogo中内置的欧氏距离)来识别最接近它的免费卡车。由于卡车很多,因此使用“ foreach”遍历所有可用卡车并使用上述方法计算实际距离不是很好。您可以使用原始的“距离我自己”来快速定位卡车,但这并不准确。有没有一种更快的计算方法来识别最近的卡车的好方法?
答案 0 :(得分:2)
我不知道这是否适用于您当前的设置,但是您可能还会发现B
扩展名很有帮助。例如,尝试以下设置(我为您的长度表示歉意,只是近似您的世界):
nw
提供一个像这样的简单世界:
您可以使用extensions [ nw ]
breed [ nodes node ]
breed [ trucks truck ]
breed [ cells cell ]
to setup
ca
resize-world -29 29 -14 14
ask patches with [ ( pxcor mod 5 = 0 or pycor = 0 ) ] [
set pcolor grey
sprout-nodes 1 [
set size 0.5
set shape "circle"
set color green
]
]
ask nodes [
create-links-with turtles-on neighbors4 [
set color green
]
]
ask n-of 5 nodes [
hatch 1 [
set size 1
set color red
set breed trucks
set shape "car"
]
]
ask n-of 2 trucks [
set color blue
]
ask one-of nodes [
ask one-of neighbors with [ pcolor = black ] [
sprout-cells 1 [
set size 1.5
set shape "box"
set color yellow
]
]
]
reset-ticks
end
扩展名即时计算距离,而不必将其存储在每个单元格表中,并使叉车(此处为卡车)遵循最短路径。评论中的更多详细信息:
nw
这有一个黄色框,它根据返回的to summon-nearest-truck
; Treat blue trucks as 'empty' and ready to go to a cell
let ready-trucks trucks with [ color = blue ]
; Get the nodes associated with those ready trucks
let truck-proxies turtle-set map [ i -> [nodes-on patch-here] of i ] sort ready-trucks
; Randomly ask one of the cells to
ask one-of cells [
; Choose one of the neighboring road nodes as a proxy for distance calculation
let node-proxy one-of nodes-on neighbors4
; Get the node proxy to:
ask node-proxy [
; Find the nearest (by network distance) trucks, and select the node
; located on the same patch as that truck
let my-truck-proxy min-one-of truck-proxies [length ( nw:turtles-on-path-to myself) ]
; Get that truck-proxy node to generate the path to the original asking node
; and have the appropriate truck follow that path
ask my-truck-proxy [
; Generate the path to follow
let path-to-follow nw:turtles-on-path-to myself
; Highlight that path for visualization
ask turtle-set path-to-follow [
set color orange
]
; Get the truck ready to move
let ready-truck one-of trucks-here with [ color = blue ]
ask ready-truck[
set color yellow
]
; Move that truck along the path-to-follow
ask ready-truck [
foreach path-to-follow [
n ->
face n
move-to n
; For visualization only
wait 0.1
]
]
]
]
]
end
的长度来召唤最近的卡车。那辆卡车沿着通往召唤节点的路径走: