Browse Source

Added more move constructors.

Former-commit-id: 9770365fbb
main
PBerger 12 years ago
parent
commit
b978a4d311
  1. 11
      src/adapters/EigenAdapter.h
  2. 73
      src/adapters/ExplicitModelAdapter.cpp
  3. 12
      src/adapters/ExplicitModelAdapter.h
  4. 1
      src/modelchecker/prctl/SparseDtmcPrctlModelChecker.h
  5. 18
      src/models/AbstractDeterministicModel.h
  6. 87
      src/models/AbstractModel.h
  7. 50
      src/models/AbstractNondeterministicModel.h
  8. 14
      src/models/AtomicPropositionsLabeling.h
  9. 23
      src/models/Ctmc.h
  10. 40
      src/models/Ctmdp.h
  11. 32
      src/models/Dtmc.h
  12. 40
      src/models/Mdp.h
  13. 19
      src/storage/SparseMatrix.h

11
src/adapters/EigenAdapter.h

@ -14,6 +14,8 @@
#include "log4cplus/logger.h" #include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h" #include "log4cplus/loggingmacros.h"
#include "src/utility/OsDetection.h"
extern log4cplus::Logger logger; extern log4cplus::Logger logger;
namespace storm { namespace storm {
@ -36,7 +38,10 @@ public:
result->resizeNonZeros(static_cast<int>(realNonZeros)); result->resizeNonZeros(static_cast<int>(realNonZeros));
//result->reserve(realNonZeros); //result->reserve(realNonZeros);
#ifdef WINDOWS
# pragma warning(push)
# pragma warning(disable: 4244) // possible loss of data
#endif
// Copy Row Indications // Copy Row Indications
std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), (result->outerIndexPtr())); std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), (result->outerIndexPtr()));
// Copy Columns Indications // Copy Columns Indications
@ -44,6 +49,10 @@ public:
// And do the same thing with the actual values. // And do the same thing with the actual values.
std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), (result->valuePtr())); std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), (result->valuePtr()));
#ifdef WINDOWS
# pragma warning(pop)
#endif
LOG4CPLUS_DEBUG(logger, "Done converting matrix to Eigen format."); LOG4CPLUS_DEBUG(logger, "Done converting matrix to Eigen format.");
return result; return result;

73
src/adapters/ExplicitModelAdapter.cpp

