Class RuleIndividual
- java.lang.Object
-
- ec.Individual
-
- ec.rule.RuleIndividual
-
- All Implemented Interfaces:
- Prototype, Setup, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
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.
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringP_NUMRULESETSstatic java.lang.StringP_RULESETRuleSet[]rulesetsThe individual's rulesets.-
Fields inherited from class ec.Individual
evaluated, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species
-
-
Constructor Summary
Constructors Constructor and Description RuleIndividual()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Objectclone()Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.ParameterdefaultBase()Returns the default base for this prototype.booleanequals(java.lang.Object ind)Returns 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, java.io.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, java.io.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, java.io.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, java.io.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 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
-
rulesets
public RuleSet[] rulesets
The individual's rulesets.
-
-
Method Detail
-
defaultBase
public Parameter 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
public java.lang.Object 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 Groups.
- 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
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: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
public void setup(EvolutionState state, Parameter base)
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.- Specified by:
setupin interfacePrototype- Specified by:
setupin interfaceSetup- Overrides:
setupin classIndividual- See Also:
Prototype.setup(EvolutionState,Parameter)
-
printIndividualForHumans
public void printIndividualForHumans(EvolutionState state, int log)
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
public void printIndividual(EvolutionState state, int log)
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
public void printIndividual(EvolutionState state, java.io.PrintWriter writer)
Overridden for the RuleIndividual genotype, writing each ruleset in turn.- Overrides:
printIndividualin classIndividual
-
writeGenotype
public void writeGenotype(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
Overridden for the RuleIndividual genotype, writing each ruleset in turn.- Overrides:
writeGenotypein classIndividual- Throws:
java.io.IOException
-
readGenotype
public void readGenotype(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
Overridden for the RuleIndividual genotype.- Overrides:
readGenotypein classIndividual- Throws:
java.io.IOException
-
parseGenotype
public void parseGenotype(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
Overridden for the RuleIndividual genotype.- Throws:
java.io.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
public void reset(EvolutionState state, int thread)
-
mutate
public void mutate(EvolutionState state, int thread)
Mutates the Individual. The default implementation simply calls mutate(...) on each of the RuleSets.
-
-
DMelt 3.0 © DataMelt by jWork.ORG