Esempio n. 1
0
cmdopt = vars(args)
neighbors = cmdopt.get('neighbors')
dsfile = cmdopt.get('file')
depth = cmdopt.get('depth')
verbose = cmdopt.get('verbose')

cities = []
with open(dsfile) as datasetFile:
    dataset = csv.reader(datasetFile, delimiter=',')
    for row in dataset:
        cities.append(City(row[0], int(row[1]), int(row[2])))
random.shuffle(cities)
Tour.init_roads(cities)
tour = Tour(cities)
answer = 'Y'
while answer in ['Yes', 'yes', 'YES', 'y', 'Y']:
    tour.plot_cities()
    begin = time.time()
    tour, iteration = tour_improve(tour, neighbors, verbose, depth)
    end = time.time()
    duration = end - begin
    print "Iterations took ", duration, " seconds."
    tour.plot_paths(2 * len(tour), iteration, True, True)
    answer = raw_input("Try to improve this tour ? [Y/N] (default No) : ")
    if answer in ['Yes', 'yes', 'YES', 'y', 'Y']:
        neighbors_in = raw_input(
            "Set a new value for neighbors count (default = actual = " +
            str(neighbors) + ') : ')
        if neighbors_in:
            neighbors = int(neighbors_in)