Skip to content

Commit

Permalink
add functionality of L_max and L_kmax
Browse files Browse the repository at this point in the history
  • Loading branch information
Magikarpm committed Nov 12, 2023
1 parent 86c01a2 commit 86ceacb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct ClusteringContext {
ConcurrentClusteringData& clustering_data,
NumNodesTracker& num_nodes_tracker):
hierarchy_contraction_limit(hierarchy_contraction_limit),
max_weight_function(context.coarsening.max_weight_function),
max_allowed_node_weight(context.coarsening.max_allowed_node_weight),
original_num_threads(context.shared_memory.original_num_threads),
num_hns_before_pass(0),
Expand Down Expand Up @@ -139,6 +140,7 @@ struct ClusteringContext {
}

HypernodeID hierarchy_contraction_limit;
MaxWeightFunction max_weight_function;
HypernodeWeight max_allowed_node_weight;
size_t original_num_threads;
bool may_ignore_communities = false;
Expand Down
39 changes: 28 additions & 11 deletions mt-kahypar/partition/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,35 @@ namespace mt_kahypar {
}

void Context::setupMaximumAllowedNodeWeight(const HypernodeWeight total_hypergraph_weight) {
HypernodeWeight min_block_weight = std::numeric_limits<HypernodeWeight>::max();
for ( PartitionID part_id = 0; part_id < partition.k; ++part_id ) {
min_block_weight = std::min(min_block_weight, partition.max_part_weights[part_id]);
}

double hypernode_weight_fraction =
coarsening.max_allowed_weight_multiplier
/ coarsening.contraction_limit;
coarsening.max_allowed_node_weight =
std::ceil(hypernode_weight_fraction * total_hypergraph_weight);
coarsening.max_allowed_node_weight =
std::min(coarsening.max_allowed_node_weight, min_block_weight);
coarsening.max_allowed_weight_multiplier
/ coarsening.contraction_limit;
switch (coarsening.max_weight_function) {
case MaxWeightFunction::L_max:
{
HypernodeWeight min_block_weight = std::numeric_limits<HypernodeWeight>::max();
for ( PartitionID part_id = 0; part_id < partition.k; ++part_id ) {
min_block_weight = std::min(min_block_weight, partition.max_part_weights[part_id]);
}
coarsening.max_allowed_node_weight =
std::ceil(hypernode_weight_fraction * total_hypergraph_weight);
coarsening.max_allowed_node_weight =
std::min(coarsening.max_allowed_node_weight, min_block_weight);
break;
}
case MaxWeightFunction::L_kmax:
{
HypernodeWeight max_block_weight = std::numeric_limits<HypernodeWeight>::min();
for ( PartitionID part_id = 0; part_id < partition.k; ++part_id ) {
max_block_weight = std::max(max_block_weight, partition.max_part_weights[part_id]);
}
coarsening.max_allowed_node_weight =
std::max(hypernode_weight_fraction * total_hypergraph_weight, hypernode_weight_fraction + max_block_weight);
break;
}
case MaxWeightFunction::UNDEFINED:
break;
}
}

void Context::sanityCheck(const TargetGraph* target_graph) {
Expand Down

0 comments on commit 86ceacb

Please sign in to comment.