Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0

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]
Exemplo n.º 4
0

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]
Exemplo n.º 5
0
def tournament(population,t_size):
    """Deterministic. Maximization"""
    #print(population)
    #print(t_size)

    pool = random.sample(population, t_size)
    pool.sort(key=itemgetter(1), reverse=True)
    return pool[0]


if __name__ == '__main__':
    import init_pop
    import fitness
    from numpy import *
    import random

    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     = 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)
    print("len(population)="+str(len(population)))
    mates = select_parents(population,pop_size,3)
    print("len(mates)="+str(len(mates)))
    print (mates == population)

Exemplo n.º 6
0
def tournament(population, t_size):
    """Deterministic. Maximization"""
    #print(population)
    #print(t_size)

    pool = random.sample(population, t_size)
    pool.sort(key=itemgetter(1), reverse=True)
    return pool[0]


if __name__ == '__main__':
    import init_pop
    import fitness
    from numpy import *
    import random

    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 = 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)
    print("len(population)=" + str(len(population)))
    mates = select_parents(population, pop_size, 3)
    print("len(mates)=" + str(len(mates)))
    print(mates == population)