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

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

问题描述

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

您也可以尝试关闭世界环绕.

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

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).

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

Thanks very much for your help.

解决方案

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

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

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天全站免登陆