src/work/jacint/preflow_max_flow.cc
author klao
Thu, 26 Feb 2004 16:07:40 +0000
changeset 132 1ac27e476e25
permissions -rw-r--r--
makefile: tobb include konyvtar, jobb depend keszites
flow_test.cc: torolve, mert a depend-et megakasztja, igy gondolom nem is fordul
jacint@109
     1
#include <iostream>
jacint@109
     2
#include <fstream>
jacint@109
     3
jacint@109
     4
#include <list_graph.hh>
jacint@109
     5
#include <dimacs.hh>
jacint@109
     6
#include <preflow_max_flow.h>
jacint@109
     7
#include <time_measure.h>
jacint@109
     8
jacint@109
     9
using namespace hugo;
jacint@109
    10
jacint@109
    11
// Use a DIMACS max flow file as stdin.
jacint@109
    12
// read_dimacs_demo < dimacs_max_flow_file
jacint@109
    13
int main(int, char **) {
jacint@109
    14
  typedef ListGraph::NodeIt NodeIt;
jacint@109
    15
  typedef ListGraph::EachEdgeIt EachEdgeIt;
jacint@109
    16
typedef ListGraph::EachNodeIt EachNodeIt;
jacint@109
    17
jacint@109
    18
  ListGraph G;
jacint@109
    19
  NodeIt s, t;
jacint@109
    20
  ListGraph::EdgeMap<int> cap(G);
jacint@109
    21
  readDimacsMaxFlow(std::cin, G, s, t, cap);
jacint@109
    22
jacint@109
    23
  std::cout << "preflow_max_flow demo ..." << std::endl;
jacint@109
    24
  
jacint@109
    25
  double pre_time=currTime();
jacint@109
    26
  preflow_max_flow<ListGraph, int> max_flow_test(G, s, t, cap);
jacint@109
    27
  ListGraph::NodeMap<bool> cut=max_flow_test.minCut();
jacint@109
    28
  double post_time=currTime();
jacint@109
    29
  
jacint@109
    30
  int cut_value=0;
jacint@109
    31
  for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
jacint@109
    32
    if (cut.get(G.tail(e)) && !cut.get(G.head(e))) cut_value+=cap.get(e);
jacint@109
    33
  }
jacint@109
    34
  
jacint@109
    35
  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
jacint@109
    36
  std::cout << "flow value: "<< max_flow_test.maxFlow() << std::endl;
jacint@109
    37
  std::cout << "cut value: "<< cut_value << std::endl;
jacint@109
    38
jacint@109
    39
  return 0;
jacint@109
    40
}