ec.rule
Class RuleIndividual

java.lang.Object
  extended byec.Individual
      extended byec.rule.RuleIndividual
All Implemented Interfaces:
java.lang.Cloneable, Prototype, java.io.Serializable, Setup

public class RuleIndividual
extends Individual

RuleIndividual is an Individual with an array of RuleSets, each of which is a set of Rules. RuleIndividuals belong to some subclass of RuleSpecies (or just RuleSpecies itself).

RuleIndividuals really have basically one parameter: the number of RuleSets to use. This is determined by the num-rulesets parameter.

Parameters

base.num-rulesets
int >= 1
(number of rulesets used)
base.ruleset.n
Classname, subclass of or = ec.rule.RuleSet
(class of ruleset n)

Parameter bases

base.ruleset.n
RuleSet n

Default Base
rule.individual

See Also:
Serialized Form

Field Summary
static java.lang.String EVALUATED_PREAMBLE
           
static java.lang.String P_INDIVIDUAL
           
static java.lang.String P_NUMRULESETS
           
static java.lang.String P_RULESET
           
 RuleSet[] rulesets
          The individual's rulesets.
 
Fields inherited from class ec.Individual
evaluated, fitness, species
 
Constructor Summary
RuleIndividual()
           
 
Method Summary
 Parameter defaultBase()
          Returns the default base for this prototype.
 boolean equals(java.lang.Object ind)
          Returns true if I am genetically "equal" to ind.
 int hashCode()
          Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
 void parseGenotype(EvolutionState state, java.io.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.
 void postprocessIndividual(EvolutionState state, int thread)
          Called by pipelines after they've modified the individual and it might need to be "fixed" -- basically a hook for you to override.
 void preprocessIndividual(EvolutionState state, int thread)
          Called by pipelines before they've modified the individual and it might need to be "fixed" -- basically a hook for you to override.
 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);
 void printIndividual(EvolutionState state, java.io.PrintWriter writer)
          Should print the individual in a way that can be read by computer, including its fitness.
 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.
 void readGenotype(EvolutionState state, java.io.DataInput dataInput)
           
 void reset(EvolutionState state, int thread)
           
 void setup(EvolutionState state, Parameter base)
          Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
 long size()
          Returns the "size" of the individual.
 void writeGenotype(EvolutionState state, java.io.DataOutput dataOutput)
           
 
Methods inherited from class ec.Individual
deepClone, genotypeToString, genotypeToStringForHumans, protoCloneSimple, readIndividual, readIndividual, toString, writeIndividual
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

P_RULESET

public static final java.lang.String P_RULESET
See Also:
Constant Field Values

P_NUMRULESETS

public static final java.lang.String P_NUMRULESETS
See Also:
Constant Field Values

P_INDIVIDUAL

public static final java.lang.String P_INDIVIDUAL
See Also:
Constant Field Values

EVALUATED_PREAMBLE

public static final java.lang.String EVALUATED_PREAMBLE
See Also:
Constant Field Values

rulesets

public RuleSet[] rulesets
The individual's rulesets.

Constructor Detail

RuleIndividual

public RuleIndividual()
Method Detail

defaultBase

public Parameter defaultBase()
Description copied from interface: Prototype
Returns 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(...).


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
Overrides:
protoClone in class Individual
Throws:
java.lang.CloneNotSupportedException

preprocessIndividual

public void preprocessIndividual(EvolutionState state,
                                 int thread)
Called by pipelines before they've modified the individual and it might need to be "fixed" -- basically a hook for you to override. By default, calls validateRules on each ruleset.


postprocessIndividual

public void postprocessIndividual(EvolutionState state,
                                  int thread)
Called by pipelines after they've modified the individual and it might need to be "fixed" -- basically a hook for you to override. By default, calls validateRules on each ruleset.


equals

public boolean equals(java.lang.Object ind)
Description copied from class: Individual
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.

Specified by:
equals in class Individual

hashCode

public int hashCode()
Description copied from class: Individual
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.

Specified by:
hashCode in class Individual

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from interface: Prototype
Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.

Specified by:
setup in interface Prototype
Overrides:
setup in class Individual

printIndividualForHumans

public void printIndividualForHumans(EvolutionState state,
                                     int log,
                                     int verbosity)
Description copied from class: Individual
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);

The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then Individual.genotypeToStringForHumans(). Feel free to override this to produce more sophisticated behavior.

Overrides:
printIndividualForHumans in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            int log,
                            int verbosity)
Description copied from class: Individual
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);

The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior.

Overrides:
printIndividual in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            java.io.PrintWriter writer)
Description copied from class: Individual
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.

The default form of this method simply prints out whether or not the individual has been evaluated, its fitness, and then Individual.genotypeToString(). Feel free to override this to produce more sophisticated behavior.

Overrides:
printIndividual in class Individual

writeGenotype

public void writeGenotype(EvolutionState state,
                          java.io.DataOutput dataOutput)
                   throws java.io.IOException
Overrides:
writeGenotype in class Individual
Throws:
java.io.IOException

readGenotype

public void readGenotype(EvolutionState state,
                         java.io.DataInput dataInput)
                  throws java.io.IOException,
                         java.lang.CloneNotSupportedException
Overrides:
readGenotype in class Individual
Throws:
java.io.IOException
java.lang.CloneNotSupportedException

parseGenotype

public void parseGenotype(EvolutionState state,
                          java.io.LineNumberReader reader)
                   throws java.io.IOException,
                          java.lang.CloneNotSupportedException
Description copied from class: Individual
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. 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:
parseGenotype in class Individual
Throws:
java.io.IOException
java.lang.CloneNotSupportedException

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

reset

public void reset(EvolutionState state,
                  int thread)