New data structure features make initializing the population much simpler
This commit is contained in:
@ -2,27 +2,11 @@ def _chromosomes_to_population(initialize):
|
||||
"""Makes a population from chromosomes."""
|
||||
return lambda ga:\
|
||||
ga.make_population(
|
||||
[
|
||||
(
|
||||
initialize(ga)
|
||||
for _
|
||||
in range(ga.population_size)
|
||||
]
|
||||
)
|
||||
|
||||
def _genes_to_chromosome(initialize):
|
||||
"""Converts a collection of genes to a chromosome."""
|
||||
return lambda ga:\
|
||||
ga.make_chromosome(
|
||||
list(initialize(ga))
|
||||
)
|
||||
|
||||
def _values_to_genes(initialize):
|
||||
"""Converts a collection of values to genes."""
|
||||
return lambda ga:\
|
||||
(
|
||||
ga.make_gene(value)
|
||||
for value
|
||||
in initialize(ga)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@ -31,13 +15,9 @@ class Initialization_Methods:
|
||||
|
||||
# Private method decorators, see above.
|
||||
_chromosomes_to_population = _chromosomes_to_population
|
||||
_genes_to_chromosome = _genes_to_chromosome
|
||||
_values_to_genes = _values_to_genes
|
||||
|
||||
|
||||
@_chromosomes_to_population
|
||||
@_genes_to_chromosome
|
||||
@_values_to_genes
|
||||
def random_initialization(ga):
|
||||
"""Takes the initialization inputs and returns a collection of values.
|
||||
Method decorators convert them to a GA population object.
|
||||
|
||||
Reference in New Issue
Block a user