gaft.components.population

class gaft.components.population.Individuals(name)

Bases: object

Descriptor for all individuals in population.

Note

Use this descriptor to ensure the individual related flags can be updated when the population indivduals are changed.

class gaft.components.population.Memoized(func)

Bases: object

Descriptor for population statistical varibles caching.

class gaft.components.population.Population(indv_template, size=100)

Bases: object

Class for representing population in genetic algorithm.

Parameters:
  • indv_template (gaft.components.IndividualBase) – A template individual to clone all the other individuals in current population.
  • size (int) – The size of population, number of individuals in population.
best_indv(fitness)

The individual with the best fitness.

Parameters:fitness (function) – Fitness function to calculate fitness value
Returns:the best individual in current population
Return type:gaft.components.IndividualBase
init(indvs=None)

Initialize current population with individuals.

Parameters:indvs (list of Individual object) – Initial individuals in population, randomly initialized individuals are created if not provided.
max(fitness)

Get the maximum fitness value in population.

Parameters:fitness (function) – Fitness function to calculate fitness value
Returns:The maximum fitness value
Return type:float
mean(fitness)

Get the average fitness value in population.

Parameters:fitness (function) – Fitness function to calculate fitness value
Returns:The average fitness value
Return type:float
min(fitness)

Get the minimum value of fitness in population.

Parameters:fitness (function) – Fitness function to calculate fitness value
Returns:The minimum fitness value
Return type:float
new()

Create a new emtpy population.

update_flag()

Interface for updating individual update flag to True.

updated

Query function for population updating flag.

worst_indv(fitness)

The individual with the worst fitness.

Parameters:fitness (function) – Fitness function to calculate fitness value
Returns:the worst individual in current population
Return type:gaft.components.IndividualBase