@ -28,7 +28,7 @@ namespace adapters {
ExplicitModelAdapter::ExplicitModelAdapter(storm::ir::Program program) : program(program), ExplicitModelAdapter::ExplicitModelAdapter(storm::ir::Program program) : program(program),
booleanVariables(), integerVariables(), booleanVariableToIndexMap(), integerVariableToIndexMap(), booleanVariables(), integerVariables(), booleanVariableToIndexMap(), integerVariableToIndexMap(),
allStates(), stateToIndexMap(), numberOfTransitions(0), numberOfChoices(0), transitionRewards(nullptr), transitionMap() {
allStates(), stateToIndexMap(), numberOfTransitions(0), numberOfChoices(0), transitionMap() {
// Get variables from program. // Get variables from program.
this->initializeVariables(); this->initializeVariables();
storm::settings::Settings* s = storm::settings::instance(); storm::settings::Settings* s = storm::settings::instance();
@ -50,12 +50,12 @@ namespace adapters {
this->buildTransitionMap(); this->buildTransitionMap();
// Compute labeling. // Compute labeling.
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling = this->getStateLabeling(this->program.getLabels());
storm::models::AtomicPropositionsLabeling stateLabeling = this->getStateLabeling(this->program.getLabels());
// Compute state rewards. // Compute state rewards.
std::shared_ptr<std::vector<double>> stateRewards = nullptr;
boost::optional<std::vector<double>> stateRewards;
if ((this->rewardModel != nullptr) && this->rewardModel->hasStateRewards()) { if ((this->rewardModel != nullptr) && this->rewardModel->hasStateRewards()) {
stateRewards = this->getStateRewards(this->rewardModel->getStateRewards());
stateRewards.reset(this->getStateRewards(this->rewardModel->getStateRewards()));
} }
// Build and return actual model. // Build and return actual model.
@ -63,19 +63,19 @@ namespace adapters {
{ {
case storm::ir::Program::DTMC: case storm::ir::Program::DTMC:
{ {
std::shared_ptr<storm::storage::SparseMatrix<double>> matrix = this->buildDeterministicMatrix();
storm::storage::SparseMatrix<double> matrix = this->buildDeterministicMatrix();
return std::shared_ptr<storm::models::AbstractModel<double>>(new storm::models::Dtmc<double>(matrix, stateLabeling, stateRewards, this->transitionRewards)); return std::shared_ptr<storm::models::AbstractModel<double>>(new storm::models::Dtmc<double>(matrix, stateLabeling, stateRewards, this->transitionRewards));
break; break;
} }
case storm::ir::Program::CTMC: case storm::ir::Program::CTMC:
{ {
std::shared_ptr<storm::storage::SparseMatrix<double>> matrix = this->buildDeterministicMatrix();
storm::storage::SparseMatrix<double> matrix = this->buildDeterministicMatrix();
return std::shared_ptr<storm::models::AbstractModel<double>>(new storm::models::Ctmc<double>(matrix, stateLabeling, stateRewards, this->transitionRewards)); return std::shared_ptr<storm::models::AbstractModel<double>>(new storm::models::Ctmc<double>(matrix, stateLabeling, stateRewards, this->transitionRewards));
break; break;
} }
case storm::ir::Program::MDP: case storm::ir::Program::MDP:
{ {
std::shared_ptr<storm::storage::SparseMatrix<double>> matrix = this->buildNondeterministicMatrix();
storm::storage::SparseMatrix<double> matrix = this->buildNondeterministicMatrix();
return std::shared_ptr<storm::models::AbstractModel<double>>(new storm::models::Mdp<double>(matrix, stateLabeling, this->choiceIndices, stateRewards, this->transitionRewards)); return std::shared_ptr<storm::models::AbstractModel<double>>(new storm::models::Mdp<double>(matrix, stateLabeling, this->choiceIndices, stateRewards, this->transitionRewards));
break; break;
} }
@ -88,8 +88,6 @@ namespace adapters {
throw storm::exceptions::WrongFormatException() << "Error while creating model from probabilistic program: We can't handle this model type."; throw storm::exceptions::WrongFormatException() << "Error while creating model from probabilistic program: We can't handle this model type.";
break; break;
} }
return std::shared_ptr<storm::models::AbstractModel<double>>(nullptr);
} }
void ExplicitModelAdapter::setValue(StateType* const state, uint_fast64_t const index, bool const value) { void ExplicitModelAdapter::setValue(StateType* const state, uint_fast64_t const index, bool const value) {
@ -107,31 +105,31 @@ namespace adapters {
return ss.str(); return ss.str();
} }
std::shared_ptr<std::vector<double>> ExplicitModelAdapter::getStateRewards(std::vector<storm::ir::StateReward> const& rewards) {
std::shared_ptr<std::vector<double>> results(new std::vector<double>(this->allStates.size()));
std::vector<double> ExplicitModelAdapter::getStateRewards(std::vector<storm::ir::StateReward> const & rewards) {
std::vector<double> results(this->allStates.size());
for (uint_fast64_t index = 0; index < this->allStates.size(); index++) { for (uint_fast64_t index = 0; index < this->allStates.size(); index++) {
(*results)[index] = 0;
results[index] = 0;
for (auto reward: rewards) { for (auto reward: rewards) {
// Add this reward to the state if the state is included in the state reward. // Add this reward to the state if the state is included in the state reward.
if (reward.getStatePredicate()->getValueAsBool(this->allStates[index]) == true) { if (reward.getStatePredicate()->getValueAsBool(this->allStates[index]) == true) {
(*results)[index] += reward.getRewardValue()->getValueAsDouble(this->allStates[index]);
results[index] += reward.getRewardValue()->getValueAsDouble(this->allStates[index]);
} }
} }
} }
return results; return results;
} }
std::shared_ptr<storm::models::AtomicPropositionsLabeling> ExplicitModelAdapter::getStateLabeling(std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels) {
std::shared_ptr<storm::models::AtomicPropositionsLabeling> results(new storm::models::AtomicPropositionsLabeling(this->allStates.size(), labels.size()));
storm::models::AtomicPropositionsLabeling ExplicitModelAdapter::getStateLabeling(std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels) {
storm::models::AtomicPropositionsLabeling results(this->allStates.size(), labels.size());
// Initialize labeling. // Initialize labeling.
for (auto it: labels) { for (auto it: labels) {
results->addAtomicProposition(it.first);
results.addAtomicProposition(it.first);
} }
for (uint_fast64_t index = 0; index < this->allStates.size(); index++) { for (uint_fast64_t index = 0; index < this->allStates.size(); index++) {
for (auto label: labels) { for (auto label: labels) {
// Add label to state, if guard is true. // Add label to state, if guard is true.
if (label.second->getValueAsBool(this->allStates[index])) { if (label.second->getValueAsBool(this->allStates[index])) {
results->addAtomicPropositionToState(label.first, index);
results.addAtomicPropositionToState(label.first, index);
} }
} }
} }
@ -434,7 +432,7 @@ namespace adapters {
* @param intermediate Intermediate representation of transition mapping. * @param intermediate Intermediate representation of transition mapping.
* @return result matrix. * @return result matrix.
*/ */
std::shared_ptr<storm::storage::SparseMatrix<double>> ExplicitModelAdapter::buildDeterministicMatrix() {
storm::storage::SparseMatrix<double> ExplicitModelAdapter::buildDeterministicMatrix() {
// ***** ATTENTION ***** // ***** ATTENTION *****
// this->numberOfTransitions is meaningless, as we combine all choices into one for each state. // this->numberOfTransitions is meaningless, as we combine all choices into one for each state.
// Hence, we compute the correct number of transitions now. // Hence, we compute the correct number of transitions now.
@ -452,11 +450,11 @@ namespace adapters {
LOG4CPLUS_INFO(logger, "Building deterministic transition matrix: " << allStates.size() << " x " << allStates.size() << " with " << numberOfTransitions << " transitions."); LOG4CPLUS_INFO(logger, "Building deterministic transition matrix: " << allStates.size() << " x " << allStates.size() << " with " << numberOfTransitions << " transitions.");
// Now build matrix. // Now build matrix.
std::shared_ptr<storm::storage::SparseMatrix<double>> result(new storm::storage::SparseMatrix<double>(allStates.size()));
result->initialize(numberOfTransitions);
storm::storage::SparseMatrix<double> result(allStates.size());
result.initialize(numberOfTransitions);
if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) { if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) {
this->transitionRewards = std::shared_ptr<storm::storage::SparseMatrix<double>>(new storm::storage::SparseMatrix<double>(allStates.size()));
this->transitionRewards->initialize(numberOfTransitions);
this->transitionRewards.reset(storm::storage::SparseMatrix<double>(allStates.size()));
this->transitionRewards.get().initialize(numberOfTransitions);
} }
for (uint_fast64_t state = 0; state < this->allStates.size(); state++) { for (uint_fast64_t state = 0; state < this->allStates.size(); state++) {
if (transitionMap[state].size() > 1) { if (transitionMap[state].size() > 1) {
@ -480,14 +478,14 @@ namespace adapters {
// Scale probabilities by number of choices. // Scale probabilities by number of choices.
double factor = 1.0 / transitionMap[state].size(); double factor = 1.0 / transitionMap[state].size();
for (auto it : map) { for (auto it : map) {
result->addNextValue(state, it.first, it.second * factor);
result.addNextValue(state, it.first, it.second * factor);
if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) { if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) {
this->transitionRewards->addNextValue(state, it.first, rewardMap[it.first] * factor);
this->transitionRewards.get().addNextValue(state, it.first, rewardMap[it.first] * factor);
} }
} }
} }
result->finalize();
result.finalize();
return result; return result;
} }
@ -497,23 +495,23 @@ namespace adapters {
* @param choices Overall number of choices for all nodes. * @param choices Overall number of choices for all nodes.
* @return result matrix. * @return result matrix.
*/ */
std::shared_ptr<storm::storage::SparseMatrix<double>> ExplicitModelAdapter::buildNondeterministicMatrix() {
storm::storage::SparseMatrix<double> ExplicitModelAdapter::buildNondeterministicMatrix() {
LOG4CPLUS_INFO(logger, "Building nondeterministic transition matrix: " << this->numberOfChoices << " x " << allStates.size() << " with " << this->numberOfTransitions << " transitions."); LOG4CPLUS_INFO(logger, "Building nondeterministic transition matrix: " << this->numberOfChoices << " x " << allStates.size() << " with " << this->numberOfTransitions << " transitions.");
std::shared_ptr<storm::storage::SparseMatrix<double>> result(new storm::storage::SparseMatrix<double>(this->numberOfChoices, allStates.size()));
result->initialize(this->numberOfTransitions);
storm::storage::SparseMatrix<double> result(this->numberOfChoices, allStates.size());
result.initialize(this->numberOfTransitions);
if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) { if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) {
this->transitionRewards = std::shared_ptr<storm::storage::SparseMatrix<double>>(new storm::storage::SparseMatrix<double>(this->numberOfChoices, allStates.size()));
this->transitionRewards->initialize(this->numberOfTransitions);
this->transitionRewards.reset(storm::storage::SparseMatrix<double>(this->numberOfChoices, allStates.size()));
this->transitionRewards.get().initialize(this->numberOfTransitions);
} }
this->choiceIndices = std::shared_ptr<std::vector<uint_fast64_t>>(new std::vector<uint_fast64_t>());
this->choiceIndices->reserve(allStates.size());
this->choiceIndices.clear();
this->choiceIndices.reserve(allStates.size());
// Build matrix. // Build matrix.
uint_fast64_t nextRow = 0; uint_fast64_t nextRow = 0;
for (uint_fast64_t state = 0; state < this->allStates.size(); state++) { for (uint_fast64_t state = 0; state < this->allStates.size(); state++) {
this->choiceIndices->push_back(transitionMap[state].size());
this->choiceIndices.push_back(transitionMap[state].size());
for (auto choice : transitionMap[state]) { for (auto choice : transitionMap[state]) {
for (auto it : choice.second) { for (auto it : choice.second) {
result->addNextValue(nextRow, it.first, it.second);
result.addNextValue(nextRow, it.first, it.second);
if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) { if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) {
double rewardValue = 0; double rewardValue = 0;
for (auto reward : this->rewardModel->getTransitionRewards()) { for (auto reward : this->rewardModel->getTransitionRewards()) {
@ -521,13 +519,13 @@ namespace adapters {
rewardValue = reward.getRewardValue()->getValueAsDouble(this->allStates[state]); rewardValue = reward.getRewardValue()->getValueAsDouble(this->allStates[state]);
} }
} }
this->transitionRewards->addNextValue(nextRow, it.first, rewardValue);
this->transitionRewards.get().addNextValue(nextRow, it.first, rewardValue);
} }
} }
nextRow++; nextRow++;
} }
} }
result->finalize();
result.finalize();
return result; return result;
} }
@ -572,7 +570,8 @@ namespace adapters {
stateToIndexMap.clear(); stateToIndexMap.clear();
this->numberOfTransitions = 0; this->numberOfTransitions = 0;
this->numberOfChoices = 0; this->numberOfChoices = 0;
this->transitionRewards = nullptr;
this->choiceIndices.clear();
this->transitionRewards.reset();
this->transitionMap.clear(); this->transitionMap.clear();
} }

12
src/adapters/ExplicitModelAdapter.h

@ -121,14 +121,14 @@ private:
* @param rewards List of state reward models. * @param rewards List of state reward models.
* @return Reward for every state. * @return Reward for every state.
*/ */
std::shared_ptr<std::vector<double>> getStateRewards(std::vector<storm::ir::StateReward> const & rewards);
std::vector<double> getStateRewards(std::vector<storm::ir::StateReward> const & rewards);
/*! /*!
* Determines the labels for every reachable state, based on a list of available labels. * Determines the labels for every reachable state, based on a list of available labels.
* @param labels Mapping from label names to boolean expressions. * @param labels Mapping from label names to boolean expressions.
* @returns The resulting labeling. * @returns The resulting labeling.
*/ */
std::shared_ptr<storm::models::AtomicPropositionsLabeling> getStateLabeling(std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels);
storm::models::AtomicPropositionsLabeling getStateLabeling(std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels);
/*! /*!
* Retrieves all active command labeled by some label, ordered by modules. * Retrieves all active command labeled by some label, ordered by modules.
@ -181,7 +181,7 @@ private:
* @param intermediate Intermediate representation of transition mapping. * @param intermediate Intermediate representation of transition mapping.
* @return result matrix. * @return result matrix.
*/ */
std::shared_ptr<storm::storage::SparseMatrix<double>> buildDeterministicMatrix();
storm::storage::SparseMatrix<double> buildDeterministicMatrix();
/*! /*!
* Create matrix from intermediate mapping, assuming it is a mdp model. * Create matrix from intermediate mapping, assuming it is a mdp model.
@ -189,7 +189,7 @@ private:
* @param choices Overall number of choices for all nodes. * @param choices Overall number of choices for all nodes.
* @return result matrix. * @return result matrix.
*/ */
std::shared_ptr<storm::storage::SparseMatrix<double>> buildNondeterministicMatrix();
storm::storage::SparseMatrix<double> buildNondeterministicMatrix();
/*! /*!
* Generate internal transition map from given model. * Generate internal transition map from given model.
@ -225,9 +225,9 @@ private:
// Number of choices. (Is number of rows in matrix of nondeterministic model.) // Number of choices. (Is number of rows in matrix of nondeterministic model.)
uint_fast64_t numberOfChoices; uint_fast64_t numberOfChoices;
// Number of choices for each state. // Number of choices for each state.
std::shared_ptr<std::vector<uint_fast64_t>> choiceIndices;
std::vector<uint_fast64_t> choiceIndices;
// Rewards for transitions. // Rewards for transitions.
std::shared_ptr<storm::storage::SparseMatrix<double>> transitionRewards;
boost::optional<storm::storage::SparseMatrix<double>> transitionRewards;
/*! /*!
* Maps a source node to a list of probability distributions over target nodes. * Maps a source node to a list of probability distributions over target nodes.

1
src/modelchecker/prctl/SparseDtmcPrctlModelChecker.h

@ -409,6 +409,7 @@ public:
storm::utility::vector::setVectorValues<Type>(*result, maybeStates, storm::utility::constGetOne<Type>()); storm::utility::vector::setVectorValues<Type>(*result, maybeStates, storm::utility::constGetOne<Type>());
} else { } else {
// In this case we have to compute the reward values for the remaining states. // In this case we have to compute the reward values for the remaining states.
uint_fast64_t maybeStatesSetBitCount = maybeStates.getNumberOfSetBits();
// Now we can eliminate the rows and columns from the original transition probability matrix. // Now we can eliminate the rows and columns from the original transition probability matrix.
storm::storage::SparseMatrix<Type> submatrix = this->getModel().getTransitionMatrix().getSubmatrix(maybeStates); storm::storage::SparseMatrix<Type> submatrix = this->getModel().getTransitionMatrix().getSubmatrix(maybeStates);

18
src/models/AbstractDeterministicModel.h

@ -20,28 +20,28 @@ class AbstractDeterministicModel: public AbstractModel<T> {
public: public:
/*! Constructs an abstract determinstic model from the given parameters. /*! Constructs an abstract determinstic model from the given parameters.
* All values are copied.
* @param transitionMatrix The matrix representing the transitions in the model. * @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
* @param stateRewardVector The reward values associated with the states. * @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model. * @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) {
AbstractDeterministicModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
} }
/*! Constructs an abstract determinstic model from the given parameters. /*! Constructs an abstract determinstic model from the given parameters.
* All values are copied.
* Moves all references.
* @param transitionMatrix The matrix representing the transitions in the model. * @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
* @param stateRewardVector The reward values associated with the states. * @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model. * @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/ */
AbstractDeterministicModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
AbstractDeterministicModel(storm::storage::SparseMatrix<T>&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { : AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
} }
@ -66,7 +66,7 @@ class AbstractDeterministicModel: public AbstractModel<T> {
* @return An iterator to the successors of the given state. * @return An iterator to the successors of the given state.
*/ */
virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorBegin(uint_fast64_t state) const { virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorBegin(uint_fast64_t state) const {
return this->transitionMatrix->constColumnIteratorBegin(state);
return this->transitionMatrix.constColumnIteratorBegin(state);
} }
/*! /*!
@ -76,7 +76,7 @@ class AbstractDeterministicModel: public AbstractModel<T> {
* @return An iterator pointing to the element past the successors of the given state. * @return An iterator pointing to the element past the successors of the given state.
*/ */
virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorEnd(uint_fast64_t state) const { virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorEnd(uint_fast64_t state) const {
return this->transitionMatrix->constColumnIteratorEnd(state);
return this->transitionMatrix.constColumnIteratorEnd(state);
} }
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 { 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 {

87
src/models/AbstractModel.h

@ -35,19 +35,16 @@ template<class T>
class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> { class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
public: public:
/*! Constructs an abstract model from the given transition matrix and
* the given labeling of the states.
* @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.
/*! Move Constructor for an abstract model from the given transition matrix and
* the given labeling of the states. Creates copies of all given references.
* @param other The Source Abstract Model
*/ */
AbstractModel(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)
: transitionMatrix(transitionMatrix), stateLabeling(stateLabeling), stateRewardVector(stateRewardVector), transitionRewardMatrix(transitionRewardMatrix) {
// Intentionally left empty.
AbstractModel(AbstractModel<T>&& other) {
this->transitionMatrix = std::move(other.transitionMatrix);
this->stateLabeling = std::move(other.stateLabeling);
this->stateRewardVector = std::move(other.stateRewardVector);
this->transitionRewardMatrix = std::move(other.transitionRewardMatrix);
} }
/*! Constructs an abstract model from the given transition matrix and /*! Constructs an abstract model from the given transition matrix and
@ -59,22 +56,34 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @param transitionRewardMatrix The reward values associated with the transitions of the model. * @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/ */
AbstractModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling, AbstractModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix) {
this->transitionMatrix.reset(new storm::storage::SparseMatrix<T>(transitionMatrix));
this->stateLabeling.reset(new storm::models::AtomicPropositionsLabeling(stateLabeling));
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: transitionMatrix(transitionMatrix), stateLabeling(stateLabeling) {
this->stateRewardVector = nullptr;
this->transitionRewardMatrix = nullptr;
if (optionalStateRewardVector) { // Boost::Optional if (optionalStateRewardVector) { // Boost::Optional
this->stateRewardVector.reset(new std::vector<T>(optionalStateRewardVector.get()));
this->stateRewardVector.reset(optionalStateRewardVector.get());
} }
if (optionalTransitionRewardMatrix) { // Boost::Optional if (optionalTransitionRewardMatrix) { // Boost::Optional
this->transitionRewardMatrix.reset(new storm::storage::SparseMatrix<T>(optionalTransitionRewardMatrix.get()));
this->transitionRewardMatrix.reset(optionalTransitionRewardMatrix.get());
} }
} }
/*! Constructs an abstract model from the given transition matrix and
* the given labeling of the states. Moves all given references.
* @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.
*/
AbstractModel(storm::storage::SparseMatrix<T>&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix) {
this->transitionMatrix = std::move(transitionMatrix);
this->stateLabeling = std::move(stateLabeling);
this->stateRewardVector = std::move(optionalStateRewardVector);
this->transitionRewardMatrix = std::move(optionalTransitionRewardMatrix);
}
/*! /*!
* Destructor. * Destructor.
*/ */
@ -254,7 +263,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* correspond to a state labeled with the given atomic proposition. * correspond to a state labeled with the given atomic proposition.
*/ */
storm::storage::BitVector const& getLabeledStates(std::string const& ap) const { storm::storage::BitVector const& getLabeledStates(std::string const& ap) const {
return stateLabeling->getLabeledStates(ap);
return stateLabeling.getLabeledStates(ap);
} }
/*! /*!
@ -263,7 +272,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return True if the given atomic proposition is valid in this model. * @return True if the given atomic proposition is valid in this model.
*/ */
bool hasAtomicProposition(std::string const& atomicProposition) const { bool hasAtomicProposition(std::string const& atomicProposition) const {
return stateLabeling->containsAtomicProposition(atomicProposition);
return stateLabeling.containsAtomicProposition(atomicProposition);
} }
/*! /*!
@ -273,7 +282,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* function. * function.
*/ */
storm::storage::SparseMatrix<T> const& getTransitionMatrix() const { storm::storage::SparseMatrix<T> const& getTransitionMatrix() const {
return *transitionMatrix;
return transitionMatrix;
} }
/*! /*!
@ -281,7 +290,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return A pointer to the matrix representing the transition rewards. * @return A pointer to the matrix representing the transition rewards.
*/ */
storm::storage::SparseMatrix<T> const& getTransitionRewardMatrix() const { storm::storage::SparseMatrix<T> const& getTransitionRewardMatrix() const {
return *transitionRewardMatrix;
return transitionRewardMatrix.get();
} }
/*! /*!
@ -289,7 +298,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return A pointer to the vector representing the state rewards. * @return A pointer to the vector representing the state rewards.
*/ */
std::vector<T> const& getStateRewardVector() const { std::vector<T> const& getStateRewardVector() const {
return *stateRewardVector;
return stateRewardVector.get();
} }
/*! /*!
@ -299,7 +308,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return The set of labels with which the given state is labeled. * @return The set of labels with which the given state is labeled.
*/ */
std::set<std::string> getLabelsForState(uint_fast64_t state) const { std::set<std::string> getLabelsForState(uint_fast64_t state) const {
return stateLabeling->getPropositionsForState(state);
return stateLabeling.getPropositionsForState(state);
} }
/*! /*!
@ -307,7 +316,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return The state labeling associated with this model. * @return The state labeling associated with this model.
*/ */
storm::models::AtomicPropositionsLabeling const& getStateLabeling() const { storm::models::AtomicPropositionsLabeling const& getStateLabeling() const {
return *stateLabeling;
return stateLabeling;
} }
/*! /*!
@ -315,7 +324,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return True if this model has a state reward model. * @return True if this model has a state reward model.
*/ */
bool hasStateRewards() const { bool hasStateRewards() const {
return stateRewardVector != nullptr;
return stateRewardVector;
} }
/*! /*!
@ -323,7 +332,7 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @return True if this model has a transition reward model. * @return True if this model has a transition reward model.
*/ */
bool hasTransitionRewards() const { bool hasTransitionRewards() const {
return transitionRewardMatrix != nullptr;
return transitionRewardMatrix;
} }
/*! /*!
@ -332,12 +341,12 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* measured in bytes. * measured in bytes.
*/ */
virtual uint_fast64_t getSizeInMemory() const { virtual uint_fast64_t getSizeInMemory() const {
uint_fast64_t result = transitionMatrix->getSizeInMemory() + stateLabeling->getSizeInMemory();
if (stateRewardVector != nullptr) {
result += stateRewardVector->size() * sizeof(T);
uint_fast64_t result = transitionMatrix.getSizeInMemory() + stateLabeling.getSizeInMemory();
if (stateRewardVector) {
result += getStateRewardVector().size() * sizeof(T);
} }
if (transitionRewardMatrix != nullptr) {
result += transitionRewardMatrix->getSizeInMemory();
if (hasTransitionRewards()) {
result += getTransitionRewardMatrix().getSizeInMemory();
} }
return result; return result;
} }
@ -430,17 +439,17 @@ protected:
} }
/*! A matrix representing the likelihoods of moving between states. */ /*! A matrix representing the likelihoods of moving between states. */
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionMatrix;
storm::storage::SparseMatrix<T> transitionMatrix;
private: private:
/*! The labeling of the states of the model. */ /*! The labeling of the states of the model. */
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling;
storm::models::AtomicPropositionsLabeling stateLabeling;
/*! The state-based rewards of the model. */ /*! The state-based rewards of the model. */
std::shared_ptr<std::vector<T>> stateRewardVector;
boost::optional<std::vector<T>> stateRewardVector;
/*! The transition-based rewards of the model. */ /*! The transition-based rewards of the model. */
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix;
boost::optional<storm::storage::SparseMatrix<T>> transitionRewardMatrix;
}; };
} // namespace models } // namespace models

