# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1235430899 -3600
# Node ID 726568ea7ed44dc2ad1285f9138688548e6d9b95
# Parent 7f07ddefb52dd2ce7ce6f2f11b7bd699022c04a9
Support min cost flow in dimacs-solver (#234)
diff --git a/tools/dimacs-solver.cc b/tools/dimacs-solver.cc
a
|
b
|
|
45 | 45 | #include <lemon/dijkstra.h> |
46 | 46 | #include <lemon/preflow.h> |
47 | 47 | #include <lemon/max_matching.h> |
| 48 | #include <lemon/network_simplex.h> |
48 | 49 | |
49 | 50 | using namespace lemon; |
50 | 51 | typedef SmartDigraph Digraph; |
… |
… |
|
92 | 93 | if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; |
93 | 94 | } |
94 | 95 | |
| 96 | template<class Value> |
| 97 | void solve_min(ArgParser &ap, std::istream &is, std::ostream &, |
| 98 | DimacsDescriptor &desc) |
| 99 | { |
| 100 | bool report = !ap.given("q"); |
| 101 | Digraph g; |
| 102 | Digraph::ArcMap<Value> lower(g), cap(g), cost(g); |
| 103 | Digraph::NodeMap<Value> sup(g); |
| 104 | Timer ti; |
| 105 | ti.restart(); |
| 106 | readDimacsMin(is, g, lower, cap, cost, sup, desc); |
| 107 | if (report) std::cerr << "Read the file: " << ti << '\n'; |
| 108 | ti.restart(); |
| 109 | NetworkSimplex< Digraph, Digraph::ArcMap<Value>, Digraph::ArcMap<Value>, |
| 110 | Digraph::ArcMap<Value>, Digraph::NodeMap<Value> > |
| 111 | ns(g, lower, cap, cost, sup); |
| 112 | if (report) std::cerr << "Setup NetworkSimplex class: " << ti << '\n'; |
| 113 | ti.restart(); |
| 114 | ns.run(); |
| 115 | if (report) std::cerr << "Run NetworkSimplex: " << ti << '\n'; |
| 116 | if (report) std::cerr << "\nMin flow cost: " << ns.totalCost() << '\n'; |
| 117 | } |
| 118 | |
95 | 119 | void solve_mat(ArgParser &ap, std::istream &is, std::ostream &, |
96 | 120 | DimacsDescriptor &desc) |
97 | 121 | { |
… |
… |
|
119 | 143 | switch(desc.type) |
120 | 144 | { |
121 | 145 | case DimacsDescriptor::MIN: |
122 | | std::cerr << |
123 | | "\n\n Sorry, the min. cost flow solver is not yet available.\n" |
124 | | << std::endl; |
| 146 | solve_min<Value>(ap,is,os,desc); |
125 | 147 | break; |
126 | 148 | case DimacsDescriptor::MAX: |
127 | 149 | solve_max<Value>(ap,is,os,desc); |