diff --git a/cpp/switchchain_exponent.cpp b/cpp/switchchain_exponent.cpp index a862a133c15ed69daaa554f23ea96850a24429a7..85d514b2ab9cbfc5f076c6c835e83996ddb9c59a 100644 --- a/cpp/switchchain_exponent.cpp +++ b/cpp/switchchain_exponent.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; -}; - int main() { // Generate a random degree sequence std::mt19937 rng(std::random_device{}()); @@ -75,8 +21,6 @@ int main() { float tauValues[] = {2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f}; Graph g; - Graph g1; - Graph g2; std::ofstream outfile("graphdata_exponent_hightau.m"); outfile << '{';