tests/circulation.cc
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 11 Dec 2011 06:55:47 +0100
changeset 9 7768d68909e8
child 10 d7ce0311ece2
permissions -rw-r--r--
Circulation test code added
     1 #include <lemon/circulation.h>
     2 #include <lemon/smart_graph.h>
     3 #include <lemon/lgf_reader.h>
     4 #include <lemon/dimacs.h>
     5 #include <lemon/time_measure.h>
     6 #include <lemon/error.h>
     7 
     8 const char test_name[] = "circulation";
     9 
    10 using namespace lemon;
    11 
    12 int main(int argc, char **argv)
    13 {
    14   if(argc!=2) exit(1);
    15 
    16   typedef int Value;
    17   
    18   SmartDigraph g;
    19   
    20   SmartDigraph::ArcMap<Value> lo_cap(g);
    21   SmartDigraph::ArcMap<Value> up_cap(g);
    22   SmartDigraph::ArcMap<Value> cost(g);
    23   SmartDigraph::NodeMap<Value> sup(g);
    24   
    25   Timer ti;
    26   try {
    27     std::ifstream input;
    28     input.open(argv[1]);
    29     readDimacsMin(input, g, lo_cap, up_cap, cost, sup);
    30   } catch (FormatError& error) {
    31     std::cerr << error.what() << std::endl;
    32     return 1;
    33   }
    34   std::cerr << "Read the file: " << ti << '\n';
    35   ti.restart();
    36   
    37   Circulation<SmartDigraph,
    38     SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
    39     SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
    40   std::cerr << "Setup Circulation class: " << ti << '\n';
    41   ti.restart();
    42   bool res = circ.run();
    43   if(res)
    44     {
    45       std::cerr << "A feasible circulation is found: " << ti << "\n";
    46       ti.restart();
    47       bool res2 = circ.checkFlow();
    48       std::cerr << "Checked in time " << ti << "\n";
    49       if(res2)
    50         std::cerr << "Success!\nn";
    51       else
    52         std::cerr << "Oops!!!!\n\n";
    53     }
    54   else
    55     {
    56       std::cerr << "A dual solution is found: " << ti << "\n";
    57       ti.restart();
    58       bool res2 = circ.checkBarrier();
    59       std::cerr << "Checked in time " << ti << "\n";
    60       if(res2)
    61         std::cerr << "Success!\nn";
    62       else
    63         std::cerr << "Dual-Oops!!!!\n\n";
    64 
    65     }
    66 }
    67