======================================== Notes for Lecture 22 - April 17, 2007 ======================================== * Testing code ** Method *** Run program under different input sets *** Verify that operation is correct on each input set ** Goals of test *** Cause each line of code to be executed (not always easy) *** Try both "normal" and "extreme" cases *** Make sure you know what the correct output/behavior is ** Testing ADT implementations *** Can't run code by itself; a client program is needed *** Client's job is to test, not to do anything useful *** As minimum, each public function must be tested ** Design for testing *** Code can be "instrumented" to facilitate testing *** Extra outputs might be produced to make it easier to verify correct operation *** Public interface to ADT might be expanded to allow direct access to parts of program * Dijkstra's algorithm ** Problem: Find shortest path (if any) in graph between source and sink node ** Method: *** High-level overview **** Mark nodes in increasing order of shortest distance from source **** If sink gets marked, then output path to sink. **** If sink does not get marked, the output "no path". *** At each stage, nodes are split into three sets: **** Marked nodes: Shortest distance from source is known. **** Unmarked neighbors of marked nodes. **** Other nodes *** Fact Let e = (u, w, v) be an edge from u to v of weight w. Let u be marked and v unmarked. (v is a neighbor of u.) Let c_e = d_u + w, where d_u is u's distance from the source. Let c be the minimum over all c_e such that e is an edge from a marked to an unmarked node. Then if e = (u w, v) is such an edge and c_e = c, the shortest path from source to v has length c, and e is the last edge on a shortest path from source to e. *** Algorithm Whenever a node is marked, put all edges e from it into a heap ordered by c_e. To decide which node to mark next, repeatedly use delete_min() from heap to find an edge whose head node (destination) is not marked. Mark the head node. ** Implementation (see 22.1_dijkstra class demo) Note that modules util, flexbuf, and heap are drawn from previous work in the course and just used here. The versions of util and heap are identical to those posted for PS8. flexbuf is from my solution to PS4. # Local Variables: # mode: outline # End: