def time_comparison(problem_sizes):
    times_no_heuristic = []
    times_first_satisfy = []
    times_first_fail = []

    for i in problem_sizes:
        path_file = "../data/queens_bis/{0}Q.txt".format(i)
        print(path_file)
        f = open(path_file, "r")
        literal, clause = load(f)

        start = time()
        dpll(literal, clause, first_satisfy, find_all_solutions=True)
        times_first_satisfy.append(time() - start)

        start = time()
        dpll(literal, clause, first_fail, find_all_solutions=True)
        times_first_fail.append(time() - start)

        start = time()
        dpll(literal, clause, no_heuristic, find_all_solutions=True)
        times_no_heuristic.append(time() - start)

    plt.figure()
    plt.title("Dames: temps des différentes heuristiques")
    plt.xlabel("Taille du problème")
    plt.ylabel("Temps (s)")
    plt.plot(problem_sizes, times_no_heuristic, label="No heuristic")
    plt.plot(problem_sizes, times_first_satisfy, label="First satisfy")
    plt.plot(problem_sizes, times_first_fail, label="First fail")
    plt.legend(loc='best')
    plt.savefig("images/queens_bis_heuristics.png")
    plt.show()
def tree_comparison(problem_sizes):
    nodes_no_heuristic = []
    nodes_first_satisfy = []
    nodes_first_fail = []

    for i in problem_sizes:
        path_file = "../data/queens_bis/{0}Q.txt".format(i)
        f = open(path_file, "r")

        literal, clause = load(f)

        mod1, n1 = dpll(literal, clause, first_satisfy)
        mod2, n2 = dpll(literal, clause, first_fail)
        mode3, n3 = dpll(literal, clause, no_heuristic)

        nodes_first_satisfy.append(n1)
        nodes_first_fail.append(n2)
        nodes_no_heuristic.append(n3)

    plt.figure()
    plt.title("Dames: taille des arbres")
    plt.xlabel("Taille du problème")
    plt.ylabel("Nombre de noeuds")
    plt.plot(problem_sizes, nodes_no_heuristic, label="No heuristic")
    plt.plot(problem_sizes, nodes_first_satisfy, label="First satisfy")
    plt.plot(problem_sizes, nodes_first_fail, label="First fail")
    plt.legend(loc='best')
    plt.savefig("images/queens_bis_tree.png")
    plt.show()
Esempio n. 3
0
def tree_comparison(problem_sizes):
    nodes_no_heuristic = []
    nodes_first_satisfy = []
    nodes_first_fail = []

    for i in problem_sizes:
        path_file = "../data/pigeon_hole/{0}p{1}P.txt".format(i, i - 1)
        f = open(path_file, "r")

        literal, clause = load(f)

        mod1, n1 = dpll(literal, clause, first_satisfy)
        mod2, n2 = dpll(literal, clause, first_fail)
        mode3, n3 = dpll(literal, clause, no_heuristic)

        nodes_first_satisfy.append(n1)
        nodes_first_fail.append(n2)
        nodes_no_heuristic.append(n3)
Esempio n. 4
0
def time_comparison(problem_sizes):
    times_no_heuristic = []
    times_first_satisfy = []
    times_first_fail = []

    for i in problem_sizes:
        path_file = "../data/pigeon_hole/{0}p{1}P.txt".format(i, i - 1)
        f = open(path_file, "r")

        literal, clause = load(f)

        start = time()
        dpll(literal, clause, first_satisfy)
        times_first_satisfy.append(time() - start)

        start = time()
        dpll(literal, clause, first_fail)
        times_first_fail.append(time() - start)

        start = time()
        dpll(literal, clause, no_heuristic)
        times_no_heuristic.append(time() - start)
Esempio n. 5
0
        s = self.s
        t = func_test(first_satisfy, s, g)


def main(params, n_runs=4):
    for i in range(n_runs):
        print('Run', i)
        n = np.random.randint(0, 3)
        res = dpll(params[n][0], params[n][1])
        res.time_dpll()


if __name__ == '__main__':
    path_file_1 = "../data/5p4P.txt"
    f_1 = open(path_file_1, "r")
    literal_1, clause_1 = load(f_1)

    path_file_2 = "../data/6p5P.txt"
    f_2 = open(path_file_2, "r")
    literal_2, clause_2 = load(f_2)

    path_file_3 = "../data/7p6P.txt"
    f_3 = open(path_file_3, "r")
    literal_3, clause_3 = load(f_3)

    my_params = [(literal_1, clause_1), (literal_2, clause_2),
                 (literal_3, clause_3)]

    lp = line_profiler.LineProfiler()
    lp.add_function(func_test)
    lp_wrapper = lp(main)
                        loop = False
                    else:
                        lit = next_lit

            elif sat is False:
                next_lit, clause_state, clause_lenght = backtrack(
                    literal, clause, literal_state, running_literal)
                if next_lit is None:
                    loop = False
                else:
                    lit = next_lit

            else:
                lit = literal_choice(literal, literal_state, clause,
                                     clause_state, clause_lenght, heuristic)

        return models, i


if __name__ == "__main__":
    path_file = "../data/queens_bis/6Q.txt"
    f = open(path_file, "r")

    literal, clause = load(f)

    d = time()
    mod, nodes = dpll(literal, clause, first_satisfy, find_all_solutions=False)
    print("time:", time() - d)
    print("nombre de modeles:", count_models(literal, mod))
    print("nombre de noeuds:", nodes)
        l_2 = l_1 - 1
    literals_state_2 = update_literal_state(literals_state, l_2)
    running_literals_2 = [l_2] + running_literals
    clauses_state_2, clauses_lenght_2 = update_clause(literals, clauses_state, clauses_lenght, l_2)

    """Models construction"""
    if (state == 0 for state in clauses_state):
        models += dpll_recursif(heuristic_choice, clauses, literals, clauses_lenght_1, literals_state_1,
                                clauses_state_1, running_literals_1)
        models += dpll_recursif(heuristic_choice, clauses, literals, clauses_lenght_2, literals_state_2,
                                clauses_state_2, running_literals_2)
    else:
        return [dpll_recursif(heuristic_choice, clauses, literals, clauses_lenght_1, literals_state_1, clauses_state_1,
                              running_literals_1),
                dpll_recursif(heuristic_choice, clauses, literals, clauses_lenght_2, literals_state_2, clauses_state_2,
                              running_literals_2)]
    return models


file_path = "../../data/queens_bis/6Q.txt"
f = open(file_path, "r")
f_literals, f_clauses = load(f)

t = time()
print(dpll_recursif(first_fail, f_clauses, f_literals))
t = time() - t
print(t)

f_2 = "../../data/queens_bis/res6Q.txt"
display(f_literals, dpll_recursif(first_fail, f_clauses, f_literals), f_2)