Class BitChromosomeFactory
java.lang.Object
net.bmahe.genetics4j.core.chromosomes.factory.BitChromosomeFactory
- All Implemented Interfaces:
ChromosomeFactory<BitChromosome>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandle
(ChromosomeSpec chromosomeSpec) Determines if this factory can create chromosomes for the given specification.generate
(ChromosomeSpec chromosomeSpec) Creates a new chromosome instance based on the provided specification.
-
Field Details
-
randomGenerator
-
-
Constructor Details
-
BitChromosomeFactory
-
-
Method Details
-
canHandle
Description copied from interface:ChromosomeFactory
Determines if this factory can create chromosomes for the given specification.This method implements the type-checking logic that allows the factory system to automatically select the appropriate factory for each chromosome specification. Implementations typically check if the specification is of the expected type.
The method should be:
- Fast: Called frequently during factory selection
- Accurate: Return true only if generation will succeed
- Safe: Handle null and unexpected specification types gracefully
- Specified by:
canHandle
in interfaceChromosomeFactory<BitChromosome>
- Parameters:
chromosomeSpec
- the chromosome specification to evaluate- Returns:
true
if this factory can generate chromosomes for the given specification,false
otherwise
-
generate
Description copied from interface:ChromosomeFactory
Creates a new chromosome instance based on the provided specification.This method implements the core factory logic, creating and initializing a new chromosome according to the parameters defined in the specification. The generated chromosome should be ready for use in genetic operations.
The generation process typically involves:
- Extracting parameters from the specification (size, bounds, constraints)
- Generating random values within the specified constraints
- Creating and initializing the chromosome instance
- Validating that the result meets all requirements
Implementation requirements:
- Specification compatibility: Only call after
ChromosomeFactory.canHandle(net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec)
returns true - Randomization: Use appropriate random number generation for initialization
- Constraint compliance: Ensure generated values respect specification bounds
- Thread safety: Support concurrent calls in multi-threaded environments
- Specified by:
generate
in interfaceChromosomeFactory<BitChromosome>
- Parameters:
chromosomeSpec
- the specification defining the chromosome to create- Returns:
- a newly created chromosome instance conforming to the specification
-