From 70b13f405bf861dd16e0ddb963293e5546599b3d Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 25 Jun 2021 10:57:46 +0200 Subject: Partial progress towards merging BM model into global objects. --- biroli-mezard.cpp | 178 ++++++------------------------------------------------ 1 file changed, 18 insertions(+), 160 deletions(-) (limited to 'biroli-mezard.cpp') diff --git a/biroli-mezard.cpp b/biroli-mezard.cpp index e2fb71a..5b6213f 100644 --- a/biroli-mezard.cpp +++ b/biroli-mezard.cpp @@ -1,149 +1,30 @@ #include #include -#include -#include -#include -#include -#include #include -#include - -#include "pcg-cpp/include/pcg_random.hpp" -#include "randutils/randutils.hpp" - -using Rng = randutils::random_generator; - -template using Vector = Eigen::Matrix; -template using Matrix = Eigen::Matrix; +#include "glass.hpp" const unsigned Empty = std::numeric_limits::max(); -int iPow(int x, unsigned p) { - if (p == 0) - return 1; - if (p == 1) - return x; - - int tmp = iPow(x, p / 2); - if (p % 2 == 0) - return tmp * tmp; - else - return x * tmp * tmp; -} - -unsigned mod(signed a, unsigned b) { return ((a < 0) ? (a + (1 - a / (signed)b) * b) : a) % b; } - -template Vector mod(const Eigen::MatrixBase& v, unsigned b) { - Vector u; - for (unsigned i = 0; i < D; i++) { - u(i) = mod(v(i), b); - } - return u; -} - -template void one_sequences(std::list>& sequences, unsigned level) { - if (level > 0) { - unsigned new_level = level - 1; - for (std::array& sequence : sequences) { - std::array new_sequence = sequence; - new_sequence[new_level] = -1; - sequences.push_front(new_sequence); - } - one_sequences(sequences, new_level); - } -} - -template std::vector> generateTorusMatrices() { - std::vector> mats; - - std::array ini_sequence; - ini_sequence.fill(1); - std::list> sequences; - sequences.push_back(ini_sequence); - - one_sequences(sequences, D); - - sequences.pop_back(); // don't want the identity matrix! - - for (std::array sequence : sequences) { - Matrix m; - for (unsigned i = 0; i < D; i++) { - for (unsigned j = 0; j < D; j++) { - if (i == j) { - m(i, j) = sequence[i]; - } else { - m(i, j) = 0; - } - } - } - - mats.push_back(m); - } - - for (unsigned i = 0; i < D; i++) { - for (unsigned j = 0; j < D; j++) { - if (i != j) { - Matrix m; - for (unsigned k = 0; k < D; k++) { - for (unsigned l = 0; l < D; l++) { - if ((k == i && l == j) || (k == j && l == i)) { - if (i < j) { - m(k, l) = 1; - } else { - m(k, l) = -1; - } - } else if (k == l && (k != i && k != j)) { - m(k, l) = 1; - } else { - m(k, l) = 0; - } - } - } - mats.push_back(m); - } - } - } - - return mats; -} - -template class Transformation { +class BiroliState { public: - unsigned L; - Matrix m; - Vector v; - - Transformation(unsigned L) : L(L) { - m.setIdentity(); - v.setZero(); - } - - Transformation(unsigned L, const Matrix& m, const Vector& v) : L(L), m(m), v(v) {} - - Transformation(unsigned L, const std::vector>& ms, Rng& r) : m(r.pick(ms)), L(L) { - for (unsigned i = 0; i < D; i++) { - v[i] = r.uniform((unsigned)0, L - 1); - } + unsigned maximumNeighbors; + unsigned occupiedNeighbors; - v = v - m * v; + BiroliState() { + maximumNeighbors = Empty; + occupiedNeighbors = 0; } - Transformation inverse() const { - return Transformation(L, m.transpose(), -m.transpose() * v); + bool empty() const { return maximumNeighbors == Empty; } + bool frustrated() const { return occupiedNeighbors > maximumNeighbors; } + bool operator==(const BiroliState& s) const { + return s.maximumNeighbors == maximumNeighbors; } - - Vector apply(const Vector& x) const { return mod(v + m * x, L); } - - Transformation apply(const Transformation& t) const { - Transformation tNew(L); - - tNew.m = m * t.m; - tNew.v = apply(t.v); - - return tNew; + void remove() { + maximumNeighbors = Empty; } -}; +} template class Vertex { public: @@ -156,8 +37,6 @@ public: bool visited; Vertex() { - occupiedNeighbors = 0; - maximumNeighbors = Empty; marked = false; } @@ -179,20 +58,15 @@ public: } }; -template class System { +template class BiroliSystem : public HardSystem { public: - const unsigned L; std::vector N; - std::unordered_set*> occupants; - std::vector> vertices; - Transformation orientation; - - unsigned size() const { return vertices.size(); } + std::unordered_set*> occupants; unsigned types() const { return N.size() - 1; } unsigned occupancy() const { - return size() - N[0]; + return BiroliSystem::size() - N[0]; } double density() const { return (double)occupancy() / size(); } @@ -217,23 +91,7 @@ public: return true; } - unsigned vectorToIndex(const Vector& x) const { - unsigned i = 0; - for (unsigned d = 0; d < D; d++) { - i += x[d] * iPow(L, d); - } - return i; - } - - Vector indexToVector(unsigned i) const { - Vector x; - for (unsigned d = 0; d < D; d++) { - x[d] = (i / iPow(L, d)) % L; - } - return x; - } - - System(unsigned L, unsigned T) : L(L), N(T + 1, 0), vertices(iPow(L, D)), orientation(L) { + BiroliSystem(unsigned L, unsigned T) : L(L), N(T + 1, 0), vertices(iPow(L, D)), orientation(L) { N[0] = size(); for (unsigned i = 0; i < size(); i++) { -- cgit v1.2.3-54-g00ecf