示例#1
0
def main():
    args, initial_condition = parse_args()
    # Always multiply the number of evolutions by 2 to get the length of each row.
    # This produces cleaner images.
    automata = Automata(initial_condition(args.evolutions * 2),
                        apply_elementary_rule(args.rule_number))
    automata.evolve(len(automata.state))
示例#2
0
文件: regex.py 项目: nathayush/CS-305
def dotMachine(a, b):
    a, n1 = a.rebuild(1)
    b, n2 = b.rebuild(n1)
    state1 = 1
    state2 = n2 - 1
    auto = Automata()
    auto.setInitialState(state1)
    auto.addFinalStates(state2)
    auto.addTransition(
        a.final[0], b.initial,
        ":e:")  # e-transition from a's final state to b's initial state
    auto.addTransitionTable(a.transitions)
    auto.addTransitionTable(b.transitions)
    return auto
示例#3
0
文件: regex.py 项目: nathayush/CS-305
def basicMachine(char):
    state1 = 1
    state2 = 2
    auto = Automata()
    auto.setInitialState(state1)
    auto.addFinalStates(state2)
    auto.addTransition(state1, state2, char)
    return auto
示例#4
0
    def afd_parser(self, rawToken, paint):
        
        tokens = self.fix_tokens(rawToken)
        #print("Hi, im being passed this tokens! \n", tokens)
        tree = generate_tree(tokens)
        st = self.tree_to_stack(tree, [])
        st.reverse()
        table = self.compute_positions(st)
        #we turn it around to have depth first..

        self.final = self.get_hashtags(st)
        st.reverse()
        self.initial = st[0].first_pos
        self.createDFA(tokens)
        #self.translate()
        
        #print("STATES", self.fn)
        initial = self.fn[0]
        initial.set_initial(True)
        au = Automata([], self.language, initial, self.finalDFA, self.fn)
        print("automata", au)

        if paint:
            export_chart_subset(au)
        
        return au
示例#5
0
    def clear_canvas(self, full_clear):

        self.drawing_area.delete(ALL)
        GUI.state_nodes = []
        GUI.au = Automata("Pfa")
        GUI.transition_edge = []

        if full_clear:
            GUI.state_position = []
def construct_automata(trigger_dict):
    '''trigger_dict : type => triggers => rules '''
    automata_dict = init_dict(dict)
    for k in trigger_dict.keys():
        trigger_to_context = trigger_dict[k]
        for trigger in trigger_to_context.keys():
            automata_dict[k][trigger] = Automata(trigger)
            for contexts in trigger_to_context[trigger]:
                automata_dict[k][trigger].learn(contexts)
    return automata_dict
    def makeAutomata(self):
        Q = [self.empty]

        # On remplit d'abord Q
        for i in range(0, len(self.S)):
            b = False
            for j in range(0, i):
                if i != j and self.S.table[i] == self.S.table[j]:
                    b = False
                    break
                if self.S.key[
                        i] not in Q and self.S.table[i] != self.S.table[j]:
                    b = True
            if b:
                Q.append(self.S.key[i])

        automata = Automata(self.alphabet, Q)

        # Ensuite, on peut remplir les tables Fa et Fr
        for qu in range(len(Q)):
            if self.allKey.getValue(Q[qu] + self.empty) == 1:
                automata.Fa.append(qu)
            else:
                automata.Fr.append(qu)

        # Enfin, on peut créer la table contenant les états et les transitions
        for qu in range(len(Q)):
            for a in self.alphabet:
                for qw in range(len(Q)):
                    if self.getRow(Q[qu] + a) == self.getRow(Q[qw]):
                        automata.setValue(qw, qu, a)
                        break

        print("\n-- Q  ------------------------------")
        print(automata.Q)
        print("\n-- Fa ------------------------------")
        print(automata.Fa)
        print("\n-- Fr ------------------------------")
        print(automata.Fr)

        return automata
示例#8
0
def main():
    parser = argparse.ArgumentParser(
        description='Argumentos para entrada de arquivo e palavra')
    parser.add_argument('-f',
                        '--filename',
                        help='Input filename',
                        required=False)
    parser.add_argument('-w', '--word', help='Input word', required=False)
    args = parser.parse_args()

    if args.filename:
        grammar_path = args.filename
    else:
        grammar_path = 'gramatica_exemplos/gramatica_exemplo_loop.txt'
    with open(grammar_path, 'r') as gf:
        grammar = gf.readline().rstrip()
    g = Grammar(grammar)
    ehValido = g.validateGrammar()

    if args.word:
        word = args.word
    else:
        word = input('Digite a palavra a ser validada: ')

    g.recognize(word)

    if ehValido:
        dfa = Automata(start_state=g.startSymbol)
        dfa.convertGrammar(g)
        dfa.convertER()
        print('A ER gerada é: ')
        print(dfa.ER)
示例#9
0
    def empty_stack(self, stack):
        merge_nfa = None

        while stack.length() < 1:
            #lo tomamos como join
            nfa2 = stack.pop()
            nfa1 = stack.pop()
            initial = nfa2.get_initial_state()
            final = nfa1.get_final_state()
            #print("INIT", initial)
            #print("FINAL", final)
            for state in nfa2.arr_states():
                #print("STATE", state)
                if (state.get_start() == initial):

                    state.set_start(final)

            for state in nfa1.arr_states():
                if (state.get_start() == final):

                    state.set_start(initial)
            merge_nfa = Automata([], [], nfa1.get_initial_state(),
                                 nfa2.get_final_state(), [])

            opsNfa2 = nfa2.arr_states()
            opsNfa1 = nfa1.arr_states()

            merged = opsNfa2 + opsNfa1

            for transition in merged:
                if (transition.get_transition() != None):
                    merge_nfa.add_state(transition)

        if not merge_nfa:
            merge_nfa = self.opStack.pop()

        self.opStack.add(merge_nfa)

        return stack
示例#10
0
def read_word(fa: Automata, word: str, state=-1):
    for letter in word:
        if letter not in fa.symboles:
            return False
    if word == "" and state == -1:
        for init in fa.initialStates:
            if fa.has_finalStates(init):
                return True
        return False
    elif state == -1:
        for init in fa.initialStates:
            if not read_word(fa, word, init):
                continue
            else:
                return read_word(fa, word, init)
    elif word is "":
        if fa.has_finalStates(state):
            return True
        else:
            return False
    else:
        if word[0] not in fa.states[state]:
            return False
        else:
            nextState = fa.states[state][word[0]]
            print(nextState)
            if nextState is []:
                if fa.has_finalStates(state):
                    return True
                else:
                    return False
            else:
                for newstate in nextState:
                    if not read_word(fa, word[1:], newstate):
                        continue
                    else:
                        return read_word(fa, word[1:], newstate)
    def subset_parser(self, auto, paint):
        self.prepare(auto)
        self.build_automata(automata=auto)
        # aqui deberiamos convertir todo..

        self.translate()
        initial = self.newfn[0]
        initial.set_initial(True)
        au = Automata([],[], initial, self.finalDFA, self.newfn)
        print("PowerSet AFD", au)
        #au.update_everything()
        if paint:
            export_chart_subset(au)
        
        return au
