|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.gp.GPTree
public class GPTree
GPTree is a GPNodeParent which holds the root GPNode of a tree of GPNodes. GPTrees typically fill out an array held in a GPIndividual (their "owner") and their roots are evaluated to evaluate a Genetic programming tree. GPTrees also have constraints, which are shared, and define items shared among several GPTrees.
In addition to serialization for checkpointing, GPTrees may read and write themselves to streams in three ways.
GPTrees can print themselves for humans in one of three ways:
You turn the C-printing feature on with the c parameter, plus certain optional parameters (c-operators, c-variables) as described below. You turn the latex-printing latex parameter below. The C-printing parameter takes precedence.
Here's how the latex system works. To insert the code, you'll need to include the epic,ecltree, and probably the fancybox packages, in that order. You'll also need to define the command \gpbox, which takes one argument (the string name for the GPNode) and draws a box with that node. Lastly, you might want to set a few parameters dealing with the ecltree package.
Here's an example which looks quite good (pardon the double-backslashes in front of the usepackage statements -- javadoc is freaking out if I put a single backslash. So you'll need to remove the extra backslash in order to try out this example):
\documentclass[]{article} \ \usepackage{epic} % required by ecltree and fancybox packages \ \usepackage{ecltree} % to draw the GP trees \ \usepackage{fancybox} % required by \Ovalbox \begin{document} % minimum distance between nodes on the same line \setlength{\GapWidth}{1em} % draw with a thick dashed line, very nice looking \thicklines \drawwith{\dottedline{2}} % draw an oval and center it with the rule. You may want to fool with the % rule values, though these seem to work quite well for me. If you make the % rule smaller than the text height, then the GP nodes may not line up with % each other horizontally quite right, so watch out. \newcommand{\gpbox}[1]{\Ovalbox{#1\rule[-.7ex]{0ex}{2.7ex}}} % Here's the tree which the GP system spat out \begin{bundle}{\gpbox{progn3}}\chunk{\begin{bundle}{\gpbox{if-food-ahead}} \chunk{\begin{bundle}{\gpbox{progn3}}\chunk{\gpbox{right}} \chunk{\gpbox{left}}\chunk{\gpbox{move}}\end{bundle}} \chunk{\begin{bundle}{\gpbox{if-food-ahead}}\chunk{\gpbox{move}} \chunk{\gpbox{left}}\end{bundle}}\end{bundle}}\chunk{\begin{bundle}{\gpbox{progn2}} \chunk{\begin{bundle}{\gpbox{progn2}}\chunk{\gpbox{move}} \chunk{\gpbox{move}}\end{bundle}}\chunk{\begin{bundle}{\gpbox{progn2}} \chunk{\gpbox{right}}\chunk{\gpbox{left}}\end{bundle}}\end{bundle}} \chunk{\begin{bundle}{\gpbox{if-food-ahead}}\chunk{\begin{bundle}{\gpbox{if-food-ahead}} \chunk{\gpbox{move}}\chunk{\gpbox{left}}\end{bundle}} \chunk{\begin{bundle}{\gpbox{if-food-ahead}}\chunk{\gpbox{left}}\chunk{\gpbox{right}} \end{bundle}}\end{bundle}}\end{bundle} \end{document} |
Parameters
base.tc String |
(The tree's constraints) |
base.latex bool = true or false (default) |
(print for humans using latex?) |
base.c bool = true or false (default) |
(print for humans using c? Takes precedence over latex) |
base.c-operators bool = true (default) or false |
(when printing using c, print two-argument functions operators "b a c"? The alternative is functions "a(b, c)." |
base.c-variables bool = true (default) or false |
(when printing using c, print zero-argument functions as variables "a"? The alternative is functions "a()".) |
Default Base
gp.tree
Field Summary | |
---|---|
GPNode |
child
the root GPNode in the GPTree |
byte |
constraints
constraints on the GPTree -- don't access the constraints through this variable -- use the constraints() method instead, which will give the actual constraints object. |
static int |
NO_TREENUM
|
GPIndividual |
owner
the owner of the GPTree |
static java.lang.String |
P_TREE
|
static java.lang.String |
P_TREECONSTRAINTS
|
static java.lang.String |
P_USEC
|
static java.lang.String |
P_USELATEX
|
static java.lang.String |
P_USEOPS
|
static java.lang.String |
P_USEVARS
|
boolean |
printTerminalsAsVariablesInC
When using c to print for humans, do we print terminals as variables? (as opposed to zero-argument functions)? |
boolean |
printTwoArgumentNonterminalsAsOperatorsInC
When using c to print for humans, do we print two-argument nonterminals in operator form "a op b"? (as opposed to functions "op(a, b)")? |
boolean |
useC
Use c to print for humans? Takes precedence over latex. |
boolean |
useLatex
Use latex to print for humans? |
Constructor Summary | |
---|---|
GPTree()
|
Method Summary | |
---|---|
void |
buildTree(EvolutionState state,
int thread)
Builds a new randomly-generated rooted tree and attaches it to the GPTree. |
java.lang.Object |
clone()
Deep-clones the tree. |
GPTreeConstraints |
constraints(GPInitializer initializer)
|
Parameter |
defaultBase()
Returns the default base for this prototype. |
GPTree |
lightClone()
Like clone() but doesn't copy the tree. |
void |
printTree(EvolutionState state,
int log,
int verbosity)
Prints out the tree in single-line fashion suitable for reading in later by computer. |
void |
printTree(EvolutionState state,
java.io.PrintWriter writer)
Prints out the tree in single-line fashion suitable for reading in later by computer. |
void |
printTreeForHumans(EvolutionState state,
int log,
int verbosity)
Prints out the tree in a readable Lisp-like fashion. |
void |
readTree(EvolutionState state,
java.io.DataInput dataInput)
|
void |
readTree(EvolutionState state,
java.io.LineNumberReader reader)
Reads in the tree from a form printed by printTree. |
void |
setup(EvolutionState state,
Parameter base)
Sets up a prototypical GPTree with those features it shares with other GPTrees in its position in its GPIndividual, and nothhing more. |
boolean |
treeEquals(GPTree tree)
Returns true if I am "genetically" the same as tree, though we may have different owners. |
int |
treeHashCode()
Returns a hash code for comparing different GPTrees. |
int |
treeNumber()
An expensive function which determines my tree number -- only use for errors, etc. |
void |
verify(EvolutionState state)
Verification of validity of the tree -- strictly for debugging purposes only |
void |
writeTree(EvolutionState state,
java.io.DataOutput dataOutput)
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String P_TREE
public static final java.lang.String P_TREECONSTRAINTS
public static final java.lang.String P_USELATEX
public static final java.lang.String P_USEC
public static final java.lang.String P_USEOPS
public static final java.lang.String P_USEVARS
public static final int NO_TREENUM
public GPNode child
public GPIndividual owner
public byte constraints
public boolean useLatex
public boolean useC
public boolean printTerminalsAsVariablesInC
public boolean printTwoArgumentNonterminalsAsOperatorsInC
Constructor Detail |
---|
public GPTree()
Method Detail |
---|
public final GPTreeConstraints constraints(GPInitializer initializer)
public Parameter defaultBase()
Prototype
defaultBase
in interface Prototype
public boolean treeEquals(GPTree tree)
public int treeHashCode()
public GPTree lightClone()
public java.lang.Object clone()
clone
in interface Prototype
clone
in class java.lang.Object
public int treeNumber()
public void setup(EvolutionState state, Parameter base)
setup
in interface Prototype
setup
in interface Setup
public final void verify(EvolutionState state)
public void printTree(EvolutionState state, int log, int verbosity)
public void printTree(EvolutionState state, java.io.PrintWriter writer)
public void readTree(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException
java.io.IOException
public void writeTree(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
java.io.IOException
public void readTree(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
java.io.IOException
public void printTreeForHumans(EvolutionState state, int log, int verbosity)
public void buildTree(EvolutionState state, int thread)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |