-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobservable.cpp
More file actions
157 lines (125 loc) · 4.35 KB
/
observable.cpp
File metadata and controls
157 lines (125 loc) · 4.35 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2021 Joren Brunekreef, Daniel Nemeth and Andrzej Görlich
#include <iostream>
#include <fstream>
#include <vector>
#include "observable.hpp"
std::default_random_engine Observable::rng(0); // TODO(JorenB): seed properly
std::string Observable::data_dir = "";
std::vector<bool> Observable::doneL;
void Observable::write() {
std::string filename = data_dir + "/" + name + "-" + identifier + extension;
std::ifstream infile(filename);
std::ofstream file;
file.open(filename, std::ios::app);
assert(file.is_open());
file << output << "\n";
file.close();
}
void Observable::clear() {
std::string filename = data_dir + "/" + name + "-" + identifier + extension;
std::ofstream file;
file.open(filename, std::ios::app);
assert(file.is_open());
file.close();
initialize();
}
std::vector<Vertex::Label> Observable::sphere(Vertex::Label origin, int radius) {
std::vector<Vertex::Label> thisDepth;
std::vector<Vertex::Label> nextDepth;
std::vector<Vertex::Label> vertexList;
std::vector<Vertex::Label> flippedVertices;
doneL.at(origin) = true;
thisDepth.push_back(origin);
flippedVertices.push_back(origin);
for (int currentDepth = 0; currentDepth < radius; currentDepth++) {
for (auto v : thisDepth) {
for (auto neighbor : Universe::vertexNeighbors[v]) {
if (!doneL.at(neighbor)) {
flippedVertices.push_back(neighbor);
nextDepth.push_back(neighbor);
doneL.at(neighbor) = true;
if(currentDepth == radius-1) vertexList.push_back(neighbor);
}
}
}
thisDepth = nextDepth;
nextDepth.clear();
}
for (auto v : flippedVertices) {
doneL.at(v) = false;
}
return vertexList;
}
std::vector<Vertex::Label> Observable::sphere2d(Vertex::Label origin, int radius) {
std::vector<Vertex::Label> thisDepth;
std::vector<Vertex::Label> nextDepth;
std::vector<Vertex::Label> vertexList;
std::vector<Vertex::Label> flippedVertices;
doneL.at(origin) = true;
thisDepth.push_back(origin);
flippedVertices.push_back(origin);
for (int currentDepth = 0; currentDepth < radius; currentDepth++) {
for (auto v : thisDepth) {
for (auto neighbor : Universe::vertexNeighbors[v]) {
if (neighbor->time != origin->time) continue;
if (!doneL.at(neighbor)) {
flippedVertices.push_back(neighbor);
nextDepth.push_back(neighbor);
doneL.at(neighbor) = true;
if(currentDepth == radius-1) vertexList.push_back(neighbor);
}
}
}
thisDepth = nextDepth;
nextDepth.clear();
}
for (auto v : flippedVertices) {
doneL.at(v) = false;
}
return vertexList;
}
std::vector<Tetra::Label> Observable::sphereDual(Tetra::Label origin, int radius) {
// TODO(JorenB): optimize BFS (see sphere())
std::vector<Tetra::Label> done;
std::vector<Tetra::Label> thisDepth;
std::vector<Tetra::Label> nextDepth;
done.push_back(origin);
thisDepth.push_back(origin);
std::vector<Tetra::Label> tetraList;
for (int currentDepth = 0; currentDepth < radius; currentDepth++) {
for (auto t : thisDepth) {
for (auto neighbor : t->tnbr) {
if (std::find(done.begin(), done.end(), neighbor) == done.end()) {
nextDepth.push_back(neighbor);
done.push_back(neighbor);
if (currentDepth == radius - 1) tetraList.push_back(neighbor);
}
}
}
thisDepth = nextDepth;
nextDepth.clear();
}
return tetraList;
}
std::vector<Triangle::Label> Observable::sphere2dDual(Triangle::Label origin, int radius) {
std::vector<Triangle::Label> done;
std::vector<Triangle::Label> thisDepth;
std::vector<Triangle::Label> nextDepth;
done.push_back(origin);
thisDepth.push_back(origin);
std::vector<Triangle::Label> triangleList;
for (int currentDepth = 0; currentDepth < radius; currentDepth++) {
for (auto t : thisDepth) {
for (auto neighbor : t->trnbr) {
if (std::find(done.begin(), done.end(), neighbor) == done.end()) {
nextDepth.push_back(neighbor);
done.push_back(neighbor);
if (currentDepth == radius - 1) triangleList.push_back(neighbor);
}
}
}
thisDepth = nextDepth;
nextDepth.clear();
}
return triangleList;
}