def __init__(self, distance_matrix, demand, truck_capacity, depot=0, initial_solution=None, initial_solution_strategy='random', neighborhood='2-opt-star', seed=None, tabu_size=None): CVRP.__init__(self, distance_matrix, demand, truck_capacity, depot, initial_solution, initial_solution_strategy, neighborhood, seed) self.tabu_size = tabu_size self.tabu = [self.current_solution_] self.current_cost_ = self._evaluate_solution(self.current_solution_) self.best_solution = self.current_solution_ self.best_cost = self.current_cost_
def get_solutions(self): cvrps = { "GUIDED_LOCAL_SEARCH": CVRP( self.data, local_search_metaheuristic=routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH, time_limit=self.time_limit), "TABU_SEARCH": CVRP( self.data, local_search_metaheuristic=routing_enums_pb2.LocalSearchMetaheuristic.TABU_SEARCH, time_limit=self.time_limit), "PATH_CHEAPEST_ARC": CVRP( self.data, first_solution_strategy=routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC) } future_solutions = {} for key, cvrp in cvrps.items(): future_solutions[key] = self.executor.submit(cvrp.get_solution) solutions = {} for key, future_solution in future_solutions.items(): solutions[key] = future_solution.result() return solutions
def __init__(self, distance_matrix, demand, truck_capacity, depot=0, initial_solution=None, initial_solution_strategy='random', neighborhood='2-opt-star', seed=None, t_max=100, t_min=0.01, cooling_function=(lambda (t, i): t * 0.99), max_iterations_at_each_t=50): CVRP.__init__(self, distance_matrix, demand, truck_capacity, depot, initial_solution, initial_solution_strategy, neighborhood, seed) self.t_max = float(t_max) self.t_min = float(t_min) self.cooling_function = cooling_function self.max_iterations_at_each_t = max_iterations_at_each_t
def cvrp(): mat, capacity, cities_nb, vehicules_nb, demand_matrix, coords = get_mat() # CVRP vrp = CVRP(vehicules_nb,cities_nb) if mat is None: vrp.create_data_model() else: vrp.pass_matrix(mat, demand_matrix,capacity) print(vrp.data) vrp_solve(vrp)
def call_stats_dev(arg1): print('VRP ou CVRP : ', end='') vrp_type = input() if vrp_type.upper() != 'VRP' and vrp_type.upper() != 'CVRP': raise Exception("Type de VRP non reconnu") dataset_name = None print('Chemin vers le fichier contenant les path : ', end='') path = input() if(os.path.isfile(path) == False): raise Exception("Chemin invalide") allPath = get_all_path(path) for line in allPath: dataset_name = os.path.basename(line[0]) mat, capacity, cities_nb, vehicules_nb, demand_matrix, coords = from_file_to_adj_matr(line[0]) if vrp_type.upper() == 'VRP': # VRP vrp = VRP(vehicules_nb,cities_nb) vrp.pass_matrix(mat) elif vrp_type.upper() == 'CVRP': # CVRP vrp = CVRP(vehicules_nb,cities_nb) vrp.pass_matrix(mat, demand_matrix,capacity) path_cost = line[1] if(os.path.isfile(path_cost) == False): raise Exception("Chemin invalide") cost = get_particular_info(path_cost, 'cost') print(line[0], line[1]) execution_quality_cities(algos_metaheuristic, vrp, cities_nb, dataset_name, cost)
def call_stats(arg1): print('VRP ou CVRP : ', end='') vrp_type = input() if vrp_type.upper() != 'VRP' and vrp_type.upper() != 'CVRP': raise Exception("Type de VRP non reconnu") dataset_name = None if arg1.upper()== "TIMECITIESQ": random = False else: random = query_yes_no("Générer une matrice aléatoirement ?") if not random: print('Chemin vers le fichier : ', end='') path = input() if(os.path.isfile(path) == False): raise Exception("Chemin invalide") dataset_name = os.path.basename(path) mat, capacity, cities_nb, vehicules_nb, demand_matrix, coords = from_file_to_adj_matr(path) else: print('Entrez le nombre de villes : ', end='') cities_nb = int(input()) print('Entrez le nombre de véhicules : ', end='') vehicules_nb = int(input()) dataset_name = "random-k" + str(vehicules_nb) + "-n" + str(cities_nb) if vrp_type.upper() == 'VRP': # VRP vrp = VRP(vehicules_nb,cities_nb) if random: vrp.create_data_model() else: vrp.pass_matrix(mat) elif vrp_type.upper() == 'CVRP': # CVRP vrp = CVRP(vehicules_nb,cities_nb) if random: vrp.create_data_model() else: vrp.pass_matrix(mat, demand_matrix,capacity) if arg1.upper()== "TIMESOLUTIONS": solutionsLimitArray = [] while True: print('Appuyez sur enter pour arreter l ajout de solution... ') print('Entrez un nombre dans le tableau de solutions locales max : ', end='') tempLimit = input() if tempLimit.isnumeric(): solutionsLimitArray.append(int(tempLimit)) else: print("Fin de l'entrée, tableau : " , solutionsLimitArray) break execution_time_solutions(algos_metaheuristic, vrp, solutionsLimitArray, dataset_name) elif arg1.upper()== "TIMEVEHICULES": for i in tqdm(range(vehicules_nb)): execution_time_vehicules(algos_metaheuristic, vrp, i, dataset_name) elif arg1.upper()== "TIMECITIES": for i in tqdm(range(cities_nb)): execution_time_cities(algos_metaheuristic, vrp, i, dataset_name) elif arg1.upper()== "TIMECITIESQ": print('Chemin vers le fichier de la solution: ', end='') path_cost = input() if(os.path.isfile(path_cost) == False): raise Exception("Chemin invalide") cost = get_particular_info(path_cost, 'cost') execution_quality_cities(algos_metaheuristic, vrp, cities_nb, dataset_name, cost) print('Appuyez sur entrée pour continuer...') input()
from vrp import VRP from cvrp import CVRP filename = 'PL' if __name__ == '__main__': print("\nVRP: ") vrp = VRP(filename) vrp.calculate_best_base_location() print("\nCVRP: ") cvrp = CVRP(filename) cvrp.calculate_best_base_location()