Class DoubleChromosomeFactory

java.lang.Object
net.bmahe.genetics4j.core.chromosomes.factory.DoubleChromosomeFactory
All Implemented Interfaces:
ChromosomeFactory<DoubleChromosome>

public class DoubleChromosomeFactory extends Object implements ChromosomeFactory<DoubleChromosome>
  • Field Details

  • Constructor Details

    • DoubleChromosomeFactory

      public DoubleChromosomeFactory(RandomGenerator _randomGenerator)
  • Method Details

    • canHandle

      public boolean canHandle(ChromosomeSpec chromosomeSpec)
      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 interface ChromosomeFactory<DoubleChromosome>
      Parameters:
      chromosomeSpec - the chromosome specification to evaluate
      Returns:
      true if this factory can generate chromosomes for the given specification, false otherwise
    • generate

      public DoubleChromosome generate(ChromosomeSpec chromosomeSpec)
      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:

      Specified by:
      generate in interface ChromosomeFactory<DoubleChromosome>
      Parameters:
      chromosomeSpec - the specification defining the chromosome to create
      Returns:
      a newly created chromosome instance conforming to the specification