COIN-OR::LEMON - Graph Library

Ticket #234: dimacs-solver-726568ea7ed4.patch

File dimacs-solver-726568ea7ed4.patch, 1.9 KB (added by Peter Kovacs, 16 years ago)

Add MCF support for dimacs-solver

  • tools/dimacs-solver.cc

    # 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  
    4545#include <lemon/dijkstra.h>
    4646#include <lemon/preflow.h>
    4747#include <lemon/max_matching.h>
     48#include <lemon/network_simplex.h>
    4849
    4950using namespace lemon;
    5051typedef SmartDigraph Digraph;
     
    9293  if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; 
    9394}
    9495
     96template<class Value>
     97void 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
    95119void solve_mat(ArgParser &ap, std::istream &is, std::ostream &,
    96120              DimacsDescriptor &desc)
    97121{
     
    119143  switch(desc.type)
    120144    {
    121145    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);
    125147      break;
    126148    case DimacsDescriptor::MAX:
    127149      solve_max<Value>(ap,is,os,desc);