@@ -12,7 +12,7 @@ def __init__(self, data, automaton_type, print_info=True):
1212
1313 pta_construction_start = time .time ()
1414 self .root_node = createPTA (data , automaton_type )
15- self .test_data = extract_unique_sequences (self .root_node )
15+ self .test_data = extract_unique_sequences (self .root_node , automaton_type )
1616
1717 if self .print_info :
1818 print (f'PTA Construction Time: { round (time .time () - pta_construction_start , 2 )} ' )
@@ -27,7 +27,7 @@ def run_rpni(self):
2727 merged = False
2828
2929 for red_state in red :
30- if not self . _compatible_states ( red_state , lex_min_blue ):
30+ if not red_state . compatible_outputs ( lex_min_blue ):
3131 continue
3232 merge_candidate = self ._merge (red_state , lex_min_blue , copy_nodes = True )
3333 if self ._compatible (merge_candidate ):
@@ -62,21 +62,6 @@ def _compatible(self, root_node):
6262 return False
6363 return True
6464
65- def _compatible_states (self , red_node , blue_node ):
66- """
67- Only allow merging of states that have same output(s).
68- """
69- if self .automaton_type != 'mealy' :
70- # None is compatible with everything
71- return red_node .output == blue_node .output or red_node .output is None or blue_node .output is None
72- else :
73- red_io = {i : o for i , o in red_node .children .keys ()}
74- blue_io = {i : o for i , o in blue_node .children .keys ()}
75- for common_i in set (red_io .keys ()).intersection (blue_io .keys ()):
76- if red_io [common_i ] != blue_io [common_i ]:
77- return False
78- return True
79-
8065 def _merge (self , red_node , lex_min_blue , copy_nodes = False ):
8166 """
8267 Merge two states and return the root node of resulting model.
@@ -112,18 +97,12 @@ def _fold(self, red_node, blue_node):
11297 red_node .children [i ] = blue_node .children [i ]
11398
11499 def _fold_mealy (self , red_node , blue_node ):
115- blue_io_map = {i : o for i , o in blue_node .children .keys ()}
100+ for i , o in blue_node .output .items ():
101+ red_node .output [i ] = o
116102
117- updated_keys = {}
118- for io , val in red_node .children .items ():
119- o = blue_io_map [io [0 ]] if io [0 ] in blue_io_map .keys () else io [1 ]
120- updated_keys [(io [0 ], o )] = val
121-
122- red_node .children = updated_keys
123-
124- for io in blue_node .children .keys ():
125- if io in red_node .children .keys ():
126- self ._fold_mealy (red_node .children [io ], blue_node .children [io ])
103+ for i in blue_node .children .keys ():
104+ if i in red_node .children .keys ():
105+ self ._fold_mealy (red_node .children [i ], blue_node .children [i ])
127106 else :
128- red_node .children [io ] = blue_node .children [io ]
107+ red_node .children [i ] = blue_node .children [i ]
129108
0 commit comments