tools/dimacs-solver.cc
changeset 982 0b9a94956916
parent 846 9d380bf27194
child 1006 764826c6e2b4
equal deleted inserted replaced
13:2ec83ad7b967 14:6292a65aced7
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2009
     5  * Copyright (C) 2003-2010
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
    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();
    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, class LargeValue>
    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)
   146   if(report) std::cerr << "Setup MaxMatching class: " << ti << '\n';
   146   if(report) std::cerr << "Setup MaxMatching class: " << ti << '\n';
   147   ti.restart();
   147   ti.restart();
   148   mat.run();
   148   mat.run();
   149   if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
   149   if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
   150   if(report) std::cerr << "\nCardinality of max matching: "
   150   if(report) std::cerr << "\nCardinality of max matching: "
   151                        << mat.matchingSize() << '\n';  
   151                        << mat.matchingSize() << '\n';
   152 }
   152 }
   153 
   153 
   154 
   154 
   155 template<class Value, class LargeValue>
   155 template<class Value, class LargeValue>
   156 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   156 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   164       std::cerr << "Cannot interpret '"
   164       std::cerr << "Cannot interpret '"
   165                 << static_cast<std::string>(ap["infcap"]) << "' as infinite"
   165                 << static_cast<std::string>(ap["infcap"]) << "' as infinite"
   166                 << std::endl;
   166                 << std::endl;
   167       exit(1);
   167       exit(1);
   168     }
   168     }
   169   
   169 
   170   switch(desc.type)
   170   switch(desc.type)
   171     {
   171     {
   172     case DimacsDescriptor::MIN:
   172     case DimacsDescriptor::MIN:
   173       solve_min<Value, LargeValue>(ap,is,os,infty,desc);
   173       solve_min<Value, LargeValue>(ap,is,os,infty,desc);
   174       break;
   174       break;
   236     }
   236     }
   237   std::istream& is = (ap.files().size()<1 ? std::cin : input);
   237   std::istream& is = (ap.files().size()<1 ? std::cin : input);
   238   std::ostream& os = (ap.files().size()<2 ? std::cout : output);
   238   std::ostream& os = (ap.files().size()<2 ? std::cout : output);
   239 
   239 
   240   DimacsDescriptor desc = dimacsType(is);
   240   DimacsDescriptor desc = dimacsType(is);
   241   
   241 
   242   if(!ap.given("q"))
   242   if(!ap.given("q"))
   243     {
   243     {
   244       std::cout << "Problem type: ";
   244       std::cout << "Problem type: ";
   245       switch(desc.type)
   245       switch(desc.type)
   246         {
   246         {
   261         }
   261         }
   262       std::cout << "\nNum of nodes: " << desc.nodeNum;
   262       std::cout << "\nNum of nodes: " << desc.nodeNum;
   263       std::cout << "\nNum of arcs:  " << desc.edgeNum;
   263       std::cout << "\nNum of arcs:  " << desc.edgeNum;
   264       std::cout << "\n\n";
   264       std::cout << "\n\n";
   265     }
   265     }
   266     
   266 
   267   if(ap.given("double"))
   267   if(ap.given("double"))
   268     solve<double, double>(ap,is,os,desc);
   268     solve<double, double>(ap,is,os,desc);
   269   else if(ap.given("ldouble"))
   269   else if(ap.given("ldouble"))
   270     solve<long double, long double>(ap,is,os,desc);
   270     solve<long double, long double>(ap,is,os,desc);
   271 #ifdef LEMON_HAVE_LONG_LONG
   271 #ifdef LEMON_HAVE_LONG_LONG