public class BitChromosome extends Number implements Chromosome<BitGene>, Comparable<BitChromosome>, Serializable
BitGene
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected byte[] |
_genes
The boolean array which holds the
BitGene s. |
protected int |
_length
The length of the chromosomes (number of bits).
|
protected double |
_p
The ones probability of the randomly generated Chromosome.
|
Constructor and Description |
---|
BitChromosome(byte[] bits)
Create a new
BitChromosome from the given byte array. |
BitChromosome(byte[] bits,
int start,
int end)
Create a new bit chromosome from the given bit (byte) array.
|
Modifier and Type | Method and Description |
---|---|
int |
bitCount()
Returns the number of bits set to true in this
BitChromosome . |
boolean |
booleanValue()
Return the value of the first gene of this chromosome.
|
boolean |
booleanValue(int index)
Return the value on the specified index.
|
int |
compareTo(BitChromosome that) |
double |
doubleValue()
Return the double value this BitChromosome represents.
|
boolean |
equals(Object obj) |
float |
floatValue()
Return the float value this BitChromosome represents.
|
boolean |
get()
Deprecated.
Use
booleanValue() instead |
boolean |
get(int index)
Deprecated.
Use
booleanValue(int) instead |
BitGene |
getGene()
Return the first gene of this chromosome.
|
BitGene |
getGene(int index)
Return the gene on the specified index.
|
double |
getOneProbability()
Return the one probability of this chromosome.
|
int |
hashCode() |
int |
intValue()
Return the long value this BitChromosome represents.
|
BitChromosome |
invert()
Invert the ones and zeros of this bit chromosome.
|
boolean |
isValid()
Check if this object is valid.
|
Iterator<BitGene> |
iterator() |
int |
length()
Returns the length of the Chromosome.
|
ListIterator<BitGene> |
listIterator() |
long |
longValue()
Return the long value this BitChromosome represents.
|
BitChromosome |
newInstance()
Create a new instance of type T.
|
BitChromosome |
newInstance(ISeq<BitGene> genes)
A factory method which creates a new
Chromosome of specific type
and the given genes . |
static BitChromosome |
of(BigInteger value)
Create a new
BitChromosome from the given big integer value. |
static BitChromosome |
of(BigInteger value,
double p)
Create a new
BitChromosome from the given big integer value and
ones probability. |
static BitChromosome |
of(BitSet bits)
Constructing a new BitChromosome from a given BitSet.
|
static BitChromosome |
of(BitSet bits,
int length)
Create a new
BitChromosome with the given parameters. |
static BitChromosome |
of(BitSet bits,
int length,
double p)
Create a new
BitChromosome with the given parameters. |
static BitChromosome |
of(CharSequence value)
Create a new
BitChromosome from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method. |
static BitChromosome |
of(CharSequence value,
double p)
Create a new
BitChromosome from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method. |
static BitChromosome |
of(CharSequence value,
int length,
double p)
Create a new
BitChromosome from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method. |
static BitChromosome |
of(int length)
Constructing a new BitChromosome with the given _length.
|
static BitChromosome |
of(int length,
double p)
Construct a new BitChromosome with the given _length.
|
IntStream |
ones()
Return the indexes of the ones of this bit-chromosome as stream.
|
BigInteger |
toBigInteger()
Return the
BigInteger value this BitChromosome represents. |
BitSet |
toBitSet()
Return the corresponding BitSet of this BitChromosome.
|
byte[] |
toByteArray() |
int |
toByteArray(byte[] bytes)
Returns the two's-complement binary representation of this
large integer.
|
String |
toCanonicalString()
Return the BitChromosome as String.
|
ISeq<BitGene> |
toSeq()
Return an unmodifiable sequence of the genes of this chromosome.
|
String |
toString() |
IntStream |
zeros()
Return the indexes of the zeros of this bit-chromosome as stream.
|
byteValue, shortValue
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
as, stream
forEach, spliterator
protected double _p
protected int _length
public BitChromosome(byte[] bits, int start, int end)
bits
- the bit values of the new chromosome gene.start
- the initial (bit) index of the range to be copied, inclusiveend
- the final (bit) index of the range to be copied, exclusive.
(This index may lie outside the array.)ArrayIndexOutOfBoundsException
- if start < 0
or
start > bits.length*8
IllegalArgumentException
- if start > end
NullPointerException
- if the bits
array is
null
.public BitChromosome(byte[] bits)
BitChromosome
from the given byte
array.
This is a shortcut for new BitChromosome(bits, 0, bits.length*8)
.bits
- the byte
array.public double getOneProbability()
public BitGene getGene()
Chromosome
getGene
in interface Chromosome<BitGene>
@Deprecated public boolean get()
booleanValue()
insteadpublic boolean booleanValue()
public BitGene getGene(int index)
Chromosome
getGene
in interface Chromosome<BitGene>
index
- The gene index.@Deprecated public boolean get(int index)
booleanValue(int)
insteadindex
- the gene indexIndexOutOfBoundsException
- if the index is out of range
(index < 1 || index >= length()).public boolean booleanValue(int index)
index
- the gene indexIndexOutOfBoundsException
- if the index is out of range
(index < 1 || index >= length()).public ISeq<BitGene> toSeq()
Chromosome
toSeq
in interface Chromosome<BitGene>
public int length()
Chromosome
length
in interface Chromosome<BitGene>
public int bitCount()
BitChromosome
.BitChromosome
public ListIterator<BitGene> listIterator()
public int intValue()
public long longValue()
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public boolean isValid()
Verifiable
isValid
in interface Verifiable
public BigInteger toBigInteger()
BigInteger
value this BitChromosome
represents.BigInteger
value this BitChromosome
represents.public int toByteArray(byte[] bytes)
Note: This representation is consistent with java.lang.BigInteger
byte array representation and can be used for conversion
between the two classes.
bytes
- the bytes to hold the binary representation
(two's-complement) of this large integer.IndexOutOfBoundsException
- if bytes.length < (int)Math.ceil(length()/8.0)
NullPointerException
- it the give array is null
.public byte[] toByteArray()
BitChromosome
. The
length of the array is (int)Math.ceil(length()/8.0)
.toByteArray(byte[])
public BitSet toBitSet()
public IntStream ones()
public IntStream zeros()
public BitChromosome newInstance(ISeq<BitGene> genes)
Chromosome
Chromosome
of specific type
and the given genes
.newInstance
in interface Chromosome<BitGene>
genes
- the genes of the new chromosome. The given genes array is
not copied.Chromosome
of the same type with the given genes.public BitChromosome newInstance()
Factory
newInstance
in interface Factory<Chromosome<BitGene>>
public String toCanonicalString()
of(CharSequence)
constructor.public int compareTo(BitChromosome that)
compareTo
in interface Comparable<BitChromosome>
public BitChromosome invert()
public static BitChromosome of(int length, double p)
length
- Length of the BitChromosome, number of bits.p
- Probability of the TRUEs in the BitChromosome.BitChromosome
with the given parameterNegativeArraySizeException
- if the length
is smaller
than one.IllegalArgumentException
- if p
is not a valid probability.public static BitChromosome of(int length)
Chromosome
are equally distributed.length
- Length of the BitChromosome.BitChromosome
with the given parameterNegativeArraySizeException
- if the _length
is smaller
than one.public static BitChromosome of(BitSet bits, int length)
BitChromosome
with the given parameters.length
- length of the BitChromosome.bits
- the bit-set which initializes the chromosomeBitChromosome
with the given parameterNegativeArraySizeException
- if the length
is smaller
than one.NullPointerException
- if the bitSet
is
null
.public static BitChromosome of(BitSet bits, int length, double p)
BitChromosome
with the given parameters.length
- length of the BitChromosome.bits
- the bit-set which initializes the chromosomep
- Probability of the TRUEs in the BitChromosome.BitChromosome
with the given parameterNegativeArraySizeException
- if the length
is smaller than
one.NullPointerException
- if the bitSet
is null
.IllegalArgumentException
- if p
is not a valid probability.public static BitChromosome of(BitSet bits)
bitSet.length()
(BitSet.length()
).bits
- the bit-set which initializes the chromosomeBitChromosome
with the given parameterNullPointerException
- if the bitSet
is
null
.public static BitChromosome of(BigInteger value)
BitChromosome
from the given big integer value.value
- the value of the created BitChromosome
BitChromosome
with the given parameterNullPointerException
- if the given value
is null
.public static BitChromosome of(BigInteger value, double p)
BitChromosome
from the given big integer value and
ones probability.value
- the value of the created BitChromosome
p
- Probability of the TRUEs in the BitChromosome.BitChromosome
with the given parameterNullPointerException
- if the given value
is null
.IllegalArgumentException
- if p
is not a valid probability.public static BitChromosome of(CharSequence value)
BitChromosome
from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method.value
- the input string.BitChromosome
with the given parameterNullPointerException
- if the value
is null
.IllegalArgumentException
- if the length of the character sequence
is zero or contains other characters than '0' or '1'.public static BitChromosome of(CharSequence value, double p)
BitChromosome
from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method.value
- the input string.p
- Probability of the TRUEs in the BitChromosome.BitChromosome
with the given parameterNullPointerException
- if the value
is null
.IllegalArgumentException
- if the length of the character sequence
is zero or contains other characters than '0' or '1'.IllegalArgumentException
- if p
is not a valid probability.public static BitChromosome of(CharSequence value, int length, double p)
BitChromosome
from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method.value
- the input string.length
- length of the BitChromosomep
- Probability of the TRUEs in the BitChromosome.BitChromosome
with the given parameterNullPointerException
- if the value
is null
.IllegalArgumentException
- if the length of the character sequence
is zero or contains other characters than '0' or '1'.IllegalArgumentException
- if p
is not a valid probability.© 2007-2019 Franz Wilhelmstötter (2019-02-19 21:44)