diff --git a/src/storm/abstraction/prism/AbstractCommand.cpp b/src/storm/abstraction/prism/AbstractCommand.cpp index 4430dccc3..0124d24d2 100644 --- a/src/storm/abstraction/prism/AbstractCommand.cpp +++ b/src/storm/abstraction/prism/AbstractCommand.cpp @@ -51,21 +51,12 @@ namespace storm { // whether they changed. std::pair, std::vector>> newRelevantPredicates = this->computeRelevantPredicates(); - // If the DD does not need recomputation, we can return the cached result. - bool recomputeDd = forceRecomputation || this->relevantPredicatesChanged(newRelevantPredicates); - if (!recomputeDd) { - // If the new predicates are unrelated to the BDD of this command, we need to multiply their identities. - cachedDd.bdd &= computeMissingGlobalIdentities(); - } else { - // If the DD needs recomputation, it is because of new relevant predicates, so we need to assert the appropriate clauses in the solver. + // Check whether we need to recompute the abstraction. + bool relevantPredicatesChanged = this->relevantPredicatesChanged(newRelevantPredicates); + if (relevantPredicatesChanged) { addMissingPredicates(newRelevantPredicates); - - // Finally recompute the cached BDD. - this->recomputeCachedBdd(); - - // Disable forcing recomputation until it is set again. - forceRecomputation = false; } + forceRecomputation |= relevantPredicatesChanged; // Refine bottom state abstractor. Note that this does not trigger a recomputation yet. bottomStateAbstractor.refine(predicates); @@ -141,6 +132,7 @@ namespace storm { auto end = std::chrono::high_resolution_clock::now(); STORM_LOG_TRACE("Enumerated " << numberOfSolutions << " solutions in " << std::chrono::duration_cast(end - start).count() << "ms."); + forceRecomputation = false; } template @@ -318,6 +310,12 @@ namespace storm { template GameBddResult AbstractCommand::getAbstractBdd() { + if (forceRecomputation) { + this->recomputeCachedBdd(); + } else { + cachedDd.bdd &= computeMissingGlobalIdentities(); + } + return cachedDd; } diff --git a/src/storm/abstraction/prism/AbstractProgram.cpp b/src/storm/abstraction/prism/AbstractProgram.cpp index a68c730cf..f2e5f718d 100644 --- a/src/storm/abstraction/prism/AbstractProgram.cpp +++ b/src/storm/abstraction/prism/AbstractProgram.cpp @@ -31,7 +31,7 @@ namespace storm { AbstractProgram::AbstractProgram(storm::prism::Program const& program, std::shared_ptr const& smtSolverFactory, bool addAllGuards) - : program(program), smtSolverFactory(smtSolverFactory), abstractionInformation(program.getManager()), modules(), initialStateAbstractor(abstractionInformation, program.getAllExpressionVariables(), {program.getInitialStatesExpression()}, this->smtSolverFactory), addedAllGuards(addAllGuards), currentGame(nullptr) { + : program(program), smtSolverFactory(smtSolverFactory), abstractionInformation(program.getManager()), modules(), initialStateAbstractor(abstractionInformation, program.getAllExpressionVariables(), {program.getInitialStatesExpression()}, this->smtSolverFactory), addedAllGuards(addAllGuards), currentGame(nullptr), refinementPerformed(false) { // For now, we assume that there is a single module. If the program has more than one module, it needs // to be flattened before the procedure. @@ -103,13 +103,16 @@ namespace storm { // Refine initial state abstractor. initialStateAbstractor.refine(newPredicateIndices); - // Finally, we rebuild the game. - currentGame = buildGame(); + // Update the flag that stores whether a refinement was performed. + refinementPerformed = refinementPerformed || !newPredicateIndices.empty(); } template - MenuGame AbstractProgram::getAbstractGame() { - STORM_LOG_ASSERT(currentGame != nullptr, "Game was not properly created."); + MenuGame AbstractProgram::abstract() { + if (refinementPerformed) { + currentGame = buildGame(); + refinementPerformed = true; + } return *currentGame; } diff --git a/src/storm/abstraction/prism/AbstractProgram.h b/src/storm/abstraction/prism/AbstractProgram.h index fca4ab6c0..c67506e61 100644 --- a/src/storm/abstraction/prism/AbstractProgram.h +++ b/src/storm/abstraction/prism/AbstractProgram.h @@ -55,7 +55,7 @@ namespace storm { * * @return The abstract stochastic two player game. */ - MenuGame getAbstractGame(); + MenuGame abstract(); /*! * Retrieves information about the abstraction. @@ -142,6 +142,9 @@ namespace storm { // The current game-based abstraction. std::unique_ptr> currentGame; + + // A flag storing whether a refinement was performed. + bool refinementPerformed; }; } } diff --git a/src/storm/abstraction/prism/PrismMenuGameAbstractor.cpp b/src/storm/abstraction/prism/PrismMenuGameAbstractor.cpp index a4a1eae47..7789bfc8a 100644 --- a/src/storm/abstraction/prism/PrismMenuGameAbstractor.cpp +++ b/src/storm/abstraction/prism/PrismMenuGameAbstractor.cpp @@ -16,7 +16,7 @@ namespace storm { template storm::abstraction::MenuGame PrismMenuGameAbstractor::abstract() { - return abstractProgram.getAbstractGame(); + return abstractProgram.abstract(); } template