From 7b875ba141887db70da052126be410fee7c80da5 Mon Sep 17 00:00:00 2001 From: Richard Wong Date: Tue, 7 May 2024 11:38:31 +0900 Subject: [PATCH] Feat: added graph generation for barabasi-albert and regular --- ....cpp => make_random_biconnected_graph.cpp} | 0 make_graphs/make_regular_graph.cpp | 27 +++++++++++++++++ make_graphs/make_scale_free_graph.cpp | 27 +++++++++++++++++ synthetic_data/barabasi/.gitignore | 2 ++ synthetic_data/barabasi/generate_graphs.bash | 30 +++++++++++++++++++ synthetic_data/regular/.gitignore | 2 ++ synthetic_data/regular/generate_graphs.bash | 30 +++++++++++++++++++ 7 files changed, 118 insertions(+) rename make_graphs/{make_graphs.cpp => make_random_biconnected_graph.cpp} (100%) create mode 100644 make_graphs/make_regular_graph.cpp create mode 100644 make_graphs/make_scale_free_graph.cpp create mode 100644 synthetic_data/barabasi/.gitignore create mode 100644 synthetic_data/barabasi/generate_graphs.bash create mode 100644 synthetic_data/regular/.gitignore create mode 100644 synthetic_data/regular/generate_graphs.bash diff --git a/make_graphs/make_graphs.cpp b/make_graphs/make_random_biconnected_graph.cpp similarity index 100% rename from make_graphs/make_graphs.cpp rename to make_graphs/make_random_biconnected_graph.cpp diff --git a/make_graphs/make_regular_graph.cpp b/make_graphs/make_regular_graph.cpp new file mode 100644 index 0000000..d098b2e --- /dev/null +++ b/make_graphs/make_regular_graph.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +using namespace ogdf; + +int main(int argc, char **argv) { + int nodeCount = std::stoi(argv[1]); + int edgeCount = std::stoi(argv[2]); + int copies = std::stoi(argv[3]); + int seed = std::stoi(argv[4]); + std::string outputFolder = argv[5]; + + setSeed(seed); + for (int i = 0; i < copies; i++) { + Graph G; + randomRegularGraph(G, nodeCount, edgeCount); + + std::stringstream ss; + ss << outputFolder << "/graphn" << nodeCount << "e" << edgeCount << "s" + << seed << "i" << i << ".gml"; + std::string s = ss.str(); + GraphIO::write(G, s, GraphIO::writeGML); + } + +} diff --git a/make_graphs/make_scale_free_graph.cpp b/make_graphs/make_scale_free_graph.cpp new file mode 100644 index 0000000..4b17a47 --- /dev/null +++ b/make_graphs/make_scale_free_graph.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +using namespace ogdf; + +int main(int argc, char **argv) { + int nodeCount = std::stoi(argv[1]); + int edgeCount = std::stoi(argv[2]); + int copies = std::stoi(argv[3]); + int seed = std::stoi(argv[4]); + std::string outputFolder = argv[5]; + + setSeed(seed); + for (int i = 0; i < copies; i++) { + Graph G; + preferentialAttachmentGraph(G, nodeCount, edgeCount); + + std::stringstream ss; + ss << outputFolder << "/graphn" << nodeCount << "e" << edgeCount << "s" + << seed << "i" << i << ".gml"; + std::string s = ss.str(); + GraphIO::write(G, s, GraphIO::writeGML); + } + +} diff --git a/synthetic_data/barabasi/.gitignore b/synthetic_data/barabasi/.gitignore new file mode 100644 index 0000000..c92f9d1 --- /dev/null +++ b/synthetic_data/barabasi/.gitignore @@ -0,0 +1,2 @@ +100* +make_scale_free_graph diff --git a/synthetic_data/barabasi/generate_graphs.bash b/synthetic_data/barabasi/generate_graphs.bash new file mode 100644 index 0000000..fbef199 --- /dev/null +++ b/synthetic_data/barabasi/generate_graphs.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +# Define the parameters +num_node_range=(100 1000 10000) +edge_multiplier_range=(2 3 5 10 20) +copies=20 +seed=41 + +max_jobs=2 +running_jobs=0 + +# Loop through different parameters +for num_node in "${num_node_range[@]}"; do + for edge_multiplier in "${edge_multiplier_range[@]}"; do + num_edge=$((num_node * edge_multiplier)) + output_folder="${num_node}n${num_edge}e" + mkdir -p $output_folder + + # Run the program with the parameters + echo "run with $num_node nodes and $num_edge edges output to $output_folder" + ./make_scale_free_graph $num_node $num_edge $copies $seed $output_folder & + + ((running_jobs++)) + + if ((running_jobs >= max_jobs)); then + wait + running_jobs=0 + fi + done +done diff --git a/synthetic_data/regular/.gitignore b/synthetic_data/regular/.gitignore new file mode 100644 index 0000000..7dd6445 --- /dev/null +++ b/synthetic_data/regular/.gitignore @@ -0,0 +1,2 @@ +100* +make_regular_graph diff --git a/synthetic_data/regular/generate_graphs.bash b/synthetic_data/regular/generate_graphs.bash new file mode 100644 index 0000000..fba2a83 --- /dev/null +++ b/synthetic_data/regular/generate_graphs.bash @@ -0,0 +1,30 @@ +#!/bin/bash + +# Define the parameters +num_node_range=(100 1000 10000) +edge_multiplier_range=(2 3 5 10 20) +copies=20 +seed=41 + +max_jobs=2 +running_jobs=0 + +# Loop through different parameters +for num_node in "${num_node_range[@]}"; do + for edge_multiplier in "${edge_multiplier_range[@]}"; do + num_edge=$((num_node * edge_multiplier)) + output_folder="${num_node}n${num_edge}e" + mkdir -p $output_folder + + # Run the program with the parameters + echo "run with $num_node nodes and $num_edge edges output to $output_folder" + ./make_regular_graph $num_node $num_edge $copies $seed $output_folder & + + ((running_jobs++)) + + if ((running_jobs >= max_jobs)); then + wait + running_jobs=0 + fi + done +done