Browse Source

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

tempestpy_adaptions
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;
if (model && model->hasStateValuations()) {
stateChoicesJson["s"] = model->getStateValuations().toJson(state);
stateChoicesJson["s"] = model->getStateValuations().template toJson<storm::RationalNumber>(state);
} else {
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);
typename std::set<storm::expressions::Variable>::const_iterator setIt;
if (selectedVariables) {
setIt = selectedVariables->begin();
}
Json result;
storm::json<JsonRationalType> 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<JsonRationalType>(valIt.getRationalValue());
}
if (selectedVariables) {
@ -358,6 +359,10 @@ namespace storm {
rationalVarCount = 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 {
public:
friend class StateValuationsBuilder;
typedef storm::json<storm::RationalNumber> 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<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.
uint_fast64_t getNumberOfStates() const;

Loading…
Cancel
Save