culebra.solution.abc.Individual class¶
- class Individual(species: Species, fitness_cls: type[Fitness])¶
Bases:
SolutionConstruct a default solution.
Class attributes¶
Class methods¶
- classmethod Individual.load(filename: str) Base¶
Load a serialized object from a file.
- Parameters:
filename (str) – The file name.
- Returns:
The loaded object
- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
SERIALIZED_FILE_EXTENSION
Properties¶
Methods¶
- abstract Individual.crossover(other: Individual) tuple[Individual, Individual]¶
Cross this individual with another one.
This method must be overridden by subclasses to return a correct value.
- Parameters:
other (Individual) – The other individual
- Returns:
The two offspring
- Return type:
- Raises:
NotImplementedError – If has not been overridden
- Individual.dump(filename: str) None¶
Serialize this object and save it to a file.
- Parameters:
filename (str) – The file name.
- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
SERIALIZED_FILE_EXTENSION
- abstract Individual.mutate(indpb: float) tuple[Individual]¶
Mutate the individual.
This method must be overridden by subclasses to return a correct value.
- Parameters:
indpb (float) – Independent probability for each gene to be mutated.
- Returns:
The mutant
- Return type:
- Raises:
NotImplementedError – If has not been overridden
Dunder methods¶
Intended to compare (lexicographically) two individuals according to their fitness.
- Individual.__hash__() int¶
Return the hash number for this solution.
The hash number is used for equality comparisons. Currently is implemented as the hash of the solution’s string representation.
- Return type:

