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.

74 lines
4.6 KiB

  1. #include "scheduler.h"
  2. #include "src/helpers.h"
  3. #include "storm/storage/Scheduler.h"
  4. #include "storm/storage/PostScheduler.h"
  5. #include "storm/storage/PreScheduler.h"
  6. template<typename ValueType>
  7. void define_scheduler(py::module& m, std::string vt_suffix) {
  8. using Scheduler = storm::storage::Scheduler<ValueType>;
  9. using SchedulerChoice = storm::storage::SchedulerChoice<ValueType>;
  10. using PreScheduler = storm::storage::PreScheduler<ValueType>;
  11. using PreSchedulerChoice = storm::storage::PreSchedulerChoice<ValueType>;
  12. using PostScheduler = storm::storage::PostScheduler<ValueType>;
  13. using PostSchedulerChoice = storm::storage::PostSchedulerChoice<ValueType>;
  14. std::string schedulerClassName = std::string("Scheduler") + vt_suffix;
  15. py::class_<Scheduler, std::shared_ptr<storm::storage::Scheduler<ValueType>>> scheduler(m, schedulerClassName.c_str(), "A Finite Memory Scheduler");
  16. scheduler
  17. .def("__str__", [](Scheduler const& s) {
  18. std::stringstream str;
  19. s.printToStream(str);
  20. return str.str();
  21. })
  22. .def_property_readonly("memoryless", &Scheduler::isMemorylessScheduler, "Is the scheduler memoryless?")
  23. .def_property_readonly("memory_size", &Scheduler::getNumberOfMemoryStates, "How much memory does the scheduler take?")
  24. .def_property_readonly("deterministic", &Scheduler::isDeterministicScheduler, "Is the scheduler deterministic?")
  25. .def_property_readonly("partial", &Scheduler::isPartialScheduler, "Is the scheduler partial?")
  26. .def("get_choice", &Scheduler::getChoice, py::arg("state_index"), py::arg("memory_index") = 0)
  27. .def("compute_action_support", &Scheduler::computeActionSupport, "nondeterministic_choice_indices"_a)
  28. ;
  29. std::string schedulerChoiceClassName = std::string("SchedulerChoice") + vt_suffix;
  30. py::class_<SchedulerChoice> schedulerChoice(m, schedulerChoiceClassName.c_str(), "A choice of a finite memory scheduler");
  31. schedulerChoice
  32. .def_property_readonly("defined", &SchedulerChoice::isDefined, "Is the choice defined by the scheduler?")
  33. .def_property_readonly("deterministic", &SchedulerChoice::isDeterministic, "Is the choice deterministic (given by a Dirac distribution)?")
  34. .def("get_deterministic_choice", &SchedulerChoice::getDeterministicChoice, "Get the deterministic choice")
  35. .def("get_choice", &SchedulerChoice::getChoiceAsDistribution, "Get the distribution over the actions")
  36. .def("__str__", &streamToString<SchedulerChoice>);
  37. std::string preSchedulerClassName = std::string("PreScheduler") + vt_suffix;
  38. py::class_<PreScheduler> preScheduler(m, preSchedulerClassName.c_str(), "A pre scheduler");
  39. preScheduler
  40. .def_property_readonly("memoryless", &PreScheduler::isMemorylessScheduler, "is the pre scheduler memoryless?")
  41. .def_property_readonly("memory_size", &PreScheduler::getNumberOfMemoryStates, "How much memory does the scheduler take?")
  42. .def("get_choice", &PreScheduler::getChoice, py::arg("state_index"), py::arg("memory_index") = 0)
  43. ;
  44. std::string preSchedulerChoiceClassName = std::string("PreSchedulerChoice") + vt_suffix;
  45. py::class_<PreSchedulerChoice> preSchedulerChoice(m, preSchedulerChoiceClassName.c_str(), "A choice of a finite memory pre scheduler");
  46. preSchedulerChoice
  47. .def_property_readonly("choice_map", &PreSchedulerChoice::getChoiceMap, "Get the choice map")
  48. ;
  49. std::string postSchedulerClassName = std::string("PostScheduler") + vt_suffix;
  50. py::class_<PostScheduler> postScheduler(m, postSchedulerClassName.c_str(), "A post scheduler");
  51. postScheduler
  52. .def_property_readonly("memoryless", &PostScheduler::isMemorylessScheduler, "is the pre scheduler memoryless?")
  53. .def_property_readonly("deterministic", &PostScheduler::isDeterministicScheduler, "Is the scheduler deterministic?")
  54. .def("get_choice", &PostScheduler::getChoice, py::arg("state_index"), py::arg("memory_index") = 0)
  55. ;
  56. std::string postSchedulerChoiceClassName = std::string("PostSchedulerChoice") + vt_suffix;
  57. py::class_<PostSchedulerChoice> postSchedulerChoice(m, postSchedulerChoiceClassName.c_str(), "A choice of a finite memory post scheduler");
  58. postSchedulerChoice
  59. .def_property_readonly("choice_map", &PostSchedulerChoice::getChoiceMap, "Get the choice map")
  60. ;
  61. }
  62. template void define_scheduler<double>(py::module& m, std::string vt_suffix);
  63. template void define_scheduler<storm::RationalNumber>(py::module& m, std::string vt_suffix);