Package io.jenetics

Class Phenotype<G extends Gene<?,​G>,​C extends Comparable<? super C>>

    • Method Detail

      • eval

        public Phenotype<G,​Ceval​(Function<? super Genotype<G>,​? extends C> ff)
        Applies the given fitness function to the underlying genotype and return a new phenotype with the (newly) evaluated fitness function, if not already evaluated. If the fitness value is already set this phenotype is returned.
        Parameters:
        ff - the fitness function
        Returns:
        a evaluated phenotype or this if the fitness value is already set
        Throws:
        NullPointerException - if the given fitness function is null
        Since:
        5.0
      • genotype

        public Genotype<Ggenotype()
        This method returns a copy of the Genotype, to guarantee a immutable class.
        Returns:
        the cloned Genotype of this Phenotype.
        Throws:
        NullPointerException - if one of the arguments is null.
      • isEvaluated

        public boolean isEvaluated()
        A phenotype instance can be created with or without fitness value. Initially, the phenotype is created without fitness value. The fitness evaluation strategy is responsible for creating phenotypes with fitness value assigned.
        Returns:
        true is this phenotype has an fitness value assigned, false otherwise
        Since:
        4.2
        See Also:
        nonEvaluated()
      • nonEvaluated

        public boolean nonEvaluated()
        A phenotype instance can be created with or without fitness value. Initially, the phenotype is created without fitness value. The fitness evaluation strategy is responsible for creating phenotypes with fitness value assigned.
        Returns:
        false is this phenotype has an fitness value assigned, true otherwise
        Since:
        5.0
        See Also:
        isEvaluated()
      • age

        public long age​(long currentGeneration)
        Return the age of this phenotype depending on the given current generation.
        Parameters:
        currentGeneration - the current generation evaluated by the GA.
        Returns:
        the age of this phenotype: currentGeneration - this.getGeneration().
        See Also:
        generation()
      • nullifyFitness

        public Phenotype<G,​CnullifyFitness()
        Return a phenotype, where the fitness is set to null. If this phenotype isn't evaluated, this instance is returned.
        Returns:
        a phenotype, where the fitness is set to null
        Since:
        6.0
      • isValid

        public boolean isValid()
        Test whether this phenotype is valid. The phenotype is valid if its Genotype is valid.
        Specified by:
        isValid in interface Verifiable
        Returns:
        true if this phenotype is valid, false otherwise.
      • withFitness

        public Phenotype<G,​CwithFitness​(C fitness)
        Return a new Phenotype object with the given raw fitness value. The returned phenotype is automatically evaluated: isEvaluated() == true
        Parameters:
        fitness - the phenotypes fitness value
        Returns:
        a new phenotype with the given fitness value
        Throws:
        NullPointerException - if the given fitness value is null
        Since:
        4.2
      • withGeneration

        public Phenotype<G,​CwithGeneration​(long generation)
        Return a new Phenotype object with the given generation.
        Parameters:
        generation - the generation of the newly created phenotype
        Returns:
        a new phenotype with the given generation
        Since:
        5.0
      • of

        public static <G extends Gene<?,​G>,​C extends Comparable<? super C>> Phenotype<G,​C> of​(Genotype<G> genotype,
                                                                                                                long generation)
        Create a new phenotype from the given arguments. The phenotype is created with a non assigned fitness function and the call of isEvaluated() will return false.
        Type Parameters:
        G - the gene type of the chromosome
        C - the fitness value type
        Parameters:
        genotype - the genotype of this phenotype.
        generation - the current generation of the generated phenotype.
        Returns:
        a new phenotype object
        Throws:
        NullPointerException - if one of the arguments is null.
        IllegalArgumentException - if the given generation is < 0.
      • of

        public static <G extends Gene<?,​G>,​C extends Comparable<? super C>> Phenotype<G,​C> of​(Genotype<G> genotype,
                                                                                                                long generation,
                                                                                                                C fitness)
        Create a new phenotype from the given arguments.
        Type Parameters:
        G - the gene type of the chromosome
        C - the fitness value type
        Parameters:
        genotype - the genotype of this phenotype.
        generation - the current generation of the generated phenotype.
        fitness - the known fitness of the phenotype.
        Returns:
        a new phenotype object
        Throws:
        NullPointerException - if one of the arguments is null.
        IllegalArgumentException - if the given generation is < 0.