Exemple #1
0
def assignment_q1():
    # start a dict to store the running time
    slow_run = {}
    fast_run = {}

    for ctr in range(2, 200):
        t1 = time.time()
        project.slow_closest_pairs(gen_random_clusters(ctr))
        slow_run[ctr] = time.time() - t1

        t1 = time.time()
        project.fast_closest_pair(gen_random_clusters(ctr))
        fast_run[ctr] = time.time() - t1

        print "done:", ctr

    # plot the data
    xvals = slow_run.keys()

    plt.plot(xvals, slow_run.values(), '-b', label='slow_closest_pairs')
    plt.plot(xvals, fast_run.values(), '-r', label='fast_closest_pair')
    plt.legend(loc='upper right')
    plt.xlabel("Number of points")
    plt.ylabel("Running Time")
    plt.title("Comparison of slow_closest_pairs/fast_closest_pair algorithms")
    plt.show()
Exemple #2
0
def fast_closest_pair(num_clusters):
    return project.fast_closest_pair(gen_random_clusters(num_clusters))