COIN-OR::LEMON - Graph Library

Ticket #179: 179-2-interface-d66ff32624e2.patch

File 179-2-interface-d66ff32624e2.patch, 4.5 KB (added by Peter Kovacs, 15 years ago)
  • lemon/min_mean_cycle.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1249302938 -7200
    # Node ID d66ff32624e2cec102cedea55dca5e9f67ce1931
    # Parent  b31e130db13dc0fb04aa077d61de09785b55fe43
    Simplify the interface of MinMeanCycle (#179)
    Remove init() and reset(), and move their content into findMinMean().
    
    diff --git a/lemon/min_mean_cycle.h b/lemon/min_mean_cycle.h
    a b  
    122122    /// found cycle.
    123123    ///
    124124    /// If you don't call this function before calling \ref run() or
    125     /// \ref init(), it will allocate a local \ref Path "path"
     125    /// \ref findMinMean(), it will allocate a local \ref Path "path"
    126126    /// structure. The destuctor deallocates this automatically
    127127    /// allocated object, of course.
    128128    ///
     
    144144    /// \name Execution control
    145145    /// The simplest way to execute the algorithm is to call the \ref run()
    146146    /// function.\n
    147     /// If you only need the minimum mean length, you may call \ref init()
    148     /// and \ref findMinMean().
    149     /// If you would like to run the algorithm again (e.g. the underlying
    150     /// digraph and/or the arc lengths has been modified), you may not
    151     /// create a new instance of the class, rather call \ref reset(),
    152     /// \ref findMinMean() and \ref findCycle() instead.
     147    /// If you only need the minimum mean length, you may call
     148    /// \ref findMinMean().
    153149
    154150    /// @{
    155151
    156152    /// \brief Run the algorithm.
    157153    ///
    158154    /// This function runs the algorithm.
     155    /// It can be called more than once (e.g. if the underlying digraph
     156    /// and/or the arc lengths have been modified).
    159157    ///
    160158    /// \return \c true if a directed cycle exists in the digraph.
    161159    ///
    162     /// \note Apart from the return value, <tt>mmc.run()</tt> is just a
    163     /// shortcut of the following code.
     160    /// \note <tt>mmc.run()</tt> is just a shortcut of the following code.
    164161    /// \code
    165     ///   mmc.init();
    166     ///   mmc.findMinMean();
    167     ///   mmc.findCycle();
     162    ///   return mmc.findMinMean() && mmc.findCycle();
    168163    /// \endcode
    169164    bool run() {
    170       init();
    171165      return findMinMean() && findCycle();
    172166    }
    173167
    174     /// \brief Initialize the internal data structures.
     168    /// \brief Find the minimum cycle mean.
    175169    ///
    176     /// This function initializes the internal data structures.
     170    /// This function finds the minimum mean length of the directed
     171    /// cycles in the digraph.
    177172    ///
    178     /// \sa reset()
    179     void init() {
     173    /// \return \c true if a directed cycle exists in the digraph.
     174    bool findMinMean() {
     175      // Initialize
    180176      _tol.epsilon(1e-6);
    181177      if (!_cycle_path) {
    182178        _local_path = true;
    183179        _cycle_path = new Path;
    184180      }
     181      _cycle_path->clear();
    185182      _cycle_found = false;
     183
     184      // Find the minimum cycle mean in the components
    186185      _comp_num = stronglyConnectedComponents(_gr, _comp);
    187     }
    188 
    189     /// \brief Reset the internal data structures.
    190     ///
    191     /// This function resets the internal data structures so that
    192     /// findMinMean() and findCycle() can be called again (e.g. when the
    193     /// underlying digraph and/or the arc lengths has been modified).
    194     ///
    195     /// \sa init()
    196     void reset() {
    197       if (_cycle_path) _cycle_path->clear();
    198       _cycle_found = false;
    199       _comp_num = stronglyConnectedComponents(_gr, _comp);
    200     }
    201 
    202     /// \brief Find the minimum cycle mean.
    203     ///
    204     /// This function computes all the required data and finds the
    205     /// minimum mean length of the directed cycles in the digraph.
    206     ///
    207     /// \return \c true if a directed cycle exists in the digraph.
    208     ///
    209     /// \pre \ref init() must be called before using this function.
    210     bool findMinMean() {
    211       // Find the minimum cycle mean in the components
    212186      for (int comp = 0; comp < _comp_num; ++comp) {
    213187        if (!initCurrentComponent(comp)) continue;
    214188        while (true) {
     
    227201    ///
    228202    /// \return \c true if a directed cycle exists in the digraph.
    229203    ///
    230     /// \pre \ref init() and \ref findMinMean() must be called before
    231     /// using this function.
     204    /// \pre \ref findMinMean() must be called before using this function.
    232205    bool findCycle() {
    233206      if (!_cycle_found) return false;
    234207      _cycle_path->addBack(_policy[_cycle_node]);
     
    242215    /// @}
    243216
    244217    /// \name Query Functions
    245     /// The result of the algorithm can be obtained using these
     218    /// The results of the algorithm can be obtained using these
    246219    /// functions.\n
    247220    /// The algorithm should be executed before using them.
    248221