diff --git a/cpp/switchchain.cpp b/cpp/switchchain.cpp index 559d9fa4814dbd2f820d3479cb823654384822fc..23d96eda05bceffb77cd0a7ed52c0f6a575ae204 100644 --- a/cpp/switchchain.cpp +++ b/cpp/switchchain.cpp @@ -36,21 +36,17 @@ class SwitchChain { } bool doMove() { - Edge e1, e2; int e1index, e2index; int timeout = 0; // Keep regenerating while conflicting edges do { e1index = edgeDistribution(mt); e2index = edgeDistribution(mt); - e1 = g.getEdge(e1index); - e2 = g.getEdge(e2index); - ++timeout; - if (timeout % 100 == 0) { + if (++timeout % 100 == 0) { std::cerr << "Warning: sampled " << timeout << " random edges but they keep conflicting.\n"; } - } while (edgeConflicts(e1, e2)); + } 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) @@ -117,12 +113,10 @@ int main() { std::cout << "Running n = " << numVertices << ", tau = " << tau << ". \t" << std::flush; - constexpr int mixingTime = 40000; - constexpr int measureTime = 20000; + int mixingTime = (32.0f - 26.0f*(tau - 2.0f)) * numVertices; //40000; + constexpr int measurements = 50; constexpr int measureSkip = 200; // Take a sample every ... steps - constexpr int measurements = - (measureTime - 1) / measureSkip + 1; int movesDone = 0; int triangles[measurements]; @@ -131,15 +125,18 @@ int main() { if (chain.doMove()) ++movesDone; } - for (int i = 0; i < measureTime; ++i) { - if (chain.doMove()) - ++movesDone; - if (i % measureSkip == 0) - triangles[i / measureSkip] = chain.g.countTriangles(); + for (int i = 0; i < measurements; ++i) { + for (int j = 0; j < measureSkip; ++j) + if (chain.doMove()) + ++movesDone; + triangles[i] = chain.g.countTriangles(); } - std::cout << movesDone << '/' << mixingTime + measureTime - << " moves succeeded." << std::endl; + std::cout << movesDone << '/' << mixingTime + measurements * measureSkip + << " moves succeeded (" + << 100.0f * float(movesDone) / + float(mixingTime + measurements * measureSkip) + << "%)." << std::endl; if (outputComma) outfile << ',';