athos@276: // -*- c++ -*- athos@276: #ifndef HUGO_SUURBALLE_H athos@276: #define HUGO_SUURBALLE_H athos@276: athos@276: #include athos@276: #include athos@276: #include athos@276: namespace hugo { athos@276: athos@276: athos@276: ///\brief Implementation of Suurballe's algorithm athos@276: /// athos@276: /// The class \ref hugo::Suurballe "Suurballe" implements athos@276: /// Suurballe's algorithm which seeks for k edge-disjoint paths athos@276: /// from a given source node to a given target node in an athos@276: /// edge-weighted directed graph having minimal total cost. athos@276: /// athos@276: /// athos@276: athos@276: athos@276: template > athos@276: class Suurballe { athos@276: athos@276: athos@276: //Writing maps athos@276: class ConstMap { athos@276: public : athos@276: typedef int ValueType; athos@276: int operator[](typename Graph::Edge e) const { athos@276: return 1; athos@276: } athos@276: }; athos@276: /* athos@276: // template athos@276: class ModLengthMap { athos@276: typedef typename Graph::EdgeMap EdgeMap; athos@276: typedef typename Graph::NodeMap NodeMap; athos@276: athos@276: const EdgeMap &ol; athos@276: const NodeMap &pot; athos@276: public : athos@276: typedef typename EdgeMap::KeyType KeyType; athos@276: typedef typename EdgeMap::ValueType ValueType; athos@276: athos@276: double operator[](typename Graph::EdgeIt e) const { athos@276: return 10;//ol.get(e)-pot.get(v)-pot.get(u); athos@276: } athos@276: athos@276: ModLengthMap(const EdgeMap &o, athos@276: const NodeMap &p) : athos@276: ol(o), pot(p){}; athos@276: }; athos@276: */ athos@276: athos@276: athos@276: typedef typename Graph::Node Node; athos@276: typedef typename Graph::NodeIt NodeIt; athos@276: typedef typename Graph::Edge Edge; athos@276: typedef typename Graph::OutEdgeIt OutEdgeIt; athos@276: typedef ResGraphWrapper< Graph,T,typename Graph::EdgeMap, ConstMap > ResGraphType; athos@276: athos@276: const Graph& G; athos@276: const LengthMap& length; athos@276: athos@276: athos@276: //auxiliary variables athos@276: athos@276: typename Graph::EdgeMap reversed; athos@276: typename Graph::NodeMap dijkstra_dist; athos@276: athos@276: public : athos@276: athos@276: athos@276: Suurballe(Graph& _G, LengthMap& _length) : G(_G), athos@276: length(_length), reversed(_G), dijkstra_dist(_G){ } athos@276: athos@276: ///Runs Suurballe's algorithm athos@276: ///Returns true iff there are k edge-disjoint paths from s to t athos@276: bool run(Node s, Node t, int k) { athos@276: athos@276: LengthMap mod_length_c = length; athos@276: ConstMap const1map; athos@276: //ResGraphWrapper< Graph,T,typename Graph::EdgeMap, ConstMap> athos@276: ResGraphType res_graph(G, reversed, const1map); athos@276: //ModLengthMap modified_length(length, dijkstra_dist); athos@276: //Dijkstra dijkstra(res_graph, modified_length); athos@276: //ResGraphWrapper< Graph,T,typename Graph::EdgeMap, ConstMap> athos@276: Dijkstra dijkstra(res_graph, mod_length_c); athos@276: athos@276: for (int i=0; i