Changeset 1009:c85f53572941 in lemon
- Timestamp:
- 09/22/10 09:26:01 (13 years ago)
- Branch:
- 1.1
- Parents:
- 1004:d0e5734fc48e (diff), 1007:e24922c56bc2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/dfs.h
r631 r1009 558 558 void start(Node t) 559 559 { 560 while ( !emptyQueue() && G->target(_stack[_stack_head])!=t)560 while ( !emptyQueue() && !(*_reached)[t] ) 561 561 processNextArc(); 562 562 } … … 1510 1510 /// with addSource() before using this function. 1511 1511 void start(Node t) { 1512 while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != t)1512 while ( !emptyQueue() && !(*_reached)[t] ) 1513 1513 processNextArc(); 1514 1514 } -
lemon/dfs.h
r1007 r1009 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 Dfs, it is only passed to \ref DfsDefaultTraits. 124 ///\tparam TR Traits class to set various data types used by the algorithm. 125 ///The default traits class is 126 ///\ref DfsDefaultTraits "DfsDefaultTraits<GR>". 127 ///See \ref DfsDefaultTraits for the documentation of 128 ///a Dfs 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 DfsDefaultTraits "traits class" of the algorithm. 155 149 typedef TR Traits; 156 150 … … 213 207 typedef Dfs Create; 214 208 215 ///\name Named template parameters209 ///\name Named Template Parameters 216 210 217 211 ///@{ … … 227 221 }; 228 222 ///\brief \ref named-templ-param "Named parameter" for setting 229 /// PredMap type.223 ///\c PredMap type. 230 224 /// 231 225 ///\ref named-templ-param "Named parameter" for setting 232 ///PredMap type. 226 ///\c PredMap type. 227 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 233 228 template <class T> 234 229 struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > { … … 246 241 }; 247 242 ///\brief \ref named-templ-param "Named parameter" for setting 248 /// DistMap type.243 ///\c DistMap type. 249 244 /// 250 245 ///\ref named-templ-param "Named parameter" for setting 251 ///DistMap type. 246 ///\c DistMap type. 247 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 252 248 template <class T> 253 249 struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > { … … 265 261 }; 266 262 ///\brief \ref named-templ-param "Named parameter" for setting 267 /// ReachedMap type.263 ///\c ReachedMap type. 268 264 /// 269 265 ///\ref named-templ-param "Named parameter" for setting 270 ///ReachedMap type. 266 ///\c ReachedMap type. 267 ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. 271 268 template <class T> 272 269 struct SetReachedMap : public Dfs< Digraph, SetReachedMapTraits<T> > { … … 284 281 }; 285 282 ///\brief \ref named-templ-param "Named parameter" for setting 286 /// ProcessedMap type.283 ///\c ProcessedMap type. 287 284 /// 288 285 ///\ref named-templ-param "Named parameter" for setting 289 ///ProcessedMap type. 286 ///\c ProcessedMap type. 287 ///It must meet the \ref concepts::WriteMap "WriteMap" concept. 290 288 template <class T> 291 289 struct SetProcessedMap : public Dfs< Digraph, SetProcessedMapTraits<T> > { … … 301 299 }; 302 300 ///\brief \ref named-templ-param "Named parameter" for setting 303 /// ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.301 ///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. 304 302 /// 305 303 ///\ref named-templ-param "Named parameter" for setting 306 /// ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>.304 ///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. 307 305 ///If you don't set it explicitly, it will be automatically allocated. 308 306 struct SetStandardProcessedMap : … … 339 337 340 338 ///Sets the map that stores the predecessor arcs. 341 ///If you don't use this function before calling \ref run(), 342 ///it will allocate one. The destructor deallocates this 343 ///automatically allocated map, of course. 339 ///If you don't use this function before calling \ref run(Node) "run()" 340 ///or \ref init(), an instance will be allocated automatically. 341 ///The destructor deallocates this automatically allocated map, 342 ///of course. 344 343 ///\return <tt> (*this) </tt> 345 344 Dfs &predMap(PredMap &m) … … 356 355 357 356 ///Sets the map that indicates which nodes are reached. 358 ///If you don't use this function before calling \ref run(), 359 ///it will allocate one. The destructor deallocates this 360 ///automatically allocated map, of course. 357 ///If you don't use this function before calling \ref run(Node) "run()" 358 ///or \ref init(), an instance will be allocated automatically. 359 ///The destructor deallocates this automatically allocated map, 360 ///of course. 361 361 ///\return <tt> (*this) </tt> 362 362 Dfs &reachedMap(ReachedMap &m) … … 373 373 374 374 ///Sets the map that indicates which nodes are processed. 375 ///If you don't use this function before calling \ref run(), 376 ///it will allocate one. The destructor deallocates this 377 ///automatically allocated map, of course. 375 ///If you don't use this function before calling \ref run(Node) "run()" 376 ///or \ref init(), an instance will be allocated automatically. 377 ///The destructor deallocates this automatically allocated map, 378 ///of course. 378 379 ///\return <tt> (*this) </tt> 379 380 Dfs &processedMap(ProcessedMap &m) … … 391 392 ///Sets the map that stores the distances of the nodes calculated by 392 393 ///the algorithm. 393 ///If you don't use this function before calling \ref run(), 394 ///it will allocate one. The destructor deallocates this 395 ///automatically allocated map, of course. 394 ///If you don't use this function before calling \ref run(Node) "run()" 395 ///or \ref init(), an instance will be allocated automatically. 396 ///The destructor deallocates this automatically allocated map, 397 ///of course. 396 398 ///\return <tt> (*this) </tt> 397 399 Dfs &distMap(DistMap &m) … … 407 409 public: 408 410 409 ///\name Execution control 410 ///The simplest way to execute the algorithm is to use 411 ///one of the member functions called \ref lemon::Dfs::run() "run()". 412 ///\n 413 ///If you need more control on the execution, first you must call 414 ///\ref lemon::Dfs::init() "init()", then you can add a source node 415 ///with \ref lemon::Dfs::addSource() "addSource()". 416 ///Finally \ref lemon::Dfs::start() "start()" will perform the 417 ///actual path computation. 411 ///\name Execution Control 412 ///The simplest way to execute the DFS algorithm is to use one of the 413 ///member functions called \ref run(Node) "run()".\n 414 ///If you need more control on the execution, first you have to call 415 ///\ref init(), then you can add a source node with \ref addSource() 416 ///and perform the actual computation with \ref start(). 417 ///This procedure can be repeated if there are nodes that have not 418 ///been reached. 418 419 419 420 ///@{ 420 421 422 ///\brief Initializes the internal data structures. 423 /// 421 424 ///Initializes the internal data structures. 422 423 ///Initializes the internal data structures.424 ///425 425 void init() 426 426 { … … 439 439 ///Adds a new source node to the set of nodes to be processed. 440 440 /// 441 ///\pre The stack must be empty. (Otherwise the algorithm gives 442 ///false results.) 443 /// 444 ///\warning Distances will be wrong (or at least strange) in case of 445 ///multiple sources. 441 ///\pre The stack must be empty. Otherwise the algorithm gives 442 ///wrong results. (One of the outgoing arcs of all the source nodes 443 ///except for the last one will not be visited and distances will 444 ///also be wrong.) 446 445 void addSource(Node s) 447 446 { … … 507 506 } 508 507 509 ///\brief Returns \c false if there are nodes 510 ///to be processed. 511 /// 512 ///Returns \c false if there are nodes 513 ///to be processed in the queue (stack). 508 ///Returns \c false if there are nodes to be processed. 509 510 ///Returns \c false if there are nodes to be processed 511 ///in the queue (stack). 514 512 bool emptyQueue() const { return _stack_head<0; } 515 513 516 514 ///Returns the number of the nodes to be processed. 517 515 518 ///Returns the number of the nodes to be processed in the queue (stack). 516 ///Returns the number of the nodes to be processed 517 ///in the queue (stack). 519 518 int queueSize() const { return _stack_head+1; } 520 519 … … 638 637 /// 639 638 ///The algorithm computes 640 ///- the %DFS tree ,641 ///- the distance of each node from the root in the %DFS tree.639 ///- the %DFS tree (forest), 640 ///- the distance of each node from the root(s) in the %DFS tree. 642 641 /// 643 642 ///\note <tt>d.run()</tt> is just a shortcut of the following code. … … 664 663 665 664 ///\name Query Functions 666 ///The result of the %DFS algorithm can be obtained using these665 ///The results of the DFS algorithm can be obtained using these 667 666 ///functions.\n 668 ///Either \ref lemon::Dfs::run() "run()" or \ref lemon::Dfs::start()669 /// "start()" must be calledbefore using them.667 ///Either \ref run(Node) "run()" or \ref start() should be called 668 ///before using them. 670 669 671 670 ///@{ … … 675 674 ///Returns the DFS path to a node. 676 675 /// 677 ///\warning \c t should be reach able from the root.678 /// 679 ///\pre Either \ref run( ) or \ref start() must be called before680 /// using this function.676 ///\warning \c t should be reached from the root(s). 677 /// 678 ///\pre Either \ref run(Node) "run()" or \ref init() 679 ///must be called before using this function. 681 680 Path path(Node t) const { return Path(*G, *_pred, t); } 682 681 683 ///The distance of a node from the root .684 685 ///Returns the distance of a node from the root .686 /// 687 ///\warning If node \c v is not reach able from the root, then682 ///The distance of a node from the root(s). 683 684 ///Returns the distance of a node from the root(s). 685 /// 686 ///\warning If node \c v is not reached from the root(s), then 688 687 ///the return value of this function is undefined. 689 688 /// 690 ///\pre Either \ref run( ) or \ref start() must be called before691 /// using this function.689 ///\pre Either \ref run(Node) "run()" or \ref init() 690 ///must be called before using this function. 692 691 int dist(Node v) const { return (*_dist)[v]; } 693 692 … … 695 694 696 695 ///This function returns the 'previous arc' of the %DFS tree for the 697 ///node \c v, i.e. it returns the last arc of a %DFS path from the698 ///root to \c v. It is \c INVALID 699 /// if \c v is not reachable from theroot(s) or if \c v is a root.696 ///node \c v, i.e. it returns the last arc of a %DFS path from a 697 ///root to \c v. It is \c INVALID if \c v is not reached from the 698 ///root(s) or if \c v is a root. 700 699 /// 701 700 ///The %DFS tree used here is equal to the %DFS tree used in 702 701 ///\ref predNode(). 703 702 /// 704 ///\pre Either \ref run( ) or \ref start() must be called before using705 /// this function.703 ///\pre Either \ref run(Node) "run()" or \ref init() 704 ///must be called before using this function. 706 705 Arc predArc(Node v) const { return (*_pred)[v];} 707 706 … … 710 709 ///This function returns the 'previous node' of the %DFS 711 710 ///tree for the node \c v, i.e. it returns the last but one node 712 ///from a %DFS path from theroot to \c v. It is \c INVALID713 ///if \c v is not reach ablefrom the root(s) or if \c v is a root.711 ///from a %DFS path from a root to \c v. It is \c INVALID 712 ///if \c v is not reached from the root(s) or if \c v is a root. 714 713 /// 715 714 ///The %DFS tree used here is equal to the %DFS tree used in 716 715 ///\ref predArc(). 717 716 /// 718 ///\pre Either \ref run( ) or \ref start() must be called before719 /// using this function.717 ///\pre Either \ref run(Node) "run()" or \ref init() 718 ///must be called before using this function. 720 719 Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: 721 720 G->source((*_pred)[v]); } … … 727 726 ///distances of the nodes calculated by the algorithm. 728 727 /// 729 ///\pre Either \ref run( )or \ref init()728 ///\pre Either \ref run(Node) "run()" or \ref init() 730 729 ///must be called before using this function. 731 730 const DistMap &distMap() const { return *_dist;} … … 737 736 ///arcs, which form the DFS tree. 738 737 /// 739 ///\pre Either \ref run( )or \ref init()738 ///\pre Either \ref run(Node) "run()" or \ref init() 740 739 ///must be called before using this function. 741 740 const PredMap &predMap() const { return *_pred;} 742 741 743 ///Checks if a node is reachable from the root(s). 744 745 ///Returns \c true if \c v is reachable from the root(s). 746 ///\pre Either \ref run() or \ref start() 742 ///Checks if a node is reached from the root(s). 743 744 ///Returns \c true if \c v is reached from the root(s). 745 /// 746 ///\pre Either \ref run(Node) "run()" or \ref init() 747 747 ///must be called before using this function. 748 748 bool reached(Node v) const { return (*_reached)[v]; } … … 890 890 /// This auxiliary class is created to implement the 891 891 /// \ref dfs() "function-type interface" of \ref Dfs algorithm. 892 /// It does not have own \ref run( ) method, it uses the functions893 /// and features of the plain \ref Dfs.892 /// It does not have own \ref run(Node) "run()" method, it uses the 893 /// functions and features of the plain \ref Dfs. 894 894 /// 895 895 /// This class should only be used through the \ref dfs() function, … … 1111 1111 /// bool reached = dfs(g).path(p).dist(d).run(s,t); 1112 1112 ///\endcode 1113 1114 ///\warning Don't forget to put the \ref DfsWizard::run() "run()" 1113 ///\warning Don't forget to put the \ref DfsWizard::run(Node) "run()" 1115 1114 ///to the end of the parameter list. 1116 1115 ///\sa DfsWizard … … 1128 1127 /// This class defines the interface of the DfsVisit events, and 1129 1128 /// it could be the base of a real visitor class. 1130 template <typename _Digraph>1129 template <typename GR> 1131 1130 struct DfsVisitor { 1132 typedef _DigraphDigraph;1131 typedef GR Digraph; 1133 1132 typedef typename Digraph::Arc Arc; 1134 1133 typedef typename Digraph::Node Node; … … 1166 1165 }; 1167 1166 #else 1168 template <typename _Digraph>1167 template <typename GR> 1169 1168 struct DfsVisitor { 1170 typedef _DigraphDigraph;1169 typedef GR Digraph; 1171 1170 typedef typename Digraph::Arc Arc; 1172 1171 typedef typename Digraph::Node Node; … … 1201 1200 /// Default traits class of DfsVisit class. 1202 1201 /// \tparam _Digraph The type of the digraph the algorithm runs on. 1203 template<class _Digraph>1202 template<class GR> 1204 1203 struct DfsVisitDefaultTraits { 1205 1204 1206 1205 /// \brief The type of the digraph the algorithm runs on. 1207 typedef _DigraphDigraph;1206 typedef GR Digraph; 1208 1207 1209 1208 /// \brief The type of the map that indicates which nodes are reached. … … 1226 1225 /// \ingroup search 1227 1226 /// 1228 /// \brief %DFS algorithm class with visitor interface.1227 /// \brief DFS algorithm class with visitor interface. 1229 1228 /// 1230 /// This class provides an efficient implementation of the %DFS algorithm1229 /// This class provides an efficient implementation of the DFS algorithm 1231 1230 /// with visitor interface. 1232 1231 /// 1233 /// The %DfsVisit class provides an alternative interface to the Dfs1232 /// The DfsVisit class provides an alternative interface to the Dfs 1234 1233 /// class. It works with callback mechanism, the DfsVisit object calls 1235 1234 /// the member functions of the \c Visitor class on every DFS event. … … 1240 1239 /// instead. 1241 1240 /// 1242 /// \tparam _DigraphThe type of the digraph the algorithm runs on.1243 /// The default value is1244 /// \ref ListDigraph. The value of _Digraph is not used directly by1245 /// \ref DfsVisit,it is only passed to \ref DfsVisitDefaultTraits.1246 /// \tparam _VisitorThe Visitor type that is used by the algorithm.1247 /// \ref DfsVisitor "DfsVisitor< _Digraph>" is an empty visitor, which1241 /// \tparam GR The type of the digraph the algorithm runs on. 1242 /// The default type is \ref ListDigraph. 1243 /// The value of GR is not used directly by \ref DfsVisit, 1244 /// it is only passed to \ref DfsVisitDefaultTraits. 1245 /// \tparam VS The Visitor type that is used by the algorithm. 1246 /// \ref DfsVisitor "DfsVisitor<GR>" is an empty visitor, which 1248 1247 /// does not observe the DFS events. If you want to observe the DFS 1249 1248 /// events, you should implement your own visitor class. 1250 /// \tparam _TraitsTraits class to set various data types used by the1249 /// \tparam TR Traits class to set various data types used by the 1251 1250 /// algorithm. The default traits class is 1252 /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits< _Digraph>".1251 /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<GR>". 1253 1252 /// See \ref DfsVisitDefaultTraits for the documentation of 1254 1253 /// a DFS visit traits class. 1255 1254 #ifdef DOXYGEN 1256 template <typename _Digraph, typename _Visitor, typename _Traits>1255 template <typename GR, typename VS, typename TR> 1257 1256 #else 1258 template <typename _Digraph= ListDigraph,1259 typename _Visitor = DfsVisitor<_Digraph>,1260 typename _Traits = DfsVisitDefaultTraits<_Digraph> >1257 template <typename GR = ListDigraph, 1258 typename VS = DfsVisitor<GR>, 1259 typename TR = DfsVisitDefaultTraits<GR> > 1261 1260 #endif 1262 1261 class DfsVisit { … … 1264 1263 1265 1264 ///The traits class. 1266 typedef _TraitsTraits;1265 typedef TR Traits; 1267 1266 1268 1267 ///The type of the digraph the algorithm runs on. … … 1270 1269 1271 1270 ///The visitor type used by the algorithm. 1272 typedef _VisitorVisitor;1271 typedef VS Visitor; 1273 1272 1274 1273 ///The type of the map that indicates which nodes are reached. … … 1310 1309 typedef DfsVisit Create; 1311 1310 1312 /// \name Named template parameters1311 /// \name Named Template Parameters 1313 1312 1314 1313 ///@{ … … 1352 1351 /// 1353 1352 /// Sets the map that indicates which nodes are reached. 1354 /// If you don't use this function before calling \ref run(), 1355 /// it will allocate one. The destructor deallocates this 1356 /// automatically allocated map, of course. 1353 /// If you don't use this function before calling \ref run(Node) "run()" 1354 /// or \ref init(), an instance will be allocated automatically. 1355 /// The destructor deallocates this automatically allocated map, 1356 /// of course. 1357 1357 /// \return <tt> (*this) </tt> 1358 1358 DfsVisit &reachedMap(ReachedMap &m) { … … 1367 1367 public: 1368 1368 1369 /// \name Execution control 1370 /// The simplest way to execute the algorithm is to use 1371 /// one of the member functions called \ref lemon::DfsVisit::run() 1372 /// "run()". 1373 /// \n 1374 /// If you need more control on the execution, first you must call 1375 /// \ref lemon::DfsVisit::init() "init()", then you can add several 1376 /// source nodes with \ref lemon::DfsVisit::addSource() "addSource()". 1377 /// Finally \ref lemon::DfsVisit::start() "start()" will perform the 1378 /// actual path computation. 1369 /// \name Execution Control 1370 /// The simplest way to execute the DFS algorithm is to use one of the 1371 /// member functions called \ref run(Node) "run()".\n 1372 /// If you need more control on the execution, first you have to call 1373 /// \ref init(), then you can add a source node with \ref addSource() 1374 /// and perform the actual computation with \ref start(). 1375 /// This procedure can be repeated if there are nodes that have not 1376 /// been reached. 1379 1377 1380 1378 /// @{ … … 1392 1390 } 1393 1391 1394 ///Adds a new source node. 1395 1396 ///Adds a new source node to the set of nodes to be processed. 1397 /// 1398 ///\pre The stack must be empty. (Otherwise the algorithm gives 1399 ///false results.) 1400 /// 1401 ///\warning Distances will be wrong (or at least strange) in case of 1402 ///multiple sources. 1392 /// \brief Adds a new source node. 1393 /// 1394 /// Adds a new source node to the set of nodes to be processed. 1395 /// 1396 /// \pre The stack must be empty. Otherwise the algorithm gives 1397 /// wrong results. (One of the outgoing arcs of all the source nodes 1398 /// except for the last one will not be visited and distances will 1399 /// also be wrong.) 1403 1400 void addSource(Node s) 1404 1401 { … … 1414 1411 } else { 1415 1412 _visitor->leave(s); 1413 _visitor->stop(s); 1416 1414 } 1417 1415 } … … 1590 1588 /// 1591 1589 /// The algorithm computes 1592 /// - the %DFS tree ,1593 /// - the distance of each node from the root in the %DFS tree.1590 /// - the %DFS tree (forest), 1591 /// - the distance of each node from the root(s) in the %DFS tree. 1594 1592 /// 1595 1593 /// \note <tt>d.run()</tt> is just a shortcut of the following code. … … 1616 1614 1617 1615 /// \name Query Functions 1618 /// The result of the %DFS algorithm can be obtained using these1616 /// The results of the DFS algorithm can be obtained using these 1619 1617 /// functions.\n 1620 /// Either \ref lemon::DfsVisit::run() "run()" or1621 /// \ref lemon::DfsVisit::start() "start()" must be called before1622 /// using them. 1618 /// Either \ref run(Node) "run()" or \ref start() should be called 1619 /// before using them. 1620 1623 1621 ///@{ 1624 1622 1625 /// \brief Checks if a node is reachable from the root(s). 1626 /// 1627 /// Returns \c true if \c v is reachable from the root(s). 1628 /// \pre Either \ref run() or \ref start() 1623 /// \brief Checks if a node is reached from the root(s). 1624 /// 1625 /// Returns \c true if \c v is reached from the root(s). 1626 /// 1627 /// \pre Either \ref run(Node) "run()" or \ref init() 1629 1628 /// must be called before using this function. 1630 bool reached(Node v) { return (*_reached)[v]; }1629 bool reached(Node v) const { return (*_reached)[v]; } 1631 1630 1632 1631 ///@} -
test/dfs_test.cc
r632 r1009 51 51 "@attributes\n" 52 52 "source 0\n" 53 "target 5\n"; 53 "target 5\n" 54 "source1 6\n" 55 "target1 3\n"; 56 54 57 55 58 void checkDfsCompile() … … 180 183 Digraph G; 181 184 Node s, t; 185 Node s1, t1; 182 186 183 187 std::istringstream input(test_lgf); … … 185 189 node("source", s). 186 190 node("target", t). 191 node("source1", s1). 192 node("target1", t1). 187 193 run(); 188 194 … … 211 217 212 218 { 219 Dfs<Digraph> dfs(G); 220 check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6."); 221 } 222 223 { 213 224 NullMap<Node,Arc> myPredMap; 214 225 dfs(G).predMap(myPredMap).run(s); -
test/dfs_test.cc
r1007 r1009 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). … … 66 66 Node s, t; 67 67 Arc e; 68 int l ;68 int l, i; 69 69 bool b; 70 70 DType::DistMap d(G); 71 71 DType::PredMap p(G); 72 72 Path<Digraph> pp; 73 concepts::ReadMap<Arc,bool> am; 73 74 74 75 { 75 76 DType dfs_test(G); 77 const DType& const_dfs_test = dfs_test; 76 78 77 79 dfs_test.run(s); … … 79 81 dfs_test.run(); 80 82 81 l = dfs_test.dist(t); 82 e = dfs_test.predArc(t); 83 s = dfs_test.predNode(t); 84 b = dfs_test.reached(t); 85 d = dfs_test.distMap(); 86 p = dfs_test.predMap(); 87 pp = dfs_test.path(t); 83 dfs_test.init(); 84 dfs_test.addSource(s); 85 e = dfs_test.processNextArc(); 86 e = const_dfs_test.nextArc(); 87 b = const_dfs_test.emptyQueue(); 88 i = const_dfs_test.queueSize(); 89 90 dfs_test.start(); 91 dfs_test.start(t); 92 dfs_test.start(am); 93 94 l = const_dfs_test.dist(t); 95 e = const_dfs_test.predArc(t); 96 s = const_dfs_test.predNode(t); 97 b = const_dfs_test.reached(t); 98 d = const_dfs_test.distMap(); 99 p = const_dfs_test.predMap(); 100 pp = const_dfs_test.path(t); 88 101 } 89 102 { … … 92 105 ::SetDistMap<concepts::ReadWriteMap<Node,int> > 93 106 ::SetReachedMap<concepts::ReadWriteMap<Node,bool> > 107 ::SetStandardProcessedMap 94 108 ::SetProcessedMap<concepts::WriteMap<Node,bool> > 95 ::SetStandardProcessedMap96 109 ::Create dfs_test(G); 110 111 concepts::ReadWriteMap<Node,Arc> pred_map; 112 concepts::ReadWriteMap<Node,int> dist_map; 113 concepts::ReadWriteMap<Node,bool> reached_map; 114 concepts::WriteMap<Node,bool> processed_map; 115 116 dfs_test 117 .predMap(pred_map) 118 .distMap(dist_map) 119 .reachedMap(reached_map) 120 .processedMap(processed_map); 97 121 98 122 dfs_test.run(s); 99 123 dfs_test.run(s,t); 100 124 dfs_test.run(); 125 dfs_test.init(); 126 127 dfs_test.addSource(s); 128 e = dfs_test.processNextArc(); 129 e = dfs_test.nextArc(); 130 b = dfs_test.emptyQueue(); 131 i = dfs_test.queueSize(); 132 133 dfs_test.start(); 134 dfs_test.start(t); 135 dfs_test.start(am); 101 136 102 137 l = dfs_test.dist(t);
Note: See TracChangeset
for help on using the changeset viewer.