tools/dimacs-solver.cc
branch1.1
changeset 762 54abdfda0076
parent 640 8d289c89d43e
child 795 b78a46fe8002
equal deleted inserted replaced
12:f51eb289c8b3 13:921f94d9cf21
     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-2011
     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>
    94 template<class Value>
    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)
   145   if(report) std::cerr << "Setup MaxMatching class: " << ti << '\n';
   145   if(report) std::cerr << "Setup MaxMatching class: " << ti << '\n';
   146   ti.restart();
   146   ti.restart();
   147   mat.run();
   147   mat.run();
   148   if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
   148   if(report) std::cerr << "Run MaxMatching: " << ti << '\n';
   149   if(report) std::cerr << "\nCardinality of max matching: "
   149   if(report) std::cerr << "\nCardinality of max matching: "
   150                        << mat.matchingSize() << '\n';  
   150                        << mat.matchingSize() << '\n';
   151 }
   151 }
   152 
   152 
   153 
   153 
   154 template<class Value>
   154 template<class Value>
   155 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   155 void solve(ArgParser &ap, std::istream &is, std::ostream &os,
   163       std::cerr << "Cannot interpret '"
   163       std::cerr << "Cannot interpret '"
   164                 << static_cast<std::string>(ap["infcap"]) << "' as infinite"
   164                 << static_cast<std::string>(ap["infcap"]) << "' as infinite"
   165                 << std::endl;
   165                 << std::endl;
   166       exit(1);
   166       exit(1);
   167     }
   167     }
   168   
   168 
   169   switch(desc.type)
   169   switch(desc.type)
   170     {
   170     {
   171     case DimacsDescriptor::MIN:
   171     case DimacsDescriptor::MIN:
   172       solve_min<Value>(ap,is,os,infty,desc);
   172       solve_min<Value>(ap,is,os,infty,desc);
   173       break;
   173       break;
   235     }
   235     }
   236   std::istream& is = (ap.files().size()<1 ? std::cin : input);
   236   std::istream& is = (ap.files().size()<1 ? std::cin : input);
   237   std::ostream& os = (ap.files().size()<2 ? std::cout : output);
   237   std::ostream& os = (ap.files().size()<2 ? std::cout : output);
   238 
   238 
   239   DimacsDescriptor desc = dimacsType(is);
   239   DimacsDescriptor desc = dimacsType(is);
   240   
   240 
   241   if(!ap.given("q"))
   241   if(!ap.given("q"))
   242     {
   242     {
   243       std::cout << "Problem type: ";
   243       std::cout << "Problem type: ";
   244       switch(desc.type)
   244       switch(desc.type)
   245         {
   245         {
   260         }
   260         }
   261       std::cout << "\nNum of nodes: " << desc.nodeNum;
   261       std::cout << "\nNum of nodes: " << desc.nodeNum;
   262       std::cout << "\nNum of arcs:  " << desc.edgeNum;
   262       std::cout << "\nNum of arcs:  " << desc.edgeNum;
   263       std::cout << "\n\n";
   263       std::cout << "\n\n";
   264     }
   264     }
   265     
   265 
   266   if(ap.given("double"))
   266   if(ap.given("double"))
   267     solve<double>(ap,is,os,desc);
   267     solve<double>(ap,is,os,desc);
   268   else if(ap.given("ldouble"))
   268   else if(ap.given("ldouble"))
   269     solve<long double>(ap,is,os,desc);
   269     solve<long double>(ap,is,os,desc);
   270 #ifdef LEMON_HAVE_LONG_LONG
   270 #ifdef LEMON_HAVE_LONG_LONG