summaryrefslogtreecommitdiff
path: root/uniform.cpp
blob: 07d794e7b49dbbca2376cff4e2202d8e43cf9b0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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;
}