示例#12
0
def minimization(fa: Automata):
    if not is_complete(fa):
        print("c pa possible")
    else:
        groupeList = []
        groupeList.append([])
        for final in fa.finalStates:
            groupeList[0].append(final)

        groupeList.append([])
        for state in fa.states:
            if not fa.has_finalStates(state):
                groupeList[1].append(state)

        print(groupeList)
        temp = []
        while (temp != groupeList):
            tempGroupe = []
            print(tempGroupe)
            temp = groupeList
示例#13
0
class TestAutomata(unittest.TestCase):

    test_unit = None
    state_name = "testState"
    transition_letter = "s"
    from_state_id = 42
    to_state_id = 91

    def setUp(self):
        unittest.TestCase.setUp(self)
        self.test_unit = Automata()

    def test_add_and_get_state(self):
        self.assertIsNone(self.test_unit.get_state(self.state_name))
        self.test_unit.add_state(self.state_name)
        state = self.test_unit.get_state(self.state_name)
        self.assertIsNotNone(state)
        self.assertIs(state.name, self.state_name)

    def test_add_initial_state(self):
        self.test_unit.add_initial_state(self.state_name)
        self.assertTrue(self.test_unit.get_state(self.state_name).initial)

    def test_add_accepting_state(self):
        self.test_unit.add_accepting_state(self.state_name)
        self.assertTrue(self.test_unit.get_state(self.state_name).accepting)

    def test_add_transition(self):
        self.assertIsNone(self.test_unit.get_transition_by_from_state_id(self.from_state_id))
        self.test_unit.add_transition(self.transition_letter, self.from_state_id, self.to_state_id)
        transition = self.test_unit.get_transition_by_from_state_id(self.from_state_id)
        self.assertIsNotNone(transition)
        self.assertIs(transition.from_state_id, self.from_state_id)
        self.assertIs(transition.to_state_id, self.to_state_id)
        self.assertIs(transition.letter, self.transition_letter)

    def test_accepts_rejects_single_char(self):
        # q0 - a -> (q1)
        self.test_unit.add_initial_state('q0')
        self.test_unit.add_accepting_state('q1')
        self.test_unit.add_transition('a', 'q0', 'q1')

        self.assertTrue(self.test_unit.accepts('a'))
        self.assertFalse(self.test_unit.accepts('b'))

    def test_accepts_rejects_three_chars(self):
        # q0 - a -> (q1)
        # (q1) - b -> q0
        self.test_unit.add_initial_state('q0')
        self.test_unit.add_accepting_state('q1')
        self.test_unit.add_transition('a', 'q0', 'q1')
        self.test_unit.add_transition('b', 'q1', 'q0')

        self.assertTrue(self.test_unit.accepts('aba'))
        self.assertFalse(self.test_unit.accepts('ab'))
示例#14
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.test_unit = Automata()
示例#15
0
文件: regex.py 项目: nathayush/CS-305
def unionMachine(a, b):
    a, n1 = a.rebuild(
        2)  # rename the states to accomodate the new start and final states
    b, n2 = b.rebuild(
        n1
    )  # 'b' is an automata and 'n2' is the last state name(number) of 'b'
    state1 = 1
    state2 = n2
    auto = Automata()
    auto.setInitialState(state1)  # new initial state
    auto.addFinalStates(state2)  # new final state
    auto.addTransition(
        auto.initial, a.initial, ":e:"
    )  # :e: = epsilon, e-transition from new starting state to original starting states
    auto.addTransition(auto.initial, b.initial, ":e:")
    auto.addTransition(
        a.final[0], auto.final[0],
        ":e:")  # e-transition from original final states to new final state
    auto.addTransition(b.final[0], auto.final[0], ":e:")
    auto.addTransitionTable(a.transitions)  # add original transitions
    auto.addTransitionTable(b.transitions)
    return auto
示例#16
0
文件: regex.py 项目: nathayush/CS-305
def starMachine(a):
    a, n1 = a.rebuild(2)
    state1 = 1
    state2 = n1
    auto = Automata()
    auto.setInitialState(state1)
    auto.addFinalStates(state2)
    auto.addTransition(auto.initial, a.initial, ":e:")
    auto.addTransition(
        auto.initial, auto.final[0], ":e:"
    )  # e-transition from initial state to final state for empty string
    auto.addTransition(a.final[0], auto.final[0], ":e:")
    auto.addTransition(
        a.final[0], a.initial, ":e:"
    )  # e-transition from old final state to old initial state for loop
    auto.addTransitionTable(a.transitions)
    return auto
示例#17
0
from Automata import Automata

myAutomata = Automata()
myAutomata.add_initial_state('q0')
myAutomata.add_state('q1')
myAutomata.add_accepting_state('q2')

# q0 - a -> q1
myAutomata.add_transition('a', 'q0', 'q1')
# q1 - b -> (q2)
myAutomata.add_transition('b', 'q1', 'q2')

words = {'ab', 'ba', 'aa', 'bb'}

for word in words:
    if myAutomata.accepts(word):
        print word + " is accepted.\n"
    else:
        print word + " is not accepted.\n"
示例#18
0
from Automata import Automata as Automata
from minimization import *
# from plantuml import *

test = Automata("fa13.txt")
print(test)

test.toFile()

# Convert to an UML pic
# p = PlantUML()
# p.processes_file("output.txt")
示例#19
0
# -*- coding:utf-8 -*-
from Reader import Reader
from Automata import Automata

reader = (Reader()).read().run()
#Procesar reader con un autómata
automata = (Automata(reader)).run()

print("\n\nResultados")
for token in automata.tokens:
    #Obtener el valor y tipo de valor del token
    value, valueType = token.info()
    print("\t%s - %s" % (value,valueType))
示例#20
0
        q.put(temp[0])
        while not q.empty():
            state = q.get()
            temp_states = [state]
            for i in range(1, len(temp)):
                if len(set(temp[i]).intersection(state)) > 0:
                    state = list(set(temp[i] + state))
                    temp_states.append(temp[i])
                elif q.empty():
                    q.put(temp[i])
            new_states.append(state)
            temp = [x for x in temp if x not in temp_states]

        return new_states

    def print_table(self):
        pp = pprint.PrettyPrinter()
        pp.pprint(self.table)


if __name__ == "__main__":
    nfa = Automata()
    nfa.getGraphFromFile("test.txt")
    dfa = nfa.toDFA()
    # dfa.printGraph()
    m = Minimization(dfa)
    # m.print_table()
    mdfa = m.minimize()
    mdfa.printStateTable()
    mdfa.printGraph()
    # mdfa.render("mtest/dfa")
