Package io.jenetics

Class LongChromosome

java.lang.Object
io.jenetics.AbstractChromosome<G>
io.jenetics.LongChromosome
All Implemented Interfaces:
BoundedChromosome<Long,LongGene>, Chromosome<LongGene>, NumericChromosome<Long,LongGene>, BaseSeq<LongGene>, Factory<Chromosome<LongGene>>, Verifiable, Serializable, Iterable<LongGene>, RandomAccess

Numeric chromosome implementation which holds 64-bit integer numbers.
Since:
1.6
Version:
6.1
See Also:
Implementation Note:
This class is immutable and thread-safe.
  • Constructor Details

    • LongChromosome

      protected LongChromosome(ISeq<LongGene> genes, IntRange lengthRange)
      Create a new chromosome from the given genes and the allowed length range of the chromosome.
      Parameters:
      genes - the genes that form the chromosome.
      lengthRange - the allowed length range of the chromosome
      Throws:
      NullPointerException - if one of the arguments is null.
      IllegalArgumentException - if the length of the gene sequence is empty, doesn't match with the allowed length range, the minimum or maximum of the range is smaller or equal zero or the given range size is zero.
      Since:
      4.0
  • Method Details

    • newInstance

      Description copied from interface: Chromosome
      A factory method which creates a new Chromosome of specific type and the given genes.
      Specified by:
      newInstance in interface Chromosome<LongGene>
      Parameters:
      genes - the genes of the new chromosome. The given genes array is not copied.
      Returns:
      A new Chromosome of the same type with the given genes.
    • newInstance

      Description copied from interface: Factory
      Create a new instance of type T.
      Specified by:
      newInstance in interface Factory<Chromosome<LongGene>>
      Returns:
      a new instance of type T
    • map

      public LongChromosome map(Function<? super long[],long[]> f)
      Maps the gene alleles of this chromosome, given as long[] array, by applying the given mapper function f. The mapped gene values are then wrapped into a newly created chromosome.
      final LongChromosome chromosome = ...; final LongChromosome halved = chromosome.map(Main::half); static long[] half(final long[] values) { for (int i = 0; i < values.length; ++i) { values[i] /= 2; } return values; }
      Parameters:
      f - the mapper function
      Returns:
      a newly created chromosome with the mapped gene values
      Throws:
      NullPointerException - if the mapper function is null.
      IllegalArgumentException - if the length of the mapped long[] array is empty or doesn't match with the allowed length range
      Since:
      6.1
    • longStream

      Returns a sequential stream of the alleles with this chromosome as its source.
      Returns:
      a sequential stream of alleles
      Since:
      4.3
    • toArray

      public long[] toArray(long[] array)
      Returns an long array containing all the elements in this chromosome in proper sequence. If the chromosome fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the length of this chromosome.
      Parameters:
      array - the array into which the elements of these chromosomes are to be stored, if it is big enough; otherwise, a new array is allocated for this purpose.
      Returns:
      an array containing the elements of this chromosome
      Throws:
      NullPointerException - if the given array is null
      Since:
      3.0
    • toArray

      public long[] toArray()
      Returns an long array containing all the elements in this chromosome in proper sequence.
      Returns:
      an array containing the elements of this chromosome
      Since:
      3.0
    • of

      public static LongChromosome of(LongGene... genes)
      Create a new LongChromosome with the given genes.
      Parameters:
      genes - the genes of the chromosome.
      Returns:
      a new chromosome with the given genes.
      Throws:
      NullPointerException - if the given genes are null
      IllegalArgumentException - if the length of the genes array is empty or the given genes doesn't have the same range.
    • of

      public static LongChromosome of(Iterable<LongGene> genes)
      Create a new LongChromosome with the given genes.
      Parameters:
      genes - the genes of the chromosome.
      Returns:
      a new chromosome with the given genes.
      Throws:
      NullPointerException - if the given genes are null
      IllegalArgumentException - if the of the genes iterable is empty or the given genes doesn't have the same range.
      Since:
      4.3
    • of

      public static LongChromosome of(long min, long max, IntRange lengthRange)
      Create a new random chromosome.
      Parameters:
      min - the min value of the LongGenes (inclusively).
      max - the max value of the LongGenes (exclusively).
      lengthRange - the allowed length range of the chromosome.
      Returns:
      a new IntegerChromosome with the given parameter
      Throws:
      IllegalArgumentException - if the length of the gene sequence is empty, doesn't match with the allowed length range, the minimum or maximum of the range is smaller or equal zero or the given range size is zero.
      IllegalArgumentException - if max is greater than or equal to min
      NullPointerException - if the given lengthRange is null
      Since:
      4.0
    • of

      public static LongChromosome of(long min, long max, int length)
      Create a new random LongChromosome.
      Parameters:
      min - the min value of the LongGenes (inclusively).
      max - the max value of the LongGenes (exclusively).
      length - the length of the chromosome.
      Returns:
      a new LongChromosome with the given gene parameters.
      Throws:
      IllegalArgumentException - if the length is smaller than one.
      IllegalArgumentException - if max is greater than or equal to min
    • of

      public static LongChromosome of(LongRange range, IntRange lengthRange)
      Create a new random chromosome.
      Parameters:
      range - the integer range of the chromosome.
      lengthRange - the allowed length range of the chromosome.
      Returns:
      a new LongChromosome with the given parameter
      Throws:
      IllegalArgumentException - if the length of the gene sequence is empty, doesn't match with the allowed length range, the minimum or maximum of the range is smaller or equal zero or the given range size is zero.
      IllegalArgumentException - if max is greater than or equal to min
      NullPointerException - if the given lengthRange is null
      Since:
      4.0
    • of

      public static LongChromosome of(LongRange range, int length)
      Create a new random LongChromosome.
      Parameters:
      range - the long range of the chromosome.
      length - the length of the chromosome.
      Returns:
      a new random LongChromosome
      Throws:
      NullPointerException - if the given range is null
      IllegalArgumentException - if the length is smaller than one.
      IllegalArgumentException - if max is greater than or equal to min
      Since:
      3.2
    • of

      public static LongChromosome of(long min, long max)
      Create a new random LongChromosome of length one.
      Parameters:
      min - the minimal value of this chromosome (inclusively).
      max - the maximal value of this chromosome (exclusively).
      Returns:
      a new LongChromosome with the given gene parameters.
      Throws:
      IllegalArgumentException - if max is greater than or equal to min
    • of

      public static LongChromosome of(LongRange range)
      Create a new random LongChromosome of length one.
      Parameters:
      range - the long range of the chromosome.
      Returns:
      a new random LongChromosome of length one
      Throws:
      NullPointerException - if the given range is null
      IllegalArgumentException - if max is greater than or equal to min
      Since:
      3.2
    • min

      public Long min()
      Description copied from interface: BoundedChromosome
      Return the minimum value of this BoundedChromosome.
      Specified by:
      min in interface BoundedChromosome<A extends Comparable<? super A>,G extends BoundedGene<A,G>>
      Returns:
      the minimum value of this BoundedChromosome.
    • max

      public Long max()
      Description copied from interface: BoundedChromosome
      Return the maximum value of this BoundedChromosome.
      Specified by:
      max in interface BoundedChromosome<A extends Comparable<? super A>,G extends BoundedGene<A,G>>
      Returns:
      the maximum value of this BoundedChromosome.
    • hashCode

      public int hashCode()
    • equals

      public boolean equals(Object obj)
    • lengthRange

      public IntRange lengthRange()
      Return the allowed length range of the chromosome. The minimum value of the range is included and the maximum value is excluded.
      Returns:
      the allowed length range of the chromosome