Browse Source

Added symbolic models and made DD-based model generator build the correct instances.

Former-commit-id: c054401cfd
tempestpy_adaptions
dehnert 10 years ago
parent
commit
239caf57eb
  1. 3
      CMakeLists.txt
  2. 34
      src/builder/DdPrismModelBuilder.cpp
  3. 15
      src/builder/DdPrismModelBuilder.h
  4. 10
      src/builder/ExplicitPrismModelBuilder.cpp
  5. 2
      src/builder/ExplicitPrismModelBuilder.h
  6. 7
      src/models/ModelBase.h
  7. 2
      src/models/sparse/Model.cpp
  8. 1
      src/models/sparse/Model.h
  9. 2
      src/models/sparse/NondeterministicModel.cpp
  10. 30
      src/models/symbolic/DeterministicModel.cpp
  11. 63
      src/models/symbolic/DeterministicModel.h
  12. 29
      src/models/symbolic/Dtmc.cpp
  13. 61
      src/models/symbolic/Dtmc.h
  14. 30
      src/models/symbolic/Mdp.cpp
  15. 65
      src/models/symbolic/Mdp.h
  16. 137
      src/models/symbolic/Model.cpp
  17. 238
      src/models/symbolic/Model.h
  18. 60
      src/models/symbolic/NondeterministicModel.cpp
  19. 86
      src/models/symbolic/NondeterministicModel.h
  20. 82
      test/functional/builder/DdPrismModelBuilderTest.cpp

3
CMakeLists.txt

