def hill_climb(init_tour): cur_iterator = 0 max_iterator = 100 min_distance = 100000; best_tour = init_tour while cur_iterator < max_iterator: flag = False for newtour in swap_cities(init_tour): if cur_iterator > max_iterator: break cur_iterator += 1 distance = util.get_path_distance(newtour, util.read_file()) if distance < min_distance: best_tour = newtour min_distance = distance flag = True break if flag == False: break #print best_tour #print min_distance #print cur_iterator return best_tour, min_distance
def exhaustive_iterator(city_Number, distance_table): start_time = datetime.datetime.now() min_distance = 100000.0 index = 0 for path in list(itertools.permutations(range(city_Number), city_Number)): #print(path) distance = util.get_path_distance(path, distance_table) if distance < min_distance: min_distance = distance print "new distance", min_distance print(path) print index index += 1 print min_distance print index end_time = datetime.datetime.now() print "runing time", (end_time - start_time).seconds, " seconds"
def get_distance(self): return util.get_path_distance(self.tour, util.read_file())