summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/include/graph.hpp43
-rw-r--r--lib/src/graph.cpp30
-rw-r--r--lib/src/problem.cpp12
3 files changed, 69 insertions, 16 deletions
diff --git a/lib/include/graph.hpp b/lib/include/graph.hpp
index c78fe9f..5ad4c8b 100644
--- a/lib/include/graph.hpp
+++ b/lib/include/graph.hpp
@@ -13,13 +13,44 @@
#include "array_hash.hpp"
-class graph {
+class coordinate {
public:
- typedef struct coordinate {
- double x;
- double y;
- } coordinate;
+ double x;
+ double y;
+
+ coordinate operator+(const coordinate& r) const {
+ coordinate rp = {0, 0};
+ rp.x = x + r.x;
+ rp.y = y + r.y;
+
+ return rp;
+ }
+
+ template <class T>
+ coordinate operator*(const T& a) const {
+ coordinate rp = *this;
+ rp.x *= a;
+ rp.y *= a;
+ return rp;
+ }
+
+ coordinate operator-(const coordinate& r) const {
+ coordinate rp = *this;
+ return rp + (r * -1);
+ }
+
+ coordinate operator-() const {
+ return *this * -1;
+ }
+ void operator+=(const coordinate& r) {
+ x += r.x;
+ y += r.y;
+ }
+};
+
+class graph {
+public:
typedef struct vertex {
coordinate r;
std::vector<unsigned> nd;
@@ -49,4 +80,6 @@ public:
graph const rotate();
std::string write() const;
+
+ coordinate Δr(unsigned e) const;
};
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp
index c75d466..1c770e9 100644
--- a/lib/src/graph.cpp
+++ b/lib/src/graph.cpp
@@ -445,14 +445,14 @@ void graph::helper(unsigned nv, std::mt19937& rng) {
jcv_diagram_free(&diagram);
}
-graph::coordinate reverse(const graph::coordinate& x) { return {x.y, x.x}; }
+coordinate reverse(const coordinate& x) { return {x.y, x.x}; }
graph const graph::rotate() {
graph g2(*this);
for (graph::vertex& v : g2.vertices) {
v.r = reverse(v.r);
- for (graph::coordinate& r : v.polygon) {
+ for (coordinate& r : v.polygon) {
r = reverse(r);
}
}
@@ -464,7 +464,7 @@ graph const graph::rotate() {
for (graph::vertex& v : g2.dual_vertices) {
v.r = reverse(v.r);
- for (graph::coordinate& r : v.polygon) {
+ for (coordinate& r : v.polygon) {
r = reverse(r);
}
}
@@ -490,7 +490,7 @@ std::string graph::write() const {
output += "},\"vp\"->{";
for (const graph::vertex &v : vertices) {
output += "{";
- for (const graph::coordinate &r : v.polygon) {
+ for (const coordinate &r : v.polygon) {
output += "{" + std::to_string(r.x) + "," + std::to_string(r.y) + "},";
}
output.pop_back();
@@ -505,7 +505,7 @@ std::string graph::write() const {
output += "},\"up\"->{";
for (const graph::vertex &v : dual_vertices) {
output += "{";
- for (const graph::coordinate &r : v.polygon) {
+ for (const coordinate &r : v.polygon) {
output += "{" + std::to_string(r.x) + "," + std::to_string(r.y) + "},";
}
output.pop_back();
@@ -536,3 +536,23 @@ std::string graph::write() const {
return output;
}
+
+coordinate graph::Δr(unsigned e) const {
+ coordinate tmp = dual_vertices[dual_edges[e].v[1]].r - dual_vertices[dual_edges[e].v[0]].r;
+ if (dual_edges[e].crossings[0]) {
+ if (tmp.x > 0) {
+ tmp.x -= L.x;
+ } else {
+ tmp.x += L.x;
+ }
+ }
+ if (dual_edges[e].crossings[1]) {
+ if (tmp.y > 0) {
+ tmp.y -= L.y;
+ } else {
+ tmp.y += L.y;
+ }
+ }
+
+ return tmp;
+}
diff --git a/lib/src/problem.cpp b/lib/src/problem.cpp
index ab87b0c..a029d66 100644
--- a/lib/src/problem.cpp
+++ b/lib/src/problem.cpp
@@ -9,8 +9,8 @@ problem::problem(const graph& G, unsigned axis, cholmod_sparse* vcmat, cholmod_c
: G(G), axis(axis), voltcurmat(vcmat), c(c) {
b = CHOL_F(zeros)(G.vertices.size(), 1, CHOLMOD_REAL, c);
for (unsigned i = 0; i < G.edges.size(); i++) {
- graph::coordinate v0 = G.vertices[G.edges[i].v[0]].r;
- graph::coordinate v1 = G.vertices[G.edges[i].v[1]].r;
+ coordinate v0 = G.vertices[G.edges[i].v[0]].r;
+ coordinate v1 = G.vertices[G.edges[i].v[1]].r;
if (G.edges[i].crossings[axis]) {
bool ind;
@@ -131,8 +131,8 @@ void problem::solve(std::vector<bool>& fuses) {
} else {
sol.currents[i] = ((double*)y->x)[i];
- graph::coordinate v0 = G.vertices[G.edges[i].v[0]].r;
- graph::coordinate v1 = G.vertices[G.edges[i].v[1]].r;
+ coordinate v0 = G.vertices[G.edges[i].v[0]].r;
+ coordinate v1 = G.vertices[G.edges[i].v[1]].r;
if (G.edges[i].crossings[axis]) {
bool comp;
@@ -196,8 +196,8 @@ void problem::break_edge(unsigned e, bool unbreak) {
CHOL_F(free_sparse)(&perm_update_mat, c);
CHOL_F(free_sparse)(&update_mat, c);
- graph::coordinate r0 = G.vertices[v0].r;
- graph::coordinate r1 = G.vertices[v1].r;
+ coordinate r0 = G.vertices[v0].r;
+ coordinate r1 = G.vertices[v1].r;
if (G.edges[e].crossings[axis]) {
bool ind;