Browse Source

cleaned

refactoring
hannah 5 years ago
committed by Matthias Volk
parent
commit
c038a82e3e
No known key found for this signature in database GPG Key ID: 83A57678F739FCD3
  1. 12
      src/storage/model.cpp
  2. 12
      src/storage/model_components.cpp

12
src/storage/model.cpp

@ -198,12 +198,12 @@ void define_sparse_model(py::module& m) {
; ;
py::class_<SparseDtmc<double>, std::shared_ptr<SparseDtmc<double>>>(m, "SparseDtmc", "DTMC in sparse representation", model) py::class_<SparseDtmc<double>, std::shared_ptr<SparseDtmc<double>>>(m, "SparseDtmc", "DTMC in sparse representation", model)
.def(py::init<SparseDtmc<double>>(), py::arg("other_model")) .def(py::init<SparseDtmc<double>>(), py::arg("other_model"))
.def(py::init<ModelComponents<double> const&>(), py::arg("components")) //todo tests
.def(py::init<ModelComponents<double> const&>(), py::arg("components"))
.def("__str__", &getModelInfoPrinter) .def("__str__", &getModelInfoPrinter)
; ;
py::class_<SparseMdp<double>, std::shared_ptr<SparseMdp<double>>> mdp(m, "SparseMdp", "MDP in sparse representation", model); py::class_<SparseMdp<double>, std::shared_ptr<SparseMdp<double>>> mdp(m, "SparseMdp", "MDP in sparse representation", model);
mdp.def(py::init<SparseMdp<double>>(), py::arg("other_model")) mdp.def(py::init<SparseMdp<double>>(), py::arg("other_model"))
.def(py::init<ModelComponents<double> const&, storm::models::ModelType>(), py::arg("components"), py::arg("type")=storm::models::ModelType::Mdp) //todo tests
.def(py::init<ModelComponents<double> const&, storm::models::ModelType>(), py::arg("components"), py::arg("type")=storm::models::ModelType::Mdp)
.def_property_readonly("nondeterministic_choice_indices", [](SparseMdp<double> const& mdp) { return mdp.getNondeterministicChoiceIndices(); }) .def_property_readonly("nondeterministic_choice_indices", [](SparseMdp<double> const& mdp) { return mdp.getNondeterministicChoiceIndices(); })
.def("get_nr_available_actions", [](SparseMdp<double> const& mdp, uint64_t stateIndex) { return mdp.getNondeterministicChoiceIndices()[stateIndex+1] - mdp.getNondeterministicChoiceIndices()[stateIndex] ; }, py::arg("state")) .def("get_nr_available_actions", [](SparseMdp<double> const& mdp, uint64_t stateIndex) { return mdp.getNondeterministicChoiceIndices()[stateIndex+1] - mdp.getNondeterministicChoiceIndices()[stateIndex] ; }, py::arg("state"))
.def("get_choice_index", [](SparseMdp<double> 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.") .def("get_choice_index", [](SparseMdp<double> 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.")
@ -212,7 +212,7 @@ void define_sparse_model(py::module& m) {
; ;
py::class_<SparsePomdp<double>, std::shared_ptr<SparsePomdp<double>>>(m, "SparsePomdp", "POMDP in sparse representation", mdp) py::class_<SparsePomdp<double>, std::shared_ptr<SparsePomdp<double>>>(m, "SparsePomdp", "POMDP in sparse representation", mdp)
.def(py::init<SparsePomdp<double>>(), py::arg("other_model")) .def(py::init<SparsePomdp<double>>(), py::arg("other_model"))
.def(py::init<ModelComponents<double> const&, bool>(), py::arg("components"), py::arg("canonic_flag")=false) //todo tests
.def(py::init<ModelComponents<double> const&, bool>(), py::arg("components"), py::arg("canonic_flag")=false)
.def("__str__", &getModelInfoPrinter) .def("__str__", &getModelInfoPrinter)
.def("get_observation", &SparsePomdp<double>::getObservation, py::arg("state")) .def("get_observation", &SparsePomdp<double>::getObservation, py::arg("state"))
.def_property_readonly("observations", &SparsePomdp<double>::getObservations) .def_property_readonly("observations", &SparsePomdp<double>::getObservations)
@ -220,14 +220,14 @@ void define_sparse_model(py::module& m) {
; ;
py::class_<SparseCtmc<double>, std::shared_ptr<SparseCtmc<double>>>(m, "SparseCtmc", "CTMC in sparse representation", model) py::class_<SparseCtmc<double>, std::shared_ptr<SparseCtmc<double>>>(m, "SparseCtmc", "CTMC in sparse representation", model)
.def(py::init<SparseCtmc<double>>(), py::arg("other_model")) .def(py::init<SparseCtmc<double>>(), py::arg("other_model"))
.def(py::init<ModelComponents<double> const&>(), py::arg("components")) //todo tests
.def(py::init<ModelComponents<double> const&>(), py::arg("components"))
.def_property_readonly("exit_rates", [](SparseCtmc<double> const& ctmc) { return ctmc.getExitRateVector(); }) //todo new: tests .def_property_readonly("exit_rates", [](SparseCtmc<double> const& ctmc) { return ctmc.getExitRateVector(); }) //todo new: tests
.def("__str__", &getModelInfoPrinter) .def("__str__", &getModelInfoPrinter)
; ;
py::class_<SparseMarkovAutomaton<double>, std::shared_ptr<SparseMarkovAutomaton<double>>>(m, "SparseMA", "MA in sparse representation", model) py::class_<SparseMarkovAutomaton<double>, std::shared_ptr<SparseMarkovAutomaton<double>>>(m, "SparseMA", "MA in sparse representation", model)
.def(py::init<SparseMarkovAutomaton<double>>(), py::arg("other_model")) .def(py::init<SparseMarkovAutomaton<double>>(), py::arg("other_model"))
.def(py::init<ModelComponents<double> const&>(), py::arg("components")) // todo tests
.def_property_readonly("exit_rates", [](SparseMarkovAutomaton<double> const& ma) { return ma.getExitRates(); }) //todo new: tests
.def(py::init<ModelComponents<double> const&>(), py::arg("components"))
.def_property_readonly("exit_rates", [](SparseMarkovAutomaton<double> const& ma) { return ma.getExitRates(); })
.def_property_readonly("markovian_states", [](SparseMarkovAutomaton<double> const& ma) { return ma.getMarkovianStates(); }) //todo new: tests .def_property_readonly("markovian_states", [](SparseMarkovAutomaton<double> const& ma) { return ma.getMarkovianStates(); }) //todo new: tests
.def_property_readonly("nondeterministic_choice_indices", [](SparseMarkovAutomaton<double> const& ma) { return ma.getNondeterministicChoiceIndices(); }) .def_property_readonly("nondeterministic_choice_indices", [](SparseMarkovAutomaton<double> const& ma) { return ma.getNondeterministicChoiceIndices(); })
.def("apply_scheduler", [](SparseMarkovAutomaton<double> const& ma, storm::storage::Scheduler<double> const& scheduler, bool dropUnreachableStates) { return ma.applyScheduler(scheduler, dropUnreachableStates); } , "apply scheduler", "scheduler"_a, "drop_unreachable_states"_a = true) .def("apply_scheduler", [](SparseMarkovAutomaton<double> const& ma, storm::storage::Scheduler<double> const& scheduler, bool dropUnreachableStates) { return ma.applyScheduler(scheduler, dropUnreachableStates); } , "apply scheduler", "scheduler"_a, "drop_unreachable_states"_a = true)

12
src/storage/model_components.cpp

@ -15,17 +15,11 @@ template<typename ValueType> using SparseRewardModel = storm::models::sparse::St
template<typename ValueType> using SparseModelComponents = storm::storage::sparse::ModelComponents<ValueType>; template<typename ValueType> using SparseModelComponents = storm::storage::sparse::ModelComponents<ValueType>;
// others: todo
// <storm::RationalFunction>;
//
// <storm::RationalNumber>
// <double, storm::models::sparse::StandardRewardModel<storm::Interval>>
// Parametric models, Valuetype: <storm::RationalFunction> todo // Parametric models, Valuetype: <storm::RationalFunction> todo
void define_sparse_model_components(py::module& m) { void define_sparse_model_components(py::module& m) {
// shared_ptr? todo
py::class_<SparseModelComponents<double>, std::shared_ptr<SparseModelComponents<double>>>(m, "SparseModelComponents", "ModelComponents description..") //todo py::class_<SparseModelComponents<double>, std::shared_ptr<SparseModelComponents<double>>>(m, "SparseModelComponents", "ModelComponents description..") //todo
.def(py::init<SparseMatrix<double> const&, StateLabeling const&, std::unordered_map<std::string, SparseRewardModel<double>> const&, .def(py::init<SparseMatrix<double> const&, StateLabeling const&, std::unordered_map<std::string, SparseRewardModel<double>> const&,
@ -34,11 +28,9 @@ void define_sparse_model_components(py::module& m) {
py::arg("reward_models") = std::unordered_map<std::string, SparseRewardModel<double>>(), py::arg("rate_transitions") = false, py::arg("reward_models") = std::unordered_map<std::string, SparseRewardModel<double>>(), py::arg("rate_transitions") = false,
py::arg("markovian_states") = boost::none, py::arg("player1_matrix") = boost::none) py::arg("markovian_states") = boost::none, py::arg("player1_matrix") = boost::none)
// General components (for all model types) // General components (for all model types)
.def_readwrite("transition_matrix", &SparseModelComponents<double>::transitionMatrix)
.def_readwrite("state_labeling", &SparseModelComponents<double>::stateLabeling)
.def_readwrite("transition_matrix", &SparseModelComponents<double>::transitionMatrix, "The transition matrix")
.def_readwrite("state_labeling", &SparseModelComponents<double>::stateLabeling, "The state labeling")
.def_readwrite("reward_models", &SparseModelComponents<double>::rewardModels, "Reward models associated with the model") .def_readwrite("reward_models", &SparseModelComponents<double>::rewardModels, "Reward models associated with the model")
.def_readwrite("choice_labeling", &SparseModelComponents<double>::choiceLabeling, "A vector that stores a labeling for each choice") .def_readwrite("choice_labeling", &SparseModelComponents<double>::choiceLabeling, "A vector that stores a labeling for each choice")
.def_readwrite("state_valuations", &SparseModelComponents<double>::stateValuations, "A vector that stores for each state to which variable valuation it belongs") .def_readwrite("state_valuations", &SparseModelComponents<double>::stateValuations, "A vector that stores for each state to which variable valuation it belongs")

Loading…
Cancel
Save