Published on

Published in: Technology, Art & Photos
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. PATHFINDINGPelotas, August 16, 2012Vinicius SilvaFlash Page 1
  2. 2. Pathfinding Pathfinding or pathing refers to the plotting, by a computer application, of the shortest routebetween two points. It is a more practical variant on solving mazes Page 2
  3. 3. A* algorithm A* uses a best-first search and finds a least-costpath from a given initial node to one goal node (outof one or more possible goals). As A* traverses the graph, it follows a path of the lowest known heuristic cost, keeping a sorted priority queue of alternate path segments along the way. Page 3
  4. 4. A* algorithm Green – start Red – Goal Blue - Walls Page 4
  5. 5. A* algorithm (starting the search)1- Starting from A, add the node to a “open list” of nodes to be considered. The “open list” is like a shop list, at this moment we just have only one node on our list.Basically is a list of the nodes that must be verified. Page 5
  6. 6. A* algorithm (starting the search) 2- Look at all reachable nodes, neighbors that are not walls, water or any other unreachable node. Add all of them to the “open list”, for each one ofthe nodes, save the previous node (in this case node A) as a father node. This reference will be crucial when we want ot make the trackback. Page 6
  7. 7. A* algorithm (starting the search)3- Remove A from your “open list” and add it to a“closed list” of nodes that you should not search again. Page 7
  8. 8. A* algorithm(starting the search) 3- Now we have a lot of itens to choose on our “open list”, but, which one to choose? Page 8
  9. 9. A* algorithm (Filtering nodes)You have to search on the “open list” the node with the smaller value for F, where F=G+HAditionally,G = cost to arrive until this pointH = estimated cost to arrive on the goal, from thecurrent node, called heuristic Page 9
  10. 10. A* algorithm (Filtering nodes) Heuristic is a way to guess about something, youcannot assume that the heuristic is the best value, b but how you still don’t know how to arrive to thegoal you have to guess if you are getting warmer or colder. In our case we are going use the sum of nodes on the horizontal and vertical directions from the current node to the goal. (Manhattan method)Page 10
  11. 11. A* algorithm (Filtering nodes) After calculating F, G and H we have the following situation Page 11
  12. 12. A* algorithm (Continuing the search) To continue the search just take the node with minor value of F on the “open list”, then1- Remove it from the “open list” and add it to the “closed list”. Page 12
  13. 13. A* algorithm (Continuing the search) 2 – Check all neighbors nodes, ignoring the ones that are on the “closed list” or are not reachable(walls, water, ...), add them to the “open list” if they are not already. Make sure to reference the father node to the new ones. Page 13
  14. 14. A* algorithm (Continuing the search) 3 – If one of the neighbors nodes are on the “openlist” you must check if the new path is shorter than the previous, if is greater, do nothing.But if is really shorter, you must update the value of G on this node and it father node, ignoring the previous path taken. Page 14
  15. 15. A* algorithm(Continuing the search) Page 15
  16. 16. A* algorithm (Finishing the search) When we should stop? There are 2 cases: The goal node was added to the “closed list”, thiscase, the path was found The “open list” does not have any more itens andthe goal node was not found, this way you shouldstop and say that there are no possible path. Page 16
  17. 17. A* algorithm(Finishing the search) The trackback is just a list of the father nodes, starting from the goal node until you reach the starting point. Page 17
  18. 18. A* algorithm (Finishing the search) Notes:• Collision detection (multiple agents)•Variable cost for terrains•Corners, can we walk diagonally always? Page 18
  19. 19. Dijkstra algorithm Conceived by Dutch computer scientist Edsger Dijkstra in 1956, is a graph search algorithm thatsolves the single-source shortest path problem for a graph, producing a shortest path tree. This algorithm is often used in routing and as a subroutine in other graph algorithms. Page 19
  20. 20. Dijkstra algorithmThe algorithm is very similar to the A* algorithm the main difference is that we don’t have aheuristic for the calculation of the F. Additionally in the end of the process we will have ALL the minor distances between ALL the nodes of the graph. Page 20
  21. 21. Dijkstra algorithm (Setting the graph) We gonna assume a group of nodes with infinite weight to reach it, and zero for the starting point. Additionally we gonna set values on the connections between the nodes as a distance between them. Page 21
  22. 22. Dijkstra algorithm (Starting the search)1 – We gonna take the starting node and add it to a “open list”.2- We visit every single node reachable from thestarting node, calculate the weight to arrive until that node, if is smaller than the actual value we“relax” it and set the father as the starting point. 3 – All visited nodes go to the “open list”. 4 – The starting node goes to the “closed list” Page 22
  23. 23. Dijkstra algorithm (Starting the search) In the end of the first step we will have the start node checked and some nodes with their distances set. Page 23
  24. 24. Dijkstra algorithm (Continuing the search)Now we will have (hopefully) some nodes on the “open list” so we must retrieve the onewith minor weight, and do all the steps once again. Page 24
  25. 25. Dijkstra algorithm (Continuing the search) Page 25
  26. 26. Dijkstra algorithm (Continuing the search) Page 26
  27. 27. Dijkstra algorithm (Continuing the search) Page 27