From be827b3536914906a57ef5b3a7489dce7ad0c9eb Mon Sep 17 00:00:00 2001 From: Tobias Kempf Date: Wed, 20 Nov 2024 22:53:49 +0100 Subject: [PATCH] Fix add/remove edges/pins --- mt-kahypar/datastructures/static_hypergraph.h | 49 +++++-------------- mt-kahypar/dynamic/dynamic_io.h | 6 +-- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/mt-kahypar/datastructures/static_hypergraph.h b/mt-kahypar/datastructures/static_hypergraph.h index 5506883dc..cbf1426fa 100644 --- a/mt-kahypar/datastructures/static_hypergraph.h +++ b/mt-kahypar/datastructures/static_hypergraph.h @@ -772,38 +772,24 @@ class StaticHypergraph { // ####################### Remove / Restore Pins ####################### /*! - * Removes a pin from the hyperedge. + * Removes a pin. */ - void removeIncidentPinFromEdge(const HyperedgeID hn, const HypernodeID he) { + void removePin(const HyperedgeID hn, const HypernodeID he) { using std::swap; ASSERT(edgeIsEnabled(he), "Hyperedge" << he << "is disabled"); ASSERT(nodeIsEnabled(hn), "Hypernode" << hn << "is disabled"); - const size_t pos = hyperedge(he).firstEntry(); - const size_t end = hyperedge(he).firstInvalidEntry(); - for ( size_t i = pos; i < end; ++i ) { - if ( _incidence_array[i] == hn ) { - swap(_incidence_array[i], _incidence_array[end - 1]); - hyperedge(he).setSize(hyperedge(he).size() - 1); - return; - } - } + removeIncidentEdgeFromHypernode(he, hn); + removeIncidentHypernodeFromEdge(hn, he); } /*! - * Restores a pin previously removed from the hyperedge. + * Restores a pin previously removed */ - void restoreIncidentPinToEdge(const HyperedgeID hn, const HypernodeID he) { + void restorePin(const HyperedgeID hn, const HypernodeID he) { ASSERT(edgeIsEnabled(he), "Hyperedge" << he << "is disabled"); ASSERT(nodeIsEnabled(hn), "Hypernode" << hn << "is disabled"); - const size_t pos = hyperedge(he).firstEntry(); - const size_t end = hyperedge(he).firstInvalidEntry(); - for ( size_t i = pos; i < end; ++i ) { - if ( _incidence_array[i] == hn ) { - return; - } - } - _incidence_array[end] = hn; - hyperedge(he).setSize(hyperedge(he).size() + 1); + insertIncidentEdgeToHypernode(he, hn); + restoreIncidentHypernodeToEdge(hn, he); } // ####################### Remove / Restore Hyperedges ####################### @@ -824,18 +810,6 @@ class StaticHypergraph { disableHyperedge(he); } - /*! - * Removes a hyperedge from the hypergraph without removing the pins. - * - * NOTE, this function is not thread-safe and should only be called in a single-threaded - * setting. - */ - void removeEdgeWithoutRemovingPins(const HyperedgeID he) { - ASSERT(edgeIsEnabled(he), "Hyperedge" << he << "is disabled"); - ++_num_removed_hyperedges; - disableHyperedge(he); - } - /*! * Restores a hyperedge previously removed from the hypergraph. * This includes the restoration of he to all of its pins. @@ -846,10 +820,9 @@ class StaticHypergraph { void restoreEdge(const HyperedgeID he) { ASSERT(!edgeIsEnabled(he), "Hyperedge" << he << "is enabled"); enableHyperedge(he); - //TODO only needed if edge was removed -// for ( const HypernodeID& pin : pins(he) ) { -// insertIncidentEdgeToHypernode(he, pin); -// } + for ( const HypernodeID& pin : pins(he) ) { + insertIncidentEdgeToHypernode(he, pin); + } --_num_removed_hyperedges; } diff --git a/mt-kahypar/dynamic/dynamic_io.h b/mt-kahypar/dynamic/dynamic_io.h index 612bf5eaa..6c2e1febc 100644 --- a/mt-kahypar/dynamic/dynamic_io.h +++ b/mt-kahypar/dynamic/dynamic_io.h @@ -54,7 +54,7 @@ namespace mt_kahypar::dyn { // Disable all the edges using seed for ( const HyperedgeID& he : disabling_order ) { - hypergraph_s.removeEdgeWithoutRemovingPins(he); + hypergraph_s.removeEdge(he); added_edges.push_back(he); } @@ -90,14 +90,14 @@ namespace mt_kahypar::dyn { if ( !hypergraph_s.nodeIsEnabled(hn) ) { continue; } - hypergraph_s.removeIncidentPinFromEdge(hn, he); + hypergraph_s.removePin(hn, he); added_pins.push_back({hn, he}); } } // re-enable all pins until start_id for ( auto [hn, he]: added_pins ) { - hypergraph_s.restoreIncidentPinToEdge(hn, he); + hypergraph_s.restorePin(hn, he); ASSERT(std::find(hypergraph_s.pins(he).begin(), hypergraph_s.pins(he).end(), hn) != hypergraph_s.pins(he).end()); }