a-star - 路径未到达我的 A* 算法中的结束节点

标签 a-star netlogo

How to speed up least-cost path model at large spatial extents ,我尝试在 Netlogo 中编写 A* 算法,以在较大的空间范围内增加我的最低成本路径模型。这是我的代码:

to findPath [ID-start-node ID-end-node]

 let currentNodesInList [ ]
 let current-node node ID-start-node
 let end-node node ID-end-node
 ask current-node [ set color red]
 ask end-node [ set color red]

 set currentNodesInList lput current-node currentNodesInList

 while [not member? end-node currentNodesInList] [

 ask current-node [ 

 foreach sort nodes-on neighbors [ 

  ask ? [set f-value [link-cost] of link ([who] of current-node) ([who] of ?) + distance end-node] ]  

  let next-current-node min-one-of [nodes-on neighbors] of current-node [f-value]
  ask link ([who] of current-node) ([who] of next-current-node) [set color red]
  set current-node next-current-node

  set currentNodesInList lput current-node currentNodesInList] ]
end

当 ID-start-node 和 ID-end-node 在景观中接近时,代码似乎可以工作。但是,当 ID-start-node 和 ID-end-node 之间的距离较大时,路径不会到达 ID-end-node(见下图;但有时,代码有效)。

图中,ID-start-node和ID-end-node用红色起点表示,路径用红色绘制。

enter image description here

非常感谢您的帮助。

最佳答案

您可能想在 NetLogo 用户社区中查看此模型:

http://ccl.northwestern.edu/netlogo/models/community/Astardemo1

它实现了一个简单的过程(find-a-path),该过程将源补丁和目标补丁作为参数,并使用 A- 返回补丁列表(这是从源补丁到目标补丁的最短路径之一)星形最短路径寻找算法。

您也可以尝试关闭世界包装。

关于a-star - 路径未到达我的 A* 算法中的结束节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23438674/

相关文章:

algorithm - A*搜索邻居处理说明

artificial-intelligence - 详细的跳点搜索

c# - 如何使用 A* 管理 "no-path"场景

gis - 将栅格数据导入 NetLogo 会生成一列所有补丁变量 = 0

netlogo - 加载重复项/合并变量

python - 带有 turtle 和 tkinter 的 Python 可以替代 NetLogo 吗?哪个更值得花时间?

python - N-puzzle a-star python求解器效率

algorithm - 寻找有界子图之间的最小割集

netlogo - NetLogo与Java集成: when should we think about this integration as a good option?

netlogo - 如何让netlogo中的海龟死掉