Class ProgramTreeChromosomeFactory

java.lang.Object
net.bmahe.genetics4j.gp.chromosomes.factory.ProgramTreeChromosomeFactory
All Implemented Interfaces:
ChromosomeFactory<TreeChromosome<Operation<?>>>

public class ProgramTreeChromosomeFactory extends Object implements ChromosomeFactory<TreeChromosome<Operation<?>>>
  • Field Details

  • Constructor Details

    • ProgramTreeChromosomeFactory

      public ProgramTreeChromosomeFactory(ProgramGenerator _programGenerator)
  • 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<TreeChromosome<Operation<?>>>
      Parameters:
      chromosomeSpec - the chromosome specification to evaluate
      Returns:
      true if this factory can generate chromosomes for the given specification, false otherwise
    • generate

      public TreeChromosome<Operation<?>> 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<TreeChromosome<Operation<?>>>
      Parameters:
      chromosomeSpec - the specification defining the chromosome to create
      Returns:
      a newly created chromosome instance conforming to the specification