C++ Population Layer
This section documents the C++ population layer implementation.
- class Population
Manages population of solutions for memetic algorithm.
The Population class handles evolutionary operations:
Initialization of diverse solutions using local search
Parent selection via tournament selection
Solution evaluation based on fitness (cost + diversity)
Population updates maintaining quality and diversity
Optional adaptive population sizing
Fitness is computed as a weighted combination of objective value and Jaccard similarity to existing solutions, promoting both quality and diversity in the population.
Note
This class is designed for internal use by the memetic algorithm.
- get_all_three_solutions(self: Population) tuple
Get up to three prominent solutions from the population.
Returns the best solution and two diverse alternatives. Used by the IRR crossover operator which requires three parents.
- Returns:
Tuple of (solution1, solution2, solution3)
- Return type:
Tuple[Solution, Solution, Solution]
- get_size(self: Population) int
Get the current population size.
- Returns:
Number of solutions in the population
- Return type:
- initialize(self: Population, display: bool = False, stopping_criterion: object = None) tuple[set, int]
- select(self: Population) tuple
Select two parent solutions using tournament selection.
Performs k-ary tournament selection twice to choose two distinct parents. Higher fitness solutions are more likely to be selected.
- Parameters:
k (int, default=2) – Tournament size
- Returns:
Pair of (first parent, second parent) as solution sets
- Return type:
Tuple[Solution, Solution]
- update(self: Population, solution: set, obj_value: SupportsInt | SupportsIndex, num_idle_generations: SupportsInt | SupportsIndex, verbose: bool = False) None
Update population with a new offspring solution.
Evaluates the new solution and updates the population if the solution is sufficiently good or diverse. May expand population if enabled and no progress has been made.