Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
2 * lemon/bfs.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
22 ///\brief Bfs algorithm.
24 #include <lemon/list_graph.h>
25 #include <lemon/graph_utils.h>
26 #include <lemon/invalid.h>
27 #include <lemon/error.h>
28 #include <lemon/maps.h>
34 ///Default traits class of Bfs class.
36 ///Default traits class of Bfs class.
37 ///\param GR Graph type.
39 struct BfsDefaultTraits
41 ///The graph type the algorithm runs on.
43 ///\brief The type of the map that stores the last
44 ///edges of the shortest paths.
46 ///The type of the map that stores the last
47 ///edges of the shortest paths.
48 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
50 typedef typename Graph::template NodeMap<typename GR::Edge> PredMap;
51 ///Instantiates a PredMap.
53 ///This function instantiates a \ref PredMap.
54 ///\param G is the graph, to which we would like to define the PredMap.
55 ///\todo The graph alone may be insufficient to initialize
56 static PredMap *createPredMap(const GR &G)
58 return new PredMap(G);
60 ///The type of the map that indicates which nodes are processed.
62 ///The type of the map that indicates which nodes are processed.
63 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
64 ///\todo named parameter to set this type, function to read and write.
65 typedef NullMap<typename Graph::Node,bool> ProcessedMap;
66 ///Instantiates a ProcessedMap.
68 ///This function instantiates a \ref ProcessedMap.
69 ///\param g is the graph, to which
70 ///we would like to define the \ref ProcessedMap
72 static ProcessedMap *createProcessedMap(const GR &g)
74 static ProcessedMap *createProcessedMap(const GR &)
77 return new ProcessedMap();
79 ///The type of the map that indicates which nodes are reached.
81 ///The type of the map that indicates which nodes are reached.
82 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
83 ///\todo named parameter to set this type, function to read and write.
84 typedef typename Graph::template NodeMap<bool> ReachedMap;
85 ///Instantiates a ReachedMap.
87 ///This function instantiates a \ref ReachedMap.
88 ///\param G is the graph, to which
89 ///we would like to define the \ref ReachedMap.
90 static ReachedMap *createReachedMap(const GR &G)
92 return new ReachedMap(G);
94 ///The type of the map that stores the dists of the nodes.
96 ///The type of the map that stores the dists of the nodes.
97 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
99 typedef typename Graph::template NodeMap<int> DistMap;
100 ///Instantiates a DistMap.
102 ///This function instantiates a \ref DistMap.
103 ///\param G is the graph, to which we would like to define the \ref DistMap
104 static DistMap *createDistMap(const GR &G)
106 return new DistMap(G);
110 ///%BFS algorithm class.
113 ///This class provides an efficient implementation of the %BFS algorithm.
115 ///\param GR The graph type the algorithm runs on. The default value is
116 ///\ref ListGraph. The value of GR is not used directly by Bfs, it
117 ///is only passed to \ref BfsDefaultTraits.
118 ///\param TR Traits class to set various data types used by the algorithm.
119 ///The default traits class is
120 ///\ref BfsDefaultTraits "BfsDefaultTraits<GR>".
121 ///See \ref BfsDefaultTraits for the documentation of
122 ///a Bfs traits class.
124 ///\author Alpar Juttner
127 template <typename GR,
130 template <typename GR=ListGraph,
131 typename TR=BfsDefaultTraits<GR> >
136 * \brief \ref Exception for uninitialized parameters.
138 * This error represents problems in the initialization
139 * of the parameters of the algorithms.
141 class UninitializedParameter : public lemon::UninitializedParameter {
143 virtual const char* exceptionName() const {
144 return "lemon::Bfs::UninitializedParameter";
149 ///The type of the underlying graph.
150 typedef typename TR::Graph Graph;
152 typedef typename Graph::Node Node;
154 typedef typename Graph::NodeIt NodeIt;
156 typedef typename Graph::Edge Edge;
158 typedef typename Graph::OutEdgeIt OutEdgeIt;
160 ///\brief The type of the map that stores the last
161 ///edges of the shortest paths.
162 typedef typename TR::PredMap PredMap;
163 ///The type of the map indicating which nodes are reached.
164 typedef typename TR::ReachedMap ReachedMap;
165 ///The type of the map indicating which nodes are processed.
166 typedef typename TR::ProcessedMap ProcessedMap;
167 ///The type of the map that stores the dists of the nodes.
168 typedef typename TR::DistMap DistMap;
170 /// Pointer to the underlying graph.
172 ///Pointer to the map of predecessors edges.
174 ///Indicates if \ref _pred is locally allocated (\c true) or not.
176 ///Pointer to the map of distances.
178 ///Indicates if \ref _dist is locally allocated (\c true) or not.
180 ///Pointer to the map of reached status of the nodes.
181 ReachedMap *_reached;
182 ///Indicates if \ref _reached is locally allocated (\c true) or not.
184 ///Pointer to the map of processed status of the nodes.
185 ProcessedMap *_processed;
186 ///Indicates if \ref _processed is locally allocated (\c true) or not.
187 bool local_processed;
189 std::vector<typename Graph::Node> _queue;
190 int _queue_head,_queue_tail,_queue_next_dist;
193 ///Creates the maps if necessary.
195 ///\todo Better memory allocation (instead of new).
200 _pred = Traits::createPredMap(*G);
204 _dist = Traits::createDistMap(*G);
207 local_reached = true;
208 _reached = Traits::createReachedMap(*G);
211 local_processed = true;
212 _processed = Traits::createProcessedMap(*G);
224 ///\name Named template parameters
229 struct DefPredMapTraits : public Traits {
231 static PredMap *createPredMap(const Graph &)
233 throw UninitializedParameter();
236 ///\ref named-templ-param "Named parameter" for setting PredMap type
238 ///\ref named-templ-param "Named parameter" for setting PredMap type
241 struct DefPredMap : public Bfs< Graph, DefPredMapTraits<T> > {
242 typedef Bfs< Graph, DefPredMapTraits<T> > Create;
246 struct DefDistMapTraits : public Traits {
248 static DistMap *createDistMap(const Graph &)
250 throw UninitializedParameter();
253 ///\ref named-templ-param "Named parameter" for setting DistMap type
255 ///\ref named-templ-param "Named parameter" for setting DistMap type
258 struct DefDistMap : public Bfs< Graph, DefDistMapTraits<T> > {
259 typedef Bfs< Graph, DefDistMapTraits<T> > Create;
263 struct DefReachedMapTraits : public Traits {
264 typedef T ReachedMap;
265 static ReachedMap *createReachedMap(const Graph &)
267 throw UninitializedParameter();
270 ///\ref named-templ-param "Named parameter" for setting ReachedMap type
272 ///\ref named-templ-param "Named parameter" for setting ReachedMap type
275 struct DefReachedMap : public Bfs< Graph, DefReachedMapTraits<T> > {
276 typedef Bfs< Graph, DefReachedMapTraits<T> > Create;
280 struct DefProcessedMapTraits : public Traits {
281 typedef T ProcessedMap;
282 static ProcessedMap *createProcessedMap(const Graph &G)
284 throw UninitializedParameter();
287 ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
289 ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
292 struct DefProcessedMap : public Bfs< Graph, DefProcessedMapTraits<T> > {
293 typedef Bfs< Graph, DefProcessedMapTraits<T> > Create;
296 struct DefGraphProcessedMapTraits : public Traits {
297 typedef typename Graph::template NodeMap<bool> ProcessedMap;
298 static ProcessedMap *createProcessedMap(const Graph &G)
300 return new ProcessedMap(G);
303 ///\brief \ref named-templ-param "Named parameter"
304 ///for setting the ProcessedMap type to be Graph::NodeMap<bool>.
306 ///\ref named-templ-param "Named parameter"
307 ///for setting the ProcessedMap type to be Graph::NodeMap<bool>.
308 ///If you don't set it explicitly, it will be automatically allocated.
310 struct DefProcessedMapToBeDefaultMap :
311 public Bfs< Graph, DefGraphProcessedMapTraits> {
312 typedef Bfs< Graph, DefGraphProcessedMapTraits> Create;
321 ///\param _G the graph the algorithm will run on.
323 Bfs(const Graph& _G) :
325 _pred(NULL), local_pred(false),
326 _dist(NULL), local_dist(false),
327 _reached(NULL), local_reached(false),
328 _processed(NULL), local_processed(false)
334 if(local_pred) delete _pred;
335 if(local_dist) delete _dist;
336 if(local_reached) delete _reached;
337 if(local_processed) delete _processed;
340 ///Sets the map storing the predecessor edges.
342 ///Sets the map storing the predecessor edges.
343 ///If you don't use this function before calling \ref run(),
344 ///it will allocate one. The destructor deallocates this
345 ///automatically allocated map, of course.
346 ///\return <tt> (*this) </tt>
347 Bfs &predMap(PredMap &m)
357 ///Sets the map indicating the reached nodes.
359 ///Sets the map indicating the reached nodes.
360 ///If you don't use this function before calling \ref run(),
361 ///it will allocate one. The destructor deallocates this
362 ///automatically allocated map, of course.
363 ///\return <tt> (*this) </tt>
364 Bfs &reachedMap(ReachedMap &m)
374 ///Sets the map indicating the processed nodes.
376 ///Sets the map indicating the processed nodes.
377 ///If you don't use this function before calling \ref run(),
378 ///it will allocate one. The destructor deallocates this
379 ///automatically allocated map, of course.
380 ///\return <tt> (*this) </tt>
381 Bfs &processedMap(ProcessedMap &m)
383 if(local_processed) {
385 local_processed=false;
391 ///Sets the map storing the distances calculated by the algorithm.
393 ///Sets the map storing the distances calculated by the algorithm.
394 ///If you don't use this function before calling \ref run(),
395 ///it will allocate one. The destructor deallocates this
396 ///automatically allocated map, of course.
397 ///\return <tt> (*this) </tt>
398 Bfs &distMap(DistMap &m)
409 ///\name Execution control
410 ///The simplest way to execute the algorithm is to use
411 ///one of the member functions called \c run(...).
413 ///If you need more control on the execution,
414 ///first you must call \ref init(), then you can add several source nodes
415 ///with \ref addSource().
416 ///Finally \ref start() will perform the actual path
421 ///Initializes the internal data structures.
423 ///Initializes the internal data structures.
428 _queue.resize(countNodes(*G));
429 _queue_head=_queue_tail=0;
431 for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
432 _pred->set(u,INVALID);
433 _reached->set(u,false);
434 _processed->set(u,false);
438 ///Adds a new source node.
440 ///Adds a new source node to the set of nodes to be processed.
442 void addSource(Node s)
446 _reached->set(s,true);
447 _pred->set(s,INVALID);
449 _queue[_queue_head++]=s;
450 _queue_next_dist=_queue_head;
454 ///Processes the next node.
456 ///Processes the next node.
458 ///\return The processed node.
460 ///\warning The queue must not be empty!
461 Node processNextNode()
463 if(_queue_tail==_queue_next_dist) {
465 _queue_next_dist=_queue_head;
467 Node n=_queue[_queue_tail++];
468 _processed->set(n,true);
470 for(OutEdgeIt e(*G,n);e!=INVALID;++e)
471 if(!(*_reached)[m=G->target(e)]) {
472 _queue[_queue_head++]=m;
473 _reached->set(m,true);
475 _dist->set(m,_curr_dist);
480 ///Next node to be processed.
482 ///Next node to be processed.
484 ///\return The next node to be processed or INVALID if the queue is
488 return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID;
491 ///\brief Returns \c false if there are nodes
492 ///to be processed in the queue
494 ///Returns \c false if there are nodes
495 ///to be processed in the queue
496 bool emptyQueue() { return _queue_tail==_queue_head; }
497 ///Returns the number of the nodes to be processed.
499 ///Returns the number of the nodes to be processed in the queue.
501 int queueSize() { return _queue_head-_queue_tail; }
503 ///Executes the algorithm.
505 ///Executes the algorithm.
507 ///\pre init() must be called and at least one node should be added
508 ///with addSource() before using this function.
510 ///This method runs the %BFS algorithm from the root node(s)
513 ///shortest path to each node. The algorithm computes
514 ///- The shortest path tree.
515 ///- The distance of each node from the root(s).
519 while ( !emptyQueue() ) processNextNode();
522 ///Executes the algorithm until \c dest is reached.
524 ///Executes the algorithm until \c dest is reached.
526 ///\pre init() must be called and at least one node should be added
527 ///with addSource() before using this function.
529 ///This method runs the %BFS algorithm from the root node(s)
532 ///shortest path to \c dest. The algorithm computes
533 ///- The shortest path to \c dest.
534 ///- The distance of \c dest from the root(s).
536 void start(Node dest)
538 while ( !emptyQueue() && _queue[_queue_tail]!=dest ) processNextNode();
541 ///Executes the algorithm until a condition is met.
543 ///Executes the algorithm until a condition is met.
545 ///\pre init() must be called and at least one node should be added
546 ///with addSource() before using this function.
548 ///\param nm must be a bool (or convertible) node map. The algorithm
549 ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
551 void start(const NM &nm)
553 while ( !emptyQueue() && !nm[_queue[_queue_tail]] ) processNextNode();
556 ///Runs %BFS algorithm from node \c s.
558 ///This method runs the %BFS algorithm from a root node \c s
561 ///shortest path to each node. The algorithm computes
562 ///- The shortest path tree.
563 ///- The distance of each node from the root.
565 ///\note d.run(s) is just a shortcut of the following code.
577 ///Finds the shortest path between \c s and \c t.
579 ///Finds the shortest path between \c s and \c t.
581 ///\return The length of the shortest s---t path if there exists one,
583 ///\note Apart from the return value, d.run(s) is
584 ///just a shortcut of the following code.
590 int run(Node s,Node t) {
594 return reached(t)?_curr_dist-1+(_queue_tail==_queue_next_dist):0;
599 ///\name Query Functions
600 ///The result of the %BFS algorithm can be obtained using these
602 ///Before the use of these functions,
603 ///either run() or start() must be called.
607 ///Copies the shortest path to \c t into \c p
609 ///This function copies the shortest path to \c t into \c p.
610 ///If \c t is a source itself or unreachable, then it does not
612 ///\return Returns \c true if a path to \c t was actually copied to \c p,
613 ///\c false otherwise.
616 bool getPath(P &p,Node t)
620 typename P::Builder b(p);
621 for(b.setStartNode(t);predEdge(t)!=INVALID;t=predNode(t))
622 b.pushFront(predEdge(t));
629 ///The distance of a node from the root(s).
631 ///Returns the distance of a node from the root(s).
632 ///\pre \ref run() must be called before using this function.
633 ///\warning If node \c v in unreachable from the root(s) the return value
634 ///of this function is undefined.
635 int dist(Node v) const { return (*_dist)[v]; }
637 ///Returns the 'previous edge' of the shortest path tree.
639 ///For a node \c v it returns the 'previous edge'
640 ///of the shortest path tree,
641 ///i.e. it returns the last edge of a shortest path from the root(s) to \c
642 ///v. It is \ref INVALID
643 ///if \c v is unreachable from the root(s) or \c v is a root. The
644 ///shortest path tree used here is equal to the shortest path tree used in
646 ///\pre Either \ref run() or \ref start() must be called before using
648 Edge predEdge(Node v) const { return (*_pred)[v];}
650 ///Returns the 'previous node' of the shortest path tree.
652 ///For a node \c v it returns the 'previous node'
653 ///of the shortest path tree,
654 ///i.e. it returns the last but one node from a shortest path from the
656 ///It is INVALID if \c v is unreachable from the root(s) or
657 ///if \c v itself a root.
658 ///The shortest path tree used here is equal to the shortest path
659 ///tree used in \ref predEdge().
660 ///\pre Either \ref run() or \ref start() must be called before
661 ///using this function.
662 Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
663 G->source((*_pred)[v]); }
665 ///Returns a reference to the NodeMap of distances.
667 ///Returns a reference to the NodeMap of distances.
668 ///\pre Either \ref run() or \ref init() must
669 ///be called before using this function.
670 const DistMap &distMap() const { return *_dist;}
672 ///Returns a reference to the shortest path tree map.
674 ///Returns a reference to the NodeMap of the edges of the
675 ///shortest path tree.
676 ///\pre Either \ref run() or \ref init()
677 ///must be called before using this function.
678 const PredMap &predMap() const { return *_pred;}
680 ///Checks if a node is reachable from the root.
682 ///Returns \c true if \c v is reachable from the root.
683 ///\warning The source nodes are indicated as unreached.
684 ///\pre Either \ref run() or \ref start()
685 ///must be called before using this function.
687 bool reached(Node v) { return (*_reached)[v]; }
692 ///Default traits class of Bfs function.
694 ///Default traits class of Bfs function.
695 ///\param GR Graph type.
697 struct BfsWizardDefaultTraits
699 ///The graph type the algorithm runs on.
701 ///\brief The type of the map that stores the last
702 ///edges of the shortest paths.
704 ///The type of the map that stores the last
705 ///edges of the shortest paths.
706 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
708 typedef NullMap<typename Graph::Node,typename GR::Edge> PredMap;
709 ///Instantiates a PredMap.
711 ///This function instantiates a \ref PredMap.
712 ///\param g is the graph, to which we would like to define the PredMap.
713 ///\todo The graph alone may be insufficient to initialize
715 static PredMap *createPredMap(const GR &g)
717 static PredMap *createPredMap(const GR &)
720 return new PredMap();
723 ///The type of the map that indicates which nodes are processed.
725 ///The type of the map that indicates which nodes are processed.
726 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
727 ///\todo named parameter to set this type, function to read and write.
728 typedef NullMap<typename Graph::Node,bool> ProcessedMap;
729 ///Instantiates a ProcessedMap.
731 ///This function instantiates a \ref ProcessedMap.
732 ///\param g is the graph, to which
733 ///we would like to define the \ref ProcessedMap
735 static ProcessedMap *createProcessedMap(const GR &g)
737 static ProcessedMap *createProcessedMap(const GR &)
740 return new ProcessedMap();
742 ///The type of the map that indicates which nodes are reached.
744 ///The type of the map that indicates which nodes are reached.
745 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
746 ///\todo named parameter to set this type, function to read and write.
747 typedef typename Graph::template NodeMap<bool> ReachedMap;
748 ///Instantiates a ReachedMap.
750 ///This function instantiates a \ref ReachedMap.
751 ///\param G is the graph, to which
752 ///we would like to define the \ref ReachedMap.
753 static ReachedMap *createReachedMap(const GR &G)
755 return new ReachedMap(G);
757 ///The type of the map that stores the dists of the nodes.
759 ///The type of the map that stores the dists of the nodes.
760 ///It must meet the \ref concept::WriteMap "WriteMap" concept.
762 typedef NullMap<typename Graph::Node,int> DistMap;
763 ///Instantiates a DistMap.
765 ///This function instantiates a \ref DistMap.
766 ///\param g is the graph, to which we would like to define the \ref DistMap
768 static DistMap *createDistMap(const GR &g)
770 static DistMap *createDistMap(const GR &)
773 return new DistMap();
777 /// Default traits used by \ref BfsWizard
779 /// To make it easier to use Bfs algorithm
780 ///we have created a wizard class.
781 /// This \ref BfsWizard class needs default traits,
782 ///as well as the \ref Bfs class.
783 /// The \ref BfsWizardBase is a class to be the default traits of the
784 /// \ref BfsWizard class.
786 class BfsWizardBase : public BfsWizardDefaultTraits<GR>
789 typedef BfsWizardDefaultTraits<GR> Base;
791 /// Type of the nodes in the graph.
792 typedef typename Base::Graph::Node Node;
794 /// Pointer to the underlying graph.
796 ///Pointer to the map of reached nodes.
798 ///Pointer to the map of processed nodes.
800 ///Pointer to the map of predecessors edges.
802 ///Pointer to the map of distances.
804 ///Pointer to the source node.
810 /// This constructor does not require parameters, therefore it initiates
811 /// all of the attributes to default values (0, INVALID).
812 BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
813 _dist(0), _source(INVALID) {}
817 /// This constructor requires some parameters,
818 /// listed in the parameters list.
819 /// Others are initiated to 0.
820 /// \param g is the initial value of \ref _g
821 /// \param s is the initial value of \ref _source
822 BfsWizardBase(const GR &g, Node s=INVALID) :
823 _g((void *)&g), _reached(0), _processed(0), _pred(0),
824 _dist(0), _source(s) {}
828 /// A class to make the usage of Bfs algorithm easier
830 /// This class is created to make it easier to use Bfs algorithm.
831 /// It uses the functions and features of the plain \ref Bfs,
832 /// but it is much simpler to use it.
834 /// Simplicity means that the way to change the types defined
835 /// in the traits class is based on functions that returns the new class
836 /// and not on templatable built-in classes.
837 /// When using the plain \ref Bfs
838 /// the new class with the modified type comes from
839 /// the original class by using the ::
840 /// operator. In the case of \ref BfsWizard only
841 /// a function have to be called and it will
842 /// return the needed class.
844 /// It does not have own \ref run method. When its \ref run method is called
845 /// it initiates a plain \ref Bfs class, and calls the \ref Bfs::run
848 class BfsWizard : public TR
852 ///The type of the underlying graph.
853 typedef typename TR::Graph Graph;
855 typedef typename Graph::Node Node;
857 typedef typename Graph::NodeIt NodeIt;
859 typedef typename Graph::Edge Edge;
861 typedef typename Graph::OutEdgeIt OutEdgeIt;
863 ///\brief The type of the map that stores
865 typedef typename TR::ReachedMap ReachedMap;
866 ///\brief The type of the map that stores
867 ///the processed nodes
868 typedef typename TR::ProcessedMap ProcessedMap;
869 ///\brief The type of the map that stores the last
870 ///edges of the shortest paths.
871 typedef typename TR::PredMap PredMap;
872 ///The type of the map that stores the dists of the nodes.
873 typedef typename TR::DistMap DistMap;
877 BfsWizard() : TR() {}
879 /// Constructor that requires parameters.
881 /// Constructor that requires parameters.
882 /// These parameters will be the default values for the traits class.
883 BfsWizard(const Graph &g, Node s=INVALID) :
887 BfsWizard(const TR &b) : TR(b) {}
891 ///Runs Bfs algorithm from a given node.
893 ///Runs Bfs algorithm from a given node.
894 ///The node can be given by the \ref source function.
897 if(Base::_source==INVALID) throw UninitializedParameter();
898 Bfs<Graph,TR> alg(*(Graph*)Base::_g);
900 alg.reachedMap(*(ReachedMap*)Base::_reached);
901 if(Base::_processed) alg.processedMap(*(ProcessedMap*)Base::_processed);
902 if(Base::_pred) alg.predMap(*(PredMap*)Base::_pred);
903 if(Base::_dist) alg.distMap(*(DistMap*)Base::_dist);
904 alg.run(Base::_source);
907 ///Runs Bfs algorithm from the given node.
909 ///Runs Bfs algorithm from the given node.
910 ///\param s is the given source.
918 struct DefPredMapBase : public Base {
920 static PredMap *createPredMap(const Graph &) { return 0; };
921 DefPredMapBase(const TR &b) : TR(b) {}
924 ///\brief \ref named-templ-param "Named parameter"
925 ///function for setting PredMap
927 /// \ref named-templ-param "Named parameter"
928 ///function for setting PredMap
931 BfsWizard<DefPredMapBase<T> > predMap(const T &t)
933 Base::_pred=(void *)&t;
934 return BfsWizard<DefPredMapBase<T> >(*this);
939 struct DefReachedMapBase : public Base {
940 typedef T ReachedMap;
941 static ReachedMap *createReachedMap(const Graph &) { return 0; };
942 DefReachedMapBase(const TR &b) : TR(b) {}
945 ///\brief \ref named-templ-param "Named parameter"
946 ///function for setting ReachedMap
948 /// \ref named-templ-param "Named parameter"
949 ///function for setting ReachedMap
952 BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
954 Base::_pred=(void *)&t;
955 return BfsWizard<DefReachedMapBase<T> >(*this);
960 struct DefProcessedMapBase : public Base {
961 typedef T ProcessedMap;
962 static ProcessedMap *createProcessedMap(const Graph &) { return 0; };
963 DefProcessedMapBase(const TR &b) : TR(b) {}
966 ///\brief \ref named-templ-param "Named parameter"
967 ///function for setting ProcessedMap
969 /// \ref named-templ-param "Named parameter"
970 ///function for setting ProcessedMap
973 BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
975 Base::_pred=(void *)&t;
976 return BfsWizard<DefProcessedMapBase<T> >(*this);
981 struct DefDistMapBase : public Base {
983 static DistMap *createDistMap(const Graph &) { return 0; };
984 DefDistMapBase(const TR &b) : TR(b) {}
987 ///\brief \ref named-templ-param "Named parameter"
988 ///function for setting DistMap type
990 /// \ref named-templ-param "Named parameter"
991 ///function for setting DistMap type
994 BfsWizard<DefDistMapBase<T> > distMap(const T &t)
996 Base::_dist=(void *)&t;
997 return BfsWizard<DefDistMapBase<T> >(*this);
1000 /// Sets the source node, from which the Bfs algorithm runs.
1002 /// Sets the source node, from which the Bfs algorithm runs.
1003 /// \param s is the source node.
1004 BfsWizard<TR> &source(Node s)
1012 ///Function type interface for Bfs algorithm.
1014 /// \ingroup flowalgs
1015 ///Function type interface for Bfs algorithm.
1017 ///This function also has several
1018 ///\ref named-templ-func-param "named parameters",
1019 ///they are declared as the members of class \ref BfsWizard.
1021 ///example shows how to use these parameters.
1023 /// bfs(g,source).predMap(preds).run();
1025 ///\warning Don't forget to put the \ref BfsWizard::run() "run()"
1026 ///to the end of the parameter list.
1030 BfsWizard<BfsWizardBase<GR> >
1031 bfs(const GR &g,typename GR::Node s=INVALID)
1033 return BfsWizard<BfsWizardBase<GR> >(g,s);
1036 } //END OF NAMESPACE LEMON