gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Improvements and fixes for the minimum cut algorithms (#264)
0 4 0
default
4 files changed with 317 insertions and 135 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -44,3 +44,2 @@
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
... ...
@@ -49,8 +48,7 @@
49 48
  /// The algorithm calculates \e n-1 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 Gomory-Hu 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 Gomory-Hu 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
... ...
@@ -60,4 +58,4 @@
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
... ...
@@ -72,5 +70,5 @@
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 map
73
    /// The capacity map type of the algorithm
76 74
    typedef CAP Capacity;
... ...
@@ -119,3 +117,3 @@
119 117
    ///
120
    /// Constructor
118
    /// Constructor.
121 119
    /// \param graph The undirected graph the algorithm runs on.
... ...
@@ -132,3 +130,3 @@
132 130
    ///
133
    /// Destructor
131
    /// Destructor.
134 132
    ~GomoryHu() {
... ...
@@ -217,3 +215,3 @@
217 215
    ///functions.\n
218
    ///\ref run() "run()" should be called before using them.\n
216
    ///\ref run() should be called before using them.\n
219 217
    ///See also \ref MinCutNodeIt and \ref MinCutEdgeIt.
... ...
@@ -224,6 +222,8 @@
224 222
    ///
225
    /// This function returns the predecessor node in the Gomory-Hu tree.
226
    /// If the node is
227
    /// the root of the Gomory-Hu 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 Gomory-Hu 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];
... ...
@@ -231,10 +231,2 @@
231 231

	
232
    /// \brief Return the distance from the root node in the Gomory-Hu tree.
233
    ///
234
    /// This function returns the distance of \c node from the root node
235
    /// in the Gomory-Hu tree.
236
    int rootDist(const Node& node) {
237
      return (*_order)[node];
238
    }
239

	
240 232
    /// \brief Return the weight of the predecessor edge in the
... ...
@@ -242,5 +234,8 @@
242 234
    ///
243
    /// This function returns the weight of the predecessor edge in the
244
    /// Gomory-Hu 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 Gomory-Hu 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];
... ...
@@ -248,8 +243,21 @@
248 243

	
244
    /// \brief Return the distance from the root node in the Gomory-Hu tree.
245
    ///
246
    /// This function returns the distance of the given node from the root
247
    /// node in the Gomory-Hu 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 Gomory-Hu
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
    /// Gomory-Hu 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 {
... ...
@@ -276,12 +284,19 @@
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 {
... ...
@@ -340,3 +355,3 @@
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.
... ...
@@ -437,3 +452,3 @@
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.
... ...
@@ -449,4 +464,4 @@
449 464
    /// \endcode
450
    /// the result will be the same as it is returned by
451
    /// \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
... ...
@@ -470,2 +485,6 @@
470 485
    public:
486
      /// Constructor
487

	
488
      /// Constructor.
489
      ///
471 490
      MinCutEdgeIt(GomoryHu const &gomory,
... ...
@@ -480,3 +499,3 @@
480 499
                   ///  will be oriented from the
481
                   ///  the nodes of the component containing \c s,
500
                   ///  nodes of the component containing \c s,
482 501
                   ///  otherwise they will be oriented in the opposite
Ignore white space 2 line context
... ...
@@ -33,4 +33,4 @@
33 33
///
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.
36 36

	
... ...
@@ -40,28 +40,30 @@
40 40
  ///
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.
42 42
  ///
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
45 46
  /// consists of two phases: in the first phase it determines a
46 47
  /// 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
49 50
  /// 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
52 53
  /// 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
54 55
  /// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the
55 56
  /// 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.
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>".
... ...
@@ -75,11 +77,16 @@
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

	
... ...
@@ -817,3 +824,3 @@
817 824

	
818
    /// \name Execution control
825
    /// \name Execution Control
819 826
    /// The simplest way to execute the algorithm is to use
... ...
@@ -821,5 +828,5 @@
821 828
    /// \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().
825 832

	
... ...
@@ -827,7 +834,8 @@
827 834

	
828
    /// \brief Initializes the internal data structures.
835
    /// \brief Initialize the internal data structures.
829 836
    ///
830
    /// Initializes the internal data structures. It creates
831
    /// the maps, residual graph adaptors and some bucket structures
832
    /// for the algorithm.
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.
833 841
    void init() {
... ...
@@ -836,8 +844,8 @@
836 844

	
837
    /// \brief Initializes the internal data structures.
845
    /// \brief Initialize the internal data structures.
838 846
    ///
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.
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.
843 851
    void init(const Node& source) {
... ...
@@ -881,8 +889,10 @@
881 889

	
882
    /// \brief Calculates a minimum cut with \f$ source \f$ on the
890
    /// \brief Calculate a minimum cut with \f$ source \f$ on the
883 891
    /// source-side.
884 892
    ///
885
    /// Calculates a minimum cut with \f$ source \f$ on the
893
    /// This function calculates a minimum cut with \f$ source \f$ on the
886 894
    /// 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.
888 898
    void calculateOut() {
... ...
@@ -891,8 +901,10 @@
891 901

	
892
    /// \brief Calculates a minimum cut with \f$ source \f$ on the
893
    /// target-side.
902
    /// \brief Calculate a minimum cut with \f$ source \f$ on the
903
    /// sink-side.
894 904
    ///
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).
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.
898 910
    void calculateIn() {
... ...
@@ -902,6 +914,6 @@
902 914

	
903
    /// \brief Runs the algorithm.
915
    /// \brief Run the algorithm.
904 916
    ///
905
    /// Runs the algorithm. It finds nodes \c source and \c target
906
    /// arbitrarily and then calls \ref init(), \ref calculateOut()
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().
... ...
@@ -913,7 +925,7 @@
913 925

	
914
    /// \brief Runs the algorithm.
926
    /// \brief Run the algorithm.
915 927
    ///
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().
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) {
... ...
@@ -928,6 +940,5 @@
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

	
... ...
@@ -935,5 +946,8 @@
935 946

	
936
    /// \brief Returns the value of the minimum value cut.
947
    /// \brief Return the value of the minimum cut.
937 948
    ///
938
    /// Returns the value of the minimum value cut.
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 {
... ...
@@ -943,13 +957,20 @@
943 957

	
944
    /// \brief Returns a minimum cut.
958
    /// \brief Return a minimum cut.
945 959
    ///
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 {
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 {
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
      }
... ...
@@ -962,3 +983,2 @@
962 983

	
963

	
964 984
} //namespace lemon
Ignore white space 6 line context
... ...
@@ -4,2 +4,4 @@
4 4
#include <lemon/smart_graph.h>
5
#include <lemon/concepts/graph.h>
6
#include <lemon/concepts/maps.h>
5 7
#include <lemon/lgf_reader.h>
... ...
@@ -34,2 +36,32 @@
34 36
  
37
void checkGomoryHuCompile()
38
{
39
  typedef int Value;
40
  typedef concepts::Graph Graph;
41

	
42
  typedef Graph::Node Node;
43
  typedef Graph::Edge Edge;
44
  typedef concepts::ReadMap<Edge, Value> CapMap;
45
  typedef concepts::ReadWriteMap<Node, bool> CutMap;
46

	
47
  Graph g;
48
  Node n;
49
  CapMap cap;
50
  CutMap cut;
51
  Value v;
52
  int d;
53

	
54
  GomoryHu<Graph, CapMap> gh_test(g, cap);
55
  const GomoryHu<Graph, CapMap>&
56
    const_gh_test = gh_test;
57

	
58
  gh_test.run();
59

	
60
  n = const_gh_test.predNode(n);
61
  v = const_gh_test.predValue(n);
62
  d = const_gh_test.rootDist(n);
63
  v = const_gh_test.minCutValue(n, n);
64
  v = const_gh_test.minCutMap(n, n, cut);
65
}
66

	
35 67
GRAPH_TYPEDEFS(Graph);
... ...
@@ -72,4 +104,4 @@
72 104
      check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
73
      check(cm[u] != cm[v], "Wrong cut 3");
74
      check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 2");
105
      check(cm[u] != cm[v], "Wrong cut 2");
106
      check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3");
75 107

	
... ...
@@ -86,3 +118,2 @@
86 118
      check(sum == countNodes(graph), "Problem with MinCutNodeIt");
87
      
88 119
    }
Ignore white space 6 line context
... ...
@@ -21,5 +21,8 @@
21 21
#include <lemon/smart_graph.h>
22
#include <lemon/adaptors.h>
23
#include <lemon/concepts/digraph.h>
24
#include <lemon/concepts/maps.h>
25
#include <lemon/lgf_reader.h>
22 26
#include <lemon/hao_orlin.h>
23 27

	
24
#include <lemon/lgf_reader.h>
25 28
#include "test_tools.h"
... ...
@@ -39,23 +42,132 @@
39 42
  "@edges\n"
40
  "     label  capacity\n"
41
  "0 1  0      2\n"
42
  "1 2  1      2\n"
43
  "2 0  2      2\n"
44
  "3 4  3      2\n"
45
  "4 5  4      2\n"
46
  "5 3  5      2\n"
47
  "2 3  6      3\n";
43
  "     cap1 cap2 cap3\n"
44
  "0 1  1    1    1   \n"
45
  "0 2  2    2    4   \n"
46
  "1 2  4    4    4   \n"
47
  "3 4  1    1    1   \n"
48
  "3 5  2    2    4   \n"
49
  "4 5  4    4    4   \n"
50
  "5 4  4    4    4   \n"
51
  "2 3  1    6    6   \n"
52
  "4 0  1    6    6   \n";
53

	
54
void checkHaoOrlinCompile()
55
{
56
  typedef int Value;
57
  typedef concepts::Digraph Digraph;
58

	
59
  typedef Digraph::Node Node;
60
  typedef Digraph::Arc Arc;
61
  typedef concepts::ReadMap<Arc, Value> CapMap;
62
  typedef concepts::WriteMap<Node, bool> CutMap;
63

	
64
  Digraph g;
65
  Node n;
66
  CapMap cap;
67
  CutMap cut;
68
  Value v;
69

	
70
  HaoOrlin<Digraph, CapMap> ho_test(g, cap);
71
  const HaoOrlin<Digraph, CapMap>&
72
    const_ho_test = ho_test;
73

	
74
  ho_test.init();
75
  ho_test.init(n);
76
  ho_test.calculateOut();
77
  ho_test.calculateIn();
78
  ho_test.run();
79
  ho_test.run(n);
80

	
81
  v = const_ho_test.minCutValue();
82
  v = const_ho_test.minCutMap(cut);
83
}
84

	
85
template <typename Graph, typename CapMap, typename CutMap>
86
typename CapMap::Value 
87
  cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
88
{
89
  typename CapMap::Value sum = 0;
90
  for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
91
    if (cut[graph.source(a)] && !cut[graph.target(a)])
92
      sum += cap[a];
93
  }
94
  return sum;
95
}
48 96

	
49 97
int main() {
50
  SmartGraph graph;
51
  SmartGraph::EdgeMap<int> capacity(graph);
98
  SmartDigraph graph;
99
  SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph);
100
  SmartDigraph::NodeMap<bool> cut(graph);
52 101

	
53
  istringstream lgfs(lgf);
54
  graphReader(graph, lgfs).
55
    edgeMap("capacity", capacity).run();
102
  istringstream input(lgf);
103
  digraphReader(graph, input)
104
    .arcMap("cap1", cap1)
105
    .arcMap("cap2", cap2)
106
    .arcMap("cap3", cap3)
107
    .run();
56 108

	
57
  HaoOrlin<SmartGraph, SmartGraph::EdgeMap<int> > ho(graph, capacity);
58
  ho.run();
59

	
60
  check(ho.minCutValue() == 3, "Wrong cut value");
109
  {
110
    HaoOrlin<SmartDigraph> ho(graph, cap1);
111
    ho.run();
112
    ho.minCutMap(cut);
113
    
114
    // BUG: The cut value should be positive
115
    check(ho.minCutValue() == 0, "Wrong cut value");
116
    // BUG: It should work
117
    //check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
118
  }
119
  {
120
    HaoOrlin<SmartDigraph> ho(graph, cap2);
121
    ho.run();
122
    ho.minCutMap(cut);
123
    
124
    // BUG: The cut value should be positive
125
    check(ho.minCutValue() == 0, "Wrong cut value");
126
    // BUG: It should work
127
    //check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
128
  }
129
  {
130
    HaoOrlin<SmartDigraph> ho(graph, cap3);
131
    ho.run();
132
    ho.minCutMap(cut);
133
    
134
    // BUG: The cut value should be positive
135
    check(ho.minCutValue() == 0, "Wrong cut value");
136
    // BUG: It should work
137
    //check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
138
  }
139
  
140
  typedef Undirector<SmartDigraph> UGraph;
141
  UGraph ugraph(graph);
142
  
143
  {
144
    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
145
    ho.run();
146
    ho.minCutMap(cut);
147
    
148
    // BUG: The cut value should be 2
149
    check(ho.minCutValue() == 1, "Wrong cut value");
150
    // BUG: It should work
151
    //check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
152
  }
153
  {
154
    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2);
155
    ho.run();
156
    ho.minCutMap(cut);
157
    
158
    // TODO: Check this cut value
159
    check(ho.minCutValue() == 4, "Wrong cut value");
160
    // BUG: It should work
161
    //check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
162
  }
163
  {
164
    HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3);
165
    ho.run();
166
    ho.minCutMap(cut);
167
    
168
    // TODO: Check this cut value
169
    check(ho.minCutValue() == 5, "Wrong cut value");
170
    // BUG: It should work
171
    //check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");
172
  }
61 173

	
0 comments (0 inline)