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

Slides:



Advertisements
Similar presentations
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Advertisements

CS 206 Introduction to Computer Science II 03 / 23 / 2009 Instructor: Michael Eckmann.
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.
Chapter 5 Decrease and Conquer. Homework 7 hw7 (due 3/17) hw7 (due 3/17) –page 127 question 5 –page 132 questions 5 and 6 –page 137 questions 5 and 6.
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.
Chapter 6: Transform and Conquer
CMPT 225 Priority Queues and Heaps. Priority Queues Items in a priority queue have a priority The priority is usually numerical value Could be lowest.
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.
CS 206 Introduction to Computer Science II 10 / 31 / 2008 Happy Halloween!!! Instructor: Michael Eckmann.
Using Search in Problem Solving
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 261 – Data Structures Priority Queues & Heaps.
COMP171 Depth-First Search.
Using Search in Problem Solving
Transforming Infix to Postfix
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 5.4 Artificial Intelligence: Pathfinding.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 CSC 427: Data Structures and Algorithm Analysis Fall 2010 transform & conquer  transform-and-conquer approach  balanced search trees o AVL, 2-3 trees,
1 Priority Queues (Heaps)  Sections 6.1 to The Priority Queue ADT  DeleteMin –log N time  Insert –log N time  Other operations –FindMin  Constant.
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
Heapsort Based off slides by: David Matuszek
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.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
GRAPHS
WAES 3308 Numerical Methods for AI
ADT Table and Heap Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 5 Binary Trees. Definitions and Properties A binary tree is made up of a finite set of elements called nodes A binary tree is made up of a finite.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
1 CSC 421: Algorithm Design Analysis Spring 2014 Transform & conquer  transform-and-conquer approach  presorting  balanced search trees, heaps  Horner's.
Priority Queues and Binary Heaps Chapter Trees Some animals are more equal than others A queue is a FIFO data structure the first element.
Chapter 21 Priority Queue: Binary Heap Saurav Karmakar.
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.
Starting at Binary Trees
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
Chapter 9 Priority Queues, Heaps, Graphs 1 Fall 2010.
PRIORITY QUEUES AND HEAPS CS16: Introduction to Data Structures & Algorithms Tuesday, February 24,
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Queues, Stacks and Heaps. Queue List structure using the FIFO process Nodes are removed form the front and added to the back ABDC FrontBack.
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.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
REFERENCE: “ARTIFICIAL INTELLIGENCE FOR GAMES”, IAN MILLINGTON. A* (A-STAR)
Tree Data Structures. Heaps for searching Search in a heap? Search in a heap? Would have to look at root Would have to look at root If search item smaller.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Priority Queues, Heaps, and Heapsort CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
CS 367 Introduction to Data Structures Lecture 8.
Priority Queues CS 110: Data Structures and Algorithms First Semester,
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
A* Reference: “Artificial Intelligence for Games”, Ian Millington.
1 CSC 421: Algorithm Design Analysis Spring 2013 Transform & conquer  transform-and-conquer approach  presorting  balanced search trees, heaps  Horner's.
Heaps, Heap Sort, and Priority Queues. Background: Binary Trees * Has a root at the topmost level * Each node has zero, one or two children * A node that.
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
Priority Queues and Heaps
Hashing Exercises.
CS Anya E. Vostinar Grinnell College
Data Structures and Database Applications Binary Trees in C#
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Trees 1: Theory, Models, Generic Heap Algorithms, Priority Queues
Outline This topic covers Prim’s algorithm:
Reference: “Artificial Intelligence for Games”, Ian Millington.
Heapsort.
Heapsort.
Priority Queues & Heaps
Heaps Chapter 6 Section 6.9.
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 … searchNode = None – SearchNode(graphNode, parent) You could also have a list of children (instead of parent) 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) – We don't then need a list for 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 as long as OPEN is 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 iii.If N is on CLOSED and path from C c.s.f. + cost(C,N) < N c.s.f. : – remove it from CLOSED (???) – Update the parent and cost-so-far of N – Add N to OPEN (???) 4.Return False (no path found)

MinHeap (OPEN list) A bottle-neck is Step3a (finding best node on OPEN) Recall: OPEN is a priority-queue (lowest total cost first) A good data structure is a MinHeap – Adds: O(log n) – Removes: O(log n) – Membership: O(n), but we don't have to use this…if we're clever.

MinHeap, cont. Logical Structure: – a binary tree root is always the lowest valued node (highest priority) – a "generation" is completely filled L=>R – a node always has lower value than all descendents

MinHeap, cont. Internal structure – A list of nodes (not a tree) First element (pos=0) is a dummy node Nodes are stored L=>R, T=>B (if looking at the tree) pos node??

MinHeap, cont. Internal structure, cont. – Interesting (useful) properties For any given node index i, not the root: – i / 2 is the parent's index » i >> 1 For any given node index i, – The left child is i * 2 (i << 1) » If this value is >= len(list), there are no children – The right child is i * (i << 1 + 1) » If this value is >= len(list), the node doesn't have a right child pos node??

MinHeap (add) Step1: Add the new node to the end of the list Step2: Ensure heap constraints are satisfied. – Swap nodes if child > parent. Then check new parent against its parent pos node?? pos node?? pos node?? pos node?? Add Node(6.8) Parent(12.1) >= Child(6.8) Parent(10.3) >= Child(6.8)

MinHeap (remove) Step1: Swap the node is position 1 and position len(list)-1. Step2: Pop the last node (and save it to return at the end) Step3: Ensure heap constraints are satisfied (swap if necessary). – If the root is bigger than either child, swap the root with the smallest child. Check this node against its children recursively. – If not, end pos node?? Swap (19.8) and remove 4.5 Swap 19.8 with 7.0 Swap 8.5 with 19.8 pos node?? pos node?? pos node??

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?