- All Implemented Interfaces:
BoundedChromosome<Long,,LongGene> Chromosome<LongGene>,NumericChromosome<Long,,LongGene> BaseSeq<LongGene>,Factory<Chromosome<LongGene>>,Verifiable,Serializable,Iterable<LongGene>,RandomAccess
public class LongChromosome
extends AbstractChromosome<LongGene>
implements NumericChromosome<Long,LongGene>, Serializable
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.
-
Field Summary
Fields inherited from class io.jenetics.AbstractChromosome
_genes, _valid -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLongChromosome(ISeq<LongGene> genes, IntRange lengthRange) Create a new chromosome from the givengenesand the allowed length range of the chromosome. -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()Return the allowed length range of the chromosome.Returns a sequential stream of the alleles with this chromosome as its source.Maps the gene alleles of this chromosome, given aslong[]array, by applying the given mapper functionf.max()Return the maximum value of thisBoundedChromosome.min()Return the minimum value of thisBoundedChromosome.Create a new instance of type T.newInstance(ISeq<LongGene> genes) A factory method which creates a newChromosomeof specific type and the givengenes.static LongChromosomeof(long min, long max) Create a new randomLongChromosomeof length one.static LongChromosomeof(long min, long max, int length) Create a new randomLongChromosome.static LongChromosomeCreate a new random chromosome.static LongChromosomeCreate a newLongChromosomewith the given genes.static LongChromosomeCreate a new randomLongChromosomeof length one.static LongChromosomeCreate a new randomLongChromosome.static LongChromosomeCreate a new random chromosome.static LongChromosomeCreate a newLongChromosomewith the given genes.long[]toArray()Returns a long array containing all the elements in this chromosome in a proper sequence.long[]toArray(long[] array) Returns a long array containing all the elements in this chromosome in a proper sequence.Methods inherited from class io.jenetics.AbstractChromosome
get, isValid, length, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.jenetics.util.BaseSeq
forEach, get, isEmpty, iterator, length, listIterator, nonEmpty, spliterator, streamMethods inherited from interface io.jenetics.BoundedChromosome
max, minMethods inherited from interface io.jenetics.Chromosome
as, gene, isValidMethods inherited from interface io.jenetics.NumericChromosome
byteValue, byteValue, doubleValue, doubleValue, floatValue, floatValue, intValue, intValue, longValue, longValue, shortValue, shortValue
-
Constructor Details
-
LongChromosome
Create a new chromosome from the givengenesand 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 isnull.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:ChromosomeA factory method which creates a newChromosomeof specific type and the givengenes.- Specified by:
newInstancein interfaceChromosome<LongGene>- Parameters:
genes- the genes of the new chromosome. The given genes array is not copied.- Returns:
- A new
Chromosomeof the same type with the given genes.
-
newInstance
Description copied from interface:FactoryCreate a new instance of type T.- Specified by:
newInstancein interfaceFactory<Chromosome<LongGene>>- Returns:
- a new instance of type T
-
map
Maps the gene alleles of this chromosome, given aslong[]array, by applying the given mapper functionf. 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 isnull.IllegalArgumentException- if the length of the mappedlong[]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
Returns a long array containing all the elements in this chromosome in a 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 givenarrayisnull- Since:
- 3.0
-
toArray
Returns a long array containing all the elements in this chromosome in a proper sequence.- Returns:
- an array containing the elements of this chromosome
- Since:
- 3.0
-
of
Create a newLongChromosomewith the given genes.- Parameters:
genes- the genes of the chromosome.- Returns:
- a new chromosome with the given genes.
- Throws:
NullPointerException- if the givengenesarenullIllegalArgumentException- if the length of the genes array is empty or the givengenesdoesn't have the same range.
-
of
Create a newLongChromosomewith the given genes.- Parameters:
genes- the genes of the chromosome.- Returns:
- a new chromosome with the given genes.
- Throws:
NullPointerException- if the givengenesarenullIllegalArgumentException- if the of the genes iterable is empty or the givengenesdoesn't have the same range.- Since:
- 4.3
-
of
Create a new random chromosome.- Parameters:
min- the min value of theLongGenes (inclusively).max- the max value of theLongGenes (exclusively).lengthRange- the allowed length range of the chromosome.- Returns:
- a new
IntegerChromosomewith 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- ifmaxis greater than or equal tominNullPointerException- if the givenlengthRangeisnull- Since:
- 4.0
-
of
Create a new randomLongChromosome.- Parameters:
min- the min value of theLongGenes (inclusively).max- the max value of theLongGenes (exclusively).length- the length of the chromosome.- Returns:
- a new
LongChromosomewith the given gene parameters. - Throws:
IllegalArgumentException- if thelengthis smaller than one.IllegalArgumentException- ifmaxis greater than or equal tomin
-
of
Create a new random chromosome.- Parameters:
range- the integer range of the chromosome.lengthRange- the allowed length range of the chromosome.- Returns:
- a new
LongChromosomewith 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- ifmaxis greater than or equal tominNullPointerException- if the givenlengthRangeisnull- Since:
- 4.0
-
of
Create a new randomLongChromosome.- Parameters:
range- the long range of the chromosome.length- the length of the chromosome.- Returns:
- a new random
LongChromosome - Throws:
NullPointerException- if the givenrangeisnullIllegalArgumentException- if thelengthis smaller than one.IllegalArgumentException- ifmaxis greater than or equal tomin- Since:
- 3.2
-
of
Create a new randomLongChromosomeof length one.- Parameters:
min- the minimal value of this chromosome (inclusively).max- the maximal value of this chromosome (exclusively).- Returns:
- a new
LongChromosomewith the given gene parameters. - Throws:
IllegalArgumentException- ifmaxis greater than or equal tomin
-
of
Create a new randomLongChromosomeof length one.- Parameters:
range- the long range of the chromosome.- Returns:
- a new random
LongChromosomeof length one - Throws:
NullPointerException- if the givenrangeisnullIllegalArgumentException- ifmaxis greater than or equal tomin- Since:
- 3.2
-
min
Description copied from interface:BoundedChromosomeReturn the minimum value of thisBoundedChromosome.- Specified by:
minin interfaceBoundedChromosome<A extends Comparable<? super A>,G extends BoundedGene<A, G>> - Returns:
- the minimum value of this
BoundedChromosome.
-
max
Description copied from interface:BoundedChromosomeReturn the maximum value of thisBoundedChromosome.- Specified by:
maxin interfaceBoundedChromosome<A extends Comparable<? super A>,G extends BoundedGene<A, G>> - Returns:
- the maximum value of this
BoundedChromosome.
-
hashCode
public int hashCode() -
equals
-
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
-