public final class EnumGene<A> extends Object implements Gene<A,EnumGene<A>>, Comparable<EnumGene<A>>, Serializable
Gene which holds enumerable (countable) genes. Will be used for combinatorial
problems in combination with the PermutationChromosome.
Engine instance.
final ISeq<Integer> alleles = ISeq.of(1, 2, 3, 4, 5, 6, 7, 8);
final Factory<Genotype<EnumGene<Integer>>> gtf = Genotype.of(
PermutationChromosome.of(alleles)
);EnumGene.
final ISeq<Integer> alleles = ISeq.of(1, 2, 3, 4, 5, 6, 7, 8);
final EnumGene<Integer> gene = new EnumGene<>(5, alleles);
assert(gene.getAlleleIndex() == 5);
assert(gene.getAllele() == gene.getValidAlleles().get(5));
assert(gene.getValidAlleles() == alleles);PermutationChromosome,
PartiallyMatchedCrossover,
Serialized Form| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(EnumGene<A> gene) |
boolean |
equals(Object obj) |
A |
getAllele()
Return the allele of this gene.
|
int |
getAlleleIndex()
Return the index of the allele this gene is representing.
|
ISeq<A> |
getValidAlleles()
Return sequence of the valid alleles where this gene is a part of.
|
int |
hashCode() |
boolean |
isValid()
Check if this object is valid.
|
EnumGene<A> |
newInstance()
Return a new, random gene with the same type and with the same constraints
than this gene.
|
EnumGene<A> |
newInstance(A value)
Create a new gene from the given
value and the gene context. |
static <A> EnumGene<A> |
of(A... validAlleles)
Return a new enum gene with an allele randomly chosen from the given
valid alleles.
|
static <A> EnumGene<A> |
of(int alleleIndex,
A... validAlleles)
Create a new enum gene from the given valid genes and the chosen allele
index.
|
static <A> EnumGene<A> |
of(int alleleIndex,
ISeq<? extends A> validAlleles)
Create a new enum gene from the given valid genes and the chosen allele
index.
|
static <A> EnumGene<A> |
of(ISeq<? extends A> validAlleles)
Return a new enum gene with an allele randomly chosen from the given
valid alleles.
|
String |
toString() |
public ISeq<A> getValidAlleles()
public int getAlleleIndex()
public A getAllele()
Genepublic boolean isValid()
VerifiableisValid in interface Verifiablepublic EnumGene<A> newInstance()
Genegene.getClass() == gene.newInstance().getClass(). Implementations
of this method has to use the Random object which can
be fetched from the RandomRegistry.newInstance in interface Gene<A,EnumGene<A>>newInstance in interface Factory<EnumGene<A>>public EnumGene<A> newInstance(A value)
value and the gene context.newInstance in interface Gene<A,EnumGene<A>>value - the value of the new gene.public int compareTo(EnumGene<A> gene)
compareTo in interface Comparable<EnumGene<A>>public static <A> EnumGene<A> of(int alleleIndex, ISeq<? extends A> validAlleles)
A - the allele typealleleIndex - the index of the allele for this gene.validAlleles - the sequence of valid alleles.EnumGene with the given with the allele
validAlleles.get(alleleIndex)IllegalArgumentException - if the give valid alleles sequence is
emptyNullPointerException - if the valid alleles seq is null.public static <A> EnumGene<A> of(ISeq<? extends A> validAlleles)
A - the allele typevalidAlleles - the sequence of valid alleles.EnumGene with an randomly chosen allele from the
sequence of valid allelesIllegalArgumentException - if the give valid alleles
sequence is emptyNullPointerException - if the valid alleles seq is null.@SafeVarargs public static <A> EnumGene<A> of(int alleleIndex, A... validAlleles)
A - the allele typealleleIndex - the index of the allele for this gene.validAlleles - the array of valid alleles.EnumGene with the given with the allele
validAlleles[alleleIndex]IllegalArgumentException - if the give valid alleles
array is empty of the allele index is out of range.@SafeVarargs public static <A> EnumGene<A> of(A... validAlleles)
A - the allele typevalidAlleles - the array of valid alleles.EnumGene with an randomly chosen allele from the
sequence of valid allelesIllegalArgumentException - if the give valid alleles array is empty© 2007-2017 Franz Wilhelmstötter (2017-04-28 16:50)