Browse Source

Added elimination of reward accumulations in Jani

refactoring
Matthias Volk 7 years ago
parent
commit
8c8e46b8a3
  1. 24
      src/storage/jani.cpp
  2. 11
      tests/core/test_modelchecking.py

24
src/storage/jani.cpp

@ -2,6 +2,7 @@
#include <storm/storage/jani/Model.h> #include <storm/storage/jani/Model.h>
#include <storm/storage/jani/JSONExporter.h> #include <storm/storage/jani/JSONExporter.h>
#include <storm/storage/expressions/ExpressionManager.h> #include <storm/storage/expressions/ExpressionManager.h>
#include <storm/logic/RewardAccumulationEliminationVisitor.h>
#include "src/helpers.h" #include "src/helpers.h"
using namespace storm::jani; using namespace storm::jani;
@ -29,16 +30,21 @@ void define_jani(py::module& m) {
.def_static("encode_edge_and_automaton_index", &Model::encodeAutomatonAndEdgeIndices, "get edge/automaton-index") .def_static("encode_edge_and_automaton_index", &Model::encodeAutomatonAndEdgeIndices, "get edge/automaton-index")
.def_static("decode_edge_and_automaton_index", &Model::decodeAutomatonAndEdgeIndices, "get edge and automaton from edge/automaton index") .def_static("decode_edge_and_automaton_index", &Model::decodeAutomatonAndEdgeIndices, "get edge and automaton from edge/automaton index")
; ;
py::class_<Automaton, std::shared_ptr<Automaton>> automaton(m, "JaniAutomaton", "A Jani Automation"); py::class_<Automaton, std::shared_ptr<Automaton>> automaton(m, "JaniAutomaton", "A Jani Automation");
automaton.def_property_readonly("edges",[](const Automaton& a) {return a.getEdges();}, "get edges") automaton.def_property_readonly("edges",[](const Automaton& a) {return a.getEdges();}, "get edges")
.def_property_readonly("name", &Automaton::getName);
.def_property_readonly("name", &Automaton::getName)
;
py::class_<Edge, std::shared_ptr<Edge>> edge(m, "JaniEdge", "A Jani Edge"); py::class_<Edge, std::shared_ptr<Edge>> edge(m, "JaniEdge", "A Jani Edge");
edge.def_property_readonly("source_location_index", &Edge::getSourceLocationIndex, "index for source location") edge.def_property_readonly("source_location_index", &Edge::getSourceLocationIndex, "index for source location")
.def_property_readonly("destinations", &Edge::getDestinations, "edge destinations") .def_property_readonly("destinations", &Edge::getDestinations, "edge destinations")
.def_property_readonly("nr_destinations", &Edge::getNumberOfDestinations, "nr edge destinations") .def_property_readonly("nr_destinations", &Edge::getNumberOfDestinations, "nr edge destinations")
.def_property_readonly("guard", &Edge::getGuard, "edge guard") .def_property_readonly("guard", &Edge::getGuard, "edge guard")
.def("substitute", &Edge::substitute, py::arg("mapping")) .def("substitute", &Edge::substitute, py::arg("mapping"))
.def("has_silent_action", &Edge::hasSilentAction, "Is the edge labelled with the silent action");
.def("has_silent_action", &Edge::hasSilentAction, "Is the edge labelled with the silent action")
;
py::class_<TemplateEdge, std::shared_ptr<TemplateEdge>> templateEdge(m, "JaniTemplateEdge", "Template edge, internal data structure for edges"); py::class_<TemplateEdge, std::shared_ptr<TemplateEdge>> templateEdge(m, "JaniTemplateEdge", "Template edge, internal data structure for edges");
templateEdge.def(py::init<storm::expressions::Expression>()); templateEdge.def(py::init<storm::expressions::Expression>());
@ -47,21 +53,33 @@ void define_jani(py::module& m) {
.def_property_readonly("probability", &EdgeDestination::getProbability) .def_property_readonly("probability", &EdgeDestination::getProbability)
.def_property_readonly("assignments", &EdgeDestination::getOrderedAssignments) .def_property_readonly("assignments", &EdgeDestination::getOrderedAssignments)
; ;
py::class_<OrderedAssignments, std::shared_ptr<OrderedAssignments>> orderedAssignments(m, "JaniOrderedAssignments", "Set of assignments"); py::class_<OrderedAssignments, std::shared_ptr<OrderedAssignments>> orderedAssignments(m, "JaniOrderedAssignments", "Set of assignments");
orderedAssignments.def("__iter__", [](OrderedAssignments &v) { orderedAssignments.def("__iter__", [](OrderedAssignments &v) {
return py::make_iterator(v.begin(), v.end()); return py::make_iterator(v.begin(), v.end());
}, py::keep_alive<0, 1>()) /* Keep vector alive while iterator is used */ }, py::keep_alive<0, 1>()) /* Keep vector alive while iterator is used */
.def("__str__", &streamToString<OrderedAssignments>) .def("__str__", &streamToString<OrderedAssignments>)
; ;
py::class_<Assignment, std::shared_ptr<Assignment>> assignment(m, "JaniAssignment", "Jani Assignment"); py::class_<Assignment, std::shared_ptr<Assignment>> assignment(m, "JaniAssignment", "Jani Assignment");
assignment.def("__str__", &streamToString<Assignment>) assignment.def("__str__", &streamToString<Assignment>)
.def_property("expression", &Assignment::getAssignedExpression, &Assignment::setAssignedExpression) .def_property("expression", &Assignment::getAssignedExpression, &Assignment::setAssignedExpression)
; ;
py::class_<Constant, std::shared_ptr<Constant>> constant(m, "JaniConstant", "A Constant in JANI"); py::class_<Constant, std::shared_ptr<Constant>> constant(m, "JaniConstant", "A Constant in JANI");
constant.def_property_readonly("defined", &Constant::isDefined, "is constant defined by some expression") constant.def_property_readonly("defined", &Constant::isDefined, "is constant defined by some expression")
.def_property_readonly("name", &Constant::getName, "name of constant") .def_property_readonly("name", &Constant::getName, "name of constant")
.def_property_readonly("type", &Constant::getType, "type of constant") .def_property_readonly("type", &Constant::getType, "type of constant")
.def_property_readonly("expression_variable", &Constant::getExpressionVariable, "expression variable for this constant");
.def_property_readonly("expression_variable", &Constant::getExpressionVariable, "expression variable for this constant")
;
m.def("eliminate_reward_accumulations", [](const Model& model, std::vector<Property>& properties) {
storm::logic::RewardAccumulationEliminationVisitor v(model);
v.eliminateRewardAccumulations(properties);
return properties;
}, "Eliminate reward accumulations", py::arg("model"), py::arg("properties"));
} }

