diff --git a/src/storm/models/sparse/Mdp.cpp b/src/storm/models/sparse/Mdp.cpp index ef802d5ac..da12e439c 100644 --- a/src/storm/models/sparse/Mdp.cpp +++ b/src/storm/models/sparse/Mdp.cpp @@ -39,27 +39,7 @@ namespace storm { // Intentionally left empty } - template - Mdp Mdp::restrictChoices(storm::storage::BitVector const& enabledChoices) const { - storm::storage::sparse::ModelComponents newComponents(this->getTransitionMatrix().restrictRows(enabledChoices)); - newComponents.stateLabeling = this->getStateLabeling(); - for (auto const& rewardModel : this->getRewardModels()) { - newComponents.rewardModels.emplace(rewardModel.first, rewardModel.second.restrictActions(enabledChoices)); - } - if (this->hasChoiceLabeling()) { - newComponents.choiceLabeling = this->getChoiceLabeling().getSubLabeling(enabledChoices); - } - newComponents.stateValuations = this->getOptionalStateValuations(); - if (this->hasChoiceOrigins()) { - newComponents.choiceOrigins = this->getChoiceOrigins()->selectChoices(enabledChoices); - } - return Mdp(std::move(newComponents)); - } - template - uint_least64_t Mdp::getChoiceIndex(storm::storage::StateActionPair const& stateactPair) const { - return this->getNondeterministicChoiceIndices()[stateactPair.getState()]+stateactPair.getAction(); - } template class Mdp; template class Mdp; diff --git a/src/storm/models/sparse/Mdp.h b/src/storm/models/sparse/Mdp.h index 60d1a6b63..99c1142fd 100644 --- a/src/storm/models/sparse/Mdp.h +++ b/src/storm/models/sparse/Mdp.h @@ -1,9 +1,7 @@ #ifndef STORM_MODELS_SPARSE_MDP_H_ #define STORM_MODELS_SPARSE_MDP_H_ -#include "storm/storage/StateActionPair.h" #include "storm/models/sparse/NondeterministicModel.h" -#include "storm/utility/OsDetection.h" namespace storm { namespace models { @@ -50,19 +48,6 @@ namespace storm { Mdp(Mdp&& other) = default; Mdp& operator=(Mdp&& other) = default; - - /*! - * Constructs an MDP by copying the current MDP and restricting the choices of each state to the ones given by the bitvector. - * - * @param enabledActions A BitVector of lenght numberOfChoices(), which is one iff the action should be kept. - * @return A subMDP. - */ - Mdp restrictChoices(storm::storage::BitVector const& enabledActions) const; - - /*! - * For a state/action pair, get the choice index referring to the state-action pair. - */ - uint_fast64_t getChoiceIndex(storm::storage::StateActionPair const& stateactPair) const; }; } // namespace sparse diff --git a/src/storm/models/sparse/NondeterministicModel.cpp b/src/storm/models/sparse/NondeterministicModel.cpp index 3382bfd95..acdbd3885 100644 --- a/src/storm/models/sparse/NondeterministicModel.cpp +++ b/src/storm/models/sparse/NondeterministicModel.cpp @@ -185,7 +185,12 @@ namespace storm { outStream << "}" << std::endl; } } - + + template + uint_least64_t NondeterministicModel::getChoiceIndex(storm::storage::StateActionPair const& stateactPair) const { + return this->getNondeterministicChoiceIndices()[stateactPair.getState()]+stateactPair.getAction(); + } + template class NondeterministicModel; #ifdef STORM_HAVE_CARL diff --git a/src/storm/models/sparse/NondeterministicModel.h b/src/storm/models/sparse/NondeterministicModel.h index ab0a21a04..dd1335718 100644 --- a/src/storm/models/sparse/NondeterministicModel.h +++ b/src/storm/models/sparse/NondeterministicModel.h @@ -2,7 +2,7 @@ #define STORM_MODELS_SPARSE_NONDETERMINISTICMODEL_H_ #include "storm/models/sparse/Model.h" -#include "storm/utility/OsDetection.h" +#include "storm/storage/StateActionPair.h" namespace storm { @@ -54,7 +54,11 @@ namespace storm { uint_fast64_t getNumberOfChoices(uint_fast64_t state) const; virtual void reduceToStateBasedRewards() override; - + + /*! + * For a state/action pair, get the choice index referring to the state-action pair. + */ + uint_fast64_t getChoiceIndex(storm::storage::StateActionPair const& stateactPair) const; /*! * Applies the given scheduler to this model. * @param scheduler the considered scheduler. diff --git a/src/storm/permissivesched/PermissiveSchedulers.h b/src/storm/permissivesched/PermissiveSchedulers.h index eb09d4b24..cc29f7113 100644 --- a/src/storm/permissivesched/PermissiveSchedulers.h +++ b/src/storm/permissivesched/PermissiveSchedulers.h @@ -2,6 +2,7 @@ #ifndef PERMISSIVESCHEDULERS_H #define PERMISSIVESCHEDULERS_H +#include #include "../logic/ProbabilityOperatorFormula.h" #include "../models/sparse/Mdp.h" #include "../models/sparse/StandardRewardModel.h" @@ -38,7 +39,8 @@ namespace storm { storm::models::sparse::Mdp apply() const { - return mdp.restrictChoices(enabledChoices); + storm::transformer::ChoiceSelector cs(mdp); + return *(cs.transform(enabledChoices)->template as>()); } template diff --git a/src/storm/transformer/ChoiceSelector.cpp b/src/storm/transformer/ChoiceSelector.cpp new file mode 100644 index 000000000..1044cb42c --- /dev/null +++ b/src/storm/transformer/ChoiceSelector.cpp @@ -0,0 +1,26 @@ +#include "storm/transformer/ChoiceSelector.h" +#include "storm/models/sparse/Mdp.h" + +namespace storm { + namespace transformer { + template + std::shared_ptr> ChoiceSelector::transform(storm::storage::BitVector const& enabledActions) const + { + storm::storage::sparse::ModelComponents newComponents(inputModel.getTransitionMatrix().restrictRows(enabledActions)); + newComponents.stateLabeling = inputModel.getStateLabeling(); + for (auto const& rewardModel : inputModel.getRewardModels()) { + newComponents.rewardModels.emplace(rewardModel.first, rewardModel.second.restrictActions(enabledActions)); + } + if (inputModel.hasChoiceLabeling()) { + newComponents.choiceLabeling = inputModel.getChoiceLabeling().getSubLabeling(enabledActions); + } + newComponents.stateValuations = inputModel.getOptionalStateValuations(); + if (inputModel.hasChoiceOrigins()) { + newComponents.choiceOrigins = inputModel.getChoiceOrigins()->selectChoices(enabledActions); + } + return std::make_shared>(std::move(newComponents)); + } + + template class ChoiceSelector; + } +} diff --git a/src/storm/transformer/ChoiceSelector.h b/src/storm/transformer/ChoiceSelector.h new file mode 100644 index 000000000..70ed20974 --- /dev/null +++ b/src/storm/transformer/ChoiceSelector.h @@ -0,0 +1,30 @@ +#pragma once + +#include "storm/models/sparse/StandardRewardModel.h" +#include "storm/models/sparse/NondeterministicModel.h" + + +namespace storm { + namespace transformer { + + template> + class ChoiceSelector { + public: + ChoiceSelector(storm::models::sparse::NondeterministicModel const& inputModel) : inputModel(inputModel) { + + } + + /*! + * Constructs an MDP by copying the current MDP and restricting the choices of each state to the ones given by the bitvector. + * + * @param enabledActions A BitVector of lenght numberOfChoices(), which is one iff the action should be kept. + * @return A subMDP. + */ + std::shared_ptr> transform(storm::storage::BitVector const& enabledActions) const; + private: + + storm::models::sparse::NondeterministicModel const& inputModel; + }; + + } +} \ No newline at end of file