15#ifdef STORM_HAVE_SYLVAN
16template<
typename ValueType>
17AddIterator<DdType::Sylvan, ValueType>::AddIterator() {
21template<
typename ValueType>
22AddIterator<DdType::Sylvan, ValueType>::AddIterator(DdManager<DdType::Sylvan>
const& ddManager, sylvan::Mtbdd mtbdd, sylvan::Bdd variables,
23 uint_fast64_t numberOfDdVariables,
bool isAtEnd,
24 std::set<storm::expressions::Variable>
const* metaVariables,
bool enumerateDontCareMetaVariables)
25 : ddManager(&ddManager),
28 cube(numberOfDdVariables),
31 metaVariables(metaVariables),
32 enumerateDontCareMetaVariables(enumerateDontCareMetaVariables),
34 relevantDontCareDdVariables(),
35 currentValuation(ddManager.getExpressionManager().getSharedPointer()) {
39 this->createGlobalToLocalIndexMapping();
42 leaf = mtbdd_enum_first(mtbdd.GetMTBDD(), variables.GetBDD(), cube.data(), &mtbdd_isnonzero);
44 if (leaf != mtbdd_false) {
52template<
typename ValueType>
53void AddIterator<DdType::Sylvan, ValueType>::createGlobalToLocalIndexMapping() {
55 std::vector<uint_fast64_t> globalIndices;
56 for (
auto const& metaVariable : *this->metaVariables) {
57 auto const& ddMetaVariable = this->ddManager->getMetaVariable(metaVariable);
59 for (
auto const& ddVariable : ddMetaVariable.getDdVariables()) {
60 globalIndices.push_back(ddVariable.getIndex());
64 std::sort(globalIndices.begin(), globalIndices.end());
66 for (
auto it = globalIndices.begin(), ite = globalIndices.end(); it !=
ite; ++it) {
67 globalToLocalIndexMap[*it] = std::distance(globalIndices.begin(), it);
71template<
typename ValueType>
72AddIterator<DdType::Sylvan, ValueType> AddIterator<DdType::Sylvan, ValueType>::createBeginIterator(DdManager<DdType::Sylvan>
const& ddManager,
73 sylvan::Mtbdd mtbdd, sylvan::Bdd variables,
74 uint_fast64_t numberOfDdVariables,
75 std::set<storm::expressions::Variable>
const* metaVariables,
76 bool enumerateDontCareMetaVariables) {
77 return AddIterator<DdType::Sylvan, ValueType>(ddManager, mtbdd, variables, numberOfDdVariables,
false, metaVariables, enumerateDontCareMetaVariables);
80template<
typename ValueType>
81AddIterator<DdType::Sylvan, ValueType> AddIterator<DdType::Sylvan, ValueType>::createEndIterator(DdManager<DdType::Sylvan>
const& ddManager) {
82 return AddIterator<DdType::Sylvan, ValueType>(ddManager, sylvan::Mtbdd(), sylvan::Bdd(), 0,
true,
nullptr,
false);
85template<
typename ValueType>
86AddIterator<DdType::Sylvan, ValueType>& AddIterator<DdType::Sylvan, ValueType>::operator++() {
87 STORM_LOG_ASSERT(!this->isAtEnd,
"Illegally incrementing iterator that is already at its end.");
91 if (this->relevantDontCareDdVariables.empty() || this->cubeCounter >= std::pow(2, this->relevantDontCareDdVariables.size()) - 1) {
92 leaf = mtbdd_enum_next(mtbdd.GetMTBDD(), variables.GetBDD(), cube.data(), &mtbdd_isnonzero);
94 if (leaf != mtbdd_false) {
101 this->treatNextInCube();
107template<
typename ValueType>
108bool AddIterator<DdType::Sylvan, ValueType>::operator==(AddIterator<DdType::Sylvan, ValueType>
const& other)
const {
109 if (this->isAtEnd && other.isAtEnd) {
112 return this->ddManager == other.ddManager && this->mtbdd == other.mtbdd && this->variables == other.variables && this->cube == other.cube &&
113 this->leaf == other.leaf && this->isAtEnd == other.isAtEnd && this->metaVariables == other.metaVariables &&
114 this->cubeCounter == other.cubeCounter && this->relevantDontCareDdVariables == other.relevantDontCareDdVariables &&
115 this->currentValuation == other.currentValuation;
119template<
typename ValueType>
120bool AddIterator<DdType::Sylvan, ValueType>::operator!=(AddIterator<DdType::Sylvan, ValueType>
const& other)
const {
121 return !(*
this == other);
124template<
typename ValueType>
125std::pair<storm::expressions::SimpleValuation, ValueType> AddIterator<DdType::Sylvan, ValueType>::operator*()
const {
126 return std::make_pair(currentValuation,
static_cast<ValueType>(InternalAdd<DdType::Sylvan, ValueType>::getValue(leaf)));
129template<
typename ValueType>
130void AddIterator<DdType::Sylvan, ValueType>::treatNewCube() {
131 this->relevantDontCareDdVariables.clear();
136 for (
auto const& metaVariable : *this->metaVariables) {
137 bool metaVariableAppearsInCube =
false;
138 std::vector<std::tuple<storm::expressions::Variable, uint_fast64_t>> localRelenvantDontCareDdVariables;
139 auto const& ddMetaVariable = this->ddManager->getMetaVariable(metaVariable);
140 if (ddMetaVariable.getType() == MetaVariableType::Bool) {
141 if (this->cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables().front().getIndex())] == 0) {
142 metaVariableAppearsInCube =
true;
143 currentValuation.setBooleanValue(metaVariable,
false);
144 }
else if (this->cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables().front().getIndex())] == 1) {
145 metaVariableAppearsInCube =
true;
146 currentValuation.setBooleanValue(metaVariable,
true);
148 localRelenvantDontCareDdVariables.push_back(std::make_tuple(metaVariable, 0));
151 int_fast64_t intValue = 0;
152 for (uint_fast64_t bitIndex = 0; bitIndex < ddMetaVariable.getNumberOfDdVariables(); ++bitIndex) {
153 if (cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables()[bitIndex].getIndex())] == 0) {
155 metaVariableAppearsInCube =
true;
156 }
else if (cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables()[bitIndex].getIndex())] == 1) {
157 intValue |= 1ull << (ddMetaVariable.getNumberOfDdVariables() - bitIndex - 1);
158 metaVariableAppearsInCube =
true;
162 localRelenvantDontCareDdVariables.push_back(std::make_tuple(metaVariable, ddMetaVariable.getNumberOfDdVariables() - bitIndex - 1));
165 if (this->enumerateDontCareMetaVariables || metaVariableAppearsInCube) {
166 currentValuation.setBitVectorValue(metaVariable, intValue + ddMetaVariable.getLow());
172 if (this->enumerateDontCareMetaVariables || metaVariableAppearsInCube) {
173 relevantDontCareDdVariables.insert(relevantDontCareDdVariables.end(), localRelenvantDontCareDdVariables.begin(),
174 localRelenvantDontCareDdVariables.end());
179 this->cubeCounter = 0;
182template<
typename ValueType>
183void AddIterator<DdType::Sylvan, ValueType>::treatNextInCube() {
187 for (uint_fast64_t index = 0; index < this->relevantDontCareDdVariables.size(); ++index) {
188 auto const& ddMetaVariable = this->ddManager->getMetaVariable(std::get<0>(this->relevantDontCareDdVariables[index]));
189 if (ddMetaVariable.getType() == MetaVariableType::Bool) {
190 if ((this->cubeCounter & (1ull << index)) != 0) {
191 currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]),
true);
193 currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]),
false);
197 if ((this->cubeCounter & (1ull << index)) != 0) {
198 currentValuation.setBitVectorValue(metaVariable, ((currentValuation.getBitVectorValue(metaVariable) - ddMetaVariable.getLow()) |
199 (1ull << std::get<1>(this->relevantDontCareDdVariables[index]))) +
200 ddMetaVariable.getLow());
202 currentValuation.setBitVectorValue(metaVariable, ((currentValuation.getBitVectorValue(metaVariable) - ddMetaVariable.getLow()) &
203 ~(1ull << std::get<1>(this->relevantDontCareDdVariables[index]))) +
204 ddMetaVariable.getLow());
210template<
typename ValueType>
213 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
214 "version of Storm with Sylvan support.");
217template<
typename ValueType>
220 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
221 "version of Storm with Sylvan support.");
224template<
typename ValueType>
227 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
228 "version of Storm with Sylvan support.");
231template<
typename ValueType>
234 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
235 "version of Storm with Sylvan support.");
238template<
typename ValueType>
241 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
242 "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)