14#ifdef STORM_HAVE_SYLVAN
15template<
typename ValueType>
16AddIterator<DdType::Sylvan, ValueType>::AddIterator() {
20template<
typename ValueType>
21AddIterator<DdType::Sylvan, ValueType>::AddIterator(DdManager<DdType::Sylvan>
const& ddManager, sylvan::Mtbdd mtbdd, sylvan::Bdd variables,
22 uint_fast64_t numberOfDdVariables,
bool isAtEnd,
23 std::set<storm::expressions::Variable>
const* metaVariables,
bool enumerateDontCareMetaVariables)
24 : ddManager(&ddManager),
27 cube(numberOfDdVariables),
30 metaVariables(metaVariables),
31 enumerateDontCareMetaVariables(enumerateDontCareMetaVariables),
33 relevantDontCareDdVariables(),
34 currentValuation(ddManager.getExpressionManager().getSharedPointer()) {
38 this->createGlobalToLocalIndexMapping();
41 leaf = mtbdd_enum_first(mtbdd.GetMTBDD(), variables.GetBDD(), cube.data(), &mtbdd_isnonzero);
43 if (leaf != mtbdd_false) {
51template<
typename ValueType>
52void AddIterator<DdType::Sylvan, ValueType>::createGlobalToLocalIndexMapping() {
54 std::vector<uint_fast64_t> globalIndices;
55 for (
auto const& metaVariable : *this->metaVariables) {
56 auto const& ddMetaVariable = this->ddManager->getMetaVariable(metaVariable);
58 for (
auto const& ddVariable : ddMetaVariable.getDdVariables()) {
59 globalIndices.push_back(ddVariable.getIndex());
63 std::sort(globalIndices.begin(), globalIndices.end());
65 for (
auto it = globalIndices.begin(), ite = globalIndices.end(); it !=
ite; ++it) {
66 globalToLocalIndexMap[*it] = std::distance(globalIndices.begin(), it);
70template<
typename ValueType>
71AddIterator<DdType::Sylvan, ValueType> AddIterator<DdType::Sylvan, ValueType>::createBeginIterator(DdManager<DdType::Sylvan>
const& ddManager,
72 sylvan::Mtbdd mtbdd, sylvan::Bdd variables,
73 uint_fast64_t numberOfDdVariables,
74 std::set<storm::expressions::Variable>
const* metaVariables,
75 bool enumerateDontCareMetaVariables) {
76 return AddIterator<DdType::Sylvan, ValueType>(ddManager, mtbdd, variables, numberOfDdVariables,
false, metaVariables, enumerateDontCareMetaVariables);
79template<
typename ValueType>
80AddIterator<DdType::Sylvan, ValueType> AddIterator<DdType::Sylvan, ValueType>::createEndIterator(DdManager<DdType::Sylvan>
const& ddManager) {
81 return AddIterator<DdType::Sylvan, ValueType>(ddManager, sylvan::Mtbdd(), sylvan::Bdd(), 0,
true,
nullptr,
false);
84template<
typename ValueType>
85AddIterator<DdType::Sylvan, ValueType>& AddIterator<DdType::Sylvan, ValueType>::operator++() {
86 STORM_LOG_ASSERT(!this->isAtEnd,
"Illegally incrementing iterator that is already at its end.");
90 if (this->relevantDontCareDdVariables.empty() || this->cubeCounter >= std::pow(2, this->relevantDontCareDdVariables.size()) - 1) {
91 leaf = mtbdd_enum_next(mtbdd.GetMTBDD(), variables.GetBDD(), cube.data(), &mtbdd_isnonzero);
93 if (leaf != mtbdd_false) {
100 this->treatNextInCube();
106template<
typename ValueType>
107bool AddIterator<DdType::Sylvan, ValueType>::operator==(AddIterator<DdType::Sylvan, ValueType>
const& other)
const {
108 if (this->isAtEnd && other.isAtEnd) {
111 return this->ddManager == other.ddManager && this->mtbdd == other.mtbdd && this->variables == other.variables && this->cube == other.cube &&
112 this->leaf == other.leaf && this->isAtEnd == other.isAtEnd && this->metaVariables == other.metaVariables &&
113 this->cubeCounter == other.cubeCounter && this->relevantDontCareDdVariables == other.relevantDontCareDdVariables &&
114 this->currentValuation == other.currentValuation;
118template<
typename ValueType>
119bool AddIterator<DdType::Sylvan, ValueType>::operator!=(AddIterator<DdType::Sylvan, ValueType>
const& other)
const {
120 return !(*
this == other);
123template<
typename ValueType>
124std::pair<storm::expressions::SimpleValuation, ValueType> AddIterator<DdType::Sylvan, ValueType>::operator*()
const {
125 return std::make_pair(currentValuation,
static_cast<ValueType>(InternalAdd<DdType::Sylvan, ValueType>::getValue(leaf)));
128template<
typename ValueType>
129void AddIterator<DdType::Sylvan, ValueType>::treatNewCube() {
130 this->relevantDontCareDdVariables.clear();
135 for (
auto const& metaVariable : *this->metaVariables) {
136 bool metaVariableAppearsInCube =
false;
137 std::vector<std::tuple<storm::expressions::Variable, uint_fast64_t>> localRelenvantDontCareDdVariables;
138 auto const& ddMetaVariable = this->ddManager->getMetaVariable(metaVariable);
139 if (ddMetaVariable.getType() == MetaVariableType::Bool) {
140 if (this->cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables().front().getIndex())] == 0) {
141 metaVariableAppearsInCube =
true;
142 currentValuation.setBooleanValue(metaVariable,
false);
143 }
else if (this->cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables().front().getIndex())] == 1) {
144 metaVariableAppearsInCube =
true;
145 currentValuation.setBooleanValue(metaVariable,
true);
147 localRelenvantDontCareDdVariables.push_back(std::make_tuple(metaVariable, 0));
150 int_fast64_t intValue = 0;
151 for (uint_fast64_t bitIndex = 0; bitIndex < ddMetaVariable.getNumberOfDdVariables(); ++bitIndex) {
152 if (cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables()[bitIndex].getIndex())] == 0) {
154 metaVariableAppearsInCube =
true;
155 }
else if (cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables()[bitIndex].getIndex())] == 1) {
156 intValue |= 1ull << (ddMetaVariable.getNumberOfDdVariables() - bitIndex - 1);
157 metaVariableAppearsInCube =
true;
161 localRelenvantDontCareDdVariables.push_back(std::make_tuple(metaVariable, ddMetaVariable.getNumberOfDdVariables() - bitIndex - 1));
164 if (this->enumerateDontCareMetaVariables || metaVariableAppearsInCube) {
165 currentValuation.setBitVectorValue(metaVariable, intValue + ddMetaVariable.getLow());
171 if (this->enumerateDontCareMetaVariables || metaVariableAppearsInCube) {
172 relevantDontCareDdVariables.insert(relevantDontCareDdVariables.end(), localRelenvantDontCareDdVariables.begin(),
173 localRelenvantDontCareDdVariables.end());
178 this->cubeCounter = 0;
181template<
typename ValueType>
182void AddIterator<DdType::Sylvan, ValueType>::treatNextInCube() {
186 for (uint_fast64_t index = 0; index < this->relevantDontCareDdVariables.size(); ++index) {
187 auto const& ddMetaVariable = this->ddManager->getMetaVariable(std::get<0>(this->relevantDontCareDdVariables[index]));
188 if (ddMetaVariable.getType() == MetaVariableType::Bool) {
189 if ((this->cubeCounter & (1ull << index)) != 0) {
190 currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]),
true);
192 currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]),
false);
196 if ((this->cubeCounter & (1ull << index)) != 0) {
197 currentValuation.setBitVectorValue(metaVariable, ((currentValuation.getBitVectorValue(metaVariable) - ddMetaVariable.getLow()) |
198 (1ull << std::get<1>(this->relevantDontCareDdVariables[index]))) +
199 ddMetaVariable.getLow());
201 currentValuation.setBitVectorValue(metaVariable, ((currentValuation.getBitVectorValue(metaVariable) - ddMetaVariable.getLow()) &
202 ~(1ull << std::get<1>(this->relevantDontCareDdVariables[index]))) +
203 ddMetaVariable.getLow());
209template<
typename ValueType>
212 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
213 "version of Storm with Sylvan support.");
216template<
typename ValueType>
219 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
220 "version of Storm with Sylvan support.");
223template<
typename ValueType>
226 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
227 "version of Storm with Sylvan support.");
230template<
typename ValueType>
233 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
234 "version of Storm with Sylvan support.");
237template<
typename ValueType>
240 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
241 "version of Storm with Sylvan support.");
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
SFTBDDChecker::ValueType ValueType
Expression ite(Expression const &condition, Expression const &thenExpression, Expression const &elseExpression)