lab2sol - CSE 542 Advanced Data Structures and Algorithms...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
- 1 - Part 1 . The source for the modified shortPath class appears below. ... class shortPath : public augPath { public: shortPath(Flograph&,int&); private: bool findPath(); int pathCount; int basicStepCount; }; --------------------------- #include "shortPath.h" shortPath::shortPath(Flograph& fg1, int& floVal) : augPath(fg1,floVal) { // Find maximum flow in fg using the shortest augment path algorithm. pathCount = basicStepCount = 0; floVal = 0; while(findPath()) { floVal += augment(); } cout << "pathCount=" << pathCount << " basicStepCount=" << basicStepCount << endl; } bool shortPath::findPath() { // Find a shortest path with unused residual capacity. vertex u,v; edge e; UiList queue(fg->n()); pathCount++; for (u = 1; u <= fg->n(); u++) pEdge[u] = 0; queue.addLast(fg->src()); while (!queue.empty()) { u = queue.first(); queue.removeFirst(); for (e = fg->firstAt(u); e != 0; e = fg->nextAt(u,e)) { basicStepCount++; v = fg->mate(u,e); CSE 542 – Advanced Data Structures and Algorithms Lab 2 Solution Jon Turner
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
- 2 - if (fg->res(u,e) > 0 && pEdge[v] == 0 && v != fg->src()) { pEdge[v] = e; if (v == fg->snk()) return true; queue.addLast(v); } } } return false; }
Background image of page 2
- 3 - The table below shows the results from the experiments and the analysis. The path bound was computed as the product mn and the stepBound as 2 m 2 n . We observe that both of these are far larger than the experimental values. StepBound 2 was computed by multiplying pathCount by 2 m . We note that this is fairly close to stepCount , indicating that the discrepancy between the experimental results and the worst-case analysis can be explained almost entirely by the fact that in practice, the number of path searches is much smaller than the bound. This is not really too surprising since the worst-case analysis allows for the possibility of edges “reversing direction” many times, where this is not likely to happen very often in practice. It’s also worth noting that the random graphs have edge capacities that will likely limit the number of path searches. The source and sink each have n /10 edges with an average capacity that is four times larger than the average capacity of the other edges in the flow graph. This suggests that a given source/sink edge would saturate after being used by about four paths. This leads to an estimated path count of 4 n /10, which for the given values of n is 20, 40, 80, 160 and 400. These values track fairly closely with the measured pathCount values. Part 2 . The table of values appears below. In this case, pathBound is computed as 2 k 3 . It differs from the experimental value by 1, only because the experimental value includes the final “failed search” where pathBound counts only the successful searches. The stepBound is computed as 2 m times the pathBound. This tracks the stepCount closely, but overestimates by a small factor. The difference between these results and the results for random graphs is quite striking. Here, a
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/08/2012 for the course CSE 542 taught by Professor Jonturner during the Spring '12 term at Washington State University .

Page1 / 9

lab2sol - CSE 542 Advanced Data Structures and Algorithms...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online