Changes in lemon/bfs.h [301:9db8964f0cf6:525:9605e051942f] in lemon
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bfs.h
r301 r525 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-200 85 * Copyright (C) 2003-2009 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 50 50 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 51 51 typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; 52 ///Instantiates a PredMap.53 54 ///This function instantiates a PredMap.52 ///Instantiates a \c PredMap. 53 54 ///This function instantiates a \ref PredMap. 55 55 ///\param g is the digraph, to which we would like to define the 56 /// PredMap.56 ///\ref PredMap. 57 57 static PredMap *createPredMap(const Digraph &g) 58 58 { … … 65 65 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 66 66 typedef NullMap<typename Digraph::Node,bool> ProcessedMap; 67 ///Instantiates a ProcessedMap.68 69 ///This function instantiates a ProcessedMap.67 ///Instantiates a \c ProcessedMap. 68 69 ///This function instantiates a \ref ProcessedMap. 70 70 ///\param g is the digraph, to which 71 ///we would like to define the ProcessedMap71 ///we would like to define the \ref ProcessedMap 72 72 #ifdef DOXYGEN 73 73 static ProcessedMap *createProcessedMap(const Digraph &g) … … 84 84 ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 85 85 typedef typename Digraph::template NodeMap<bool> ReachedMap; 86 ///Instantiates a ReachedMap.87 88 ///This function instantiates a ReachedMap.86 ///Instantiates a \c ReachedMap. 87 88 ///This function instantiates a \ref ReachedMap. 89 89 ///\param g is the digraph, to which 90 ///we would like to define the ReachedMap.90 ///we would like to define the \ref ReachedMap. 91 91 static ReachedMap *createReachedMap(const Digraph &g) 92 92 { … … 99 99 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 100 100 typedef typename Digraph::template NodeMap<int> DistMap; 101 ///Instantiates a DistMap.102 103 ///This function instantiates a DistMap.101 ///Instantiates a \c DistMap. 102 103 ///This function instantiates a \ref DistMap. 104 104 ///\param g is the digraph, to which we would like to define the 105 /// DistMap.105 ///\ref DistMap. 106 106 static DistMap *createDistMap(const Digraph &g) 107 107 { … … 120 120 /// 121 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. 124 ///\tparam TR Traits class to set various data types used by the algorithm. 125 ///The default traits class is 126 ///\ref BfsDefaultTraits "BfsDefaultTraits<GR>". 127 ///See \ref BfsDefaultTraits for the documentation of 128 ///a Bfs traits class. 122 ///The default type is \ref ListDigraph. 129 123 #ifdef DOXYGEN 130 124 template <typename GR, … … 152 146 typedef PredMapPath<Digraph, PredMap> Path; 153 147 154 ///The traits class.148 ///The \ref BfsDefaultTraits "traits class" of the algorithm. 155 149 typedef TR Traits; 156 150 … … 214 208 typedef Bfs Create; 215 209 216 ///\name Named template parameters210 ///\name Named Template Parameters 217 211 218 212 ///@{ … … 228 222 }; 229 223 ///\brief \ref named-templ-param "Named parameter" for setting 230 /// PredMap type.224 ///\c PredMap type. 231 225 /// 232 226 ///\ref named-templ-param "Named parameter" for setting 233 ///PredMap type. 227 ///\c PredMap type. 228 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 234 229 template <class T> 235 230 struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > { … … 247 242 }; 248 243 ///\brief \ref named-templ-param "Named parameter" for setting 249 /// DistMap type.244 ///\c DistMap type. 250 245 /// 251 246 ///\ref named-templ-param "Named parameter" for setting 252 ///DistMap type. 247 ///\c DistMap type. 248 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 253 249 template <class T> 254 250 struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > { … … 266 262 }; 267 263 ///\brief \ref named-templ-param "Named parameter" for setting 268 /// ReachedMap type.264 ///\c ReachedMap type. 269 265 /// 270 266 ///\ref named-templ-param "Named parameter" for setting 271 ///ReachedMap type. 267 ///\c ReachedMap type. 268 ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 272 269 template <class T> 273 270 struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > { … … 285 282 }; 286 283 ///\brief \ref named-templ-param "Named parameter" for setting 287 /// ProcessedMap type.284 ///\c ProcessedMap type. 288 285 /// 289 286 ///\ref named-templ-param "Named parameter" for setting 290 ///ProcessedMap type. 287 ///\c ProcessedMap type. 288 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 291 289 template <class T> 292 290 struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > { … … 303 301 }; 304 302 ///\brief \ref named-templ-param "Named parameter" for setting 305 /// ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.303 ///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. 306 304 /// 307 305 ///\ref named-templ-param "Named parameter" for setting 308 /// ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.306 ///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. 309 307 ///If you don't set it explicitly, it will be automatically allocated. 310 308 struct SetStandardProcessedMap : … … 341 339 342 340 ///Sets the map that stores the predecessor arcs. 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. 341 ///If you don't use this function before calling \ref run(Node) "run()" 342 ///or \ref init(), an instance will be allocated automatically. 343 ///The destructor deallocates this automatically allocated map, 344 ///of course. 346 345 ///\return <tt> (*this) </tt> 347 346 Bfs &predMap(PredMap &m) … … 358 357 359 358 ///Sets the map that indicates which nodes are reached. 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. 359 ///If you don't use this function before calling \ref run(Node) "run()" 360 ///or \ref init(), an instance will be allocated automatically. 361 ///The destructor deallocates this automatically allocated map, 362 ///of course. 363 363 ///\return <tt> (*this) </tt> 364 364 Bfs &reachedMap(ReachedMap &m) … … 375 375 376 376 ///Sets the map that indicates which nodes are processed. 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. 377 ///If you don't use this function before calling \ref run(Node) "run()" 378 ///or \ref init(), an instance will be allocated automatically. 379 ///The destructor deallocates this automatically allocated map, 380 ///of course. 380 381 ///\return <tt> (*this) </tt> 381 382 Bfs &processedMap(ProcessedMap &m) … … 393 394 ///Sets the map that stores the distances of the nodes calculated by 394 395 ///the algorithm. 395 ///If you don't use this function before calling \ref run(), 396 ///it will allocate one. The destructor deallocates this 397 ///automatically allocated map, of course. 396 ///If you don't use this function before calling \ref run(Node) "run()" 397 ///or \ref init(), an instance will be allocated automatically. 398 ///The destructor deallocates this automatically allocated map, 399 ///of course. 398 400 ///\return <tt> (*this) </tt> 399 401 Bfs &distMap(DistMap &m) … … 409 411 public: 410 412 411 ///\name Execution control 412 ///The simplest way to execute the algorithm is to use 413 ///one of the member functions called \ref lemon::Bfs::run() "run()". 414 ///\n 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. 413 ///\name Execution Control 414 ///The simplest way to execute the BFS algorithm is to use one of the 415 ///member functions called \ref run(Node) "run()".\n 416 ///If you need more control on the execution, first you have to call 417 ///\ref init(), then you can add several source nodes with 418 ///\ref addSource(). Finally the actual path computation can be 419 ///performed with one of the \ref start() functions. 420 420 421 421 ///@{ 422 422 423 ///\brief Initializes the internal data structures. 424 /// 423 425 ///Initializes the internal data structures. 424 425 ///Initializes the internal data structures.426 ///427 426 void init() 428 427 { … … 558 557 } 559 558 560 ///\brief Returns \c false if there are nodes 561 ///to be processed. 562 /// 563 ///Returns \c false if there are nodes 564 ///to be processed in the queue. 559 ///Returns \c false if there are nodes to be processed. 560 561 ///Returns \c false if there are nodes to be processed 562 ///in the queue. 565 563 bool emptyQueue() const { return _queue_tail==_queue_head; } 566 564 567 565 ///Returns the number of the nodes to be processed. 568 566 569 ///Returns the number of the nodes to be processed in the queue. 567 ///Returns the number of the nodes to be processed 568 ///in the queue. 570 569 int queueSize() const { return _queue_head-_queue_tail; } 571 570 … … 732 731 733 732 ///\name Query Functions 734 ///The result of the %BFS algorithm can be obtained using these733 ///The results of the BFS algorithm can be obtained using these 735 734 ///functions.\n 736 ///Either \ref lemon::Bfs::run() "run()" or \ref lemon::Bfs::start()737 /// "start()" must be calledbefore using them.735 ///Either \ref run(Node) "run()" or \ref start() should be called 736 ///before using them. 738 737 739 738 ///@{ … … 743 742 ///Returns the shortest path to a node. 744 743 /// 745 ///\warning \c t should be reach ablefrom the root(s).746 /// 747 ///\pre Either \ref run( ) or \ref start() must be called before748 /// using this function.744 ///\warning \c t should be reached from the root(s). 745 /// 746 ///\pre Either \ref run(Node) "run()" or \ref init() 747 ///must be called before using this function. 749 748 Path path(Node t) const { return Path(*G, *_pred, t); } 750 749 … … 753 752 ///Returns the distance of a node from the root(s). 754 753 /// 755 ///\warning If node \c v is not reach ablefrom the root(s), then754 ///\warning If node \c v is not reached from the root(s), then 756 755 ///the return value of this function is undefined. 757 756 /// 758 ///\pre Either \ref run( ) or \ref start() must be called before759 /// using this function.757 ///\pre Either \ref run(Node) "run()" or \ref init() 758 ///must be called before using this function. 760 759 int dist(Node v) const { return (*_dist)[v]; } 761 760 … … 764 763 ///This function returns the 'previous arc' of the shortest path 765 764 ///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 v767 ///is not reach ablefrom the root(s) or if \c v is a root.765 ///shortest path from a root to \c v. It is \c INVALID if \c v 766 ///is not reached from the root(s) or if \c v is a root. 768 767 /// 769 768 ///The shortest path tree used here is equal to the shortest path 770 769 ///tree used in \ref predNode(). 771 770 /// 772 ///\pre Either \ref run( ) or \ref start() must be called before773 /// using this function.771 ///\pre Either \ref run(Node) "run()" or \ref init() 772 ///must be called before using this function. 774 773 Arc predArc(Node v) const { return (*_pred)[v];} 775 774 … … 778 777 ///This function returns the 'previous node' of the shortest path 779 778 ///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 INVALID781 ///if \c v is not reach ablefrom the root(s) or if \c v is a root.779 ///from a shortest path from a root to \c v. It is \c INVALID 780 ///if \c v is not reached from the root(s) or if \c v is a root. 782 781 /// 783 782 ///The shortest path tree used here is equal to the shortest path 784 783 ///tree used in \ref predArc(). 785 784 /// 786 ///\pre Either \ref run( ) or \ref start() must be called before787 /// using this function.785 ///\pre Either \ref run(Node) "run()" or \ref init() 786 ///must be called before using this function. 788 787 Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: 789 788 G->source((*_pred)[v]); } … … 795 794 ///of the nodes calculated by the algorithm. 796 795 /// 797 ///\pre Either \ref run( )or \ref init()796 ///\pre Either \ref run(Node) "run()" or \ref init() 798 797 ///must be called before using this function. 799 798 const DistMap &distMap() const { return *_dist;} … … 805 804 ///arcs, which form the shortest path tree. 806 805 /// 807 ///\pre Either \ref run( )or \ref init()806 ///\pre Either \ref run(Node) "run()" or \ref init() 808 807 ///must be called before using this function. 809 808 const PredMap &predMap() const { return *_pred;} 810 809 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). 814 ///\pre Either \ref run() or \ref start() 810 ///Checks if a node is reached from the root(s). 811 812 ///Returns \c true if \c v is reached from the root(s). 813 /// 814 ///\pre Either \ref run(Node) "run()" or \ref init() 815 815 ///must be called before using this function. 816 816 bool reached(Node v) const { return (*_reached)[v]; } … … 958 958 /// This auxiliary class is created to implement the 959 959 /// \ref bfs() "function-type interface" of \ref Bfs algorithm. 960 /// It does not have own \ref run( ) method, it uses the functions961 /// and features of the plain \ref Bfs.960 /// It does not have own \ref run(Node) "run()" method, it uses the 961 /// functions and features of the plain \ref Bfs. 962 962 /// 963 963 /// This class should only be used through the \ref bfs() function, … … 1179 1179 /// bool reached = bfs(g).path(p).dist(d).run(s,t); 1180 1180 ///\endcode 1181 ///\warning Don't forget to put the \ref BfsWizard::run( ) "run()"1181 ///\warning Don't forget to put the \ref BfsWizard::run(Node) "run()" 1182 1182 ///to the end of the parameter list. 1183 1183 ///\sa BfsWizard … … 1195 1195 /// This class defines the interface of the BfsVisit events, and 1196 1196 /// it could be the base of a real visitor class. 1197 template <typename _Digraph>1197 template <typename GR> 1198 1198 struct BfsVisitor { 1199 typedef _DigraphDigraph;1199 typedef GR Digraph; 1200 1200 typedef typename Digraph::Arc Arc; 1201 1201 typedef typename Digraph::Node Node; … … 1225 1225 }; 1226 1226 #else 1227 template <typename _Digraph>1227 template <typename GR> 1228 1228 struct BfsVisitor { 1229 typedef _DigraphDigraph;1229 typedef GR Digraph; 1230 1230 typedef typename Digraph::Arc Arc; 1231 1231 typedef typename Digraph::Node Node; … … 1255 1255 /// 1256 1256 /// Default traits class of BfsVisit class. 1257 /// \tparam _DigraphThe type of the digraph the algorithm runs on.1258 template<class _Digraph>1257 /// \tparam GR The type of the digraph the algorithm runs on. 1258 template<class GR> 1259 1259 struct BfsVisitDefaultTraits { 1260 1260 1261 1261 /// \brief The type of the digraph the algorithm runs on. 1262 typedef _DigraphDigraph;1262 typedef GR Digraph; 1263 1263 1264 1264 /// \brief The type of the map that indicates which nodes are reached. … … 1281 1281 /// \ingroup search 1282 1282 /// 1283 /// \brief %BFS algorithm class with visitor interface.1283 /// \brief BFS algorithm class with visitor interface. 1284 1284 /// 1285 /// This class provides an efficient implementation of the %BFS algorithm1285 /// This class provides an efficient implementation of the BFS algorithm 1286 1286 /// with visitor interface. 1287 1287 /// 1288 /// The %BfsVisit class provides an alternative interface to the Bfs1288 /// The BfsVisit class provides an alternative interface to the Bfs 1289 1289 /// class. It works with callback mechanism, the BfsVisit object calls 1290 1290 /// the member functions of the \c Visitor class on every BFS event. … … 1295 1295 /// instead. 1296 1296 /// 1297 /// \tparam _DigraphThe type of the digraph the algorithm runs on.1298 /// The default value is1299 /// \ref ListDigraph. The value of _Digraph is not used directly by1300 /// \ref BfsVisit,it is only passed to \ref BfsVisitDefaultTraits.1301 /// \tparam _VisitorThe Visitor type that is used by the algorithm.1302 /// \ref BfsVisitor "BfsVisitor< _Digraph>" is an empty visitor, which1297 /// \tparam GR The type of the digraph the algorithm runs on. 1298 /// The default type is \ref ListDigraph. 1299 /// The value of GR is not used directly by \ref BfsVisit, 1300 /// it is only passed to \ref BfsVisitDefaultTraits. 1301 /// \tparam VS The Visitor type that is used by the algorithm. 1302 /// \ref BfsVisitor "BfsVisitor<GR>" is an empty visitor, which 1303 1303 /// does not observe the BFS events. If you want to observe the BFS 1304 1304 /// events, you should implement your own visitor class. 1305 /// \tparam _TraitsTraits class to set various data types used by the1305 /// \tparam TR Traits class to set various data types used by the 1306 1306 /// algorithm. The default traits class is 1307 /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits< _Digraph>".1307 /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<GR>". 1308 1308 /// See \ref BfsVisitDefaultTraits for the documentation of 1309 1309 /// a BFS visit traits class. 1310 1310 #ifdef DOXYGEN 1311 template <typename _Digraph, typename _Visitor, typename _Traits>1311 template <typename GR, typename VS, typename TR> 1312 1312 #else 1313 template <typename _Digraph= ListDigraph,1314 typename _Visitor = BfsVisitor<_Digraph>,1315 typename _Traits = BfsVisitDefaultTraits<_Digraph> >1313 template <typename GR = ListDigraph, 1314 typename VS = BfsVisitor<GR>, 1315 typename TR = BfsVisitDefaultTraits<GR> > 1316 1316 #endif 1317 1317 class BfsVisit { … … 1319 1319 1320 1320 ///The traits class. 1321 typedef _TraitsTraits;1321 typedef TR Traits; 1322 1322 1323 1323 ///The type of the digraph the algorithm runs on. … … 1325 1325 1326 1326 ///The visitor type used by the algorithm. 1327 typedef _VisitorVisitor;1327 typedef VS Visitor; 1328 1328 1329 1329 ///The type of the map that indicates which nodes are reached. … … 1365 1365 typedef BfsVisit Create; 1366 1366 1367 /// \name Named template parameters1367 /// \name Named Template Parameters 1368 1368 1369 1369 ///@{ … … 1407 1407 /// 1408 1408 /// Sets the map that indicates which nodes are reached. 1409 /// If you don't use this function before calling \ref run(), 1410 /// it will allocate one. The destructor deallocates this 1411 /// automatically allocated map, of course. 1409 /// If you don't use this function before calling \ref run(Node) "run()" 1410 /// or \ref init(), an instance will be allocated automatically. 1411 /// The destructor deallocates this automatically allocated map, 1412 /// of course. 1412 1413 /// \return <tt> (*this) </tt> 1413 1414 BfsVisit &reachedMap(ReachedMap &m) { … … 1422 1423 public: 1423 1424 1424 /// \name Execution control 1425 /// The simplest way to execute the algorithm is to use 1426 /// one of the member functions called \ref lemon::BfsVisit::run() 1427 /// "run()". 1428 /// \n 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. 1425 /// \name Execution Control 1426 /// The simplest way to execute the BFS algorithm is to use one of the 1427 /// member functions called \ref run(Node) "run()".\n 1428 /// If you need more control on the execution, first you have to call 1429 /// \ref init(), then you can add several source nodes with 1430 /// \ref addSource(). Finally the actual path computation can be 1431 /// performed with one of the \ref start() functions. 1434 1432 1435 1433 /// @{ … … 1731 1729 1732 1730 /// \name Query Functions 1733 /// The result of the %BFS algorithm can be obtained using these1731 /// The results of the BFS algorithm can be obtained using these 1734 1732 /// functions.\n 1735 /// Either \ref lemon::BfsVisit::run() "run()" or1736 /// \ref lemon::BfsVisit::start() "start()" must be called before1737 /// using them. 1733 /// Either \ref run(Node) "run()" or \ref start() should be called 1734 /// before using them. 1735 1738 1736 ///@{ 1739 1737 1740 /// \brief Checks if a node is reachable from the root(s). 1741 /// 1742 /// Returns \c true if \c v is reachable from the root(s). 1743 /// \pre Either \ref run() or \ref start() 1738 /// \brief Checks if a node is reached from the root(s). 1739 /// 1740 /// Returns \c true if \c v is reached from the root(s). 1741 /// 1742 /// \pre Either \ref run(Node) "run()" or \ref init() 1744 1743 /// must be called before using this function. 1745 bool reached(Node v) { return (*_reached)[v]; }1744 bool reached(Node v) const { return (*_reached)[v]; } 1746 1745 1747 1746 ///@}
Note: See TracChangeset
for help on using the changeset viewer.