Download presentation
Presentation is loading. Please wait.
Published byNickolas Williams Modified over 9 years ago
1
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
2
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; }
3
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); }
4
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 10 -7 < 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?
5
Limiting Re-expansion Only re-visit a node in BFS when –We find a new path with a lower cost to that node
6
Re-Expansion Wastes CPU
7
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
8
c, 10 s Take the Smallest Entry in Wavefront? source dest c a b d wavefront = 0 1 2 3 {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
9
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
10
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
11
Anything Faster than Binary Tree? Heap –Insertion: O(log N) –Removal of smallest element: O(log N) –But absolute time smaller than binary tree
12
(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 3 20 36 40 35 3760 50 Smallest item always at root of heap No ordering between sibling nodes in the heap
13
BFS and Dijkstra Demo
14
Better than Dijkstra’s Algorithm?
15
Dijkstra / BFS: Not So Smart! Why are we examining nodes in the wrong direction? Wasted CPU time!
16
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
17
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”
18
A* Search Mostly searches in the right direction, but will explore some in other directions Can go around blockages (e.g. 401)
19
A* Demo
20
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!
21
Milestone 3 User Interface Make it usable: 4% of final mark Lots of ideas in m3 handout –Don’t need to implement them all
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.