You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.9 KiB
57 lines
2.9 KiB
import stormpy
|
|
import stormpy.logic
|
|
from helpers.helper import get_example_path
|
|
|
|
import math
|
|
|
|
class TestModelChecking:
|
|
def test_model_checking_dtmc(self):
|
|
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
|
|
formulas = stormpy.parse_formulas_for_prism_program("P=? [ F \"one\" ]", program)
|
|
model = stormpy.build_model(program, formulas[0])
|
|
assert model.nr_states == 13
|
|
assert model.nr_transitions == 20
|
|
result = stormpy.model_checking(model, formulas[0])
|
|
assert math.isclose(result, 0.16666666666666663)
|
|
|
|
def test_model_checking_all_dtmc(self):
|
|
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
|
|
formulas = stormpy.parse_formulas_for_prism_program("P=? [ F \"one\" ]", program)
|
|
model = stormpy.build_model(program, formulas[0])
|
|
assert model.nr_states == 13
|
|
assert model.nr_transitions == 20
|
|
results = stormpy.model_checking_all(model, formulas[0])
|
|
reference = [0.16666666666666663, 0.3333333333333333, 0, 0.6666666666666666, 0, 0, 0, 1, 0, 0, 0, 0, 0]
|
|
assert all(map(math.isclose, results, reference))
|
|
|
|
def test_parametric_state_elimination(self):
|
|
import pycarl
|
|
import pycarl.formula
|
|
program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
|
|
prop = "P=? [F s=5]"
|
|
formulas = stormpy.parse_formulas_for_prism_program(prop, program)
|
|
model = stormpy.build_parametric_model_from_prism_program(program, formulas)
|
|
assert model.nr_states == 613
|
|
assert model.nr_transitions == 803
|
|
assert model.model_type == stormpy.ModelType.DTMC
|
|
assert model.has_parameters
|
|
result = stormpy.model_checking(model, formulas[0])
|
|
func = result.result_function
|
|
one = pycarl.FactorizedPolynomial(pycarl.Rational(1))
|
|
assert func.denominator == one
|
|
constraints_well_formed = result.constraints_well_formed
|
|
for constraint in constraints_well_formed:
|
|
assert constraint.rel() == pycarl.formula.Relation.GEQ or constraint.rel() == pycarl.formula.Relation.LEQ
|
|
constraints_graph_preserving = result.constraints_graph_preserving
|
|
for constraint in constraints_graph_preserving:
|
|
assert constraint.rel() == pycarl.formula.Relation.GREATER
|
|
|
|
def test_model_checking_prob01(self):
|
|
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
|
|
formulas = stormpy.parse_formulas_for_prism_program("P=? [ F \"one\" ]", program)
|
|
model = stormpy.build_model(program, formulas[0])
|
|
phiStates = stormpy.BitVector(model.nr_states, True)
|
|
psiStates = stormpy.BitVector(model.nr_states, [model.nr_states-1])
|
|
(prob0, prob1) = stormpy.compute_prob01states(model, phiStates, psiStates)
|
|
assert prob0.number_of_set_bits() == 9
|
|
assert prob1.number_of_set_bits() == 1
|