26#include "storm-config.h"
30namespace abstraction {
35template<storm::dd::DdType DdType,
typename ValueType>
37 std::shared_ptr<storm::utility::solver::SmtSolverFactory>
const& smtSolverFactory,
40 smtSolverFactory(smtSolverFactory),
41 abstractionInformation(program.getManager(), program.getAllExpressionVariables(), smtSolverFactory->create(program.getManager()),
45 validBlockAbstractor(abstractionInformation, smtSolverFactory),
47 refinementPerformed(
false) {
50 STORM_LOG_THROW(program.getNumberOfModules() == 1, storm::exceptions::WrongFormatException,
51 "Cannot create abstract program from program containing too many modules.");
54 for (
auto const& range : this->program.get().getAllRangeExpressions()) {
55 abstractionInformation.addConstraint(range);
56 initialStateAbstractor.constrain(range);
57 validBlockAbstractor.constrain(range);
60 uint_fast64_t totalNumberOfCommands = 0;
61 uint_fast64_t maximalUpdateCount = 0;
62 std::vector<storm::expressions::Expression> allGuards;
63 for (
auto const& module : program.getModules()) {
64 for (
auto const& command : module.getCommands()) {
65 maximalUpdateCount = std::max(maximalUpdateCount,
static_cast<uint_fast64_t
>(command.getNumberOfUpdates()));
68 totalNumberOfCommands +=
module.getNumberOfCommands();
74 abstractionInformation.createEncodingVariables(
static_cast<uint_fast64_t
>(std::ceil(std::log2(totalNumberOfCommands))), 64,
75 static_cast<uint_fast64_t
>(std::ceil(std::log2(maximalUpdateCount))));
79 bool useDecomposition = settings.isUseDecompositionSet();
81 bool addPredicatesForValidBlocks = !restrictToValidBlocks;
82 bool debug = settings.isDebugSet();
83 for (
auto const& module : program.getModules()) {
84 this->modules.emplace_back(module, abstractionInformation, this->smtSolverFactory, useDecomposition, addPredicatesForValidBlocks, debug);
88 commandUpdateProbabilitiesAdd = modules.front().getCommandUpdateProbabilitiesAdd();
91template<storm::dd::DdType DdType,
typename ValueType>
93 return abstractionInformation.getDdManager();
96template<storm::dd::DdType DdType,
typename ValueType>
99 std::vector<uint_fast64_t> predicateIndices;
101 STORM_LOG_THROW(predicate.hasBooleanType(), storm::exceptions::InvalidArgumentException,
"Expecting a predicate of type bool.");
102 predicateIndices.push_back(abstractionInformation.getOrAddPredicate(predicate));
106 for (
auto& module : modules) {
107 module.refine(predicateIndices);
111 initialStateAbstractor.refine(predicateIndices);
113 if (restrictToValidBlocks) {
115 validBlockAbstractor.refine(predicateIndices);
121template<storm::dd::DdType DdType,
typename ValueType>
123 if (refinementPerformed) {
124 currentGame = buildGame();
125 refinementPerformed =
false;
130template<storm::dd::DdType DdType,
typename ValueType>
132 return abstractionInformation;
135template<storm::dd::DdType DdType,
typename ValueType>
137 return modules.front().getGuard(player1Choice);
140template<storm::dd::DdType DdType,
typename ValueType>
142 return modules.front().getNumberOfUpdates(player1Choice);
145template<storm::dd::DdType DdType,
typename ValueType>
147 uint64_t player1Choice, uint64_t auxiliaryChoice)
const {
148 return modules.front().getVariableUpdates(player1Choice, auxiliaryChoice);
151template<storm::dd::DdType DdType,
typename ValueType>
153 return modules.front().getAssignedVariables(player1Choice);
156template<storm::dd::DdType DdType,
typename ValueType>
158 return std::make_pair(0, modules.front().getCommands().size());
161template<storm::dd::DdType DdType,
typename ValueType>
163 return program.get().getInitialStatesExpression();
166template<storm::dd::DdType DdType,
typename ValueType>
169 smtSolverFactory->create(abstractionInformation.getExpressionManager()));
173template<storm::dd::DdType DdType,
typename ValueType>
179 std::set<storm::expressions::Variable> variablesToAbstract(abstractionInformation.getPlayer1VariableSet(abstractionInformation.getPlayer1VariableCount()));
180 std::set<storm::expressions::Variable> successorAndAuxVariables(abstractionInformation.getSuccessorVariables());
182 variablesToAbstract.insert(player2Variables.begin(), player2Variables.end());
183 auto auxVariables = abstractionInformation.getAuxVariableSet(0, abstractionInformation.getAuxVariableCount());
184 variablesToAbstract.insert(auxVariables.begin(), auxVariables.end());
185 successorAndAuxVariables.insert(auxVariables.begin(), auxVariables.end());
189 if (this->isRestrictToRelevantStatesSet()) {
191 for (
auto const& expression : this->terminalStateExpressions) {
192 nonTerminalStates &= !this->getStates(expression);
194 if (this->hasTargetStateExpression()) {
195 nonTerminalStates &= !this->getStates(this->getTargetStateExpression());
198 relevantStatesWatch.stop();
202 if (restrictToValidBlocks) {
207 auto choicesWithOnlyValidSuccessors =
208 !game.
bdd.
andExists(!validBlocks.
swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()), successorAndAuxVariables) &&
212 extendedTransitionRelation &= validBlocks && choicesWithOnlyValidSuccessors;
213 initialStates &= validBlocks;
218 initialStates.
addMetaVariables(abstractionInformation.getSourcePredicateVariables());
221 abstractionInformation.getSuccessorVariables())
224 relevantStatesWatch.start();
225 if (this->isRestrictToRelevantStatesSet() && this->hasTargetStateExpression()) {
227 storm::dd::Bdd<DdType> targetStates = reachableStates && this->getStates(this->getTargetStateExpression());
231 targetStates, reachableStates, transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
236 (reachableStates && !targetStates)
237 .relationalProduct(transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
240 transitionRelation &= reachableStates && reachableStates.
swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs());
242 relevantStatesWatch.stop();
243 STORM_LOG_TRACE(
"Restricting to relevant states took " << relevantStatesWatch.getTimeInMilliseconds() <<
"ms.");
249 deadlockStates = reachableStates && !deadlockStates;
253 if (!deadlockStates.
isZero()) {
254 deadlockTransitions = (deadlockStates && abstractionInformation.getAllPredicateIdentities() &&
255 abstractionInformation.encodePlayer1Choice(0, abstractionInformation.getPlayer1VariableCount()) &&
257 abstractionInformation.encodeAux(0, 0, abstractionInformation.getAuxVariableCount()))
258 .
template toAdd<ValueType>();
262 BottomStateResult<DdType> bottomStateResult(abstractionInformation.getDdManager().getBddZero(), abstractionInformation.getDdManager().getBddZero());
264 bool hasBottomStates = !bottomStateResult.states.isZero();
270 (extendedTransitionRelation && reachableStates && reachableStates.
swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()))
271 .
template toAdd<ValueType>();
272 transitionMatrix *= commandUpdateProbabilitiesAdd;
273 transitionMatrix += deadlockTransitions;
277 (abstractionInformation.getBottomStateBdd(
true,
true) && abstractionInformation.getBottomStateBdd(
false,
true)).
template toAdd<ValueType>();
278 reachableStates &= abstractionInformation.getBottomStateBdd(
true,
true);
279 initialStates &= abstractionInformation.getBottomStateBdd(
true,
true);
282 if (hasBottomStates) {
283 transitionMatrix += bottomStateResult.transitions.template toAdd<ValueType>();
284 reachableStates |= bottomStateResult.states;
287 std::set<storm::expressions::Variable> allNondeterminismVariables = player2Variables;
288 allNondeterminismVariables.insert(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end());
290 std::set<storm::expressions::Variable> allSourceVariables(abstractionInformation.getSourceVariables());
291 allSourceVariables.insert(abstractionInformation.getBottomStateVariable(
true));
292 std::set<storm::expressions::Variable> allSuccessorVariables(abstractionInformation.getSuccessorVariables());
293 allSuccessorVariables.insert(abstractionInformation.getBottomStateVariable(
false));
295 return std::make_unique<MenuGame<DdType, ValueType>>(
296 abstractionInformation.getDdManagerAsSharedPointer(), reachableStates, initialStates, abstractionInformation.
getDdManager().getBddZero(),
297 transitionMatrix, bottomStateResult.states, allSourceVariables, allSuccessorVariables, abstractionInformation.getExtendedSourceSuccessorVariablePairs(),
298 std::set<storm::expressions::Variable>(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end()),
299 player2Variables, allNondeterminismVariables, auxVariables, abstractionInformation.getPredicateToBddMap());
302template<storm::dd::DdType DdType,
typename ValueType>
305 this->exportToDot(*currentGame, filename, highlightStates, filter);
308template<storm::dd::DdType DdType,
typename ValueType>
310 return abstractionInformation.getNumberOfPredicates();
313template<storm::dd::DdType DdType,
typename ValueType>
315 terminalStateExpressions.emplace_back(expression);
318template<storm::dd::DdType DdType,
typename ValueType>
320 for (
auto& module : modules) {
321 module.notifyGuardsArePredicates();
328#ifdef STORM_HAVE_CARL
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 an expression characterizing the initial states.
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_THROW(cond, exception, message)
SettingsType const & getModule()
Get module.
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