Class GPIndividual
- All Implemented Interfaces:
Prototype,Setup,Serializable,Cloneable,Comparable<Individual>
GPIndividuals have two clone methods: clone() and lightClone(). clone() is a deep clone method as usual. lightClone() is a light clone which does not copy the trees.
In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways.
- writeIndividual(...,DataOutput)/readIndividual(...,DataInput) This method transmits or receives an individual in binary. It is the most efficient approach to sending individuals over networks, etc. These methods write the evaluated flag and the fitness, then call readGenotype/writeGenotype, which you must implement to write those parts of your Individual special to your functions-- the default versions of readGenotype/writeGenotype throw errors. You don't need to implement them if you don't plan on using read/writeIndividual.
- printIndividual(...,PrintWriter)/readIndividual(...,LineNumberReader) This approach transmits or receives an indivdual in text encoded such that the individual is largely readable by humans but can be read back in 100% by ECJ as well. Because GPIndividuals are often very large, GPIndividual has overridden these methods -- they work differently than in Individual (the superclass). In specific: readIndividual by default reads in the fitness and the evaluation flag, then calls parseGenotype to read in the trees (via GPTree.readTree(...)). However printIndividual by default prints the fitness and evaluation flag, and prints all the trees by calling GPTree.printTree(...). It does not call genotypeToString at all. This is because it's very wasteful to build up a large string holding the printed form of the GPIndividual just to pump it out a stream once.
- printIndividualForHumans(...,PrintWriter) This
approach prints an individual in a fashion intended for human consumption only. Because GPIndividuals are often very large,
GPIndividual has overridden this methods -- it works differently than in Individual (the superclass). In specific:
printIndividual by default prints the fitness and evaluation flag, and prints all the trees
by calling GPTree.printTreeForHumans(...). It does not call genotypeToStringForHumans at all. This
is because it's very wasteful to build up a large string holding the printed form of the GPIndividual
just to pump it out a stream once.
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 GPTree array (by having each GPTree read/write itself). If you add instance variables to GPIndividual, you'll need to read/write those variables as well.
Parameters
base.numtrees
int >= 1(number of trees in the GPIndividual) base.tree.n
classname, inherits or = ec.gp.GPTree(class of tree n in the individual) Default Base
gp.individualParameter bases
base.tree.n tree n in the individual
- See Also:
-
Field Summary
FieldsFields inherited from class ec.Individual
evaluated, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Deep-clones the GPIndividual.Returns the default base for this prototype.booleanReturns true if I am genetically "equal" to ind.inthashCode()Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.Like clone(), but doesn't force the GPTrees to deep-clone themselves.voidparseGenotype(EvolutionState state, LineNumberReader reader) This method is used only by the default version of readIndividual(state,reader), and it is intended to be overridden to parse in that part of the individual that was outputted in the genotypeToString() method.voidprintIndividual(EvolutionState state, int log) Should print the individual in a way that can be read by computer, including its fitness, with a verbosity of Output.V_NO_GENERAL.voidprintIndividual(EvolutionState state, PrintWriter writer) Should print the individual in a way that can be read by computer, including its fitness.voidprintIndividualForHumans(EvolutionState state, int log) Should print the individual out in a pleasing way for humans, with a verbosity of Output.V_NO_GENERAL.voidprintTrees(EvolutionState state, int log) Prints just the trees of the GPIndividual.voidreadGenotype(EvolutionState state, DataInput dataInput) Overridden for the GPIndividual genotype.voidsetup(EvolutionState state, Parameter base) Sets up a prototypical GPIndividual with those features which it shares with other GPIndividuals in its species, and nothing more.longsize()Returns the "size" of the individual, namely, the number of nodes in all of its subtrees.voidverify(EvolutionState state) Verification of validity of the GPIndividual -- strictly for debugging purposes onlyvoidwriteGenotype(EvolutionState state, DataOutput dataOutput) Overridden for the GPIndividual genotype.Methods inherited from class ec.Individual
compareTo, distanceTo, genotypeToString, genotypeToStringForHumans, merge, printIndividual, printIndividualForHumans, readIndividual, readIndividual, toString, writeIndividual
-
Field Details
-
P_NUMTREES
- See Also:
-
P_TREE
- See Also:
-
trees
-
-
Constructor Details
-
GPIndividual
public GPIndividual()
-
-
Method Details
-
defaultBase
Description copied from interface:PrototypeReturns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...). -
equals
Description copied from class:IndividualReturns 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.- Specified by:
equalsin classIndividual
-
hashCode
public int hashCode()Description copied from class:IndividualReturns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.- Specified by:
hashCodein classIndividual
-
setup
Sets up a prototypical GPIndividual with those features which it shares with other GPIndividuals in its species, and nothing more. -
verify
Verification of validity of the GPIndividual -- strictly for debugging purposes only -
printTrees
Prints just the trees of the GPIndividual. Broken out like this to be used by GEIndividual to avoid re-printing the fitness and evaluated premables. -
printIndividualForHumans
Description copied from class:IndividualShould print the individual out in a pleasing way for humans, with a verbosity of Output.V_NO_GENERAL.- Overrides:
printIndividualForHumansin classIndividual
-
printIndividual
Description copied from class:IndividualShould print the individual in a way that can be read by computer, including its fitness, with a verbosity of Output.V_NO_GENERAL.- Overrides:
printIndividualin classIndividual
-
printIndividual
Description copied from class:IndividualShould 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:
printIndividualin classIndividual
-
writeGenotype
Overridden for the GPIndividual genotype.- Overrides:
writeGenotypein classIndividual- Throws:
IOException
-
readGenotype
Overridden for the GPIndividual genotype.- Overrides:
readGenotypein classIndividual- Throws:
IOException
-
parseGenotype
Description copied from class:IndividualThis method is used only by the default version of readIndividual(state,reader), and it is intended to be overridden to parse in that part of the individual that was outputted in the genotypeToString() method. The default version of this method exits the program with an "unimplemented" error. You'll want to override this method, or to override readIndividual(...) to not use this method.- Overrides:
parseGenotypein classIndividual- Throws:
IOException
-
clone
Deep-clones the GPIndividual. Note that you should not deep-clone the prototypical GPIndividual stored in GPSpecies: they contain blank GPTrees with null roots, and this method, which calls GPTree.clone(), will produce a NullPointerException as a result. Instead, you probably want to use GPSpecies.newIndividual(...) if you're thinking of playing with the prototypical GPIndividual.- Specified by:
clonein interfacePrototype- Overrides:
clonein classIndividual
-
lightClone
Like clone(), but doesn't force the GPTrees to deep-clone themselves. -
size
public long size()Returns the "size" of the individual, namely, the number of nodes in all of its subtrees.- Overrides:
sizein classIndividual
-