From df9c0050b37c2669a1f70a019a397816eeae6b2d Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 22 Mar 2021 21:40:19 +0100 Subject: Fixed Ciamarra model. --- ciamarra.cpp | 7 +++++-- glass.hpp | 38 ++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ciamarra.cpp b/ciamarra.cpp index 8449cbb..6b932bf 100644 --- a/ciamarra.cpp +++ b/ciamarra.cpp @@ -58,6 +58,9 @@ int main() { } std::cerr << "Found state with appropriate density." << std::endl; + if (!s.compatible()) { + std::cerr <<"whoops!" << std::endl; + } CiamarraSystem s0 = s; @@ -69,9 +72,9 @@ int main() { n++; std::cout << i << " " << s.overlap(s0) << std::endl; } - s.sweepLocal(r); +// s.sweepLocal(r); // s.sweepSwap(r); -// s.swendsenWang(Transformation(L, ms, r), r); + s.swendsenWang(Transformation(L, ms, r), r); } return 0; diff --git a/glass.hpp b/glass.hpp index da06542..e67bb51 100644 --- a/glass.hpp +++ b/glass.hpp @@ -38,7 +38,6 @@ template Vector mod(const Eigen::MatrixBase void one_sequences(std::list>& sequences, unsigned level) { if (level > 0) { unsigned new_level = level - 1; - unsigned old_length = sequences.size(); for (std::array& sequence : sequences) { std::array new_sequence = sequence; new_sequence[new_level] = -1; @@ -254,15 +253,17 @@ public: virtual bool remove(Vertex& v) { return false;}; - virtual bool tryRandomMove(Rng& r) { return false;}; + virtual bool randomMove(Rng& r) { return false;}; - virtual bool swap(Vertex& v1, Vertex& v2) { return false;}; + virtual void swap(Vertex& v1, Vertex& v2) {}; - bool tryRandomSwap(Rng& r) { + virtual bool exchange(Vertex& v1, Vertex& v2) { return false;}; + + bool randomExchange(Rng& r) { Vertex& v1 = r.pick(vertices); Vertex& v2 = r.pick(vertices); - return swap(v1, v2); + return exchange(v1, v2); } bool compatible() { @@ -302,19 +303,19 @@ public: } } - tryRandomMove(r); + randomMove(r); } } void sweepLocal(Rng& r) { for (unsigned i = 0; i < iPow(L, D); i++) { - tryRandomMove(r); + randomMove(r); } } void sweepSwap(Rng& r) { for (unsigned i = 0; i < iPow(L, D); i++) { - tryRandomSwap(r); + randomExchange(r); } } @@ -329,14 +330,13 @@ public: q.pop(); if (!v.marked) { - Vector xNew = R.apply(v.position); - Vertex& vNew = vertices[vectorToIndex(xNew)]; + Vertex& vNew = vertices[vectorToIndex(R.apply(v.position))]; v.marked = true; vNew.marked = true; - CiamarraState s = R.apply(v.state); - CiamarraState sNew = R.apply(vNew.state); + State s = R.apply(v.state); + State sNew = R.apply(vNew.state); std::list>> overlaps1 = overlaps(vNew, s, true); std::list>> overlaps2 = overlaps(v, sNew, true); @@ -350,6 +350,8 @@ public: if (!dry) { swap(v, vNew); + v.state = sNew; + vNew.state = s; } n += 1; @@ -364,7 +366,7 @@ public: if (!v.marked) { bool dry = 0.5 < r.uniform(0.0, 1.0); unsigned n = flipCluster(R, v, r, dry); - if (n > pow(L, D) / 4 && !dry) { + if (n > size() / 4 && !dry) { orientation = R.apply(orientation); } } @@ -426,7 +428,7 @@ template class CiamarraSystem : public System> { } } - bool tryRandomMove(Rng& r) override { + bool randomMove(Rng& r) override { Vertex>& v = r.pick(this->vertices); CiamarraState oldState = v.state; @@ -457,9 +459,13 @@ template class CiamarraSystem : public System> { return false; } - bool swap(Vertex>& v1, Vertex>& v2) override { + void swap(Vertex>& v1, Vertex>& v2) override { + std::swap(v1.state, v2.state); + } + + bool exchange(Vertex>& v1, Vertex>& v2) override { if (overlaps(v1, v2.state, true).size() == 0 && overlaps(v2, v1.state, true).size() == 0) { - std::swap(v1.state, v2.state); + swap(v1, v2); return true; } else { return false; -- cgit v1.2.3-70-g09d2