Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
JaniMenuGameAbstractor.cpp
Go to the documentation of this file.
2
18#include "storm/utility/dd.h"
21
22namespace storm::gbar {
23namespace abstraction {
24namespace jani {
25
27
28template<storm::dd::DdType DdType, typename ValueType>
30 std::shared_ptr<storm::utility::solver::SmtSolverFactory> const& smtSolverFactory,
31 MenuGameAbstractorOptions const& options)
32 : model(model),
33 smtSolverFactory(smtSolverFactory),
34 abstractionInformation(model.getManager(), model.getAllExpressionVariables(), smtSolverFactory->create(model.getManager()),
35 AbstractionInformationOptions(options.constraints)),
36 automata(),
37 initialStateAbstractor(abstractionInformation, {model.getInitialStatesExpression()}, this->smtSolverFactory),
38 restrictToValidBlocks(false),
39 validBlockAbstractor(abstractionInformation, smtSolverFactory),
40 currentGame(nullptr),
41 refinementPerformed(true) {
42 // Check whether the model is linear as the abstraction requires this.
43 STORM_LOG_WARN_COND(model.isLinear(), "The model appears to contain non-linear expressions, which may cause malfunctioning of the abstraction.");
44
45 // For now, we assume that there is a single module. If the program has more than one module, it needs
46 // to be flattened before the procedure.
47 STORM_LOG_THROW(model.getNumberOfAutomata() == 1, storm::exceptions::WrongFormatException,
48 "Cannot create abstract model from program containing more than one automaton.");
49
50 // Add all variables range expressions to the information object.
51 for (auto const& range : this->model.get().getAllRangeExpressions()) {
52 abstractionInformation.addConstraint(range);
53 initialStateAbstractor.constrain(range);
54 validBlockAbstractor.constrain(range);
55 }
56
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()));
63 }
64
65 totalNumberOfEdges += automaton.getNumberOfEdges();
66 }
67
68 // NOTE: currently we assume that 64 player 2 variables suffice, which corresponds to 2^64 possible
69 // choices. If for some reason this should not be enough, we could grow this vector dynamically, but
70 // odds are that it's impossible to treat such models in any event.
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))));
73
74 // For each module of the concrete program, we create an abstract counterpart.
75 auto const& settings = storm::settings::getModule<storm::settings::modules::AbstractionSettings>();
76 bool useDecomposition = settings.isUseDecompositionSet();
77 restrictToValidBlocks = settings.getValidBlockMode() == storm::settings::modules::AbstractionSettings::ValidBlockMode::BlockEnumeration;
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);
82 }
83
84 // Retrieve global BDDs/ADDs so we can multiply them in the abstraction process.
85 initialLocationsBdd = automata.front().getInitialLocationsBdd();
86 edgeDecoratorAdd = automata.front().getEdgeDecoratorAdd();
87}
88
89template<storm::dd::DdType DdType, typename ValueType>
91 return abstractionInformation.getDdManager();
92}
93
94template<storm::dd::DdType DdType, typename ValueType>
96 // Add the predicates to the global list of predicates and gather their indices.
97 std::vector<uint_fast64_t> predicateIndices;
98 for (auto const& predicate : command.getPredicates()) {
99 STORM_LOG_THROW(predicate.hasBooleanType(), storm::exceptions::InvalidArgumentException, "Expecting a predicate of type bool.");
100 predicateIndices.push_back(abstractionInformation.getOrAddPredicate(predicate));
101 }
102
103 // Refine all abstract automata.
104 for (auto& automaton : automata) {
105 automaton.refine(predicateIndices);
106 }
107
108 // Refine initial state abstractor.
109 initialStateAbstractor.refine(predicateIndices);
110
111 if (this->restrictToValidBlocks) {
112 // Refine the valid blocks.
113 validBlockAbstractor.refine(predicateIndices);
114 }
115
116 refinementPerformed |= !command.getPredicates().empty();
117}
118
119template<storm::dd::DdType DdType, typename ValueType>
121 if (refinementPerformed) {
122 currentGame = buildGame();
123 refinementPerformed = false;
124 }
125 return *currentGame;
126}
127
128template<storm::dd::DdType DdType, typename ValueType>
132
133template<storm::dd::DdType DdType, typename ValueType>
135 return automata.front().getGuard(player1Choice);
136}
137
138template<storm::dd::DdType DdType, typename ValueType>
140 return automata.front().getNumberOfUpdates(player1Choice);
141}
142
143template<storm::dd::DdType DdType, typename ValueType>
144std::map<storm::expressions::Variable, storm::expressions::Expression> JaniMenuGameAbstractor<DdType, ValueType>::getVariableUpdates(
145 uint64_t player1Choice, uint64_t auxiliaryChoice) const {
146 return automata.front().getVariableUpdates(player1Choice, auxiliaryChoice);
147}
148
149template<storm::dd::DdType DdType, typename ValueType>
150std::set<storm::expressions::Variable> const& JaniMenuGameAbstractor<DdType, ValueType>::getAssignedVariables(uint64_t player1Choice) const {
151 return automata.front().getAssignedVariables(player1Choice);
152}
153
154template<storm::dd::DdType DdType, typename ValueType>
156 return std::make_pair(0, automata.front().getNumberOfEdges());
157}
158
159template<storm::dd::DdType DdType, typename ValueType>
161 return model.get().getInitialStatesExpression({model.get().getAutomaton(0)});
162}
163
164template<storm::dd::DdType DdType, typename ValueType>
166 storm::gbar::abstraction::ExpressionTranslator<DdType> translator(abstractionInformation,
167 smtSolverFactory->create(abstractionInformation.getExpressionManager()));
168 return translator.translate(expression);
169}
170
171template<storm::dd::DdType DdType, typename ValueType>
172std::unique_ptr<MenuGame<DdType, ValueType>> JaniMenuGameAbstractor<DdType, ValueType>::buildGame() {
173 // As long as there is only one automaton, we only build its game representation.
174 GameBddResult<DdType> game = automata.front().abstract();
175
176 // Add the locations to the transitions.
177 game.bdd &= edgeDecoratorAdd.notZero();
178
179 // Construct a set of all unnecessary variables, so we can abstract from it.
180 std::set<storm::expressions::Variable> variablesToAbstract(abstractionInformation.getPlayer1VariableSet(abstractionInformation.getPlayer1VariableCount()));
181 std::set<storm::expressions::Variable> successorAndAuxVariables(abstractionInformation.getSuccessorVariables());
182 auto player2Variables = abstractionInformation.getPlayer2VariableSet(game.numberOfPlayer2Variables);
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());
187
188 storm::utility::Stopwatch relevantStatesWatch(true);
189 storm::dd::Bdd<DdType> nonTerminalStates = this->abstractionInformation.getDdManager().getBddOne();
190 if (this->isRestrictToRelevantStatesSet()) {
191 // Compute which states are non-terminal.
192 for (auto const& expression : this->terminalStateExpressions) {
193 nonTerminalStates &= !this->getStates(expression);
194 }
195 if (this->hasTargetStateExpression()) {
196 nonTerminalStates &= !this->getStates(this->getTargetStateExpression());
197 }
198 }
199 relevantStatesWatch.stop();
200
201 storm::dd::Bdd<DdType> extendedTransitionRelation = nonTerminalStates && game.bdd;
202 storm::dd::Bdd<DdType> initialStates = initialLocationsBdd && initialStateAbstractor.getAbstractStates();
203 if (this->restrictToValidBlocks) {
204 STORM_LOG_DEBUG("Restricting to valid blocks.");
205 storm::dd::Bdd<DdType> validBlocks = validBlockAbstractor.getValidBlocks();
206
207 // Compute the choices with only valid successors so we can restrict the game to these.
208 auto choicesWithOnlyValidSuccessors =
209 !game.bdd.andExists(!validBlocks.swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()), successorAndAuxVariables) &&
210 game.bdd.existsAbstract(successorAndAuxVariables);
211
212 // Restrict the proper parts.
213 extendedTransitionRelation &= validBlocks && choicesWithOnlyValidSuccessors;
214 initialStates &= validBlocks;
215 }
216
217 // Do a reachability analysis on the raw transition relation.
218 storm::dd::Bdd<DdType> transitionRelation = extendedTransitionRelation.existsAbstract(variablesToAbstract);
219 initialStates.addMetaVariables(abstractionInformation.getSourcePredicateVariables());
220 storm::dd::Bdd<DdType> reachableStates =
221 storm::utility::dd::computeReachableStates(initialStates, transitionRelation, abstractionInformation.getSourceVariables(),
222 abstractionInformation.getSuccessorVariables())
223 .first;
224
225 relevantStatesWatch.start();
226 if (this->isRestrictToRelevantStatesSet() && this->hasTargetStateExpression()) {
227 // Get the target state BDD.
228 storm::dd::Bdd<DdType> targetStates = reachableStates && this->getStates(this->getTargetStateExpression());
229
230 // In the presence of target states, we keep only states that can reach the target states.
232 targetStates, reachableStates, transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
233
234 // Include all successors of reachable states, because the backward search otherwise potentially
235 // cuts probability 0 choices of these states.
236 reachableStates |=
237 (reachableStates && !targetStates)
238 .relationalProduct(transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
239
240 // Restrict transition relation to relevant fragment for computation of deadlock states.
241 transitionRelation &= reachableStates && reachableStates.swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs());
242
243 relevantStatesWatch.stop();
244 STORM_LOG_TRACE("Restricting to relevant states took " << relevantStatesWatch.getTimeInMilliseconds() << "ms.");
245 }
246
247 // Find the deadlock states in the model. Note that this does not find the 'deadlocks' in bottom states,
248 // as the bottom states are not contained in the reachable states.
249 storm::dd::Bdd<DdType> deadlockStates = transitionRelation.existsAbstract(abstractionInformation.getSuccessorVariables());
250 deadlockStates = reachableStates && !deadlockStates;
251
252 // If there are deadlock states, we fix them now.
253 storm::dd::Add<DdType, ValueType> deadlockTransitions = abstractionInformation.getDdManager().template getAddZero<ValueType>();
254 if (!deadlockStates.isZero()) {
255 deadlockTransitions = (deadlockStates && abstractionInformation.getAllPredicateIdentities() && abstractionInformation.getAllLocationIdentities() &&
256 abstractionInformation.encodePlayer1Choice(0, abstractionInformation.getPlayer1VariableCount()) &&
257 abstractionInformation.encodePlayer2Choice(0, 0, game.numberOfPlayer2Variables) &&
258 abstractionInformation.encodeAux(0, 0, abstractionInformation.getAuxVariableCount()))
259 .template toAdd<ValueType>();
260 }
261
262 // Compute bottom states and the appropriate transitions if necessary.
263 BottomStateResult<DdType> bottomStateResult(abstractionInformation.getDdManager().getBddZero(), abstractionInformation.getDdManager().getBddZero());
264 bottomStateResult = automata.front().getBottomStateTransitions(reachableStates, game.numberOfPlayer2Variables);
265 bool hasBottomStates = !bottomStateResult.states.isZero();
266
267 // Construct the transition matrix by cutting away the transitions of unreachable states.
268 // Note that we also restrict the successor states of transitions, because there might be successors
269 // that are not in the set of relevant states we restrict to.
270 storm::dd::Add<DdType, ValueType> transitionMatrix =
271 (extendedTransitionRelation && reachableStates && reachableStates.swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs()))
272 .template toAdd<ValueType>();
273 transitionMatrix *= edgeDecoratorAdd;
274 transitionMatrix += deadlockTransitions;
275
276 // Extend the current game information with the 'non-bottom' tag before potentially adding bottom state transitions.
277 transitionMatrix *=
278 (abstractionInformation.getBottomStateBdd(true, true) && abstractionInformation.getBottomStateBdd(false, true)).template toAdd<ValueType>();
279 reachableStates &= abstractionInformation.getBottomStateBdd(true, true);
280 initialStates &= abstractionInformation.getBottomStateBdd(true, true);
281
282 // If there are bottom transitions, exnted the transition matrix and reachable states now.
283 if (hasBottomStates) {
284 transitionMatrix += bottomStateResult.transitions.template toAdd<ValueType>();
285 reachableStates |= bottomStateResult.states;
286 }
287
288 std::set<storm::expressions::Variable> allNondeterminismVariables = player2Variables;
289 allNondeterminismVariables.insert(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end());
290
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));
295
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());
301}
302
303template<storm::dd::DdType DdType, typename ValueType>
304void JaniMenuGameAbstractor<DdType, ValueType>::exportToDot(std::string const& filename, storm::dd::Bdd<DdType> const& highlightStates,
305 storm::dd::Bdd<DdType> const& filter) const {
306 this->exportToDot(*currentGame, filename, highlightStates, filter);
307}
308
309template<storm::dd::DdType DdType, typename ValueType>
311 return abstractionInformation.getNumberOfPredicates();
312}
313
314template<storm::dd::DdType DdType, typename ValueType>
316 terminalStateExpressions.emplace_back(expression);
317}
318
319template<storm::dd::DdType DdType, typename ValueType>
321 for (auto& automaton : automata) {
322 automaton.notifyGuardsArePredicates();
323 }
324}
325
326// Explicitly instantiate the class.
330} // namespace jani
331} // namespace abstraction
332} // 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)
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.
JaniMenuGameAbstractor(storm::jani::Model const &model, std::shared_ptr< storm::utility::solver::SmtSolverFactory > const &smtSolverFactory, MenuGameAbstractorOptions const &options=MenuGameAbstractorOptions())
Constructs an abstractor for the given model.
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.
storm::expressions::Expression getInitialStatesExpression() const
Retrieves the expression defining the legal initial values of the variables.
Definition Model.cpp:1312
This class represents the settings for the abstraction procedures.
A class that provides convenience operations to display run times.
Definition Stopwatch.h:14
#define STORM_LOG_DEBUG(message)
Definition logging.h:18
#define STORM_LOG_TRACE(message)
Definition logging.h:12
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
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