src/work/marci/read_dimacs_demo.cc
author alpar
Tue, 10 Feb 2004 13:29:15 +0000
changeset 70 851ca9a60e90
child 71 1d8d806ac8e0
permissions -rw-r--r--
.
     1 #include <iostream>
     2 #include <fstream>
     3 #include <list_graph.hh>
     4 #include <dimacs.hh>
     5 #include <edmonds_karp.hh>
     6 
     7 using namespace marci;
     8 
     9 // Use a DIMACS max flow file as stdin.
    10 // read_dimacs_demo < dimacs_flow_file
    11 int main(int, char **) {
    12   typedef ListGraph::NodeIt NodeIt;
    13   typedef ListGraph::EachEdgeIt EachEdgeIt;
    14 
    15   ListGraph G;
    16   NodeIt s, t;
    17   ListGraph::EdgeMap<int> cap(G);
    18   readDimacsMaxFlow(std::cin, G, s, t, cap);
    19 
    20   std::cout << "augmenting path flow algorithm demo..." << std::endl;
    21   ListGraph::EdgeMap<int> flow(G); //0 flow
    22   MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
    23   max_flow_test.run();
    24 
    25   std::cout << "maximum flow: "<< std::endl;
    26   for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
    27     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
    28   }
    29   std::cout<<std::endl;
    30   std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
    31 
    32   return 0;
    33 }