alpar@906: /* -*- C++ -*- alpar@906: * src/test/min_cost_flow_test.cc - Part of HUGOlib, a generic C++ optimization library alpar@906: * alpar@906: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@906: * (Egervary Combinatorial Optimization Research Group, 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@899: #include alpar@899: #include alpar@899: //#include alpar@899: //#include alpar@899: alpar@899: using namespace std; alpar@899: using namespace hugo; alpar@899: 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: { alpar@899: alpar@899: typedef ListGraph::Node Node; alpar@899: typedef ListGraph::Edge Edge; alpar@899: alpar@899: ListGraph 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: alpar@899: ListGraph::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: alpar@899: ListGraph::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: alpar@899: MinCostFlow< ListGraph, ListGraph::EdgeMap, ListGraph::EdgeMap > alpar@899: surb_test(graph, length, capacity); alpar@899: alpar@899: int k=1; alpar@899: alpar@899: check( surb_test.run(s,t,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: alpar@899: check( surb_test.run(s,t,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: alpar@899: alpar@899: k=4; alpar@899: alpar@899: check( surb_test.run(s,t,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: alpar@899: cout << (passed ? "All tests passed." : "Some of the tests failed!!!") alpar@899: << endl; alpar@899: alpar@899: return passed ? 0 : 1; alpar@899: alpar@899: }