diff options
-rw-r--r-- | uniform.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/uniform.cpp b/uniform.cpp index c7d6367..53fd60b 100644 --- a/uniform.cpp +++ b/uniform.cpp @@ -1,7 +1,6 @@ #include <functional> #include <iostream> -#include <list> -#include <ranges> +#include <stack> #include "randutils/randutils.hpp" #include "pcg-cpp/include/pcg_random.hpp" @@ -10,7 +9,7 @@ using Rng = randutils::random_generator<pcg32>; using Real = long double; typedef struct Edge { - std::list<Real> weights; + std::stack<Real> weights; Real probability = 0; } Edge; @@ -41,27 +40,27 @@ public: void computeWeights() { for (std::vector<Face>& 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<Real, std::exponential_distribution>(1) / T)}; + e.weights.push(exp(- r.variate<Real, std::exponential_distribution>(1) / T)); e.probability = 0; } a.computeWeights(); |