#include "storm/abstraction/prism/ModuleAbstractor.h" #include "storm/abstraction/BottomStateResult.h" #include "storm/abstraction/AbstractionInformation.h" #include "storm/abstraction/GameBddResult.h" #include "storm/storage/dd/DdManager.h" #include "storm/storage/dd/Add.h" #include "storm/storage/prism/Module.h" #include "storm/settings/SettingsManager.h" #include "storm-config.h" #include "storm/adapters/RationalFunctionAdapter.h" #include "storm/utility/macros.h" namespace storm { namespace abstraction { namespace prism { using storm::settings::modules::AbstractionSettings; template ModuleAbstractor::ModuleAbstractor(storm::prism::Module const& module, AbstractionInformation& abstractionInformation, std::shared_ptr const& smtSolverFactory, bool useDecomposition, bool addPredicatesForValidBlocks, bool debug) : smtSolverFactory(smtSolverFactory), abstractionInformation(abstractionInformation), commands(), module(module) { // For each concrete command, we create an abstract counterpart. for (auto const& command : module.getCommands()) { commands.emplace_back(command, abstractionInformation, smtSolverFactory, useDecomposition, addPredicatesForValidBlocks, debug); } } template void ModuleAbstractor::refine(std::vector const& predicates) { for (uint_fast64_t index = 0; index < commands.size(); ++index) { STORM_LOG_TRACE("Refining command with index " << index << "."); commands[index].refine(predicates); } } template storm::expressions::Expression const& ModuleAbstractor::getGuard(uint64_t player1Choice) const { return commands[player1Choice].getGuard(); } template uint64_t ModuleAbstractor::getNumberOfUpdates(uint64_t player1Choice) const { return commands[player1Choice].getNumberOfUpdates(player1Choice); } template std::map ModuleAbstractor::getVariableUpdates(uint64_t player1Choice, uint64_t auxiliaryChoice) const { return commands[player1Choice].getVariableUpdates(auxiliaryChoice); } template std::set const& ModuleAbstractor::getAssignedVariables(uint64_t player1Choice) const { return commands[player1Choice].getAssignedVariables(); } template GameBddResult ModuleAbstractor::abstract() { // First, we retrieve the abstractions of all commands. std::vector> commandDdsAndUsedOptionVariableCounts; uint_fast64_t maximalNumberOfUsedOptionVariables = 0; for (auto& command : commands) { commandDdsAndUsedOptionVariableCounts.push_back(command.abstract()); maximalNumberOfUsedOptionVariables = std::max(maximalNumberOfUsedOptionVariables, commandDdsAndUsedOptionVariableCounts.back().numberOfPlayer2Variables); } // Then, we build the module BDD by adding the single command DDs. We need to make sure that all command // DDs use the same amount DD variable encoding the choices of player 2. storm::dd::Bdd result = this->getAbstractionInformation().getDdManager().getBddZero(); for (auto const& commandDd : commandDdsAndUsedOptionVariableCounts) { result |= commandDd.bdd && this->getAbstractionInformation().encodePlayer2Choice(1, commandDd.numberOfPlayer2Variables, maximalNumberOfUsedOptionVariables); } return GameBddResult(result, maximalNumberOfUsedOptionVariables); } template BottomStateResult ModuleAbstractor::getBottomStateTransitions(storm::dd::Bdd const& reachableStates, uint_fast64_t numberOfPlayer2Variables) { BottomStateResult result(this->getAbstractionInformation().getDdManager().getBddZero(), this->getAbstractionInformation().getDdManager().getBddZero()); for (auto& command : commands) { BottomStateResult commandBottomStateResult = command.getBottomStateTransitions(reachableStates, numberOfPlayer2Variables); result.states |= commandBottomStateResult.states; result.transitions |= commandBottomStateResult.transitions; } return result; } template storm::dd::Add ModuleAbstractor::getCommandUpdateProbabilitiesAdd() const { storm::dd::Add result = this->getAbstractionInformation().getDdManager().template getAddZero(); for (auto const& command : commands) { result += command.getCommandUpdateProbabilitiesAdd(); } return result; } template std::vector> const& ModuleAbstractor::getCommands() const { return commands; } template std::vector>& ModuleAbstractor::getCommands() { return commands; } template AbstractionInformation const& ModuleAbstractor::getAbstractionInformation() const { return abstractionInformation.get(); } template void ModuleAbstractor::notifyGuardsArePredicates() { for (auto& command : commands) { command.notifyGuardIsPredicate(); } } template class ModuleAbstractor; template class ModuleAbstractor; #ifdef STORM_HAVE_CARL template class ModuleAbstractor; #endif } } }