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

Mar*_*ine 5 a-star netlogo

继续如何在大空间范围内加速最低成本路径模型之后,我尝试在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
Run Code Online (Sandbox Code Playgroud)

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

在该图中,ID-start-node和ID-end-node由红色开始表示,路径以红色表示.

在此输入图像描述

非常感谢您的帮助.

小智 5

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

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

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

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