#include "storm/models/sparse/Mdp.h" #include "storm/exceptions/InvalidArgumentException.h" #include "storm/utility/constants.h" #include "storm/utility/vector.h" #include "storm/adapters/CarlAdapter.h" #include "storm/models/sparse/StandardRewardModel.h" namespace storm { namespace models { namespace sparse { template Mdp::Mdp(storm::storage::SparseMatrix const& transitionMatrix, storm::models::sparse::StateLabeling const& stateLabeling, std::unordered_map const& rewardModels, boost::optional const& optionalChoiceLabeling) : NondeterministicModel(storm::models::ModelType::Mdp, transitionMatrix, stateLabeling, rewardModels, optionalChoiceLabeling) { STORM_LOG_THROW(transitionMatrix.isProbabilistic(), storm::exceptions::InvalidArgumentException, "The probability matrix is invalid."); } template Mdp::Mdp(storm::storage::SparseMatrix&& transitionMatrix, storm::models::sparse::StateLabeling&& stateLabeling, std::unordered_map&& rewardModels, boost::optional&& optionalChoiceLabeling) : NondeterministicModel(storm::models::ModelType::Mdp, std::move(transitionMatrix), std::move(stateLabeling), std::move(rewardModels), std::move(optionalChoiceLabeling)) { STORM_LOG_THROW(transitionMatrix.isProbabilistic(), storm::exceptions::InvalidArgumentException, "The probability matrix is invalid."); } template Mdp Mdp::restrictChoices(storm::storage::BitVector const& enabledChoices) const { storm::storage::SparseMatrix restrictedTransitions = this->getTransitionMatrix().restrictRows(enabledChoices); std::unordered_map newRewardModels; for (auto const& rewardModel : this->getRewardModels()) { newRewardModels.emplace(rewardModel.first, rewardModel.second.restrictActions(enabledChoices)); } if(this->hasChoiceLabeling()) { return Mdp(restrictedTransitions, this->getStateLabeling(), newRewardModels, this->getChoiceLabeling().getSubLabeling(enabledChoices)); } else { return Mdp(restrictedTransitions, this->getStateLabeling(), newRewardModels); } } 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; #ifdef STORM_HAVE_CARL template class Mdp; template class Mdp>; template class Mdp; #endif } // namespace sparse } // namespace models } // namespace storm