summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2022-10-10 18:47:09 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2022-10-10 18:47:09 +0200
commit3961d9c977933192c39c456d7a5b2e0f4acb174a (patch)
treeb559b2542196d23b7522ddc5cd9074b1f37c8139
parent9c2a77d4cc668a9d5fc25d7bd15ad8a34ac90d34 (diff)
downloadcode-3961d9c977933192c39c456d7a5b2e0f4acb174a.tar.gz
code-3961d9c977933192c39c456d7a5b2e0f4acb174a.tar.bz2
code-3961d9c977933192c39c456d7a5b2e0f4acb174a.zip
Output data in style used previously.
-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;
}