From 9c2a77d4cc668a9d5fc25d7bd15ad8a34ac90d34 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 10 Oct 2022 18:01:31 +0200 Subject: Changed weight structure to a stack. --- uniform.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'uniform.cpp') diff --git a/uniform.cpp b/uniform.cpp index c7d6367..53fd60b 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -1,7 +1,6 @@ #include #include -#include -#include +#include #include "randutils/randutils.hpp" #include "pcg-cpp/include/pcg_random.hpp" @@ -10,7 +9,7 @@ using Rng = randutils::random_generator; using Real = long double; typedef struct Edge { - std::list weights; + std::stack weights; Real probability = 0; } Edge; @@ -41,27 +40,27 @@ public: void computeWeights() { for (std::vector& faces : lattices) { for (Face& f : faces) { - Real w = f[0].get().weights.back(); - Real x = f[1].get().weights.back(); - Real y = f[2].get().weights.back(); - Real z = f[3].get().weights.back(); + Real w = f[0].get().weights.top(); + Real x = f[1].get().weights.top(); + Real y = f[2].get().weights.top(); + Real z = f[3].get().weights.top(); Real cellFactor = w * z + x * y; - f[0].get().weights.push_back(z / cellFactor); - f[1].get().weights.push_back(y / cellFactor); - f[2].get().weights.push_back(x / cellFactor); - f[3].get().weights.push_back(w / cellFactor); + f[0].get().weights.push(z / cellFactor); + f[1].get().weights.push(y / cellFactor); + f[2].get().weights.push(x / cellFactor); + f[3].get().weights.push(w / cellFactor); } } // This process computes one extra weight per edge. for (Edge& e : edges) { - e.weights.pop_back(); + e.weights.pop(); } } - void computeProbabilities() { + void computeProbabilities() { // destroys *all* weights for (auto it = lattices.rbegin(); it != lattices.rend(); it++) { for (Face& f : *it) { Real p = f[0].get().probability; @@ -69,10 +68,10 @@ public: Real r = f[2].get().probability; Real s = f[3].get().probability; - Real w = f[0].get().weights.back(); - Real x = f[1].get().weights.back(); - Real y = f[2].get().weights.back(); - Real z = f[3].get().weights.back(); + Real w = f[0].get().weights.top(); + Real x = f[1].get().weights.top(); + Real y = f[2].get().weights.top(); + Real z = f[3].get().weights.top(); Real cellFactor = w * z + x * y; Real deficit = 1 - p - q - r - s; @@ -83,7 +82,7 @@ public: f[3].get().probability = p + deficit * w * z / cellFactor; for (Edge& e : f) { - e.weights.pop_back(); + e.weights.pop(); } } } @@ -120,7 +119,7 @@ int main(int argc, char* argv[]) { for (unsigned i = 0; i < m; i++) { for (Edge& e : a.edges) { - e.weights = {exp(- r.variate(1) / T)}; + e.weights.push(exp(- r.variate(1) / T)); e.probability = 0; } a.computeWeights(); -- cgit v1.2.3-70-g09d2