Package ec.neat

Class NEATSubspecies

java.lang.Object
ec.neat.NEATSubspecies
All Implemented Interfaces:
Prototype, Setup, Serializable, Cloneable

public class NEATSubspecies extends Object implements Prototype
NEATSubspecies is the actual Species in original code. However, since we already have Species in ECJ, we name Species in original code as Subspecies in our implementation. The creation of the Subspecies is done in the speciate method.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Age of the current subspecies.
    int
    Record the last time the best fitness improved within the individuals of this subspecies If this is too long ago, the subspecies will goes extinct
    int
    Expected Offspring for next generation for this subspecies
    The individuals within this species
    double
    The max fitness the an individual in this subspecies ever achieved.
    The next generation individuals within this species
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add the individual to the next generation of this subspecies
    void
    adjustFitness(EvolutionState state, int dropoffAge, double ageSignificance)
    Adjust the fitness of the individuals within this subspecies.
    Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
    double
    countOffspring(double skim)
    Compute the collective offspring the entire species (the sum of all individual's offspring) is assigned skim is fractional offspring left over from a previous subspecies that was counted.
    Returns the default base for this prototype.
    Return a clone of this subspecies, but with a empty individuals and newGenIndividuals list.
    Return the first individual in this subspecies
    boolean
    Test if newGenIndividuals list is empty.
    void
    markReproducableIndividuals(double survivalThreshold)
    Mark the individual who can reproduce for this generation.
    Return the first individual in newGenIndividuals list.
    void
    Remove the individuals from current subspecies who have been mark as eliminate the remain individuals will be allow to reproduce
    boolean
    reproduce(EvolutionState state, int thread, int subpop, ArrayList<NEATSubspecies> sortedSubspecies)
    Where the actual reproduce is happening, it will grab the candidate parents, and calls the crossover or mutation method on these parents individuals.
    void
    Reset the status of the current subspecies.
    void
    Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
    void
    Sort the individuals in this subspecies, the one with highest fitness comes first.
    int
    Compute generations gap since last improvement
    void
    After we finish the reproduce, the newGenIndividual list has the all the individuals that is ready for evalution in next generation.
    void
    Update the maxFitnessEver variable.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • P_SUBSPECIES

      public static final String P_SUBSPECIES
      See Also:
    • age

      public int age
      Age of the current subspecies.
    • ageOfLastImprovement

      public int ageOfLastImprovement
      Record the last time the best fitness improved within the individuals of this subspecies If this is too long ago, the subspecies will goes extinct
    • maxFitnessEver

      public double maxFitnessEver
      The max fitness the an individual in this subspecies ever achieved.
    • individuals

      public ArrayList<Individual> individuals
      The individuals within this species
    • newGenIndividuals

      public ArrayList<Individual> newGenIndividuals
      The next generation individuals within this species
    • expectedOffspring

      public int expectedOffspring
      Expected Offspring for next generation for this subspecies
  • Constructor Details

    • NEATSubspecies

      public NEATSubspecies()
  • Method Details

    • setup

      public void setup(EvolutionState state, Parameter base)
      Description copied from interface: Prototype
      Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

      For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.

      Specified by:
      setup in interface Prototype
      Specified by:
      setup in interface Setup
    • emptyClone

      public Object emptyClone()
      Return a clone of this subspecies, but with a empty individuals and newGenIndividuals list.
    • 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 Object
    • reset

      public void reset()
      Reset the status of the current subspecies.
    • first

      public Individual first()
      Return the first individual in this subspecies
    • newGenerationFirst

      public Individual newGenerationFirst()
      Return the first individual in newGenIndividuals list.
    • 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
    • adjustFitness

      public void adjustFitness(EvolutionState state, int dropoffAge, double ageSignificance)
      Adjust the fitness of the individuals within this subspecies. We will use the adjusted fitness to determine the expected offsprings within each subspecies.
    • sortIndividuals

      public void sortIndividuals()
      Sort the individuals in this subspecies, the one with highest fitness comes first.
    • updateSubspeciesMaxFitness

      public void updateSubspeciesMaxFitness()
      Update the maxFitnessEver variable.
    • markReproducableIndividuals

      public void markReproducableIndividuals(double survivalThreshold)
      Mark the individual who can reproduce for this generation.
    • hasNewGeneration

      public boolean hasNewGeneration()
      Test if newGenIndividuals list is empty.
    • countOffspring

      public double countOffspring(double skim)
      Compute the collective offspring the entire species (the sum of all individual's offspring) is assigned skim is fractional offspring left over from a previous subspecies that was counted. These fractional parts are kept until they add up to 1
    • reproduce

      public boolean reproduce(EvolutionState state, int thread, int subpop, ArrayList<NEATSubspecies> sortedSubspecies)
      Where the actual reproduce is happening, it will grab the candidate parents, and calls the crossover or mutation method on these parents individuals.
    • timeSinceLastImproved

      public int timeSinceLastImproved()
      Compute generations gap since last improvement
    • addNewGenIndividual

      public void addNewGenIndividual(NEATIndividual neatInd)
      Add the individual to the next generation of this subspecies
    • removePoorFitnessIndividuals

      public void removePoorFitnessIndividuals()
      Remove the individuals from current subspecies who have been mark as eliminate the remain individuals will be allow to reproduce
    • toNewGeneration

      public void toNewGeneration()
      After we finish the reproduce, the newGenIndividual list has the all the individuals that is ready for evalution in next generation. Let's switch to it.