-
Notifications
You must be signed in to change notification settings - Fork 0
/
poset_fsm.py
58 lines (53 loc) · 1.21 KB
/
poset_fsm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import fsm, angluin
from itertools import permutations
class PosetTeacher:
def __init__(self,lins):
self.syms = set(lins[0])
self.lins = list(map(tuple, lins))
self.ls = list(lins)
self.ls.append(lins[0]*2)
self.M = fsm.DFA({},'',set())
def get_alphabet(self):
syms = self.syms
lins = self.lins
ls = self.ls
return syms
def member(self, w):
syms = self.syms
lins = self.lins
ls = self.ls
return 'T' if w in lins else 'F'
def equiv(self, H):
syms = self.syms
lins = self.lins
ls = self.ls
if ls:
l = ls.pop()
self.counter = tuple(l)
return False
print(fsm.rename(H))
fsm.render(fsm.rename(H), name='poset_fsm')
return True
'''
d = input('is it good? (y/n) ')
if d == 'y':
return True
else:
self.counter = tuple(d)
return False
self.counter = tuple(c)
'''
def learn(lins):
l = angluin.Learner(PosetTeacher(lins))
l.go(debug=True)
# example
lins = [
'abcdef',
'acbdfe',
'acbfde',
'adcbef',
'acdbfe',
'acdfbe',
'bacdef'
]
learn(lins)