Skip to content

Commit

Permalink
add scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
konpklr committed Dec 19, 2023
1 parent a382923 commit 06c4c20
Show file tree
Hide file tree
Showing 64 changed files with 67 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mt-kahypar/datastructures/hypergraph_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "mt-kahypar/datastructures/array.h"

namespace mt_kahypar {
static constexpr size_t dimension = 3;
static constexpr size_t dimension = 2;
struct NodeWeight {
std::array<int32_t, dimension> weights;

Expand Down
56 changes: 56 additions & 0 deletions mt-kahypar/hmetis_mc_hmetis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/python3
import argparse

# Converts a graph (in metis format) into a hypergraph (in hmetis format)
# by interpreting nodes as hyperedges and edges as nodes. A hyperedge
# connects all edges of the original graph that are incident to the same node.

# Each node in the resulting hypergraph has degree 2. Further, a vertex
# partition of the hypergraph corresponds to an edge partition of the original
# graph.

parser = argparse.ArgumentParser()
parser.add_argument("input", type=str)
parser.add_argument("hypergraph", type=str)

args = parser.parse_args()

mapping = {}

def insertToMapping(u):
if u in mapping:
mapping[u] = mapping[u] + 1
else:
mapping[u] = 1
return u

with open(args.input) as f, open(args.hypergraph, "w") as out:
header = f.readline()
while header.startswith("%"):
header = f.readline()
header_vals = header.strip().split(" ")
n_edges = int(header_vals[0])
n_nodes = int(header_vals[1])
assert len(header_vals) <= 3
out.write(' '.join([header_vals[0], header_vals[1], "11\n"]))
counter = n_edges
for line in f:
if counter == 0:
break
counter = counter -1
vals = line.strip().split(" ")
out.write(vals[0])
out.write(" ")
out.write(' '.join([str(insertToMapping(u)) for u in map(int, vals[1:])]))
out.write("\n")
if header_vals[2] == "11":
for line in f:
out.write(line[:-1])
out.write(" 1\n")
else:
for i in range(1, n_nodes + 1):
if i in mapping:
out.write(str(mapping[i]))
else:
out.write("0")
out.write(" 1\n")
10 changes: 5 additions & 5 deletions mt-kahypar/io/hypergraph_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace mt_kahypar::io {

MT_KAHYPAR_ATTRIBUTE_ALWAYS_INLINE
void do_line_ending(char* mapped_file, size_t& pos) {
ASSERT(is_line_ending(mapped_file, pos));
ASSERT(is_line_ending(mapped_file, pos), mapped_file[pos]);
if (mapped_file[pos] != '\0') {
if (mapped_file[pos] == '\r') { // windows line ending
++pos;
Expand Down Expand Up @@ -400,7 +400,7 @@ namespace mt_kahypar::io {
if ( has_hypernode_weights ) {
hypernodes_weight.resize(num_hypernodes);
for ( HypernodeID hn = 0; hn < num_hypernodes; ++hn ) {
ASSERT(pos > 0 && pos < length);
ASSERT(pos > 0 && pos < length, hypernodes_weight[0].weights[0]);
ASSERT(mapped_file[pos - 1] == '\n');
for(uint8_t j = 0; j < mt_kahypar::dimension; j++){
hypernodes_weight[hn].weights[j] = read_number(mapped_file, pos, length);
Expand All @@ -420,10 +420,10 @@ namespace mt_kahypar::io {
vec<HypernodeWeight>& hypernodes_weight,
const bool remove_single_pin_hes) {
ASSERT(!filename.empty(), "No filename for hypergraph file specified");
/*FileHandle handle = mmap_file(filename);*/
FileHandle handle = mmap_file(filename);
std::string input = "4 7 11\n4 1 3\n2 1 2 4 5\n3 4 5 7\n8 3 6 7\n5 5 5\n8 8 8\n2 2 2\n3 3 3\n4 4 4\n9 9 9\n8 8 8";

FileHandle handle = {0, &input[0], input.length()};
/*FileHandle handle = {0, &input[0], input.length()};*/
size_t pos = 0;

// Read Hypergraph Header
Expand All @@ -446,7 +446,7 @@ namespace mt_kahypar::io {
readHypernodeWeights(handle.mapped_file, pos, handle.length, num_hypernodes, type, hypernodes_weight);
ASSERT(pos == handle.length);

/*munmap_file(handle);*/
munmap_file(handle);
}

void readMetisHeader(char* mapped_file,
Expand Down
2 changes: 1 addition & 1 deletion mt-kahypar/partition/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ namespace mt_kahypar {
} else {
partition.perfect_balance_part_weights.clear();
HypernodeWeight nw;
for(int i = 0; i < partition.k; i++){
for(int i = 0; i < dimension; i++){
nw.weights[i] = ceil(total_hypergraph_weight.weights[i]
/ static_cast<double>(partition.k));
}
Expand Down
5 changes: 3 additions & 2 deletions mt-kahypar/partition/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct PartitioningParameters {
HypernodeID large_hyperedge_size_threshold = std::numeric_limits<HypernodeID>::max();
HypernodeID smallest_large_he_size_threshold = std::numeric_limits<HypernodeID>::max();
HypernodeID ignore_hyperedge_size_threshold = std::numeric_limits<HypernodeID>::max();

bool verbose_output = true;
bool show_detailed_timings = false;
bool show_detailed_clustering_timings = false;
Expand All @@ -72,7 +72,7 @@ struct PartitioningParameters {
bool enable_progress_bar = false;
bool sp_process_output = false;
bool csv_output = false;
bool write_partition_file = false;
bool write_partition_file = true;
bool deterministic = false;

std::string graph_filename { };
Expand Down Expand Up @@ -282,6 +282,7 @@ class Context {
SharedMemoryParameters shared_memory { };
ContextType type = ContextType::main;


std::string algorithm_name = "Mt-KaHyPar";
mutable size_t initial_km1 = std::numeric_limits<size_t>::max();
size_t utility_id = std::numeric_limits<size_t>::max();
Expand Down
2 changes: 1 addition & 1 deletion tests/instances/test_instance.hgr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
100 100 11
100 100 01
1 87 78 16
1 36 87 93 50 22 63 28 91 60 64 27 41 73
1 12 69 68 30 83 31 63 24 36 3 23 59 70 94 57 43
Expand Down

0 comments on commit 06c4c20

Please sign in to comment.