gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Remane GomoryHuTree to GomoryHu (#66)
1 2 1
default
4 files changed with 22 insertions and 22 deletions:
↑ Collapse diff ↑
Show white space 24 line context
... ...
@@ -59,25 +59,25 @@
59 59
	lemon/core.h \
60 60
	lemon/cplex.h \
61 61
	lemon/dfs.h \
62 62
	lemon/dijkstra.h \
63 63
	lemon/dim2.h \
64 64
	lemon/dimacs.h \
65 65
	lemon/edge_set.h \
66 66
	lemon/elevator.h \
67 67
	lemon/error.h \
68 68
	lemon/euler.h \
69 69
	lemon/full_graph.h \
70 70
	lemon/glpk.h \
71
	lemon/gomory_hu_tree.h \
71
	lemon/gomory_hu.h \
72 72
	lemon/graph_to_eps.h \
73 73
	lemon/grid_graph.h \
74 74
	lemon/hypercube_graph.h \
75 75
	lemon/kruskal.h \
76 76
	lemon/hao_orlin.h \
77 77
	lemon/lgf_reader.h \
78 78
	lemon/lgf_writer.h \
79 79
	lemon/list_graph.h \
80 80
	lemon/lp.h \
81 81
	lemon/lp_base.h \
82 82
	lemon/lp_skeleton.h \
83 83
	lemon/list_graph.h \
Show white space 24 line context
... ...
@@ -54,25 +54,25 @@
54 54
  /// 
55 55
  /// The members \c minCutMap() and \c minCutValue() calculate
56 56
  /// the minimum cut and the minimum cut value between any two node
57 57
  /// in the digraph. You can also list (iterate on) the nodes and the
58 58
  /// edges of the cuts using MinCutNodeIt and MinCutEdgeIt.
59 59
  ///
60 60
  /// \tparam GR The undirected graph data structure the algorithm will run on
61 61
  /// \tparam CAP type of the EdgeMap describing the Edge capacities.
62 62
  /// it is typename GR::template EdgeMap<int> by default.
63 63
  template <typename GR,
64 64
	    typename CAP = typename GR::template EdgeMap<int>
65 65
            >
66
  class GomoryHuTree {
66
  class GomoryHu {
67 67
  public:
68 68

	
69 69
    /// The graph type
70 70
    typedef GR Graph;
71 71
    /// The type if the edge capacity map
72 72
    typedef CAP Capacity;
73 73
    /// The value type of capacities
74 74
    typedef typename Capacity::Value Value;
75 75
    
76 76
  private:
77 77

	
78 78
    TEMPLATE_GRAPH_TYPEDEFS(Graph);
... ...
@@ -107,36 +107,36 @@
107 107
      if (_order) {
108 108
	delete _order;
109 109
      }
110 110
    }
111 111
  
112 112
  public:
113 113

	
114 114
    /// \brief Constructor
115 115
    ///
116 116
    /// Constructor
117 117
    /// \param graph The graph the algorithm will run on.
118 118
    /// \param capacity The capacity map.
119
    GomoryHuTree(const Graph& graph, const Capacity& capacity) 
119
    GomoryHu(const Graph& graph, const Capacity& capacity) 
120 120
      : _graph(graph), _capacity(capacity),
121 121
	_pred(0), _weight(0), _order(0) 
122 122
    {
123 123
      checkConcept<concepts::ReadMap<Edge, Value>, Capacity>();
124 124
    }
125 125

	
126 126

	
127 127
    /// \brief Destructor
128 128
    ///
129 129
    /// Destructor
130
    ~GomoryHuTree() {
130
    ~GomoryHu() {
131 131
      destroyStructures();
132 132
    }
133 133

	
134 134
    // \brief Initialize the internal data structures.
135 135
    //
136 136
    // This function initializes the internal data structures.
137 137
    //
138 138
    void init() {
139 139
      createStructures();
140 140

	
141 141
      _root = NodeIt(_graph);
142 142
      for (NodeIt n(_graph); n != INVALID; ++n) {
... ...
@@ -331,47 +331,47 @@
331 331
      }
332 332
      
333 333
      return value;
334 334
    }
335 335

	
336 336
    ///@}
337 337

	
338 338
    friend class MinCutNodeIt;
339 339

	
340 340
    /// Iterate on the nodes of a minimum cut
341 341
    
342 342
    /// This iterator class lists the nodes of a minimum cut found by
343
    /// GomoryHuTree. Before using it, you must allocate a GomoryHuTree class,
344
    /// and call its \ref GomoryHuTree::run() "run()" method.
343
    /// GomoryHu. Before using it, you must allocate a GomoryHu class,
344
    /// and call its \ref GomoryHu::run() "run()" method.
345 345
    ///
346 346
    /// This example counts the nodes in the minimum cut separating \c s from
347 347
    /// \c t.
348 348
    /// \code
349
    /// GomoruHuTree<Graph> gom(g, capacities);
349
    /// GomoruHu<Graph> gom(g, capacities);
350 350
    /// gom.run();
351 351
    /// int sum=0;
352
    /// for(GomoruHuTree<Graph>::MinCutNodeIt n(gom,s,t);n!=INVALID;++n) ++sum;
352
    /// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t);n!=INVALID;++n) ++sum;
353 353
    /// \endcode
354 354
    class MinCutNodeIt
355 355
    {
356 356
      bool _side;
357 357
      typename Graph::NodeIt _node_it;
358 358
      typename Graph::template NodeMap<bool> _cut;
359 359
    public:
360 360
      /// Constructor
361 361

	
362 362
      /// Constructor
363 363
      ///
364
      MinCutNodeIt(GomoryHuTree const &gomory,
365
                   ///< The GomoryHuTree class. You must call its
364
      MinCutNodeIt(GomoryHu const &gomory,
365
                   ///< The GomoryHu class. You must call its
366 366
                   ///  run() method
367 367
                   ///  before initializing this iterator
368 368
                   const Node& s, ///< Base node
369 369
                   const Node& t,
370 370
                   ///< The node you want to separate from Node s.
371 371
                   bool side=true
372 372
                   ///< If it is \c true (default) then the iterator lists
373 373
                   ///  the nodes of the component containing \c s,
374 374
                   ///  otherwise it lists the other component.
375 375
                   /// \note As the minimum cut is not always unique,
376 376
                   /// \code
377 377
                   /// MinCutNodeIt(gomory, s, t, true);
... ...
@@ -428,59 +428,59 @@
428 428
      {
429 429
        typename Graph::Node n=*this;
430 430
        ++(*this);
431 431
        return n;
432 432
      }
433 433
    };
434 434
    
435 435
    friend class MinCutEdgeIt;
436 436
    
437 437
    /// Iterate on the edges of a minimum cut
438 438
    
439 439
    /// This iterator class lists the edges of a minimum cut found by
440
    /// GomoryHuTree. Before using it, you must allocate a GomoryHuTree class,
441
    /// and call its \ref GomoryHuTree::run() "run()" method.
440
    /// GomoryHu. Before using it, you must allocate a GomoryHu class,
441
    /// and call its \ref GomoryHu::run() "run()" method.
442 442
    ///
443 443
    /// This example computes the value of the minimum cut separating \c s from
444 444
    /// \c t.
445 445
    /// \code
446
    /// GomoruHuTree<Graph> gom(g, capacities);
446
    /// GomoruHu<Graph> gom(g, capacities);
447 447
    /// gom.run();
448 448
    /// int value=0;
449
    /// for(GomoruHuTree<Graph>::MinCutEdgeIt e(gom,s,t);e!=INVALID;++e)
449
    /// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t);e!=INVALID;++e)
450 450
    ///   value+=capacities[e];
451 451
    /// \endcode
452 452
    /// the result will be the same as it is returned by
453
    /// \ref GomoryHuTree::minCostValue() "gom.minCostValue(s,t)"
453
    /// \ref GomoryHu::minCostValue() "gom.minCostValue(s,t)"
454 454
    class MinCutEdgeIt
455 455
    {
456 456
      bool _side;
457 457
      const Graph &_graph;
458 458
      typename Graph::NodeIt _node_it;
459 459
      typename Graph::OutArcIt _arc_it;
460 460
      typename Graph::template NodeMap<bool> _cut;
461 461
      void step()
462 462
      {
463 463
        ++_arc_it;
464 464
        while(_node_it!=INVALID && _arc_it==INVALID)
465 465
          {
466 466
            for(++_node_it;_node_it!=INVALID&&!_cut[_node_it];++_node_it) {}
467 467
            if(_node_it!=INVALID)
468 468
              _arc_it=typename Graph::OutArcIt(_graph,_node_it);
469 469
          }
470 470
      }
471 471
      
472 472
    public:
473
      MinCutEdgeIt(GomoryHuTree const &gomory,
474
                   ///< The GomoryHuTree class. You must call its
473
      MinCutEdgeIt(GomoryHu const &gomory,
474
                   ///< The GomoryHu class. You must call its
475 475
                   ///  run() method
476 476
                   ///  before initializing this iterator
477 477
                   const Node& s,  ///< Base node
478 478
                   const Node& t,
479 479
                   ///< The node you want to separate from Node s.
480 480
                   bool side=true
481 481
                   ///< If it is \c true (default) then the listed arcs
482 482
                   ///  will be oriented from the
483 483
                   ///  the nodes of the component containing \c s,
484 484
                   ///  otherwise they will be oriented in the opposite
485 485
                   ///  direction.
486 486
                   )
Show white space 24 line context
1 1
#include <iostream>
2 2

	
3 3
#include "test_tools.h"
4 4
#include <lemon/smart_graph.h>
5 5
#include <lemon/lgf_reader.h>
6
#include <lemon/gomory_hu_tree.h>
6
#include <lemon/gomory_hu.h>
7 7
#include <cstdlib>
8 8

	
9 9
using namespace std;
10 10
using namespace lemon;
11 11

	
12 12
typedef SmartGraph Graph;
13 13

	
14 14
char test_lgf[] =
15 15
  "@nodes\n"
16 16
  "label\n"
17 17
  "0\n"
18 18
  "1\n"
... ...
@@ -51,43 +51,43 @@
51 51
  return sum;
52 52
}
53 53

	
54 54

	
55 55
int main() {
56 56
  Graph graph;
57 57
  IntEdgeMap capacity(graph);
58 58

	
59 59
  std::istringstream input(test_lgf);
60 60
  GraphReader<Graph>(graph, input).
61 61
    edgeMap("capacity", capacity).run();
62 62

	
63
  GomoryHuTree<Graph> ght(graph, capacity);
63
  GomoryHu<Graph> ght(graph, capacity);
64 64
  ght.init();
65 65
  ght.run();
66 66

	
67 67
  for (NodeIt u(graph); u != INVALID; ++u) {
68 68
    for (NodeIt v(graph); v != u; ++v) {
69 69
      Preflow<Graph, IntEdgeMap> pf(graph, capacity, u, v);
70 70
      pf.runMinCut();
71 71
      BoolNodeMap cm(graph);
72 72
      ght.minCutMap(u, v, cm);
73 73
      check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
74 74
      check(cm[u] != cm[v], "Wrong cut 3");
75 75
      check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 2");
76 76

	
77 77
      int sum=0;
78
      for(GomoryHuTree<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
78
      for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
79 79
        sum+=capacity[a]; 
80 80
      check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt");
81 81

	
82 82
      sum=0;
83
      for(GomoryHuTree<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n)
83
      for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n)
84 84
        sum++;
85
      for(GomoryHuTree<Graph>::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n)
85
      for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n)
86 86
        sum++;
87 87
      check(sum == countNodes(graph), "Problem with MinCutNodeIt");
88 88
      
89 89
    }
90 90
  }
91 91
  
92 92
  return 0;
93 93
}
0 comments (0 inline)