COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/jacint/preflow_hl4.cc @ 134:e606071614f0

Last change on this file since 134:e606071614f0 was 109:fc5982b39e10, checked in by jacint, 21 years ago

Flows with test files. The best is preflow.h

File size: 2.3 KB
Line 
1#include <iostream>
2#include <fstream>
3
4#include <list_graph.hh>
5#include <dimacs.hh>
6#include <preflow_hl4.h>
7#include <time_measure.h>
8
9using namespace hugo;
10
11//Note, that preflow_hl4.h has a member NodeMap<bool> cut,
12//the construction of which slowing the running time by 1-10%.
13
14// Use a DIMACS max flow file as stdin.
15// read_dimacs_demo < dimacs_max_flow_file
16int main(int, char **) {
17  typedef ListGraph::NodeIt NodeIt;
18  typedef ListGraph::EachEdgeIt EachEdgeIt;
19
20  ListGraph G;
21  NodeIt s, t;
22  ListGraph::EdgeMap<int> cap(G);
23  readDimacsMaxFlow(std::cin, G, s, t, cap);
24
25  std::cout << "preflow_hl4 demo ..." << std::endl;
26 
27  double mintime=1000000;
28
29  for ( int i=1; i!=11; ++i ) {
30    double pre_time=currTime();
31    preflow_hl4<ListGraph, int> max_flow_test(G, s, t, cap);
32    double post_time=currTime();
33    if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
34  }
35
36  double pre_time=currTime();
37  preflow_hl4<ListGraph, int> max_flow_test(G, s, t, cap);
38  double post_time=currTime();
39     
40  ListGraph::NodeMap<bool> cut(G);
41  max_flow_test.minCut(cut);
42  int min_cut_value=0;
43  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
44    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) min_cut_value+=cap.get(e);
45  }
46
47  ListGraph::NodeMap<bool> cut1(G);
48  max_flow_test.minMinCut(cut1);
49  int min_min_cut_value=0;
50  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
51    if (cut.get(G.tail(e)) && !cut.get(G.head(e)))
52      min_min_cut_value+=cap.get(e);
53  }
54
55  ListGraph::NodeMap<bool> cut2(G);
56  max_flow_test.maxMinCut(cut2);
57  int max_min_cut_value=0;
58  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
59    if (cut2.get(G.tail(e)) && !cut2.get(G.head(e)))
60      max_min_cut_value+=cap.get(e);
61  }
62 
63  std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl;
64  std::cout << "phase 0: " << max_flow_test.time-pre_time
65            << " sec"<< std::endl;
66  std::cout << "phase 1: " << post_time-max_flow_test.time
67            << " sec"<< std::endl;
68  std::cout << "flow value: "<< max_flow_test.maxFlow() << std::endl;
69  std::cout << "min cut value: "<< min_cut_value << std::endl;
70  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
71  std::cout << "max min cut value: "<< max_min_cut_value <<
72    std::endl<< std::endl;
73
74 
75  return 0;
76}
Note: See TracBrowser for help on using the repository browser.