65 Edge v3_v5=graph.addEdge(v3, v5); |
63 Edge v3_v5=graph.addEdge(v3, v5); |
66 Edge v4_t=graph.addEdge(v4, t); |
64 Edge v4_t=graph.addEdge(v4, t); |
67 Edge v5_t=graph.addEdge(v5, t); |
65 Edge v5_t=graph.addEdge(v5, t); |
68 |
66 |
69 |
67 |
70 ListGraph::EdgeMap<int> length(graph); |
68 Graph::EdgeMap<int> length(graph); |
71 |
69 |
72 length.set(s_v1, 6); |
70 length.set(s_v1, 6); |
73 length.set(v1_v2, 4); |
71 length.set(v1_v2, 4); |
74 length.set(s_v3, 10); |
72 length.set(s_v3, 10); |
75 length.set(v2_v4, 5); |
73 length.set(v2_v4, 5); |
76 length.set(v2_v5, 1); |
74 length.set(v2_v5, 1); |
77 length.set(v3_v5, 4); |
75 length.set(v3_v5, 4); |
78 length.set(v4_t, 8); |
76 length.set(v4_t, 8); |
79 length.set(v5_t, 8); |
77 length.set(v5_t, 8); |
80 |
78 |
81 ListGraph::EdgeMap<int> capacity(graph); |
79 Graph::EdgeMap<int> capacity(graph); |
82 |
80 |
83 capacity.set(s_v1, 2); |
81 capacity.set(s_v1, 2); |
84 capacity.set(v1_v2, 2); |
82 capacity.set(v1_v2, 2); |
85 capacity.set(s_v3, 1); |
83 capacity.set(s_v3, 1); |
86 capacity.set(v2_v4, 1); |
84 capacity.set(v2_v4, 1); |
90 capacity.set(v5_t, 2); |
88 capacity.set(v5_t, 2); |
91 |
89 |
92 // ConstMap<Edge, int> const1map(1); |
90 // ConstMap<Edge, int> const1map(1); |
93 std::cout << "Mincostflows algorithm test..." << std::endl; |
91 std::cout << "Mincostflows algorithm test..." << std::endl; |
94 |
92 |
95 MinCostFlow< ListGraph, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > |
93 MinCostFlow< Graph, Graph::EdgeMap<int>, Graph::EdgeMap<int> > |
96 surb_test(graph, length, capacity); |
94 surb_test(graph, length, capacity, s, t); |
97 |
95 |
98 int k=1; |
96 int k=1; |
99 |
97 |
100 check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); |
98 surb_test.augment(); |
|
99 check( surb_test.flowValue() == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); |
|
100 |
|
101 check( surb_test.run(k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); |
101 |
102 |
102 check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); |
103 check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); |
103 |
104 |
104 k=2; |
105 k=2; |
105 |
106 |
106 check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41"); |
107 check( surb_test.run(k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41"); |
107 |
108 |
108 check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); |
109 check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); |
109 |
110 |
110 |
111 surb_test.augment(); |
|
112 surb_test.augment(); |
|
113 surb_test.augment(); |
111 k=4; |
114 k=4; |
112 |
115 |
113 check( surb_test.run(s,t,k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64"); |
116 check( surb_test.run(k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64"); |
114 |
117 |
115 check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); |
118 check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); |
116 |
119 |
117 |
120 |
118 cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
121 std::cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
119 << endl; |
122 << std::endl; |
120 |
123 |
121 return passed ? 0 : 1; |
124 return passed ? 0 : 1; |
122 |
125 |
123 } |
126 } |