summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2020-05-18 16:21:35 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2020-05-18 16:21:35 -0400
commitb117d7922e3e9760e4418541d030ed30f01a5b20 (patch)
tree4860977309d2ba1c2a29ea2ba29b56e9b53ed2e5
downloadcode-b117d7922e3e9760e4418541d030ed30f01a5b20.tar.gz
code-b117d7922e3e9760e4418541d030ed30f01a5b20.tar.bz2
code-b117d7922e3e9760e4418541d030ed30f01a5b20.zip
Initial commit.
-rw-r--r--.gitmodules6
-rw-r--r--grown_networks.cpp126
m---------pcg-cpp0
m---------randutils0
4 files changed, 132 insertions, 0 deletions
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 <fstream>
+#include <random>
+#include <cinttypes>
+#include <vector>
+#include <string>
+
+#include "pcg-cpp/include/pcg_random.hpp"
+#include "randutils/randutils.hpp"
+
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/connected_components.hpp>
+
+using Rng = randutils::random_generator<pcg32>;
+
+typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> 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<double> dr(0.0, 1.0);
+
+ std::vector<uint64_t> ns(T);
+ std::vector<uint64_t> 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<unsigned> components(T);
+ unsigned nc = boost::connected_components(G, &components[0]);
+
+ std::vector<unsigned> 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<uint64_t> 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 <<std::fixed<< ns_old[i] + ns[i] << " ";
+ }
+
+ std::string filename_S = "nS_" + std::to_string(δ) + "_" + std::to_string(T) + ".dat";
+
+ std::ifstream outfile_S(filename_S);
+
+ std::vector<uint64_t> 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 <<std::fixed<< nS_old[i] + nS[i] << " ";
+ }
+
+ return 0;
+}
+
+
diff --git a/pcg-cpp b/pcg-cpp
new file mode 160000
+Subproject 5b5cac8d61339e810c5dbb4692d868a1d7ca1b2
diff --git a/randutils b/randutils
new file mode 160000
+Subproject 8486a610a954a8248c12485fb4cfc390a5f5f85