Skip to content

Commit

Permalink
Try Fix deg 0 nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
T3C42 committed Nov 26, 2024
1 parent 771778e commit bcfae8d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
18 changes: 18 additions & 0 deletions mt-kahypar/dynamic/dynamic_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace mt_kahypar::dyn {
continue;
}
std::vector<HyperedgeID> edges = hypergraph_s.incidentEdgesCopy(hn);
std::vector<HypernodeID> remove_prio_nodes;
std::vector<PinChange> removed_pins;
std::vector<HyperedgeID> removed_edges;
for ( const HyperedgeID& he : edges ) {
Expand All @@ -56,13 +57,27 @@ namespace mt_kahypar::dyn {
hypergraph_s.removeEdge(he);
removed_pins.push_back({hn2, he});
removed_edges.push_back(he);
//remove node if it is degree 0
if ( hypergraph_s.incidentEdges(hn2).empty() ) {
if (!hypergraph_s.nodeIsEnabled(hn2)) {
continue;
}
hypergraph_s.disableHypernodeWithEdges(hn2);
if (!context.dynamic.use_final_weight) {
hypergraph_s.decrementTotalWeight(hn2);
}
remove_prio_nodes.push_back(hn2);
}
}
}
hypergraph_s.disableHypernodeWithEdges(hn);
if ( !context.dynamic.use_final_weight ) {
hypergraph_s.decrementTotalWeight(hn);
}
added_nodes_changes.push_back({{hn}, removed_edges, removed_pins, {}, {}, {}});
for ( const HypernodeID& hn2 : remove_prio_nodes ) {
added_nodes_changes.push_back({{hn2}, {}, {}, {}, {}, {}});
}
}

// reverse the order of added_nodes_changes
Expand Down Expand Up @@ -247,6 +262,9 @@ namespace mt_kahypar::dyn {
}

void log_km1_live(size_t i, Context& context, DynamicStrategy::PartitionResult result) {
if (!result.valid) {
return;
}
//TODO change initial_partitioning_size to useful value
std::string filename = context.dynamic.result_folder + context.dynamic.strategy + "_" + std::to_string(context.dynamic.initial_partitioning_size) + "_" + std::to_string(context.partition.k) + "k" + (context.dynamic.use_final_weight ? "_final_weight" : "");
std::ofstream file(filename, std::ios_base::app);
Expand Down
4 changes: 2 additions & 2 deletions mt-kahypar/dynamic/dynamic_partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace mt_kahypar::dyn {
throw std::runtime_error("Unknown dynamic strategy: " + context.dynamic.strategy);
}

std::cout << "Processing " << changes.size() << " changes" << std::endl;
std::cout << "Processing " << context.dynamic.max_changes << " changes" << std::endl;

for (size_t i = 0; i < context.dynamic.max_changes; ++i) {
Change& change = changes[i];
strategy->partition(hypergraph_s, context, change);
if (*(&strategy->history.back().valid)) {
print_progress_bar(i, changes.size(), &strategy->history);
print_progress_bar(i, context.dynamic.max_changes, &strategy->history);
}
log_km1_live(i, context, strategy->history.back());
}
Expand Down
12 changes: 12 additions & 0 deletions mt-kahypar/dynamic/strategies/connectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ namespace mt_kahypar::dyn {
} (), "Number of removed nodes is not correct.");
partitioned_hypergraph_s = partition_hypergraph_km1(hypergraph_s, context);
repartition_count++;

if (!context.dynamic.use_final_weight) {
// TODO check if this is necessary
ASSERT(context.partition.use_individual_part_weights == false);
context.partition.perfect_balance_part_weights.clear();
context.partition.perfect_balance_part_weights = std::vector<HypernodeWeight>(context.partition.k, ceil(
hypergraph_s.totalWeight()
/ static_cast<double>(context.partition.k)));
context.partition.max_part_weights.clear();
context.partition.max_part_weights = std::vector<HypernodeWeight>(context.partition.k, (1 + context.partition.epsilon)
* context.partition.perfect_balance_part_weights[0]);
}
}
public:

Expand Down
13 changes: 13 additions & 0 deletions mt-kahypar/dynamic/strategies/repartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ namespace mt_kahypar::dyn {

auto partitioned_hypergraph_s = partition_hypergraph_km1(hypergraph, context);


if (!context.dynamic.use_final_weight) {
// TODO check if this is necessary
ASSERT(context.partition.use_individual_part_weights == false);
context.partition.perfect_balance_part_weights.clear();
context.partition.perfect_balance_part_weights = std::vector<HypernodeWeight>(context.partition.k, ceil(
hypergraph.totalWeight()
/ static_cast<double>(context.partition.k)));
context.partition.max_part_weights.clear();
context.partition.max_part_weights = std::vector<HypernodeWeight>(context.partition.k, (1 + context.partition.epsilon)
* context.partition.perfect_balance_part_weights[0]);
}

partition_result.km1 = mt_kahypar::metrics::quality(partitioned_hypergraph_s, Objective::km1);
partition_result.imbalance = mt_kahypar::metrics::imbalance(partitioned_hypergraph_s, context);
history.push_back(partition_result);
Expand Down

0 comments on commit bcfae8d

Please sign in to comment.