COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/jacint/preflow_max_flow.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: 1.1 KB
Line 
1#include <iostream>
2#include <fstream>
3
4#include <list_graph.hh>
5#include <dimacs.hh>
6#include <preflow_max_flow.h>
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;
16typedef ListGraph::EachNodeIt EachNodeIt;
17
18  ListGraph G;
19  NodeIt s, t;
20  ListGraph::EdgeMap<int> cap(G);
21  readDimacsMaxFlow(std::cin, G, s, t, cap);
22
23  std::cout << "preflow_max_flow demo ..." << std::endl;
24 
25  double pre_time=currTime();
26  preflow_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
27  ListGraph::NodeMap<bool> cut=max_flow_test.minCut();
28  double post_time=currTime();
29 
30  int cut_value=0;
31  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
32    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
33  }
34 
35  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl;
36  std::cout << "flow value: "<< max_flow_test.maxFlow() << std::endl;
37  std::cout << "cut value: "<< cut_value << std::endl;
38
39  return 0;
40}
Note: See TracBrowser for help on using the repository browser.