示例#21
0
    def evalPostfix(self, tokens):
        """
        Definimos las reglas segun: 
        https://medium.com/swlh/visualizing-thompsons-construction-algorithm-for-nfas-step-by-step-f92ef378581b 
        """

        for i in range(0, len(tokens)):

            currentToken = tokens[i]
            if currentToken.get_type() == "SYMBOL" and currentToken.get_value(
            ) == "&":
                #Regla #1:
                #0 -> {1: "&"}
                trans1 = Transition(start=self.stateCounter,
                                    transition=currentToken.get_value(),
                                    end=self.stateCounter + 1)
                self.stateCounter += 1
                #1 -> {} y es final.
                trans2 = Transition(start=self.stateCounter,
                                    transition=None,
                                    end=None)
                self.stateCounter += 1

                #estados, alfabeto, estado inicial, estado final, funcion de transicion
                au = Automata([], [], trans1.get_start(), trans2.get_start(),
                              [])
                au.add_state(trans1)
                au.add_state(trans2)
                #print(au)
                #print("DONE &")
                self.opStack.add(au)

            elif currentToken.get_type(
            ) == "SYMBOL" and currentToken.get_value() != "&":
                #Regla #2:
                #0 -> {1: "B"}
                trans1 = Transition(start=self.stateCounter,
                                    transition=currentToken.get_value(),
                                    end=self.stateCounter + 1)
                self.stateCounter += 1
                #1 -> {} y es final.
                trans2 = Transition(start=self.stateCounter,
                                    transition=None,
                                    end=None)
                self.stateCounter += 1

                #estados, alfabeto, estado inicial, estado final, funcion de transicion
                au = Automata([], [], trans1.get_start(), trans2.get_start(),
                              [])
                au.add_state(trans1)
                au.add_state(trans2)
                #print(au)
                #print("DONE SYMB")
                self.opStack.add(au)

            #sea una operacion
            elif currentToken.get_type() != "SYMBOL":

                #regla #3: OR
                if currentToken.get_type() == BuilderEnum.OR.value:
                    #sacamos del stack
                    nfa2 = self.opStack.pop()

                    nfa1 = self.opStack.pop()

                    #armado de nfa base.
                    #TRANSICIONES
                    transitionInitial1 = Transition(
                        start=self.stateCounter,
                        transition="&",
                        end=nfa1.get_initial_state())
                    transitionInitial2 = Transition(
                        start=self.stateCounter,
                        transition="&",
                        end=nfa2.get_initial_state())
                    self.stateCounter += 1
                    transitionFinal1 = Transition(start=nfa1.get_final_state(),
                                                  transition="&",
                                                  end=self.stateCounter)
                    transitionFinal2 = Transition(start=nfa2.get_final_state(),
                                                  transition="&",
                                                  end=self.stateCounter)
                    self.stateCounter += 1

                    #Sacamos todas las transiciones del elem1 y elem2
                    arr2 = nfa2.arr_states()  #array
                    arr1 = nfa1.arr_states()  #array
                    #unificamos los nfa
                    unifiedArray = arr2 + arr1
                    newTrans = [
                        transitionInitial1, transitionInitial2,
                        transitionFinal1, transitionFinal2
                    ]
                    finalTrans = unifiedArray + newTrans

                    or_nfa = Automata([], [], transitionInitial1.get_start(),
                                      transitionFinal1.get_end(), [])
                    # me devuelve un array de States.
                    for transition in finalTrans:
                        if (transition.get_transition() != None):
                            or_nfa.add_state(transition)

                    #print(or_nfa)
                    #print("DONE OR, to: \n", nfa2, "\n", nfa1 )
                    self.opStack.add(or_nfa)

                #REGLA KLEENE
                if currentToken.get_type() == BuilderEnum.KLEENE.value:
                    nfa = self.opStack.pop()

                    #encontramos estados finales e iniciales:
                    final = nfa.get_final_state()
                    initial = nfa.get_initial_state()
                    #transicion de final a inicial del nfa preexistente
                    finalMod = Transition(start=final,
                                          transition="&",
                                          end=initial)

                    #estado inicial de nfa preexistente a nuevo estado de trans
                    initialState = Transition(self.stateCounter, "&", initial)

                    self.stateCounter += 1

                    finalState = Transition(self.stateCounter, None, None)
                    initialEnd = Transition(initialState.get_start(), "&",
                                            finalState.get_start())
                    #transicion de nfa final a final de nuevo nfa
                    finalTofinal = Transition(start=final,
                                              transition="&",
                                              end=finalState.get_start())

                    self.stateCounter += 1

                    kleene_nfa = Automata([], [], initialState.get_start(),
                                          finalState.get_start(), [])
                    arr1 = nfa.arr_states()
                    unifiedArray = arr1
                    newTrans = [
                        initialState, initialEnd, finalState, finalTofinal,
                        finalMod
                    ]
                    finalTrans = unifiedArray + newTrans

                    for transition in finalTrans:
                        if (transition.get_transition() != None):
                            kleene_nfa.add_state(transition)

                    #print("DONE KLEENE to \n", nfa)
                    self.opStack.add(kleene_nfa)

                if currentToken.get_type() == BuilderEnum.PLUS.value:
                    nfa = self.opStack.pop()

                    #encontramos estados finales e iniciales:
                    final = nfa.get_final_state()
                    initial = nfa.get_initial_state()

                    target_symbol = None
                    for fn in nfa.arr_states():
                        if initial == fn.get_start():
                            target_symbol = fn.get_transition()
                            break

                    midState = Transition(self.stateCounter,
                                          transition="&",
                                          end=initial)
                    self.stateCounter += 1

                    cycle_state = Transition(self.stateCounter,
                                             transition=target_symbol,
                                             end=midState.get_start())
                    self.stateCounter += 1

                    #transicion de final a inicial del nfa preexistente
                    finalMod = Transition(start=final,
                                          transition="&",
                                          end=initial)

                    #estado inicial de nfa preexistente a nuevo estado de trans

                    finalState = Transition(self.stateCounter, None, None)
                    self.stateCounter += 1
                    initialState = Transition(midState.get_start(), "&",
                                              finalState.get_start())

                    #transicion de nfa final a final de nuevo nfa
                    finalTofinal = Transition(start=final,
                                              transition="&",
                                              end=finalState.get_start())

                    plus_nfa = Automata([], [], cycle_state.get_start(),
                                        finalState.get_start(), [])
                    arr1 = nfa.arr_states()
                    unifiedArray = arr1
                    newTrans = [
                        initialState, finalState, finalTofinal, midState,
                        cycle_state, finalMod
                    ]
                    finalTrans = unifiedArray + newTrans

                    for transition in finalTrans:
                        if (transition.get_transition() != None):
                            plus_nfa.add_state(transition)

                    #print("DONE PLUS to: \n", nfa)
                    self.opStack.add(plus_nfa)

                if currentToken.get_type() == BuilderEnum.CONCAT.value:
                    nfa2 = self.opStack.pop()
                    nfa1 = self.opStack.pop()

                    initial = nfa2.get_initial_state()
                    final = nfa1.get_final_state()
                    #print("INIT", initial)
                    #print("FINAL", final)
                    for state in nfa2.arr_states():
                        #print("STATE", state)
                        if (state.get_start() == initial):
                            state.set_start(final)

                    for state in nfa1.arr_states():
                        if (state.get_start() == final):
                            state.set_start(initial)
                    merge_nfa = Automata([], [], nfa1.get_initial_state(),
                                         nfa2.get_final_state(), [])

                    opsNfa2 = nfa2.arr_states()
                    opsNfa1 = nfa1.arr_states()

                    merged = opsNfa2 + opsNfa1

                    for transition in merged:
                        if (transition.get_transition() != None):
                            merge_nfa.add_state(transition)

                    #print(merge_nfa)
                    #print("DONE CONCAT to \n", nfa1, "\n", nfa2 )
                    self.opStack.add(merge_nfa)

        #opstack is ready to be exported
        return self.opStack
