2 #ifndef HUGO_SUURBALLE_H
3 #define HUGO_SUURBALLE_H
6 ///\brief Suurballe algorithm.
10 #include <graph_wrapper.h>
14 ///\brief Implementation of Suurballe's algorithm
16 /// The class \ref hugo::Suurballe "Suurballe" implements
17 /// Suurballe's algorithm which seeks for k edge-disjoint paths
18 /// from a given source node to a given target node in an
19 /// edge-weighted directed graph having minimal total cost.
23 template <typename Graph, typename T,
24 typename LengthMap=typename Graph::EdgeMap<T> >
31 typedef int ValueType;
32 typedef typename Graph::Edge KeyType;
34 int operator[](typename Graph::Edge e) const {
39 // template <typename Graph, typename T>
41 typedef typename Graph::EdgeMap<T> EdgeMap;
42 typedef typename Graph::NodeMap<T> NodeMap;
47 typedef typename EdgeMap::KeyType KeyType;
48 typedef typename EdgeMap::ValueType ValueType;
50 double operator[](typename Graph::EdgeIt e) const {
51 return 10;//ol.get(e)-pot.get(v)-pot.get(u);
54 ModLengthMap(const EdgeMap &o,
61 typedef typename Graph::Node Node;
62 typedef typename Graph::NodeIt NodeIt;
63 typedef typename Graph::Edge Edge;
64 typedef typename Graph::OutEdgeIt OutEdgeIt;
65 typedef TrivGraphWrapper<const Graph> TrivGraphType;
66 typedef ResGraphWrapper<TrivGraphType,int,typename Graph::EdgeMap<int>,
67 ConstMap> ResGraphType;
70 const LengthMap& length;
75 typename Graph::EdgeMap<int> reversed;
76 typename Graph::NodeMap<T> dijkstra_dist;
81 Suurballe(Graph& _G, LengthMap& _length) : G(_G),
82 length(_length), reversed(_G), dijkstra_dist(_G){ }
84 ///Runs Suurballe's algorithm
86 ///Runs Suurballe's algorithm
87 ///Returns true iff there are k edge-disjoint paths from s to t
88 bool run(Node s, Node t, int k) {
90 LengthMap mod_length_c = length;
92 //ResGraphWrapper< Graph,T,typename Graph::EdgeMap<int>, ConstMap>
94 ResGraphType res_graph(ize, reversed, const1map);
95 //ModLengthMap modified_length(length, dijkstra_dist);
96 //Dijkstra<ResGraphType, ModLengthMap> dijkstra(res_graph, modified_length);
97 //ResGraphWrapper< Graph,T,typename Graph::EdgeMap<int>, ConstMap>
98 Dijkstra<ResGraphType, LengthMap> dijkstra(res_graph, mod_length_c);
100 for (int i=0; i<k; ++i){
102 if (!dijkstra.reached(t)){
103 //There is no k path from s to t
107 //We have to copy the potential
108 typename ResGraphType::EdgeIt e;
109 for ( res_graph.first(e) ; res_graph.valid(e) ; res_graph.next(e) ) {
110 //dijkstra_dist[e] = dijkstra.distMap()[e];
111 mod_length_c[Edge(e)] = mod_length_c[Edge(e)] -
112 dijkstra.distMap()[res_graph.head(e)] +
113 dijkstra.distMap()[res_graph.tail(e)];
117 //Reversing the sortest path
121 e = dijkstra.pred(n);
122 n = dijkstra.predNode(n);
123 reversed[e] = 1-reversed[e];
142 #endif //HUGO_SUURBALLE_H