blob: 8c972749c09d66d5d59af87b7df1891ceed28619 (
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
|
#include "graph.h"
graph_t::graph_t(D_t D, L_t L) {
nv = pow(L, D);
ne = D * nv;
v_adj.resize(nv);
for (std::vector<v_t> v_adj_i : v_adj) {
v_adj_i.reserve(2 * D);
}
for (v_t i = 0; i < nv; i++) {
for (D_t j = 0; j < D; j++) {
v_adj[i].push_back(pow(L, j + 1) * (i / ((v_t)pow(L, j + 1))) + fmod(i + pow(L, j), pow(L, j + 1)));
v_adj[i].push_back(pow(L, j + 1) * (i / ((v_t)pow(L, j + 1))) + fmod(pow(L, j+1) + i - pow(L, j), pow(L, j + 1)));
}
}
}
void graph_t::add_ext() {
for (std::vector<v_t>& v_adj_i : v_adj) {
v_adj_i.push_back(nv);
}
v_adj.resize(nv + 1);
v_adj[nv].reserve(nv);
for (v_t i = 0; i < nv; i++) {
v_adj[nv].push_back(i);
}
ne += nv;
nv += 1;
}
|