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.
65 lines
2.6 KiB
65 lines
2.6 KiB
import stormpy
|
|
import stormpy.logic
|
|
from helpers.helper import get_example_path
|
|
|
|
import math
|
|
|
|
|
|
class TestScheduler:
|
|
|
|
def test_scheduler_mdp(self):
|
|
program = stormpy.parse_prism_program(get_example_path("mdp", "coin2-2.nm"))
|
|
formulas = stormpy.parse_properties_for_prism_program("Pmin=? [ F \"finished\" & \"all_coins_equal_1\"]", program)
|
|
model = stormpy.build_model(program, formulas)
|
|
assert model.nr_states == 272
|
|
assert model.nr_transitions == 492
|
|
assert len(model.initial_states) == 1
|
|
initial_state = model.initial_states[0]
|
|
assert initial_state == 0
|
|
result = stormpy.model_checking(model, formulas[0], extract_scheduler=True)
|
|
assert result.has_scheduler
|
|
scheduler = result.scheduler
|
|
assert scheduler.memoryless
|
|
assert scheduler.memory_size == 1
|
|
assert scheduler.deterministic
|
|
for state in model.states:
|
|
choice = scheduler.get_choice(state)
|
|
assert choice.defined
|
|
assert choice.deterministic
|
|
action = choice.get_deterministic_choice()
|
|
assert 0 <= action
|
|
assert action < len(state.actions)
|
|
|
|
def test_scheduler_ma_via_mdp(self):
|
|
program = stormpy.parse_prism_program(get_example_path("ma", "simple.ma"), False, True)
|
|
formulas = stormpy.parse_properties_for_prism_program("Tmin=? [ F s=4 ]", program)
|
|
ma = stormpy.build_model(program, formulas)
|
|
assert ma.nr_states == 5
|
|
assert ma.nr_transitions == 8
|
|
assert ma.model_type == stormpy.ModelType.MA
|
|
|
|
# Convert MA to MDP
|
|
mdp, mdp_formulas = stormpy.transform_to_discrete_time_model(ma, formulas)
|
|
assert mdp.nr_states == 5
|
|
assert mdp.nr_transitions == 8
|
|
assert mdp.model_type == stormpy.ModelType.MDP
|
|
assert len(mdp.initial_states) == 1
|
|
initial_state = mdp.initial_states[0]
|
|
assert initial_state == 0
|
|
|
|
result = stormpy.model_checking(mdp, mdp_formulas[0], extract_scheduler=True)
|
|
assert math.isclose(result.at(initial_state), 0.08333333333)
|
|
assert result.has_scheduler
|
|
scheduler = result.scheduler
|
|
assert scheduler.memoryless
|
|
assert scheduler.memory_size == 1
|
|
assert scheduler.deterministic
|
|
for state in mdp.states:
|
|
choice = scheduler.get_choice(state)
|
|
assert choice.defined
|
|
assert choice.deterministic
|
|
action = choice.get_deterministic_choice()
|
|
if state.id == 0:
|
|
assert action == 1
|
|
else:
|
|
assert action == 0
|