COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/edmonds_karp_demo.cc @ 168:27fbd1559fb7

Last change on this file since 168:27fbd1559fb7 was 168:27fbd1559fb7, checked in by marci, 17 years ago

graph wrapper improvements, blocking flow on fly

File size: 4.6 KB
Line 
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
10using 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
31int 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>()) {
91//     for(EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) {
92//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
93//     }
94//     std::cout<<std::endl;
95    ++i;
96  }
97  //double post_time=currTime();
98
99  //std::cout << "maximum flow: "<< std::endl;
100  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
101  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
102  //}
103  //std::cout<<std::endl;
104  std::cout << "elapsed time: " << ts << std::endl;
105  std::cout << "number of augmentation phases: " << i << std::endl;
106  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
107  }
108
109  {
110  std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
111  ListGraph::EdgeMap<int> flow(G); //0 flow
112
113  Timer ts;
114  ts.reset();
115  //double pre_time=currTime();
116  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
117  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
118  int i=0;
119  while (max_flow_test.augmentOnBlockingFlow2()) {
120//     for(EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) {
121//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
122//     }
123//     std::cout<<std::endl;
124    ++i;
125  }
126  //double post_time=currTime();
127
128  //std::cout << "maximum flow: "<< std::endl;
129  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
130  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
131  //}
132  //std::cout<<std::endl;
133  std::cout << "elapsed time: " << ts << std::endl;
134  std::cout << "number of augmentation phases: " << i << std::endl;
135  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
136  }
137
138  {
139  std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl;
140  ListGraph::EdgeMap<int> flow(G); //0 flow
141
142  Timer ts;
143  ts.reset();
144  //double pre_time=currTime();
145  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
146  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
147  int i=0;
148  while (max_flow_test.augmentOnShortestPath()) {
149//     for(EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) {
150//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
151//     }
152//     std::cout<<std::endl;
153    ++i;
154  }
155  //double post_time=currTime();
156
157  //std::cout << "maximum flow: "<< std::endl;
158  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
159  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
160  //}
161  //std::cout<<std::endl;
162  std::cout << "elapsed time: " << ts << std::endl;
163  std::cout << "number of augmentation phases: " << i << std::endl;
164  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
165  }
166
167  return 0;
168}
Note: See TracBrowser for help on using the repository browser.