COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/jacint/preflow.cc @ 374:0fc9cd9b854a

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