From ea2a56ece7518734dd8b7ca8c2d93e3957b5854a Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Mon, 15 Jan 2018 00:19:43 +0100 Subject: [PATCH] Json translation for places and transitions --- .../storage/gspn/GspnJsonExporter.cpp | 71 ++++++++++++++++++- .../storage/gspn/GspnJsonExporter.h | 5 +- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/storm-gspn/storage/gspn/GspnJsonExporter.cpp b/src/storm-gspn/storage/gspn/GspnJsonExporter.cpp index de87952cc..aee23cf00 100644 --- a/src/storm-gspn/storage/gspn/GspnJsonExporter.cpp +++ b/src/storm-gspn/storage/gspn/GspnJsonExporter.cpp @@ -9,16 +9,81 @@ namespace storm { namespace gspn { - size_t GspnJsonExporter::currentId = 0; - void GspnJsonExporter::toStream(storm::gspn::GSPN const& gspn, std::ostream& os) { os << translate(gspn).dump(4) << std::endl; } modernjson::json GspnJsonExporter::translate(storm::gspn::GSPN const& gspn) { modernjson::json jsonGspn; - currentId = 0; + + // Export places + for (const auto &place : gspn.getPlaces()) { + modernjson::json jsonPlace = translatePlace(place); + jsonGspn.push_back(jsonPlace); + } + + // Export immediate transitions + for (const auto &transition : gspn.getImmediateTransitions()) { + modernjson::json jsonImmediateTransition = translateImmediateTransition(transition); + jsonGspn.push_back(jsonImmediateTransition); + } + + // Export timed transitions + for (const auto &transition : gspn.getTimedTransitions()) { + modernjson::json jsonTimedTransition = translateTimedTransition(transition); + jsonGspn.push_back(jsonTimedTransition); + } + return jsonGspn; } + + + modernjson::json GspnJsonExporter::translatePlace(storm::gspn::Place const& place) { + modernjson::json data; + std::stringstream stream; + stream << "p" << place.getID(); + data["id"] = stream.str(); + data["name"] = place.getName(); + data["marking"] = place.getNumberOfInitialTokens(); + + modernjson::json jsonPlace; + jsonPlace["data"] = data; + jsonPlace["group"] = "nodes"; + jsonPlace["classes"] = "place"; + return jsonPlace; + } + + modernjson::json GspnJsonExporter::translateImmediateTransition(storm::gspn::ImmediateTransition const& transition) { + modernjson::json data; + std::stringstream stream; + stream << "i" << transition.getID(); + data["id"] = stream.str(); + data["name"] = transition.getName(); + data["priority"] = transition.getPriority(); + data["weight"] = transition.getWeight(); + + modernjson::json jsonTrans; + jsonTrans["data"] = data; + jsonTrans["group"] = "nodes"; + jsonTrans["classes"] = "trans_im"; + return jsonTrans; + } + + modernjson::json GspnJsonExporter::translateTimedTransition(storm::gspn::TimedTransition const& transition) { + modernjson::json data; + std::stringstream stream; + stream << "t" << transition.getID(); + data["id"] = stream.str(); + data["name"] = transition.getName(); + data["rate"] = transition.getRate(); + data["priority"] = transition.getPriority(); + + modernjson::json jsonTrans; + jsonTrans["data"] = data; + jsonTrans["group"] = "nodes"; + jsonTrans["classes"] = "trans_time"; + return jsonTrans; + } + } } diff --git a/src/storm-gspn/storage/gspn/GspnJsonExporter.h b/src/storm-gspn/storage/gspn/GspnJsonExporter.h index 86e0cec01..00b3f19a4 100644 --- a/src/storm-gspn/storage/gspn/GspnJsonExporter.h +++ b/src/storm-gspn/storage/gspn/GspnJsonExporter.h @@ -24,8 +24,11 @@ namespace storm { static modernjson::json translate(storm::gspn::GSPN const& gspn); private: - static size_t currentId; + static modernjson::json translatePlace(storm::gspn::Place const& place); + static modernjson::json translateImmediateTransition(storm::gspn::ImmediateTransition const& transition); + + static modernjson::json translateTimedTransition(storm::gspn::TimedTransition const& transition); }; }