示例#22
0
def main():
    # How to use argparse: https://www.pythonforbeginners.com/argparse/argparse-tutorial
    parser = argparse.ArgumentParser()
    parser.add_argument("--Type", help="Use conway or wolfram", nargs='?', default="none")
    parser.add_argument("--Par", help="For wolfram, type in a number betweeen 0 and 255 inclusive. For," +
    "Conway type in the survive numbers a forward slash, and the birth numbers with no spaces e.g. 23/3", nargs='?', default=30)
    parser.add_argument("--Size", help="Sets the dimensions of the automata; the horizontal will be twice the size of the input", nargs='?', default=100)
    parser.add_argument("--Cheat", help="Only for wolfram; creates faster output but does not follow the algorithm perfectly", nargs='?', default=False)
    parser.add_argument("--SaveFile", help="Save file name; don't add .jpg or .gif; the file extensions will be appended automatically", nargs='?', default="out")
    parser.add_argument("--Times", help="Number of iterations in the automata", nargs='?', default=0)
    parser.add_argument("--Speed", help="Rate of video for conway", default=.2)
    parser.add_argument("--Creature", help="For conway only, type in the name of a creature. Here are all the creatures\n" + str(creatures.keys()), nargs='?',default='square')
    args = parser.parse_args()
    args.Type = args.Type.lower()
    args.Size = int(args.Size)
    if args.Type == "conway":
        if(type(args.Par) == int):
            args.Par = '23/3'
        if(args.Times == 0):
            args.Times = 50
        aut = Automata(x_size = args.Size, y_size = args.Size, par = args.Par, rule= conway,
                       setup = setup_conway, setup_params=creatures[args.Creature])
        aut.setup()
        update_with_commentary(aut, int(args.Times))
        print('Creating movie')
        aut.print_movie(args.Speed, args.SaveFile + '.gif')
        print('Done!')
    elif args.Type == "wolfram":
        aut = Automata(x_size=args.Size, y_size=args.Size * 2, par = (int(args.Par), bool(args.Cheat)), rule = wolfram)
        if(args.Times == 0):
            args.Times = 50
        aut.setup()
        if (args.Cheat == False):
            update_with_commentary(aut, int(args.Times))
        else:
            aut.update_automata(times = 1)
        print('Creating image')
        aut.print(args.SaveFile + '.jpg')
        print('Done!')
    else:
        args.Size = 100
        x = input('Invalid input; would you like to get some samples? y or n?')
        x = x.lower()
        if x == 'y' or x == 'yes':
            print('Doing wolfram rule 90')
            aut = Automata(x_size=args.Size, y_size=args.Size * 2, par = (90,True), rule = wolfram)
            aut.setup()
            aut.update_automata()
            aut.print('Rule_ninety.jpg')
            print('Saving to Rule_ninety.jpg')
            print('Doing wolfram rule 45')
            aut = Automata(x_size=args.Size, y_size=args.Size * 2, par=(45, True), rule=wolfram)
            aut.setup()
            aut.update_automata()
            aut.print('Rule_forty-five.jpg')
            print('Saving to Rule_forty-five.jpg')
            print('Doing rule 23/3 glider')
            aut = Automata(x_size=args.Size, y_size=args.Size, par='23/3', rule=conway,
                           setup=setup_conway, setup_params=creatures['glider'])
            aut.setup()
            update_with_commentary(aut, 30)
            aut.print_movie(speed = .2, name='glider.gif')
            print('Saving to glider.gif')
            print('Doing rule 23/36 replicator')
            aut = Automata(x_size=args.Size, y_size=args.Size, par='23/36', rule=conway,
                           setup=setup_conway, setup_params=creatures['replicator'])
            aut.setup()
            update_with_commentary(aut, 100)
            aut.print_movie(speed=.2, name='replicator.gif')
            print('Saving to replicator.gif')
if len(arguments) > 3:
    times = arguments[3]

print("Mega advanced automata is initiating...")
print("Using following parameters:")
print("-------")
print("States: {0}\nAutomatas: {1}\nIterations: {2}\nLoops: {3}".format(states, num_automata, iterations, times))
print("-------")
print("Progress: ")


startTime = time.time()

# Create automatas
automata_list = [Automata(states) for x in range(num_automata)]
result = {}


for x in range(times):
    for x in range(iterations):

        # Count yes for each of the automatas
        yes = 0
        for automata in automata_list:
            yes = yes + 1 if automata.isYes() else yes

    # Create environment and calculate probability
    env = Environment(yes, len(automata_list))
    env.probability()
