COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/edmonds_karp_demo.cc @ 138:c6297c121409

Last change on this file since 138:c6297c121409 was 138:c6297c121409, checked in by marci, 20 years ago

.

File size: 2.2 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
9using namespace hugo;
10
11// Use a DIMACS max flow file as stdin.
12// read_dimacs_demo < dimacs_max_flow_file
13int main(int, char **) {
14  typedef ListGraph::NodeIt NodeIt;
15  typedef ListGraph::EachEdgeIt EachEdgeIt;
16
17  ListGraph G;
18  NodeIt s, t;
19  ListGraph::EdgeMap<int> cap(G);
20  readDimacsMaxFlow(std::cin, G, s, t, cap);
21
22  {
23  std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
24  ListGraph::EdgeMap<int> flow(G); //0 flow
25
26  double pre_time=currTime();
27  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
28  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
29  int i=0;
30  while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; }
31  double post_time=currTime();
32
33  //std::cout << "maximum flow: "<< std::endl;
34  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
35  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
36  //}
37  //std::cout<<std::endl;
38  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl;
39  std::cout << "number of augmentation phases: " << i << std::endl;
40  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
41  }
42
43  {
44  std::cout << "edmonds karp demo (shortest path augmentation)..." << std::endl;
45  ListGraph::EdgeMap<int> flow(G); //0 flow
46
47  double pre_time=currTime();
48  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
49  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
50  int i=0;
51  while (max_flow_test.augmentOnShortestPath()) { ++i; }
52  double post_time=currTime();
53
54  //std::cout << "maximum flow: "<< std::endl;
55  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
56  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
57  //}
58  //std::cout<<std::endl;
59  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl;
60  std::cout << "number of augmentation phases: " << i << std::endl;
61  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
62  }
63
64  return 0;
65}
Note: See TracBrowser for help on using the repository browser.