SlideShare a Scribd company logo
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Last Time
• AI
– Fuzzy Logic
– Neural networks
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Today
• Path Planning
– Intro
– Waypoints
– A* Path Planning
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Path Finding
• Very common problem in games:
– In FPS: How does the AI get from room to room?
– In RTS: User clicks on units, tells them to go somewhere. How do they get
there? How do they avoid each other?
– Chase games, sports games, …
• Very expensive part of games
– Lots of techniques that offer quality, robustness, speed trade-offs
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Path Finding Problem
• Problem Statement (Academic): Given a start point, A, and a goal point,
B, find a path from A to B that is clear
– Generally want to minimize a cost: distance, travel time, …
• Travel time depends on terrain, for instance
– May be complicated by dynamic changes: paths being blocked or removed
– May be complicated by unknowns – don’t have complete information
• Problem Statement (Games): Find a reasonable path that gets the object
from A to B
– Reasonable may not be optimal – not shortest, for instance
– It may be OK to pass through things sometimes
– It may be OK to make mistakes and have to backtrack
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Search or Optimization?
• Path planning (also called route-finding) can be phrased as a search
problem:
– Find a path to the goal B that minimizes Cost(path)
– There are a wealth of ways to solve search problems, and we will look at
some of them
• Path planning is also an optimization problem:
– Minimize Cost(path) subject to the constraint that path joins A and B
• State space is paths joining A and B, kind of messy
– There are a wealth of ways to solve optimization problems
• The difference is mainly one of terminology: different communities (AI
vs. Optimization)
– But, search is normally on a discrete state space
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Brief Overview of Techniques
• Discrete algorithms: BFS, Greedy search, A*, …
• Potential fields:
– Put a “force field” around obstacles, and follow the “potential
valleys”
• Pre-computed plans with dynamic re-planning
– Plan as search, but pre-compute answer and modify as required
• Special algorithms for special cases:
– E.g. Given a fixed start point, fast ways to find paths around
polygonal obstacles
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Graph-Based Algorithms
• Ideally, path planning is point to point (any point in the
world to any other, through any unoccupied point)
• But, the search space is complex (space of arbitrary curves)
• The solution is to discretize the search space
– Restrict the start and goal points to a finite set
– Restrict the paths to be on lines (or other simple curves) that join
points
• Form a graph: Nodes are points, edges join nodes that can
be reached along a single curve segment
– Search for paths on the graph
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints (and Questions)
• The discrete set of points you choose are called waypoints
• Where do you put the waypoints?
– There are many possibilities
• How do you find out if there is a simple path between them?
– Depends on what paths you are willing to accept - almost always
assume straight lines
• The answers to these questions depend very much on the
type of game you are developing
– The environment: open fields, enclosed rooms, etc…
– The style of game: covert hunting, open warfare, friendly romp, …
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Where Would You Put Waypoints?
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints By Hand
• Place waypoints by hand as part of level design
– Best control, most time consuming
• Many heuristics for good places:
– In doorways, because characters have to go through doors and
straight lines joining rooms always go through doors
– Along walls, for characters seeking cover
– At other discontinuities in the environments (edges of rivers, for
example)
– At corners, because shortest paths go through corners
• The choice of waypoints can make the AI seem smarter
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints By Grid
• Place a grid over the world, and put a waypoint at every
gridpoint that is open
– Automated method, and maybe even implicit in the environment
• Do an edge/world intersection test to decide which
waypoints should be joined
– Normally only allow moves to immediate (and maybe corner)
neighbors
• What sorts of environments is this likely to be OK for?
• What are its advantages?
• What are its problems?
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Grid Example
• Note that grid points pay no
attention to the geometry
• Method can be improved:
– Perturb grid to move closer to
obstacles
– Adjust grid resolution
– Use different methods for inside
and outside building
• Join with waypoints in doorways
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints From Polygons
• Choose waypoints based on the floor
polygons in your world
• Or, explicitly design polygons to be
used for generating waypoints
• How do we go from polygons to
waypoints?
– Hint: there are two obvious options
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints From Polygons
!
Could also add points on walls
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints From Corners
• Place waypoints at every convex corner of the obstacles
– Actually, place the point away from the corner according to how wide the
moving objects are
– Or, compute corners of offset polygons
• Connects all the corners that can see each other
• Paths through these waypoints will be the shortest
• However, some unnatural paths may result
– Particularly along corridors - characters will stick to walls
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Waypoints From Corners
• NOTE: Not every edge is drawn
• Produces very dense graphs
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Getting On and Off
• Typically, you do not wish to restrict the character to the
waypoints or the graph edges
• When the character starts, find the closest waypoint and
move to that first
– Or, find the waypoint most in the direction you think you need to go
– Or, try all of the potential starting waypoints and see which gives
the shortest path
• When the character reaches the closest waypoint to its goal,
jump off and go straight to the goal point
• Best option: Add a new, temporary waypoint at the precise
start and goal point, and join it to nearby waypoints
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Getting On and Off
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Best-First-Search
• Start at the start node and search outwards
• Maintain two sets of nodes:
– Open nodes are those we have reached but don’t know best path
– Closed nodes that we know the best path to
• Keep the open nodes sorted by cost
• Repeat: Expand the “best” open node
– If it’s the goal, we’re done
– Move the “best” open node to the closed set
– Add any nodes reachable from the “best” node to the open set
• Unless already there or closed
– Update the cost for any nodes reachable from the “best” node
• New cost is min(old-cost, cost-through-best)
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Best-First-Search Properties
• Precise properties depend on how “best” is defined
• But in general:
– Will always find the goal if it can be reached
– Maintains a frontier of nodes on the open list, surrounding nodes on the
closed list
– Expands the best node on the frontier, hence expanding the frontier
– Eventually, frontier will expand to contain the goal node
• To store the best path:
– Keep a pointer in each node n to the previous node along the best path to n
– Update these as nodes are added to the open set and as nodes are expanded
(whenever the cost changes)
– To find path to goal, trace pointers back from goal nodes
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Expanding Frontier
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Definitions
• g(n): The current known best cost for getting to a node from the start
point
– Can be computed based on the cost of traversing each edge along the
current shortest path to n
• h(n): The current estimate for how much more it will cost to get from a
node to the goal
– A heuristic: The exact value is unknown but this is your best guess
– Some algorithms place conditions on this estimate
• f(n): The current best estimate for the best path through a node:
f(n)=g(n)+h(n)
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Using g(n) Only
• Define “best” according to f(n)=g(n), the shortest known path from the
start to the node
• Equivalent to breadth first search
• Is it optimal?
– When the goal node is expanded, is it along the shortest path?
• Is it efficient?
– How many nodes does it explore? Many, few, …?
• Behavior is the same as defining a constant heuristic function:
h(n)=const
– Why?
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Breadth First Search
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Breadth First Search
• See Game Programming Gems for another example:
– On a grid with uniform cost per edge, the frontier
expands in a circle out from the start point
– Makes sense: We’re only using info about distance
from the start
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Using h(n) Only (Greedy Search)
• Define “best” according to f(n)=h(n), the best guess from the node to
the goal state
– Behavior depends on choice of heuristic
– Straight line distance is a good one
• Have to set the cost for a node with no exit to be infinite
– If we expand such a node, our guess of the cost was wrong
– Do it when you try to expand such a node
• Is it optimal?
– When the goal node is expanded, is it along the shortest path?
• Is it efficient?
– How many nodes does it explore? Many, few, …?
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Greedy Search (Straight-Line-Distance Heuristic)
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
A* Search
• Set f(n)=g(n)+h(n)
– Now we are expanding nodes according to best estimated total path cost
• Is it optimal?
– It depends on h(n)
• Is it efficient?
– It is the most efficient of any optimal algorithm that uses the same h(n)
• A* is the ubiquitous algorithm for path planning in games
– Much effort goes into making it fast, and making it produce pretty looking
paths
– More articles on it than you can ever hope to read
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
A* Search (Straight-Line-Distance Heuristic)
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
A* Search (Straight-Line-Distance Heuristic)
• Note that A* expands fewer nodes
than breadth-first, but more than
greedy
• It’s the price you pay for optimality
• See Game Programming Gems for
implementation details. Keys are:
– Data structure for a node
– Priority queue for sorting open
nodes
– Underlying graph structure for
finding neighbors
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Heuristics
• For A* to be optimal, the heuristic must underestimate the
true cost
– Such a heuristic is admissible
• Also, not mentioned in Gems, the f(n) function must
monotonically increase along any path out of the start node
– True for almost any admissible heuristic, related to triangle
inequality
– If not true, can fix by making cost through a node max(f(parent) +
edge, f(n))
• Combining heuristics:
– If you have more than one heuristic, all of which underestimate, but
which give different estimates, can combine with:
h(n)=max(h1(n),h2(n),h3(n),…)
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Inventing Heuristics
• Bigger estimates are always better than smaller ones
– They are closer to the “true” value
– So straight line distance is better than a small constant
• Important case: Motion on a grid
– If diagonal steps are not allowed, use Manhattan distance
• General strategy: Relax the constraints on the problem
– For example: Normal path planning says avoid obstacles
– Relax by assuming you can go through obstacles
– Result is straight line distance
is a bigger estimate than
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Non-Optimal A*
• Can use heuristics that are not admissible - A* will still give
an answer
– But it won’t be optimal: May not explore a node on the optimal path
because its estimated cost is too high
– Optimal A* will eventually explore any such node before it reaches
the goal
• Non-admissible heuristics may be much faster
– Trade-off computational efficiency for path-efficiency
• One way to make non-admissible: Multiply underestimate
by a constant factor
– See Gems for an example of this
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Project Stage 4
• AI
– Make your world interact with the player
– Use any technique you want – that’s part of the challenge
11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin
Todo
• Thurs Nov 6, Midterm, in class
– Everything up to and including lecture 15
– Sample exams online, but not all material appears in those exams
• By Monday, Nov 10, Stage 4 goals
• By Monday, Nov 24, Stage 4 demo
• By Monday, Dec 1, Final goals
• By Wednesday, Dec 10, Final Demo

