ec.vector
Class VectorIndividual

java.lang.Object
  |
  +--ec.Individual
        |
        +--ec.vector.VectorIndividual
All Implemented Interfaces:
java.lang.Cloneable, Prototype, java.io.Serializable, Setup
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).

See Also:
Serialized Form

Field Summary
static java.lang.String EVALUATED_PREAMBLE
          Evaluated string to appear when printed
 
Fields inherited from class ec.Individual
evaluated, fitness, species
 
Constructor Summary
VectorIndividual()
           
 
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 setGenome(java.lang.Object gen)
          Sets the gene array.
 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
deepClone, equals, hashCode, printIndividual, printIndividual, printIndividualForHumans, protoClone, protoCloneSimple, readIndividual, setup
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ec.Prototype
defaultBase
 

Field Detail

EVALUATED_PREAMBLE

public static final java.lang.String EVALUATED_PREAMBLE
Evaluated string to appear when printed
Constructor Detail

VectorIndividual

public VectorIndividual()
Method Detail

defaultCrossover

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.

defaultMutate

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

reset

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

getGenome

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.

setGenome

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

genomeLength

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

split

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.

join

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.

size

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.
Overrides:
size in class Individual