From 2e45a11873baef065a3993a010c9e6aebea81ed3 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Thu, 20 Apr 2017 12:04:41 +0200 Subject: [PATCH] Gather derivatives for PLA --- src/core/pla.cpp | 13 +++++++++++++ tests/core/test_pla.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/core/pla.cpp b/src/core/pla.cpp index f554cd8..641aa9c 100644 --- a/src/core/pla.cpp +++ b/src/core/pla.cpp @@ -12,6 +12,17 @@ storm::modelchecker::parametric::RegionCheckResult checkRegion(std::shared_ptr

analyzeRegion(region, initialResult, sampleVertices); } +std::set gatherDerivatives(storm::models::sparse::Dtmc const& model, carl::Variable const& var) { + std::set derivatives; + for (auto it : model.getTransitionMatrix()) { + storm::Polynomial pol = it.getValue().derivative(var, 1).nominator(); + if (!pol.isConstant()) { + derivatives.insert(pol); + } + } + return derivatives; +} + // Define python bindings void define_pla(py::module& m) { @@ -44,4 +55,6 @@ void define_pla(py::module& m) { .def("specify_formula", &specifyFormula, "Specify formula", py::arg("formula")) .def("check_region", &checkRegion, "Check region", py::arg("region"), py::arg("initialResult") = storm::modelchecker::parametric::RegionCheckResult::Unknown, py::arg("sampleVertices") = false) ; + + m.def("gather_derivatives", &gatherDerivatives, "Gather all derivatives of transition probabilities", py::arg("model"), py::arg("var")); } diff --git a/tests/core/test_pla.py b/tests/core/test_pla.py index be48f7a..4537d40 100644 --- a/tests/core/test_pla.py +++ b/tests/core/test_pla.py @@ -43,3 +43,18 @@ class TestModelChecking: region = stormpy.ParameterRegion("0.1<=pL<=0.73,0.2<=pK<=0.715", parameters) result = checker.check_region(region) assert result == stormpy.RegionCheckResult.ALLVIOLATED + + def test_derivatives(self): + import pycarl + program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm")) + prop = "P<=0.84 [F s=5 ]" + formulas = stormpy.parse_properties_for_prism_program(prop, program) + model = stormpy.build_parametric_model(program, formulas) + assert model.nr_states == 613 + assert model.nr_transitions == 803 + assert model.model_type == stormpy.ModelType.DTMC + assert model.has_parameters + parameters = model.collect_probability_parameters() + assert len(parameters) == 2 + derivatives = stormpy.gather_derivatives(model, list(parameters)[0]) + assert len(derivatives) == 0