5#include <boost/algorithm/string/join.hpp>
11namespace abstraction {
13template<storm::dd::DdType DdType>
15 : relevantVariables(abstractionInformation.getAbstractedVariables()),
16 expressionBlocks(relevantVariables.size()),
17 abstractionInformation(abstractionInformation) {
19 uint_fast64_t currentBlock = 0;
20 variableBlocks.resize(relevantVariables.size());
21 for (
auto const& variable : relevantVariables) {
22 this->variableToBlockMapping[variable] = currentBlock;
23 this->variableToExpressionsMapping[variable] = std::set<uint_fast64_t>();
24 variableBlocks[currentBlock].insert(variable);
29template<storm::dd::DdType DdType>
34 std::set<storm::expressions::Variable> expressionVariables = expression.
getVariables();
35 for (
auto const& variable : expressionVariables) {
36 variableToExpressionsMapping[variable].insert(globalExpressionIndex);
41 STORM_LOG_ASSERT(!expressionVariables.empty(),
"Found no variables in expression.");
42 expressionBlocks[getBlockIndexOfVariable(*expressionVariables.begin())].insert(globalExpressionIndex);
45 return this->relate(expressionVariables);
48template<storm::dd::DdType DdType>
50 return getBlockIndexOfVariable(firstVariable) == getBlockIndexOfVariable(secondVariable);
53template<storm::dd::DdType DdType>
56 return this->relate({firstVariable, secondVariable});
59template<storm::dd::DdType DdType>
62 std::set<uint_fast64_t> blocksToMerge;
63 for (
auto const& variable : variables) {
64 blocksToMerge.insert(getBlockIndexOfVariable(variable));
67 STORM_LOG_ASSERT(variables.empty() || !blocksToMerge.empty(),
"Found no blocks to merge.");
70 if (blocksToMerge.size() <= 1) {
71 std::map<uint64_t, uint64_t> identity;
72 for (uint64_t i = 0; i < getNumberOfBlocks(); ++i) {
73 identity.emplace_hint(identity.end(), i, i);
78 return this->mergeBlocks(blocksToMerge);
81template<storm::dd::DdType DdType>
83 std::map<uint64_t, uint64_t> oldToNewIndices;
86 std::vector<std::set<storm::expressions::Variable>> newVariableBlocks;
87 std::vector<std::set<uint_fast64_t>> newExpressionBlocks;
89 std::set<uint_fast64_t>::const_iterator blocksToMergeIt = blocksToMerge.begin();
90 std::set<uint_fast64_t>::const_iterator blocksToMergeIte = blocksToMerge.end();
93 uint_fast64_t blockToKeep = *blocksToMergeIt;
96 for (uint_fast64_t blockIndex = 0; blockIndex < variableBlocks.size(); ++blockIndex) {
98 if (blocksToMergeIt != blocksToMergeIte && *blocksToMergeIt == blockIndex && blockIndex != blockToKeep) {
100 for (
auto const& variable : variableBlocks[blockIndex]) {
101 variableToBlockMapping[variable] = blockToKeep;
103 oldToNewIndices[blockIndex] = blockToKeep;
105 newVariableBlocks[blockToKeep].insert(variableBlocks[blockIndex].begin(), variableBlocks[blockIndex].end());
106 newExpressionBlocks[blockToKeep].insert(expressionBlocks[blockIndex].begin(), expressionBlocks[blockIndex].end());
110 oldToNewIndices[blockIndex] = newVariableBlocks.size();
113 for (
auto const& variable : variableBlocks[blockIndex]) {
114 variableToBlockMapping[variable] = newVariableBlocks.size();
117 newVariableBlocks.emplace_back(std::move(variableBlocks[blockIndex]));
118 newExpressionBlocks.emplace_back(std::move(expressionBlocks[blockIndex]));
122 variableBlocks = std::move(newVariableBlocks);
123 expressionBlocks = std::move(newExpressionBlocks);
125 return oldToNewIndices;
128template<storm::dd::DdType DdType>
130 return variableBlocks[getBlockIndexOfVariable(variable)];
133template<storm::dd::DdType DdType>
135 return this->variableBlocks.size();
138template<storm::dd::DdType DdType>
140 return this->variableBlocks[blockIndex];
143template<storm::dd::DdType DdType>
145 STORM_LOG_ASSERT(this->relevantVariables.find(variable) != this->relevantVariables.end(),
"Illegal variable '" << variable.
getName() <<
"' for partition.");
146 return this->variableToBlockMapping.find(variable)->second;
149template<storm::dd::DdType DdType>
151 std::set<uint_fast64_t> result;
152 for (
auto const& variable : variables) {
153 result.insert(getBlockIndexOfVariable(variable));
158template<storm::dd::DdType DdType>
160 return this->expressionBlocks[getBlockIndexOfVariable(variable)];
163template<storm::dd::DdType DdType>
166 std::set<uint_fast64_t> relatedExpressionBlockIndices;
167 for (
auto const& variable : variables) {
168 relatedExpressionBlockIndices.insert(getBlockIndexOfVariable(variable));
172 std::set<uint_fast64_t> result;
173 for (
auto const& blockIndex : relatedExpressionBlockIndices) {
174 result.insert(expressionBlocks[blockIndex].begin(), expressionBlocks[blockIndex].end());
179template<storm::dd::DdType DdType>
181 STORM_LOG_ASSERT(this->relevantVariables.find(variable) != this->relevantVariables.end(),
"Illegal variable '" << variable.
getName() <<
"' for partition.");
182 return this->variableToExpressionsMapping.find(variable)->second;
185template<storm::dd::DdType DdType>
187 std::set<uint_fast64_t> result;
189 for (
auto const& variable : variables) {
190 STORM_LOG_ASSERT(this->relevantVariables.find(variable) != this->relevantVariables.end(),
191 "Illegal variable '" << variable.getName() <<
"' for partition.");
192 auto it = this->variableToExpressionsMapping.find(variable);
193 result.insert(it->second.begin(), it->second.end());
199template<storm::dd::DdType DdType>
201 return expressionBlocks[index];
204template<storm::dd::DdType DdType>
206 std::vector<std::string> blocks;
207 for (uint_fast64_t index = 0; index < partition.variableBlocks.size(); ++index) {
208 auto const& variableBlock = partition.variableBlocks[index];
209 auto const& expressionBlock = partition.expressionBlocks[index];
211 std::vector<std::string> variablesInBlock;
212 for (
auto const& variable : variableBlock) {
213 variablesInBlock.push_back(variable.getName());
216 std::vector<std::string> expressionsInBlock;
217 for (
auto const& expressionIndex : expressionBlock) {
218 std::stringstream stream;
219 stream << partition.abstractionInformation.get().getPredicateByIndex(expressionIndex);
220 expressionsInBlock.push_back(stream.str());
223 blocks.push_back(
"<[" + boost::algorithm::join(variablesInBlock,
", ") +
"], [" + boost::algorithm::join(expressionsInBlock,
", ") +
"]>");
227 out << boost::join(blocks,
", ");
232template class LocalExpressionInformation<storm::dd::DdType::CUDD>;
233template class LocalExpressionInformation<storm::dd::DdType::Sylvan>;
std::set< storm::expressions::Variable > getVariables() const
Retrieves the set of all variables that appear in the expression.
std::string const & getName() const
Retrieves the name of the variable.
#define STORM_LOG_ASSERT(cond, message)
std::ostream & operator<<(std::ostream &out, LocalExpressionInformation< DdType > const &partition)