Class VectorIndividual

  extended by ec.Individual
      extended by ec.vector.VectorIndividual
All Implemented Interfaces:
Prototype, Setup,, java.lang.Cloneable
Direct Known Subclasses:
BitVectorIndividual, ByteVectorIndividual, DoubleVectorIndividual, FloatVectorIndividual, GeneVectorIndividual, IntegerVectorIndividual, LongVectorIndividual, ShortVectorIndividual

public abstract class VectorIndividual
extends Individual

VectorIndividual is the abstract superclass of simple individual representations which consist of vectors of values (booleans, integers, floating-point, etc.)

This class contains two methods, defaultCrossover and defaultMutate, which can be overridden if all you need is a simple crossover and a simple mutate mechanism. the VectorCrossoverPipeline and VectorMutationPipeline classes use these methods to do their handiwork. For more sophisticated crossover and mutation, you'll need to write a custom breeding pipeline.

The kind of default crossover and mutation, and associated information, is stored in the VectorIndividual's VectorSpecies object, which is obtained through the species variable. For example, VectorIndividual assumes three common types of crossover as defined in VectorSpecies which you should implement in your defaultCrossover method: one-point, two-point, and any-point (otherwise known as "uniform") crossover.

VectorIndividual is typically used for fixed-length vector representations; however, it can also be used with variable-length representations. Two methods have been provided in all subclasses of VectorIndividual to help you there: split and join, which you can use to break up and reconnect VectorIndividuals in a variety of ways. Note that you may want to override the reset() method to create individuals with different initial lengths.

VectorIndividuals must belong to the species VectorSpecies (or some subclass of it).

From ec.Individual:

In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways.

In general, the various readers and writers do three things: they tell the Fitness to read/write itself, they read/write the evaluated flag, and they read/write the gene array. If you add instance variables to a VectorIndividual or subclass, you'll need to read/write those variables as well.

Sean Luke
See Also:
Serialized Form

Field Summary
static java.lang.String DEFAULT_SPECIES
Fields inherited from class ec.Individual
evaluated, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species
Constructor Summary
Method Summary
 void defaultCrossover(EvolutionState state, int thread, VectorIndividual ind)
          Destructively crosses over the individual with another in some default manner.
 void defaultMutate(EvolutionState state, int thread)
          Destructively mutates the individual in some default manner.
 long genomeLength()
          Returns the length of the gene array.
 java.lang.Object getGenome()
          Returns the gene array.
 void join(java.lang.Object[] pieces)
          Joins the n pieces and sets the genome to their concatenation.
abstract  void reset(EvolutionState state, int thread)
          Initializes the individual.
 void reset(EvolutionState state, int thread, int newSize)
          Initializes the individual to a new size.
 void setGenome(java.lang.Object gen)
          Sets the gene array.
 void setGenomeLength(int len)
          Sets the genome length.
 long size()
          Returns the "size" of the individual.
 void split(int[] points, java.lang.Object[] pieces)
          Splits the genome into n pieces, according to points, which *must* be sorted.
Methods inherited from class ec.Individual
clone, equals, genotypeToString, genotypeToStringForHumans, hashCode, parseGenotype, printIndividual, printIndividual, printIndividualForHumans, readGenotype, readIndividual, readIndividual, setup, toString, writeGenotype, writeIndividual
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ec.Prototype

Field Detail


public static final java.lang.String DEFAULT_SPECIES
Constructor Detail


public VectorIndividual()
Method Detail


public void defaultCrossover(EvolutionState state,
                             int thread,
                             VectorIndividual ind)
Destructively crosses over the individual with another in some default manner. In most implementations provided in ECJ, one-, two-, and any-point crossover is done with a for loop, rather than a possibly more efficient approach like arrayCopy(). The disadvantage is that arrayCopy() takes advantage of a CPU's bulk copying. The advantage is that arrayCopy() would require a scratch array, so you'd be allocing and GCing an array for every crossover. Dunno which is more efficient.


public void defaultMutate(EvolutionState state,
                          int thread)
Destructively mutates the individual in some default manner. The default version calls reset()


public abstract void reset(EvolutionState state,
                           int thread)
Initializes the individual.


public java.lang.Object getGenome()
Returns the gene array. If you know the type of the array, you can cast it and work on it directly. Otherwise, you can still manipulate it in general, because arrays (like all objects) respond to clone() and can be manipulated with arrayCopy without bothering with their type. This might be useful in creating special generalized crossover operators -- we apologize in advance for the fact that Java doesn't have a template system. :-( The default version returns null.


public void setGenome(java.lang.Object gen)
Sets the gene array. See getGenome(). The default version does nothing.


public long genomeLength()
Returns the length of the gene array. By default, this method returns 0.


public void reset(EvolutionState state,
                  int thread,
                  int newSize)
Initializes the individual to a new size. Only use this if you need to initialize variable-length individuals.


public void setGenomeLength(int len)
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.


public void split(int[] points,
                  java.lang.Object[] pieces)
Splits the genome into n pieces, according to points, which *must* be sorted. pieces.length must be 1 + points.length. The default form does nothing -- be careful not to use this method if it's not implemented! It should be trivial to implement it for your genome -- just like at the other implementations.


public void join(java.lang.Object[] pieces)
Joins the n pieces and sets the genome to their concatenation. The default form does nothing. It should be trivial to implement it for your genome -- just like at the other implementations.


public long size()
Description copied from class: Individual
Returns the "size" of the individual. This is used for things like parsimony pressure. The default form of this method returns 0 -- if you care about parsimony pressure, you'll need to override the default to provide a more descriptive measure of size.

size in class Individual