athos@611: #include athos@611: #include "test_tools.h" athos@611: #include athos@611: #include athos@611: //#include athos@611: //#include athos@611: athos@611: using namespace std; athos@611: using namespace hugo; athos@611: athos@611: athos@611: athos@611: bool passed = true; athos@611: /* athos@611: void check(bool rc, char *msg="") { athos@611: passed = passed && rc; athos@611: if(!rc) { athos@611: std::cerr << "Test failed! ("<< msg << ")" << std::endl; \ athos@611: athos@611: athos@611: } athos@611: } athos@611: */ athos@611: athos@611: athos@611: int main() athos@611: { athos@611: athos@611: typedef ListGraph::Node Node; athos@611: typedef ListGraph::Edge Edge; athos@611: athos@611: ListGraph graph; athos@611: athos@611: //Ahuja könyv példája athos@611: athos@611: Node s=graph.addNode(); athos@611: Node v1=graph.addNode(); athos@611: Node v2=graph.addNode(); athos@611: Node v3=graph.addNode(); athos@611: Node v4=graph.addNode(); athos@611: Node v5=graph.addNode(); athos@611: Node t=graph.addNode(); athos@611: athos@611: Edge s_v1=graph.addEdge(s, v1); athos@611: Edge v1_v2=graph.addEdge(v1, v2); athos@611: Edge s_v3=graph.addEdge(s, v3); athos@611: Edge v2_v4=graph.addEdge(v2, v4); athos@611: Edge v2_v5=graph.addEdge(v2, v5); athos@611: Edge v3_v5=graph.addEdge(v3, v5); athos@611: Edge v4_t=graph.addEdge(v4, t); athos@611: Edge v5_t=graph.addEdge(v5, t); athos@611: athos@611: athos@611: ListGraph::EdgeMap length(graph); athos@611: athos@611: length.set(s_v1, 6); athos@611: length.set(v1_v2, 4); athos@611: length.set(s_v3, 10); athos@611: length.set(v2_v4, 5); athos@611: length.set(v2_v5, 1); athos@630: length.set(v3_v5, 4); athos@611: length.set(v4_t, 8); athos@611: length.set(v5_t, 8); athos@611: athos@630: ListGraph::EdgeMap capacity(graph); athos@630: athos@630: capacity.set(s_v1, 2); athos@630: capacity.set(v1_v2, 2); athos@630: capacity.set(s_v3, 1); athos@630: capacity.set(v2_v4, 1); athos@630: capacity.set(v2_v5, 1); athos@630: capacity.set(v3_v5, 1); athos@630: capacity.set(v4_t, 1); athos@630: capacity.set(v5_t, 2); athos@630: athos@630: // ConstMap const1map(1); athos@611: std::cout << "Mincostflows algorithm test..." << std::endl; athos@611: athos@630: MinCostFlows< ListGraph, ListGraph::EdgeMap, ListGraph::EdgeMap > athos@630: surb_test(graph, length, capacity); athos@611: athos@630: int k=1; athos@611: athos@611: check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); athos@611: athos@611: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); athos@611: athos@630: k=2; athos@630: athos@630: check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41"); athos@630: athos@630: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); athos@630: athos@630: athos@630: k=4; athos@630: athos@630: check( surb_test.run(s,t,k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64"); athos@630: athos@630: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); athos@630: athos@611: athos@611: cout << (passed ? "All tests passed." : "Some of the tests failed!!!") athos@611: << endl; athos@611: athos@611: return passed ? 0 : 1; athos@611: athos@611: }