summaryrefslogtreecommitdiff
path: root/lib/graph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/graph.cpp')
-rw-r--r--lib/graph.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/graph.cpp b/lib/graph.cpp
new file mode 100644
index 0000000..021873d
--- /dev/null
+++ b/lib/graph.cpp
@@ -0,0 +1,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;
+}
+