def generate_cc_data(no_trials, no_cities, lower_bound, upper_bound, sa_iterations): random_cities = generate_cities(25) initial_config = list(range(len(random_cities))) results = [] T_RANGE = upper_bound - lower_bound baseline_solution, baseline_cost = None, float('inf') for i in tqdm(range(no_trials)): random.shuffle(initial_config) t = random.random()*T_RANGE + lower_bound solution,cost = solve_tsp_simulated_annealing(random_cities, sa_iterations, t, initial_configuration=initial_config) results.append((t, cost)) _, new_baseline_cost = solve_tsp_hill_climbing(random_cities, sa_iterations, initial_configuration=initial_config) baseline_cost = min(new_baseline_cost, baseline_cost) print('Baseline cost: ', baseline_cost) temps, costs = zip(*results) return temps, costs, baseline_cost
def test_square(self): points = [(0, 0), (1, 0), (1, 1), (0, 1)] solution, cost = solve_tsp_hill_climbing(points, 100, initial_configuration=[0, 2, 1, 3]) self._assert_cyclic_equals(solution, [0, 1, 2, 3])