Browse Source

added some useful functions to variable partition

Former-commit-id: b290129abb
main
dehnert 10 years ago
parent
commit
36e8359efa
  1. 37
      src/storage/prism/menu_games/VariablePartition.cpp
  2. 21
      src/storage/prism/menu_games/VariablePartition.h

37
src/storage/prism/menu_games/VariablePartition.cpp

@ -1,5 +1,7 @@
#include "src/storage/prism/menu_games/VariablePartition.h" #include "src/storage/prism/menu_games/VariablePartition.h"
#include <boost/algorithm/string/join.hpp>
#include "src/utility/macros.h" #include "src/utility/macros.h"
namespace storm { namespace storm {
@ -65,13 +67,8 @@ namespace storm {
continue; continue;
} }
for (auto const& variable : variableBlocks[blockToMerge]) { variableBlocks[blockToKeep].insert(variableBlocks[blockToMerge].begin(), variableBlocks[blockToMerge].end());
variableBlocks[blockToKeep].insert(variable); expressionBlocks[blockToKeep].insert(expressionBlocks[blockToMerge].begin(), expressionBlocks[blockToMerge].end());
}
for (auto const& expression : expressionBlocks[blockToMerge]) {
expressionBlocks[blockToKeep].insert(expression);
}
} }
} }
@ -121,6 +118,32 @@ namespace storm {
} }
return result; return result;
} }
std::set<uint_fast64_t> const& VariablePartition::getExpressionsUsingVariable(storm::expressions::Variable const& variable) const {
STORM_LOG_ASSERT(this->relevantVariables.find(variable) != this->relevantVariables.end(), "Illegal variable '" << variable.getName() << "' for partition.");
return this->variableToExpressionsMapping.find(variable)->second;
}
storm::expressions::Expression const& VariablePartition::getExpression(uint_fast64_t expressionIndex) const {
return this->expressions[expressionIndex];
}
std::ostream& operator<<(std::ostream& out, VariablePartition const& partition) {
std::vector<std::string> blocks;
for (auto const& block : partition.variableBlocks) {
std::vector<std::string> variablesInBlock;
for (auto const& variable : block) {
variablesInBlock.push_back(variable.getName());
}
blocks.push_back("[" + boost::algorithm::join(variablesInBlock, ", ") + "]");
}
out << "{";
out << boost::join(blocks, ", ");
out << "}";
return out;
}
} }
} }
} }

21
src/storage/prism/menu_games/VariablePartition.h

@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <set> #include <set>
#include <vector> #include <vector>
#include <ostream>
#include "src/storage/expressions/Variable.h" #include "src/storage/expressions/Variable.h"
#include "src/storage/expressions/Expression.h" #include "src/storage/expressions/Expression.h"
@ -103,6 +104,24 @@ namespace storm {
*/ */
std::set<uint_fast64_t> getRelatedExpressions(std::set<storm::expressions::Variable> const& variables) const; std::set<uint_fast64_t> getRelatedExpressions(std::set<storm::expressions::Variable> const& variables) const;
/*!
* Retrieves the indices of the expressions in which the given variable appears.
*
* @param variable The variable for which to retrieve the expressions.
* @return The indices of all expressions using the given variable.
*/
std::set<uint_fast64_t> const& getExpressionsUsingVariable(storm::expressions::Variable const& variable) const;
/*!
* Retrieves the expression with the given index.
*
* @param expressionIndex The index of the expression to retrieve.
* @return The corresponding expression.
*/
storm::expressions::Expression const& getExpression(uint_fast64_t expressionIndex) const;
friend std::ostream& operator<<(std::ostream& out, VariablePartition const& partition);
private: private:
/*! /*!
* Merges the blocks with the given indices. * Merges the blocks with the given indices.
@ -130,6 +149,8 @@ namespace storm {
std::vector<storm::expressions::Expression> expressions; std::vector<storm::expressions::Expression> expressions;
}; };
std::ostream& operator<<(std::ostream& out, VariablePartition const& partition);
} }
} }
} }

|||||||
100:0
Loading…
Cancel
Save