Class RuleIndividual
- All Implemented Interfaces:
Prototype,Setup,Serializable,Cloneable,Comparable<Individual>
RuleIndividuals really have basically one parameter: the number of RuleSets to use. This is determined by the num-rulesets parameter.
From ec.Individual:
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. To do this, these methods will encode numbers
using the ec.util.Code class. These methods are mostly used to write out populations to
files for inspection, slight modification, then reading back in later on. readIndividualreads
in the fitness and the evaluation flag, then calls parseGenotype to read in the remaining individual.
You are responsible for implementing parseGenotype: the Code class is there to help you.
printIndividual writes out the fitness and evaluation flag, then calls genotypeToString
and printlns the resultant string. You are responsible for implementing the genotypeToString method in such
a way that parseGenotype can read back in the individual println'd with genotypeToString. The default form
of genotypeToString simply calls toString, which you may override instead if you like. The default
form of parseGenotype throws an error. You are not required to implement these methods, but without
them you will not be able to write individuals to files in a simultaneously computer- and human-readable fashion.
- printIndividualForHumans(...,PrintWriter) This approach prints an individual in a fashion intended for human consumption only. printIndividualForHumans writes out the fitness and evaluation flag, then calls genotypeToStringForHumans and printlns the resultant string. You are responsible for implementing the genotypeToStringForHumans method. The default form of genotypeToStringForHumans simply calls toString, which you may override instead if you like (though note that genotypeToString's default also calls toString). You should handle one of these methods properly to ensure individuals can be printed by ECJ.
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 Rulesets. If you add instance variables to a RuleIndividual or subclass, you'll need to read/write those variables as well.
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringRuleSet[]The individual's rulesets.Fields inherited from class ec.Individual
evaluated, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.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.voidmutate(EvolutionState state, int thread) Mutates the Individual.voidparseGenotype(EvolutionState state, LineNumberReader reader) Overridden for the RuleIndividual genotype.voidpostprocessIndividual(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.voidpreprocessIndividual(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.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) Overridden for the RuleIndividual genotype, writing each ruleset in turn.voidprintIndividualForHumans(EvolutionState state, int log) Should print the individual out in a pleasing way for humans, with a verbosity of Output.V_NO_GENERAL.voidreadGenotype(EvolutionState state, DataInput dataInput) Overridden for the RuleIndividual genotype.voidreset(EvolutionState state, int thread) voidsetup(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.longsize()Returns the "size" of the individual.voidwriteGenotype(EvolutionState state, DataOutput dataOutput) Overridden for the RuleIndividual genotype, writing each ruleset in turn.Methods inherited from class ec.Individual
compareTo, distanceTo, genotypeToString, genotypeToStringForHumans, merge, printIndividual, printIndividualForHumans, readIndividual, readIndividual, toString, writeIndividual
-
Field Details
-
P_RULESET
- See Also:
-
P_NUMRULESETS
- See Also:
-
rulesets
The individual's rulesets.
-
-
Constructor Details
-
RuleIndividual
public RuleIndividual()
-
-
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(...). -
clone
Description copied from interface:PrototypeCreates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:
- If you hold objects which are shared with other instances, don't clone them.
- If you hold objects which must be unique, clone them.
- If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
- DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
- Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.
Implementations.
- If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
- If no ancestor of yours implements clone(),
and you have no need to do clone deeply,
and you are not abstract, then you should implement
it as follows:
public Object clone() { try { return super.clone(); } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens } - If no ancestor of yours implements clone(), but you
need to deep-clone some things, then you should implement it
as follows:
public Object clone() { try { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens return myobj; } - If an ancestor has implemented clone(), and you also need
to deep clone some things, then you should implement it as follows:
public Object clone() { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... return myobj; }
- Specified by:
clonein interfacePrototype- Overrides:
clonein classIndividual
-
preprocessIndividual
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
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
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
Description copied from class:IndividualThis 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. -
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
Overridden for the RuleIndividual genotype, writing each ruleset in turn.- Overrides:
printIndividualin classIndividual
-
writeGenotype
Overridden for the RuleIndividual genotype, writing each ruleset in turn.- Overrides:
writeGenotypein classIndividual- Throws:
IOException
-
readGenotype
Overridden for the RuleIndividual genotype.- Overrides:
readGenotypein classIndividual- Throws:
IOException
-
parseGenotype
Overridden for the RuleIndividual genotype.- Overrides:
parseGenotypein classIndividual- Throws:
IOException
-
size
public long size()Description copied from class:IndividualReturns 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:
sizein classIndividual
-
reset
-
mutate
Mutates the Individual. The default implementation simply calls mutate(...) on each of the RuleSets.
-