diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-10-10 14:31:51 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-10-10 14:31:51 +0200 |
commit | b2451666ef1aec1aadc7bb54458f04542b4b7ccb (patch) | |
tree | 3eb28d20fc537041352d9327ad414b5c34ec9e43 | |
parent | 4824391250150840717c1609c99ff8c234c76665 (diff) | |
download | code-b2451666ef1aec1aadc7bb54458f04542b4b7ccb.tar.gz code-b2451666ef1aec1aadc7bb54458f04542b4b7ccb.tar.bz2 code-b2451666ef1aec1aadc7bb54458f04542b4b7ccb.zip |
Started implementation of Propp algorithm.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | uniform.cpp | 97 |
2 files changed, 101 insertions, 1 deletions
@@ -9,7 +9,10 @@ CXX = clang++ LD = ld.lld
LIBS := -lrt
-all: excitation order
+all: excitation order uniform
+
+uniform: uniform.cpp $(BLOSSOM_DIR)/blossom5.o
+ $(CXX) $(CFLAGS) $(BLOSSOM_DIR)/blossom5.o uniform.cpp -o $@
order: order.cpp $(BLOSSOM_DIR)/blossom5.o
$(CXX) $(CFLAGS) $(BLOSSOM_DIR)/blossom5.o order.cpp -o $@
diff --git a/uniform.cpp b/uniform.cpp new file mode 100644 index 0000000..07d794e --- /dev/null +++ b/uniform.cpp @@ -0,0 +1,97 @@ +#include <functional> +#include <iostream> +#include <fstream> +#include <list> + +#include <cmath> + +#include "randutils/randutils.hpp" +#include "pcg-cpp/include/pcg_random.hpp" + +using Rng = randutils::random_generator<pcg32>; + +class Edge { +public: + unsigned index; + std::list<double> weights; + double probability; + + Edge() { + probability = 0; + } +}; + +class Face { +public: + std::array<std::reference_wrapper<Edge>, 4> edges; + + Face(Edge& a, Edge& b, Edge& c, Edge& d) : edges({a, b, c, d}) {} +}; + +class AztecDiamond { +public: + std::vector<Edge> edges; + std::vector<std::vector<Face>> faces; + + AztecDiamond(unsigned n) : edges(pow(2 * n, 2)), faces(n) { + for (unsigned i = 0; i < edges.size(); i++) { + edges[i].index = i; + } + for (unsigned i = 1; i <= n; i++) { + faces[i - 1].reserve(pow(i, 2)); + for (unsigned j = 0; j < pow(i, 2); j++) { + unsigned x = j % (i); + unsigned y = j / (i); + unsigned x0 = n - i; + unsigned y0 = n - i; + faces[i - 1].push_back(Face( + edges[2 * n * (y0 + 2 * y) + x0 + 2 * x], + edges[2 * n * (y0 + 2 * y) + x0 + 2 * x + 1], + edges[2 * n * (y0 + 2 * y + 1) + x0 + 2 * x], + edges[2 * n * (y0 + 2 * y + 1) + x0 + 2 * x + 1] + )); + } + } + } +}; + +int main(int argc, char* argv[]) { + unsigned n = 100; + unsigned m = 100; + + int opt; + + while ((opt = getopt(argc, argv, "n:m:")) != -1) { + switch (opt) { + case 'n': + n = atoi(optarg); + break; + case 'm': + m = (unsigned)atof(optarg); + break; + default: + exit(1); + } + } + + Rng r; + AztecDiamond a(n); + + + + /* For checking if the faces are appropriately defined. + for (std::vector<Face>& fs : a.faces) { + for (Face& f : fs) { + for (Edge& e : f.edges) { + unsigned v1 = (1 + (e.index % (2 * n))) / 2 + (n + 1) * ((e.index / 4) / n); + unsigned v2 = n * (n + 1) + (e.index % (2 * n)) / 2 + n * (((e.index + 2 * n) / 4) / n); + + std::cout << v1 << " " << v2 << " "; + } + } + std::cout << std::endl; + } + */ + + return 0; +} |