Package net.bmahe.genetics4j.core
Class Genotype
java.lang.Object
net.bmahe.genetics4j.core.Genotype
Represents a genotype in an evolutionary algorithm, which is a collection of chromosomes.
A genotype encapsulates the complete genetic representation of an individual solution, consisting of one or more chromosomes that together define the individual's characteristics. Each chromosome may represent different aspects or components of the solution space.
Genotypes are immutable once created and provide type-safe access to their constituent chromosomes.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGenotype
(Collection<Chromosome> _chromosomes) Creates a new genotype with chromosomes from the specified collection.Genotype
(Chromosome... _chromosomes) Creates a new genotype with the specified chromosomes. -
Method Summary
Modifier and TypeMethodDescriptionboolean
getChromosome
(int index) Returns the chromosome at the specified index.<T extends Chromosome>
TgetChromosome
(int index, Class<T> clazz) Returns the chromosome at the specified index, cast to the specified type.Returns all chromosomes in this genotype.int
getSize()
Returns the number of chromosomes in this genotype.int
hashCode()
toString()
-
Field Details
-
chromosomes
-
-
Constructor Details
-
Genotype
Creates a new genotype with the specified chromosomes.- Parameters:
_chromosomes
- one or more chromosomes to include in this genotype- Throws:
IllegalArgumentException
- if chromosomes array is null or empty
-
Genotype
Creates a new genotype with chromosomes from the specified collection.- Parameters:
_chromosomes
- a collection of chromosomes to include in this genotype- Throws:
IllegalArgumentException
- if chromosomes collection is null or empty
-
-
Method Details
-
getSize
public int getSize()Returns the number of chromosomes in this genotype.- Returns:
- the count of chromosomes
-
getChromosomes
Returns all chromosomes in this genotype.- Returns:
- an array containing all chromosomes
-
getChromosome
Returns the chromosome at the specified index.- Parameters:
index
- the index of the chromosome to retrieve (0-based)- Returns:
- the chromosome at the specified index
- Throws:
IllegalArgumentException
- if index is negative or greater than or equal to the number of chromosomes
-
getChromosome
Returns the chromosome at the specified index, cast to the specified type.- Type Parameters:
T
- the expected chromosome type- Parameters:
index
- the index of the chromosome to retrieve (0-based)clazz
- the class to cast the chromosome to- Returns:
- the chromosome at the specified index, cast to the specified type
- Throws:
IllegalArgumentException
- if index is invalid or clazz is nullClassCastException
- if the chromosome cannot be cast to the specified type
-
hashCode
public int hashCode() -
equals
-
toString
-