23namespace abstraction {
28template<storm::dd::DdType DdType,
typename ValueType>
30 std::shared_ptr<storm::utility::solver::SmtSolverFactory>
const& smtSolverFactory,
33 smtSolverFactory(smtSolverFactory),
34 abstractionInformation(model.getManager(), model.getAllExpressionVariables(), smtSolverFactory->create(model.getManager()),
38 restrictToValidBlocks(
false),
39 validBlockAbstractor(abstractionInformation, smtSolverFactory),
41 refinementPerformed(
true) {
43 STORM_LOG_WARN_COND(model.isLinear(),
"The model appears to contain non-linear expressions, which may cause malfunctioning of the abstraction.");
47 STORM_LOG_THROW(model.getNumberOfAutomata() == 1, storm::exceptions::WrongFormatException,
48 "Cannot create abstract model from program containing more than one automaton.");
51 for (
auto const& range : this->model.get().getAllRangeExpressions()) {
52 abstractionInformation.addConstraint(range);
53 initialStateAbstractor.constrain(range);
54 validBlockAbstractor.constrain(range);
57 uint_fast64_t totalNumberOfEdges = 0;
58 uint_fast64_t maximalDestinationCount = 0;
59 std::vector<storm::expressions::Expression> allGuards;
60 for (
auto const& automaton : model.getAutomata()) {
61 for (
auto const& edge : automaton.getEdges()) {
62 maximalDestinationCount = std::max(maximalDestinationCount,
static_cast<uint_fast64_t
>(edge.getNumberOfDestinations()));
65 totalNumberOfEdges += automaton.getNumberOfEdges();
71 abstractionInformation.createEncodingVariables(
static_cast<uint_fast64_t
>(std::ceil(std::log2(totalNumberOfEdges))), 64,
72 static_cast<uint_fast64_t
>(std::ceil(std::log2(maximalDestinationCount))));
75 auto const& settings = storm::settings::getModule<storm::settings::modules::AbstractionSettings>();
76 bool useDecomposition = settings.isUseDecompositionSet();
78 bool addPredicatesForValidBlocks = !restrictToValidBlocks;
79 bool debug = settings.isDebugSet();
80 for (
auto const& automaton : model.getAutomata()) {
81 automata.emplace_back(automaton, abstractionInformation, this->smtSolverFactory, useDecomposition, addPredicatesForValidBlocks, debug);
85 initialLocationsBdd = automata.front().getInitialLocationsBdd();
86 edgeDecoratorAdd = automata.front().getEdgeDecoratorAdd();
89template<storm::dd::DdType DdType,
typename ValueType>
91 return abstractionInformation.getDdManager();
94template<storm::dd::DdType DdType,
typename ValueType>
97 std::vector<uint_fast64_t> predicateIndices;
99 STORM_LOG_THROW(predicate.hasBooleanType(), storm::exceptions::InvalidArgumentException,
"Expecting a predicate of type bool.");
100 predicateIndices.push_back(abstractionInformation.getOrAddPredicate(predicate));
104 for (
auto& automaton : automata) {
105 automaton.refine(predicateIndices);
109 initialStateAbstractor.refine(predicateIndices);
111 if (this->restrictToValidBlocks) {
113 validBlockAbstractor.refine(predicateIndices);
119template<storm::dd::DdType DdType,
typename ValueType>
121 if (refinementPerformed) {
122 currentGame = buildGame();
123 refinementPerformed =
false;
128template<storm::dd::DdType DdType,
typename ValueType>
130 return abstractionInformation;
133template<storm::dd::DdType DdType,
typename ValueType>
135 return automata.front().getGuard(player1Choice);
138template<storm::dd::DdType DdType,
typename ValueType>
140 return automata.front().getNumberOfUpdates(player1Choice);
143template<storm::dd::DdType DdType,
typename ValueType>
145 uint64_t player1Choice, uint64_t auxiliaryChoice)
const {
146 return automata.front().getVariableUpdates(player1Choice, auxiliaryChoice);
149template<storm::dd::DdType DdType,
typename ValueType>
151 return automata.front().getAssignedVariables(player1Choice);
154template<storm::dd::DdType DdType,
typename ValueType>
156 return std::make_pair(0, automata.front().getNumberOfEdges());
159template<storm::dd::DdType DdType,
typename ValueType>
161 return model.get().getInitialStatesExpression({model.get().getAutomaton(0)});
164template<storm::dd::DdType DdType,
typename ValueType>
167 smtSolverFactory->create(abstractionInformation.getExpressionManager()));
171template<storm::dd::DdType DdType,
typename ValueType>
177 game.
bdd &= edgeDecoratorAdd.notZero();
180 std::set<storm::expressions::Variable> variablesToAbstract(abstractionInformation.getPlayer1VariableSet(abstractionInformation.getPlayer1VariableCount()));
181 std::set<storm::expressions::Variable> successorAndAuxVariables(abstractionInformation.getSuccessorVariables());
183 variablesToAbstract.insert(player2Variables.begin(), player2Variables.end());
184 auto auxVariables = abstractionInformation.getAuxVariableSet(0, abstractionInformation.getAuxVariableCount());
185 variablesToAbstract.insert(auxVariables.begin(), auxVariables.end());
186 successorAndAuxVariables.insert(auxVariables.begin(), auxVariables.end());
190 if (this->isRestrictToRelevantStatesSet()) {
192 for (
auto const& expression : this->terminalStateExpressions) {
193 nonTerminalStates &= !this->getStates(expression);
195 if (this->hasTargetStateExpression()) {
196 nonTerminalStates &= !this->getStates(this->getTargetStateExpression());
199 relevantStatesWatch.stop();
203 if (this->restrictToValidBlocks) {
208 auto choicesWithOnlyValidSuccessors =
209 !game.
bdd.
andExists(!validBlocks.
swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()), successorAndAuxVariables) &&
213 extendedTransitionRelation &= validBlocks && choicesWithOnlyValidSuccessors;
214 initialStates &= validBlocks;
219 initialStates.
addMetaVariables(abstractionInformation.getSourcePredicateVariables());
222 abstractionInformation.getSuccessorVariables())
225 relevantStatesWatch.start();
226 if (this->isRestrictToRelevantStatesSet() && this->hasTargetStateExpression()) {
228 storm::dd::Bdd<DdType> targetStates = reachableStates && this->getStates(this->getTargetStateExpression());
232 targetStates, reachableStates, transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
237 (reachableStates && !targetStates)
238 .relationalProduct(transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
241 transitionRelation &= reachableStates && reachableStates.
swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs());
243 relevantStatesWatch.stop();
244 STORM_LOG_TRACE(
"Restricting to relevant states took " << relevantStatesWatch.getTimeInMilliseconds() <<
"ms.");
250 deadlockStates = reachableStates && !deadlockStates;
254 if (!deadlockStates.
isZero()) {
255 deadlockTransitions = (deadlockStates && abstractionInformation.getAllPredicateIdentities() && abstractionInformation.getAllLocationIdentities() &&
256 abstractionInformation.encodePlayer1Choice(0, abstractionInformation.getPlayer1VariableCount()) &&
258 abstractionInformation.encodeAux(0, 0, abstractionInformation.getAuxVariableCount()))
259 .
template toAdd<ValueType>();
263 BottomStateResult<DdType> bottomStateResult(abstractionInformation.getDdManager().getBddZero(), abstractionInformation.getDdManager().getBddZero());
265 bool hasBottomStates = !bottomStateResult.states.isZero();
271 (extendedTransitionRelation && reachableStates && reachableStates.
swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs()))
272 .
template toAdd<ValueType>();
273 transitionMatrix *= edgeDecoratorAdd;
274 transitionMatrix += deadlockTransitions;
278 (abstractionInformation.getBottomStateBdd(
true,
true) && abstractionInformation.getBottomStateBdd(
false,
true)).
template toAdd<ValueType>();
279 reachableStates &= abstractionInformation.getBottomStateBdd(
true,
true);
280 initialStates &= abstractionInformation.getBottomStateBdd(
true,
true);
283 if (hasBottomStates) {
284 transitionMatrix += bottomStateResult.transitions.template toAdd<ValueType>();
285 reachableStates |= bottomStateResult.states;
288 std::set<storm::expressions::Variable> allNondeterminismVariables = player2Variables;
289 allNondeterminismVariables.insert(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end());
291 std::set<storm::expressions::Variable> allSourceVariables(abstractionInformation.getSourceVariables());
292 allSourceVariables.insert(abstractionInformation.getBottomStateVariable(
true));
293 std::set<storm::expressions::Variable> allSuccessorVariables(abstractionInformation.getSuccessorVariables());
294 allSuccessorVariables.insert(abstractionInformation.getBottomStateVariable(
false));
296 return std::make_unique<MenuGame<DdType, ValueType>>(
297 abstractionInformation.getDdManagerAsSharedPointer(), reachableStates, initialStates, abstractionInformation.
getDdManager().getBddZero(),
298 transitionMatrix, bottomStateResult.states, allSourceVariables, allSuccessorVariables, abstractionInformation.getExtendedSourceSuccessorVariablePairs(),
299 std::set<storm::expressions::Variable>(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end()),
300 player2Variables, allNondeterminismVariables, auxVariables, abstractionInformation.getPredicateToBddMap());
303template<storm::dd::DdType DdType,
typename ValueType>
306 this->exportToDot(*currentGame, filename, highlightStates, filter);
309template<storm::dd::DdType DdType,
typename ValueType>
311 return abstractionInformation.getNumberOfPredicates();
314template<storm::dd::DdType DdType,
typename ValueType>
316 terminalStateExpressions.emplace_back(expression);
319template<storm::dd::DdType DdType,
typename ValueType>
321 for (
auto& automaton : automata) {
322 automaton.notifyGuardsArePredicates();
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
bool isZero() const
Retrieves whether this DD represents the constant zero function.
Bdd< LibraryType > andExists(Bdd< LibraryType > const &other, std::set< storm::expressions::Variable > const &existentialVariables) const
Computes the logical and of the current and the given BDD and existentially abstracts from the given ...
Bdd< LibraryType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the BDD.
void addMetaVariables(std::set< storm::expressions::Variable > const &metaVariables)
Adds the given set of meta variables to the DD.
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
storm::dd::Bdd< DdType > translate(storm::expressions::Expression const &expression)
std::vector< storm::expressions::Expression > const & getPredicates() const
storm::expressions::Expression getInitialStatesExpression() const
Retrieves the expression defining the legal initial values of the variables.
This class represents the settings for the abstraction procedures.
A class that provides convenience operations to display run times.
#define STORM_LOG_DEBUG(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::dd::Bdd< Type > computeBackwardsReachableStates(storm::dd::Bdd< Type > const &initialStates, storm::dd::Bdd< Type > const &constraintStates, storm::dd::Bdd< Type > const &transitions, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables)
std::pair< storm::dd::Bdd< Type >, uint64_t > computeReachableStates(storm::dd::Bdd< Type > const &initialStates, storm::dd::Bdd< Type > const &transitions, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables)
uint_fast64_t numberOfPlayer2Variables
storm::dd::Bdd< DdType > bdd