5
desired = ['a','b','c','d','b',-1,.25,.6, .8, 0]
7
actual = self.get_values()
8
pairs = zip(actual[:5],desired[:5])
12
pairs = zip(actual[5:],desired[5:])
19
""" This example illustrates the main steps in setting
20
up a genetic optimization:
22
1. Specify the genes types used to encode your problem
23
2. Group these genes into a genome.
24
a. Specify the fitness function that evaluates the genomes.
25
3. Create a population of the genomes
26
4. Specify the algorithm used to evolve the population
30
# 1. First scpecify your genes. To gene types are
31
# currently supported, list_gene and float_gene
33
# A list gene chooses its value from a list of values.
34
# The list can contain any type of object.
35
g1 = ga.gene.list_gene(['a','b','c','d'])
36
# Float genes take on a continuous value between two
38
g2 = ga.gene.float_gene((-1.,1.))
39
# We'll replicate these genes several times to make a longer
41
all_genes = g1.replicate(5) + g2.replicate(5)
42
# 2. Create a specialized "list_genome" (as opposed to tree_genome)
43
# class with the desired fitness function.
44
# It's structure is defined by our gene list.
45
class this_genome(ga.genome.list_genome):
47
this_genome.performance = fitness_ex1
48
gnm = this_genome(all_genes)
50
# 3. Create a population of the genomes.
52
pop = ga.population.population(gnm)
53
# 4. Now use the basic genetic algorithm to evolve the population
55
galg = ga.algorithm.galg(pop)
56
# change a few settings
66
galg.settings.update(settings)
70
if __name__ == '__main__':