New data structure features make initializing the population much simpler

This commit is contained in:
SimpleArt
2020-12-20 14:00:10 -05:00
parent a15803e7ef
commit ef3be9d5d1

View File

@ -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.