Browse Source

started on factoring out preservation information

tempestpy_adaptions
dehnert 7 years ago
parent
commit
c586213bc6
  1. 65
      src/storm/storage/dd/bisimulation/Partition.cpp
  2. 35
      src/storm/storage/dd/bisimulation/Partition.h
  3. 74
      src/storm/storage/dd/bisimulation/PreservationInformation.cpp
  4. 13
      src/storm/storage/dd/bisimulation/PreservationInformation.h

65
src/storm/storage/dd/bisimulation/Partition.cpp

@ -20,12 +20,12 @@ namespace storm {
namespace bisimulation {
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType>::Partition(std::shared_ptr<PreservationInformation> preservationInformation, storm::dd::Add<DdType, ValueType> const& partitionAdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex) : preservationInformation(preservationInformation), partition(partitionAdd), blockVariables(blockVariables), nextFreeBlockIndex(nextFreeBlockIndex) {
Partition<DdType, ValueType>::Partition(storm::dd::Add<DdType, ValueType> const& partitionAdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex) : partition(partitionAdd), blockVariables(blockVariables), nextFreeBlockIndex(nextFreeBlockIndex) {
// Intentionally left empty.
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType>::Partition(std::shared_ptr<PreservationInformation> preservationInformation, storm::dd::Bdd<DdType> const& partitionBdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex) : preservationInformation(preservationInformation), partition(partitionBdd), blockVariables(blockVariables), nextFreeBlockIndex(nextFreeBlockIndex) {
Partition<DdType, ValueType>::Partition(storm::dd::Bdd<DdType> const& partitionBdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex) : partition(partitionBdd), blockVariables(blockVariables), nextFreeBlockIndex(nextFreeBlockIndex) {
// Intentionally left empty.
}
@ -36,72 +36,27 @@ namespace storm {
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::replacePartition(storm::dd::Add<DdType, ValueType> const& newPartitionAdd, uint64_t nextFreeBlockIndex) const {
return Partition<DdType, ValueType>(preservationInformation, newPartitionAdd, blockVariables, nextFreeBlockIndex);
return Partition<DdType, ValueType>(newPartitionAdd, blockVariables, nextFreeBlockIndex);
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::replacePartition(storm::dd::Bdd<DdType> const& newPartitionBdd, uint64_t nextFreeBlockIndex) const {
return Partition<DdType, ValueType>(preservationInformation, newPartitionBdd, blockVariables, nextFreeBlockIndex);
return Partition<DdType, ValueType>(newPartitionBdd, blockVariables, nextFreeBlockIndex);
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, storm::storage::BisimulationType const& bisimulationType) {
return create(model, model.getLabels(), bisimulationType);
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::string> const& labels, storm::storage::BisimulationType const& bisimulationType) {
std::shared_ptr<PreservationInformation> preservationInformation = std::make_shared<PreservationInformation>();
std::vector<storm::expressions::Expression> expressions;
for (auto const& label : labels) {
preservationInformation->addLabel(label);
expressions.push_back(model.getExpression(label));
}
return create(model, expressions, preservationInformation, bisimulationType);
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, storm::storage::BisimulationType const& bisimulationType) {
std::shared_ptr<PreservationInformation> preservationInformation = std::make_shared<PreservationInformation>();
for (auto const& expression : expressions) {
preservationInformation->addExpression(expression);
}
return create(model, expressions, preservationInformation, bisimulationType);
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas, storm::storage::BisimulationType const& bisimulationType) {
if (formulas.empty()) {
return create(model, bisimulationType);
}
std::shared_ptr<PreservationInformation> preservationInformation = std::make_shared<PreservationInformation>();
std::set<std::string> labels;
std::set<storm::expressions::Expression> expressions;
for (auto const& formula : formulas) {
for (auto const& expressionFormula : formula->getAtomicExpressionFormulas()) {
expressions.insert(expressionFormula->getExpression());
preservationInformation->addExpression(expressionFormula->getExpression());
}
for (auto const& labelFormula : formula->getAtomicLabelFormulas()) {
std::string const& label = labelFormula->getLabel();
STORM_LOG_THROW(model.hasLabel(label), storm::exceptions::InvalidPropertyException, "Property refers to illegal label '" << label << "'.");
preservationInformation->addLabel(label);
expressions.insert(model.getExpression(label));
}
}
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, storm::storage::BisimulationType const& bisimulationType, PreservationInformation const& preservationInformation) {
std::vector<storm::expressions::Expression> expressionVector;
for (auto const& expression : expressions) {
for (auto const& expression : preservationInformation.getExpressions()) {
expressionVector.emplace_back(expression);
}
return create(model, expressionVector, preservationInformation, bisimulationType);
return create(model, expressionVector, bisimulationType);
}
template<storm::dd::DdType DdType, typename ValueType>
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, std::shared_ptr<PreservationInformation> const& preservationInformation, storm::storage::BisimulationType const& bisimulationType) {
Partition<DdType, ValueType> Partition<DdType, ValueType>::create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, storm::storage::BisimulationType const& bisimulationType) {
STORM_LOG_THROW(bisimulationType == storm::storage::BisimulationType::Strong, storm::exceptions::NotSupportedException, "Currently only strong bisimulation is supported.");
@ -123,9 +78,9 @@ namespace storm {
// Store the partition as an ADD only in the case of CUDD.
if (DdType == storm::dd::DdType::CUDD) {
return Partition<DdType, ValueType>(preservationInformation, partitionBddAndBlockCount.first.template toAdd<ValueType>(), blockVariables, partitionBddAndBlockCount.second);
return Partition<DdType, ValueType>(partitionBddAndBlockCount.first.template toAdd<ValueType>(), blockVariables, partitionBddAndBlockCount.second);
} else {
return Partition<DdType, ValueType>(preservationInformation, partitionBddAndBlockCount.first, blockVariables, partitionBddAndBlockCount.second);
return Partition<DdType, ValueType>(partitionBddAndBlockCount.first, blockVariables, partitionBddAndBlockCount.second);
}
}

35
src/storm/storage/dd/bisimulation/Partition.h

@ -30,28 +30,9 @@ namespace storm {
bool operator==(Partition<DdType, ValueType> const& other);
Partition<DdType, ValueType> replacePartition(storm::dd::Add<DdType, ValueType> const& newPartitionAdd, uint64_t nextFreeBlockIndex) const;
Partition<DdType, ValueType> replacePartition(storm::dd::Bdd<DdType> const& newPartitionBdd, uint64_t nextFreeBlockIndex) const;
/*!
* Creates a partition from the given model that respects all labels.
*/
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, storm::storage::BisimulationType const& bisimulationType);
/*!
* Creates a partition from the given model that respects the given labels.
*/
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::string> const& labels, storm::storage::BisimulationType const& bisimulationType);
/*!
* Creates a partition from the given model that respects the given expressions.
*/
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, storm::storage::BisimulationType const& bisimulationType);
/*!
* Creates a partition from the given model that preserves the given formulas.
*/
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas, storm::storage::BisimulationType const& bisimulationType);
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, storm::storage::BisimulationType const& bisimulationType, PreservationInformation const& preservationInformation);
uint64_t getNumberOfStates() const;
uint64_t getNumberOfBlocks() const;
@ -69,14 +50,11 @@ namespace storm {
uint64_t getNodeCount() const;
storm::dd::Bdd<DdType> getStates() const;
PreservationInformation const& getPreservationInformation() const;
private:
/*!
* Creates a new partition from the given data.
*
* @param preservationInformation Informatin about which labels/expressions this partition preserves.
* @param partitionAdd An ADD that maps encoding over the state/row variables and the block variable to
* one iff the state is in the block.
* @param blockVariables The variables to use for the block encoding. Its range must be [0, x] where x is
@ -84,12 +62,11 @@ namespace storm {
* @param nextFreeBlockIndex The next free block index. The existing blocks must be encoded with indices
* between 0 and this number.
*/
Partition(std::shared_ptr<PreservationInformation> preservationInformation, storm::dd::Add<DdType, ValueType> const& partitionAdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex);
Partition(storm::dd::Add<DdType, ValueType> const& partitionAdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex);
/*!
* Creates a new partition from the given data.
*
* @param preservationInformation Informatin about which labels/expressions this partition preserves.
* @param partitionBdd A BDD that maps encoding over the state/row variables and the block variable to
* true iff the state is in the block.
* @param blockVariables The variables to use for the block encoding. Their range must be [0, x] where x is
@ -97,18 +74,16 @@ namespace storm {
* @param nextFreeBlockIndex The next free block index. The existing blocks must be encoded with indices
* between 0 and this number.
*/
Partition(std::shared_ptr<PreservationInformation> preservationInformation, storm::dd::Bdd<DdType> const& partitionBdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex);
Partition(storm::dd::Bdd<DdType> const& partitionBdd, std::pair<storm::expressions::Variable, storm::expressions::Variable> const& blockVariables, uint64_t nextFreeBlockIndex);
/*!
* Creates a partition from the given model that respects the given expressions.
*/
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, std::shared_ptr<PreservationInformation> const& preservationInformation, storm::storage::BisimulationType const& bisimulationType);
static Partition create(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, storm::storage::BisimulationType const& bisimulationType);
static std::pair<storm::dd::Bdd<DdType>, uint64_t> createPartitionBdd(storm::dd::DdManager<DdType> const& manager, storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::dd::Bdd<DdType>> const& stateSets, storm::expressions::Variable const& blockVariable);
static std::pair<storm::expressions::Variable, storm::expressions::Variable> createBlockVariables(storm::dd::DdManager<DdType>& manager, uint64_t numberOfDdVariables);
std::shared_ptr<PreservationInformation> preservationInformation;
/// The DD representing the partition. The DD is over the row variables of the model and the block variable.
boost::variant<storm::dd::Bdd<DdType>, storm::dd::Add<DdType, ValueType>> partition;

74
src/storm/storage/dd/bisimulation/PreservationInformation.cpp

@ -1,24 +1,90 @@
#include "storm/storage/dd/bisimulation/PreservationInformation.h"
#include "storm/logic/Formulas.h"
#include "storm/utility/macros.h"
#include "storm/exceptions/InvalidPropertyException.h"
namespace storm {
namespace dd {
namespace bisimulation {
void PreservationInformation::addLabel(std::string const& label) {
template <storm::dd::DdType DdType, typename ValueType>
PreservationInformation<DdType, ValueType>::PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, storm::storage::BisimulationType const& bisimulationType) : PreservationInformation(model, model.getLabels(), bisimulationType) {
// Intentionally left empty.
}
template <storm::dd::DdType DdType, typename ValueType>
PreservationInformation<DdType, ValueType>::PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::string> const& labels, storm::storage::BisimulationType const& bisimulationType) {
for (auto const& label : labels) {
this->addLabel(label);
this->addExpression(model.getExpression(label));
}
}
template <storm::dd::DdType DdType, typename ValueType>
PreservationInformation<DdType, ValueType>::PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, storm::storage::BisimulationType const& bisimulationType) {
for (auto const& e : expressions) {
this->addExpression(e);
}
}
template <storm::dd::DdType DdType, typename ValueType>
PreservationInformation<DdType, ValueType>::PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas, storm::storage::BisimulationType const& bisimulationType) {
if (formulas.empty()) {
// Default to respect all labels if no formulas are given.
for (auto const& label : model.getLabels()) {
this->addLabel(label);
this->addExpression(model.getExpression(label));
}
} else {
std::set<std::string> labels;
std::set<storm::expressions::Expression> expressions;
for (auto const& formula : formulas) {
for (auto const& expressionFormula : formula->getAtomicExpressionFormulas()) {
this->addExpression(expressionFormula->getExpression());
}
for (auto const& labelFormula : formula->getAtomicLabelFormulas()) {
this->addLabel(labelFormula->getLabel());
std::string const& label = labelFormula->getLabel();
STORM_LOG_THROW(model.hasLabel(label), storm::exceptions::InvalidPropertyException, "Property refers to illegal label '" << label << "'.");
this->addExpression(model.getExpression(label));
}
}
std::vector<storm::expressions::Expression> expressionVector;
for (auto const& expression : expressions) {
expressionVector.emplace_back(expression);
}
}
}
template <storm::dd::DdType DdType, typename ValueType>
void PreservationInformation<DdType, ValueType>::addLabel(std::string const& label) {
labels.insert(label);
}
void PreservationInformation::addExpression(storm::expressions::Expression const& expression) {
template <storm::dd::DdType DdType, typename ValueType>
void PreservationInformation<DdType, ValueType>::addExpression(storm::expressions::Expression const& expression) {
expressions.insert(expression);
}
std::set<std::string> const& PreservationInformation::getLabels() const {
template <storm::dd::DdType DdType, typename ValueType>
std::set<std::string> const& PreservationInformation<DdType, ValueType>::getLabels() const {
return labels;
}
std::set<storm::expressions::Expression> const& PreservationInformation::getExpressions() const {
template <storm::dd::DdType DdType, typename ValueType>
std::set<storm::expressions::Expression> const& PreservationInformation<DdType, ValueType>::getExpressions() const {
return expressions;
}
template class PreservationInformation<storm::dd::DdType::CUDD, double>;
template class PreservationInformation<storm::dd::DdType::Sylvan, double>;
template class PreservationInformation<storm::dd::DdType::Sylvan, storm::RationalNumber>;
template class PreservationInformation<storm::dd::DdType::Sylvan, storm::RationalFunction>;
}
}
}

13
src/storm/storage/dd/bisimulation/PreservationInformation.h

@ -2,6 +2,13 @@
#include <set>
#include <string>
#include <vector>
#include <memory>
#include "storm/models/symbolic/Model.h"
#include "storm/storage/bisimulation/BisimulationType.h"
#include "storm/logic/Formula.h"
#include "storm/storage/expressions/Expression.h"
@ -9,9 +16,15 @@ namespace storm {
namespace dd {
namespace bisimulation {
template <storm::dd::DdType DdType, typename ValueType>
class PreservationInformation {
public:
PreservationInformation() = default;
PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, storm::storage::BisimulationType const& bisimulationType);
PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::string> const& labels, storm::storage::BisimulationType const& bisimulationType);
PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<storm::expressions::Expression> const& expressions, storm::storage::BisimulationType const& bisimulationType);
PreservationInformation(storm::models::symbolic::Model<DdType, ValueType> const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas, storm::storage::BisimulationType const& bisimulationType);
void addLabel(std::string const& label);
void addExpression(storm::expressions::Expression const& expression);

Loading…
Cancel
Save