Matthias Volk
8 years ago
7 changed files with 101 additions and 33 deletions
-
2src/mod_storage.cpp
-
7src/storage/bitvector.cpp
-
29src/storage/labeling.cpp
-
8src/storage/labeling.h
-
13src/storage/model.cpp
-
49tests/storage/test_labeling.py
-
26tests/storage/test_model.py
@ -0,0 +1,29 @@ |
|||
#include "labeling.h"
|
|||
|
|||
#include "storm/models/sparse/StateLabeling.h"
|
|||
|
|||
// Define python bindings
|
|||
void define_labeling(py::module& m) { |
|||
|
|||
// StateLabeling
|
|||
py::class_<storm::models::sparse::StateLabeling, std::shared_ptr<storm::models::sparse::StateLabeling>>(m, "StateLabeling", "Labeling for states") |
|||
.def("add_label", [](storm::models::sparse::StateLabeling& labeling, std::string label) { |
|||
labeling.addLabel(label); |
|||
}, py::arg("label"), "Add label") |
|||
.def("get_labels", &storm::models::sparse::StateLabeling::getLabels, "Get all labels") |
|||
.def("get_labels_of_state", &storm::models::sparse::StateLabeling::getLabelsOfState, "Get labels of given state", py::arg("state")) |
|||
.def("contains_label", &storm::models::sparse::StateLabeling::containsLabel, "Check if the given label is contained in the labeling", py::arg("label")) |
|||
.def("add_label_to_state", &storm::models::sparse::StateLabeling::addLabelToState, "Add label to state", py::arg("label"), py::arg("state")) |
|||
.def("has_state_label", &storm::models::sparse::StateLabeling::getStateHasLabel, "Check if the given state has the given label", py::arg("label"), py::arg("state")) |
|||
.def("get_states", &storm::models::sparse::StateLabeling::getStates, "Get all states which have the given label", py::arg("label")) |
|||
.def("set_states", [](storm::models::sparse::StateLabeling& labeling, std::string const& label, storm::storage::BitVector const& states) { |
|||
labeling.setStates(label, states); |
|||
}, "Set all states which have the given label", py::arg("label"), py::arg("states")) |
|||
.def("__str__", [](storm::models::sparse::StateLabeling const& labeling) { |
|||
std::ostringstream oss; |
|||
oss << labeling; |
|||
return oss.str(); |
|||
}) |
|||
; |
|||
|
|||
} |
@ -0,0 +1,8 @@ |
|||
#ifndef PYTHON_STORAGE_LABELING_H_ |
|||
#define PYTHON_STORAGE_LABELING_H_ |
|||
|
|||
#include "common.h" |
|||
|
|||
void define_labeling(py::module& m); |
|||
|
|||
#endif /* PYTHON_STORAGE_LABELING_H_ */ |
@ -0,0 +1,49 @@ |
|||
import stormpy |
|||
import stormpy.logic |
|||
from helpers.helper import get_example_path |
|||
|
|||
class TestLabeling: |
|||
def test_set_labeling(self): |
|||
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm")) |
|||
model = stormpy.build_model(program) |
|||
labeling = model.labeling |
|||
assert "tmp" not in labeling.get_labels() |
|||
assert not labeling.contains_label("tmp") |
|||
labeling.add_label("tmp") |
|||
assert labeling.contains_label("tmp") |
|||
labeling.add_label_to_state("tmp", 0) |
|||
assert labeling.has_state_label("tmp", 0) |
|||
states = labeling.get_states("tmp") |
|||
assert states.get(0) |
|||
states.set(3) |
|||
labeling.set_states("tmp", states) |
|||
assert labeling.has_state_label("tmp", 3) |
|||
|
|||
def test_label(self): |
|||
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm")) |
|||
formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program) |
|||
model = stormpy.build_model(program, formulas) |
|||
labeling = model.labeling |
|||
labels = labeling.get_labels() |
|||
assert len(labels) == 3 |
|||
assert "init" in labels |
|||
assert "one" in labels |
|||
assert "init" in model.labels_state(0) |
|||
assert "init" in labeling.get_labels_of_state(0) |
|||
assert "one" in model.labels_state(7) |
|||
assert "one" in labeling.get_labels_of_state(7) |
|||
|
|||
def test_label_parametric(self): |
|||
program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm")) |
|||
formulas = stormpy.parse_properties_for_prism_program("P=? [ F s=5 ]", program) |
|||
model = stormpy.build_parametric_model(program, formulas) |
|||
labels = model.labeling.get_labels() |
|||
assert len(labels) == 3 |
|||
assert "init" in labels |
|||
assert "(s = 5)" in labels |
|||
assert "init" in model.labels_state(0) |
|||
assert "(s = 5)" in model.labels_state(28) |
|||
assert "(s = 5)" in model.labels_state(611) |
|||
initial_states = model.initial_states |
|||
assert len(initial_states) == 1 |
|||
assert 0 in initial_states |
Write
Preview
Loading…
Cancel
Save
Reference in new issue