ec
Class Individual

java.lang.Object
  |
  +--ec.Individual
Direct Known Subclasses:
GPIndividual

public abstract class Individual
extends java.lang.Object
implements Prototype

An Individual is an item in the EC population stew which is evaluated and assigned a fitness which determines its likelihood of selection. Individuals are created most commonly by the newIndividual(...) method of the ec.Species class. In general Individuals are immutable. That is, once they are created they should not be modified. This protocol helps insure that they are safe to read under multithreaded conditions.

See Also:
Serialized Form

Field Summary
 boolean evaluated
          Has the individual been evaluated and its fitness determined yet?
 Fitness fitness
          The fitness of the Individual.
 
Constructor Summary
Individual()
           
 
Method Summary
abstract  boolean equals(java.lang.Object ind)
          Returns true if I am genetically "equal" to ind.
abstract  int hashCode()
          Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
abstract  void printIndividual(EvolutionState state, int log, int verbosity)
          Should print the individual in a way that can be read by computer, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,verbosity);
abstract  void printIndividual(EvolutionState state, int thread, java.io.PrintWriter writer)
          Should print the individual in a way that can be read by computer, including its fitness.
abstract  void printIndividualForHumans(EvolutionState state, int log, int verbosity)
          Should print the individual out in a pleasing way for humans, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitnessForHumans(state,log,verbosity);
 java.lang.Object protoClone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 java.lang.Object protoCloneSimple()
          This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final.
abstract  void readIndividual(EvolutionState state, int thread, java.io.LineNumberReader reader)
          Reads in the individual from a form printed by printIndividual().
abstract  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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fitness

public Fitness fitness
The fitness of the Individual.

evaluated

public boolean evaluated
Has the individual been evaluated and its fitness determined yet?
Constructor Detail

Individual

public Individual()
Method Detail

protoClone

public java.lang.Object protoClone()
                            throws java.lang.CloneNotSupportedException
Description copied from interface: Prototype
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:

Implementations.

If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).

In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.

The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.

Specified by:
protoClone in interface Prototype

protoCloneSimple

public final java.lang.Object protoCloneSimple()
Description copied from interface: Prototype
This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final. It should be implemented as follows:

public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e) 
{ throw new InternalError(); } // never happens
} 
Specified by:
protoCloneSimple in interface Prototype

equals

public abstract boolean equals(java.lang.Object ind)
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 java.lang.Object

hashCode

public abstract int hashCode()
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
Overrides:
hashCode in class java.lang.Object

setup

public abstract 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.
Specified by:
setup in interface Prototype
See Also:
Prototype.setup(EvolutionState,Parameter)

printIndividualForHumans

public abstract void printIndividualForHumans(EvolutionState state,
                                              int log,
                                              int verbosity)
Should print the individual out in a pleasing way for humans, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitnessForHumans(state,log,verbosity);

printIndividual

public abstract void printIndividual(EvolutionState state,
                                     int log,
                                     int verbosity)
Should print the individual in a way that can be read by computer, including its fitness, using state.output.println(...,verbosity,log) You can get fitness to print itself at the appropriate time by calling fitness.printFitness(state,log,verbosity);

printIndividual

public abstract void printIndividual(EvolutionState state,
                                     int thread,
                                     java.io.PrintWriter writer)
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.

readIndividual

public abstract void readIndividual(EvolutionState state,
                                    int thread,
                                    java.io.LineNumberReader reader)
                             throws java.io.IOException,
                                    java.lang.CloneNotSupportedException
Reads in the individual from a form printed by printIndividual().