Browse Source

Added Export of state valuations to JSON

tempestpy_adaptions
Tim Quatmann 5 years ago
parent
commit
42be5537ae
  1. 17
      src/storm/storage/expressions/SimpleValuation.cpp
  2. 4
      src/storm/storage/expressions/SimpleValuation.h

17
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) { std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation) {
out << valuation.toString(false) << std::endl; out << valuation.toString(false) << std::endl;
return out; return out;

4
src/storm/storage/expressions/SimpleValuation.h

@ -6,6 +6,7 @@
#include <set> #include <set>
#include "storm/storage/expressions/Valuation.h" #include "storm/storage/expressions/Valuation.h"
#include "storm/adapters/JsonAdapter.h"
namespace storm { namespace storm {
namespace expressions { namespace expressions {
@ -17,6 +18,8 @@ namespace storm {
public: public:
friend class SimpleValuationPointerHash; friend class SimpleValuationPointerHash;
friend class SimpleValuationPointerLess; friend class SimpleValuationPointerLess;
typedef storm::json<double> Json;
/*! /*!
* Creates an empty simple valuation that is associated to no manager and has no variables. * 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<storm::expressions::Variable> const& selectedVariables) const; virtual std::string toPrettyString(std::set<storm::expressions::Variable> const& selectedVariables) const;
virtual std::string toString(bool pretty = true) const; virtual std::string toString(bool pretty = true) const;
Json toJson() const;
friend std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation); friend std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation);

Loading…
Cancel
Save