def run(self): #First let's read our config file, in this case a yaml file yaml = yamlFile.ReadYaml() #Initialization of storage class, passing the configuration storage = dbStorage.Storage(yaml) #Initialization of the Genetic algorithm for seeking the solution genetic = algorithm.GeneticAlgorithm(self.__queens) #Finally , print the solution myPrinter = printer.Printer(genetic, storage)
def loadDataset(): dataset = fh.readFile(globals.INPUT_FILE) ga = GA.GeneticAlgorithm(globals.CROSSOVER_RATE) # individuo = GA.Individual(4, 0) # ind.printIndividual() population = GA.Population() ind_count = 0 jump = 0 # Itera sobre cada um dos individuos da populacao for ind in range(globals.MAX_INDIVIDUALS): # Salto para corrigir a posicao da linha no dataset jump = ind * globals.LINES_PER_SINGLE_INDIVIDUAL # Para cada uma das caracteristicas for i in range(globals.LINES_PER_SINGLE_INDIVIDUAL): if i == globals.WINDOW: for j in range(len(dataset[0])): population.getIndividual(ind).setWindow( j, dataset[i + jump][j]) population.getIndividual(ind).setWeight(j) elif i == globals.KLINE: for j in range(len(dataset[i])): population.getIndividual(ind).setKline( j, dataset[i + jump][j]) elif i == globals.REQUEST_BEGINNING: for j in range(len(dataset[i])): population.getIndividual(ind).setReqBegin( j, dataset[i + jump][j]) elif i == globals.REQUEST_ENDING: for j in range(len(dataset[i])): population.getIndividual(ind).setReqEnd( j, dataset[i + jump][j]) elif i == globals.STATION: for j in range(len(dataset[i])): population.getIndividual(ind).setStation( j, dataset[i + jump][j]) elif i == globals.WINDOW_BEGINNING: for j in range(len(dataset[i])): population.getIndividual(ind).setWindowBegin( j, dataset[i + jump][j]) elif i == globals.WINDOW_ENDING: for j in range(len(dataset[i])): population.getIndividual(ind).setWindowEnd( j, dataset[i + jump][j]) return population
def initGA(dimensions, population_size, i_max, tournament_size, parent_num, precision, encoder, stride): """ starts Simulated Annealing for each blackbox and writes output to csv file Parameters ---------- dimensions : dictionary key: blackbox_id value: size of input vector Returns ------- None. """ for bb_id, bb_dim in dimensions.items(): process = runBlackBox(bb_id) gaInstance = ga.GeneticAlgorithm(population_size, i_max, tournament_size, parent_num, precision, encoder, stride) gaInstance.initGA(process, bb_dim) writeCSV(gaInstance.avg, bb_id, encoder) process.terminate()
def setUp(self): self.ga = geneticAlgorithm.GeneticAlgorithm(0)
# the tolerance of the times of camera off Kca = 3 if __name__ == "__main__": # Create a 3D Occupancy Grid print( '\033[94m Generating random occupancy grid and objectives... \033[0m') occ_grid, obstacle_num = map_generate(grid_x, grid_y, grid_z, starting_point, end_point, safety_threshold, privacy_threshold) print(occ_grid) pri_grid, privacy_sum = privacy_init(grid_x, grid_y, grid_z, occ_grid, privacy_radius) print(pri_grid) objectives = [end_point] alg = gA.GeneticAlgorithm(population, 0.00001, 5, 2, 40, grid_map) print('\033[94m Generating random initial solutions... \033[0m') paths = alg.init_population(starting_point, objectives, Kca) for p in range(len(paths)): paths[p].fitness = alg.get_fitness(paths[p], occ_grid, pri_grid, starting_point, end_point, privacy_sum, obstacle_num) max_p = max(paths, key=lambda x: x.fitness) max_f = -5 count = 0 fitnv = [] print(len(paths))