diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-11-06 13:55:38 -0500 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-11-06 13:55:38 -0500 |
commit | 19d657b60b22159359f7a229f5a5b73e729cff79 (patch) | |
tree | f0dc1df96e26bdbe3f49032d396a9efe36a3c5df /lib | |
parent | ba4a31df421ff47de1f8c3dc86daea2cacd942ed (diff) | |
download | fuse_networks-19d657b60b22159359f7a229f5a5b73e729cff79.tar.gz fuse_networks-19d657b60b22159359f7a229f5a5b73e729cff79.tar.bz2 fuse_networks-19d657b60b22159359f7a229f5a5b73e729cff79.zip |
added support for saving networks to the library and revamped the sample method
Diffstat (limited to 'lib')
-rw-r--r-- | lib/include/graph.hpp | 3 | ||||
-rw-r--r-- | lib/include/network.hpp | 3 | ||||
-rw-r--r-- | lib/src/graph.cpp | 59 | ||||
-rw-r--r-- | lib/src/network.cpp | 37 |
4 files changed, 102 insertions, 0 deletions
diff --git a/lib/include/graph.hpp b/lib/include/graph.hpp index 9d2b5a1..c78fe9f 100644 --- a/lib/include/graph.hpp +++ b/lib/include/graph.hpp @@ -7,6 +7,7 @@ #include <exception> #include <list> #include <random> +#include <string> #include <unordered_map> #include <vector> @@ -46,4 +47,6 @@ public: void helper(unsigned n, std::mt19937& rng); graph const rotate(); + + std::string write() const; }; diff --git a/lib/include/network.hpp b/lib/include/network.hpp index 5b474bb..d562530 100644 --- a/lib/include/network.hpp +++ b/lib/include/network.hpp @@ -5,6 +5,7 @@ #include <limits> #include <random> #include <set> +#include <string> #include <utility> #include <valarray> #include <vector> @@ -66,6 +67,8 @@ public: current_info empty; return empty; }; + + std::string write(); }; class fuse_network : public network { diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp index 1475c40..c75d466 100644 --- a/lib/src/graph.cpp +++ b/lib/src/graph.cpp @@ -1,6 +1,7 @@ #include "graph.hpp" #include <cstring> +#include <sstream> #define JC_VORONOI_IMPLEMENTATION #define JCV_REAL_TYPE double @@ -477,3 +478,61 @@ graph const graph::rotate() { return g2; } + +std::string graph::write() const { + std::string output; + + output += "\"vr\"->{"; + for (const graph::vertex &v : vertices) { + output += "{" + std::to_string(v.r.x) + "," + std::to_string(v.r.y) + "},"; + } + output.pop_back(); + output += "},\"vp\"->{"; + for (const graph::vertex &v : vertices) { + output += "{"; + for (const graph::coordinate &r : v.polygon) { + output += "{" + std::to_string(r.x) + "," + std::to_string(r.y) + "},"; + } + output.pop_back(); + output += "},"; + } + output.pop_back(); + output += "},\"ur\"->{"; + for (const graph::vertex &v : dual_vertices) { + output += "{" + std::to_string(v.r.x) + "," + std::to_string(v.r.y) + "},"; + } + output.pop_back(); + output += "},\"up\"->{"; + for (const graph::vertex &v : dual_vertices) { + output += "{"; + for (const graph::coordinate &r : v.polygon) { + output += "{" + std::to_string(r.x) + "," + std::to_string(r.y) + "},"; + } + output.pop_back(); + output += "},"; + } + output.pop_back(); + output += "},\"e\"->{"; + for (const graph::edge &e : edges) { + output += "{" + std::to_string(e.v[0]) + "," + std::to_string(e.v[1]) + "},"; + } + output.pop_back(); + output += "},\"ec\"->{"; + for (const graph::edge &e : edges) { + output += "{" + std::to_string(e.crossings[0]) + "," + std::to_string(e.crossings[1]) + "},"; + } + output.pop_back(); + output += "},\"d\"->{"; + for (const graph::edge &e : dual_edges) { + output += "{" + std::to_string(e.v[0]) + "," + std::to_string(e.v[1]) + "},"; + } + output.pop_back(); + output += "},\"dc\"->{"; + for (const graph::edge &e : dual_edges) { + output += "{" + std::to_string(e.crossings[0]) + "," + std::to_string(e.crossings[1]) + "},"; + } + output.pop_back(); + output += "}"; + + return output; +} diff --git a/lib/src/network.cpp b/lib/src/network.cpp index 05fc0dd..561796b 100644 --- a/lib/src/network.cpp +++ b/lib/src/network.cpp @@ -1,5 +1,6 @@ #include "network.hpp" +#include <sstream> class nofuseException : public std::exception { virtual const char* what() const throw() { return "No valid fuse was available to break."; } @@ -511,6 +512,42 @@ void network::break_edge(unsigned e, bool unbreak) { py.break_edge(e, unbreak); } +std::string network::write() { + std::string output; + + current_info c = this->get_current_info(); + + output += "\"fuses\"->{"; + for (unsigned i = 0; i < G.edges.size(); i++) { + if (!fuses[i]) { + output += std::to_string(i) +","; + } + } + output.pop_back(); + output += "},\"backbone\"->{"; + for (unsigned i = 0; i < G.edges.size(); i++) { + if (!backbone[i]) { + output += std::to_string(i) + ","; + } + } + output.pop_back(); + output += "},\"thresholds\"->{"; + for (const long double& t : thresholds) { + output += std::to_string(t) + ","; + } + output.pop_back(); + output += "},\"conductivity\"->{" + std::to_string(c.conductivity[0]) + "," + std::to_string(c.conductivity[1]); + output += "},\"currents\"->{"; + for (const double& t : c.currents) { + output += std::to_string(t) + ","; + } + output.pop_back(); + output += "}," + G.write(); + + return output; +}; + + fuse_network::fuse_network(const graph& G, cholmod_common* c, double weight) : network(G, c), weight(weight) {} |