路径未到达我的A *算法中的末端节点 [英] The path does not reach the end node in my A* algorithm

查看:96
本文介绍了路径未到达我的A *算法中的末端节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着如何进行加快在大空间范围内的最小成本路径模型,我尝试在Netlogo中编写A *算法,以在大空间范围内增加我的最小成本路径模型.这是我的代码:

Following on from How to speed up least-cost path model at large spatial extents, I tried to code an A* algorithm in Netlogo to increase my least-cost path model at large spatial extents. Here is my code:

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起点节点与ID终点节点之间的距离较大时,路径不会到达ID终点节点(请参见下图;但有时,代码可以工作).

When ID-start-node and ID-end-node are close in the landscape, the code seems to work. However, when the distance between ID-start-node and ID-end-node is higher, the path does not reach the ID-end-node (see figure below; but sometimes, the code works).

在图中,ID起点节点和ID终点节点用红色起点表示,路径用红色绘制.

In the figure, ID-start-node and ID-end-node are represented by a red start and the path is drawn in red.

非常感谢您的帮助.

推荐答案

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

You might want to take a look at this model in the NetLogo users community:

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

它实现了一个简单的过程(查找路径),该过程使用源补丁程序和目标补丁程序作为参数,并使用以下命令返回补丁程序列表(这是从源补丁程序到目标补丁程序的最短路径之一). A-star最短路径查找算法.

It implements a simple procedure (find-a-path) that takes in the source and the target patches as parameters and returns a list of patches (which is one of the shortest paths from the source patch to the destination patch) using the A-star shortest path finding algorithm.

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

Also you might try turning off world wrapping.

这篇关于路径未到达我的A *算法中的末端节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