PATHFINDING WITH A* Presented by Joseph Siefers February 19 th, 2008.

Slides:



Advertisements
Similar presentations
Review: Search problem formulation
Advertisements

Informed Search Algorithms
An Introduction to Artificial Intelligence
A* Search. 2 Tree search algorithms Basic idea: Exploration of state space by generating successors of already-explored states (a.k.a.~expanding states).
Informed Search Methods Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 4 Spring 2004.
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2007.
Solving Problem by Searching
1 Heuristic Search Chapter 4. 2 Outline Heuristic function Greedy Best-first search Admissible heuristic and A* Properties of A* Algorithm IDA*
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
Blind Search1 Solving problems by searching Chapter 3.
Search Strategies CPS4801. Uninformed Search Strategies Uninformed search strategies use only the information available in the problem definition Breadth-first.
Review: Search problem formulation
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2004.
Toy Problem: Missionaries and Cannibals
1 Solving Problems by Searching. 2 Terminology State State Space Initial State Goal Test Action Step Cost Path Cost State Change Function State-Space.
Uninformed Search Reading: Chapter 3 by today, Chapter by Wednesday, 9/12 Homework #2 will be given out on Wednesday DID YOU TURN IN YOUR SURVEY?
Problem Solving and Search in AI Heuristic Search
CSC344: AI for Games Lecture 4: Informed search
Solving problems by searching
Solving Problems by Searching
Informed Search Idea: be smart about what paths to try.
Problem Solving and Search Andrea Danyluk September 11, 2013.
Graphs II Robin Burke GAM 376. Admin Skip the Lua topic.
Dr.Abeer Mahmoud ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information.
1 CO Games Development 1 Week 6 Introduction To Pathfinding + Crash and Turn + Breadth-first Search Gareth Bellaby.
How are things going? Core AI Problem Mobile robot path planning: identifying a trajectory that, when executed, will enable the robot to reach the goal.
Today’s Topics FREE Code that will Write Your PhD Thesis, a Best-Selling Novel, or Your Next Methods for Intelligently/Efficiently Searching a Space.
Informed (Heuristic) Search
Informed search algorithms Chapter 4. Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most.
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select.
Informed Search Strategies Lecture # 8 & 9. Outline 2 Best-first search Greedy best-first search A * search Heuristics.
For Friday Finish reading chapter 4 Homework: –Lisp handout 4.
For Monday Read chapter 4, section 1 No homework..
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
Advanced Artificial Intelligence Lecture 2: Search.
For Wednesday Read chapter 6, sections 1-3 Homework: –Chapter 4, exercise 1.
For Wednesday Read chapter 5, sections 1-4 Homework: –Chapter 3, exercise 23. Then do the exercise again, but use greedy heuristic search instead of A*
Artificial Intelligence for Games Informed Search (2) Patrick Olivier
CSC3203: AI for Games Informed search (1) Patrick Olivier
For Friday Read chapter 4, sections 1 and 2 Homework –Chapter 3, exercise 7 –May be done in groups.
1 Kuliah 4 : Informed Search. 2 Outline Best-First Search Greedy Search A* Search.
Search (continued) CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Solving problems by searching 1. Outline Problem formulation Example problems Basic search algorithms 2.
Heuristic Functions. A Heuristic is a function that, when applied to a state, returns a number that is an estimate of the merit of the state, with respect.
Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu Blind Searches - Introduction.
The A* and applications to Games Sources: My own Joseph Siefers presentation 2008.
Chapter 3.5 and 3.6 Heuristic Search Continued. Review:Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
CSCI 4310 Lecture 4: Search 2 – Including A*. Book Winston Chapters 4,5,6.
G5AIAI Introduction to AI Graham Kendall Heuristic Searches.
Artificial Intelligence Lecture No. 8 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Blind Search Russell and Norvig: Chapter 3, Sections 3.4 – 3.6 CS121 – Winter 2003.
For Monday Read chapter 4 exercise 1 No homework.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Review: Tree search Initialize the frontier using the starting state
For Monday Chapter 6 Homework: Chapter 3, exercise 7.
Department of Computer Science
Heuristic Search Introduction to Artificial Intelligence
Problem Solving by Searching
Artificial Intelligence Problem solving by searching CSC 361
HW #1 Due 29/9/2008 Write Java Applet to solve Goats and Cabbage “Missionaries and cannibals” problem with the following search algorithms: Breadth first.
The A* Algorithm Héctor Muñoz-Avila.
CS 4100 Artificial Intelligence
Informed search algorithms
Informed search algorithms
HW 1: Warmup Missionaries and Cannibals
Informed Search Idea: be smart about what paths to try.
HW 1: Warmup Missionaries and Cannibals
Artificial Intelligence: Theory and Practice Ch. 3. Search
Informed Search Idea: be smart about what paths to try.
Presentation transcript:

PATHFINDING WITH A* Presented by Joseph Siefers February 19 th, 2008

Outline  Introduction to Pathfinding  Search Terminology  Search Methods  Uninformed Search  Informed Search  A* Search: How it Works  A* Optimizations  Conclusion

Introduction  Effective pathfinding is the key to a good game  …unless your studio wants to be the laughing stalk of gamers worldwide:    But it is difficult to do.  Efficient search strategy/algorithms  A* is the “star of the search”

Case Study—The 8-Puzzle

Case Study: The 8-Puzzle  From the set of AI exercises know as “Toy Problems”  Why?  Easy to define and understand.  Sufficiently complex to analyze search methods.

