#include #include #include #include #include #include "pcg-cpp/include/pcg_random.hpp" #include "randutils/randutils.hpp" using Rng = randutils::random_generator; class ClusterTree { private: std::vector p; std::vector o; unsigned findroot(unsigned i) { if (p[i] < 0) return i; else return p[i] = this->findroot(p[i]); } void join(unsigned i, unsigned j) { if (o[i] < o[j]) { p[i] = j; o[j] += o[i]; } else { p[j] = i; o[i] += o[j]; } } public: ClusterTree(unsigned n) : p(n, -1), o(n, 1) {} void add_bond(unsigned v0, unsigned v1) { unsigned i = this->findroot(v0); unsigned j = this->findroot(v1); if (i != j) { this->join(i, j); } } bool same_component(unsigned v0, unsigned v1) { unsigned i = this->findroot(v0); unsigned j = this->findroot(v1); return i == j; } signed pointer(unsigned i) const { return p[i]; } unsigned size(unsigned i) const { return o[i]; } }; 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++) { ClusterTree G(T); for (unsigned t = 0; t < T; t++) { if (rng.uniform(0.0, 1.0) < δ) { G.add_bond(rng.uniform(0, t), rng.uniform(0, t)); } } unsigned maxSize = 0; for (unsigned j = 0; j < T; j++) { if (G.pointer(j) < 0) { ns[G.size(j) - 1]++; if (G.size(j) > maxSize) { maxSize= G.size(j); } } } nS[maxSize - 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 <