21namespace abstraction {
26template<storm::dd::DdType DdType,
typename ValueType>
28 std::shared_ptr<storm::utility::solver::SmtSolverFactory>
const& smtSolverFactory,
31 smtSolverFactory(smtSolverFactory),
32 abstractionInformation(program.getManager(), program.getAllExpressionVariables(), smtSolverFactory->create(program.getManager()),
36 validBlockAbstractor(abstractionInformation, smtSolverFactory),
38 refinementPerformed(
false) {
41 STORM_LOG_THROW(program.getNumberOfModules() == 1, storm::exceptions::WrongFormatException,
42 "Cannot create abstract program from program containing too many modules.");
45 for (
auto const& range : this->program.get().getAllRangeExpressions()) {
46 abstractionInformation.addConstraint(range);
47 initialStateAbstractor.constrain(range);
48 validBlockAbstractor.constrain(range);
51 uint_fast64_t totalNumberOfCommands = 0;
52 uint_fast64_t maximalUpdateCount = 0;
53 std::vector<storm::expressions::Expression> allGuards;
54 for (
auto const& module : program.getModules()) {
55 for (
auto const& command : module.getCommands()) {
56 maximalUpdateCount = std::max(maximalUpdateCount,
static_cast<uint_fast64_t
>(command.getNumberOfUpdates()));
59 totalNumberOfCommands +=
module.getNumberOfCommands();
65 abstractionInformation.createEncodingVariables(
static_cast<uint_fast64_t
>(std::ceil(std::log2(totalNumberOfCommands))), 64,
66 static_cast<uint_fast64_t
>(std::ceil(std::log2(maximalUpdateCount))));
69 auto const& settings = storm::settings::getModule<storm::settings::modules::AbstractionSettings>();
70 bool useDecomposition = settings.isUseDecompositionSet();
72 bool addPredicatesForValidBlocks = !restrictToValidBlocks;
73 bool debug = settings.isDebugSet();
74 for (
auto const& module : program.getModules()) {
75 this->modules.emplace_back(module, abstractionInformation, this->smtSolverFactory, useDecomposition, addPredicatesForValidBlocks, debug);
79 commandUpdateProbabilitiesAdd = modules.front().getCommandUpdateProbabilitiesAdd();
82template<storm::dd::DdType DdType,
typename ValueType>
84 return abstractionInformation.getDdManager();
87template<storm::dd::DdType DdType,
typename ValueType>
90 std::vector<uint_fast64_t> predicateIndices;
92 STORM_LOG_THROW(predicate.hasBooleanType(), storm::exceptions::InvalidArgumentException,
"Expecting a predicate of type bool.");
93 predicateIndices.push_back(abstractionInformation.getOrAddPredicate(predicate));
97 for (
auto& module : modules) {
98 module.refine(predicateIndices);
102 initialStateAbstractor.refine(predicateIndices);
104 if (restrictToValidBlocks) {
106 validBlockAbstractor.refine(predicateIndices);
112template<storm::dd::DdType DdType,
typename ValueType>
114 if (refinementPerformed) {
115 currentGame = buildGame();
116 refinementPerformed =
false;
121template<storm::dd::DdType DdType,
typename ValueType>
123 return abstractionInformation;
126template<storm::dd::DdType DdType,
typename ValueType>
128 return modules.front().getGuard(player1Choice);
131template<storm::dd::DdType DdType,
typename ValueType>
133 return modules.front().getNumberOfUpdates(player1Choice);
136template<storm::dd::DdType DdType,
typename ValueType>
138 uint64_t player1Choice, uint64_t auxiliaryChoice)
const {
139 return modules.front().getVariableUpdates(player1Choice, auxiliaryChoice);
142template<storm::dd::DdType DdType,
typename ValueType>
144 return modules.front().getAssignedVariables(player1Choice);
147template<storm::dd::DdType DdType,
typename ValueType>
149 return std::make_pair(0, modules.front().getCommands().size());
152template<storm::dd::DdType DdType,
typename ValueType>
154 return program.get().getInitialStatesExpression();
157template<storm::dd::DdType DdType,
typename ValueType>
160 smtSolverFactory->create(abstractionInformation.getExpressionManager()));
164template<storm::dd::DdType DdType,
typename ValueType>
170 std::set<storm::expressions::Variable> variablesToAbstract(abstractionInformation.getPlayer1VariableSet(abstractionInformation.getPlayer1VariableCount()));
171 std::set<storm::expressions::Variable> successorAndAuxVariables(abstractionInformation.getSuccessorVariables());
173 variablesToAbstract.insert(player2Variables.begin(), player2Variables.end());
174 auto auxVariables = abstractionInformation.getAuxVariableSet(0, abstractionInformation.getAuxVariableCount());
175 variablesToAbstract.insert(auxVariables.begin(), auxVariables.end());
176 successorAndAuxVariables.insert(auxVariables.begin(), auxVariables.end());
180 if (this->isRestrictToRelevantStatesSet()) {
182 for (
auto const& expression : this->terminalStateExpressions) {
183 nonTerminalStates &= !this->getStates(expression);
185 if (this->hasTargetStateExpression()) {
186 nonTerminalStates &= !this->getStates(this->getTargetStateExpression());
189 relevantStatesWatch.stop();
193 if (restrictToValidBlocks) {
198 auto choicesWithOnlyValidSuccessors =
199 !game.
bdd.
andExists(!validBlocks.
swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()), successorAndAuxVariables) &&
203 extendedTransitionRelation &= validBlocks && choicesWithOnlyValidSuccessors;
204 initialStates &= validBlocks;
209 initialStates.
addMetaVariables(abstractionInformation.getSourcePredicateVariables());
212 abstractionInformation.getSuccessorVariables())
215 relevantStatesWatch.start();
216 if (this->isRestrictToRelevantStatesSet() && this->hasTargetStateExpression()) {
218 storm::dd::Bdd<DdType> targetStates = reachableStates && this->getStates(this->getTargetStateExpression());
222 targetStates, reachableStates, transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
227 (reachableStates && !targetStates)
228 .relationalProduct(transitionRelation, abstractionInformation.getSourceVariables(), abstractionInformation.getSuccessorVariables());
231 transitionRelation &= reachableStates && reachableStates.
swapVariables(abstractionInformation.getExtendedSourceSuccessorVariablePairs());
233 relevantStatesWatch.stop();
234 STORM_LOG_TRACE(
"Restricting to relevant states took " << relevantStatesWatch.getTimeInMilliseconds() <<
"ms.");
240 deadlockStates = reachableStates && !deadlockStates;
244 if (!deadlockStates.
isZero()) {
245 deadlockTransitions = (deadlockStates && abstractionInformation.getAllPredicateIdentities() &&
246 abstractionInformation.encodePlayer1Choice(0, abstractionInformation.getPlayer1VariableCount()) &&
248 abstractionInformation.encodeAux(0, 0, abstractionInformation.getAuxVariableCount()))
249 .
template toAdd<ValueType>();
253 BottomStateResult<DdType> bottomStateResult(abstractionInformation.getDdManager().getBddZero(), abstractionInformation.getDdManager().getBddZero());
255 bool hasBottomStates = !bottomStateResult.states.isZero();
261 (extendedTransitionRelation && reachableStates && reachableStates.
swapVariables(abstractionInformation.getSourceSuccessorVariablePairs()))
262 .
template toAdd<ValueType>();
263 transitionMatrix *= commandUpdateProbabilitiesAdd;
264 transitionMatrix += deadlockTransitions;
268 (abstractionInformation.getBottomStateBdd(
true,
true) && abstractionInformation.getBottomStateBdd(
false,
true)).
template toAdd<ValueType>();
269 reachableStates &= abstractionInformation.getBottomStateBdd(
true,
true);
270 initialStates &= abstractionInformation.getBottomStateBdd(
true,
true);
273 if (hasBottomStates) {
274 transitionMatrix += bottomStateResult.transitions.template toAdd<ValueType>();
275 reachableStates |= bottomStateResult.states;
278 std::set<storm::expressions::Variable> allNondeterminismVariables = player2Variables;
279 allNondeterminismVariables.insert(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end());
281 std::set<storm::expressions::Variable> allSourceVariables(abstractionInformation.getSourceVariables());
282 allSourceVariables.insert(abstractionInformation.getBottomStateVariable(
true));
283 std::set<storm::expressions::Variable> allSuccessorVariables(abstractionInformation.getSuccessorVariables());
284 allSuccessorVariables.insert(abstractionInformation.getBottomStateVariable(
false));
286 return std::make_unique<MenuGame<DdType, ValueType>>(
287 abstractionInformation.getDdManagerAsSharedPointer(), reachableStates, initialStates, abstractionInformation.
getDdManager().getBddZero(),
288 transitionMatrix, bottomStateResult.states, allSourceVariables, allSuccessorVariables, abstractionInformation.getExtendedSourceSuccessorVariablePairs(),
289 std::set<storm::expressions::Variable>(abstractionInformation.getPlayer1Variables().begin(), abstractionInformation.getPlayer1Variables().end()),
290 player2Variables, allNondeterminismVariables, auxVariables, abstractionInformation.getPredicateToBddMap());
293template<storm::dd::DdType DdType,
typename ValueType>
296 this->exportToDot(*currentGame, filename, highlightStates, filter);
299template<storm::dd::DdType DdType,
typename ValueType>
301 return abstractionInformation.getNumberOfPredicates();
304template<storm::dd::DdType DdType,
typename ValueType>
306 terminalStateExpressions.emplace_back(expression);
309template<storm::dd::DdType DdType,
typename ValueType>
311 for (
auto& module : modules) {
312 module.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 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)
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