Exemple #1
0
def get_distinguishing_set(fsm: Union[MealyMachine, DFA], method="Hopcroft"):
    if isinstance(fsm, MealyMachine):
        alphabet = list(sorted(fsm.get_alphabet()))
        tmp = set(_do_partition(fsm, alphabet, method))
        tmp.remove(tuple())  # Meaningless in the case of a Mealy machine
    elif isinstance(fsm, DFA):
        # In the case of a DFA, we need to consider the empty string as part of the alphabet as well
        alphabet = list(sorted(fsm.get_alphabet()))
        alphabet = ['λ'] + alphabet
        tmp = set(_do_partition(fsm, alphabet, method))
        if ('λ', ) in tmp:
            tmp.remove(('λ', ))
        else:
            tmp.remove(tuple())
    else:
        raise NotImplementedError

    if len(tmp) < 1:
        tmp.add(tuple())

    check_ok = check_distinguishing_set(fsm, tmp)
    assert check_ok, "If this goes wrong your fsm is probably not minimal, e.g. two or more states show the same behavior"

    return tmp
Exemple #2
0
 def test_simple_moore(self):
     dset = get_distinguishing_set(self.dfa, method="Moore")
     self.assertTrue(check_distinguishing_set(self.dfa, dset))
     self.assertEqual({tuple(), ('b', )}, dset)
Exemple #3
0
 def test_simple_hopcroft(self):
     dset = get_distinguishing_set(self.dfa, method="Hopcroft")
     self.assertTrue(check_distinguishing_set(self.dfa, dset))
     self.assertEqual({('a', ), tuple()}, dset)
Exemple #4
0
 def test_m182_moore(self):
     dset = get_distinguishing_set(self.m182, method="Moore")
     self.assertTrue(check_distinguishing_set(self.m182, dset))
Exemple #5
0
 def test_m182_hopcroft(self):
     dset = get_distinguishing_set(self.m182, method="Hopcroft")
     self.assertTrue(check_distinguishing_set(self.m182, dset))
Exemple #6
0
 def test_at_least_one_moore(self):
     dset = get_distinguishing_set(self.dfa, method="Moore")
     self.assertTrue(check_distinguishing_set(self.dfa, dset))
     self.assertEqual({tuple()}, dset)