Package io.jenetics
Class DoubleChromosome
- java.lang.Object
-
- io.jenetics.AbstractChromosome<G>
-
- io.jenetics.DoubleChromosome
-
- All Implemented Interfaces:
BoundedChromosome<Double,DoubleGene>,Chromosome<DoubleGene>,NumericChromosome<Double,DoubleGene>,BaseSeq<DoubleGene>,Factory<Chromosome<DoubleGene>>,Verifiable,Serializable,Iterable<DoubleGene>,RandomAccess
public class DoubleChromosome extends AbstractChromosome<G> implements NumericChromosome<Double,DoubleGene>, Serializable
Numeric chromosome implementation which holds 64 bit floating point numbers.- Since:
- 1.6
- Version:
- 6.1
- See Also:
DoubleGene, 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 protectedDoubleChromosome(ISeq<DoubleGene> genes, IntRange lengthRange)Create a new chromosome from the givengenesand the allowed length range of the chromosome.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DoubleStreamdoubleStream()Returns a sequential stream of the alleles with this chromosome as its source.booleanequals(Object obj)inthashCode()IntRangelengthRange()Return the allowed length range of the chromosome.DoubleChromosomemap(Function<? super double[],double[]> f)Maps the gene alleles of this chromosome, given asdouble[]array, by applying the given mapper functionf.Amax()Return the maximum value of thisBoundedChromosome.Amin()Return the minimum value of thisBoundedChromosome.DoubleChromosomenewInstance()Create a new instance of type T.DoubleChromosomenewInstance(ISeq<DoubleGene> genes)A factory method which creates a newChromosomeof specific type and the givengenes.static DoubleChromosomeof(double min, double max)Create a new randomDoubleChromosomeof length one.static DoubleChromosomeof(double min, double max, int length)Create a new randomDoubleChromosome.static DoubleChromosomeof(double min, double max, IntRange lengthRange)Create a new random chromosome.static DoubleChromosomeof(DoubleGene... genes)Create a newDoubleChromosomewith the given genes.static DoubleChromosomeof(DoubleRange range)Create a new randomDoubleChromosomeof length one.static DoubleChromosomeof(DoubleRange range, int length)Create a new randomDoubleChromosome.static DoubleChromosomeof(DoubleRange range, IntRange lengthRange)Create a new random chromosome.static DoubleChromosomeof(Iterable<DoubleGene> genes)Create a newDoubleChromosomewith the given genes.double[]toArray()Returns an double array containing all of the elements in this chromosome in proper sequence.double[]toArray(double[] array)Returns an double 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
-
DoubleChromosome
protected DoubleChromosome(ISeq<DoubleGene> genes, IntRange lengthRange)
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 Detail
-
newInstance
public DoubleChromosome newInstance(ISeq<DoubleGene> genes)
Description copied from interface:ChromosomeA factory method which creates a newChromosomeof specific type and the givengenes.- Specified by:
newInstancein interfaceChromosome<DoubleGene>- 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
public DoubleChromosome newInstance()
Description copied from interface:FactoryCreate a new instance of type T.- Specified by:
newInstancein interfaceFactory<Chromosome<DoubleGene>>- Returns:
- a new instance of type T
-
map
public DoubleChromosome map(Function<? super double[],double[]> f)
Maps the gene alleles of this chromosome, given asdouble[]array, by applying the given mapper functionf. The mapped gene values are then wrapped into a newly created chromosome.final DoubleChromosome chromosome = ...; final DoubleChromosome normalized = chromosome.map(Main::normalize); static double[] normalize(final double[] values) { final double sum = sum(values); for (int i = 0; i < values.length; ++i) { values[i] /= sum; } 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 mappeddouble[]array is empty or doesn't match with the allowed length range- Since:
- 6.1
-
doubleStream
public DoubleStream doubleStream()
Returns a sequential stream of the alleles with this chromosome as its source.- Returns:
- a sequential stream of alleles
- Since:
- 4.3
-
toArray
public double[] toArray(double[] array)
Returns an double 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 givenarrayisnull- Since:
- 3.0
-
toArray
public double[] toArray()
Returns an double 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 DoubleChromosome of(DoubleGene... genes)
Create a newDoubleChromosomewith 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 givengenesdoesn't have the same range.NullPointerException- if the givengenesarray isnull
-
of
public static DoubleChromosome of(Iterable<DoubleGene> genes)
Create a newDoubleChromosomewith 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
public static DoubleChromosome of(double min, double max, IntRange lengthRange)
Create a new random chromosome.- Parameters:
min- the min value of theDoubleGenes (inclusively).max- the max value of theDoubleGenes (exclusively).lengthRange- the allowed length range of the chromosome.- Returns:
- a new
DoubleChromosomewith 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 givenlengthRangeisnull- Since:
- 4.0
-
of
public static DoubleChromosome of(double min, double max, int length)
Create a new randomDoubleChromosome.- Parameters:
min- the min value of theDoubleGenes (inclusively).max- the max value of theDoubleGenes (exclusively).length- the length of the chromosome.- Returns:
- a new
DoubleChromosomewith the given parameter - Throws:
IllegalArgumentException- if thelengthis smaller than one.
-
of
public static DoubleChromosome of(DoubleRange 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
DoubleChromosomewith 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 givenlengthRangeisnull- Since:
- 4.0
-
of
public static DoubleChromosome of(DoubleRange range, int length)
Create a new randomDoubleChromosome.- Parameters:
range- the integer range of the chromosome.length- the length of the chromosome.- Returns:
- a new random
DoubleChromosome - Throws:
NullPointerException- if the givenrangeisnullIllegalArgumentException- if thelengthis smaller than one.- Since:
- 3.2
-
of
public static DoubleChromosome of(double min, double max)
Create a new randomDoubleChromosomeof length one.- Parameters:
min- the minimal value of this chromosome (inclusively).max- the maximal value of this chromosome (exclusively).- Returns:
- a new
DoubleChromosomewith the given parameter
-
of
public static DoubleChromosome of(DoubleRange range)
Create a new randomDoubleChromosomeof length one.- Parameters:
range- the double range of the chromosome.- Returns:
- a new random
DoubleChromosomeof length one - Throws:
NullPointerException- if the givenrangeisnull- Since:
- 3.2
-
min
public A 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
public A 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
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
-
-