You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.5 KiB

  1. #ifndef PERMISSIVESCHEDULERS_H
  2. #define PERMISSIVESCHEDULERS_H
  3. #include <storm/transformer/ChoiceSelector.h>
  4. #include "../logic/ProbabilityOperatorFormula.h"
  5. #include "../models/sparse/Mdp.h"
  6. #include "../models/sparse/StandardRewardModel.h"
  7. namespace storm {
  8. namespace ps {
  9. class PermissiveScheduler {
  10. public:
  11. virtual ~PermissiveScheduler() = default;
  12. };
  13. template<typename RM= storm::models::sparse::StandardRewardModel<double>>
  14. class SubMDPPermissiveScheduler : public PermissiveScheduler {
  15. storm::models::sparse::Mdp<double, RM> const &mdp;
  16. storm::storage::BitVector enabledChoices;
  17. public:
  18. virtual ~SubMDPPermissiveScheduler() = default;
  19. SubMDPPermissiveScheduler(SubMDPPermissiveScheduler &&) = default;
  20. SubMDPPermissiveScheduler(SubMDPPermissiveScheduler const &) = delete;
  21. SubMDPPermissiveScheduler(storm::models::sparse::Mdp<double, RM> const &refmdp, bool allEnabled) :
  22. PermissiveScheduler(), mdp(refmdp), enabledChoices(refmdp.getNumberOfChoices(), allEnabled) {
  23. // Intentionally left empty.
  24. }
  25. void disable(uint_fast64_t choiceIndex) {
  26. STORM_LOG_ASSERT(choiceIndex < enabledChoices.size(), "Invalid choiceIndex.");
  27. enabledChoices.set(choiceIndex, false);
  28. }
  29. storm::models::sparse::Mdp<double, RM> apply() const {
  30. storm::transformer::ChoiceSelector<double, RM> cs(mdp);
  31. return *(cs.transform(enabledChoices)->template as<storm::models::sparse::Mdp<double, RM>>());
  32. }
  33. template<typename T>
  34. std::map<uint_fast64_t, T> remapChoiceIndices(std::map<uint_fast64_t, T> const& in) const {
  35. std::map<uint_fast64_t, T> res;
  36. uint_fast64_t last = 0;
  37. uint_fast64_t curr = 0;
  38. storm::storage::BitVector::const_iterator it = enabledChoices.begin();
  39. for(auto const& entry : in) {
  40. curr = entry.first;
  41. uint_fast64_t diff = last - curr;
  42. it += diff;
  43. res[*it] = entry.second;
  44. last = curr;
  45. }
  46. return res;
  47. }
  48. template<typename T>
  49. std::map<uint_fast64_t, T> remapChoiceIndices(std::map<storm::storage::StateActionPair, T> const& in) const {
  50. std::map<uint_fast64_t, T> res;
  51. uint_fast64_t last = 0;
  52. uint_fast64_t curr = 0;
  53. storm::storage::BitVector::const_iterator it = enabledChoices.begin();
  54. for(auto const& entry : in) {
  55. curr = mdp.getChoiceIndex(entry.first);
  56. uint_fast64_t diff = curr-last;
  57. it += diff;
  58. res[*it] = entry.second;
  59. last = curr;
  60. }
  61. return res;
  62. }
  63. };
  64. template<typename RM = storm::models::sparse::StandardRewardModel<double>>
  65. boost::optional<SubMDPPermissiveScheduler<RM>> computePermissiveSchedulerViaMILP(storm::models::sparse::Mdp<double, RM> const& mdp, storm::logic::ProbabilityOperatorFormula const &safeProp);
  66. template<typename RM>
  67. boost::optional<SubMDPPermissiveScheduler<RM>> computePermissiveSchedulerViaSMT(storm::models::sparse::Mdp<double, RM> const& mdp, storm::logic::ProbabilityOperatorFormula const& safeProp);
  68. }
  69. }
  70. #endif /* PERMISSIVESCHEDULERS_H */