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
alpar@10
     1
#include <benchmark_tools.h>
alpar@9
     2
#include <lemon/circulation.h>
alpar@9
     3
#include <lemon/smart_graph.h>
alpar@9
     4
#include <lemon/lgf_reader.h>
alpar@9
     5
#include <lemon/dimacs.h>
alpar@9
     6
#include <lemon/error.h>
alpar@9
     7
alpar@9
     8
const char test_name[] = "circulation";
alpar@9
     9
alpar@9
    10
using namespace lemon;
alpar@9
    11
alpar@10
    12
int testMain(int argc, char **argv)
alpar@9
    13
{
alpar@9
    14
  if(argc!=2) exit(1);
alpar@9
    15
alpar@9
    16
  typedef int Value;
alpar@9
    17
  
alpar@9
    18
  SmartDigraph g;
alpar@9
    19
  
alpar@9
    20
  SmartDigraph::ArcMap<Value> lo_cap(g);
alpar@9
    21
  SmartDigraph::ArcMap<Value> up_cap(g);
alpar@9
    22
  SmartDigraph::ArcMap<Value> cost(g);
alpar@9
    23
  SmartDigraph::NodeMap<Value> sup(g);
alpar@9
    24
  
alpar@9
    25
  Timer ti;
alpar@9
    26
  try {
alpar@9
    27
    std::ifstream input;
alpar@9
    28
    input.open(argv[1]);
alpar@9
    29
    readDimacsMin(input, g, lo_cap, up_cap, cost, sup);
alpar@9
    30
  } catch (FormatError& error) {
alpar@9
    31
    std::cerr << error.what() << std::endl;
alpar@9
    32
    return 1;
alpar@9
    33
  }
alpar@10
    34
  logTime("file-read",ti);
alpar@10
    35
alpar@10
    36
  Timer tf;
alpar@9
    37
  ti.restart();
alpar@9
    38
  Circulation<SmartDigraph,
alpar@9
    39
    SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
alpar@9
    40
    SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
alpar@10
    41
  logTime("setup",ti);
alpar@9
    42
  ti.restart();
alpar@9
    43
  bool res = circ.run();
alpar@10
    44
  logTime("alg",ti);
alpar@10
    45
  logTime("full",tf);
alpar@9
    46
  if(res)
alpar@9
    47
    {
alpar@10
    48
      std::cerr << "A feasible circulation is found\n";
alpar@10
    49
      std::cerr << "Checking...\n";
alpar@9
    50
      ti.restart();
alpar@9
    51
      bool res2 = circ.checkFlow();
alpar@10
    52
      logTime("check",ti);
alpar@9
    53
      if(res2)
alpar@10
    54
        std::cerr << "Success!\n";
alpar@9
    55
      else
alpar@10
    56
        std::cerr << "Oops!!!!\n";
alpar@9
    57
    }
alpar@9
    58
  else
alpar@9
    59
    {
alpar@10
    60
      std::cerr << "A dual solution is found\n";
alpar@10
    61
      std::cerr << "Checking...\n";
alpar@9
    62
      ti.restart();
alpar@9
    63
      bool res2 = circ.checkBarrier();
alpar@10
    64
      logTime("check",ti);
alpar@9
    65
      if(res2)
alpar@10
    66
        std::cerr << "Success!\n";
alpar@9
    67
      else
alpar@10
    68
        std::cerr << "Dual-Oops!!!!\n";
alpar@9
    69
alpar@9
    70
    }
alpar@9
    71
}
alpar@9
    72