Administration CI meetings resume next week, as usual Some TAs in labs, plus Dr. Betz –Go to your lab as usual –If your TA is not there, ask for help from.

Slides:



Advertisements
Similar presentations
Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
Advertisements

Single Source Shortest Paths
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
COL 106 Shweta Agrawal and Amit Kumar
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Breadth-First Search Graph Algorithm Type #3. Depth-First Search.
CHAPTER 5 PRIORITY QUEUES (HEAPS) §1 ADT Model Objects: A finite ordered list with zero or more elements. Operations:  PriorityQueue Initialize( int.
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.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
Informed Search (no corresponding text chapter). Recall: Wanted " An algorithm and associated data structure(s) that can: 1) Solve an arbitrary 8-puzzle.
Using Search in Problem Solving
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Priority Queues. Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out –The “smallest” element.
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Graphs II Robin Burke GAM 376. Admin Skip the Lua topic.
Milestone 3: Finding Routes ECE 297. Directions: How?
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
DATA STRUCTURES Queues ‘n Stacks Tries, Suffix Trees Heaps Sieve of Eratosthenes.
1 Artificial Intelligence in Games Week 6 Steve Rabin TA: Chi-Hao Kuo TA: Allan.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
CSC 213 – Large Scale Programming Lecture 15: Heap-based Priority Queue.
Data Structure & Algorithm II.  In a multiuser computer system, multiple users submit jobs to run on a single processor.  We assume that the time required.
Priority Queue. Priority Queues Queue (FIFO). Priority queue. Deletion from a priority queue is determined by the element priority. Two kinds of priority.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
1 Finding Shortest Paths with A* Search A* search operates similarly to Dijkstra’s algorithm, but extends the cost function to include an estimated distance.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
Week 8 - Monday.  What did we talk about last time?  BST traversals  Get range implementation.
Priority Queues Two kinds of priority queues: Min priority queue. Max priority queue. Nov 4,
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Queues, Stacks and Heaps. Queue List structure using the FIFO process Nodes are removed form the front and added to the back ABDC FrontBack.
CompSci 100E 30.1 Other N log N Sorts  Binary Tree Sort  Basic Recipe o Insert into binary search tree (BST) o Do Inorder Traversal  Complexity o Create:
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
Heaps & Priority Queues
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
A* Reference: “Artificial Intelligence for Games”, Ian Millington.
Breadth-First Search Graph Algorithm Type #3.
Depth First Seach: Output Fix
Breadth-First Search: Complexity
Priority Queues and Heaps
October 30th – Priority QUeues
Hashing Exercises.
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
March 31 – Priority Queues and the heap
Tutorial 8 An optional eighth tutorial will be held the week of March 6. This tutorial will give you practice with and feedback on oral presentation and.
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.
ITEC 2620M Introduction to Data Structures
Yan Shi CS/SE 2630 Lecture Notes
Milestone 3: Finding Routes
Breadth-First Search Graph Algorithm #2.
Min Heap Update E.g. remove smallest item 1. Pop off top (smallest) 3
Algorithms: Design and Analysis
Efficiently Estimating Travel Time
BFS: Min. Path Issues What happened? Node 1 was re-expanded
CSC 380: Design and Analysis of Algorithms
Priority Queues CSE 373 Data Structures.
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
Priority Queues Supports the following operations. Insert element x.
Heaps & Multi-way Search Trees
Presentation transcript:

Administration CI meetings resume next week, as usual Some TAs in labs, plus Dr. Betz –Go to your lab as usual –If your TA is not there, ask for help from another TA –Update your wiki as usual  we are still grading its quality / your project management Your TA will grade if he/she still working Or if your TA is out at end of term, Dr. Betz + CI will assign grade, based on wiki quality & CI input Self-evaluation of oral presentation 1 –Due Monday, March 9

BFS with Re-expansion bool bfsPath (Node* sourceNode, int destID) {... bool found = false; while (wavefront not empty && has entry < bestPathLen) { waveElem wave = wavefront.front (); wavefront.pop_front(); // Remove from wavefront Node *node = wave.node; if (wave.pathLen pathLen) { node->reachingEdge = wave.edgeID; node->pathLen = wave.pathLen; if (node->id == destID) { found = true; bestPathLen = node->pathLen; }

BFS with Re-expansion for each (outEdge of node) { Node *toNode = outEdge.toNode; wavefront.push_back ( waveElem(toNode, outEdge.id, node.pathLen + travelTime (outEdge)); } } // End if best path to this node } // End while wavefront might yield a better solution return (found); }

Complexity while (wavefront not empty && has entry < bestPathLen) { If we use a visited flag: –Executes maximum N times –Work in loop is O(1)  O(N) ~100,000  < 1 s BFS with re-expansion: –Difficult to bound –But in practice much less than O(2 N ) of DFS with re-expansion How could we limit re-expansion?

Limiting Re-expansion Only re-visit a node in BFS when –We find a new path with a lower cost to that node

Re-Expansion Wastes CPU

BFS Wavefront bool bfsPath (Node* sourceNode, int destID) { list wavefront; while (wavefront not empty && has entry < bestPathLen) { waveElem wave = wavefront.front (); wavefront.pop_front(); // Remove from wavefront Node *node = wave.node; if (wave.pathLen pathLen) {... wavefront.push_back ( waveElem(toNode, outEdge.id, node.pathLen + travelTime (outEdge));... 78, 20s2, 5s39, 12s Wavefront: FIFO Queue

c, 10 s Take the Smallest Entry in Wavefront? source dest c a b d wavefront = {0/0s}{1/20s,2/5s}{1/20s,1/10s}{1/20s,3/16s} 4 {1/20s,4/19s}{1/20s} b, 5 s d, 16 s e, 19 s e t = 5 s t = 20 s t = 6 s t = 3 s Found shortest path with no re-expansion Djikstra’s algorithm

How Much Work To Get Smallest? Linked list –Insertion: O(1) –Remove smallest: scan entire list O(M), where M is active wavefront entries M can be up to O(N), but usually more like O(N 0.5 ) Binary tree? –Insertion: O(log M) –Remove smallest O(log M) 78, 20s2, 5s39, 12s list wavefront

Overall Complexity O(N) items added/removed in wavefront –Work to remove next item: Linked list: O(M)  O(N 0.5 ) to O(N) Binary tree: O(log M)  O (log N) Overall complexity –Linked list: O(N 1.5 ) to O(N 2 ) N  100,000 and ~10 -7 s per function 3.2 s to 1000 s (wide range!) –Binary tree: O(N logN) <1 s

Anything Faster than Binary Tree? Heap –Insertion: O(log N) –Removal of smallest element: O(log N) –But absolute time smaller than binary tree

(Min) Heap Like a binary tree –But not fully sorted Key of parent < key of children –For all nodes in the tree –Very good for priority queues Smallest item always at root of heap No ordering between sibling nodes in the heap

BFS and Dijkstra Demo

Better than Dijkstra’s Algorithm?

Dijkstra / BFS: Not So Smart! Why are we examining nodes in the wrong direction? Wasted CPU time!

Ideas? Only look at nodes that take us closer to the destination? –distToDest(node) < distToDest (predecessor) Too severe – can result in no path, or not shortest path

A* Algorithms Enhancements to Dijkstra’s algorithm Use domain-specific heuristics –E.g. we are working in a map –Can estimate which graph nodes are closer vs. further from dest Incorporate into the wavefront sorting/ordering Look at the most promising partial solutions first “Best-first search”

A* Search Mostly searches in the right direction, but will explore some in other directions Can go around blockages (e.g. 401)

A* Demo

Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques to pass hardest speed tests –Read up online Milestone 4 (another 11% of mark) –Find a good path to connect M intersections Courier company –Will have a CPU time limit –Will benefit from fast path-finding algorithms A good milestone 3 implementation will help you!

Milestone 3 User Interface Make it usable: 4% of final mark Lots of ideas in m3 handout –Don’t need to implement them all