Beispiel #1
0
 def test_fitness_function_returns_float(self):
     """
     Makes sure the generated fitness function returns a fitness score as a
     float.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     result = fitness_function(genome)
     self.assertTrue(float, type(result))
Beispiel #2
0
 def test_fitness_function_returns_float(self):
     """
     Makes sure the generated fitness function returns a fitness score as a
     float.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     result = fitness_function(genome)
     self.assertTrue(float, type(result))
Beispiel #3
0
 def test_fitness_function_uses_cached_genome_fitness(self):
     """
     Ensures the fitness function bails if there is already a score set for
     the genome.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Beispiel #4
0
 def test_fitness_function_uses_cached_genome_fitness(self):
     """
     Ensures the fitness function bails if there is already a score set for
     the genome.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Beispiel #5
0
 def test_fitness_function_sets_fitness_on_genome(self):
     """
     Ensures the fitness score is set in the genome's fitness attribute and
     is the same as the returned fitness score.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     self.assertEqual(None, genome.fitness)
     result = fitness_function(genome)
     self.assertNotEqual(None, genome.fitness)
     self.assertEqual(result, genome.fitness)
Beispiel #6
0
 def test_fitness_function_sets_fitness_on_genome(self):
     """
     Ensures the fitness score is set in the genome's fitness attribute and
     is the same as the returned fitness score.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     self.assertEqual(None, genome.fitness)
     result = fitness_function(genome)
     self.assertNotEqual(None, genome.fitness)
     self.assertEqual(result, genome.fitness)
Beispiel #7
0
 def test_make_fitness_function_returns_callable(self):
     """
     Ensures the make_fitness_function returns a callable.
     """
     result = make_fitness_function(CANTUS_FIRMUS)
     self.assertTrue(callable(result))
Beispiel #8
0
 def test_make_fitness_function_returns_callable(self):
     """
     Ensures the make_fitness_function returns a callable.
     """
     result = make_fitness_function(CANTUS_FIRMUS)
     self.assertTrue(callable(result))
Beispiel #9
0
    args = parser.parse_args()
    cf = [int(x) for x in args.cantus_firmus]
    species = args.species
    output = 'out'
    if args.out:
        output = args.out

    population_size = 1000
    mutation_range = 7
    mutation_rate = 0.4
    if species == 1:
        population_size = first.DEFAULT_POPULATION_SIZE
        mutation_range = first.DEFAULT_MUTATION_RANGE
        mutation_rate = first.DEFAULT_MUTATION_RATE
        start_population = first.create_population(population_size, cf)
        fitness_function = first.make_fitness_function(cf)
        generate_function = first.make_generate_function(mutation_range,
            mutation_rate, cf)
        halt_function = first.halt
    elif species == 2:
        population_size = second.DEFAULT_POPULATION_SIZE
        mutation_range = second.DEFAULT_MUTATION_RANGE
        mutation_rate = second.DEFAULT_MUTATION_RATE
        start_population = second.create_population(population_size, cf)
        fitness_function = second.make_fitness_function(cf)
        generate_function = first.make_generate_function(mutation_range,
            mutation_rate, cf)
        halt_function = second.make_halt_function(cf)
    elif species == 3:
        population_size = third.DEFAULT_POPULATION_SIZE
        mutation_range = third.DEFAULT_MUTATION_RANGE