def cerate_test_enviroment(): TEST_MAPS = dict() TEST_POSITIONS = dict() for i in range(10): TEST_MAPS[i] = mapaAleatorio(N_STATIONS, N_STATES) for i in range(10): positions_list = random.sample(range(1, N_STATIONS), N_CARS+1) positions = list() for station in positions_list: positions.append("estacion_" + str(station)) TEST_POSITIONS[i] = positions save_obj(TEST_POSITIONS, "TEST_POSITIONS") save_obj(TEST_MAPS, "TEST_MAPS")
position = POSITIONS[id_car] capacity = random.randint(5,20) #TO DO: each car have their on capcity car = Car( id_car, position, capacity ) FLEET.insertCar(car) FLEET.update_carsPosition() #Save car positions in FLEET.positions MAP.update_available_stations(FLEET) #Remove car positio and car subsytem from available_stations FLEET.assignArea(MAP) #Assign subsystem to each car FLEET.solve_subsystems(MAP, SOLUCIONES, N_STATIONS, N_STATES) ts = time.time() MIN_COST, FLEET_MIN = subsystem_distribution_gradientOptimization(FLEET, MAP, SOLUCIONES, N_STATIONS, N_STATES, C, E) time_f = time.time() - ts RESULT_GRADIENT[name_config] = dict() RESULT_GRADIENT[name_config]["FLEET"] = FLEET_MIN RESULT_GRADIENT[name_config]["POSITIONS"] = POSITIONS RESULT_GRADIENT[name_config]["TIME"] = time_f RESULT_GRADIENT[name_config]["SCORE"] = MIN_COST save_obj(RESULT_GRADIENT, name) save_obj(RESULT_GRADIENT, name) print("MODELO GUARDADO")
name = "MAP" + i + "_POSITION" +j try: print(RESULTS_GENETIC[name]) except Exception as e: POSITIONS = TEST_POSITIONS[j] print("\n\tExecuting POSITIONS: ", POSITIONS) ts = time.time() POPULATION_X, solution = utils_genetic.solve_genetic_algorithm( N, PC, PM, MAX_ITERATIONS, MAP, N_STATIONS, AREA_SIZE, MAX_COBERTURE, N_CARS, N_STATES, SOLUCIONES, POSITIONS ) time = time.time() - ts RESULTS_GENETIC[name] = dict() RESULTS_GENETIC[name]["FLEET"] = POPULATION_X["FLEET"] RESULTS_GENETIC[name]["POSITIONS"] = POSITIONS RESULTS_GENETIC[name]["TIME"] = time RESULTS_GENETIC[name]["SCORE"] = POPULATION_X["FLEET"].accumulated_cost save_obj(RESULTS_GENETIC, "RESULTS_GENETIC") """ RESULT_ITERATIVE = dict() for i in TEST_MAPS.keys(): MAP = TEST_MAPS[i] print("Executing MAP: ",i) for j in TEST_POSITIONS.keys(): POSITIONS = TEST_POSITIONS[j] print("\n\tExecuting POSITIONS: ", POSITIONS) ts = time.time() subsytem_distribution_iterativeOptimization(N_ITERATION,FLEET, MAP, SOLUCIONES) time = time.time() - ts name = "MAP" + i + "_POSITION" +j
FLEET = Fleet(AREA_SIZE, MAX_COBERTURE, N_STATIONS) # We assign a random station for each car for j in range(N_CARS): id_car = j position = POSITIONS[id_car] capacity = random.randint( 5, 20) #TO DO: each car have their on capcity car = Car(id_car, position, capacity) FLEET.insertCar(car) FLEET.update_carsPosition( ) #Save car positions in FLEET.positions MAP.update_available_stations( FLEET ) #Remove car positio and car subsytem from available_stations FLEET.assignArea(MAP) #Assign subsystem to each car FLEET.solve_subsystems(MAP, SOLUCIONES, N_STATIONS, N_STATES) ts = time.time() MIN_COST, FLEET_MIN = subsytem_distribution_iterativeOptimization( N_ITERATION, FLEET, MAP, SOLUCIONES, N_STATIONS, N_STATES) time_f = time.time() - ts RESULT_ITERATIVE[name] = dict() RESULT_ITERATIVE[name]["FLEET"] = FLEET_MIN RESULT_ITERATIVE[name]["POSITIONS"] = POSITIONS RESULT_ITERATIVE[name]["TIME"] = time_f RESULT_ITERATIVE[name]["SCORE"] = MIN_COST save_obj(RESULT_ITERATIVE, name)
if SCORES[estado][area]["gradient_model"][ "min_time"] > execution_time: SCORES[estado][area]["gradient_model"][ "min_time"] = execution_time if SCORES[estado][area]["gradient_model"][ "max_time"] < execution_time: SCORES[estado][area]["gradient_model"][ "max_time"] = execution_time finalSOLUCIONES = countSOLUCIONES(SOLUCIONES) print( "---------------- Se ahn agregado {} soluciones NUEVAS---------------" .format(startSOLUCIONES - finalSOLUCIONES)) utils_solver.save_obj(SCORES, 'SCORES_optimization') """ for estado in tqdm(n_estados, ascii= True, desc= "ITERATION TEST"): for area in n_subsystems: SOLUCIONES = dict() #We are going to delete the stations that are over the 7 decil. MAX_COBERTURE = round(estado*.7) for iter in range(SECUENTIAL_ITERATIONS): #The FLEET.position (position of each car) and the System must be constant for the optimization of S #but they have to change for each iter in SECUENTIAL_ITERATIONS. MAP = Map(N_STATIONS, N_STATES) #Always the same size. FLEET = Fleet(area, MAX_COBERTURE) MAP.update_available_stations(FLEET) #Remove car positio and car subsytem from available_stations