Changeset 658:85cb3aa71cce in lemon for tools/dimacs-solver.cc
- Timestamp:
- 04/21/09 16:18:54 (16 years ago)
- Branch:
- default
- Children:
- 659:0c8e5c688440, 660:b1811c363299, 666:ec817dfc2cb7
- Parents:
- 647:0ba8dfce7259 (diff), 657:dacc2cee2b4c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/dimacs-solver.cc
r641 r658 44 44 #include <lemon/preflow.h> 45 45 #include <lemon/matching.h> 46 #include <lemon/network_simplex.h> 46 47 47 48 using namespace lemon; … … 91 92 } 92 93 94 template<class Value> 95 void solve_min(ArgParser &ap, std::istream &is, std::ostream &, 96 DimacsDescriptor &desc) 97 { 98 bool report = !ap.given("q"); 99 Digraph g; 100 Digraph::ArcMap<Value> lower(g), cap(g), cost(g); 101 Digraph::NodeMap<Value> sup(g); 102 Timer ti; 103 ti.restart(); 104 readDimacsMin(is, g, lower, cap, cost, sup, 0, desc); 105 if (report) std::cerr << "Read the file: " << ti << '\n'; 106 ti.restart(); 107 NetworkSimplex<Digraph, Value> ns(g); 108 ns.lowerMap(lower).capacityMap(cap).costMap(cost).supplyMap(sup); 109 if (report) std::cerr << "Setup NetworkSimplex class: " << ti << '\n'; 110 ti.restart(); 111 ns.run(); 112 if (report) std::cerr << "Run NetworkSimplex: " << ti << '\n'; 113 if (report) std::cerr << "\nMin flow cost: " << ns.totalCost() << '\n'; 114 } 115 93 116 void solve_mat(ArgParser &ap, std::istream &is, std::ostream &, 94 117 DimacsDescriptor &desc) … … 129 152 { 130 153 case DimacsDescriptor::MIN: 131 std::cerr << 132 "\n\n Sorry, the min. cost flow solver is not yet available.\n"; 154 solve_min<Value>(ap,is,os,desc); 133 155 break; 134 156 case DimacsDescriptor::MAX: -
tools/dimacs-solver.cc
r652 r658 24 24 /// 25 25 /// See 26 /// \ verbatim27 /// dimacs-solver --help28 /// \end verbatim26 /// \code 27 /// dimacs-solver --help 28 /// \endcode 29 29 /// for more info on usage. 30 ///31 30 32 31 #include <iostream> … … 44 43 #include <lemon/dijkstra.h> 45 44 #include <lemon/preflow.h> 46 #include <lemon/ma x_matching.h>45 #include <lemon/matching.h> 47 46 #include <lemon/network_simplex.h> 48 47 … … 74 73 template<class Value> 75 74 void solve_max(ArgParser &ap, std::istream &is, std::ostream &, 76 DimacsDescriptor &desc)75 Value infty, DimacsDescriptor &desc) 77 76 { 78 77 bool report = !ap.given("q"); … … 82 81 Timer ti; 83 82 ti.restart(); 84 readDimacsMax(is, g, cap, s, t, desc);83 readDimacsMax(is, g, cap, s, t, infty, desc); 85 84 if(report) std::cerr << "Read the file: " << ti << '\n'; 86 85 ti.restart(); … … 103 102 Timer ti; 104 103 ti.restart(); 105 readDimacsMin(is, g, lower, cap, cost, sup, desc);104 readDimacsMin(is, g, lower, cap, cost, sup, 0, desc); 106 105 if (report) std::cerr << "Read the file: " << ti << '\n'; 107 106 ti.restart(); … … 139 138 DimacsDescriptor &desc) 140 139 { 140 std::stringstream iss(static_cast<std::string>(ap["infcap"])); 141 Value infty; 142 iss >> infty; 143 if(iss.fail()) 144 { 145 std::cerr << "Cannot interpret '" 146 << static_cast<std::string>(ap["infcap"]) << "' as infinite" 147 << std::endl; 148 exit(1); 149 } 150 141 151 switch(desc.type) 142 152 { … … 145 155 break; 146 156 case DimacsDescriptor::MAX: 147 solve_max<Value>(ap,is,os, desc);157 solve_max<Value>(ap,is,os,infty,desc); 148 158 break; 149 159 case DimacsDescriptor::SP: … … 182 192 .optionGroup("datatype","ldouble") 183 193 .onlyOneGroup("datatype") 194 .stringOption("infcap","Value used for 'very high' capacities","0") 184 195 .run(); 185 196
Note: See TracChangeset
for help on using the changeset viewer.