def search_loop(): """ This is a standard search process for an evolutionary algorithm. Loop over a given number of generations. :return: The final population after the evolutionary process has run for the specified number of generations. """ # Initialise population individuals = initialisation(params['POPULATION_SIZE']) # Evaluate initial population individuals = evaluate_fitness(individuals) # Generate statistics for run so far get_stats(individuals) # Traditional GE for generation in range(1, (params['GENERATIONS'] + 1)): stats['gen'] = generation # New generation individuals = params['STEP'](individuals) return individuals
def search_loop(): """ This is a standard search process for an evolutionary algorithm. Loop over a given number of generations. :return: The final population after the evolutionary process has run for the specified number of generations. """ if params['MULTICORE']: # initialize pool once, if mutlicore is enabled params['POOL'] = Pool(processes=params['CORES'], initializer=pool_init, initargs=(params,)) # , maxtasksperchild=1) # Initialise population individuals = initialisation(params['POPULATION_SIZE']) # Evaluate initial population individuals = evaluate_fitness(individuals) # Generate statistics for run so far get_stats(individuals) # Traditional GE for generation in range(1, (params['GENERATIONS']+1)): stats['gen'] = generation # New generation individuals = params['STEP'](individuals) if params['MULTICORE']: # Close the workers pool (otherwise they'll live on forever). params['POOL'].close() return individuals
def __init__(self, selection_proportion): self.current_generation = 0 self.individuals = sorted( evaluate_fitness(initialisation(params['POPULATION_SIZE']), current_generation=self.current_generation)) self.cut_off_count = int(len(self) * (1 - selection_proportion)) self.update_fittest_individuals() self.update_probabilities()
def __init__(self, ip): # Interaction probability received in constructor self.interaction_probability = ip # Only initialize single individual. Single agent can only have single genetic information self.individual = initialisation(1) # Evaluate the fitness for the the individual self.individual = evaluate_fitness(self.individual) # Flag which store the boolean value for other neighbouring agents found or not self.agents_found = False
def __init__(self, ip): # Interaction probability received in constructor self.interaction_probability = ip # Only initialize singel individual. Single agent can only have single genetic information self.individual = initialisation(1) # Evaluate the fitness for the the individual self.individual = evaluate_fitness(self.individual) # Flag which store the boolean value for other nebouring agents found or not self.agents_found = False
def search_loop(): """ This is a standard search process for an evolutionary algorithm. Loop over a given number of generations. :return: The final population after the evolutionary process has run for the specified number of generations. """ logf = open(params['FILE_PATH'] + "/log.csv", 'w') #190312: log set_M() #190307: our mod for learning multiplier if params['MULTICORE']: # initialize pool once, if mutlicore is enabled params['POOL'] = Pool(processes=params['CORES'], initializer=pool_init, initargs=(params, )) # , maxtasksperchild=1) # Initialise population individuals = initialisation(params['POPULATION_SIZE']) # Evaluate initial population individuals = evaluate_fitness(individuals) # Generate statistics for run so far get_stats(individuals) write_log(logf, 0, params['M'], individuals) #190312: log #write_best(0, params['M'], individuals) # Traditional GE for generation in range(1, (params['GENERATIONS'] + 1)): stats['gen'] = generation update_M(generation, individuals) # 190307: our mod for learning multiplier # New generation individuals = params['STEP'](individuals) write_log(logf, generation, params['M'], individuals) #190312: log #write_best(generation, params['M'], individuals) print("generation ", generation, "/", params['GENERATIONS'], " finished at ", datetime.datetime.now()) # 190313: timestamp if params['MULTICORE']: # Close the workers pool (otherwise they'll live on forever). params['POOL'].close() logf.close() return individuals
def search_loop(): """ This is a standard search process for an evolutionary algorithm. Loop over a given number of generations. :return: The final population after the evolutionary process has run for the specified number of generations. """ if params['MULTICORE']: # initialize pool once, if mutlicore is enabled params['POOL'] = ThreadPool( processes=params['CORES'], initializer=pool_init, initargs=(params, )) # , maxtasksperchild=1) Logger.log("Generation 0 starts. Initializing...") # Initialise population individuals = initialisation(params['POPULATION_SIZE']) # Evaluate initial population individuals = evaluate_fitness(individuals) # Generate statistics for run so far get_stats(individuals) # Cleanup after evaluation if 'cleanup' in dir(params['FITNESS_FUNCTION']): params['FITNESS_FUNCTION'].cleanup(individuals) # Traditional GE for generation in range(1, (params['GENERATIONS'] + 1)): stats['gen'] = generation params['CURRENT_EVALUATION'] = 0 params['CURRENT_GENERATION'] = generation Logger.log("Generation {0} starts...".format(generation)) # New generation individuals = params['STEP'](individuals) # Cleanup after evaluation if 'cleanup' in dir(params['FITNESS_FUNCTION']): params['FITNESS_FUNCTION'].cleanup(individuals) Logger.close_all() if params['MULTICORE']: # Close the workers pool (otherwise they'll live on forever). params['POOL'].close() return individuals