Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
JaniMenuGameAbstractor.cpp
Go to the documentation of this file.
2
17#include "storm/utility/dd.h"
20
21namespace storm::gbar {
22namespace abstraction {
23namespace jani {
24
25template<storm::dd::DdType DdType, typename ValueType>
27 std::shared_ptr<storm::utility::solver::SmtSolverFactory> const& smtSolverFactory,
28 AbstractionOptions const& options)
29 : MenuGameAbstractor<DdType, ValueType>(options),
30 model(model),
31 smtSolverFactory(smtSolverFactory),
32 abstractionInformation(env, model.getManager(), model.getAllExpressionVariables(), smtSolverFactory->create(model.getManager()),
33 AbstractionInformationOptions(options.constraints)),
34 automata(),
35 initialStateAbstractor(abstractionInformation, {model.getInitialStatesExpression()}, this->smtSolverFactory),
36 restrictToValidBlocks(false),
37 validBlockAbstractor(abstractionInformation, smtSolverFactory),
38 currentGame(nullptr),
39 refinementPerformed(true) {
40 // Check whether the model is linear as the abstraction requires this.
41 STORM_LOG_WARN_COND(model.isLinear(), "The model appears to contain non-linear expressions, which may cause malfunctioning of the abstraction.");
42
43 // For now, we assume that there is a single module. If the program has more than one module, it needs
44 // to be flattened before the procedure.
45 STORM_LOG_THROW(model.getNumberOfAutomata() == 1, storm::exceptions::WrongFormatException,
46 "Cannot create abstract model from program containing more than one automaton.");
47
48 // Add all variables range expressions to the information object.
49 for (auto const& range : this->model.get().getAllRangeExpressions()) {
50 abstractionInformation.addConstraint(range);
51 initialStateAbstractor.constrain(range);
52 validBlockAbstractor.constrain(range);
53 }
54
55 uint_fast64_t totalNumberOfEdges = 0;
56 uint_fast64_t maximalDestinationCount = 0;
57 std::vector<storm::expressions::Expression> allGuards;
58 for (auto const& automaton : model.getAutomata()) {
59 for (auto const& edge : automaton.getEdges()) {
60 maximalDestinationCount = std::max(maximalDestinationCount, static_cast<uint_fast64_t>(edge.getNumberOfDestinations()));
61 }
62
63 totalNumberOfEdges += automaton.getNumberOfEdges();
64 }
65
66 // NOTE: currently we assume that 64 player 2 variables suffice, which corresponds to 2^64 possible
67 // choices. If for some reason this should not be enough, we could grow this vector dynamically, but
68 // odds are that it's impossible to treat such models in any event.
69 abstractionInformation.createEncodingVariables(static_cast<uint_fast64_t>(std::ceil(std::log2(totalNumberOfEdges))), 64,
70 static_cast<uint_fast64_t>(std::ceil(std::log2(maximalDestinationCount))));
71
72 // For each module of the concrete program, we create an abstract counterpart.
73 bool useDecomposition = options.useDecomposition;
74 restrictToValidBlocks = options.restrictToValidBlocks;
75 bool addPredicatesForValidBlocks = !restrictToValidBlocks;
76 bool debug = options.debug;
77 for (auto const& automaton : model.getAutomata()) {
78 automata.emplace_back(automaton, abstractionInformation, this->smtSolverFactory, useDecomposition, addPredicatesForValidBlocks, debug);
79 }
80
81 // Retrieve global BDDs/ADDs so we can multiply them in the abstraction process.
82 initialLocationsBdd = automata.front().getInitialLocationsBdd();
83 edgeDecoratorAdd = automata.front().getEdgeDecoratorAdd();
84}
85
86template<storm::dd::DdType DdType, typename ValueType>
88 return abstractionInformation.getDdManager();
89}
90
91template<storm::dd::DdType DdType, typename ValueType>
93 // Add the predicates to the global list of predicates and gather their indices.
94 std::vector<uint_fast64_t> predicateIndices;
95 for (auto const& predicate : command.getPredicates()) {
96 STORM_LOG_THROW(predicate.hasBooleanType(), storm::exceptions::InvalidArgumentException, "Expecting a predicate of type bool.");
97 predicateIndices.push_back(abstractionInformation.getOrAddPredicate(predicate));
98 }
99
100 // Refine all abstract automata.
101 for (auto& automaton : automata) {
102 automaton.refine(predicateIndices);
103 }
104
105 // Refine initial state abstractor.
106 initialStateAbstractor.refine(predicateIndices);
107
108 if (this->restrictToValidBlocks) {
109 // Refine the valid blocks.
110 validBlockAbstractor.refine(predicateIndices);
111 }
112
113 refinementPerformed |= !command.getPredicates().empty();
114}
115
116template<storm::dd::DdType DdType, typename ValueType>
118 if (refinementPerformed) {
119 currentGame = buildGame();
120 refinementPerformed = false;
121 }
122 return *currentGame;
123}
124
125template<storm::dd::DdType DdType, typename ValueType>
129
130template<storm::dd::DdType DdType, typename ValueType>
132 return automata.front().getGuard(player1Choice);
133}
134
135template<storm::dd::DdType DdType, typename ValueType>
137 return automata.front().getNumberOfUpdates(player1Choice);
138}
139
140template<storm::dd::DdType DdType, typename ValueType>
141std::map<storm::expressions::Variable, storm::expressions::Expression> JaniMenuGameAbstractor<DdType, ValueType>::getVariableUpdates(
142 uint64_t player1Choice, uint64_t auxiliaryChoice) const {
143 return automata.front().getVariableUpdates(player1Choice, auxiliaryChoice);
144}
145
146template<storm::dd::DdType DdType, typename ValueType>
147std::set<storm::expressions::Variable> const& JaniMenuGameAbstractor<DdType, ValueType>::getAssignedVariables(uint64_t player1Choice) const {
148 return automata.front().getAssignedVariables(player1Choice);
149}
150
151template<storm::dd::DdType DdType, typename ValueType>
153 return std::make_pair(0, automata.front().getNumberOfEdges());
154}
155
156template<storm::dd::DdType DdType, typename ValueType>
158 return model.get().getInitialStatesExpression({model.get().getAutomaton(0)});
159}
160
161template<storm::dd::DdType DdType, typename ValueType>
163 storm::gbar::abstraction::ExpressionTranslator<DdType> translator(abstractionInformation,
164 smtSolverFactory->create(abstractionInformation.getExpressionManager()));
165 return translator.translate(expression);
166}
167
168template<storm::dd::DdType DdType, typename ValueType>
169std::unique_ptr<MenuGame<DdType, ValueType>> JaniMenuGameAbstractor<DdType, ValueType>::buildGame() {
170 // As long as there is only one automaton, we only build its game representation.
171 GameBddResult<DdType> game = automata.front().abstract();
172
173 // Add the locations to the transitions.
174 game.bdd &= edgeDecoratorAdd.notZero();
175
176 // Construct a set of all unnecessary variables, so we can abstract from it.
177 std::set<storm::expressions::Variable> variablesToAbstract(abstractionInformation.getPlayer1VariableSet(abstractionInformation.getPlayer1VariableCount()));
178 std::set<storm::expressions::Variable> successorAndAuxVariables(abstractionInformation.getSuccessorVariables());
179 auto player2Variables = abstractionInformation.getPlayer2VariableSet(game.numberOfPlayer2Variables);
180 variablesToAbstract.insert(player2Variables.begin(), player2Variables.end());
181 auto auxVariables = abstractionInformation.getAuxVariableSet(0, abstractionInformation.getAuxVariableCount());
182 variablesToAbstract.insert(auxVariables.begin(), auxVariables.end());
183 successorAndAuxVariables.insert(auxVariables.begin(), auxVariables.end());
184
185 storm::utility::Stopwatch relevantStatesWatch(true);
186 storm::dd::Bdd<DdType> nonTerminalStates = this->abstractionInformation.getDdManager().getBddOne();
187 if (this->isRestrictToRelevantStatesSet()) {
188 // Compute which states are non-terminal.
189 for (auto const& expression : this->terminalStateExpressions) {
190 nonTerminalStates &= !this->getStates(expression);
191 }
192 if (this->hasTargetStateExpression()) {
193 nonTerminalStates &= !this->getStates(this->getTargetStateExpression());
194 }
195 }
196 relevantStatesWatch.stop();
197
198 storm::dd::Bdd<DdType> extendedTransitionRelation = nonTerminalStates && game.bdd;
199 storm::dd::Bdd<DdType> initialStates = initialLocationsBdd && initialStateAbstractor.getAbstractStates();
200 if (this->restrictToValidBlocks) {
201 STORM_LOG_DEBUG("Restricting to valid blocks.");
202 storm::dd::Bdd<DdType> validBlocks = validBlockAbstractor.getValidBlocks();
203
204 // Compute the choices with only valid successors so we can restrict the game to these.
205 auto choicesWithOnlyValidSuccessors =
206 !game.bdd.andExists(!validBlocks.swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()), successorAndAuxVariables) &&
207 game.bdd.existsAbstract(successorAndAuxVariables);
208
209 // Restrict the proper parts.
210 extendedTransitionRelation &= validBlocks && choicesWithOnlyValidSuccessors;
211 initialStates &= validBlocks;
212 }
213
214 // Do a reachability analysis on the raw transition relation.
215 storm::dd::Bdd<DdType> transitionRelation = extendedTransitionRelation.existsAbstract(variablesToAbstract);
216 initialStates.addMetaVariables(abstractionInformation.getSourcePredicateVariables());
217 storm::dd::Bdd<DdType> reachableStates =
218 storm::utility::dd::computeReachableStates(initialStates, transitionRelation, abstractionInformation.getSourceVariables(),
219 abstractionInformation.getSuccessorVariables())
220 .first;
221
222 relevantStatesWatch.start();
223 if (this->isRestrictToRelevantStatesSet() && this->hasTargetStateExpression()) {
224 // Get the target state BDD.
225 storm::dd::Bdd<DdType> targetStates = reachableStates && this->getStates(this->getTargetStateExpression());
226
227 // In the presence of target states, we keep only states that can reach the target states.
229 targetStates, reachableStates, transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
230
231 // Include all successors of reachable states, because the backward search otherwise potentially
232 // cuts probability 0 choices of these states.
233 reachableStates |=
234 (reachableStates && !targetStates)
235 .relationalProduct(transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
236
237 // Restrict transition relation to relevant fragment for computation of deadlock states.
238 transitionRelation &= reachableStates && reachableStates.swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs());
239
240 relevantStatesWatch.stop();
241 STORM_LOG_TRACE("Restricting to relevant states took " << relevantStatesWatch.getTimeInMilliseconds() << "ms.");
242 }
243
244 // Find the deadlock states in the model. Note that this does not find the 'deadlocks' in bottom states,
245 // as the bottom states are not contained in the reachable states.
246 storm::dd::Bdd<DdType> deadlockStates = transitionRelation.existsAbstract(abstractionInformation.getSuccessorVariables());
247 deadlockStates = reachableStates && !deadlockStates;
248
249 // If there are deadlock states, we fix them now.
250 storm::dd::Add<DdType, ValueType> deadlockTransitions = abstractionInformation.getDdManager().template getAddZero<ValueType>();
251 if (!deadlockStates.isZero()) {
252 deadlockTransitions = (deadlockStates && abstractionInformation.getAllPredicateIdentities() && abstractionInformation.getAllLocationIdentities() &&
253 abstractionInformation.encodePlayer1Choice(0, abstractionInformation.getPlayer1VariableCount()) &&
254 abstractionInformation.encodePlayer2Choice(0, 0, game.numberOfPlayer2Variables) &&
255 abstractionInformation.encodeAux(0, 0, abstractionInformation.getAuxVariableCount()))
256 .template toAdd<ValueType>();
257 }
258
259 // Compute bottom states and the appropriate transitions if necessary.
260 BottomStateResult<DdType> bottomStateResult(abstractionInformation.getDdManager().getBddZero(), abstractionInformation.getDdManager().getBddZero());
261 bottomStateResult = automata.front().getBottomStateTransitions(reachableStates, game.numberOfPlayer2Variables);
262 bool hasBottomStates = !bottomStateResult.states.isZero();
263
264 // Construct the transition matrix by cutting away the transitions of unreachable states.
265 // Note that we also restrict the successor states of transitions, because there might be successors
266 // that are not in the set of relevant states we restrict to.
267 storm::dd::Add<DdType, ValueType> transitionMatrix =
268 (extendedTransitionRelation && reachableStates && reachableStates.swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs()))
269 .template toAdd<ValueType>();
270 transitionMatrix *= edgeDecoratorAdd;
271 transitionMatrix += deadlockTransitions;
272
273 // Extend the current game information with the 'non-bottom' tag before potentially adding bottom state transitions.
274 transitionMatrix *=
275 (abstractionInformation.getBottomStateBdd(true, true) && abstractionInformation.getBottomStateBdd(false, true)).template toAdd<ValueType>();
276 reachableStates &= abstractionInformation.getBottomStateBdd(true, true);
277 initialStates &= abstractionInformation.getBottomStateBdd(true, true);
278
279 // If there are bottom transitions, exnted the transition matrix and reachable states now.
280 if (hasBottomStates) {
281 transitionMatrix += bottomStateResult.transitions.template toAdd<ValueType>();
282 reachableStates |= bottomStateResult.states;
283 }
284
285 std::set<storm::expressions::Variable> allNondeterminismVariables = player2Variables;
286 allNondeterminismVariables.insert(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end());
287
288 std::set<storm::expressions::Variable> allSourceVariables(abstractionInformation.getSourceVariables());
289 allSourceVariables.insert(abstractionInformation.getBottomStateVariable(true));
290 std::set<storm::expressions::Variable> allSuccessorVariables(abstractionInformation.getSuccessorVariables());
291 allSuccessorVariables.insert(abstractionInformation.getBottomStateVariable(false));
292
293 return std::make_unique<MenuGame<DdType, ValueType>>(
294 abstractionInformation.getDdManagerAsSharedPointer(), reachableStates, initialStates, abstractionInformation.getDdManager().getBddZero(),
295 transitionMatrix, bottomStateResult.states, allSourceVariables, allSuccessorVariables, abstractionInformation.getExtendedSourceSuccessorVariablePairs(),
296 std::set<storm::expressions::Variable>(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end()),
297 player2Variables, allNondeterminismVariables, auxVariables, abstractionInformation.getPredicateToBddMap());
298}
299
300template<storm::dd::DdType DdType, typename ValueType>
301void JaniMenuGameAbstractor<DdType, ValueType>::exportToDot(std::string const& filename, storm::dd::Bdd<DdType> const& highlightStates,
302 storm::dd::Bdd<DdType> const& filter) const {
303 this->exportToDot(*currentGame, filename, highlightStates, filter);
304}
305
306template<storm::dd::DdType DdType, typename ValueType>
308 return abstractionInformation.getNumberOfPredicates();
309}
310
311template<storm::dd::DdType DdType, typename ValueType>
313 terminalStateExpressions.emplace_back(expression);
314}
315
316template<storm::dd::DdType DdType, typename ValueType>
318 for (auto& automaton : automata) {
319 automaton.notifyGuardsArePredicates();
320 }
321}
322
323// Explicitly instantiate the class.
327} // namespace jani
328} // namespace abstraction
329} // namespace storm::gbar
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
Definition Bdd.cpp:172
bool isZero() const
Retrieves whether this DD represents the constant zero function.
Definition Bdd.cpp:541
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 ...
Definition Bdd.cpp:190
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.
Definition Bdd.cpp:296
void addMetaVariables(std::set< storm::expressions::Variable > const &metaVariables)
Adds the given set of meta variables to the DD.
Definition Dd.cpp:43
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
Definition Dd.cpp:38
storm::dd::Bdd< DdType > translate(storm::expressions::Expression const &expression)
MenuGameAbstractor(AbstractionOptions const &options)
This class represents a discrete-time stochastic two-player game.
Definition MenuGame.h:14
std::vector< storm::expressions::Expression > const & getPredicates() const
storm::expressions::Expression getInitialExpression() const override
Retrieves the expression that characterizes the initial states.
virtual void refine(RefinementCommand const &command) override
Performs the given refinement command.
storm::dd::DdManager< DdType > const & getDdManager() const override
MenuGame< DdType, ValueType > abstract() override
Uses the current set of predicates to derive the abstract menu game in the form of an ADD.
AbstractionInformation< DdType > const & getAbstractionInformation() const override
Retrieves information about the abstraction.
storm::expressions::Expression const & getGuard(uint64_t player1Choice) const override
Retrieves the guard predicate of the given player 1 choice.
virtual uint64_t getNumberOfPredicates() const override
Retrieves the number of predicates currently in use.
std::map< storm::expressions::Variable, storm::expressions::Expression > getVariableUpdates(uint64_t player1Choice, uint64_t auxiliaryChoice) const override
Retrieves a mapping from variables to expressions that define their updates wrt.
virtual std::set< storm::expressions::Variable > const & getAssignedVariables(uint64_t player1Choice) const override
Retrieves the variables assigned by the given player 1 choice.
virtual void exportToDot(std::string const &filename, storm::dd::Bdd< DdType > const &highlightStates, storm::dd::Bdd< DdType > const &filter) const override
Exports the current state of the abstraction in the dot format to the given file.
virtual uint64_t getNumberOfUpdates(uint64_t player1Choice) const override
Retrieves the number of updates of the specified player 1 choice.
std::pair< uint64_t, uint64_t > getPlayer1ChoiceRange() const override
Retrieves the range of player 1 choices.
virtual void notifyGuardsArePredicates() override
Notifies the abstractor that the guards are predicates, which may be used to improve the bottom state...
storm::dd::Bdd< DdType > getStates(storm::expressions::Expression const &expression) override
Retrieves a BDD that characterizes the states corresponding to the given expression.
virtual void addTerminalStates(storm::expressions::Expression const &expression) override
Adds the expression to the ones characterizing terminal states, i.e.
JaniMenuGameAbstractor(storm::Environment const &env, storm::jani::Model const &model, std::shared_ptr< storm::utility::solver::SmtSolverFactory > const &smtSolverFactory, AbstractionOptions const &options=AbstractionOptions())
Constructs an abstractor for the given model.
A class that provides convenience operations to display run times.
Definition Stopwatch.h:13
#define STORM_LOG_DEBUG(message)
Definition logging.h:28
#define STORM_LOG_TRACE(message)
Definition logging.h:22
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:54
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
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)
Definition dd.cpp:50
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)
Definition dd.cpp:13
Options that configure the game-based abstraction-refinement procedure.