Browse Source

Refactored sparse model bindings

refactoring
Matthias Volk 7 years ago
parent
commit
d9b020b1bc
  1. 97
      lib/stormpy/__init__.py
  2. 1
      src/mod_storage.cpp
  3. 188
      src/storage/model.cpp
  4. 1
      src/storage/model.h

97
lib/stormpy/__init__.py

@ -22,15 +22,46 @@ except ImportError:
core._set_up("")
def _convert_sparse_model(model, parametric=False):
"""
Convert (parametric) model in sparse representation into model corresponding to exact model type.
:param model: Sparse model.
:param parametric: Flag indicating if the model is parametric.
:return: Model corresponding to exact model type.
"""
if parametric:
assert model.supports_parameters
if model.model_type == ModelType.DTMC:
return model._as_sparse_pdtmc()
elif model.model_type == ModelType.MDP:
return model._as_sparse_pmdp()
elif model.model_type == ModelType.CTMC:
return model._as_sparse_pctmc()
elif model.model_type == ModelType.MA:
return model._as_sparse_pma()
else:
raise StormError("Not supported parametric model constructed")
else:
assert not model.supports_parameters
if model.model_type == ModelType.DTMC:
return model._as_sparse_dtmc()
elif model.model_type == ModelType.MDP:
return model._as_sparse_mdp()
elif model.model_type == ModelType.CTMC:
return model._as_sparse_ctmc()
elif model.model_type == ModelType.MA:
return model._as_sparse_ma()
else:
raise StormError("Not supported non-parametric model constructed")
def build_model(symbolic_description, properties=None):
"""
Build a model from a symbolic description.
Build a model in sparse representation from a symbolic description.
:param symbolic_description: Symbolic model description to translate into a model.
:param List[Property] properties: List of properties that should be preserved during the translation. If None, then all properties are preserved.
:return: Model in sparse representation.
:rtype: SparseDtmc or SparseMdp
"""
if not symbolic_description.undefined_constants_are_graph_preserving:
raise StormError("Program still contains undefined constants")
@ -40,91 +71,49 @@ def build_model(symbolic_description, properties=None):
intermediate = core._build_sparse_model_from_prism_program(symbolic_description, formulae)
else:
intermediate = core._build_sparse_model_from_prism_program(symbolic_description)
assert not intermediate.supports_parameters
if intermediate.model_type == ModelType.DTMC:
return intermediate._as_dtmc()
elif intermediate.model_type == ModelType.MDP:
return intermediate._as_mdp()
elif intermediate.model_type == ModelType.CTMC:
return intermediate._as_ctmc()
elif intermediate.model_type == ModelType.MA:
return intermediate._as_ma()
else:
raise StormError("Not supported non-parametric model constructed")
return _convert_sparse_model(intermediate, parametric=False)
def build_parametric_model(symbolic_description, properties=None):
"""
Build a parametric model from a symbolic description.
Build a parametric model in sparse representation from a symbolic description.
:param symbolic_description: Symbolic model description to translate into a model.
:param List[Property] properties: List of properties that should be preserved during the translation. If None, then all properties are preserved.
:return: Parametric model in sparse representation.
:rtype: SparseParametricDtmc or SparseParametricMdp
"""
if not symbolic_description.undefined_constants_are_graph_preserving:
raise StormError("Program still contains undefined constants")
if properties:
formulae = [prop.raw_formula for prop in properties]
intermediate = core._build_sparse_parametric_model_from_prism_program(symbolic_description, formulae)
else:
formulae = []
intermediate = core._build_sparse_parametric_model_from_prism_program(symbolic_description, formulae)
assert intermediate.supports_parameters
if intermediate.model_type == ModelType.DTMC:
return intermediate._as_pdtmc()
elif intermediate.model_type == ModelType.MDP:
return intermediate._as_pmdp()
elif intermediate.model_type == ModelType.CTMC:
return intermediate._as_pctmc()
elif intermediate.model_type == ModelType.MA:
return intermediate._as_pma()
else:
raise StormError("Not supported parametric model constructed")
intermediate = core._build_sparse_parametric_model_from_prism_program(symbolic_description)
return _convert_sparse_model(intermediate, parametric=True)
def build_model_from_drn(file):
"""
Build a model from the explicit DRN representation.
Build a model in sparse representation from the explicit DRN representation.
:param String file: DRN file containing the model.
:return: Model in sparse representation.
:rtype: SparseDtmc or SparseMdp or SparseCTMC or SparseMA
"""
intermediate = core._build_sparse_model_from_drn(file)
assert not intermediate.supports_parameters
if intermediate.model_type == ModelType.DTMC:
return intermediate._as_dtmc()
elif intermediate.model_type == ModelType.MDP:
return intermediate._as_mdp()
elif intermediate.model_type == ModelType.CTMC:
return intermediate._as_ctmc()
elif intermediate.model_type == ModelType.MA:
return intermediate._as_ma()
else:
raise StormError("Not supported non-parametric model constructed")
return _convert_sparse_model(intermediate, parametric=False)
def build_parametric_model_from_drn(file):
"""
Build a parametric model from the explicit DRN representation.
Build a parametric model in sparse representation from the explicit DRN representation.
:param String file: DRN file containing the model.
:return: Parametric model in sparse representation.
:rtype: SparseParametricDtmc or SparseParametricMdp or SparseParametricCTMC or SparseParametricMA
"""
intermediate = core._build_sparse_parametric_model_from_drn(file)
assert intermediate.supports_parameters
if intermediate.model_type == ModelType.DTMC:
return intermediate._as_pdtmc()
elif intermediate.model_type == ModelType.MDP:
return intermediate._as_pmdp()
elif intermediate.model_type == ModelType.CTMC:
return intermediate._as_pctmc()
elif intermediate.model_type == ModelType.MA:
return intermediate._as_pma()
else:
raise StormError("Not supported parametric model constructed")
return _convert_sparse_model(intermediate, parametric=True)
def perform_bisimulation(model, properties, bisimulation_type):

