lemon/hao_orlin.h
branch1.1
changeset 776 fe5718b39fda
parent 589 2ca0cdb5f366
equal deleted inserted replaced
7:56d45e2efc2c 8:45a301c562e2
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2009
     5  * Copyright (C) 2003-2011
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
    29 
    29 
    30 /// \file
    30 /// \file
    31 /// \ingroup min_cut
    31 /// \ingroup min_cut
    32 /// \brief Implementation of the Hao-Orlin algorithm.
    32 /// \brief Implementation of the Hao-Orlin algorithm.
    33 ///
    33 ///
    34 /// Implementation of the Hao-Orlin algorithm for finding a minimum cut 
    34 /// Implementation of the Hao-Orlin algorithm for finding a minimum cut
    35 /// in a digraph.
    35 /// in a digraph.
    36 
    36 
    37 namespace lemon {
    37 namespace lemon {
    38 
    38 
    39   /// \ingroup min_cut
    39   /// \ingroup min_cut
    40   ///
    40   ///
    41   /// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph.
    41   /// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph.
    42   ///
    42   ///
    43   /// This class implements the Hao-Orlin algorithm for finding a minimum
    43   /// This class implements the Hao-Orlin algorithm for finding a minimum
    44   /// value cut in a directed graph \f$D=(V,A)\f$. 
    44   /// value cut in a directed graph \f$D=(V,A)\f$.
    45   /// It takes a fixed node \f$ source \in V \f$ and
    45   /// It takes a fixed node \f$ source \in V \f$ and
    46   /// consists of two phases: in the first phase it determines a
    46   /// consists of two phases: in the first phase it determines a
    47   /// minimum cut with \f$ source \f$ on the source-side (i.e. a set
    47   /// minimum cut with \f$ source \f$ on the source-side (i.e. a set
    48   /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing
    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
    49   /// capacity) and in the second phase it determines a minimum cut
    56   /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The
    56   /// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The
    57   /// purpose of such algorithm is e.g. testing network reliability.
    57   /// purpose of such algorithm is e.g. testing network reliability.
    58   ///
    58   ///
    59   /// For an undirected graph you can run just the first phase of 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,
    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$ 
    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.
    62   /// time. It is implemented in the NagamochiIbaraki algorithm class.
    63   ///
    63   ///
    64   /// \tparam GR The type of the digraph the algorithm runs on.
    64   /// \tparam GR The type of the digraph the algorithm runs on.
    65   /// \tparam CAP The type of the arc map containing the capacities,
    65   /// \tparam CAP The type of the arc map containing the capacities,
    66   /// which can be any numreric type. The default map type is
    66   /// which can be any numreric type. The default map type is
    74             typename CAP = typename GR::template ArcMap<int>,
    74             typename CAP = typename GR::template ArcMap<int>,
    75             typename TOL = Tolerance<typename CAP::Value> >
    75             typename TOL = Tolerance<typename CAP::Value> >
    76 #endif
    76 #endif
    77   class HaoOrlin {
    77   class HaoOrlin {
    78   public:
    78   public:
    79    
    79 
    80     /// The digraph type of the algorithm
    80     /// The digraph type of the algorithm
    81     typedef GR Digraph;
    81     typedef GR Digraph;
    82     /// The capacity map type of the algorithm
    82     /// The capacity map type of the algorithm
    83     typedef CAP CapacityMap;
    83     typedef CAP CapacityMap;
    84     /// The tolerance type of the algorithm
    84     /// The tolerance type of the algorithm
   845     }
   845     }
   846 
   846 
   847     /// \brief Initialize the internal data structures.
   847     /// \brief Initialize the internal data structures.
   848     ///
   848     ///
   849     /// This function initializes the internal data structures. It creates
   849     /// This function initializes the internal data structures. It creates
   850     /// the maps and some bucket structures for the algorithm. 
   850     /// the maps and some bucket structures for the algorithm.
   851     /// The given node is used as the source node for the push-relabel
   851     /// The given node is used as the source node for the push-relabel
   852     /// algorithm.
   852     /// algorithm.
   853     void init(const Node& source) {
   853     void init(const Node& source) {
   854       _source = source;
   854       _source = source;
   855 
   855 
   925       calculateIn();
   925       calculateIn();
   926     }
   926     }
   927 
   927 
   928     /// \brief Run the algorithm.
   928     /// \brief Run the algorithm.
   929     ///
   929     ///
   930     /// This function runs the algorithm. It uses the given \c source node, 
   930     /// This function runs the algorithm. It uses the given \c source node,
   931     /// finds a proper \c target node and then calls the \ref init(),
   931     /// finds a proper \c target node and then calls the \ref init(),
   932     /// \ref calculateOut() and \ref calculateIn().
   932     /// \ref calculateOut() and \ref calculateIn().
   933     void run(const Node& s) {
   933     void run(const Node& s) {
   934       init(s);
   934       init(s);
   935       calculateOut();
   935       calculateOut();
   939     /// @}
   939     /// @}
   940 
   940 
   941     /// \name Query Functions
   941     /// \name Query Functions
   942     /// The result of the %HaoOrlin algorithm
   942     /// The result of the %HaoOrlin algorithm
   943     /// can be obtained using these functions.\n
   943     /// can be obtained using these functions.\n
   944     /// \ref run(), \ref calculateOut() or \ref calculateIn() 
   944     /// \ref run(), \ref calculateOut() or \ref calculateIn()
   945     /// should be called before using them.
   945     /// should be called before using them.
   946 
   946 
   947     /// @{
   947     /// @{
   948 
   948 
   949     /// \brief Return the value of the minimum cut.
   949     /// \brief Return the value of the minimum cut.
   950     ///
   950     ///
   951     /// This function returns the value of the minimum cut.
   951     /// This function returns the value of the minimum cut.
   952     ///
   952     ///
   953     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 
   953     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
   954     /// must be called before using this function.
   954     /// must be called before using this function.
   955     Value minCutValue() const {
   955     Value minCutValue() const {
   956       return _min_cut;
   956       return _min_cut;
   957     }
   957     }
   958 
   958 
   967     /// \param cutMap A \ref concepts::WriteMap "writable" node map with
   967     /// \param cutMap A \ref concepts::WriteMap "writable" node map with
   968     /// \c bool (or convertible) value type.
   968     /// \c bool (or convertible) value type.
   969     ///
   969     ///
   970     /// \return The value of the minimum cut.
   970     /// \return The value of the minimum cut.
   971     ///
   971     ///
   972     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn() 
   972     /// \pre \ref run(), \ref calculateOut() or \ref calculateIn()
   973     /// must be called before using this function.
   973     /// must be called before using this function.
   974     template <typename CutMap>
   974     template <typename CutMap>
   975     Value minCutMap(CutMap& cutMap) const {
   975     Value minCutMap(CutMap& cutMap) const {
   976       for (NodeIt it(_graph); it != INVALID; ++it) {
   976       for (NodeIt it(_graph); it != INVALID; ++it) {
   977         cutMap.set(it, (*_min_cut_map)[it]);
   977         cutMap.set(it, (*_min_cut_map)[it]);