Browse Source

a first version of sparse model hashing

tempestpy_adaptions
Sebastian Junges 5 years ago
parent
commit
2fa2ea1283
  1. 4
      src/storm/models/sparse/ItemLabeling.cpp
  2. 3
      src/storm/models/sparse/ItemLabeling.h
  3. 25
      src/storm/models/sparse/Model.cpp
  4. 2
      src/storm/models/sparse/Model.h
  5. 15
      src/storm/models/sparse/StandardRewardModel.cpp
  6. 2
      src/storm/models/sparse/StandardRewardModel.h
  7. 2
      src/storm/storage/sparse/ChoiceOrigins.h
  8. 4
      src/storm/storage/sparse/JaniChoiceOrigins.cpp
  9. 2
      src/storm/storage/sparse/JaniChoiceOrigins.h
  10. 4
      src/storm/storage/sparse/PrismChoiceOrigins.cpp
  11. 2
      src/storm/storage/sparse/PrismChoiceOrigins.h
  12. 4
      src/storm/storage/sparse/StateValuations.cpp
  13. 3
      src/storm/storage/sparse/StateValuations.h

4
src/storm/models/sparse/ItemLabeling.cpp

@ -201,6 +201,10 @@ namespace storm {
}
}
std::size_t ItemLabeling::hash() const {
return 0;
}
std::ostream& operator<<(std::ostream& out, ItemLabeling const& labeling) {
labeling.printLabelingInformationToStream(out);
return out;

3
src/storm/models/sparse/ItemLabeling.h

@ -121,6 +121,9 @@ namespace storm {
void permuteItems(std::vector<uint64_t> const& inversePermutation);
virtual std::size_t hash() const;
/*!
* Prints information about the labeling to the specified stream.
*

25
src/storm/models/sparse/Model.cpp

@ -298,6 +298,31 @@ namespace storm {
this->printModelInformationHeaderToStream(out);
this->printModelInformationFooterToStream(out);
}
template<typename ValueType, typename RewardModelType>
std::size_t Model<ValueType, RewardModelType>::hash() const {
// if set, retrieves for each state the variable valuation that this state represents
boost::optional<storm::storage::sparse::StateValuations> stateValuations;
// if set, gives information about where each choice originates w.r.t. the input model description
boost::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> choiceOrigins;
std::size_t seed = 0;
boost::hash_combine(seed,transitionMatrix.hash());
boost::hash_combine(seed,stateLabeling.hash());
for (auto const& rewModel : rewardModels) {
boost::hash_combine(seed,rewModel.second.hash());
}
if(choiceLabeling) {
boost::hash_combine(seed,choiceLabeling->hash());
}
if(stateValuations) {
boost::hash_combine(seed,stateValuations->hash());
}
if(choiceOrigins) {
boost::hash_combine(seed,choiceOrigins.get()->hash());
}
}
template<typename ValueType, typename RewardModelType>
void Model<ValueType, RewardModelType>::printModelInformationHeaderToStream(std::ostream& out) const {

2
src/storm/models/sparse/Model.h

@ -358,6 +358,8 @@ namespace storm {
virtual bool hasParameters() const override;
virtual bool isExact() const override;
virtual std::size_t hash() const;
protected:
RewardModelType & rewardModel(std::string const& rewardModelName);

15
src/storm/models/sparse/StandardRewardModel.cpp

@ -399,6 +399,21 @@ namespace storm {
return true;
}
template<typename ValueType>
std::size_t StandardRewardModel<ValueType>::hash() const {
size_t seed = 0;
if(hasStateRewards()) {
boost::hash_combine(seed, boost::hash_range(optionalStateRewardVector->begin(), optionalStateRewardVector->end()));
}
if (hasStateActionRewards()) {
boost::hash_combine(seed, boost::hash_range(optionalStateActionRewardVector->begin(), optionalStateActionRewardVector->end()));
}
if (hasTransitionRewards()) {
boost::hash_combine(seed, optionalTransitionRewardMatrix->hash());
}
return seed;
}
template <typename ValueType>
std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueType> const& rewardModel) {
out << std::boolalpha << "reward model [state reward: "

2
src/storm/models/sparse/StandardRewardModel.h

@ -313,6 +313,8 @@ namespace storm {
* @param nrChoices The number of choices in the model
*/
bool isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const;
std::size_t hash() const;
template <typename ValueTypePrime>
friend std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueTypePrime> const& rewardModel);

2
src/storm/storage/sparse/ChoiceOrigins.h

@ -93,6 +93,8 @@ namespace storm {
storm::models::sparse::ChoiceLabeling toChoiceLabeling() const;
virtual std::size_t hash() const = 0;
protected:
ChoiceOrigins(std::vector<uint_fast64_t> const& indexToIdentifierMapping);
ChoiceOrigins(std::vector<uint_fast64_t>&& indexToIdentifierMapping);

4
src/storm/storage/sparse/JaniChoiceOrigins.cpp

@ -79,6 +79,10 @@ namespace storm {
this->identifierToJson.push_back(std::move(setJson));
}
}
std::size_t JaniChoiceOrigins::hash() const {
return 0;
}
}
}
}

2
src/storm/storage/sparse/JaniChoiceOrigins.h

@ -47,6 +47,8 @@ namespace storm {
* The edges set is represented by a set of indices that encode an automaton index and its local edge index.
*/
EdgeIndexSet const& getEdgeIndexSet(uint_fast64_t choiceIndex) const;
std::size_t hash() const override;
private:
/*

4
src/storm/storage/sparse/PrismChoiceOrigins.cpp

@ -156,6 +156,10 @@ namespace storm {
this->identifierToJson.push_back(std::move(setJson));
}
}
std::size_t PrismChoiceOrigins::hash() const {
return 0;
}
}
}
}

2
src/storm/storage/sparse/PrismChoiceOrigins.h

@ -51,6 +51,8 @@ namespace storm {
*/
CommandSet const& getCommandSet(uint_fast64_t choiceIndex) const;
std::size_t hash() const override;
protected:
/*
* Returns a copy of this object where the mapping of choice indices to origin identifiers is replaced by the given one.

4
src/storm/storage/sparse/StateValuations.cpp

@ -182,6 +182,10 @@ namespace storm {
uint_fast64_t StateValuations::getNumberOfStates() const {
return valuations.size();
}
std::size_t StateValuations::hash() const {
return 0;
}
StateValuations StateValuations::selectStates(storm::storage::BitVector const& selectedStates) const {
return StateValuations(variableToIndexMap, storm::utility::vector::filterVector(valuations, selectedStates));

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

@ -75,7 +75,8 @@ namespace storm {
* If an invalid state index is selected, the corresponding valuation will be empty.
*/
StateValuations selectStates(std::vector<storm::storage::sparse::state_type> const& selectedStates) const;
virtual std::size_t hash() const;
private:
StateValuations(std::map<storm::expressions::Variable, uint64_t> const& variableToIndexMap, std::vector<StateValuation>&& valuations);

Loading…
Cancel
Save