10#include "storm-config.h"
14namespace abstraction {
16template<storm::dd::DdType DdType,
typename ValueType>
18 std::vector<storm::expressions::Expression>
const& statePredicates,
19 std::shared_ptr<storm::utility::solver::SmtSolverFactory>
const& smtSolverFactory)
20 : smtSolver(smtSolverFactory->create(abstractionInformation.getExpressionManager())),
21 abstractionInformation(abstractionInformation),
22 localExpressionInformation(abstractionInformation),
23 relevantPredicatesAndVariables(),
24 concretePredicateVariables(),
25 forceRecomputation(true),
26 cachedBdd(abstractionInformation.getDdManager().getBddOne()),
27 constraint(abstractionInformation.getDdManager().getBddOne()) {
28 for (
auto const& constraint : abstractionInformation.
getConstraints()) {
29 smtSolver->add(constraint);
33 for (
auto const& predicate : statePredicates) {
34 smtSolver->add(predicate);
37 std::set<storm::expressions::Variable> usedVariables = predicate.getVariables();
38 concretePredicateVariables.insert(usedVariables.begin(), usedVariables.end());
40 localExpressionInformation.relate(concretePredicateVariables);
43template<storm::dd::DdType DdType,
typename ValueType>
45 std::vector<std::pair<storm::expressions::Variable, uint_fast64_t>> newPredicateVariables =
46 this->getAbstractionInformation().declareNewVariables(relevantPredicatesAndVariables, newRelevantPredicateIndices);
48 for (
auto const& element : newPredicateVariables) {
49 smtSolver->add(
storm::expressions::iff(element.first, this->getAbstractionInformation().getPredicateByIndex(element.second)));
50 decisionVariables.push_back(element.first);
53 relevantPredicatesAndVariables.insert(relevantPredicatesAndVariables.end(), newPredicateVariables.begin(), newPredicateVariables.end());
54 std::sort(relevantPredicatesAndVariables.begin(), relevantPredicatesAndVariables.end(),
55 [](std::pair<storm::expressions::Variable, uint_fast64_t>
const& firstPair,
56 std::pair<storm::expressions::Variable, uint_fast64_t>
const& secondPair) { return firstPair.second < secondPair.second; });
59template<storm::dd::DdType DdType,
typename ValueType>
62 for (
auto const& predicateIndex : newPredicates) {
63 localExpressionInformation.addExpression(predicateIndex);
66 std::set<uint_fast64_t> newRelevantPredicateIndices = localExpressionInformation.getRelatedExpressions(concretePredicateVariables);
69 STORM_LOG_ASSERT(newRelevantPredicateIndices.size() >= relevantPredicatesAndVariables.size(),
"Illegal size of relevant predicates.");
70 if (newRelevantPredicateIndices.size() > relevantPredicatesAndVariables.size()) {
72 this->popConstraintBdd();
76 addMissingPredicates(newRelevantPredicateIndices);
79 this->pushConstraintBdd();
80 forceRecomputation =
true;
84template<storm::dd::DdType DdType,
typename ValueType>
86 smtSolver->add(constraint);
89template<storm::dd::DdType DdType,
typename ValueType>
92 if (newConstraint != this->constraint) {
93 constraint = newConstraint;
94 this->pushConstraintBdd();
98template<storm::dd::DdType DdType,
typename ValueType>
101 for (
auto const& variableIndexPair : relevantPredicatesAndVariables) {
103 result &= this->getAbstractionInformation().encodePredicateAsSource(variableIndexPair.second);
105 result &= !this->getAbstractionInformation().encodePredicateAsSource(variableIndexPair.second);
111template<storm::dd::DdType DdType,
typename ValueType>
112void StateSetAbstractor<DdType, ValueType>::recomputeCachedBdd() {
117 result |= getStateBdd(model);
124template<storm::dd::DdType DdType,
typename ValueType>
125void StateSetAbstractor<DdType, ValueType>::popConstraintBdd() {
127 if (this->constraint.isOne()) {
133template<storm::dd::DdType DdType,
typename ValueType>
134void StateSetAbstractor<DdType, ValueType>::pushConstraintBdd() {
135 if (this->constraint.isOne()) {
143 std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> result =
144 constraint.
toExpression(this->getAbstractionInformation().getExpressionManager());
147 for (
auto const& expression : result.first) {
148 smtSolver->add(expression);
152 for (
auto const& indexVariablePair : result.second) {
154 storm::expressions::iff(indexVariablePair.second, this->getAbstractionInformation().getPredicateForDdVariableIndex(indexVariablePair.first)));
158template<storm::dd::DdType DdType,
typename ValueType>
160 if (forceRecomputation) {
161 this->recomputeCachedBdd();
166template<storm::dd::DdType DdType,
typename ValueType>
168 return abstractionInformation.get();
171template<storm::dd::DdType DdType,
typename ValueType>
172AbstractionInformation<DdType>
const& StateSetAbstractor<DdType, ValueType>::getAbstractionInformation()
const {
173 return abstractionInformation.get();
176template class StateSetAbstractor<storm::dd::DdType::CUDD, double>;
177template class StateSetAbstractor<storm::dd::DdType::Sylvan, double>;
178#ifdef STORM_HAVE_CARL
179template class StateSetAbstractor<storm::dd::DdType::Sylvan, storm::RationalNumber>;
std::pair< std::vector< storm::expressions::Expression >, std::unordered_map< uint_fast64_t, storm::expressions::Variable > > toExpression(storm::expressions::ExpressionManager &manager) const
Translates the function the BDD is representing to a set of expressions that characterize the functio...
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
void constrain(storm::expressions::Expression const &constraint)
Constrains the abstract states with the given expression.
void refine(std::vector< uint_fast64_t > const &newPredicateIndices)
Refines the abstractor by making the given predicates new abstract predicates.
storm::dd::Bdd< DdType > getAbstractStates()
Retrieves the set of abstract states matching all predicates added to this abstractor.
StateSetAbstractor(StateSetAbstractor const &other)=default
The base class for all model references.
virtual bool getBooleanValue(storm::expressions::Variable const &variable) const =0
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)
Expression iff(Expression const &first, Expression const &second)