src/demo/sub_graph_wrapper_demo.cc
changeset 867 f3cc65f9fb6b
parent 866 7477e00f1a64
child 869 c19cf2007a7a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/demo/sub_graph_wrapper_demo.cc	Thu Sep 16 13:59:36 2004 +0000
     1.3 @@ -0,0 +1,71 @@
     1.4 +// -*- c++ -*-
     1.5 +
     1.6 +// Use a DIMACS max flow file as stdin.
     1.7 +// sub_graph_wrapper_demo < dimacs_max_flow_file
     1.8 +
     1.9 +#include <iostream>
    1.10 +#include <fstream>
    1.11 +
    1.12 +#include <hugo/smart_graph.h>
    1.13 +#include <hugo/dijkstra.h>
    1.14 +#include <hugo/maps.h>
    1.15 +#include <hugo/graph_wrapper.h>
    1.16 +#include <hugo/dimacs.h>
    1.17 +#include <hugo/preflow.h>
    1.18 +#include <tight_edge_filter_map.h>
    1.19 +
    1.20 +using namespace hugo;
    1.21 +
    1.22 +using std::cout;
    1.23 +using std::endl;
    1.24 +
    1.25 +int main()
    1.26 +{    
    1.27 +  typedef SmartGraph Graph;
    1.28 +
    1.29 +  typedef Graph::Edge Edge;
    1.30 +  typedef Graph::Node Node;
    1.31 +  typedef Graph::EdgeIt EdgeIt;
    1.32 +  typedef Graph::NodeIt NodeIt;
    1.33 +  typedef Graph::EdgeMap<int> LengthMap;
    1.34 +
    1.35 +  Graph g;
    1.36 +  Node s, t;
    1.37 +  LengthMap length(g);
    1.38 +
    1.39 +  readDimacs(std::cin, g, length, s, t);
    1.40 +
    1.41 +  cout << "edges with lengths (of form tail--length->head): " << endl;
    1.42 +  for(EdgeIt e(g); e!=INVALID; ++e) 
    1.43 +    cout << " " << g.id(g.tail(e)) << "--" 
    1.44 +	 << length[e] << "->" << g.id(g.head(e)) << endl;
    1.45 +
    1.46 +  cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
    1.47 +
    1.48 +  typedef Dijkstra<Graph, LengthMap> Dijkstra;
    1.49 +  Dijkstra dijkstra(g, length);
    1.50 +  dijkstra.run(s);
    1.51 +
    1.52 +  typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap> 
    1.53 +    TightEdgeFilter;
    1.54 +  TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
    1.55 +
    1.56 +  ConstMap<Node, bool> const_true_map(true);
    1.57 +  typedef SubGraphWrapper<Graph, ConstMap<Node, bool>, TightEdgeFilter> SubGW;
    1.58 +  SubGW gw(g, const_true_map, tight_edge_filter);
    1.59 +
    1.60 +  ConstMap<Edge, int> const_1_map(1);
    1.61 +  Graph::EdgeMap<int> flow(g, 0);
    1.62 +  Preflow<SubGW, int, ConstMap<Edge, int>, Graph::EdgeMap<int> > 
    1.63 +    preflow(gw, s, t, const_1_map, flow);
    1.64 +  preflow.run();
    1.65 +
    1.66 +  cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " 
    1.67 +       << endl;
    1.68 +  for(EdgeIt e(g); e!=INVALID; ++e) 
    1.69 +    if (flow[e])
    1.70 +      cout << " " << g.id(g.tail(e)) << "--" 
    1.71 +	   << length[e] << "->" << g.id(g.head(e)) << endl;
    1.72 +
    1.73 +  return 0;
    1.74 +}