50
src/models/AbstractNondeterministicModel.h

@ -19,6 +19,7 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
public: public:
/*! Constructs an abstract non-determinstic model from the given parameters. /*! Constructs an abstract non-determinstic model from the given parameters.
* All values are copied.
* @param transitionMatrix The matrix representing the transitions in the model. * @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
@ -26,17 +27,18 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* @param stateRewardVector The reward values associated with the states. * @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model. * @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>> nondeterministicChoiceIndices,
std::shared_ptr<std::vector<T>> stateRewardVector,
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, stateRewardVector, transitionRewardMatrix),
nondeterministicChoiceIndices(nondeterministicChoiceIndices) {
AbstractNondeterministicModel(
storm::storage::SparseMatrix<T> const& transitionMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
this->nondeterministicChoiceIndices = nondeterministicChoiceIndices;
} }
/*! Constructs an abstract non-determinstic model from the given parameters. /*! Constructs an abstract non-determinstic model from the given parameters.
* All values are copied.
* All values are moved.
* @param transitionMatrix The matrix representing the transitions in the model. * @param transitionMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
@ -45,13 +47,13 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* @param transitionRewardMatrix The reward values associated with the transitions of the model. * @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/ */
AbstractNondeterministicModel( AbstractNondeterministicModel(
storm::storage::SparseMatrix<T> const& transitionMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
storm::storage::SparseMatrix<T>&& transitionMatrix,
storm::models::AtomicPropositionsLabeling&& stateLabeling,
std::vector<uint_fast64_t>&& nondeterministicChoiceIndices,
boost::optional<std::vector<T>>&& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { : AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
this->nondeterministicChoiceIndices.reset(new std::vector<uint_fast64_t>(nondeterministicChoiceIndices));
this->nondeterministicChoiceIndices = std::move(nondeterministicChoiceIndices);
} }
/*! /*!
@ -69,12 +71,20 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
// Intentionally left empty. // Intentionally left empty.
} }
/*!
* Move Constructor.
*/
AbstractNondeterministicModel(AbstractNondeterministicModel&& other) : AbstractModel<T>(other),
nondeterministicChoiceIndices(std::move(other.nondeterministicChoiceIndices)) {
// Intentionally left empty.
}
/*! /*!
* Returns the number of choices for all states of the MDP. * Returns the number of choices for all states of the MDP.
* @return The number of choices for all states of the MDP. * @return The number of choices for all states of the MDP.
*/ */
uint_fast64_t getNumberOfChoices() const { uint_fast64_t getNumberOfChoices() const {
return this->transitionMatrix->getRowCount();
return this->transitionMatrix.getRowCount();
} }
/*! /*!
@ -83,7 +93,7 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* measured in bytes. * measured in bytes.
*/ */
virtual uint_fast64_t getSizeInMemory() const { virtual uint_fast64_t getSizeInMemory() const {
return AbstractModel<T>::getSizeInMemory() + nondeterministicChoiceIndices->size() * sizeof(uint_fast64_t);
return AbstractModel<T>::getSizeInMemory() + nondeterministicChoiceIndices.size() * sizeof(uint_fast64_t);
} }
/*! /*!
@ -93,7 +103,7 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* of a certain state. * of a certain state.
*/ */
std::vector<uint_fast64_t> const& getNondeterministicChoiceIndices() const { std::vector<uint_fast64_t> const& getNondeterministicChoiceIndices() const {
return *nondeterministicChoiceIndices;
return nondeterministicChoiceIndices;
} }
/*! /*!
@ -103,7 +113,7 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* @return An iterator to the successors of the given state. * @return An iterator to the successors of the given state.
*/ */
virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorBegin(uint_fast64_t state) const { virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorBegin(uint_fast64_t state) const {
return this->transitionMatrix->constColumnIteratorBegin((*nondeterministicChoiceIndices)[state]);
return this->transitionMatrix.constColumnIteratorBegin(nondeterministicChoiceIndices[state]);
} }
/*! /*!
@ -113,7 +123,7 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* @return An iterator pointing to the element past the successors of the given state. * @return An iterator pointing to the element past the successors of the given state.
*/ */
virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorEnd(uint_fast64_t state) const { virtual typename storm::storage::SparseMatrix<T>::ConstIndexIterator constStateSuccessorIteratorEnd(uint_fast64_t state) const {
return this->transitionMatrix->constColumnIteratorEnd((*nondeterministicChoiceIndices)[state + 1] - 1);
return this->transitionMatrix.constColumnIteratorEnd(nondeterministicChoiceIndices[state + 1] - 1);
} }
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 { 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 {
@ -187,7 +197,7 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
private: private:
/*! A vector of indices mapping states to the choices (rows) in the transition matrix. */ /*! A vector of indices mapping states to the choices (rows) in the transition matrix. */
std::shared_ptr<std::vector<uint_fast64_t>> nondeterministicChoiceIndices;
std::vector<uint_fast64_t> nondeterministicChoiceIndices;
}; };
} // namespace models } // namespace models

