summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2022-10-10 18:01:31 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2022-10-10 18:01:31 +0200
commit9c2a77d4cc668a9d5fc25d7bd15ad8a34ac90d34 (patch)
tree14aa847399b9c9bcc7ec54d7aa1bb025f441fc22
parentbbc27302fa9ae20de0650154d5d479860cf000de (diff)
downloadcode-9c2a77d4cc668a9d5fc25d7bd15ad8a34ac90d34.tar.gz
code-9c2a77d4cc668a9d5fc25d7bd15ad8a34ac90d34.tar.bz2
code-9c2a77d4cc668a9d5fc25d7bd15ad8a34ac90d34.zip
Changed weight structure to a stack.
-rw-r--r--uniform.cpp37
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();