3#include <boost/algorithm/string/join.hpp>
26template<storm::dd::DdType Type,
typename ValueType>
31 std::set<storm::expressions::Variable>
const& columnVariables,
32 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>>
const& rowColumnMetaVariablePairs,
33 std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
34 std::unordered_map<std::string, RewardModelType>
const& rewardModels)
37 reachableStates(reachableStates),
39 rowVariables(rowVariables),
40 rowExpressionAdapter(rowExpressionAdapter),
41 columnVariables(columnVariables),
42 rowColumnMetaVariablePairs(rowColumnMetaVariablePairs),
43 labelToExpressionMap(labelToExpressionMap),
44 rewardModels(rewardModels) {
45 this->labelToBddMap.emplace(
"init", initialStates);
46 this->labelToBddMap.emplace(
"deadlock", deadlockStates);
49template<storm::dd::DdType Type,
typename ValueType>
53 std::set<storm::expressions::Variable>
const& columnVariables,
54 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>>
const& rowColumnMetaVariablePairs,
55 std::map<std::string,
storm::dd::Bdd<Type>> labelToBddMap, std::unordered_map<std::string, RewardModelType>
const& rewardModels)
58 reachableStates(reachableStates),
60 rowVariables(rowVariables),
61 rowExpressionAdapter(nullptr),
62 columnVariables(columnVariables),
63 rowColumnMetaVariablePairs(rowColumnMetaVariablePairs),
64 labelToBddMap(labelToBddMap),
65 rewardModels(rewardModels) {
66 STORM_LOG_THROW(this->labelToBddMap.find(
"init") == this->labelToBddMap.end(), storm::exceptions::WrongFormatException,
"Illegal custom label 'init'.");
67 STORM_LOG_THROW(this->labelToBddMap.find(
"deadlock") == this->labelToBddMap.end(), storm::exceptions::WrongFormatException,
68 "Illegal custom label 'deadlock'.");
69 this->labelToBddMap.emplace(
"init", initialStates);
70 this->labelToBddMap.emplace(
"deadlock", deadlockStates);
73template<storm::dd::DdType Type,
typename ValueType>
75 return reachableStates.getNonZeroCount();
78template<storm::dd::DdType Type,
typename ValueType>
83template<storm::dd::DdType Type,
typename ValueType>
85 return reachableStates.getNonZeroCount();
88template<storm::dd::DdType Type,
typename ValueType>
93template<storm::dd::DdType Type,
typename ValueType>
98template<storm::dd::DdType Type,
typename ValueType>
100 return reachableStates;
103template<storm::dd::DdType Type,
typename ValueType>
105 return labelToBddMap.at(
"init");
108template<storm::dd::DdType Type,
typename ValueType>
110 return labelToBddMap.at(
"deadlock");
113template<storm::dd::DdType Type,
typename ValueType>
116 auto bddIt = labelToBddMap.find(label);
117 if (bddIt != labelToBddMap.end()) {
118 return bddIt->second;
121 auto expressionIt = labelToExpressionMap.find(label);
122 STORM_LOG_THROW(expressionIt != labelToExpressionMap.end(), storm::exceptions::IllegalArgumentException,
123 "The label " << label <<
" is invalid for the labeling of the model.");
124 return this->
getStates(expressionIt->second);
128template<storm::dd::DdType Type,
typename ValueType>
130 auto expressionIt = labelToExpressionMap.find(label);
131 STORM_LOG_THROW(expressionIt != labelToExpressionMap.end(), storm::exceptions::IllegalArgumentException,
132 "Cannot retrieve the expression for the label " << label <<
".");
133 return expressionIt->second;
136template<storm::dd::DdType Type,
typename ValueType>
138 if (expression.
isTrue()) {
140 }
else if (expression.
isFalse()) {
141 return manager->getBddZero();
145 std::stringstream stream;
146 stream << expression;
147 auto bddIt = labelToBddMap.find(stream.str());
148 if (bddIt != labelToBddMap.end()) {
149 return bddIt->second;
153 STORM_LOG_THROW(rowExpressionAdapter !=
nullptr, storm::exceptions::InvalidOperationException,
154 "Cannot create BDD for expression without expression adapter.");
155 return rowExpressionAdapter->translateExpression(expression).toBdd() && this->reachableStates;
158template<storm::dd::DdType Type,
typename ValueType>
160 auto bddIt = labelToBddMap.find(label);
161 if (bddIt != labelToBddMap.end()) {
165 auto expressionIt = labelToExpressionMap.find(label);
166 if (expressionIt != labelToExpressionMap.end()) {
173template<storm::dd::DdType Type,
typename ValueType>
178template<storm::dd::DdType Type,
typename ValueType>
183template<storm::dd::DdType Type,
typename ValueType>
185 return this->getTransitionMatrix().notZero();
188template<storm::dd::DdType Type,
typename ValueType>
193template<storm::dd::DdType Type,
typename ValueType>
195 return columnVariables;
198template<storm::dd::DdType Type,
typename ValueType>
200 std::set<storm::expressions::Variable> result;
206template<storm::dd::DdType Type,
typename ValueType>
208 std::set<storm::expressions::Variable> result;
214template<storm::dd::DdType Type,
typename ValueType>
216 return emptyVariableSet;
219template<storm::dd::DdType Type,
typename ValueType>
221 return rowColumnMetaVariablePairs;
224template<storm::dd::DdType Type,
typename ValueType>
226 return labelToExpressionMap;
229template<storm::dd::DdType Type,
typename ValueType>
231 return labelToBddMap;
234template<storm::dd::DdType Type,
typename ValueType>
237 .template toAdd<ValueType>();
240template<storm::dd::DdType Type,
typename ValueType>
242 return this->rewardModels.find(rewardModelName) != this->rewardModels.end();
245template<storm::dd::DdType Type,
typename ValueType>
247 auto it = this->rewardModels.find(rewardModelName);
248 if (it == this->rewardModels.end()) {
249 if (rewardModelName.empty()) {
254 "Unable to refer to default reward model, because there is no default model or it is not unique.");
257 STORM_LOG_THROW(
false, storm::exceptions::IllegalArgumentException,
"The requested reward model '" << rewardModelName <<
"' does not exist.");
263template<storm::dd::DdType Type,
typename ValueType>
266 "Cannot retrieve unique reward model, because there is no unique one.");
267 return this->rewardModels.cbegin()->second;
270template<storm::dd::DdType Type,
typename ValueType>
273 "Cannot retrieve name of unique reward model, because there is no unique one.");
274 return this->rewardModels.cbegin()->first;
277template<storm::dd::DdType Type,
typename ValueType>
280 "Cannot retrieve unique reward model, because there is no unique one.");
281 return this->rewardModels.begin()->second;
284template<storm::dd::DdType Type,
typename ValueType>
286 return this->rewardModels.size() == 1;
289template<storm::dd::DdType Type,
typename ValueType>
291 return !this->rewardModels.empty();
294template<storm::dd::DdType Type,
typename ValueType>
296 return this->rewardModels;
299template<storm::dd::DdType Type,
typename ValueType>
301 return this->rewardModels;
304template<storm::dd::DdType Type,
typename ValueType>
310template<storm::dd::DdType Type,
typename ValueType>
312 std::vector<std::string> labels;
313 for (
auto const& entry : labelToExpressionMap) {
314 labels.push_back(entry.first);
319template<storm::dd::DdType Type,
typename ValueType>
321 out <<
"-------------------------------------------------------------- \n";
323 out <<
"States: \t" << this->
getNumberOfStates() <<
" (" << reachableStates.getNodeCount() <<
" nodes)\n";
327template<storm::dd::DdType Type,
typename ValueType>
331 out <<
"\nLabels: \t" << (this->labelToExpressionMap.size() + this->labelToBddMap.size()) <<
'\n';
332 for (
auto const& label : labelToBddMap) {
333 out <<
" * " << label.first <<
" -> " << label.second.getNonZeroCount() <<
" state(s) (" << label.second.getNodeCount() <<
" nodes)\n";
335 for (
auto const& label : labelToExpressionMap) {
336 out <<
" * " << label.first <<
'\n';
338 out <<
"-------------------------------------------------------------- \n";
341template<storm::dd::DdType Type,
typename ValueType>
343 if (this->rewardModels.size()) {
344 std::vector<std::string> rewardModelNames;
345 std::for_each(this->rewardModels.cbegin(), this->rewardModels.cend(),
346 [&rewardModelNames](
typename std::pair<std::string, RewardModelType>
const& nameRewardModelPair) {
347 if (nameRewardModelPair.first.empty()) {
348 rewardModelNames.push_back(
"(default)");
350 rewardModelNames.push_back(nameRewardModelPair.first);
353 out <<
"Reward Models: " << boost::join(rewardModelNames,
", ") <<
'\n';
355 out <<
"Reward Models: none\n";
359template<storm::dd::DdType Type,
typename ValueType>
361 uint_fast64_t rowVariableCount = 0;
362 for (
auto const& metaVariable : this->rowVariables) {
363 rowVariableCount += this->
getManager().getMetaVariable(metaVariable).getNumberOfDdVariables();
365 uint_fast64_t columnVariableCount = 0;
366 for (
auto const& metaVariable : this->columnVariables) {
367 columnVariableCount += this->
getManager().getMetaVariable(metaVariable).getNumberOfDdVariables();
370 out <<
"Variables: \t"
371 <<
"rows: " << this->rowVariables.size() <<
" meta variables (" << rowVariableCount <<
" DD variables)"
372 <<
", columns: " << this->columnVariables.size() <<
" meta variables (" << columnVariableCount <<
" DD variables)";
375template<storm::dd::DdType Type,
typename ValueType>
377 return this->rowExpressionAdapter;
380template<storm::dd::DdType Type,
typename ValueType>
385template<storm::dd::DdType Type,
typename ValueType>
390template<storm::dd::DdType Type,
typename ValueType>
395template<storm::dd::DdType Type,
typename ValueType>
397 return std::is_same<ValueType, storm::RationalFunction>::value;
400template<storm::dd::DdType Type,
typename ValueType>
404 for (
auto const& lab : this->
getLabels()) {
405 this->
getStates(lab).exportToDot(filename,
true);
409template<storm::dd::DdType Type,
typename ValueType>
424template<storm::dd::DdType Type,
typename ValueType>
426 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"This value type does not support parameters.");
429template<storm::dd::DdType Type,
typename ValueType>
431 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"This value type does not support parameters.");
436 this->parameters.insert(parameters.begin(), parameters.end());
444template<storm::dd::DdType Type,
typename ValueType>
445template<
typename NewValueType>
448 STORM_LOG_TRACE(
"Converting value type of symbolic model from " <<
typeid(
ValueType).name() <<
" to " <<
typeid(NewValueType).name() <<
".");
467template<storm::dd::DdType Type,
typename ValueType>
468template<
typename NewValueType>
473 return std::make_shared<storm::models::symbolic::Dtmc<Type, ValueType>>(*this->
template as<storm::models::symbolic::Dtmc<Type, ValueType>>());
475 return std::make_shared<storm::models::symbolic::Ctmc<Type, ValueType>>(*this->
template as<storm::models::symbolic::Ctmc<Type, ValueType>>());
477 return std::make_shared<storm::models::symbolic::Mdp<Type, ValueType>>(*this->
template as<storm::models::symbolic::Mdp<Type, ValueType>>());
479 return std::make_shared<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>(
480 *this->
template as<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>());
482 return std::make_shared<storm::models::symbolic::StochasticTwoPlayerGame<Type, ValueType>>(
483 *this->
template as<storm::models::symbolic::StochasticTwoPlayerGame<Type, ValueType>>());
492template typename std::enable_if<std::is_same<double, double>::value, std::shared_ptr<Model<storm::dd::DdType::CUDD, double>>>::type
497template typename std::enable_if<std::is_same<double, double>::value, std::shared_ptr<Model<storm::dd::DdType::Sylvan, double>>>::type
499template typename std::enable_if<std::is_same<storm::RationalNumber, storm::RationalNumber>::value,
500 std::shared_ptr<Model<storm::dd::DdType::Sylvan, storm::RationalNumber>>>::type
502template typename std::enable_if<std::is_same<storm::RationalFunction, storm::RationalFunction>::value,
503 std::shared_ptr<Model<storm::dd::DdType::Sylvan, storm::RationalFunction>>>::type
505template typename std::enable_if<!std::is_same<storm::RationalNumber, double>::value, std::shared_ptr<Model<storm::dd::DdType::Sylvan, double>>>::type
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 ModelType getType() const
Return the actual type of the model.
std::shared_ptr< ModelType > as()
Casts the model into the model type given by the template parameter.
virtual bool supportsParameters() const
Checks whether the model supports parameters.
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.
void addParameters(std::set< storm::RationalFunctionVariable > const ¶meters)
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.
std::shared_ptr< storm::adapters::AddExpressionAdapter< Type, ValueType > > const & getRowExpressionAdapter() const
Retrieves the expression adapter of this model.
void writeDotToFile(std::string const &filename) const
RewardModelType const & getUniqueRewardModel() const
Retrieves the unique reward model, if there exists exactly one.
virtual void printDdVariableInformationToStream(std::ostream &out) const
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
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.
virtual storm::dd::Bdd< Type > getQualitativeTransitionMatrix(bool keepNondeterminism=true) const
Retrieves the matrix qualitatively (i.e.
Model(Model< Type, ValueType > const &other)=default
std::enable_if<!std::is_same< ValueType, NewValueType >::value, std::shared_ptr< Model< Type, NewValueType > > >::type toValueType() const
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.
virtual bool supportsParameters() const override
Checks whether the model supports parameters.
std::map< std::string, storm::dd::Bdd< Type > > const & getLabelToBddMap() const
Retrieves the mapping of labels to their defining expressions.
std::set< storm::RationalFunctionVariable > const & getParameters() const
storm::dd::Bdd< Type > const & getInitialStates() const
Retrieves the initial states of the model.
storm::dd::Add< Type, ValueType > transitionMatrix
virtual std::set< storm::expressions::Variable > const & getNondeterminismVariables() const
Retrieves all meta variables used to encode the nondeterminism.
void printModelInformationFooterToStream(std::ostream &out) const
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
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.
StandardRewardModel< Type, ValueType > RewardModelType
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)
storm::dd::Bdd< Type > getRowColumnDiagonal(storm::dd::DdManager< Type > const &ddManager, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs)
bool isConstant(ValueType const &)
constexpr bool IsIntervalType
Helper to check if a type is an interval.
static const bool IsExact