Administration CI meetings resume next week, as usual Some TAs in labs, plus Dr. Betz –Go to your...

21
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

Transcript of Administration CI meetings resume next week, as usual Some TAs in labs, plus Dr. Betz –Go to your...

Page 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.

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

Page 2: 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.

BFS with Re-expansionbool 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 < node->pathLen) { node->reachingEdge = wave.edgeID; node->pathLen = wave.pathLen;

if (node->id == destID) { found = true; bestPathLen = node->pathLen; }

Page 3: 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.

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); }

Page 4: 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.

Complexitywhile (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(2N) of DFS with re-expansion

• How could we limit re-expansion?

Page 5: 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.

Limiting Re-expansion

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

node

Page 6: 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.

Re-Expansion Wastes CPU

Page 7: 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.

BFS Wavefrontbool bfsPath (Node* sourceNode, int destID) {

list<waveElem> 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 < node->pathLen) { ... wavefront.push_back ( waveElem(toNode, outEdge.id, node.pathLen + travelTime (outEdge)); ...

78, 20s 2, 5s 39, 12s Wavefront: FIFO Queue

Page 8: 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.

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 = 5 s

t = 20 s

t = 6 s

t = 3 s Found shortest path with no re-expansion

Djikstra’s algorithm

Page 9: 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.

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(N0.5)

• Binary tree?– Insertion: O(log M)– Remove smallest

• O(log M)

78, 20s 2, 5s 39, 12s list<waveElem> wavefront

Page 10: 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.

Overall Complexity

• O(N) items added/removed in wavefront– Work to remove next item:

• Linked list: O(M) O(N0.5) to O(N)• Binary tree: O(log M) O (log N)

• Overall complexity– Linked list: O(N1.5) to O(N2)

• N 100,000 and ~10-7 s per function• 3.2 s to 1000 s (wide range!)

– Binary tree: O(N logN)• <1 s

Page 11: 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.

Anything Faster than Binary Tree?

• Heap– Insertion: O(log N)– Removal of smallest element: O(log N)– But absolute time smaller than binary tree

Page 12: 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.

(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 37 60

50

Smallest item always at root

of heap

No ordering between sibling

nodes in the heap

Page 13: 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.

BFS and Dijkstra Demo

Page 14: 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.

Better than Dijkstra’s Algorithm?

Page 15: 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.

Dijkstra / BFS: Not So Smart!

Why are we examining nodes in the wrong direction?Wasted CPU time!

Page 16: 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.

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

Page 17: 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.

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”

Page 18: 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.

A* Search

Mostly searches in the right direction, but will explore some in other directions

Can go around blockages (e.g. 401)

Page 19: 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.

A* Demo

Page 20: 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.

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!

Page 21: 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.

Milestone 3 User Interface

• Make it usable: 4% of final mark• Lots of ideas in m3 handout

– Don’t need to implement them all