[12] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2011 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[10] | 19 | #include <benchmark_tools.h> |
---|
[9] | 20 | #include <lemon/circulation.h> |
---|
| 21 | #include <lemon/smart_graph.h> |
---|
| 22 | #include <lemon/lgf_reader.h> |
---|
| 23 | #include <lemon/dimacs.h> |
---|
| 24 | #include <lemon/error.h> |
---|
[11] | 25 | #include <istream> |
---|
[9] | 26 | |
---|
[11] | 27 | std::string test_name = "circulation"; |
---|
[9] | 28 | |
---|
| 29 | using namespace lemon; |
---|
| 30 | |
---|
[11] | 31 | int testMain(std::istream &input) |
---|
[9] | 32 | { |
---|
| 33 | typedef int Value; |
---|
| 34 | |
---|
| 35 | SmartDigraph g; |
---|
| 36 | |
---|
| 37 | SmartDigraph::ArcMap<Value> lo_cap(g); |
---|
| 38 | SmartDigraph::ArcMap<Value> up_cap(g); |
---|
| 39 | SmartDigraph::ArcMap<Value> cost(g); |
---|
| 40 | SmartDigraph::NodeMap<Value> sup(g); |
---|
| 41 | |
---|
| 42 | Timer ti; |
---|
| 43 | try { |
---|
| 44 | readDimacsMin(input, g, lo_cap, up_cap, cost, sup); |
---|
| 45 | } catch (FormatError& error) { |
---|
| 46 | std::cerr << error.what() << std::endl; |
---|
| 47 | return 1; |
---|
| 48 | } |
---|
[11] | 49 | logTime("fread",ti); |
---|
[10] | 50 | |
---|
| 51 | Timer tf; |
---|
[9] | 52 | ti.restart(); |
---|
| 53 | Circulation<SmartDigraph, |
---|
| 54 | SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>, |
---|
| 55 | SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup); |
---|
[10] | 56 | logTime("setup",ti); |
---|
[9] | 57 | ti.restart(); |
---|
| 58 | bool res = circ.run(); |
---|
[10] | 59 | logTime("alg",ti); |
---|
| 60 | logTime("full",tf); |
---|
[9] | 61 | if(res) |
---|
| 62 | { |
---|
[10] | 63 | std::cerr << "A feasible circulation is found\n"; |
---|
| 64 | std::cerr << "Checking...\n"; |
---|
[9] | 65 | ti.restart(); |
---|
| 66 | bool res2 = circ.checkFlow(); |
---|
[10] | 67 | logTime("check",ti); |
---|
[9] | 68 | if(res2) |
---|
[10] | 69 | std::cerr << "Success!\n"; |
---|
[9] | 70 | else |
---|
[10] | 71 | std::cerr << "Oops!!!!\n"; |
---|
[9] | 72 | } |
---|
| 73 | else |
---|
| 74 | { |
---|
[10] | 75 | std::cerr << "A dual solution is found\n"; |
---|
| 76 | std::cerr << "Checking...\n"; |
---|
[9] | 77 | ti.restart(); |
---|
| 78 | bool res2 = circ.checkBarrier(); |
---|
[10] | 79 | logTime("check",ti); |
---|
[9] | 80 | if(res2) |
---|
[10] | 81 | std::cerr << "Success!\n"; |
---|
[9] | 82 | else |
---|
[10] | 83 | std::cerr << "Dual-Oops!!!!\n"; |
---|
[9] | 84 | |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|