@@ -139,6 +139,13 @@ def remove_start_state(self, state: Hashable) -> int:
139
139
return 1
140
140
return 0
141
141
142
+ def get_next_state (self , s_from : Hashable , symb_by : Hashable ) \
143
+ -> Optional [State ]:
144
+ """ Make a call of deterministic transition function """
145
+ s_from = to_state (s_from )
146
+ symb_by = to_symbol (symb_by )
147
+ return self ._transition_function .get_next_state (s_from , symb_by )
148
+
142
149
def accepts (self , word : Iterable [Hashable ]) -> bool :
143
150
""" Checks whether the dfa accepts a given word
144
151
@@ -168,8 +175,7 @@ def accepts(self, word: Iterable[Hashable]) -> bool:
168
175
for symbol in word :
169
176
if current_state is None :
170
177
return False
171
- current_state = self ._transition_function .get_next_state (
172
- current_state , symbol )
178
+ current_state = self .get_next_state (current_state , symbol )
173
179
return current_state is not None and self .is_final_state (current_state )
174
180
175
181
def is_deterministic (self ) -> bool :
@@ -213,19 +219,12 @@ def copy(self) -> "DeterministicFiniteAutomaton":
213
219
"""
214
220
return self ._copy_to (DeterministicFiniteAutomaton ())
215
221
216
- def get_next_state (self , s_from : Hashable , symb_by : Hashable ) \
217
- -> Optional [State ]:
218
- """ Make a call of deterministic transition function """
219
- s_from = to_state (s_from )
220
- symb_by = to_symbol (symb_by )
221
- return self ._transition_function .get_next_state (s_from , symb_by )
222
-
223
222
def _get_previous_transitions (self ) -> PreviousTransitions :
224
223
previous_transitions = PreviousTransitions (self ._states ,
225
224
self ._input_symbols )
226
225
for state in self ._states :
227
226
for symbol in self ._input_symbols :
228
- next0 = self ._transition_function . get_next_state (state , symbol )
227
+ next0 = self .get_next_state (state , symbol )
229
228
previous_transitions .add (next0 , symbol , state )
230
229
return previous_transitions
231
230
@@ -276,8 +275,7 @@ def minimize(self) -> "DeterministicFiniteAutomaton":
276
275
done = set ()
277
276
new_state = to_new_states [state ]
278
277
for symbol in self ._input_symbols :
279
- next_node = self ._transition_function .get_next_state (
280
- state , symbol )
278
+ next_node = self .get_next_state (state , symbol )
281
279
if next_node and next_node in states :
282
280
next_node = to_new_states [next_node ]
283
281
if (next_node , symbol ) not in done :
@@ -431,10 +429,8 @@ def _is_equivalent_to_minimal(
431
429
matches = {self_minimal .start_state : other_minimal .start_state }
432
430
while to_process :
433
431
current_self , current_other = to_process .pop ()
434
- if (self_minimal .is_final_state (current_self )
435
- and not other_minimal .is_final_state (current_other )) or \
436
- (not self_minimal .is_final_state (current_self )
437
- and other_minimal .is_final_state (current_other )):
432
+ if self_minimal .is_final_state (current_self ) != \
433
+ other_minimal .is_final_state (current_other ):
438
434
return False
439
435
next_self = list (self_minimal .get_transitions_from (current_self ))
440
436
next_other = list (other_minimal .get_transitions_from (current_other ))
0 commit comments