Skip to content

Commit 920fba5

Browse files
committed
add connected blocks to verify partition tool
1 parent 75ff475 commit 920fba5

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

mt-kahypar/partition/connected_components/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ set(ConnectedComponentsSources
22
compute_components.cpp)
33

44
target_sources(MtKaHyPar-Sources INTERFACE ${ConnectedComponentsSources})
5+
6+
target_sources(MtKaHyPar-ToolsSources INTERFACE ${ConnectedComponentsSources})

tools/verify_partition.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "mt-kahypar/datastructures/static_hypergraph.h"
3636
#include "mt-kahypar/datastructures/partitioned_hypergraph.h"
3737
#include "mt-kahypar/datastructures/connectivity_info.h"
38+
#include "mt-kahypar/partition/connected_components/compute_components.h"
3839
#include "mt-kahypar/partition/context.h"
3940
#include "mt-kahypar/partition/metrics.h"
4041
#include "mt-kahypar/io/hypergraph_factory.h"
@@ -100,6 +101,11 @@ int main(int argc, char* argv[]) {
100101
" - hmetis: hMETIS hypergraph file format\n"
101102
" - metis: METIS graph file format"
102103
)->default_str("hmetis");
104+
app.add_option(
105+
"--connected-blocks",
106+
context.partition.connected_blocks,
107+
"Ensure that the blocks of the resulting partition are connected"
108+
)->capture_default_str();
103109
app.add_option(
104110
"-f,--fixed,--fixed-vertices",
105111
context.partition.fixed_vertex_filename,
@@ -150,6 +156,19 @@ int main(int argc, char* argv[]) {
150156
}
151157
}
152158

159+
// Check connected blocks
160+
if ( context.partition.connected_blocks ) {
161+
vec<vec<connected_components::ConnectedComponent>> components;
162+
connected_components::compute_components_per_block(phg, context, components);
163+
164+
for ( PartitionID i = 0; i < context.partition.k; ++i ) {
165+
if ( components[i].size() > 1 ) {
166+
LOG << RED << "Block" << i << "has" << components[i].size() << "components and is therefore not connected" << END;
167+
success = false;
168+
}
169+
}
170+
}
171+
153172
std::cout << "***********************" << context.partition.k
154173
<< "-way Partition Result************************" << std::endl;
155174
std::cout << "cut =" << metrics::quality(phg, Objective::cut) << std::endl;

0 commit comments

Comments
 (0)