コード例 #1
0
ファイル: testIO.py プロジェクト: TCatshoek/STMLearn
    def test_read_write_dset_go(self):

        # Load a test mealy machine
        mm_og = load_mealy_dot("../partition/rers_industrial_tests/m182.dot")
        print("Original:", len(mm_og.get_states()), "States")

        # Write it to disk
        path = tempfile.mktemp(".dot")
        _render(mm_og, path)

        # And load it again
        mm_loaded = load_mealy_dot(path, parse_rules=go_mealy_parser)

        # Do we have the same amount of states?
        self.assertEqual(
            len(mm_og.get_states()),
            len(mm_loaded.get_states()),
        msg="Amount of states not equal")

        # Do a W-method equivalence check to ensure the state machines are equal
        eqc = WmethodEquivalenceChecker(mm_og, m=len(mm_og.get_states()))
        equivalent, _ = eqc.test_equivalence(mm_loaded)

        self.assertTrue(
            equivalent,
            msg="Loaded state machine is not equal to the original!"
        )
コード例 #2
0
    def setUp(self):
        # Load testcases
        self.m54 = load_mealy_dot("testcases/m54.dot")
        self.m164 = load_mealy_dot("testcases/m164.dot")
        self.m22 = load_mealy_dot("testcases/m22.dot")
        self.m182 = load_mealy_dot("testcases/m182.dot")

        self.systems = {
            'm54': self.m54,
            'm164': self.m164,
            # 'm22':  self.m22,      # too slow
            # 'm182': self.m182      # too slow
        }
コード例 #3
0
    def test_wmethod_different_problematic(self):
        name = "testcases/m164.dot"
        system = self.systems[name]

        # Change one output
        system2 = load_mealy_dot(name)
        modified_state = [
            state for state in system2.get_states() if state.name == '3'
        ][0]

        # Choose random input
        random_inp = 'usr2_ai3_re5'
        og_next_state, og_out = modified_state.edges[random_inp]
        modified_state.edges[random_inp] = (og_next_state,
                                            'FKSLDJFKSLDJFLSKDJ')
        print(
            f"Modified state {modified_state.name}, action {random_inp} -> ({og_next_state.name}, {og_out})"
        )
        n_states = len(system.get_states())

        eqc = WmethodEquivalenceChecker(system, m=n_states)

        equivalent, _ = eqc.test_equivalence(system2)

        self.assertFalse(equivalent, msg=f'Failure in {name}')
コード例 #4
0
 def setUp(self):
     # Load testcases
     testcases = [
         "testcases/m54.dot",
         "testcases/m164.dot",
         "testcases/m22.dot",
         #"testcases/m182.dot" # slow
     ]
     self.systems = {name: load_mealy_dot(name) for name in testcases}
コード例 #5
0
 def setUp(self):
     # Load testcases
     testcases = [
         "testcases/m54.dot", "testcases/m164.dot", "testcases/m22.dot",
         "testcases/m182.dot"
     ]
     self.systems: Dict[str, MealyMachine] = {
         name: load_mealy_dot(name)
         for name in testcases
     }
コード例 #6
0
    def test_smart_wmethod_random_changes(self):
        for i in range(10):  # try a bunch of random changes
            for name, system in self.systems.items():
                # Change one output
                system2 = load_mealy_dot(name)
                modified_state = random.choice(system2.get_states())
                # Choose random input
                random_inp = random.choice(list(system.get_alphabet()))
                og_next_state, og_out = modified_state.edges[random_inp]
                modified_state.edges[random_inp] = (og_next_state,
                                                    'FKSLDJFKSLDJFLSKDJ')
                print(
                    f"Modified state {modified_state.name}, action {random_inp} -> ({og_next_state.name}, {og_out})"
                )
                n_states = len(system.get_states())
                eqc = SmartWmethodEquivalenceChecker(system, m=n_states)
                equivalent, _ = eqc.test_equivalence(system2)

                self.assertFalse(equivalent, msg=f'Failure in {name}')
コード例 #7
0
            mm.reset()
        outputs[state] = tuple(out.copy())
    return outputs


# Uses partition refinement to find a distinguishing set for a given mealy machine
def get_distinguishing_set(fsm: MealyMachine, check=True):
    ptree = PartitionTree(fsm)
    ptree.build()

    dset = ptree.solution

    if check:
        assert check_distinguishing_set(fsm, dset)

    return ptree.solution


import pickle
import time
if __name__ == '__main__':
    path = "/home/tom/projects/lstar/rers/industrial/m34.dot"

    fsm = load_mealy_dot(path)

    t0 = time.time()
    dset = get_distinguishing_set(fsm)
    t1 = time.time()

    print(t1 - t0)
コード例 #8
0
ファイル: partition.py プロジェクト: TCatshoek/STMLearn
 def setUp(self):
     # Load testcases
     self.m54 = load_mealy_dot("testcases/m54.dot")
     self.m164 = load_mealy_dot("testcases/m164.dot")
     self.m22 = load_mealy_dot("testcases/m22.dot")
     self.m182 = load_mealy_dot("testcases/m182.dot")