Browse Source

Added a Hash Class in the Utility Namespace.

Added a function getHash() which returns a size_t to most of the used Models and Containers.


Former-commit-id: ed52aa3996
main
PBerger 12 years ago
parent
commit
78184f9537
  1. 8
      src/models/AbstractDeterministicModel.h
  2. 18
      src/models/AbstractModel.h
  3. 11
      src/models/AbstractNondeterministicModel.h
  4. 25
      src/models/AtomicPropositionsLabeling.h
  5. 8
      src/models/Ctmc.h
  6. 8
      src/models/Ctmdp.h
  7. 8
      src/models/Dtmc.h
  8. 7
      src/models/Mdp.h
  9. 19
      src/storage/BitVector.h
  10. 20
      src/storage/SparseMatrix.h
  11. 25
      src/utility/Hash.h

8
src/models/AbstractDeterministicModel.h

@ -78,6 +78,14 @@ class AbstractDeterministicModel: public AbstractModel<T> {
virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorEnd(uint_fast64_t state) const {
return this->transitionMatrix.constColumnIteratorEnd(state);
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual std::size_t getHash() const override {
return AbstractModel::getHash();
}
virtual void writeDotToStream(std::ostream& outStream, bool includeLabeling = true, storm::storage::BitVector const* subsystem = nullptr, std::vector<T> const* firstValue = nullptr, std::vector<T> const* secondValue = nullptr, std::vector<uint_fast64_t> const* stateColoring = nullptr, std::vector<std::string> const* colors = nullptr, std::vector<uint_fast64_t>* scheduler = nullptr, bool finalizeOutput = true) const override {
AbstractModel<T>::writeDotToStream(outStream, includeLabeling, subsystem, firstValue, secondValue, stateColoring, colors, scheduler, false);

18
src/models/AbstractModel.h

@ -4,6 +4,7 @@
#include "src/models/AtomicPropositionsLabeling.h"
#include "src/storage/BitVector.h"
#include "src/storage/SparseMatrix.h"
#include "src/utility/Hash.h"
#include <memory>
#include <vector>
@ -377,6 +378,23 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
out << "-------------------------------------------------------------- " << std::endl;
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual size_t getHash() const {
std::size_t result = 0;
boost::hash_combine(result, transitionMatrix.getHash());
boost::hash_combine(result, stateLabeling.getHash());
if (stateRewardVector) {
boost::hash_combine(result, storm::utility::Hash<T>::getHash(stateRewardVector.get()));
}
if (transitionRewardMatrix) {
boost::hash_combine(result, transitionRewardMatrix.get().getHash());
}
return result;
}
protected:
/*!
* Exports the model to the dot-format and prints the result to the given stream.

11
src/models/AbstractNondeterministicModel.h

@ -126,6 +126,17 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
return this->transitionMatrix.constColumnIteratorEnd(nondeterministicChoiceIndices[state + 1] - 1);
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual size_t getHash() const override {
std::size_t result = 0;
boost::hash_combine(result, AbstractModel::getHash());
boost::hash_combine(result, storm::utility::Hash<uint_fast64_t>::getHash(nondeterministicChoiceIndices));
return result;
}
virtual void writeDotToStream(std::ostream& outStream, bool includeLabeling = true, storm::storage::BitVector const* subsystem = nullptr, std::vector<T> const* firstValue = nullptr, std::vector<T> const* secondValue = nullptr, std::vector<uint_fast64_t> const* stateColoring = nullptr, std::vector<std::string> const* colors = nullptr, std::vector<uint_fast64_t>* scheduler = nullptr, bool finalizeOutput = true) const override {
AbstractModel<T>::writeDotToStream(outStream, includeLabeling, subsystem, firstValue, secondValue, stateColoring, colors, scheduler, false);

25
src/models/AtomicPropositionsLabeling.h

@ -15,6 +15,8 @@
#include <unordered_map>
#include <set>
#include "src/utility/Hash.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
@ -234,6 +236,29 @@ public:
return this->nameToLabelingMap;
}
/*!
* Calculates a hash over all values contained in this Sparse Matrix.
* @return size_t A Hash Value
*/
std::size_t getHash() const {
std::size_t result = 0;
boost::hash_combine(result, stateCount);
boost::hash_combine(result, apCountMax);
boost::hash_combine(result, apsCurrent);
for (auto it = nameToLabelingMap.begin(); it != nameToLabelingMap.end(); ++it) {
boost::hash_combine(result, it->first);
boost::hash_combine(result, it->second);
}
for (auto it = singleLabelings.begin(); it != singleLabelings.end(); ++it) {
boost::hash_combine(result, it->getHash());
}
return result;
}
private:
/*! The number of states whose labels are to be stored by this object. */

8
src/models/Ctmc.h

@ -72,6 +72,14 @@ public:
storm::models::ModelType getType() const {
return CTMC;
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual std::size_t getHash() const override {
return AbstractDeterministicModel::getHash();
}
};
} // namespace models

8
src/models/Ctmdp.h

@ -103,6 +103,14 @@ public:
return CTMDP;
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual std::size_t getHash() const override {
return AbstractNondeterministicModel::getHash();
}
private:
/*!

8
src/models/Dtmc.h

@ -109,6 +109,14 @@ public:
return DTMC;
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual std::size_t getHash() const override {
return AbstractDeterministicModel::getHash();
}
private:
/*!
* @brief Perform some sanity checks.

7
src/models/Mdp.h

@ -105,6 +105,13 @@ public:
return MDP;
}
/*!
* Calculates a hash over all values contained in this Model.
* @return size_t A Hash Value
*/
virtual std::size_t getHash() const override {
return AbstractNondeterministicModel::getHash();
}
private:
/*!

19
src/storage/BitVector.h

@ -11,6 +11,7 @@
#include "src/exceptions/OutOfRangeException.h"
#include "src/utility/OsDetection.h"
#include "src/utility/Hash.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
@ -80,6 +81,7 @@ public:
bool operator!=(const constIndexIterator& rhs) const {
return currentIndex != rhs.currentIndex;
}
private:
/*! The bit vector to search for set bits. */
@ -628,6 +630,23 @@ public:
return result.str();
}
/*!
* Calculates a hash over all values contained in this Sparse Matrix.
* @return size_t A Hash Value
*/
std::size_t getHash() const {
std::size_t result = 0;
boost::hash_combine(result, bucketCount);
boost::hash_combine(result, bitCount);
for (uint_fast64_t i = 0; i < bucketCount; ++i) {
boost::hash_combine(result, bucketArray[i]);
}
return result;
}
private:
/*!

20
src/storage/SparseMatrix.h

@ -17,6 +17,7 @@
#include "src/storage/JacobiDecomposition.h"
#include "src/utility/ConstTemplates.h"
#include "src/utility/Hash.h"
#include "Eigen/Sparse"
#include "gmm/gmm_matrix.h"
@ -1232,6 +1233,25 @@ public:
return result.str();
}
/*!
* Calculates a hash over all values contained in this Sparse Matrix.
* @return size_t A Hash Value
*/
std::size_t getHash() const {
std::size_t result = 0;
boost::hash_combine(result, rowCount);
boost::hash_combine(result, colCount);
boost::hash_combine(result, nonZeroEntryCount);
boost::hash_combine(result, currentSize);
boost::hash_combine(result, lastRow);
boost::hash_combine(result, storm::utility::Hash<T>::getHash(valueStorage));
boost::hash_combine(result, storm::utility::Hash<uint_fast64_t>::getHash(columnIndications));
boost::hash_combine(result, storm::utility::Hash<uint_fast64_t>::getHash(rowIndications));
return result;
}
private:
/*!

25
src/utility/Hash.h

@ -0,0 +1,25 @@
#ifndef STORM_UTILITY_HASH_H_
#define STORM_UTILITY_HASH_H_
#include <boost/functional/hash.hpp>
#include <functional>
#include <vector>
namespace storm {
namespace utility {
template<class T>
class Hash {
public:
static std::size_t getHash(std::vector<T> const& target) {
return boost::hash_range(target.begin(), target.end());
}
private:
Hash() {}
~Hash() {}
};
}
}
#endif // STORM_UTILITY_HASH_H_
Loading…
Cancel
Save