Class BinaryChromosome
- java.lang.Object
-
- org.apache.commons.math4.legacy.genetics.Chromosome
-
- org.apache.commons.math4.legacy.genetics.AbstractListChromosome<Integer>
-
- org.apache.commons.math4.legacy.genetics.BinaryChromosome
-
- All Implemented Interfaces:
Comparable<Chromosome>,Fitness
public abstract class BinaryChromosome extends AbstractListChromosome<Integer>
Chromosome represented by a vector of 0s and 1s.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description BinaryChromosome(Integer[] representation)Constructor.BinaryChromosome(List<Integer> representation)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckValidity(List<Integer> chromosomeRepresentation)Asserts thatrepresentationcan represent a valid chromosome.protected booleanisSame(Chromosome another)Returnstrueiffanotherhas the same representation and therefore the same fitness.static List<Integer>randomBinaryRepresentation(int length)Returns a representation of a random binary array of lengthlength.-
Methods inherited from class org.apache.commons.math4.legacy.genetics.AbstractListChromosome
getLength, getRepresentation, newFixedLengthChromosome, toString
-
Methods inherited from class org.apache.commons.math4.legacy.genetics.Chromosome
compareTo, findSameChromosome, getFitness, searchForFitnessUpdate
-
-
-
-
Constructor Detail
-
BinaryChromosome
public BinaryChromosome(List<Integer> representation) throws InvalidRepresentationException
Constructor.- Parameters:
representation- list of {0,1} values representing the chromosome- Throws:
InvalidRepresentationException- iff therepresentationcan not represent a valid chromosome
-
BinaryChromosome
public BinaryChromosome(Integer[] representation) throws InvalidRepresentationException
Constructor.- Parameters:
representation- array of {0,1} values representing the chromosome- Throws:
InvalidRepresentationException- iff therepresentationcan not represent a valid chromosome
-
-
Method Detail
-
checkValidity
protected void checkValidity(List<Integer> chromosomeRepresentation) throws InvalidRepresentationException
Asserts thatrepresentationcan represent a valid chromosome.- Specified by:
checkValidityin classAbstractListChromosome<Integer>- Parameters:
chromosomeRepresentation- representation of the chromosome- Throws:
InvalidRepresentationException- iff therepresentationcan not represent a valid chromosome
-
randomBinaryRepresentation
public static List<Integer> randomBinaryRepresentation(int length)
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
protected boolean isSame(Chromosome another)
Returnstrueiffanotherhas the same representation and therefore the same fitness. By default, it returns false -- override it in your implementation if you need it.- Overrides:
isSamein classChromosome- Parameters:
another- chromosome to compare- Returns:
- true if
anotheris equivalent to this chromosome
-
-