Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CW 33: Pathfinding - Vinicius Maciel

CW 33: Pathfinding - Vinicius Maciel

Avatar for hackthursday

hackthursday

August 16, 2012
Tweet

More Decks by hackthursday

Other Decks in Programming

Transcript

  1. Pathfinding Page 2 Pathfinding or pathing refers to the plotting,

    by a computer application, of the shortest route between two points. It is a more practical variant on solving mazes
  2. A* algorithm Page 3 A* uses a best-first search and

    finds a least-cost path from a given initial node to one goal node (out of 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.
  3. A* algorithm Page 5 (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.
  4. A* algorithm Page 6 (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 of the 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.
  5. A* algorithm Page 7 (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.
  6. A* algorithm Page 8 (starting the search) 3- Now we

    have a lot of itens to choose on our “open list”, but, which one to choose?
  7. A* algorithm Page 9 (Filtering nodes) You have to search

    on the “open list” the node with the smaller value for F, where F = G + H Aditionally, G = cost to arrive until this point H = estimated cost to arrive on the goal, from the current node, called heuristic
  8. A* algorithm Page 10 (Filtering nodes) Heuristic is a way

    to guess about something, you cannot assume that the heuristic is the best value, b but how you still don’t know how to arrive to the goal 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)
  9. A* algorithm Page 11 After calculating F, G and H

    we have the following situation (Filtering nodes)
  10. A* algorithm Page 12 (Continuing the search) To continue the

    search just take the node with minor value of F on the “open list”, then 1- Remove it from the “open list” and add it to the “closed list”.
  11. A* algorithm Page 13 (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.
  12. A* algorithm Page 14 (Continuing the search) 3 – If

    one of the neighbors nodes are on the “open list” 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.
  13. A* algorithm Page 16 (Finishing the search) When we should

    stop? There are 2 cases:  The goal node was added to the “closed list”, this case, the path was found  The “open list” does not have any more itens and the goal node was not found, this way you should stop and say that there are no possible path.
  14. A* algorithm Page 17 (Finishing the search) The trackback is

    just a list of the father nodes, starting from the goal node until you reach the starting point.
  15. A* algorithm Page 18 (Finishing the search) Notes: • Collision

    detection (multiple agents) •Variable cost for terrains •Corners, can we walk diagonally always?
  16. Dijkstra algorithm Page 19 Conceived by Dutch computer scientist Edsger

    Dijkstra in 1956, is a graph search algorithm that solves 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.
  17. Dijkstra algorithm Page 20 The algorithm is very similar to

    the A* algorithm the main difference is that we don’t have a heuristic 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.
  18. Dijkstra algorithm Page 21 (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.
  19. Dijkstra algorithm Page 22 (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 the starting 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”
  20. Dijkstra algorithm Page 23 (Starting the search) In the end

    of the first step we will have the start node checked and some nodes with their distances set.
  21. Dijkstra algorithm Page 24 (Continuing the search) Now we will

    have (hopefully) some nodes on the “open list” so we must retrieve the one with minor weight, and do all the steps once again.