Open
Description
The accept method for accepting a string could be made faster by stopping the iteration over the string symbols when the DFA is in a sink state. Here is my custom solution that should work:
...
current_states = reduce(set.union, map(lambda x: dfa.get_successors(x, temp), current_states),set(),)
sink_state = all(is_sink(dfa, state) for state in current_states)
if sink_state:
break
is_accepted = any(dfa.is_accepting(state) for state in current_states)
where
def is_sink(dfa: SymbolicDFA, current_state: int):
sink = True
for output_state in dfa._transition_function[current_state].keys():
if output_state != current_state:
sink = False
return sink
Hope it will be useful. My 2 cents.
Ivan
Metadata
Metadata
Assignees
Labels
No labels