Esempio n. 1
0
def pop_main():
    filename = "test-input-3.txt"
    nodes = readinstance(filename)
    job_server = pp.Server(ncpus=7)

    # Create clusters of k
    k = 20
    k_clusters = associate_points(nodes, kmeans_pp(nodes, k))

    depfuncs=(wrapped_nearest_neighbor, two_opt, dist, swap_edges, nearest_neighbor, tour_length)
    modules=("math","itertools")
    jobs = [job_server.submit(parallel_two_opt_and_nearest_neighbor,
                              (cluster,),
                              depfuncs,
                              modules) for cluster in k_clusters.values()]
    clusters = []
    for cluster in jobs:
        clusters.append(cluster())
        print "job %s has run" % id(cluster)

    # Cluter Gluing
    candr = center_f(clusters)

    cluster_tour = nearest_neighbor([k for k in candr],0)
    better = two_opt(cluster_tour)
    tours = glue(candr,better)

    tour_output(tours, filename)
Esempio n. 2
0
def main():
    filename = "test-input-1.txt"
    nodes = readinstance(filename)
    job_server = pp.Server()

    depfuncs=(wrapped_nearest_neighbor, two_opt, dist, swap_edges, nearest_neighbor, tour_length)
    modules=("math","itertools")
    jobs = [job_server.submit(parallel_two_opt_and_nearest_neighbor,
                              (nodes,),
                              depfuncs,
                              modules)]
    clusters = []
    for cluster in jobs:
        clusters.append(cluster())
        print "job %s has run" % id(cluster)

    # Cluter Gluing
    candr = center_f(clusters)

    cluster_tour = nearest_neighbor([k for k in candr],0)
    better = two_opt(cluster_tour)
    tours = glue(candr,better)

    tour_output(tours, filename)