@ -269,6 +269,7 @@ file(GLOB_RECURSE STORM_MODELCHECKER_RESULTS_FILES ${PROJECT_SOURCE_DIR}/src/mod
file(GLOB_RECURSE STORM_COUNTEREXAMPLES_FILES ${PROJECT_SOURCE_DIR}/src/counterexamples/*.h ${PROJECT_SOURCE_DIR}/src/counterexamples/*.cpp)
file(GLOB STORM_MODELS_FILES ${PROJECT_SOURCE_DIR}/src/models/*.h ${PROJECT_SOURCE_DIR}/src/models/*.cpp)
file(GLOB_RECURSE STORM_MODELS_SPARSE_FILES ${PROJECT_SOURCE_DIR}/src/models/sparse/*.h ${PROJECT_SOURCE_DIR}/src/models/sparse/*.cpp)
file(GLOB_RECURSE STORM_MODELS_SYMBOLIC_FILES ${PROJECT_SOURCE_DIR}/src/models/symbolic/*.h ${PROJECT_SOURCE_DIR}/src/models/symbolic/*.cpp)
file(GLOB STORM_PARSER_FILES ${PROJECT_SOURCE_DIR}/src/parser/*.h ${PROJECT_SOURCE_DIR}/src/parser/*.cpp)
file(GLOB_RECURSE STORM_PARSER_PRISMPARSER_FILES ${PROJECT_SOURCE_DIR}/src/parser/prismparser/*.h ${PROJECT_SOURCE_DIR}/src/parser/prismparser/*.cpp)
file(GLOB STORM_SETTINGS_FILES ${PROJECT_SOURCE_DIR}/src/settings/*.h ${PROJECT_SOURCE_DIR}/src/settings/*.cpp)
@ -290,7 +291,6 @@ file(GLOB_RECURSE STORM_PERFORMANCE_TEST_FILES ${STORM_CPP_TESTS_BASE_PATH}/perf
# Additional include files like the storm-config.h
file(GLOB_RECURSE STORM_BUILD_HEADERS ${PROJECT_BINARY_DIR}/include/*.h)
# Group the headers and sources
source_group(main FILES ${STORM_MAIN_FILE})
source_group(adapters FILES ${STORM_ADAPTERS_FILES})
@ -307,6 +307,7 @@ source_group(modelchecker\\results FILES ${STORM_MODELCHECKER_RESULTS_FILES})
source_group(counterexamples FILES ${STORM_COUNTEREXAMPLES_FILES})
source_group(models FILES ${STORM_MODELS_FILES})
source_group(models\\sparse FILES ${STORM_MODELS_SPARSE_FILES})
source_group(models\\symbolic FILES ${STORM_MODELS_SYMBOLIC_FILES})
source_group(parser FILES ${STORM_PARSER_FILES})
source_group(parser\\prismparser FILES ${STORM_PARSER_PRISMPARSER_FILES})
source_group(settings FILES ${STORM_SETTINGS_FILES})

34
src/builder/DdPrismModelBuilder.cpp

@ -1,5 +1,8 @@
#include "src/builder/DdPrismModelBuilder.h"
#include "src/models/symbolic/Dtmc.h"
#include "src/models/symbolic/Mdp.h"
#include "src/storage/dd/CuddDd.h"
#include "src/storage/dd/CuddDdManager.h"
#include "src/settings/SettingsManager.h"
@ -574,7 +577,7 @@ namespace storm {
}
template <storm::dd::DdType Type>
std::pair<storm::dd::Dd<Type>, storm::dd::Dd<Type>> DdPrismModelBuilder<Type>::translateProgram(storm::prism::Program const& program, Options const& options) {
std::shared_ptr<storm::models::symbolic::Model<Type>> DdPrismModelBuilder<Type>::translateProgram(storm::prism::Program const& program, Options const& options) {
// There might be nondeterministic variables. In that case the program must be prepared before translating.
storm::prism::Program preparedProgram;
if (options.constantDefinitions) {
@ -600,13 +603,11 @@ namespace storm {
}
preparedProgram = preparedProgram.substituteConstants();
// std::cout << "translated prog: " << preparedProgram << std::endl;
// Start by initializing the structure used for storing all information needed during the model generation.
// In particular, this creates the meta variables used to encode the model.
GenerationInformation generationInfo(preparedProgram);
auto totalTimeStart = std::chrono::high_resolution_clock::now();
std::pair<storm::dd::Dd<Type>, ModuleDecisionDiagram> transitionMatrixModulePair = createSystemDecisionDiagram(generationInfo);
storm::dd::Dd<Type> transitionMatrix = transitionMatrixModulePair.first;
ModuleDecisionDiagram const& globalModule = transitionMatrixModulePair.second;
@ -632,19 +633,10 @@ namespace storm {
stateAndTransitionRewards = createRewardDecisionDiagrams(generationInfo, rewardModel, globalModule, transitionMatrix);
}
auto totalTimeEnd = std::chrono::high_resolution_clock::now();
std::cout << "building matrices and vectors took " << std::chrono::duration_cast<std::chrono::milliseconds>(totalTimeEnd - totalTimeStart).count() << "ms" << std::endl;
// Cut the transition matrix to the reachable fragment of the state space.
totalTimeStart = std::chrono::high_resolution_clock::now();
storm::dd::Dd<Type> reachableStates = computeReachableStates(generationInfo, createInitialStatesDecisionDiagram(generationInfo), transitionMatrix);
totalTimeEnd = std::chrono::high_resolution_clock::now();
std::cout << "reachability took " << std::chrono::duration_cast<std::chrono::milliseconds>(totalTimeEnd - totalTimeStart).count() << "ms" << std::endl;
totalTimeStart = std::chrono::high_resolution_clock::now();
storm::dd::Dd<Type> initialStates = createInitialStatesDecisionDiagram(generationInfo);
storm::dd::Dd<Type> reachableStates = computeReachableStates(generationInfo, initialStates, transitionMatrix);
transitionMatrix *= reachableStates.toMtbdd();
totalTimeEnd = std::chrono::high_resolution_clock::now();
std::cout << "cutting trans to reachable took " << std::chrono::duration_cast<std::chrono::milliseconds>(totalTimeEnd - totalTimeStart).count() << "ms" << std::endl;
// Detect deadlocks and 1) fix them if requested 2) throw an error otherwise.
storm::dd::Dd<Type> statesWithTransition = transitionMatrix.notZero();
@ -674,9 +666,19 @@ namespace storm {
}
}
std::cout << reachableStates.getNonZeroCount() << " states and " << transitionMatrix.getNonZeroCount() << " transitions." << std::endl;
// Build the labels that can be accessed as a shortcut.
std::map<std::string, storm::expressions::Expression> labelToExpressionMapping;
for (auto const& label : program.getLabels()) {
labelToExpressionMapping.emplace(label.getName(), label.getStatePredicateExpression());
}
return std::make_pair(reachableStates, transitionMatrix);
if (program.getModelType() == storm::prism::Program::ModelType::DTMC) {
return std::unique_ptr<storm::models::symbolic::Model<Type>>(new storm::models::symbolic::Dtmc<Type>(generationInfo.manager, reachableStates, initialStates, transitionMatrix, generationInfo.rowMetaVariables, generationInfo.rowExpressionAdapter, generationInfo.columnMetaVariables, generationInfo.columnExpressionAdapter, generationInfo.rowColumnMetaVariablePairs, labelToExpressionMapping, stateAndTransitionRewards ? stateAndTransitionRewards.get().first : boost::optional<storm::dd::Dd<Type>>(), stateAndTransitionRewards ? stateAndTransitionRewards.get().second : boost::optional<storm::dd::Dd<Type>>()));
} else if (program.getModelType() == storm::prism::Program::ModelType::MDP) {
return std::unique_ptr<storm::models::symbolic::Model<Type>>(new storm::models::symbolic::Mdp<Type>(generationInfo.manager, reachableStates, initialStates, transitionMatrix, generationInfo.rowMetaVariables, generationInfo.rowExpressionAdapter, generationInfo.columnMetaVariables, generationInfo.columnExpressionAdapter, generationInfo.rowColumnMetaVariablePairs, generationInfo.allNondeterminismVariables, labelToExpressionMapping, stateAndTransitionRewards ? stateAndTransitionRewards.get().first : boost::optional<storm::dd::Dd<Type>>(), stateAndTransitionRewards ? stateAndTransitionRewards.get().second : boost::optional<storm::dd::Dd<Type>>()));
} else {
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Invalid model type.");
}
}
template <storm::dd::DdType Type>

15
src/builder/DdPrismModelBuilder.h

@ -4,6 +4,7 @@
#include <map>
#include <boost/optional.hpp>
#include "src/models/symbolic/Model.h"
#include "src/logic/Formulas.h"
#include "src/storage/prism/Program.h"
#include "src/adapters/DdExpressionAdapter.h"
@ -55,11 +56,13 @@ namespace storm {
};
/*!
* Translates the given program into a model that stores the transition relation as a decision diagram.
* Translates the given program into a symbolic model (i.e. one that stores the transition relation as a
* decision diagram).
*
* @param program The program to translate.
* @return A pointer to the resulting model.
*/
static std::pair<storm::dd::Dd<Type>, storm::dd::Dd<Type>> translateProgram(storm::prism::Program const& program, Options const& options = Options());
static std::shared_ptr<storm::models::symbolic::Model<Type>> translateProgram(storm::prism::Program const& program, Options const& options = Options());
private:
// This structure can store the decision diagrams representing a particular action.
@ -132,8 +135,8 @@ namespace storm {
// Initializes variables and identity DDs.
createMetaVariablesAndIdentities();
rowExpressionAdapter = std::unique_ptr<storm::adapters::DdExpressionAdapter<Type>>(new storm::adapters::DdExpressionAdapter<Type>(*manager, variableToRowMetaVariableMap));
columnExpressionAdapter = std::unique_ptr<storm::adapters::DdExpressionAdapter<Type>>(new storm::adapters::DdExpressionAdapter<Type>(*manager, variableToColumnMetaVariableMap));
rowExpressionAdapter = std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>>(new storm::adapters::DdExpressionAdapter<Type>(*manager, variableToRowMetaVariableMap));
columnExpressionAdapter = std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>>(new storm::adapters::DdExpressionAdapter<Type>(*manager, variableToColumnMetaVariableMap));
}
// The program that is currently translated.
@ -145,12 +148,12 @@ namespace storm {
// The meta variables for the row encoding.
std::set<storm::expressions::Variable> rowMetaVariables;
std::map<storm::expressions::Variable, storm::expressions::Variable> variableToRowMetaVariableMap;
std::unique_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter;
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter;
// The meta variables for the column encoding.
std::set<storm::expressions::Variable> columnMetaVariables;
std::map<storm::expressions::Variable, storm::expressions::Variable> variableToColumnMetaVariableMap;
std::unique_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter;
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter;
// All pairs of row/column meta variables.
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> rowColumnMetaVariablePairs;

10
src/builder/ExplicitPrismModelBuilder.cpp

@ -91,7 +91,7 @@ namespace storm {
}
template <typename ValueType, typename IndexType>
std::unique_ptr<storm::models::sparse::Model<ValueType>> ExplicitPrismModelBuilder<ValueType, IndexType>::translateProgram(storm::prism::Program program, Options const& options) {
std::shared_ptr<storm::models::sparse::Model<ValueType>> ExplicitPrismModelBuilder<ValueType, IndexType>::translateProgram(storm::prism::Program program, Options const& options) {
// Start by defining the undefined constants in the model.
storm::prism::Program preparedProgram;
if (options.constantDefinitions) {
@ -166,16 +166,16 @@ namespace storm {
ModelComponents modelComponents = buildModelComponents(preparedProgram, rewardModel, options);
std::unique_ptr<storm::models::sparse::Model<ValueType>> result;
std::shared_ptr<storm::models::sparse::Model<ValueType>> result;
switch (program.getModelType()) {
case storm::prism::Program::ModelType::DTMC:
result = std::unique_ptr<storm::models::sparse::Model<ValueType>>(new storm::models::sparse::Dtmc<ValueType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), rewardModel.hasStateRewards() ? std::move(modelComponents.stateRewards) : boost::optional<std::vector<ValueType>>(), rewardModel.hasTransitionRewards() ? std::move(modelComponents.transitionRewardMatrix) : boost::optional<storm::storage::SparseMatrix<ValueType>>(), std::move(modelComponents.choiceLabeling)));
result = std::shared_ptr<storm::models::sparse::Model<ValueType>>(new storm::models::sparse::Dtmc<ValueType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), rewardModel.hasStateRewards() ? std::move(modelComponents.stateRewards) : boost::optional<std::vector<ValueType>>(), rewardModel.hasTransitionRewards() ? std::move(modelComponents.transitionRewardMatrix) : boost::optional<storm::storage::SparseMatrix<ValueType>>(), std::move(modelComponents.choiceLabeling)));
break;
case storm::prism::Program::ModelType::CTMC:
result = std::unique_ptr<storm::models::sparse::Model<ValueType>>(new storm::models::sparse::Ctmc<ValueType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), rewardModel.hasStateRewards() ? std::move(modelComponents.stateRewards) : boost::optional<std::vector<ValueType>>(), rewardModel.hasTransitionRewards() ? std::move(modelComponents.transitionRewardMatrix) : boost::optional<storm::storage::SparseMatrix<ValueType>>(), std::move(modelComponents.choiceLabeling)));
result = std::shared_ptr<storm::models::sparse::Model<ValueType>>(new storm::models::sparse::Ctmc<ValueType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), rewardModel.hasStateRewards() ? std::move(modelComponents.stateRewards) : boost::optional<std::vector<ValueType>>(), rewardModel.hasTransitionRewards() ? std::move(modelComponents.transitionRewardMatrix) : boost::optional<storm::storage::SparseMatrix<ValueType>>(), std::move(modelComponents.choiceLabeling)));
break;
case storm::prism::Program::ModelType::MDP:
result = std::unique_ptr<storm::models::sparse::Model<ValueType>>(new storm::models::sparse::Mdp<ValueType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), rewardModel.hasStateRewards() ? std::move(modelComponents.stateRewards) : boost::optional<std::vector<ValueType>>(), rewardModel.hasTransitionRewards() ? std::move(modelComponents.transitionRewardMatrix) : boost::optional<storm::storage::SparseMatrix<ValueType>>(), std::move(modelComponents.choiceLabeling)));
result = std::shared_ptr<storm::models::sparse::Model<ValueType>>(new storm::models::sparse::Mdp<ValueType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), rewardModel.hasStateRewards() ? std::move(modelComponents.stateRewards) : boost::optional<std::vector<ValueType>>(), rewardModel.hasTransitionRewards() ? std::move(modelComponents.transitionRewardMatrix) : boost::optional<storm::storage::SparseMatrix<ValueType>>(), std::move(modelComponents.choiceLabeling)));
break;
default:
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Error while creating model from probabilistic program: cannot handle this model type.");

