3 // Use a DIMACS max flow file as input.
4 // sub_graph_adaptor_demo < dimacs_max_flow_file
5 // This program computes a maximum number of edge-disjoint shortest paths
11 #include <lemon/smart_graph.h>
12 #include <lemon/dijkstra.h>
13 #include <lemon/maps.h>
14 #include <lemon/graph_adaptor.h>
15 #include <lemon/dimacs.h>
16 #include <lemon/preflow.h>
17 #include <tight_edge_filter_map.h>
19 using namespace lemon;
24 int main(int argc, char *argv[])
28 std::cerr << "USAGE: sub_graph_adaptor_demo <input_file.dim>" << std::endl;
29 std::cerr << "The file 'input_file.dim' has to contain a max flow instance in DIMACS format (e.g. sub_graph_adaptor_demo.dim is such a file)." << std::endl;
34 //input stream to read the graph from
35 std::ifstream is(argv[1]);
37 typedef SmartGraph Graph;
39 typedef Graph::Edge Edge;
40 typedef Graph::Node Node;
41 typedef Graph::EdgeIt EdgeIt;
42 typedef Graph::NodeIt NodeIt;
43 typedef Graph::EdgeMap<int> LengthMap;
49 readDimacs(is, g, length, s, t);
51 cout << "edges with lengths (of form id, source--length->target): " << endl;
52 for(EdgeIt e(g); e!=INVALID; ++e)
53 cout << " " << g.id(e) << ", " << g.id(g.source(e)) << "--"
54 << length[e] << "->" << g.id(g.target(e)) << endl;
56 cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
58 typedef Dijkstra<Graph, LengthMap> Dijkstra;
59 Dijkstra dijkstra(g, length);
62 // This map returns true exactly for those edges which are
63 // tight w.r.t the length funcion and the potential
64 // given by the dijkstra algorithm.
65 typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap>
67 TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
69 // ConstMap<Node, bool> const_true_map(true);
70 // This graph contains exaclty the tight edges.
71 // typedef SubGraphAdaptor<Graph, ConstMap<Node, bool>, TightEdgeFilter> SubGW;
72 typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGW;
73 SubGW gw(g, tight_edge_filter);
75 ConstMap<Edge, int> const_1_map(1);
76 Graph::EdgeMap<int> flow(g, 0);
77 // Max flow between s and t in the graph of tight edges.
78 Preflow<SubGW, int, ConstMap<Edge, int>, Graph::EdgeMap<int> >
79 preflow(gw, s, t, const_1_map, flow);
82 cout << "maximum number of edge-disjoint shortest paths: "
83 << preflow.flowValue() << endl;
84 cout << "edges of the maximum number of edge-disjoint shortest s-t paths: "
86 for(EdgeIt e(g); e!=INVALID; ++e)
88 cout << " " << g.id(e) << ", "
89 << g.id(g.source(e)) << "--"
90 << length[e] << "->" << g.id(g.target(e)) << endl;