src/work/marci/max_flow_1.cc
author marci
Fri, 14 May 2004 18:33:17 +0000
changeset 643 f8053cb51047
parent 640 d426dca0aaf7
child 762 511200bdb71f
permissions -rw-r--r--
comparision of ListGraph, SmartGraph and SageGraph
marci@615
     1
// -*- c++ -*-
marci@615
     2
#include <iostream>
marci@615
     3
#include <fstream>
marci@615
     4
marci@642
     5
#include <sage_graph.h>
marci@615
     6
#include <hugo/smart_graph.h>
marci@615
     7
#include <hugo/dimacs.h>
marci@615
     8
#include <hugo/time_measure.h>
marci@615
     9
//#include <graph_wrapper.h>
marci@615
    10
#include <max_flow.h>
marci@615
    11
//#include <preflow_res.h>
marci@640
    12
#include <hugo/for_each_macros.h>
marci@615
    13
marci@615
    14
using namespace hugo;
marci@615
    15
marci@615
    16
// Use a DIMACS max flow file as stdin.
marci@615
    17
// read_dimacs_demo < dimacs_max_flow_file
marci@615
    18
marci@615
    19
marci@615
    20
int main(int, char **) {
marci@615
    21
marci@642
    22
  typedef SageGraph MutableGraph;
marci@615
    23
marci@615
    24
  typedef SmartGraph Graph;
marci@615
    25
  //  typedef ListGraph Graph;
marci@615
    26
  typedef Graph::Node Node;
marci@615
    27
  typedef Graph::EdgeIt EdgeIt;
marci@615
    28
marci@615
    29
marci@615
    30
  Graph g;
marci@615
    31
  Node s, t;
marci@615
    32
  Graph::EdgeMap<int> cap(g);
marci@615
    33
  //readDimacsMaxFlow(std::cin, g, s, t, cap);
marci@615
    34
  readDimacs(std::cin, g, cap, s, t);
marci@615
    35
  Timer ts;
marci@615
    36
  Graph::EdgeMap<int> flow(g); //0 flow
marci@615
    37
  MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
marci@615
    38
    max_flow_test(g, s, t, cap, flow);
marci@615
    39
marci@615
    40
  {
marci@615
    41
    std::cout << "preflow ..." << std::endl;
marci@615
    42
    FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@615
    43
    ts.reset();
jacint@629
    44
    max_flow_test.preflowPhase1(MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::ZERO_FLOW);
marci@615
    45
    std::cout << "elapsed time: " << ts << std::endl;
marci@615
    46
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@615
    47
  }
marci@615
    48
marci@615
    49
  {
marci@615
    50
    std::cout << "preflow ..." << std::endl;
marci@615
    51
    FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
marci@615
    52
    ts.reset();
jacint@629
    53
    max_flow_test.preflowPhase1(MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::ZERO_FLOW);
marci@615
    54
    std::cout << "elapsed time: " << ts << std::endl;
marci@615
    55
    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
marci@615
    56
  }
marci@615
    57
marci@615
    58
marci@615
    59
  return 0;
marci@615
    60
}