Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making accept method faster #115

Open
ivanDonadello opened this issue Sep 15, 2023 · 0 comments
Open

Making accept method faster #115

ivanDonadello opened this issue Sep 15, 2023 · 0 comments

Comments

@ivanDonadello
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant