public class BitChromosome extends Number<BitChromosome> implements Chromosome<BitGene>, XMLSerializable
Modifier 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 one's probability of the randomly generated Chromosome.
|
Constructor and Description |
---|
BitChromosome(BitSet bits)
Deprecated.
Use
of(java.util.BitSet) instead. |
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.
|
BitChromosome(CharSequence value)
Deprecated.
Use
of(CharSequence) instead. |
BitChromosome(int length)
Deprecated.
Use
of(int) instead. |
BitChromosome(int length,
BitSet bits)
Deprecated.
Use
of(java.util.BitSet, int) instead. |
BitChromosome(int length,
double p)
Deprecated.
Use
of(int, double) instead. |
BitChromosome(LargeInteger value)
Deprecated.
Use
of(java.math.BigInteger) instead. |
Modifier and Type | Method and Description |
---|---|
int |
bitCount()
Returns the number of bits set to true in this
BitChromosome . |
int |
compareTo(BitChromosome that) |
BitChromosome |
copy()
Deprecated.
|
double |
doubleValue()
Return the double value this BitChromosome represents.
|
boolean |
equals(Object o) |
BitGene |
getGene()
Return the first gene of this chromosome.
|
BitGene |
getGene(int index)
Return the gene on the specified index.
|
int |
hashCode() |
BitChromosome |
invert()
Invert the ones and zeros of this bit chromosome.
|
boolean |
isLargerThan(BitChromosome that)
Deprecated.
|
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(BitSet bits)
Constructing a new BitChromosome from a given BitSet.
|
static BitChromosome |
of(BitSet bits,
int length) |
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(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.
|
BitChromosome |
opposite()
Deprecated.
|
BitChromosome |
plus(BitChromosome that)
Deprecated.
|
LargeInteger |
sqrt()
Deprecated.
|
BitChromosome |
times(BitChromosome that)
Deprecated.
|
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.
|
LargeInteger |
toLargeInteger()
Deprecated.
Use
toBigInteger() instead. |
ISeq<BitGene> |
toSeq()
Return an unmodifiable sequence of the genes of this chromosome.
|
Text |
toText()
Deprecated.
|
byteValue, floatValue, intValue, isGreaterThan, isLessThan, minus, pow, shortValue, toString
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*8IllegalArgumentException
- if start > endNullPointerException
- 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.@Deprecated public BitChromosome(int length, double p)
of(int, double)
instead.length
- Length of the BitChromosome, number of bits.p
- Probability of the TRUEs in the BitChromosome.NegativeArraySizeException
- if the length
is smaller
than one.IllegalArgumentException
- if p
is not a valid probability.@Deprecated public BitChromosome(int length)
of(int)
instead.Chromosome
are equally distributed.length
- Length of the BitChromosome.NegativeArraySizeException
- if the _length
is smaller
than one.@Deprecated public BitChromosome(int length, BitSet bits)
of(java.util.BitSet, int)
instead.length
- Length of the BitChromosome.bits
- the bit-set which initializes the chromosomeNegativeArraySizeException
- if the length
is smaller
than one.NullPointerException
- if the bitSet
is
null
.@Deprecated public BitChromosome(BitSet bits)
of(java.util.BitSet)
instead.bitSet.length()
(@see BitSet#length).bits
- the bit-set which initializes the chromosomeNullPointerException
- if the bitSet
is
null
.@Deprecated public BitChromosome(LargeInteger value)
of(java.math.BigInteger)
instead.BitChromosome
from the given large integer value.value
- the value of the created BitChromosome
NullPointerException
- if the given value
is null
.@Deprecated public BitChromosome(CharSequence value)
of(CharSequence)
instead.BitChromosome
from the given character sequence
containing '0' and '1'; as created with the toCanonicalString()
method.value
- the input string.NullPointerException
- if the value
is null
.IllegalArgumentException
- if the length of the character sequence
is zero or contains other characters than '0' or '1'.public BitGene getGene()
Chromosome
getGene
in interface Chromosome<BitGene>
public BitGene getGene(int index)
Chromosome
getGene
in interface Chromosome<BitGene>
index
- The gene index.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 long longValue()
longValue
in class Number<BitChromosome>
public double doubleValue()
doubleValue
in class Number<BitChromosome>
public boolean isValid()
Verifiable
isValid
in interface Verifiable
@Deprecated public LargeInteger toLargeInteger()
toBigInteger()
instead.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 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()
BitChromosome(CharSequence)
constructor.public int compareTo(BitChromosome that)
compareTo
in interface Comparable<BitChromosome>
compareTo
in class Number<BitChromosome>
@Deprecated public boolean isLargerThan(BitChromosome that)
isLargerThan
in class Number<BitChromosome>
@Deprecated public LargeInteger sqrt()
@Deprecated public BitChromosome plus(BitChromosome that)
plus
in interface GroupAdditive<BitChromosome>
@Deprecated public BitChromosome opposite()
opposite
in interface GroupAdditive<BitChromosome>
public BitChromosome invert()
@Deprecated public BitChromosome times(BitChromosome that)
times
in interface Ring<BitChromosome>
public static BitChromosome of(int length, double p)
length
- Length of the BitChromosome, number of bits.p
- Probability of the TRUEs in the BitChromosome.NegativeArraySizeException
- 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.NegativeArraySizeException
- if the _length
is smaller
than one.public static BitChromosome of(BitSet bits, int length)
length
- length of the BitChromosome.bits
- the bit-set which initializes the chromosomeNegativeArraySizeException
- if the length
is smaller
than one.NullPointerException
- if the bitSet
is
null
.public static BitChromosome of(BitSet bits)
bitSet.length()
(@see BitSet#length).bits
- the bit-set which initializes the chromosomeNullPointerException
- 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
NullPointerException
- if the given value
is null
.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.NullPointerException
- if the value
is null
.IllegalArgumentException
- if the length of the character sequence
is zero or contains other characters than '0' or '1'.public int hashCode()
hashCode
in class Number<BitChromosome>
public boolean equals(Object o)
equals
in class Number<BitChromosome>
@Deprecated public Text toText()
toText
in interface Realtime
toText
in class Number<BitChromosome>
@Deprecated public BitChromosome copy()
copy
in interface ValueType
copy
in class Number<BitChromosome>
© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)