summaryrefslogtreecommitdiff
path: root/uniform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'uniform.cpp')
-rw-r--r--uniform.cpp48
1 files changed, 33 insertions, 15 deletions
diff --git a/uniform.cpp b/uniform.cpp
index 53fd60b..474399b 100644
--- a/uniform.cpp
+++ b/uniform.cpp
@@ -1,22 +1,20 @@
#include <functional>
-#include <iostream>
+#include <fstream>
#include <stack>
-#include "randutils/randutils.hpp"
-#include "pcg-cpp/include/pcg_random.hpp"
+#include "rbmp.hpp"
-using Rng = randutils::random_generator<pcg32>;
using Real = long double;
-typedef struct Edge {
- std::stack<Real> weights;
- Real probability = 0;
-} Edge;
-
-using Face = std::array<std::reference_wrapper<Edge>, 4>;
-
class AztecDiamond {
public:
+ typedef struct Edge {
+ std::stack<Real> weights;
+ Real probability = 0;
+ } Edge;
+
+ using Face = std::array<std::reference_wrapper<Edge>, 4>;
+
std::vector<Edge> edges;
std::vector<std::vector<Face>> lattices;
@@ -112,13 +110,16 @@ int main(int argc, char* argv[]) {
}
}
+ std::string filename = "order_" + std::to_string(n) + "_" + std::to_string(T) + ".dat";
+ std::ifstream input(filename);
+
Rng r;
AztecDiamond a(n);
std::vector<Real> avgProbabilities(a.edges.size());
for (unsigned i = 0; i < m; i++) {
- for (Edge& e : a.edges) {
+ for (AztecDiamond::Edge& e : a.edges) {
e.weights.push(exp(- r.variate<Real, std::exponential_distribution>(1) / T));
e.probability = 0;
}
@@ -130,11 +131,28 @@ int main(int argc, char* argv[]) {
}
}
+ Graph G(n, r);
- for (Real& x : avgProbabilities) {
- std::cout << x << " ";
+ std::vector<Real> data_x(G.vertices.size());
+ std::vector<Real> data_y(G.vertices.size());
+
+ for (unsigned i = 0; i < G.edges.size(); i++) {
+ const Edge& e = G.edges[i];
+ const Vertex& vt = e.halfedges[0].getTail();
+ const Vertex& vh = e.halfedges[0].getHead();
+ data_x[vt.index] += avgProbabilities[i] * (vt.coordinate[0] - vh.coordinate[0]);
+ data_y[vt.index] += avgProbabilities[i] * (vt.coordinate[1] - vh.coordinate[1]);
+ data_x[vh.index] += avgProbabilities[i] * (vt.coordinate[0] - vh.coordinate[0]);
+ data_y[vh.index] += avgProbabilities[i] * (vt.coordinate[1] - vh.coordinate[1]);
}
- std::cout << std::endl;
+
+ std::ofstream output(filename);
+
+ for (unsigned i = 0; i < G.vertices.size(); i++) {
+ output << data_x[i] << " " << data_y[i] << std::endl;
+ }
+
+ output.close();
return 0;
}