Skip to content

Making accept method faster #115

Open
@ivanDonadello

Description

@ivanDonadello

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions