tools/dimacs-solver.cc
changeset 564 eda12d8ac953
parent 532 997a75bac45a
child 569 24682336c38e
equal deleted inserted replaced
1:2a25b5457ab5 2:a08874be0237
    70   if(report) std::cerr << "Run Dijkstra: " << t << '\n';
    70   if(report) std::cerr << "Run Dijkstra: " << t << '\n';
    71 }
    71 }
    72 
    72 
    73 template<class Value>
    73 template<class Value>
    74 void solve_max(ArgParser &ap, std::istream &is, std::ostream &,
    74 void solve_max(ArgParser &ap, std::istream &is, std::ostream &,
    75               DimacsDescriptor &desc)
    75                Value infty, DimacsDescriptor &desc)
    76 {
    76 {
    77   bool report = !ap.given("q");
    77   bool report = !ap.given("q");
    78   Digraph g;
    78   Digraph g;
    79   Node s,t;
    79   Node s,t;
    80   Digraph::ArcMap<Value> cap(g);
    80   Digraph::ArcMap<Value> cap(g);
    81   Timer ti;
    81   Timer ti;
    82   ti.restart();
    82   ti.restart();
    83   readDimacsMax(is, g, cap, s, t, desc);
    83   readDimacsMax(is, g, cap, s, t, infty, desc);
    84   if(report) std::cerr << "Read the file: " << ti << '\n';
    84   if(report) std::cerr << "Read the file: " << ti << '\n';
    85   ti.restart();
    85   ti.restart();
    86   Preflow<Digraph, Digraph::ArcMap<Value> > pre(g,cap,s,t);
    86   Preflow<Digraph, Digraph::ArcMap<Value> > pre(g,cap,s,t);
    87   if(report) std::cerr << "Setup Preflow class: " << ti << '\n';
    87   if(report) std::cerr << "Setup Preflow class: " << ti << '\n';
    88   ti.restart();
    88   ti.restart();
   113 
   113 
   114 template<class Value>
   114 template<class Value>
   115 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   115 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   116            DimacsDescriptor &desc)
   116            DimacsDescriptor &desc)
   117 {
   117 {
       
   118   std::stringstream iss(ap["infcap"]);
       
   119   Value infty;
       
   120   iss >> infty;
       
   121   if(iss.fail())
       
   122     {
       
   123       std::cerr << "Cannot interpret '"
       
   124                 << static_cast<std::string>(ap["infcap"]) << "' as infinite"
       
   125                 << std::endl;
       
   126       exit(1);
       
   127     }
       
   128   
   118   switch(desc.type)
   129   switch(desc.type)
   119     {
   130     {
   120     case DimacsDescriptor::MIN:
   131     case DimacsDescriptor::MIN:
   121       std::cerr <<
   132       std::cerr <<
   122         "\n\n Sorry, the min. cost flow solver is not yet available.\n";
   133         "\n\n Sorry, the min. cost flow solver is not yet available.\n";
   123       break;
   134       break;
   124     case DimacsDescriptor::MAX:
   135     case DimacsDescriptor::MAX:
   125       solve_max<Value>(ap,is,os,desc);
   136       solve_max<Value>(ap,is,os,infty,desc);
   126       break;
   137       break;
   127     case DimacsDescriptor::SP:
   138     case DimacsDescriptor::SP:
   128       solve_sp<Value>(ap,is,os,desc);
   139       solve_sp<Value>(ap,is,os,desc);
   129       break;
   140       break;
   130     case DimacsDescriptor::MAT:
   141     case DimacsDescriptor::MAT:
   157     .boolOption("double","Use 'double' for capacities, costs etc.")
   168     .boolOption("double","Use 'double' for capacities, costs etc.")
   158     .optionGroup("datatype","double")
   169     .optionGroup("datatype","double")
   159     .boolOption("ldouble","Use 'long double' for capacities, costs etc.")
   170     .boolOption("ldouble","Use 'long double' for capacities, costs etc.")
   160     .optionGroup("datatype","ldouble")
   171     .optionGroup("datatype","ldouble")
   161     .onlyOneGroup("datatype")
   172     .onlyOneGroup("datatype")
       
   173     .stringOption("infcap","Value used for 'very high' capacities","0")
   162     .run();
   174     .run();
   163 
   175 
   164   std::ifstream input;
   176   std::ifstream input;
   165   std::ofstream output;
   177   std::ofstream output;
   166 
   178