diff --git a/cpp/switchchain_dsp.cpp b/cpp/switchchain_dsp.cpp index 268504b74542a89f3b293d016b0335c7511d9f3f..e7b052a0827d70c0d93e8499e01c935d770d18ae 100644 --- a/cpp/switchchain_dsp.cpp +++ b/cpp/switchchain_dsp.cpp @@ -1,6 +1,7 @@ #include "exports.hpp" #include "graph.hpp" #include "powerlaw.hpp" +#include "switchchain.hpp" #include #include #include @@ -8,61 +9,6 @@ #include #include -// Its assumed that u,v are distinct. -// Check if all four vertices are distinct -bool edgeConflicts(const Edge& e1, const Edge& e2) { - return (e1.u == e2.u || e1.u == e2.v || e1.v == e2.u || e1.v == e2.v); -} - -class SwitchChain { - public: - SwitchChain() - : mt(std::random_device{}()), permutationDistribution(0.5) - // permutationDistribution(0, 2) - { - // random_device uses hardware entropy if available - // std::random_device rd; - // mt.seed(rd()); - } - ~SwitchChain() {} - - bool initialize(const Graph& gstart) { - if (gstart.edgeCount() == 0) - return false; - g = gstart; - edgeDistribution.param( - std::uniform_int_distribution<>::param_type(0, g.edgeCount() - 1)); - return true; - } - - bool doMove() { - int e1index, e2index; - int timeout = 0; - // Keep regenerating while conflicting edges - do { - e1index = edgeDistribution(mt); - e2index = edgeDistribution(mt); - if (++timeout % 100 == 0) { - std::cerr << "Warning: sampled " << timeout - << " random edges but they keep conflicting.\n"; - } - } while (edgeConflicts(g.getEdge(e1index), g.getEdge(e2index))); - - // Consider one of the three possible permutations - // 1) e1.u - e1.v and e2.u - e2.v (original) - // 2) e1.u - e2.u and e1.v - e2.v - // 3) e1.u - e2.v and e1.v - e2.u - bool switchType = permutationDistribution(mt); - return g.exchangeEdges(e1index, e2index, switchType); - } - - Graph g; - std::mt19937 mt; - std::uniform_int_distribution<> edgeDistribution; - //std::uniform_int_distribution<> permutationDistribution; - std::bernoulli_distribution permutationDistribution; -}; - double getProperty(const DegreeSequence& ds) { std::vector> vals(ds.size()); for (auto& v : vals) { @@ -104,8 +50,6 @@ int main() { float tauValues[] = {2.1f, 2.5f, 2.9f}; Graph g; - Graph g1; - Graph g2; std::ofstream outfile("graphdata_dsp.m"); outfile << '{';