diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-10-10 21:45:32 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-10-10 21:45:32 -0400 |
commit | a43ff1f98e9b9814f858bccb11c174b418458491 (patch) | |
tree | ae7e094d914eddb8a1ae9548420ba8c2f329ffae /lib/src | |
parent | 6e264d243f0b29d90e90b605b6cdeab8227129c9 (diff) | |
download | c++-a43ff1f98e9b9814f858bccb11c174b418458491.tar.gz c++-a43ff1f98e9b9814f858bccb11c174b418458491.tar.bz2 c++-a43ff1f98e9b9814f858bccb11c174b418458491.zip |
big rearrangement of files to make libraries and example (research) files clearer, and changed to c++ std lib random numbers
Diffstat (limited to 'lib/src')
-rw-r--r-- | lib/src/graph.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp new file mode 100644 index 0000000..4043413 --- /dev/null +++ b/lib/src/graph.cpp @@ -0,0 +1,44 @@ + +#include <wolff/graph.hpp> + +graph_t::graph_t(D_t D, L_t L) { + nv = pow(L, D); + ne = D * nv; + + v_adj.resize(nv); + coordinate.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++) { + coordinate[i].resize(D); + for (D_t j = 0; j < D; j++) { + coordinate[i][j] = (i / (v_t)pow(L, D - j - 1)) % L; + + 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); + coordinate.resize(nv + 1); + v_adj[nv].reserve(nv); + + for (v_t i = 0; i < nv; i++) { + v_adj[nv].push_back(i); + } + + coordinate[nv].resize(coordinate[0].size()); + + ne += nv; + nv += 1; +} + |