/* * dtmc.h * * Created on: 14.11.2012 * Author: Christian Dehnert */ #ifndef DTMC_H_ #define DTMC_H_ #include #include "AtomicPropositionsLabeling.h" #include "GraphTransitions.h" #include "src/storage/SquareSparseMatrix.h" namespace mrmc { namespace models { /*! * This class represents a discrete-time Markov chain (DTMC) whose states are * labeled with atomic propositions. */ template class Dtmc { public: //! Constructor /*! * Constructs a DTMC object from the given transition probability matrix and * the given labeling of the states. * @param probabilityMatrix The transition probability function of the * DTMC given by a matrix. * @param stateLabeling The labeling that assigns a set of atomic * propositions to each state. */ Dtmc(mrmc::storage::SquareSparseMatrix* probabilityMatrix, mrmc::models::AtomicPropositionsLabeling* stateLabeling) : backwardTransitions(nullptr) { this->probabilityMatrix = probabilityMatrix; this->stateLabeling = stateLabeling; } //! Copy Constructor /*! * Copy Constructor. Performs a deep copy of the given DTMC. * @param dtmc A reference to the DTMC that is to be copied. */ Dtmc(const Dtmc &dtmc) : probabilityMatrix(dtmc.probabilityMatrix), stateLabeling(dtmc.stateLabeling) { if (dtmc.backardTransitions != nullptr) { this->backwardTransitions = new mrmc::models::GraphTransitions(*dtmc.backwardTransitions); } } //! Destructor /*! * Destructor. Frees the matrix and labeling associated with this DTMC. */ ~Dtmc() { if (this->probabilityMatrix != nullptr) { delete this->probabilityMatrix; } if (this->stateLabeling != nullptr) { delete this->stateLabeling; } if (this->backwardTransitions != nullptr) { delete this->backwardTransitions; } } /*! * Returns the state space size of the DTMC. * @return The size of the state space of the DTMC. */ uint_fast64_t getNumberOfStates() const { return this->probabilityMatrix->getRowCount(); } /*! * Returns the number of (non-zero) transitions of the DTMC. * @return The number of (non-zero) transitions of the DTMC. */ uint_fast64_t getNumberOfTransitions() const { return this->probabilityMatrix->getNonZeroEntryCount(); } /*! * Returns a bit vector in which exactly those bits are set to true that * correspond to a state labeled with the given atomic proposition. * @param ap The atomic proposition for which to get the bit vector. * @return A bit vector in which exactly those bits are set to true that * correspond to a state labeled with the given atomic proposition. */ mrmc::storage::BitVector* getLabeledStates(std::string ap) const { return this->stateLabeling->getAtomicProposition(ap); } /*! * Returns a pointer to the matrix representing the transition probability * function. * @return A pointer to the matrix representing the transition probability * function. */ mrmc::storage::SquareSparseMatrix* getTransitionProbabilityMatrix() const { return this->probabilityMatrix; } /*! * */ std::set getPropositionsForState(uint_fast32_t state) { return stateLabeling->getPropositionsForState(state); } /*! * Retrieves a reference to the backwards transition relation. * @return A reference to the backwards transition relation. */ mrmc::models::GraphTransitions& getBackwardTransitions() { if (this->backwardTransitions == nullptr) { this->backwardTransitions = new mrmc::models::GraphTransitions(this->probabilityMatrix, false); } return *this->backwardTransitions; } /*! * Prints information about the model to the specified stream. * @param out The stream the information is to be printed to. */ void printModelInformationToStream(std::ostream& out) const { out << "-------------------------------------------------------------- " << std::endl; out << "Model type: \t\tDTMC" << std::endl; out << "States: \t\t" << this->getNumberOfStates() << std::endl; out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl; this->stateLabeling->printAtomicPropositionsInformationToStream(out); out << "Size in memory: \t" << (this->probabilityMatrix->getSizeInMemory() + this->stateLabeling->getSizeInMemory() + sizeof(*this))/1024 << " kbytes" << std::endl; out << "-------------------------------------------------------------- " << std::endl; } private: /*! A matrix representing the transition probability function of the DTMC. */ mrmc::storage::SquareSparseMatrix* probabilityMatrix; /*! The labeling of the states of the DTMC. */ mrmc::models::AtomicPropositionsLabeling* stateLabeling; /*! * A data structure that stores the predecessors for all states. This is * needed for backwards directed searches. */ mrmc::models::GraphTransitions* backwardTransitions; }; } // namespace models } // namespace mrmc #endif /* DTMC_H_ */