From 84e6984659e7f126a7a3e658b1de052e69c05859 Mon Sep 17 00:00:00 2001 From: Tim Quatmann Date: Fri, 11 Dec 2020 15:53:55 +0100 Subject: [PATCH] StateValuations::toJson now has a template parameter to change the exported type of rationals. --- src/storm/storage/Scheduler.cpp | 2 +- src/storm/storage/sparse/StateValuations.cpp | 11 ++++++++--- src/storm/storage/sparse/StateValuations.h | 5 ++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/storm/storage/Scheduler.cpp b/src/storm/storage/Scheduler.cpp index 689917f32..59db79429 100644 --- a/src/storm/storage/Scheduler.cpp +++ b/src/storm/storage/Scheduler.cpp @@ -241,7 +241,7 @@ namespace storm { } storm::json stateChoicesJson; if (model && model->hasStateValuations()) { - stateChoicesJson["s"] = model->getStateValuations().toJson(state); + stateChoicesJson["s"] = model->getStateValuations().template toJson(state); } else { stateChoicesJson["s"] = state; } diff --git a/src/storm/storage/sparse/StateValuations.cpp b/src/storm/storage/sparse/StateValuations.cpp index 95cc3368a..68ae39a7d 100644 --- a/src/storm/storage/sparse/StateValuations.cpp +++ b/src/storm/storage/sparse/StateValuations.cpp @@ -197,13 +197,14 @@ namespace storm { } } - typename StateValuations::Json StateValuations::toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional> const& selectedVariables) const { + template + storm::json StateValuations::toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional> const& selectedVariables) const { auto const& valueAssignment = at(stateIndex); typename std::set::const_iterator setIt; if (selectedVariables) { setIt = selectedVariables->begin(); } - Json result; + storm::json result; for (auto valIt = valueAssignment.begin(); valIt != valueAssignment.end(); ++valIt) { if (selectedVariables && (*setIt != valIt.getVariable())) { continue; @@ -215,7 +216,7 @@ namespace storm { result[valIt.getName()] = valIt.getIntegerValue(); } else { STORM_LOG_ASSERT(valIt.isRational(), "Unexpected variable type."); - result[valIt.getName()] = valIt.getRationalValue(); + result[valIt.getName()] = storm::utility::convertNumber(valIt.getRationalValue()); } if (selectedVariables) { @@ -358,6 +359,10 @@ namespace storm { rationalVarCount = 0; labelCount = 0; } + + template storm::json StateValuations::toJson(storm::storage::sparse::state_type const& , boost::optional> const&) const; + template storm::json StateValuations::toJson(storm::storage::sparse::state_type const&, boost::optional> const&) const; + } } } diff --git a/src/storm/storage/sparse/StateValuations.h b/src/storm/storage/sparse/StateValuations.h index ac78ce816..017e449df 100644 --- a/src/storm/storage/sparse/StateValuations.h +++ b/src/storm/storage/sparse/StateValuations.h @@ -20,7 +20,6 @@ namespace storm { class StateValuations : public storm::models::sparse::StateAnnotation { public: friend class StateValuationsBuilder; - typedef storm::json Json; class StateValuation { public: @@ -112,8 +111,8 @@ namespace storm { * @param selectedVariables If given, only the informations for the variables in this set are processed. * @return */ - Json toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional> const& selectedVariables = boost::none) const; - + template + storm::json toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional> const& selectedVariables = boost::none) const; // Returns the (current) number of states that this object describes. uint_fast64_t getNumberOfStates() const;