Exemple #1
0
 def test_returns_valid_genomes(self):
     """
     Checks the genomes returned by the create_population function are
     of the correct type.
     """
     result = create_population(1, CANTUS_FIRMUS)
     self.assertEqual(Genome, type(result[0]))
Exemple #2
0
 def test_returns_valid_genomes(self):
     """
     Checks the genomes returned by the create_population function are
     of the correct type.
     """
     result = create_population(1, CANTUS_FIRMUS)
     self.assertEqual(Genome, type(result[0]))
Exemple #3
0
 def test_uses_only_valid_intervals(self):
     """
     Tests that only valid consonant intervals are used.
     """
     valid_intervals = [2, 4, 5, 7, 9, 11]
     result = create_population(20, CANTUS_FIRMUS)
     for genome in result:
         for i in range(len(genome.chromosome)):
             contrapunctus_note = genome.chromosome[i]
             cantus_firmus_note = CANTUS_FIRMUS[i]
             interval = contrapunctus_note - cantus_firmus_note
             self.assertIn(interval, valid_intervals)
Exemple #4
0
 def test_uses_only_valid_intervals(self):
     """
     Tests that only valid consonant intervals are used.
     """
     valid_intervals = [2, 4, 5, 7, 9, 11]
     result = create_population(20, CANTUS_FIRMUS)
     for genome in result:
         for i in range(len(genome.chromosome)):
             contrapunctus_note = genome.chromosome[i]
             cantus_firmus_note = CANTUS_FIRMUS[i]
             interval = contrapunctus_note - cantus_firmus_note
             self.assertIn(interval, valid_intervals)
Exemple #5
0
 def test_returns_correct_number_of_genomes(self):
     """
     Ensures the correct number of genomes are returned by the function.
     """
     result = create_population(100, CANTUS_FIRMUS)
     self.assertEqual(100, len(result))
Exemple #6
0
 def test_returns_correct_number_of_genomes(self):
     """
     Ensures the correct number of genomes are returned by the function.
     """
     result = create_population(100, CANTUS_FIRMUS)
     self.assertEqual(100, len(result))
Exemple #7
0
if __name__ == '__main__':
    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