2 #ifndef HUGO_SUURBALLE_H
3 #define HUGO_SUURBALLE_H
7 #include <graph_wrapper.h>
11 ///\brief Implementation of Suurballe's algorithm
13 /// The class \ref hugo::Suurballe "Suurballe" implements
14 /// Suurballe's algorithm which seeks for k edge-disjoint paths
15 /// from a given source node to a given target node in an
16 /// edge-weighted directed graph having minimal total cost.
21 template <typename Graph, typename T,
22 typename LengthMap=typename Graph::EdgeMap<T> >
29 typedef int ValueType;
30 typedef typename Graph::Edge KeyType;
32 int operator[](typename Graph::Edge e) const {
37 // template <typename Graph, typename T>
39 typedef typename Graph::EdgeMap<T> EdgeMap;
40 typedef typename Graph::NodeMap<T> NodeMap;
45 typedef typename EdgeMap::KeyType KeyType;
46 typedef typename EdgeMap::ValueType ValueType;
48 double operator[](typename Graph::EdgeIt e) const {
49 return 10;//ol.get(e)-pot.get(v)-pot.get(u);
52 ModLengthMap(const EdgeMap &o,
59 typedef typename Graph::Node Node;
60 typedef typename Graph::NodeIt NodeIt;
61 typedef typename Graph::Edge Edge;
62 typedef typename Graph::OutEdgeIt OutEdgeIt;
63 typedef TrivGraphWrapper<const Graph> TrivGraphType;
64 typedef ResGraphWrapper<TrivGraphType,int,typename Graph::EdgeMap<int>,
65 ConstMap> ResGraphType;
68 const LengthMap& length;
73 typename Graph::EdgeMap<int> reversed;
74 typename Graph::NodeMap<T> dijkstra_dist;
79 Suurballe(Graph& _G, LengthMap& _length) : G(_G),
80 length(_length), reversed(_G), dijkstra_dist(_G){ }
82 ///Runs Suurballe's algorithm
83 ///Returns true iff there are k edge-disjoint paths from s to t
84 bool run(Node s, Node t, int k) {
86 LengthMap mod_length_c = length;
88 //ResGraphWrapper< Graph,T,typename Graph::EdgeMap<int>, ConstMap>
90 ResGraphType res_graph(ize, reversed, const1map);
91 //ModLengthMap modified_length(length, dijkstra_dist);
92 //Dijkstra<ResGraphType, ModLengthMap> dijkstra(res_graph, modified_length);
93 //ResGraphWrapper< Graph,T,typename Graph::EdgeMap<int>, ConstMap>
94 Dijkstra<ResGraphType, LengthMap> dijkstra(res_graph, mod_length_c);
96 for (int i=0; i<k; ++i){
98 if (!dijkstra.reached(t)){
99 //There is no k path from s to t
103 //We have to copy the potential
104 typename ResGraphType::EdgeIt e;
105 for ( res_graph.first(e) ; res_graph.valid(e) ; res_graph.next(e) ) {
106 //dijkstra_dist[e] = dijkstra.distMap()[e];
107 mod_length_c[Edge(e)] = mod_length_c[Edge(e)] -
108 dijkstra.distMap()[res_graph.head(e)] +
109 dijkstra.distMap()[res_graph.tail(e)];
113 //Reversing the sortest path
117 e = dijkstra.pred(n);
118 n = dijkstra.predNode(n);
119 reversed[e] = 1-reversed[e];
138 #endif //HUGO_SUURBALLE_H