14
src/models/AtomicPropositionsLabeling.h

@ -57,6 +57,20 @@ public:
// Intentionally left empty. // Intentionally left empty.
} }
/*!
* Move Constructor that performs a move copy on the given atomic proposition labeling.
*
* @param atomicPropositionsLabeling The atomic propositions labeling to copy.
*/
AtomicPropositionsLabeling(AtomicPropositionsLabeling&& atomicPropositionsLabeling)
: stateCount(atomicPropositionsLabeling.stateCount),
apCountMax(atomicPropositionsLabeling.apCountMax),
apsCurrent(atomicPropositionsLabeling.apsCurrent),
nameToLabelingMap(std::move(atomicPropositionsLabeling.nameToLabelingMap)),
singleLabelings(std::move(atomicPropositionsLabeling.singleLabelings)) {
// Intentionally left empty.
}
/*! /*!
* (Empty) destructor. * (Empty) destructor.
*/ */

23
src/models/Ctmc.h

@ -27,7 +27,6 @@ template <class T>
class Ctmc : public storm::models::AbstractDeterministicModel<T> { class Ctmc : public storm::models::AbstractDeterministicModel<T> {
public: public:
//! Constructor
/*! /*!
* Constructs a CTMC object from the given transition rate matrix and * Constructs a CTMC object from the given transition rate matrix and
* the given labeling of the states. * the given labeling of the states.
@ -36,11 +35,9 @@ public:
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Ctmc(std::shared_ptr<storm::storage::SparseMatrix<T>> rateMatrix,
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling,
std::shared_ptr<std::vector<T>> stateRewardVector = nullptr,
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix = nullptr)
: AbstractDeterministicModel<T>(rateMatrix, stateLabeling, stateRewardVector, transitionRewardMatrix) {
Ctmc(storm::storage::SparseMatrix<T> const& rateMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractDeterministicModel<T>(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
} }
/*! /*!
@ -51,8 +48,8 @@ public:
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Ctmc(storm::storage::SparseMatrix<T> const& rateMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
Ctmc(storm::storage::SparseMatrix<T>&& rateMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
: AbstractDeterministicModel<T>(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { : AbstractDeterministicModel<T>(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
} }
@ -61,7 +58,15 @@ public:
* Copy Constructor. Performs a deep copy of the given CTMC. * Copy Constructor. Performs a deep copy of the given CTMC.
* @param ctmc A reference to the CTMC that is to be copied. * @param ctmc A reference to the CTMC that is to be copied.
*/ */
Ctmc(const Ctmc<T> &ctmc) : AbstractDeterministicModel<T>(ctmc) {
Ctmc(Ctmc<T> const & ctmc) : AbstractDeterministicModel<T>(ctmc) {
// Intentionally left empty.
}
/*!
* Move Constructor. Performs a move on the given CTMC.
* @param ctmc A reference to the CTMC that is to be moved from.
*/
Ctmc(Ctmc<T>&& ctmc) : AbstractDeterministicModel<T>(ctmc) {
// Intentionally left empty. // Intentionally left empty.
} }

40
src/models/Ctmdp.h

@ -28,21 +28,21 @@ template <class T>
class Ctmdp : public storm::models::AbstractNondeterministicModel<T> { class Ctmdp : public storm::models::AbstractNondeterministicModel<T> {
public: public:
//! Constructor
/*! /*!
* Constructs a CTMDP object from the given transition probability matrix and * Constructs a CTMDP object from the given transition probability matrix and
* the given labeling of the states. * the given labeling of the states.
* All values are copied.
* @param probabilityMatrix The transition probability relation of the * @param probabilityMatrix The transition probability relation of the
* CTMDP given by a matrix. * CTMDP given by a matrix.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Ctmdp(std::shared_ptr<storm::storage::SparseMatrix<T>> probabilityMatrix,
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling,
std::shared_ptr<std::vector<uint_fast64_t>> choiceIndices,
std::shared_ptr<std::vector<T>> stateRewardVector = nullptr,
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix = nullptr)
: AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, choiceIndices, stateRewardVector, transitionRewardMatrix) {
Ctmdp(storm::storage::SparseMatrix<T> const& probabilityMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
@ -52,17 +52,17 @@ public:
/*! /*!
* Constructs a CTMDP object from the given transition probability matrix and * Constructs a CTMDP object from the given transition probability matrix and
* the given labeling of the states. * the given labeling of the states.
* All values are copied.
* All values are moved.
* @param probabilityMatrix The transition probability relation of the * @param probabilityMatrix The transition probability relation of the
* CTMDP given by a matrix. * CTMDP given by a matrix.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Ctmdp(storm::storage::SparseMatrix<T> const& probabilityMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
Ctmdp(storm::storage::SparseMatrix<T>&& probabilityMatrix,
storm::models::AtomicPropositionsLabeling&& stateLabeling,
std::vector<uint_fast64_t>&& nondeterministicChoiceIndices,
boost::optional<std::vector<T>>&& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
: AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) { : AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
@ -70,12 +70,22 @@ public:
} }
} }
//! Copy Constructor
/*! /*!
* Copy Constructor. Performs a deep copy of the given CTMDP. * Copy Constructor. Performs a deep copy of the given CTMDP.
* @param ctmdp A reference to the CTMDP that is to be copied. * @param ctmdp A reference to the CTMDP that is to be copied.
*/ */
Ctmdp(const Ctmdp<T> &ctmdp) : AbstractNondeterministicModel<T>(ctmdp) {
Ctmdp(Ctmdp<T> const & ctmdp) : AbstractNondeterministicModel<T>(ctmdp) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
}
}
/*!
* Move Constructor. Performs a move on the given CTMDP.
* @param ctmdp A reference to the CTMDP that is to be moved.
*/
Ctmdp(Ctmdp<T>&& ctmdp) : AbstractNondeterministicModel<T>(ctmdp) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";

32
src/models/Dtmc.h

@ -31,20 +31,19 @@ template <class T>
class Dtmc : public storm::models::AbstractDeterministicModel<T> { class Dtmc : public storm::models::AbstractDeterministicModel<T> {
public: public:
//! Constructor
/*! /*!
* Constructs a DTMC object from the given transition probability matrix and * Constructs a DTMC object from the given transition probability matrix and
* the given labeling of the states. * the given labeling of the states.
* @param probabilityMatrix The transition probability function of the
* DTMC given by a matrix.
* All values are copied.
* @param probabilityMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * 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.
*/ */
Dtmc(std::shared_ptr<storm::storage::SparseMatrix<T>> probabilityMatrix,
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling,
std::shared_ptr<std::vector<T>> stateRewardVector = nullptr,
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix = nullptr)
: AbstractDeterministicModel<T>(probabilityMatrix, stateLabeling, stateRewardVector, transitionRewardMatrix) {
Dtmc(storm::storage::SparseMatrix<T> const& probabilityMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractDeterministicModel<T>(probabilityMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
@ -60,15 +59,15 @@ public:
/*! /*!
* Constructs a DTMC object from the given transition probability matrix and * Constructs a DTMC object from the given transition probability matrix and
* the given labeling of the states. * the given labeling of the states.
* All values are copied.
* All values are moved.
* @param probabilityMatrix The matrix representing the transitions in the model. * @param probabilityMatrix The matrix representing the transitions in the model.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
* @param stateRewardVector The reward values associated with the states. * @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model. * @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/ */
Dtmc(storm::storage::SparseMatrix<T> const& probabilityMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
Dtmc(storm::storage::SparseMatrix<T>&& probabilityMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
: AbstractDeterministicModel<T>(probabilityMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { : AbstractDeterministicModel<T>(probabilityMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
@ -82,12 +81,19 @@ public:
} }
} }
//! Copy Constructor
/*! /*!
* Copy Constructor. Performs a deep copy of the given DTMC. * Copy Constructor. Performs a deep copy of the given DTMC.
* @param dtmc A reference to the DTMC that is to be copied. * @param dtmc A reference to the DTMC that is to be copied.
*/ */
Dtmc(Dtmc<T> const& dtmc) : AbstractDeterministicModel<T>(dtmc) {
Dtmc(Dtmc<T> const & dtmc) : AbstractDeterministicModel<T>(dtmc) {
// Intentionally left empty.
}
/*!
* Move Constructor. Performs a move on the given DTMC.
* @param dtmc A reference to the DTMC that is to be moved.
*/
Dtmc(Dtmc<T>&& dtmc) : AbstractDeterministicModel<T>(dtmc) {
// Intentionally left empty. // Intentionally left empty.
} }

40
src/models/Mdp.h

@ -30,21 +30,21 @@ template <class T>
class Mdp : public storm::models::AbstractNondeterministicModel<T> { class Mdp : public storm::models::AbstractNondeterministicModel<T> {
public: public:
//! Constructor
/*! /*!
* Constructs a MDP object from the given transition probability matrix and * Constructs a MDP object from the given transition probability matrix and
* the given labeling of the states. * the given labeling of the states.
* All values are copied.
* @param probabilityMatrix The transition probability relation of the * @param probabilityMatrix The transition probability relation of the
* MDP given by a matrix. * MDP given by a matrix.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Mdp(std::shared_ptr<storm::storage::SparseMatrix<T>> probabilityMatrix,
std::shared_ptr<storm::models::AtomicPropositionsLabeling> stateLabeling,
std::shared_ptr<std::vector<uint_fast64_t>> choiceIndices,
std::shared_ptr<std::vector<T>> stateRewardVector = nullptr,
std::shared_ptr<storm::storage::SparseMatrix<T>> transitionRewardMatrix = nullptr)
: AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, choiceIndices, stateRewardVector, transitionRewardMatrix) {
Mdp(storm::storage::SparseMatrix<T> const& transitionMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractNondeterministicModel<T>(transitionMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
@ -54,17 +54,17 @@ public:
/*! /*!
* Constructs a MDP object from the given transition probability matrix and * Constructs a MDP object from the given transition probability matrix and
* the given labeling of the states. * the given labeling of the states.
* All values are copied.
* All values are moved.
* @param probabilityMatrix The transition probability relation of the * @param probabilityMatrix The transition probability relation of the
* MDP given by a matrix. * MDP given by a matrix.
* @param stateLabeling The labeling that assigns a set of atomic * @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state. * propositions to each state.
*/ */
Mdp(storm::storage::SparseMatrix<T> const& transitionMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
Mdp(storm::storage::SparseMatrix<T>&& transitionMatrix,
storm::models::AtomicPropositionsLabeling&& stateLabeling,
std::vector<uint_fast64_t>&& nondeterministicChoiceIndices,
boost::optional<std::vector<T>>&& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
: AbstractNondeterministicModel<T>(transitionMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) { : AbstractNondeterministicModel<T>(transitionMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
@ -72,12 +72,22 @@ public:
} }
} }
//! Copy Constructor
/*! /*!
* Copy Constructor. Performs a deep copy of the given MDP. * Copy Constructor. Performs a deep copy of the given MDP.
* @param mdp A reference to the MDP that is to be copied. * @param mdp A reference to the MDP that is to be copied.
*/ */
Mdp(const Mdp<T> &mdp) : AbstractNondeterministicModel<T>(mdp) {
Mdp(Mdp<T> const & mdp) : AbstractNondeterministicModel<T>(mdp) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
}
}
/*!
* Move Constructor. Performs a move on the given MDP.
* @param mdp A reference to the MDP that is to be moved.
*/
Mdp(Mdp<T>&& mdp) : AbstractNondeterministicModel<T>(mdp) {
if (!this->checkValidityOfProbabilityMatrix()) { if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";

19
src/storage/SparseMatrix.h

@ -224,6 +224,25 @@ public:
internalStatus(MatrixStatus::UnInitialized), currentSize(0), lastRow(0) { internalStatus(MatrixStatus::UnInitialized), currentSize(0), lastRow(0) {
// Intentionally left empty. // Intentionally left empty.
} }
/*!
* Move Constructor.
*
* @param other The Matrix from which to move the content
*/
SparseMatrix(SparseMatrix&& other)
: rowCount(other.rowCount), colCount(other.colCount), nonZeroEntryCount(other.nonZeroEntryCount),
internalStatus(other.internalStatus), currentSize(other.currentSize), lastRow(other.lastRow),
valueStorage(std::move(other.valueStorage)), columnIndications(std::move(other.columnIndications)),
rowIndications(std::move(other.rowIndications)) {
// Now update the source matrix
other.rowCount = 0;
other.colCount = 0;
other.nonZeroEntryCount = 0;
other.internalStatus = MatrixStatus::Error;
other.currentSize = 0;
other.lastRow = 0;
}
/*! /*!
* Constructs a sparse matrix object with the given (moved) contents. * Constructs a sparse matrix object with the given (moved) contents.

Loading…
Cancel
Save