diff --git a/lemon/matching.h b/lemon/matching.h --- a/lemon/matching.h +++ b/lemon/matching.h @@ -810,41 +810,60 @@ if (!_matching) { _matching = new MatchingMap(_graph); } + if (!_node_potential) { _node_potential = new NodePotential(_graph); } + if (!_blossom_set) { _blossom_index = new IntNodeMap(_graph); _blossom_set = new BlossomSet(*_blossom_index); _blossom_data = new RangeMap(_blossom_num); + } else if (_blossom_data->size() != _blossom_num) { + delete _blossom_data; + _blossom_data = new RangeMap(_blossom_num); } if (!_node_index) { _node_index = new IntNodeMap(_graph); _node_heap_index = new IntArcMap(_graph); _node_data = new RangeMap(_node_num, - NodeData(*_node_heap_index)); + NodeData(*_node_heap_index)); + } else { + delete _node_data; + _node_data = new RangeMap(_node_num, + NodeData(*_node_heap_index)); } if (!_tree_set) { _tree_set_index = new IntIntMap(_blossom_num); _tree_set = new TreeSet(*_tree_set_index); + } else { + _tree_set_index->resize(_blossom_num); } + if (!_delta1) { _delta1_index = new IntNodeMap(_graph); _delta1 = new BinHeap(*_delta1_index); } + if (!_delta2) { _delta2_index = new IntIntMap(_blossom_num); _delta2 = new BinHeap(*_delta2_index); + } else { + _delta2_index->resize(_blossom_num); } + if (!_delta3) { _delta3_index = new IntEdgeMap(_graph); _delta3 = new BinHeap(*_delta3_index); } + if (!_delta4) { _delta4_index = new IntIntMap(_blossom_num); _delta4 = new BinHeap(*_delta4_index); + } else { + _delta4_index->resize(_blossom_num); } } @@ -1588,6 +1607,9 @@ void init() { createStructures(); + _blossom_node_list.clear(); + _blossom_potential.clear(); + for (ArcIt e(_graph); e != INVALID; ++e) { (*_node_heap_index)[e] = BinHeap::PRE_HEAP; } @@ -1601,9 +1623,16 @@ (*_delta2_index)[i] = _delta2->PRE_HEAP; (*_delta4_index)[i] = _delta4->PRE_HEAP; } - + _unmatched = _node_num; + _delta1->clear(); + _delta2->clear(); + _delta3->clear(); + _delta4->clear(); + _blossom_set->clear(); + _tree_set->clear(); + int index = 0; for (NodeIt n(_graph); n != INVALID; ++n) { Value max = 0; @@ -1614,6 +1643,8 @@ } } (*_node_index)[n] = index; + (*_node_data)[index].heap_index.clear(); + (*_node_data)[index].heap.clear(); (*_node_data)[index].pot = max; _delta1->push(n, max); int blossom = @@ -2237,13 +2268,18 @@ if (!_matching) { _matching = new MatchingMap(_graph); } + if (!_node_potential) { _node_potential = new NodePotential(_graph); } + if (!_blossom_set) { _blossom_index = new IntNodeMap(_graph); _blossom_set = new BlossomSet(*_blossom_index); _blossom_data = new RangeMap(_blossom_num); + } else if (_blossom_data->size() != _blossom_num) { + delete _blossom_data; + _blossom_data = new RangeMap(_blossom_num); } if (!_node_index) { @@ -2251,23 +2287,36 @@ _node_heap_index = new IntArcMap(_graph); _node_data = new RangeMap(_node_num, NodeData(*_node_heap_index)); + } else if (_node_data->size() != _node_num) { + delete _node_data; + _node_data = new RangeMap(_node_num, + NodeData(*_node_heap_index)); } if (!_tree_set) { _tree_set_index = new IntIntMap(_blossom_num); _tree_set = new TreeSet(*_tree_set_index); + } else { + _tree_set_index->resize(_blossom_num); } + if (!_delta2) { _delta2_index = new IntIntMap(_blossom_num); _delta2 = new BinHeap(*_delta2_index); + } else { + _delta2_index->resize(_blossom_num); } + if (!_delta3) { _delta3_index = new IntEdgeMap(_graph); _delta3 = new BinHeap(*_delta3_index); } + if (!_delta4) { _delta4_index = new IntIntMap(_blossom_num); _delta4 = new BinHeap(*_delta4_index); + } else { + _delta4_index->resize(_blossom_num); } } @@ -2968,6 +3017,9 @@ void init() { createStructures(); + _blossom_node_list.clear(); + _blossom_potential.clear(); + for (ArcIt e(_graph); e != INVALID; ++e) { (*_node_heap_index)[e] = BinHeap::PRE_HEAP; } @@ -2981,6 +3033,12 @@ _unmatched = _node_num; + _delta2->clear(); + _delta3->clear(); + _delta4->clear(); + _blossom_set->clear(); + _tree_set->clear(); + int index = 0; for (NodeIt n(_graph); n != INVALID; ++n) { Value max = - std::numeric_limits::max(); @@ -2991,6 +3049,8 @@ } } (*_node_index)[n] = index; + (*_node_data)[index].heap_index.clear(); + (*_node_data)[index].heap.clear(); (*_node_data)[index].pot = max; int blossom = _blossom_set->insert(n, std::numeric_limits::max()); diff --git a/lemon/unionfind.h b/lemon/unionfind.h --- a/lemon/unionfind.h +++ b/lemon/unionfind.h @@ -1288,6 +1288,15 @@ : index(_index), first_class(-1), first_free_class(-1), first_free_node(-1) {} + /// \brief Clears the union-find data structure + /// + /// Erase each item from the data structure. + void clear() { + nodes.clear(); + classes.clear(); + first_free_node = first_free_class = first_class = -1; + } + /// \brief Insert a new node into a new component. /// /// Insert a new node into a new component.