|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ec.rule.RuleSet
RuleSet is a set of Rules, implemented straightforwardly as an arbitrary-length array of Rules. A RuleIndividual is simply a list of RuleSets. Most typically, a RuleIndividual contains a single RuleSet, containing a variety of Rules. RuleSets contain many useful subsetting and modification functions which you can use in breeding operators which modify RuleSets and Rules.
Besides the Rules themselves, the only thing else a RuleSet contains is a pointer to a corresponding RuleSetConstraints object, which holds all of its modification parameters. See RuleSetConstraints for a description of these parameters.
Parameters
base.constraints string |
(name of the rule set constraints) |
Default Base
rule.ruleset
Field Summary | |
byte |
constraints
An index to a RuleSetConstraints |
static java.lang.String |
N_RULES
The message to appear when printing the rule set |
int |
numRules
How many rules are there used in the rules array |
static java.lang.String |
P_CONSTRAINTS
The constraint for the rule set |
static java.lang.String |
P_RULESET
|
Rule[] |
rules
The rules in the rule set |
Constructor Summary | |
RuleSet()
|
Method Summary | |
void |
addRandomRule(EvolutionState state,
int thread)
Add a random rule to the rule set |
void |
addRule(Rule rule)
Add a rule directly to the rule set. |
RuleSetConstraints |
constraints()
|
Parameter |
defaultBase()
Returns the default base for this prototype. |
boolean |
equals(java.lang.Object _other)
|
int |
hashCode()
The hash code for the rule set. |
void |
join(RuleSet other)
Makes a copy of the rules in another RuleSet and adds the rule copies. |
void |
mutateRules(EvolutionState state,
int thread)
Mutates rules in the RuleSet independently with the given probability. |
int |
numRules()
How many rules are there used in the rules array |
void |
printRuleSet(EvolutionState state,
int log,
int verbosity)
Prints the rule set such that the computer can read it later |
void |
printRuleSet(EvolutionState state,
java.io.PrintWriter writer)
Prints the rule set such that the computer can read it later |
void |
printRuleSetForHumans(EvolutionState state,
int log,
int verbosity)
Prints out the rule set in a readable fashion. |
java.lang.Object |
protoClone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
java.lang.Object |
protoCloneSimple()
This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final. |
void |
randomizeRulesOrder(EvolutionState state,
int thread)
Randomizes the order of the rules in the rule set. |
void |
readRuleSet(EvolutionState state,
java.io.LineNumberReader reader)
Reads the rule set |
Rule |
removeRandomRule(EvolutionState state,
int thread)
Removes a randomly-chosen rule from the rule set and returns it. |
Rule |
removeRule(int index)
Removes a rule from the rule set and returns it. |
void |
reset(EvolutionState state,
int thread)
A reset method for randomly reinitializing the RuleSet |
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. |
RuleSet[] |
split(EvolutionState state,
int thread,
RuleSet[] sets)
Splits the rule set into a number of disjoint rule sets, copying the rules and adding them to the sets as appropriate. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String N_RULES
public static final java.lang.String P_RULESET
public static final java.lang.String P_CONSTRAINTS
public byte constraints
public Rule[] rules
public int numRules
Constructor Detail |
public RuleSet()
Method Detail |
public final RuleSetConstraints constraints()
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
Prototype
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.
public Object protoClone() throws CloneNotSupportedException
{
return super.clone();
}
public Object protoClone() throws CloneNotSupportedException
{
myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
public Object protoClone() throws CloneNotSupportedException
{
MyObject myobj = (MyObject)(super.protoClone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
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.
protoClone
in interface Prototype
public final java.lang.Object protoCloneSimple()
Prototype
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
protoCloneSimple
in interface Prototype
public int numRules()
public void reset(EvolutionState state, int thread)
public void mutateRules(EvolutionState state, int thread)
public void randomizeRulesOrder(EvolutionState state, int thread)
public void addRandomRule(EvolutionState state, int thread)
public void addRule(Rule rule)
public Rule removeRule(int index)
public Rule removeRandomRule(EvolutionState state, int thread)
public void join(RuleSet other)
public RuleSet[] split(EvolutionState state, int thread, RuleSet[] sets)
public void printRuleSetForHumans(EvolutionState state, int log, int verbosity)
public void printRuleSet(EvolutionState state, int log, int verbosity)
public void printRuleSet(EvolutionState state, java.io.PrintWriter writer)
public void readRuleSet(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
public Parameter defaultBase()
Prototype
defaultBase
in interface Prototype
public void setup(EvolutionState state, Parameter base)
Prototype
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.
setup
in interface Prototype
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object _other)
equals
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |