From 42be5537ae761391ba269453d27b4a4c62614d83 Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Thu, 9 Apr 2020 21:11:41 +0200 Subject: [PATCH] Added Export of state valuations to JSON --- .../storage/expressions/SimpleValuation.cpp | 17 +++++++++++++++++ src/storm/storage/expressions/SimpleValuation.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/storm/storage/expressions/SimpleValuation.cpp b/src/storm/storage/expressions/SimpleValuation.cpp index e60556305..4ed71239a 100644 --- a/src/storm/storage/expressions/SimpleValuation.cpp +++ b/src/storm/storage/expressions/SimpleValuation.cpp @@ -144,6 +144,23 @@ namespace storm { } } + typename SimpleValuation::Json SimpleValuation::toJson() const { + Json result; + for (auto const& variable : getManager()) { + if (variable.second.isBooleanType()) { + result[variable.first.getName()] = this->getBooleanValue(variable.first); + } else if (variable.second.isIntegerType()) { + result[variable.first.getName()] = this->getIntegerValue(variable.first); + } else if (variable.second.isRationalType()) { + result[variable.first.getName()] = this->getRationalValue(variable.first); + } else { + STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "Unexpected variable type."); + } + } + return result; + } + + std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation) { out << valuation.toString(false) << std::endl; return out; diff --git a/src/storm/storage/expressions/SimpleValuation.h b/src/storm/storage/expressions/SimpleValuation.h index 3936ed546..b0569ff1f 100644 --- a/src/storm/storage/expressions/SimpleValuation.h +++ b/src/storm/storage/expressions/SimpleValuation.h @@ -6,6 +6,7 @@ #include #include "storm/storage/expressions/Valuation.h" +#include "storm/adapters/JsonAdapter.h" namespace storm { namespace expressions { @@ -17,6 +18,8 @@ namespace storm { public: friend class SimpleValuationPointerHash; friend class SimpleValuationPointerLess; + typedef storm::json Json; + /*! * Creates an empty simple valuation that is associated to no manager and has no variables. @@ -63,6 +66,7 @@ namespace storm { virtual std::string toPrettyString(std::set const& selectedVariables) const; virtual std::string toString(bool pretty = true) const; + Json toJson() const; friend std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation);