COIN-OR::LEMON - Graph Library

Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/bfs.h


Ignore:
Timestamp:
07/13/08 20:51:02 (11 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Apply unify-sources.sh to the source tree

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bfs.h

    r158 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3434
    3535
    36  
     36
    3737  ///Default traits class of Bfs class.
    3838
     
    4242  struct BfsDefaultTraits
    4343  {
    44     ///The digraph type the algorithm runs on. 
     44    ///The digraph type the algorithm runs on.
    4545    typedef GR Digraph;
    4646    ///\brief The type of the map that stores the last
    4747    ///arcs of the shortest paths.
    48     /// 
     48    ///
    4949    ///The type of the map that stores the last
    5050    ///arcs of the shortest paths.
     
    5353    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
    5454    ///Instantiates a PredMap.
    55  
    56     ///This function instantiates a \ref PredMap. 
     55
     56    ///This function instantiates a \ref PredMap.
    5757    ///\param G is the digraph, to which we would like to define the PredMap.
    5858    ///\todo The digraph alone may be insufficient to initialize
    59     static PredMap *createPredMap(const GR &G) 
     59    static PredMap *createPredMap(const GR &G)
    6060    {
    6161      return new PredMap(G);
    6262    }
    6363    ///The type of the map that indicates which nodes are processed.
    64  
     64
    6565    ///The type of the map that indicates which nodes are processed.
    6666    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    6868    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    6969    ///Instantiates a ProcessedMap.
    70  
    71     ///This function instantiates a \ref ProcessedMap. 
     70
     71    ///This function instantiates a \ref ProcessedMap.
    7272    ///\param g is the digraph, to which
    7373    ///we would like to define the \ref ProcessedMap
     
    8181    }
    8282    ///The type of the map that indicates which nodes are reached.
    83  
     83
    8484    ///The type of the map that indicates which nodes are reached.
    8585    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    8787    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    8888    ///Instantiates a ReachedMap.
    89  
    90     ///This function instantiates a \ref ReachedMap. 
     89
     90    ///This function instantiates a \ref ReachedMap.
    9191    ///\param G is the digraph, to which
    9292    ///we would like to define the \ref ReachedMap.
     
    9696    }
    9797    ///The type of the map that stores the dists of the nodes.
    98  
     98
    9999    ///The type of the map that stores the dists of the nodes.
    100100    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    102102    typedef typename Digraph::template NodeMap<int> DistMap;
    103103    ///Instantiates a DistMap.
    104  
    105     ///This function instantiates a \ref DistMap. 
     104
     105    ///This function instantiates a \ref DistMap.
    106106    ///\param G is the digraph, to which we would like to define the \ref DistMap
    107107    static DistMap *createDistMap(const GR &G)
     
    110110    }
    111111  };
    112  
     112
    113113  ///%BFS algorithm class.
    114  
     114
    115115  ///\ingroup search
    116116  ///This class provides an efficient implementation of the %BFS algorithm.
     
    127127#ifdef DOXYGEN
    128128  template <typename GR,
    129             typename TR>
     129            typename TR>
    130130#else
    131131  template <typename GR=ListDigraph,
    132             typename TR=BfsDefaultTraits<GR> >
     132            typename TR=BfsDefaultTraits<GR> >
    133133#endif
    134134  class Bfs {
     
    143143    public:
    144144      virtual const char* what() const throw() {
    145         return "lemon::Bfs::UninitializedParameter";
     145        return "lemon::Bfs::UninitializedParameter";
    146146      }
    147147    };
     
    150150    ///The type of the underlying digraph.
    151151    typedef typename TR::Digraph Digraph;
    152    
     152
    153153    ///\brief The type of the map that stores the last
    154154    ///arcs of the shortest paths.
     
    191191
    192192    ///Creates the maps if necessary.
    193    
     193
    194194    ///\todo Better memory allocation (instead of new).
    195     void create_maps() 
     195    void create_maps()
    196196    {
    197197      if(!_pred) {
    198         local_pred = true;
    199         _pred = Traits::createPredMap(*G);
     198        local_pred = true;
     199        _pred = Traits::createPredMap(*G);
    200200      }
    201201      if(!_dist) {
    202         local_dist = true;
    203         _dist = Traits::createDistMap(*G);
     202        local_dist = true;
     203        _dist = Traits::createDistMap(*G);
    204204      }
    205205      if(!_reached) {
    206         local_reached = true;
    207         _reached = Traits::createReachedMap(*G);
     206        local_reached = true;
     207        _reached = Traits::createReachedMap(*G);
    208208      }
    209209      if(!_processed) {
    210         local_processed = true;
    211         _processed = Traits::createProcessedMap(*G);
     210        local_processed = true;
     211        _processed = Traits::createProcessedMap(*G);
    212212      }
    213213    }
    214214
    215215  protected:
    216    
     216
    217217    Bfs() {}
    218    
     218
    219219  public:
    220  
     220
    221221    typedef Bfs Create;
    222222
     
    228228    struct DefPredMapTraits : public Traits {
    229229      typedef T PredMap;
    230       static PredMap *createPredMap(const Digraph &) 
     230      static PredMap *createPredMap(const Digraph &)
    231231      {
    232         throw UninitializedParameter();
     232        throw UninitializedParameter();
    233233      }
    234234    };
     
    239239    ///
    240240    template <class T>
    241     struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > { 
     241    struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {
    242242      typedef Bfs< Digraph, DefPredMapTraits<T> > Create;
    243243    };
    244    
     244
    245245    template <class T>
    246246    struct DefDistMapTraits : public Traits {
    247247      typedef T DistMap;
    248       static DistMap *createDistMap(const Digraph &) 
     248      static DistMap *createDistMap(const Digraph &)
    249249      {
    250         throw UninitializedParameter();
     250        throw UninitializedParameter();
    251251      }
    252252    };
     
    257257    ///
    258258    template <class T>
    259     struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > { 
     259    struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > {
    260260      typedef Bfs< Digraph, DefDistMapTraits<T> > Create;
    261261    };
    262    
     262
    263263    template <class T>
    264264    struct DefReachedMapTraits : public Traits {
    265265      typedef T ReachedMap;
    266       static ReachedMap *createReachedMap(const Digraph &) 
     266      static ReachedMap *createReachedMap(const Digraph &)
    267267      {
    268         throw UninitializedParameter();
     268        throw UninitializedParameter();
    269269      }
    270270    };
     
    275275    ///
    276276    template <class T>
    277     struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > { 
     277    struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > {
    278278      typedef Bfs< Digraph, DefReachedMapTraits<T> > Create;
    279279    };
    280    
     280
    281281    template <class T>
    282282    struct DefProcessedMapTraits : public Traits {
    283283      typedef T ProcessedMap;
    284       static ProcessedMap *createProcessedMap(const Digraph &) 
     284      static ProcessedMap *createProcessedMap(const Digraph &)
    285285      {
    286         throw UninitializedParameter();
     286        throw UninitializedParameter();
    287287      }
    288288    };
     
    296296      typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create;
    297297    };
    298    
     298
    299299    struct DefDigraphProcessedMapTraits : public Traits {
    300300      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    301       static ProcessedMap *createProcessedMap(const Digraph &G) 
     301      static ProcessedMap *createProcessedMap(const Digraph &G)
    302302      {
    303         return new ProcessedMap(G);
     303        return new ProcessedMap(G);
    304304      }
    305305    };
     
    312312    template <class T>
    313313    struct DefProcessedMapToBeDefaultMap :
    314       public Bfs< Digraph, DefDigraphProcessedMapTraits> { 
     314      public Bfs< Digraph, DefDigraphProcessedMapTraits> {
    315315      typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create;
    316316    };
    317    
     317
    318318    ///@}
    319319
    320   public:     
    321    
     320  public:
     321
    322322    ///Constructor.
    323    
     323
    324324    ///\param _G the digraph the algorithm will run on.
    325325    ///
     
    331331      _processed(NULL), local_processed(false)
    332332    { }
    333    
     333
    334334    ///Destructor.
    335     ~Bfs() 
     335    ~Bfs()
    336336    {
    337337      if(local_pred) delete _pred;
     
    348348    ///automatically allocated map, of course.
    349349    ///\return <tt> (*this) </tt>
    350     Bfs &predMap(PredMap &m) 
     350    Bfs &predMap(PredMap &m)
    351351    {
    352352      if(local_pred) {
    353         delete _pred;
    354         local_pred=false;
     353        delete _pred;
     354        local_pred=false;
    355355      }
    356356      _pred = &m;
     
    365365    ///automatically allocated map, of course.
    366366    ///\return <tt> (*this) </tt>
    367     Bfs &reachedMap(ReachedMap &m) 
     367    Bfs &reachedMap(ReachedMap &m)
    368368    {
    369369      if(local_reached) {
    370         delete _reached;
    371         local_reached=false;
     370        delete _reached;
     371        local_reached=false;
    372372      }
    373373      _reached = &m;
     
    382382    ///automatically allocated map, of course.
    383383    ///\return <tt> (*this) </tt>
    384     Bfs &processedMap(ProcessedMap &m) 
     384    Bfs &processedMap(ProcessedMap &m)
    385385    {
    386386      if(local_processed) {
    387         delete _processed;
    388         local_processed=false;
     387        delete _processed;
     388        local_processed=false;
    389389      }
    390390      _processed = &m;
     
    399399    ///automatically allocated map, of course.
    400400    ///\return <tt> (*this) </tt>
    401     Bfs &distMap(DistMap &m) 
     401    Bfs &distMap(DistMap &m)
    402402    {
    403403      if(local_dist) {
    404         delete _dist;
    405         local_dist=false;
     404        delete _dist;
     405        local_dist=false;
    406406      }
    407407      _dist = &m;
     
    433433      _curr_dist=1;
    434434      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
    435         _pred->set(u,INVALID);
    436         _reached->set(u,false);
    437         _processed->set(u,false);
    438       }
    439     }
    440    
     435        _pred->set(u,INVALID);
     436        _reached->set(u,false);
     437        _processed->set(u,false);
     438      }
     439    }
     440
    441441    ///Adds a new source node.
    442442
     
    446446    {
    447447      if(!(*_reached)[s])
    448         {
    449           _reached->set(s,true);
    450           _pred->set(s,INVALID);
    451           _dist->set(s,0);
    452           _queue[_queue_head++]=s;
    453           _queue_next_dist=_queue_head;
    454         }
    455     }
    456    
     448        {
     449          _reached->set(s,true);
     450          _pred->set(s,INVALID);
     451          _dist->set(s,0);
     452          _queue[_queue_head++]=s;
     453          _queue_next_dist=_queue_head;
     454        }
     455    }
     456
    457457    ///Processes the next node.
    458458
     
    465465    {
    466466      if(_queue_tail==_queue_next_dist) {
    467         _curr_dist++;
    468         _queue_next_dist=_queue_head;
     467        _curr_dist++;
     468        _queue_next_dist=_queue_head;
    469469      }
    470470      Node n=_queue[_queue_tail++];
     
    472472      Node m;
    473473      for(OutArcIt e(*G,n);e!=INVALID;++e)
    474         if(!(*_reached)[m=G->target(e)]) {
    475           _queue[_queue_head++]=m;
    476           _reached->set(m,true);
    477           _pred->set(m,e);
    478           _dist->set(m,_curr_dist);
    479         }
     474        if(!(*_reached)[m=G->target(e)]) {
     475          _queue[_queue_head++]=m;
     476          _reached->set(m,true);
     477          _pred->set(m,e);
     478          _dist->set(m,_curr_dist);
     479        }
    480480      return n;
    481481    }
     
    496496    {
    497497      if(_queue_tail==_queue_next_dist) {
    498         _curr_dist++;
    499         _queue_next_dist=_queue_head;
     498        _curr_dist++;
     499        _queue_next_dist=_queue_head;
    500500      }
    501501      Node n=_queue[_queue_tail++];
     
    503503      Node m;
    504504      for(OutArcIt e(*G,n);e!=INVALID;++e)
    505         if(!(*_reached)[m=G->target(e)]) {
    506           _queue[_queue_head++]=m;
    507           _reached->set(m,true);
    508           _pred->set(m,e);
    509           _dist->set(m,_curr_dist);
     505        if(!(*_reached)[m=G->target(e)]) {
     506          _queue[_queue_head++]=m;
     507          _reached->set(m,true);
     508          _pred->set(m,e);
     509          _dist->set(m,_curr_dist);
    510510          reach = reach || (target == m);
    511         }
     511        }
    512512      return n;
    513513    }
     
    529529    {
    530530      if(_queue_tail==_queue_next_dist) {
    531         _curr_dist++;
    532         _queue_next_dist=_queue_head;
     531        _curr_dist++;
     532        _queue_next_dist=_queue_head;
    533533      }
    534534      Node n=_queue[_queue_tail++];
     
    536536      Node m;
    537537      for(OutArcIt e(*G,n);e!=INVALID;++e)
    538         if(!(*_reached)[m=G->target(e)]) {
    539           _queue[_queue_head++]=m;
    540           _reached->set(m,true);
    541           _pred->set(m,e);
    542           _dist->set(m,_curr_dist);
    543           if (nm[m] && rnode == INVALID) rnode = m;
    544         }
     538        if(!(*_reached)[m=G->target(e)]) {
     539          _queue[_queue_head++]=m;
     540          _reached->set(m,true);
     541          _pred->set(m,e);
     542          _dist->set(m,_curr_dist);
     543          if (nm[m] && rnode == INVALID) rnode = m;
     544        }
    545545      return n;
    546546    }
    547      
     547
    548548    ///Next node to be processed.
    549549
     
    553553    /// empty.
    554554    Node nextNode()
    555     { 
     555    {
    556556      return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID;
    557557    }
    558  
     558
    559559    ///\brief Returns \c false if there are nodes
    560560    ///to be processed in the queue
     
    564564    bool emptyQueue() { return _queue_tail==_queue_head; }
    565565    ///Returns the number of the nodes to be processed.
    566    
     566
    567567    ///Returns the number of the nodes to be processed in the queue.
    568568    int queueSize() { return _queue_head-_queue_tail; }
    569    
     569
    570570    ///Executes the algorithm.
    571571
     
    585585      while ( !emptyQueue() ) processNextNode();
    586586    }
    587    
     587
    588588    ///Executes the algorithm until \c dest is reached.
    589589
     
    603603      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
    604604    }
    605    
     605
    606606    ///Executes the algorithm until a condition is met.
    607607
     
    622622      Node rnode = INVALID;
    623623      while ( !emptyQueue() && rnode == INVALID ) {
    624         processNextNode(nm, rnode);
     624        processNextNode(nm, rnode);
    625625      }
    626626      return rnode;
    627627    }
    628    
     628
    629629    ///Runs %BFS algorithm from node \c s.
    630    
     630
    631631    ///This method runs the %BFS algorithm from a root node \c s
    632632    ///in order to
     
    647647      start();
    648648    }
    649    
     649
    650650    ///Finds the shortest path between \c s and \c t.
    651    
     651
    652652    ///Finds the shortest path between \c s and \c t.
    653653    ///
     
    667667      return reached(t) ? _curr_dist : 0;
    668668    }
    669    
     669
    670670    ///@}
    671671
     
    675675    ///Before the use of these functions,
    676676    ///either run() or start() must be calleb.
    677    
     677
    678678    ///@{
    679679
     
    681681
    682682    ///Gives back the shortest path.
    683    
     683
    684684    ///Gives back the shortest path.
    685685    ///\pre The \c t should be reachable from the source.
    686     Path path(Node t) 
     686    Path path(Node t)
    687687    {
    688688      return Path(*G, *_pred, t);
     
    723723    ///using this function.
    724724    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
    725                                   G->source((*_pred)[v]); }
    726    
     725                                  G->source((*_pred)[v]); }
     726
    727727    ///Returns a reference to the NodeMap of distances.
    728728
     
    731731    ///be called before using this function.
    732732    const DistMap &distMap() const { return *_dist;}
    733  
     733
    734734    ///Returns a reference to the shortest path tree map.
    735735
     
    739739    ///must be called before using this function.
    740740    const PredMap &predMap() const { return *_pred;}
    741  
     741
    742742    ///Checks if a node is reachable from the root.
    743743
     
    748748    ///
    749749    bool reached(Node v) { return (*_reached)[v]; }
    750    
     750
    751751    ///@}
    752752  };
     
    759759  struct BfsWizardDefaultTraits
    760760  {
    761     ///The digraph type the algorithm runs on. 
     761    ///The digraph type the algorithm runs on.
    762762    typedef GR Digraph;
    763763    ///\brief The type of the map that stores the last
    764764    ///arcs of the shortest paths.
    765     /// 
     765    ///
    766766    ///The type of the map that stores the last
    767767    ///arcs of the shortest paths.
     
    770770    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
    771771    ///Instantiates a PredMap.
    772  
    773     ///This function instantiates a \ref PredMap. 
     772
     773    ///This function instantiates a \ref PredMap.
    774774    ///\param g is the digraph, to which we would like to define the PredMap.
    775775    ///\todo The digraph alone may be insufficient to initialize
    776776#ifdef DOXYGEN
    777     static PredMap *createPredMap(const GR &g) 
     777    static PredMap *createPredMap(const GR &g)
    778778#else
    779     static PredMap *createPredMap(const GR &) 
     779    static PredMap *createPredMap(const GR &)
    780780#endif
    781781    {
     
    784784
    785785    ///The type of the map that indicates which nodes are processed.
    786  
     786
    787787    ///The type of the map that indicates which nodes are processed.
    788788    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    790790    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    791791    ///Instantiates a ProcessedMap.
    792  
    793     ///This function instantiates a \ref ProcessedMap. 
     792
     793    ///This function instantiates a \ref ProcessedMap.
    794794    ///\param g is the digraph, to which
    795795    ///we would like to define the \ref ProcessedMap
     
    803803    }
    804804    ///The type of the map that indicates which nodes are reached.
    805  
     805
    806806    ///The type of the map that indicates which nodes are reached.
    807807    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    809809    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    810810    ///Instantiates a ReachedMap.
    811  
    812     ///This function instantiates a \ref ReachedMap. 
     811
     812    ///This function instantiates a \ref ReachedMap.
    813813    ///\param G is the digraph, to which
    814814    ///we would like to define the \ref ReachedMap.
     
    818818    }
    819819    ///The type of the map that stores the dists of the nodes.
    820  
     820
    821821    ///The type of the map that stores the dists of the nodes.
    822822    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    824824    typedef NullMap<typename Digraph::Node,int> DistMap;
    825825    ///Instantiates a DistMap.
    826  
    827     ///This function instantiates a \ref DistMap. 
     826
     827    ///This function instantiates a \ref DistMap.
    828828    ///\param g is the digraph, to which we would like to define the \ref DistMap
    829829#ifdef DOXYGEN
     
    836836    }
    837837  };
    838  
     838
    839839  /// Default traits used by \ref BfsWizard
    840840
     
    866866    ///Pointer to the source node.
    867867    Node _source;
    868    
     868
    869869    public:
    870870    /// Constructor.
    871    
     871
    872872    /// This constructor does not require parameters, therefore it initiates
    873873    /// all of the attributes to default values (0, INVALID).
    874874    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    875                            _dist(0), _source(INVALID) {}
     875                           _dist(0), _source(INVALID) {}
    876876
    877877    /// Constructor.
    878    
     878
    879879    /// This constructor requires some parameters,
    880880    /// listed in the parameters list.
     
    883883    /// \param s is the initial value of  \ref _source
    884884    BfsWizardBase(const GR &g, Node s=INVALID) :
    885       _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
     885      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    886886      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
    887887
    888888  };
    889  
     889
    890890  /// A class to make the usage of Bfs algorithm easier
    891891
     
    922922    //\e
    923923    typedef typename Digraph::OutArcIt OutArcIt;
    924    
     924
    925925    ///\brief The type of the map that stores
    926926    ///the reached nodes
     
    952952
    953953    ///Runs Bfs algorithm from a given node.
    954    
     954
    955955    ///Runs Bfs algorithm from a given node.
    956956    ///The node can be given by the \ref source function.
     
    960960      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    961961      if(Base::_reached)
    962         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    963       if(Base::_processed) 
     962        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
     963      if(Base::_processed)
    964964        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    965       if(Base::_pred) 
     965      if(Base::_pred)
    966966        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    967       if(Base::_dist) 
     967      if(Base::_dist)
    968968        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    969969      alg.run(Base::_source);
     
    986986      DefPredMapBase(const TR &b) : TR(b) {}
    987987    };
    988    
     988
    989989    ///\brief \ref named-templ-param "Named parameter"
    990990    ///function for setting PredMap
     
    994994    ///
    995995    template<class T>
    996     BfsWizard<DefPredMapBase<T> > predMap(const T &t) 
     996    BfsWizard<DefPredMapBase<T> > predMap(const T &t)
    997997    {
    998998      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    999999      return BfsWizard<DefPredMapBase<T> >(*this);
    10001000    }
    1001    
    1002  
     1001
     1002
    10031003    template<class T>
    10041004    struct DefReachedMapBase : public Base {
     
    10071007      DefReachedMapBase(const TR &b) : TR(b) {}
    10081008    };
    1009    
     1009
    10101010    ///\brief \ref named-templ-param "Named parameter"
    10111011    ///function for setting ReachedMap
     
    10151015    ///
    10161016    template<class T>
    1017     BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
     1017    BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
    10181018    {
    10191019      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
    10201020      return BfsWizard<DefReachedMapBase<T> >(*this);
    10211021    }
    1022    
     1022
    10231023
    10241024    template<class T>
     
    10281028      DefProcessedMapBase(const TR &b) : TR(b) {}
    10291029    };
    1030    
     1030
    10311031    ///\brief \ref named-templ-param "Named parameter"
    10321032    ///function for setting ProcessedMap
     
    10361036    ///
    10371037    template<class T>
    1038     BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
     1038    BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
    10391039    {
    10401040      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    10411041      return BfsWizard<DefProcessedMapBase<T> >(*this);
    10421042    }
    1043    
    1044    
     1043
     1044
    10451045    template<class T>
    10461046    struct DefDistMapBase : public Base {
     
    10491049      DefDistMapBase(const TR &b) : TR(b) {}
    10501050    };
    1051    
     1051
    10521052    ///\brief \ref named-templ-param "Named parameter"
    10531053    ///function for setting DistMap type
     
    10571057    ///
    10581058    template<class T>
    1059     BfsWizard<DefDistMapBase<T> > distMap(const T &t) 
     1059    BfsWizard<DefDistMapBase<T> > distMap(const T &t)
    10601060    {
    10611061      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    10621062      return BfsWizard<DefDistMapBase<T> >(*this);
    10631063    }
    1064    
     1064
    10651065    /// Sets the source node, from which the Bfs algorithm runs.
    10661066
    10671067    /// Sets the source node, from which the Bfs algorithm runs.
    10681068    /// \param s is the source node.
    1069     BfsWizard<TR> &source(Node s) 
     1069    BfsWizard<TR> &source(Node s)
    10701070    {
    10711071      Base::_source=s;
    10721072      return *this;
    10731073    }
    1074    
     1074
    10751075  };
    1076  
     1076
    10771077  ///Function type interface for Bfs algorithm.
    10781078
     
    11011101#ifdef DOXYGEN
    11021102  /// \brief Visitor class for bfs.
    1103   /// 
     1103  ///
    11041104  /// This class defines the interface of the BfsVisit events, and
    11051105  /// it could be the base of a real Visitor class.
     
    11101110    typedef typename Digraph::Node Node;
    11111111    /// \brief Called when the arc reach a node.
    1112     /// 
     1112    ///
    11131113    /// It is called when the bfs find an arc which target is not
    11141114    /// reached yet.
    11151115    void discover(const Arc& arc) {}
    11161116    /// \brief Called when the node reached first time.
    1117     /// 
     1117    ///
    11181118    /// It is Called when the node reached first time.
    11191119    void reach(const Node& node) {}
    1120     /// \brief Called when the arc examined but target of the arc 
     1120    /// \brief Called when the arc examined but target of the arc
    11211121    /// already discovered.
    1122     /// 
    1123     /// It called when the arc examined but the target of the arc 
     1122    ///
     1123    /// It called when the arc examined but the target of the arc
    11241124    /// already discovered.
    11251125    void examine(const Arc& arc) {}
    11261126    /// \brief Called for the source node of the bfs.
    1127     /// 
     1127    ///
    11281128    /// It is called for the source node of the bfs.
    11291129    void start(const Node& node) {}
    11301130    /// \brief Called when the node processed.
    1131     /// 
     1131    ///
    11321132    /// It is Called when the node processed.
    11331133    void process(const Node& node) {}
     
    11481148    struct Constraints {
    11491149      void constraints() {
    1150         Arc arc;
    1151         Node node;
    1152         visitor.discover(arc);
    1153         visitor.reach(node);
    1154         visitor.examine(arc);
    1155         visitor.start(node);
     1150        Arc arc;
     1151        Node node;
     1152        visitor.discover(arc);
     1153        visitor.reach(node);
     1154        visitor.examine(arc);
     1155        visitor.start(node);
    11561156        visitor.process(node);
    11571157      }
     
    11681168  struct BfsVisitDefaultTraits {
    11691169
    1170     /// \brief The digraph type the algorithm runs on. 
     1170    /// \brief The digraph type the algorithm runs on.
    11711171    typedef _Digraph Digraph;
    11721172
    11731173    /// \brief The type of the map that indicates which nodes are reached.
    1174     /// 
     1174    ///
    11751175    /// The type of the map that indicates which nodes are reached.
    11761176    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    11801180    /// \brief Instantiates a ReachedMap.
    11811181    ///
    1182     /// This function instantiates a \ref ReachedMap. 
     1182    /// This function instantiates a \ref ReachedMap.
    11831183    /// \param digraph is the digraph, to which
    11841184    /// we would like to define the \ref ReachedMap.
     
    11901190
    11911191  /// \ingroup search
    1192   /// 
     1192  ///
    11931193  /// \brief %BFS Visit algorithm class.
    1194   /// 
     1194  ///
    11951195  /// This class provides an efficient implementation of the %BFS algorithm
    11961196  /// with visitor interface.
     
    11981198  /// The %BfsVisit class provides an alternative interface to the Bfs
    11991199  /// class. It works with callback mechanism, the BfsVisit object calls
    1200   /// on every bfs event the \c Visitor class member functions. 
     1200  /// on every bfs event the \c Visitor class member functions.
    12011201  ///
    12021202  /// \tparam _Digraph The digraph type the algorithm runs on. The default value is
    12031203  /// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it
    12041204  /// is only passed to \ref BfsDefaultTraits.
    1205   /// \tparam _Visitor The Visitor object for the algorithm. The 
     1205  /// \tparam _Visitor The Visitor object for the algorithm. The
    12061206  /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which
    12071207  /// does not observe the Bfs events. If you want to observe the bfs
    12081208  /// events you should implement your own Visitor class.
    1209   /// \tparam _Traits Traits class to set various data types used by the 
     1209  /// \tparam _Traits Traits class to set various data types used by the
    12101210  /// algorithm. The default traits class is
    12111211  /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>".
     
    12161216#else
    12171217  template <typename _Digraph = ListDigraph,
    1218             typename _Visitor = BfsVisitor<_Digraph>,
    1219             typename _Traits = BfsDefaultTraits<_Digraph> >
     1218            typename _Visitor = BfsVisitor<_Digraph>,
     1219            typename _Traits = BfsDefaultTraits<_Digraph> >
    12201220#endif
    12211221  class BfsVisit {
    12221222  public:
    1223    
     1223
    12241224    /// \brief \ref Exception for uninitialized parameters.
    12251225    ///
     
    12281228    class UninitializedParameter : public lemon::UninitializedParameter {
    12291229    public:
    1230       virtual const char* what() const throw() 
     1230      virtual const char* what() const throw()
    12311231      {
    1232         return "lemon::BfsVisit::UninitializedParameter";
     1232        return "lemon::BfsVisit::UninitializedParameter";
    12331233      }
    12341234    };
     
    12671267    void create_maps() {
    12681268      if(!_reached) {
    1269         local_reached = true;
    1270         _reached = Traits::createReachedMap(*_digraph);
     1269        local_reached = true;
     1270        _reached = Traits::createReachedMap(*_digraph);
    12711271      }
    12721272    }
     
    12751275
    12761276    BfsVisit() {}
    1277    
     1277
    12781278  public:
    12791279
     
    12871287      typedef T ReachedMap;
    12881288      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1289         throw UninitializedParameter();
    1290       }
    1291     };
    1292     /// \brief \ref named-templ-param "Named parameter" for setting 
     1289        throw UninitializedParameter();
     1290      }
     1291    };
     1292    /// \brief \ref named-templ-param "Named parameter" for setting
    12931293    /// ReachedMap type
    12941294    ///
     
    12961296    template <class T>
    12971297    struct DefReachedMap : public BfsVisit< Digraph, Visitor,
    1298                                             DefReachedMapTraits<T> > {
     1298                                            DefReachedMapTraits<T> > {
    12991299      typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;
    13001300    };
    13011301    ///@}
    13021302
    1303   public:     
    1304    
     1303  public:
     1304
    13051305    /// \brief Constructor.
    13061306    ///
     
    13101310    /// \param visitor The visitor of the algorithm.
    13111311    ///
    1312     BfsVisit(const Digraph& digraph, Visitor& visitor) 
     1312    BfsVisit(const Digraph& digraph, Visitor& visitor)
    13131313      : _digraph(&digraph), _visitor(&visitor),
    1314         _reached(0), local_reached(false) {}
    1315    
     1314        _reached(0), local_reached(false) {}
     1315
    13161316    /// \brief Destructor.
    13171317    ///
     
    13301330    BfsVisit &reachedMap(ReachedMap &m) {
    13311331      if(local_reached) {
    1332         delete _reached;
    1333         local_reached = false;
     1332        delete _reached;
     1333        local_reached = false;
    13341334      }
    13351335      _reached = &m;
     
    13581358      _list_front = _list_back = -1;
    13591359      for (NodeIt u(*_digraph) ; u != INVALID ; ++u) {
    1360         _reached->set(u, false);
    1361       }
    1362     }
    1363    
     1360        _reached->set(u, false);
     1361      }
     1362    }
     1363
    13641364    /// \brief Adds a new source node.
    13651365    ///
     
    13671367    void addSource(Node s) {
    13681368      if(!(*_reached)[s]) {
    1369           _reached->set(s,true);
    1370           _visitor->start(s);
    1371           _visitor->reach(s);
     1369          _reached->set(s,true);
     1370          _visitor->start(s);
     1371          _visitor->reach(s);
    13721372          _list[++_list_back] = s;
    1373         }
    1374     }
    1375    
     1373        }
     1374    }
     1375
    13761376    /// \brief Processes the next node.
    13771377    ///
     
    13811381    ///
    13821382    /// \pre The queue must not be empty!
    1383     Node processNextNode() { 
     1383    Node processNextNode() {
    13841384      Node n = _list[++_list_front];
    13851385      _visitor->process(n);
     
    14681468    /// \return The next node to be processed or INVALID if the stack is
    14691469    /// empty.
    1470     Node nextNode() { 
     1470    Node nextNode() {
    14711471      return _list_front != _list_back ? _list[_list_front + 1] : INVALID;
    14721472    }
     
    14831483    /// Returns the number of the nodes to be processed in the queue.
    14841484    int queueSize() { return _list_back - _list_front; }
    1485    
     1485
    14861486    /// \brief Executes the algorithm.
    14871487    ///
     
    14931493      while ( !emptyQueue() ) processNextNode();
    14941494    }
    1495    
     1495
    14961496    /// \brief Executes the algorithm until \c dest is reached.
    14971497    ///
     
    15041504      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
    15051505    }
    1506    
     1506
    15071507    /// \brief Executes the algorithm until a condition is met.
    15081508    ///
     
    15221522      Node rnode = INVALID;
    15231523      while ( !emptyQueue() && rnode == INVALID ) {
    1524         processNextNode(nm, rnode);
     1524        processNextNode(nm, rnode);
    15251525      }
    15261526      return rnode;
     
    15431543
    15441544    /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph.
    1545     ///   
     1545    ///
    15461546    /// This method runs the %BFS algorithm in order to
    15471547    /// compute the %BFS path to each node. The algorithm computes
Note: See TracChangeset for help on using the changeset viewer.