diff --git a/src/storage/model.cpp b/src/storage/model.cpp index 19f1fc5..b3f824d 100644 --- a/src/storage/model.cpp +++ b/src/storage/model.cpp @@ -29,6 +29,7 @@ using RationalFunction = storm::RationalFunction; using ModelBase = storm::models::ModelBase; +template using ModelComponents = storm::storage::sparse::ModelComponents; template using SparseModel = storm::models::sparse::Model; template using SparseDtmc = storm::models::sparse::Dtmc; template using SparseMdp = storm::models::sparse::Mdp; @@ -197,10 +198,12 @@ void define_sparse_model(py::module& m) { ; py::class_, std::shared_ptr>>(m, "SparseDtmc", "DTMC in sparse representation", model) .def(py::init>(), py::arg("other_model")) + .def(py::init const&>(), py::arg("components")) //todo tests .def("__str__", &getModelInfoPrinter) ; py::class_, std::shared_ptr>> mdp(m, "SparseMdp", "MDP in sparse representation", model); mdp.def(py::init>(), py::arg("other_model")) + .def(py::init const&, storm::models::ModelType>(), py::arg("components"), py::arg("type")=storm::models::ModelType::Mdp) //todo tests .def_property_readonly("nondeterministic_choice_indices", [](SparseMdp const& mdp) { return mdp.getNondeterministicChoiceIndices(); }) .def("get_nr_available_actions", [](SparseMdp const& mdp, uint64_t stateIndex) { return mdp.getNondeterministicChoiceIndices()[stateIndex+1] - mdp.getNondeterministicChoiceIndices()[stateIndex] ; }, py::arg("state")) .def("get_choice_index", [](SparseMdp const& mdp, uint64_t state, uint64_t actOff) { return mdp.getNondeterministicChoiceIndices()[state]+actOff; }, py::arg("state"), py::arg("action_offset"), "gets the choice index for the offset action from the given state.") @@ -209,6 +212,7 @@ void define_sparse_model(py::module& m) { ; py::class_, std::shared_ptr>>(m, "SparsePomdp", "POMDP in sparse representation", mdp) .def(py::init>(), py::arg("other_model")) + .def(py::init const&, bool>(), py::arg("components"), py::arg("canonicFlag")=false) //todo tests .def("__str__", &getModelInfoPrinter) .def("get_observation", &SparsePomdp::getObservation, py::arg("state")) .def_property_readonly("observations", &SparsePomdp::getObservations) @@ -216,10 +220,12 @@ void define_sparse_model(py::module& m) { ; py::class_, std::shared_ptr>>(m, "SparseCtmc", "CTMC in sparse representation", model) .def(py::init>(), py::arg("other_model")) + .def(py::init const&>(), py::arg("components")) //todo tests .def("__str__", &getModelInfoPrinter) ; py::class_, std::shared_ptr>>(m, "SparseMA", "MA in sparse representation", model) .def(py::init>(), py::arg("other_model")) + .def(py::init const&>(), py::arg("components")) //todo tests .def_property_readonly("nondeterministic_choice_indices", [](SparseMarkovAutomaton const& ma) { return ma.getNondeterministicChoiceIndices(); }) .def("apply_scheduler", [](SparseMarkovAutomaton const& ma, storm::storage::Scheduler const& scheduler, bool dropUnreachableStates) { return ma.applyScheduler(scheduler, dropUnreachableStates); } , "apply scheduler", "scheduler"_a, "drop_unreachable_states"_a = true) .def("__str__", &getModelInfoPrinter) @@ -228,6 +234,7 @@ void define_sparse_model(py::module& m) { ; py::class_>(m, "SparseRewardModel", "Reward structure for sparse models") + //todo init? .def_property_readonly("has_state_rewards", &SparseRewardModel::hasStateRewards) .def_property_readonly("has_state_action_rewards", &SparseRewardModel::hasStateActionRewards) .def_property_readonly("has_transition_rewards", &SparseRewardModel::hasTransitionRewards) @@ -290,6 +297,7 @@ void define_sparse_model(py::module& m) { ; py::class_>(m, "SparseParametricRewardModel", "Reward structure for parametric sparse models") + //todo init? .def_property_readonly("has_state_rewards", &SparseRewardModel::hasStateRewards) .def_property_readonly("has_state_action_rewards", &SparseRewardModel::hasStateActionRewards) .def_property_readonly("has_transition_rewards", &SparseRewardModel::hasTransitionRewards) diff --git a/src/storage/modelcomponents.cpp b/src/storage/modelcomponents.cpp index 97536ee..83c4ec5 100644 --- a/src/storage/modelcomponents.cpp +++ b/src/storage/modelcomponents.cpp @@ -8,31 +8,37 @@ -template using SparseMatrix = storm::storage::SparseMatrix; + using stateLabeling = storm::models::sparse::StateLabeling; using BitVector = storm::storage::BitVector; +template using SparseMatrix = storm::storage::SparseMatrix; +template using SparseRewardModel = storm::models::sparse::StandardRewardModel; -template using StandardRewardModel = storm::models::sparse::StandardRewardModel; -template> using ModelComponents = storm::storage::sparse::ModelComponents; - -// other: todo -// >; -// py::class_>>(m, "ModelComponents", "ModelComponents description..") +template using ModelComponents = storm::storage::sparse::ModelComponents; +// others: todo +// ; +// +// +// > +// todo +// 1. create constructor for sparseModels double in models.h using model comp. +// 2. write tests +// 3. rationalfct void define_model_components(py::module& m) { py::class_>(m, "ModelComponents", "ModelComponents description..") - .def(py::init const &, stateLabeling const &, std::unordered_map> const &, + .def(py::init const &, stateLabeling const &, std::unordered_map> const &, bool, boost::optional const &, boost::optional> const &>(), "Construct from Prism program", py::arg("transition_matrix"), py::arg("state_labeling") = stateLabeling(), - py::arg("reward_models") = std::unordered_map>(), py::arg("rate_transitions") = false, + py::arg("reward_models") = std::unordered_map>(), py::arg("rate_transitions") = false, py::arg("markovian_states") = boost::none, py::arg("player1_matrix") = boost::none) .def(py::init<>()) // for rvalue ? todo - // general components (for all model types) + // General components (for all model types) .def_readwrite("transition_matrix", &ModelComponents::transitionMatrix) .def_readwrite("state_labeling", &ModelComponents::stateLabeling) .def_readwrite("reward_models", &ModelComponents::rewardModels, "Reward models associated with the model") diff --git a/src/storage/modelcomponents.h b/src/storage/modelcomponents.h index cce0999..fdccc99 100644 --- a/src/storage/modelcomponents.h +++ b/src/storage/modelcomponents.h @@ -3,6 +3,6 @@ #include "common.h" -void define_model_cmponents(py::module& m); +void define_model_components(py::module& m); #endif /* PYSTORM_MODELCOMPONENTS_H */