def test_evaluate_fitness(self):

        #   test whether select from fitness selections works

        self.assertEqual(.5, self.ges._max_fitness_rate)

        self.ges.set_fitness_selections(
            FitnessElites(self.ges.fitness_list, .1))

        pool = self.ges._evaluate_fitness()
        self.assertEqual(1, len(pool))

        #   test whether max fitness rate works
        self.ges.set_fitness_selections(
            FitnessElites(self.ges.fitness_list, .75))

        pool = self.ges._evaluate_fitness()
        self.assertEqual(3, len(pool))
    def test_evaluate_fitness(self):

        #   test whether select from fitness selections works

        self.assertEqual(.5, self.ges._max_fitness_rate)

        self.ges.set_fitness_selections(
            FitnessElites(self.ges.fitness_list, .1))

        pool = self.ges._evaluate_fitness()
        #self.assertEqual(1, len(pool)) # TODO: what's going on here? apparently it has to be reduced by one for python 3.x?
        self.assertEqual(0, len(pool))

        #   test whether max fitness rate works
        self.ges.set_fitness_selections(
            FitnessElites(self.ges.fitness_list, .75))

        pool = self.ges._evaluate_fitness()
        #self.assertEqual(3, len(pool)) # TODO: what's going on here? apparently it has to be reduced by one for python 3.x?
        self.assertEqual(2, len(pool))
Ejemplo n.º 3
0
    def test_classinit_(self):
        self.assertRaises(ValueError,
                          FitnessElites,
                          self.fitness_list,
                          rate=1.1)
        self.assertRaises(ValueError,
                          FitnessElites,
                          self.fitness_list,
                          rate=-1.1)
        self.assertRaises(ValueError,
                          FitnessElites,
                          self.fitness_list,
                          rate=0.0)

        fit = FitnessElites(self.fitness_list, rate=0.1)
        self.assertAlmostEqual(0.1, fit._rate)
        self.assertAlmostEqual(MIN, fit._selection_type)
ges.set_bnf(bnf)
ges.set_genotype_length(start_gene_length=20, max_gene_length=50)
ges.set_population_size(50)
ges.set_wrap(True)

ges.set_max_generations(1000)
ges.set_fitness_type(MIN, .01)

ges.set_max_program_length(500)
ges.set_timeouts(10, 120)
ges.set_fitness_fail(100.0)

ges.set_mutation_rate(.025)
ges.set_fitness_selections(
    FitnessElites(ges.fitness_list, .05),
    FitnessTournament(ges.fitness_list, tournament_size=2))
ges.set_max_fitness_rate(.5)

ges.set_crossover_rate(.2)
ges.set_children_per_crossover(2)
ges.set_mutation_type('m')
ges.set_max_fitness_rate(.25)

ges.set_replacement_selections(
    ReplacementTournament(ges.fitness_list, tournament_size=3))

ges.set_maintain_history(True)
ges.create_genotypes()
print ges.run()
print ges.fitness_list.sorted()
Ejemplo n.º 5
0
 def test_select(self):
     fit = FitnessElites(self.fitness_list, rate=0.3333)
     count = len([i for i in fit.select()])
     self.assertEqual(1, count)
Ejemplo n.º 6
0
 def test_set_rate(self):
     fit = FitnessElites(self.fitness_list, rate=0.1)
     self.assertAlmostEqual(0.1, fit._rate)
 def test_select(self):
     fit = FitnessElites(self.fitness_list, rate=0.3333)
     count = len([i for i in fit.select()])
     self.assertEqual(1, count)