Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DdMetaVariable.cpp
Go to the documentation of this file.
2
5
6namespace storm {
7namespace dd {
8template<DdType LibraryType>
9DdMetaVariable<LibraryType>::DdMetaVariable(std::string const& name, int_fast64_t low, int_fast64_t high, std::vector<Bdd<LibraryType>> const& ddVariables)
10 : name(name), type(MetaVariableType::Int), low(low), high(high), ddVariables(ddVariables), lowestIndex(0) {
11 this->createCube();
12 this->precomputeLowestIndex();
13}
14
15template<DdType LibraryType>
16DdMetaVariable<LibraryType>::DdMetaVariable(MetaVariableType const& type, std::string const& name, std::vector<Bdd<LibraryType>> const& ddVariables)
17 : name(name), type(type), low(0), ddVariables(ddVariables), lowestIndex(0) {
18 STORM_LOG_ASSERT(type == MetaVariableType::Bool || type == MetaVariableType::BitVector, "Cannot create this type of meta variable in this constructor.");
19 if (ddVariables.size() < 63) {
20 this->high = (1ull << ddVariables.size()) - 1;
21 }
22
23 // Correct type in the case of boolean variables.
24 if (ddVariables.size() == 1) {
25 this->type = MetaVariableType::Bool;
26 }
27 this->createCube();
28 this->precomputeLowestIndex();
29}
30
31template<DdType LibraryType>
32std::string const& DdMetaVariable<LibraryType>::getName() const {
33 return this->name;
34}
35
36template<DdType LibraryType>
38 return this->type;
39}
40
41template<DdType LibraryType>
43 return this->low;
44}
45
46template<DdType LibraryType>
48 return this->high.get();
49}
50
51template<DdType LibraryType>
53 return static_cast<bool>(this->high);
54}
55
56template<DdType LibraryType>
57bool DdMetaVariable<LibraryType>::canRepresent(int_fast64_t value) const {
58 bool result = value >= this->low;
59 if (result && high) {
60 return value <= this->high;
61 }
62 return result;
63}
64
65template<DdType LibraryType>
67 return this->ddVariables.size();
68}
69
70template<DdType LibraryType>
71std::vector<Bdd<LibraryType>> const& DdMetaVariable<LibraryType>::getDdVariables() const {
72 return this->ddVariables;
73}
74
75template<DdType LibraryType>
77 return this->cube;
78}
79
80template<DdType LibraryType>
81std::vector<uint64_t> DdMetaVariable<LibraryType>::getIndices(bool sortedByLevel) const {
82 std::vector<std::pair<uint64_t, uint64_t>> indicesAndLevels = this->getIndicesAndLevels();
83 if (sortedByLevel) {
84 std::sort(indicesAndLevels.begin(), indicesAndLevels.end(),
85 [](std::pair<uint64_t, uint64_t> const& a, std::pair<uint64_t, uint64_t> const& b) { return a.second < b.second; });
86 }
87
88 std::vector<uint64_t> indices;
89 for (auto const& e : indicesAndLevels) {
90 indices.emplace_back(e.first);
91 }
92
93 return indices;
94}
95
96template<DdType LibraryType>
97std::vector<std::pair<uint64_t, uint64_t>> DdMetaVariable<LibraryType>::getIndicesAndLevels() const {
98 std::vector<std::pair<uint64_t, uint64_t>> indicesAndLevels;
99 for (auto const& v : ddVariables) {
100 indicesAndLevels.emplace_back(v.getIndex(), v.getLevel());
101 }
102
103 return indicesAndLevels;
104}
105
106template<DdType LibraryType>
108 uint64_t result = 0;
109 bool first = true;
110 for (auto const& v : ddVariables) {
111 if (first) {
112 result = v.getLevel();
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
LabParser.cpp.
Definition cli.cpp:18