def setUp(self): self.maxDiff = None self.nfa_intersection_1_test_01 = \ automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_intersection_1_test_01.dot') self.nfa_intersection_2_test_01 = \ automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_intersection_2_test_01.dot') self.nfa_intersection_test_01_solution = { 'alphabet': {'a', 'b'}, 'states': {('s3', 't1'), ('s0', 't4'), ('s1', 't4'), ('s4', 't0'), ('s0', 't1'), ('s2', 't1'), ('s3', 't4'), ('s1', 't2'), ('s2', 't4'), ('s0', 't0'), ('s2', 't2'), ('s4', 't4'), ('s3', 't0'), ('s4', 't1'), ('s4', 't2'), ('s2', 't0')}, 'initial_states': {('s0', 't0')}, 'accepting_states': {('s2', 't0'), ('s2', 't4')}, 'transitions': { (('s0', 't0'), 'b'): {('s3', 't1')}, (('s0', 't0'), 'a'): {('s1', 't2')}, (('s3', 't1'), 'b'): {('s4', 't4')}, (('s1', 't2'), 'b'): {('s2', 't1')}, (('s1', 't2'), 'a'): {('s4', 't2'), ('s4', 't4')}, (('s4', 't4'), 'b'): {('s0', 't0')}, (('s4', 't4'), 'a'): {('s4', 't4')}, (('s2', 't1'), 'b'): {('s0', 't4'), ('s2', 't4')}, (('s2', 't4'), 'b'): {('s0', 't0'), ('s2', 't0')}, (('s4', 't2'), 'b'): {('s0', 't1')}, (('s4', 't2'), 'a'): {('s4', 't2'), ('s4', 't4')}, (('s2', 't0'), 'b'): {('s0', 't1'), ('s2', 't1')}, (('s0', 't4'), 'b'): {('s3', 't0')}, (('s0', 't4'), 'a'): {('s1', 't4')}, (('s1', 't4'), 'b'): {('s2', 't0')}, (('s1', 't4'), 'a'): {('s4', 't4')}, (('s0', 't1'), 'b'): {('s3', 't4')}, (('s3', 't0'), 'b'): {('s4', 't1')}, (('s3', 't0'), 'a'): {('s2', 't2')}, (('s4', 't1'), 'b'): {('s0', 't4')}, (('s2', 't2'), 'b'): {('s0', 't1'), ('s2', 't1')}, (('s3', 't4'), 'b'): {('s4', 't0')}, (('s3', 't4'), 'a'): {('s2', 't4')}, (('s4', 't0'), 'b'): {('s0', 't1')}, (('s4', 't0'), 'a'): {('s4', 't2')} } } self.nfa_intersection_test_02_empty = { 'alphabet': set(), 'states': set(), 'initial_states': set(), 'accepting_states': set(), 'transitions': {} }
def setUp(self): self.maxDiff = None self.nfa_interestingness_test_01 = \ automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_interestingness_test_01.dot') self.nfa_interestingness_test_02 = \ automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_interestingness_test_02.dot') self.nfa_interestingness_test_empty = { 'alphabet': set(), 'states': set(), 'initial_states': set(), 'accepting_states': set(), 'transitions': {} }
def test_nfa_dot_importer_from_simple_pydot_render(self): """ Tests if a dfa imported from dot file generated by nfa_pydot_render() is correct """ nfa_01 = automata_IO.nfa_dot_importer( './tests/dot/automata_io' '/automata_io_nfa_importer_pydot_nfa_simple.dot') self.assertDictEqual(nfa_01, self.nfa_test_01)
def test_nfa_dot_importer_intersection(self): """ Tests importing a nfa from a dot file derived from an intersection """ nfa_02 = automata_IO.nfa_dot_importer( './tests/dot/automata_io' '/automata_io_nfa_imported_intersection.dot') self.assertDictEqual(nfa_02, self.nfa_test_02)
def mostrar(self): f = open("Token" + str(self.N) + ".dot", "w") f.write( "digraph{\nfake [style=invisible]\nfake -> s0 [style=bold]\n\n") print("Alfabeto que acepta el automata") print(self.Sigma) print("Estado de inicio del automata") print(self.S.__str__()) print("Conjunto de Estados(Objeto) no vacios") for e in self.K: print(e.__str__()) f.write(e.__str__()) f.write("\n") f.write("\n") print("Conjunto de Estados(Objeto) de aceptacion") print(self.Z.__str__()) print("Conjunto de Transiciones(Objeto)") for e in self.M: print(e.__str__()) f.write(e.__str__() + "\n") f.write("\n}") f.close() afn = automata_IO.nfa_dot_importer("Token" + str(self.N) + ".dot") automata_IO.nfa_to_dot(afn, "Token" + str(self.N), ".")
def read_determinize_minimized_write(path, model): nfa = automata_IO.nfa_dot_importer(path + model) dfa = NFA.nfa_determinization(nfa) automata_IO.dfa_to_dot(dfa, model + '_det', path) new_dfa = DFA.dfa_minimization(dfa) automata_IO.dfa_to_dot(new_dfa, model + "_det_min", path)
def setUp(self): self.maxDiff = None self.nfa_nfa_to_afw_test_01 = automata_IO.nfa_dot_importer( './tests/dot/afw/nfa_nfa_to_afw_test_01.dot') self.afw_nfa_to_afw_test_01 = automata_IO.afw_json_importer( './tests/json/afw/afw_nfa_to_afw_test_01.json') self.nfa_nfa_to_afw_test_empty = { 'alphabet': set(), 'states': set(), 'initial_states': set(), 'accepting_states': set(), 'transitions': {} } self.afw_nfa_to_afw_test_empty = { 'alphabet': set(), 'states': set(), 'initial_state': None, 'accepting_states': set(), 'transitions': {} }
def test_nfa_dot_importer(self): """ Tests importing a nfa from a simple .dot file """ nfa_01 = automata_IO.nfa_dot_importer( './tests/dot/automata_io' '/automata_io_nfa_dot_importer_test_01.dot') self.assertDictEqual(nfa_01, self.nfa_test_01)
def setUp(self): self.maxDiff = None self.nfa_1 = automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_renaming_test_01.dot')
def setUp(self): self.maxDiff = None self.nfa_union_1_test_01 = automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_union_1_test_01.dot') self.nfa_union_2_test_01 = automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_union_2_test_01.dot') self.nfa_union_3_test_01 = automata_IO.nfa_dot_importer( './tests/dot/nfa/nfa_union_3_test_01.dot') self.nfa_union_test_01_solution = { 'alphabet': {'a', 'b', 'c'}, 'states': {'s0', 's1', 's2', 's3', 's4', 't0', 't1', 't2', 't3', 't4'}, 'initial_states': {'s0', 't0'}, 'accepting_states': {'s2', 't0', 't4'}, 'transitions': { ('s3', 'b'): {'s4'}, ('s0', 'a'): {'s1'}, ('s4', 'a'): {'s4'}, ('s2', 'b'): {'s0', 's2'}, ('s3', 'a'): {'s2'}, ('s1', 'b'): {'s2'}, ('s4', 'b'): {'s0'}, ('s0', 'b'): {'s3'}, ('s1', 'a'): {'s4'}, ('t3', 'c'): {'t0'}, ('t1', 'c'): {'t2', 't3'}, ('t4', 'c'): {'t0'}, ('t0', 'a'): {'t2'}, ('t4', 'b'): {'t0'}, ('t0', 'b'): {'t1'}, ('t3', 'a'): {'t1', 't4'}, ('t4', 'a'): {'t4'}, ('t2', 'a'): {'t4', 't2'}, ('t3', 'b'): {'t0', 't3'}, ('t1', 'b'): {'t4'}, ('t2', 'b'): {'t1'} } } self.nfa_union_test_02_solution = { 'alphabet': {'a', 'b', 'c'}, 'states': {'t0', 't1', 't2', 't3', 't4', 'c0', 'c4', 'c1', 'c2', 'c3'}, 'initial_states': {'t0', 'c0'}, 'accepting_states': {'t0', 't4', 'c4'}, 'transitions': { ('t0', 'a'): {'t2'}, ('t0', 'b'): {'t1'}, ('t1', 'b'): {'t4'}, ('t1', 'c'): {'t2', 't3'}, ('t2', 'a'): {'t4', 't2'}, ('t2', 'b'): {'t1', 'c2'}, ('t3', 'a'): {'t1', 't4'}, ('t3', 'b'): {'t0', 't3'}, ('t3', 'c'): {'t0', 'c4'}, ('t4', 'a'): {'t4'}, ('t4', 'b'): {'t0'}, ('t4', 'c'): {'t0'}, ('c0', 'a'): {'t1', 't2'}, ('c0', 'b'): {'c1'}, ('c1', 'c'): {'c3'}, ('c2', 'c'): {'c3'}, ('c3', 'a'): {'c4'}, ('c3', 'b'): {'c4'} } } self.nfa_union_test_03_empty = { 'alphabet': set(), 'states': set(), 'initial_states': set(), 'accepting_states': set(), 'transitions': {} }
from PySimpleAutomata import NFA, automata_IO nfa_example = automata_IO.nfa_dot_importer('Input.dot') automata_IO.nfa_to_dot(nfa_example, 'Input', '.') import webbrowser import os new = 2 url = 'file://' + os.path.realpath("input.dot.svg") webbrowser.open(url, new=new)
# # nfa1 = automata_IO.nfa_dot_importer(path + "csv_10__model.dot") # nfa2 = automata_IO.nfa_dot_importer(path + "csv_past_10__model.dot") # dfa1 = NFA.nfa_determinization(nfa1) # dfa1 = DFA.dfa_minimization(dfa1) # dfa2 = NFA.nfa_determinization(nfa2) # dfa2 = DFA.dfa_minimization(dfa2) # dfa1 = DFA.dfa_co_reachable(dfa1) # dfa2 = DFA.dfa_co_reachable(dfa2) # automata_IO.dfa_to_dot(dfa1, 'csv_10__model' + "_det_min", path) # automata_IO.dfa_to_dot(dfa2, 'csv_10__model_past' + "_det_min", path) # print('relation:', check_relation(nfa1, nfa2)) nfa1 = automata_IO.nfa_dot_importer(path + "csv_7__model.dot") nfa2 = automata_IO.nfa_dot_importer(path + "csv_past_7__model.dot") nfa3 = automata_IO.nfa_dot_importer(path + "cvs.net.dot") print('relation:', check_relation(nfa1, nfa2)) print('relation:', check_relation(nfa1, nfa3)) print('relation:', check_relation(nfa2, nfa3)) # nfa1 = automata_IO.nfa_dot_importer(path + "csv_10__model.dot") # nfa2 = automata_IO.nfa_dot_importer(path + "csv_past_10__model.dot") # print('relation:', check_relation(nfa1, nfa2)) # check_equivelence(path + "csv_2__model.dot", path + "csv_past_2__model.dot") # check_equivelence(path + "csv_3__model.dot", path + "csv_past_3__model.dot")