COIN-OR::LEMON - Graph Library

Changes in / [247:f1158744a112:246:7c67988fca07] in lemon-main


Ignore:
Location:
lemon
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/bfs.h

    r247 r220  
    2222///\ingroup search
    2323///\file
    24 ///\brief BFS algorithm.
     24///\brief Bfs algorithm.
    2525
    2626#include <lemon/list_graph.h>
     
    3232namespace lemon {
    3333
     34
     35
    3436  ///Default traits class of Bfs class.
    3537
     
    3941  struct BfsDefaultTraits
    4042  {
    41     ///The type of the digraph the algorithm runs on.
     43    ///The digraph type the algorithm runs on.
    4244    typedef GR Digraph;
    43 
    44     ///\brief The type of the map that stores the predecessor
     45    ///\brief The type of the map that stores the last
    4546    ///arcs of the shortest paths.
    4647    ///
    47     ///The type of the map that stores the predecessor
     48    ///The type of the map that stores the last
    4849    ///arcs of the shortest paths.
    4950    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    50     typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    51     ///Instantiates a \ref PredMap.
     51    ///
     52    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
     53    ///Instantiates a PredMap.
    5254
    5355    ///This function instantiates a \ref PredMap.
    54     ///\param g is the digraph, to which we would like to define the
    55     ///\ref PredMap.
     56    ///\param G is the digraph, to which we would like to define the PredMap.
    5657    ///\todo The digraph alone may be insufficient to initialize
    57     static PredMap *createPredMap(const Digraph &g)
    58     {
    59       return new PredMap(g);
    60     }
    61 
     58    static PredMap *createPredMap(const GR &G)
     59    {
     60      return new PredMap(G);
     61    }
    6262    ///The type of the map that indicates which nodes are processed.
    6363
    6464    ///The type of the map that indicates which nodes are processed.
    6565    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    66     ///By default it is a NullMap.
     66    ///\todo named parameter to set this type, function to read and write.
    6767    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    68     ///Instantiates a \ref ProcessedMap.
     68    ///Instantiates a ProcessedMap.
    6969
    7070    ///This function instantiates a \ref ProcessedMap.
     
    7272    ///we would like to define the \ref ProcessedMap
    7373#ifdef DOXYGEN
    74     static ProcessedMap *createProcessedMap(const Digraph &g)
     74    static ProcessedMap *createProcessedMap(const GR &g)
    7575#else
    76     static ProcessedMap *createProcessedMap(const Digraph &)
     76    static ProcessedMap *createProcessedMap(const GR &)
    7777#endif
    7878    {
    7979      return new ProcessedMap();
    8080    }
    81 
    8281    ///The type of the map that indicates which nodes are reached.
    8382
    8483    ///The type of the map that indicates which nodes are reached.
    85     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     84    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     85    ///\todo named parameter to set this type, function to read and write.
    8686    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    87     ///Instantiates a \ref ReachedMap.
     87    ///Instantiates a ReachedMap.
    8888
    8989    ///This function instantiates a \ref ReachedMap.
    90     ///\param g is the digraph, to which
     90    ///\param G is the digraph, to which
    9191    ///we would like to define the \ref ReachedMap.
    92     static ReachedMap *createReachedMap(const Digraph &g)
    93     {
    94       return new ReachedMap(g);
    95     }
    96 
    97     ///The type of the map that stores the distances of the nodes.
    98 
    99     ///The type of the map that stores the distances of the nodes.
     92    static ReachedMap *createReachedMap(const GR &G)
     93    {
     94      return new ReachedMap(G);
     95    }
     96    ///The type of the map that stores the dists of the nodes.
     97
     98    ///The type of the map that stores the dists of the nodes.
    10099    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     100    ///
    101101    typedef typename Digraph::template NodeMap<int> DistMap;
    102     ///Instantiates a \ref DistMap.
     102    ///Instantiates a DistMap.
    103103
    104104    ///This function instantiates a \ref DistMap.
    105     ///\param g is the digraph, to which we would like to define the
    106     ///\ref DistMap.
    107     static DistMap *createDistMap(const Digraph &g)
    108     {
    109       return new DistMap(g);
     105    ///\param G is the digraph, to which we would like to define
     106    ///the \ref DistMap
     107    static DistMap *createDistMap(const GR &G)
     108    {
     109      return new DistMap(G);
    110110    }
    111111  };
     
    116116  ///This class provides an efficient implementation of the %BFS algorithm.
    117117  ///
    118   ///There is also a \ref bfs() "function type interface" for the BFS
    119   ///algorithm, which is convenient in the simplier cases and it can be
    120   ///used easier.
    121   ///
    122   ///\tparam GR The type of the digraph the algorithm runs on.
    123   ///The default value is \ref ListDigraph. The value of GR is not used
    124   ///directly by \ref Bfs, it is only passed to \ref BfsDefaultTraits.
     118  ///\tparam GR The digraph type the algorithm runs on. The default value is
     119  ///\ref ListDigraph. The value of GR is not used directly by Bfs, it
     120  ///is only passed to \ref BfsDefaultTraits.
    125121  ///\tparam TR Traits class to set various data types used by the algorithm.
    126122  ///The default traits class is
     
    128124  ///See \ref BfsDefaultTraits for the documentation of
    129125  ///a Bfs traits class.
     126
    130127#ifdef DOXYGEN
    131128  template <typename GR,
     
    137134  class Bfs {
    138135  public:
    139     ///\ref Exception for uninitialized parameters.
    140 
    141     ///This error represents problems in the initialization of the
    142     ///parameters of the algorithm.
     136    /**
     137     * \brief \ref Exception for uninitialized parameters.
     138     *
     139     * This error represents problems in the initialization
     140     * of the parameters of the algorithms.
     141     */
    143142    class UninitializedParameter : public lemon::UninitializedParameter {
    144143    public:
     
    148147    };
    149148
    150     ///The type of the digraph the algorithm runs on.
     149    typedef TR Traits;
     150    ///The type of the underlying digraph.
    151151    typedef typename TR::Digraph Digraph;
    152152
    153     ///\brief The type of the map that stores the predecessor arcs of the
    154     ///shortest paths.
     153    ///\brief The type of the map that stores the last
     154    ///arcs of the shortest paths.
    155155    typedef typename TR::PredMap PredMap;
    156     ///The type of the map that stores the distances of the nodes.
     156    ///The type of the map indicating which nodes are reached.
     157    typedef typename TR::ReachedMap ReachedMap;
     158    ///The type of the map indicating which nodes are processed.
     159    typedef typename TR::ProcessedMap ProcessedMap;
     160    ///The type of the map that stores the dists of the nodes.
    157161    typedef typename TR::DistMap DistMap;
    158     ///The type of the map that indicates which nodes are reached.
    159     typedef typename TR::ReachedMap ReachedMap;
    160     ///The type of the map that indicates which nodes are processed.
    161     typedef typename TR::ProcessedMap ProcessedMap;
    162     ///The type of the paths.
    163     typedef PredMapPath<Digraph, PredMap> Path;
    164 
    165     ///The traits class.
    166     typedef TR Traits;
    167 
    168162  private:
    169163
     
    173167    typedef typename Digraph::OutArcIt OutArcIt;
    174168
    175     //Pointer to the underlying digraph.
     169    /// Pointer to the underlying digraph.
    176170    const Digraph *G;
    177     //Pointer to the map of predecessor arcs.
     171    ///Pointer to the map of predecessors arcs.
    178172    PredMap *_pred;
    179     //Indicates if _pred is locally allocated (true) or not.
     173    ///Indicates if \ref _pred is locally allocated (\c true) or not.
    180174    bool local_pred;
    181     //Pointer to the map of distances.
     175    ///Pointer to the map of distances.
    182176    DistMap *_dist;
    183     //Indicates if _dist is locally allocated (true) or not.
     177    ///Indicates if \ref _dist is locally allocated (\c true) or not.
    184178    bool local_dist;
    185     //Pointer to the map of reached status of the nodes.
     179    ///Pointer to the map of reached status of the nodes.
    186180    ReachedMap *_reached;
    187     //Indicates if _reached is locally allocated (true) or not.
     181    ///Indicates if \ref _reached is locally allocated (\c true) or not.
    188182    bool local_reached;
    189     //Pointer to the map of processed status of the nodes.
     183    ///Pointer to the map of processed status of the nodes.
    190184    ProcessedMap *_processed;
    191     //Indicates if _processed is locally allocated (true) or not.
     185    ///Indicates if \ref _processed is locally allocated (\c true) or not.
    192186    bool local_processed;
    193187
     
    197191
    198192    ///Creates the maps if necessary.
     193
    199194    ///\todo Better memory allocation (instead of new).
    200195    void create_maps()
     
    239234    };
    240235    ///\brief \ref named-templ-param "Named parameter" for setting
    241     ///\ref PredMap type.
    242     ///
    243     ///\ref named-templ-param "Named parameter" for setting
    244     ///\ref PredMap type.
     236    ///PredMap type
     237    ///
     238    ///\ref named-templ-param "Named parameter" for setting PredMap type
     239    ///
    245240    template <class T>
    246241    struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {
     
    257252    };
    258253    ///\brief \ref named-templ-param "Named parameter" for setting
    259     ///\ref DistMap type.
    260     ///
    261     ///\ref named-templ-param "Named parameter" for setting
    262     ///\ref DistMap type.
     254    ///DistMap type
     255    ///
     256    ///\ref named-templ-param "Named parameter" for setting DistMap type
     257    ///
    263258    template <class T>
    264259    struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > {
     
    275270    };
    276271    ///\brief \ref named-templ-param "Named parameter" for setting
    277     ///\ref ReachedMap type.
    278     ///
    279     ///\ref named-templ-param "Named parameter" for setting
    280     ///\ref ReachedMap type.
     272    ///ReachedMap type
     273    ///
     274    ///\ref named-templ-param "Named parameter" for setting ReachedMap type
     275    ///
    281276    template <class T>
    282277    struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > {
     
    293288    };
    294289    ///\brief \ref named-templ-param "Named parameter" for setting
    295     ///\ref ProcessedMap type.
    296     ///
    297     ///\ref named-templ-param "Named parameter" for setting
    298     ///\ref ProcessedMap type.
     290    ///ProcessedMap type
     291    ///
     292    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
     293    ///
    299294    template <class T>
    300295    struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits<T> > {
     
    304299    struct DefDigraphProcessedMapTraits : public Traits {
    305300      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    306       static ProcessedMap *createProcessedMap(const Digraph &g)
     301      static ProcessedMap *createProcessedMap(const Digraph &G)
    307302      {
    308         return new ProcessedMap(g);
    309       }
    310     };
    311     ///\brief \ref named-templ-param "Named parameter" for setting
    312     ///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
    313     ///
    314     ///\ref named-templ-param "Named parameter" for setting
    315     ///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
     303        return new ProcessedMap(G);
     304      }
     305    };
     306    ///\brief \ref named-templ-param "Named parameter"
     307    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
     308    ///
     309    ///\ref named-templ-param "Named parameter"
     310    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
    316311    ///If you don't set it explicitly, it will be automatically allocated.
    317312    template <class T>
     
    327322    ///Constructor.
    328323
    329     ///Constructor.
    330     ///\param g The digraph the algorithm runs on.
    331     Bfs(const Digraph &g) :
    332       G(&g),
     324    ///\param _G the digraph the algorithm will run on.
     325    ///
     326    Bfs(const Digraph& _G) :
     327      G(&_G),
    333328      _pred(NULL), local_pred(false),
    334329      _dist(NULL), local_dist(false),
     
    346341    }
    347342
    348     ///Sets the map that stores the predecessor arcs.
    349 
    350     ///Sets the map that stores the predecessor arcs.
     343    ///Sets the map storing the predecessor arcs.
     344
     345    ///Sets the map storing the predecessor arcs.
    351346    ///If you don't use this function before calling \ref run(),
    352347    ///it will allocate one. The destructor deallocates this
     
    363358    }
    364359
    365     ///Sets the map that indicates which nodes are reached.
    366 
    367     ///Sets the map that indicates which nodes are reached.
     360    ///Sets the map indicating the reached nodes.
     361
     362    ///Sets the map indicating the reached nodes.
    368363    ///If you don't use this function before calling \ref run(),
    369364    ///it will allocate one. The destructor deallocates this
     
    380375    }
    381376
    382     ///Sets the map that indicates which nodes are processed.
    383 
    384     ///Sets the map that indicates which nodes are processed.
     377    ///Sets the map indicating the processed nodes.
     378
     379    ///Sets the map indicating the processed nodes.
    385380    ///If you don't use this function before calling \ref run(),
    386381    ///it will allocate one. The destructor deallocates this
     
    397392    }
    398393
    399     ///Sets the map that stores the distances of the nodes.
    400 
    401     ///Sets the map that stores the distances of the nodes calculated by
    402     ///the algorithm.
     394    ///Sets the map storing the distances calculated by the algorithm.
     395
     396    ///Sets the map storing the distances calculated by the algorithm.
    403397    ///If you don't use this function before calling \ref run(),
    404398    ///it will allocate one. The destructor deallocates this
     
    416410
    417411  public:
    418 
    419412    ///\name Execution control
    420413    ///The simplest way to execute the algorithm is to use
    421     ///one of the member functions called \ref lemon::Bfs::run() "run()".
     414    ///one of the member functions called \c run(...).
    422415    ///\n
    423     ///If you need more control on the execution, first you must call
    424     ///\ref lemon::Bfs::init() "init()", then you can add several source
    425     ///nodes with \ref lemon::Bfs::addSource() "addSource()".
    426     ///Finally \ref lemon::Bfs::start() "start()" will perform the
    427     ///actual path computation.
     416    ///If you need more control on the execution,
     417    ///first you must call \ref init(), then you can add several source nodes
     418    ///with \ref addSource().
     419    ///Finally \ref start() will perform the actual path
     420    ///computation.
    428421
    429422    ///@{
    430423
    431     ///Initializes the internal data structures.
    432 
     424    ///\brief Initializes the internal data structures.
     425    ///
    433426    ///Initializes the internal data structures.
    434427    ///
     
    468461    ///\return The processed node.
    469462    ///
    470     ///\pre The queue must not be empty.
     463    ///\warning The queue must not be empty!
    471464    Node processNextNode()
    472465    {
     
    490483    ///Processes the next node.
    491484
    492     ///Processes the next node and checks if the given target node
     485    ///Processes the next node. And checks that the given target node
    493486    ///is reached. If the target node is reachable from the processed
    494     ///node, then the \c reach parameter will be set to \c true.
     487    ///node then the reached parameter will be set true. The reached
     488    ///parameter should be initially false.
    495489    ///
    496490    ///\param target The target node.
    497     ///\retval reach Indicates if the target node is reached.
    498     ///It should be initially \c false.
    499     ///
     491    ///\retval reach Indicates that the target node is reached.
    500492    ///\return The processed node.
    501493    ///
    502     ///\pre The queue must not be empty.
     494    ///\warning The queue must not be empty!
    503495    Node processNextNode(Node target, bool& reach)
    504496    {
     
    523515    ///Processes the next node.
    524516
    525     ///Processes the next node and checks if at least one of reached
    526     ///nodes has \c true value in the \c nm node map. If one node
    527     ///with \c true value is reachable from the processed node, then the
    528     ///\c rnode parameter will be set to the first of such nodes.
    529     ///
    530     ///\param nm A \c bool (or convertible) node map that indicates the
    531     ///possible targets.
     517    ///Processes the next node. And checks that at least one of
     518    ///reached node has true value in the \c nm node map. If one node
     519    ///with true value is reachable from the processed node then the
     520    ///rnode parameter will be set to the first of such nodes.
     521    ///
     522    ///\param nm The node map of possible targets.
    532523    ///\retval rnode The reached target node.
    533     ///It should be initially \c INVALID.
    534     ///
    535524    ///\return The processed node.
    536525    ///
    537     ///\pre The queue must not be empty.
     526    ///\warning The queue must not be empty!
    538527    template<class NM>
    539528    Node processNextNode(const NM& nm, Node& rnode)
     
    557546    }
    558547
    559     ///The next node to be processed.
    560 
    561     ///Returns the next node to be processed or \c INVALID if the queue
    562     ///is empty.
    563     Node nextNode() const
     548    ///Next node to be processed.
     549
     550    ///Next node to be processed.
     551    ///
     552    ///\return The next node to be processed or INVALID if the queue is
     553    /// empty.
     554    Node nextNode()
    564555    {
    565556      return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID;
     
    567558
    568559    ///\brief Returns \c false if there are nodes
    569     ///to be processed.
     560    ///to be processed in the queue
    570561    ///
    571562    ///Returns \c false if there are nodes
    572     ///to be processed in the queue.
    573     bool emptyQueue() const { return _queue_tail==_queue_head; }
    574 
     563    ///to be processed in the queue
     564    bool emptyQueue() { return _queue_tail==_queue_head; }
    575565    ///Returns the number of the nodes to be processed.
    576566
    577567    ///Returns the number of the nodes to be processed in the queue.
    578     int queueSize() const { return _queue_head-_queue_tail; }
     568    int queueSize() { return _queue_head-_queue_tail; }
    579569
    580570    ///Executes the algorithm.
     
    582572    ///Executes the algorithm.
    583573    ///
     574    ///\pre init() must be called and at least one node should be added
     575    ///with addSource() before using this function.
     576    ///
    584577    ///This method runs the %BFS algorithm from the root node(s)
    585     ///in order to compute the shortest path to each node.
    586     ///
    587     ///The algorithm computes
    588     ///- the shortest path tree (forest),
    589     ///- the distance of each node from the root(s).
    590     ///
    591     ///\pre init() must be called and at least one root node should be
    592     ///added with addSource() before using this function.
    593     ///
    594     ///\note <tt>b.start()</tt> is just a shortcut of the following code.
    595     ///\code
    596     ///  while ( !b.emptyQueue() ) {
    597     ///    b.processNextNode();
    598     ///  }
    599     ///\endcode
     578    ///in order to
     579    ///compute the
     580    ///shortest path to each node. The algorithm computes
     581    ///- The shortest path tree.
     582    ///- The distance of each node from the root(s).
    600583    void start()
    601584    {
     
    603586    }
    604587
    605     ///Executes the algorithm until the given target node is reached.
    606 
    607     ///Executes the algorithm until the given target node is reached.
     588    ///Executes the algorithm until \c dest is reached.
     589
     590    ///Executes the algorithm until \c dest is reached.
     591    ///
     592    ///\pre init() must be called and at least one node should be added
     593    ///with addSource() before using this function.
    608594    ///
    609595    ///This method runs the %BFS algorithm from the root node(s)
    610596    ///in order to compute the shortest path to \c dest.
    611     ///
    612597    ///The algorithm computes
    613     ///- the shortest path to \c dest,
    614     ///- the distance of \c dest from the root(s).
    615     ///
    616     ///\pre init() must be called and at least one root node should be
    617     ///added with addSource() before using this function.
    618     ///
    619     ///\note <tt>b.start(t)</tt> is just a shortcut of the following code.
    620     ///\code
    621     ///  bool reach = false;
    622     ///  while ( !b.emptyQueue() && !reach ) {
    623     ///    b.processNextNode(t, reach);
    624     ///  }
    625     ///\endcode
     598    ///- The shortest path to \c  dest.
     599    ///- The distance of \c dest from the root(s).
    626600    void start(Node dest)
    627601    {
     
    634608    ///Executes the algorithm until a condition is met.
    635609    ///
    636     ///This method runs the %BFS algorithm from the root node(s) in
    637     ///order to compute the shortest path to a node \c v with
    638     /// <tt>nm[v]</tt> true, if such a node can be found.
    639     ///
    640     ///\param nm A \c bool (or convertible) node map. The algorithm
    641     ///will stop when it reaches a node \c v with <tt>nm[v]</tt> true.
     610    ///\pre init() must be called and at least one node should be added
     611    ///with addSource() before using this function.
     612    ///
     613    ///\param nm must be a bool (or convertible) node map. The
     614    ///algorithm will stop when it reaches a node \c v with
     615    /// <tt>nm[v]</tt> true.
    642616    ///
    643617    ///\return The reached node \c v with <tt>nm[v]</tt> true or
    644618    ///\c INVALID if no such node was found.
    645     ///
    646     ///\pre init() must be called and at least one root node should be
    647     ///added with addSource() before using this function.
    648     ///
    649     ///\note <tt>b.start(nm)</tt> is just a shortcut of the following code.
    650     ///\code
    651     ///  Node rnode = INVALID;
    652     ///  while ( !b.emptyQueue() && rnode == INVALID ) {
    653     ///    b.processNextNode(nm, rnode);
    654     ///  }
    655     ///  return rnode;
    656     ///\endcode
    657     template<class NodeBoolMap>
    658     Node start(const NodeBoolMap &nm)
     619    template<class NM>
     620    Node start(const NM &nm)
    659621    {
    660622      Node rnode = INVALID;
     
    665627    }
    666628
    667     ///Runs the algorithm from the given node.
    668 
    669     ///This method runs the %BFS algorithm from node \c s
    670     ///in order to compute the shortest path to each node.
    671     ///
    672     ///The algorithm computes
    673     ///- the shortest path tree,
    674     ///- the distance of each node from the root.
    675     ///
    676     ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
     629    ///Runs %BFS algorithm from node \c s.
     630
     631    ///This method runs the %BFS algorithm from a root node \c s
     632    ///in order to
     633    ///compute the
     634    ///shortest path to each node. The algorithm computes
     635    ///- The shortest path tree.
     636    ///- The distance of each node from the root.
     637    ///
     638    ///\note b.run(s) is just a shortcut of the following code.
    677639    ///\code
    678640    ///  b.init();
     
    688650    ///Finds the shortest path between \c s and \c t.
    689651
    690     ///This method runs the %BFS algorithm from node \c s
    691     ///in order to compute the shortest path to \c t.
    692     ///
    693     ///\return The length of the shortest <tt>s</tt>--<tt>t</tt> path,
    694     ///if \c t is reachable form \c s, \c 0 otherwise.
    695     ///
    696     ///\note Apart from the return value, <tt>b.run(s,t)</tt> is just a
    697     ///shortcut of the following code.
     652    ///Finds the shortest path between \c s and \c t.
     653    ///
     654    ///\return The length of the shortest s---t path if there exists one,
     655    ///0 otherwise.
     656    ///\note Apart from the return value, b.run(s) is
     657    ///just a shortcut of the following code.
    698658    ///\code
    699659    ///  b.init();
     
    708668    }
    709669
    710     ///Runs the algorithm to visit all nodes in the digraph.
    711 
    712     ///This method runs the %BFS algorithm in order to
    713     ///compute the shortest path to each node.
    714     ///
    715     ///The algorithm computes
    716     ///- the shortest path tree (forest),
    717     ///- the distance of each node from the root(s).
    718     ///
    719     ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
    720     ///\code
    721     ///  b.init();
    722     ///  for (NodeIt n(gr); n != INVALID; ++n) {
    723     ///    if (!b.reached(n)) {
    724     ///      b.addSource(n);
    725     ///      b.start();
    726     ///    }
    727     ///  }
    728     ///\endcode
    729     void run() {
    730       init();
    731       for (NodeIt n(*G); n != INVALID; ++n) {
    732         if (!reached(n)) {
    733           addSource(n);
    734           start();
    735         }
    736       }
    737     }
    738 
    739670    ///@}
    740671
     
    742673    ///The result of the %BFS algorithm can be obtained using these
    743674    ///functions.\n
    744     ///Either \ref lemon::Bfs::run() "run()" or \ref lemon::Bfs::start()
    745     ///"start()" must be called before using them.
     675    ///Before the use of these functions,
     676    ///either run() or start() must be calleb.
    746677
    747678    ///@{
    748679
    749     ///The shortest path to a node.
    750 
    751     ///Returns the shortest path to a node.
    752     ///
    753     ///\warning \c t should be reachable from the root(s).
    754     ///
    755     ///\pre Either \ref run() or \ref start() must be called before
    756     ///using this function.
    757     Path path(Node t) const { return Path(*G, *_pred, t); }
     680    typedef PredMapPath<Digraph, PredMap> Path;
     681
     682    ///Gives back the shortest path.
     683
     684    ///Gives back the shortest path.
     685    ///\pre The \c t should be reachable from the source.
     686    Path path(Node t)
     687    {
     688      return Path(*G, *_pred, t);
     689    }
    758690
    759691    ///The distance of a node from the root(s).
    760692
    761693    ///Returns the distance of a node from the root(s).
    762     ///
    763     ///\warning If node \c v is not reachable from the root(s), then
    764     ///the return value of this function is undefined.
    765     ///
    766     ///\pre Either \ref run() or \ref start() must be called before
    767     ///using this function.
     694    ///\pre \ref run() must be called before using this function.
     695    ///\warning If node \c v in unreachable from the root(s) the return value
     696    ///of this function is undefined.
    768697    int dist(Node v) const { return (*_dist)[v]; }
    769698
    770     ///Returns the 'previous arc' of the shortest path tree for a node.
    771 
    772     ///This function returns the 'previous arc' of the shortest path
    773     ///tree for the node \c v, i.e. it returns the last arc of a
    774     ///shortest path from the root(s) to \c v. It is \c INVALID if \c v
    775     ///is not reachable from the root(s) or if \c v is a root.
    776     ///
    777     ///The shortest path tree used here is equal to the shortest path
    778     ///tree used in \ref predNode().
    779     ///
    780     ///\pre Either \ref run() or \ref start() must be called before
    781     ///using this function.
     699    ///Returns the 'previous arc' of the shortest path tree.
     700
     701    ///For a node \c v it returns the 'previous arc'
     702    ///of the shortest path tree,
     703    ///i.e. it returns the last arc of a shortest path from the root(s) to \c
     704    ///v. It is \ref INVALID
     705    ///if \c v is unreachable from the root(s) or \c v is a root. The
     706    ///shortest path tree used here is equal to the shortest path tree used in
     707    ///\ref predNode().
     708    ///\pre Either \ref run() or \ref start() must be called before using
     709    ///this function.
    782710    Arc predArc(Node v) const { return (*_pred)[v];}
    783711
    784     ///Returns the 'previous node' of the shortest path tree for a node.
    785 
    786     ///This function returns the 'previous node' of the shortest path
    787     ///tree for the node \c v, i.e. it returns the last but one node
    788     ///from a shortest path from the root(s) to \c v. It is \c INVALID
    789     ///if \c v is not reachable from the root(s) or if \c v is a root.
    790     ///
     712    ///Returns the 'previous node' of the shortest path tree.
     713
     714    ///For a node \c v it returns the 'previous node'
     715    ///of the shortest path tree,
     716    ///i.e. it returns the last but one node from a shortest path from the
     717    ///root(a) to \c /v.
     718    ///It is INVALID if \c v is unreachable from the root(s) or
     719    ///if \c v itself a root.
    791720    ///The shortest path tree used here is equal to the shortest path
    792721    ///tree used in \ref predArc().
    793     ///
    794722    ///\pre Either \ref run() or \ref start() must be called before
    795723    ///using this function.
     
    797725                                  G->source((*_pred)[v]); }
    798726
    799     ///\brief Returns a const reference to the node map that stores the
    800     /// distances of the nodes.
    801     ///
    802     ///Returns a const reference to the node map that stores the distances
    803     ///of the nodes calculated by the algorithm.
    804     ///
    805     ///\pre Either \ref run() or \ref init()
    806     ///must be called before using this function.
     727    ///Returns a reference to the NodeMap of distances.
     728
     729    ///Returns a reference to the NodeMap of distances.
     730    ///\pre Either \ref run() or \ref init() must
     731    ///be called before using this function.
    807732    const DistMap &distMap() const { return *_dist;}
    808733
    809     ///\brief Returns a const reference to the node map that stores the
    810     ///predecessor arcs.
    811     ///
    812     ///Returns a const reference to the node map that stores the predecessor
    813     ///arcs, which form the shortest path tree.
    814     ///
     734    ///Returns a reference to the shortest path tree map.
     735
     736    ///Returns a reference to the NodeMap of the arcs of the
     737    ///shortest path tree.
    815738    ///\pre Either \ref run() or \ref init()
    816739    ///must be called before using this function.
    817740    const PredMap &predMap() const { return *_pred;}
    818741
    819     ///Checks if a node is reachable from the root(s).
    820 
    821     ///Returns \c true if \c v is reachable from the root(s).
     742    ///Checks if a node is reachable from the root.
     743
     744    ///Returns \c true if \c v is reachable from the root.
     745    ///\warning The source nodes are indicated as unreached.
    822746    ///\pre Either \ref run() or \ref start()
    823747    ///must be called before using this function.
    824     bool reached(Node v) const { return (*_reached)[v]; }
     748    ///
     749    bool reached(Node v) { return (*_reached)[v]; }
    825750
    826751    ///@}
    827752  };
    828753
    829   ///Default traits class of bfs() function.
    830 
    831   ///Default traits class of bfs() function.
     754  ///Default traits class of Bfs function.
     755
     756  ///Default traits class of Bfs function.
    832757  ///\tparam GR Digraph type.
    833758  template<class GR>
    834759  struct BfsWizardDefaultTraits
    835760  {
    836     ///The type of the digraph the algorithm runs on.
     761    ///The digraph type the algorithm runs on.
    837762    typedef GR Digraph;
    838 
    839     ///\brief The type of the map that stores the predecessor
     763    ///\brief The type of the map that stores the last
    840764    ///arcs of the shortest paths.
    841765    ///
    842     ///The type of the map that stores the predecessor
     766    ///The type of the map that stores the last
    843767    ///arcs of the shortest paths.
    844768    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    845     typedef NullMap<typename Digraph::Node,typename Digraph::Arc> PredMap;
    846     ///Instantiates a \ref PredMap.
     769    ///
     770    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
     771    ///Instantiates a PredMap.
    847772
    848773    ///This function instantiates a \ref PredMap.
    849     ///\param g is the digraph, to which we would like to define the
    850     ///\ref PredMap.
     774    ///\param g is the digraph, to which we would like to define the PredMap.
    851775    ///\todo The digraph alone may be insufficient to initialize
    852776#ifdef DOXYGEN
    853     static PredMap *createPredMap(const Digraph &g)
     777    static PredMap *createPredMap(const GR &g)
    854778#else
    855     static PredMap *createPredMap(const Digraph &)
     779    static PredMap *createPredMap(const GR &)
    856780#endif
    857781    {
     
    863787    ///The type of the map that indicates which nodes are processed.
    864788    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     789    ///\todo named parameter to set this type, function to read and write.
    865790    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    866     ///Instantiates a \ref ProcessedMap.
     791    ///Instantiates a ProcessedMap.
    867792
    868793    ///This function instantiates a \ref ProcessedMap.
    869794    ///\param g is the digraph, to which
    870     ///we would like to define the \ref ProcessedMap.
     795    ///we would like to define the \ref ProcessedMap
    871796#ifdef DOXYGEN
    872     static ProcessedMap *createProcessedMap(const Digraph &g)
     797    static ProcessedMap *createProcessedMap(const GR &g)
    873798#else
    874     static ProcessedMap *createProcessedMap(const Digraph &)
     799    static ProcessedMap *createProcessedMap(const GR &)
    875800#endif
    876801    {
    877802      return new ProcessedMap();
    878803    }
    879 
    880804    ///The type of the map that indicates which nodes are reached.
    881805
    882806    ///The type of the map that indicates which nodes are reached.
    883     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     807    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     808    ///\todo named parameter to set this type, function to read and write.
    884809    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    885     ///Instantiates a \ref ReachedMap.
     810    ///Instantiates a ReachedMap.
    886811
    887812    ///This function instantiates a \ref ReachedMap.
    888     ///\param g is the digraph, to which
     813    ///\param G is the digraph, to which
    889814    ///we would like to define the \ref ReachedMap.
    890     static ReachedMap *createReachedMap(const Digraph &g)
    891     {
    892       return new ReachedMap(g);
    893     }
    894 
    895     ///The type of the map that stores the distances of the nodes.
    896 
    897     ///The type of the map that stores the distances of the nodes.
     815    static ReachedMap *createReachedMap(const GR &G)
     816    {
     817      return new ReachedMap(G);
     818    }
     819    ///The type of the map that stores the dists of the nodes.
     820
     821    ///The type of the map that stores the dists of the nodes.
    898822    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    899823    ///
    900824    typedef NullMap<typename Digraph::Node,int> DistMap;
    901     ///Instantiates a \ref DistMap.
     825    ///Instantiates a DistMap.
    902826
    903827    ///This function instantiates a \ref DistMap.
     
    905829    ///the \ref DistMap
    906830#ifdef DOXYGEN
    907     static DistMap *createDistMap(const Digraph &g)
     831    static DistMap *createDistMap(const GR &g)
    908832#else
    909     static DistMap *createDistMap(const Digraph &)
     833    static DistMap *createDistMap(const GR &)
    910834#endif
    911835    {
     
    914838  };
    915839
    916   /// Default traits class used by \ref BfsWizard
     840  /// Default traits used by \ref BfsWizard
    917841
    918842  /// To make it easier to use Bfs algorithm
    919   /// we have created a wizard class.
     843  ///we have created a wizard class.
    920844  /// This \ref BfsWizard class needs default traits,
    921   /// as well as the \ref Bfs class.
     845  ///as well as the \ref Bfs class.
    922846  /// The \ref BfsWizardBase is a class to be the default traits of the
    923847  /// \ref BfsWizard class.
     
    928852    typedef BfsWizardDefaultTraits<GR> Base;
    929853  protected:
    930     //The type of the nodes in the digraph.
     854    /// Type of the nodes in the digraph.
    931855    typedef typename Base::Digraph::Node Node;
    932856
    933     //Pointer to the digraph the algorithm runs on.
     857    /// Pointer to the underlying digraph.
    934858    void *_g;
    935     //Pointer to the map of reached nodes.
     859    ///Pointer to the map of reached nodes.
    936860    void *_reached;
    937     //Pointer to the map of processed nodes.
     861    ///Pointer to the map of processed nodes.
    938862    void *_processed;
    939     //Pointer to the map of predecessors arcs.
     863    ///Pointer to the map of predecessors arcs.
    940864    void *_pred;
    941     //Pointer to the map of distances.
     865    ///Pointer to the map of distances.
    942866    void *_dist;
    943     //Pointer to the source node.
     867    ///Pointer to the source node.
    944868    Node _source;
    945869
     
    950874    /// all of the attributes to default values (0, INVALID).
    951875    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    952                       _dist(0), _source(INVALID) {}
     876                           _dist(0), _source(INVALID) {}
    953877
    954878    /// Constructor.
     
    957881    /// listed in the parameters list.
    958882    /// Others are initiated to 0.
    959     /// \param g The digraph the algorithm runs on.
    960     /// \param s The source node.
     883    /// \param g is the initial value of  \ref _g
     884    /// \param s is the initial value of  \ref _source
    961885    BfsWizardBase(const GR &g, Node s=INVALID) :
    962886      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
     
    965889  };
    966890
    967   /// Auxiliary class for the function type interface of BFS algorithm.
    968 
    969   /// This auxiliary class is created to implement the function type
    970   /// interface of \ref Bfs algorithm. It uses the functions and features
    971   /// of the plain \ref Bfs, but it is much simpler to use it.
    972   /// It should only be used through the \ref bfs() function, which makes
    973   /// it easier to use the algorithm.
     891  /// A class to make the usage of Bfs algorithm easier
     892
     893  /// This class is created to make it easier to use Bfs algorithm.
     894  /// It uses the functions and features of the plain \ref Bfs,
     895  /// but it is much simpler to use it.
    974896  ///
    975897  /// Simplicity means that the way to change the types defined
     
    980902  /// the original class by using the ::
    981903  /// operator. In the case of \ref BfsWizard only
    982   /// a function have to be called, and it will
     904  /// a function have to be called and it will
    983905  /// return the needed class.
    984906  ///
    985   /// It does not have own \ref run() method. When its \ref run() method
    986   /// is called, it initiates a plain \ref Bfs object, and calls the
    987   /// \ref Bfs::run() method of it.
     907  /// It does not have own \ref run method. When its \ref run method is called
     908  /// it initiates a plain \ref Bfs class, and calls the \ref Bfs::run
     909  /// method of it.
    988910  template<class TR>
    989911  class BfsWizard : public TR
     
    991913    typedef TR Base;
    992914
    993     ///The type of the digraph the algorithm runs on.
     915    ///The type of the underlying digraph.
    994916    typedef typename TR::Digraph Digraph;
    995 
     917    //\e
    996918    typedef typename Digraph::Node Node;
     919    //\e
    997920    typedef typename Digraph::NodeIt NodeIt;
     921    //\e
    998922    typedef typename Digraph::Arc Arc;
     923    //\e
    999924    typedef typename Digraph::OutArcIt OutArcIt;
    1000925
    1001     ///\brief The type of the map that stores the predecessor
     926    ///\brief The type of the map that stores
     927    ///the reached nodes
     928    typedef typename TR::ReachedMap ReachedMap;
     929    ///\brief The type of the map that stores
     930    ///the processed nodes
     931    typedef typename TR::ProcessedMap ProcessedMap;
     932    ///\brief The type of the map that stores the last
    1002933    ///arcs of the shortest paths.
    1003934    typedef typename TR::PredMap PredMap;
    1004     ///\brief The type of the map that stores the distances of the nodes.
     935    ///The type of the map that stores the dists of the nodes.
    1005936    typedef typename TR::DistMap DistMap;
    1006     ///\brief The type of the map that indicates which nodes are reached.
    1007     typedef typename TR::ReachedMap ReachedMap;
    1008     ///\brief The type of the map that indicates which nodes are processed.
    1009     typedef typename TR::ProcessedMap ProcessedMap;
    1010937
    1011938  public:
    1012 
    1013939    /// Constructor.
    1014940    BfsWizard() : TR() {}
     
    1026952    ~BfsWizard() {}
    1027953
    1028     ///Runs BFS algorithm from a source node.
    1029 
    1030     ///Runs BFS algorithm from a source node.
    1031     ///The node can be given with the \ref source() function.
     954    ///Runs Bfs algorithm from a given node.
     955
     956    ///Runs Bfs algorithm from a given node.
     957    ///The node can be given by the \ref source function.
    1032958    void run()
    1033959    {
     
    1045971    }
    1046972
    1047     ///Runs BFS algorithm from the given node.
    1048 
    1049     ///Runs BFS algorithm from the given node.
     973    ///Runs Bfs algorithm from the given node.
     974
     975    ///Runs Bfs algorithm from the given node.
    1050976    ///\param s is the given source.
    1051977    void run(Node s)
     
    1053979      Base::_source=s;
    1054980      run();
    1055     }
    1056 
    1057     /// Sets the source node, from which the Bfs algorithm runs.
    1058 
    1059     /// Sets the source node, from which the Bfs algorithm runs.
    1060     /// \param s is the source node.
    1061     BfsWizard<TR> &source(Node s)
    1062     {
    1063       Base::_source=s;
    1064       return *this;
    1065981    }
    1066982
     
    1071987      DefPredMapBase(const TR &b) : TR(b) {}
    1072988    };
     989
    1073990    ///\brief \ref named-templ-param "Named parameter"
    1074     ///for setting \ref PredMap object.
     991    ///function for setting PredMap
    1075992    ///
    1076993    /// \ref named-templ-param "Named parameter"
    1077     ///for setting \ref PredMap object.
     994    ///function for setting PredMap
     995    ///
    1078996    template<class T>
    1079997    BfsWizard<DefPredMapBase<T> > predMap(const T &t)
     
    10821000      return BfsWizard<DefPredMapBase<T> >(*this);
    10831001    }
     1002
    10841003
    10851004    template<class T>
     
    10891008      DefReachedMapBase(const TR &b) : TR(b) {}
    10901009    };
     1010
    10911011    ///\brief \ref named-templ-param "Named parameter"
    1092     ///for setting \ref ReachedMap object.
     1012    ///function for setting ReachedMap
    10931013    ///
    10941014    /// \ref named-templ-param "Named parameter"
    1095     ///for setting \ref ReachedMap object.
     1015    ///function for setting ReachedMap
     1016    ///
    10961017    template<class T>
    10971018    BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
     
    11001021      return BfsWizard<DefReachedMapBase<T> >(*this);
    11011022    }
     1023
    11021024
    11031025    template<class T>
     
    11071029      DefProcessedMapBase(const TR &b) : TR(b) {}
    11081030    };
     1031
    11091032    ///\brief \ref named-templ-param "Named parameter"
    1110     ///for setting \ref ProcessedMap object.
     1033    ///function for setting ProcessedMap
    11111034    ///
    11121035    /// \ref named-templ-param "Named parameter"
    1113     ///for setting \ref ProcessedMap object.
     1036    ///function for setting ProcessedMap
     1037    ///
    11141038    template<class T>
    11151039    BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
     
    11181042      return BfsWizard<DefProcessedMapBase<T> >(*this);
    11191043    }
     1044
    11201045
    11211046    template<class T>
     
    11251050      DefDistMapBase(const TR &b) : TR(b) {}
    11261051    };
     1052
    11271053    ///\brief \ref named-templ-param "Named parameter"
    1128     ///for setting \ref DistMap object.
     1054    ///function for setting DistMap type
    11291055    ///
    11301056    /// \ref named-templ-param "Named parameter"
    1131     ///for setting \ref DistMap object.
     1057    ///function for setting DistMap type
     1058    ///
    11321059    template<class T>
    11331060    BfsWizard<DefDistMapBase<T> > distMap(const T &t)
     
    11351062      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    11361063      return BfsWizard<DefDistMapBase<T> >(*this);
     1064    }
     1065
     1066    /// Sets the source node, from which the Bfs algorithm runs.
     1067
     1068    /// Sets the source node, from which the Bfs algorithm runs.
     1069    /// \param s is the source node.
     1070    BfsWizard<TR> &source(Node s)
     1071    {
     1072      Base::_source=s;
     1073      return *this;
    11371074    }
    11381075
     
    11641101
    11651102#ifdef DOXYGEN
    1166   /// \brief Visitor class for BFS.
     1103  /// \brief Visitor class for bfs.
    11671104  ///
    11681105  /// This class defines the interface of the BfsVisit events, and
    1169   /// it could be the base of a real visitor class.
     1106  /// it could be the base of a real Visitor class.
    11701107  template <typename _Digraph>
    11711108  struct BfsVisitor {
     
    11731110    typedef typename Digraph::Arc Arc;
    11741111    typedef typename Digraph::Node Node;
    1175     /// \brief Called for the source node(s) of the BFS.
    1176     ///
    1177     /// This function is called for the source node(s) of the BFS.
    1178     void start(const Node& node) {}
    1179     /// \brief Called when a node is reached first time.
    1180     ///
    1181     /// This function is called when a node is reached first time.
     1112    /// \brief Called when the arc reach a node.
     1113    ///
     1114    /// It is called when the bfs find an arc which target is not
     1115    /// reached yet.
     1116    void discover(const Arc& arc) {}
     1117    /// \brief Called when the node reached first time.
     1118    ///
     1119    /// It is Called when the node reached first time.
    11821120    void reach(const Node& node) {}
    1183     /// \brief Called when a node is processed.
    1184     ///
    1185     /// This function is called when a node is processed.
    1186     void process(const Node& node) {}
    1187     /// \brief Called when an arc reaches a new node.
    1188     ///
    1189     /// This function is called when the BFS finds an arc whose target node
    1190     /// is not reached yet.
    1191     void discover(const Arc& arc) {}
    1192     /// \brief Called when an arc is examined but its target node is
     1121    /// \brief Called when the arc examined but target of the arc
    11931122    /// already discovered.
    11941123    ///
    1195     /// This function is called when an arc is examined but its target node is
     1124    /// It called when the arc examined but the target of the arc
    11961125    /// already discovered.
    11971126    void examine(const Arc& arc) {}
     1127    /// \brief Called for the source node of the bfs.
     1128    ///
     1129    /// It is called for the source node of the bfs.
     1130    void start(const Node& node) {}
     1131    /// \brief Called when the node processed.
     1132    ///
     1133    /// It is Called when the node processed.
     1134    void process(const Node& node) {}
    11981135  };
    11991136#else
     
    12031140    typedef typename Digraph::Arc Arc;
    12041141    typedef typename Digraph::Node Node;
     1142    void discover(const Arc&) {}
     1143    void reach(const Node&) {}
     1144    void examine(const Arc&) {}
    12051145    void start(const Node&) {}
    1206     void reach(const Node&) {}
    12071146    void process(const Node&) {}
    1208     void discover(const Arc&) {}
    1209     void examine(const Arc&) {}
    12101147
    12111148    template <typename _Visitor>
     
    12141151        Arc arc;
    12151152        Node node;
     1153        visitor.discover(arc);
     1154        visitor.reach(node);
     1155        visitor.examine(arc);
    12161156        visitor.start(node);
    1217         visitor.reach(node);
    12181157        visitor.process(node);
    1219         visitor.discover(arc);
    1220         visitor.examine(arc);
    12211158      }
    12221159      _Visitor& visitor;
     
    12281165  ///
    12291166  /// Default traits class of BfsVisit class.
    1230   /// \tparam _Digraph The type of the digraph the algorithm runs on.
     1167  /// \tparam _Digraph Digraph type.
    12311168  template<class _Digraph>
    12321169  struct BfsVisitDefaultTraits {
    12331170
    1234     /// \brief The type of the digraph the algorithm runs on.
     1171    /// \brief The digraph type the algorithm runs on.
    12351172    typedef _Digraph Digraph;
    12361173
     
    12381175    ///
    12391176    /// The type of the map that indicates which nodes are reached.
    1240     /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     1177    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
     1178    /// \todo named parameter to set this type, function to read and write.
    12411179    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    12421180
    1243     /// \brief Instantiates a \ref ReachedMap.
     1181    /// \brief Instantiates a ReachedMap.
    12441182    ///
    12451183    /// This function instantiates a \ref ReachedMap.
     
    12541192  /// \ingroup search
    12551193  ///
    1256   /// \brief %BFS algorithm class with visitor interface.
     1194  /// \brief %BFS Visit algorithm class.
    12571195  ///
    12581196  /// This class provides an efficient implementation of the %BFS algorithm
     
    12611199  /// The %BfsVisit class provides an alternative interface to the Bfs
    12621200  /// class. It works with callback mechanism, the BfsVisit object calls
    1263   /// the member functions of the \c Visitor class on every BFS event.
     1201  /// on every bfs event the \c Visitor class member functions.
    12641202  ///
    1265   /// \tparam _Digraph The type of the digraph the algorithm runs on.
     1203  /// \tparam _Digraph The digraph type the algorithm runs on.
    12661204  /// The default value is
    1267   /// \ref ListDigraph. The value of _Digraph is not used directly by
    1268   /// \ref BfsVisit, it is only passed to \ref BfsVisitDefaultTraits.
    1269   /// \tparam _Visitor The Visitor type that is used by the algorithm.
    1270   /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty visitor, which
    1271   /// does not observe the BFS events. If you want to observe the BFS
    1272   /// events, you should implement your own visitor class.
     1205  /// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it
     1206  /// is only passed to \ref BfsDefaultTraits.
     1207  /// \tparam _Visitor The Visitor object for the algorithm. The
     1208  /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which
     1209  /// does not observe the Bfs events. If you want to observe the bfs
     1210  /// events you should implement your own Visitor class.
    12731211  /// \tparam _Traits Traits class to set various data types used by the
    12741212  /// algorithm. The default traits class is
    12751213  /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>".
    12761214  /// See \ref BfsVisitDefaultTraits for the documentation of
    1277   /// a BFS visit traits class.
     1215  /// a Bfs visit traits class.
    12781216#ifdef DOXYGEN
    12791217  template <typename _Digraph, typename _Visitor, typename _Traits>
     
    12891227    ///
    12901228    /// This error represents problems in the initialization
    1291     /// of the parameters of the algorithm.
     1229    /// of the parameters of the algorithms.
    12921230    class UninitializedParameter : public lemon::UninitializedParameter {
    12931231    public:
     
    12981236    };
    12991237
    1300     ///The traits class.
    13011238    typedef _Traits Traits;
    13021239
    1303     ///The type of the digraph the algorithm runs on.
    13041240    typedef typename Traits::Digraph Digraph;
    13051241
    1306     ///The visitor type used by the algorithm.
    13071242    typedef _Visitor Visitor;
    13081243
    1309     ///The type of the map that indicates which nodes are reached.
     1244    ///The type of the map indicating which nodes are reached.
    13101245    typedef typename Traits::ReachedMap ReachedMap;
    13111246
     
    13171252    typedef typename Digraph::OutArcIt OutArcIt;
    13181253
    1319     //Pointer to the underlying digraph.
     1254    /// Pointer to the underlying digraph.
    13201255    const Digraph *_digraph;
    1321     //Pointer to the visitor object.
     1256    /// Pointer to the visitor object.
    13221257    Visitor *_visitor;
    1323     //Pointer to the map of reached status of the nodes.
     1258    ///Pointer to the map of reached status of the nodes.
    13241259    ReachedMap *_reached;
    1325     //Indicates if _reached is locally allocated (true) or not.
     1260    ///Indicates if \ref _reached is locally allocated (\c true) or not.
    13261261    bool local_reached;
    13271262
     
    13291264    int _list_front, _list_back;
    13301265
    1331     ///Creates the maps if necessary.
    1332     ///\todo Better memory allocation (instead of new).
     1266    /// \brief Creates the maps if necessary.
     1267    ///
     1268    /// Creates the maps if necessary.
    13331269    void create_maps() {
    13341270      if(!_reached) {
     
    13571293    };
    13581294    /// \brief \ref named-templ-param "Named parameter" for setting
    1359     /// ReachedMap type.
    1360     ///
    1361     /// \ref named-templ-param "Named parameter" for setting ReachedMap type.
     1295    /// ReachedMap type
     1296    ///
     1297    /// \ref named-templ-param "Named parameter" for setting ReachedMap type
    13621298    template <class T>
    13631299    struct DefReachedMap : public BfsVisit< Digraph, Visitor,
     
    13731309    /// Constructor.
    13741310    ///
    1375     /// \param digraph The digraph the algorithm runs on.
    1376     /// \param visitor The visitor object of the algorithm.
     1311    /// \param digraph the digraph the algorithm will run on.
     1312    /// \param visitor The visitor of the algorithm.
     1313    ///
    13771314    BfsVisit(const Digraph& digraph, Visitor& visitor)
    13781315      : _digraph(&digraph), _visitor(&visitor),
     
    13801317
    13811318    /// \brief Destructor.
     1319    ///
     1320    /// Destructor.
    13821321    ~BfsVisit() {
    13831322      if(local_reached) delete _reached;
    13841323    }
    13851324
    1386     /// \brief Sets the map that indicates which nodes are reached.
    1387     ///
    1388     /// Sets the map that indicates which nodes are reached.
     1325    /// \brief Sets the map indicating if a node is reached.
     1326    ///
     1327    /// Sets the map indicating if a node is reached.
    13891328    /// If you don't use this function before calling \ref run(),
    1390     /// it will allocate one. The destructor deallocates this
     1329    /// it will allocate one. The destuctor deallocates this
    13911330    /// automatically allocated map, of course.
    13921331    /// \return <tt> (*this) </tt>
     
    14011340
    14021341  public:
    1403 
    14041342    /// \name Execution control
    14051343    /// The simplest way to execute the algorithm is to use
    1406     /// one of the member functions called \ref lemon::BfsVisit::run()
    1407     /// "run()".
     1344    /// one of the member functions called \c run(...).
    14081345    /// \n
    1409     /// If you need more control on the execution, first you must call
    1410     /// \ref lemon::BfsVisit::init() "init()", then you can add several
    1411     /// source nodes with \ref lemon::BfsVisit::addSource() "addSource()".
    1412     /// Finally \ref lemon::BfsVisit::start() "start()" will perform the
    1413     /// actual path computation.
     1346    /// If you need more control on the execution,
     1347    /// first you must call \ref init(), then you can adda source node
     1348    /// with \ref addSource().
     1349    /// Finally \ref start() will perform the actual path
     1350    /// computation.
    14141351
    14151352    /// @{
    1416 
    14171353    /// \brief Initializes the internal data structures.
    14181354    ///
    14191355    /// Initializes the internal data structures.
     1356    ///
    14201357    void init() {
    14211358      create_maps();
     
    14451382    /// \return The processed node.
    14461383    ///
    1447     /// \pre The queue must not be empty.
     1384    /// \pre The queue must not be empty!
    14481385    Node processNextNode() {
    14491386      Node n = _list[++_list_front];
     
    14661403    /// \brief Processes the next node.
    14671404    ///
    1468     /// Processes the next node and checks if the given target node
     1405    /// Processes the next node. And checks that the given target node
    14691406    /// is reached. If the target node is reachable from the processed
    1470     /// node, then the \c reach parameter will be set to \c true.
     1407    /// node then the reached parameter will be set true. The reached
     1408    /// parameter should be initially false.
    14711409    ///
    14721410    /// \param target The target node.
    1473     /// \retval reach Indicates if the target node is reached.
    1474     /// It should be initially \c false.
    1475     ///
     1411    /// \retval reach Indicates that the target node is reached.
    14761412    /// \return The processed node.
    14771413    ///
    1478     /// \pre The queue must not be empty.
     1414    /// \warning The queue must not be empty!
    14791415    Node processNextNode(Node target, bool& reach) {
    14801416      Node n = _list[++_list_front];
     
    14981434    /// \brief Processes the next node.
    14991435    ///
    1500     /// Processes the next node and checks if at least one of reached
    1501     /// nodes has \c true value in the \c nm node map. If one node
    1502     /// with \c true value is reachable from the processed node, then the
    1503     /// \c rnode parameter will be set to the first of such nodes.
    1504     ///
    1505     /// \param nm A \c bool (or convertible) node map that indicates the
    1506     /// possible targets.
     1436    /// Processes the next node. And checks that at least one of
     1437    /// reached node has true value in the \c nm node map. If one node
     1438    /// with true value is reachable from the processed node then the
     1439    /// rnode parameter will be set to the first of such nodes.
     1440    ///
     1441    /// \param nm The node map of possible targets.
    15071442    /// \retval rnode The reached target node.
    1508     /// It should be initially \c INVALID.
    1509     ///
    15101443    /// \return The processed node.
    15111444    ///
    1512     /// \pre The queue must not be empty.
     1445    /// \warning The queue must not be empty!
    15131446    template <typename NM>
    15141447    Node processNextNode(const NM& nm, Node& rnode) {
     
    15311464    }
    15321465
    1533     /// \brief The next node to be processed.
    1534     ///
    1535     /// Returns the next node to be processed or \c INVALID if the queue
    1536     /// is empty.
    1537     Node nextNode() const {
     1466    /// \brief Next node to be processed.
     1467    ///
     1468    /// Next node to be processed.
     1469    ///
     1470    /// \return The next node to be processed or INVALID if the stack is
     1471    /// empty.
     1472    Node nextNode() {
    15381473      return _list_front != _list_back ? _list[_list_front + 1] : INVALID;
    15391474    }
    15401475
    15411476    /// \brief Returns \c false if there are nodes
    1542     /// to be processed.
     1477    /// to be processed in the queue
    15431478    ///
    15441479    /// Returns \c false if there are nodes
    1545     /// to be processed in the queue.
    1546     bool emptyQueue() const { return _list_front == _list_back; }
     1480    /// to be processed in the queue
     1481    bool emptyQueue() { return _list_front == _list_back; }
    15471482
    15481483    /// \brief Returns the number of the nodes to be processed.
    15491484    ///
    15501485    /// Returns the number of the nodes to be processed in the queue.
    1551     int queueSize() const { return _list_back - _list_front; }
     1486    int queueSize() { return _list_back - _list_front; }
    15521487
    15531488    /// \brief Executes the algorithm.
     
    15551490    /// Executes the algorithm.
    15561491    ///
    1557     /// This method runs the %BFS algorithm from the root node(s)
    1558     /// in order to compute the shortest path to each node.
    1559     ///
    1560     /// The algorithm computes
    1561     /// - the shortest path tree (forest),
    1562     /// - the distance of each node from the root(s).
    1563     ///
    1564     /// \pre init() must be called and at least one root node should be added
     1492    /// \pre init() must be called and at least one node should be added
    15651493    /// with addSource() before using this function.
    1566     ///
    1567     /// \note <tt>b.start()</tt> is just a shortcut of the following code.
    1568     /// \code
    1569     ///   while ( !b.emptyQueue() ) {
    1570     ///     b.processNextNode();
    1571     ///   }
    1572     /// \endcode
    15731494    void start() {
    15741495      while ( !emptyQueue() ) processNextNode();
    15751496    }
    15761497
    1577     /// \brief Executes the algorithm until the given target node is reached.
    1578     ///
    1579     /// Executes the algorithm until the given target node is reached.
    1580     ///
    1581     /// This method runs the %BFS algorithm from the root node(s)
    1582     /// in order to compute the shortest path to \c dest.
    1583     ///
    1584     /// The algorithm computes
    1585     /// - the shortest path to \c dest,
    1586     /// - the distance of \c dest from the root(s).
    1587     ///
    1588     /// \pre init() must be called and at least one root node should be
    1589     /// added with addSource() before using this function.
    1590     ///
    1591     /// \note <tt>b.start(t)</tt> is just a shortcut of the following code.
    1592     /// \code
    1593     ///   bool reach = false;
    1594     ///   while ( !b.emptyQueue() && !reach ) {
    1595     ///     b.processNextNode(t, reach);
    1596     ///   }
    1597     /// \endcode
     1498    /// \brief Executes the algorithm until \c dest is reached.
     1499    ///
     1500    /// Executes the algorithm until \c dest is reached.
     1501    ///
     1502    /// \pre init() must be called and at least one node should be added
     1503    /// with addSource() before using this function.
    15981504    void start(Node dest) {
    15991505      bool reach = false;
     
    16051511    /// Executes the algorithm until a condition is met.
    16061512    ///
    1607     /// This method runs the %BFS algorithm from the root node(s) in
    1608     /// order to compute the shortest path to a node \c v with
    1609     /// <tt>nm[v]</tt> true, if such a node can be found.
    1610     ///
    1611     /// \param nm must be a bool (or convertible) node map. The
    1612     /// algorithm will stop when it reaches a node \c v with
     1513    /// \pre init() must be called and at least one node should be added
     1514    /// with addSource() before using this function.
     1515    ///
     1516    ///\param nm must be a bool (or convertible) node map. The
     1517    ///algorithm will stop when it reaches a node \c v with
    16131518    /// <tt>nm[v]</tt> true.
    16141519    ///
    1615     /// \return The reached node \c v with <tt>nm[v]</tt> true or
    1616     /// \c INVALID if no such node was found.
    1617     ///
    1618     /// \pre init() must be called and at least one root node should be
    1619     /// added with addSource() before using this function.
    1620     ///
    1621     /// \note <tt>b.start(nm)</tt> is just a shortcut of the following code.
    1622     /// \code
    1623     ///   Node rnode = INVALID;
    1624     ///   while ( !b.emptyQueue() && rnode == INVALID ) {
    1625     ///     b.processNextNode(nm, rnode);
    1626     ///   }
    1627     ///   return rnode;
    1628     /// \endcode
     1520    ///\return The reached node \c v with <tt>nm[v]</tt> true or
     1521    ///\c INVALID if no such node was found.
    16291522    template <typename NM>
    16301523    Node start(const NM &nm) {
     
    16361529    }
    16371530
    1638     /// \brief Runs the algorithm from the given node.
    1639     ///
    1640     /// This method runs the %BFS algorithm from node \c s
    1641     /// in order to compute the shortest path to each node.
    1642     ///
    1643     /// The algorithm computes
    1644     /// - the shortest path tree,
    1645     /// - the distance of each node from the root.
    1646     ///
    1647     /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
     1531    /// \brief Runs %BFSVisit algorithm from node \c s.
     1532    ///
     1533    /// This method runs the %BFS algorithm from a root node \c s.
     1534    /// \note b.run(s) is just a shortcut of the following code.
    16481535    ///\code
    16491536    ///   b.init();
     
    16571544    }
    16581545
    1659     /// \brief Runs the algorithm to visit all nodes in the digraph.
     1546    /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph.
    16601547    ///
    16611548    /// This method runs the %BFS algorithm in order to
    1662     /// compute the shortest path to each node.
    1663     ///
    1664     /// The algorithm computes
    1665     /// - the shortest path tree (forest),
    1666     /// - the distance of each node from the root(s).
    1667     ///
    1668     /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
     1549    /// compute the %BFS path to each node. The algorithm computes
     1550    /// - The %BFS tree.
     1551    /// - The distance of each node from the root in the %BFS tree.
     1552    ///
     1553    ///\note b.run() is just a shortcut of the following code.
    16691554    ///\code
    16701555    ///  b.init();
    1671     ///  for (NodeIt n(gr); n != INVALID; ++n) {
    1672     ///    if (!b.reached(n)) {
    1673     ///      b.addSource(n);
     1556    ///  for (NodeIt it(digraph); it != INVALID; ++it) {
     1557    ///    if (!b.reached(it)) {
     1558    ///      b.addSource(it);
    16741559    ///      b.start();
    16751560    ///    }
     
    16851570      }
    16861571    }
    1687 
    16881572    ///@}
    16891573
     
    16911575    /// The result of the %BFS algorithm can be obtained using these
    16921576    /// functions.\n
    1693     /// Either \ref lemon::BfsVisit::run() "run()" or
    1694     /// \ref lemon::BfsVisit::start() "start()" must be called before
    1695     /// using them.
     1577    /// Before the use of these functions,
     1578    /// either run() or start() must be called.
    16961579    ///@{
    16971580
    1698     /// \brief Checks if a node is reachable from the root(s).
     1581    /// \brief Checks if a node is reachable from the root.
    16991582    ///
    17001583    /// Returns \c true if \c v is reachable from the root(s).
     1584    /// \warning The source nodes are inditated as unreachable.
    17011585    /// \pre Either \ref run() or \ref start()
    17021586    /// must be called before using this function.
     1587    ///
    17031588    bool reached(Node v) { return (*_reached)[v]; }
    1704 
    17051589    ///@}
    1706 
    17071590  };
    17081591
     
    17101593
    17111594#endif
     1595
  • lemon/dfs.h

    r247 r220  
    2222///\ingroup search
    2323///\file
    24 ///\brief DFS algorithm.
     24///\brief Dfs algorithm.
    2525
    2626#include <lemon/list_graph.h>
     
    2828#include <lemon/core.h>
    2929#include <lemon/error.h>
    30 #include <lemon/assert.h>
    3130#include <lemon/maps.h>
    3231
     32#include <lemon/concept_check.h>
     33
    3334namespace lemon {
     35
    3436
    3537  ///Default traits class of Dfs class.
     
    4042  struct DfsDefaultTraits
    4143  {
    42     ///The type of the digraph the algorithm runs on.
     44    ///The digraph type the algorithm runs on.
    4345    typedef GR Digraph;
    44 
    45     ///\brief The type of the map that stores the predecessor
     46    ///\brief The type of the map that stores the last
    4647    ///arcs of the %DFS paths.
    4748    ///
    48     ///The type of the map that stores the predecessor
     49    ///The type of the map that stores the last
    4950    ///arcs of the %DFS paths.
    5051    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    51     typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    52     ///Instantiates a \ref PredMap.
     52    ///
     53    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
     54    ///Instantiates a PredMap.
    5355
    5456    ///This function instantiates a \ref PredMap.
    55     ///\param g is the digraph, to which we would like to define the
    56     ///\ref PredMap.
     57    ///\param G is the digraph, to which we would like to define the PredMap.
    5758    ///\todo The digraph alone may be insufficient to initialize
    58     static PredMap *createPredMap(const Digraph &g)
    59     {
    60       return new PredMap(g);
     59    static PredMap *createPredMap(const GR &G)
     60    {
     61      return new PredMap(G);
    6162    }
    6263
     
    6566    ///The type of the map that indicates which nodes are processed.
    6667    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    67     ///By default it is a NullMap.
     68    ///\todo named parameter to set this type, function to read and write.
    6869    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    69     ///Instantiates a \ref ProcessedMap.
     70    ///Instantiates a ProcessedMap.
    7071
    7172    ///This function instantiates a \ref ProcessedMap.
     
    7374    ///we would like to define the \ref ProcessedMap
    7475#ifdef DOXYGEN
    75     static ProcessedMap *createProcessedMap(const Digraph &g)
     76    static ProcessedMap *createProcessedMap(const GR &g)
    7677#else
    77     static ProcessedMap *createProcessedMap(const Digraph &)
     78    static ProcessedMap *createProcessedMap(const GR &)
    7879#endif
    7980    {
    8081      return new ProcessedMap();
    8182    }
    82 
    8383    ///The type of the map that indicates which nodes are reached.
    8484
    8585    ///The type of the map that indicates which nodes are reached.
    86     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     86    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     87    ///\todo named parameter to set this type, function to read and write.
    8788    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    88     ///Instantiates a \ref ReachedMap.
     89    ///Instantiates a ReachedMap.
    8990
    9091    ///This function instantiates a \ref ReachedMap.
    91     ///\param g is the digraph, to which
     92    ///\param G is the digraph, to which
    9293    ///we would like to define the \ref ReachedMap.
    93     static ReachedMap *createReachedMap(const Digraph &g)
    94     {
    95       return new ReachedMap(g);
    96     }
    97 
    98     ///The type of the map that stores the distances of the nodes.
    99 
    100     ///The type of the map that stores the distances of the nodes.
     94    static ReachedMap *createReachedMap(const GR &G)
     95    {
     96      return new ReachedMap(G);
     97    }
     98    ///The type of the map that stores the dists of the nodes.
     99
     100    ///The type of the map that stores the dists of the nodes.
    101101    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     102    ///
    102103    typedef typename Digraph::template NodeMap<int> DistMap;
    103     ///Instantiates a \ref DistMap.
     104    ///Instantiates a DistMap.
    104105
    105106    ///This function instantiates a \ref DistMap.
    106     ///\param g is the digraph, to which we would like to define the
    107     ///\ref DistMap.
    108     static DistMap *createDistMap(const Digraph &g)
    109     {
    110       return new DistMap(g);
     107    ///\param G is the digraph, to which we would like to define
     108    ///the \ref DistMap
     109    static DistMap *createDistMap(const GR &G)
     110    {
     111      return new DistMap(G);
    111112    }
    112113  };
     
    117118  ///This class provides an efficient implementation of the %DFS algorithm.
    118119  ///
    119   ///There is also a \ref dfs() "function type interface" for the DFS
    120   ///algorithm, which is convenient in the simplier cases and it can be
    121   ///used easier.
    122   ///
    123   ///\tparam GR The type of the digraph the algorithm runs on.
    124   ///The default value is \ref ListDigraph. The value of GR is not used
    125   ///directly by \ref Dfs, it is only passed to \ref DfsDefaultTraits.
     120  ///\tparam GR The digraph type the algorithm runs on. The default value is
     121  ///\ref ListDigraph. The value of GR is not used directly by Dfs, it
     122  ///is only passed to \ref DfsDefaultTraits.
    126123  ///\tparam TR Traits class to set various data types used by the algorithm.
    127124  ///The default traits class is
     
    138135  class Dfs {
    139136  public:
    140     ///\ref Exception for uninitialized parameters.
    141 
    142     ///This error represents problems in the initialization of the
    143     ///parameters of the algorithm.
     137    /**
     138     * \brief \ref Exception for uninitialized parameters.
     139     *
     140     * This error represents problems in the initialization
     141     * of the parameters of the algorithms.
     142     */
    144143    class UninitializedParameter : public lemon::UninitializedParameter {
    145144    public:
     
    149148    };
    150149
    151     ///The type of the digraph the algorithm runs on.
     150    typedef TR Traits;
     151    ///The type of the underlying digraph.
    152152    typedef typename TR::Digraph Digraph;
    153 
    154     ///\brief The type of the map that stores the predecessor arcs of the
    155     ///DFS paths.
     153    ///\e
     154    typedef typename Digraph::Node Node;
     155    ///\e
     156    typedef typename Digraph::NodeIt NodeIt;
     157    ///\e
     158    typedef typename Digraph::Arc Arc;
     159    ///\e
     160    typedef typename Digraph::OutArcIt OutArcIt;
     161
     162    ///\brief The type of the map that stores the last
     163    ///arcs of the %DFS paths.
    156164    typedef typename TR::PredMap PredMap;
    157     ///The type of the map that stores the distances of the nodes.
     165    ///The type of the map indicating which nodes are reached.
     166    typedef typename TR::ReachedMap ReachedMap;
     167    ///The type of the map indicating which nodes are processed.
     168    typedef typename TR::ProcessedMap ProcessedMap;
     169    ///The type of the map that stores the dists of the nodes.
    158170    typedef typename TR::DistMap DistMap;
    159     ///The type of the map that indicates which nodes are reached.
    160     typedef typename TR::ReachedMap ReachedMap;
    161     ///The type of the map that indicates which nodes are processed.
    162     typedef typename TR::ProcessedMap ProcessedMap;
    163     ///The type of the paths.
    164     typedef PredMapPath<Digraph, PredMap> Path;
    165 
    166     ///The traits class.
    167     typedef TR Traits;
    168 
    169171  private:
    170 
    171     typedef typename Digraph::Node Node;
    172     typedef typename Digraph::NodeIt NodeIt;
    173     typedef typename Digraph::Arc Arc;
    174     typedef typename Digraph::OutArcIt OutArcIt;
    175 
    176     //Pointer to the underlying digraph.
     172    /// Pointer to the underlying digraph.
    177173    const Digraph *G;
    178     //Pointer to the map of predecessor arcs.
     174    ///Pointer to the map of predecessors arcs.
    179175    PredMap *_pred;
    180     //Indicates if _pred is locally allocated (true) or not.
     176    ///Indicates if \ref _pred is locally allocated (\c true) or not.
    181177    bool local_pred;
    182     //Pointer to the map of distances.
     178    ///Pointer to the map of distances.
    183179    DistMap *_dist;
    184     //Indicates if _dist is locally allocated (true) or not.
     180    ///Indicates if \ref _dist is locally allocated (\c true) or not.
    185181    bool local_dist;
    186     //Pointer to the map of reached status of the nodes.
     182    ///Pointer to the map of reached status of the nodes.
    187183    ReachedMap *_reached;
    188     //Indicates if _reached is locally allocated (true) or not.
     184    ///Indicates if \ref _reached is locally allocated (\c true) or not.
    189185    bool local_reached;
    190     //Pointer to the map of processed status of the nodes.
     186    ///Pointer to the map of processed status of the nodes.
    191187    ProcessedMap *_processed;
    192     //Indicates if _processed is locally allocated (true) or not.
     188    ///Indicates if \ref _processed is locally allocated (\c true) or not.
    193189    bool local_processed;
    194190
     
    197193
    198194    ///Creates the maps if necessary.
     195
    199196    ///\todo Better memory allocation (instead of new).
    200197    void create_maps()
     
    233230    struct DefPredMapTraits : public Traits {
    234231      typedef T PredMap;
    235       static PredMap *createPredMap(const Digraph &)
     232      static PredMap *createPredMap(const Digraph &G)
    236233      {
    237234        throw UninitializedParameter();
     
    239236    };
    240237    ///\brief \ref named-templ-param "Named parameter" for setting
    241     ///\ref PredMap type.
    242     ///
    243     ///\ref named-templ-param "Named parameter" for setting
    244     ///\ref PredMap type.
     238    ///PredMap type
     239    ///
     240    ///\ref named-templ-param "Named parameter" for setting PredMap type
     241    ///
    245242    template <class T>
    246243    struct DefPredMap : public Dfs<Digraph, DefPredMapTraits<T> > {
    247244      typedef Dfs<Digraph, DefPredMapTraits<T> > Create;
    248245    };
     246
    249247
    250248    template <class T>
     
    257255    };
    258256    ///\brief \ref named-templ-param "Named parameter" for setting
    259     ///\ref DistMap type.
    260     ///
    261     ///\ref named-templ-param "Named parameter" for setting
    262     ///\ref DistMap type.
     257    ///DistMap type
     258    ///
     259    ///\ref named-templ-param "Named parameter" for setting DistMap
     260    ///type
    263261    template <class T>
    264     struct DefDistMap : public Dfs< Digraph, DefDistMapTraits<T> > {
     262    struct DefDistMap {
    265263      typedef Dfs<Digraph, DefDistMapTraits<T> > Create;
    266264    };
     
    275273    };
    276274    ///\brief \ref named-templ-param "Named parameter" for setting
    277     ///\ref ReachedMap type.
    278     ///
    279     ///\ref named-templ-param "Named parameter" for setting
    280     ///\ref ReachedMap type.
     275    ///ReachedMap type
     276    ///
     277    ///\ref named-templ-param "Named parameter" for setting ReachedMap type
     278    ///
    281279    template <class T>
    282280    struct DefReachedMap : public Dfs< Digraph, DefReachedMapTraits<T> > {
     
    293291    };
    294292    ///\brief \ref named-templ-param "Named parameter" for setting
    295     ///\ref ProcessedMap type.
    296     ///
    297     ///\ref named-templ-param "Named parameter" for setting
    298     ///\ref ProcessedMap type.
     293    ///ProcessedMap type
     294    ///
     295    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
     296    ///
    299297    template <class T>
    300298    struct DefProcessedMap : public Dfs< Digraph, DefProcessedMapTraits<T> > {
     
    304302    struct DefDigraphProcessedMapTraits : public Traits {
    305303      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    306       static ProcessedMap *createProcessedMap(const Digraph &g)
     304      static ProcessedMap *createProcessedMap(const Digraph &G)
    307305      {
    308         return new ProcessedMap(g);
    309       }
    310     };
    311     ///\brief \ref named-templ-param "Named parameter" for setting
    312     ///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
    313     ///
    314     ///\ref named-templ-param "Named parameter" for setting
    315     ///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
    316     ///If you don't set it explicitly, it will be automatically allocated.
     306        return new ProcessedMap(G);
     307      }
     308    };
     309    ///\brief \ref named-templ-param "Named parameter"
     310    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
     311    ///
     312    ///\ref named-templ-param "Named parameter"
     313    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
     314    ///If you don't set it explicitely, it will be automatically allocated.
    317315    template <class T>
    318     struct DefProcessedMapToBeDefaultMap :
     316    class DefProcessedMapToBeDefaultMap :
    319317      public Dfs< Digraph, DefDigraphProcessedMapTraits> {
    320318      typedef Dfs< Digraph, DefDigraphProcessedMapTraits> Create;
     
    327325    ///Constructor.
    328326
    329     ///Constructor.
    330     ///\param g The digraph the algorithm runs on.
    331     Dfs(const Digraph &g) :
    332       G(&g),
     327    ///\param _G the digraph the algorithm will run on.
     328    ///
     329    Dfs(const Digraph& _G) :
     330      G(&_G),
    333331      _pred(NULL), local_pred(false),
    334332      _dist(NULL), local_dist(false),
     
    346344    }
    347345
    348     ///Sets the map that stores the predecessor arcs.
    349 
    350     ///Sets the map that stores the predecessor arcs.
     346    ///Sets the map storing the predecessor arcs.
     347
     348    ///Sets the map storing the predecessor arcs.
    351349    ///If you don't use this function before calling \ref run(),
    352     ///it will allocate one. The destructor deallocates this
     350    ///it will allocate one. The destuctor deallocates this
    353351    ///automatically allocated map, of course.
    354352    ///\return <tt> (*this) </tt>
     
    363361    }
    364362
    365     ///Sets the map that indicates which nodes are reached.
    366 
    367     ///Sets the map that indicates which nodes are reached.
     363    ///Sets the map storing the distances calculated by the algorithm.
     364
     365    ///Sets the map storing the distances calculated by the algorithm.
    368366    ///If you don't use this function before calling \ref run(),
    369     ///it will allocate one. The destructor deallocates this
     367    ///it will allocate one. The destuctor deallocates this
     368    ///automatically allocated map, of course.
     369    ///\return <tt> (*this) </tt>
     370    Dfs &distMap(DistMap &m)
     371    {
     372      if(local_dist) {
     373        delete _dist;
     374        local_dist=false;
     375      }
     376      _dist = &m;
     377      return *this;
     378    }
     379
     380    ///Sets the map indicating if a node is reached.
     381
     382    ///Sets the map indicating if a node is reached.
     383    ///If you don't use this function before calling \ref run(),
     384    ///it will allocate one. The destuctor deallocates this
    370385    ///automatically allocated map, of course.
    371386    ///\return <tt> (*this) </tt>
     
    380395    }
    381396
    382     ///Sets the map that indicates which nodes are processed.
    383 
    384     ///Sets the map that indicates which nodes are processed.
     397    ///Sets the map indicating if a node is processed.
     398
     399    ///Sets the map indicating if a node is processed.
    385400    ///If you don't use this function before calling \ref run(),
    386     ///it will allocate one. The destructor deallocates this
     401    ///it will allocate one. The destuctor deallocates this
    387402    ///automatically allocated map, of course.
    388403    ///\return <tt> (*this) </tt>
     
    397412    }
    398413
    399     ///Sets the map that stores the distances of the nodes.
    400 
    401     ///Sets the map that stores the distances of the nodes calculated by
    402     ///the algorithm.
    403     ///If you don't use this function before calling \ref run(),
    404     ///it will allocate one. The destructor deallocates this
    405     ///automatically allocated map, of course.
    406     ///\return <tt> (*this) </tt>
    407     Dfs &distMap(DistMap &m)
    408     {
    409       if(local_dist) {
    410         delete _dist;
    411         local_dist=false;
    412       }
    413       _dist = &m;
    414       return *this;
    415     }
    416 
    417414  public:
    418 
    419415    ///\name Execution control
    420416    ///The simplest way to execute the algorithm is to use
    421     ///one of the member functions called \ref lemon::Dfs::run() "run()".
     417    ///one of the member functions called \c run(...).
    422418    ///\n
    423     ///If you need more control on the execution, first you must call
    424     ///\ref lemon::Dfs::init() "init()", then you can add a source node
    425     ///with \ref lemon::Dfs::addSource() "addSource()".
    426     ///Finally \ref lemon::Dfs::start() "start()" will perform the
    427     ///actual path computation.
     419    ///If you need more control on the execution,
     420    ///first you must call \ref init(), then you can add a source node
     421    ///with \ref addSource().
     422    ///Finally \ref start() will perform the actual path
     423    ///computation.
    428424
    429425    ///@{
     
    440436      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
    441437        _pred->set(u,INVALID);
     438        // _predNode->set(u,INVALID);
    442439        _reached->set(u,false);
    443440        _processed->set(u,false);
     
    449446    ///Adds a new source node to the set of nodes to be processed.
    450447    ///
    451     ///\pre The stack must be empty. (Otherwise the algorithm gives
    452     ///false results.)
    453     ///
    454     ///\warning Distances will be wrong (or at least strange) in case of
    455     ///multiple sources.
     448    ///\warning dists are wrong (or at least strange)
     449    ///in case of multiple sources.
    456450    void addSource(Node s)
    457451    {
    458       LEMON_DEBUG(emptyQueue(), "The stack is not empty.");
    459452      if(!(*_reached)[s])
    460453        {
     
    479472    ///\return The processed arc.
    480473    ///
    481     ///\pre The stack must not be empty.
     474    ///\pre The stack must not be empty!
    482475    Arc processNextArc()
    483476    {
     
    505498      return e;
    506499    }
    507 
    508500    ///Next arc to be processed.
    509501
    510502    ///Next arc to be processed.
    511503    ///
    512     ///\return The next arc to be processed or \c INVALID if the stack
    513     ///is empty.
    514     OutArcIt nextArc() const
     504    ///\return The next arc to be processed or INVALID if the stack is
     505    /// empty.
     506    OutArcIt nextArc()
    515507    {
    516508      return _stack_head>=0?_stack[_stack_head]:INVALID;
     
    518510
    519511    ///\brief Returns \c false if there are nodes
    520     ///to be processed.
     512    ///to be processed in the queue
    521513    ///
    522514    ///Returns \c false if there are nodes
    523     ///to be processed in the queue (stack).
    524     bool emptyQueue() const { return _stack_head<0; }
    525 
     515    ///to be processed in the queue
     516    bool emptyQueue() { return _stack_head<0; }
    526517    ///Returns the number of the nodes to be processed.
    527518
    528     ///Returns the number of the nodes to be processed in the queue (stack).
    529     int queueSize() const { return _stack_head+1; }
     519    ///Returns the number of the nodes to be processed in the queue.
     520    int queueSize() { return _stack_head+1; }
    530521
    531522    ///Executes the algorithm.
     
    533524    ///Executes the algorithm.
    534525    ///
    535     ///This method runs the %DFS algorithm from the root node
    536     ///in order to compute the DFS path to each node.
    537     ///
    538     /// The algorithm computes
    539     ///- the %DFS tree,
    540     ///- the distance of each node from the root in the %DFS tree.
    541     ///
    542     ///\pre init() must be called and a root node should be
    543     ///added with addSource() before using this function.
    544     ///
    545     ///\note <tt>d.start()</tt> is just a shortcut of the following code.
     526    ///\pre init() must be called and at least one node should be added
     527    ///with addSource() before using this function.
     528    ///
     529    ///This method runs the %DFS algorithm from the root node(s)
     530    ///in order to
     531    ///compute the
     532    ///%DFS path to each node. The algorithm computes
     533    ///- The %DFS tree.
     534    ///- The distance of each node from the root(s) in the %DFS tree.
     535    ///
     536    void start()
     537    {
     538      while ( !emptyQueue() ) processNextArc();
     539    }
     540
     541    ///Executes the algorithm until \c dest is reached.
     542
     543    ///Executes the algorithm until \c dest is reached.
     544    ///
     545    ///\pre init() must be called and at least one node should be added
     546    ///with addSource() before using this function.
     547    ///
     548    ///This method runs the %DFS algorithm from the root node(s)
     549    ///in order to
     550    ///compute the
     551    ///%DFS path to \c dest. The algorithm computes
     552    ///- The %DFS path to \c  dest.
     553    ///- The distance of \c dest from the root(s) in the %DFS tree.
     554    ///
     555    void start(Node dest)
     556    {
     557      while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest )
     558        processNextArc();
     559    }
     560
     561    ///Executes the algorithm until a condition is met.
     562
     563    ///Executes the algorithm until a condition is met.
     564    ///
     565    ///\pre init() must be called and at least one node should be added
     566    ///with addSource() before using this function.
     567    ///
     568    ///\param em must be a bool (or convertible) arc map. The algorithm
     569    ///will stop when it reaches an arc \c e with <tt>em[e]</tt> true.
     570    ///
     571    ///\return The reached arc \c e with <tt>em[e]</tt> true or
     572    ///\c INVALID if no such arc was found.
     573    ///
     574    ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an arc map,
     575    ///not a node map.
     576    template<class EM>
     577    Arc start(const EM &em)
     578    {
     579      while ( !emptyQueue() && !em[_stack[_stack_head]] )
     580        processNextArc();
     581      return emptyQueue() ? INVALID : _stack[_stack_head];
     582    }
     583
     584    ///Runs %DFS algorithm to visit all nodes in the digraph.
     585
     586    ///This method runs the %DFS algorithm in order to
     587    ///compute the
     588    ///%DFS path to each node. The algorithm computes
     589    ///- The %DFS tree.
     590    ///- The distance of each node from the root in the %DFS tree.
     591    ///
     592    ///\note d.run() is just a shortcut of the following code.
    546593    ///\code
    547     ///  while ( !d.emptyQueue() ) {
    548     ///    d.processNextArc();
     594    ///  d.init();
     595    ///  for (NodeIt it(digraph); it != INVALID; ++it) {
     596    ///    if (!d.reached(it)) {
     597    ///      d.addSource(it);
     598    ///      d.start();
     599    ///    }
    549600    ///  }
    550601    ///\endcode
    551     void start()
    552     {
    553       while ( !emptyQueue() ) processNextArc();
    554     }
    555 
    556     ///Executes the algorithm until the given target node is reached.
    557 
    558     ///Executes the algorithm until the given target node is reached.
    559     ///
    560     ///This method runs the %DFS algorithm from the root node
    561     ///in order to compute the DFS path to \c dest.
    562     ///
    563     ///The algorithm computes
    564     ///- the %DFS path to \c dest,
    565     ///- the distance of \c dest from the root in the %DFS tree.
    566     ///
    567     ///\pre init() must be called and a root node should be
    568     ///added with addSource() before using this function.
    569     void start(Node dest)
    570     {
    571       while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest )
    572         processNextArc();
    573     }
    574 
    575     ///Executes the algorithm until a condition is met.
    576 
    577     ///Executes the algorithm until a condition is met.
    578     ///
    579     ///This method runs the %DFS algorithm from the root node
    580     ///until an arc \c a with <tt>am[a]</tt> true is found.
    581     ///
    582     ///\param am A \c bool (or convertible) arc map. The algorithm
    583     ///will stop when it reaches an arc \c a with <tt>am[a]</tt> true.
    584     ///
    585     ///\return The reached arc \c a with <tt>am[a]</tt> true or
    586     ///\c INVALID if no such arc was found.
    587     ///
    588     ///\pre init() must be called and a root node should be
    589     ///added with addSource() before using this function.
    590     ///
    591     ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c am is an arc map,
    592     ///not a node map.
    593     template<class ArcBoolMap>
    594     Arc start(const ArcBoolMap &am)
    595     {
    596       while ( !emptyQueue() && !am[_stack[_stack_head]] )
    597         processNextArc();
    598       return emptyQueue() ? INVALID : _stack[_stack_head];
    599     }
    600 
    601     ///Runs the algorithm from the given node.
    602 
    603     ///This method runs the %DFS algorithm from node \c s
    604     ///in order to compute the DFS path to each node.
    605     ///
    606     ///The algorithm computes
    607     ///- the %DFS tree,
    608     ///- the distance of each node from the root in the %DFS tree.
    609     ///
    610     ///\note <tt>d.run(s)</tt> is just a shortcut of the following code.
     602    void run() {
     603      init();
     604      for (NodeIt it(*G); it != INVALID; ++it) {
     605        if (!reached(it)) {
     606          addSource(it);
     607          start();
     608        }
     609      }
     610    }
     611
     612    ///Runs %DFS algorithm from node \c s.
     613
     614    ///This method runs the %DFS algorithm from a root node \c s
     615    ///in order to
     616    ///compute the
     617    ///%DFS path to each node. The algorithm computes
     618    ///- The %DFS tree.
     619    ///- The distance of each node from the root in the %DFS tree.
     620    ///
     621    ///\note d.run(s) is just a shortcut of the following code.
    611622    ///\code
    612623    ///  d.init();
     
    622633    ///Finds the %DFS path between \c s and \c t.
    623634
    624     ///This method runs the %DFS algorithm from node \c s
    625     ///in order to compute the DFS path to \c t.
    626     ///
    627     ///\return The length of the <tt>s</tt>--<tt>t</tt> DFS path,
    628     ///if \c t is reachable form \c s, \c 0 otherwise.
    629     ///
    630     ///\note Apart from the return value, <tt>d.run(s,t)</tt> is
     635    ///Finds the %DFS path between \c s and \c t.
     636    ///
     637    ///\return The length of the %DFS s---t path if there exists one,
     638    ///0 otherwise.
     639    ///\note Apart from the return value, d.run(s,t) is
    631640    ///just a shortcut of the following code.
    632641    ///\code
     
    642651    }
    643652
    644     ///Runs the algorithm to visit all nodes in the digraph.
    645 
    646     ///This method runs the %DFS algorithm in order to compute the
    647     ///%DFS path to each node.
    648     ///
    649     ///The algorithm computes
    650     ///- the %DFS tree,
    651     ///- the distance of each node from the root in the %DFS tree.
    652     ///
    653     ///\note <tt>d.run()</tt> is just a shortcut of the following code.
    654     ///\code
    655     ///  d.init();
    656     ///  for (NodeIt n(digraph); n != INVALID; ++n) {
    657     ///    if (!d.reached(n)) {
    658     ///      d.addSource(n);
    659     ///      d.start();
    660     ///    }
    661     ///  }
    662     ///\endcode
    663     void run() {
    664       init();
    665       for (NodeIt it(*G); it != INVALID; ++it) {
    666         if (!reached(it)) {
    667           addSource(it);
    668           start();
    669         }
    670       }
    671     }
    672 
    673653    ///@}
    674654
     
    676656    ///The result of the %DFS algorithm can be obtained using these
    677657    ///functions.\n
    678     ///Either \ref lemon::Dfs::run() "run()" or \ref lemon::Dfs::start()
    679     ///"start()" must be called before using them.
     658    ///Before the use of these functions,
     659    ///either run() or start() must be called.
    680660
    681661    ///@{
    682662
    683     ///The DFS path to a node.
    684 
    685     ///Returns the DFS path to a node.
    686     ///
    687     ///\warning \c t should be reachable from the root.
    688     ///
    689     ///\pre Either \ref run() or \ref start() must be called before
    690     ///using this function.
    691     Path path(Node t) const { return Path(*G, *_pred, t); }
    692 
    693     ///The distance of a node from the root.
    694 
    695     ///Returns the distance of a node from the root.
    696     ///
    697     ///\warning If node \c v is not reachable from the root, then
    698     ///the return value of this function is undefined.
    699     ///
    700     ///\pre Either \ref run() or \ref start() must be called before
    701     ///using this function.
     663    typedef PredMapPath<Digraph, PredMap> Path;
     664
     665    ///Gives back the shortest path.
     666
     667    ///Gives back the shortest path.
     668    ///\pre The \c t should be reachable from the source.
     669    Path path(Node t)
     670    {
     671      return Path(*G, *_pred, t);
     672    }
     673
     674    ///The distance of a node from the root(s).
     675
     676    ///Returns the distance of a node from the root(s).
     677    ///\pre \ref run() must be called before using this function.
     678    ///\warning If node \c v is unreachable from the root(s) then the return
     679    ///value of this funcion is undefined.
    702680    int dist(Node v) const { return (*_dist)[v]; }
    703681
    704     ///Returns the 'previous arc' of the %DFS tree for a node.
    705 
    706     ///This function returns the 'previous arc' of the %DFS tree for the
    707     ///node \c v, i.e. it returns the last arc of a %DFS path from the
    708     ///root to \c v. It is \c INVALID
    709     ///if \c v is not reachable from the root(s) or if \c v is a root.
    710     ///
    711     ///The %DFS tree used here is equal to the %DFS tree used in
     682    ///Returns the 'previous arc' of the %DFS tree.
     683
     684    ///For a node \c v it returns the 'previous arc'
     685    ///of the %DFS path,
     686    ///i.e. it returns the last arc of a %DFS path from the root(s) to \c
     687    ///v. It is \ref INVALID
     688    ///if \c v is unreachable from the root(s) or \c v is a root. The
     689    ///%DFS tree used here is equal to the %DFS tree used in
    712690    ///\ref predNode().
    713     ///
    714691    ///\pre Either \ref run() or \ref start() must be called before using
    715692    ///this function.
     
    718695    ///Returns the 'previous node' of the %DFS tree.
    719696
    720     ///This function returns the 'previous node' of the %DFS
    721     ///tree for the node \c v, i.e. it returns the last but one node
    722     ///from a %DFS path from the root to \c v. It is \c INVALID
    723     ///if \c v is not reachable from the root(s) or if \c v is a root.
    724     ///
    725     ///The %DFS tree used here is equal to the %DFS tree used in
    726     ///\ref predArc().
    727     ///
     697    ///For a node \c v it returns the 'previous node'
     698    ///of the %DFS tree,
     699    ///i.e. it returns the last but one node from a %DFS path from the
     700    ///root(s) to \c v.
     701    ///It is INVALID if \c v is unreachable from the root(s) or
     702    ///if \c v itself a root.
     703    ///The %DFS tree used here is equal to the %DFS
     704    ///tree used in \ref predArc().
    728705    ///\pre Either \ref run() or \ref start() must be called before
    729706    ///using this function.
     
    731708                                  G->source((*_pred)[v]); }
    732709
    733     ///\brief Returns a const reference to the node map that stores the
    734     ///distances of the nodes.
    735     ///
    736     ///Returns a const reference to the node map that stores the
    737     ///distances of the nodes calculated by the algorithm.
    738     ///
    739     ///\pre Either \ref run() or \ref init()
    740     ///must be called before using this function.
     710    ///Returns a reference to the NodeMap of distances.
     711
     712    ///Returns a reference to the NodeMap of distances.
     713    ///\pre Either \ref run() or \ref init() must
     714    ///be called before using this function.
    741715    const DistMap &distMap() const { return *_dist;}
    742716
    743     ///\brief Returns a const reference to the node map that stores the
    744     ///predecessor arcs.
    745     ///
    746     ///Returns a const reference to the node map that stores the predecessor
    747     ///arcs, which form the DFS tree.
    748     ///
     717    ///Returns a reference to the %DFS arc-tree map.
     718
     719    ///Returns a reference to the NodeMap of the arcs of the
     720    ///%DFS tree.
    749721    ///\pre Either \ref run() or \ref init()
    750722    ///must be called before using this function.
    751723    const PredMap &predMap() const { return *_pred;}
    752724
    753     ///Checks if a node is reachable from the root(s).
     725    ///Checks if a node is reachable from the root.
    754726
    755727    ///Returns \c true if \c v is reachable from the root(s).
     728    ///\warning The source nodes are inditated as unreachable.
    756729    ///\pre Either \ref run() or \ref start()
    757730    ///must be called before using this function.
    758     bool reached(Node v) const { return (*_reached)[v]; }
     731    ///
     732    bool reached(Node v) { return (*_reached)[v]; }
    759733
    760734    ///@}
    761735  };
    762736
    763   ///Default traits class of dfs() function.
    764 
    765   ///Default traits class of dfs() function.
     737  ///Default traits class of Dfs function.
     738
     739  ///Default traits class of Dfs function.
    766740  ///\tparam GR Digraph type.
    767741  template<class GR>
    768742  struct DfsWizardDefaultTraits
    769743  {
    770     ///The type of the digraph the algorithm runs on.
     744    ///The digraph type the algorithm runs on.
    771745    typedef GR Digraph;
    772 
    773     ///\brief The type of the map that stores the predecessor
     746    ///\brief The type of the map that stores the last
    774747    ///arcs of the %DFS paths.
    775748    ///
    776     ///The type of the map that stores the predecessor
     749    ///The type of the map that stores the last
    777750    ///arcs of the %DFS paths.
    778751    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    779752    ///
    780     typedef NullMap<typename Digraph::Node,typename Digraph::Arc> PredMap;
    781     ///Instantiates a \ref PredMap.
     753    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
     754    ///Instantiates a PredMap.
    782755
    783756    ///This function instantiates a \ref PredMap.
    784     ///\param g is the digraph, to which we would like to define the
    785     ///\ref PredMap.
     757    ///\param g is the digraph, to which we would like to define the PredMap.
    786758    ///\todo The digraph alone may be insufficient to initialize
    787759#ifdef DOXYGEN
    788     static PredMap *createPredMap(const Digraph &g)
     760    static PredMap *createPredMap(const GR &g)
    789761#else
    790     static PredMap *createPredMap(const Digraph &)
     762    static PredMap *createPredMap(const GR &)
    791763#endif
    792764    {
     
    798770    ///The type of the map that indicates which nodes are processed.
    799771    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     772    ///\todo named parameter to set this type, function to read and write.
    800773    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    801     ///Instantiates a \ref ProcessedMap.
     774    ///Instantiates a ProcessedMap.
    802775
    803776    ///This function instantiates a \ref ProcessedMap.
    804777    ///\param g is the digraph, to which
    805     ///we would like to define the \ref ProcessedMap.
     778    ///we would like to define the \ref ProcessedMap
    806779#ifdef DOXYGEN
    807     static ProcessedMap *createProcessedMap(const Digraph &g)
     780    static ProcessedMap *createProcessedMap(const GR &g)
    808781#else
    809     static ProcessedMap *createProcessedMap(const Digraph &)
     782    static ProcessedMap *createProcessedMap(const GR &)
    810783#endif
    811784    {
    812785      return new ProcessedMap();
    813786    }
    814 
    815787    ///The type of the map that indicates which nodes are reached.
    816788
    817789    ///The type of the map that indicates which nodes are reached.
    818     ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     790    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     791    ///\todo named parameter to set this type, function to read and write.
    819792    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    820     ///Instantiates a \ref ReachedMap.
     793    ///Instantiates a ReachedMap.
    821794
    822795    ///This function instantiates a \ref ReachedMap.
    823     ///\param g is the digraph, to which
     796    ///\param G is the digraph, to which
    824797    ///we would like to define the \ref ReachedMap.
    825     static ReachedMap *createReachedMap(const Digraph &g)
    826     {
    827       return new ReachedMap(g);
    828     }
    829 
    830     ///The type of the map that stores the distances of the nodes.
    831 
    832     ///The type of the map that stores the distances of the nodes.
     798    static ReachedMap *createReachedMap(const GR &G)
     799    {
     800      return new ReachedMap(G);
     801    }
     802    ///The type of the map that stores the dists of the nodes.
     803
     804    ///The type of the map that stores the dists of the nodes.
    833805    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    834806    ///
    835807    typedef NullMap<typename Digraph::Node,int> DistMap;
    836     ///Instantiates a \ref DistMap.
     808    ///Instantiates a DistMap.
    837809
    838810    ///This function instantiates a \ref DistMap.
     
    840812    ///the \ref DistMap
    841813#ifdef DOXYGEN
    842     static DistMap *createDistMap(const Digraph &g)
     814    static DistMap *createDistMap(const GR &g)
    843815#else
    844     static DistMap *createDistMap(const Digraph &)
     816    static DistMap *createDistMap(const GR &)
    845817#endif
    846818    {
     
    849821  };
    850822
    851   /// Default traits class used by \ref DfsWizard
     823  /// Default traits used by \ref DfsWizard
    852824
    853825  /// To make it easier to use Dfs algorithm
    854   /// we have created a wizard class.
     826  ///we have created a wizard class.
    855827  /// This \ref DfsWizard class needs default traits,
    856   /// as well as the \ref Dfs class.
     828  ///as well as the \ref Dfs class.
    857829  /// The \ref DfsWizardBase is a class to be the default traits of the
    858830  /// \ref DfsWizard class.
     
    863835    typedef DfsWizardDefaultTraits<GR> Base;
    864836  protected:
    865     //The type of the nodes in the digraph.
     837    /// Type of the nodes in the digraph.
    866838    typedef typename Base::Digraph::Node Node;
    867839
    868     //Pointer to the digraph the algorithm runs on.
     840    /// Pointer to the underlying digraph.
    869841    void *_g;
    870     //Pointer to the map of reached nodes.
     842    ///Pointer to the map of reached nodes.
    871843    void *_reached;
    872     //Pointer to the map of processed nodes.
     844    ///Pointer to the map of processed nodes.
    873845    void *_processed;
    874     //Pointer to the map of predecessors arcs.
     846    ///Pointer to the map of predecessors arcs.
    875847    void *_pred;
    876     //Pointer to the map of distances.
     848    ///Pointer to the map of distances.
    877849    void *_dist;
    878     //Pointer to the source node.
     850    ///Pointer to the source node.
    879851    Node _source;
    880852
     
    885857    /// all of the attributes to default values (0, INVALID).
    886858    DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    887                       _dist(0), _source(INVALID) {}
     859                           _dist(0), _source(INVALID) {}
    888860
    889861    /// Constructor.
     
    892864    /// listed in the parameters list.
    893865    /// Others are initiated to 0.
    894     /// \param g The digraph the algorithm runs on.
    895     /// \param s The source node.
     866    /// \param g is the initial value of  \ref _g
     867    /// \param s is the initial value of  \ref _source
    896868    DfsWizardBase(const GR &g, Node s=INVALID) :
    897869      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
     
    900872  };
    901873
    902   /// Auxiliary class for the function type interface of DFS algorithm.
    903 
    904   /// This auxiliary class is created to implement the function type
    905   /// interface of \ref Dfs algorithm. It uses the functions and features
    906   /// of the plain \ref Dfs, but it is much simpler to use it.
    907   /// It should only be used through the \ref dfs() function, which makes
    908   /// it easier to use the algorithm.
     874  /// A class to make the usage of the Dfs algorithm easier
     875
     876  /// This class is created to make it easier to use the Dfs algorithm.
     877  /// It uses the functions and features of the plain \ref Dfs,
     878  /// but it is much simpler to use it.
    909879  ///
    910880  /// Simplicity means that the way to change the types defined
     
    915885  /// the original class by using the ::
    916886  /// operator. In the case of \ref DfsWizard only
    917   /// a function have to be called, and it will
     887  /// a function have to be called and it will
    918888  /// return the needed class.
    919889  ///
    920   /// It does not have own \ref run() method. When its \ref run() method
    921   /// is called, it initiates a plain \ref Dfs object, and calls the
    922   /// \ref Dfs::run() method of it.
     890  /// It does not have own \ref run method. When its \ref run method is called
     891  /// it initiates a plain \ref Dfs object, and calls the \ref Dfs::run
     892  /// method of it.
    923893  template<class TR>
    924894  class DfsWizard : public TR
     
    926896    typedef TR Base;
    927897
    928     ///The type of the digraph the algorithm runs on.
     898    ///The type of the underlying digraph.
    929899    typedef typename TR::Digraph Digraph;
    930 
     900    //\e
    931901    typedef typename Digraph::Node Node;
     902    //\e
    932903    typedef typename Digraph::NodeIt NodeIt;
     904    //\e
    933905    typedef typename Digraph::Arc Arc;
     906    //\e
    934907    typedef typename Digraph::OutArcIt OutArcIt;
    935908
    936     ///\brief The type of the map that stores the predecessor
    937     ///arcs of the shortest paths.
     909    ///\brief The type of the map that stores
     910    ///the reached nodes
     911    typedef typename TR::ReachedMap ReachedMap;
     912    ///\brief The type of the map that stores
     913    ///the processed nodes
     914    typedef typename TR::ProcessedMap ProcessedMap;
     915    ///\brief The type of the map that stores the last
     916    ///arcs of the %DFS paths.
    938917    typedef typename TR::PredMap PredMap;
    939     ///\brief The type of the map that stores the distances of the nodes.
     918    ///The type of the map that stores the distances of the nodes.
    940919    typedef typename TR::DistMap DistMap;
    941     ///\brief The type of the map that indicates which nodes are reached.
    942     typedef typename TR::ReachedMap ReachedMap;
    943     ///\brief The type of the map that indicates which nodes are processed.
    944     typedef typename TR::ProcessedMap ProcessedMap;
    945920
    946921  public:
    947 
    948922    /// Constructor.
    949923    DfsWizard() : TR() {}
     
    961935    ~DfsWizard() {}
    962936
    963     ///Runs DFS algorithm from a source node.
    964 
    965     ///Runs DFS algorithm from a source node.
    966     ///The node can be given with the \ref source() function.
     937    ///Runs Dfs algorithm from a given node.
     938
     939    ///Runs Dfs algorithm from a given node.
     940    ///The node can be given by the \ref source function.
    967941    void run()
    968942    {
     
    980954    }
    981955
    982     ///Runs DFS algorithm from the given node.
    983 
    984     ///Runs DFS algorithm from the given node.
     956    ///Runs Dfs algorithm from the given node.
     957
     958    ///Runs Dfs algorithm from the given node.
    985959    ///\param s is the given source.
    986960    void run(Node s)
     
    988962      Base::_source=s;
    989963      run();
    990     }
    991 
    992     /// Sets the source node, from which the Dfs algorithm runs.
    993 
    994     /// Sets the source node, from which the Dfs algorithm runs.
    995     /// \param s is the source node.
    996     DfsWizard<TR> &source(Node s)
    997     {
    998       Base::_source=s;
    999       return *this;
    1000964    }
    1001965
     
    1006970      DefPredMapBase(const TR &b) : TR(b) {}
    1007971    };
     972
    1008973    ///\brief \ref named-templ-param "Named parameter"
    1009     ///for setting \ref PredMap object.
    1010     ///
    1011     ///\ref named-templ-param "Named parameter"
    1012     ///for setting \ref PredMap object.
     974    ///function for setting PredMap type
     975    ///
     976    /// \ref named-templ-param "Named parameter"
     977    ///function for setting PredMap type
     978    ///
    1013979    template<class T>
    1014980    DfsWizard<DefPredMapBase<T> > predMap(const T &t)
     
    1017983      return DfsWizard<DefPredMapBase<T> >(*this);
    1018984    }
     985
    1019986
    1020987    template<class T>
     
    1024991      DefReachedMapBase(const TR &b) : TR(b) {}
    1025992    };
     993
    1026994    ///\brief \ref named-templ-param "Named parameter"
    1027     ///for setting \ref ReachedMap object.
     995    ///function for setting ReachedMap
    1028996    ///
    1029997    /// \ref named-templ-param "Named parameter"
    1030     ///for setting \ref ReachedMap object.
     998    ///function for setting ReachedMap
     999    ///
    10311000    template<class T>
    10321001    DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
     
    10351004      return DfsWizard<DefReachedMapBase<T> >(*this);
    10361005    }
     1006
    10371007
    10381008    template<class T>
     
    10421012      DefProcessedMapBase(const TR &b) : TR(b) {}
    10431013    };
     1014
    10441015    ///\brief \ref named-templ-param "Named parameter"
    1045     ///for setting \ref ProcessedMap object.
     1016    ///function for setting ProcessedMap
    10461017    ///
    10471018    /// \ref named-templ-param "Named parameter"
    1048     ///for setting \ref ProcessedMap object.
     1019    ///function for setting ProcessedMap
     1020    ///
    10491021    template<class T>
    10501022    DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
     
    10601032      DefDistMapBase(const TR &b) : TR(b) {}
    10611033    };
     1034
    10621035    ///\brief \ref named-templ-param "Named parameter"
    1063     ///for setting \ref DistMap object.
    1064     ///
    1065     ///\ref named-templ-param "Named parameter"
    1066     ///for setting \ref DistMap object.
     1036    ///function for setting DistMap type
     1037    ///
     1038    /// \ref named-templ-param "Named parameter"
     1039    ///function for setting DistMap type
     1040    ///
    10671041    template<class T>
    10681042    DfsWizard<DefDistMapBase<T> > distMap(const T &t)
     
    10701044      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    10711045      return DfsWizard<DefDistMapBase<T> >(*this);
     1046    }
     1047
     1048    /// Sets the source node, from which the Dfs algorithm runs.
     1049
     1050    /// Sets the source node, from which the Dfs algorithm runs.
     1051    /// \param s is the source node.
     1052    DfsWizard<TR> &source(Node s)
     1053    {
     1054      Base::_source=s;
     1055      return *this;
    10721056    }
    10731057
     
    10991083
    11001084#ifdef DOXYGEN
    1101   /// \brief Visitor class for DFS.
     1085  /// \brief Visitor class for dfs.
    11021086  ///
    1103   /// This class defines the interface of the DfsVisit events, and
    1104   /// it could be the base of a real visitor class.
     1087  /// It gives a simple interface for a functional interface for dfs
     1088  /// traversal. The traversal on a linear data structure.
    11051089  template <typename _Digraph>
    11061090  struct DfsVisitor {
     
    11081092    typedef typename Digraph::Arc Arc;
    11091093    typedef typename Digraph::Node Node;
    1110     /// \brief Called for the source node of the DFS.
    1111     ///
    1112     /// This function is called for the source node of the DFS.
    1113     void start(const Node& node) {}
    1114     /// \brief Called when the source node is leaved.
    1115     ///
    1116     /// This function is called when the source node is leaved.
    1117     void stop(const Node& node) {}
    1118     /// \brief Called when a node is reached first time.
    1119     ///
    1120     /// This function is called when a node is reached first time.
     1094    /// \brief Called when the arc reach a node.
     1095    ///
     1096    /// It is called when the dfs find an arc which target is not
     1097    /// reached yet.
     1098    void discover(const Arc& arc) {}
     1099    /// \brief Called when the node reached first time.
     1100    ///
     1101    /// It is Called when the node reached first time.
    11211102    void reach(const Node& node) {}
    1122     /// \brief Called when an arc reaches a new node.
    1123     ///
    1124     /// This function is called when the DFS finds an arc whose target node
    1125     /// is not reached yet.
    1126     void discover(const Arc& arc) {}
    1127     /// \brief Called when an arc is examined but its target node is
     1103    /// \brief Called when we step back on an arc.
     1104    ///
     1105    /// It is called when the dfs should step back on the arc.
     1106    void backtrack(const Arc& arc) {}
     1107    /// \brief Called when we step back from the node.
     1108    ///
     1109    /// It is called when we step back from the node.
     1110    void leave(const Node& node) {}
     1111    /// \brief Called when the arc examined but target of the arc
    11281112    /// already discovered.
    11291113    ///
    1130     /// This function is called when an arc is examined but its target node is
     1114    /// It called when the arc examined but the target of the arc
    11311115    /// already discovered.
    11321116    void examine(const Arc& arc) {}
    1133     /// \brief Called when the DFS steps back from a node.
    1134     ///
    1135     /// This function is called when the DFS steps back from a node.
    1136     void leave(const Node& node) {}
    1137     /// \brief Called when the DFS steps back on an arc.
    1138     ///
    1139     /// This function is called when the DFS steps back on an arc.
    1140     void backtrack(const Arc& arc) {}
     1117    /// \brief Called for the source node of the dfs.
     1118    ///
     1119    /// It is called for the source node of the dfs.
     1120    void start(const Node& node) {}
     1121    /// \brief Called when we leave the source node of the dfs.
     1122    ///
     1123    /// It is called when we leave the source node of the dfs.
     1124    void stop(const Node& node) {}
     1125
    11411126  };
    11421127#else
     
    11461131    typedef typename Digraph::Arc Arc;
    11471132    typedef typename Digraph::Node Node;
     1133    void discover(const Arc&) {}
     1134    void reach(const Node&) {}
     1135    void backtrack(const Arc&) {}
     1136    void leave(const Node&) {}
     1137    void examine(const Arc&) {}
    11481138    void start(const Node&) {}
    11491139    void stop(const Node&) {}
    1150     void reach(const Node&) {}
    1151     void discover(const Arc&) {}
    1152     void examine(const Arc&) {}
    1153     void leave(const Node&) {}
    1154     void backtrack(const Arc&) {}
    11551140
    11561141    template <typename _Visitor>
     
    11591144        Arc arc;
    11601145        Node node;
     1146        visitor.discover(arc);
     1147        visitor.reach(node);
     1148        visitor.backtrack(arc);
     1149        visitor.leave(node);
     1150        visitor.examine(arc);
    11611151        visitor.start(node);
    11621152        visitor.stop(arc);
    1163         visitor.reach(node);
    1164         visitor.discover(arc);
    1165         visitor.examine(arc);
    1166         visitor.leave(node);
    1167         visitor.backtrack(arc);
    11681153      }
    11691154      _Visitor& visitor;
     
    11751160  ///
    11761161  /// Default traits class of DfsVisit class.
    1177   /// \tparam _Digraph The type of the digraph the algorithm runs on.
     1162  /// \tparam _Digraph Digraph type.
    11781163  template<class _Digraph>
    11791164  struct DfsVisitDefaultTraits {
    11801165
    1181     /// \brief The type of the digraph the algorithm runs on.
     1166    /// \brief The digraph type the algorithm runs on.
    11821167    typedef _Digraph Digraph;
    11831168
     
    11851170    ///
    11861171    /// The type of the map that indicates which nodes are reached.
    1187     /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
     1172    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
     1173    /// \todo named parameter to set this type, function to read and write.
    11881174    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    11891175
    1190     /// \brief Instantiates a \ref ReachedMap.
     1176    /// \brief Instantiates a ReachedMap.
    11911177    ///
    11921178    /// This function instantiates a \ref ReachedMap.
     
    11991185  };
    12001186
     1187  /// %DFS Visit algorithm class.
     1188
    12011189  /// \ingroup search
    1202   ///
    1203   /// \brief %DFS algorithm class with visitor interface.
    1204   ///
    12051190  /// This class provides an efficient implementation of the %DFS algorithm
    12061191  /// with visitor interface.
     
    12081193  /// The %DfsVisit class provides an alternative interface to the Dfs
    12091194  /// class. It works with callback mechanism, the DfsVisit object calls
    1210   /// the member functions of the \c Visitor class on every DFS event.
     1195  /// on every dfs event the \c Visitor class member functions.
    12111196  ///
    1212   /// \tparam _Digraph The type of the digraph the algorithm runs on.
     1197  /// \tparam _Digraph The digraph type the algorithm runs on.
    12131198  /// The default value is
    1214   /// \ref ListDigraph. The value of _Digraph is not used directly by
    1215   /// \ref DfsVisit, it is only passed to \ref DfsVisitDefaultTraits.
    1216   /// \tparam _Visitor The Visitor type that is used by the algorithm.
    1217   /// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty visitor, which
    1218   /// does not observe the DFS events. If you want to observe the DFS
    1219   /// events, you should implement your own visitor class.
     1199  /// \ref ListDigraph. The value of _Digraph is not used directly by Dfs, it
     1200  /// is only passed to \ref DfsDefaultTraits.
     1201  /// \tparam _Visitor The Visitor object for the algorithm. The
     1202  /// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty Visitor which
     1203  /// does not observe the Dfs events. If you want to observe the dfs
     1204  /// events you should implement your own Visitor class.
    12201205  /// \tparam _Traits Traits class to set various data types used by the
    12211206  /// algorithm. The default traits class is
    12221207  /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>".
    12231208  /// See \ref DfsVisitDefaultTraits for the documentation of
    1224   /// a DFS visit traits class.
     1209  /// a Dfs visit traits class.
     1210  ///
     1211  /// \author Jacint Szabo, Alpar Juttner and Balazs Dezso
    12251212#ifdef DOXYGEN
    12261213  template <typename _Digraph, typename _Visitor, typename _Traits>
     
    12361223    ///
    12371224    /// This error represents problems in the initialization
    1238     /// of the parameters of the algorithm.
     1225    /// of the parameters of the algorithms.
    12391226    class UninitializedParameter : public lemon::UninitializedParameter {
    12401227    public:
     
    12451232    };
    12461233
    1247     ///The traits class.
    12481234    typedef _Traits Traits;
    12491235
    1250     ///The type of the digraph the algorithm runs on.
    12511236    typedef typename Traits::Digraph Digraph;
    12521237
    1253     ///The visitor type used by the algorithm.
    12541238    typedef _Visitor Visitor;
    12551239
    1256     ///The type of the map that indicates which nodes are reached.
     1240    ///The type of the map indicating which nodes are reached.
    12571241    typedef typename Traits::ReachedMap ReachedMap;
    12581242
     
    12641248    typedef typename Digraph::OutArcIt OutArcIt;
    12651249
    1266     //Pointer to the underlying digraph.
     1250    /// Pointer to the underlying digraph.
    12671251    const Digraph *_digraph;
    1268     //Pointer to the visitor object.
     1252    /// Pointer to the visitor object.
    12691253    Visitor *_visitor;
    1270     //Pointer to the map of reached status of the nodes.
     1254    ///Pointer to the map of reached status of the nodes.
    12711255    ReachedMap *_reached;
    1272     //Indicates if _reached is locally allocated (true) or not.
     1256    ///Indicates if \ref _reached is locally allocated (\c true) or not.
    12731257    bool local_reached;
    12741258
     
    12761260    int _stack_head;
    12771261
    1278     ///Creates the maps if necessary.
    1279     ///\todo Better memory allocation (instead of new).
     1262    /// \brief Creates the maps if necessary.
     1263    ///
     1264    /// Creates the maps if necessary.
    12801265    void create_maps() {
    12811266      if(!_reached) {
     
    13041289    };
    13051290    /// \brief \ref named-templ-param "Named parameter" for setting
    1306     /// ReachedMap type.
    1307     ///
    1308     /// \ref named-templ-param "Named parameter" for setting ReachedMap type.
     1291    /// ReachedMap type
     1292    ///
     1293    /// \ref named-templ-param "Named parameter" for setting ReachedMap type
    13091294    template <class T>
    13101295    struct DefReachedMap : public DfsVisit< Digraph, Visitor,
     
    13201305    /// Constructor.
    13211306    ///
    1322     /// \param digraph The digraph the algorithm runs on.
    1323     /// \param visitor The visitor object of the algorithm.
     1307    /// \param digraph the digraph the algorithm will run on.
     1308    /// \param visitor The visitor of the algorithm.
     1309    ///
    13241310    DfsVisit(const Digraph& digraph, Visitor& visitor)
    13251311      : _digraph(&digraph), _visitor(&visitor),
     
    13271313
    13281314    /// \brief Destructor.
     1315    ///
     1316    /// Destructor.
    13291317    ~DfsVisit() {
    13301318      if(local_reached) delete _reached;
    13311319    }
    13321320
    1333     /// \brief Sets the map that indicates which nodes are reached.
    1334     ///
    1335     /// Sets the map that indicates which nodes are reached.
     1321    /// \brief Sets the map indicating if a node is reached.
     1322    ///
     1323    /// Sets the map indicating if a node is reached.
    13361324    /// If you don't use this function before calling \ref run(),
    1337     /// it will allocate one. The destructor deallocates this
     1325    /// it will allocate one. The destuctor deallocates this
    13381326    /// automatically allocated map, of course.
    13391327    /// \return <tt> (*this) </tt>
     
    13481336
    13491337  public:
    1350 
    13511338    /// \name Execution control
    13521339    /// The simplest way to execute the algorithm is to use
    1353     /// one of the member functions called \ref lemon::DfsVisit::run()
    1354     /// "run()".
     1340    /// one of the member functions called \c run(...).
    13551341    /// \n
    1356     /// If you need more control on the execution, first you must call
    1357     /// \ref lemon::DfsVisit::init() "init()", then you can add several
    1358     /// source nodes with \ref lemon::DfsVisit::addSource() "addSource()".
    1359     /// Finally \ref lemon::DfsVisit::start() "start()" will perform the
    1360     /// actual path computation.
     1342    /// If you need more control on the execution,
     1343    /// first you must call \ref init(), then you can adda source node
     1344    /// with \ref addSource().
     1345    /// Finally \ref start() will perform the actual path
     1346    /// computation.
    13611347
    13621348    /// @{
    1363 
    13641349    /// \brief Initializes the internal data structures.
    13651350    ///
    13661351    /// Initializes the internal data structures.
     1352    ///
    13671353    void init() {
    13681354      create_maps();
     
    13741360    }
    13751361
    1376     ///Adds a new source node.
    1377 
    1378     ///Adds a new source node to the set of nodes to be processed.
    1379     ///
    1380     ///\pre The stack must be empty. (Otherwise the algorithm gives
    1381     ///false results.)
    1382     ///
    1383     ///\warning Distances will be wrong (or at least strange) in case of
    1384     ///multiple sources.
    1385     void addSource(Node s)
    1386     {
    1387       LEMON_DEBUG(emptyQueue(), "The stack is not empty.");
     1362    /// \brief Adds a new source node.
     1363    ///
     1364    /// Adds a new source node to the set of nodes to be processed.
     1365    void addSource(Node s) {
    13881366      if(!(*_reached)[s]) {
    13891367          _reached->set(s,true);
     
    14061384    /// \return The processed arc.
    14071385    ///
    1408     /// \pre The stack must not be empty.
     1386    /// \pre The stack must not be empty!
    14091387    Arc processNextArc() {
    14101388      Arc e = _stack[_stack_head];
     
    14401418    /// \return The next arc to be processed or INVALID if the stack is
    14411419    /// empty.
    1442     Arc nextArc() const {
     1420    Arc nextArc() {
    14431421      return _stack_head >= 0 ? _stack[_stack_head] : INVALID;
    14441422    }
    14451423
    14461424    /// \brief Returns \c false if there are nodes
    1447     /// to be processed.
     1425    /// to be processed in the queue
    14481426    ///
    14491427    /// Returns \c false if there are nodes
    1450     /// to be processed in the queue (stack).
    1451     bool emptyQueue() const { return _stack_head < 0; }
     1428    /// to be processed in the queue
     1429    bool emptyQueue() { return _stack_head < 0; }
    14521430
    14531431    /// \brief Returns the number of the nodes to be processed.
    14541432    ///
    1455     /// Returns the number of the nodes to be processed in the queue (stack).
    1456     int queueSize() const { return _stack_head + 1; }
     1433    /// Returns the number of the nodes to be processed in the queue.
     1434    int queueSize() { return _stack_head + 1; }
    14571435
    14581436    /// \brief Executes the algorithm.
     
    14601438    /// Executes the algorithm.
    14611439    ///
    1462     /// This method runs the %DFS algorithm from the root node
    1463     /// in order to compute the %DFS path to each node.
    1464     ///
    1465     /// The algorithm computes
    1466     /// - the %DFS tree,
    1467     /// - the distance of each node from the root in the %DFS tree.
    1468     ///
    1469     /// \pre init() must be called and a root node should be
    1470     /// added with addSource() before using this function.
    1471     ///
    1472     /// \note <tt>d.start()</tt> is just a shortcut of the following code.
    1473     /// \code
    1474     ///   while ( !d.emptyQueue() ) {
    1475     ///     d.processNextArc();
    1476     ///   }
    1477     /// \endcode
     1440    /// \pre init() must be called and at least one node should be added
     1441    /// with addSource() before using this function.
    14781442    void start() {
    14791443      while ( !emptyQueue() ) processNextArc();
    14801444    }
    14811445
    1482     /// \brief Executes the algorithm until the given target node is reached.
    1483     ///
    1484     /// Executes the algorithm until the given target node is reached.
    1485     ///
    1486     /// This method runs the %DFS algorithm from the root node
    1487     /// in order to compute the DFS path to \c dest.
    1488     ///
    1489     /// The algorithm computes
    1490     /// - the %DFS path to \c dest,
    1491     /// - the distance of \c dest from the root in the %DFS tree.
    1492     ///
    1493     /// \pre init() must be called and a root node should be added
     1446    /// \brief Executes the algorithm until \c dest is reached.
     1447    ///
     1448    /// Executes the algorithm until \c dest is reached.
     1449    ///
     1450    /// \pre init() must be called and at least one node should be added
    14941451    /// with addSource() before using this function.
    14951452    void start(Node dest) {
     
    15021459    /// Executes the algorithm until a condition is met.
    15031460    ///
    1504     /// This method runs the %DFS algorithm from the root node
    1505     /// until an arc \c a with <tt>am[a]</tt> true is found.
    1506     ///
    1507     /// \param am A \c bool (or convertible) arc map. The algorithm
    1508     /// will stop when it reaches an arc \c a with <tt>am[a]</tt> true.
    1509     ///
    1510     /// \return The reached arc \c a with <tt>am[a]</tt> true or
    1511     /// \c INVALID if no such arc was found.
    1512     ///
    1513     /// \pre init() must be called and a root node should be added
     1461    /// \pre init() must be called and at least one node should be added
    15141462    /// with addSource() before using this function.
    15151463    ///
    1516     /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c am is an arc map,
     1464    /// \param em must be a bool (or convertible) arc map. The algorithm
     1465    /// will stop when it reaches an arc \c e with <tt>em[e]</tt> true.
     1466    ///
     1467    ///\return The reached arc \c e with <tt>em[e]</tt> true or
     1468    ///\c INVALID if no such arc was found.
     1469    ///
     1470    /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an arc map,
    15171471    /// not a node map.
    1518     template <typename AM>
    1519     Arc start(const AM &am) {
    1520       while ( !emptyQueue() && !am[_stack[_stack_head]] )
     1472    template <typename EM>
     1473    Arc start(const EM &em) {
     1474      while ( !emptyQueue() && !em[_stack[_stack_head]] )
    15211475        processNextArc();
    15221476      return emptyQueue() ? INVALID : _stack[_stack_head];
    15231477    }
    15241478
    1525     /// \brief Runs the algorithm from the given node.
    1526     ///
    1527     /// This method runs the %DFS algorithm from node \c s.
    1528     /// in order to compute the DFS path to each node.
    1529     ///
    1530     /// The algorithm computes
    1531     /// - the %DFS tree,
    1532     /// - the distance of each node from the root in the %DFS tree.
    1533     ///
    1534     /// \note <tt>d.run(s)</tt> is just a shortcut of the following code.
     1479    /// \brief Runs %DFSVisit algorithm from node \c s.
     1480    ///
     1481    /// This method runs the %DFS algorithm from a root node \c s.
     1482    /// \note d.run(s) is just a shortcut of the following code.
    15351483    ///\code
    15361484    ///   d.init();
     
    15441492    }
    15451493
    1546     /// \brief Finds the %DFS path between \c s and \c t.
    1547 
    1548     /// This method runs the %DFS algorithm from node \c s
    1549     /// in order to compute the DFS path to \c t.
    1550     ///
    1551     /// \return The length of the <tt>s</tt>--<tt>t</tt> DFS path,
    1552     /// if \c t is reachable form \c s, \c 0 otherwise.
    1553     ///
    1554     /// \note Apart from the return value, <tt>d.run(s,t)</tt> is
    1555     /// just a shortcut of the following code.
     1494    /// \brief Runs %DFSVisit algorithm to visit all nodes in the digraph.
     1495
     1496    /// This method runs the %DFS algorithm in order to
     1497    /// compute the %DFS path to each node. The algorithm computes
     1498    /// - The %DFS tree.
     1499    /// - The distance of each node from the root in the %DFS tree.
     1500    ///
     1501    ///\note d.run() is just a shortcut of the following code.
    15561502    ///\code
    1557     ///   d.init();
    1558     ///   d.addSource(s);
    1559     ///   d.start(t);
    1560     ///\endcode
    1561     int run(Node s,Node t) {
    1562       init();
    1563       addSource(s);
    1564       start(t);
    1565       return reached(t)?_stack_head+1:0;
    1566     }
    1567 
    1568     /// \brief Runs the algorithm to visit all nodes in the digraph.
    1569 
    1570     /// This method runs the %DFS algorithm in order to
    1571     /// compute the %DFS path to each node.
    1572     ///
    1573     /// The algorithm computes
    1574     /// - the %DFS tree,
    1575     /// - the distance of each node from the root in the %DFS tree.
    1576     ///
    1577     /// \note <tt>d.run()</tt> is just a shortcut of the following code.
    1578     ///\code
    1579     ///   d.init();
    1580     ///   for (NodeIt n(digraph); n != INVALID; ++n) {
    1581     ///     if (!d.reached(n)) {
    1582     ///       d.addSource(n);
    1583     ///       d.start();
    1584     ///     }
    1585     ///   }
     1503    ///  d.init();
     1504    ///  for (NodeIt it(digraph); it != INVALID; ++it) {
     1505    ///    if (!d.reached(it)) {
     1506    ///      d.addSource(it);
     1507    ///      d.start();
     1508    ///    }
     1509    ///  }
    15861510    ///\endcode
    15871511    void run() {
     
    15941518      }
    15951519    }
    1596 
    15971520    ///@}
    15981521
     
    16001523    /// The result of the %DFS algorithm can be obtained using these
    16011524    /// functions.\n
    1602     /// Either \ref lemon::DfsVisit::run() "run()" or
    1603     /// \ref lemon::DfsVisit::start() "start()" must be called before
    1604     /// using them.
     1525    /// Before the use of these functions,
     1526    /// either run() or start() must be called.
    16051527    ///@{
    1606 
    1607     /// \brief Checks if a node is reachable from the root(s).
     1528    /// \brief Checks if a node is reachable from the root.
    16081529    ///
    16091530    /// Returns \c true if \c v is reachable from the root(s).
     1531    /// \warning The source nodes are inditated as unreachable.
    16101532    /// \pre Either \ref run() or \ref start()
    16111533    /// must be called before using this function.
     1534    ///
    16121535    bool reached(Node v) { return (*_reached)[v]; }
    1613 
    16141536    ///@}
    1615 
    16161537  };
    16171538
     1539
    16181540} //END OF NAMESPACE LEMON
    16191541
    16201542#endif
     1543
  • lemon/dijkstra.h

    r247 r220  
    3434namespace lemon {
    3535
    36   /// \brief Default operation traits for the Dijkstra algorithm class.
     36  /// \brief Default OperationTraits for the Dijkstra algorithm class.
    3737  ///
    38   /// This operation traits class defines all computational operations and
    39   /// constants which are used in the Dijkstra algorithm.
     38  /// It defines all computational operations and constants which are
     39  /// used in the Dijkstra algorithm.
    4040  template <typename Value>
    4141  struct DijkstraDefaultOperationTraits {
     
    4848      return left + right;
    4949    }
    50     /// \brief Gives back true only if the first value is less than the second.
     50    /// \brief Gives back true only if the first value less than the second.
    5151    static bool less(const Value& left, const Value& right) {
    5252      return left < right;
     
    5454  };
    5555
    56   /// \brief Widest path operation traits for the Dijkstra algorithm class.
     56  /// \brief Widest path OperationTraits for the Dijkstra algorithm class.
    5757  ///
    58   /// This operation traits class defines all computational operations and
    59   /// constants which are used in the Dijkstra algorithm for widest path
    60   /// computation.
    61   ///
    62   /// \see DijkstraDefaultOperationTraits
     58  /// It defines all computational operations and constants which are
     59  /// used in the Dijkstra algorithm for widest path computation.
    6360  template <typename Value>
    6461  struct DijkstraWidestPathOperationTraits {
     
    7168      return std::min(left, right);
    7269    }
    73     /// \brief Gives back true only if the first value is less than the second.
     70    /// \brief Gives back true only if the first value less than the second.
    7471    static bool less(const Value& left, const Value& right) {
    7572      return left < right;
     
    8077
    8178  ///Default traits class of Dijkstra class.
    82   ///\tparam GR The type of the digraph.
    83   ///\tparam LM The type of the length map.
     79  ///\tparam GR Digraph type.
     80  ///\tparam LM Type of length map.
    8481  template<class GR, class LM>
    8582  struct DijkstraDefaultTraits
    8683  {
    87     ///The type of the digraph the algorithm runs on.
     84    ///The digraph type the algorithm runs on.
    8885    typedef GR Digraph;
    89 
    9086    ///The type of the map that stores the arc lengths.
    9187
     
    9389    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
    9490    typedef LM LengthMap;
    95     ///The type of the length of the arcs.
     91    //The type of the length of the arcs.
    9692    typedef typename LM::Value Value;
    97 
    9893    /// Operation traits for Dijkstra algorithm.
    9994
    100     /// This class defines the operations that are used in the algorithm.
     95    /// It defines the used operation by the algorithm.
    10196    /// \see DijkstraDefaultOperationTraits
    10297    typedef DijkstraDefaultOperationTraits<Value> OperationTraits;
    103 
    104     /// The cross reference type used by the heap.
    105 
    106     /// The cross reference type used by the heap.
     98    /// The cross reference type used by heap.
     99
     100
     101    /// The cross reference type used by heap.
    107102    /// Usually it is \c Digraph::NodeMap<int>.
    108103    typedef typename Digraph::template NodeMap<int> HeapCrossRef;
    109     ///Instantiates a \ref HeapCrossRef.
    110 
    111     ///This function instantiates a \ref HeapCrossRef.
    112     /// \param g is the digraph, to which we would like to define the
    113     /// \ref HeapCrossRef.
    114     static HeapCrossRef *createHeapCrossRef(const Digraph &g)
    115     {
    116       return new HeapCrossRef(g);
    117     }
    118 
    119     ///The heap type used by the Dijkstra algorithm.
    120 
    121     ///The heap type used by the Dijkstra algorithm.
     104    ///Instantiates a HeapCrossRef.
     105
     106    ///This function instantiates a \c HeapCrossRef.
     107    /// \param G is the digraph, to which we would like to define the
     108    /// HeapCrossRef.
     109    static HeapCrossRef *createHeapCrossRef(const GR &G)
     110    {
     111      return new HeapCrossRef(G);
     112    }
     113
     114    ///The heap type used by Dijkstra algorithm.
     115
     116    ///The heap type used by Dijkstra algorithm.
    122117    ///
    123118    ///\sa BinHeap
    124119    ///\sa Dijkstra
    125120    typedef BinHeap<typename LM::Value, HeapCrossRef, std::less<Value> > Heap;
    126     ///Instantiates a \ref Heap.
    127 
    128     ///This function instantiates a \ref Heap.
    129     static Heap *createHeap(HeapCrossRef& r)
    130     {
    131       return new Heap(r);
    132     }
    133 
    134     ///\brief The type of the map that stores the predecessor
     121
     122    static Heap *createHeap(HeapCrossRef& R)
     123    {
     124      return new Heap(R);
     125    }
     126
     127    ///\brief The type of the map that stores the last
    135128    ///arcs of the shortest paths.
    136129    ///
    137     ///The type of the map that stores the predecessor
     130    ///The type of the map that stores the last
    138131    ///arcs of the shortest paths.
    139132    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    140     typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    141     ///Instantiates a \ref PredMap.
    142 
    143     ///This function instantiates a \ref PredMap.
    144     ///\param g is the digraph, to which we would like to define the
    145     ///\ref PredMap.
     133    ///
     134    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
     135    ///Instantiates a PredMap.
     136
     137    ///This function instantiates a \c PredMap.
     138    ///\param G is the digraph, to which we would like to define the PredMap.
    146139    ///\todo The digraph alone may be insufficient for the initialization
    147     static PredMap *createPredMap(const Digraph &g)
    148     {
    149       return new PredMap(g);
    150     }
    151 
    152     ///The type of the map that indicates which nodes are processed.
    153 
    154     ///The type of the map that indicates which nodes are processed.
     140    static PredMap *createPredMap(const GR &G)
     141    {
     142      return new PredMap(G);
     143    }
     144
     145    ///The type of the map that stores whether a nodes is processed.
     146
     147    ///The type of the map that stores whether a nodes is processed.
    155148    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    156149    ///By default it is a NullMap.
    157150    ///\todo If it is set to a real map,
    158151    ///Dijkstra::processed() should read this.
     152    ///\todo named parameter to set this type, function to read and write.
    159153    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    160     ///Instantiates a \ref ProcessedMap.
    161 
    162     ///This function instantiates a \ref ProcessedMap.
     154    ///Instantiates a ProcessedMap.
     155
     156    ///This function instantiates a \c ProcessedMap.
    163157    ///\param g is the digraph, to which
    164     ///we would like to define the \ref ProcessedMap
     158    ///we would like to define the \c ProcessedMap
    165159#ifdef DOXYGEN
    166     static ProcessedMap *createProcessedMap(const Digraph &g)
     160    static ProcessedMap *createProcessedMap(const GR &g)
    167161#else
    168     static ProcessedMap *createProcessedMap(const Digraph &)
     162    static ProcessedMap *createProcessedMap(const GR &)
    169163#endif
    170164    {
    171165      return new ProcessedMap();
    172166    }
    173 
    174     ///The type of the map that stores the distances of the nodes.
    175 
    176     ///The type of the map that stores the distances of the nodes.
     167    ///The type of the map that stores the dists of the nodes.
     168
     169    ///The type of the map that stores the dists of the nodes.
    177170    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     171    ///
    178172    typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
    179     ///Instantiates a \ref DistMap.
     173    ///Instantiates a DistMap.
    180174
    181175    ///This function instantiates a \ref DistMap.
    182     ///\param g is the digraph, to which we would like to define
     176    ///\param G is the digraph, to which we would like to define
    183177    ///the \ref DistMap
    184     static DistMap *createDistMap(const Digraph &g)
    185     {
    186       return new DistMap(g);
     178    static DistMap *createDistMap(const GR &G)
     179    {
     180      return new DistMap(G);
    187181    }
    188182  };
     
    191185
    192186  /// \ingroup shortest_path
    193   ///This class provides an efficient implementation of the %Dijkstra algorithm.
    194   ///
     187  ///This class provides an efficient implementation of %Dijkstra algorithm.
    195188  ///The arc lengths are passed to the algorithm using a
    196189  ///\ref concepts::ReadMap "ReadMap",
    197190  ///so it is easy to change it to any kind of length.
     191  ///
    198192  ///The type of the length is determined by the
    199193  ///\ref concepts::ReadMap::Value "Value" of the length map.
     194  ///
    200195  ///It is also possible to change the underlying priority heap.
    201196  ///
    202   ///There is also a \ref dijkstra() "function type interface" for the
    203   ///%Dijkstra algorithm, which is convenient in the simplier cases and
    204   ///it can be used easier.
    205   ///
    206   ///\tparam GR The type of the digraph the algorithm runs on.
    207   ///The default value is \ref ListDigraph.
    208   ///The value of GR is not used directly by \ref Dijkstra, it is only
    209   ///passed to \ref DijkstraDefaultTraits.
    210   ///\tparam LM A readable arc map that determines the lengths of the
     197  ///\tparam GR The digraph type the algorithm runs on. The default value
     198  ///is \ref ListDigraph. The value of GR is not used directly by
     199  ///Dijkstra, it is only passed to \ref DijkstraDefaultTraits.
     200  ///\tparam LM This read-only ArcMap determines the lengths of the
    211201  ///arcs. It is read once for each arc, so the map may involve in
    212   ///relatively time consuming process to compute the arc lengths if
     202  ///relatively time consuming process to compute the arc length if
    213203  ///it is necessary. The default map type is \ref
    214   ///concepts::Digraph::ArcMap "Digraph::ArcMap<int>".
    215   ///The value of LM is not used directly by \ref Dijkstra, it is only
    216   ///passed to \ref DijkstraDefaultTraits.
    217   ///\tparam TR Traits class to set various data types used by the algorithm.
    218   ///The default traits class is \ref DijkstraDefaultTraits
    219   ///"DijkstraDefaultTraits<GR,LM>". See \ref DijkstraDefaultTraits
    220   ///for the documentation of a Dijkstra traits class.
     204  ///concepts::Digraph::ArcMap "Digraph::ArcMap<int>".  The value
     205  ///of LM is not used directly by Dijkstra, it is only passed to \ref
     206  ///DijkstraDefaultTraits.
     207  ///\tparam TR Traits class to set
     208  ///various data types used by the algorithm.  The default traits
     209  ///class is \ref DijkstraDefaultTraits
     210  ///"DijkstraDefaultTraits<GR,LM>".  See \ref
     211  ///DijkstraDefaultTraits for the documentation of a Dijkstra traits
     212  ///class.
     213
    221214#ifdef DOXYGEN
    222215  template <typename GR, typename LM, typename TR>
     
    228221  class Dijkstra {
    229222  public:
    230     ///\ref Exception for uninitialized parameters.
    231 
    232     ///This error represents problems in the initialization of the
    233     ///parameters of the algorithm.
     223    /**
     224     * \brief \ref Exception for uninitialized parameters.
     225     *
     226     * This error represents problems in the initialization
     227     * of the parameters of the algorithms.
     228     */
    234229    class UninitializedParameter : public lemon::UninitializedParameter {
    235230    public:
     
    239234    };
    240235
    241     ///The type of the digraph the algorithm runs on.
     236    typedef TR Traits;
     237    ///The type of the underlying digraph.
    242238    typedef typename TR::Digraph Digraph;
     239    ///\e
     240    typedef typename Digraph::Node Node;
     241    ///\e
     242    typedef typename Digraph::NodeIt NodeIt;
     243    ///\e
     244    typedef typename Digraph::Arc Arc;
     245    ///\e
     246    typedef typename Digraph::OutArcIt OutArcIt;
    243247
    244248    ///The type of the length of the arcs.
     
    246250    ///The type of the map that stores the arc lengths.
    247251    typedef typename TR::LengthMap LengthMap;
    248     ///\brief The type of the map that stores the predecessor arcs of the
    249     ///shortest paths.
     252    ///\brief The type of the map that stores the last
     253    ///arcs of the shortest paths.
    250254    typedef typename TR::PredMap PredMap;
    251     ///The type of the map that stores the distances of the nodes.
     255    ///The type of the map indicating if a node is processed.
     256    typedef typename TR::ProcessedMap ProcessedMap;
     257    ///The type of the map that stores the dists of the nodes.
    252258    typedef typename TR::DistMap DistMap;
    253     ///The type of the map that indicates which nodes are processed.
    254     typedef typename TR::ProcessedMap ProcessedMap;
    255     ///The type of the paths.
    256     typedef PredMapPath<Digraph, PredMap> Path;
    257259    ///The cross reference type used for the current heap.
    258260    typedef typename TR::HeapCrossRef HeapCrossRef;
    259     ///The heap type used by the algorithm.
     261    ///The heap type used by the dijkstra algorithm.
    260262    typedef typename TR::Heap Heap;
    261     ///The operation traits class.
     263    ///The operation traits.
    262264    typedef typename TR::OperationTraits OperationTraits;
    263 
    264     ///The traits class.
    265     typedef TR Traits;
    266 
    267265  private:
    268 
    269     typedef typename Digraph::Node Node;
    270     typedef typename Digraph::NodeIt NodeIt;
    271     typedef typename Digraph::Arc Arc;
    272     typedef typename Digraph::OutArcIt OutArcIt;
    273 
    274     //Pointer to the underlying digraph.
     266    /// Pointer to the underlying digraph.
    275267    const Digraph *G;
    276     //Pointer to the length map.
     268    /// Pointer to the length map
    277269    const LengthMap *length;
    278     //Pointer to the map of predecessors arcs.
     270    ///Pointer to the map of predecessors arcs.
    279271    PredMap *_pred;
    280     //Indicates if _pred is locally allocated (true) or not.
     272    ///Indicates if \ref _pred is locally allocated (\c true) or not.
    281273    bool local_pred;
    282     //Pointer to the map of distances.
     274    ///Pointer to the map of distances.
    283275    DistMap *_dist;
    284     //Indicates if _dist is locally allocated (true) or not.
     276    ///Indicates if \ref _dist is locally allocated (\c true) or not.
    285277    bool local_dist;
    286     //Pointer to the map of processed status of the nodes.
     278    ///Pointer to the map of processed status of the nodes.
    287279    ProcessedMap *_processed;
    288     //Indicates if _processed is locally allocated (true) or not.
     280    ///Indicates if \ref _processed is locally allocated (\c true) or not.
    289281    bool local_processed;
    290     //Pointer to the heap cross references.
     282    ///Pointer to the heap cross references.
    291283    HeapCrossRef *_heap_cross_ref;
    292     //Indicates if _heap_cross_ref is locally allocated (true) or not.
     284    ///Indicates if \ref _heap_cross_ref is locally allocated (\c true) or not.
    293285    bool local_heap_cross_ref;
    294     //Pointer to the heap.
     286    ///Pointer to the heap.
    295287    Heap *_heap;
    296     //Indicates if _heap is locally allocated (true) or not.
     288    ///Indicates if \ref _heap is locally allocated (\c true) or not.
    297289    bool local_heap;
    298290
    299291    ///Creates the maps if necessary.
     292
    300293    ///\todo Better memory allocation (instead of new).
    301294    void create_maps()
     
    323316    }
    324317
    325   public:
     318  public :
    326319
    327320    typedef Dijkstra Create;
     
    339332      }
    340333    };
    341     ///\brief \ref named-templ-param "Named parameter" for setting
    342     ///\ref PredMap type.
    343     ///
    344     ///\ref named-templ-param "Named parameter" for setting
    345     ///\ref PredMap type.
     334    ///\ref named-templ-param "Named parameter" for setting PredMap type
     335
     336    ///\ref named-templ-param "Named parameter" for setting PredMap type
     337    ///
    346338    template <class T>
    347339    struct DefPredMap
     
    358350      }
    359351    };
    360     ///\brief \ref named-templ-param "Named parameter" for setting
    361     ///\ref DistMap type.
    362     ///
    363     ///\ref named-templ-param "Named parameter" for setting
    364     ///\ref DistMap type.
     352    ///\ref named-templ-param "Named parameter" for setting DistMap type
     353
     354    ///\ref named-templ-param "Named parameter" for setting DistMap type
     355    ///
    365356    template <class T>
    366357    struct DefDistMap
     
    372363    struct DefProcessedMapTraits : public Traits {
    373364      typedef T ProcessedMap;
    374       static ProcessedMap *createProcessedMap(const Digraph &)
     365      static ProcessedMap *createProcessedMap(const Digraph &G)
    375366      {
    376367        throw UninitializedParameter();
    377368      }
    378369    };
    379     ///\brief \ref named-templ-param "Named parameter" for setting
    380     ///\ref ProcessedMap type.
    381     ///
    382     ///\ref named-templ-param "Named parameter" for setting
    383     ///\ref ProcessedMap type.
     370    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
     371
     372    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
     373    ///
    384374    template <class T>
    385375    struct DefProcessedMap
     
    390380    struct DefDigraphProcessedMapTraits : public Traits {
    391381      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    392       static ProcessedMap *createProcessedMap(const Digraph &g)
     382      static ProcessedMap *createProcessedMap(const Digraph &G)
    393383      {
    394         return new ProcessedMap(g);
    395       }
    396     };
    397     ///\brief \ref named-templ-param "Named parameter" for setting
    398     ///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
    399     ///
    400     ///\ref named-templ-param "Named parameter" for setting
    401     ///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
    402     ///If you don't set it explicitly, it will be automatically allocated.
     384        return new ProcessedMap(G);
     385      }
     386    };
     387    ///\brief \ref named-templ-param "Named parameter"
     388    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
     389    ///
     390    ///\ref named-templ-param "Named parameter"
     391    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
     392    ///If you don't set it explicitely, it will be automatically allocated.
    403393    template <class T>
    404394    struct DefProcessedMapToBeDefaultMap
     
    424414    ///
    425415    ///\ref named-templ-param "Named parameter" for setting heap and cross
    426     ///reference type.
     416    ///reference type
     417    ///
    427418    template <class H, class CR = typename Digraph::template NodeMap<int> >
    428419    struct DefHeap
     
    463454
    464455    /// \brief \ref named-templ-param "Named parameter" for setting
    465     ///\ref OperationTraits type
    466     ///
    467     ///\ref named-templ-param "Named parameter" for setting
    468     ///\ref OperationTraits type.
     456    /// OperationTraits type
     457    ///
     458    /// \ref named-templ-param "Named parameter" for setting OperationTraits
     459    /// type
    469460    template <class T>
    470461    struct DefOperationTraits
     
    476467    ///@}
    477468
     469
    478470  protected:
    479471
     
    484476    ///Constructor.
    485477
    486     ///Constructor.
    487     ///\param _g The digraph the algorithm runs on.
    488     ///\param _length The length map used by the algorithm.
    489     Dijkstra(const Digraph& _g, const LengthMap& _length) :
    490       G(&_g), length(&_length),
     478    ///\param _G the digraph the algorithm will run on.
     479    ///\param _length the length map used by the algorithm.
     480    Dijkstra(const Digraph& _G, const LengthMap& _length) :
     481      G(&_G), length(&_length),
    491482      _pred(NULL), local_pred(false),
    492483      _dist(NULL), local_dist(false),
     
    516507    }
    517508
    518     ///Sets the map that stores the predecessor arcs.
    519 
    520     ///Sets the map that stores the predecessor arcs.
     509    ///Sets the map storing the predecessor arcs.
     510
     511    ///Sets the map storing the predecessor arcs.
    521512    ///If you don't use this function before calling \ref run(),
    522     ///it will allocate one. The destructor deallocates this
     513    ///it will allocate one. The destuctor deallocates this
    523514    ///automatically allocated map, of course.
    524515    ///\return <tt> (*this) </tt>
     
    533524    }
    534525
    535     ///Sets the map that indicates which nodes are processed.
    536 
    537     ///Sets the map that indicates which nodes are processed.
     526    ///Sets the map storing the distances calculated by the algorithm.
     527
     528    ///Sets the map storing the distances calculated by the algorithm.
    538529    ///If you don't use this function before calling \ref run(),
    539     ///it will allocate one. The destructor deallocates this
    540     ///automatically allocated map, of course.
    541     ///\return <tt> (*this) </tt>
    542     Dijkstra &processedMap(ProcessedMap &m)
    543     {
    544       if(local_processed) {
    545         delete _processed;
    546         local_processed=false;
    547       }
    548       _processed = &m;
    549       return *this;
    550     }
    551 
    552     ///Sets the map that stores the distances of the nodes.
    553 
    554     ///Sets the map that stores the distances of the nodes calculated by the
    555     ///algorithm.
    556     ///If you don't use this function before calling \ref run(),
    557     ///it will allocate one. The destructor deallocates this
     530    ///it will allocate one. The destuctor deallocates this
    558531    ///automatically allocated map, of course.
    559532    ///\return <tt> (*this) </tt>
     
    572545    ///Sets the heap and the cross reference used by algorithm.
    573546    ///If you don't use this function before calling \ref run(),
    574     ///it will allocate one. The destructor deallocates this
     547    ///it will allocate one. The destuctor deallocates this
    575548    ///automatically allocated heap and cross reference, of course.
    576549    ///\return <tt> (*this) </tt>
     
    591564
    592565  private:
    593 
    594566    void finalizeNodeData(Node v,Value dst)
    595567    {
     
    600572  public:
    601573
     574    typedef PredMapPath<Digraph, PredMap> Path;
     575
    602576    ///\name Execution control
    603     ///The simplest way to execute the algorithm is to use one of the
    604     ///member functions called \ref lemon::Dijkstra::run() "run()".
     577    ///The simplest way to execute the algorithm is to use
     578    ///one of the member functions called \c run(...).
    605579    ///\n
    606     ///If you need more control on the execution, first you must call
    607     ///\ref lemon::Dijkstra::init() "init()", then you can add several
    608     ///source nodes with \ref lemon::Dijkstra::addSource() "addSource()".
    609     ///Finally \ref lemon::Dijkstra::start() "start()" will perform the
    610     ///actual path computation.
     580    ///If you need more control on the execution,
     581    ///first you must call \ref init(), then you can add several source nodes
     582    ///with \ref addSource().
     583    ///Finally \ref start() will perform the actual path
     584    ///computation.
    611585
    612586    ///@{
     
    630604
    631605    ///Adds a new source node to the priority heap.
     606    ///
    632607    ///The optional second parameter is the initial distance of the node.
    633608    ///
    634     ///The function checks if the node has already been added to the heap and
     609    ///It checks if the node has already been added to the heap and
    635610    ///it is pushed to the heap only if either it was not in the heap
    636611    ///or the shortest path found till then is shorter than \c dst.
     
    651626    ///\return The processed node.
    652627    ///
    653     ///\warning The priority heap must not be empty.
     628    ///\warning The priority heap must not be empty!
    654629    Node processNextNode()
    655630    {
     
    682657    }
    683658
    684     ///The next node to be processed.
    685 
    686     ///Returns the next node to be processed or \c INVALID if the
    687     ///priority heap is empty.
    688     Node nextNode() const
     659    ///Next node to be processed.
     660
     661    ///Next node to be processed.
     662    ///
     663    ///\return The next node to be processed or INVALID if the priority heap
     664    /// is empty.
     665    Node nextNode()
    689666    {
    690667      return !_heap->empty()?_heap->top():INVALID;
     
    692669
    693670    ///\brief Returns \c false if there are nodes
    694     ///to be processed.
     671    ///to be processed in the priority heap
    695672    ///
    696673    ///Returns \c false if there are nodes
    697     ///to be processed in the priority heap.
    698     bool emptyQueue() const { return _heap->empty(); }
    699 
     674    ///to be processed in the priority heap
     675    bool emptyQueue() { return _heap->empty(); }
    700676    ///Returns the number of the nodes to be processed in the priority heap
    701677
    702     ///Returns the number of the nodes to be processed in the priority heap.
    703     ///
    704     int queueSize() const { return _heap->size(); }
     678    ///Returns the number of the nodes to be processed in the priority heap
     679    ///
     680    int queueSize() { return _heap->size(); }
    705681
    706682    ///Executes the algorithm.
     
    708684    ///Executes the algorithm.
    709685    ///
     686    ///\pre init() must be called and at least one node should be added
     687    ///with addSource() before using this function.
     688    ///
    710689    ///This method runs the %Dijkstra algorithm from the root node(s)
    711     ///in order to compute the shortest path to each node.
    712     ///
    713     ///The algorithm computes
    714     ///- the shortest path tree (forest),
    715     ///- the distance of each node from the root(s).
    716     ///
    717     ///\pre init() must be called and at least one root node should be
    718     ///added with addSource() before using this function.
    719     ///
    720     ///\note <tt>d.start()</tt> is just a shortcut of the following code.
    721     ///\code
    722     ///  while ( !d.emptyQueue() ) {
    723     ///    d.processNextNode();
    724     ///  }
    725     ///\endcode
     690    ///in order to
     691    ///compute the
     692    ///shortest path to each node. The algorithm computes
     693    ///- The shortest path tree.
     694    ///- The distance of each node from the root(s).
     695    ///
    726696    void start()
    727697    {
    728       while ( !emptyQueue() ) processNextNode();
    729     }
    730 
    731     ///Executes the algorithm until the given target node is reached.
    732 
    733     ///Executes the algorithm until the given target node is reached.
     698      while ( !_heap->empty() ) processNextNode();
     699    }
     700
     701    ///Executes the algorithm until \c dest is reached.
     702
     703    ///Executes the algorithm until \c dest is reached.
     704    ///
     705    ///\pre init() must be called and at least one node should be added
     706    ///with addSource() before using this function.
    734707    ///
    735708    ///This method runs the %Dijkstra algorithm from the root node(s)
    736     ///in order to compute the shortest path to \c dest.
    737     ///
    738     ///The algorithm computes
    739     ///- the shortest path to \c dest,
    740     ///- the distance of \c dest from the root(s).
    741     ///
    742     ///\pre init() must be called and at least one root node should be
    743     ///added with addSource() before using this function.
     709    ///in order to
     710    ///compute the
     711    ///shortest path to \c dest. The algorithm computes
     712    ///- The shortest path to \c  dest.
     713    ///- The distance of \c dest from the root(s).
     714    ///
    744715    void start(Node dest)
    745716    {
     
    752723    ///Executes the algorithm until a condition is met.
    753724    ///
    754     ///This method runs the %Dijkstra algorithm from the root node(s) in
    755     ///order to compute the shortest path to a node \c v with
    756     /// <tt>nm[v]</tt> true, if such a node can be found.
    757     ///
    758     ///\param nm A \c bool (or convertible) node map. The algorithm
     725    ///\pre init() must be called and at least one node should be added
     726    ///with addSource() before using this function.
     727    ///
     728    ///\param nm must be a bool (or convertible) node map. The algorithm
    759729    ///will stop when it reaches a node \c v with <tt>nm[v]</tt> true.
    760730    ///
    761731    ///\return The reached node \c v with <tt>nm[v]</tt> true or
    762732    ///\c INVALID if no such node was found.
    763     ///
    764     ///\pre init() must be called and at least one root node should be
    765     ///added with addSource() before using this function.
    766733    template<class NodeBoolMap>
    767734    Node start(const NodeBoolMap &nm)
     
    773740    }
    774741
    775     ///Runs the algorithm from the given node.
    776 
    777     ///This method runs the %Dijkstra algorithm from node \c s
    778     ///in order to compute the shortest path to each node.
    779     ///
    780     ///The algorithm computes
    781     ///- the shortest path tree,
    782     ///- the distance of each node from the root.
    783     ///
    784     ///\note <tt>d.run(s)</tt> is just a shortcut of the following code.
     742    ///Runs %Dijkstra algorithm from node \c s.
     743
     744    ///This method runs the %Dijkstra algorithm from a root node \c s
     745    ///in order to
     746    ///compute the
     747    ///shortest path to each node. The algorithm computes
     748    ///- The shortest path tree.
     749    ///- The distance of each node from the root.
     750    ///
     751    ///\note d.run(s) is just a shortcut of the following code.
    785752    ///\code
    786753    ///  d.init();
     
    796763    ///Finds the shortest path between \c s and \c t.
    797764
    798     ///This method runs the %Dijkstra algorithm from node \c s
    799     ///in order to compute the shortest path to \c t.
    800     ///
    801     ///\return The length of the shortest <tt>s</tt>--<tt>t</tt> path,
    802     ///if \c t is reachable form \c s, \c 0 otherwise.
    803     ///
    804     ///\note Apart from the return value, <tt>d.run(s,t)</tt> is just a
    805     ///shortcut of the following code.
     765    ///Finds the shortest path between \c s and \c t.
     766    ///
     767    ///\return The length of the shortest s---t path if there exists one,
     768    ///0 otherwise.
     769    ///\note Apart from the return value, d.run(s) is
     770    ///just a shortcut of the following code.
    806771    ///\code
    807772    ///  d.init();
     
    821786    ///The result of the %Dijkstra algorithm can be obtained using these
    822787    ///functions.\n
    823     ///Either \ref lemon::Dijkstra::run() "run()" or
    824     ///\ref lemon::Dijkstra::start() "start()" must be called before
    825     ///using them.
     788    ///Before the use of these functions,
     789    ///either run() or start() must be called.
    826790
    827791    ///@{
    828792
    829     ///The shortest path to a node.
    830 
    831     ///Returns the shortest path to a node.
    832     ///
    833     ///\warning \c t should be reachable from the root(s).
    834     ///
    835     ///\pre Either \ref run() or \ref start() must be called before
    836     ///using this function.
    837     Path path(Node t) const { return Path(*G, *_pred, t); }
    838 
    839     ///The distance of a node from the root(s).
    840 
    841     ///Returns the distance of a node from the root(s).
    842     ///
    843     ///\warning If node \c v is not reachable from the root(s), then
    844     ///the return value of this function is undefined.
    845     ///
    846     ///\pre Either \ref run() or \ref start() must be called before
    847     ///using this function.
     793    ///Gives back the shortest path.
     794
     795    ///Gives back the shortest path.
     796    ///\pre The \c t should be reachable from the source.
     797    Path path(Node t)
     798    {
     799      return Path(*G, *_pred, t);
     800    }
     801
     802    ///The distance of a node from the root.
     803
     804    ///Returns the distance of a node from the root.
     805    ///\pre \ref run() must be called before using this function.
     806    ///\warning If node \c v in unreachable from the root the return value
     807    ///of this funcion is undefined.
    848808    Value dist(Node v) const { return (*_dist)[v]; }
    849809
    850     ///Returns the 'previous arc' of the shortest path tree for a node.
    851 
    852     ///This function returns the 'previous arc' of the shortest path
    853     ///tree for the node \c v, i.e. it returns the last arc of a
    854     ///shortest path from the root(s) to \c v. It is \c INVALID if \c v
    855     ///is not reachable from the root(s) or if \c v is a root.
    856     ///
    857     ///The shortest path tree used here is equal to the shortest path
    858     ///tree used in \ref predNode().
    859     ///
    860     ///\pre Either \ref run() or \ref start() must be called before
    861     ///using this function.
     810    ///The current distance of a node from the root.
     811
     812    ///Returns the current distance of a node from the root.
     813    ///It may be decreased in the following processes.
     814    ///\pre \c node should be reached but not processed
     815    Value currentDist(Node v) const { return (*_heap)[v]; }
     816
     817    ///Returns the 'previous arc' of the shortest path tree.
     818
     819    ///For a node \c v it returns the 'previous arc' of the shortest path tree,
     820    ///i.e. it returns the last arc of a shortest path from the root to \c
     821    ///v. It is \ref INVALID
     822    ///if \c v is unreachable from the root or if \c v=s. The
     823    ///shortest path tree used here is equal to the shortest path tree used in
     824    ///\ref predNode().  \pre \ref run() must be called before using
     825    ///this function.
    862826    Arc predArc(Node v) const { return (*_pred)[v]; }
    863827
    864     ///Returns the 'previous node' of the shortest path tree for a node.
    865 
    866     ///This function returns the 'previous node' of the shortest path
    867     ///tree for the node \c v, i.e. it returns the last but one node
    868     ///from a shortest path from the root(s) to \c v. It is \c INVALID
    869     ///if \c v is not reachable from the root(s) or if \c v is a root.
    870     ///
    871     ///The shortest path tree used here is equal to the shortest path
    872     ///tree used in \ref predArc().
    873     ///
    874     ///\pre Either \ref run() or \ref start() must be called before
     828    ///Returns the 'previous node' of the shortest path tree.
     829
     830    ///For a node \c v it returns the 'previous node' of the shortest path tree,
     831    ///i.e. it returns the last but one node from a shortest path from the
     832    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
     833    ///\c v=s. The shortest path tree used here is equal to the shortest path
     834    ///tree used in \ref predArc().  \pre \ref run() must be called before
    875835    ///using this function.
    876836    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
    877837                                  G->source((*_pred)[v]); }
    878838
    879     ///\brief Returns a const reference to the node map that stores the
    880     ///distances of the nodes.
    881     ///
    882     ///Returns a const reference to the node map that stores the distances
    883     ///of the nodes calculated by the algorithm.
    884     ///
    885     ///\pre Either \ref run() or \ref init()
    886     ///must be called before using this function.
     839    ///Returns a reference to the NodeMap of distances.
     840
     841    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
     842    ///be called before using this function.
    887843    const DistMap &distMap() const { return *_dist;}
    888844
    889     ///\brief Returns a const reference to the node map that stores the
    890     ///predecessor arcs.
    891     ///
    892     ///Returns a const reference to the node map that stores the predecessor
    893     ///arcs, which form the shortest path tree.
    894     ///
    895     ///\pre Either \ref run() or \ref init()
    896     ///must be called before using this function.
     845    ///Returns a reference to the shortest path tree map.
     846
     847    ///Returns a reference to the NodeMap of the arcs of the
     848    ///shortest path tree.
     849    ///\pre \ref run() must be called before using this function.
    897850    const PredMap &predMap() const { return *_pred;}
    898851
    899     ///Checks if a node is reachable from the root(s).
    900 
    901     ///Returns \c true if \c v is reachable from the root(s).
    902     ///\pre Either \ref run() or \ref start()
    903     ///must be called before using this function.
    904     bool reached(Node v) const { return (*_heap_cross_ref)[v] !=
    905                                         Heap::PRE_HEAP; }
     852    ///Checks if a node is reachable from the root.
     853
     854    ///Returns \c true if \c v is reachable from the root.
     855    ///\warning The source nodes are inditated as unreached.
     856    ///\pre \ref run() must be called before using this function.
     857    ///
     858    bool reached(Node v) { return (*_heap_cross_ref)[v] != Heap::PRE_HEAP; }
    906859
    907860    ///Checks if a node is processed.
     
    909862    ///Returns \c true if \c v is processed, i.e. the shortest
    910863    ///path to \c v has already found.
    911     ///\pre Either \ref run() or \ref start()
    912     ///must be called before using this function.
    913     bool processed(Node v) const { return (*_heap_cross_ref)[v] ==
    914                                           Heap::POST_HEAP; }
    915 
    916     ///The current distance of a node from the root(s).
    917 
    918     ///Returns the current distance of a node from the root(s).
    919     ///It may be decreased in the following processes.
    920     ///\pre \c v should be reached but not processed.
    921     Value currentDist(Node v) const { return (*_heap)[v]; }
     864    ///\pre \ref run() must be called before using this function.
     865    ///
     866    bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; }
    922867
    923868    ///@}
     
    925870
    926871
    927   ///Default traits class of dijkstra() function.
    928 
    929   ///Default traits class of dijkstra() function.
    930   ///\tparam GR The type of the digraph.
    931   ///\tparam LM The type of the length map.
     872
     873
     874
     875  ///Default traits class of Dijkstra function.
     876
     877  ///Default traits class of Dijkstra function.
     878  ///\tparam GR Digraph type.
     879  ///\tparam LM Type of length map.
    932880  template<class GR, class LM>
    933881  struct DijkstraWizardDefaultTraits
    934882  {
    935     ///The type of the digraph the algorithm runs on.
     883    ///The digraph type the algorithm runs on.
    936884    typedef GR Digraph;
    937885    ///The type of the map that stores the arc lengths.
     
    940888    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
    941889    typedef LM LengthMap;
    942     ///The type of the length of the arcs.
     890    //The type of the length of the arcs.
    943891    typedef typename LM::Value Value;
    944 
    945892    /// Operation traits for Dijkstra algorithm.
    946893
    947     /// This class defines the operations that are used in the algorithm.
     894    /// It defines the used operation by the algorithm.
    948895    /// \see DijkstraDefaultOperationTraits
    949896    typedef DijkstraDefaultOperationTraits<Value> OperationTraits;
    950 
    951     /// The cross reference type used by the heap.
    952 
    953     /// The cross reference type used by the heap.
     897    ///The heap type used by Dijkstra algorithm.
     898
     899    /// The cross reference type used by heap.
     900
     901    /// The cross reference type used by heap.
    954902    /// Usually it is \c Digraph::NodeMap<int>.
    955903    typedef typename Digraph::template NodeMap<int> HeapCrossRef;
    956     ///Instantiates a \ref HeapCrossRef.
     904    ///Instantiates a HeapCrossRef.
    957905
    958906    ///This function instantiates a \ref HeapCrossRef.
    959     /// \param g is the digraph, to which we would like to define the
     907    /// \param G is the digraph, to which we would like to define the
    960908    /// HeapCrossRef.
    961909    /// \todo The digraph alone may be insufficient for the initialization
    962     static HeapCrossRef *createHeapCrossRef(const Digraph &g)
    963     {
    964       return new HeapCrossRef(g);
    965     }
    966 
    967     ///The heap type used by the Dijkstra algorithm.
    968 
    969     ///The heap type used by the Dijkstra algorithm.
     910    static HeapCrossRef *createHeapCrossRef(const GR &G)
     911    {
     912      return new HeapCrossRef(G);
     913    }
     914
     915    ///The heap type used by Dijkstra algorithm.
     916
     917    ///The heap type used by Dijkstra algorithm.
    970918    ///
    971919    ///\sa BinHeap
    972920    ///\sa Dijkstra
    973     typedef BinHeap<Value, typename Digraph::template NodeMap<int>,
     921    typedef BinHeap<typename LM::Value, typename GR::template NodeMap<int>,
    974922                    std::less<Value> > Heap;
    975923
    976     ///Instantiates a \ref Heap.
    977 
    978     ///This function instantiates a \ref Heap.
    979     /// \param r is the HeapCrossRef which is used.
    980     static Heap *createHeap(HeapCrossRef& r)
    981     {
    982       return new Heap(r);
    983     }
    984 
    985     ///\brief The type of the map that stores the predecessor
     924    static Heap *createHeap(HeapCrossRef& R)
     925    {
     926      return new Heap(R);
     927    }
     928
     929    ///\brief The type of the map that stores the last
    986930    ///arcs of the shortest paths.
    987931    ///
    988     ///The type of the map that stores the predecessor
     932    ///The type of the map that stores the last
    989933    ///arcs of the shortest paths.
    990934    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    991     typedef NullMap <typename Digraph::Node,typename Digraph::Arc> PredMap;
    992     ///Instantiates a \ref PredMap.
     935    ///
     936    typedef NullMap <typename GR::Node,typename GR::Arc> PredMap;
     937    ///Instantiates a PredMap.
    993938
    994939    ///This function instantiates a \ref PredMap.
    995     ///\param g is the digraph, to which we would like to define the
    996     ///\ref PredMap.
    997     ///\todo The digraph alone may be insufficient to initialize
     940    ///\param g is the digraph, to which we would like to define the PredMap.
     941    ///\todo The digraph alone may be insufficient for the initialization
    998942#ifdef DOXYGEN
    999     static PredMap *createPredMap(const Digraph &g)
     943    static PredMap *createPredMap(const GR &g)
    1000944#else
    1001     static PredMap *createPredMap(const Digraph &)
     945    static PredMap *createPredMap(const GR &)
    1002946#endif
    1003947    {
    1004948      return new PredMap();
    1005949    }
    1006 
    1007     ///The type of the map that indicates which nodes are processed.
    1008 
    1009     ///The type of the map that indicates which nodes are processed.
     950    ///The type of the map that stores whether a nodes is processed.
     951
     952    ///The type of the map that stores whether a nodes is processed.
    1010953    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    1011954    ///By default it is a NullMap.
     
    1014957    ///\todo named parameter to set this type, function to read and write.
    1015958    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    1016     ///Instantiates a \ref ProcessedMap.
     959    ///Instantiates a ProcessedMap.
    1017960
    1018961    ///This function instantiates a \ref ProcessedMap.
    1019962    ///\param g is the digraph, to which
    1020     ///we would like to define the \ref ProcessedMap.
     963    ///we would like to define the \ref ProcessedMap
    1021964#ifdef DOXYGEN
    1022     static ProcessedMap *createProcessedMap(const Digraph &g)
     965    static ProcessedMap *createProcessedMap(const GR &g)
    1023966#else
    1024     static ProcessedMap *createProcessedMap(const Digraph &)
     967    static ProcessedMap *createProcessedMap(const GR &)
    1025968#endif
    1026969    {
    1027970      return new ProcessedMap();
    1028971    }
    1029 
    1030     ///The type of the map that stores the distances of the nodes.
    1031 
    1032     ///The type of the map that stores the distances of the nodes.
     972    ///The type of the map that stores the dists of the nodes.
     973
     974    ///The type of the map that stores the dists of the nodes.
    1033975    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    1034     typedef NullMap<typename Digraph::Node,Value> DistMap;
    1035     ///Instantiates a \ref DistMap.
     976    ///
     977    typedef NullMap<typename Digraph::Node,typename LM::Value> DistMap;
     978    ///Instantiates a DistMap.
    1036979
    1037980    ///This function instantiates a \ref DistMap.
     
    1039982    ///the \ref DistMap
    1040983#ifdef DOXYGEN
    1041     static DistMap *createDistMap(const Digraph &g)
     984    static DistMap *createDistMap(const GR &g)
    1042985#else
    1043     static DistMap *createDistMap(const Digraph &)
     986    static DistMap *createDistMap(const GR &)
    1044987#endif
    1045988    {
     
    1048991  };
    1049992
    1050   /// Default traits class used by \ref DijkstraWizard
     993  /// Default traits used by \ref DijkstraWizard
    1051994
    1052995  /// To make it easier to use Dijkstra algorithm
    1053   /// we have created a wizard class.
     996  ///we have created a wizard class.
    1054997  /// This \ref DijkstraWizard class needs default traits,
    1055   /// as well as the \ref Dijkstra class.
     998  ///as well as the \ref Dijkstra class.
    1056999  /// The \ref DijkstraWizardBase is a class to be the default traits of the
    10571000  /// \ref DijkstraWizard class.
     
    10601003  class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM>
    10611004  {
     1005
    10621006    typedef DijkstraWizardDefaultTraits<GR,LM> Base;
    10631007  protected:
    1064     //The type of the nodes in the digraph.
     1008    /// Type of the nodes in the digraph.
    10651009    typedef typename Base::Digraph::Node Node;
    10661010
    1067     //Pointer to the digraph the algorithm runs on.
     1011    /// Pointer to the underlying digraph.
    10681012    void *_g;
    1069     //Pointer to the length map
     1013    /// Pointer to the length map
    10701014    void *_length;
    1071     //Pointer to the map of predecessors arcs.
     1015    ///Pointer to the map of predecessors arcs.
    10721016    void *_pred;
    1073     //Pointer to the map of distances.
     1017    ///Pointer to the map of distances.
    10741018    void *_dist;
    1075     //Pointer to the source node.
     1019    ///Pointer to the source node.
    10761020    Node _source;
    10771021
    1078   public:
     1022    public:
    10791023    /// Constructor.
    10801024
     
    10891033    /// listed in the parameters list.
    10901034    /// Others are initiated to 0.
    1091     /// \param g The digraph the algorithm runs on.
    1092     /// \param l The length map.
    1093     /// \param s The source node.
     1035    /// \param g is the initial value of  \ref _g
     1036    /// \param l is the initial value of  \ref _length
     1037    /// \param s is the initial value of  \ref _source
    10941038    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
    10951039      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
     
    10991043  };
    11001044
    1101   /// Auxiliary class for the function type interface of Dijkstra algorithm.
    1102 
    1103   /// This auxiliary class is created to implement the function type
    1104   /// interface of \ref Dijkstra algorithm. It uses the functions and features
    1105   /// of the plain \ref Dijkstra, but it is much simpler to use it.
    1106   /// It should only be used through the \ref dijkstra() function, which makes
    1107   /// it easier to use the algorithm.
     1045  /// A class to make the usage of Dijkstra algorithm easier
     1046
     1047  /// This class is created to make it easier to use Dijkstra algorithm.
     1048  /// It uses the functions and features of the plain \ref Dijkstra,
     1049  /// but it is much simpler to use it.
    11081050  ///
    11091051  /// Simplicity means that the way to change the types defined
     
    11141056  /// the original class by using the ::
    11151057  /// operator. In the case of \ref DijkstraWizard only
    1116   /// a function have to be called, and it will
     1058  /// a function have to be called and it will
    11171059  /// return the needed class.
    11181060  ///
    1119   /// It does not have own \ref run() method. When its \ref run() method
    1120   /// is called, it initiates a plain \ref Dijkstra object, and calls the
    1121   /// \ref Dijkstra::run() method of it.
     1061  /// It does not have own \ref run method. When its \ref run method is called
     1062  /// it initiates a plain \ref Dijkstra class, and calls the \ref
     1063  /// Dijkstra::run method of it.
    11221064  template<class TR>
    11231065  class DijkstraWizard : public TR
     
    11251067    typedef TR Base;
    11261068
    1127     ///The type of the digraph the algorithm runs on.
     1069    ///The type of the underlying digraph.
    11281070    typedef typename TR::Digraph Digraph;
    1129 
     1071    //\e
    11301072    typedef typename Digraph::Node Node;
     1073    //\e
    11311074    typedef typename Digraph::NodeIt NodeIt;
     1075    //\e
    11321076    typedef typename Digraph::Arc Arc;
     1077    //\e
    11331078    typedef typename Digraph::OutArcIt OutArcIt;
    11341079
     
    11371082    ///The type of the length of the arcs.
    11381083    typedef typename LengthMap::Value Value;
    1139     ///\brief The type of the map that stores the predecessor
     1084    ///\brief The type of the map that stores the last
    11401085    ///arcs of the shortest paths.
    11411086    typedef typename TR::PredMap PredMap;
    1142     ///The type of the map that stores the distances of the nodes.
     1087    ///The type of the map that stores the dists of the nodes.
    11431088    typedef typename TR::DistMap DistMap;
    1144     ///The type of the map that indicates which nodes are processed.
    1145     typedef typename TR::ProcessedMap ProcessedMap;
    11461089    ///The heap type used by the dijkstra algorithm.
    11471090    typedef typename TR::Heap Heap;
    1148 
    11491091  public:
    1150 
    11511092    /// Constructor.
    11521093    DijkstraWizard() : TR() {}
     
    11641105    ~DijkstraWizard() {}
    11651106
    1166     ///Runs Dijkstra algorithm from a source node.
    1167 
    1168     ///Runs Dijkstra algorithm from a source node.
    1169     ///The node can be given with the \ref source() function.
     1107    ///Runs Dijkstra algorithm from a given node.
     1108
     1109    ///Runs Dijkstra algorithm from a given node.
     1110    ///The node can be given by the \ref source function.
    11701111    void run()
    11711112    {
     
    11891130    }
    11901131
    1191     /// Sets the source node, from which the Dijkstra algorithm runs.
    1192 
    1193     /// Sets the source node, from which the Dijkstra algorithm runs.
    1194     /// \param s is the source node.
    1195     DijkstraWizard<TR> &source(Node s)
    1196     {
    1197       Base::_source=s;
    1198       return *this;
    1199     }
    1200 
    12011132    template<class T>
    12021133    struct DefPredMapBase : public Base {
     
    12051136      DefPredMapBase(const TR &b) : TR(b) {}
    12061137    };
     1138
    12071139    ///\brief \ref named-templ-param "Named parameter"
    1208     ///for setting \ref PredMap object.
    1209     ///
    1210     ///\ref named-templ-param "Named parameter"
    1211     ///for setting \ref PredMap object.
     1140    ///function for setting PredMap type
     1141    ///
     1142    /// \ref named-templ-param "Named parameter"
     1143    ///function for setting PredMap type
     1144    ///
    12121145    template<class T>
    12131146    DijkstraWizard<DefPredMapBase<T> > predMap(const T &t)
     
    12151148      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    12161149      return DijkstraWizard<DefPredMapBase<T> >(*this);
    1217     }
    1218 
    1219     template<class T>
    1220     struct DefProcessedMapBase : public Base {
    1221       typedef T ProcessedMap;
    1222       static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
    1223       DefProcessedMapBase(const TR &b) : TR(b) {}
    1224     };
    1225     ///\brief \ref named-templ-param "Named parameter"
    1226     ///for setting \ref ProcessedMap object.
    1227     ///
    1228     /// \ref named-templ-param "Named parameter"
    1229     ///for setting \ref ProcessedMap object.
    1230     template<class T>
    1231     DijkstraWizard<DefProcessedMapBase<T> > processedMap(const T &t)
    1232     {
    1233       Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    1234       return DijkstraWizard<DefProcessedMapBase<T> >(*this);
    12351150    }
    12361151
     
    12411156      DefDistMapBase(const TR &b) : TR(b) {}
    12421157    };
     1158
    12431159    ///\brief \ref named-templ-param "Named parameter"
    1244     ///for setting \ref DistMap object.
    1245     ///
    1246     ///\ref named-templ-param "Named parameter"
    1247     ///for setting \ref DistMap object.
     1160    ///function for setting DistMap type
     1161    ///
     1162    /// \ref named-templ-param "Named parameter"
     1163    ///function for setting DistMap type
     1164    ///
    12481165    template<class T>
    12491166    DijkstraWizard<DefDistMapBase<T> > distMap(const T &t)
     
    12511168      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    12521169      return DijkstraWizard<DefDistMapBase<T> >(*this);
     1170    }
     1171
     1172    /// Sets the source node, from which the Dijkstra algorithm runs.
     1173
     1174    /// Sets the source node, from which the Dijkstra algorithm runs.
     1175    /// \param s is the source node.
     1176    DijkstraWizard<TR> &source(Node s)
     1177    {
     1178      Base::_source=s;
     1179      return *this;
    12531180    }
    12541181
Note: See TracChangeset for help on using the changeset viewer.