11
tests/core/test_modelchecking.py

@ -32,17 +32,18 @@ class TestModelChecking:
def test_model_checking_jani_dtmc(self): def test_model_checking_jani_dtmc(self):
jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani")) jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani"))
formula = properties["Probability to throw a six"]
formula2 = properties["Expected number of coin flips"]
model = stormpy.build_model(jani_model, [formula, formula2])
formulas = [properties["Probability to throw a six"], properties["Expected number of coin flips"]]
formulas = stormpy.eliminate_reward_accumulations(jani_model, formulas)
assert len(formulas) == 2
model = stormpy.build_model(jani_model, formulas)
assert model.nr_states == 13 assert model.nr_states == 13
assert model.nr_transitions == 20 assert model.nr_transitions == 20
assert len(model.initial_states) == 1 assert len(model.initial_states) == 1
initial_state = model.initial_states[0] initial_state = model.initial_states[0]
assert initial_state == 0 assert initial_state == 0
result = stormpy.model_checking(model, formula)
result = stormpy.model_checking(model, formulas[0])
assert math.isclose(result.at(initial_state), 1 / 6) assert math.isclose(result.at(initial_state), 1 / 6)
result = stormpy.model_checking(model, formula2)
result = stormpy.model_checking(model, formulas[1])
assert math.isclose(result.at(initial_state), 11 / 3) assert math.isclose(result.at(initial_state), 11 / 3)
def test_model_checking_dtmc_all_labels(self): def test_model_checking_dtmc_all_labels(self):

Loading…
Cancel
Save