Simplify the interface of MinMeanCycle (#179)
authorPeter Kovacs <kpeter@inf.elte.hu>
Mon, 03 Aug 2009 14:35:38 +0200
changeset 806d66ff32624e2
parent 805 b31e130db13d
child 807 83ce7ce39f21
Simplify the interface of MinMeanCycle (#179)
Remove init() and reset(), and move their content into findMinMean().
lemon/min_mean_cycle.h
     1.1 --- a/lemon/min_mean_cycle.h	Mon Aug 03 14:12:55 2009 +0200
     1.2 +++ b/lemon/min_mean_cycle.h	Mon Aug 03 14:35:38 2009 +0200
     1.3 @@ -122,7 +122,7 @@
     1.4      /// found cycle.
     1.5      ///
     1.6      /// If you don't call this function before calling \ref run() or
     1.7 -    /// \ref init(), it will allocate a local \ref Path "path"
     1.8 +    /// \ref findMinMean(), it will allocate a local \ref Path "path"
     1.9      /// structure. The destuctor deallocates this automatically
    1.10      /// allocated object, of course.
    1.11      ///
    1.12 @@ -144,71 +144,45 @@
    1.13      /// \name Execution control
    1.14      /// The simplest way to execute the algorithm is to call the \ref run()
    1.15      /// function.\n
    1.16 -    /// If you only need the minimum mean length, you may call \ref init()
    1.17 -    /// and \ref findMinMean().
    1.18 -    /// If you would like to run the algorithm again (e.g. the underlying
    1.19 -    /// digraph and/or the arc lengths has been modified), you may not
    1.20 -    /// create a new instance of the class, rather call \ref reset(),
    1.21 -    /// \ref findMinMean() and \ref findCycle() instead.
    1.22 +    /// If you only need the minimum mean length, you may call
    1.23 +    /// \ref findMinMean().
    1.24  
    1.25      /// @{
    1.26  
    1.27      /// \brief Run the algorithm.
    1.28      ///
    1.29      /// This function runs the algorithm.
    1.30 +    /// It can be called more than once (e.g. if the underlying digraph
    1.31 +    /// and/or the arc lengths have been modified).
    1.32      ///
    1.33      /// \return \c true if a directed cycle exists in the digraph.
    1.34      ///
    1.35 -    /// \note Apart from the return value, <tt>mmc.run()</tt> is just a
    1.36 -    /// shortcut of the following code.
    1.37 +    /// \note <tt>mmc.run()</tt> is just a shortcut of the following code.
    1.38      /// \code
    1.39 -    ///   mmc.init();
    1.40 -    ///   mmc.findMinMean();
    1.41 -    ///   mmc.findCycle();
    1.42 +    ///   return mmc.findMinMean() && mmc.findCycle();
    1.43      /// \endcode
    1.44      bool run() {
    1.45 -      init();
    1.46        return findMinMean() && findCycle();
    1.47      }
    1.48  
    1.49 -    /// \brief Initialize the internal data structures.
    1.50 +    /// \brief Find the minimum cycle mean.
    1.51      ///
    1.52 -    /// This function initializes the internal data structures.
    1.53 +    /// This function finds the minimum mean length of the directed
    1.54 +    /// cycles in the digraph.
    1.55      ///
    1.56 -    /// \sa reset()
    1.57 -    void init() {
    1.58 +    /// \return \c true if a directed cycle exists in the digraph.
    1.59 +    bool findMinMean() {
    1.60 +      // Initialize
    1.61        _tol.epsilon(1e-6);
    1.62        if (!_cycle_path) {
    1.63          _local_path = true;
    1.64          _cycle_path = new Path;
    1.65        }
    1.66 +      _cycle_path->clear();
    1.67        _cycle_found = false;
    1.68 +
    1.69 +      // Find the minimum cycle mean in the components
    1.70        _comp_num = stronglyConnectedComponents(_gr, _comp);
    1.71 -    }
    1.72 -
    1.73 -    /// \brief Reset the internal data structures.
    1.74 -    ///
    1.75 -    /// This function resets the internal data structures so that
    1.76 -    /// findMinMean() and findCycle() can be called again (e.g. when the
    1.77 -    /// underlying digraph and/or the arc lengths has been modified).
    1.78 -    ///
    1.79 -    /// \sa init()
    1.80 -    void reset() {
    1.81 -      if (_cycle_path) _cycle_path->clear();
    1.82 -      _cycle_found = false;
    1.83 -      _comp_num = stronglyConnectedComponents(_gr, _comp);
    1.84 -    }
    1.85 -
    1.86 -    /// \brief Find the minimum cycle mean.
    1.87 -    ///
    1.88 -    /// This function computes all the required data and finds the
    1.89 -    /// minimum mean length of the directed cycles in the digraph.
    1.90 -    ///
    1.91 -    /// \return \c true if a directed cycle exists in the digraph.
    1.92 -    ///
    1.93 -    /// \pre \ref init() must be called before using this function.
    1.94 -    bool findMinMean() {
    1.95 -      // Find the minimum cycle mean in the components
    1.96        for (int comp = 0; comp < _comp_num; ++comp) {
    1.97          if (!initCurrentComponent(comp)) continue;
    1.98          while (true) {
    1.99 @@ -227,8 +201,7 @@
   1.100      ///
   1.101      /// \return \c true if a directed cycle exists in the digraph.
   1.102      ///
   1.103 -    /// \pre \ref init() and \ref findMinMean() must be called before
   1.104 -    /// using this function.
   1.105 +    /// \pre \ref findMinMean() must be called before using this function.
   1.106      bool findCycle() {
   1.107        if (!_cycle_found) return false;
   1.108        _cycle_path->addBack(_policy[_cycle_node]);
   1.109 @@ -242,7 +215,7 @@
   1.110      /// @}
   1.111  
   1.112      /// \name Query Functions
   1.113 -    /// The result of the algorithm can be obtained using these
   1.114 +    /// The results of the algorithm can be obtained using these
   1.115      /// functions.\n
   1.116      /// The algorithm should be executed before using them.
   1.117