示例#24
0
class AutomataManager():
    def __init__(self,abstraction):
        self.automata = Automata(abstraction)

        self.abstraction = abstraction
        self.automata._Automata__setConsideredAttributes(self.abstraction.getConsideredAttributes())
        self.automata._Automata__setIgnoredAttributes(self.abstraction.getIgnoredAttributes())

    def newTrace(self):
        self.trace = []
        self.prevStateID = -1
        self.currentStateID = -1
        self.currentState = None
        self.edgeState = None

    def setParentPath(self,parentPath):
        self.parentPath = parentPath

    def getAutomata(self):
        return self.automata

    def getTrace(self):
        return self.trace

    def getCurrentState(self):
        return self.currentState

    def saveAutomata(self,automataDir):
        print("Save automata.")

        # clean the automata directory first
        for file in os.listdir(automataDir):
            targetFile = os.path.join(automataDir,file)
            if os.path.isfile(targetFile):
                os.remove(targetFile)

        # dump states informations
        for state in self.automata.states:
            statePath = os.path.join(automataDir,"state"+str(state.ID)+".json")
            data = {'stateID':state.ID}
            data["stateType"] = state.Type
            data["stateXMLs"] = state.XMLs
            data["stateMoves"] = state.Moves
            data["stateParent"] = state.parent
            with open(statePath, "w") as outfile:
                json.dump(data, outfile, indent=4)

        # dump edges informations
        edgePath = os.path.join(automataDir,"edges.json")
        edges = list(self.automata.edges)
        data = {'edges':edges}
        with open(edgePath, "w") as outfile:
                json.dump(data, outfile, indent=4)

    '''
    This function can load only one already existed automata as a current automata.
    '''
    def loadAutomata(self,automataDir,algo):
        for root,dirnames,filenames in os.walk(automataDir):
            for file in filenames:
                if file.startswith("state"):
                    stateFile = os.path.join(root,file)
                    state_json = open(stateFile)
                    stateData = json.load(state_json)
                    state_json.close()

                    # new a state
                    if stateData["stateType"] == "View":
                        # get first XML in stateXMLs
                        # ex: David-exp1\net.mandaria.tippytipper\version1\abstraction1\session9\traceSet\1\uidump0.xml
                        xml = self.getXMLbyStepID(stateData["stateXMLs"][0],algo)

                        newState = self.automata._Automata__generateState(xml)

                    if stateData["stateType"] == "Action":
                        # get first Move in stateMoves
                        # ex: David-exp1\net.mandaria.tippytipper\version1\abstraction1\session9\traceSet\1\move1.json
                        move = self.getMovebyStepID(stateData["stateMoves"][0],algo)

                        newState = self.automata._Automata__generateState(move)

                    newState.ID = stateData["stateID"]
                    newState.Type = stateData["stateType"]
                    newState.Moves = stateData["stateMoves"]
                    newState.XMLs = stateData["stateXMLs"]
                    newState.parent = stateData["stateParent"]

                    # add new state into automata
                    self.automata.states.append(newState)

                    # update the stateNum of the automata
                    self.automata.stateNum += 1

                elif file.startswith("edges"):
                    edgeFile = os.path.join(root,file)
                    edge_json = open(edgeFile)
                    edgeData = json.load(edge_json)
                    edge_json.close()

                    self.automata.edges = edgeData["edges"]

        #return a duplicated automata
        return deepcopy(self.automata)

    '''
    This function can be called repeatedly, keep adding new state in current automata
    '''
    def loadSession(self,sessionDir):
        # sessionDir is 'David\\net.mandaria.tippytipper\\version1\\abstraction1\\session1\\traceSet'
        sessionNum = int( os.path.split(os.path.split(sessionDir)[0])[1].replace("session",""))
        abstractionNum = int( os.path.split(os.path.split(os.path.split(sessionDir)[0])[0])[1].replace("abstraction",""))
        versionNum = int( os.path.split(os.path.split(os.path.split(os.path.split(sessionDir)[0])[0])[0])[1].replace("version",""))

        for root,dirnames,filenames in os.walk(sessionDir):
            if dirnames != []:
                # each session enter once
                # dirnames = [1,10,2,3,4,5,6,7,8,9]
                # totalTrace = [1,2,3,4,5,6,7,8,9,10]
                totalTrace = sorted([int(x) for x in dirnames])
                for traceNum in totalTrace:
                    step = 0
                    while os.path.isfile(os.path.join(root,str(traceNum),"uidump"+str(step)+".xml")):
                        print("trace = ",str(traceNum),"step = ",str(step))
                        stepID = (versionNum,abstractionNum,sessionNum,int(traceNum),step)
                        xml = os.path.join(root,str(traceNum),"uidump"+str(step)+".xml")
                        if step == 0 : # handle the initial state in each session
                            self.updateAutomataByRestart(xml,stepID)
                        else:
                            move = os.path.join(root,str(traceNum),"move"+str(step)+".json")
                            action = self.automata._Automata__generateAction(move)
                            if action[0] == "restart":
                                self.updateAutomataByRestart(xml,stepID)
                            else:
                                self.updateAutomataByAction(action,stepID)
                                self.updateAutomataByXML(xml,stepID)
                        step += 1

    def getXMLbyStepID(self,stepID,algo):
        if algo == "SELabeler":
            versionNum,abstractionNum,sessionNum,traceNum,stepNum = stepID
            xml = os.path.join(self.parentPath,"version"+str(versionNum),"abstraction"+str(abstractionNum),\
                            "labeledTrace","traceSet",str(traceNum),"uidump"+str(stepNum)+".xml")
        else:
            versionNum,abstractionNum,sessionNum,traceNum,stepNum = stepID
            xml = os.path.join(self.parentPath,"version"+str(versionNum),"abstraction"+str(abstractionNum),\
                            "session"+str(sessionNum),"traceSet",str(traceNum),"uidump"+str(stepNum)+".xml")
        return xml

    def getMovebyStepID(self,stepID,algo):
        if algo == "SELabeler":
            versionNum,abstractionNum,sessionNum,traceNum,stepNum = stepID
            move = os.path.join(self.parentPath,"version"+str(versionNum),"abstraction"+str(abstractionNum),\
                            "labeledTrace","traceSet",str(traceNum),"move"+str(stepNum)+".json")
        else:
            versionNum,abstractionNum,sessionNum,traceNum,stepNum = stepID
            move = os.path.join(self.parentPath,"version"+str(versionNum),"abstraction"+str(abstractionNum),\
                            "session"+str(sessionNum),"traceSet",str(traceNum),"move"+str(stepNum)+".json")
        return move

    def updateAutomataByRestart(self,xml,stepID,memInfo):
        self.edgeState = None
        self.currentState = self.automata._Automata__generateState(xml)
        tempViewList = self.currentState.viewList

        self.currentStateID = self.automata._Automata__addState(self.currentState,stepID) # view state
        for state in self.automata.states:
            if state.ID == self.currentStateID:
                self.currentState = state

        # 1. update current viewList
        self.currentState.viewList = tempViewList

        # 2. get memory information
        self.currentState.totalMemory = memInfo.pssTotal

        self.currentState.ID = self.currentStateID
        self.trace.append(self.currentState)

        return self.currentStateID


    def updateAutomataByXML(self,xml,stepID,memInfo):
        self.currentState = self.automata._Automata__generateState(xml)
        tempViewList = self.currentState.viewList

        if self.edgeState == None: # the beginning state
            self.currentStateID = self.automata._Automata__addState(self.currentState,stepID) # view state
            self.currentState.ID = self.currentStateID

            # get memory information
            self.currentState.totalMemory = memInfo.pssTotal

            self.trace.append(self.currentState)

        else: # the rest states, need to update edgeState's fromState and toState
            self.prevStateID = self.currentStateID
            self.currentStateID = self.automata._Automata__addState(self.currentState,stepID) # view state
            for state in self.automata.states:
                if state.ID == self.currentStateID:
                    self.currentState = state

            # 1. update current viewList
            self.currentState.viewList = tempViewList

            # 2. get memory information
            self.currentState.totalMemory = memInfo.pssTotal

            self.automata._Automata__addEdge(self.prevStateID,self.currentStateID)
            self.trace.append(self.currentState)

        return self.currentStateID

        #print("shortest path = "+str(self.automata.getShortestPath(self.automata.initialState.ID,self.currentState.ID)))

    def updateAutomataByAction(self,action,stepID):
        self.edgeState = State()
        self.edgeState.Type = "Action"
        self.edgeState.action = action
        self.prevStateID = self.currentStateID
        self.edgeState.parent = self.prevStateID
        self.currentStateID = self.automata._Automata__addState(self.edgeState,stepID) # action state
        self.edgeState.ID = self.currentStateID
        print(" add edge prev = ",self.prevStateID," curr = ",self.currentStateID)
        self.automata._Automata__addEdge(self.prevStateID,self.currentStateID)
        self.trace.append(self.edgeState)

        return self.currentStateID
示例#25
0
    def __init__(self,abstraction):
        self.automata = Automata(abstraction)

        self.abstraction = abstraction
        self.automata._Automata__setConsideredAttributes(self.abstraction.getConsideredAttributes())
        self.automata._Automata__setIgnoredAttributes(self.abstraction.getIgnoredAttributes())
示例#26
0
 def minimize(self):
     new_states = self.get_new_states()
     new_states = self.combine_states(new_states)
     graph = self.create_graph(new_states)
     return Automata(graph)
