Browse Source

a first version of sparse model hashing

main
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) { std::ostream& operator<<(std::ostream& out, ItemLabeling const& labeling) {
labeling.printLabelingInformationToStream(out); labeling.printLabelingInformationToStream(out);
return out; return out;

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

@ -121,6 +121,9 @@ namespace storm {
void permuteItems(std::vector<uint64_t> const& inversePermutation); void permuteItems(std::vector<uint64_t> const& inversePermutation);
virtual std::size_t hash() const;
/*! /*!
* Prints information about the labeling to the specified stream. * 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->printModelInformationHeaderToStream(out);
this->printModelInformationFooterToStream(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> template<typename ValueType, typename RewardModelType>
void Model<ValueType, RewardModelType>::printModelInformationHeaderToStream(std::ostream& out) const { 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 hasParameters() const override;
virtual bool isExact() const override; virtual bool isExact() const override;
virtual std::size_t hash() const;
protected: protected:
RewardModelType & rewardModel(std::string const& rewardModelName); RewardModelType & rewardModel(std::string const& rewardModelName);

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

@ -399,6 +399,21 @@ namespace storm {
return true; 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> template <typename ValueType>
std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueType> const& rewardModel) { std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueType> const& rewardModel) {
out << std::boolalpha << "reward model [state reward: " 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 * @param nrChoices The number of choices in the model
*/ */
bool isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const; bool isCompatible(uint_fast64_t nrStates, uint_fast64_t nrChoices) const;
std::size_t hash() const;
template <typename ValueTypePrime> template <typename ValueTypePrime>
friend std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueTypePrime> const& rewardModel); 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; storm::models::sparse::ChoiceLabeling toChoiceLabeling() const;
virtual std::size_t hash() const = 0;
protected: protected:
ChoiceOrigins(std::vector<uint_fast64_t> const& indexToIdentifierMapping); ChoiceOrigins(std::vector<uint_fast64_t> const& indexToIdentifierMapping);
ChoiceOrigins(std::vector<uint_fast64_t>&& 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)); 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. * 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; EdgeIndexSet const& getEdgeIndexSet(uint_fast64_t choiceIndex) const;
std::size_t hash() const override;
private: private:
/* /*

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

@ -156,6 +156,10 @@ namespace storm {
this->identifierToJson.push_back(std::move(setJson)); 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; CommandSet const& getCommandSet(uint_fast64_t choiceIndex) const;
std::size_t hash() const override;
protected: protected:
/* /*
* Returns a copy of this object where the mapping of choice indices to origin identifiers is replaced by the given one. * 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 { uint_fast64_t StateValuations::getNumberOfStates() const {
return valuations.size(); return valuations.size();
} }
std::size_t StateValuations::hash() const {
return 0;
}
StateValuations StateValuations::selectStates(storm::storage::BitVector const& selectedStates) const { StateValuations StateValuations::selectStates(storm::storage::BitVector const& selectedStates) const {
return StateValuations(variableToIndexMap, storm::utility::vector::filterVector(valuations, selectedStates)); 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. * 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; StateValuations selectStates(std::vector<storm::storage::sparse::state_type> const& selectedStates) const;
virtual std::size_t hash() const;
private: private:
StateValuations(std::map<storm::expressions::Variable, uint64_t> const& variableToIndexMap, std::vector<StateValuation>&& valuations); StateValuations(std::map<storm::expressions::Variable, uint64_t> const& variableToIndexMap, std::vector<StateValuation>&& valuations);

Loading…
Cancel
Save