ec.rule
Class RuleIndividual

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

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.

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

Version:
1.0
Author:
Sean Luke
See Also:
Serialized Form

Field Summary
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, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species
 
Constructor Summary
RuleIndividual()
           
 
Method Summary
 java.lang.Object clone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 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)
          Overridden for the RuleIndividual genotype.
 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)
          Overridden for the RuleIndividual genotype, writing each ruleset in turn.
 void printIndividual(EvolutionState state, java.io.PrintWriter writer)
          Overridden for the RuleIndividual genotype, writing each ruleset in turn.
 void printIndividualForHumans(EvolutionState state, int log, int verbosity)
          Overridden for the RuleIndividual genotype, writing each ruleset in turn.
 void readGenotype(EvolutionState state, java.io.DataInput dataInput)
          Overridden for the RuleIndividual genotype.
 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)
          Overridden for the RuleIndividual genotype, writing each ruleset in turn.
 
Methods inherited from class ec.Individual
genotypeToString, genotypeToStringForHumans, readIndividual, readIndividual, toString, writeIndividual
 
Methods inherited from class java.lang.Object
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

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(...).


clone

public java.lang.Object clone()
Description copied from interface: Prototype
Creates 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:
clone in interface Prototype
Overrides:
clone in class Individual

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
Specified by:
setup in interface Setup
Overrides:
setup in class Individual

printIndividualForHumans

public void printIndividualForHumans(EvolutionState state,
                                     int log,
                                     int verbosity)
Overridden for the RuleIndividual genotype, writing each ruleset in turn.

Overrides:
printIndividualForHumans in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            int log,
                            int verbosity)
Overridden for the RuleIndividual genotype, writing each ruleset in turn.

Overrides:
printIndividual in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            java.io.PrintWriter writer)
Overridden for the RuleIndividual genotype, writing each ruleset in turn.

Overrides:
printIndividual in class Individual

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:
writeGenotype in class Individual
Throws:
java.io.IOException

readGenotype

public void readGenotype(EvolutionState state,
                         java.io.DataInput dataInput)
                  throws java.io.IOException
Overridden for the RuleIndividual genotype.

Overrides:
readGenotype in class Individual
Throws:
java.io.IOException

parseGenotype

public void parseGenotype(EvolutionState state,
                          java.io.LineNumberReader reader)
                   throws java.io.IOException
Overridden for the RuleIndividual genotype.

Overrides:
parseGenotype in class Individual
Throws:
java.io.IOException

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)