COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/jacint/preflow.cc @ 334:63703ea7d02f

Last change on this file since 334:63703ea7d02f was 220:7deda4d6a07a, checked in by jacint, 21 years ago

* empty log message *

File size: 2.0 KB
RevLine 
[109]1#include <iostream>
2#include <fstream>
3
[220]4#include <smart_graph.h>
[211]5#include <list_graph.h>
6#include <dimacs.h>
[109]7#include <preflow.h>
8#include <time_measure.h>
9
10using namespace hugo;
11
12// Use a DIMACS max flow file as stdin.
13// read_dimacs_demo < dimacs_max_flow_file
14int main(int, char **) {
[220]15  typedef SmartGraph::Node Node;
16  typedef SmartGraph::EdgeIt EdgeIt;
[109]17
[220]18  SmartGraph G;
[211]19  Node s, t;
[220]20  SmartGraph::EdgeMap<int> cap(G);
[109]21  readDimacsMaxFlow(std::cin, G, s, t, cap);
22
23  std::cout << "preflow demo ..." << std::endl;
24 
25  double mintime=1000000;
26
27  for ( int i=1; i!=11; ++i ) {
[220]28    SmartGraph::EdgeMap<int> flow(G);
[109]29    double pre_time=currTime();
[220]30    Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
[211]31    max_flow_test.run();
[109]32    double post_time=currTime();
33    if ( mintime > post_time-pre_time ) mintime = post_time-pre_time;
34  }
35
[220]36  SmartGraph::EdgeMap<int> flow(G);
37  Preflow<SmartGraph, int> max_flow_test(G, s, t, cap, flow);
[211]38  max_flow_test.run();
39 
[220]40  SmartGraph::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
[220]48  SmartGraph::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
[220]56  SmartGraph::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 
64  std::cout << "min time of 10 runs: " << mintime << " sec"<< std::endl;
[211]65  std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
[109]66  std::cout << "min cut value: "<< min_cut_value << std::endl;
67  std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
68  std::cout << "max min cut value: "<< max_min_cut_value <<
69    std::endl<< std::endl;
70 
71  return 0;
72}
Note: See TracBrowser for help on using the repository browser.