17template<
typename ValueType>
22template<
typename ValueType>
24 uint_fast64_t numberOfDdVariables,
bool isAtEnd,
25 std::set<storm::expressions::Variable>
const* metaVariables,
bool enumerateDontCareMetaVariables)
26 : ddManager(&ddManager),
29 cube(numberOfDdVariables),
32 metaVariables(metaVariables),
33 enumerateDontCareMetaVariables(enumerateDontCareMetaVariables),
35 relevantDontCareDdVariables(),
36 currentValuation(ddManager.getExpressionManager().getSharedPointer()) {
40 this->createGlobalToLocalIndexMapping();
43 leaf = mtbdd_enum_first(mtbdd.GetMTBDD(), variables.GetBDD(), cube.data(), &mtbdd_isnonzero);
45 if (leaf != mtbdd_false) {
53template<
typename ValueType>
54void AddIterator<DdType::Sylvan, ValueType>::createGlobalToLocalIndexMapping() {
56 std::vector<uint_fast64_t> globalIndices;
57 for (
auto const& metaVariable : *this->metaVariables) {
58 auto const& ddMetaVariable = this->ddManager->
getMetaVariable(metaVariable);
60 for (
auto const& ddVariable : ddMetaVariable.getDdVariables()) {
61 globalIndices.push_back(ddVariable.getIndex());
65 std::sort(globalIndices.begin(), globalIndices.end());
67 for (
auto it = globalIndices.begin(), ite = globalIndices.end(); it !=
ite; ++it) {
68 globalToLocalIndexMap[*it] = std::distance(globalIndices.begin(), it);
72template<
typename ValueType>
73AddIterator<DdType::Sylvan, ValueType> AddIterator<DdType::Sylvan, ValueType>::createBeginIterator(DdManager<DdType::Sylvan>
const& ddManager,
74 sylvan::Mtbdd mtbdd, sylvan::Bdd variables,
75 uint_fast64_t numberOfDdVariables,
76 std::set<storm::expressions::Variable>
const* metaVariables,
77 bool enumerateDontCareMetaVariables) {
78 return AddIterator<DdType::Sylvan, ValueType>(ddManager, mtbdd, variables, numberOfDdVariables,
false, metaVariables, enumerateDontCareMetaVariables);
81template<
typename ValueType>
82AddIterator<DdType::Sylvan, ValueType> AddIterator<DdType::Sylvan, ValueType>::createEndIterator(DdManager<DdType::Sylvan>
const& ddManager) {
83 return AddIterator<DdType::Sylvan, ValueType>(ddManager, sylvan::Mtbdd(), sylvan::Bdd(), 0,
true,
nullptr,
false);
86template<
typename ValueType>
88 STORM_LOG_ASSERT(!this->isAtEnd,
"Illegally incrementing iterator that is already at its end.");
92 if (this->relevantDontCareDdVariables.empty() || this->cubeCounter >= std::pow(2, this->relevantDontCareDdVariables.size()) - 1) {
93 leaf = mtbdd_enum_next(mtbdd.GetMTBDD(), variables.GetBDD(), cube.data(), &mtbdd_isnonzero);
95 if (leaf != mtbdd_false) {
102 this->treatNextInCube();
108template<
typename ValueType>
110 if (this->isAtEnd && other.isAtEnd) {
113 return this->ddManager == other.ddManager && this->mtbdd == other.mtbdd && this->variables == other.variables && this->cube == other.cube &&
114 this->leaf == other.leaf && this->isAtEnd == other.isAtEnd && this->metaVariables == other.metaVariables &&
115 this->cubeCounter == other.cubeCounter && this->relevantDontCareDdVariables == other.relevantDontCareDdVariables &&
116 this->currentValuation == other.currentValuation;
120template<
typename ValueType>
122 return !(*
this == other);
125template<
typename ValueType>
130template<
typename ValueType>
132 this->relevantDontCareDdVariables.clear();
137 for (
auto const& metaVariable : *this->metaVariables) {
138 bool metaVariableAppearsInCube =
false;
139 std::vector<std::tuple<storm::expressions::Variable, uint_fast64_t>> localRelenvantDontCareDdVariables;
140 auto const& ddMetaVariable = this->ddManager->getMetaVariable(metaVariable);
142 if (this->cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables().front().getIndex())] == 0) {
143 metaVariableAppearsInCube =
true;
144 currentValuation.setBooleanValue(metaVariable,
false);
145 }
else if (this->cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables().front().getIndex())] == 1) {
146 metaVariableAppearsInCube =
true;
147 currentValuation.setBooleanValue(metaVariable,
true);
149 localRelenvantDontCareDdVariables.push_back(std::make_tuple(metaVariable, 0));
152 int_fast64_t intValue = 0;
153 for (uint_fast64_t bitIndex = 0; bitIndex < ddMetaVariable.getNumberOfDdVariables(); ++bitIndex) {
154 if (cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables()[bitIndex].getIndex())] == 0) {
156 metaVariableAppearsInCube =
true;
157 }
else if (cube[globalToLocalIndexMap.at(ddMetaVariable.getDdVariables()[bitIndex].getIndex())] == 1) {
158 intValue |= 1ull << (ddMetaVariable.getNumberOfDdVariables() - bitIndex - 1);
159 metaVariableAppearsInCube =
true;
163 localRelenvantDontCareDdVariables.push_back(std::make_tuple(metaVariable, ddMetaVariable.getNumberOfDdVariables() - bitIndex - 1));
166 if (this->enumerateDontCareMetaVariables || metaVariableAppearsInCube) {
167 currentValuation.setBitVectorValue(metaVariable, intValue + ddMetaVariable.getLow());
173 if (this->enumerateDontCareMetaVariables || metaVariableAppearsInCube) {
174 relevantDontCareDdVariables.insert(relevantDontCareDdVariables.end(), localRelenvantDontCareDdVariables.begin(),
175 localRelenvantDontCareDdVariables.end());
180 this->cubeCounter = 0;
183template<
typename ValueType>
184void AddIterator<DdType::Sylvan, ValueType>::treatNextInCube() {
188 for (uint_fast64_t index = 0; index < this->relevantDontCareDdVariables.size(); ++index) {
189 auto const& ddMetaVariable = this->ddManager->getMetaVariable(std::get<0>(this->relevantDontCareDdVariables[index]));
191 if ((this->cubeCounter & (1ull << index)) != 0) {
192 currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]),
true);
194 currentValuation.setBooleanValue(std::get<0>(this->relevantDontCareDdVariables[index]),
false);
198 if ((this->cubeCounter & (1ull << index)) != 0) {
199 currentValuation.setBitVectorValue(metaVariable, ((currentValuation.getBitVectorValue(metaVariable) - ddMetaVariable.getLow()) |
200 (1ull << std::get<1>(this->relevantDontCareDdVariables[index]))) +
201 ddMetaVariable.getLow());
203 currentValuation.setBitVectorValue(metaVariable, ((currentValuation.getBitVectorValue(metaVariable) - ddMetaVariable.getLow()) &
204 ~(1ull << std::get<1>(this->relevantDontCareDdVariables[index]))) +
205 ddMetaVariable.getLow());
211template class AddIterator<DdType::Sylvan, double>;
212template class AddIterator<DdType::Sylvan, uint_fast64_t>;
214template class AddIterator<DdType::Sylvan, storm::RationalNumber>;
216#ifdef STORM_HAVE_CARL
217template class AddIterator<DdType::Sylvan, storm::RationalFunction>;
storm::expressions::Variable getMetaVariable(std::string const &variableName) const
Retrieves the given meta variable by name.
#define STORM_LOG_ASSERT(cond, message)
Expression ite(Expression const &condition, Expression const &thenExpression, Expression const &elseExpression)