def test_mecs(): import numpy as np E = [[0,1],[1,2],[2,0],[3,2],[3,1],[3,5],[4,2],[4,6],[5,4],[5,3],[6,4],[7,5],[7,6],[7,7]] P = np.zeros(shape=(8,8)) for u,v in E: # initialize with arbitrary probabilities ucount = len([w for w,z in E if w == u]) P[u,v] = 1/ucount dtmc = DTMC(P) components,mec_count = dtmc.maximal_end_components() assert (components == np.array([1., 1., 1., 0., 0., 0., 0., 0.])).all()
def test_read_write(): for dtmc in dtmcs: print(dtmc) with tempfile.NamedTemporaryFile() as namedtf: dtmc.save(namedtf.name) read_dtmc = DTMC.from_file( namedtf.name + ".lab", namedtf.name + ".tra")
def example_dtmcs(): dtmcs = [] dtmcs.append( DTMC.from_prism_model("./examples/datasets/crowds.pm", prism_constants={("CrowdSize", 2), ("TotalRuns", 8)}, extra_labels={("target", "observe0>1")})) dtmcs.append(toy_dtmc1()) dtmcs.append(toy_dtmc2()) dtmcs.append( DTMC.from_prism_model("./examples/datasets/leader_sync3_2.pm", extra_labels={("target", "s1=3 & s2=3 & s3=3")})) dtmcs.append( DTMC.from_prism_model("./examples/datasets/brp.pm", prism_constants={("N", 2), ("MAX", 1)}, extra_labels={("target", "s=5 & srep=2"), ("all", "true")})) return dtmcs
def toy_dtmc1(): P = [[0.3, 0.7, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5], [0.0, 0.1, 0.0, 0.7, 0.0, 0.2, 0.0], [0.0, 0.2, 0.0, 0.4, 0.4, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.1, 0.9, 0.0, 0.0, 0.0]] labels = {"target": {3, 4, 6}, "init": {0}} return (DTMC(P, label_to_states=labels))
def construct_conflicts(self, family, assignment, dtmc, conflict_requests, ce_generator): conflicts = [] for request in conflict_requests: index,prop,member_result,family_result = request if prop.minimizing: # safety threshold = prop.threshold target_label = str(prop.property.raw_formula.subformula.subformula) else: # liveness: flip threshold threshold = 1 - prop.threshold target_label = "target" # construct a labeled SWITSS DTMC switss_dtmc = SWITSS_DTMC.from_stormpy(dtmc.model) for i,state in enumerate(dtmc.model.states): # copy labels for label in state.labels: switss_dtmc.add_label(i, label) # label fail states if not prop.minimizing and not member_result.result.at(i) > 0.0: switss_dtmc.add_label(i, "target") # label states by relevant holes id for dtmc_state in range(dtmc.states): mdp_state = dtmc.quotient_state_map[dtmc_state] for hole in dtmc.quotient_container.coloring.state_to_holes[mdp_state]: switss_dtmc.add_label(dtmc_state, str(hole)) switss_dtmc_rf,_,_ = ReachabilityForm.reduce(switss_dtmc, "init", target_label) results = list(ce_generator.solveiter(switss_dtmc_rf, threshold, "max")) # get last result witnessing_subsystem = results[-1].subsystem.subsys.system conflict = set([int(label) for label in witnessing_subsystem.states_by_label.keys() if label.isnumeric()]) conflict = list(conflict) scheduler_selection = None if family_result is not None: scheduler_selection = family_result.primary_selection conflict = self.generalize_conflict(assignment, conflict, scheduler_selection) conflicts.append(conflict) return conflicts
def toy_dtmc2(): P = [[0.3, 0.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.1, 0.0, 0.7, 0.0, 0.1, 0.0, 0.0, 0.1, 0.0], [0.0, 0.1, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.8, 0.0], [0.0, 0.2, 0.0, 0.4, 0.2, 0.0, 0.1, 0.1, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.7, 0.0, 0.0, 0.1, 0.2, 0.0], [0.0, 0.0, 0.0, 0.1, 0.0, 0.8, 0.0, 0.0, 0.1, 0.0], [0.0, 0.0, 0.7, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.3, 0.0, 0.0, 0.6, 0.0, 0.1], [0.0, 0.0, 0.0, 0.0, 0.0, 0.9, 0.0, 0.0, 0.1, 0.0], [0.0, 0.0, 0.1, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] labels = { "target": {8}, "init": {0}, "group1": {1, 3, 6}, "group2": {7, 9, 2}, "group3": {4, 5} } return (DTMC(P, label_to_states=labels))