tools/dimacs-solver.cc
changeset 934 930ddeafdb20
parent 691 8d289c89d43e
child 956 141f9c0db4a3
equal deleted inserted replaced
12:f51eb289c8b3 13:2ec83ad7b967
    89   pre.run();
    89   pre.run();
    90   if(report) std::cerr << "Run Preflow: " << ti << '\n';
    90   if(report) std::cerr << "Run Preflow: " << ti << '\n';
    91   if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';  
    91   if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n';  
    92 }
    92 }
    93 
    93 
    94 template<class Value>
    94 template<class Value, class LargeValue>
    95 void solve_min(ArgParser &ap, std::istream &is, std::ostream &,
    95 void solve_min(ArgParser &ap, std::istream &is, std::ostream &,
    96                Value infty, DimacsDescriptor &desc)
    96                Value infty, DimacsDescriptor &desc)
    97 {
    97 {
    98   bool report = !ap.given("q");
    98   bool report = !ap.given("q");
    99   Digraph g;
    99   Digraph g;
   125   ti.restart();
   125   ti.restart();
   126   bool res = ns.run();
   126   bool res = ns.run();
   127   if (report) {
   127   if (report) {
   128     std::cerr << "Run NetworkSimplex: " << ti << "\n\n";
   128     std::cerr << "Run NetworkSimplex: " << ti << "\n\n";
   129     std::cerr << "Feasible flow: " << (res ? "found" : "not found") << '\n';
   129     std::cerr << "Feasible flow: " << (res ? "found" : "not found") << '\n';
   130     if (res) std::cerr << "Min flow cost: " << ns.totalCost() << '\n';
   130     if (res) std::cerr << "Min flow cost: "
       
   131                        << ns.template totalCost<LargeValue>() << '\n';
   131   }
   132   }
   132 }
   133 }
   133 
   134 
   134 void solve_mat(ArgParser &ap, std::istream &is, std::ostream &,
   135 void solve_mat(ArgParser &ap, std::istream &is, std::ostream &,
   135               DimacsDescriptor &desc)
   136               DimacsDescriptor &desc)
   149   if(report) std::cerr << "\nCardinality of max matching: "
   150   if(report) std::cerr << "\nCardinality of max matching: "
   150                        << mat.matchingSize() << '\n';  
   151                        << mat.matchingSize() << '\n';  
   151 }
   152 }
   152 
   153 
   153 
   154 
   154 template<class Value>
   155 template<class Value, class LargeValue>
   155 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   156 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   156            DimacsDescriptor &desc)
   157            DimacsDescriptor &desc)
   157 {
   158 {
   158   std::stringstream iss(static_cast<std::string>(ap["infcap"]));
   159   std::stringstream iss(static_cast<std::string>(ap["infcap"]));
   159   Value infty;
   160   Value infty;
   167     }
   168     }
   168   
   169   
   169   switch(desc.type)
   170   switch(desc.type)
   170     {
   171     {
   171     case DimacsDescriptor::MIN:
   172     case DimacsDescriptor::MIN:
   172       solve_min<Value>(ap,is,os,infty,desc);
   173       solve_min<Value, LargeValue>(ap,is,os,infty,desc);
   173       break;
   174       break;
   174     case DimacsDescriptor::MAX:
   175     case DimacsDescriptor::MAX:
   175       solve_max<Value>(ap,is,os,infty,desc);
   176       solve_max<Value>(ap,is,os,infty,desc);
   176       break;
   177       break;
   177     case DimacsDescriptor::SP:
   178     case DimacsDescriptor::SP:
   262       std::cout << "\nNum of arcs:  " << desc.edgeNum;
   263       std::cout << "\nNum of arcs:  " << desc.edgeNum;
   263       std::cout << "\n\n";
   264       std::cout << "\n\n";
   264     }
   265     }
   265     
   266     
   266   if(ap.given("double"))
   267   if(ap.given("double"))
   267     solve<double>(ap,is,os,desc);
   268     solve<double, double>(ap,is,os,desc);
   268   else if(ap.given("ldouble"))
   269   else if(ap.given("ldouble"))
   269     solve<long double>(ap,is,os,desc);
   270     solve<long double, long double>(ap,is,os,desc);
   270 #ifdef LEMON_HAVE_LONG_LONG
   271 #ifdef LEMON_HAVE_LONG_LONG
   271   else if(ap.given("long"))
   272   else if(ap.given("long"))
   272     solve<long long>(ap,is,os,desc);
   273     solve<long long, long long>(ap,is,os,desc);
       
   274   else solve<int, long long>(ap,is,os,desc);
       
   275 #else
       
   276   else solve<int, long>(ap,is,os,desc);
   273 #endif
   277 #endif
   274   else solve<int>(ap,is,os,desc);
       
   275 
   278 
   276   return 0;
   279   return 0;
   277 }
   280 }