lemon/min_mean_cycle.h
changeset 2522 616c019215c4
parent 2509 a8081c9cd96a
child 2529 93de38566e6c
equal deleted inserted replaced
3:7c5686a40e4d 4:2cab37eb9ab5
   248     ///
   248     ///
   249     /// Runs the algorithm.
   249     /// Runs the algorithm.
   250     ///
   250     ///
   251     /// \return \c true if a cycle exists in the graph.
   251     /// \return \c true if a cycle exists in the graph.
   252     ///
   252     ///
   253     /// \note Apart from the return value, m.run() is just a shortcut
   253     /// \note Apart from the return value, <tt>m.run()</tt> is just a
   254     /// of the following code.
   254     /// shortcut of the following code.
   255     /// \code
   255     /// \code
   256     ///   m.init();
   256     ///   m.init();
   257     ///   m.findMinMean();
   257     ///   m.findMinMean();
   258     ///   m.findCycle();
   258     ///   m.findCycle();
   259     /// \endcode
   259     /// \endcode
   262       findMinMean();
   262       findMinMean();
   263       return findCycle();
   263       return findCycle();
   264     }
   264     }
   265 
   265 
   266     /// \brief Initializes the internal data structures.
   266     /// \brief Initializes the internal data structures.
       
   267     ///
       
   268     /// Initializes the internal data structures.
       
   269     ///
       
   270     /// \sa reset()
   267     void init() {
   271     void init() {
   268       comp_num = stronglyConnectedComponents(graph, comp);
   272       comp_num = stronglyConnectedComponents(graph, comp);
   269       if (!cycle_path) {
   273       if (!cycle_path) {
   270 	local_path = true;
   274 	local_path = true;
   271 	cycle_path = new Path;
   275 	cycle_path = new Path;
   339     /// \brief Resets the internal data structures.
   343     /// \brief Resets the internal data structures.
   340     ///
   344     ///
   341     /// Resets the internal data structures so that \ref findMinMean()
   345     /// Resets the internal data structures so that \ref findMinMean()
   342     /// and \ref findCycle() can be called again (e.g. when the
   346     /// and \ref findCycle() can be called again (e.g. when the
   343     /// underlaying graph has been modified).
   347     /// underlaying graph has been modified).
       
   348     ///
       
   349     /// \sa init()
   344     void reset() {
   350     void reset() {
   345       for (NodeIt u(graph); u != INVALID; ++u)
   351       for (NodeIt u(graph); u != INVALID; ++u)
   346 	dmap[u].clear();
   352 	dmap[u].clear();
   347       cycle_node = INVALID;
   353       cycle_node = INVALID;
   348       if (cycle_path) cycle_path->clear();
   354       if (cycle_path) cycle_path->clear();
   351 
   357 
   352     /// \brief Returns the total length of the found cycle.
   358     /// \brief Returns the total length of the found cycle.
   353     ///
   359     ///
   354     /// Returns the total length of the found cycle.
   360     /// Returns the total length of the found cycle.
   355     ///
   361     ///
   356     /// \pre \ref run() must be called before using this function.
   362     /// \pre \ref run() or \ref findCycle() must be called before
       
   363     /// using this function. If only \ref findMinMean() is called,
       
   364     /// the return value is not valid.
   357     Length cycleLength() const {
   365     Length cycleLength() const {
   358       return cycle_length;
   366       return cycle_length;
   359     }
   367     }
   360 
   368 
   361     /// \brief Returns the number of edges in the found cycle.
   369     /// \brief Returns the number of edges in the found cycle.
   362     ///
   370     ///
   363     /// Returns the number of edges in the found cycle.
   371     /// Returns the number of edges in the found cycle.
   364     ///
   372     ///
   365     /// \pre \ref run() must be called before using this function.
   373     /// \pre \ref run() or \ref findCycle() must be called before
       
   374     /// using this function. If only \ref findMinMean() is called,
       
   375     /// the return value is not valid.
   366     int cycleEdgeNum() const {
   376     int cycleEdgeNum() const {
   367       return cycle_size;
   377       return cycle_size;
   368     }
   378     }
   369 
   379 
   370     /// \brief Returns the mean length of the found cycle.
   380     /// \brief Returns the mean length of the found cycle.
   371     ///
   381     ///
   372     /// Returns the mean length of the found cycle.
   382     /// Returns the mean length of the found cycle.
   373     ///
   383     ///
   374     /// \pre \ref run() must be called before using this function.
   384     /// \pre \ref run() or \ref findMinMean() must be called before
       
   385     /// using this function.
   375     ///
   386     ///
   376     /// \warning LengthMap::Value must be convertible to double.
   387     /// \warning LengthMap::Value must be convertible to double.
   377     ///
   388     ///
   378     /// \note m.minMean() is just a shortcut of the following code.
   389     /// \note <tt>m.minMean()</tt> is just a shortcut of the following
       
   390     /// code.
   379     /// \code
   391     /// \code
   380     ///   return m.cycleEdgeNum() / double(m.cycleLength());
   392     ///   return m.cycleLength() / double(m.cycleEdgeNum());
   381     /// \endcode
   393     /// \endcode
       
   394     /// However if only \ref findMinMean() is called before using this
       
   395     /// function, <tt>m.cycleLength()</tt> and <tt>m.cycleEdgeNum()</tt>
       
   396     /// are not valid alone, only their ratio is valid.
   382     double minMean() const {
   397     double minMean() const {
   383       return cycle_length / (double)cycle_size;
   398       return cycle_length / (double)cycle_size;
   384     }
   399     }
   385 
   400 
   386     /// \brief Returns a const reference to the \ref lemon::Path "Path"
   401     /// \brief Returns a const reference to the \ref lemon::Path "Path"