# HG changeset patch # User Peter Kovacs # Date 2009-10-16 09:35:46 # Node ID abb95d48e89efff4b62c44364faa0b68a13c96ad # Parent 5df6a8f29d5e48db8e1f4aa56cf10b3c99b1571d Add traits class + named parameters to Suurballe (#323) The following types can be modified using named parameters: - FlowMap - PotentialMap - Path - Heap + HeapCrossRef diff --git a/lemon/suurballe.h b/lemon/suurballe.h --- a/lemon/suurballe.h +++ b/lemon/suurballe.h @@ -34,6 +34,49 @@ namespace lemon { + /// \brief Default traits class of Suurballe algorithm. + /// + /// Default traits class of Suurballe algorithm. + /// \tparam GR The digraph type the algorithm runs on. + /// \tparam LEN The type of the length map. + /// The default value is GR::ArcMap. +#ifdef DOXYGEN + template +#else + template < typename GR, + typename LEN = typename GR::template ArcMap > +#endif + struct SuurballeDefaultTraits + { + /// The type of the digraph. + typedef GR Digraph; + /// The type of the length map. + typedef LEN LengthMap; + /// The type of the lengths. + typedef typename LEN::Value Length; + /// The type of the flow map. + typedef typename GR::template ArcMap FlowMap; + /// The type of the potential map. + typedef typename GR::template NodeMap PotentialMap; + + /// \brief The path type + /// + /// The type used for storing the found arc-disjoint paths. + /// It must conform to the \ref lemon::concepts::Path "Path" concept + /// and it must have an \c addBack() function. + typedef lemon::Path Path; + + /// The cross reference type used for the heap. + typedef typename GR::template NodeMap HeapCrossRef; + + /// \brief The heap type used for internal Dijkstra computations. + /// + /// The type of the heap used for internal Dijkstra computations. + /// It must conform to the \ref lemon::concepts::Heap "Heap" concept + /// and its priority type must be \c Length. + typedef BinHeap Heap; + }; + /// \addtogroup shortest_path /// @{ @@ -61,10 +104,11 @@ /// \note For finding \e node-disjoint paths, this algorithm can be used /// along with the \ref SplitNodes adaptor. #ifdef DOXYGEN - template + template #else template < typename GR, - typename LEN = typename GR::template ArcMap > + typename LEN = typename GR::template ArcMap, + typename TR = SuurballeDefaultTraits > #endif class Suurballe { @@ -75,32 +119,29 @@ public: - /// The type of the digraph the algorithm runs on. - typedef GR Digraph; + /// The type of the digraph. + typedef typename TR::Digraph Digraph; /// The type of the length map. - typedef LEN LengthMap; + typedef typename TR::LengthMap LengthMap; /// The type of the lengths. - typedef typename LengthMap::Value Length; -#ifdef DOXYGEN + typedef typename TR::Length Length; + /// The type of the flow map. - typedef GR::ArcMap FlowMap; + typedef typename TR::FlowMap FlowMap; /// The type of the potential map. - typedef GR::NodeMap PotentialMap; -#else - /// The type of the flow map. - typedef typename Digraph::template ArcMap FlowMap; - /// The type of the potential map. - typedef typename Digraph::template NodeMap PotentialMap; -#endif + typedef typename TR::PotentialMap PotentialMap; + /// The type of the path structures. + typedef typename TR::Path Path; + /// The cross reference type used for the heap. + typedef typename TR::HeapCrossRef HeapCrossRef; + /// The heap type used for internal Dijkstra computations. + typedef typename TR::Heap Heap; - /// The type of the path structures. - typedef SimplePath Path; + /// The \ref SuurballeDefaultTraits "traits class" of the algorithm. + typedef TR Traits; private: - typedef typename Digraph::template NodeMap HeapCrossRef; - typedef BinHeap Heap; - // ResidualDijkstra is a special implementation of the // Dijkstra algorithm for finding shortest paths in the // residual network with respect to the reduced arc lengths @@ -254,6 +295,83 @@ }; //class ResidualDijkstra + public: + + /// \name Named Template Parameters + /// @{ + + template + struct SetFlowMapTraits : public Traits { + typedef T FlowMap; + }; + + /// \brief \ref named-templ-param "Named parameter" for setting + /// \c FlowMap type. + /// + /// \ref named-templ-param "Named parameter" for setting + /// \c FlowMap type. + template + struct SetFlowMap + : public Suurballe > { + typedef Suurballe > Create; + }; + + template + struct SetPotentialMapTraits : public Traits { + typedef T PotentialMap; + }; + + /// \brief \ref named-templ-param "Named parameter" for setting + /// \c PotentialMap type. + /// + /// \ref named-templ-param "Named parameter" for setting + /// \c PotentialMap type. + template + struct SetPotentialMap + : public Suurballe > { + typedef Suurballe > Create; + }; + + template + struct SetPathTraits : public Traits { + typedef T Path; + }; + + /// \brief \ref named-templ-param "Named parameter" for setting + /// \c %Path type. + /// + /// \ref named-templ-param "Named parameter" for setting \c %Path type. + /// It must conform to the \ref lemon::concepts::Path "Path" concept + /// and it must have an \c addBack() function. + template + struct SetPath + : public Suurballe > { + typedef Suurballe > Create; + }; + + template + struct SetHeapTraits : public Traits { + typedef H Heap; + typedef CR HeapCrossRef; + }; + + /// \brief \ref named-templ-param "Named parameter" for setting + /// \c Heap and \c HeapCrossRef types. + /// + /// \ref named-templ-param "Named parameter" for setting \c Heap + /// and \c HeapCrossRef types with automatic allocation. + /// They will be used for internal Dijkstra computations. + /// The heap type must conform to the \ref lemon::concepts::Heap "Heap" + /// concept and its priority type must be \c Length. + template > + struct SetHeap + : public Suurballe > { + typedef Suurballe > Create; + }; + + /// @} + private: // The digraph the algorithm runs on diff --git a/test/suurballe_test.cc b/test/suurballe_test.cc --- a/test/suurballe_test.cc +++ b/test/suurballe_test.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include "test_tools.h" @@ -81,7 +82,13 @@ typedef Digraph::Arc Arc; typedef concepts::ReadMap LengthMap; - typedef Suurballe SuurballeType; + typedef Suurballe ST; + typedef Suurballe + ::SetFlowMap + ::SetPotentialMap + ::SetPath > + ::SetHeap > > + ::Create SuurballeType; Digraph g; Node n;