|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.gp.GPNode
ec.gp.ERC
ec.app.lawnmower.func.LawnERC
public class LawnERC
Field Summary | |
---|---|
int |
maxx
|
int |
maxy
|
int |
x
|
int |
y
|
Fields inherited from class ec.gp.ERC |
---|
ERC_PREFIX |
Fields inherited from class ec.gp.GPNode |
---|
argposition, children, constraints, GPNODEPRINTTAB, MAXPRINTBYTES, NODESEARCH_ALL, NODESEARCH_CUSTOM, NODESEARCH_NONTERMINALS, NODESEARCH_TERMINALS, P_NODE, P_NODECONSTRAINTS, parent, REPLACEMENT_CHAR, SITUATION_MUTATION, SITUATION_NEWIND |
Constructor Summary | |
---|---|
LawnERC()
|
Method Summary | |
---|---|
boolean |
decode(DecodeReturn dret)
Decodes data into the ERC from dret. |
java.lang.String |
encode()
Encodes data from the ERC, using ec.util.Code. |
void |
eval(EvolutionState state,
int thread,
GPData input,
ADFStack stack,
GPIndividual individual,
Problem problem)
Evaluates the node with the given thread, state, individual, problem, and stack. |
java.lang.String |
name()
Returns the lowercase "name" of this ERC function class, some simple, short name which distinguishes this class from other ERC function classes you're using. |
boolean |
nodeEquals(GPNode node)
Implement this to do ERC-to-ERC comparisons. |
int |
nodeHashCode()
Implement this to hash ERCs, along with other nodes, in such a way that two "equal" ERCs will usually hash to the same value. |
void |
readNode(EvolutionState state,
java.io.DataInput dataInput)
To successfully read from a DataOutput, you must override this to read your specific ERC data in. |
void |
resetNode(EvolutionState state,
int thread)
Remember to override this to randomize your ERC after it has been cloned. |
void |
setup(EvolutionState state,
Parameter base)
Sets up a prototypical GPNode with those features all nodes of that prototype share, and nothing more. |
java.lang.String |
toStringForHumans()
You might want to override this to return a special human-readable version of the erc value; otherwise this defaults to toString(); This should be something that resembles a LISP atom. |
void |
writeNode(EvolutionState state,
java.io.DataOutput dataOutput)
To successfully write to a DataOutput, you must override this to write your specific ERC data out. |
Methods inherited from class ec.gp.ERC |
---|
checkConstraints, mutateERC, readNode, toString |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public int maxx
public int maxy
public int x
public int y
Constructor Detail |
---|
public LawnERC()
Method Detail |
---|
public void setup(EvolutionState state, Parameter base)
GPNode
setup
in interface Prototype
setup
in interface Setup
setup
in class GPNode
public void resetNode(EvolutionState state, int thread)
ERC
resetNode
in class ERC
public int nodeHashCode()
ERC
nodeHashCode
in class ERC
public boolean nodeEquals(GPNode node)
ERC
nodeEquals
in class ERC
public void readNode(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
ERC
readNode
in class ERC
java.io.IOException
public void writeNode(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
ERC
writeNode
in class ERC
java.io.IOException
public java.lang.String encode()
ERC
encode
in class ERC
public boolean decode(DecodeReturn dret)
ERC
decode
in class ERC
public java.lang.String name()
ERC
name
in class ERC
public java.lang.String toStringForHumans()
ERC
toStringForHumans
in class ERC
public void eval(EvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual, Problem problem)
GPNode
About input: input is special; it is how data is passed between parent and child nodes. If children "receive" data from their parent node when it evaluates them, they should receive this data stored in input. If (more likely) the parent "receives" results from its children, it should pass them an input object, which they'll fill out, then it should check this object for the returned value.
A tree is typically evaluated by dropping a GPData into the root. When the root returns, the resultant input should hold the return value.
In general, you should not be creating new GPDatas. If you think about it, in most conditions (excepting ADFs and ADMs) you can use and reuse input for most communications purposes between parents and children.
So, let's say that your GPNode function implements the boolean AND function,
and expects its children to return return boolean values (as it does itself).
You've implemented your GPData subclass to be, uh, BooleanData, which
looks like
public class BooleanData extends GPData
{
public boolean result;
public GPData copyTo(GPData gpd)
{
((BooleanData)gpd).result = result;
}
}
...so, you might implement your eval(...) function as follows:
public void eval(final EvolutionState state,
final int thread,
final GPData input,
final ADFStack stack,
final GPIndividual individual,
final Problem problem
{
BooleanData dat = (BooleanData)input;
boolean x;
// evaluate the first child
children[0].eval(state,thread,input,stack,individual,problem);
// store away its result
x = dat.result;
// evaluate the second child
children[1].eval(state,thread,input,stack,individual,problem);
// return (in input) the result of the two ANDed
dat.result = dat.result && x;
return;
}
eval
in class GPNode
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |