From b2451666ef1aec1aadc7bb54458f04542b4b7ccb Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 10 Oct 2022 14:31:51 +0200 Subject: Started implementation of Propp algorithm. --- Makefile | 5 +++- uniform.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 uniform.cpp diff --git a/Makefile b/Makefile index 84be93f..33c8b6c 100644 --- a/Makefile +++ b/Makefile @@ -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 +#include +#include +#include + +#include + +#include "randutils/randutils.hpp" +#include "pcg-cpp/include/pcg_random.hpp" + +using Rng = randutils::random_generator; + +class Edge { +public: + unsigned index; + std::list weights; + double probability; + + Edge() { + probability = 0; + } +}; + +class Face { +public: + std::array, 4> edges; + + Face(Edge& a, Edge& b, Edge& c, Edge& d) : edges({a, b, c, d}) {} +}; + +class AztecDiamond { +public: + std::vector edges; + std::vector> 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& 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; +} -- cgit v1.2.3-70-g09d2