Esempio n. 1
0
def evaluateDFA2():
    print("Eval DFA2")
    value = str(mainWidget.lineEdit_eval.text())
    dfa = DFA(states=getStates(),
              input_symbols=symbols,
              transitions=getTransitions(),
              initial_state=str(startNode.label.text()),
              final_states=getFinalStates())
    try:
        print(str(list(dfa.validate_input(value, step=True))))
        showMsg("DFA Successful, Last:" + str(dfa.validate_input(value)))
    except:
        showMsg("ERROR EVALUATING DFA")

    return dfa
        valid_starting_pos = i_valid
        invalid_starting_pos = i_invalid
        POSSIBLE_SAMPLES = 2**length
        # print('\tFor strings of length {}, {} samples can be produced.'
        #       '\n\t{} samples were requested.'
        #       '\n\tGenerating {} samples'.format(length, POSSIBLE_SAMPLES, NUM_SAMPLES_PER_LEN, min(NUM_SAMPLES_PER_LEN, POSSIBLE_SAMPLES)))
        attempt = 1
        while (ctr_valid < min(NUM_SAMPLES_PER_LEN, POSSIBLE_SAMPLES)) and (ctr_invalid < min(NUM_SAMPLES_PER_LEN, POSSIBLE_SAMPLES)):
            a = np.random.randint(
                low=1, high=3, size=length, dtype=np.uint8) * 3
            z = np.zeros(DATA_WIDTH - len(a), dtype=np.uint8)
            s = np.vstack(np.append(a, z))

            try:

                dfa_0.validate_input(a)

                # a = np.vstack(np.append(a, z))
                if (ctr_valid < min(NUM_SAMPLES_PER_LEN, POSSIBLE_SAMPLES)):
                    found = False
                    for j in range(valid_starting_pos, valid_starting_pos+ctr_valid):
                        if np.array_equal(valid_data[j], s):
                            found = True
                            break

                    if not found:
                        valid_data[i_valid] = s
                        i_valid += 1
                        ctr_valid += 1
                    else:
                        attempt += 1
Esempio n. 3
0
               },
               'q8': {
                   'I': 'q8',
                   'C': 'q8',
                   'D': 'q8',
                   'E': 'q8',
                   'F': 'q8',
                   'G': 'q8',
                   'H': 'q8',
                   'A': 'q8',
                   'B': 'q8'
               }
           },
           initial_state='q0',
           final_states={'q7', 'q8'})
stopped_state1 = dfa1.validate_input('ABCDEFGHI')
if (stopped_state1 != 'q8'):
    print("DFA accepted!")
else:
    print("DFA Rejected!")
"""
a - when backdrop switches to level2
b - show
c - goto xy
d - forever
1 - [up,down,left,right,stop]
0 - [if any of the above repeat]
"""
#level2
dfa2 = DFA(states={'q0', 'q1', 'q2', 'q3', 'q4', 'q5'},
           input_symbols={'a', 'b', 'c', 'd', '0', '1'},