Exemple #1
0
 def test_fitness_positive_fitness_high_values(self):
     genes = [Gene(6, 1, True), Gene(8, 2, True), Gene(4, 3, True)]
     chromosome = Chromosome(genes)
     score = chromosome.fitness_score(
         BoundedKnapsackGA.fitness_func(BoundedKnapsackGA.MAX_WEIGHT))
     other_genes = [Gene(2, 1, True), Gene(3, 2, True), Gene(4, 3, True)]
     other_chromosome = Chromosome(other_genes)
     other_score = other_chromosome.fitness_score(
         BoundedKnapsackGA.fitness_func(BoundedKnapsackGA.MAX_WEIGHT))
     self.assertTrue(score > 0 and score > other_score)
Exemple #2
0
 def test_fitness_func_bad_fitness(self):
     genes = [Gene(1, 5, True), Gene(2, 8, True), Gene(3, 2, True)]
     chromosome = Chromosome(genes)
     score = chromosome.fitness_score(
         BoundedKnapsackGA.fitness_func(BoundedKnapsackGA.MAX_WEIGHT))
     self.assertTrue(score == 0)
Exemple #3
0
 def test_fitness_func_with_reward(self):
     genes = [Gene(2, 1, True), Gene(3, 2, True), Gene(4, 3, True)]
     chromosome = Chromosome(genes)
     score = chromosome.fitness_score(
         BoundedKnapsackGA.fitness_func(BoundedKnapsackGA.MAX_WEIGHT))
     self.assertTrue(score > 0)