Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DdMetaVariable.cpp
Go to the documentation of this file.
2
4
5namespace storm {
6namespace dd {
7template<DdType LibraryType>
8DdMetaVariable<LibraryType>::DdMetaVariable(std::string const& name, int_fast64_t low, int_fast64_t high, std::vector<Bdd<LibraryType>> const& ddVariables)
9 : name(name), type(MetaVariableType::Int), low(low), high(high), ddVariables(ddVariables), lowestIndex(0) {
10 this->createCube();
11 this->precomputeLowestIndex();
12}
13
14template<DdType LibraryType>
15DdMetaVariable<LibraryType>::DdMetaVariable(MetaVariableType const& type, std::string const& name, std::vector<Bdd<LibraryType>> const& ddVariables)
16 : name(name), type(type), low(0), ddVariables(ddVariables), lowestIndex(0) {
17 STORM_LOG_ASSERT(type == MetaVariableType::Bool || type == MetaVariableType::BitVector, "Cannot create this type of meta variable in this constructor.");
18 if (ddVariables.size() < 63) {
19 this->high = (1ull << ddVariables.size()) - 1;
20 }
21
22 // Correct type in the case of boolean variables.
23 if (ddVariables.size() == 1) {
24 this->type = MetaVariableType::Bool;
25 }
26 this->createCube();
27 this->precomputeLowestIndex();
28}
29
30template<DdType LibraryType>
31std::string const& DdMetaVariable<LibraryType>::getName() const {
32 return this->name;
33}
34
35template<DdType LibraryType>
37 return this->type;
38}
39
40template<DdType LibraryType>
42 return this->low;
43}
44
45template<DdType LibraryType>
47 return this->high.get();
48}
49
50template<DdType LibraryType>
52 return static_cast<bool>(this->high);
53}
54
55template<DdType LibraryType>
56bool DdMetaVariable<LibraryType>::canRepresent(int_fast64_t value) const {
57 bool result = value >= this->low;
58 if (result && high) {
59 return value <= this->high;
60 }
61 return result;
62}
63
64template<DdType LibraryType>
66 return this->ddVariables.size();
67}
68
69template<DdType LibraryType>
70std::vector<Bdd<LibraryType>> const& DdMetaVariable<LibraryType>::getDdVariables() const {
71 return this->ddVariables;
72}
73
74template<DdType LibraryType>
76 return this->cube;
77}
78
79template<DdType LibraryType>
80std::vector<uint64_t> DdMetaVariable<LibraryType>::getIndices(bool sortedByLevel) const {
81 std::vector<std::pair<uint64_t, uint64_t>> indicesAndLevels = this->getIndicesAndLevels();
82 if (sortedByLevel) {
83 std::sort(indicesAndLevels.begin(), indicesAndLevels.end(),
84 [](std::pair<uint64_t, uint64_t> const& a, std::pair<uint64_t, uint64_t> const& b) { return a.second < b.second; });
85 }
86
87 std::vector<uint64_t> indices;
88 for (auto const& e : indicesAndLevels) {
89 indices.emplace_back(e.first);
90 }
91
92 return indices;
93}
94
95template<DdType LibraryType>
96std::vector<std::pair<uint64_t, uint64_t>> DdMetaVariable<LibraryType>::getIndicesAndLevels() const {
97 std::vector<std::pair<uint64_t, uint64_t>> indicesAndLevels;
98 for (auto const& v : ddVariables) {
99 indicesAndLevels.emplace_back(v.getIndex(), v.getLevel());
100 }
101
102 return indicesAndLevels;
103}
104
105template<DdType LibraryType>
107 uint64_t result = 0;
108 bool first = true;
109 for (auto const& v : ddVariables) {
110 if (first) {
111 result = v.getLevel();
112 first = false;
113 } else {
114 result = std::max(result, v.getLevel());
115 }
116 }
117
118 return result;
119}
120
121template<DdType LibraryType>
123 return lowestIndex;
124}
125
126template<DdType LibraryType>
128 STORM_LOG_ASSERT(!this->ddVariables.empty(), "The DD variables must not be empty.");
129 auto it = this->ddVariables.begin();
130 this->cube = *it;
131 ++it;
132 for (auto ite = this->ddVariables.end(); it != ite; ++it) {
133 this->cube &= *it;
134 }
135}
136
137template<DdType LibraryType>
138void DdMetaVariable<LibraryType>::precomputeLowestIndex() {
139 bool first = true;
140 for (auto const& var : this->ddVariables) {
141 if (first) {
142 first = false;
143 this->lowestIndex = var.getIndex();
144 } else {
145 this->lowestIndex = std::min(lowestIndex, var.getIndex());
146 }
147 }
148}
149
150template class DdMetaVariable<DdType::CUDD>;
151template class DdMetaVariable<DdType::Sylvan>;
152} // namespace dd
153} // namespace storm
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11