public final class EnumGene<A> extends Object implements Gene<A,EnumGene<A>>, Comparable<EnumGene<A>>
Gene which holds enumerable (countable) genes. Will be used for combinatorial
problems in combination with the PermutationChromosome
.
GeneticAlgorithm
instance.
final ISeq〈Integer〉 alleles = Array.box(1, 2, 3, 4, 5, 6, 7, 8).toISeq();
final Factory〈Genotype〈EnumGene〈Integer〉〉〉 gtf = Genotype.of(
new PermutationChromosome<>(alleles)
);
EnumGene
.
final ISeq〈Integer〉 alleles = Array.box(1, 2, 3, 4, 5, 6, 7, 8).toISeq();
final EnumGene〈Integer〉 gene = new EnumGene<>(5, alleles);
assert(gene.getAlleleIndex() == 5);
assert(gene.getAllele() == gene.getValidAlleles().get(5));
assert(gene.getValidAlleles() == alleles);
PermutationChromosome
,
Serialized FormConstructor and Description |
---|
EnumGene(int alleleIndex,
ISeq<? extends A> validAlleles)
Create a new enum gene from the given valid genes and the chosen allele
index.
|
Modifier and Type | Method and Description |
---|---|
Factory<EnumGene<A>> |
asFactory()
Deprecated.
No longer needed after adding new factory methods to the
Array class. |
int |
compareTo(EnumGene<A> gene) |
EnumGene<A> |
copy()
Deprecated.
|
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 of the same type than this gene.
|
EnumGene<A> |
newInstance(A value)
Create a new gene from the given
value and the gene context. |
static <G> EnumGene<G> |
of(G... validAlleles)
Return a new enum gene with an allele randomly chosen from the given
valid alleles.
|
static <G> EnumGene<G> |
of(int alleleIndex,
G... 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() |
static <G> EnumGene<G> |
valueOf(G[] validAlleles)
Deprecated.
Use
of(Object[]) instead. |
static <G> EnumGene<G> |
valueOf(G[] validAlleles,
int alleleIndex)
Deprecated.
Use
of(int, Object[]) instead. |
static <A> EnumGene<A> |
valueOf(ISeq<? extends A> validAlleles,
int alleleIndex)
Deprecated.
Use
EnumGene(int, org.jenetics.util.ISeq) instead. |
static <G> EnumGene<G> |
valueOf(ISeq<G> validAlleles)
Deprecated.
Use
of(org.jenetics.util.ISeq) instead. |
public EnumGene(int alleleIndex, ISeq<? extends A> validAlleles)
alleleIndex
- the index of the allele for this gene.validAlleles
- the sequence of valid alleles.IllegalArgumentException
- if the give valid alleles
sequence is emptyNullPointerException
- if the valid alleles seq is null
.public ISeq<A> getValidAlleles()
public int getAlleleIndex()
public A getAllele()
Gene
@Deprecated public EnumGene<A> copy()
public boolean isValid()
Verifiable
isValid
in interface Verifiable
public EnumGene<A> newInstance()
Gene
gene.getClass() ==
gene.newInstance().getClass()
.newInstance
in interface Gene<A,EnumGene<A>>
newInstance
in interface Factory<EnumGene<A>>
public EnumGene<A> newInstance(A value)
value
and the gene context.value
- the value of the new gene.public int compareTo(EnumGene<A> gene)
compareTo
in interface Comparable<EnumGene<A>>
@Deprecated public Factory<EnumGene<A>> asFactory()
Array
class.public static <A> EnumGene<A> of(ISeq<? extends A> validAlleles)
validAlleles
- the sequence of valid alleles.IllegalArgumentException
- if the give valid alleles
sequence is emptyNullPointerException
- if the valid alleles seq is null
.@Deprecated public static <A> EnumGene<A> valueOf(ISeq<? extends A> validAlleles, int alleleIndex)
EnumGene(int, org.jenetics.util.ISeq)
instead.@SafeVarargs public static <G> EnumGene<G> of(int alleleIndex, G... validAlleles)
alleleIndex
- the index of the allele for this gene.validAlleles
- the array of valid alleles.IllegalArgumentException
- if the give valid alleles
array is empty of the allele index is out of range.@Deprecated public static <G> EnumGene<G> valueOf(G[] validAlleles, int alleleIndex)
of(int, Object[])
instead.@Deprecated public static <G> EnumGene<G> valueOf(ISeq<G> validAlleles)
of(org.jenetics.util.ISeq)
instead.@SafeVarargs public static <G> EnumGene<G> of(G... validAlleles)
validAlleles
- the array of valid alleles.IllegalArgumentException
- if the give valid alleles
array is empty@Deprecated public static <G> EnumGene<G> valueOf(G[] validAlleles)
of(Object[])
instead.© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)