Until this commitment gui gave us segmentation fault in the case when no element was on graph_displayer_canvas and a map to visualize by a property has been changed.
2 * demo/lp_maxflow_demo.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
19 ///\brief Computing maximum number of edge-disjoint shortest paths
21 /// This program computes a maximum number of edge-disjoint shortest paths
22 /// between nodes \c s and \c t.
25 // Use a DIMACS max flow file as input.
26 // sub_graph_adaptor_demo < dimacs_max_flow_file
27 // Modified to eat lemon graph format!
33 #include <lemon/smart_graph.h>
34 #include <lemon/dijkstra.h>
35 #include <lemon/maps.h>
36 #include <lemon/graph_adaptor.h>
37 #include <lemon/dimacs.h>
38 #include <lemon/preflow.h>
39 #include <tight_edge_filter_map.h>
41 #include <lemon/graph_reader.h>
44 using namespace lemon;
49 int main(int argc, char *argv[])
53 std::cerr << "USAGE: sub_graph_adaptor_demo input_file.lgf" << std::endl;
54 std::cerr << "The file 'input_file.lgf' has to contain a max flow "
55 << "instance in \n LEMON format "
56 << "(e.g. sub_gad_input.lgf is such a file)."
62 //input stream to read the graph from
63 std::ifstream is(argv[1]);
65 typedef SmartGraph Graph;
67 typedef Graph::Edge Edge;
68 typedef Graph::Node Node;
69 typedef Graph::EdgeIt EdgeIt;
70 typedef Graph::NodeIt NodeIt;
71 typedef Graph::EdgeMap<int> LengthMap;
77 //readDimacs(is, g, length, s, t);
80 GraphReader<SmartGraph> reader(is,g);
81 reader.readNode("source",s).readNode("target",t)
82 .readEdgeMap("length",length).run();
84 cout << "edges with lengths (of form id, source--length->target): " << endl;
85 for(EdgeIt e(g); e!=INVALID; ++e)
86 cout << " " << g.id(e) << ", " << g.id(g.source(e)) << "--"
87 << length[e] << "->" << g.id(g.target(e)) << endl;
89 cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
91 typedef Dijkstra<Graph, LengthMap> Dijkstra;
92 Dijkstra dijkstra(g, length);
95 // This map returns true exactly for those edges which are
96 // tight w.r.t the length funcion and the potential
97 // given by the dijkstra algorithm.
98 typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap>
100 TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
102 // ConstMap<Node, bool> const_true_map(true);
103 // This graph contains exaclty the tight edges.
104 // typedef SubGraphAdaptor<Graph, ConstMap<Node, bool>, TightEdgeFilter> SubGW;
105 typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGW;
106 SubGW gw(g, tight_edge_filter);
108 ConstMap<Edge, int> const_1_map(1);
109 Graph::EdgeMap<int> flow(g, 0);
110 // Max flow between s and t in the graph of tight edges.
111 Preflow<SubGW, int, ConstMap<Edge, int>, Graph::EdgeMap<int> >
112 preflow(gw, s, t, const_1_map, flow);
115 cout << "maximum number of edge-disjoint shortest paths: "
116 << preflow.flowValue() << endl;
117 cout << "edges of the maximum number of edge-disjoint shortest s-t paths: "
119 for(EdgeIt e(g); e!=INVALID; ++e)
121 cout << " " << g.id(e) << ", "
122 << g.id(g.source(e)) << "--"
123 << length[e] << "->" << g.id(g.target(e)) << endl;