More Related Content

PPT
Straight Line Distance Heuristic
PDF
Pathfinding - Part 3: Beyond the basics
PDF
Pathfinding - Part 1: Α* heuristic search
PDF
Path Finding Solutions For Grid Based Graph
PDF
Node Path Visualizer Using Shortest Path Algorithms
PDF
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PPT
Different Search Techniques used in AI.ppt
PPT
11-RoutingThe development of wireless systems traces its roots .ppt
Straight Line Distance Heuristic
Pathfinding - Part 3: Beyond the basics
Pathfinding - Part 1: Α* heuristic search
Path Finding Solutions For Grid Based Graph
Node Path Visualizer Using Shortest Path Algorithms
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
Different Search Techniques used in AI.ppt
11-RoutingThe development of wireless systems traces its roots .ppt

Similar to cs679-19.ppt aravaw afraaaarw aaw da adw (20)

PPT
Routing and IP in Advance Computer Network,Vikram Snehi
PPT
ai and search algorithms general on a* and searching
PPTX
Ai part 1
PPT
11 routing
PPTX
CptS 440 / 540 Artificial Intelligence
PPT
problem solving for AI and Machine Learning
PPTX
mini project_shortest path visualizer.pptx
PPTX
PDF
Pathfinding in games
PPT
cps170_search.ppt. This ppt talk about search algorithm
PPT
cps170_search CPS 170: Artificial Intelligence http://www.cs.duke.edu/courses...
PDF
Algorithms
PPTX
Chapter 3.pptx
PDF
Search problems in Artificial Intelligence
PPT
chapter3part1.ppt
PDF
Talk on Graph Theory - I
PPT
Unit 2 for the Artificial intelligence and machine learning
PPT
12 routing
PDF
Introduction to Graph Theory
Routing and IP in Advance Computer Network,Vikram Snehi
ai and search algorithms general on a* and searching
Ai part 1
11 routing
CptS 440 / 540 Artificial Intelligence
problem solving for AI and Machine Learning
mini project_shortest path visualizer.pptx
Pathfinding in games
cps170_search.ppt. This ppt talk about search algorithm
cps170_search CPS 170: Artificial Intelligence http://www.cs.duke.edu/courses...
Algorithms
Chapter 3.pptx
Search problems in Artificial Intelligence
chapter3part1.ppt
Talk on Graph Theory - I
Unit 2 for the Artificial intelligence and machine learning
12 routing
Introduction to Graph Theory
Ad