示例#27
0
class GUI(Frame):
    """
    def __init__(self):
        # au = Automata("dfa")
        au = Automata("nfa")

        # au.generate_automata("a,I|b,N|c,F|d,N|e,N|f,N|g,N|h,N*a,0,b|a,1,f|b,1,c|b,0,g|c,1,c|c,0,a|d,0,c|d,1,g|e,1,
        # f|e,0,h|f,1,g|f,0,c|g,0,g|g,1,e|h,0,g|h,1,c")  #000000000010111111

        au.generate_automata("a,I|b,F*a,0,a|a,1,a|a,1,b")

        if EvaluateAutomata().evaluate_dfa("1", au):
            print("Acepta")
        else:
            print("NO acepta")
"""
    # ER->NFAE
    # DFA->ER
    # Resta
    # Complemento
    # Reflexion (regex)

    # DFA
    # NFA
    # NFA->DFA
    # NFA-E
    # NFA-E>DFA
    # Union
    # Interseccion

    # PDA
    # Turing

    drawing_area = None
    au = Automata("nfa")
    pda = Automata("pda")
    state_nodes = []
    transition_edge = []
    edit_states = False
    automataType = None
    nfa_to_dfa_button = None

    automata_type = "Turing"
    shown_transitions = ""
    glc_string_data = ""
    state_position = []
    record_state_position = False

    def __init__(self):
        super().__init__()
        self.init_ui()

    def draw_circle_aux(canv, x, y, fill_color, label_text):

        oval_id = canv.create_oval(x - 25,
                                   y - 25,
                                   x + 25,
                                   y + 25,
                                   width=0,
                                   fill=fill_color,
                                   tags="label_text")
        text_id = canv.create_text(x, y, text=label_text, font=("Purisa", 12))
        GUI.state_nodes.append(
            node_data(x, y, label_text, fill_color, text_id, oval_id))

    def init_ui(self):
        self.master.title("Pythomatas: Turing")
        self.pack(fill=BOTH, expand=1)
        self.center_window()

        quit_button = Button(self, text="Quit", command=self.quit)
        quit_button.place(x=710, y=560)
        GUI.drawing_area = Canvas(bg="#cccccc", height=520, width=760)
        self.drawing_area.place(x=20, y=20)

        new_transition_button = Button(self,
                                       text="New Transiton",
                                       command=self.create_transition_aux)
        new_transition_button.place(x=20, y=549)

        test_input = Entry(self, width=25)
        test_input.place(x=20, y=590)

        test_string_button = Button(
            self,
            text="Test String",
            command=lambda: self.test_string_fun(test_input.get()))
        test_string_button.place(x=200, y=590)

        delete_button = Button(self,
                               text="Delete",
                               command=self.change_edit_state)
        delete_button.place(x=115, y=549)

        state_pos = Button(self,
                           text="State position",
                           command=convert_nfa_to_dfa)
        state_pos.place(x=200, y=549)

        dfa_to_regex_button = Button(self,
                                     text="Switch",
                                     command=self.switch_automata)
        dfa_to_regex_button.place(x=800, y=20)

        nfa_to_dfa_button = Button(self,
                                   text="To DFA",
                                   command=self.nfa_to_dfa)
        nfa_to_dfa_button.place(x=800, y=50)

        nfae_to_dfa_button = Button(self,
                                    text="NFA-ε to DFA",
                                    command=self.convert_nfae_to_dfa)
        nfae_to_dfa_button.place(x=800, y=80)

        save_automata_button = Button(self,
                                      text="Save automata",
                                      command=self.save_automata)
        save_automata_button.place(x=800, y=490)

        load_automata_button = Button(self,
                                      text="Load automata",
                                      command=self.load_automata)
        load_automata_button.place(x=800, y=520)

        clear_all_button = Button(self,
                                  text="Clear",
                                  command=lambda: self.clear_canvas(True))
        clear_all_button.place(x=800, y=460)

        union_button = Button(self,
                              text="Union",
                              command=lambda: self.automata_operations("u"))
        union_button.place(x=800, y=130)

        compliment_button = Button(
            self,
            text="Compliment",
            command=lambda: self.automata_operations("c"))
        compliment_button.place(x=880, y=160)

        reflexion_button = Button(
            self,
            text="Reflexion",
            command=lambda: self.automata_operations("r"))
        reflexion_button.place(x=800, y=160)

        intersection_button = Button(
            self,
            text="Intersection",
            command=lambda: self.automata_operations("i"))
        intersection_button.place(x=880, y=130)

        show_new_drawing_area_button = Button(
            self,
            text="Show PDA Data",
            command=lambda: self.show_new_area(True))
        show_new_drawing_area_button.place(x=800, y=410)

        pda_to_glc = Button(self, text="PDA to GLC", command=self.pda_to_glc)
        pda_to_glc.place(x=800, y=350)

        glc_to_pda = Button(self,
                            text="GLC to PDA",
                            command=lambda: self.show_new_area(False))
        glc_to_pda.place(x=800, y=380)

    def pda_to_glc(self):
        result = EvaluateAutomata().pda_to_glc(self.au)
        if result:
            GUI.glc_string_data = result
            self.show_new_area(False)

    def automata_operations(self, operation):
        result = EvaluateAutomata().automata_operations(self.au, operation)
        self.clear_canvas(False)

        self.generate_text_automata(result)

    def minimize_automata(self):
        result = self.au.minimize()
        self.clear_canvas(False)
        self.generate_text_automata(result)

    def show_new_area(self, data):
        t = Toplevel(self)
        t.geometry('%dx%d+%d+%d' % (760, 520, 480, 250))
        t.wm_title("Data")

        text_area = Text(t, bg="#cccccc", height=29, width=90)
        text_area.place(x=10, y=10)

        text_area.insert(END, GUI.glc_string_data)

        if not data:
            save_text_button = Button(
                t,
                text="Create PDA",
                command=lambda: self.glc_to_pda(text_area.get("1.0", END)))
            save_text_button.place(x=645, y=480)
            load_glc_button = Button(t, text="Load GLC", command=self.load_glc)
            load_glc_button.place(x=545, y=480)
        else:
            text_area = Text(t, bg="#cccccc", height=29, width=90)
            text_area.place(x=10, y=10)
            text_area.insert(END, GUI.au.get_pda_transitions())

        save_glc_button = Button(
            t,
            text="Save GLC",
            command=lambda: self.save_glc(text_area.get("1.0", END)))
        save_glc_button.place(x=450, y=480)

    def glc_to_pda(self, glc_data):

        clean_glc_data = ""

        for gd in glc_data:
            if gd == " " or gd == "[" or gd == "]":
                pass
            else:
                clean_glc_data += gd

        r1 = self.fix_pda_input(clean_glc_data)
        result = EvaluateAutomata().glc_to_pda(clean_glc_data)

        self.clear_canvas(True)
        GUI.state_position.append([150, 300])
        GUI.state_position.append([400, 300])
        GUI.state_position.append([650, 300])
        self.generate_text_automata(result)

    def fix_pda_input(self, glc_data):

        first_split = glc_data.split("\n")
        pop_dictionary = []

        i = 0
        for fs in first_split:
            pop_split = fs.split(">")
            for pd in pop_dictionary:
                for p in pd:
                    if any(p):
                        d = chr(i)
                        pop_dictionary.append([pop_split, d])
                        i += 1

        for l in pop_dictionary:
            print(l[0] + ", " + l[1])

        return glc_data

    def load_glc(self):
        glc_text = askopenfilename()
        if glc_text:
            automata_text = get_text_from_file(glc_text)
            self.glc_to_pda(automata_text)

    def test_regex(self, regex_string):

        test_string = askstring('Insert string', " ")

        if test_string:

            result = Regex(regex_string).text_match(test_string, regex_string)

            if result:
                messagebox.showinfo("Result", "La cadena fue aceptada")
            else:
                messagebox.showinfo("Result", "La cadena no fue aceptada")

                # regex.split_parenthesis(regex_string)

    def switch_automata(self):
        if GUI.automata_type == "Nfa":
            GUI.automata_type = "Pda"
            self.master.title("Pythomatas: " + GUI.automata_type)
            self.clear_canvas(True)
        elif GUI.automata_type == "Pda":
            GUI.automata_type = "Turing"
            self.master.title("Pythomatas: " + GUI.automata_type)
            self.clear_canvas(True)
        elif GUI.automata_type == "Turing":
            GUI.automata_type = "Nfa"
            self.master.title("Pythomatas: " + GUI.automata_type)
            self.clear_canvas(True)

    def nfa_to_dfa(self):
        result = EvaluateAutomata().nfa_to_dfa(self.au)
        self.clear_canvas(False)
        self.generate_text_automata(result)

    def convert_nfae_to_dfa(self):
        result = EvaluateAutomata().nfae_to_dfa(self.au)
        self.clear_canvas(False)
        self.generate_text_automata(result)

    def save_automata(self):
        file_name = askstring('File name', "")

        if file_name:
            if GUI.automata_type == "Pda":
                if self.au.save_pda_automata(file_name, "y"):
                    messagebox.showinfo("Result", "El automata se salvo")
            elif GUI.automata_type == "Turing":
                if self.au.save_turing_automata(file_name, "y"):
                    messagebox.showinfo("Result", "El automata se salvo")
            else:
                if self.au.save_automata(file_name, "y"):
                    messagebox.showinfo("Result", "El automata se salvo")

    def create_self_transition(self, transition_char, x, y, state, node_id):

        text_id = GUI.drawing_area.create_text(x,
                                               y - 50,
                                               text=transition_char,
                                               font=("Purisa", 12))
        edge_left_id = GUI.drawing_area.create_line(x - 18,
                                                    y - 18,
                                                    x - 15,
                                                    y - 40,
                                                    tags=("line", ))
        edge_top_id = GUI.drawing_area.create_line(x - 15,
                                                   y - 40,
                                                   x + 15,
                                                   y - 40,
                                                   tags=("line", ))
        edge_right_id = GUI.drawing_area.create_line(x + 15,
                                                     y - 40,
                                                     x + 18,
                                                     y - 20,
                                                     tags=("line", ),
                                                     arrow="last")

        self.state_nodes.append(
            edge_data(node_id, node_id, x - 18, y - 18, x - 15, y - 40,
                      transition_char, text_id, edge_left_id, state, state))
        self.state_nodes.append(
            edge_data(node_id, node_id, x - 15, y - 40, x + 15, y - 40,
                      transition_char, text_id, edge_top_id, state, state))
        self.state_nodes.append(
            edge_data(node_id, node_id, x + 15, y - 40, x + 18, y - 20,
                      transition_char, text_id, edge_right_id, state, state))

    def load_automata(self):
        f_name = askopenfilename()
        if f_name:
            automata_text = get_text_from_file(f_name)
            self.generate_text_automata(automata_text)

    def save_glc(self, glc_text):
        file_name = askstring('File name', "")

        if file_name:
            EvaluateAutomata().save_glc(file_name, glc_text)

    def change_edit_state(self):
        if GUI.edit_states:
            GUI.edit_states = False
            self.master.title("Pythomatas")
        else:
            GUI.edit_states = True
            self.master.title("Pythomatas Edit*")

    def create_transition_aux(self):

        if GUI.automata_type == "Pda":
            transition_data = askstring('Insert Transition',
                                        "a,b,char,pop,push")
        elif GUI.automata_type == "Turing":
            transition_data = askstring('Insert Transition',
                                        "a,b,char,tape,move")
        else:
            transition_data = askstring('Insert Transition', "a,0,b")

        if transition_data:
            ntd = transition_data.split(",")

            if len(ntd) == 3:
                if self.au.create_transition(ntd[0], ntd[2], ntd[1]):
                    self.draw_line(ntd[0], ntd[2], ntd[1])
                else:
                    messagebox.showinfo("Info", "La transision no se creo")
            else:
                if self.au.create_turing_transition(ntd[0], ntd[1], ntd[2],
                                                    ntd[3], ntd[4]):

                    arrow = "←"

                    if ntd[4] == "r" or ntd[4] == "R":
                        arrow = "→"

                    self.draw_line(ntd[0], ntd[1],
                                   ntd[2] + "/" + ntd[3] + arrow)
                else:
                    messagebox.showinfo("Info", "La transision no se creo")

    def draw_line(self, state1, state2, transition_char):
        x1, y1, node_id1 = self.get_state_data(state1)
        x2, y2, node_id2 = self.get_state_data(state2)

        if node_id1 == node_id2:
            self.create_self_transition(transition_char, x1, y1, state1,
                                        node_id1)
            return

        tlx = (int(x1) + int(x2)) / 2
        tly = (int(y1) + int(y2)) / 2

        text_id = GUI.drawing_area.create_text(tlx,
                                               tly - 15,
                                               text=transition_char,
                                               font=("Purisa", 12))

        if int(x1) < int(x2):
            if int(y1) < int(y2):
                xa = int(x1) + 15
                ya = int(y1) + 15
                xb = int(x2) - 15
                yb = int(y2) - 15
            else:
                xa = int(x1) + 15
                ya = int(y1) - 15
                xb = int(x2) - 15
                yb = int(y2) + 15
        else:
            if int(y1) < int(y2):
                xa = int(x1) - 15
                ya = int(y1) + 15
                xb = int(x2) + 15
                yb = int(y2) - 15
            else:
                xa = int(x1) - 15
                ya = int(y1) - 15
                xb = int(x2) + 15
                yb = int(y2) + 15

        edge_id = GUI.drawing_area.create_line(xa,
                                               ya,
                                               xb,
                                               yb,
                                               tags=("line", ),
                                               arrow="last")
        self.state_nodes.append(
            edge_data(node_id1, node_id2, xa, ya, xb, yb, transition_char,
                      text_id, edge_id, state1, state2))

    def get_state_data(self, state_name):
        for sn in self.state_nodes:
            if sn.type == "node":
                if sn.node_name == state_name:
                    return sn.x_pos, sn.y_pos, sn.node_id

    def test_string_fun(self, test_string):

        if test_string:
            if GUI.automata_type == "Pda":
                result = EvaluateAutomata().evaluate_pda(test_string, self.au)
            elif GUI.automata_type == "Turing":
                result = EvaluateAutomata().evaluate_turing(
                    test_string, self.au)
            else:
                result = EvaluateAutomata().evaluate_nfa_e(
                    test_string, self.au)

            if result:
                if GUI.automata_type == "Pda":
                    messagebox.showinfo("Result", "La cadena fue aceptada")
                elif GUI.automata_type == "Turing":
                    messagebox.showinfo(
                        "Result", "Resultado de la cinta" + "\n" + result)
            else:
                messagebox.showinfo("Result", "La cadena no fue aceptada")

    def canvas_operations(event):
        if GUI.edit_states:
            GUI.delete_drawn_object(event)
        else:
            GUI.create_node(event)

    def create_node(event):
        state_name = askstring('State name', 'a,I')

        if state_name:
            draw_circle(GUI.drawing_area, event.x, event.y, state_name)

    def delete_drawn_object(event):
        item = GUI.drawing_area.find_closest(event.x, event.y)
        if len(item) is not 0:
            object_type, state_name, element1, element2, c_id, e_id, i = get_all_state_components(
                item[0])

            if object_type == "node":
                GUI.au.delete_state(state_name)
                GUI.drawing_area.delete(element1)
                GUI.drawing_area.delete(element2)
                del GUI.state_nodes[i]

                for sn in GUI.state_nodes:
                    if sn.type == "edge":
                        if sn.node_origin == item[
                                0] or sn.node_destiny == item[0]:
                            # GUI.drawing_area.delete(sn.char_id)
                            GUI.drawing_area.delete(sn.edge_id)

            if object_type == "edge":

                if GUI.automata_type == "pda":
                    GUI.au.delete_pda_transition(state_name, element1,
                                                 element2)
                    GUI.drawing_area.delete(c_id)
                    GUI.drawing_area.delete(e_id)
                    del GUI.state_nodes[i]
                elif GUI.automata_type == "Turing":
                    GUI.au.delete_turing_transition(state_name, element1,
                                                    element2)
                    GUI.drawing_area.delete(c_id)
                    GUI.drawing_area.delete(e_id)
                    del GUI.state_nodes[i]
                else:
                    GUI.au.delete_transition(state_name, element1, element2)
                    GUI.drawing_area.delete(c_id)
                    GUI.drawing_area.delete(e_id)
                    del GUI.state_nodes[i]

    def center_window(self):
        w = 1000
        h = 650
        sw = self.master.winfo_screenwidth()
        sh = self.master.winfo_screenheight()
        x = (sw - w) / 2
        y = (sh - h) / 2
        self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))

    def generate_text_automata(self, automata_text):

        state_transition_division = automata_text.split("*")
        states_division = state_transition_division[0].split("|")
        transition_division = state_transition_division[1].split("|")

        GUI.shown_transitions = transition_division

        i = 0
        for sd in states_division:
            draw_circle(self.drawing_area, self.state_position[i][0],
                        self.state_position[i][1], sd)
            i += 1

        for td in transition_division:
            ntd = td.split(",")
            if GUI.automata_type == "Pda":
                self.au.create_pda_transition(ntd[0], ntd[4], ntd[1], ntd[2],
                                              ntd[3])
                self.draw_line(ntd[0], ntd[4],
                               ntd[1] + "," + ntd[2] + "/" + ntd[3])
            elif GUI.automata_type == "Turing":
                self.au.create_turing_transition(ntd[0], ntd[4], ntd[1],
                                                 ntd[2], ntd[3])

                arrow = "←"

                if ntd[3] == "r" or ntd[3] == "R":
                    arrow = "→"

                self.draw_line(ntd[0], ntd[4], ntd[1] + "/" + ntd[2] + arrow)
            else:
                self.au.create_transition(ntd[0], ntd[2], ntd[1])
                self.draw_line(ntd[0], ntd[2], ntd[1])

    def get_mouse_data(event):
        if GUI.record_state_position:
            GUI.global_x = event.x
            GUI.global_y = event.y
            GUI.state_position.append([GUI.global_x, GUI.global_y])

    def test_event_state(event):
        # messagebox.showinfo("Result", "La cadena fue aceptada")
        pass

    def clear_canvas(self, full_clear):

        self.drawing_area.delete(ALL)
        GUI.state_nodes = []
        GUI.au = Automata("Pfa")
        GUI.transition_edge = []

        if full_clear:
            GUI.state_position = []

    def print_states_transitions(self):
        self.au.list_transitions()
        self.au.list_states()
