Skip to content

Commit

Permalink
added metis converter
Browse files Browse the repository at this point in the history
  • Loading branch information
lidlessey3 committed Dec 23, 2023
1 parent 1e29c0d commit 8579867
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ add_executable(Memory_Tester src/test/memory-tester.cpp src/partitioning.h src/l
src/parallel_partitioning.cpp src/parallel_coarsening.cpp src/loader.cpp src/parallel_kernighanLin.cpp
src/output.cpp src/Graph.h src/Graph.cpp
src/clusterCutSize.h src/clusterCutSize.cpp src/output.cpp)

add_executable(MetisConverter src/tools/metis_converter.cpp
src/loader.cpp src/Graph.cpp)
37 changes: 37 additions & 0 deletions src/tools/metis_converter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <fstream>
#include <iostream>
#include <string>
#include "../partitioning.h"

int main(int argc, char** argv) {
if (argc != 3) {
std::cout << "Usage:" << std::endl << argv[0] << " <input file> <output file>" << std::endl;
return 1;
}

std::cout << "Loading from file" << std::endl;
auto graph = loadFromFile(std::string(argv[1]), 4);

std::ofstream out(argv[2]); // open the file in text mode

std::cout << "Writing file" << std::endl;
out << graph->V() << " " << graph->E() << " 011" << std::endl;

for (auto node : graph->nodes) {
out << node->weight;
for (auto edge : node->edges) {
out << " ";
auto node1 = edge->node1.lock();

if (node1->id != node->id)
out << node1->id + 1;
else
out <<edge->node2.lock()->id + 1;

out << " " << edge->weight;
}
out << std::endl;
}

out.close();
}

0 comments on commit 8579867

Please sign in to comment.