Skip to main content

raygeo.geo.algo.nest2d.genetic

Genetic algorithm for nesting optimization.

Provides a GeneticAlgorithm class that manages a population of placement configurations (rotations, flips) and evolves them via mutation, crossover, and selection.

GeneticAlgorithm

generation()

generation() -> None

Evolve one generation.

ParameterTypeDescription
ReturnsNoneThe genetic algorithm state after one generation.
ComplexityO(p * n) where p = population size, n = num_parts

get_fitness()

get_fitness(idx: int) -> float

Returns the fitness of individual at idx.

ParameterTypeDescription
idxintIndex of the individual.
ReturnsfloatFitness value of the individual.
ComplexityO(1)

get_individual()

get_individual(idx: int) -> tuple[list[float], list[bool], list[bool], float]

Returns (rotations, flips_h, flips_v, fitness) for individual at idx.

ParameterTypeDescription
idxintIndex of the individual.
Returnstuple[list[float], list[bool], list[bool], float](rotations, flips_h, flips_v, fitness) tuple.
ComplexityO(1)

mate()

mate(
male_idx: int,
female_idx: int,
) -> list[tuple[list[float], list[bool], list[bool]]]

Mate two individuals and return the two children.

ParameterTypeDescription
male_idxintIndex of the male parent.
female_idxintIndex of the female parent.
Returnslist[tuple[list[float], list[bool], list[bool]]]List of two child individuals.
ComplexityO(n) where n = num_parts

mutate()

mutate(idx: int) -> tuple[list[float], list[bool], list[bool]]

Mutate and return a copy of individual at idx.

ParameterTypeDescription
idxintIndex of the individual to mutate.
Returnstuple[list[float], list[bool], list[bool]](rotations, flips_h, flips_v) of the mutated individual.
ComplexityO(n) where n = num_parts

set_fitness()

set_fitness(idx: int, fitness: float) -> None

Set the fitness for individual at idx.

ParameterTypeDescription
idxintIndex of the individual.
fitnessfloatFitness value to set.
ReturnsNone
ComplexityO(1)