Browse Source

Fix for memory structure product and toString method

tempestpy_adaptions
TimQu 8 years ago
parent
commit
ef90b1b224
  1. 43
      src/storm/storage/memorystructure/MemoryStructure.cpp
  2. 2
      src/storm/storage/memorystructure/MemoryStructure.h

43
src/storm/storage/memorystructure/MemoryStructure.cpp

@ -1,5 +1,7 @@
#include "storm/storage/memorystructure/MemoryStructure.h" #include "storm/storage/memorystructure/MemoryStructure.h"
#include <iostream>
#include "storm/logic/Formulas.h" #include "storm/logic/Formulas.h"
#include "storm/utility/macros.h" #include "storm/utility/macros.h"
#include "storm/storage/memorystructure/SparseModelMemoryProduct.h" #include "storm/storage/memorystructure/SparseModelMemoryProduct.h"
@ -40,12 +42,12 @@ namespace storm {
for (uint_fast64_t lhsState = 0; lhsState < lhsNumStates; ++lhsState) { for (uint_fast64_t lhsState = 0; lhsState < lhsNumStates; ++lhsState) {
for (uint_fast64_t rhsState = 0; rhsState < rhsNumStates; ++rhsState) { for (uint_fast64_t rhsState = 0; rhsState < rhsNumStates; ++rhsState) {
assert (resState == (lhsState * rhsNumStates) + rhsState); assert (resState == (lhsState * rhsNumStates) + rhsState);
auto resStateTransitions = resultTransitions[resState];
auto& resStateTransitions = resultTransitions[resState];
for (uint_fast64_t lhsTransitionTarget = 0; lhsTransitionTarget < lhsNumStates; ++lhsTransitionTarget) { for (uint_fast64_t lhsTransitionTarget = 0; lhsTransitionTarget < lhsNumStates; ++lhsTransitionTarget) {
auto& lhsTransition = this->getTransitionMatrix()[lhsState][lhsTransitionTarget]; auto& lhsTransition = this->getTransitionMatrix()[lhsState][lhsTransitionTarget];
if (lhsTransition) { if (lhsTransition) {
for (uint_fast64_t rhsTransitionTarget = 0; rhsTransitionTarget < rhsNumStates; ++rhsTransitionTarget) { for (uint_fast64_t rhsTransitionTarget = 0; rhsTransitionTarget < rhsNumStates; ++rhsTransitionTarget) {
auto& rhsTransition = this->getTransitionMatrix()[rhsState][rhsTransitionTarget];
auto& rhsTransition = rhs.getTransitionMatrix()[rhsState][rhsTransitionTarget];
if (rhsTransition) { if (rhsTransition) {
uint_fast64_t resTransitionTarget = (lhsTransitionTarget * rhsNumStates) + rhsTransitionTarget; uint_fast64_t resTransitionTarget = (lhsTransitionTarget * rhsNumStates) + rhsTransitionTarget;
resStateTransitions[resTransitionTarget] = std::make_shared<storm::logic::BinaryBooleanStateFormula const>(storm::logic::BinaryBooleanStateFormula::OperatorType::And, lhsTransition,rhsTransition); resStateTransitions[resTransitionTarget] = std::make_shared<storm::logic::BinaryBooleanStateFormula const>(storm::logic::BinaryBooleanStateFormula::OperatorType::And, lhsTransition,rhsTransition);
@ -82,7 +84,11 @@ namespace storm {
} }
resultLabeling.addLabel(rhsLabel, std::move(resLabeledStates)); resultLabeling.addLabel(rhsLabel, std::move(resLabeledStates));
} }
return MemoryStructure(std::move(resultTransitions), std::move(resultLabeling));
//return MemoryStructure(std::move(resultTransitions), std::move(resultLabeling));
MemoryStructure res(std::move(resultTransitions), std::move(resultLabeling));
return res;
} }
template <typename ValueType> template <typename ValueType>
@ -90,6 +96,37 @@ namespace storm {
return SparseModelMemoryProduct<ValueType>(sparseModel, *this); return SparseModelMemoryProduct<ValueType>(sparseModel, *this);
} }
std::string MemoryStructure::toString() const {
std::stringstream stream;
stream << "Memory Structure with " << getNumberOfStates() << " states: " << std::endl;
for (uint_fast64_t state = 0; state < getNumberOfStates(); ++state) {
stream << "State " << state << ": Labels = {";
bool firstLabel = true;
for (auto const& label : getStateLabeling().getLabelsOfState(state)) {
if (!firstLabel) {
stream << ", ";
}
firstLabel = false;
stream << label;
}
stream << "}, Transitions: " << std::endl;
for (uint_fast64_t transitionTarget = 0; transitionTarget < getNumberOfStates(); ++transitionTarget) {
stream << "\t From " << state << " to " << transitionTarget << ": \t";
auto const& transition = getTransitionMatrix()[state][transitionTarget];
if (transition) {
stream << *transition;
} else {
stream << "false";
}
stream << std::endl;
}
}
return stream.str();
}
template SparseModelMemoryProduct<double> MemoryStructure::product(storm::models::sparse::Model<double> const& sparseModel) const; template SparseModelMemoryProduct<double> MemoryStructure::product(storm::models::sparse::Model<double> const& sparseModel) const;
template SparseModelMemoryProduct<storm::RationalNumber> MemoryStructure::product(storm::models::sparse::Model<storm::RationalNumber> const& sparseModel) const; template SparseModelMemoryProduct<storm::RationalNumber> MemoryStructure::product(storm::models::sparse::Model<storm::RationalNumber> const& sparseModel) const;

2
src/storm/storage/memorystructure/MemoryStructure.h

@ -54,6 +54,8 @@ namespace storm {
*/ */
template <typename ValueType> template <typename ValueType>
SparseModelMemoryProduct<ValueType> product(storm::models::sparse::Model<ValueType> const& sparseModel) const; SparseModelMemoryProduct<ValueType> product(storm::models::sparse::Model<ValueType> const& sparseModel) const;
std::string toString() const;
private: private:
TransitionMatrix transitions; TransitionMatrix transitions;

Loading…
Cancel
Save