diff --git a/cpp/switchchain_spectrum.cpp b/cpp/switchchain_spectrum.cpp index 5ccf1e5f81447b1789ee6e8c8fb717cbb325db12..e9d8603be10a778cd2facf9c113bf48b65a899dd 100644 --- a/cpp/switchchain_spectrum.cpp +++ b/cpp/switchchain_spectrum.cpp @@ -3,7 +3,7 @@ #include "graph.hpp" #include "graph_gcm.hpp" #include "graph_spectrum.hpp" -#include "powerlaw.hpp" +#include "graph_powerlaw.hpp" #include #include #include @@ -42,37 +42,11 @@ int main(int argc, char* argv[]) { for (int numVertices = 500; numVertices <= 500; numVertices += 1000) { for (float tau : tauValues) { - - DegreeSequence ds(numVertices); - powerlaw_distribution degDist(tau, 1, numVertices); - //std::poisson_distribution<> degDist(12); - // For a single n,tau take samples over several instances of // the degree distribution. - // 500 samples seems to give reasonable results for (int degreeSample = 0; degreeSample < 5; ++degreeSample) { - // Generate a graph - // might require multiple tries - for (int i = 1; ; ++i) { - std::generate(ds.begin(), ds.end(), - [°Dist, &rng] { return degDist(rng); }); - // First make the sum even - unsigned int sum = std::accumulate(ds.begin(), ds.end(), 0); - if (sum % 2) { - continue; - // Can we do this: ?? - ds.back()++; - } - - 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"; - } - } + DegreeSequence ds; + generatePowerlawGraph(numVertices, tau, g, ds, rng); SwitchChain chain; if (!chain.initialize(g)) {