File demoprograms.dox thrown away: demos module used instead.
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>
21 //#include <lemon/graph_reader.h>
22 //#include <lemon/graph_writer.h>
24 using namespace lemon;
29 int main(int argc, char *argv[])
33 std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl;
34 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;
39 //input stream to read the graph from
40 std::ifstream is(argv[1]);
42 typedef SmartGraph Graph;
44 typedef Graph::Edge Edge;
45 typedef Graph::Node Node;
46 typedef Graph::EdgeIt EdgeIt;
47 typedef Graph::NodeIt NodeIt;
48 typedef Graph::EdgeMap<int> LengthMap;
54 readDimacs(is, g, length, s, t);
56 // GraphWriter<SmartGraph> writer(std::cout, g);
57 // writer.writeEdgeMap("length", length);
58 // writer.writeNode("source",s);
59 // writer.writeNode("target",t);
62 // GraphReader<ListGraph> reader(is,g);
63 // reader.readNode("source",s).readNode("target",t)
64 // .readEdgeMap("length",length).run();
66 cout << "edges with lengths (of form id, source--length->target): " << endl;
67 for(EdgeIt e(g); e!=INVALID; ++e)
68 cout << " " << g.id(e) << ", " << g.id(g.source(e)) << "--"
69 << length[e] << "->" << g.id(g.target(e)) << endl;
71 cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
73 typedef Dijkstra<Graph, LengthMap> Dijkstra;
74 Dijkstra dijkstra(g, length);
77 // This map returns true exactly for those edges which are
78 // tight w.r.t the length funcion and the potential
79 // given by the dijkstra algorithm.
80 typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap>
82 TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
84 // ConstMap<Node, bool> const_true_map(true);
85 // This graph contains exaclty the tight edges.
86 // typedef SubGraphAdaptor<Graph, ConstMap<Node, bool>, TightEdgeFilter> SubGW;
87 typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGW;
88 SubGW gw(g, tight_edge_filter);
90 ConstMap<Edge, int> const_1_map(1);
91 Graph::EdgeMap<int> flow(g, 0);
92 // Max flow between s and t in the graph of tight edges.
93 Preflow<SubGW, int, ConstMap<Edge, int>, Graph::EdgeMap<int> >
94 preflow(gw, s, t, const_1_map, flow);
97 cout << "maximum number of edge-disjoint shortest paths: "
98 << preflow.flowValue() << endl;
99 cout << "edges of the maximum number of edge-disjoint shortest s-t paths: "
101 for(EdgeIt e(g); e!=INVALID; ++e)
103 cout << " " << g.id(e) << ", "
104 << g.id(g.source(e)) << "--"
105 << length[e] << "->" << g.id(g.target(e)) << endl;