Package io.jenetics
Class IntegerChromosome
- java.lang.Object
-
- io.jenetics.AbstractChromosome<G>
-
- io.jenetics.IntegerChromosome
-
- All Implemented Interfaces:
BoundedChromosome<Integer,IntegerGene>
,Chromosome<IntegerGene>
,NumericChromosome<Integer,IntegerGene>
,BaseSeq<IntegerGene>
,Factory<Chromosome<IntegerGene>>
,Verifiable
,Serializable
,Iterable<IntegerGene>
,RandomAccess
public class IntegerChromosome extends AbstractChromosome<G> implements NumericChromosome<Integer,IntegerGene>, Serializable
Numeric chromosome implementation which holds 32 bit integer numbers.- Since:
- 2.0
- Version:
- 5.2
- Author:
- Franz Wilhelmstötter
- See Also:
IntegerGene
, Serialized Form- Implementation Note:
- This class is immutable and thread-safe.
-
-
Field Summary
-
Fields inherited from class io.jenetics.AbstractChromosome
_genes, _valid
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
IntegerChromosome(ISeq<IntegerGene> genes, IntRange lengthRange)
Create a new chromosome from the givengenes
and the allowed length range of the chromosome.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
int
hashCode()
IntStream
intStream()
Returns a sequential stream of the alleles with this chromosome as its source.IntRange
lengthRange()
Return the allowed length range of the chromosome.A
max()
Return the maximum value of thisBoundedChromosome
.A
min()
Return the minimum value of thisBoundedChromosome
.IntegerChromosome
newInstance()
Create a new instance of type T.IntegerChromosome
newInstance(ISeq<IntegerGene> genes)
A factory method which creates a newChromosome
of specific type and the givengenes
.static IntegerChromosome
of(int min, int max)
Create a new randomIntegerChromosome
of length one.static IntegerChromosome
of(int min, int max, int length)
Create a new randomIntegerChromosome
.static IntegerChromosome
of(int min, int max, IntRange lengthRange)
Create a new random chromosome.static IntegerChromosome
of(IntegerGene... genes)
Create a newIntegerChromosome
with the given genes.static IntegerChromosome
of(IntRange range)
Create a new randomIntegerChromosome
of length one.static IntegerChromosome
of(IntRange range, int length)
Create a new randomIntegerChromosome
.static IntegerChromosome
of(IntRange range, IntRange lengthRange)
Create a new random chromosome.static IntegerChromosome
of(Iterable<IntegerGene> genes)
Create a newIntegerChromosome
with the given genes.int[]
toArray()
Returns an int array containing all of the elements in this chromosome in proper sequence.int[]
toArray(int[] array)
Returns an int array containing all of the elements in this chromosome in proper sequence.-
Methods inherited from class io.jenetics.AbstractChromosome
get, isValid, length, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.jenetics.util.BaseSeq
get, isEmpty, iterator, length, listIterator, nonEmpty, spliterator, stream
-
Methods inherited from interface io.jenetics.BoundedChromosome
max, min
-
Methods inherited from interface io.jenetics.Chromosome
as, gene, isValid
-
Methods inherited from interface io.jenetics.NumericChromosome
byteValue, byteValue, doubleValue, doubleValue, floatValue, floatValue, intValue, intValue, longValue, longValue, shortValue, shortValue
-
-
-
-
Constructor Detail
-
IntegerChromosome
protected IntegerChromosome(ISeq<IntegerGene> genes, IntRange lengthRange)
Create a new chromosome from the givengenes
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 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 Detail
-
newInstance
public IntegerChromosome newInstance(ISeq<IntegerGene> genes)
Description copied from interface:Chromosome
A factory method which creates a newChromosome
of specific type and the givengenes
.- Specified by:
newInstance
in interfaceChromosome<IntegerGene>
- 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
public IntegerChromosome newInstance()
Description copied from interface:Factory
Create a new instance of type T.- Specified by:
newInstance
in interfaceFactory<Chromosome<IntegerGene>>
- Returns:
- a new instance of type T
-
intStream
public IntStream intStream()
Returns a sequential stream of the alleles with this chromosome as its source.- Returns:
- a sequential stream of alleles
- Since:
- 4.3
-
toArray
public int[] toArray(int[] array)
Returns an int array containing all of 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 this 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 givenarray
isnull
- Since:
- 3.0
-
toArray
public int[] toArray()
Returns an int array containing all of the elements in this chromosome in proper sequence.- Returns:
- an array containing the elements of this chromosome
- Since:
- 3.0
-
of
public static IntegerChromosome of(IntegerGene... genes)
Create a newIntegerChromosome
with the given genes.- Parameters:
genes
- the genes of the chromosome.- Returns:
- a new chromosome with the given genes.
- Throws:
IllegalArgumentException
- if the length of the genes array is empty or the givengenes
doesn't have the same range.
-
of
public static IntegerChromosome of(Iterable<IntegerGene> genes)
Create a newIntegerChromosome
with the given genes.- Parameters:
genes
- the genes of the chromosome.- Returns:
- a new chromosome with the given genes.
- Throws:
NullPointerException
- if the givengenes
arenull
IllegalArgumentException
- if the of the genes iterable is empty or the givengenes
doesn't have the same range.- Since:
- 4.3
-
of
public static IntegerChromosome of(int min, int max, IntRange lengthRange)
Create a new random chromosome.- Parameters:
min
- the min value of theIntegerGene
s (inclusively).max
- the max value of theIntegerGene
s (inclusively).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.NullPointerException
- if the givenlengthRange
isnull
- Since:
- 4.0
-
of
public static IntegerChromosome of(int min, int max, int length)
Create a new randomIntegerChromosome
.- Parameters:
min
- the min value of theIntegerGene
s (inclusively).max
- the max value of theIntegerGene
s (inclusively).length
- the length of the chromosome.- Returns:
- a new random
IntegerChromosome
- Throws:
IllegalArgumentException
- if the length is smaller than one
-
of
public static IntegerChromosome of(IntRange 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
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.NullPointerException
- if the givenlengthRange
isnull
- Since:
- 4.0
-
of
public static IntegerChromosome of(IntRange range, int length)
Create a new randomIntegerChromosome
.- Parameters:
range
- the integer range of the chromosome.length
- the length of the chromosome.- Returns:
- a new random
IntegerChromosome
- Throws:
NullPointerException
- if the givenrange
isnull
IllegalArgumentException
- if the length is smaller than one- Since:
- 3.2
-
of
public static IntegerChromosome of(int min, int max)
Create a new randomIntegerChromosome
of length one.- Parameters:
min
- the minimal value of this chromosome (inclusively).max
- the maximal value of this chromosome (inclusively).- Returns:
- a new random
IntegerChromosome
of length one
-
of
public static IntegerChromosome of(IntRange range)
Create a new randomIntegerChromosome
of length one.- Parameters:
range
- the integer range of the chromosome.- Returns:
- a new random
IntegerChromosome
of length one - Throws:
NullPointerException
- if the givenrange
isnull
- Since:
- 3.2
-
min
public A min()
Description copied from interface:BoundedChromosome
Return the minimum value of thisBoundedChromosome
.- Specified by:
min
in interfaceBoundedChromosome<A extends Comparable<? super A>,G extends BoundedGene<A,G>>
- Returns:
- the minimum value of this
BoundedChromosome
.
-
max
public A max()
Description copied from interface:BoundedChromosome
Return the maximum value of thisBoundedChromosome
.- Specified by:
max
in interfaceBoundedChromosome<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
-
-