COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bfs.h

    r220 r301  
    2222///\ingroup search
    2323///\file
    24 ///\brief Bfs algorithm.
     24///\brief BFS algorithm.
    2525
    2626#include <lemon/list_graph.h>
     
    2929#include <lemon/error.h>
    3030#include <lemon/maps.h>
     31#include <lemon/path.h>
    3132
    3233namespace lemon {
    33 
    34 
    3534
    3635  ///Default traits class of Bfs class.
     
    4140  struct BfsDefaultTraits
    4241  {
    43     ///The digraph type the algorithm runs on.
     42    ///The type of the digraph the algorithm runs on.
    4443    typedef GR Digraph;
    45     ///\brief The type of the map that stores the last
     44
     45    ///\brief The type of the map that stores the predecessor
    4646    ///arcs of the shortest paths.
    4747    ///
    48     ///The type of the map that stores the last
     48    ///The type of the map that stores the predecessor
    4949    ///arcs of the shortest paths.
    5050    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    51     ///
    52     typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
     51    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    5352    ///Instantiates a PredMap.
    5453
    55     ///This function instantiates a \ref PredMap.
    56     ///\param G is the digraph, to which we would like to define the PredMap.
    57     ///\todo The digraph alone may be insufficient to initialize
    58     static PredMap *createPredMap(const GR &G)
    59     {
    60       return new PredMap(G);
    61     }
     54    ///This function instantiates a PredMap.
     55    ///\param g is the digraph, to which we would like to define the
     56    ///PredMap.
     57    static PredMap *createPredMap(const Digraph &g)
     58    {
     59      return new PredMap(g);
     60    }
     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     ///\todo named parameter to set this type, function to read and write.
    6766    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    6867    ///Instantiates a ProcessedMap.
    6968
    70     ///This function instantiates a \ref ProcessedMap.
     69    ///This function instantiates a ProcessedMap.
    7170    ///\param g is the digraph, to which
    72     ///we would like to define the \ref ProcessedMap
     71    ///we would like to define the ProcessedMap
    7372#ifdef DOXYGEN
    74     static ProcessedMap *createProcessedMap(const GR &g)
     73    static ProcessedMap *createProcessedMap(const Digraph &g)
    7574#else
    76     static ProcessedMap *createProcessedMap(const GR &)
     75    static ProcessedMap *createProcessedMap(const Digraph &)
    7776#endif
    7877    {
    7978      return new ProcessedMap();
    8079    }
     80
    8181    ///The type of the map that indicates which nodes are reached.
    8282
    8383    ///The type of the map that indicates which nodes are reached.
    84     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    85     ///\todo named parameter to set this type, function to read and write.
     84    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    8685    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    8786    ///Instantiates a ReachedMap.
    8887
    89     ///This function instantiates a \ref ReachedMap.
    90     ///\param G is the digraph, to which
    91     ///we would like to define the \ref ReachedMap.
    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.
     88    ///This function instantiates a ReachedMap.
     89    ///\param g is the digraph, to which
     90    ///we would like to define the ReachedMap.
     91    static ReachedMap *createReachedMap(const Digraph &g)
     92    {
     93      return new ReachedMap(g);
     94    }
     95
     96    ///The type of the map that stores the distances of the nodes.
     97
     98    ///The type of the map that stores the distances of the nodes.
    9999    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    100     ///
    101100    typedef typename Digraph::template NodeMap<int> DistMap;
    102101    ///Instantiates a DistMap.
    103102
    104     ///This function instantiates a \ref DistMap.
    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);
     103    ///This function instantiates a DistMap.
     104    ///\param g is the digraph, to which we would like to define the
     105    ///DistMap.
     106    static DistMap *createDistMap(const Digraph &g)
     107    {
     108      return new DistMap(g);
    110109    }
    111110  };
     
    116115  ///This class provides an efficient implementation of the %BFS algorithm.
    117116  ///
    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.
     117  ///There is also a \ref bfs() "function-type interface" for the BFS
     118  ///algorithm, which is convenient in the simplier cases and it can be
     119  ///used easier.
     120  ///
     121  ///\tparam GR The type of the digraph the algorithm runs on.
     122  ///The default value is \ref ListDigraph. The value of GR is not used
     123  ///directly by \ref Bfs, it is only passed to \ref BfsDefaultTraits.
    121124  ///\tparam TR Traits class to set various data types used by the algorithm.
    122125  ///The default traits class is
     
    124127  ///See \ref BfsDefaultTraits for the documentation of
    125128  ///a Bfs traits class.
    126 
    127129#ifdef DOXYGEN
    128130  template <typename GR,
     
    134136  class Bfs {
    135137  public:
    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      */
    142     class UninitializedParameter : public lemon::UninitializedParameter {
    143     public:
    144       virtual const char* what() const throw() {
    145         return "lemon::Bfs::UninitializedParameter";
    146       }
    147     };
    148 
     138
     139    ///The type of the digraph the algorithm runs on.
     140    typedef typename TR::Digraph Digraph;
     141
     142    ///\brief The type of the map that stores the predecessor arcs of the
     143    ///shortest paths.
     144    typedef typename TR::PredMap PredMap;
     145    ///The type of the map that stores the distances of the nodes.
     146    typedef typename TR::DistMap DistMap;
     147    ///The type of the map that indicates which nodes are reached.
     148    typedef typename TR::ReachedMap ReachedMap;
     149    ///The type of the map that indicates which nodes are processed.
     150    typedef typename TR::ProcessedMap ProcessedMap;
     151    ///The type of the paths.
     152    typedef PredMapPath<Digraph, PredMap> Path;
     153
     154    ///The traits class.
    149155    typedef TR Traits;
    150     ///The type of the underlying digraph.
    151     typedef typename TR::Digraph Digraph;
    152 
    153     ///\brief The type of the map that stores the last
    154     ///arcs of the shortest paths.
    155     typedef typename TR::PredMap PredMap;
    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.
    161     typedef typename TR::DistMap DistMap;
     156
    162157  private:
    163158
     
    167162    typedef typename Digraph::OutArcIt OutArcIt;
    168163
    169     /// Pointer to the underlying digraph.
     164    //Pointer to the underlying digraph.
    170165    const Digraph *G;
    171     ///Pointer to the map of predecessors arcs.
     166    //Pointer to the map of predecessor arcs.
    172167    PredMap *_pred;
    173     ///Indicates if \ref _pred is locally allocated (\c true) or not.
     168    //Indicates if _pred is locally allocated (true) or not.
    174169    bool local_pred;
    175     ///Pointer to the map of distances.
     170    //Pointer to the map of distances.
    176171    DistMap *_dist;
    177     ///Indicates if \ref _dist is locally allocated (\c true) or not.
     172    //Indicates if _dist is locally allocated (true) or not.
    178173    bool local_dist;
    179     ///Pointer to the map of reached status of the nodes.
     174    //Pointer to the map of reached status of the nodes.
    180175    ReachedMap *_reached;
    181     ///Indicates if \ref _reached is locally allocated (\c true) or not.
     176    //Indicates if _reached is locally allocated (true) or not.
    182177    bool local_reached;
    183     ///Pointer to the map of processed status of the nodes.
     178    //Pointer to the map of processed status of the nodes.
    184179    ProcessedMap *_processed;
    185     ///Indicates if \ref _processed is locally allocated (\c true) or not.
     180    //Indicates if _processed is locally allocated (true) or not.
    186181    bool local_processed;
    187182
     
    190185    int _curr_dist;
    191186
    192     ///Creates the maps if necessary.
    193 
    194     ///\todo Better memory allocation (instead of new).
     187    //Creates the maps if necessary.
    195188    void create_maps()
    196189    {
     
    226219
    227220    template <class T>
    228     struct DefPredMapTraits : public Traits {
     221    struct SetPredMapTraits : public Traits {
    229222      typedef T PredMap;
    230223      static PredMap *createPredMap(const Digraph &)
    231224      {
    232         throw UninitializedParameter();
     225        LEMON_ASSERT(false, "PredMap is not initialized");
     226        return 0; // ignore warnings
    233227      }
    234228    };
    235229    ///\brief \ref named-templ-param "Named parameter" for setting
    236     ///PredMap type
    237     ///
    238     ///\ref named-templ-param "Named parameter" for setting PredMap type
    239     ///
     230    ///PredMap type.
     231    ///
     232    ///\ref named-templ-param "Named parameter" for setting
     233    ///PredMap type.
    240234    template <class T>
    241     struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {
    242       typedef Bfs< Digraph, DefPredMapTraits<T> > Create;
     235    struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > {
     236      typedef Bfs< Digraph, SetPredMapTraits<T> > Create;
    243237    };
    244238
    245239    template <class T>
    246     struct DefDistMapTraits : public Traits {
     240    struct SetDistMapTraits : public Traits {
    247241      typedef T DistMap;
    248242      static DistMap *createDistMap(const Digraph &)
    249243      {
    250         throw UninitializedParameter();
     244        LEMON_ASSERT(false, "DistMap is not initialized");
     245        return 0; // ignore warnings
    251246      }
    252247    };
    253248    ///\brief \ref named-templ-param "Named parameter" for setting
    254     ///DistMap type
    255     ///
    256     ///\ref named-templ-param "Named parameter" for setting DistMap type
    257     ///
     249    ///DistMap type.
     250    ///
     251    ///\ref named-templ-param "Named parameter" for setting
     252    ///DistMap type.
    258253    template <class T>
    259     struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > {
    260       typedef Bfs< Digraph, DefDistMapTraits<T> > Create;
     254    struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > {
     255      typedef Bfs< Digraph, SetDistMapTraits<T> > Create;
    261256    };
    262257
    263258    template <class T>
    264     struct DefReachedMapTraits : public Traits {
     259    struct SetReachedMapTraits : public Traits {
    265260      typedef T ReachedMap;
    266261      static ReachedMap *createReachedMap(const Digraph &)
    267262      {
    268         throw UninitializedParameter();
     263        LEMON_ASSERT(false, "ReachedMap is not initialized");
     264        return 0; // ignore warnings
    269265      }
    270266    };
    271267    ///\brief \ref named-templ-param "Named parameter" for setting
    272     ///ReachedMap type
    273     ///
    274     ///\ref named-templ-param "Named parameter" for setting ReachedMap type
    275     ///
     268    ///ReachedMap type.
     269    ///
     270    ///\ref named-templ-param "Named parameter" for setting
     271    ///ReachedMap type.
    276272    template <class T>
    277     struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > {
    278       typedef Bfs< Digraph, DefReachedMapTraits<T> > Create;
     273    struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > {
     274      typedef Bfs< Digraph, SetReachedMapTraits<T> > Create;
    279275    };
    280276
    281277    template <class T>
    282     struct DefProcessedMapTraits : public Traits {
     278    struct SetProcessedMapTraits : public Traits {
    283279      typedef T ProcessedMap;
    284280      static ProcessedMap *createProcessedMap(const Digraph &)
    285281      {
    286         throw UninitializedParameter();
     282        LEMON_ASSERT(false, "ProcessedMap is not initialized");
     283        return 0; // ignore warnings
    287284      }
    288285    };
    289286    ///\brief \ref named-templ-param "Named parameter" for setting
    290     ///ProcessedMap type
    291     ///
    292     ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
    293     ///
     287    ///ProcessedMap type.
     288    ///
     289    ///\ref named-templ-param "Named parameter" for setting
     290    ///ProcessedMap type.
    294291    template <class T>
    295     struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits<T> > {
    296       typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create;
     292    struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > {
     293      typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create;
    297294    };
    298295
    299     struct DefDigraphProcessedMapTraits : public Traits {
     296    struct SetStandardProcessedMapTraits : public Traits {
    300297      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    301       static ProcessedMap *createProcessedMap(const Digraph &G)
     298      static ProcessedMap *createProcessedMap(const Digraph &g)
    302299      {
    303         return new ProcessedMap(G);
     300        return new ProcessedMap(g);
     301        return 0; // ignore warnings
    304302      }
    305303    };
    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>.
     304    ///\brief \ref named-templ-param "Named parameter" for setting
     305    ///ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
     306    ///
     307    ///\ref named-templ-param "Named parameter" for setting
     308    ///ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.
    311309    ///If you don't set it explicitly, it will be automatically allocated.
    312     template <class T>
    313     struct DefProcessedMapToBeDefaultMap :
    314       public Bfs< Digraph, DefDigraphProcessedMapTraits> {
    315       typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create;
     310    struct SetStandardProcessedMap :
     311      public Bfs< Digraph, SetStandardProcessedMapTraits > {
     312      typedef Bfs< Digraph, SetStandardProcessedMapTraits > Create;
    316313    };
    317314
     
    322319    ///Constructor.
    323320
    324     ///\param _G the digraph the algorithm will run on.
    325     ///
    326     Bfs(const Digraph& _G) :
    327       G(&_G),
     321    ///Constructor.
     322    ///\param g The digraph the algorithm runs on.
     323    Bfs(const Digraph &g) :
     324      G(&g),
    328325      _pred(NULL), local_pred(false),
    329326      _dist(NULL), local_dist(false),
     
    341338    }
    342339
    343     ///Sets the map storing the predecessor arcs.
    344 
    345     ///Sets the map storing the predecessor arcs.
     340    ///Sets the map that stores the predecessor arcs.
     341
     342    ///Sets the map that stores the predecessor arcs.
    346343    ///If you don't use this function before calling \ref run(),
    347344    ///it will allocate one. The destructor deallocates this
     
    358355    }
    359356
    360     ///Sets the map indicating the reached nodes.
    361 
    362     ///Sets the map indicating the reached nodes.
     357    ///Sets the map that indicates which nodes are reached.
     358
     359    ///Sets the map that indicates which nodes are reached.
    363360    ///If you don't use this function before calling \ref run(),
    364361    ///it will allocate one. The destructor deallocates this
     
    375372    }
    376373
    377     ///Sets the map indicating the processed nodes.
    378 
    379     ///Sets the map indicating the processed nodes.
     374    ///Sets the map that indicates which nodes are processed.
     375
     376    ///Sets the map that indicates which nodes are processed.
    380377    ///If you don't use this function before calling \ref run(),
    381378    ///it will allocate one. The destructor deallocates this
     
    392389    }
    393390
    394     ///Sets the map storing the distances calculated by the algorithm.
    395 
    396     ///Sets the map storing the distances calculated by the algorithm.
     391    ///Sets the map that stores the distances of the nodes.
     392
     393    ///Sets the map that stores the distances of the nodes calculated by
     394    ///the algorithm.
    397395    ///If you don't use this function before calling \ref run(),
    398396    ///it will allocate one. The destructor deallocates this
     
    410408
    411409  public:
     410
    412411    ///\name Execution control
    413412    ///The simplest way to execute the algorithm is to use
    414     ///one of the member functions called \c run(...).
     413    ///one of the member functions called \ref lemon::Bfs::run() "run()".
    415414    ///\n
    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.
     415    ///If you need more control on the execution, first you must call
     416    ///\ref lemon::Bfs::init() "init()", then you can add several source
     417    ///nodes with \ref lemon::Bfs::addSource() "addSource()".
     418    ///Finally \ref lemon::Bfs::start() "start()" will perform the
     419    ///actual path computation.
    421420
    422421    ///@{
    423422
    424     ///\brief Initializes the internal data structures.
    425     ///
     423    ///Initializes the internal data structures.
     424
    426425    ///Initializes the internal data structures.
    427426    ///
     
    461460    ///\return The processed node.
    462461    ///
    463     ///\warning The queue must not be empty!
     462    ///\pre The queue must not be empty.
    464463    Node processNextNode()
    465464    {
     
    483482    ///Processes the next node.
    484483
    485     ///Processes the next node. And checks that the given target node
     484    ///Processes the next node and checks if the given target node
    486485    ///is reached. If the target node is reachable from the processed
    487     ///node then the reached parameter will be set true. The reached
    488     ///parameter should be initially false.
     486    ///node, then the \c reach parameter will be set to \c true.
    489487    ///
    490488    ///\param target The target node.
    491     ///\retval reach Indicates that the target node is reached.
     489    ///\retval reach Indicates if the target node is reached.
     490    ///It should be initially \c false.
     491    ///
    492492    ///\return The processed node.
    493493    ///
    494     ///\warning The queue must not be empty!
     494    ///\pre The queue must not be empty.
    495495    Node processNextNode(Node target, bool& reach)
    496496    {
     
    515515    ///Processes the next node.
    516516
    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.
     517    ///Processes the next node and checks if at least one of reached
     518    ///nodes has \c true value in the \c nm node map. If one node
     519    ///with \c true value is reachable from the processed node, then the
     520    ///\c rnode parameter will be set to the first of such nodes.
     521    ///
     522    ///\param nm A \c bool (or convertible) node map that indicates the
     523    ///possible targets.
    523524    ///\retval rnode The reached target node.
     525    ///It should be initially \c INVALID.
     526    ///
    524527    ///\return The processed node.
    525528    ///
    526     ///\warning The queue must not be empty!
     529    ///\pre The queue must not be empty.
    527530    template<class NM>
    528531    Node processNextNode(const NM& nm, Node& rnode)
     
    546549    }
    547550
    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()
     551    ///The next node to be processed.
     552
     553    ///Returns the next node to be processed or \c INVALID if the queue
     554    ///is empty.
     555    Node nextNode() const
    555556    {
    556557      return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID;
     
    558559
    559560    ///\brief Returns \c false if there are nodes
    560     ///to be processed in the queue
     561    ///to be processed.
    561562    ///
    562563    ///Returns \c false if there are nodes
    563     ///to be processed in the queue
    564     bool emptyQueue() { return _queue_tail==_queue_head; }
     564    ///to be processed in the queue.
     565    bool emptyQueue() const { return _queue_tail==_queue_head; }
     566
    565567    ///Returns the number of the nodes to be processed.
    566568
    567569    ///Returns the number of the nodes to be processed in the queue.
    568     int queueSize() { return _queue_head-_queue_tail; }
     570    int queueSize() const { return _queue_head-_queue_tail; }
    569571
    570572    ///Executes the algorithm.
     
    572574    ///Executes the algorithm.
    573575    ///
    574     ///\pre init() must be called and at least one node should be added
    575     ///with addSource() before using this function.
    576     ///
    577576    ///This method runs the %BFS algorithm from the root node(s)
    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).
     577    ///in order to compute the shortest path to each node.
     578    ///
     579    ///The algorithm computes
     580    ///- the shortest path tree (forest),
     581    ///- the distance of each node from the root(s).
     582    ///
     583    ///\pre init() must be called and at least one root node should be
     584    ///added with addSource() before using this function.
     585    ///
     586    ///\note <tt>b.start()</tt> is just a shortcut of the following code.
     587    ///\code
     588    ///  while ( !b.emptyQueue() ) {
     589    ///    b.processNextNode();
     590    ///  }
     591    ///\endcode
    583592    void start()
    584593    {
     
    586595    }
    587596
    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.
     597    ///Executes the algorithm until the given target node is reached.
     598
     599    ///Executes the algorithm until the given target node is reached.
    594600    ///
    595601    ///This method runs the %BFS algorithm from the root node(s)
    596     ///in order to compute the shortest path to \c dest.
     602    ///in order to compute the shortest path to \c t.
     603    ///
    597604    ///The algorithm computes
    598     ///- The shortest path to \c  dest.
    599     ///- The distance of \c dest from the root(s).
    600     void start(Node dest)
     605    ///- the shortest path to \c t,
     606    ///- the distance of \c t from the root(s).
     607    ///
     608    ///\pre init() must be called and at least one root node should be
     609    ///added with addSource() before using this function.
     610    ///
     611    ///\note <tt>b.start(t)</tt> is just a shortcut of the following code.
     612    ///\code
     613    ///  bool reach = false;
     614    ///  while ( !b.emptyQueue() && !reach ) {
     615    ///    b.processNextNode(t, reach);
     616    ///  }
     617    ///\endcode
     618    void start(Node t)
    601619    {
    602620      bool reach = false;
    603       while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
     621      while ( !emptyQueue() && !reach ) processNextNode(t, reach);
    604622    }
    605623
     
    608626    ///Executes the algorithm until a condition is met.
    609627    ///
    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.
     628    ///This method runs the %BFS algorithm from the root node(s) in
     629    ///order to compute the shortest path to a node \c v with
     630    /// <tt>nm[v]</tt> true, if such a node can be found.
     631    ///
     632    ///\param nm A \c bool (or convertible) node map. The algorithm
     633    ///will stop when it reaches a node \c v with <tt>nm[v]</tt> true.
    616634    ///
    617635    ///\return The reached node \c v with <tt>nm[v]</tt> true or
    618636    ///\c INVALID if no such node was found.
    619     template<class NM>
    620     Node start(const NM &nm)
     637    ///
     638    ///\pre init() must be called and at least one root node should be
     639    ///added with addSource() before using this function.
     640    ///
     641    ///\note <tt>b.start(nm)</tt> is just a shortcut of the following code.
     642    ///\code
     643    ///  Node rnode = INVALID;
     644    ///  while ( !b.emptyQueue() && rnode == INVALID ) {
     645    ///    b.processNextNode(nm, rnode);
     646    ///  }
     647    ///  return rnode;
     648    ///\endcode
     649    template<class NodeBoolMap>
     650    Node start(const NodeBoolMap &nm)
    621651    {
    622652      Node rnode = INVALID;
     
    627657    }
    628658
    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.
     659    ///Runs the algorithm from the given source node.
     660
     661    ///This method runs the %BFS algorithm from node \c s
     662    ///in order to compute the shortest path to each node.
     663    ///
     664    ///The algorithm computes
     665    ///- the shortest path tree,
     666    ///- the distance of each node from the root.
     667    ///
     668    ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
    639669    ///\code
    640670    ///  b.init();
     
    650680    ///Finds the shortest path between \c s and \c t.
    651681
    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.
     682    ///This method runs the %BFS algorithm from node \c s
     683    ///in order to compute the shortest path to node \c t
     684    ///(it stops searching when \c t is processed).
     685    ///
     686    ///\return \c true if \c t is reachable form \c s.
     687    ///
     688    ///\note Apart from the return value, <tt>b.run(s,t)</tt> is just a
     689    ///shortcut of the following code.
    658690    ///\code
    659691    ///  b.init();
     
    661693    ///  b.start(t);
    662694    ///\endcode
    663     int run(Node s,Node t) {
     695    bool run(Node s,Node t) {
    664696      init();
    665697      addSource(s);
    666698      start(t);
    667       return reached(t) ? _curr_dist : 0;
     699      return reached(t);
     700    }
     701
     702    ///Runs the algorithm to visit all nodes in the digraph.
     703
     704    ///This method runs the %BFS algorithm in order to
     705    ///compute the shortest path to each node.
     706    ///
     707    ///The algorithm computes
     708    ///- the shortest path tree (forest),
     709    ///- the distance of each node from the root(s).
     710    ///
     711    ///\note <tt>b.run(s)</tt> is just a shortcut of the following code.
     712    ///\code
     713    ///  b.init();
     714    ///  for (NodeIt n(gr); n != INVALID; ++n) {
     715    ///    if (!b.reached(n)) {
     716    ///      b.addSource(n);
     717    ///      b.start();
     718    ///    }
     719    ///  }
     720    ///\endcode
     721    void run() {
     722      init();
     723      for (NodeIt n(*G); n != INVALID; ++n) {
     724        if (!reached(n)) {
     725          addSource(n);
     726          start();
     727        }
     728      }
    668729    }
    669730
     
    673734    ///The result of the %BFS algorithm can be obtained using these
    674735    ///functions.\n
    675     ///Before the use of these functions,
    676     ///either run() or start() must be calleb.
     736    ///Either \ref lemon::Bfs::run() "run()" or \ref lemon::Bfs::start()
     737    ///"start()" must be called before using them.
    677738
    678739    ///@{
    679740
    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     }
     741    ///The shortest path to a node.
     742
     743    ///Returns the shortest path to a node.
     744    ///
     745    ///\warning \c t should be reachable from the root(s).
     746    ///
     747    ///\pre Either \ref run() or \ref start() must be called before
     748    ///using this function.
     749    Path path(Node t) const { return Path(*G, *_pred, t); }
    690750
    691751    ///The distance of a node from the root(s).
    692752
    693753    ///Returns the distance of a node from the root(s).
    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.
     754    ///
     755    ///\warning If node \c v is not reachable from the root(s), then
     756    ///the return value of this function is undefined.
     757    ///
     758    ///\pre Either \ref run() or \ref start() must be called before
     759    ///using this function.
    697760    int dist(Node v) const { return (*_dist)[v]; }
    698761
    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.
     762    ///Returns the 'previous arc' of the shortest path tree for a node.
     763
     764    ///This function returns the 'previous arc' of the shortest path
     765    ///tree for the node \c v, i.e. it returns the last arc of a
     766    ///shortest path from the root(s) to \c v. It is \c INVALID if \c v
     767    ///is not reachable from the root(s) or if \c v is a root.
     768    ///
     769    ///The shortest path tree used here is equal to the shortest path
     770    ///tree used in \ref predNode().
     771    ///
     772    ///\pre Either \ref run() or \ref start() must be called before
     773    ///using this function.
    710774    Arc predArc(Node v) const { return (*_pred)[v];}
    711775
    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.
     776    ///Returns the 'previous node' of the shortest path tree for a node.
     777
     778    ///This function returns the 'previous node' of the shortest path
     779    ///tree for the node \c v, i.e. it returns the last but one node
     780    ///from a shortest path from the root(s) to \c v. It is \c INVALID
     781    ///if \c v is not reachable from the root(s) or if \c v is a root.
     782    ///
    720783    ///The shortest path tree used here is equal to the shortest path
    721784    ///tree used in \ref predArc().
     785    ///
    722786    ///\pre Either \ref run() or \ref start() must be called before
    723787    ///using this function.
     
    725789                                  G->source((*_pred)[v]); }
    726790
    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.
     791    ///\brief Returns a const reference to the node map that stores the
     792    /// distances of the nodes.
     793    ///
     794    ///Returns a const reference to the node map that stores the distances
     795    ///of the nodes calculated by the algorithm.
     796    ///
     797    ///\pre Either \ref run() or \ref init()
     798    ///must be called before using this function.
    732799    const DistMap &distMap() const { return *_dist;}
    733800
    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.
     801    ///\brief Returns a const reference to the node map that stores the
     802    ///predecessor arcs.
     803    ///
     804    ///Returns a const reference to the node map that stores the predecessor
     805    ///arcs, which form the shortest path tree.
     806    ///
    738807    ///\pre Either \ref run() or \ref init()
    739808    ///must be called before using this function.
    740809    const PredMap &predMap() const { return *_pred;}
    741810
    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.
     811    ///Checks if a node is reachable from the root(s).
     812
     813    ///Returns \c true if \c v is reachable from the root(s).
    746814    ///\pre Either \ref run() or \ref start()
    747815    ///must be called before using this function.
    748     ///
    749     bool reached(Node v) { return (*_reached)[v]; }
     816    bool reached(Node v) const { return (*_reached)[v]; }
    750817
    751818    ///@}
    752819  };
    753820
    754   ///Default traits class of Bfs function.
    755 
    756   ///Default traits class of Bfs function.
     821  ///Default traits class of bfs() function.
     822
     823  ///Default traits class of bfs() function.
    757824  ///\tparam GR Digraph type.
    758825  template<class GR>
    759826  struct BfsWizardDefaultTraits
    760827  {
    761     ///The digraph type the algorithm runs on.
     828    ///The type of the digraph the algorithm runs on.
    762829    typedef GR Digraph;
    763     ///\brief The type of the map that stores the last
     830
     831    ///\brief The type of the map that stores the predecessor
    764832    ///arcs of the shortest paths.
    765833    ///
    766     ///The type of the map that stores the last
     834    ///The type of the map that stores the predecessor
    767835    ///arcs of the shortest paths.
    768836    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    769     ///
    770     typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
     837    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
    771838    ///Instantiates a PredMap.
    772839
    773     ///This function instantiates a \ref PredMap.
    774     ///\param g is the digraph, to which we would like to define the PredMap.
    775     ///\todo The digraph alone may be insufficient to initialize
    776 #ifdef DOXYGEN
    777     static PredMap *createPredMap(const GR &g)
    778 #else
    779     static PredMap *createPredMap(const GR &)
    780 #endif
    781     {
    782       return new PredMap();
     840    ///This function instantiates a PredMap.
     841    ///\param g is the digraph, to which we would like to define the
     842    ///PredMap.
     843    static PredMap *createPredMap(const Digraph &g)
     844    {
     845      return new PredMap(g);
    783846    }
    784847
     
    787850    ///The type of the map that indicates which nodes are processed.
    788851    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    789     ///\todo named parameter to set this type, function to read and write.
     852    ///By default it is a NullMap.
    790853    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    791854    ///Instantiates a ProcessedMap.
    792855
    793     ///This function instantiates a \ref ProcessedMap.
     856    ///This function instantiates a ProcessedMap.
    794857    ///\param g is the digraph, to which
    795     ///we would like to define the \ref ProcessedMap
     858    ///we would like to define the ProcessedMap.
    796859#ifdef DOXYGEN
    797     static ProcessedMap *createProcessedMap(const GR &g)
     860    static ProcessedMap *createProcessedMap(const Digraph &g)
    798861#else
    799     static ProcessedMap *createProcessedMap(const GR &)
     862    static ProcessedMap *createProcessedMap(const Digraph &)
    800863#endif
    801864    {
    802865      return new ProcessedMap();
    803866    }
     867
    804868    ///The type of the map that indicates which nodes are reached.
    805869
    806870    ///The type of the map that indicates which nodes are reached.
    807     ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    808     ///\todo named parameter to set this type, function to read and write.
     871    ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    809872    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    810873    ///Instantiates a ReachedMap.
    811874
    812     ///This function instantiates a \ref ReachedMap.
    813     ///\param G is the digraph, to which
    814     ///we would like to define the \ref ReachedMap.
    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.
     875    ///This function instantiates a ReachedMap.
     876    ///\param g is the digraph, to which
     877    ///we would like to define the ReachedMap.
     878    static ReachedMap *createReachedMap(const Digraph &g)
     879    {
     880      return new ReachedMap(g);
     881    }
     882
     883    ///The type of the map that stores the distances of the nodes.
     884
     885    ///The type of the map that stores the distances of the nodes.
    822886    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
    823     ///
    824     typedef NullMap<typename Digraph::Node,int> DistMap;
     887    typedef typename Digraph::template NodeMap<int> DistMap;
    825888    ///Instantiates a DistMap.
    826889
    827     ///This function instantiates a \ref DistMap.
     890    ///This function instantiates a DistMap.
    828891    ///\param g is the digraph, to which we would like to define
    829     ///the \ref DistMap
    830 #ifdef DOXYGEN
    831     static DistMap *createDistMap(const GR &g)
    832 #else
    833     static DistMap *createDistMap(const GR &)
    834 #endif
    835     {
    836       return new DistMap();
    837     }
     892    ///the DistMap
     893    static DistMap *createDistMap(const Digraph &g)
     894    {
     895      return new DistMap(g);
     896    }
     897
     898    ///The type of the shortest paths.
     899
     900    ///The type of the shortest paths.
     901    ///It must meet the \ref concepts::Path "Path" concept.
     902    typedef lemon::Path<Digraph> Path;
    838903  };
    839904
    840   /// Default traits used by \ref BfsWizard
     905  /// Default traits class used by BfsWizard
    841906
    842907  /// To make it easier to use Bfs algorithm
    843   ///we have created a wizard class.
     908  /// we have created a wizard class.
    844909  /// This \ref BfsWizard class needs default traits,
    845   ///as well as the \ref Bfs class.
     910  /// as well as the \ref Bfs class.
    846911  /// The \ref BfsWizardBase is a class to be the default traits of the
    847912  /// \ref BfsWizard class.
     
    852917    typedef BfsWizardDefaultTraits<GR> Base;
    853918  protected:
    854     /// Type of the nodes in the digraph.
     919    //The type of the nodes in the digraph.
    855920    typedef typename Base::Digraph::Node Node;
    856921
    857     /// Pointer to the underlying digraph.
     922    //Pointer to the digraph the algorithm runs on.
    858923    void *_g;
    859     ///Pointer to the map of reached nodes.
     924    //Pointer to the map of reached nodes.
    860925    void *_reached;
    861     ///Pointer to the map of processed nodes.
     926    //Pointer to the map of processed nodes.
    862927    void *_processed;
    863     ///Pointer to the map of predecessors arcs.
     928    //Pointer to the map of predecessors arcs.
    864929    void *_pred;
    865     ///Pointer to the map of distances.
     930    //Pointer to the map of distances.
    866931    void *_dist;
    867     ///Pointer to the source node.
    868     Node _source;
     932    //Pointer to the shortest path to the target node.
     933    void *_path;
     934    //Pointer to the distance of the target node.
     935    int *_di;
    869936
    870937    public:
     
    872939
    873940    /// This constructor does not require parameters, therefore it initiates
    874     /// all of the attributes to default values (0, INVALID).
     941    /// all of the attributes to \c 0.
    875942    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    876                            _dist(0), _source(INVALID) {}
     943                      _dist(0), _path(0), _di(0) {}
    877944
    878945    /// Constructor.
    879946
    880     /// This constructor requires some parameters,
    881     /// listed in the parameters list.
    882     /// Others are initiated to 0.
    883     /// \param g is the initial value of  \ref _g
    884     /// \param s is the initial value of  \ref _source
    885     BfsWizardBase(const GR &g, Node s=INVALID) :
     947    /// This constructor requires one parameter,
     948    /// others are initiated to \c 0.
     949    /// \param g The digraph the algorithm runs on.
     950    BfsWizardBase(const GR &g) :
    886951      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    887       _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
     952      _reached(0), _processed(0), _pred(0), _dist(0),  _path(0), _di(0) {}
    888953
    889954  };
    890955
    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.
     956  /// Auxiliary class for the function-type interface of BFS algorithm.
     957
     958  /// This auxiliary class is created to implement the
     959  /// \ref bfs() "function-type interface" of \ref Bfs algorithm.
     960  /// It does not have own \ref run() method, it uses the functions
     961  /// and features of the plain \ref Bfs.
    896962  ///
    897   /// Simplicity means that the way to change the types defined
    898   /// in the traits class is based on functions that returns the new class
    899   /// and not on templatable built-in classes.
    900   /// When using the plain \ref Bfs
    901   /// the new class with the modified type comes from
    902   /// the original class by using the ::
    903   /// operator. In the case of \ref BfsWizard only
    904   /// a function have to be called and it will
    905   /// return the needed class.
    906   ///
    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.
     963  /// This class should only be used through the \ref bfs() function,
     964  /// which makes it easier to use the algorithm.
    910965  template<class TR>
    911966  class BfsWizard : public TR
     
    913968    typedef TR Base;
    914969
    915     ///The type of the underlying digraph.
     970    ///The type of the digraph the algorithm runs on.
    916971    typedef typename TR::Digraph Digraph;
    917     //\e
     972
    918973    typedef typename Digraph::Node Node;
    919     //\e
    920974    typedef typename Digraph::NodeIt NodeIt;
    921     //\e
    922975    typedef typename Digraph::Arc Arc;
    923     //\e
    924976    typedef typename Digraph::OutArcIt OutArcIt;
    925977
    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
     978    ///\brief The type of the map that stores the predecessor
    933979    ///arcs of the shortest paths.
    934980    typedef typename TR::PredMap PredMap;
    935     ///The type of the map that stores the dists of the nodes.
     981    ///\brief The type of the map that stores the distances of the nodes.
    936982    typedef typename TR::DistMap DistMap;
     983    ///\brief The type of the map that indicates which nodes are reached.
     984    typedef typename TR::ReachedMap ReachedMap;
     985    ///\brief The type of the map that indicates which nodes are processed.
     986    typedef typename TR::ProcessedMap ProcessedMap;
     987    ///The type of the shortest paths
     988    typedef typename TR::Path Path;
    937989
    938990  public:
     991
    939992    /// Constructor.
    940993    BfsWizard() : TR() {}
     
    944997    /// Constructor that requires parameters.
    945998    /// These parameters will be the default values for the traits class.
    946     BfsWizard(const Digraph &g, Node s=INVALID) :
    947       TR(g,s) {}
     999    /// \param g The digraph the algorithm runs on.
     1000    BfsWizard(const Digraph &g) :
     1001      TR(g) {}
    9481002
    9491003    ///Copy constructor
     
    9521006    ~BfsWizard() {}
    9531007
    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.
     1008    ///Runs BFS algorithm from the given source node.
     1009
     1010    ///This method runs BFS algorithm from node \c s
     1011    ///in order to compute the shortest path to each node.
     1012    void run(Node s)
     1013    {
     1014      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
     1015      if (Base::_pred)
     1016        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     1017      if (Base::_dist)
     1018        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
     1019      if (Base::_reached)
     1020        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
     1021      if (Base::_processed)
     1022        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
     1023      if (s!=INVALID)
     1024        alg.run(s);
     1025      else
     1026        alg.run();
     1027    }
     1028
     1029    ///Finds the shortest path between \c s and \c t.
     1030
     1031    ///This method runs BFS algorithm from node \c s
     1032    ///in order to compute the shortest path to node \c t
     1033    ///(it stops searching when \c t is processed).
     1034    ///
     1035    ///\return \c true if \c t is reachable form \c s.
     1036    bool run(Node s, Node t)
     1037    {
     1038      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
     1039      if (Base::_pred)
     1040        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     1041      if (Base::_dist)
     1042        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
     1043      if (Base::_reached)
     1044        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
     1045      if (Base::_processed)
     1046        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
     1047      alg.run(s,t);
     1048      if (Base::_path)
     1049        *reinterpret_cast<Path*>(Base::_path) = alg.path(t);
     1050      if (Base::_di)
     1051        *Base::_di = alg.dist(t);
     1052      return alg.reached(t);
     1053    }
     1054
     1055    ///Runs BFS algorithm to visit all nodes in the digraph.
     1056
     1057    ///This method runs BFS algorithm in order to compute
     1058    ///the shortest path to each node.
    9581059    void run()
    9591060    {
    960       if(Base::_source==INVALID) throw UninitializedParameter();
    961       Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    962       if(Base::_reached)
    963         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    964       if(Base::_processed)
    965         alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    966       if(Base::_pred)
    967         alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    968       if(Base::_dist)
    969         alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    970       alg.run(Base::_source);
    971     }
    972 
    973     ///Runs Bfs algorithm from the given node.
    974 
    975     ///Runs Bfs algorithm from the given node.
    976     ///\param s is the given source.
    977     void run(Node s)
    978     {
    979       Base::_source=s;
    980       run();
     1061      run(INVALID);
    9811062    }
    9821063
    9831064    template<class T>
    984     struct DefPredMapBase : public Base {
     1065    struct SetPredMapBase : public Base {
    9851066      typedef T PredMap;
    9861067      static PredMap *createPredMap(const Digraph &) { return 0; };
    987       DefPredMapBase(const TR &b) : TR(b) {}
     1068      SetPredMapBase(const TR &b) : TR(b) {}
    9881069    };
    989 
    990     ///\brief \ref named-templ-param "Named parameter"
    991     ///function for setting PredMap
    992     ///
    993     /// \ref named-templ-param "Named parameter"
    994     ///function for setting PredMap
    995     ///
     1070    ///\brief \ref named-func-param "Named parameter"
     1071    ///for setting PredMap object.
     1072    ///
     1073    ///\ref named-func-param "Named parameter"
     1074    ///for setting PredMap object.
    9961075    template<class T>
    997     BfsWizard<DefPredMapBase<T> > predMap(const T &t)
     1076    BfsWizard<SetPredMapBase<T> > predMap(const T &t)
    9981077    {
    9991078      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    1000       return BfsWizard<DefPredMapBase<T> >(*this);
    1001     }
    1002 
     1079      return BfsWizard<SetPredMapBase<T> >(*this);
     1080    }
    10031081
    10041082    template<class T>
    1005     struct DefReachedMapBase : public Base {
     1083    struct SetReachedMapBase : public Base {
    10061084      typedef T ReachedMap;
    10071085      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
    1008       DefReachedMapBase(const TR &b) : TR(b) {}
     1086      SetReachedMapBase(const TR &b) : TR(b) {}
    10091087    };
    1010 
    1011     ///\brief \ref named-templ-param "Named parameter"
    1012     ///function for setting ReachedMap
    1013     ///
    1014     /// \ref named-templ-param "Named parameter"
    1015     ///function for setting ReachedMap
    1016     ///
     1088    ///\brief \ref named-func-param "Named parameter"
     1089    ///for setting ReachedMap object.
     1090    ///
     1091    /// \ref named-func-param "Named parameter"
     1092    ///for setting ReachedMap object.
    10171093    template<class T>
    1018     BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
     1094    BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t)
    10191095    {
    10201096      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
    1021       return BfsWizard<DefReachedMapBase<T> >(*this);
    1022     }
    1023 
     1097      return BfsWizard<SetReachedMapBase<T> >(*this);
     1098    }
    10241099
    10251100    template<class T>
    1026     struct DefProcessedMapBase : public Base {
     1101    struct SetDistMapBase : public Base {
     1102      typedef T DistMap;
     1103      static DistMap *createDistMap(const Digraph &) { return 0; };
     1104      SetDistMapBase(const TR &b) : TR(b) {}
     1105    };
     1106    ///\brief \ref named-func-param "Named parameter"
     1107    ///for setting DistMap object.
     1108    ///
     1109    /// \ref named-func-param "Named parameter"
     1110    ///for setting DistMap object.
     1111    template<class T>
     1112    BfsWizard<SetDistMapBase<T> > distMap(const T &t)
     1113    {
     1114      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
     1115      return BfsWizard<SetDistMapBase<T> >(*this);
     1116    }
     1117
     1118    template<class T>
     1119    struct SetProcessedMapBase : public Base {
    10271120      typedef T ProcessedMap;
    10281121      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
    1029       DefProcessedMapBase(const TR &b) : TR(b) {}
     1122      SetProcessedMapBase(const TR &b) : TR(b) {}
    10301123    };
    1031 
    1032     ///\brief \ref named-templ-param "Named parameter"
    1033     ///function for setting ProcessedMap
    1034     ///
    1035     /// \ref named-templ-param "Named parameter"
    1036     ///function for setting ProcessedMap
    1037     ///
     1124    ///\brief \ref named-func-param "Named parameter"
     1125    ///for setting ProcessedMap object.
     1126    ///
     1127    /// \ref named-func-param "Named parameter"
     1128    ///for setting ProcessedMap object.
    10381129    template<class T>
    1039     BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
     1130    BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t)
    10401131    {
    10411132      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    1042       return BfsWizard<DefProcessedMapBase<T> >(*this);
    1043     }
    1044 
     1133      return BfsWizard<SetProcessedMapBase<T> >(*this);
     1134    }
    10451135
    10461136    template<class T>
    1047     struct DefDistMapBase : public Base {
    1048       typedef T DistMap;
    1049       static DistMap *createDistMap(const Digraph &) { return 0; };
    1050       DefDistMapBase(const TR &b) : TR(b) {}
     1137    struct SetPathBase : public Base {
     1138      typedef T Path;
     1139      SetPathBase(const TR &b) : TR(b) {}
    10511140    };
    1052 
    1053     ///\brief \ref named-templ-param "Named parameter"
    1054     ///function for setting DistMap type
    1055     ///
    1056     /// \ref named-templ-param "Named parameter"
    1057     ///function for setting DistMap type
    1058     ///
     1141    ///\brief \ref named-func-param "Named parameter"
     1142    ///for getting the shortest path to the target node.
     1143    ///
     1144    ///\ref named-func-param "Named parameter"
     1145    ///for getting the shortest path to the target node.
    10591146    template<class T>
    1060     BfsWizard<DefDistMapBase<T> > distMap(const T &t)
    1061     {
    1062       Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    1063       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;
     1147    BfsWizard<SetPathBase<T> > path(const T &t)
     1148    {
     1149      Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t));
     1150      return BfsWizard<SetPathBase<T> >(*this);
     1151    }
     1152
     1153    ///\brief \ref named-func-param "Named parameter"
     1154    ///for getting the distance of the target node.
     1155    ///
     1156    ///\ref named-func-param "Named parameter"
     1157    ///for getting the distance of the target node.
     1158    BfsWizard dist(const int &d)
     1159    {
     1160      Base::_di=const_cast<int*>(&d);
    10731161      return *this;
    10741162    }
     
    10761164  };
    10771165
    1078   ///Function type interface for Bfs algorithm.
     1166  ///Function-type interface for BFS algorithm.
    10791167
    10801168  /// \ingroup search
    1081   ///Function type interface for Bfs algorithm.
     1169  ///Function-type interface for BFS algorithm.
    10821170  ///
    1083   ///This function also has several
    1084   ///\ref named-templ-func-param "named parameters",
     1171  ///This function also has several \ref named-func-param "named parameters",
    10851172  ///they are declared as the members of class \ref BfsWizard.
    1086   ///The following
    1087   ///example shows how to use these parameters.
     1173  ///The following examples show how to use these parameters.
    10881174  ///\code
    1089   ///  bfs(g,source).predMap(preds).run();
     1175  ///  // Compute shortest path from node s to each node
     1176  ///  bfs(g).predMap(preds).distMap(dists).run(s);
     1177  ///
     1178  ///  // Compute shortest path from s to t
     1179  ///  bool reached = bfs(g).path(p).dist(d).run(s,t);
    10901180  ///\endcode
    10911181  ///\warning Don't forget to put the \ref BfsWizard::run() "run()"
     
    10951185  template<class GR>
    10961186  BfsWizard<BfsWizardBase<GR> >
    1097   bfs(const GR &g,typename GR::Node s=INVALID)
     1187  bfs(const GR &digraph)
    10981188  {
    1099     return BfsWizard<BfsWizardBase<GR> >(g,s);
     1189    return BfsWizard<BfsWizardBase<GR> >(digraph);
    11001190  }
    11011191
    11021192#ifdef DOXYGEN
    1103   /// \brief Visitor class for bfs.
     1193  /// \brief Visitor class for BFS.
    11041194  ///
    11051195  /// This class defines the interface of the BfsVisit events, and
    1106   /// it could be the base of a real Visitor class.
     1196  /// it could be the base of a real visitor class.
    11071197  template <typename _Digraph>
    11081198  struct BfsVisitor {
     
    11101200    typedef typename Digraph::Arc Arc;
    11111201    typedef typename Digraph::Node Node;
    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.
     1202    /// \brief Called for the source node(s) of the BFS.
     1203    ///
     1204    /// This function is called for the source node(s) of the BFS.
     1205    void start(const Node& node) {}
     1206    /// \brief Called when a node is reached first time.
     1207    ///
     1208    /// This function is called when a node is reached first time.
     1209    void reach(const Node& node) {}
     1210    /// \brief Called when a node is processed.
     1211    ///
     1212    /// This function is called when a node is processed.
     1213    void process(const Node& node) {}
     1214    /// \brief Called when an arc reaches a new node.
     1215    ///
     1216    /// This function is called when the BFS finds an arc whose target node
     1217    /// is not reached yet.
    11161218    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.
    1120     void reach(const Node& node) {}
    1121     /// \brief Called when the arc examined but target of the arc
     1219    /// \brief Called when an arc is examined but its target node is
    11221220    /// already discovered.
    11231221    ///
    1124     /// It called when the arc examined but the target of the arc
     1222    /// This function is called when an arc is examined but its target node is
    11251223    /// already discovered.
    11261224    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) {}
    11351225  };
    11361226#else
     
    11401230    typedef typename Digraph::Arc Arc;
    11411231    typedef typename Digraph::Node Node;
     1232    void start(const Node&) {}
     1233    void reach(const Node&) {}
     1234    void process(const Node&) {}
    11421235    void discover(const Arc&) {}
    1143     void reach(const Node&) {}
    11441236    void examine(const Arc&) {}
    1145     void start(const Node&) {}
    1146     void process(const Node&) {}
    11471237
    11481238    template <typename _Visitor>
     
    11511241        Arc arc;
    11521242        Node node;
     1243        visitor.start(node);
     1244        visitor.reach(node);
     1245        visitor.process(node);
    11531246        visitor.discover(arc);
    1154         visitor.reach(node);
    11551247        visitor.examine(arc);
    1156         visitor.start(node);
    1157         visitor.process(node);
    11581248      }
    11591249      _Visitor& visitor;
     
    11651255  ///
    11661256  /// Default traits class of BfsVisit class.
    1167   /// \tparam _Digraph Digraph type.
     1257  /// \tparam _Digraph The type of the digraph the algorithm runs on.
    11681258  template<class _Digraph>
    11691259  struct BfsVisitDefaultTraits {
    11701260
    1171     /// \brief The digraph type the algorithm runs on.
     1261    /// \brief The type of the digraph the algorithm runs on.
    11721262    typedef _Digraph Digraph;
    11731263
     
    11751265    ///
    11761266    /// The type of the map that indicates which nodes are reached.
    1177     /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
    1178     /// \todo named parameter to set this type, function to read and write.
     1267    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    11791268    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    11801269
    11811270    /// \brief Instantiates a ReachedMap.
    11821271    ///
    1183     /// This function instantiates a \ref ReachedMap.
     1272    /// This function instantiates a ReachedMap.
    11841273    /// \param digraph is the digraph, to which
    1185     /// we would like to define the \ref ReachedMap.
     1274    /// we would like to define the ReachedMap.
    11861275    static ReachedMap *createReachedMap(const Digraph &digraph) {
    11871276      return new ReachedMap(digraph);
     
    11921281  /// \ingroup search
    11931282  ///
    1194   /// \brief %BFS Visit algorithm class.
     1283  /// \brief %BFS algorithm class with visitor interface.
    11951284  ///
    11961285  /// This class provides an efficient implementation of the %BFS algorithm
     
    11991288  /// The %BfsVisit class provides an alternative interface to the Bfs
    12001289  /// class. It works with callback mechanism, the BfsVisit object calls
    1201   /// on every bfs event the \c Visitor class member functions.
     1290  /// the member functions of the \c Visitor class on every BFS event.
    12021291  ///
    1203   /// \tparam _Digraph The digraph type the algorithm runs on.
     1292  /// This interface of the BFS algorithm should be used in special cases
     1293  /// when extra actions have to be performed in connection with certain
     1294  /// events of the BFS algorithm. Otherwise consider to use Bfs or bfs()
     1295  /// instead.
     1296  ///
     1297  /// \tparam _Digraph The type of the digraph the algorithm runs on.
    12041298  /// The default value is
    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.
     1299  /// \ref ListDigraph. The value of _Digraph is not used directly by
     1300  /// \ref BfsVisit, it is only passed to \ref BfsVisitDefaultTraits.
     1301  /// \tparam _Visitor The Visitor type that is used by the algorithm.
     1302  /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty visitor, which
     1303  /// does not observe the BFS events. If you want to observe the BFS
     1304  /// events, you should implement your own visitor class.
    12111305  /// \tparam _Traits Traits class to set various data types used by the
    12121306  /// algorithm. The default traits class is
    12131307  /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>".
    12141308  /// See \ref BfsVisitDefaultTraits for the documentation of
    1215   /// a Bfs visit traits class.
     1309  /// a BFS visit traits class.
    12161310#ifdef DOXYGEN
    12171311  template <typename _Digraph, typename _Visitor, typename _Traits>
     
    12191313  template <typename _Digraph = ListDigraph,
    12201314            typename _Visitor = BfsVisitor<_Digraph>,
    1221             typename _Traits = BfsDefaultTraits<_Digraph> >
     1315            typename _Traits = BfsVisitDefaultTraits<_Digraph> >
    12221316#endif
    12231317  class BfsVisit {
    12241318  public:
    12251319
    1226     /// \brief \ref Exception for uninitialized parameters.
    1227     ///
    1228     /// This error represents problems in the initialization
    1229     /// of the parameters of the algorithms.
    1230     class UninitializedParameter : public lemon::UninitializedParameter {
    1231     public:
    1232       virtual const char* what() const throw()
    1233       {
    1234         return "lemon::BfsVisit::UninitializedParameter";
    1235       }
    1236     };
    1237 
     1320    ///The traits class.
    12381321    typedef _Traits Traits;
    12391322
     1323    ///The type of the digraph the algorithm runs on.
    12401324    typedef typename Traits::Digraph Digraph;
    12411325
     1326    ///The visitor type used by the algorithm.
    12421327    typedef _Visitor Visitor;
    12431328
    1244     ///The type of the map indicating which nodes are reached.
     1329    ///The type of the map that indicates which nodes are reached.
    12451330    typedef typename Traits::ReachedMap ReachedMap;
    12461331
     
    12521337    typedef typename Digraph::OutArcIt OutArcIt;
    12531338
    1254     /// Pointer to the underlying digraph.
     1339    //Pointer to the underlying digraph.
    12551340    const Digraph *_digraph;
    1256     /// Pointer to the visitor object.
     1341    //Pointer to the visitor object.
    12571342    Visitor *_visitor;
    1258     ///Pointer to the map of reached status of the nodes.
     1343    //Pointer to the map of reached status of the nodes.
    12591344    ReachedMap *_reached;
    1260     ///Indicates if \ref _reached is locally allocated (\c true) or not.
     1345    //Indicates if _reached is locally allocated (true) or not.
    12611346    bool local_reached;
    12621347
     
    12641349    int _list_front, _list_back;
    12651350
    1266     /// \brief Creates the maps if necessary.
    1267     ///
    1268     /// Creates the maps if necessary.
     1351    //Creates the maps if necessary.
    12691352    void create_maps() {
    12701353      if(!_reached) {
     
    12861369    ///@{
    12871370    template <class T>
    1288     struct DefReachedMapTraits : public Traits {
     1371    struct SetReachedMapTraits : public Traits {
    12891372      typedef T ReachedMap;
    12901373      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1291         throw UninitializedParameter();
     1374        LEMON_ASSERT(false, "ReachedMap is not initialized");
     1375        return 0; // ignore warnings
    12921376      }
    12931377    };
    12941378    /// \brief \ref named-templ-param "Named parameter" for setting
    1295     /// ReachedMap type
    1296     ///
    1297     /// \ref named-templ-param "Named parameter" for setting ReachedMap type
     1379    /// ReachedMap type.
     1380    ///
     1381    /// \ref named-templ-param "Named parameter" for setting ReachedMap type.
    12981382    template <class T>
    1299     struct DefReachedMap : public BfsVisit< Digraph, Visitor,
    1300                                             DefReachedMapTraits<T> > {
    1301       typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;
     1383    struct SetReachedMap : public BfsVisit< Digraph, Visitor,
     1384                                            SetReachedMapTraits<T> > {
     1385      typedef BfsVisit< Digraph, Visitor, SetReachedMapTraits<T> > Create;
    13021386    };
    13031387    ///@}
     
    13091393    /// Constructor.
    13101394    ///
    1311     /// \param digraph the digraph the algorithm will run on.
    1312     /// \param visitor The visitor of the algorithm.
    1313     ///
     1395    /// \param digraph The digraph the algorithm runs on.
     1396    /// \param visitor The visitor object of the algorithm.
    13141397    BfsVisit(const Digraph& digraph, Visitor& visitor)
    13151398      : _digraph(&digraph), _visitor(&visitor),
     
    13171400
    13181401    /// \brief Destructor.
    1319     ///
    1320     /// Destructor.
    13211402    ~BfsVisit() {
    13221403      if(local_reached) delete _reached;
    13231404    }
    13241405
    1325     /// \brief Sets the map indicating if a node is reached.
    1326     ///
    1327     /// Sets the map indicating if a node is reached.
     1406    /// \brief Sets the map that indicates which nodes are reached.
     1407    ///
     1408    /// Sets the map that indicates which nodes are reached.
    13281409    /// If you don't use this function before calling \ref run(),
    1329     /// it will allocate one. The destuctor deallocates this
     1410    /// it will allocate one. The destructor deallocates this
    13301411    /// automatically allocated map, of course.
    13311412    /// \return <tt> (*this) </tt>
     
    13401421
    13411422  public:
     1423
    13421424    /// \name Execution control
    13431425    /// The simplest way to execute the algorithm is to use
    1344     /// one of the member functions called \c run(...).
     1426    /// one of the member functions called \ref lemon::BfsVisit::run()
     1427    /// "run()".
    13451428    /// \n
    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.
     1429    /// If you need more control on the execution, first you must call
     1430    /// \ref lemon::BfsVisit::init() "init()", then you can add several
     1431    /// source nodes with \ref lemon::BfsVisit::addSource() "addSource()".
     1432    /// Finally \ref lemon::BfsVisit::start() "start()" will perform the
     1433    /// actual path computation.
    13511434
    13521435    /// @{
     1436
    13531437    /// \brief Initializes the internal data structures.
    13541438    ///
    13551439    /// Initializes the internal data structures.
    1356     ///
    13571440    void init() {
    13581441      create_maps();
     
    13821465    /// \return The processed node.
    13831466    ///
    1384     /// \pre The queue must not be empty!
     1467    /// \pre The queue must not be empty.
    13851468    Node processNextNode() {
    13861469      Node n = _list[++_list_front];
     
    14031486    /// \brief Processes the next node.
    14041487    ///
    1405     /// Processes the next node. And checks that the given target node
     1488    /// Processes the next node and checks if the given target node
    14061489    /// is reached. If the target node is reachable from the processed
    1407     /// node then the reached parameter will be set true. The reached
    1408     /// parameter should be initially false.
     1490    /// node, then the \c reach parameter will be set to \c true.
    14091491    ///
    14101492    /// \param target The target node.
    1411     /// \retval reach Indicates that the target node is reached.
     1493    /// \retval reach Indicates if the target node is reached.
     1494    /// It should be initially \c false.
     1495    ///
    14121496    /// \return The processed node.
    14131497    ///
    1414     /// \warning The queue must not be empty!
     1498    /// \pre The queue must not be empty.
    14151499    Node processNextNode(Node target, bool& reach) {
    14161500      Node n = _list[++_list_front];
     
    14341518    /// \brief Processes the next node.
    14351519    ///
    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.
     1520    /// Processes the next node and checks if at least one of reached
     1521    /// nodes has \c true value in the \c nm node map. If one node
     1522    /// with \c true value is reachable from the processed node, then the
     1523    /// \c rnode parameter will be set to the first of such nodes.
     1524    ///
     1525    /// \param nm A \c bool (or convertible) node map that indicates the
     1526    /// possible targets.
    14421527    /// \retval rnode The reached target node.
     1528    /// It should be initially \c INVALID.
     1529    ///
    14431530    /// \return The processed node.
    14441531    ///
    1445     /// \warning The queue must not be empty!
     1532    /// \pre The queue must not be empty.
    14461533    template <typename NM>
    14471534    Node processNextNode(const NM& nm, Node& rnode) {
     
    14641551    }
    14651552
    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() {
     1553    /// \brief The next node to be processed.
     1554    ///
     1555    /// Returns the next node to be processed or \c INVALID if the queue
     1556    /// is empty.
     1557    Node nextNode() const {
    14731558      return _list_front != _list_back ? _list[_list_front + 1] : INVALID;
    14741559    }
    14751560
    14761561    /// \brief Returns \c false if there are nodes
    1477     /// to be processed in the queue
     1562    /// to be processed.
    14781563    ///
    14791564    /// Returns \c false if there are nodes
    1480     /// to be processed in the queue
    1481     bool emptyQueue() { return _list_front == _list_back; }
     1565    /// to be processed in the queue.
     1566    bool emptyQueue() const { return _list_front == _list_back; }
    14821567
    14831568    /// \brief Returns the number of the nodes to be processed.
    14841569    ///
    14851570    /// Returns the number of the nodes to be processed in the queue.
    1486     int queueSize() { return _list_back - _list_front; }
     1571    int queueSize() const { return _list_back - _list_front; }
    14871572
    14881573    /// \brief Executes the algorithm.
     
    14901575    /// Executes the algorithm.
    14911576    ///
    1492     /// \pre init() must be called and at least one node should be added
     1577    /// This method runs the %BFS algorithm from the root node(s)
     1578    /// in order to compute the shortest path to each node.
     1579    ///
     1580    /// The algorithm computes
     1581    /// - the shortest path tree (forest),
     1582    /// - the distance of each node from the root(s).
     1583    ///
     1584    /// \pre init() must be called and at least one root node should be added
    14931585    /// with addSource() before using this function.
     1586    ///
     1587    /// \note <tt>b.start()</tt> is just a shortcut of the following code.
     1588    /// \code
     1589    ///   while ( !b.emptyQueue() ) {
     1590    ///     b.processNextNode();
     1591    ///   }
     1592    /// \endcode
    14941593    void start() {
    14951594      while ( !emptyQueue() ) processNextNode();
    14961595    }
    14971596
    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.
    1504     void start(Node dest) {
     1597    /// \brief Executes the algorithm until the given target node is reached.
     1598    ///
     1599    /// Executes the algorithm until the given target node is reached.
     1600    ///
     1601    /// This method runs the %BFS algorithm from the root node(s)
     1602    /// in order to compute the shortest path to \c t.
     1603    ///
     1604    /// The algorithm computes
     1605    /// - the shortest path to \c t,
     1606    /// - the distance of \c t from the root(s).
     1607    ///
     1608    /// \pre init() must be called and at least one root node should be
     1609    /// added with addSource() before using this function.
     1610    ///
     1611    /// \note <tt>b.start(t)</tt> is just a shortcut of the following code.
     1612    /// \code
     1613    ///   bool reach = false;
     1614    ///   while ( !b.emptyQueue() && !reach ) {
     1615    ///     b.processNextNode(t, reach);
     1616    ///   }
     1617    /// \endcode
     1618    void start(Node t) {
    15051619      bool reach = false;
    1506       while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
     1620      while ( !emptyQueue() && !reach ) processNextNode(t, reach);
    15071621    }
    15081622
     
    15111625    /// Executes the algorithm until a condition is met.
    15121626    ///
    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
     1627    /// This method runs the %BFS algorithm from the root node(s) in
     1628    /// order to compute the shortest path to a node \c v with
     1629    /// <tt>nm[v]</tt> true, if such a node can be found.
     1630    ///
     1631    /// \param nm must be a bool (or convertible) node map. The
     1632    /// algorithm will stop when it reaches a node \c v with
    15181633    /// <tt>nm[v]</tt> true.
    15191634    ///
    1520     ///\return The reached node \c v with <tt>nm[v]</tt> true or
    1521     ///\c INVALID if no such node was found.
     1635    /// \return The reached node \c v with <tt>nm[v]</tt> true or
     1636    /// \c INVALID if no such node was found.
     1637    ///
     1638    /// \pre init() must be called and at least one root node should be
     1639    /// added with addSource() before using this function.
     1640    ///
     1641    /// \note <tt>b.start(nm)</tt> is just a shortcut of the following code.
     1642    /// \code
     1643    ///   Node rnode = INVALID;
     1644    ///   while ( !b.emptyQueue() && rnode == INVALID ) {
     1645    ///     b.processNextNode(nm, rnode);
     1646    ///   }
     1647    ///   return rnode;
     1648    /// \endcode
    15221649    template <typename NM>
    15231650    Node start(const NM &nm) {
     
    15291656    }
    15301657
    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.
     1658    /// \brief Runs the algorithm from the given source node.
     1659    ///
     1660    /// This method runs the %BFS algorithm from node \c s
     1661    /// in order to compute the shortest path to each node.
     1662    ///
     1663    /// The algorithm computes
     1664    /// - the shortest path tree,
     1665    /// - the distance of each node from the root.
     1666    ///
     1667    /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
    15351668    ///\code
    15361669    ///   b.init();
     
    15441677    }
    15451678
    1546     /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph.
     1679    /// \brief Finds the shortest path between \c s and \c t.
     1680    ///
     1681    /// This method runs the %BFS algorithm from node \c s
     1682    /// in order to compute the shortest path to node \c t
     1683    /// (it stops searching when \c t is processed).
     1684    ///
     1685    /// \return \c true if \c t is reachable form \c s.
     1686    ///
     1687    /// \note Apart from the return value, <tt>b.run(s,t)</tt> is just a
     1688    /// shortcut of the following code.
     1689    ///\code
     1690    ///   b.init();
     1691    ///   b.addSource(s);
     1692    ///   b.start(t);
     1693    ///\endcode
     1694    bool run(Node s,Node t) {
     1695      init();
     1696      addSource(s);
     1697      start(t);
     1698      return reached(t);
     1699    }
     1700
     1701    /// \brief Runs the algorithm to visit all nodes in the digraph.
    15471702    ///
    15481703    /// This method runs the %BFS algorithm in order to
    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.
     1704    /// compute the shortest path to each node.
     1705    ///
     1706    /// The algorithm computes
     1707    /// - the shortest path tree (forest),
     1708    /// - the distance of each node from the root(s).
     1709    ///
     1710    /// \note <tt>b.run(s)</tt> is just a shortcut of the following code.
    15541711    ///\code
    15551712    ///  b.init();
    1556     ///  for (NodeIt it(digraph); it != INVALID; ++it) {
    1557     ///    if (!b.reached(it)) {
    1558     ///      b.addSource(it);
     1713    ///  for (NodeIt n(gr); n != INVALID; ++n) {
     1714    ///    if (!b.reached(n)) {
     1715    ///      b.addSource(n);
    15591716    ///      b.start();
    15601717    ///    }
     
    15701727      }
    15711728    }
     1729
    15721730    ///@}
    15731731
     
    15751733    /// The result of the %BFS algorithm can be obtained using these
    15761734    /// functions.\n
    1577     /// Before the use of these functions,
    1578     /// either run() or start() must be called.
     1735    /// Either \ref lemon::BfsVisit::run() "run()" or
     1736    /// \ref lemon::BfsVisit::start() "start()" must be called before
     1737    /// using them.
    15791738    ///@{
    15801739
    1581     /// \brief Checks if a node is reachable from the root.
     1740    /// \brief Checks if a node is reachable from the root(s).
    15821741    ///
    15831742    /// Returns \c true if \c v is reachable from the root(s).
    1584     /// \warning The source nodes are inditated as unreachable.
    15851743    /// \pre Either \ref run() or \ref start()
    15861744    /// must be called before using this function.
    1587     ///
    15881745    bool reached(Node v) { return (*_reached)[v]; }
     1746
    15891747    ///@}
     1748
    15901749  };
    15911750
     
    15931752
    15941753#endif
    1595 
Note: See TracChangeset for help on using the changeset viewer.