COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/jacint/preflow.cc @ 373:259ea2d741a2

Last change on this file since 373:259ea2d741a2 was 372:e6a156fc186d, checked in by jacint, 17 years ago
File size: 1.6 KB
Line 
1#include <iostream>
2
3#include <smart_graph.h>
4#include <list_graph.h>
5#include <dimacs.h>
6#include <preflowproba.h>
7#include <time_measure.h>
8
9using namespace hugo;
10
11int main(int, char **) {
12 
13  typedef SmartGraph Graph;
14 
15  typedef Graph::Node Node;
16  typedef Graph::EdgeIt EdgeIt;
17
18  Graph G;
19  Node s, t;
20  Graph::EdgeMap<int> cap(G);
21  readDimacsMaxFlow(std::cin, G, s, t, cap);
22  Timer ts;
23 
24  std::cout << "preflow demo ..." << std::endl;
25 
26  Graph::EdgeMap<int> flow(G);
27  Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 1);
28  ts.reset();
29  max_flow_test.run();
30  std::cout << "elapsed time: " << ts << std::endl;
31 
32  Graph::NodeMap<bool> cut(G);
33  max_flow_test.minCut(cut);
34  int min_cut_value=0;
35  EdgeIt e;
36  for(G.first(e); G.valid(e); G.next(e)) {
37    if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=cap[e];
38  }
39
40  Graph::NodeMap<bool> cut1(G);
41  max_flow_test.minMinCut(cut1);
42  int min_min_cut_value=0;
43  for(G.first(e); G.valid(e); G.next(e)) {
44    if (cut[G.tail(e)] && !cut[G.head(e)])
45      min_min_cut_value+=cap[e];
46  }
47
48  Graph::NodeMap<bool> cut2(G);
49  max_flow_test.maxMinCut(cut2);
50  int max_min_cut_value=0;
51  for(G.first(e); G.valid(e); G.next(e)) {
52    if (cut2[G.tail(e)] && !cut2[G.head(e)])
53      max_min_cut_value+=cap[e];
54      }
55 
56  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
57  std::cout << "min cut value: "<< min_cut_value << std::endl;
58  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
59  std::cout << "max min cut value: "<< max_min_cut_value <<
60    std::endl<< std::endl;
61 
62  return 0;
63}
Note: See TracBrowser for help on using the repository browser.