summaryrefslogtreecommitdiff
path: root/uniform.cpp
blob: 1e8ae7d18a881de3597ce7009b3ccaf06d78ef26 (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
98
99
100
101
#include <fstream>

#include "aztec.hpp"

int main(int argc, char* argv[]) {
  unsigned n = 100;
  unsigned m = 100;
  Real T = 1;

  int opt;

  while ((opt = getopt(argc, argv, "n:m:T:")) != -1) {
    switch (opt) {
    case 'n':
      n = atoi(optarg);
      break;
    case 'm':
      m = (unsigned)atof(optarg);
      break;
    case 'T':
      T = atof(optarg);
      break;
    default:
      exit(1);
    }
  }

  std::string filename = "order_" + std::to_string(n) + "_" + std::to_string(T) + ".dat";

  Rng r;
  AztecDiamond a(n);

  std::vector<Real> avgProbabilities(a.edges.size());

  for (unsigned i = 0; i < m; i++) {
    a.setWeights(r);
    a.computeWeights(T);
    a.computeProbabilities();

    for (unsigned j = 0; j < a.edges.size(); j++) {
      avgProbabilities[j] += a.edges[j].probability;
    }
  }

  std::vector<Real> data_x(a.vertices.size());
  std::vector<Real> data_y(a.vertices.size());

  for (unsigned i = 0; i < a.edges.size(); i++) {
    const AztecDiamond::Edge& e = a.edges[i];
    const AztecDiamond::Vertex& vt = *e.tail;
    const AztecDiamond::Vertex& vh = *e.head;
    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::ofstream output(filename);

  for (unsigned i = 0; i < a.vertices.size(); i++) {
    output << data_x[i] << " " << data_y[i] << std::endl;
  }

  output.close();

  std::vector<long int> data_x0(a.vertices.size());
  std::vector<long int> data_y0(a.vertices.size());

  PerfectMatching pm(a.vertices.size(), a.edges.size());

  for (const AztecDiamond::Edge& e : a.edges) {
    pm.AddEdge(e.head->index, e.tail->index, e.weight);
  }

  pm.options.verbose = false;
  pm.Solve();

  for (unsigned i = 0; i < a.vertices.size() / 2; i++) {
    unsigned j = pm.GetMatch(i);

    data_x0[i] += a.vertices[i].coordinate[0];
    data_y0[i] += a.vertices[i].coordinate[1];
    data_x0[i] -= a.vertices[j].coordinate[0];
    data_y0[i] -= a.vertices[j].coordinate[1];

    data_x0[j] += a.vertices[i].coordinate[0];
    data_y0[j] += a.vertices[i].coordinate[1];
    data_x0[j] -= a.vertices[j].coordinate[0];
    data_y0[j] -= a.vertices[j].coordinate[1];
  }

  std::ofstream output2("order_0.dat");

  for (unsigned i = 0; i < a.vertices.size(); i++) {
    output2 << data_x0[i] << " " << data_y0[i] << std::endl;
  }

  output.close();

  return 0;
}