Ejemplo n.º 1
0
def print_var(event=None):
    """print_var
    Reads the functions and the query and says if there exists a smart plan or
    not.
    :param event: The event which called the function
    """
    functions = get_functions()
    q = [x.strip() for x in query.get().split(",")]
    i_grammar = FunctionIndexedGrammar(functions, [q])
    if i_grammar.is_empty():
        showinfo("Emptyness", "There exists no smart plan")
    else:
        showinfo("Emptyness", "There exists a smart plan")
Ejemplo n.º 2
0
def find_prolog(event=None):
    functions = get_functions()
    q = query.get()
    q_g = [x.strip() for x in query.get().split(",")]
    i_grammar = FunctionIndexedGrammar(functions, [q_g])
    if i_grammar.is_empty():
        showinfo("Prolog", "There exists no smart plan")
        return
    write_prolog(functions, q, 10, "tmp/tmp_prolog.pl")
    p = subprocess.Popen(["swipl", "-f", "tmp/tmp_prolog.pl", "-q", "main"],
                         stdout=subprocess.PIPE)
    output, err = p.communicate()
    if (len(output) == 0):
        showinfo("Prolog", "No plan found by Prolog")
    else:
        showinfo("Prolog", "The found plan:\n" + read_output(output))
Ejemplo n.º 3
0
    results_temp.append(n_reachable * 100.0 / float(len(terminals[key])))
    titles.append("DFS Strong time")
    results_temp.append(delta_t)


    print("### Smootie ###")
    titles.append("Smootie")
    n_reachable = 0

    current_time = time.time()

    for terminal in terminals[key]:
        i_grammar = FunctionIndexedGrammar(functions_single, [[terminal]],
                                           palindrome=True,
                                           susie=True)
        if i_grammar.is_empty():
            pass
            # print(terminal)
        else:
            n_reachable += 1

    print(str(n_reachable * 100.0 / float(len(terminals[key]))) +
            "% terminals reachable")
    results_temp.append(n_reachable * 100.0 / float(len(terminals[key])))

    delta_t = time.time() - current_time
    print("Elapsed time", delta_t)
    titles.append("Smootie time")
    results_temp.append(delta_t)

Ejemplo n.º 4
0
        pfsm = fsm.get_palindrome_fsm(query, weak=False)
        fsm_not_weak_res = pfsm.is_empty()
        fsm_not_weak_time = time.time() - current_time

        # === WEAK ===

        pfsm = fsm.get_palindrome_fsm(query, weak=True)
        fsm_weak_res = pfsm.is_empty()
        fsm_weak_time = time.time() - current_time

        # ==== SUSIE ====

        current_time = time.time()
        i_grammar = FunctionIndexedGrammar(functions, [[query]],
                                           palindrome=True,
                                           susie=True)
        susie_res = i_grammar.is_empty()
        susie_time = time.time() - current_time

        with open("pali_vs_susie_weak.csv", "a") as f:
            f.write(str(fsm_not_weak_res) + "," +
                    str(fsm_weak_res) + "," +
                    str(susie_res) + "," +
                    str(fsm_not_weak_time) + "," +
                    str(fsm_weak_time) + "," +
                    str(susie_time) + "," +
                    str(n_relations) + "," +
                    str(size_max) + "," +
                    str(n_functions) + "\n")
Ejemplo n.º 5
0
# number relations
n_relations = 10
size_max = 10
generator = FunctionGenerator(n_relations)

functions = []

optims = [2, 3, 6, 7, 8]

deltas = dict()
for optim in optims:
    deltas[optim] = []

for i in range(0, 1000):
    # 1 function, size_max is 10
    functions = []
    temp = generator.generate(25, size_max)
    functions += temp
    query = generator.get_random_query(functions)
    for optim in optims:
        current_time = time.time()
        grammar = FunctionIndexedGrammar(functions, [[query]], optim=optim)
        grammar.is_empty()
        delta_t = time.time() - current_time
        with open("rule_ordering2.csv", "a") as f:
            f.write(
                str(optim) + "," + str(i) + "," + str(delta_t) + "," +
                str(n_relations) + "," + str(size_max) + "\n")
        deltas[optim].append(delta_t)
Ejemplo n.º 6
0
size_max = 6
generator = FunctionGenerator(n_relations)

functions = []

for i in range(0, 1000):
    # 10 functions, size_max is 10
    functions = []
    n_functions = 9
    temp = generator.generate(n_functions, size_max)
    functions += temp
    query = generator.get_random_query(functions)

    current_time = time.time()
    grammar = FunctionIndexedGrammar(functions, [[query]], 7, False)
    res0 = grammar.is_empty()
    delta_t0 = time.time() - current_time
    n_rules0 = grammar.get_n_rules()
    n_rules0 = n_rules0[0] + n_rules0[1]

    current_time = time.time()
    grammar = FunctionIndexedGrammar(functions, [[query]], 7, True)
    res1 = grammar.is_empty()
    delta_t1 = time.time() - current_time
    n_rules1 = grammar.get_n_rules()
    n_rules1 = n_rules1[0] + n_rules1[1]

    functions.append(Function(functions[-1].get_inverse_function(), "f"))

    current_time = time.time()
    grammar = FunctionIndexedGrammar(functions, [[query]], 7, False)