1
src/mod_storage.cpp

@ -20,6 +20,7 @@ PYBIND11_MODULE(storage, m) {
define_bitvector(m);
define_model(m);
define_sparse_model(m);
define_sparse_matrix(m);
define_state(m);
define_prism(m);

188
src/storage/model.cpp

@ -13,22 +13,22 @@
#include <string>
#include <sstream>
// Typedefs
using RationalFunction = storm::RationalFunction;
using state_type = storm::storage::sparse::state_type;
template<typename ValueType> using SparseRewardModel = storm::models::sparse::StandardRewardModel<ValueType>;
using ModelBase = storm::models::ModelBase;
using state_type = storm::storage::sparse::state_type;
using RationalFunction = storm::RationalFunction;
using RationalFunctionVariable = storm::RationalFunctionVariable;
template<typename ValueType> using Model = storm::models::sparse::Model<ValueType>;
template<typename ValueType> using Dtmc = storm::models::sparse::Dtmc<ValueType>;
template<typename ValueType> using Mdp = storm::models::sparse::Mdp<ValueType>;
template<typename ValueType> using Ctmc = storm::models::sparse::Ctmc<ValueType>;
template<typename ValueType> using MarkovAutomaton = storm::models::sparse::MarkovAutomaton<ValueType>;
template<typename ValueType> using SparseMatrix = storm::storage::SparseMatrix<ValueType>;
template<typename ValueType> using RewardModel = storm::models::sparse::StandardRewardModel<ValueType>;
template<typename ValueType> using SparseModel = storm::models::sparse::Model<ValueType>;
template<typename ValueType> using SparseDtmc = storm::models::sparse::Dtmc<ValueType>;
template<typename ValueType> using SparseMdp = storm::models::sparse::Mdp<ValueType>;
template<typename ValueType> using SparseCtmc = storm::models::sparse::Ctmc<ValueType>;
template<typename ValueType> using SparseMarkovAutomaton = storm::models::sparse::MarkovAutomaton<ValueType>;
// Thin wrapper for getting initial states
template<typename ValueType>
std::vector<state_type> getInitialStates(Model<ValueType> const& model) {
std::vector<state_type> getInitialStates(SparseModel<ValueType> const& model) {
std::vector<state_type> initialStates;
for (auto entry : model.getInitialStates()) {
initialStates.push_back(entry);
@ -38,28 +38,28 @@ std::vector<state_type> getInitialStates(Model<ValueType> const& model) {
// Thin wrapper for getting transition matrix
template<typename ValueType>
SparseMatrix<ValueType>& getTransitionMatrix(Model<ValueType>& model) {
storm::storage::SparseMatrix<ValueType>& getTransitionMatrix(SparseModel<ValueType>& model) {
return model.getTransitionMatrix();
}
template<typename ValueType>
storm::storage::SparseMatrix<ValueType> getBackwardTransitionMatrix(storm::models::sparse::Model<ValueType>& model) {
return model.getBackwardTransitions();
storm::storage::SparseMatrix<ValueType> getBackwardTransitionMatrix(SparseModel<ValueType> const& model) {
return std::move(model.getBackwardTransitions());
}
// requires pycarl.Variable
std::set<RationalFunctionVariable> probabilityVariables(Model<RationalFunction> const& model) {
std::set<storm::RationalFunctionVariable> probabilityVariables(SparseModel<RationalFunction> const& model) {
return storm::models::sparse::getProbabilityParameters(model);
}
std::set<RationalFunctionVariable> rewardVariables(Model<RationalFunction> const& model) {
std::set<storm::RationalFunctionVariable> rewardVariables(SparseModel<RationalFunction> const& model) {
return storm::models::sparse::getRewardParameters(model);
}
template<typename ValueType>
std::function<std::string (Model<ValueType> const&)> getModelInfoPrinter(std::string name = "Model") {
std::function<std::string (storm::models::Model<ValueType> const&)> getModelInfoPrinter(std::string name = "Model") {
// look, C++ has lambdas and stuff!
return [name](Model<ValueType> const& model) {
return [name](storm::models::Model<ValueType> const& model) {
std::stringstream ss;
model.printModelInformationToStream(ss);
@ -75,11 +75,12 @@ std::function<std::string (Model<ValueType> const&)> getModelInfoPrinter(std::st
}
template<typename ValueType>
storm::models::sparse::StateLabeling& getLabeling(storm::models::sparse::Model<ValueType>& model) {
storm::models::sparse::StateLabeling& getLabeling(SparseModel<ValueType>& model) {
return model.getStateLabeling();
}
// Define python bindings
// Bindings for general models
void define_model(py::module& m) {
// ModelType
@ -98,116 +99,121 @@ void define_model(py::module& m) {
.def_property_readonly("supports_parameters", &ModelBase::supportsParameters, "Flag whether model supports parameters")
.def_property_readonly("has_parameters", &ModelBase::hasParameters, "Flag whether model has parameters")
.def_property_readonly("is_exact", &ModelBase::isExact, "Flag whether model is exact")
.def("_as_dtmc", [](ModelBase &modelbase) {
return modelbase.as<Dtmc<double>>();
}, "Get model as DTMC")
.def("_as_pdtmc", [](ModelBase &modelbase) {
return modelbase.as<Dtmc<RationalFunction>>();
}, "Get model as pDTMC")
.def("_as_mdp", [](ModelBase &modelbase) {
return modelbase.as<Mdp<double>>();
}, "Get model as MDP")
.def("_as_pmdp", [](ModelBase &modelbase) {
return modelbase.as<Mdp<RationalFunction>>();
}, "Get model as pMDP")
.def("_as_ctmc", [](ModelBase &modelbase) {
return modelbase.as<Ctmc<double>>();
}, "Get model as CTMC")
.def("_as_pctmc", [](ModelBase &modelbase) {
return modelbase.as<Ctmc<RationalFunction>>();
}, "Get model as pCTMC")
.def("_as_ma", [](ModelBase &modelbase) {
return modelbase.as<MarkovAutomaton<double>>();
}, "Get model as MA")
.def("_as_pma", [](ModelBase &modelbase) {
return modelbase.as<MarkovAutomaton<RationalFunction>>();
}, "Get model as pMA")
.def("_as_sparse_dtmc", [](ModelBase &modelbase) {
return modelbase.as<SparseDtmc<double>>();
}, "Get model as sparse DTMC")
.def("_as_sparse_pdtmc", [](ModelBase &modelbase) {
return modelbase.as<SparseDtmc<RationalFunction>>();
}, "Get model as sparse pDTMC")
.def("_as_sparse_mdp", [](ModelBase &modelbase) {
return modelbase.as<SparseMdp<double>>();
}, "Get model as sparse MDP")
.def("_as_sparse_pmdp", [](ModelBase &modelbase) {
return modelbase.as<SparseMdp<RationalFunction>>();
}, "Get model as sparse pMDP")
.def("_as_sparse_ctmc", [](ModelBase &modelbase) {
return modelbase.as<SparseCtmc<double>>();
}, "Get model as sparse CTMC")
.def("_as_sparse_pctmc", [](ModelBase &modelbase) {
return modelbase.as<SparseCtmc<RationalFunction>>();
}, "Get model as sparse pCTMC")
.def("_as_sparse_ma", [](ModelBase &modelbase) {
return modelbase.as<SparseMarkovAutomaton<double>>();
}, "Get model as sparse MA")
.def("_as_sparse_pma", [](ModelBase &modelbase) {
return modelbase.as<SparseMarkovAutomaton<RationalFunction>>();
}, "Get model as sparse pMA")
.def("_as_symbolic_dtmc", [](ModelBase &modelbase) {
return modelbase.as<SymbolicDtmc<double>>();
}, "Get model as symbolic DTMC")
;
}
// Bindings for sparse models
void define_sparse_model(py::module& m) {
// Models
py::class_<Model<double>, std::shared_ptr<Model<double>>> model(m, "_SparseModel", "A probabilistic model where transitions are represented by doubles and saved in a sparse matrix", modelBase);
py::class_<SparseModel<double>, std::shared_ptr<SparseModel<double>>, ModelBase> model(m, "_SparseModel", "A probabilistic model where transitions are represented by doubles and saved in a sparse matrix");
model.def_property_readonly("labeling", &getLabeling<double>, "Labels")
.def("labels_state", &Model<double>::getLabelsOfState, py::arg("state"), "Get labels of state")
.def("labels_state", &SparseModel<double>::getLabelsOfState, py::arg("state"), "Get labels of state")
.def_property_readonly("initial_states", &getInitialStates<double>, "Initial states")
.def_property_readonly("states", [](Model<double>& model) {
.def_property_readonly("states", [](SparseModel<double>& model) {
return SparseModelStates<double>(model);
}, "Get states")
.def_property_readonly("reward_models", [](Model<double>& model) {return model.getRewardModels(); }, "Reward models")
.def_property_readonly("reward_models", [](SparseModel<double>& model) {return model.getRewardModels(); }, "Reward models")
.def_property_readonly("transition_matrix", &getTransitionMatrix<double>, py::return_value_policy::reference, py::keep_alive<1, 0>(), "Transition matrix")
.def_property_readonly("backward_transition_matrix", &getBackwardTransitionMatrix<double>, py::return_value_policy::reference, py::keep_alive<1, 0>(), "Backward transition matrix")
.def("reduce_to_state_based_rewards", &Model<double>::reduceToStateBasedRewards)
.def("reduce_to_state_based_rewards", &SparseModel<double>::reduceToStateBasedRewards)
.def("__str__", getModelInfoPrinter<double>())
;
py::class_<Dtmc<double>, std::shared_ptr<Dtmc<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("__str__", getModelInfoPrinter<double>("DTMC"))
;
py::class_<Mdp<double>, std::shared_ptr<Mdp<double>>>(m, "SparseMdp", "MDP in sparse representation", model)
py::class_<SparseMdp<double>, std::shared_ptr<SparseMdp<double>>>(m, "SparseMdp", "MDP in sparse representation", model)
.def("__str__", getModelInfoPrinter<double>("MDP"))
;
py::class_<storm::models::sparse::Ctmc<double>, std::shared_ptr<storm::models::sparse::Ctmc<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("__str__", getModelInfoPrinter<double>("CTMC"))
;
py::class_<storm::models::sparse::MarkovAutomaton<double>, std::shared_ptr<storm::models::sparse::MarkovAutomaton<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("__str__", getModelInfoPrinter<double>("MA"))
;
py::class_<storm::models::sparse::StandardRewardModel<double>>(m, "SparseRewardModel", "Reward structure for sparse models")
.def_property_readonly("has_state_rewards", &RewardModel<double>::hasStateRewards)
.def_property_readonly("has_state_action_rewards", &RewardModel<double>::hasStateActionRewards)
.def_property_readonly("has_transition_rewards", &RewardModel<double>::hasTransitionRewards)
.def_property_readonly("transition_rewards", [](RewardModel<double>& rewardModel) {return rewardModel.getTransitionRewardMatrix();})
.def_property_readonly("state_rewards", [](RewardModel<double>& rewardModel) {return rewardModel.getStateRewardVector();})
.def("get_state_reward", [](RewardModel<double>& rewardModel, uint64_t state) {return rewardModel.getStateReward(state);})
.def("get_state_action_reward", [](RewardModel<double>& rewardModel, uint64_t action_index) {return rewardModel.getStateActionReward(action_index);})
.def_property_readonly("state_action_rewards", [](RewardModel<double>& rewardModel) {return rewardModel.getStateActionRewardVector();})
.def("reduce_to_state_based_rewards", [](RewardModel<double>& rewardModel, SparseMatrix<double> const& transitions, bool onlyStateRewards){return rewardModel.reduceToStateBasedRewards(transitions, onlyStateRewards);}, py::arg("transition_matrix"), py::arg("only_state_rewards"), "Reduce to state-based rewards")
;
py::class_<SparseRewardModel<double>>(m, "SparseRewardModel", "Reward structure for sparse models")
.def_property_readonly("has_state_rewards", &SparseRewardModel<double>::hasStateRewards)
.def_property_readonly("has_state_action_rewards", &SparseRewardModel<double>::hasStateActionRewards)
.def_property_readonly("has_transition_rewards", &SparseRewardModel<double>::hasTransitionRewards)
.def_property_readonly("transition_rewards", [](SparseRewardModel<double>& rewardModel) {return rewardModel.getTransitionRewardMatrix();})
.def_property_readonly("state_rewards", [](SparseRewardModel<double>& rewardModel) {return rewardModel.getStateRewardVector();})
.def("get_state_reward", [](SparseRewardModel<double>& rewardModel, uint64_t state) {return rewardModel.getStateReward(state);})
.def("get_state_action_reward", [](SparseRewardModel<double>& rewardModel, uint64_t action_index) {return rewardModel.getStateActionReward(action_index);})
.def_property_readonly("state_action_rewards", [](SparseRewardModel<double>& rewardModel) {return rewardModel.getStateActionRewardVector();})
.def("reduce_to_state_based_rewards", [](SparseRewardModel<double>& rewardModel, storm::storage::SparseMatrix<double> const& transitions, bool onlyStateRewards){return rewardModel.reduceToStateBasedRewards(transitions, onlyStateRewards);}, py::arg("transition_matrix"), py::arg("only_state_rewards"), "Reduce to state-based rewards")
;
py::class_<Model<RationalFunction>, std::shared_ptr<Model<RationalFunction>>> modelRatFunc(m, "_SparseParametricModel", "A probabilistic model where transitions are represented by rational functions and saved in a sparse matrix", modelBase);
py::class_<SparseModel<RationalFunction>, std::shared_ptr<SparseModel<RationalFunction>>, ModelBase> modelRatFunc(m, "_SparseParametricModel", "A probabilistic model where transitions are represented by rational functions and saved in a sparse matrix");
modelRatFunc.def("collect_probability_parameters", &probabilityVariables, "Collect parameters")
.def("collect_reward_parameters", &rewardVariables, "Collect reward parameters")
.def_property_readonly("labeling", &getLabeling<storm::RationalFunction>, "Labels")
.def("labels_state", &Model<RationalFunction>::getLabelsOfState, py::arg("state"), "Get labels of state")
.def_property_readonly("labeling", &getLabeling<RationalFunction>, "Labels")
.def("labels_state", &SparseModel<RationalFunction>::getLabelsOfState, py::arg("state"), "Get labels of state")
.def_property_readonly("initial_states", &getInitialStates<RationalFunction>, "Initial states")
.def_property_readonly("states", [](Model<storm::RationalFunction>& model) {
return SparseModelStates<storm::RationalFunction>(model);
.def_property_readonly("states", [](SparseModel<RationalFunction>& model) {
return SparseModelStates<RationalFunction>(model);
}, "Get states")
.def_property_readonly("reward_models", [](Model<storm::RationalFunction> const& model) {return model.getRewardModels(); }, "Reward models")
.def_property_readonly("reward_models", [](SparseModel<RationalFunction> const& model) {return model.getRewardModels(); }, "Reward models")
.def_property_readonly("transition_matrix", &getTransitionMatrix<RationalFunction>, py::return_value_policy::reference, py::keep_alive<1, 0>(), "Transition matrix")
.def_property_readonly("backward_transition_matrix", &getBackwardTransitionMatrix<storm::RationalFunction>, py::return_value_policy::reference, py::keep_alive<1, 0>(), "Backward transition matrix")
.def("reduce_to_state_based_rewards", &Model<RationalFunction>::reduceToStateBasedRewards)
.def_property_readonly("backward_transition_matrix", &getBackwardTransitionMatrix<RationalFunction>, py::return_value_policy::reference, py::keep_alive<1, 0>(), "Backward transition matrix")
.def("reduce_to_state_based_rewards", &SparseModel<RationalFunction>::reduceToStateBasedRewards)
.def("__str__", getModelInfoPrinter<RationalFunction>("ParametricModel"))
;
py::class_<Dtmc<RationalFunction>, std::shared_ptr<Dtmc<RationalFunction>>>(m, "SparseParametricDtmc", "pDTMC in sparse representation", modelRatFunc)
py::class_<SparseDtmc<RationalFunction>, std::shared_ptr<SparseDtmc<RationalFunction>>>(m, "SparseParametricDtmc", "pDTMC in sparse representation", modelRatFunc)
.def("__str__", getModelInfoPrinter<RationalFunction>("ParametricDTMC"))
;
py::class_<Mdp<RationalFunction>, std::shared_ptr<Mdp<RationalFunction>>>(m, "SparseParametricMdp", "pMDP in sparse representation", modelRatFunc)
py::class_<SparseMdp<RationalFunction>, std::shared_ptr<SparseMdp<RationalFunction>>>(m, "SparseParametricMdp", "pMDP in sparse representation", modelRatFunc)
.def("__str__", getModelInfoPrinter<RationalFunction>("ParametricMDP"))
;
py::class_<storm::models::sparse::Ctmc<storm::RationalFunction>, std::shared_ptr<storm::models::sparse::Ctmc<storm::RationalFunction>>>(m, "SparseParametricCtmc", "pCTMC in sparse representation", modelRatFunc)
py::class_<SparseCtmc<RationalFunction>, std::shared_ptr<SparseCtmc<RationalFunction>>>(m, "SparseParametricCtmc", "pCTMC in sparse representation", modelRatFunc)
.def("__str__", getModelInfoPrinter<RationalFunction>("ParametricCTMC"))
;
py::class_<storm::models::sparse::MarkovAutomaton<storm::RationalFunction>, std::shared_ptr<storm::models::sparse::MarkovAutomaton<storm::RationalFunction>>>(m, "SparseParametricMA", "pMA in sparse representation", modelRatFunc)
py::class_<SparseMarkovAutomaton<RationalFunction>, std::shared_ptr<SparseMarkovAutomaton<RationalFunction>>>(m, "SparseParametricMA", "pMA in sparse representation", modelRatFunc)
.def("__str__", getModelInfoPrinter<RationalFunction>("ParametricMA"))
;
py::class_<storm::models::sparse::StandardRewardModel<storm::RationalFunction>>(m, "SparseParametricRewardModel", "Reward structure for parametric sparse models")
.def_property_readonly("has_state_rewards", &RewardModel<storm::RationalFunction>::hasStateRewards)
.def_property_readonly("has_state_action_rewards", &RewardModel<storm::RationalFunction>::hasStateActionRewards)
.def_property_readonly("has_transition_rewards", &RewardModel<storm::RationalFunction>::hasTransitionRewards)
.def_property_readonly("transition_rewards", [](RewardModel<storm::RationalFunction>& rewardModel) {return rewardModel.getTransitionRewardMatrix();})
.def_property_readonly("state_rewards", [](RewardModel<storm::RationalFunction>& rewardModel) {return rewardModel.getStateRewardVector();})
.def("get_state_reward", [](RewardModel<storm::RationalFunction>& rewardModel, uint64_t state) {return rewardModel.getStateReward(state);})
.def("get_state_action_reward", [](RewardModel<storm::RationalFunction>& rewardModel, uint64_t action_index) {return rewardModel.getStateActionReward(action_index);})
.def_property_readonly("state_action_rewards", [](RewardModel<storm::RationalFunction>& rewardModel) {return rewardModel.getStateActionRewardVector();})
.def("reduce_to_state_based_rewards", [](RewardModel<storm::RationalFunction>& rewardModel, SparseMatrix<storm::RationalFunction> const& transitions, bool onlyStateRewards){return rewardModel.reduceToStateBasedRewards(transitions, onlyStateRewards);}, py::arg("transition_matrix"), py::arg("only_state_rewards"), "Reduce to state-based rewards")
py::class_<SparseRewardModel<RationalFunction>>(m, "SparseParametricRewardModel", "Reward structure for parametric sparse models")
.def_property_readonly("has_state_rewards", &SparseRewardModel<RationalFunction>::hasStateRewards)
.def_property_readonly("has_state_action_rewards", &SparseRewardModel<RationalFunction>::hasStateActionRewards)
.def_property_readonly("has_transition_rewards", &SparseRewardModel<RationalFunction>::hasTransitionRewards)
.def_property_readonly("transition_rewards", [](SparseRewardModel<RationalFunction>& rewardModel) {return rewardModel.getTransitionRewardMatrix();})
.def_property_readonly("state_rewards", [](SparseRewardModel<RationalFunction>& rewardModel) {return rewardModel.getStateRewardVector();})
.def("get_state_reward", [](SparseRewardModel<RationalFunction>& rewardModel, uint64_t state) {return rewardModel.getStateReward(state);})
.def("get_state_action_reward", [](SparseRewardModel<RationalFunction>& rewardModel, uint64_t action_index) {return rewardModel.getStateActionReward(action_index);})
.def_property_readonly("state_action_rewards", [](SparseRewardModel<RationalFunction>& rewardModel) {return rewardModel.getStateActionRewardVector();})
.def("reduce_to_state_based_rewards", [](SparseRewardModel<RationalFunction>& rewardModel, storm::storage::SparseMatrix<RationalFunction> const& transitions, bool onlyStateRewards){return rewardModel.reduceToStateBasedRewards(transitions, onlyStateRewards);}, py::arg("transition_matrix"), py::arg("only_state_rewards"), "Reduce to state-based rewards")
;
}

1
src/storage/model.h

@ -4,5 +4,6 @@
#include "common.h"
void define_model(py::module& m);
void define_sparse_model(py::module& m);
#endif /* PYTHON_STORAGE_MODEL_H_ */
Loading…
Cancel
Save