Exemplo n.º 1
0
def grasp(parameters, num_vertices, num_groups, groups_limits,
          vertices_weights, edges):
    # Parameters
    num_iter = int(parameters[0])
    restricted_candidate_list_size = int(parameters[1])
    num_local_iter = int(parameters[2])
    
    # Current best value
    best_value = 0.0

    # Getting time elapsed
    start = time()

    for i in range(int(num_iter)):
        print("GRASP iteration - " + str(i))
        groups = greedy_randomized(restricted_candidate_list_size, num_vertices, num_groups,
                                    groups_limits, vertices_weights, edges)
        initial_solution = deepcopy(groups)
        groups = local_search(num_local_iter, groups, edges, groups_limits)
        new_value = check_group_value(groups, edges)
        if (new_value > best_value):
            best_solution = deepcopy(groups)
            best_initial_solution = deepcopy(initial_solution)
            best_value = new_value

    end = time()
    time_elapsed = end - start
    
    return best_solution, best_initial_solution, time_elapsed
Exemplo n.º 2
0
                total_capacity, num_customers_depot,
                pop_particle_velocity_list, pop_particle_position_list, M)

            flag, arr_results, arr_pbest_results, pop_particle_routeList_list, pop_particle_position_list, pop_particle_distance_list, pop_distance_list, pop_num_route_list, arr_gbest_result, gbest_velocity_list, gbest_position_list, gbest_routeList_list, gbest_distance_list, gbest_tracker, pbest_particle_routeList_list, pbest_particle_position_list, pbest_particle_distance_list, pbest_distance_list, pbest_num_route_list, pbest_particle_velocity_list = CLPSO_result_updater(
                M, arr_results, arr_pbest_results, flag,
                pop_particle_velocity_list, position_resultslist,
                arr_gbest_result, gbest_velocity_list, gbest_position_list,
                gbest_routeList_list, gbest_distance_list, gbest_tracker,
                pbest_particle_routeList_list, pbest_particle_position_list,
                pbest_particle_distance_list, pbest_distance_list,
                pbest_num_route_list, pbest_particle_velocity_list)

            #LOCAL SEARCH
            local_search_results_list = local_search(
                M, num_cores, df_customers, arr_distance_matrix, total_time,
                total_capacity, pop_distance_list, pop_num_route_list,
                pop_particle_routeList_list, pop_particle_distance_list,
                pop_particle_position_list, pop_particle_velocity_list,
                arr_customer_info, service_time)

            flag, arr_results, arr_pbest_results, pop_particle_routeList_list, pop_particle_position_list, pop_particle_velocity_list, pop_particle_distance_list, pop_distance_list, pop_num_route_list, arr_gbest_result, gbest_velocity_list, gbest_position_list, gbest_routeList_list, gbest_distance_list, gbest_tracker, pbest_particle_routeList_list, pbest_particle_position_list, pbest_particle_distance_list, pbest_distance_list, pbest_num_route_list, pbest_particle_velocity_list = local_search_result_updater(
                local_search_results_list, flag, arr_results,
                arr_pbest_results, pop_particle_velocity_list,
                pop_particle_routeList_list, pop_particle_position_list,
                pop_particle_distance_list, pop_distance_list,
                pop_num_route_list, arr_gbest_result, gbest_velocity_list,
                gbest_position_list, gbest_routeList_list, gbest_distance_list,
                gbest_tracker, pbest_particle_routeList_list,
                pbest_particle_position_list, pbest_particle_distance_list,
                pbest_distance_list, pbest_num_route_list,
                pbest_particle_velocity_list)