Exemplo n.º 1
0
def example_generation():
    structures, candidates = generation(8, 10)
    candidates = [i+1 for i in range(8)]
    preferences = structures["preferences"]
    print("Preferences : " + str(preferences))
    print("Candidats : " + str(candidates))
    t1 = time()
    bb, best = bnb(len(preferences), preferences, candidates)
    t2 = time()
    print ("Best solution : " + str(best))
    #print bb
    print("Duration : " + str(t2-t1))
    print("On explore " + str(len(bb)) + " noeuds parmi " + str(nodes(len(preferences))) + " noeuds.")
Exemplo n.º 2
0
def example2():
    structure, axis = generation(7, 10000, 3)
    print("Generated axis: " + str(axis))
    mat = create_similarity_matrix(structure, dissimilarity_function=dissimilarity_over_over)
    print("Similarity Matrix")
    print(mat)
    print("Gradient score: " + str(get_matrix_score(mat)))
    print("Weighted Gradient score: " + str(get_weighted_matrix_score(mat)))

    t = time()
    dico = find_permutation_dynamic_programming(mat, Set(structure["candidates"].keys()), {}, weighted=True)
    t = time() - t
    print("Dynamic programming algorithm: " + str(t) + "seconds")
    print("Optimal permutations: " + str(dico[Set(structure["candidates"].keys())][1]))

    t = time()
    optimal_permutation = find_permutation_naive(mat)
    t = time() - t
    print("Naive algorithm: " + str(t) + "seconds")
    print("Optimal permutations: " + str(optimal_permutation))
def example2():
    structure, axis = generation(7, 10000, 3)
    print("Generated axis: " + str(axis))
    mat = create_similarity_matrix(
        structure, dissimilarity_function=dissimilarity_over_over)
    print("Similarity Matrix")
    print(mat)
    print("Gradient score: " + str(get_matrix_score(mat)))
    print("Weighted Gradient score: " + str(get_weighted_matrix_score(mat)))

    t = time()
    dico = find_permutation_dynamic_programming(
        mat, Set(structure["candidates"].keys()), {}, weighted=True)
    t = time() - t
    print("Dynamic programming algorithm: " + str(t) + "seconds")
    print("Optimal permutations: " +
          str(dico[Set(structure["candidates"].keys())][1]))

    t = time()
    optimal_permutation = find_permutation_naive(mat)
    t = time() - t
    print("Naive algorithm: " + str(t) + "seconds")
    print("Optimal permutations: " + str(optimal_permutation))