From 19d657b60b22159359f7a229f5a5b73e729cff79 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 6 Nov 2019 13:55:38 -0500 Subject: added support for saving networks to the library and revamped the sample method --- lib/src/network.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/src/network.cpp') 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 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) {} -- cgit v1.2.3-70-g09d2