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
RevLine 
[73]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
[105]9using namespace hugo;
[73]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
[133]22  {
23  std::cout << "edmonds karp demo (blocking flow augmentation)..." << std::endl;
[73]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);
[133]28  //max_flow_test.augmentWithBlockingFlow<ListGraph>();
[138]29  int i=0;
30  while (max_flow_test.augmentOnBlockingFlow<ListGraph>()) { ++i; }
[73]31  double post_time=currTime();
[133]32
[73]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;
[138]39  std::cout << "number of augmentation phases: " << i << std::endl;
[73]40  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
[133]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>();
[138]50  int i=0;
51  while (max_flow_test.augmentOnShortestPath()) { ++i; }
[133]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;
[138]60  std::cout << "number of augmentation phases: " << i << std::endl;
[133]61  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
62  }
[73]63
64  return 0;
65}
Note: See TracBrowser for help on using the repository browser.