diff options
Diffstat (limited to 'lib/src/network.cpp')
-rw-r--r-- | lib/src/network.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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) {} |