Browse Source

added basic shield export functionality

refactoring
Thomas Knoll 1 year ago
parent
commit
fa533af4c4
  1. 4
      lib/stormpy/__init__.py
  2. 2
      src/core/input.cpp
  3. 3
      src/core/modelchecking.cpp
  4. 3
      src/logic/formulae.cpp
  5. 1
      src/mod_shields.cpp
  6. 2
      src/shields/abstract_shield.cpp
  7. 2
      src/shields/optimal_shield.cpp
  8. 2
      src/shields/post_shield.cpp
  9. 3
      src/shields/pre_shield.cpp
  10. 3
      src/shields/shield_handling.cpp

4
lib/stormpy/__init__.py

@ -322,6 +322,10 @@ def check_model_sparse(model, property, only_initial_states=False, extract_sched
else:
task = core.CheckTask(formula, only_initial_states)
task.set_produce_schedulers(extract_scheduler)
if property.is_shielding_property():
task.set_shielding_expression(property.shielding_expression)
return core._model_checking_sparse_engine(model, task, environment=environment)

2
src/core/input.cpp

@ -9,6 +9,8 @@ void define_property(py::module& m) {
.def(py::init<storm::jani::Property>())
.def_property_readonly("name", &storm::jani::Property::getName, "Obtain the name of the property")
.def_property_readonly("raw_formula", &storm::jani::Property::getRawFormula, "Obtain the formula directly")
.def_property_readonly("shielding_expression", &storm::jani::Property::getShieldingExpression, "Obtain the shielding expression")
.def("is_shielding_property", &storm::jani::Property::isShieldingProperty, "Is the property a shielding property?")
.def("__str__", &streamToString<storm::jani::Property>)
;
}

3
src/core/modelchecking.cpp

@ -65,17 +65,20 @@ void define_modelchecking(py::module& m) {
//m.def("create_check_task", &storm::api::createTask, "Create task for verification", py::arg("formula"), py::arg("only_initial_states") = false);
.def(py::init<storm::logic::Formula const&, bool>(), py::arg("formula"), py::arg("only_initial_states") = false)
.def("set_produce_schedulers", &CheckTask<double>::setProduceSchedulers, "Set whether schedulers should be produced (if possible)", py::arg("produce_schedulers") = true)
.def("set_shielding_expression", &CheckTask<double>::setShieldingExpression, py::arg("expr"))
;
// CheckTask
py::class_<CheckTask<storm::RationalNumber>, std::shared_ptr<CheckTask<storm::RationalNumber>>>(m, "ExactCheckTask", "Task for model checking with exact numbers")
//m.def("create_check_task", &storm::api::createTask, "Create task for verification", py::arg("formula"), py::arg("only_initial_states") = false);
.def(py::init<storm::logic::Formula const&, bool>(), py::arg("formula"), py::arg("only_initial_states") = false)
.def("set_produce_schedulers", &CheckTask<storm::RationalNumber>::setProduceSchedulers, "Set whether schedulers should be produced (if possible)", py::arg("produce_schedulers") = true)
.def("set_shielding_expression", &CheckTask<storm::RationalNumber>::setShieldingExpression, py::arg("expr"))
;
py::class_<CheckTask<storm::RationalFunction>, std::shared_ptr<CheckTask<storm::RationalFunction>>>(m, "ParametricCheckTask", "Task for parametric model checking")
//m.def("create_check_task", &storm::api::createTask, "Create task for verification", py::arg("formula"), py::arg("only_initial_states") = false);
.def(py::init<storm::logic::Formula const&, bool>(), py::arg("formula"), py::arg("only_initial_states") = false)
.def("set_produce_schedulers", &CheckTask<storm::RationalFunction>::setProduceSchedulers, "Set whether schedulers should be produced (if possible)", py::arg("produce_schedulers") = true)
.def("set_shielding_expression", &CheckTask<storm::RationalFunction>::setShieldingExpression, py::arg("expr"))
;
// Model checking

3
src/logic/formulae.cpp

@ -2,7 +2,7 @@
#include "storm/logic/Formulas.h"
#include "storm/logic/CloneVisitor.h"
#include "storm/logic/LabelSubstitutionVisitor.h"
#include "storm/logic/ShieldExpression.h"
void define_formulae(py::module& m) {
@ -100,4 +100,5 @@ void define_formulae(py::module& m) {
.def_property_readonly("reward_name", &storm::logic::RewardOperatorFormula::getRewardModelName);
py::class_<storm::logic::BinaryStateFormula, std::shared_ptr<storm::logic::BinaryStateFormula>> binaryStateFormula(m, "BinaryStateFormula", "State formula with two operands", stateFormula);
py::class_<storm::logic::BinaryBooleanStateFormula, std::shared_ptr<storm::logic::BinaryBooleanStateFormula>>(m, "BooleanBinaryStateFormula", "Boolean binary state formula", binaryStateFormula);
py::class_<storm::logic::ShieldExpression, std::shared_ptr<storm::logic::ShieldExpression>>(m, "ShieldExpression");
}

1
src/mod_shields.cpp

@ -30,4 +30,5 @@ PYBIND11_MODULE(shields, m) {
define_post_shield<storm::RationalNumber, typename storm::storage::SparseMatrix<storm::RationalNumber>::index_type>(m, "Exact");
define_optimal_shield<double, typename storm::storage::SparseMatrix<double>::index_type>(m, "Double");
define_optimal_shield<storm::RationalNumber, typename storm::storage::SparseMatrix<storm::RationalNumber>::index_type>(m, "Exact");
define_shield_handling<double, typename storm::storage::SparseMatrix<double>::index_type>(m);
}

2
src/shields/abstract_shield.cpp

@ -11,7 +11,7 @@ void define_abstract_shield(py::module& m, std::string vt_suffix) {
using AbstractShield = tempest::shields::AbstractShield<ValueType, IndexType>;
std::string shieldClassName = std::string("AbstractShield") + vt_suffix;
py::class_<AbstractShield>(m, shieldClassName.c_str())
py::class_<AbstractShield, std::shared_ptr<AbstractShield>>(m, shieldClassName.c_str())
.def("compute_row_group_size", &AbstractShield::computeRowGroupSizes)
.def("get_class_name", &AbstractShield::getClassName)
.def("get_optimization_direction", &AbstractShield::getOptimizationDirection)

2
src/shields/optimal_shield.cpp

@ -10,7 +10,7 @@ void define_optimal_shield(py::module& m, std::string vt_suffix) {
std::string shieldClassName = std::string("OptimalShield") + vt_suffix;
py::class_<OptimalShield, AbstractShield>(m, shieldClassName.c_str())
py::class_<OptimalShield, AbstractShield, std::shared_ptr<OptimalShield>>(m, shieldClassName.c_str())
;
}

2
src/shields/post_shield.cpp

@ -10,7 +10,7 @@ void define_post_shield(py::module& m, std::string vt_suffix) {
std::string shieldClassName = std::string("PostShield") + vt_suffix;
py::class_<PostShield, AbstractShield>(m, shieldClassName.c_str())
py::class_<PostShield, AbstractShield, std::shared_ptr<PostShield>>(m, shieldClassName.c_str())
;
}

3
src/shields/pre_shield.cpp

@ -18,7 +18,8 @@ void define_pre_shield(py::module& m, std::string vt_suffix) {
std::string shieldClassName = std::string("PreShield") + vt_suffix;
py::class_<PreShield, AbstractShield>(m, shieldClassName.c_str())
py::class_<PreShield, AbstractShield, std::shared_ptr<PreShield>>(m, shieldClassName.c_str())
.def("construct", &PreShield::construct, "Construct the shield")
;
}

3
src/shields/shield_handling.cpp

@ -1,10 +1,11 @@
#include "shield_handling.h"
#include "storm/shields/ShieldHandling.h"
#include "storm/api/export.h"
template <typename ValueType, typename IndexType>
void define_shield_handling(py::module& m) {
m.def("create_shield", &tempest::shields::createShield<ValueType, IndexType>, "hi");
m.def("export_shield", &storm::api::exportShield<ValueType, IndexType>, py::arg("model"), py::arg("shield"));
}
template void define_shield_handling<double, typename storm::storage::SparseMatrix<double>::index_type>(py::module& m);
Loading…
Cancel
Save