src/work/marci/sub_graph_wrapper_demo.cc
author marci
Thu, 16 Sep 2004 13:57:41 +0000
changeset 866 7477e00f1a64
permissions -rw-r--r--
(none)
marci@866
     1
// -*- c++ -*-
marci@866
     2
marci@866
     3
// Use a DIMACS max flow file as stdin.
marci@866
     4
// sub_graph_wrapper_demo < dimacs_max_flow_file
marci@866
     5
marci@866
     6
#include <iostream>
marci@866
     7
#include <fstream>
marci@866
     8
marci@866
     9
#include <hugo/smart_graph.h>
marci@866
    10
#include <hugo/dijkstra.h>
marci@866
    11
#include <hugo/maps.h>
marci@866
    12
#include <hugo/graph_wrapper.h>
marci@866
    13
#include <hugo/dimacs.h>
marci@866
    14
#include <hugo/preflow.h>
marci@866
    15
#include <tight_edge_filter_map.h>
marci@866
    16
marci@866
    17
using namespace hugo;
marci@866
    18
marci@866
    19
using std::cout;
marci@866
    20
using std::endl;
marci@866
    21
marci@866
    22
int main()
marci@866
    23
{    
marci@866
    24
  typedef SmartGraph Graph;
marci@866
    25
marci@866
    26
  typedef Graph::Edge Edge;
marci@866
    27
  typedef Graph::Node Node;
marci@866
    28
  typedef Graph::EdgeIt EdgeIt;
marci@866
    29
  typedef Graph::NodeIt NodeIt;
marci@866
    30
  typedef Graph::EdgeMap<int> LengthMap;
marci@866
    31
marci@866
    32
  Graph g;
marci@866
    33
  Node s, t;
marci@866
    34
  LengthMap length(g);
marci@866
    35
marci@866
    36
  readDimacs(std::cin, g, length, s, t);
marci@866
    37
marci@866
    38
  cout << "edges with lengths (of form tail--length->head): " << endl;
marci@866
    39
  for(EdgeIt e(g); e!=INVALID; ++e) 
marci@866
    40
    cout << " " << g.id(g.tail(e)) << "--" 
marci@866
    41
	 << length[e] << "->" << g.id(g.head(e)) << endl;
marci@866
    42
marci@866
    43
  cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
marci@866
    44
marci@866
    45
  typedef Dijkstra<Graph, LengthMap> Dijkstra;
marci@866
    46
  Dijkstra dijkstra(g, length);
marci@866
    47
  dijkstra.run(s);
marci@866
    48
marci@866
    49
  typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap> 
marci@866
    50
    TightEdgeFilter;
marci@866
    51
  TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
marci@866
    52
marci@866
    53
  ConstMap<Node, bool> const_true_map(true);
marci@866
    54
  typedef SubGraphWrapper<Graph, ConstMap<Node, bool>, TightEdgeFilter> SubGW;
marci@866
    55
  SubGW gw(g, const_true_map, tight_edge_filter);
marci@866
    56
marci@866
    57
  ConstMap<Edge, int> const_1_map(1);
marci@866
    58
  Graph::EdgeMap<int> flow(g, 0);
marci@866
    59
  Preflow<SubGW, int, ConstMap<Edge, int>, Graph::EdgeMap<int> > 
marci@866
    60
    preflow(gw, s, t, const_1_map, flow);
marci@866
    61
  preflow.run();
marci@866
    62
marci@866
    63
  cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " 
marci@866
    64
       << endl;
marci@866
    65
  for(EdgeIt e(g); e!=INVALID; ++e) 
marci@866
    66
    if (flow[e])
marci@866
    67
      cout << " " << g.id(g.tail(e)) << "--" 
marci@866
    68
	   << length[e] << "->" << g.id(g.head(e)) << endl;
marci@866
    69
marci@866
    70
  return 0;
marci@866
    71
}