Recently uploaded (20)

PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Feature types and data preprocessing steps
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPT
Total quality management ppt for engineering students
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
introduction to high performance computing
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Feature types and data preprocessing steps
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Total quality management ppt for engineering students
Fundamentals of Mechanical Engineering.pptx
Visual Aids for Exploratory Data Analysis.pdf
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
Soil Improvement Techniques Note - Rabbi
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Categorization of Factors Affecting Classification Algorithms Selection
Management Information system : MIS-e-Business Systems.pptx
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Exploratory_Data_Analysis_Fundamentals.pdf
introduction to high performance computing
Amdahl’s law is explained in the above power point presentations
Fundamentals of safety and accident prevention -final (1).pptx
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Ad

cs679-19.ppt aravaw afraaaarw aaw da adw

  • 1. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Last Time • AI – Fuzzy Logic – Neural networks
  • 2. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Today • Path Planning – Intro – Waypoints – A* Path Planning
  • 3. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Path Finding • Very common problem in games: – In FPS: How does the AI get from room to room? – In RTS: User clicks on units, tells them to go somewhere. How do they get there? How do they avoid each other? – Chase games, sports games, … • Very expensive part of games – Lots of techniques that offer quality, robustness, speed trade-offs
  • 4. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Path Finding Problem • Problem Statement (Academic): Given a start point, A, and a goal point, B, find a path from A to B that is clear – Generally want to minimize a cost: distance, travel time, … • Travel time depends on terrain, for instance – May be complicated by dynamic changes: paths being blocked or removed – May be complicated by unknowns – don’t have complete information • Problem Statement (Games): Find a reasonable path that gets the object from A to B – Reasonable may not be optimal – not shortest, for instance – It may be OK to pass through things sometimes – It may be OK to make mistakes and have to backtrack
  • 5. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Search or Optimization? • Path planning (also called route-finding) can be phrased as a search problem: – Find a path to the goal B that minimizes Cost(path) – There are a wealth of ways to solve search problems, and we will look at some of them • Path planning is also an optimization problem: – Minimize Cost(path) subject to the constraint that path joins A and B • State space is paths joining A and B, kind of messy – There are a wealth of ways to solve optimization problems • The difference is mainly one of terminology: different communities (AI vs. Optimization) – But, search is normally on a discrete state space
  • 6. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Brief Overview of Techniques • Discrete algorithms: BFS, Greedy search, A*, … • Potential fields: – Put a “force field” around obstacles, and follow the “potential valleys” • Pre-computed plans with dynamic re-planning – Plan as search, but pre-compute answer and modify as required • Special algorithms for special cases: – E.g. Given a fixed start point, fast ways to find paths around polygonal obstacles
  • 7. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Graph-Based Algorithms • Ideally, path planning is point to point (any point in the world to any other, through any unoccupied point) • But, the search space is complex (space of arbitrary curves) • The solution is to discretize the search space – Restrict the start and goal points to a finite set – Restrict the paths to be on lines (or other simple curves) that join points • Form a graph: Nodes are points, edges join nodes that can be reached along a single curve segment – Search for paths on the graph
  • 8. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints (and Questions) • The discrete set of points you choose are called waypoints • Where do you put the waypoints? – There are many possibilities • How do you find out if there is a simple path between them? – Depends on what paths you are willing to accept - almost always assume straight lines • The answers to these questions depend very much on the type of game you are developing – The environment: open fields, enclosed rooms, etc… – The style of game: covert hunting, open warfare, friendly romp, …
  • 9. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Where Would You Put Waypoints?
  • 10. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints By Hand • Place waypoints by hand as part of level design – Best control, most time consuming • Many heuristics for good places: – In doorways, because characters have to go through doors and straight lines joining rooms always go through doors – Along walls, for characters seeking cover – At other discontinuities in the environments (edges of rivers, for example) – At corners, because shortest paths go through corners • The choice of waypoints can make the AI seem smarter
  • 11. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints By Grid • Place a grid over the world, and put a waypoint at every gridpoint that is open – Automated method, and maybe even implicit in the environment • Do an edge/world intersection test to decide which waypoints should be joined – Normally only allow moves to immediate (and maybe corner) neighbors • What sorts of environments is this likely to be OK for? • What are its advantages? • What are its problems?
  • 12. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Grid Example • Note that grid points pay no attention to the geometry • Method can be improved: – Perturb grid to move closer to obstacles – Adjust grid resolution – Use different methods for inside and outside building • Join with waypoints in doorways
  • 13. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints From Polygons • Choose waypoints based on the floor polygons in your world • Or, explicitly design polygons to be used for generating waypoints • How do we go from polygons to waypoints? – Hint: there are two obvious options
  • 14. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints From Polygons ! Could also add points on walls
  • 15. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints From Corners • Place waypoints at every convex corner of the obstacles – Actually, place the point away from the corner according to how wide the moving objects are – Or, compute corners of offset polygons • Connects all the corners that can see each other • Paths through these waypoints will be the shortest • However, some unnatural paths may result – Particularly along corridors - characters will stick to walls
  • 16. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Waypoints From Corners • NOTE: Not every edge is drawn • Produces very dense graphs
  • 17. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Getting On and Off • Typically, you do not wish to restrict the character to the waypoints or the graph edges • When the character starts, find the closest waypoint and move to that first – Or, find the waypoint most in the direction you think you need to go – Or, try all of the potential starting waypoints and see which gives the shortest path • When the character reaches the closest waypoint to its goal, jump off and go straight to the goal point • Best option: Add a new, temporary waypoint at the precise start and goal point, and join it to nearby waypoints
  • 18. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Getting On and Off
  • 19. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Best-First-Search • Start at the start node and search outwards • Maintain two sets of nodes: – Open nodes are those we have reached but don’t know best path – Closed nodes that we know the best path to • Keep the open nodes sorted by cost • Repeat: Expand the “best” open node – If it’s the goal, we’re done – Move the “best” open node to the closed set – Add any nodes reachable from the “best” node to the open set • Unless already there or closed – Update the cost for any nodes reachable from the “best” node • New cost is min(old-cost, cost-through-best)
  • 20. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Best-First-Search Properties • Precise properties depend on how “best” is defined • But in general: – Will always find the goal if it can be reached – Maintains a frontier of nodes on the open list, surrounding nodes on the closed list – Expands the best node on the frontier, hence expanding the frontier – Eventually, frontier will expand to contain the goal node • To store the best path: – Keep a pointer in each node n to the previous node along the best path to n – Update these as nodes are added to the open set and as nodes are expanded (whenever the cost changes) – To find path to goal, trace pointers back from goal nodes
  • 21. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Expanding Frontier
  • 22. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Definitions • g(n): The current known best cost for getting to a node from the start point – Can be computed based on the cost of traversing each edge along the current shortest path to n • h(n): The current estimate for how much more it will cost to get from a node to the goal – A heuristic: The exact value is unknown but this is your best guess – Some algorithms place conditions on this estimate • f(n): The current best estimate for the best path through a node: f(n)=g(n)+h(n)
  • 23. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Using g(n) Only • Define “best” according to f(n)=g(n), the shortest known path from the start to the node • Equivalent to breadth first search • Is it optimal? – When the goal node is expanded, is it along the shortest path? • Is it efficient? – How many nodes does it explore? Many, few, …? • Behavior is the same as defining a constant heuristic function: h(n)=const – Why?
  • 24. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Breadth First Search
  • 25. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Breadth First Search • See Game Programming Gems for another example: – On a grid with uniform cost per edge, the frontier expands in a circle out from the start point – Makes sense: We’re only using info about distance from the start
  • 26. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Using h(n) Only (Greedy Search) • Define “best” according to f(n)=h(n), the best guess from the node to the goal state – Behavior depends on choice of heuristic – Straight line distance is a good one • Have to set the cost for a node with no exit to be infinite – If we expand such a node, our guess of the cost was wrong – Do it when you try to expand such a node • Is it optimal? – When the goal node is expanded, is it along the shortest path? • Is it efficient? – How many nodes does it explore? Many, few, …?
  • 27. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Greedy Search (Straight-Line-Distance Heuristic)
  • 28. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin A* Search • Set f(n)=g(n)+h(n) – Now we are expanding nodes according to best estimated total path cost • Is it optimal? – It depends on h(n) • Is it efficient? – It is the most efficient of any optimal algorithm that uses the same h(n) • A* is the ubiquitous algorithm for path planning in games – Much effort goes into making it fast, and making it produce pretty looking paths – More articles on it than you can ever hope to read
  • 29. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin A* Search (Straight-Line-Distance Heuristic)
  • 30. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin A* Search (Straight-Line-Distance Heuristic) • Note that A* expands fewer nodes than breadth-first, but more than greedy • It’s the price you pay for optimality • See Game Programming Gems for implementation details. Keys are: – Data structure for a node – Priority queue for sorting open nodes – Underlying graph structure for finding neighbors
  • 31. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Heuristics • For A* to be optimal, the heuristic must underestimate the true cost – Such a heuristic is admissible • Also, not mentioned in Gems, the f(n) function must monotonically increase along any path out of the start node – True for almost any admissible heuristic, related to triangle inequality – If not true, can fix by making cost through a node max(f(parent) + edge, f(n)) • Combining heuristics: – If you have more than one heuristic, all of which underestimate, but which give different estimates, can combine with: h(n)=max(h1(n),h2(n),h3(n),…)
  • 32. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Inventing Heuristics • Bigger estimates are always better than smaller ones – They are closer to the “true” value – So straight line distance is better than a small constant • Important case: Motion on a grid – If diagonal steps are not allowed, use Manhattan distance • General strategy: Relax the constraints on the problem – For example: Normal path planning says avoid obstacles – Relax by assuming you can go through obstacles – Result is straight line distance is a bigger estimate than
  • 33. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Non-Optimal A* • Can use heuristics that are not admissible - A* will still give an answer – But it won’t be optimal: May not explore a node on the optimal path because its estimated cost is too high – Optimal A* will eventually explore any such node before it reaches the goal • Non-admissible heuristics may be much faster – Trade-off computational efficiency for path-efficiency • One way to make non-admissible: Multiply underestimate by a constant factor – See Gems for an example of this
  • 34. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Project Stage 4 • AI – Make your world interact with the player – Use any technique you want – that’s part of the challenge
  • 35. 11/04/03 CS679 - Fall 2003 - Copyright Univ. of Wisconsin Todo • Thurs Nov 6, Midterm, in class – Everything up to and including lecture 15 – Sample exams online, but not all material appears in those exams • By Monday, Nov 10, Stage 4 goals • By Monday, Nov 24, Stage 4 demo • By Monday, Dec 1, Final goals • By Wednesday, Dec 10, Final Demo