# Variável auxiliar para contar o número de grafos impressos graph_counter = 0 # ----- PASSO I: Inicialização do autômato ----- # Inicializa os estados S0 e S1 (sendo S1 um estado final) S0 = State('S0') S1 = State('S1', final=True) # Adiciona os estados à e-NFA Machine.set_initial_state(S0) Machine.add_state(S1) # Adiciona a transição S0 -> S1 à e-NFA utilizando a regEx de entrada Machine.add_transition(S0, S1, regEx) # Imprime o resultado do passo I filename = 'grafos/Q1_grafo_passo_' + str(graph_counter) + '.dot' Machine.print_graph(filename, view=False) #imagename = filename + '.png' #display(Image(filename=#imagename)) # Incrementa o contador de grafos graph_counter = graph_counter + 1 # Enquanto o autômato não estiver pronto (somente arcos de um símbolo), contrói o autômato automata_ready = False while (not automata_ready): # ----- PASSO II: Verifica se alguma transição é união de linguagens -----
Machine = Automata() for node in graph.get_nodes(): node_name = node.get_name() if node_name != 'node': if node_name == 'S1': final = True else: final = False state = State(node_name, final=final) if node_name == 'S0': Machine.set_initial_state(state) else: Machine.add_state(state) for edge in graph.get_edges(): from_state = Machine.states[edge.get_source()] to_state = Machine.states[edge.get_destination()] label = edge.to_string() print(label) label = label.split('=') label = label[1] label = label[:-2] label = label.replace('"', '') Machine.add_transition(from_state, to_state, label) Machine.print_source()
S3 = State('3') S4 = State('4') S5 = State('5') S6 = State('6') # Adiciona os estados à e-NFA teste_1.set_initial_state(S0) teste_1.add_state(S1) teste_1.add_state(S2) teste_1.add_state(S3) teste_1.add_state(S4) teste_1.add_state(S5) teste_1.add_state(S6) # Adiciona as transições da e-NFA teste_1.add_transition(S0, S3, '&') teste_1.add_transition(S3, S3, 'a,b') teste_1.add_transition(S3, S2, '&') teste_1.add_transition(S2, S4, 'b') teste_1.add_transition(S4, S5, 'b') teste_1.add_transition(S5, S6, '&') teste_1.add_transition(S6, S6, 'b,a') teste_1.add_transition(S6, S1, '&') # Imprime o resultado do passo I filename = 'grafos/Q1_grafo_1.dot' teste_1.print_graph(filename, view=False) imagename = filename + '.png' display(Image(filename=imagename)) #Vetores pra armazenar os epsilon fechos de cada estado. Vetor e[i] armazena o epsilon fecho do estado com label = 'i'