Package ec.neat

# Class NEATGene

java.lang.Object
ec.vector.Gene
ec.neat.NEATGene

All Implemented Interfaces:
  `Prototype`, `Setup`, `Serializable`, `Cloneable`

public class NEATGene extends Gene
NEATGene is the combination of class Gene and class Link in original code. It is used to represent a single connection between two nodes (NEATNode) of a neural network, and extends the abstract Gene class to make use of its read/write utilities.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `boolean`
  `enable`
  Is the link this gene represent is enable in network activation.
  `boolean`
  `frozen`
  Is this gene frozen, a frozen gene's weight cannot get mutated in breeding procedure.
  `NEATNode`
  `inNode`
  The actual in node this gene connect to.
  `int`
  `inNodeId`
  The id of the in node, this is useful in reading a gene from file, we will use this id to find the actual node after we finish reading the genome file.
  `int`
  `innovationNumber`
  The innovation number of this link.
  `boolean`
  `isRecurrent`
  Is the link this gene represent a recurrent link.
  `double`
  `mutationNumber`
  The mutation number of this gene, Used to see how much mutation has changed.
  `NEATNode`
  `outNode`
  The actual out node this gene connect to.
  `int`
  `outNodeId`
  The id of the in node, this is useful in reading a gene from file, we will use this id to find the actual node after we finish reading the genome file.
  `static final String`
  `P_GENE`
  `boolean`
  `timeDelay`
  Time delay of the link, used in network activation.
  `double`
  `weight`
  The weight of link this gene is represent.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NEATGene()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
  `Parameter`
  `defaultBase()`
  Returns the default base for this prototype.
  `boolean`
  `equals(Object o)`
  Unlike the standard form for Java, this function should return true if this gene is "genetically identical" to the other gene.
  `int`
  `hashCode()`
  "Placeholder" method for generating a hashcode.
  `String`
  `printGeneToString()`
  This method is used to output a gene that is same as the format in start genome file.
  `String`
  `printGeneToStringForHumans()`
  Prints the gene to a string in a human-readable fashion.
  `void`
  `readGeneFromString(String string, EvolutionState state)`
  This method is used to read a gene in start genome from file.
  `void`
  `reset(double w, int iNodeId, int oNodeId, boolean recur, int innov, double mutNum)`
  Reset the gene with given parameters.
  `void`
  `reset(EvolutionState state, int thread)`
  The reset method randomly reinitializes the gene.
  `void`
  `setup(EvolutionState state, Parameter base)`
  The setup method initializes a "meaningless" gene that does not specify any connection.
  `String`
  `toString()`
  This method convert the gene in to human readable format.

  ### Methods inherited from class ec.vector.Gene

  `mutate, printGene, printGene, printGeneForHumans, readGene, readGene, writeGene`

  ### Methods inherited from class java.lang.Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### P_GENE

    public static final String P_GENE
    See Also:
      - Constant Field Values

  - ### weight

    public double weight
    The weight of link this gene is represent.

  - ### inNode

    public NEATNode inNode
    The actual in node this gene connect to.

  - ### outNode

    public NEATNode outNode
    The actual out node this gene connect to.

  - ### inNodeId

    public int inNodeId
    The id of the in node, this is useful in reading a gene from file, we will use this id to find the actual node after we finish reading the genome file.

  - ### outNodeId

    public int outNodeId
    The id of the in node, this is useful in reading a gene from file, we will use this id to find the actual node after we finish reading the genome file.

  - ### isRecurrent

    public boolean isRecurrent
    Is the link this gene represent a recurrent link.

  - ### timeDelay

    public boolean timeDelay
    Time delay of the link, used in network activation.

  - ### innovationNumber

    public int innovationNumber
    The innovation number of this link.

  - ### mutationNumber

    public double mutationNumber
    The mutation number of this gene, Used to see how much mutation has changed.

  - ### enable

    public boolean enable
    Is the link this gene represent is enable in network activation.

  - ### frozen

    public boolean frozen
    Is this gene frozen, a frozen gene's weight cannot get mutated in breeding procedure.

