10namespace abstraction {
12template<storm::dd::DdType DdType,
typename ValueType>
14 std::vector<storm::expressions::Expression>
const& statePredicates,
15 std::shared_ptr<storm::utility::solver::SmtSolverFactory>
const& smtSolverFactory)
16 : smtSolver(smtSolverFactory->create(abstractionInformation.getExpressionManager())),
17 abstractionInformation(abstractionInformation),
18 localExpressionInformation(abstractionInformation),
19 relevantPredicatesAndVariables(),
20 concretePredicateVariables(),
21 forceRecomputation(true),
22 cachedBdd(abstractionInformation.getDdManager().getBddOne()),
23 constraint(abstractionInformation.getDdManager().getBddOne()) {
24 for (
auto const& constraint : abstractionInformation.
getConstraints()) {
25 smtSolver->add(constraint);
29 for (
auto const& predicate : statePredicates) {
30 smtSolver->add(predicate);
33 std::set<storm::expressions::Variable> usedVariables = predicate.getVariables();
34 concretePredicateVariables.insert(usedVariables.begin(), usedVariables.end());
36 localExpressionInformation.relate(concretePredicateVariables);
39template<storm::dd::DdType DdType,
typename ValueType>
41 std::vector<std::pair<storm::expressions::Variable, uint_fast64_t>> newPredicateVariables =
42 this->getAbstractionInformation().declareNewVariables(relevantPredicatesAndVariables, newRelevantPredicateIndices);
44 for (
auto const& element : newPredicateVariables) {
45 smtSolver->add(
storm::expressions::iff(element.first, this->getAbstractionInformation().getPredicateByIndex(element.second)));
46 decisionVariables.push_back(element.first);
49 relevantPredicatesAndVariables.insert(relevantPredicatesAndVariables.end(), newPredicateVariables.begin(), newPredicateVariables.end());
50 std::sort(relevantPredicatesAndVariables.begin(), relevantPredicatesAndVariables.end(),
51 [](std::pair<storm::expressions::Variable, uint_fast64_t>
const& firstPair,
52 std::pair<storm::expressions::Variable, uint_fast64_t>
const& secondPair) { return firstPair.second < secondPair.second; });
55template<storm::dd::DdType DdType,
typename ValueType>
58 for (
auto const& predicateIndex : newPredicates) {
59 localExpressionInformation.addExpression(predicateIndex);
62 std::set<uint_fast64_t> newRelevantPredicateIndices = localExpressionInformation.getRelatedExpressions(concretePredicateVariables);
65 STORM_LOG_ASSERT(newRelevantPredicateIndices.size() >= relevantPredicatesAndVariables.size(),
"Illegal size of relevant predicates.");
66 if (newRelevantPredicateIndices.size() > relevantPredicatesAndVariables.size()) {
68 this->popConstraintBdd();
72 addMissingPredicates(newRelevantPredicateIndices);
75 this->pushConstraintBdd();
76 forceRecomputation =
true;
80template<storm::dd::DdType DdType,
typename ValueType>
82 smtSolver->add(constraint);
85template<storm::dd::DdType DdType,
typename ValueType>
88 if (newConstraint != this->constraint) {
89 constraint = newConstraint;
90 this->pushConstraintBdd();
94template<storm::dd::DdType DdType,
typename ValueType>
97 for (
auto const& variableIndexPair : relevantPredicatesAndVariables) {
99 result &= this->getAbstractionInformation().encodePredicateAsSource(variableIndexPair.second);
101 result &= !this->getAbstractionInformation().encodePredicateAsSource(variableIndexPair.second);
107template<storm::dd::DdType DdType,
typename ValueType>
108void StateSetAbstractor<DdType, ValueType>::recomputeCachedBdd() {
113 result |= getStateBdd(model);
120template<storm::dd::DdType DdType,
typename ValueType>
121void StateSetAbstractor<DdType, ValueType>::popConstraintBdd() {
123 if (this->constraint.isOne()) {
129template<storm::dd::DdType DdType,
typename ValueType>
130void StateSetAbstractor<DdType, ValueType>::pushConstraintBdd() {
131 if (this->constraint.isOne()) {
139 std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>> result =
140 constraint.
toExpression(this->getAbstractionInformation().getExpressionManager());
143 for (
auto const& expression : result.first) {
144 smtSolver->add(expression);
148 for (
auto const& indexVariablePair : result.second) {
150 storm::expressions::iff(indexVariablePair.second, this->getAbstractionInformation().getPredicateForDdVariableIndex(indexVariablePair.first)));
154template<storm::dd::DdType DdType,
typename ValueType>
156 if (forceRecomputation) {
157 this->recomputeCachedBdd();
162template<storm::dd::DdType DdType,
typename ValueType>
164 return abstractionInformation.get();
167template<storm::dd::DdType DdType,
typename ValueType>
168AbstractionInformation<DdType>
const& StateSetAbstractor<DdType, ValueType>::getAbstractionInformation()
const {
169 return abstractionInformation.get();
172template class StateSetAbstractor<storm::dd::DdType::CUDD, double>;
173template class StateSetAbstractor<storm::dd::DdType::Sylvan, double>;
174template 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)