Bug fixes is HaoOrlin and MinCostArborescence
authordeba
Wed, 08 Oct 2008 09:17:01 +0000
changeset 2624dc4dd5fc0e25
parent 2623 90defb96ee61
child 2625 c51b320bc51c
Bug fixes is HaoOrlin and MinCostArborescence

MinCostArborescence
- proper deallocation
HaoOrlin
- the target needn't to be the last in its bucket
- proper size of container (if each node starts in different buckets initially)
lemon/hao_orlin.h
lemon/min_cost_arborescence.h
     1.1 --- a/lemon/hao_orlin.h	Mon Oct 06 15:08:17 2008 +0000
     1.2 +++ b/lemon/hao_orlin.h	Wed Oct 08 09:17:01 2008 +0000
     1.3 @@ -21,13 +21,11 @@
     1.4  
     1.5  #include <vector>
     1.6  #include <list>
     1.7 -#include <ext/hash_set>
     1.8  #include <limits>
     1.9  
    1.10  #include <lemon/maps.h>
    1.11  #include <lemon/graph_utils.h>
    1.12 -#include <lemon/graph_adaptor.h>
    1.13 -#include <lemon/iterable_maps.h>
    1.14 +#include <lemon/tolerance.h>
    1.15  
    1.16  /// \file
    1.17  /// \ingroup min_cut
    1.18 @@ -293,10 +291,11 @@
    1.19  	    _flow->set(e, (*_capacity)[e]);
    1.20  	    _excess->set(u, (*_excess)[u] + (*_capacity)[e]);
    1.21  	    if (!(*_active)[u] && u != _source) {
    1.22 -	      activate(u);
    1.23 +	      activate(u);	      
    1.24  	    }
    1.25  	  }
    1.26  	}
    1.27 +
    1.28  	if ((*_active)[target]) {
    1.29  	  deactivate(target);
    1.30  	}
    1.31 @@ -308,7 +307,6 @@
    1.32  	}
    1.33        }
    1.34  
    1.35 -
    1.36        while (true) {
    1.37  	while (_highest != _sets.back().end()) {
    1.38  	  Node n = _first[*_highest];
    1.39 @@ -462,10 +460,19 @@
    1.40  
    1.41  	{
    1.42  	  Node new_target;
    1.43 -	  if ((*_prev)[target] != INVALID) {
    1.44 -	    _last[(*_bucket)[target]] = (*_prev)[target];
    1.45 -	    _next->set((*_prev)[target], INVALID);
    1.46 -	    new_target = (*_prev)[target];
    1.47 +	  if ((*_prev)[target] != INVALID || (*_next)[target] != INVALID) {
    1.48 +	    if ((*_next)[target] == INVALID) {
    1.49 +	      _last[(*_bucket)[target]] = (*_prev)[target];
    1.50 +	      new_target = (*_prev)[target];
    1.51 +	    } else {
    1.52 +	      _prev->set((*_next)[target], (*_prev)[target]);
    1.53 +	      new_target = (*_next)[target];
    1.54 +	    }
    1.55 +	    if ((*_prev)[target] == INVALID) {
    1.56 +	      _first[(*_bucket)[target]] = (*_next)[target];
    1.57 +	    } else {
    1.58 +	      _next->set((*_prev)[target], (*_next)[target]);
    1.59 +	    }
    1.60  	  } else {
    1.61  	    _sets.back().pop_back();
    1.62  	    if (_sets.back().empty()) {
    1.63 @@ -761,10 +768,19 @@
    1.64  
    1.65  	{
    1.66  	  Node new_target;
    1.67 -	  if ((*_prev)[target] != INVALID) {
    1.68 -	    _last[(*_bucket)[target]] = (*_prev)[target];
    1.69 -	    _next->set((*_prev)[target], INVALID);
    1.70 -	    new_target = (*_prev)[target];
    1.71 +	  if ((*_prev)[target] != INVALID || (*_next)[target] != INVALID) {
    1.72 +	    if ((*_next)[target] == INVALID) {
    1.73 +	      _last[(*_bucket)[target]] = (*_prev)[target];
    1.74 +	      new_target = (*_prev)[target];
    1.75 +	    } else {
    1.76 +	      _prev->set((*_next)[target], (*_prev)[target]);
    1.77 +	      new_target = (*_next)[target];
    1.78 +	    }
    1.79 +	    if ((*_prev)[target] == INVALID) {
    1.80 +	      _first[(*_bucket)[target]] = (*_next)[target];
    1.81 +	    } else {
    1.82 +	      _next->set((*_prev)[target], (*_next)[target]);
    1.83 +	    }
    1.84  	  } else {
    1.85  	    _sets.back().pop_back();
    1.86  	    if (_sets.back().empty()) {
    1.87 @@ -850,10 +866,10 @@
    1.88        
    1.89        _node_num = countNodes(_graph);
    1.90        
    1.91 -      _first.resize(_node_num);
    1.92 -      _last.resize(_node_num);
    1.93 +      _first.resize(_node_num + 1);
    1.94 +      _last.resize(_node_num + 1);
    1.95  
    1.96 -      _dormant.resize(_node_num);
    1.97 +      _dormant.resize(_node_num + 1);
    1.98  
    1.99        if (!_flow) {
   1.100  	_flow = new FlowMap(_graph);
     2.1 --- a/lemon/min_cost_arborescence.h	Mon Oct 06 15:08:17 2008 +0000
     2.2 +++ b/lemon/min_cost_arborescence.h	Wed Oct 08 09:17:01 2008 +0000
     2.3 @@ -643,19 +643,19 @@
     2.4        if (local_pred) {
     2.5          delete _pred;
     2.6        }
     2.7 -      if (!_edge_order) {
     2.8 +      if (_edge_order) {
     2.9          delete _edge_order;
    2.10        }
    2.11        if (_node_order) {
    2.12          delete _node_order;
    2.13        }
    2.14 -      if (!_cost_edges) {
    2.15 +      if (_cost_edges) {
    2.16          delete _cost_edges;
    2.17        }
    2.18 -      if (!_heap) {
    2.19 +      if (_heap) {
    2.20          delete _heap;
    2.21        }
    2.22 -      if (!_heap_cross_ref) {
    2.23 +      if (_heap_cross_ref) {
    2.24          delete _heap_cross_ref;
    2.25        }
    2.26      }