diff --git a/cpp/graph_ecm.hpp b/cpp/graph_ecm.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4cb88c77b6d42f3485e74eb1605d321aaf9939ba --- /dev/null +++ b/cpp/graph_ecm.hpp @@ -0,0 +1,31 @@ +#include "graph.hpp" +#include +#include +#include +#include + +template +bool erasedConfigurationModel(DegreeSequence &ds, Graph &g, RNG &rng) { + // List of all half-edges + std::vector halfEdges; + for (unsigned int i = 0; i < ds.size(); ++i) + halfEdges.insert(halfEdges.end(), ds[i], i); + + // Clear the graph + g.reset(ds.size()); + + if (halfEdges.size() % 2 != 0) + return false; + + std::shuffle(halfEdges.begin(), halfEdges.end(), rng); + // pair halfEdges[2*i] with halfEdges[2*i+1] + for (auto iter = halfEdges.begin(); iter != halfEdges.end();) { + auto u = *iter++; + auto v = *iter++; + if (u != v) + g.addEdge({u, v}); // checks for double edges + } + + return true; +} +