tools/dimacs-solver.cc
changeset 1284 ad40f7d32846
parent 956 141f9c0db4a3
parent 1167 c5990f454032
child 1270 dceba191c00d
child 1424 7edc220d6244
     1.1 --- a/tools/dimacs-solver.cc	Fri Aug 09 11:07:27 2013 +0200
     1.2 +++ b/tools/dimacs-solver.cc	Sun Aug 11 15:28:12 2013 +0200
     1.3 @@ -2,7 +2,7 @@
     1.4   *
     1.5   * This file is a part of LEMON, a generic C++ optimization library.
     1.6   *
     1.7 - * Copyright (C) 2003-2009
     1.8 + * Copyright (C) 2003-2010
     1.9   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11   *
    1.12 @@ -88,10 +88,10 @@
    1.13    ti.restart();
    1.14    pre.run();
    1.15    if(report) std::cerr << "Run Preflow: " << ti << '\n';
    1.16 -  if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';  
    1.17 +  if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';
    1.18  }
    1.19  
    1.20 -template<class Value>
    1.21 +template<class Value, class LargeValue>
    1.22  void solve_min(ArgParser &ap, std::istream &is, std::ostream &,
    1.23                 Value infty, DimacsDescriptor &desc)
    1.24  {
    1.25 @@ -128,7 +128,8 @@
    1.26    if (report) {
    1.27      std::cerr << "Run NetworkSimplex: " << ti << "\n\n";
    1.28      std::cerr << "Feasible flow: " << (res == MCF::OPTIMAL ? "found" : "not found") << '\n';
    1.29 -    if (res) std::cerr << "Min flow cost: " << ns.totalCost() << '\n';
    1.30 +    if (res) std::cerr << "Min flow cost: "
    1.31 +                       << ns.template totalCost<LargeValue>() << '\n';
    1.32    }
    1.33  }
    1.34  
    1.35 @@ -148,11 +149,11 @@
    1.36    mat.run();
    1.37    if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
    1.38    if(report) std::cerr << "\nCardinality of max matching: "
    1.39 -                       << mat.matchingSize() << '\n';  
    1.40 +                       << mat.matchingSize() << '\n';
    1.41  }
    1.42  
    1.43  
    1.44 -template<class Value>
    1.45 +template<class Value, class LargeValue>
    1.46  void solve(ArgParser &ap, std::istream &is, std::ostream &os,
    1.47             DimacsDescriptor &desc)
    1.48  {
    1.49 @@ -166,11 +167,11 @@
    1.50                  << std::endl;
    1.51        exit(1);
    1.52      }
    1.53 -  
    1.54 +
    1.55    switch(desc.type)
    1.56      {
    1.57      case DimacsDescriptor::MIN:
    1.58 -      solve_min<Value>(ap,is,os,infty,desc);
    1.59 +      solve_min<Value, LargeValue>(ap,is,os,infty,desc);
    1.60        break;
    1.61      case DimacsDescriptor::MAX:
    1.62        solve_max<Value>(ap,is,os,infty,desc);
    1.63 @@ -235,7 +236,7 @@
    1.64    std::ostream& os = (ap.files().size()<2 ? std::cout : output);
    1.65  
    1.66    DimacsDescriptor desc = dimacsType(is);
    1.67 -  
    1.68 +
    1.69    if(!ap.given("q"))
    1.70      {
    1.71        std::cout << "Problem type: ";
    1.72 @@ -260,16 +261,18 @@
    1.73        std::cout << "\nNum of arcs:  " << desc.edgeNum;
    1.74        std::cout << "\n\n";
    1.75      }
    1.76 -    
    1.77 +
    1.78    if(ap.given("double"))
    1.79 -    solve<double>(ap,is,os,desc);
    1.80 +    solve<double, double>(ap,is,os,desc);
    1.81    else if(ap.given("ldouble"))
    1.82 -    solve<long double>(ap,is,os,desc);
    1.83 +    solve<long double, long double>(ap,is,os,desc);
    1.84  #ifdef LEMON_HAVE_LONG_LONG
    1.85    else if(ap.given("long"))
    1.86 -    solve<long long>(ap,is,os,desc);
    1.87 +    solve<long long, long long>(ap,is,os,desc);
    1.88 +  else solve<int, long long>(ap,is,os,desc);
    1.89 +#else
    1.90 +  else solve<int, long>(ap,is,os,desc);
    1.91  #endif
    1.92 -  else solve<int>(ap,is,os,desc);
    1.93  
    1.94    return 0;
    1.95  }