Class BinaryChromosome
java.lang.Object
org.apache.commons.math3.genetics.Chromosome
org.apache.commons.math3.genetics.AbstractListChromosome<Integer>
org.apache.commons.math3.genetics.BinaryChromosome
- All Implemented Interfaces:
Comparable<Chromosome>
,Fitness
Chromosome represented by a vector of 0s and 1s.
- Since:
- 2.0
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryChromosome
(Integer[] representation) Constructor.BinaryChromosome
(List<Integer> representation) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkValidity
(List<Integer> chromosomeRepresentation) Asserts thatrepresentation
can represent a valid chromosome.protected boolean
isSame
(Chromosome another) Returnstrue
iffanother
has the same representation and therefore the same fitness.randomBinaryRepresentation
(int length) Returns a representation of a random binary array of lengthlength
.Methods inherited from class org.apache.commons.math3.genetics.AbstractListChromosome
getLength, getRepresentation, newFixedLengthChromosome, toString
Methods inherited from class org.apache.commons.math3.genetics.Chromosome
compareTo, findSameChromosome, getFitness, searchForFitnessUpdate
-
Constructor Details
-
BinaryChromosome
Constructor.- Parameters:
representation
- list of {0,1} values representing the chromosome- Throws:
InvalidRepresentationException
- iff therepresentation
can not represent a valid chromosome
-
BinaryChromosome
Constructor.- Parameters:
representation
- array of {0,1} values representing the chromosome- Throws:
InvalidRepresentationException
- iff therepresentation
can not represent a valid chromosome
-
-
Method Details
-
checkValidity
protected void checkValidity(List<Integer> chromosomeRepresentation) throws InvalidRepresentationException Asserts thatrepresentation
can represent a valid chromosome.- Specified by:
checkValidity
in classAbstractListChromosome<Integer>
- Parameters:
chromosomeRepresentation
- representation of the chromosome- Throws:
InvalidRepresentationException
- iff therepresentation
can not represent a valid chromosome
-
randomBinaryRepresentation
Returns a representation of a random binary array of lengthlength
.- Parameters:
length
- length of the array- Returns:
- a random binary array of length
length
-
isSame
Returnstrue
iffanother
has the same representation and therefore the same fitness. By default, it returns false -- override it in your implementation if you need it.- Overrides:
isSame
in classChromosome
- Parameters:
another
- chromosome to compare- Returns:
- true if
another
is equivalent to this chromosome
-