Best First Search algorithm in Scheme

╄→尐↘猪︶ㄣ 提交于 2019-11-29 15:33:28

Ok, so the first thing you do is discretize your search space. Using your example of a 5x5 grid, this means you have a total of 25 points your robot can occupy.

Then, you select your search algorithm. You've chosen Greedy Best First Search (GBFS), so let's go with that, but in a real situation you should choose it as per your problem requirements.

GBFS is a simple algorithm and requires the following ( and you'll need most of these modules for any path finding algorithm):

  1. A function to list all the neighbors of any node. E.g. in the grid we've specified above, the neighbors are trivially determined (+1,-1 permutations in both directions with some boundary checking and of course, check if it's an obstacle).

  2. A data structure to keep track of Open nodes: Open nodes are nodes which are yet to be examined. So in the example code in Wikipedia, you start with the initial position, find its successors (using the above function) and based on a heuristic (you can use the Euclidean or Manhattan distance between the goal and the successor as a heuristic) you add it to the Open "list" - which is better implemented as a priority queue.

  3. Your main function: This will essentially start with the initial position (1,5) and find its neighbors and add them to the priority queue based on the Euclidean distance to the goal. Then recurse (i.e. do the same thing as what you did with the initial position) on that list until you find your goal.

So, what you should note about Greedy Best First is you may not have the optimal path, but you're guaranteed termination and a path (if one exists). You should think about other algorithms like A* or Breadth First or Depth First and see what works for your requirements.

Probably related: C#: A-Star is born at CodeProject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!