Exemplo n.º 1
0
 def test_get_best_not_natural(self):
     candidate1 = Candidate()
     candidate1.fitness = Fitness(-1, is_natural=False)
     candidate2 = Candidate()
     candidate2.fitness = Fitness(-2, is_natural=False)
     result = Population([candidate1, candidate2]).get_best()
     self.assertEqual(result, candidate2)
     result = Population([candidate2, candidate1]).get_best()
     self.assertEqual(result, candidate2)
Exemplo n.º 2
0
 def test_sort_by_fitness_not_natural(self):
     candidate1 = Candidate()
     candidate1.fitness = Fitness(-1, is_natural=False)
     candidate2 = Candidate()
     candidate2.fitness = Fitness(-2, is_natural=False)
     population = Population([candidate2, candidate1])
     population.sort_by_fitness()
     self.assertEqual(population[0], candidate1)
     self.assertEqual(population[1], candidate2)
Exemplo n.º 3
0
def setup(goals, constraints, configs, \
    repair_function=None):
    # Update services with problem and functions.
    ga_configs.configs = configs
    problem_service.goals = goals
    problem_service.constraints = constraints
    problem_service.repair_function = repair_function
    population_service.population = Population()
    plot_service.plot = Plot()
    datalogger_service.init_logfile()
Exemplo n.º 4
0
 def test_sort_by_fitness_empty(self):
     population = Population()
     population.sort_by_fitness()
Exemplo n.º 5
0
 def test_add(self):
     self.assertIsInstance(Population() + Population(), Population)
Exemplo n.º 6
0
 def test_get_best_empty(self):
     population = Population()
     result = population.get_best()
     self.assertEqual(result, None)