A* Reference: “Artificial Intelligence for Games”, Ian Millington.

Slides:



Advertisements
Similar presentations
AI Pathfinding Representing the Search Space
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Topological Sort Topological sort is the list of vertices in the reverse order of their finishing times (post-order) of the depth-first search. Topological.
1 Graphs Traversals In many graph problems, we need to traverse the vertices of the graph in some order Analogy: Binary tree traversals –Pre-order Traversal.
Graphs - II CS 2110, Spring Where did I leave that book?
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.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
CSE 380 – Computer Game Programming Pathfinding AI
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
Breadth-First Search David Johnson. Today Look at one version of Breadth-first search on a grid Develop Matlab version of BFS.
CS171 Introduction to Computer Science II Graphs Strike Back.
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
Using Search in Problem Solving
COMP171 Depth-First Search.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Using Search in Problem Solving
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Uninformed Search (cont.)
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
Chapter 5.4 Artificial Intelligence: Pathfinding.
State-Space Searches.
Informed Search Idea: be smart about what paths to try.
CMU Snake Robot
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Chapter 5.4 Artificial Intelligence: Pathfinding.
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.
Lab 3 How’d it go?.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
GRAPHS
WAES 3308 Numerical Methods for AI
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l inference l all learning.
BackTracking CS335. N-Queens The object is to place queens on a chess board in such as way as no queen can capture another one in a single move –Recall.
P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.
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.
Artificial Intelligence in Game Design Dynamic Path Planning Algorithms.
COMP261 Lecture 7 A* Search. A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
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.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Search (continued) CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
REFERENCE: “ARTIFICIAL INTELLIGENCE FOR GAMES”, IAN MILLINGTON. A* (A-STAR)
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
CPSC 322, Lecture 6Slide 1 Uniformed Search (cont.) Computer Science cpsc322, Lecture 6 (Textbook finish 3.5) Sept, 17, 2012.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Best-first search is a search algorithm which explores a graph by expanding the most promising node chosen according to a specified rule.
A* Reference: “Artificial Intelligence for Games”, Ian Millington.
Graphs – Part III CS 367 – Introduction to Data Structures.
Graphs - II CS 2110, Spring Where did David leave that book? 2.
Chapter 5.4 Artificial Intelligence: Pathfinding
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Reference: “Artificial Intelligence for Games”, Ian Millington.
Team 17c ****** Pathfinding
Graphs Part 2 Adjacency Matrix
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Graph Search in C++ Andrew Lindsay.
Presentation transcript:

A* Reference: “Artificial Intelligence for Games”, Ian Millington.

Goals Find a “pretty- short” path from point A to point B. – The best path is often prohibitively expensive to find. S G

Graph-based algorithm Graph – Vertices (Nodes) – Edges Single edge Double edge Cost – (For map traversal), distance is the norm – Cost multiplier (>1) for rough terrain. Representation – Adjacency Matrix – Adjacency List

Graph Nodes vs. Search Nodes Graph Start == 0, Goal == 6 Search Tree There are usually many search trees for the same graph. 2.0

Graph Nodes vs. Search Nodes, cont. One approach: – GraphNode(id, …) Id … Neighbor_refs = […] # Or this could be stored in map – SearchNode(graphNode, parent) Parent is None for the starting node Create a search node as you traverse the graph.

Depth-first search S G Need a (bool) visited value for each graph node (to prevent re-visiting). Visit a (“random”) new node from the current node. Total Cost is the edge cost of all edges traversed. We have to try all possible search graphs to find the least costly path – EXPENSIVE! Total=17 Total=19

Breadth-first search S G Need a list of “frontier” nodes and a (bool) visited flag. Expand the frontier by one hop each iteration. We end up with several search trees. Problem: A lot of search trees – MEMORY + TIME INTENSIVE (especially for large graphs). The search trees are dependent on the graph structure (2=>6 vs 0=>6)

Heuristics (dictionary.reference.com) Pertaining to a trial- and-error method of problem solving used when an algorithmic approach is impractical. In A*: an estimate of how far a given node is from the goal state. – Accuracy is critical to good performance of A* – For path-finding, often the straight-line distance. We'll store 3 things for each search node: – The parent search node (if any) – The cost-so-far value – The cost-heuristic

OPEN, CLOSED “lists” We'll maintain two "lists" of search nodes: – OPEN: Those on the search "frontier" – CLOSED: Those we've already visited – anything not on these lists is unexplored The graph node doesn't have a search node. Often more efficient to maintain: – A Priority Queue for OPEN – A state variable for each search node (OPEN or CLOSED)

A* Algorithm 1.Create search node for Start Node a)Parent = None b)Cost-so-far = 0 c)Heuristic = (distance to goal) 2.Add this new node to OPEN 3.Repeat these steps until OPEN isn’t empty. a)Take the best node, C, off OPEN i.If C is the goal, construct a Graph-node sequence and return. ii.If not, add C to CLOSED. b)Repeat for each of C's neighbors, N: i.If N is unexplored, create a Search Node for it and add it to OPEN. ii.If N is on OPEN and path from C c.s.f. + cost(C,N) < N c.s.f. : – Update the parent and cost-so-far of N – Reheapify that node on OPEN iii.If N is on CLOSED and path from C c.s.f. + cost(C,N) < N c.s.f. : – remove it from CLOSED and put it on OPEN – Update the parent and cost-so-far of N 4.Return False (no path found)

MinHeap + A* A* uses this as its "metric" CostSoFar (actual cost from start to this node) + Heuristic (estimated cost from this node to the goal) Note: The heuristic is almost always an under- estimate. So…we give priority to those nodes that appear to take us closer to the goal.

Under-/over-estimating heuristic Very important to get as close as possible! – Too high => find a "bad" path before a "good" – Too low => look at too many nodes.

Nav-Meshes A common way to represent: – Walkable areas of a map. – Cover-spots – Jumping-points (to cross a chasm) – Ladders – Save points, ammo drops, etc. Key Ideas: – Not usually visible – Usually much lower poly-count than the actual ground

Nav-Meshes, cont. Display Mesh (16541 faces) Nav Mesh (301 faces)

Nav-Meshes, cont. We can use these for pathfinding… – Nodes are faces (their center?) – Edges are connections between neighboring faces Cost is just the euclidean distance between centers. Probably best done off-line – Finding neighbors can be costly.

Another application of A* … … … … … … … … … … Hueristic?