From b117d7922e3e9760e4418541d030ed30f01a5b20 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 18 May 2020 16:21:35 -0400 Subject: Initial commit. --- .gitmodules | 6 +++ grown_networks.cpp | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++ pcg-cpp | 1 + randutils | 1 + 4 files changed, 134 insertions(+) create mode 100644 .gitmodules create mode 100644 grown_networks.cpp create mode 160000 pcg-cpp create mode 160000 randutils diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a14394b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "randutils"] + path = randutils + url = https://gist.github.com/imneme/540829265469e673d045 +[submodule "pcg-cpp"] + path = pcg-cpp + url = https://github.com/imneme/pcg-cpp diff --git a/grown_networks.cpp b/grown_networks.cpp new file mode 100644 index 0000000..bacbb71 --- /dev/null +++ b/grown_networks.cpp @@ -0,0 +1,126 @@ + +#include +#include +#include +#include +#include + +#include "pcg-cpp/include/pcg_random.hpp" +#include "randutils/randutils.hpp" + +#include +#include + +using Rng = randutils::random_generator; + +typedef boost::adjacency_list Graph; + +int main(int argc, char* argv[]) { + unsigned N = 10; + unsigned T = 1000; + double δ = 1.0 / 8; + + int opt; + + while ((opt = getopt(argc, argv, "N:T:d:")) != -1) { + switch (opt) { + case 'N': + N = (unsigned)atof(optarg); + break; + case 'T': + T = (unsigned)atof(optarg); + break; + case 'd': + δ = atof(optarg); + break; + default: + exit(1); + } + } + + Rng rng; + + std::uniform_real_distribution dr(0.0, 1.0); + + std::vector ns(T); + std::vector nS(T); + + for (unsigned i = 0; i < N; i++) { + Graph G(T); + + for (unsigned t = 0; t < T; t++) { + if (rng.uniform(0.0, 1.0) < δ) { + boost::add_edge(rng.uniform((unsigned)0, t), rng.uniform((unsigned)0, t), G); + } + } + + std::vector components(T); + unsigned nc = boost::connected_components(G, &components[0]); + + std::vector s(nc); + + for (unsigned j : components) { + s[j]++; + } + + unsigned j_max = 0; + + for (unsigned j : s) { + ns[j - 1]++; + + if (j > j_max) { + j_max = j; + } + } + + nS[j_max - 1]++; + } + + std::string filename = "ns_" + std::to_string(δ) + "_" + std::to_string(T) + ".dat"; + + std::ifstream outfile(filename); + + std::vector ns_old(T, 0); + + if (outfile.is_open()) { + for (unsigned i = 0; i < T; i++) { + uint64_t num; + outfile >> num; + ns_old[i] = num; + } + + outfile.close(); + } + + std::ofstream file_out(filename); + + for (unsigned i = 0; i < T; i++) { + file_out < nS_old(T, 0); + + if (outfile_S.is_open()) { + for (unsigned i = 0; i < T; i++) { + uint64_t num; + outfile_S >> num; + nS_old[i] = num; + } + + outfile_S.close(); + } + + std::ofstream file_out_S(filename_S); + + for (unsigned i = 0; i < T; i++) { + file_out_S <