Package ec.neat

Class NEATIndividual

All Implemented Interfaces:
Prototype, Setup, Serializable, Cloneable, Comparable<Individual>

public class NEATIndividual extends GeneVectorIndividual
NEATIndividual is GeneVectorIndividual with NEATNetwork as phenotype. It contains the genome of the individual and also the nodes (NEATNode) for phenotype. It's the combination of Organism class and Genome class in original code. Most of the mutation and crossover happen in this class.

Parameters

base.network
Classname, = ec.neat.NEATNetwork
Class of network in the individual

Parameter bases

base.network
network in the individual

Default Base
neat.individual

See Also:
  • Field Details

    • adjustedFitness

      public double adjustedFitness
      Fitness after the adjustment.
    • subspecies

      public NEATSubspecies subspecies
      The individual's subpecies
    • expectedOffspring

      public double expectedOffspring
      Number of children this individual may have for next generation.
    • generation

      public int generation
      Tells which generation this individual is from.
    • eliminate

      public boolean eliminate
      Marker for destruction of inferior individual.
    • champion

      public boolean champion
      Marks the subspecies champion, which is the individual who has the highest fitness with the subspecies.
    • superChampionOffspring

      public int superChampionOffspring
      Number of reserved offspring for a population leader. This is used for delta coding.
    • popChampion

      public boolean popChampion
      Marks the best individual in current generation of the population.
    • popChampionChild

      public boolean popChampionChild
      Marks the duplicate child of a champion (for tracking purposes).
    • highFit

      public double highFit
      debug variable, highest fitness of champion
    • timeAlive

      public int timeAlive
      When playing in real-time allows knowing the maturity of an individual
    • nodes

      public ArrayList<NEATNode> nodes
      All the node of this individual. Nodes are arranged so that the first part of the nodes are SENSOR nodes.
  • Constructor Details

    • NEATIndividual

      public NEATIndividual()
  • Method Details

    • setup

      public void setup(EvolutionState state, Parameter base)
      Description copied from class: Individual
      This should be used to set up only those things which you share in common with all other individuals in your species; individual-specific items which make you you should be filled in by Species.newIndividual(...), and modified by breeders.
      Specified by:
      setup in interface Prototype
      Specified by:
      setup in interface Setup
      Overrides:
      setup in class GeneVectorIndividual
      See Also:
    • 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 GeneVectorIndividual
    • reset

      public void reset(EvolutionState state, int thread)
      Initializes an individual with minimal structure.
      Overrides:
      reset in class GeneVectorIndividual
    • reset

      public void reset(ArrayList<NEATNode> nodeList, ArrayList<Gene> genes)
      Reset the individual with given nodes and genome
    • hashCode

      public int hashCode()
      Description copied from class: Individual
      Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
      Overrides:
      hashCode in class GeneVectorIndividual
    • equals

      public boolean equals(Object obj)
      Description copied from class: Individual
      Returns true if I am genetically "equal" to ind. This should mostly be interpreted as saying that we are of the same class and that we hold the same data. It should NOT be a pointer comparison.
      Overrides:
      equals in class GeneVectorIndividual
    • setGeneration

      public void setGeneration(EvolutionState state)
      Set the born generation of this individual.
    • getNodeIdSup

      public int getNodeIdSup()
      Get the upperbound for the node id, used in Initializer.
    • getGeneInnovationNumberSup

      public int getGeneInnovationNumberSup()
      Get the upperbound for the innovation number, used in Initializer.
    • 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 GeneVectorIndividual
    • genotypeToString

      public String genotypeToString()
      This method is used to output a individual that is same as the format in start genome file.
      Overrides:
      genotypeToString in class GeneVectorIndividual
    • parseGenotype

      protected void parseGenotype(EvolutionState state, LineNumberReader reader) throws IOException
      This method is used to read a gene in start genome from file. It will then calls the corresponding methods to parse genome and nodes respectively.
      Overrides:
      parseGenotype in class GeneVectorIndividual
      Throws:
      IOException
    • parseNodes

      public void parseNodes(EvolutionState state, LineNumberReader reader) throws IOException
      Create the nodes from the reader, and calls readNode method on each node.
      Throws:
      IOException
    • addGene

      public void addGene(NEATGene[] appendGenes)
      We append new gene(s) to the current genome
    • mutateLinkWeights

      public void mutateLinkWeights(EvolutionState state, int thread, NEATSpecies species, double power, double rate, NEATSpecies.MutationType mutationType)
      Mutate the weights of the genes
    • mutateAddLink

      public void mutateAddLink(EvolutionState state, int thread)
      Try to add a new gene (link) into the current genome.
    • mutateAddNode

      public void mutateAddNode(EvolutionState state, int thread)
      Add a new node into this individual.
    • mutateToggleEnable

      public void mutateToggleEnable(EvolutionState state, int thread, int times)
      Randomly enable or disable a gene.
    • mutateGeneReenable

      public void mutateGeneReenable()
      Reenable a gene if it's disabled.
    • defaultMutate

      public void defaultMutate(EvolutionState state, int thread)
      Mutation function, determine which mutation is going to proceed with certain probabilities parameters.
      Overrides:
      defaultMutate in class GeneVectorIndividual
    • crossover

      public NEATIndividual crossover(EvolutionState state, int thread, NEATIndividual secondParent)
      Crossover function. Unlike defaultCrossover, this does not do destructive crossover. It will create a new individual as the crossover of the new parents.
    • mateSinglepoint

      @Deprecated public NEATIndividual mateSinglepoint(EvolutionState state, int thread, NEATIndividual secondParent)
      Deprecated.
    • hasGene

      public boolean hasGene(ArrayList<Gene> genome, Gene gene)
      Test if a genome has certain gene.
    • createNodeCopyIfMissing

      public void createNodeCopyIfMissing(ArrayList<NEATNode> nodeList, NEATNode node)
      Create the node if the nodeList do not have that node.The nodes in the nodeList is guarantee in ascending order according to node's nodeId.
    • mateMultipoint

      public NEATIndividual mateMultipoint(EvolutionState state, int thread, NEATIndividual secondParent, boolean averageFlag)
      Doing crossover from two parent at multiple points in the genome.
    • createNetwork

      public NEATNetwork createNetwork()
    • toString

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