alpar@906: /* -*- C++ -*- alpar@906: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@2553: * Copyright (C) 2003-2008 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1359: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@906: alpar@899: #include alpar@899: #include "test_tools.h" alpar@921: #include deba@2276: #include alpar@899: //#include alpar@899: //#include alpar@899: alpar@921: using namespace lemon; alpar@899: alpar@899: alpar@899: bool passed = true; alpar@899: /* alpar@899: void check(bool rc, char *msg="") { alpar@899: passed = passed && rc; alpar@899: if(!rc) { alpar@899: std::cerr << "Test failed! ("<< msg << ")" << std::endl; \ alpar@899: alpar@899: alpar@899: } alpar@899: } alpar@899: */ alpar@899: alpar@899: alpar@899: int main() alpar@899: { marci@941: typedef ListGraph Graph; marci@941: typedef Graph::Node Node; marci@941: typedef Graph::Edge Edge; alpar@899: marci@941: Graph graph; alpar@899: alpar@899: //Ahuja könyv példája alpar@899: alpar@899: Node s=graph.addNode(); alpar@899: Node v1=graph.addNode(); alpar@899: Node v2=graph.addNode(); alpar@899: Node v3=graph.addNode(); alpar@899: Node v4=graph.addNode(); alpar@899: Node v5=graph.addNode(); alpar@899: Node t=graph.addNode(); alpar@899: alpar@899: Edge s_v1=graph.addEdge(s, v1); alpar@899: Edge v1_v2=graph.addEdge(v1, v2); alpar@899: Edge s_v3=graph.addEdge(s, v3); alpar@899: Edge v2_v4=graph.addEdge(v2, v4); alpar@899: Edge v2_v5=graph.addEdge(v2, v5); alpar@899: Edge v3_v5=graph.addEdge(v3, v5); alpar@899: Edge v4_t=graph.addEdge(v4, t); alpar@899: Edge v5_t=graph.addEdge(v5, t); alpar@899: alpar@899: marci@941: Graph::EdgeMap length(graph); alpar@899: alpar@899: length.set(s_v1, 6); alpar@899: length.set(v1_v2, 4); alpar@899: length.set(s_v3, 10); alpar@899: length.set(v2_v4, 5); alpar@899: length.set(v2_v5, 1); alpar@899: length.set(v3_v5, 4); alpar@899: length.set(v4_t, 8); alpar@899: length.set(v5_t, 8); alpar@899: marci@941: Graph::EdgeMap capacity(graph); alpar@899: alpar@899: capacity.set(s_v1, 2); alpar@899: capacity.set(v1_v2, 2); alpar@899: capacity.set(s_v3, 1); alpar@899: capacity.set(v2_v4, 1); alpar@899: capacity.set(v2_v5, 1); alpar@899: capacity.set(v3_v5, 1); alpar@899: capacity.set(v4_t, 1); alpar@899: capacity.set(v5_t, 2); alpar@899: alpar@899: // ConstMap const1map(1); alpar@899: std::cout << "Mincostflows algorithm test..." << std::endl; alpar@899: deba@2276: SspMinCostFlow< Graph, Graph::EdgeMap, Graph::EdgeMap > marci@941: surb_test(graph, length, capacity, s, t); alpar@899: alpar@899: int k=1; alpar@899: marci@941: surb_test.augment(); marci@941: check( surb_test.flowValue() == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); marci@941: marci@941: check( surb_test.run(k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19"); alpar@899: alpar@899: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); alpar@899: alpar@899: k=2; alpar@899: marci@941: check( surb_test.run(k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41"); alpar@899: alpar@899: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); alpar@899: marci@941: surb_test.augment(); marci@941: surb_test.augment(); marci@941: surb_test.augment(); alpar@899: k=4; alpar@899: marci@941: check( surb_test.run(k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64"); alpar@899: alpar@899: check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?"); alpar@899: alpar@899: marci@941: std::cout << (passed ? "All tests passed." : "Some of the tests failed!!!") marci@941: << std::endl; alpar@899: alpar@899: return passed ? 0 : 1; alpar@899: alpar@899: }