3#include <boost/algorithm/string/join.hpp>
24template<storm::dd::DdType Type,
typename ValueType>
29 std::set<storm::expressions::Variable>
const& columnVariables,
30 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>>
const& rowColumnMetaVariablePairs,
31 std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
32 std::unordered_map<std::string, RewardModelType>
const& rewardModels)
35 reachableStates(reachableStates),
36 transitionMatrix(transitionMatrix),
37 rowVariables(rowVariables),
38 rowExpressionAdapter(rowExpressionAdapter),
39 columnVariables(columnVariables),
40 rowColumnMetaVariablePairs(rowColumnMetaVariablePairs),
41 labelToExpressionMap(labelToExpressionMap),
42 rewardModels(rewardModels) {
43 this->labelToBddMap.emplace(
"init", initialStates);
44 this->labelToBddMap.emplace(
"deadlock", deadlockStates);
47template<storm::dd::DdType Type,
typename ValueType>
51 std::set<storm::expressions::Variable>
const& columnVariables,
52 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>>
const& rowColumnMetaVariablePairs,
53 std::map<std::string,
storm::dd::Bdd<Type>> labelToBddMap, std::unordered_map<std::string, RewardModelType>
const& rewardModels)
56 reachableStates(reachableStates),
57 transitionMatrix(transitionMatrix),
58 rowVariables(rowVariables),
59 rowExpressionAdapter(nullptr),
60 columnVariables(columnVariables),
61 rowColumnMetaVariablePairs(rowColumnMetaVariablePairs),
62 labelToBddMap(labelToBddMap),
63 rewardModels(rewardModels) {
64 STORM_LOG_THROW(this->labelToBddMap.find(
"init") == this->labelToBddMap.end(), storm::exceptions::WrongFormatException,
"Illegal custom label 'init'.");
65 STORM_LOG_THROW(this->labelToBddMap.find(
"deadlock") == this->labelToBddMap.end(), storm::exceptions::WrongFormatException,
66 "Illegal custom label 'deadlock'.");
67 this->labelToBddMap.emplace(
"init", initialStates);
68 this->labelToBddMap.emplace(
"deadlock", deadlockStates);
71template<storm::dd::DdType Type,
typename ValueType>
73 return reachableStates.getNonZeroCount();
76template<storm::dd::DdType Type,
typename ValueType>
78 return transitionMatrix.getNonZeroCount();
81template<storm::dd::DdType Type,
typename ValueType>
83 return reachableStates.getNonZeroCount();
86template<storm::dd::DdType Type,
typename ValueType>
91template<storm::dd::DdType Type,
typename ValueType>
96template<storm::dd::DdType Type,
typename ValueType>
98 return reachableStates;
101template<storm::dd::DdType Type,
typename ValueType>
103 return labelToBddMap.at(
"init");
106template<storm::dd::DdType Type,
typename ValueType>
108 return labelToBddMap.at(
"deadlock");
111template<storm::dd::DdType Type,
typename ValueType>
114 auto bddIt = labelToBddMap.find(label);
115 if (bddIt != labelToBddMap.end()) {
116 return bddIt->second;
119 auto expressionIt = labelToExpressionMap.find(label);
120 STORM_LOG_THROW(expressionIt != labelToExpressionMap.end(), storm::exceptions::IllegalArgumentException,
121 "The label " << label <<
" is invalid for the labeling of the model.");
122 return this->getStates(expressionIt->second);
126template<storm::dd::DdType Type,
typename ValueType>
128 auto expressionIt = labelToExpressionMap.find(label);
129 STORM_LOG_THROW(expressionIt != labelToExpressionMap.end(), storm::exceptions::IllegalArgumentException,
130 "Cannot retrieve the expression for the label " << label <<
".");
131 return expressionIt->second;
134template<storm::dd::DdType Type,
typename ValueType>
136 if (expression.
isTrue()) {
137 return this->getReachableStates();
138 }
else if (expression.
isFalse()) {
139 return manager->getBddZero();
143 std::stringstream stream;
144 stream << expression;
145 auto bddIt = labelToBddMap.find(stream.str());
146 if (bddIt != labelToBddMap.end()) {
147 return bddIt->second;
151 STORM_LOG_THROW(rowExpressionAdapter !=
nullptr, storm::exceptions::InvalidOperationException,
152 "Cannot create BDD for expression without expression adapter.");
153 return rowExpressionAdapter->translateExpression(expression).toBdd() && this->reachableStates;
156template<storm::dd::DdType Type,
typename ValueType>
158 auto bddIt = labelToBddMap.find(label);
159 if (bddIt != labelToBddMap.end()) {
163 auto expressionIt = labelToExpressionMap.find(label);
164 if (expressionIt != labelToExpressionMap.end()) {
171template<storm::dd::DdType Type,
typename ValueType>
173 return transitionMatrix;
176template<storm::dd::DdType Type,
typename ValueType>
178 return transitionMatrix;
181template<storm::dd::DdType Type,
typename ValueType>
183 return this->getTransitionMatrix().notZero();
186template<storm::dd::DdType Type,
typename ValueType>
191template<storm::dd::DdType Type,
typename ValueType>
193 return columnVariables;
196template<storm::dd::DdType Type,
typename ValueType>
198 std::set<storm::expressions::Variable> result;
199 std::set_union(this->getRowVariables().begin(), this->getRowVariables().end(), this->getNondeterminismVariables().begin(),
200 this->getNondeterminismVariables().end(), std::inserter(result, result.begin()));
204template<storm::dd::DdType Type,
typename ValueType>
206 std::set<storm::expressions::Variable> result;
207 std::set_union(this->getColumnVariables().begin(), this->getColumnVariables().end(), this->getNondeterminismVariables().begin(),
208 this->getNondeterminismVariables().end(), std::inserter(result, result.begin()));
212template<storm::dd::DdType Type,
typename ValueType>
214 return emptyVariableSet;
217template<storm::dd::DdType Type,
typename ValueType>
219 return rowColumnMetaVariablePairs;
222template<storm::dd::DdType Type,
typename ValueType>
224 return labelToExpressionMap;
227template<storm::dd::DdType Type,
typename ValueType>
229 return labelToBddMap;
232template<storm::dd::DdType Type,
typename ValueType>
234 return (storm::utility::dd::getRowColumnDiagonal<Type>(this->getManager(), this->getRowColumnMetaVariablePairs()) && this->getReachableStates())
235 .template toAdd<ValueType>();
238template<storm::dd::DdType Type,
typename ValueType>
240 return this->rewardModels.find(rewardModelName) != this->rewardModels.end();
243template<storm::dd::DdType Type,
typename ValueType>
245 auto it = this->rewardModels.find(rewardModelName);
246 if (it == this->rewardModels.end()) {
247 if (rewardModelName.empty()) {
248 if (this->hasUniqueRewardModel()) {
249 return this->getUniqueRewardModel();
252 "Unable to refer to default reward model, because there is no default model or it is not unique.");
255 STORM_LOG_THROW(
false, storm::exceptions::IllegalArgumentException,
"The requested reward model '" << rewardModelName <<
"' does not exist.");
261template<storm::dd::DdType Type,
typename ValueType>
263 STORM_LOG_THROW(this->hasUniqueRewardModel(), storm::exceptions::InvalidOperationException,
264 "Cannot retrieve unique reward model, because there is no unique one.");
265 return this->rewardModels.cbegin()->second;
268template<storm::dd::DdType Type,
typename ValueType>
270 STORM_LOG_THROW(this->hasUniqueRewardModel(), storm::exceptions::InvalidOperationException,
271 "Cannot retrieve name of unique reward model, because there is no unique one.");
272 return this->rewardModels.cbegin()->first;
275template<storm::dd::DdType Type,
typename ValueType>
277 STORM_LOG_THROW(this->hasUniqueRewardModel(), storm::exceptions::InvalidOperationException,
278 "Cannot retrieve unique reward model, because there is no unique one.");
279 return this->rewardModels.begin()->second;
282template<storm::dd::DdType Type,
typename ValueType>
284 return this->rewardModels.size() == 1;
287template<storm::dd::DdType Type,
typename ValueType>
289 return !this->rewardModels.empty();
292template<storm::dd::DdType Type,
typename ValueType>
294 return this->rewardModels;
297template<storm::dd::DdType Type,
typename ValueType>
299 return this->rewardModels;
302template<storm::dd::DdType Type,
typename ValueType>
304 this->printModelInformationHeaderToStream(out);
305 this->printModelInformationFooterToStream(out);
308template<storm::dd::DdType Type,
typename ValueType>
310 std::vector<std::string> labels;
311 for (
auto const& entry : labelToExpressionMap) {
312 labels.push_back(entry.first);
317template<storm::dd::DdType Type,
typename ValueType>
319 out <<
"-------------------------------------------------------------- \n";
320 out <<
"Model type: \t" << this->getType() <<
" (symbolic)\n";
321 out <<
"States: \t" << this->getNumberOfStates() <<
" (" << reachableStates.getNodeCount() <<
" nodes)\n";
322 out <<
"Transitions: \t" << this->getNumberOfTransitions() <<
" (" << transitionMatrix.getNodeCount() <<
" nodes)\n";
325template<storm::dd::DdType Type,
typename ValueType>
327 this->printRewardModelsInformationToStream(out);
328 this->printDdVariableInformationToStream(out);
329 out <<
"\nLabels: \t" << (this->labelToExpressionMap.size() + this->labelToBddMap.size()) <<
'\n';
330 for (
auto const& label : labelToBddMap) {
331 out <<
" * " << label.first <<
" -> " << label.second.getNonZeroCount() <<
" state(s) (" << label.second.getNodeCount() <<
" nodes)\n";
333 for (
auto const& label : labelToExpressionMap) {
334 out <<
" * " << label.first <<
'\n';
336 out <<
"-------------------------------------------------------------- \n";
339template<storm::dd::DdType Type,
typename ValueType>
341 if (this->rewardModels.size()) {
342 std::vector<std::string> rewardModelNames;
343 std::for_each(this->rewardModels.cbegin(), this->rewardModels.cend(),
344 [&rewardModelNames](
typename std::pair<std::string, RewardModelType>
const& nameRewardModelPair) {
345 if (nameRewardModelPair.first.empty()) {
346 rewardModelNames.push_back(
"(default)");
348 rewardModelNames.push_back(nameRewardModelPair.first);
351 out <<
"Reward Models: " << boost::join(rewardModelNames,
", ") <<
'\n';
353 out <<
"Reward Models: none\n";
357template<storm::dd::DdType Type,
typename ValueType>
359 uint_fast64_t rowVariableCount = 0;
360 for (
auto const& metaVariable : this->rowVariables) {
361 rowVariableCount += this->getManager().getMetaVariable(metaVariable).getNumberOfDdVariables();
363 uint_fast64_t columnVariableCount = 0;
364 for (
auto const& metaVariable : this->columnVariables) {
365 columnVariableCount += this->getManager().getMetaVariable(metaVariable).getNumberOfDdVariables();
368 out <<
"Variables: \t" <<
"rows: " << this->rowVariables.size() <<
" meta variables (" << rowVariableCount <<
" DD variables)"
369 <<
", columns: " << this->columnVariables.size() <<
" meta variables (" << columnVariableCount <<
" DD variables)";
372template<storm::dd::DdType Type,
typename ValueType>
374 return this->rowExpressionAdapter;
377template<storm::dd::DdType Type,
typename ValueType>
382template<storm::dd::DdType Type,
typename ValueType>
387template<storm::dd::DdType Type,
typename ValueType>
392template<storm::dd::DdType Type,
typename ValueType>
394 return std::is_same<ValueType, storm::RationalFunction>::value;
397template<storm::dd::DdType Type,
typename ValueType>
399 this->getTransitionMatrix().exportToDot(filename,
true);
400 this->getInitialStates().exportToDot(filename,
true);
401 for (
auto const& lab : this->getLabels()) {
402 this->getStates(lab).exportToDot(filename,
true);
406template<storm::dd::DdType Type,
typename ValueType>
408 if (!this->supportsParameters()) {
412 for (
auto it = this->getTransitionMatrix().begin(
false); it != this->getTransitionMatrix().end(); ++it) {
421template<storm::dd::DdType Type,
typename ValueType>
423 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"This value type does not support parameters.");
426template<storm::dd::DdType Type,
typename ValueType>
428 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"This value type does not support parameters.");
433 this->parameters.insert(parameters.begin(), parameters.end());
441template<storm::dd::DdType Type,
typename ValueType>
442template<
typename NewValueType>
445 STORM_LOG_TRACE(
"Converting value type of symbolic model from " <<
typeid(
ValueType).name() <<
" to " <<
typeid(NewValueType).name() <<
".");
449 return this->
template as<storm::models::symbolic::Dtmc<Type, ValueType>>()->
template toValueType<NewValueType>();
451 return this->
template as<storm::models::symbolic::Ctmc<Type, ValueType>>()->
template toValueType<NewValueType>();
453 return this->
template as<storm::models::symbolic::Mdp<Type, ValueType>>()->
template toValueType<NewValueType>();
455 return this->
template as<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>()->
template toValueType<NewValueType>();
457 return this->
template as<storm::models::symbolic::StochasticTwoPlayerGame<Type, ValueType>>()->
template toValueType<NewValueType>();
464template<storm::dd::DdType Type,
typename ValueType>
465template<
typename NewValueType>
470 return std::make_shared<storm::models::symbolic::Dtmc<Type, ValueType>>(*this->
template as<storm::models::symbolic::Dtmc<Type, ValueType>>());
472 return std::make_shared<storm::models::symbolic::Ctmc<Type, ValueType>>(*this->
template as<storm::models::symbolic::Ctmc<Type, ValueType>>());
474 return std::make_shared<storm::models::symbolic::Mdp<Type, ValueType>>(*this->
template as<storm::models::symbolic::Mdp<Type, ValueType>>());
476 return std::make_shared<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>(
477 *this->
template as<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>());
479 return std::make_shared<storm::models::symbolic::StochasticTwoPlayerGame<Type, ValueType>>(
480 *this->
template as<storm::models::symbolic::StochasticTwoPlayerGame<Type, ValueType>>());
488template class Model<storm::dd::DdType::CUDD, double>;
489template typename std::enable_if<std::is_same<double, double>::value, std::shared_ptr<Model<storm::dd::DdType::CUDD, double>>>::type
490Model<storm::dd::DdType::CUDD, double>::toValueType<double>()
const;
492template class Model<storm::dd::DdType::Sylvan, double>;
493template class Model<storm::dd::DdType::Sylvan, storm::RationalNumber>;
494template typename std::enable_if<std::is_same<double, double>::value, std::shared_ptr<Model<storm::dd::DdType::Sylvan, double>>>::type
495Model<storm::dd::DdType::Sylvan, double>::toValueType<double>()
const;
496template typename std::enable_if<std::is_same<storm::RationalNumber, storm::RationalNumber>::value,
497 std::shared_ptr<Model<storm::dd::DdType::Sylvan, storm::RationalNumber>>>::type
498Model<storm::dd::DdType::Sylvan, storm::RationalNumber>::toValueType<storm::RationalNumber>()
const;
499template typename std::enable_if<std::is_same<storm::RationalFunction, storm::RationalFunction>::value,
500 std::shared_ptr<Model<storm::dd::DdType::Sylvan, storm::RationalFunction>>>::type
501Model<storm::dd::DdType::Sylvan, storm::RationalFunction>::toValueType<storm::RationalFunction>()
const;
502template typename std::enable_if<!std::is_same<storm::RationalNumber, double>::value, std::shared_ptr<Model<storm::dd::DdType::Sylvan, double>>>::type
503Model<storm::dd::DdType::Sylvan, storm::RationalNumber>::toValueType<double>()
const;
504template class Model<storm::dd::DdType::Sylvan, storm::RationalFunction>;
bool isFalse() const
Checks if the expression is equal to the boolean literal false.
bool isTrue() const
Checks if the expression is equal to the boolean literal true.
virtual bool isExact() const
Checks whether the model is exact.
virtual bool isSymbolicModel() const
Checks whether the model is a symbolic model.
virtual std::optional< storm::dd::DdType > getDdType() const
virtual bool hasParameters() const
Checks whether the model has parameters.
virtual bool supportsParameters() const
Checks whether the model supports parameters.
Base class for all symbolic models.
storm::dd::DdManager< Type > & getManager() const
Retrieves the manager responsible for the DDs that represent this model.
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
storm::dd::Add< Type, ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
storm::dd::Bdd< Type > const & getDeadlockStates() const
virtual void printModelInformationToStream(std::ostream &out) const override
Prints information about the model to the specified stream.
virtual storm::expressions::Expression getExpression(std::string const &label) const
Returns the expression for the given label.
RewardModelType const & getUniqueRewardModel() const
Retrieves the unique reward model, if there exists exactly one.
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
virtual storm::dd::Bdd< Type > getQualitativeTransitionMatrix(bool keepNondeterminism=true) const
Retrieves the matrix qualitatively (i.e.
std::set< storm::expressions::Variable > const & getColumnVariables() const
Retrieves the meta variables used to encode the columns of the transition matrix and the vector indic...
std::shared_ptr< storm::dd::DdManager< Type > > const & getManagerAsSharedPointer() const
Retrieves the manager responsible for the DDs that represent this model.
Model(Model< Type, ValueType > const &other)=default
std::vector< std::string > getLabels() const
storm::dd::Add< Type, ValueType > getRowColumnIdentity() const
Retrieves an ADD that represents the diagonal of the transition matrix.
void printRewardModelsInformationToStream(std::ostream &out) const
Prints information about the reward models to the specified stream.
std::map< std::string, storm::dd::Bdd< Type > > const & getLabelToBddMap() const
Retrieves the mapping of labels to their defining expressions.
storm::dd::Bdd< Type > const & getInitialStates() const
Retrieves the initial states of the model.
virtual std::set< storm::expressions::Variable > const & getNondeterminismVariables() const
Retrieves all meta variables used to encode the nondeterminism.
void printModelInformationFooterToStream(std::ostream &out) const
Prints the information footer (reward models, labels) of the model to the specified stream.
std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const & getRowColumnMetaVariablePairs() const
Retrieves the pairs of row and column meta variables.
std::set< storm::expressions::Variable > const & getRowVariables() const
Retrieves the meta variables used to encode the rows of the transition matrix and the vector indices.
virtual bool hasLabel(std::string const &label) const
Retrieves whether the given label is a valid label in this model.
std::map< std::string, storm::expressions::Expression > const & getLabelToExpressionMap() const
Retrieves the mapping of labels to their defining expressions.
void printModelInformationHeaderToStream(std::ostream &out) const
Prints the information header (number of states and transitions) of the model to the specified stream...
std::unordered_map< std::string, RewardModelType > & getRewardModels()
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
std::set< storm::expressions::Variable > getRowAndNondeterminismVariables() const
Retrieves all meta variables used to encode rows and nondetermism.
std::set< storm::expressions::Variable > getColumnAndNondeterminismVariables() const
Retrieves all meta variables used to encode columns and nondetermism.
virtual storm::dd::Bdd< Type > getStates(std::string const &label) const
Returns the sets of states labeled with the given label.
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
bool hasRewardModel() const
Retrieves whether the model has at least one reward model.
virtual bool hasUniqueRewardModel() const override
Retrieves whether the model has a unique reward model.
storm::dd::Bdd< Type > const & getReachableStates() const
Retrieves the reachable states of the model.
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
#define STORM_LOG_WARN(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_THROW(cond, exception, message)
bool isConstant(ValueType const &)