COIN-OR::LEMON - Graph Library

Changeset 596:293551ad254f in lemon-1.2 for lemon/hao_orlin.h


Ignore:
Timestamp:
04/15/09 09:37:51 (11 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Improvements and fixes for the minimum cut algorithms (#264)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/hao_orlin.h

    r581 r596  
    3232/// \brief Implementation of the Hao-Orlin algorithm.
    3333///
    34 /// Implementation of the Hao-Orlin algorithm class for testing network
    35 /// reliability.
     34/// Implementation of the Hao-Orlin algorithm for finding a minimum cut
     35/// in a digraph.
    3636
    3737namespace lemon {
     
    3939  /// \ingroup min_cut
    4040  ///
    41   /// \brief %Hao-Orlin algorithm to find a minimum cut in directed graphs.
     41  /// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph.
    4242  ///
    43   /// Hao-Orlin calculates a minimum cut in a directed graph
    44   /// \f$D=(V,A)\f$. It takes a fixed node \f$ source \in V \f$ and
     43  /// This class implements the Hao-Orlin algorithm for finding a minimum
     44  /// value cut in a directed graph \f$D=(V,A)\f$.
     45  /// It takes a fixed node \f$ source \in V \f$ and
    4546  /// consists of two phases: in the first phase it determines a
    4647  /// minimum cut with \f$ source \f$ on the source-side (i.e. a set
    47   /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal
    48   /// out-degree) and in the second phase it determines a minimum cut
     48  /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing
     49  /// capacity) and in the second phase it determines a minimum cut
    4950  /// with \f$ source \f$ on the sink-side (i.e. a set
    50   /// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal
    51   /// out-degree). Obviously, the smaller of these two cuts will be a
     51  /// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal outgoing
     52  /// capacity). Obviously, the smaller of these two cuts will be a
    5253  /// minimum cut of \f$ D \f$. The algorithm is a modified
    53   /// push-relabel preflow algorithm and our implementation calculates
     54  /// preflow push-relabel algorithm. Our implementation calculates
    5455  /// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the
    5556  /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The
    56   /// purpose of such algorithm is testing network reliability. For an
    57   /// undirected graph you can run just the first phase of the
    58   /// algorithm or you can use the algorithm of Nagamochi and Ibaraki
    59   /// which solves the undirected problem in
    60   /// \f$ O(nm + n^2 \log n) \f$ time: it is implemented in the
    61   /// NagamochiIbaraki algorithm class.
     57  /// purpose of such algorithm is e.g. testing network reliability.
    6258  ///
    63   /// \param GR The digraph class the algorithm runs on.
    64   /// \param CAP An arc map of capacities which can be any numreric type.
    65   /// The default type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
    66   /// \param TOL Tolerance class for handling inexact computations. The
     59  /// For an undirected graph you can run just the first phase of the
     60  /// algorithm or you can use the algorithm of Nagamochi and Ibaraki,
     61  /// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$
     62  /// time. It is implemented in the NagamochiIbaraki algorithm class.
     63  ///
     64  /// \tparam GR The type of the digraph the algorithm runs on.
     65  /// \tparam CAP The type of the arc map containing the capacities,
     66  /// which can be any numreric type. The default map type is
     67  /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
     68  /// \tparam TOL Tolerance class for handling inexact computations. The
    6769  /// default tolerance type is \ref Tolerance "Tolerance<CAP::Value>".
    6870#ifdef DOXYGEN
     
    7476#endif
    7577  class HaoOrlin {
     78  public:
     79   
     80    /// The digraph type of the algorithm
     81    typedef GR Digraph;
     82    /// The capacity map type of the algorithm
     83    typedef CAP CapacityMap;
     84    /// The tolerance type of the algorithm
     85    typedef TOL Tolerance;
     86
    7687  private:
    7788
    78     typedef GR Digraph;
    79     typedef CAP CapacityMap;
    80     typedef TOL Tolerance;
    81 
    8289    typedef typename CapacityMap::Value Value;
    8390
    84     TEMPLATE_GRAPH_TYPEDEFS(Digraph);
     91    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    8592
    8693    const Digraph& _graph;
     
    816823  public:
    817824
    818     /// \name Execution control
     825    /// \name Execution Control
    819826    /// The simplest way to execute the algorithm is to use
    820827    /// one of the member functions called \ref run().
    821828    /// \n
    822     /// If you need more control on the execution,
    823     /// first you must call \ref init(), then the \ref calculateIn() or
    824     /// \ref calculateOut() functions.
     829    /// If you need better control on the execution,
     830    /// you have to call one of the \ref init() functions first, then
     831    /// \ref calculateOut() and/or \ref calculateIn().
    825832
    826833    /// @{
    827834
    828     /// \brief Initializes the internal data structures.
    829     ///
    830     /// Initializes the internal data structures. It creates
    831     /// the maps, residual graph adaptors and some bucket structures
    832     /// for the algorithm.
     835    /// \brief Initialize the internal data structures.
     836    ///
     837    /// This function initializes the internal data structures. It creates
     838    /// the maps and some bucket structures for the algorithm.
     839    /// The first node is used as the source node for the push-relabel
     840    /// algorithm.
    833841    void init() {
    834842      init(NodeIt(_graph));
    835843    }
    836844
    837     /// \brief Initializes the internal data structures.
    838     ///
    839     /// Initializes the internal data structures. It creates
    840     /// the maps, residual graph adaptor and some bucket structures
    841     /// for the algorithm. Node \c source  is used as the push-relabel
    842     /// algorithm's source.
     845    /// \brief Initialize the internal data structures.
     846    ///
     847    /// This function initializes the internal data structures. It creates
     848    /// the maps and some bucket structures for the algorithm.
     849    /// The given node is used as the source node for the push-relabel
     850    /// algorithm.
    843851    void init(const Node& source) {
    844852      _source = source;
     
    880888
    881889
    882     /// \brief Calculates a minimum cut with \f$ source \f$ on the
     890    /// \brief Calculate a minimum cut with \f$ source \f$ on the
    883891    /// source-side.
    884892    ///
    885     /// Calculates a minimum cut with \f$ source \f$ on the
     893    /// This function calculates a minimum cut with \f$ source \f$ on the
    886894    /// source-side (i.e. a set \f$ X\subsetneq V \f$ with
    887     /// \f$ source \in X \f$ and minimal out-degree).
     895    /// \f$ source \in X \f$ and minimal outgoing capacity).
     896    ///
     897    /// \pre \ref init() must be called before using this function.
    888898    void calculateOut() {
    889899      findMinCutOut();
    890900    }
    891901
    892     /// \brief Calculates a minimum cut with \f$ source \f$ on the
    893     /// target-side.
    894     ///
    895     /// Calculates a minimum cut with \f$ source \f$ on the
    896     /// target-side (i.e. a set \f$ X\subsetneq V \f$ with
    897     /// \f$ source \in X \f$ and minimal out-degree).
     902    /// \brief Calculate a minimum cut with \f$ source \f$ on the
     903    /// sink-side.
     904    ///
     905    /// This function calculates a minimum cut with \f$ source \f$ on the
     906    /// sink-side (i.e. a set \f$ X\subsetneq V \f$ with
     907    /// \f$ source \notin X \f$ and minimal outgoing capacity).
     908    ///
     909    /// \pre \ref init() must be called before using this function.
    898910    void calculateIn() {
    899911      findMinCutIn();
     
    901913
    902914
    903     /// \brief Runs the algorithm.
    904     ///
    905     /// Runs the algorithm. It finds nodes \c source and \c target
    906     /// arbitrarily and then calls \ref init(), \ref calculateOut()
     915    /// \brief Run the algorithm.
     916    ///
     917    /// This function runs the algorithm. It finds nodes \c source and
     918    /// \c target arbitrarily and then calls \ref init(), \ref calculateOut()
    907919    /// and \ref calculateIn().
    908920    void run() {
     
    912924    }
    913925
    914     /// \brief Runs the algorithm.
    915     ///
    916     /// Runs the algorithm. It uses the given \c source node, finds a
    917     /// proper \c target and then calls the \ref init(), \ref
    918     /// calculateOut() and \ref calculateIn().
     926    /// \brief Run the algorithm.
     927    ///
     928    /// This function runs the algorithm. It uses the given \c source node,
     929    /// finds a proper \c target node and then calls the \ref init(),
     930    /// \ref calculateOut() and \ref calculateIn().
    919931    void run(const Node& s) {
    920932      init(s);
     
    927939    /// \name Query Functions
    928940    /// The result of the %HaoOrlin algorithm
    929     /// can be obtained using these functions.
    930     /// \n
    931     /// Before using these functions, either \ref run(), \ref
    932     /// calculateOut() or \ref calculateIn() must be called.
     941    /// can be obtained using these functions.\n
     942    /// \ref run(), \ref calculateOut() or \ref calculateIn()
     943    /// should be called before using them.
    933944
    934945    /// @{
    935946
    936     /// \brief Returns the value of the minimum value cut.
    937     ///
    938     /// Returns the value of the minimum value cut.
     947    /// \brief Return the value of the minimum cut.
     948    ///
     949    /// This function returns the value of the minimum cut.
     950    ///
     951    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
     952    /// must be called before using this function.
    939953    Value minCutValue() const {
    940954      return _min_cut;
     
    942956
    943957
    944     /// \brief Returns a minimum cut.
    945     ///
    946     /// Sets \c nodeMap to the characteristic vector of a minimum
    947     /// value cut: it will give a nonempty set \f$ X\subsetneq V \f$
    948     /// with minimal out-degree (i.e. \c nodeMap will be true exactly
    949     /// for the nodes of \f$ X \f$).  \pre nodeMap should be a
    950     /// bool-valued node-map.
    951     template <typename NodeMap>
    952     Value minCutMap(NodeMap& nodeMap) const {
     958    /// \brief Return a minimum cut.
     959    ///
     960    /// This function sets \c cutMap to the characteristic vector of a
     961    /// minimum value cut: it will give a non-empty set \f$ X\subsetneq V \f$
     962    /// with minimal outgoing capacity (i.e. \c cutMap will be \c true exactly
     963    /// for the nodes of \f$ X \f$).
     964    ///
     965    /// \param cutMap A \ref concepts::WriteMap "writable" node map with
     966    /// \c bool (or convertible) value type.
     967    ///
     968    /// \return The value of the minimum cut.
     969    ///
     970    /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
     971    /// must be called before using this function.
     972    template <typename CutMap>
     973    Value minCutMap(CutMap& cutMap) const {
    953974      for (NodeIt it(_graph); it != INVALID; ++it) {
    954         nodeMap.set(it, (*_min_cut_map)[it]);
     975        cutMap.set(it, (*_min_cut_map)[it]);
    955976      }
    956977      return _min_cut;
     
    961982  }; //class HaoOrlin
    962983
    963 
    964984} //namespace lemon
    965985
Note: See TracChangeset for help on using the changeset viewer.