COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/edmonds_karp_demo.cc @ 127:dcace15b1874

Last change on this file since 127:dcace15b1874 was 105:a3c73e9b9b2e, checked in by Alpar Juttner, 20 years ago

marci -> hugo replacements
resize -> update replacements

File size: 1.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
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  double pre_time_copy=currTime();
24  ListGraph F;
25  ListGraph::NodeMap<NodeIt> G_to_F(G);
26  typedef ListGraph::EachNodeIt EachNodeIt;
27  for(EachNodeIt n=G.first<EachNodeIt>(); n.valid(); ++n) {
28    G_to_F.set(n, F.addNode());
29  }
30  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
31    F.addEdge(G_to_F.get(G.tail(e)), G_to_F.get(G.head(e)));
32  }
33  double post_time_copy=currTime();
34  std::cout << "copy time: " << post_time_copy-pre_time_copy << " sec"<< std::endl;
35*/
36
37  std::cout << "edmonds karp demo..." << std::endl;
38  ListGraph::EdgeMap<int> flow(G); //0 flow
39
40  double pre_time=currTime();
41  MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
42  max_flow_test.augmentWithBlockingFlow();
43  max_flow_test.run();
44  double post_time=currTime();
45  //std::cout << "maximum flow: "<< std::endl;
46  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
47  //  std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
48  //}
49  //std::cout<<std::endl;
50  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl;
51  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
52
53  return 0;
54}
Note: See TracBrowser for help on using the repository browser.