2
src/builder/ExplicitPrismModelBuilder.h

@ -172,7 +172,7 @@ namespace storm {
* @param rewardModel The reward model that is to be built.
* @return The explicit model that was given by the probabilistic program.
*/
static std::unique_ptr<storm::models::sparse::Model<ValueType>> translateProgram(storm::prism::Program program, Options const& options = Options());
static std::shared_ptr<storm::models::sparse::Model<ValueType>> translateProgram(storm::prism::Program program, Options const& options = Options());
private:
static void unpackStateIntoEvaluator(storm::storage::BitVector const& currentState, VariableInformation const& variableInformation, storm::expressions::ExpressionEvaluator<ValueType>& evaluator);

7
src/models/ModelBase.h

@ -69,6 +69,13 @@ namespace storm {
*/
virtual std::size_t getSizeInBytes() const = 0;
/*!
* Prints information about the model to the specified stream.
*
* @param out The stream the information is to be printed to.
*/
virtual void printModelInformationToStream(std::ostream& out) const = 0;
private:
// The type of the model.
ModelType modelType;

2
src/models/sparse/Model.cpp

@ -199,7 +199,7 @@ namespace storm {
template <typename ValueType>
void Model<ValueType>::printModelInformationToStream(std::ostream& out) const {
out << "-------------------------------------------------------------- " << std::endl;
out << "Model type: \t\t" << this->getType() << std::endl;
out << "Model type: \t\t" << this->getType() << " (sparse)" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl;
this->getStateLabeling().printLabelingInformationToStream(out);

1
src/models/sparse/Model.h

@ -73,6 +73,7 @@ namespace storm {
*/
template <typename BlockType>
storm::storage::SparseMatrix<ValueType> extractPartitionDependencyGraph(storm::storage::Decomposition<BlockType> const& decomposition) const;
/*!
* Retrieves the backward transition relation of the model, i.e. a set of transitions between states
* that correspond to the reversed transition relation of this model.

2
src/models/sparse/NondeterministicModel.cpp

@ -42,7 +42,7 @@ namespace storm {
template<typename ValueType>
void NondeterministicModel<ValueType>::printModelInformationToStream(std::ostream& out) const {
out << "-------------------------------------------------------------- " << std::endl;
out << "Model type: \t\t" << this->getType() << std::endl;
out << "Model type: \t\t" << this->getType() << " (sparse)" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << std::endl;
out << "Choices: \t\t" << this->getNumberOfChoices() << std::endl;

30
src/models/symbolic/DeterministicModel.cpp

@ -0,0 +1,30 @@
#include "src/models/symbolic/DeterministicModel.h"
namespace storm {
namespace models {
namespace symbolic {
template<storm::dd::DdType Type>
DeterministicModel<Type>::DeterministicModel(storm::models::ModelType const& modelType,
std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector,
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix)
: Model<Type>(modelType, manager, reachableStates, initialStates, transitionMatrix, rowVariables, rowExpressionAdapter, columnVariables, columnExpressionAdapter, rowColumnMetaVariablePairs, labelToExpressionMap, optionalStateRewardVector, optionalTransitionRewardMatrix) {
// Intentionally left empty.
}
// Explicitly instantiate the template class.
template class DeterministicModel<storm::dd::DdType::CUDD>;
} // namespace symbolic
} // namespace models
} // namespace storm

63
src/models/symbolic/DeterministicModel.h

@ -0,0 +1,63 @@
#ifndef STORM_MODELS_SYMBOLIC_DETERMINISTICMODEL_H_
#define STORM_MODELS_SYMBOLIC_DETERMINISTICMODEL_H_
#include "src/models/symbolic/Model.h"
#include "src/utility/OsDetection.h"
namespace storm {
namespace models {
namespace symbolic {
/*!
* Base class for all deterministic symbolic models.
*/
template<storm::dd::DdType Type>
class DeterministicModel : public Model<Type> {
public:
DeterministicModel(DeterministicModel<Type> const& other) = default;
DeterministicModel& operator=(DeterministicModel<Type> const& other) = default;
#ifndef WINDOWS
DeterministicModel(DeterministicModel<Type>&& other) = default;
DeterministicModel& operator=(DeterministicModel<Type>&& other) = default;
#endif
/*!
* Constructs a model from the given data.
*
* @param modelType The type of the model.
* @param manager The manager responsible for the decision diagrams.
* @param reachableStates A DD representing the reachable states.
* @param initialStates A DD representing the initial states of the model.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param rowVariables The set of row meta variables used in the DDs.
* @param rowExpressionAdapter An object that can be used to translate expressions in terms of the row
* meta variables.
* @param columVariables The set of column meta variables used in the DDs.
* @param columnExpressionAdapter An object that can be used to translate expressions in terms of the
* column meta variables.
* @param rowColumnMetaVariablePairs All pairs of row/column meta variables.
* @param labelToExpressionMap A mapping from label names to their defining expressions.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
*/
DeterministicModel(storm::models::ModelType const& modelType,
std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap = std::map<std::string, storm::expressions::Expression>(),
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector = boost::optional<storm::dd::Dd<Type>>(),
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix = boost::optional<storm::dd::Dd<Type>>());
};
} // namespace symbolic
} // namespace models
} // namespace storm
#endif /* STORM_MODELS_SYMBOLIC_DETERMINISTICMODEL_H_ */

29
src/models/symbolic/Dtmc.cpp

@ -0,0 +1,29 @@
#include "src/models/symbolic/Dtmc.h"
namespace storm {
namespace models {
namespace symbolic {
template<storm::dd::DdType Type>
Dtmc<Type>::Dtmc(std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector,
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix)
: DeterministicModel<Type>(storm::models::ModelType::Dtmc, manager, reachableStates, initialStates, transitionMatrix, rowVariables, rowExpressionAdapter, columnVariables, columnExpressionAdapter, rowColumnMetaVariablePairs, labelToExpressionMap, optionalStateRewardVector, optionalTransitionRewardMatrix) {
// Intentionally left empty.
}
// Explicitly instantiate the template class.
template class Dtmc<storm::dd::DdType::CUDD>;
} // namespace symbolic
} // namespace models
} // namespace storm

61
src/models/symbolic/Dtmc.h

@ -0,0 +1,61 @@
#ifndef STORM_MODELS_SYMBOLIC_DTMC_H_
#define STORM_MODELS_SYMBOLIC_DTMC_H_
#include "src/models/symbolic/DeterministicModel.h"
#include "src/utility/OsDetection.h"
namespace storm {
namespace models {
namespace symbolic {
/*!
* This class represents a discrete-time Markov chain.
*/
template<storm::dd::DdType Type>
class Dtmc : public DeterministicModel<Type> {
public:
Dtmc(Dtmc<Type> const& other) = default;
Dtmc& operator=(Dtmc<Type> const& other) = default;
#ifndef WINDOWS
Dtmc(Dtmc<Type>&& other) = default;
Dtmc& operator=(Dtmc<Type>&& other) = default;
#endif
/*!
* Constructs a model from the given data.
*
* @param manager The manager responsible for the decision diagrams.
* @param reachableStates A DD representing the reachable states.
* @param initialStates A DD representing the initial states of the model.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param rowVariables The set of row meta variables used in the DDs.
* @param rowExpressionAdapter An object that can be used to translate expressions in terms of the row
* meta variables.
* @param columVariables The set of column meta variables used in the DDs.
* @param columnExpressionAdapter An object that can be used to translate expressions in terms of the
* column meta variables.
* @param rowColumnMetaVariablePairs All pairs of row/column meta variables.
* @param labelToExpressionMap A mapping from label names to their defining expressions.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
*/
Dtmc(std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap = std::map<std::string, storm::expressions::Expression>(),
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector = boost::optional<storm::dd::Dd<Type>>(),
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix = boost::optional<storm::dd::Dd<Type>>());
};
} // namespace symbolic
} // namespace models
} // namespace storm
#endif /* STORM_MODELS_SYMBOLIC_DTMC_H_ */

30
src/models/symbolic/Mdp.cpp

@ -0,0 +1,30 @@
#include "src/models/symbolic/Mdp.h"
namespace storm {
namespace models {
namespace symbolic {
template<storm::dd::DdType Type>
Mdp<Type>::Mdp(std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::set<storm::expressions::Variable> const& nondeterminismVariables,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector,
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix)
: NondeterministicModel<Type>(storm::models::ModelType::Mdp, manager, reachableStates, initialStates, transitionMatrix, rowVariables, rowExpressionAdapter, columnVariables, columnExpressionAdapter, rowColumnMetaVariablePairs, nondeterminismVariables, labelToExpressionMap, optionalStateRewardVector, optionalTransitionRewardMatrix) {
// Intentionally left empty.
}
// Explicitly instantiate the template class.
template class Mdp<storm::dd::DdType::CUDD>;
} // namespace symbolic
} // namespace models
} // namespace storm

65
src/models/symbolic/Mdp.h

@ -0,0 +1,65 @@
#ifndef STORM_MODELS_SYMBOLIC_MDP_H_
#define STORM_MODELS_SYMBOLIC_MDP_H_
#include "src/models/symbolic/NondeterministicModel.h"
#include "src/utility/OsDetection.h"
namespace storm {
namespace models {
namespace symbolic {
/*!
* This class represents a discrete-time Markov decision process.
*/
template<storm::dd::DdType Type>
class Mdp : public NondeterministicModel<Type> {
public:
Mdp(Mdp<Type> const& other) = default;
Mdp& operator=(Mdp<Type> const& other) = default;
#ifndef WINDOWS
Mdp(Mdp<Type>&& other) = default;
Mdp& operator=(Mdp<Type>&& other) = default;
#endif
/*!
* Constructs a model from the given data.
*
* @param modelType The type of the model.
* @param manager The manager responsible for the decision diagrams.
* @param reachableStates A DD representing the reachable states.
* @param initialStates A DD representing the initial states of the model.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param rowVariables The set of row meta variables used in the DDs.
* @param rowExpressionAdapter An object that can be used to translate expressions in terms of the row
* meta variables.
* @param columVariables The set of column meta variables used in the DDs.
* @param columnExpressionAdapter An object that can be used to translate expressions in terms of the
* column meta variables.
* @param rowColumnMetaVariablePairs All pairs of row/column meta variables.
* @param nondeterminismVariables The meta variables used to encode the nondeterminism in the model.
* @param labelToExpressionMap A mapping from label names to their defining expressions.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
*/
Mdp(std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::set<storm::expressions::Variable> const& nondeterminismVariables,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap = std::map<std::string, storm::expressions::Expression>(),
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector = boost::optional<storm::dd::Dd<Type>>(),
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix = boost::optional<storm::dd::Dd<Type>>());
};
} // namespace symbolic
} // namespace models
} // namespace storm
#endif /* STORM_MODELS_SYMBOLIC_MDP_H_ */

137
src/models/symbolic/Model.cpp

@ -0,0 +1,137 @@
#include "src/models/symbolic/Model.h"
namespace storm {
namespace models {
namespace symbolic {
template<storm::dd::DdType Type>
Model<Type>::Model(storm::models::ModelType const& modelType,
std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector,
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix)
: ModelBase(modelType), manager(manager), reachableStates(reachableStates), initialStates(initialStates), transitionMatrix(transitionMatrix), rowVariables(rowVariables), rowExpressionAdapter(rowExpressionAdapter), columnVariables(columnVariables), columnExpressionAdapter(columnExpressionAdapter), rowColumnMetaVariablePairs(rowColumnMetaVariablePairs), labelToExpressionMap(labelToExpressionMap), stateRewardVector(optionalStateRewardVector), transitionRewardMatrix(optionalTransitionRewardMatrix) {
// Intentionally left empty.
}
template<storm::dd::DdType Type>
uint_fast64_t Model<Type>::getNumberOfStates() const {
return reachableStates.getNonZeroCount();
}
template<storm::dd::DdType Type>
uint_fast64_t Model<Type>::getNumberOfTransitions() const {
return transitionMatrix.getNonZeroCount();
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> const& Model<Type>::getReachableStates() const {
return reachableStates;
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> const& Model<Type>::getInitialStates() const {
return initialStates;
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> Model<Type>::getStates(std::string const& label) const {
return rowExpressionAdapter->translateExpression(labelToExpressionMap.at(label));
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> Model<Type>::getStates(storm::expressions::Expression const& expression) const {
return rowExpressionAdapter->translateExpression(expression);
}
template<storm::dd::DdType Type>
bool Model<Type>::hasLabel(std::string const& label) const {
return labelToExpressionMap.find(label) != labelToExpressionMap.end();
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> const& Model<Type>::getTransitionMatrix() const {
return transitionMatrix;
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type>& Model<Type>::getTransitionMatrix() {
return transitionMatrix;
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> const& Model<Type>::getTransitionRewardMatrix() const {
return transitionRewardMatrix.get();
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type>& Model<Type>::getTransitionRewardMatrix() {
return transitionRewardMatrix.get();
}
template<storm::dd::DdType Type>
storm::dd::Dd<Type> const& Model<Type>::getStateRewardVector() const {
return stateRewardVector.get();
}
template<storm::dd::DdType Type>
bool Model<Type>::hasStateRewards() const {
return static_cast<bool>(stateRewardVector);
}
template<storm::dd::DdType Type>
bool Model<Type>::hasTransitionRewards() const {
return static_cast<bool>(transitionRewardMatrix);
}
template<storm::dd::DdType Type>
std::size_t Model<Type>::getSizeInBytes() const {
return sizeof(*this) + sizeof(DdNode) * (reachableStates.getNodeCount() + initialStates.getNodeCount() + transitionMatrix.getNodeCount());
}
template<storm::dd::DdType Type>
std::set<storm::expressions::Variable> const& Model<Type>::getRowVariables() const {
return rowVariables;
}
template<storm::dd::DdType Type>
std::set<storm::expressions::Variable> const& Model<Type>::getColumnVariables() const {
return columnVariables;
}
template<storm::dd::DdType Type>
void Model<Type>::setTransitionMatrix(storm::dd::Dd<Type> const& transitionMatrix) {
this->transitionMatrix = transitionMatrix;
}
template<storm::dd::DdType Type>
std::map<std::string, storm::expressions::Expression> const& Model<Type>::getLabelToExpressionMap() const {
return labelToExpressionMap;
}
template<storm::dd::DdType Type>
void Model<Type>::printModelInformationToStream(std::ostream& out) const {
out << "-------------------------------------------------------------- " << std::endl;
out << "Model type: \t\t" << this->getType() << " (symbolic)" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << " (" << reachableStates.getNodeCount() << " nodes)" << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << " (" << transitionMatrix.getNodeCount() << " nodes)" << std::endl;
out << "Variables: \t\t" << "rows:" << this->rowVariables.size() << ", columns: " << this->columnVariables.size() << std::endl;
for (auto const& label : labelToExpressionMap) {
out << "\t" << label.first << std::endl;
}
out << "Size in memory: \t" << (this->getSizeInBytes())/1024 << " kbytes" << std::endl;
out << "-------------------------------------------------------------- " << std::endl;
}
// Explicitly instantiate the template class.
template class Model<storm::dd::DdType::CUDD>;
} // namespace symbolic
} // namespace models
} // namespace storm

238
src/models/symbolic/Model.h

@ -0,0 +1,238 @@
#ifndef STORM_MODELS_SYMBOLIC_MODEL_H_
#define STORM_MODELS_SYMBOLIC_MODEL_H_
#include <memory>
#include <set>
#include <boost/optional.hpp>
#include "src/storage/expressions/Expression.h"
#include "src/storage/expressions/Variable.h"
#include "src/adapters/DdExpressionAdapter.h"
#include "src/storage/dd/CuddDd.h"
#include "src/storage/dd/CuddDdManager.h"
#include "src/models/ModelBase.h"
#include "src/utility/OsDetection.h"
namespace storm {
namespace models {
namespace symbolic {
/*!
* Base class for all symbolic models.
*/
template<storm::dd::DdType Type>
class Model : public storm::models::ModelBase {
public:
Model(Model<Type> const& other) = default;
Model& operator=(Model<Type> const& other) = default;
#ifndef WINDOWS
Model(Model<Type>&& other) = default;
Model& operator=(Model<Type>&& other) = default;
#endif
/*!
* Constructs a model from the given data.
*
* @param modelType The type of the model.
* @param manager The manager responsible for the decision diagrams.
* @param reachableStates A DD representing the reachable states.
* @param initialStates A DD representing the initial states of the model.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param rowVariables The set of row meta variables used in the DDs.
* @param rowExpressionAdapter An object that can be used to translate expressions in terms of the row
* meta variables.
* @param columVariables The set of column meta variables used in the DDs.
* @param columnExpressionAdapter An object that can be used to translate expressions in terms of the
* column meta variables.
* @param rowColumnMetaVariablePairs All pairs of row/column meta variables.
* @param labelToExpressionMap A mapping from label names to their defining expressions.
* @param optionalStateRewardVector The reward values associated with the states.
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
*/
Model(storm::models::ModelType const& modelType,
std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap = std::map<std::string, storm::expressions::Expression>(),
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector = boost::optional<storm::dd::Dd<Type>>(),
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix = boost::optional<storm::dd::Dd<Type>>());
virtual uint_fast64_t getNumberOfStates() const override;
virtual uint_fast64_t getNumberOfTransitions() const override;
/*!
* Retrieves the reachable states of the model.
*
* @return The reachble states of the model.
*/
storm::dd::Dd<Type> const& getReachableStates() const;
/*!
* Retrieves the initial states of the model.
*
* @return The initial states of the model.
*/
storm::dd::Dd<Type> const& getInitialStates() const;
/*!
* Returns the sets of states labeled with the given label.
*
* @param label The label for which to get the labeled states.
* @return The set of states labeled with the requested label in the form of a bit vector.
*/
storm::dd::Dd<Type> getStates(std::string const& label) const;
/*!
* Returns the set of states labeled satisfying the given expression (that must be of boolean type).
*
* @param expression The expression that needs to hold in the states.
* @return The set of states labeled satisfying the given expression.
*/
storm::dd::Dd<Type> getStates(storm::expressions::Expression const& expression) const;
/*!
* Retrieves whether the given label is a valid label in this model.
*
* @param label The label to be checked for validity.
* @return True if the given label is valid in this model.
*/
bool hasLabel(std::string const& label) const;
/*!
* Retrieves the matrix representing the transitions of the model.
*
* @return A matrix representing the transitions of the model.
*/
storm::dd::Dd<Type> const& getTransitionMatrix() const;
/*!
* Retrieves the matrix representing the transitions of the model.
*
* @return A matrix representing the transitions of the model.
*/
storm::dd::Dd<Type>& getTransitionMatrix();
/*!
* Retrieves the matrix representing the transition rewards of the model. Note that calling this method
* is only valid if the model has transition rewards.
*
* @return The matrix representing the transition rewards of the model.
*/
storm::dd::Dd<Type> const& getTransitionRewardMatrix() const;
/*!
* Retrieves the matrix representing the transition rewards of the model. Note that calling this method
* is only valid if the model has transition rewards.
*
* @return The matrix representing the transition rewards of the model.
*/
storm::dd::Dd<Type>& getTransitionRewardMatrix();
/*!
* Retrieves a vector representing the state rewards of the model. Note that calling this method is only
* valid if the model has state rewards.
*
* @return A vector representing the state rewards of the model.
*/
storm::dd::Dd<Type> const& getStateRewardVector() const;
/*!
* Retrieves whether this model has state rewards.
*
* @return True iff this model has state rewards.
*/
bool hasStateRewards() const;
/*!
* Retrieves whether this model has transition rewards.
*
* @return True iff this model has transition rewards.
*/
bool hasTransitionRewards() const;
/*!
* Retrieves the meta variables used to encode the rows of the transition matrix and the vector indices.
*
* @return The meta variables used to encode the rows of the transition matrix and the vector indices.
*/
std::set<storm::expressions::Variable> const& getRowVariables() const;
/*!
* Retrieves the meta variables used to encode the columns of the transition matrix and the vector indices.
*
* @return The meta variables used to encode the columns of the transition matrix and the vector indices.
*/
std::set<storm::expressions::Variable> const& getColumnVariables() const;
virtual std::size_t getSizeInBytes() const override;
virtual void printModelInformationToStream(std::ostream& out) const override;
protected:
/*!
* Sets the transition matrix of the model.
*
* @param transitionMatrix The new transition matrix of the model.
*/
void setTransitionMatrix(storm::dd::Dd<Type> const& transitionMatrix);
/*!
* Retrieves the mapping of labels to their defining expressions.
*
* @returns The mapping of labels to their defining expressions.
*/
std::map<std::string, storm::expressions::Expression> const& getLabelToExpressionMap() const;
private:
// The manager responsible for the decision diagrams.
std::shared_ptr<storm::dd::DdManager<Type>> manager;
// A vector representing the reachable states of the model.
storm::dd::Dd<Type> reachableStates;
// A vector representing the initial states of the model.
storm::dd::Dd<Type> initialStates;
// A matrix representing transition relation.
storm::dd::Dd<Type> transitionMatrix;
// The meta variables used to encode the rows of the transition matrix.
std::set<storm::expressions::Variable> rowVariables;
// An adapter that can translate expressions to DDs over the row meta variables.
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter;
// The meta variables used to encode the columns of the transition matrix.
std::set<storm::expressions::Variable> columnVariables;
// An adapter that can translate expressions to DDs over the column meta variables.
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter;
// A vector holding all pairs of row and column meta variable pairs. This is used to swap the variables
// in the DDs from row to column variables and vice versa.
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> rowColumnMetaVariablePairs;
// A mapping from labels to expressions defining them.
std::map<std::string, storm::expressions::Expression> labelToExpressionMap;
// If set, a vector representing the rewards of the states.
boost::optional<storm::dd::Dd<Type>> stateRewardVector;
// If set, a matrix representing the rewards of transitions.
boost::optional<storm::dd::Dd<Type>> transitionRewardMatrix;
};
} // namespace symbolic
} // namespace models
} // namespace storm
#endif /* STORM_MODELS_SYMBOLIC_MODEL_H_ */

60
src/models/symbolic/NondeterministicModel.cpp

@ -0,0 +1,60 @@
#include "src/models/symbolic/NondeterministicModel.h"
namespace storm {
namespace models {
namespace symbolic {
template<storm::dd::DdType Type>
NondeterministicModel<Type>::NondeterministicModel(storm::models::ModelType const& modelType,
std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::set<storm::expressions::Variable> const& nondeterminismVariables,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector,
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix)
: Model<Type>(modelType, manager, reachableStates, initialStates, transitionMatrix, rowVariables, rowExpressionAdapter, columnVariables, columnExpressionAdapter, rowColumnMetaVariablePairs, labelToExpressionMap, optionalStateRewardVector, optionalTransitionRewardMatrix), nondeterminismVariables(nondeterminismVariables) {
// Intentionally left empty.
}
template<storm::dd::DdType Type>
uint_fast64_t NondeterministicModel<Type>::getNumberOfChoices() const {
std::set<storm::expressions::Variable> rowAndNondeterminsmVariables;
std::set_union(this->getNondeterminismVariables().begin(), this->getNondeterminismVariables().end(), this->getRowVariables().begin(), this->getRowVariables().end(), std::inserter(rowAndNondeterminsmVariables, rowAndNondeterminsmVariables.begin()));
storm::dd::Dd<Type> tmp = this->getTransitionMatrix().notZero().existsAbstract(this->getColumnVariables()).sumAbstract(rowAndNondeterminsmVariables);
return static_cast<uint_fast64_t>(tmp.getValue());
}
template<storm::dd::DdType Type>
std::set<storm::expressions::Variable> const& NondeterministicModel<Type>::getNondeterminismVariables() const {
return nondeterminismVariables;
}
template<storm::dd::DdType Type>
void NondeterministicModel<Type>::printModelInformationToStream(std::ostream& out) const {
out << "-------------------------------------------------------------- " << std::endl;
out << "Model type: \t\t" << this->getType() << " (symbolic)" << std::endl;
out << "States: \t\t" << this->getNumberOfStates() << " (" << this->getReachableStates().getNodeCount() << " nodes)" << std::endl;
out << "Transitions: \t\t" << this->getNumberOfTransitions() << " (" << this->getTransitionMatrix().getNodeCount() << " nodes)" << std::endl;
out << "Choices: \t\t" << this->getNumberOfChoices() << std::endl;
out << "Variables: \t\t" << "rows:" << this->getRowVariables().size() << ", columns: " << this->getColumnVariables().size() << ", nondeterminism: " << this->getNondeterminismVariables().size() << std::endl;
for (auto const& label : this->getLabelToExpressionMap()) {
out << "\t" << label.first << std::endl;
}
out << "Size in memory: \t" << (this->getSizeInBytes())/1024 << " kbytes" << std::endl;
out << "-------------------------------------------------------------- " << std::endl;
}
// Explicitly instantiate the template class.
template class NondeterministicModel<storm::dd::DdType::CUDD>;
} // namespace symbolic
} // namespace models
} // namespace storm

86
src/models/symbolic/NondeterministicModel.h

@ -0,0 +1,86 @@
#ifndef STORM_MODELS_SYMBOLIC_NONDETERMINISTICMODEL_H_
#define STORM_MODELS_SYMBOLIC_NONDETERMINISTICMODEL_H_
#include "src/models/symbolic/Model.h"
#include "src/utility/OsDetection.h"
namespace storm {
namespace models {
namespace symbolic {
/*!
* Base class for all nondeterministic symbolic models.
*/
template<storm::dd::DdType Type>
class NondeterministicModel : public Model<Type> {
public:
NondeterministicModel(NondeterministicModel<Type> const& other) = default;
NondeterministicModel& operator=(NondeterministicModel<Type> const& other) = default;
#ifndef WINDOWS
NondeterministicModel(NondeterministicModel<Type>&& other) = default;
NondeterministicModel& operator=(NondeterministicModel<Type>&& other) = default;
#endif
/*!
* Constructs a model from the given data.
*
* @param modelType The type of the model.
* @param manager The manager responsible for the decision diagrams.
* @param reachableStates A DD representing the reachable states.
* @param initialStates A DD representing the initial states of the model.
* @param transitionMatrix The matrix representing the transitions in the model.
* @param rowVariables The set of row meta variables used in the DDs.
* @param rowExpressionAdapter An object that can be used to translate expressions in terms of the row
* meta variables.
* @param columVariables The set of column meta variables used in the DDs.
* @param columnExpressionAdapter An object that can be used to translate expressions in terms of the
* column meta variables.
* @param rowColumnMetaVariablePairs All pairs of row/column meta variables.
* @param nondeterminismVariables The meta variables used to encode the nondeterminism in the model.
* @param labelToExpressionMap A mapping from label names to their defining expressions.
* @param optionalStateRewardVector The reward values associated with the states
* @param optionalTransitionRewardMatrix The reward values associated with the transitions of the model.
*/
NondeterministicModel(storm::models::ModelType const& modelType,
std::shared_ptr<storm::dd::DdManager<Type>> manager,
storm::dd::Dd<Type> reachableStates,
storm::dd::Dd<Type> initialStates,
storm::dd::Dd<Type> transitionMatrix,
std::set<storm::expressions::Variable> const& rowVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> rowExpressionAdapter,
std::set<storm::expressions::Variable> const& columnVariables,
std::shared_ptr<storm::adapters::DdExpressionAdapter<Type>> columnExpressionAdapter,
std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
std::set<storm::expressions::Variable> const& nondeterminismVariables,
std::map<std::string, storm::expressions::Expression> labelToExpressionMap = std::map<std::string, storm::expressions::Expression>(),
boost::optional<storm::dd::Dd<Type>> const& optionalStateRewardVector = boost::optional<storm::dd::Dd<Type>>(),
boost::optional<storm::dd::Dd<Type>> const& optionalTransitionRewardMatrix = boost::optional<storm::dd::Dd<Type>>());
/*!
* Retrieves the number of nondeterministic choices in the model.
*
* @return The number of nondeterministic choices in the model.
*/
uint_fast64_t getNumberOfChoices() const;
/*!
* Retrieves the meta variables used to encode the nondeterminism in the model.
*
* @return The meta variables used to encode the nondeterminism in the model.
*/
std::set<storm::expressions::Variable> const& getNondeterminismVariables() const;
virtual void printModelInformationToStream(std::ostream& out) const override;
private:
// The meta variables encoding the nondeterminism in the model.
std::set<storm::expressions::Variable> nondeterminismVariables;
};
} // namespace symbolic
} // namespace models
} // namespace storm
#endif /* STORM_MODELS_SYMBOLIC_NONDETERMINISTICMODEL_H_ */

82
test/functional/builder/DdPrismModelBuilderTest.cpp

@ -1,8 +1,8 @@
#include "gtest/gtest.h"
#include "storm-config.h"
#include <utility>
#include "src/models/symbolic/Dtmc.h"
#include "src/models/symbolic/Mdp.h"
#include "src/storage/dd/CuddDd.h"
#include "src/parser/PrismParser.h"
#include "src/builder/DdPrismModelBuilder.h"
@ -10,59 +10,89 @@
TEST(DdPrismModelBuilderTest, Dtmc) {
storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
std::pair<storm::dd::Dd<storm::dd::DdType::CUDD>, storm::dd::Dd<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(13, model.first.getNonZeroCount());
EXPECT_EQ(20, model.second.getNonZeroCount());
std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(13, model->getNumberOfStates());
EXPECT_EQ(20, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(677, model.first.getNonZeroCount());
EXPECT_EQ(867, model.second.getNonZeroCount());
EXPECT_EQ(677, model->getNumberOfStates());
EXPECT_EQ(867, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(8607, model.first.getNonZeroCount());
EXPECT_EQ(15113, model.second.getNonZeroCount());
EXPECT_EQ(8607, model->getNumberOfStates());
EXPECT_EQ(15113, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(273, model.first.getNonZeroCount());
EXPECT_EQ(397, model.second.getNonZeroCount());
EXPECT_EQ(273, model->getNumberOfStates());
EXPECT_EQ(397, model->getNumberOfTransitions());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(1728, model.first.getNonZeroCount());
EXPECT_EQ(2505, model.second.getNonZeroCount());
EXPECT_EQ(1728, model->getNumberOfStates());
EXPECT_EQ(2505, model->getNumberOfTransitions());
}
TEST(DdPrismModelBuilderTest, Mdp) {
storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
std::pair<storm::dd::Dd<storm::dd::DdType::CUDD>, storm::dd::Dd<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(169, model.first.getNonZeroCount());
EXPECT_EQ(436, model.second.getNonZeroCount());
std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
std::shared_ptr<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>> mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
EXPECT_EQ(169, mdp->getNumberOfStates());
EXPECT_EQ(436, mdp->getNumberOfTransitions());
EXPECT_EQ(254, mdp->getNumberOfChoices());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(364, model.first.getNonZeroCount());
EXPECT_EQ(654, model.second.getNonZeroCount());
EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
EXPECT_EQ(364, mdp->getNumberOfStates());
EXPECT_EQ(654, mdp->getNumberOfTransitions());
EXPECT_EQ(573, mdp->getNumberOfChoices());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(272, model.first.getNonZeroCount());
EXPECT_EQ(492, model.second.getNonZeroCount());
EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
EXPECT_EQ(272, mdp->getNumberOfStates());
EXPECT_EQ(492, mdp->getNumberOfTransitions());
EXPECT_EQ(400, mdp->getNumberOfChoices());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(1038, model.first.getNonZeroCount());
EXPECT_EQ(1282, model.second.getNonZeroCount());
EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
EXPECT_EQ(1038, mdp->getNumberOfStates());
EXPECT_EQ(1282, mdp->getNumberOfTransitions());
EXPECT_EQ(1054, mdp->getNumberOfChoices());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(4093, model.first.getNonZeroCount());
EXPECT_EQ(5585, model.second.getNonZeroCount());
EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
EXPECT_EQ(4093, mdp->getNumberOfStates());
EXPECT_EQ(5585, mdp->getNumberOfTransitions());
EXPECT_EQ(5519, mdp->getNumberOfChoices());
program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
EXPECT_EQ(37, model.first.getNonZeroCount());
EXPECT_EQ(59, model.second.getNonZeroCount());
EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
EXPECT_EQ(37, mdp->getNumberOfStates());
EXPECT_EQ(59, mdp->getNumberOfTransitions());
EXPECT_EQ(59, mdp->getNumberOfChoices());
}
Loading…
Cancel
Save