Presentation is loading. Please wait.

Presentation is loading. Please wait.

17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)

Similar presentations


Presentation on theme: "17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)"— Presentation transcript:

1 17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)

2 Shortest path? In the BeeperHunt assignment, there are two “beepers” at all times Your robot has to choose which beeper to go after This may or may not be the closest beeper In any case, once your robot has chosen a beeper, it probably wants to find the shortest path to that beeper The maze is multiply-connected, that is, it’s a graph We have discussed two ways of finding a shortest path in a graph Breadth-first search Dijkstra’s algorithm

3 Breadth-first searching (in a tree) A breadth-first search (BFS) explores nodes nearest the root before exploring nodes further away For example, after searching A, then B, then C, the search proceeds with D, E, F, G Node are explored in the order A B C D E F G H I J K L M N O P Q J will be found before N LM N OP G Q H J IK FED BC A

4 How to do breadth-first searching Put the root node on a queue; while (queue is not empty) { remove a node from the queue; if (node is a goal node) return success; put all children of node onto the queue; } return failure; Just before starting to explore level n, the queue holds all the nodes at level n-1 In a typical tree, the number of nodes at each level increases exponentially with the depth In BeeperHunt, however, it will always be less than the number of cells in the maze—so this will not be a problem Breadth-first search does not automatically give the path to the goal—but that can be fixed

5 Searching a graph With certain modifications, any tree search technique can be applied to a graph This includes depth-first, breadth-first, depth-first iterative deepening, and other types of searches The difference is that a graph may have cycles We don’t want to search around and around in a cycle To avoid getting caught in a cycle, we must keep track of which nodes we have already explored There are two basic techniques for this: Keep a set of already explored nodes, or Mark the node itself as having been explored Either approach would work fine for BeeperHunt

6 Dijkstra’s algorithm Dijkstra’s algorithm is designed to find the shortest path in a graph when the edges have unequal costs In a maze, an “edge” is a single step between adjacent maze locations Every step has the same cost Dijkstra’s algorithm would work, but it’s more complicated than we need However, there is one idea in Dijkstra’s algorithm that we can use: Each time we find a (new shortest) path to a node, we set that node to point to it’s predecessor (where we just came from) This trick allows us to reconstruct our path

7 The End


Download ppt "17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)"

Similar presentations


Ads by Google