Пример #1
0
def test_best_individual_returned(one_island):
    generator = MultipleValueChromosomeGenerator(generate_zero,
                                                 VALUE_LIST_SIZE)
    best_indv = generator()
    one_island.load_population([best_indv], replace=False)
    archipelago = SerialArchipelago(one_island)
    assert archipelago.test_for_convergence(error_tol=ERROR_TOL)
    assert archipelago.get_best_individual().fitness == 0
Пример #2
0
def island():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    selection = Tournament(10)
    fitness = MultipleValueFitnessFunction()
    evaluator = Evaluation(fitness)
    ev_alg = MuPlusLambda(evaluator, selection, crossover, mutation, 0.2, 0.4,
                          20)
    generator = MultipleValueChromosomeGenerator(mutation_function, 10)
    return Island(ev_alg, generator, 25)
Пример #3
0
def test_multiple_indviduals_added_to_pop(init_replication_variation,
                                          weaker_population):
    indvs_added = 2
    generator = MultipleValueChromosomeGenerator(
        true_multiple_variation_function, COMPLEX_INDV_SIZE)
    rand_indv_var_or = AddRandomIndividualVariation(init_replication_variation,
                                                    generator,
                                                    num_rand_indvs=indvs_added)
    offspring = rand_indv_var_or(weaker_population, POP_SIZE)
    count = 0
    for indv in offspring:
        if all(indv.values):
            count += 1
    assert count == indvs_added
Пример #4
0
def test_age_fitness_ea_step(pareto_front_population, onemax_evaluator,
                             selected_indiviudals):
    population = pareto_front_population + selected_indiviudals
    mutation = DumbyMutation()
    crossover = DumbyCrossover()
    generator = MultipleValueChromosomeGenerator(return_false,
                                                 COMPLEX_INDV_SIZE)
    evo_alg = AgeFitnessEA(onemax_evaluator,
                           generator,
                           crossover,
                           mutation,
                           0,
                           0,
                           len(pareto_front_population),
                           selection_size=2 * len(population))
    new_population = evo_alg.generational_step(population)
    assert len(new_population) == len(population)
Пример #5
0
def population():
    generator = MultipleValueChromosomeGenerator(mutation_onemax_specific, 10)
    return [generator() for i in range(25)]
Пример #6
0
def true_chromosome_generator():
    return MultipleValueChromosomeGenerator(true_variation_function,
                                            SIMPLE_INDV_SIZE)
Пример #7
0
def weaker_population():
    generator = MultipleValueChromosomeGenerator(false_variation_function,
                                                 COMPLEX_INDV_SIZE)
    return [generator() for i in range(25)]
def unfit_generator():
    return MultipleValueChromosomeGenerator(return_false, 10)
Пример #9
0
def weak_individual():
    generator = MultipleValueChromosomeGenerator(return_false,
                                                 SIMPLE_INDV_SIZE)
    indv = generator()
    indv.genetic_age = 100
    return indv
Пример #10
0
def create_chromosome_generator():
    return MultipleValueChromosomeGenerator(generate_0_or_1,
                                            values_per_chromosome=16)
Пример #11
0
def population():
    generator = MultipleValueChromosomeGenerator(mutation_function, 10)
    return [generator() for _ in range(25)]
def generator():
    return MultipleValueChromosomeGenerator(np.random.random, 10)
def test_generator():
    generator = MultipleValueChromosomeGenerator(mutation_onemax_specific, 10)
    pop = [generator() for i in range(20)]
    assert len(pop) == 20
    assert len(pop[0].values) == 10
def mixed_fit_generator():
    return MultipleValueChromosomeGenerator(mutation_function, 10)
Пример #15
0
def fit_individual():
    generator = MultipleValueChromosomeGenerator(return_true, SIMPLE_INDV_SIZE)
    indv = generator()
    return indv
Пример #16
0
def three_island(evol_alg):
    generator = MultipleValueChromosomeGenerator(generate_three,
                                                 VALUE_LIST_SIZE)
    return Island(evol_alg, generator, POP_SIZE)
Пример #17
0
def strong_population():
    generator = MultipleValueChromosomeGenerator(return_true, SIMPLE_INDV_SIZE)
    return [generator() for _ in range(INITIAL_POP_SIZE)]
Пример #18
0
def island(evol_alg):
    generator = MultipleValueChromosomeGenerator(mutation_function,
                                                 VALUE_LIST_SIZE)
    return Island(evol_alg, generator, POP_SIZE)
Пример #19
0
def weak_population():
    generator = MultipleValueChromosomeGenerator(return_false,
                                                 2 * SIMPLE_INDV_SIZE)
    return [generator() for _ in range(INITIAL_POP_SIZE)]
def fit_generator():
    return MultipleValueChromosomeGenerator(return_true, 10)