Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
PartialQuotientExtractor.cpp
Go to the documentation of this file.
2
10
11namespace storm {
12namespace dd {
13namespace bisimulation {
14
15template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType>
17 storm::dd::bisimulation::QuotientFormat const& quotientFormat)
18 : model(model), quotientFormat(quotientFormat) {
19 if (this->quotientFormat != storm::dd::bisimulation::QuotientFormat::Dd) {
20 STORM_LOG_ERROR("Only DD-based partial quotient extraction is currently supported. Switching to DD-based extraction.");
22 }
23}
24
25template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType>
26std::shared_ptr<storm::models::Model<ExportValueType>> PartialQuotientExtractor<DdType, ValueType, ExportValueType>::extract(
27 Partition<DdType, ValueType> const& partition, PreservationInformation<DdType, ValueType> const& preservationInformation) {
28 auto start = std::chrono::high_resolution_clock::now();
29 std::shared_ptr<storm::models::Model<ExportValueType>> result;
30
31 STORM_LOG_THROW(this->quotientFormat == storm::dd::bisimulation::QuotientFormat::Dd, storm::exceptions::NotSupportedException,
32 "Only DD-based partial quotient extraction is currently supported.");
33 result = extractDdQuotient(partition, preservationInformation);
34 auto end = std::chrono::high_resolution_clock::now();
35 STORM_LOG_TRACE("Quotient extraction completed in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms.");
36
37 STORM_LOG_THROW(result, storm::exceptions::NotSupportedException, "Quotient could not be extracted.");
38
39 return result;
40}
41
42template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType>
43std::shared_ptr<storm::models::symbolic::Model<DdType, ExportValueType>> PartialQuotientExtractor<DdType, ValueType, ExportValueType>::extractDdQuotient(
44 Partition<DdType, ValueType> const& partition, PreservationInformation<DdType, ValueType> const& preservationInformation) {
45 auto modelType = model.getType();
46 if (modelType == storm::models::ModelType::Dtmc || modelType == storm::models::ModelType::Mdp) {
47 // Sanity checks.
48 STORM_LOG_ASSERT(partition.getNumberOfStates() == model.getNumberOfStates(), "Mismatching partition size.");
49 STORM_LOG_ASSERT(partition.getStates().renameVariables(model.getColumnVariables(), model.getRowVariables()) == model.getReachableStates(),
50 "Mismatching partition.");
51
52 std::set<storm::expressions::Variable> blockVariableSet = {partition.getBlockVariable()};
53 std::set<storm::expressions::Variable> blockPrimeVariableSet = {partition.getPrimedBlockVariable()};
54 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> blockMetaVariablePairs = {
55 std::make_pair(partition.getBlockVariable(), partition.getPrimedBlockVariable())};
56
57 storm::dd::Bdd<DdType> partitionAsBdd = partition.storedAsBdd() ? partition.asBdd() : partition.asAdd().notZero();
58
59 auto start = std::chrono::high_resolution_clock::now();
60 partitionAsBdd = partitionAsBdd.renameVariables(model.getColumnVariables(), model.getRowVariables());
61 storm::dd::Bdd<DdType> reachableStates = partitionAsBdd.existsAbstract(model.getRowVariables());
62 storm::dd::Bdd<DdType> initialStates = (model.getInitialStates() && partitionAsBdd).existsAbstract(model.getRowVariables());
63
64 std::map<std::string, storm::dd::Bdd<DdType>> preservedLabelBdds;
65 for (auto const& label : preservationInformation.getLabels()) {
66 preservedLabelBdds.emplace(label, (model.getStates(label) && partitionAsBdd).existsAbstract(model.getRowVariables()));
67 }
68 for (auto const& expression : preservationInformation.getExpressions()) {
69 std::stringstream stream;
70 stream << expression;
71 std::string expressionAsString = stream.str();
72
73 auto it = preservedLabelBdds.find(expressionAsString);
74 if (it != preservedLabelBdds.end()) {
75 STORM_LOG_WARN("Duplicate label '" << expressionAsString << "', dropping second label definition.");
76 } else {
77 preservedLabelBdds.emplace(stream.str(), (model.getStates(expression) && partitionAsBdd).existsAbstract(model.getRowVariables()));
78 }
79 }
80 auto end = std::chrono::high_resolution_clock::now();
81 STORM_LOG_TRACE("Quotient labels extracted in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms.");
82
83 start = std::chrono::high_resolution_clock::now();
84 std::set<storm::expressions::Variable> blockAndRowVariables;
85 std::set_union(blockVariableSet.begin(), blockVariableSet.end(), model.getRowVariables().begin(), model.getRowVariables().end(),
86 std::inserter(blockAndRowVariables, blockAndRowVariables.end()));
87 std::set<storm::expressions::Variable> blockPrimeAndColumnVariables;
88 std::set_union(blockPrimeVariableSet.begin(), blockPrimeVariableSet.end(), model.getColumnVariables().begin(), model.getColumnVariables().end(),
89 std::inserter(blockPrimeAndColumnVariables, blockPrimeAndColumnVariables.end()));
90 storm::dd::Add<DdType, ValueType> partitionAsAdd = partitionAsBdd.template toAdd<ValueType>();
91 storm::dd::Add<DdType, ValueType> quotientTransitionMatrix = model.getTransitionMatrix().multiplyMatrix(
92 partitionAsAdd.renameVariables(blockAndRowVariables, blockPrimeAndColumnVariables), model.getColumnVariables());
93
94 quotientTransitionMatrix = quotientTransitionMatrix * partitionAsAdd;
95 end = std::chrono::high_resolution_clock::now();
96
97 // Check quotient matrix for sanity.
98 if (std::is_same<ValueType, storm::RationalNumber>::value) {
99 STORM_LOG_ASSERT(quotientTransitionMatrix.greater(storm::utility::one<ValueType>()).isZero(), "Illegal entries in quotient matrix.");
100 } else {
102 "Illegal entries in quotient matrix.");
103 }
104
105 STORM_LOG_TRACE("Quotient transition matrix extracted in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms.");
106
107 storm::dd::Bdd<DdType> quotientTransitionMatrixBdd = quotientTransitionMatrix.notZero();
108 std::set<storm::expressions::Variable> nonSourceVariables;
109 std::set_union(blockPrimeVariableSet.begin(), blockPrimeVariableSet.end(), model.getRowVariables().begin(), model.getRowVariables().end(),
110 std::inserter(nonSourceVariables, nonSourceVariables.begin()));
111 storm::dd::Bdd<DdType> deadlockStates = !quotientTransitionMatrixBdd.existsAbstract(nonSourceVariables) && reachableStates;
112
113 start = std::chrono::high_resolution_clock::now();
114 std::unordered_map<std::string, storm::models::symbolic::StandardRewardModel<DdType, ValueType>> quotientRewardModels;
115 for (auto const& rewardModelName : preservationInformation.getRewardModelNames()) {
116 auto const& rewardModel = model.getRewardModel(rewardModelName);
117
118 boost::optional<storm::dd::Add<DdType, ValueType>> quotientStateRewards;
119 if (rewardModel.hasStateRewards()) {
120 quotientStateRewards = rewardModel.getStateRewardVector() * partitionAsAdd;
121 }
122
123 boost::optional<storm::dd::Add<DdType, ValueType>> quotientStateActionRewards;
124 if (rewardModel.hasStateActionRewards()) {
125 quotientStateActionRewards = rewardModel.getStateActionRewardVector() * partitionAsAdd;
126 }
127
128 quotientRewardModels.emplace(rewardModelName, storm::models::symbolic::StandardRewardModel<DdType, ValueType>(
129 quotientStateRewards, quotientStateActionRewards, boost::none));
130 }
131 end = std::chrono::high_resolution_clock::now();
132 STORM_LOG_TRACE("Reward models extracted in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms.");
133
134 std::shared_ptr<storm::models::symbolic::Model<DdType, ValueType>> result;
135 if (modelType == storm::models::ModelType::Dtmc) {
136 result = std::make_shared<storm::models::symbolic::Mdp<DdType, ValueType>>(
137 model.getManager().asSharedPointer(), reachableStates, initialStates, deadlockStates, quotientTransitionMatrix, blockVariableSet,
138 blockPrimeVariableSet, blockMetaVariablePairs, model.getRowVariables(), preservedLabelBdds, quotientRewardModels);
139 } else if (modelType == storm::models::ModelType::Mdp) {
140 std::set<storm::expressions::Variable> allNondeterminismVariables;
141 std::set_union(model.getRowVariables().begin(), model.getRowVariables().end(), model.getNondeterminismVariables().begin(),
142 model.getNondeterminismVariables().end(), std::inserter(allNondeterminismVariables, allNondeterminismVariables.begin()));
143
144 result = std::make_shared<storm::models::symbolic::StochasticTwoPlayerGame<DdType, ValueType>>(
145 model.getManager().asSharedPointer(), reachableStates, initialStates, deadlockStates, quotientTransitionMatrix, blockVariableSet,
146 blockPrimeVariableSet, blockMetaVariablePairs, model.getRowVariables(), model.getNondeterminismVariables(), allNondeterminismVariables,
147 preservedLabelBdds, quotientRewardModels);
148 } else {
149 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Unsupported quotient type.");
150 }
151
152 return result->template toValueType<ExportValueType>();
153 } else {
154 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Cannot extract partial quotient for this model type.");
155 }
156}
157
160
164
165} // namespace bisimulation
166} // namespace dd
167} // namespace storm
Bdd< LibraryType > greater(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:109
Add< LibraryType, ValueType > renameVariables(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the ADD.
Definition Add.cpp:209
Bdd< LibraryType > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
Definition Add.cpp:424
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
Definition Bdd.cpp:172
Bdd< LibraryType > renameVariables(std::set< storm::expressions::Variable > const &from, std::set< storm::expressions::Variable > const &to) const
Renames the given meta variables in the BDD.
Definition Bdd.cpp:341
PartialQuotientExtractor(storm::models::symbolic::Model< DdType, ValueType > const &model, storm::dd::bisimulation::QuotientFormat const &quotientFormat)
std::shared_ptr< storm::models::Model< ExportValueType > > extract(Partition< DdType, ValueType > const &partition, PreservationInformation< DdType, ValueType > const &preservationInformation)
storm::expressions::Variable const & getBlockVariable() const
storm::dd::Bdd< DdType > const & asBdd() const
storm::expressions::Variable const & getPrimedBlockVariable() const
storm::dd::Bdd< DdType > getStates() const
storm::dd::Add< DdType, ValueType > const & asAdd() const
std::set< std::string > const & getLabels() const
std::set< std::string > const & getRewardModelNames() const
std::set< storm::expressions::Expression > const & getExpressions() const
Base class for all symbolic models.
Definition Model.h:42
#define STORM_LOG_WARN(message)
Definition logging.h:28
#define STORM_LOG_TRACE(message)
Definition logging.h:15
#define STORM_LOG_ERROR(message)
Definition logging.h:29
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
std::pair< storm::RationalNumber, storm::RationalNumber > count(std::vector< storm::storage::BitVector > const &origSets, std::vector< storm::storage::BitVector > const &intersects, std::vector< storm::storage::BitVector > const &intersectsInfo, storm::RationalNumber val, bool plus, uint64_t remdepth)
ValueType one()
Definition constants.cpp:19
TargetType convertNumber(SourceType const &number)