Finished MinLengthPaths: a specialization of MinCostFlows.
2 #include <list_graph.h>
3 #include <minlengthpaths.h>
13 void check(bool rc, char *msg="") {
14 passed = passed && rc;
16 std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
27 typedef ListGraph::Node Node;
28 typedef ListGraph::Edge Edge;
34 Node s=graph.addNode();
35 Node v1=graph.addNode();
36 Node v2=graph.addNode();
37 Node v3=graph.addNode();
38 Node v4=graph.addNode();
39 Node v5=graph.addNode();
40 Node t=graph.addNode();
42 Edge s_v1=graph.addEdge(s, v1);
43 Edge v1_v2=graph.addEdge(v1, v2);
44 Edge s_v3=graph.addEdge(s, v3);
45 Edge v2_v4=graph.addEdge(v2, v4);
46 Edge v2_v5=graph.addEdge(v2, v5);
47 Edge v3_v5=graph.addEdge(v3, v5);
48 Edge v4_t=graph.addEdge(v4, t);
49 Edge v5_t=graph.addEdge(v5, t);
52 ListGraph::EdgeMap<int> length(graph);
63 std::cout << "Minlengthpaths algorithm test..." << std::endl;
67 MinLengthPaths< ListGraph, ListGraph::EdgeMap<int> >
68 surb_test(graph, length);
70 check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46");
72 check( surb_test.checkComplementarySlackness(), "Complementary slackness conditions are not met.");
74 typedef DirPath<ListGraph> DPath;
77 surb_test.getPath(P,0);
78 check(P.length() == 4, "First path should contain 4 edges.");
80 surb_test.getPath(P,1);
81 check(P.length() == 3, "Second path: 3 edges.");
84 check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
86 check( surb_test.checkComplementarySlackness(), "Complementary slackness conditions are not met.");
88 surb_test.getPath(P,0);
89 check(P.length() == 4, "First path should contain 4 edges.");
91 cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
94 return passed ? 0 : 1;