Case Study: The 8-Puzzle  Rules of the game:  Move free space {left, up, down, right} within boundaries of puzzle LeftUp DownRight

Search Terminology

 Search Tree  Node LeftUp DownRight

Search Terminology LeftUp DownRight “Initial State”

Search Terminology  Successor Function Left Up Down Right “Successors”

Search Terminology  Branching Factor (b) Left Up Down Right b=4

Search Terminology  Step Cost (…)

Search Terminology  Path Cost g(n) (…) g(n) = 1

Search Terminology  Path Cost g(n) (…) g(n) = 2

Search Terminology  Goal State (…)

Search Terminology  “The Fringe”  Open/Closed lists  “Algorithms which ignore their history are doomed to repeat it.” –AIMA pg 82

Search Strategies

Uninformed Search Strategies  Uninformed Search  Blindly search tree  “Driving without a map”

Uninformed Search Strategies  Breadth First  Search nodes in “hierarchical order”  FIFO Image Credit: Wikimedia Commons

Uninformed Search Strategies  Let’s see breadth-first search in action!  “Pathdemo” by Bryan Stout

Uninformed Search Strategies  Breadth-First in Action

Uninformed Search Strategy  Overall Result:

Uninformed Search Strategies  Depth First  Repeatedly traverse one path to completion

Unformed Search Strategies  Depth-First in Action?  —“No Dice”

Uninformed Search Strategies  Problems:  Not practical: (estimated with b= 10, a search rate of 10 5 nodes/sec, and 1 KiB/node) Credit: AIMA fig 3.11, pg 74

Search Strategies  Informed Search  Traverse search tree “intelligently”  “Driving with a map”  A heuristic function = “the map”

Informed Search Strategies  Heuristic function h(n)  Estimate path cost to goal  Key to improving search problems  NEVER overestimate— “be optimistic”

Heuristics  Admissibility  “Relaxed” Problems  Simplify constraints  Reduces complexity  Example: 8-Puzzle ? Initial StateGoal State

A* Search: Introduction  A * search:  Extremely fast  Provably optimal (given an admissible heuristic)  Flexible and Adaptable

A* Search: How it Works Estimated Overall Path Cost = How far I think I have to go + How far I have come

A* Search: How it Works Node evaluation function Heuristic function Current Path Cost

A* Search: How it works  A* Algorithm Pseudocode  1. Let P= the starting point  2. Assign f, g and h values to P.  3. Add P to the Open list.  4. Let B = the best node (lowest f) from the Open list  a. If B is the goal node, quit (path found)  b. If the Open list is empty, quit (path impossible)  A* Algorithm Pseudocode  1. Let P= the starting point  2. Assign f, g and h values to P.  3. Add P to the Open list.  4. Let B = the best node (lowest f) from the Open list  a. If B is the goal node, quit (path found)  b. If the Open list is empty, quit (path impossible)

A* Search: How it works  5. Expand B  a. Generate f,g,h values for the successors of B  b. Add successors to open list, appropriately  6. Repeat from step 4  5. Expand B  a. Generate f,g,h values for the successors of B  b. Add successors to open list, appropriately  6. Repeat from step 4

A* in Map Problems  Example Problem—“The hurried traveler”

A* Map Problem Heuristics  A* efficiency dependent on choice of heuristic  Euclidean Distance  Always admissible  Manhattan Distance  “City Blocks”  Admissible for discrete map problems  h = |dx-sx| + |dy-sy|

A* Map Problem Heuristics  Manhattan vs. Euclidean distance comparison Image Credit: Wikimedia Commons

A* Search: Map Problem Testing  Interesting parameters in “Pathdemo”  Heuristic weight  Sample heuristic functions Manhattan Distance Diagonal Shortcut Euclidean Max

A* Search: Compare and Contrast  Manhattan distance: Weight 0

A* Search: Compare and Contrast  Manhattan distance: Weight 1

A* Search: Compare and Contrast  Manhattan distance: Weight 2

A* Search: Compare and Contrast  Manhattan distance: Weight 3

A* Search: A Look Back…  Breadth-First Search  A*, Manhattan, W=3 75% LESS NODES

A* Optimizations  Don’t pathfind  Common solution  Quick straight line check  “Flood insurance”  Measure flooding Visually on map

A* Optimizations  Visual representation of flooding Image Credit: AIGPW Figure 3.4.1

A* Optimizations  Don’t pathfind  Common solution  “Flood insurance”  Measure flooding and reduce Visually on map  Sometimes futile…  Limit map designs?

A* Optimizations  Memory Pooling  Allocating memory CPU intensive  How much memory? Specific to each game Find “perfect balance”  Statistical Analysis  Current technology makes pooling practical

A* Optimizations  Open/Closed list implementation  “Priority queue” Heap O(lg n) operations Even this might not be fast enough Hash Table O(1) operations Problems fine-tuning “Cheap List”

Optimization Tools  Performance metric for search algorithms  Intel VTune  In-Code Timers Approximate execution time Multithreading Issues Other threads might be busy and slowing Pathfinding Valuable “Standard Path”  No tool stands by itself

Conclusion  A* solves difficult pathfinding problems  Ubiquitous across gaming industry  Shows up in every type of game  A* is highly dependent on a good heuristic  Breadth-first if bad heuristic  A* can be resource-intensive  A* is not a “one-size fits all” solution  Plan on spending time optimizing  Solved problem

Thank you!  Thanks for listening!