|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math3.genetics.Chromosome
org.apache.commons.math3.genetics.AbstractListChromosome<java.lang.Double>
org.apache.commons.math3.genetics.RandomKey<T>
T
- type of the permuted objectspublic abstract class RandomKey<T>
Random Key chromosome is used for permutation representation. It is a vector of a fixed length of real numbers in [0,1] interval. The index of the i-th smallest value in the vector represents an i-th member of the permutation.
For example, the random key [0.2, 0.3, 0.8, 0.1] corresponds to the permutation of indices (3,0,1,2). If the original (unpermuted) sequence would be (a,b,c,d), this would mean the sequence (d,a,b,c).
With this representation, common operators like n-point crossover can be used, because any such chromosome represents a valid permutation.
Since the chromosome (and thus its arrayRepresentation) is immutable, the array representation is sorted only once in the constructor.
For details, see:
Field Summary | |
---|---|
private java.util.List<java.lang.Integer> |
baseSeqPermutation
Base sequence [0,1,...,n-1], permuted accorting to the representation (unmodifiable). |
private java.util.List<java.lang.Double> |
sortedRepresentation
Cache of sorted representation (unmodifiable). |
Constructor Summary | |
---|---|
RandomKey(java.lang.Double[] representation)
Constructor. |
|
RandomKey(java.util.List<java.lang.Double> representation)
Constructor. |
Method Summary | ||
---|---|---|
private static java.util.List<java.lang.Integer> |
baseSequence(int l)
Helper for constructor. |
|
protected void |
checkValidity(java.util.List<java.lang.Double> chromosomeRepresentation)
Asserts that representation can represent a valid chromosome. |
|
static
|
comparatorPermutation(java.util.List<S> data,
java.util.Comparator<S> comparator)
Generates a representation of a permutation corresponding to the data sorted by comparator . |
|
java.util.List<T> |
decode(java.util.List<T> sequence)
Permutes the sequence of objects of type T according to the
permutation this chromosome represents. |
|
private static
|
decodeGeneric(java.util.List<S> sequence,
java.util.List<java.lang.Double> representation,
java.util.List<java.lang.Double> sortedRepr)
Decodes a permutation represented by representation and
returns a (generic) list with the permuted values. |
|
static java.util.List<java.lang.Double> |
identityPermutation(int l)
Generates a representation corresponding to an identity permutation of length l which can be passed to the RandomKey constructor. |
|
static
|
inducedPermutation(java.util.List<S> originalData,
java.util.List<S> permutedData)
Generates a representation of a permutation corresponding to a permutation which yields permutedData when applied to
originalData . |
|
protected boolean |
isSame(Chromosome another)
Returns true iff another is a RandomKey and
encodes the same permutation. |
|
static java.util.List<java.lang.Double> |
randomPermutation(int l)
Generates a representation corresponding to a random permutation of length l which can be passed to the RandomKey constructor. |
|
java.lang.String |
toString()
|
Methods inherited from class org.apache.commons.math3.genetics.AbstractListChromosome |
---|
getLength, getRepresentation, newFixedLengthChromosome |
Methods inherited from class org.apache.commons.math3.genetics.Chromosome |
---|
compareTo, findSameChromosome, getFitness, searchForFitnessUpdate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.commons.math3.genetics.Fitness |
---|
fitness |
Field Detail |
---|
private final java.util.List<java.lang.Double> sortedRepresentation
private final java.util.List<java.lang.Integer> baseSeqPermutation
Constructor Detail |
---|
public RandomKey(java.util.List<java.lang.Double> representation) throws InvalidRepresentationException
representation
- list of [0,1] values representing the permutation
InvalidRepresentationException
- iff the representation
can not represent a valid chromosomepublic RandomKey(java.lang.Double[] representation) throws InvalidRepresentationException
representation
- array of [0,1] values representing the permutation
InvalidRepresentationException
- iff the representation
can not represent a valid chromosomeMethod Detail |
---|
public java.util.List<T> decode(java.util.List<T> sequence)
sequence
of objects of type T according to the
permutation this chromosome represents. For example, if this chromosome
represents a permutation (3,0,1,2), and the unpermuted sequence is
(a,b,c,d), this yields (d,a,b,c).
decode
in interface PermutationChromosome<T>
sequence
- the unpermuted (original) sequence of objects
sequence
represented by this permutationprivate static <S> java.util.List<S> decodeGeneric(java.util.List<S> sequence, java.util.List<java.lang.Double> representation, java.util.List<java.lang.Double> sortedRepr) throws DimensionMismatchException
representation
and
returns a (generic) list with the permuted values.
S
- generic type of the sequence valuessequence
- the unpermuted sequencerepresentation
- representation of the permutation ([0,1] vector)sortedRepr
- sorted representation
DimensionMismatchException
- iff the length of the sequence
,
representation
or sortedRepr
lists are not equalprotected boolean isSame(Chromosome another)
true
iff another
is a RandomKey and
encodes the same permutation.
isSame
in class Chromosome
another
- chromosome to compare
protected void checkValidity(java.util.List<java.lang.Double> chromosomeRepresentation) throws InvalidRepresentationException
representation
can represent a valid chromosome.
checkValidity
in class AbstractListChromosome<java.lang.Double>
chromosomeRepresentation
- representation of the chromosome
InvalidRepresentationException
- iff the representation
can not represent a valid chromosomepublic static final java.util.List<java.lang.Double> randomPermutation(int l)
l
- length of the permutation
public static final java.util.List<java.lang.Double> identityPermutation(int l)
l
- length of the permutation
public static <S> java.util.List<java.lang.Double> comparatorPermutation(java.util.List<S> data, java.util.Comparator<S> comparator)
data
sorted by comparator
. The
data
is not modified during the process.
This is useful if you want to inject some permutations to the initial
population.
S
- type of the datadata
- list of data determining the ordercomparator
- how the data will be compared
public static <S> java.util.List<java.lang.Double> inducedPermutation(java.util.List<S> originalData, java.util.List<S> permutedData) throws DimensionMismatchException, MathIllegalArgumentException
permutedData
when applied to
originalData
.
This method can be viewed as an inverse to decode(List)
.
S
- type of the dataoriginalData
- the original, unpermuted datapermutedData
- the data, somehow permuted
originalData -> permutedData
DimensionMismatchException
- iff the length of originalData
and permutedData
lists are not equal
MathIllegalArgumentException
- iff the permutedData
and
originalData
lists contain different datapublic java.lang.String toString()
toString
in class AbstractListChromosome<java.lang.Double>
private static java.util.List<java.lang.Integer> baseSequence(int l)
l
- length of list to generate
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |