Files
@ ea18a7bd1a0d
Branch filter:
Location: AENC/switchchain/cpp/graph_powerlaw.hpp - annotation
ea18a7bd1a0d
1.4 KiB
text/x-c++hdr
Plot log version of exponential fit for mixing time
c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d a410aaa16af7 c9c22e41130d a410aaa16af7 c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 a410aaa16af7 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 | #pragma once
#include "graph.hpp"
#include "powerlaw.hpp"
#include <algorithm>
#include <iostream>
template <typename RNG>
void generatePowerlawGraph(int n, float tau, Graph& g, DegreeSequence& ds,
RNG& rng) {
ds.resize(n);
powerlaw_distribution degDist(tau, 1, n);
// Generate a graph
// might require multiple tries
for (int i = 1;; ++i) {
std::generate(ds.begin(), ds.end(),
[°Dist, &rng] { return degDist(rng); });
// First check if the sum is even
unsigned int sum = std::accumulate(ds.begin(), ds.end(), 0);
if (sum % 2)
continue;
if (g.createFromDegreeSequence(ds))
break;
// When 10 tries have not worked, output a warning
if (i % 10 == 0) {
std::cerr << "Warning: could not create graph from "
"degree sequence. Trying again...\n";
}
}
}
void generateCanonicalPowerlawGraph(int n, float tau, Graph &g,
DegreeSequence &ds) {
ds.resize(n);
powerlaw_distribution degDist(tau, 1, n);
degDist.getFixedDistribution(n, ds.begin());
unsigned int sum = std::accumulate(ds.begin(), ds.end(), 0);
if (sum % 2)
ds.back()++;
if (g.createFromDegreeSequence(ds))
return;
g.reset(n);
std::cerr << "ERROR: Canonical ds is not graphical" << std::endl;
}
|