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, 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.

VectorIndividual defines three common types of crossover 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 should belong to the species VectorSpecies (or some subclass of it).

Parameters
genome-size
int >= 1
(size of the genome)
chunk-size
1 <= int <= genome-size
(the chunk size for crossover (crossover will only occur on chunk boundaries))
crossover-type
string, one of: one, two, any
(default crossover type (one-point, two-point, or any-point (uniform) crossover)
crossover-prob
0.0 >= float >= 1.0
(probability that a gene will get crossed over during any-point crossover)
mutation-prob
0.0 <= float <= 1.0
(probability that a gene will get mutated over default mutation)

See Also:
Serialized Form

Field Summary
static int C_ANY_POINT
           
static int C_ONE_POINT
           
static int C_TWO_POINT
           
 int chunksize
          How big of chunks should we define for crossover?
 float crossoverProbability
          Probability that a gene will cross over -- ONLY used in V_ANY_POINT crossover
 int crossoverType
          What kind of crossover do we have?
static java.lang.String EVALUATED_PREAMBLE
          Evaluated string to appear when printed
 int genomeSize
          How big of a genome should we create on initialization?
 float mutationProbability
          Probability that a gene will mutate
static java.lang.String P_CHUNKSIZE
           
static java.lang.String P_CROSSOVERPROB
           
static java.lang.String P_CROSSOVERTYPE
           
static java.lang.String P_GENOMESIZE
           
static java.lang.String P_MUTATIONPROB
           
static java.lang.String V_ANY_POINT
           
static java.lang.String V_ONE_POINT
           
static java.lang.String V_TWO_POINT
           
 
Fields inherited from class ec.Individual
evaluated, fitness
 
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.
 void setup(EvolutionState state, Parameter base)
          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.
 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
equals, hashCode, printIndividual, printIndividual, printIndividualForHumans, protoClone, protoCloneSimple, readIndividual
 
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

C_ONE_POINT

public static final int C_ONE_POINT

C_TWO_POINT

public static final int C_TWO_POINT

C_ANY_POINT

public static final int C_ANY_POINT

P_CROSSOVERTYPE

public static final java.lang.String P_CROSSOVERTYPE

P_CHUNKSIZE

public static final java.lang.String P_CHUNKSIZE

V_ONE_POINT

public static final java.lang.String V_ONE_POINT

V_TWO_POINT

public static final java.lang.String V_TWO_POINT

V_ANY_POINT

public static final java.lang.String V_ANY_POINT

P_MUTATIONPROB

public static final java.lang.String P_MUTATIONPROB

P_CROSSOVERPROB

public static final java.lang.String P_CROSSOVERPROB

P_GENOMESIZE

public static final java.lang.String P_GENOMESIZE

EVALUATED_PREAMBLE

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

mutationProbability

public float mutationProbability
Probability that a gene will mutate

crossoverProbability

public float crossoverProbability
Probability that a gene will cross over -- ONLY used in V_ANY_POINT crossover

crossoverType

public int crossoverType
What kind of crossover do we have?

genomeSize

public int genomeSize
How big of a genome should we create on initialization?

chunksize

public int chunksize
How big of chunks should we define for crossover?
Constructor Detail

VectorIndividual

public VectorIndividual()
Method Detail

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.
Overrides:
setup in class Individual
Following copied from class: ec.Individual
See Also:
Prototype.setup(EvolutionState,Parameter)

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