tests/circulation.cc
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 11 Dec 2011 07:33:29 +0100
changeset 10 d7ce0311ece2
parent 9 7768d68909e8
child 11 cf6519daa7fa
permissions -rw-r--r--
Some common benchmarking tools added
     1 #include <benchmark_tools.h>
     2 #include <lemon/circulation.h>
     3 #include <lemon/smart_graph.h>
     4 #include <lemon/lgf_reader.h>
     5 #include <lemon/dimacs.h>
     6 #include <lemon/error.h>
     7 
     8 const char test_name[] = "circulation";
     9 
    10 using namespace lemon;
    11 
    12 int testMain(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   logTime("file-read",ti);
    35 
    36   Timer tf;
    37   ti.restart();
    38   Circulation<SmartDigraph,
    39     SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
    40     SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
    41   logTime("setup",ti);
    42   ti.restart();
    43   bool res = circ.run();
    44   logTime("alg",ti);
    45   logTime("full",tf);
    46   if(res)
    47     {
    48       std::cerr << "A feasible circulation is found\n";
    49       std::cerr << "Checking...\n";
    50       ti.restart();
    51       bool res2 = circ.checkFlow();
    52       logTime("check",ti);
    53       if(res2)
    54         std::cerr << "Success!\n";
    55       else
    56         std::cerr << "Oops!!!!\n";
    57     }
    58   else
    59     {
    60       std::cerr << "A dual solution is found\n";
    61       std::cerr << "Checking...\n";
    62       ti.restart();
    63       bool res2 = circ.checkBarrier();
    64       logTime("check",ti);
    65       if(res2)
    66         std::cerr << "Success!\n";
    67       else
    68         std::cerr << "Dual-Oops!!!!\n";
    69 
    70     }
    71 }
    72