def restrict(self, edge_indices, edge_0_indices): logger.debug("select mask for submodel construction...") all_states = stormpy.BitVector(self._model.nr_states, True) if self._color_0_actions is None: self._color_0_actions = stormpy.BitVector(self._model.nr_choices, False) for act_index in range(0, self._model.nr_choices): if self._model.choice_origins.get_edge_index_set(act_index).is_subset_of(edge_0_indices): assert self._model.choice_origins.get_edge_index_set(act_index).is_subset_of(edge_indices) self._color_0_actions.set(act_index) selected_actions = stormpy.BitVector(self._color_0_actions) for act_index in range(0, self._model.nr_choices): if selected_actions.get(act_index): continue #TODO many actions are always taken. We should preprocess these. if self._model.choice_origins.get_edge_index_set(act_index).is_subset_of(edge_indices): selected_actions.set(act_index) keep_unreachable_states = False logger.debug("Construct submodel...") subsystem_options = stormpy.SubsystemBuilderOptions() subsystem_options.build_action_mapping = True submodel_construction = stormpy.construct_submodel(self._model, all_states, selected_actions, keep_unreachable_states, subsystem_options) assert (not keep_unreachable_states) or submodel_construction.kept_actions == selected_actions, "kept: {} vs selected: {}".format(submodel_construction.kept_actions, selected_actions) self._submodel = submodel_construction.model self._mapping_to_original = submodel_construction.new_to_old_action_mapping assert len(self._mapping_to_original) == self._submodel.nr_choices, "mapping contains {} actions, but model has {} actions".format(len(self._mapping_to_original), self._submodel.nr_choices) assert self._submodel.has_choice_origins() return self._submodel
def _apply_scheduler(mdp, scheduler, drop_unreachable_states): action_selection = scheduler.compute_action_support( mdp.nondeterministic_choice_indices) all_states = stormpy.BitVector(mdp.nr_states, True) subsystem_construction_options = stormpy.SubsystemBuilderOptions() subsystem_construction_options.build_action_mapping = True result = stormpy.construct_submodel(mdp, all_states, action_selection, not drop_unreachable_states, subsystem_construction_options) return result.model, result.new_to_old_state_mapping, result.new_to_old_action_mapping
def __init__(self, sketch): # model origin self.sketch = sketch # qoutient MDP for the super-family self.quotient_mdp = None # coloring of the quotient self.coloring = None # builder options self.subsystem_builder_options = stormpy.SubsystemBuilderOptions() self.subsystem_builder_options.build_state_mapping = True self.subsystem_builder_options.build_action_mapping = True # (optional) counter of discarded assignments self.discarded = None
def test_for_ctmc(self): program = stormpy.parse_prism_program( get_example_path("ctmc", "polling2.sm"), True) formulas = stormpy.parse_properties_for_prism_program( "P=? [ F<=3 \"target\" ]", program) model = stormpy.build_model(program, formulas) assert model.nr_states == 12 selected_outgoing_transitions = stormpy.BitVector( model.nr_states, True) selected_outgoing_transitions.set(3, False) selected_outgoing_transitions.set(6, False) options = stormpy.SubsystemBuilderOptions() options.fix_deadlocks = True submodel_result = stormpy.construct_submodel( model, stormpy.BitVector(model.nr_states, True), selected_outgoing_transitions, False, options) submodel = submodel_result.model abort_label = submodel_result.deadlock_label assert submodel.nr_states == 8 assert abort_label == "deadl" assert "deadl" in submodel.labeling.get_labels()