Package ec.pso

Class Particle

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

public class Particle extends DoubleVectorIndividual
Particle is a DoubleVectorIndividual with additional statistical information necessary to perform Particle Swarm Optimization. Specifically, it has a VELOCITY, a NEIGHBORHOOD of indexes of individuals, a NEIGHBORHOOD BEST genome and fitness, and a PERSONAL BEST genome and fitness. These elements, plus the GLOBAL BEST genome and fitness found in PSOBreeder, are used to collectively update the particle's location in space.

Particle updates its location in two steps. First, it gathers current neighborhood and personal best statistics via the update(...) method. Then it updates the particle's velocity and location (genome) according to these statistics in the tweak(...) method. Notice that neither of these methods is the defaultMutate(...) method used in DoubleVectorIndividual: this means that in *theory* you could rig up Particles to also be mutated if you thought that was a good reason.

Many of the parameters passed into the tweak(...) method are based on weights determined by the PSOBreeder.

See Also:
  • Field Details

    • AUXILLARY_PREAMBLE

      public static final String AUXILLARY_PREAMBLE
      See Also:
    • velocity

      public double[] velocity
    • neighborhood

      public int[] neighborhood
    • neighborhoodBestGenome

      public double[] neighborhoodBestGenome
    • neighborhoodBestFitness

      public Fitness neighborhoodBestFitness
    • personalBestGenome

      public double[] personalBestGenome
    • personalBestFitness

      public Fitness personalBestFitness
  • Constructor Details

    • Particle

      public Particle()
  • Method Details

    • 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 DoubleVectorIndividual
    • equals

      public boolean equals(Object ind)
      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 DoubleVectorIndividual
    • 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 DoubleVectorIndividual
      See Also:
    • 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 DoubleVectorIndividual
    • update

      public void update(EvolutionState state, int subpop, int myindex, int thread)
    • tweak

      public void tweak(EvolutionState state, double[] globalBest, double velocityCoeff, double personalCoeff, double informantCoeff, double globalCoeff, int thread)
    • reset

      public void reset(EvolutionState state, int thread)
      Description copied from class: DoubleVectorIndividual
      Initializes the individual by randomly choosing doubles uniformly from mingene to maxgene.
      Overrides:
      reset in class DoubleVectorIndividual
    • setGenomeLength

      public void setGenomeLength(int len)
      Description copied from class: VectorIndividual
      Sets the genome length. If the length is longer, then it is filled with a default value (likely 0 or false). This may or may not be a valid value -- you will need to set appropriate values here. The default implementation does nothing; but all subclasses in ECJ implement a subset of this.
      Overrides:
      setGenomeLength in class DoubleVectorIndividual
    • setGenome

      public void setGenome(Object gen)
      Description copied from class: VectorIndividual
      Sets the gene array. See getGenome(). The default version does nothing.
      Overrides:
      setGenome in class DoubleVectorIndividual
    • join

      public void join(Object[] pieces)
      Description copied from class: DoubleVectorIndividual
      Joins the n pieces and sets the genome to their concatenation.
      Overrides:
      join in class DoubleVectorIndividual
    • printIndividual

      public void printIndividual(EvolutionState state, int log)
      Description copied from class: Individual
      Should print the individual in a way that can be read by computer, including its fitness, with a verbosity of Output.V_NO_GENERAL.
      Overrides:
      printIndividual in class Individual
    • printIndividual

      public void printIndividual(EvolutionState state, PrintWriter writer)
      Description copied from class: Individual
      Should print the individual in a way that can be read by computer, including its fitness. You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,writer); Usually you should try to use printIndividual(state,log,verbosity) instead -- use this method only if you can't print through the Output facility for some reason.

      The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then calls Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior, though it is rare to need to -- instead you could just override genotypeToString().

      Overrides:
      printIndividual in class Individual
    • readIndividual

      public void readIndividual(EvolutionState state, LineNumberReader reader) throws IOException
      Description copied from class: Individual
      Reads in the individual from a form printed by printIndividual(), erasing the previous information stored in this Individual. If you are trying to create an Individual from information read in from a stream or DataInput, see the various newIndividual() methods in Species. The default form of this method simply reads in evaluation information, then fitness information, and then calls parseGenotype() (which you should implement). The Species is not changed or attached, so you may need to do that elsewhere. Feel free to override this method to produce more sophisticated behavior, though it is rare to need to -- instead you could just override parseGenotype().
      Overrides:
      readIndividual in class Individual
      Throws:
      IOException
    • writeIndividual

      public void writeIndividual(EvolutionState state, DataOutput dataOutput) throws IOException
      Description copied from class: Individual
      Writes the binary form of an individual out to a DataOutput. This is not for serialization: the object should only write out the data relevant to the object sufficient to rebuild it from a DataInput. The Species will be reattached later, and you should not write it. The default version of this method writes the evaluated and fitness information, then calls writeGenotype() to write the genotype information. Feel free to override this method to produce more sophisticated behavior, though it is rare to need to -- instead you could just override writeGenotype().
      Overrides:
      writeIndividual in class Individual
      Throws:
      IOException
    • readIndividual

      public void readIndividual(EvolutionState state, DataInput dataInput) throws IOException
      Description copied from class: Individual
      Reads the binary form of an individual from a DataInput, erasing the previous information stored in this Individual. This is not for serialization: the object should only read in the data written out via printIndividual(state,dataInput). If you are trying to create an Individual from information read in from a stream or DataInput, see the various newIndividual() methods in Species. The default form of this method simply reads in evaluation information, then fitness information, and then calls readGenotype() (which you will need to override -- its default form simply throws an error). The Species is not changed or attached, so you may need to do that elsewhere. Feel free to override this method to produce more sophisticated behavior, though it is rare to need to -- instead you could just override readGenotype().
      Overrides:
      readIndividual in class Individual
      Throws:
      IOException