def msls(points, dist_matrix): result_dict = {} for i in range(100): groups = random_heuristic(points, dist_matrix) groups = local_search_steep(groups, dist_matrix) result_dict[sum_all_groups_fully_connected(groups, dist_matrix)] = groups return result_dict[min(result_dict)]
def ils_big(max_time, points, dist_matrix): timepoint = time.time() groups = random_heuristic(points, dist_matrix) previous_groups = local_search_steep(groups, dist_matrix) destroy_number = random.randint(int(len(points) * 0.1), int(len(points) * 0.3)) while get_time(timepoint) < max_time: new_groups, deleted = destroy(copy.deepcopy(previous_groups), destroy_number) new_groups = repair(new_groups, deleted, dist_matrix) new_groups = local_search_steep(new_groups, dist_matrix) if (sum_all_groups_fully_connected(new_groups, dist_matrix) < sum_all_groups_fully_connected(previous_groups, dist_matrix)): previous_groups = new_groups return previous_groups
def ils_small(max_time, points, dist_matrix): timepoint = time.time() groups = random_heuristic(points, dist_matrix) previous_groups = local_search_steep(groups, dist_matrix) swap_number = random.randint(2, 10) while get_time(timepoint) < max_time: # print(get_time(timepoint)) new_groups = swap_points(swap_number, copy.deepcopy(previous_groups)) new_groups = local_search_steep(new_groups, dist_matrix) if (sum_all_groups_fully_connected(new_groups, dist_matrix) < sum_all_groups_fully_connected(previous_groups, dist_matrix)): if swap_number > 1: swap_number -= 1 previous_groups = new_groups else: if swap_number < int(len(points) * 0.1): swap_number += 1 # print(swap_number) return previous_groups
def get_n_msls_solutions(points, dist_matrix, n): results = [] for i in range(n): if i % 20 == 0: print(i) groups = random_heuristic(points, dist_matrix) groups = local_search_steep(groups, dist_matrix) results.append({ 'groups': groups, 'result': sum_all_groups_fully_connected(groups, dist_matrix), 'best_sim': 0, 'ave_sim': 0 }) return results
def get_solution(points, dist_matrix): groups = random_heuristic(points, dist_matrix) solution = local_search_steep(groups, dist_matrix) # print(1) return solution