def final_method(path_to_file: str, Word: str) -> str: Auto = automaton.Automaton("test") # create an empty automate Auto.from_txtfile(path_to_file) if not is_det(Auto): return "ERROR" else: if is_word_inside(Auto, Word): return "YES" else: return "NO"
def final_method(chemin_vers_le_fichier: str, Word: str) -> str: Auto = automaton.Automaton("test") # create an empty automate Auto.from_txtfile(chemin_vers_le_fichier) if not is_det(Auto): return "ERROR" else: if is_word_inside(Auto, Word): return "YES" else: return "NO"
def checkFromFile(fileName: str, word: str): automata = automaton.Automaton(fileName) automata.from_txtfile(fileName) if not isDeterministic(automata): makeDeterministic(automata) if isRecognizable(word, automata): print("YES") else: print("NO")
def eliminate_other_trans( automate: automaton.Automaton) -> automaton: # Methode incompléte automate = eliminate_e_trans(automate) new_state = [automate.initial.name] PartsOf(automate.states) resulting_automaton = automaton.Automaton("test4") for i in range(len(automate.alphabet)): try: etat_cible = Transition_Function(automate, automate.initial.name, automate.alphabet[i]) new_state.append(str(etat_cible)) resulting_automaton.add_transition(automate.initial.name, automate.alphabet[i], etat_cible) except KeyError: pass for i in range(len(automate.alphabet)): print(new_state[2][2]) print( Transition_Function(automate, new_state[1][0], automate.alphabet[i])) return resulting_automaton
def parseFile(filename): ''' Parse a json file to generate an automaton For syntax, see example.json ''' data = json.load(open(filename)) auto = am.Automaton() for name in data['nodes']: node = am.Node(auto, name) if 'eqs' in data['nodes'][name]: node.set_equation(parse_system(data['nodes'][name]['eqs'])) for link in data['links']: src = auto.nodes[link['src']] dst = auto.nodes[link['dst']] link = am.Link(auto, src, dst) auto.set_init_interval(parse_init_interval(data['init'])) auto.set_init_node(data['entry']) print(auto) return auto
def construct_nfa(self): nfa = automaton.Automaton() (start, final) = self.root.construct_nfa(nfa) nfa.set_start_state(start) nfa.set_final_states(set([final])) return nfa
listOfTransitions = [] for transition in automaton.transitions: if transition[1] == symbol: listOfTransitions.append(transition) return listOfTransitions def getStateTransitions(state: str, automaton: automaton.Automaton): listOfStateTransitions = [] for transition in automaton.transitions: if transition[0] == state: listOfStateTransitions.append(transition) if listOfStateTransitions == None: raise Exception("there are no transitions from this state") return listOfStateTransitions a = automaton.Automaton("a-epsilon") source = """0 % 1 1 a 1 0 % 2 2 b 2 A 1 2 """ a.from_txt(source) print(deleteEpsilons(a))
import cell import automaton import random test_type = 1 if (test_type == 0): automaton = automaton.Automaton() automaton.traffic_flow_setup(ring_size=40, car_num=21) STEP_SIZE = 100 print(automaton) for index in range(STEP_SIZE): automaton.step() print(automaton) elif (test_type == 1): STEP_SIZE = 10 automaton = automaton.AutomatonAlt() automaton.traffic_flow_setup(branch_index=2, connecting_index=5, ring_size=10, alt_size=2, car_num=7) printtype = 'all' print(automaton) print('\n\n') for index in range(STEP_SIZE): if (printtype == 'all'): print(automaton)
else: print 'Syntax error at', pos return else: pos += 1 print state spec = {} execfile(sys.argv[1], spec) macros = spec["MACROS"] rules = spec["RULES"] nfa = automaton.Automaton() start = 0 nfa.add_state(0) nfa.set_start_state(0) finals = set() for (n, (re, action)) in enumerate(rules): for macro in macros: re = re.replace("{" + macro + "}", macros[macro]) print(re, action) r = regexp.RegExp(re) (start, final) = r.add_to_nfa(nfa) nfa.add_edge(0, automaton.EPSILON_RANGE, start) nfa.label_state(final, n)
import automaton test1 = automaton.Automaton("test") test1.add_transition("1", "a", "1") test1.add_transition("1", "a", "2") test1.add_transition("1", "b", "3") test1.add_transition("2", "b", "3") test1.add_transition("2", "%", "3") test1.add_transition("2", "%", "4") test1.add_transition("2", "a", "4") test1.add_transition("4", "%", "5") test1.add_transition("4", "b", "5") test1.add_transition("3", "a", "5") test1.add_transition("5", "a", "5") test1.add_transition("5", "b", "2") test1.add_transition("4", "a", "6") test1.add_transition("5", "%", "6") test1.add_transition("5", "a", "6") test1.add_transition("6", "b", "6") test1.make_accept("6") test1.to_graphviz("test1.gv")
* YES if word is recognized * NO if word is rejected """ import automaton import sys import pdb # for debugging if len(sys.argv) != 3: usagestring = "Usage: {} <automaton-file.af> <word-to-recognize>" automaton.error(usagestring.format(sys.argv[0])) import automaton import sys test = automaton.Automaton("Test") # create a empty automate test.add_transition("0", "b", "1") test.add_transition("1", "b", "1") test.add_transition("1", "a", "2") test.add_transition("2", "b", "3") # test.add_transition("3", "%", "3") test.make_accept("2") test.to_graphviz("test.gv") def count_element(Word: str): # méthode qui compte le nombre d"état count = 1 for i in range(len(Word)): if Word[i] == ",": count += 1