Browse Source

StateValuations::toJson now has a template parameter to change the exported type of rationals.

main
Tim Quatmann 4 years ago
parent
commit
84e6984659
  1. 2
      src/storm/storage/Scheduler.cpp
  2. 11
      src/storm/storage/sparse/StateValuations.cpp
  3. 5
      src/storm/storage/sparse/StateValuations.h

2
src/storm/storage/Scheduler.cpp

@ -241,7 +241,7 @@ namespace storm {
} }
storm::json<storm::RationalNumber> stateChoicesJson; storm::json<storm::RationalNumber> stateChoicesJson;
if (model && model->hasStateValuations()) { if (model && model->hasStateValuations()) {
stateChoicesJson["s"] = model->getStateValuations().toJson(state);
stateChoicesJson["s"] = model->getStateValuations().template toJson<storm::RationalNumber>(state);
} else { } else {
stateChoicesJson["s"] = state; stateChoicesJson["s"] = state;
} }

11
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<std::set<storm::expressions::Variable>> const& selectedVariables) const {
template<typename JsonRationalType>
storm::json<JsonRationalType> StateValuations::toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional<std::set<storm::expressions::Variable>> const& selectedVariables) const {
auto const& valueAssignment = at(stateIndex); auto const& valueAssignment = at(stateIndex);
typename std::set<storm::expressions::Variable>::const_iterator setIt; typename std::set<storm::expressions::Variable>::const_iterator setIt;
if (selectedVariables) { if (selectedVariables) {
setIt = selectedVariables->begin(); setIt = selectedVariables->begin();
} }
Json result;
storm::json<JsonRationalType> result;
for (auto valIt = valueAssignment.begin(); valIt != valueAssignment.end(); ++valIt) { for (auto valIt = valueAssignment.begin(); valIt != valueAssignment.end(); ++valIt) {
if (selectedVariables && (*setIt != valIt.getVariable())) { if (selectedVariables && (*setIt != valIt.getVariable())) {
continue; continue;
@ -215,7 +216,7 @@ namespace storm {
result[valIt.getName()] = valIt.getIntegerValue(); result[valIt.getName()] = valIt.getIntegerValue();
} else { } else {
STORM_LOG_ASSERT(valIt.isRational(), "Unexpected variable type."); STORM_LOG_ASSERT(valIt.isRational(), "Unexpected variable type.");
result[valIt.getName()] = valIt.getRationalValue();
result[valIt.getName()] = storm::utility::convertNumber<JsonRationalType>(valIt.getRationalValue());
} }
if (selectedVariables) { if (selectedVariables) {
@ -358,6 +359,10 @@ namespace storm {
rationalVarCount = 0; rationalVarCount = 0;
labelCount = 0; labelCount = 0;
} }
template storm::json<double> StateValuations::toJson<double>(storm::storage::sparse::state_type const& , boost::optional<std::set<storm::expressions::Variable>> const&) const;
template storm::json<storm::RationalNumber> StateValuations::toJson<storm::RationalNumber>(storm::storage::sparse::state_type const&, boost::optional<std::set<storm::expressions::Variable>> const&) const;
} }
} }
} }

5
src/storm/storage/sparse/StateValuations.h

@ -20,7 +20,6 @@ namespace storm {
class StateValuations : public storm::models::sparse::StateAnnotation { class StateValuations : public storm::models::sparse::StateAnnotation {
public: public:
friend class StateValuationsBuilder; friend class StateValuationsBuilder;
typedef storm::json<storm::RationalNumber> Json;
class StateValuation { class StateValuation {
public: public:
@ -112,8 +111,8 @@ namespace storm {
* @param selectedVariables If given, only the informations for the variables in this set are processed. * @param selectedVariables If given, only the informations for the variables in this set are processed.
* @return * @return
*/ */
Json toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional<std::set<storm::expressions::Variable>> const& selectedVariables = boost::none) const;
template<typename JsonRationalType = storm::RationalNumber>
storm::json<JsonRationalType> toJson(storm::storage::sparse::state_type const& stateIndex, boost::optional<std::set<storm::expressions::Variable>> const& selectedVariables = boost::none) const;
// Returns the (current) number of states that this object describes. // Returns the (current) number of states that this object describes.
uint_fast64_t getNumberOfStates() const; uint_fast64_t getNumberOfStates() const;

Loading…
Cancel
Save