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@611: length.set(v3_v5, 5); athos@611: length.set(v4_t, 8); athos@611: length.set(v5_t, 8); athos@611: athos@611: ConstMap const1map(1); athos@611: std::cout << "Mincostflows algorithm test..." << std::endl; athos@611: athos@611: athos@611: int k=3; athos@611: MinCostFlows< ListGraph, ListGraph::EdgeMap, ConstMap > athos@611: surb_test(graph, length, const1map); athos@611: athos@611: check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,"Two paths, total length should be 46"); athos@611: athos@611: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); athos@611: athos@611: k=1; 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@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: }