java.lang.Object
io.jenetics.EnumGene<A>
- All Implemented Interfaces:
Gene<A,,EnumGene<A>> Factory<EnumGene<A>>,Self<EnumGene<A>>,Verifiable,Serializable,Comparable<EnumGene<A>>
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.alleleIndex() == 5);
assert(gene.allele() == gene.validAlleles().get(5));
assert(gene.validAlleles() == alleles);
- Since:
- 1.0
- Version:
- 5.2
- See Also:
- Implementation Note:
- This class is immutable and thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionallele()Return the allele of this gene.intReturn the index of the allele this gene is representing.intbooleaninthashCode()booleanisValid()Check if this object is valid.Return a new, random gene with the same type and with the same constraints as this gene.newInstance(A value) Create a new gene from the givenvalueand the gene context.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> Create a new enum gene from the given valid genes and the chosen allele index.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> Return a new enum gene with an allele randomly chosen from the given valid alleles.toString()Return sequence of the valid alleles where this gene is a part of.
-
Method Details
-
validAlleles
Return sequence of the valid alleles where this gene is a part of.- Returns:
- the sequence of the valid alleles.
-
alleleIndex
Return the index of the allele this gene is representing.- Returns:
- the index of the allele this gene is representing
-
allele
Description copied from interface:GeneReturn the allele of this gene. -
isValid
Description copied from interface:VerifiableCheck if this object is valid.- Specified by:
isValidin interfaceVerifiable- Returns:
- true if this object is valid, false otherwise.
-
newInstance
Description copied from interface:GeneReturn a new, random gene with the same type and with the same constraints as this gene. For all genes returned by this method holdsgene.getClass() == gene.newInstance().getClass(). Implementations of this method have to use theRandomGeneratorobject which can be fetched from theRandomRegistry.- Specified by:
newInstancein interfaceFactory<A>- Specified by:
newInstancein interfaceGene<A,EnumGene<A>> - Returns:
- a new instance of type T
-
newInstance
Create a new gene from the givenvalueand the gene context.- Specified by:
newInstancein interfaceGene<A,EnumGene<A>> - Parameters:
value- the value of the new gene- Returns:
- a new gene with the given value
- Since:
- 1.6
-
compareTo
- Specified by:
compareToin interfaceComparable<A>
-
hashCode
-
equals
-
toString
-
of
Create a new enum gene from the given valid genes and the chosen allele index.- Type Parameters:
A- the allele type- Parameters:
alleleIndex- the index of the allele for this genevalidAlleles- the sequence of valid alleles- Returns:
- a new
EnumGenewith the given with the allelevalidAlleles.get(alleleIndex) - Throws:
IllegalArgumentException- if the give valid alleles sequence is emptyNullPointerException- if the valid alleles seq isnull.- Since:
- 3.4
-
of
Return a new enum gene with an allele randomly chosen from the given valid alleles.- Type Parameters:
A- the allele type- Parameters:
validAlleles- the sequence of valid alleles.- Returns:
- a new
EnumGenewith a randomly chosen allele from the sequence of valid alleles - Throws:
IllegalArgumentException- if the give valid alleles sequence is emptyNullPointerException- if the valid alleles seq isnull.
-
of
Create a new enum gene from the given valid genes and the chosen allele index.- Type Parameters:
A- the allele type- Parameters:
alleleIndex- the index of the allele for this genevalidAlleles- the array of valid alleles.- Returns:
- a new
EnumGenewith the given with the allelevalidAlleles[alleleIndex] - Throws:
IllegalArgumentException- if the give valid alleles array is empty of the allele index is out of range.
-
of
Return a new enum gene with an allele randomly chosen from the given valid alleles.- Type Parameters:
A- the allele type- Parameters:
validAlleles- the array of valid alleles- Returns:
- a new
EnumGenewith a randomly chosen allele from the sequence of valid alleles - Throws:
IllegalArgumentException- if the give valid alleles array is empty
-