示例#28
0
from Automata import Automata
from utils_automata import *

loop = True
while loop:
    fa_choice = str(input("Choose a FA to test: "))
    filename = "../res/fa" + fa_choice + ".txt"

    fa = Automata(filename)

    print("Is asycronous: " + str(is_asynchronous(fa)))
    print("Is deterministic: " + str(is_deterministic(fa)))
    print("Is Complete: " + str(is_complete(fa)))
    print("Is standard: " + str(is_standard(fa)))

    print("testing a word")
    word = input("test word: ")

    print(read_word(fa, word))

    choice = input("Exit [y/n]? ")
    if choice == "n" or choice == "N":
        loop = True
    else:
        loop = False
示例#29
0
 def __init__(self, Q, S, R, initial_state):
     self.transition_map = {}
     Automata.__init__(self, Q, S, R, initial_state)
示例#30
0
import re
from Automata import Automata
from anytree.dotexport import DotExporter


def nodenamefunc(node):
    return '%s:%s' % (node.name, node.nodeId)


def nodeattrfunc(node):
    return 'label="%s"' % (node.name)


er = "(ab|r)*123|(otro)a*"
test = "([a-z]*|[0-9]+)|(0*1+)"
#er = "(1|[a-z])|z?y"
automata = Automata(er)
DotExporter(automata.raiz,
            nodenamefunc=nodenamefunc,
            nodeattrfunc=nodeattrfunc).to_picture("arbol.png")
