Skip to content

Commit

Permalink
Fix add/remove edges/pins
Browse files Browse the repository at this point in the history
  • Loading branch information
T3C42 committed Nov 20, 2024
1 parent 54b4f82 commit be827b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
49 changes: 11 additions & 38 deletions mt-kahypar/datastructures/static_hypergraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 #######################
Expand All @@ -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.
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions mt-kahypar/dynamic/dynamic_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit be827b3

Please sign in to comment.