Changeset 596:293551ad254f in lemon1.2 for lemon
 Timestamp:
 04/15/09 09:37:51 (11 years ago)
 Branch:
 default
 Phase:
 public
 Location:
 lemon
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

lemon/gomory_hu.h
r581 r596 43 43 /// between these nodes. Moreover the components obtained by removing 44 44 /// this edge from the tree determine the corresponding minimum cut. 45 ///46 45 /// Therefore once this tree is computed, the minimum cut between any pair 47 46 /// of nodes can easily be obtained. 48 47 /// 49 48 /// The algorithm calculates \e n1 distinct minimum cuts (currently with 50 /// the \ref Preflow algorithm), therefore the algorithm has 51 /// \f$(O(n^3\sqrt{e})\f$ overall time complexity. It calculates a 52 /// rooted GomoryHu tree, its structure and the weights can be obtained 53 /// by \c predNode(), \c predValue() and \c rootDist(). 54 /// 55 /// The members \c minCutMap() and \c minCutValue() calculate 49 /// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall 50 /// time complexity. It calculates a rooted GomoryHu tree. 51 /// The structure of the tree and the edge weights can be 52 /// obtained using \c predNode(), \c predValue() and \c rootDist(). 53 /// The functions \c minCutMap() and \c minCutValue() calculate 56 54 /// the minimum cut and the minimum cut value between any two nodes 57 55 /// in the graph. You can also list (iterate on) the nodes and the … … 59 57 /// 60 58 /// \tparam GR The type of the undirected graph the algorithm runs on. 61 /// \tparam CAP The type of the edge map describing the edge capacities.62 /// It is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>" by default.59 /// \tparam CAP The type of the edge map containing the capacities. 60 /// The default map type is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>". 63 61 #ifdef DOXYGEN 64 62 template <typename GR, … … 71 69 public: 72 70 73 /// The graph type 71 /// The graph type of the algorithm 74 72 typedef GR Graph; 75 /// The type of the edge capacity map73 /// The capacity map type of the algorithm 76 74 typedef CAP Capacity; 77 75 /// The value type of capacities … … 118 116 /// \brief Constructor 119 117 /// 120 /// Constructor 118 /// Constructor. 121 119 /// \param graph The undirected graph the algorithm runs on. 122 120 /// \param capacity The edge capacity map. … … 131 129 /// \brief Destructor 132 130 /// 133 /// Destructor 131 /// Destructor. 134 132 ~GomoryHu() { 135 133 destroyStructures(); … … 216 214 ///The results of the algorithm can be obtained using these 217 215 ///functions.\n 218 ///\ref run() "run()"should be called before using them.\n216 ///\ref run() should be called before using them.\n 219 217 ///See also \ref MinCutNodeIt and \ref MinCutEdgeIt. 220 218 … … 223 221 /// \brief Return the predecessor node in the GomoryHu tree. 224 222 /// 225 /// This function returns the predecessor node in the GomoryHu tree. 226 /// If the node is 227 /// the root of the GomoryHu tree, then it returns \c INVALID. 228 Node predNode(const Node& node) { 223 /// This function returns the predecessor node of the given node 224 /// in the GomoryHu tree. 225 /// If \c node is the root of the tree, then it returns \c INVALID. 226 /// 227 /// \pre \ref run() must be called before using this function. 228 Node predNode(const Node& node) const { 229 229 return (*_pred)[node]; 230 }231 232 /// \brief Return the distance from the root node in the GomoryHu tree.233 ///234 /// This function returns the distance of \c node from the root node235 /// in the GomoryHu tree.236 int rootDist(const Node& node) {237 return (*_order)[node];238 230 } 239 231 … … 241 233 /// GomoryHu tree. 242 234 /// 243 /// This function returns the weight of the predecessor edge in the 244 /// GomoryHu tree. If the node is the root, the result is undefined. 245 Value predValue(const Node& node) { 235 /// This function returns the weight of the predecessor edge of the 236 /// given node in the GomoryHu tree. 237 /// If \c node is the root of the tree, the result is undefined. 238 /// 239 /// \pre \ref run() must be called before using this function. 240 Value predValue(const Node& node) const { 246 241 return (*_weight)[node]; 247 242 } 248 243 244 /// \brief Return the distance from the root node in the GomoryHu tree. 245 /// 246 /// This function returns the distance of the given node from the root 247 /// node in the GomoryHu tree. 248 /// 249 /// \pre \ref run() must be called before using this function. 250 int rootDist(const Node& node) const { 251 return (*_order)[node]; 252 } 253 249 254 /// \brief Return the minimum cut value between two nodes 250 255 /// 251 /// This function returns the minimum cut value between two nodes. The 252 /// algorithm finds the nearest common ancestor in the GomoryHu 253 /// tree and calculates the minimum weight edge on the paths to 254 /// the ancestor. 256 /// This function returns the minimum cut value between the nodes 257 /// \c s and \c t. 258 /// It finds the nearest common ancestor of the given nodes in the 259 /// GomoryHu tree and calculates the minimum weight edge on the 260 /// paths to the ancestor. 261 /// 262 /// \pre \ref run() must be called before using this function. 255 263 Value minCutValue(const Node& s, const Node& t) const { 256 264 Node sn = s, tn = t; … … 275 283 /// \c s to \c true and the other nodes to \c false. 276 284 /// 277 /// For higher level interfaces, see MinCutNodeIt and MinCutEdgeIt. 285 /// For higher level interfaces see MinCutNodeIt and MinCutEdgeIt. 286 /// 287 /// \param s The base node. 288 /// \param t The node you want to separate from node \c s. 289 /// \param cutMap The cut will be returned in this map. 290 /// It must be a \c bool (or convertible) \ref concepts::ReadWriteMap 291 /// "ReadWriteMap" on the graph nodes. 292 /// 293 /// \return The value of the minimum cut between \c s and \c t. 294 /// 295 /// \pre \ref run() must be called before using this function. 278 296 template <typename CutMap> 279 Value minCutMap(const Node& s, ///< The base node.297 Value minCutMap(const Node& s, ///< 280 298 const Node& t, 281 ///< The node you want to separate from node \c s.299 ///< 282 300 CutMap& cutMap 283 ///< The cut will be returned in this map. 284 /// It must be a \c bool (or convertible) 285 /// \ref concepts::ReadWriteMap "ReadWriteMap" 286 /// on the graph nodes. 301 ///< 287 302 ) const { 288 303 Node sn = s, tn = t; … … 339 354 340 355 /// This iterator class lists the nodes of a minimum cut found by 341 /// GomoryHu. Before using it, you must allocate a GomoryHu class ,356 /// GomoryHu. Before using it, you must allocate a GomoryHu class 342 357 /// and call its \ref GomoryHu::run() "run()" method. 343 358 /// … … 436 451 437 452 /// This iterator class lists the edges of a minimum cut found by 438 /// GomoryHu. Before using it, you must allocate a GomoryHu class ,453 /// GomoryHu. Before using it, you must allocate a GomoryHu class 439 454 /// and call its \ref GomoryHu::run() "run()" method. 440 455 /// … … 448 463 /// value+=capacities[e]; 449 464 /// \endcode 450 /// the result will be the same as it isreturned by451 /// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)" 465 /// The result will be the same as the value returned by 466 /// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)". 452 467 class MinCutEdgeIt 453 468 { … … 469 484 470 485 public: 486 /// Constructor 487 488 /// Constructor. 489 /// 471 490 MinCutEdgeIt(GomoryHu const &gomory, 472 491 ///< The GomoryHu class. You must call its … … 479 498 ///< If it is \c true (default) then the listed arcs 480 499 /// will be oriented from the 481 /// thenodes of the component containing \c s,500 /// nodes of the component containing \c s, 482 501 /// otherwise they will be oriented in the opposite 483 502 /// direction. 
lemon/hao_orlin.h
r581 r596 32 32 /// \brief Implementation of the HaoOrlin algorithm. 33 33 /// 34 /// Implementation of the HaoOrlin algorithm class for testing network35 /// reliability.34 /// Implementation of the HaoOrlin algorithm for finding a minimum cut 35 /// in a digraph. 36 36 37 37 namespace lemon { … … 39 39 /// \ingroup min_cut 40 40 /// 41 /// \brief %HaoOrlin algorithm to find a minimum cut in directed graphs.41 /// \brief HaoOrlin algorithm for finding a minimum cut in a digraph. 42 42 /// 43 /// HaoOrlin 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 HaoOrlin 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 45 46 /// consists of two phases: in the first phase it determines a 46 47 /// minimum cut with \f$ source \f$ on the sourceside (i.e. a set 47 /// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal 48 /// outdegree) and in the second phase it determines a minimum cut48 /// \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 50 /// with \f$ source \f$ on the sinkside (i.e. a set 50 /// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal 51 /// outdegree). Obviously, the smaller of these two cuts will be a51 /// \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 52 53 /// minimum cut of \f$ D \f$. The algorithm is a modified 53 /// p ushrelabel preflow algorithm and our implementation calculates54 /// preflow pushrelabel algorithm. Our implementation calculates 54 55 /// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the 55 56 /// highestlabel 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. 62 58 /// 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 67 69 /// default tolerance type is \ref Tolerance "Tolerance<CAP::Value>". 68 70 #ifdef DOXYGEN … … 74 76 #endif 75 77 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 76 87 private: 77 88 78 typedef GR Digraph;79 typedef CAP CapacityMap;80 typedef TOL Tolerance;81 82 89 typedef typename CapacityMap::Value Value; 83 90 84 TEMPLATE_ GRAPH_TYPEDEFS(Digraph);91 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 85 92 86 93 const Digraph& _graph; … … 816 823 public: 817 824 818 /// \name Execution control825 /// \name Execution Control 819 826 /// The simplest way to execute the algorithm is to use 820 827 /// one of the member functions called \ref run(). 821 828 /// \n 822 /// If you need morecontrol on the execution,823 /// first you must call \ref init(), then the \ref calculateIn() or824 /// \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(). 825 832 826 833 /// @{ 827 834 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 pushrelabel 840 /// algorithm. 833 841 void init() { 834 842 init(NodeIt(_graph)); 835 843 } 836 844 837 /// \brief Initialize sthe internal data structures.838 /// 839 /// Initializes the internal data structures. It creates840 /// the maps , residual graph adaptor and some bucket structures841 /// for the algorithm. Node \c source is used asthe pushrelabel842 /// 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 pushrelabel 850 /// algorithm. 843 851 void init(const Node& source) { 844 852 _source = source; … … 880 888 881 889 882 /// \brief Calculate sa minimum cut with \f$ source \f$ on the890 /// \brief Calculate a minimum cut with \f$ source \f$ on the 883 891 /// sourceside. 884 892 /// 885 /// Calculates a minimum cut with \f$ source \f$ on the893 /// This function calculates a minimum cut with \f$ source \f$ on the 886 894 /// sourceside (i.e. a set \f$ X\subsetneq V \f$ with 887 /// \f$ source \in X \f$ and minimal outdegree). 895 /// \f$ source \in X \f$ and minimal outgoing capacity). 896 /// 897 /// \pre \ref init() must be called before using this function. 888 898 void calculateOut() { 889 899 findMinCutOut(); 890 900 } 891 901 892 /// \brief Calculates a minimum cut with \f$ source \f$ on the 893 /// targetside. 894 /// 895 /// Calculates a minimum cut with \f$ source \f$ on the 896 /// targetside (i.e. a set \f$ X\subsetneq V \f$ with 897 /// \f$ source \in X \f$ and minimal outdegree). 902 /// \brief Calculate a minimum cut with \f$ source \f$ on the 903 /// sinkside. 904 /// 905 /// This function calculates a minimum cut with \f$ source \f$ on the 906 /// sinkside (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. 898 910 void calculateIn() { 899 911 findMinCutIn(); … … 901 913 902 914 903 /// \brief Run sthe algorithm.904 /// 905 /// Runs the algorithm. It finds nodes \c source and \c target906 /// 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() 907 919 /// and \ref calculateIn(). 908 920 void run() { … … 912 924 } 913 925 914 /// \brief Run sthe algorithm.915 /// 916 /// Runs the algorithm. It uses the given \c source node, finds a917 /// proper \c target and then calls the \ref init(), \ref918 /// 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(). 919 931 void run(const Node& s) { 920 932 init(s); … … 927 939 /// \name Query Functions 928 940 /// 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. 933 944 934 945 /// @{ 935 946 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. 939 953 Value minCutValue() const { 940 954 return _min_cut; … … 942 956 943 957 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 outdegree (i.e. \c nodeMap will be true exactly 949 /// for the nodes of \f$ X \f$). \pre nodeMap should be a 950 /// boolvalued nodemap. 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 nonempty 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 { 953 974 for (NodeIt it(_graph); it != INVALID; ++it) { 954 nodeMap.set(it, (*_min_cut_map)[it]);975 cutMap.set(it, (*_min_cut_map)[it]); 955 976 } 956 977 return _min_cut; … … 961 982 }; //class HaoOrlin 962 983 963 964 984 } //namespace lemon 965 985
Note: See TracChangeset
for help on using the changeset viewer.