Class AbstractTreeGene<A,G extends AbstractTreeGene<A,G>>

java.lang.Object
io.jenetics.ext.AbstractTreeGene<A,G>
All Implemented Interfaces:
TreeGene<A,G>, FlatTree<A,G>, Tree<A,G>, Gene<A,G>, Factory<G>, Self<G>, Verifiable, Serializable, Iterable<G>

public abstract class AbstractTreeGene<A,G extends AbstractTreeGene<A,G>> extends Object implements TreeGene<A,G>, Serializable
Abstract implementation of the TreeGene interface..
Since:
3.9
Version:
6.0
See Also:
  • Constructor Details

    • AbstractTreeGene

      protected AbstractTreeGene(A allele, int childOffset, int childCount)
      Creates a new tree-gene from the given data.
      Parameters:
      allele - the actual value (allele) of the tree-gene
      childOffset - the offset index of the child in the containing chromosome. If this node has no child, the value should be set to zero.
      childCount - the number of children of this gene
      Throws:
      IllegalArgumentException - if the childCount is smaller than zero
  • Method Details

    • flattenedNodes

      public ISeq<G> flattenedNodes()
      Return the whole flattened tree values in breadth-first order. This method will always return the same ISeq instance.
      Specified by:
      flattenedNodes in interface FlatTree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      the whole flattened tree values
    • root

      public G root()
      Description copied from interface: Tree
      Returns the root of the tree that contains this node. The root is the ancestor with no parent.
      Specified by:
      root in interface Tree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      the root of the tree that contains this node
    • isRoot

      public boolean isRoot()
      Description copied from interface: Tree
      Returns true if this node is the root of the tree.
      Specified by:
      isRoot in interface Tree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      true if this node is the root of its tree, false otherwise
    • size

      public int size()
      Description copied from interface: Tree
      Return the number of nodes of this node (subtree).
      Specified by:
      size in interface Tree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      the number of nodes of this node (subtree)
    • checkTreeState

      protected void checkTreeState()
    • bind

      protected void bind(BaseSeq<G> genes)
      This method is used by the AbstractTreeChromosome to attach itself to this gene.
      Parameters:
      genes - the genes of the attached chromosome
    • childOffset

      public int childOffset()
      Description copied from interface: FlatTree
      Return the index of the first child node in the underlying node array. -1 is returned if this node is a leaf.
      Specified by:
      childOffset in interface FlatTree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      Return the index of the first child node in the underlying node array, or -1 if this node is a leaf
    • allele

      public A allele()
      Specified by:
      allele in interface Gene<A,G extends AbstractTreeGene<A,G>>
    • parent

      public Optional<G> parent()
      Return the parent node of this tree node.
      Specified by:
      parent in interface Tree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      the parent node, or Optional.empty() if this node is the root of the tree
      Throws:
      IllegalStateException - if this gene is not part of a chromosome
    • childAt

      public G childAt(int index)
      Return the child gene with the given index.
      Specified by:
      childAt in interface Tree<A,G extends AbstractTreeGene<A,G>>
      Parameters:
      index - the child index
      Returns:
      the child node with the given index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds ([0, childCount()))
      IllegalStateException - if this gene is not part of a chromosome
    • childCount

      public int childCount()
      Description copied from interface: Tree
      Return the number of children this tree node consists of.
      Specified by:
      childCount in interface Tree<A,G extends AbstractTreeGene<A,G>>
      Returns:
      the number of children this tree node consists of
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface Verifiable
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object