예제 #1
0
 def test_evaluate_population(self):
     protogene = ProtoGene(IntGene, 'a', min_value=0, max_value=100)
     protogenome = ProtoGenome([protogene])
     algo = GeneticAlgorithm(protogenome, fitness_evaluator, termination_criteria=convergence_stop)
     algo.initialize()
     algo.evaluate_population()
     for individual in algo.population.individuals:
         assert individual.score == fitness_evaluator(individual)
예제 #2
0
 def test_evolve_population(self):
     protogene = ProtoGene(IntGene, 'a', min_value=0, max_value=10)
     protogenome = ProtoGenome([protogene])
     algo = GeneticAlgorithm(protogenome, fitness_evaluator, termination_criteria=convergence_stop)
     algo.initialize()
     algo.evaluate_population()
     g1 = algo.generation
     algo.evolve_population()
     g2 = algo.generation
     assert g1 == 0 and g2 == 1
예제 #3
0
    def test_best_individual(self):
        protogene = ProtoGene(IntGene, 'a', min_value=0, max_value=100)
        protogenome = ProtoGenome([protogene])
        algo = GeneticAlgorithm(protogenome, fitness_evaluator, termination_criteria=convergence_stop)
        algo.initialize()
        for i, individual in enumerate(algo.population.individuals):
            individual.set_value('a', i)
        algo.evaluate_population()

        bi = algo.best_individual()
        assert bi.score == 0