automata.dibujarAFD()

print(automata.er)
print(automata.tokens)
示例#31
0
automata = Automata(
    [], [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'ζ', '.', '\n', '\r',
        '\t', ' '
    ],
    Transition([
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
        63, 64, 65, 66
    ], '0', [
        10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36, 37,
        38, 39, 40, 41
    ], {'number': 20}), [
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62})
    ], [
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '0', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '1', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '2', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '3', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '4', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '5', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '6', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '7', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '8', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '9', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '\n', [67, 68, 69, 70, 71], {'white': 71}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '\r', [67, 68, 69, 70, 71], {'white': 71}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], '\t', [67, 68, 69, 70, 71], {'white': 71}),
        Transition([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 63, 64, 65, 66
        ], ' ', [67, 68, 69, 70, 71], {'white': 71}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '0', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '1', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '2', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '3', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '4', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '5', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '6', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '7', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '8', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '9', [
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], '.', [42, 43, 44, 45, 46, 47, 48, 49, 50, 51], None),
        Transition([67, 68, 69, 70, 71], '\n', [67, 68, 69, 70, 71],
                   {'white': 71}),
        Transition([67, 68, 69, 70, 71], '\r', [67, 68, 69, 70, 71],
                   {'white': 71}),
        Transition([67, 68, 69, 70, 71], '\t', [67, 68, 69, 70, 71],
                   {'white': 71}),
        Transition([67, 68, 69, 70, 71], ' ', [67, 68, 69, 70, 71],
                   {'white': 71}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '0',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '1',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '2',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '3',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '4',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '5',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '6',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '7',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '8',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([42, 43, 44, 45, 46, 47, 48, 49, 50, 51], '9',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '0',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '1',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '2',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '3',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '4',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '5',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '6',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '7',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '8',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], '9',
                   [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
                   {'decnumber': 62}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([
            10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 31, 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41
        ], None, None, {'number': 20}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([67, 68, 69, 70, 71], None, None, {'white': 71}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62}),
        Transition([52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62], None, None,
                   {'decnumber': 62})
    ])