tests/circulation.cc
changeset 9 7768d68909e8
child 10 d7ce0311ece2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tests/circulation.cc	Sun Dec 11 06:55:47 2011 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +#include <lemon/circulation.h>
     1.5 +#include <lemon/smart_graph.h>
     1.6 +#include <lemon/lgf_reader.h>
     1.7 +#include <lemon/dimacs.h>
     1.8 +#include <lemon/time_measure.h>
     1.9 +#include <lemon/error.h>
    1.10 +
    1.11 +const char test_name[] = "circulation";
    1.12 +
    1.13 +using namespace lemon;
    1.14 +
    1.15 +int main(int argc, char **argv)
    1.16 +{
    1.17 +  if(argc!=2) exit(1);
    1.18 +
    1.19 +  typedef int Value;
    1.20 +  
    1.21 +  SmartDigraph g;
    1.22 +  
    1.23 +  SmartDigraph::ArcMap<Value> lo_cap(g);
    1.24 +  SmartDigraph::ArcMap<Value> up_cap(g);
    1.25 +  SmartDigraph::ArcMap<Value> cost(g);
    1.26 +  SmartDigraph::NodeMap<Value> sup(g);
    1.27 +  
    1.28 +  Timer ti;
    1.29 +  try {
    1.30 +    std::ifstream input;
    1.31 +    input.open(argv[1]);
    1.32 +    readDimacsMin(input, g, lo_cap, up_cap, cost, sup);
    1.33 +  } catch (FormatError& error) {
    1.34 +    std::cerr << error.what() << std::endl;
    1.35 +    return 1;
    1.36 +  }
    1.37 +  std::cerr << "Read the file: " << ti << '\n';
    1.38 +  ti.restart();
    1.39 +  
    1.40 +  Circulation<SmartDigraph,
    1.41 +    SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
    1.42 +    SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
    1.43 +  std::cerr << "Setup Circulation class: " << ti << '\n';
    1.44 +  ti.restart();
    1.45 +  bool res = circ.run();
    1.46 +  if(res)
    1.47 +    {
    1.48 +      std::cerr << "A feasible circulation is found: " << ti << "\n";
    1.49 +      ti.restart();
    1.50 +      bool res2 = circ.checkFlow();
    1.51 +      std::cerr << "Checked in time " << ti << "\n";
    1.52 +      if(res2)
    1.53 +        std::cerr << "Success!\nn";
    1.54 +      else
    1.55 +        std::cerr << "Oops!!!!\n\n";
    1.56 +    }
    1.57 +  else
    1.58 +    {
    1.59 +      std::cerr << "A dual solution is found: " << ti << "\n";
    1.60 +      ti.restart();
    1.61 +      bool res2 = circ.checkBarrier();
    1.62 +      std::cerr << "Checked in time " << ti << "\n";
    1.63 +      if(res2)
    1.64 +        std::cerr << "Success!\nn";
    1.65 +      else
    1.66 +        std::cerr << "Dual-Oops!!!!\n\n";
    1.67 +
    1.68 +    }
    1.69 +}
    1.70 +