Pseudocode AStar. Heuristics - how to determine what's a good next step? As mentioned already, the A* algorithm depends on evaluating the best next step.

Slides:



Advertisements
Similar presentations
Informed Search Algorithms
Advertisements

Heuristic Search techniques
AI Pathfinding Representing the Search Space
Informed Search Strategies
Recursion CS 367 – Introduction to Data Structures.
Intro to Computer Org. Pipelining, Part 2 – Data hazards + Stalls.
CSE 20 – Discrete Mathematics Dr. Cynthia Bailey Lee Dr. Shachar Lovett Peer Instruction in Discrete Mathematics by Cynthia Leeis licensed under a Creative.
CS16: Introduction to Data Structures & Algorithms
CSE 380 – Computer Game Programming Pathfinding AI
CS171 Introduction to Computer Science II Graphs Strike Back.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Heapsort.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Heapsort. 2 Why study Heapsort? It is a well-known, traditional sorting algorithm you will be expected to know Heapsort is always O(n log n) Quicksort.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
EXERCISES – PATH PLANNING & ROS ISSUES By Vuk Vujovic.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Routing 2 Outline –Maze Routing –Line Probe Routing –Channel Routing Goal –Understand maze routing –Understand line probe routing.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Informed Search Idea: be smart about what paths to try.
Chapter 5.4 Artificial Intelligence: Pathfinding.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
1 Game AI Path Finding. A Common Situation of Game AI A Common Situation of Game AI Path Planning Path Planning –From a start position to a destination.
Heapsort CSC Why study Heapsort? It is a well-known, traditional sorting algorithm you will be expected to know Heapsort is always O(n log n)
Representing and Using Graphs
Informed search algorithms Chapter 4. Outline Best-first search Greedy best-first search A * search Heuristics.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
Informed Search I (Beginning of AIMA Chapter 4.1)
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Heapsort. What is a “heap”? Definitions of heap: 1.A large area of memory from which the programmer can allocate blocks as needed, and deallocate them.
A* Path Finding Ref: A-star tutorial.
1 CO Games Development 1 Week 8 A* Gareth Bellaby.
An Exact Algorithm for Difficult Detailed Routing Problems Kolja Sulimma Wolfgang Kunz J. W.-Goethe Universität Frankfurt.
G5AIAI Introduction to AI Graham Kendall Heuristic Searches.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Heuristic Search A heuristic is a rule for choosing a branch in a state space search that will most likely lead to a problem solution Heuristics are used.
Maze Implementation, Analysis and Design to find Shortest Paths
Dr. David Matuszek Heapsort Dr. David Matuszek
HW2 EE 562.
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
A* Path Finding Ref: A-star tutorial.
Spanning Trees.
CSE 373: Data Structures and Algorithms
CSE 214 – Computer Science II Graph Walking
Heapsort.
The Rock Boxers: Tabitha Greenwood Cameron Meade Noah Cahan
Slide Courtesy: Uwash, UT
Advanced Computer Networks
CO Games Development 1 Week 8 Depth-first search, Combinatorial Explosion, Heuristics, Hill-Climbing Gareth Bellaby.
Heuristic Search Methods
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
HW 1: Warmup Missionaries and Cannibals
CSE 373 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
Graphs.
Informed Search Idea: be smart about what paths to try.
Heapsort.
The Rich/Knight Implementation
HW 1: Warmup Missionaries and Cannibals
Informed Search Idea: be smart about what paths to try.
CO 303 Algorithm Analysis and Design
The Rich/Knight Implementation
Optimised Search Techniques
Presentation transcript:

Pseudocode AStar

Heuristics - how to determine what's a good next step? As mentioned already, the A* algorithm depends on evaluating the best next step in searching for a path. This is done by evaluating each of the possible next steps against a heuristic to give a value that can be used to sort the list and hence determine the most likely next step. As you can imagine this makes choosing a good heuristic for your map and game really important to getting good path finding performance.

The most obvious way to determine the best step is to always pick the step that is the closest to the target. This isn't always perfect for environments with a lot of obstacles or that are maze like but it does provide a simple heuristic to understand. It would look like: dx = targetX - currentX; dy = targetY - currentY; heuristic = sqrt((dx*dx)+(dy*dy)); Remembering that the heuristic is evaluated frequently during the path finding process we can see that this may not always be a good idea. That sqrt() call is (on most hardware) expensive. Euclidean Distance

Another common approach is to replace absolute distance with "Manhattan Distance". This is an approximation of the distance between two points based on adding the horizontal distance and vertical distances rather than computing the exact difference. That would look like this: dx = abs(targetX - currentX); dy = abs(targetY - currentY); heuristic = dx+dy; Manhattan Distance

Pseudo Code The A* algorithm works like this: 1.At initialization add the starting location to the open list and empty the closed list 2.While there are still more possible next steps in the open list and we haven't found the target: 1.Select the most likely next step (based on both the heuristic and path costs) 2.Remove it from the open list and add it to the closed 3.Consider each neighbor of the step. For each neighbor: 1.Calculate the path cost of reaching the neighbor 2.If the cost is less than the cost known for this location then remove it from the open or closed lists (since we've now found a better route) 3.If the location isn't in either the open or closed list then record the costs for the location and add it to the open list (this means it'll be considered in the next search). Record how we got to this location The loop ends when we either find a route to the destination or we run out of steps. If a route is found we back track up the records of how we reached each location to determine the path.