Browse Source

Moved model information output to super class. Moved methods to determine data structure size to superclass(es). Added missing getType methods for some models.

tempestpy_adaptions
dehnert 12 years ago
parent
commit
84c159feba
  1. 26
      src/models/AbstractDeterministicModel.h
  2. 38
      src/models/AbstractModel.h
  3. 25
      src/models/AbstractNonDeterministicModel.h
  4. 30
      src/models/Ctmc.h
  5. 33
      src/models/Ctmdp.h
  6. 25
      src/models/Dtmc.h
  7. 10
      src/models/GraphTransitions.h
  8. 25
      src/models/Mdp.h

26
src/models/AbstractDeterministicModel.h

@ -19,22 +19,48 @@ template<class T>
class AbstractDeterministicModel: public AbstractModel<T> {
public:
/*! Constructs an abstract determinstic model from the given parameters.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
AbstractDeterministicModel(std::shared_ptr<storm::storage::SparseMatrix<T>> transitionMatrix,
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling,
std::shared_ptr<std::vector<T>> stateRewardVector, std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, stateRewardVector, transitionRewardMatrix), backwardTransitions(nullptr) {
}
/*!
* Destructor.
*/
virtual ~AbstractDeterministicModel() {
// Intentionally left empty.
}
/*!
* Copy Constructor.
*/
AbstractDeterministicModel(AbstractDeterministicModel const& other) : AbstractModel<T>(other), backwardTransitions(nullptr) {
if (other.backwardTransitions != nullptr) {
backwardTransitions = new storm::models::GraphTransitions<T>(*other.backwardTransitions);
}
}
/*!
* Retrieves the size of the internal representation of the model in memory.
* @return the size of the internal representation of the model in memory
* measured in bytes.
*/
virtual uint_fast64_t getSizeInMemory() const {
uint_fast64_t result = AbstractModel<T>::getSizeInMemory();
if (backwardTransitions != nullptr) {
result += backwardTransitions->getSizeInMemory();
}
return result;
}
/*!
* Retrieves a reference to the backwards transition relation.
* @return A reference to the backwards transition relation.

38
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/CommandLine.h"
#include <memory>
#include <vector>
@ -49,7 +50,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
}
/*!
* Destructors.
* Destructor.
*/
virtual ~AbstractModel() {
// Intentionally left empty.
@ -82,7 +83,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
*
* @return Type of the model.
*/
virtual ModelType getType() = 0;
virtual ModelType getType() const = 0;
/*!
* Returns the state space size of the model.
@ -178,6 +179,39 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
return transitionRewardMatrix != nullptr;
}
/*!
* Retrieves the size of the internal representation of the model in memory.
* @return the size of the internal representation of the model in memory
* measured in bytes.
*/
virtual uint_fast64_t getSizeInMemory() const {
uint_fast64_t result = transitionMatrix->getSizeInMemory() + stateLabeling->getSizeInMemory();
if (stateRewardVector != nullptr) {
result += stateRewardVector->size() * sizeof(T);
}
if (transitionRewardMatrix != nullptr) {
result += transitionRewardMatrix->getSizeInMemory();
}
return result;
}
/*!
* 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\t" << this->getType() << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl;
this->getStateLabeling()->printAtomicPropositionsInformationToStream(out);
out << "Size in memory: \t"
<< (this->getSizeInMemory())/1024 << " kbytes" << std::endl;
out << "-------------------------------------------------------------- "
<< std::endl;
}
private:
/*! A matrix representing the likelihoods of moving between states. */
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionMatrix;

25
src/models/AbstractNonDeterministicModel.h

@ -19,7 +19,15 @@ template<class T>
class AbstractNonDeterministicModel: public AbstractModel<T> {
public:
AbstractNonDeterministicModel(std::shared_ptr<storm::storage::SparseMatrix<T>> transitionMatrix,
/*! Constructs an abstract non-determinstic model from the given parameters.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
* @param choiceIndices A mapping from states to rows in the transition matrix.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
AbstractNonDeterministicModel(std::shared_ptr<storm::storage::SparseMatrix<T>> transitionMatrix,
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling,
std::shared_ptr<std::vector<uint_fast64_t>> choiceIndices,
std::shared_ptr<std::vector<T>> stateRewardVector,
@ -28,13 +36,28 @@ class AbstractNonDeterministicModel: public AbstractModel<T> {
choiceIndices(choiceIndices) {
}
/*!
* Destructor.
*/
virtual ~AbstractNonDeterministicModel() {
// Intentionally left empty.
}
/*!
* Copy Constructor.
*/
AbstractNonDeterministicModel(AbstractNonDeterministicModel const& other) : AbstractModel<T>(other),
choiceIndices(other.choiceIndices) {
// Intentionally left empty.
}
/*!
* Retrieves the size of the internal representation of the model in memory.
* @return the size of the internal representation of the model in memory
* measured in bytes.
*/
virtual uint_fast64_t getSizeInMemory() const {
return AbstractModel<T>::getSizeInMemory() + choiceIndices->size() * sizeof(uint_fast64_t);
}
private:

30
src/models/Ctmc.h

@ -8,17 +8,12 @@
#ifndef STORM_MODELS_CTMC_H_
#define STORM_MODELS_CTMC_H_
#include <ostream>
#include <iostream>
#include <memory>
#include <cstdlib>
#include <vector>
#include "AbstractDeterministicModel.h"
#include "AtomicPropositionsLabeling.h"
#include "GraphTransitions.h"
#include "src/storage/SparseMatrix.h"
#include "src/exceptions/InvalidArgumentException.h"
#include "AbstractDeterministicModel.h"
namespace storm {
@ -57,26 +52,7 @@ public:
// Intentionally left empty.
}
/*!
* 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\tCTMC" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl;
this->getStateLabeling()->printAtomicPropositionsInformationToStream(out);
out << "Size in memory: \t"
<< (this->getTransitionMatrix()->getSizeInMemory() +
this->stateLabeling()->getSizeInMemory() +
sizeof(*this))/1024 << " kbytes" << std::endl;
out << "-------------------------------------------------------------- "
<< std::endl;
}
storm::models::ModelType getType() {
storm::models::ModelType getType() const {
return CTMC;
}
};

33
src/models/Ctmdp.h

@ -8,19 +8,13 @@
#ifndef STORM_MODELS_CTMDP_H_
#define STORM_MODELS_CTMDP_H_
#include <ostream>
#include <iostream>
#include <memory>
#include <cstdlib>
#include <vector>
#include "AtomicPropositionsLabeling.h"
#include "GraphTransitions.h"
#include "AbstractNonDeterministicModel.h"
#include "src/storage/SparseMatrix.h"
#include "src/exceptions/InvalidArgumentException.h"
#include "src/utility/CommandLine.h"
#include "src/utility/Settings.h"
#include "src/models/AbstractNonDeterministicModel.h"
#include "src/parser/NonDeterministicSparseTransitionParser.h"
namespace storm {
@ -74,27 +68,8 @@ public:
~Ctmdp() {
// Intentionally left empty.
}
/*!
* 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 {
storm::utility::printSeparationLine(out);
out << std::endl;
out << "Model type: \t\tCTMDP" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl;
this->getStateLabeling()->printAtomicPropositionsInformationToStream(out);
out << "Size in memory: \t"
<< (this->getTransitionMatrix()->getSizeInMemory() +
this->getStateLabeling()->getSizeInMemory() +
sizeof(*this))/1024 << " kbytes" << std::endl;
out << std::endl;
storm::utility::printSeparationLine(out);
}
storm::models::ModelType getType() {
storm::models::ModelType getType() const {
return CTMDP;
}

25
src/models/Dtmc.h

@ -13,13 +13,11 @@
#include <memory>
#include <cstdlib>
#include "AbstractDeterministicModel.h"
#include "AtomicPropositionsLabeling.h"
#include "GraphTransitions.h"
#include "src/storage/SparseMatrix.h"
#include "src/exceptions/InvalidArgumentException.h"
#include "src/utility/CommandLine.h"
#include "src/utility/Settings.h"
#include "src/models/AbstractDeterministicModel.h"
namespace storm {
@ -75,27 +73,8 @@ public:
~Dtmc() {
// Intentionally left empty.
}
/*!
* 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 {
storm::utility::printSeparationLine(out);
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->getStateLabeling()->printAtomicPropositionsInformationToStream(out);
out << "Size in memory: \t"
<< (this->getTransitionMatrix()->getSizeInMemory() +
this->getStateLabeling()->getSizeInMemory() +
sizeof(*this))/1024 << " kbytes" << std::endl;
out << std::endl;
storm::utility::printSeparationLine(out);
}
storm::models::ModelType getType() {
storm::models::ModelType getType() const {
return DTMC;
}

10
src/models/GraphTransitions.h

@ -61,6 +61,16 @@ public:
}
}
/*!
* Retrieves the size of the internal representation of the graph transitions in memory.
* @return the size of the internal representation of the graph transitions in memory
* measured in bytes.
*/
virtual uint_fast64_t getSizeInMemory() const {
uint_fast64_t result = sizeof(this) + (numberOfStates + numberOfNonZeroTransitions + 1) * sizeof(uint_fast64_t);
return result;
}
/*!
* Returns an iterator to the successors of the given state.
* @param state The state for which to get the successor iterator.

25
src/models/Mdp.h

@ -14,13 +14,9 @@
#include <cstdlib>
#include "AtomicPropositionsLabeling.h"
#include "GraphTransitions.h"
#include "src/storage/SparseMatrix.h"
#include "src/exceptions/InvalidArgumentException.h"
#include "src/utility/CommandLine.h"
#include "src/utility/Settings.h"
#include "src/models/AbstractNonDeterministicModel.h"
#include "src/parser/NonDeterministicSparseTransitionParser.h"
namespace storm {
@ -75,26 +71,7 @@ public:
// Intentionally left empty.
}
/*!
* 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 {
storm::utility::printSeparationLine(out);
out << std::endl;
out << "Model type: \t\tMDP" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl;
this->getStateLabeling()->printAtomicPropositionsInformationToStream(out);
out << "Size in memory: \t"
<< (this->getTransitionMatrix()->getSizeInMemory() +
this->getStateLabeling()->getSizeInMemory() +
sizeof(*this))/1024 << " kbytes" << std::endl;
out << std::endl;
storm::utility::printSeparationLine(out);
}
storm::models::ModelType getType() {
storm::models::ModelType getType() const {
return MDP;
}
Loading…
Cancel
Save