def test_function_represents_one_run_with_30_generations(bests_matrix, averages_matrix, max_gener, numb_runs,current_run): import init_pop import fitness sizes = numpy.array([5, 8, 4, 11, 6, 12]) max_size = 20 pop_size = 10 cromo_size = len(sizes) fitness_func = fitness.subset_fitness initial_pop = init_pop.init_pop(pop_size, cromo_size, init_pop.cromo_bin) population = fitness.eval_pop(initial_pop, fitness_func, sizes, max_size) #generation 1...30 generations for current_generation in range(max_gener): evaluate_generation(population, bests_matrix, averages_matrix,current_generation, current_run ) # population is reinitialized to simulate that a generation changed initial_pop = init_pop.init_pop(pop_size, cromo_size, init_pop.cromo_bin) population = fitness.eval_pop(initial_pop, fitness_func, sizes, max_size)
def test_function_represents_one_run_with_30_generations( bests_matrix, averages_matrix, max_gener, numb_runs, current_run): import init_pop import fitness sizes = numpy.array([5, 8, 4, 11, 6, 12]) max_size = 20 pop_size = 10 cromo_size = len(sizes) fitness_func = fitness.subset_fitness initial_pop = init_pop.init_pop(pop_size, cromo_size, init_pop.cromo_bin) population = fitness.eval_pop(initial_pop, fitness_func, sizes, max_size) #generation 1...30 generations for current_generation in range(max_gener): evaluate_generation(population, bests_matrix, averages_matrix, current_generation, current_run) # population is reinitialized to simulate that a generation changed initial_pop = init_pop.init_pop(pop_size, cromo_size, init_pop.cromo_bin) population = fitness.eval_pop(initial_pop, fitness_func, sizes, max_size)
if __name__ == '__main__': import init_pop import fitness import parent_selection import crossover sizes = array([5, 8, 4, 11, 6, 12]) max_size = 20 pop_size = 10 cromo_size = len(sizes) fitness_func = fitness.subset_fitness select_parents = parent_selection.tournament_sel initial_pop = init_pop.init_pop(pop_size, cromo_size, init_pop.cromo_bin) population = fitness.eval_pop(initial_pop, fitness_func, sizes, max_size) mates = select_parents(population, pop_size, 3) prob_cross = 0.8 cross_method = crossover.one_point_cross, crossover.uniform_cross offspring = crossover.crossover(mates, prob_cross, cross_method[0]) offspring = fitness.eval_pop(offspring, fitness_func, sizes, max_size) select_survivors = survivors_steady_state population = select_survivors(population, offspring, 0.02) #[print (i) for i in offspring] print("pop:") #[print (i) for i in population]
if __name__ == '__main__': import init_pop import fitness import parent_selection import crossover sizes = array([5, 8, 4, 11, 6, 12]) max_size = 20 pop_size = 10 cromo_size = len(sizes) fitness_func = fitness.subset_fitness select_parents = parent_selection.tournament_sel initial_pop = init_pop.init_pop(pop_size, cromo_size, init_pop.cromo_bin) population = fitness.eval_pop(initial_pop, fitness_func, sizes, max_size) mates = select_parents(population,pop_size,3) prob_cross = 0.8 cross_method = crossover.one_point_cross, crossover.uniform_cross offspring = crossover.crossover(mates, prob_cross, cross_method[0]) offspring = fitness.eval_pop(offspring,fitness_func, sizes, max_size) select_survivors = survivors_steady_state population = select_survivors(population, offspring, 0.02) #[print (i) for i in offspring] print ("pop:") #[print (i) for i in population]