COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/edmonds_karp_demo.cc @ 268:f4eb1ae59b50

Last change on this file since 268:f4eb1ae59b50 was 268:f4eb1ae59b50, checked in by marci, 16 years ago

blocking flows

File size: 6.0 KB
Line 
1// -*- c++ -*-
2#include <iostream>
3#include <fstream>
4
5#include <list_graph.h>
6#include <smart_graph.h>
7#include <dimacs.h>
8#include <edmonds_karp.h>
9#include <time_measure.h>
10#include <graph_wrapper.h>
11
12class CM {
13public:
14  template<typename T> int get(T) const {return 1;}
15};
16
17using namespace hugo;
18
19// Use a DIMACS max flow file as stdin.
20// read_dimacs_demo < dimacs_max_flow_file
21
22
23//   struct Ize {
24//   };
25 
26//   struct Mize {
27//     Ize bumm;
28//   };
29
30//   template <typename B>
31//     class Huha {
32//     public:
33//       int u;
34//       B brr;
35//     };
36
37
38int main(int, char **) {
39
40  typedef ListGraph MutableGraph;
41
42  //typedef SmartGraph Graph;
43  typedef ListGraph Graph;
44  typedef Graph::Node Node;
45  typedef Graph::EdgeIt EdgeIt;
46
47
48//   Mize mize[10];
49//   Mize bize[0];
50//   Mize zize;
51//   typedef Mize Tize[0];
52
53//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
54//   std::cout << sizeof(bize) << std::endl;
55
56
57//   Huha<Tize> k;
58//   std::cout << sizeof(k) << std::endl;
59
60
61//   struct Bumm {
62//     //int a;
63//     bool b;
64//   };
65
66//   std::cout << sizeof(Bumm) << std::endl;
67
68
69  Graph G;
70  Node s, t;
71  Graph::EdgeMap<int> cap(G);
72  readDimacsMaxFlow(std::cin, G, s, t, cap);
73
74//   typedef TrivGraphWrapper<Graph> TGW;
75//   TGW gw(G);
76//   TGW::NodeIt sw;
77//   gw./*getF*/first(sw);
78//   std::cout << "p1:" << gw.nodeNum() << std::endl;
79//   gw.erase(sw);
80//   std::cout << "p2:" << gw.nodeNum() << std::endl;
81
82//   typedef const Graph cLG;
83//   typedef TrivGraphWrapper<const cLG> CTGW;
84//   CTGW cgw(G);
85//   CTGW::NodeIt csw;
86//   cgw./*getF*/first(csw);
87//   std::cout << "p1:" << cgw.nodeNum() << std::endl;
88//   //cgw.erase(csw);
89//   std::cout << "p2:" << cgw.nodeNum() << std::endl;
90
91
92  {
93    //std::cout << "SmartGraph..." << std::endl;
94    typedef TrivGraphWrapper<const Graph> GW;
95    GW gw(G);
96    std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
97    GW::EdgeMap<int> flow(G); //0 flow
98
99    Timer ts;
100    ts.reset();
101
102    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
103    EMW cw(cap);
104    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
105    int i=0;
106    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) {
107//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
108//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
109//     }
110//     std::cout<<std::endl;
111      ++i;
112    }
113
114//   std::cout << "maximum flow: "<< std::endl;
115//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
116//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
117//   }
118//   std::cout<<std::endl;
119    std::cout << "elapsed time: " << ts << std::endl;
120    std::cout << "number of augmentation phases: " << i << std::endl;
121    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
122  }
123
124  {
125    //std::cout << "SmartGraph..." << std::endl;
126    typedef TrivGraphWrapper<const Graph> GW;
127    GW gw(G);
128    std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
129    GW::EdgeMap<int> flow(G); //0 flow
130
131    Timer ts;
132    ts.reset();
133
134    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
135    EMW cw(cap);
136    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
137    int i=0;
138    while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
139//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
140//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
141//     }
142//     std::cout<<std::endl;
143      ++i;
144    }
145
146//   std::cout << "maximum flow: "<< std::endl;
147//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
148//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
149//   }
150//   std::cout<<std::endl;
151    std::cout << "elapsed time: " << ts << std::endl;
152    std::cout << "number of augmentation phases: " << i << std::endl;
153    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
154  }
155
156//   {
157//     std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
158//     Graph::EdgeMap<int> flow(G); //0 flow
159
160//     Timer ts;
161//     ts.reset();
162
163//     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
164//     int i=0;
165//     while (max_flow_test.augmentOnBlockingFlow2()) {
166// //     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
167// //       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
168// //     }
169// //     std::cout<<std::endl;
170//       ++i;
171//     }
172
173// //   std::cout << "maximum flow: "<< std::endl;
174// //   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
175// //     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
176// //   }
177// //   std::cout<<std::endl;
178//     std::cout << "elapsed time: " << ts << std::endl;
179//     std::cout << "number of augmentation phases: " << i << std::endl;
180//     std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
181//   }
182
183  {
184    typedef TrivGraphWrapper<const Graph> GW;
185    GW gw(G);
186    std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
187    GW::EdgeMap<int> flow(gw); //0 flow
188
189    Timer ts;
190    ts.reset();
191
192    //CM cm;
193    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
194    EMW cw(cap);
195    MaxFlow<GW, int, GW::EdgeMap<int>, EMW> max_flow_test(gw, s, t, flow, cw);
196    int i=0;
197    while (max_flow_test.augmentOnShortestPath()) {
198//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
199//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
200//     }
201//     std::cout<<std::endl;
202      ++i;
203    }
204
205//   std::cout << "maximum flow: "<< std::endl;
206//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) {
207//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
208//   }
209//   std::cout<<std::endl;
210    std::cout << "elapsed time: " << ts << std::endl;
211    std::cout << "number of augmentation phases: " << i << std::endl;
212    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
213  }
214
215
216  return 0;
217}
Note: See TracBrowser for help on using the repository browser.