src/work/marci/edmonds_karp_demo.cc
author marci
Thu, 04 Mar 2004 19:45:06 +0000
changeset 156 a34e5a909e97
parent 146 c4adf922624f
child 168 27fbd1559fb7
permissions -rw-r--r--
.
     1 #include <iostream>
     2 #include <fstream>
     3 
     4 #include <list_graph.hh>
     5 #include <dimacs.hh>
     6 #include <edmonds_karp.hh>
     7 #include <time_measure.h>
     8 #include <graph_wrapper.h>
     9 
    10 using namespace hugo;
    11 
    12 // Use a DIMACS max flow file as stdin.
    13 // read_dimacs_demo < dimacs_max_flow_file
    14 
    15 /*
    16   struct Ize {
    17   };
    18   
    19   struct Mize {
    20     Ize bumm;
    21   };
    22 
    23   template <typename B>
    24     class Huha {
    25     public:
    26       int u;
    27       B brr;
    28     };
    29 */
    30 
    31 int main(int, char **) {
    32   typedef ListGraph::NodeIt NodeIt;
    33   typedef ListGraph::EachEdgeIt EachEdgeIt;
    34 
    35 /*
    36   Mize mize[10];
    37   Mize bize[0];
    38   Mize zize;
    39   typedef Mize Tize[0];
    40 
    41   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
    42   std::cout << sizeof(bize) << std::endl;
    43 
    44 
    45   Huha<Tize> k;
    46   std::cout << sizeof(k) << std::endl;
    47 
    48 
    49   struct Bumm {
    50     //int a;
    51     bool b;
    52   };
    53 
    54   std::cout << sizeof(Bumm) << std::endl;
    55 */
    56 
    57   ListGraph G;
    58   NodeIt s, t;
    59   ListGraph::EdgeMap<int> cap(G);
    60   readDimacsMaxFlow(std::cin, G, s, t, cap);
    61 /*
    62   typedef TrivGraphWrapper<ListGraph> TGW;
    63   TGW gw(G);
    64   TGW::EachNodeIt sw;
    65   gw.getFirst(sw);
    66   std::cout << "p1:" << gw.nodeNum() << std::endl;
    67   gw.erase(sw);
    68   std::cout << "p2:" << gw.nodeNum() << std::endl;
    69 
    70   typedef const ListGraph cLG;
    71   typedef TrivGraphWrapper<const cLG> CTGW;
    72   CTGW cgw(G);
    73   CTGW::EachNodeIt csw;
    74   cgw.getFirst(csw);
    75   std::cout << "p1:" << cgw.nodeNum() << std::endl;
    76   //cgw.erase(csw);
    77   std::cout << "p2:" << cgw.nodeNum() << std::endl;
    78 */
    79 
    80   {
    81   std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
    82   ListGraph::EdgeMap<int> flow(G); //0 flow
    83 
    84   Timer ts;
    85   ts.reset();
    86   //double pre_time=currTime();
    87   MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
    88   //max_flow_test.augmentWithBlockingFlow<ListGraph>();
    89   int i=0;
    90   while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; }
    91   //double post_time=currTime();
    92 
    93   //std::cout << "maximum flow: "<< std::endl;
    94   //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
    95   //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
    96   //}
    97   //std::cout<<std::endl;
    98   std::cout << "elapsed time: " << ts << std::endl;
    99   std::cout << "number of augmentation phases: " << i << std::endl; 
   100   std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   101   }
   102 
   103   {
   104   std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl;
   105   ListGraph::EdgeMap<int> flow(G); //0 flow
   106 
   107   Timer ts;
   108   ts.reset();
   109   //double pre_time=currTime();
   110   MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
   111   //max_flow_test.augmentWithBlockingFlow<ListGraph>();
   112   int i=0;
   113   while (max_flow_test.augmentOnShortestPath()) { ++i; }
   114   //double post_time=currTime();
   115 
   116   //std::cout << "maximum flow: "<< std::endl;
   117   //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) { 
   118   //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   119   //}
   120   //std::cout<<std::endl;
   121   std::cout << "elapsed time: " << ts << std::endl;
   122   std::cout << "number of augmentation phases: " << i << std::endl; 
   123   std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   124   }
   125 
   126   return 0;
   127 }