- ## Constructor Details

  - ### NEATGene

    public NEATGene()

- ## Method Details

  - ### setup

    public void setup(EvolutionState state, Parameter base)
    The setup method initializes a "meaningless" gene that does not specify any connection.
    Specified by:
      `setup` in interface `Prototype`
    Specified by:
      `setup` in interface `Setup`
    Overrides:
      `setup` in class `Gene`

  - ### defaultBase

    public Parameter defaultBase()
    Description copied from interface: `Prototype`
    Returns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...).
    Specified by:
      `defaultBase` in interface `Prototype`
    Overrides:
      `defaultBase` in class `Gene`

  - ### reset

    public void reset(EvolutionState state, int thread)
    Description copied from class: `Gene`
    The reset method randomly reinitializes the gene.
    Specified by:
      `reset` in class `Gene`

  - ### reset

    public void reset(double w, int iNodeId, int oNodeId, boolean recur, int innov, double mutNum)
    Reset the gene with given parameters.

  - ### clone

    public Object clone()
    Description copied from interface: `Prototype`
    Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

    Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:

    - If you hold objects which are shared with other instances, don't clone them.
    - If you hold objects which must be unique, clone them.
    - If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
    - DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
    - Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.

    Implementations.

    - If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
    - If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are not abstract, then you should implement it as follows:

      ``

           public Object clone()
               {
               try
                   {
                   return super.clone();
                   }
               catch ((CloneNotSupportedException e)
                   { throw new InternalError(); } // never happens
               }

    - If no ancestor of yours implements clone(), but you need to deep-clone some things, then you should implement it as follows:

      ``

           public Object clone()
               {
               try
                   {
                   MyObject myobj = (MyObject) (super.clone());

                   // put your deep-cloning code here...
                   }
               catch ((CloneNotSupportedException e)
                   { throw new InternalError(); } // never happens
               return myobj;
               }

    - If an ancestor has implemented clone(), and you also need to deep clone some things, then you should implement it as follows:

      ``

           public Object clone()
               {
               MyObject myobj = (MyObject) (super.clone());

               // put your deep-cloning code here...

               return myobj;
               }

    Specified by:
      `clone` in interface `Prototype`
    Overrides:
      `clone` in class `Gene`

  - ### printGeneToStringForHumans

    public String printGeneToStringForHumans()
    Description copied from class: `Gene`
    Prints the gene to a string in a human-readable fashion. The default simply calls toString().
    Overrides:
      `printGeneToStringForHumans` in class `Gene`

  - ### toString

    public String toString()
    This method convert the gene in to human readable format. It can be useful in debugging.
    Overrides:
      `toString` in class `Object`

  - ### printGeneToString

    public String printGeneToString()
    This method is used to output a gene that is same as the format in start genome file.
    Overrides:
      `printGeneToString` in class `Gene`

  - ### readGeneFromString

    public void readGeneFromString(String string, EvolutionState state)
    This method is used to read a gene in start genome from file. Example : i1|i4|d0|0.0|Fi1|d0|0.0|T have these parts : i1 i4 d0|0.0 F i1 d0|0.0 T which are: inNode outNode weight isRecurrent innovationNumber mutationNumber enable
    Overrides:
      `readGeneFromString` in class `Gene`

  - ### hashCode

    public int hashCode()
    "Placeholder" method for generating a hashcode. The algorithm is stolen from GPIndividual and modified a bit to use NEATGene's variables. It is by no means "good" and is subject for improvement.
    Specified by:
      `hashCode` in class `Gene`

  - ### equals

    public boolean equals(Object o)
    Description copied from class: `Gene`
    Unlike the standard form for Java, this function should return true if this gene is "genetically identical" to the other gene.
    Specified by:
      `equals` in class `Gene`