Пример #1
0
n_relations = 10
size_max = 3
n_functions = 30
generator = FunctionGenerator(n_relations)

functions = []

for j in range(5, 70, 5):
    n_functions = j
# for j in range(2, 20, 2):
#     n_relations = j
    generator = FunctionGenerator(n_relations)
    for i in range(0, 200):
        # 1 function, size_max is 10
        functions = []
        temp = generator.generate(n_functions, size_max)
        functions += temp
        query = generator.get_random_query(functions)

        # ==== FSM ====

        current_time = time.time()
        new_function = "|".join(["(" +
                                 ",".join(function.to_list("m")) +
                                 ")" for function in functions])
        regex_function = RegexTree(Node(new_function))
        fsm = regex_function.to_fsm()
        fsm.close()

        # === NOT WEAK ===
Пример #2
0
Tests the time it takes to get the emptyness
"""

import time
from function_generator import FunctionGenerator
from function_indexed_grammar import FunctionIndexedGrammar
import cProfile


def get_millis():
    return int(round(time.time() * 1000))


current_time = get_millis()
total = 0
n_loop = 10

for _ in range(n_loop):
    generator = FunctionGenerator(5)
    functions = generator.generate(25, 10)
    query = generator.get_random_query(functions)
    # print(functions)
    # print(query)
    grammar = FunctionIndexedGrammar(functions, query)
    # cProfile.run("grammar.is_empty()")
    print(get_millis() - current_time)
    total += get_millis() - current_time
    current_time = get_millis()

print("Mean :" + str(total / n_loop))
Пример #3
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)
    * the file where to write the functions
    * the file where to write the query
"""

if len(sys.argv) != 6:
    sys.exit(
        "Correct usage : python3 function_generator_main.py n_relations " +
        "n_functions max_size_functions function_file query_file")

# Read arguments
n_relations = int(sys.argv[1])
n_functions = int(sys.argv[2])
max_size_functions = int(sys.argv[3])

generator = FunctionGenerator(n_relations)

lasts = []

f = open(sys.argv[4], "w")

# Generate the functions, in prolog format
for f_rel in generator.generate(n_functions, max_size_functions):
    f.write(f_rel.get_prolog())
    lasts.append(f_rel.get_last())

f.close()

# Generate the query
with open(sys.argv[5], "w") as f:
    f.write(random.choice(lasts) + "\n")