简体   繁体   English

在 Scheme/Racket 中实现 A* 搜索算法

[英]Implementing the A* search algorithm in Scheme/Racket

I am looking forward to implement the A* search algorithm but I dont know where I should really start.我期待着实现 A* 搜索算法,但我不知道我应该从哪里真正开始。 I came up with a way to represent my graph like so:我想出了一种方法来表示我的图表,如下所示:

(
'("city1" (x y (("neighbour1" edgeWeight1)("neighbour2" edgeWeight2))))
...
)

I created an openlist and a closedlist, but from this point on I don't really know what to do.我创建了一个开放列表和一个封闭列表,但从这一点开始,我真的不知道该怎么做。 Any ideas?有任何想法吗?

The first thing you should do when trying to implement an algorithm is implementing the abstractions the algorithm uses.尝试实现算法时应该做的第一件事是实现算法使用的抽象。

The A* search algorithm uses two abstractions. A* 搜索算法使用两个抽象。 The first abstraction is that of a graph.第一个抽象是图的抽象。 You should come up with some definition of a graph and implement functions to do "graph-y things" that A* requires (eg getting the neighbours of a given node, finding all nodes in a graph, etc.).你应该想出一些图的定义并实现函数来做 A* 需要的“图的事情”(例如,获取给定节点的邻居,查找图中的所有节点等)。

The second abstraction which A* search uses is that of a priority queue, which is used for the "open set". A* 搜索使用的第二个抽象是优先级队列,它用于“开放集”。 You will need to come up a Scheme definition for the "open set" and write Scheme functions to do the things which must be done (ie find and remove the node with the lowest cost).您将需要为“开放集”提供一个方案定义,并编写方案函数来完成必须完成的事情(即找到并删除成本最低的节点)。

Once you do those things, you should find the algorithm to be fairly straightforward.一旦你做了这些事情,你应该会发现算法相当简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM