def validar(sets, tipo): if tipo == False: aux = list(sets[2].values()) for i in range(len(sets[0])): if '' in aux[i].values() or not sets[4]: return False automata = DFA(states=sets[0], input_symbols=sets[1], transitions=sets[2], initial_state=sets[3], final_states=sets[4]) else: if sets[4]: automata = NFA(states=sets[0], input_symbols=sets[1], transitions=sets[2], initial_state=sets[3], final_states=sets[4]) else: return False if automata.validate(): del automata return True else: del automata return False
from automata.fa.dfa import DFA # DFA which matches all binary strings ending in an odd number of '1's dfa = DFA( states={'q1', 'q2', 'q4', 'q5', 'q6'}, input_symbols={'0', '1'}, transitions={ 'q1': {'0': 'q0', '1': 'q1'} }, initial_state='q0', final_states={'q0'} ) #print(dfa.read_input('01')) dfa.validate()
if (start in Q) and (set(accept).issubset(Q)): initial = start final = accept break else: print( "Please enter STATE_STATE and ACCEPT_STATES that are in Q : {}.\nAccept states should be a valid subset of Q\n" .format(Q)) CURRENT_STATE = None dfa = DFA(states=Q, input_symbols=SIGMA, transitions=transition_dict, initial_state=initial, final_states=set(final)) if dfa.validate(): print("\nThe DFA is accepted.") s = input("Enter the Input String: ") if dfa.accepts_input(s): print('Accepted!') print("The final state that the DFA stopped on:", dfa.read_input(s)) else: print('Rejected!') else: print("\nThe DFA is rejected.") """ Non-Deterministic Finite Automata (NFA) """ nfa = NFA( states={'q0', 'q1', 'q2'}, input_symbols={'a', 'b'}, transitions={