June 2005


Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sean Luke <[log in to unmask]>
Reply To:
ECJ Evolutionary Computation Toolkit <[log in to unmask]>
Mon, 13 Jun 2005 14:07:29 -0400
text/plain (896 bytes) , (24 kB) , (7 kB) , erc.params (7 kB) , text/plain (7 kB)
I'm having a difficult time reproducing the error you described, Artur.
  Here's what I've done so far:

1. I fixed so that it should produce javadocs with
properly-indented pseudocode for you to read.

2. I fixed a bug in that occurs when no trees of a given
return type exist for any possible size (a common situation I would

3. I hacked up a modification of symbolic regression erc.params to do
some atomic typing.  The types are nil (the default), float and float2
(for no good reason -- they're just symbols).  The objective here was
to add a return type (float) which had no terminal, and a return type
(float2) which had no nonterminals.

sin(float) -> nil
cos(nil) -> float
exp(float2) -> nil
X() -> float2
X() -> nil
add(nil,nil) -> nil
sub(nil,nil) -> nil
mul(nil,nil) -> nil
div(nil, nil) -> nil

Seems to work fine.  Here are the files.  Try java ec.Evolve -file

package; import*; import java.util.*; import java.math.*; import ec.util.*; import ec.*; /*  *  *  * Created Fri Jan 26 14:02:08 EST 2001  * By: Sean Luke  */ /**    Uniform implements the algorithm described in    <p>Bohm, Walter and Andreas Geyer-Schulz. 1996. "Exact Uniform Initialization for Genetic Programming". In <i>Foundations of Genetic Algorithms IV,</i> Richard Belew and Michael Vose, eds. Morgan Kaufmann. 379-407. (ISBN 1-55860-460-X)    <p> The user-provided requested tree size is either provided directly to the Uniform algorithm, or if the size is NOSIZEGIVEN, then Uniform will pick one at random from the GPNodeBuilder probability distribution system (using either max-depth and min-depth, or using num-sizes).    <p>Further, if the user sets the <tt>true-dist</tt> parameter, the Uniform will ignore the user's specified probability distribution and instead pick from a distribution between the minimum size and the maximum size the user specified, where the sizes are distributed according to the <i>actual</i> number of trees that can be created with that size. Since many more trees of size 10 than size 3 can be created, for example, size 10 will be picked that much more often.    <p>Uniform also prints out the actual number of trees that exist for a given size, return type, and function set. As if this were useful to you. :-)    <p> The algorithm, which is quite complex, is described in pseudocode below. Basically what the algorithm does is this:    <ol>    <li> For each function set and return type, determine the number of trees of each size which exist for that function set and tree type. Also determine all the permutations of tree sizes among children of a given node. All this can be done with dynamic programming. Do this just once offline, after the function sets are loaded.    <li> Using these tables, construct distributions of choices of tree size, child tree size permutations, etc.    <li> When you need to create a tree, pick a size, then use the distriutions to recursively create the tree (top-down).    </ol>    <p> <b>Dealing with Zero Distributions</b>    <p> Some domains have NO tree of a certain size. For example,    Artificial Ant's function set can make NO trees of size 2.    What happens when we're asked to make a tree of (invalid) size 2 in    Artificial Ant then? Uniform presently handles it as follows:    <ol><li> If the system specifically requests a given size that's invalid, Uniform will    look for the next larger size which is valid. If it can't find any,    it will then look for the next smaller size which is valid.    <li> If a random choice yields a given size that's invalid,    Uniform will pick again.    <li> If there is *no* valid size for a given return type, which probably indicates    an error, Uniform will halt and complain.    </ol>    <h3>Pseudocode:</h3>    <pre> * Func NumTreesOfType(type,size) * If NUMTREESOFTYPE[type,size] not defined, // memoize * N[type] = all nodes compatible with type * NUMTREESOFTYPE[type,size] = Sum(n in N[type], NumTreesRootedByNode(n,size)) * return NUMTREESOFTYPE[type,size] * * Func NumTreesRootedByNode(node,size) * If NUMTREESROOTEDBYNODE[node,size] not defined, // memoize * count = 0 * left = size - 1 * If node.children.length = 0 and left = 0 // a valid terminal * count = 1 * Else if node.children.length <= left // a valid nonterminal * For s is 1 to left inclusive // yeah, that allows some illegal stuff, it gets set to 0 * count += NumChildPermutations(node,s,left,0) * NUMTREESROOTEDBYNODE[node,size] = count * return NUMTREESROOTEBYNODE[node,size] * * * Func NumChildPermutations(parent,size,outof,pickchild) * // parent is our parent node * // size is the size of pickchild's tree that we're considering * // pickchild is the child we're considering * // outof is the total number of remaining nodes (including size) yet to fill * If NUMCHILDPERMUTATIONS[parent,size,outof,pickchild] is not defined, // memoize * count = 0 * if pickchild = parent.children.length - 1 and outof==size // our last child, outof must be size * count = NumTreesOfType(parent.children[pickchild].type,size) * else if pickchild < parent.children.length - 1 and * outof-size >= (parent.children.length - pickchild-1) // maybe we can fill with terminals * cval = NumTreesOfType(parent.children[pickchild].type,size) * tot = 0 * For s is 1 to outof-size // some illegal stuff, it gets set to 0 * tot += NumChildPermutations(parent,s,outof-size,pickchild+1) * count = cval * tot * NUMCHILDPERMUTATIONS [parent,size,outof,pickchild] = count * return NUMCHILDPERMUTATIONS[parent,size,outof,pickchild] * * * For each type type, size size * ROOT_D[type,size] = probability distribution of nodes of type and size, derived from * NUMTREESOFTYPE[type,size], our node list, and NUMTREESROOTEDBYNODE[node,size] * * For each parent,outof,pickchild * CHILD_D[parent,outof,pickchild] = probability distribution of tree sizes, derived from * NUMCHILDPERMUTATIONS[parent,size,outof,pickchild] * * Func FillNodeWithChildren(parent,pickchild,outof) * If pickchild = parent.children.length - 1 // last child * Fill parent.children[pickchild] with CreateTreeOfType(parent.children[pickchild].type,outof) * Else choose size from CHILD_D[parent,outof,pickchild] * Fill parent.pickchildren[pickchild] with CreateTreeOfType(parent.children[pickchild].type,size) * FillNodeWithChildren(parent,pickchild+1,outof-size) * return     </pre>     Func CreateTreeOfType(type,size)         Choose node from ROOT_D[type,size]         If size > 1             FillNodeWithChildren(node,0,size-1)         return node <p><b>Parameters</b><br> <table> <tr><td valign=top><i>base</i>.<tt>true-dist</tt><br> <font size=-1>bool= true or false (default)</font></td> <td valign=top>(should we use the true numbers of trees for each size as the distribution for picking trees, as opposed to the user-specified distribution?)</td></tr> </table> */ public class Uniform extends GPNodeBuilder     {     public static final String P_UNIFORM = "uniform";     public static final String P_TRUEDISTRIBUTION = "true-dist";     public Parameter defaultBase()         {         return GPBuildDefaults.base().push(P_UNIFORM);         }     // the checkboundary we hand to RandomChoice     public final static int CHECKBOUNDARY = 8;     // Mapping of integers to function sets     public GPFunctionSet[] functionsets;     // Mapping of function sets to Integers     public Hashtable _functionsets;     // Mapping of GPNodes to Integers (thus to ints)     public Hashtable funcnodes;     // number of nodes     public int numfuncnodes;     // max arity of any node     public int maxarity;     // maximum size of nodes computed     public int maxtreesize;     // true size distributions     public BigInteger[/*functionset*/][/*type*/][/*size*/] _truesizes;     public double[/*functionset*/][/*type*/][/*size*/] truesizes;     // do we use the true distributions to pick tree sizes?     public boolean useTrueDistribution;     // Sun in its infinite wisdom (what idiots) decided to make     // BigInteger IMMUTABLE. There is a MutableBigInteger, but it's not     // public! And Sun only caches the first 16 positive and 16 negative     // integer constants, not exactly that useful for us. As a result, we'll     // be making a dang lot of BigIntegers here. Garbage-collection hell. :-(     // ...well, it's not all that slow really.     public BigInteger NUMTREESOFTYPE[/*FunctionSet*/][/*type*/][/*size*/];     public BigInteger NUMTREESROOTEDBYNODE[/*FunctionSet*/][/*nodenum*/][/*size*/];     public BigInteger NUMCHILDPERMUTATIONS[/*FunctionSet*/][/*parentnodenum*/][/*size*/][/*outof*/][/*pickchild*/];     // tables derived from the previous ones through some massaging     public UniformGPNodeStorage ROOT_D[/*FunctionSet*/][/*type*/][/*size*/][/*the nodes*/];     public boolean ROOT_D_ZERO[/*FunctionSet*/][/*type*/][/*size*/]; // is ROOT_D all zero for these values?     public double CHILD_D[/*FunctionSet*/][/*type*/][/*outof*/][/*pickchild*/][/* the nodes*/];     public void setup(final EvolutionState state, final Parameter base)         {         super.setup(state,base);         Parameter def = defaultBase();         // use true distributions? false is default         useTrueDistribution = state.parameters.getBoolean(             base.push(P_TRUEDISTRIBUTION), def.push(P_TRUEDISTRIBUTION),false);         if (minSize>0) // we're using maxSize and minSize             maxtreesize=maxSize;         else if (sizeDistribution != null)             maxtreesize = sizeDistribution.length;         else state.output.fatal("Uniform is used for the GP node builder, but no distribution was specified." +                                 " You must specify either a min/max size, or a full size distribution.",                                 base.push(P_MINSIZE), def.push(P_MINSIZE));         // preprocess offline         preprocess(state,maxtreesize);         }     public int pickSize(final EvolutionState state, final int thread,                         final int functionset, final int type)         {         if (useTrueDistribution)             return RandomChoice.pickFromDistribution(                 truesizes[functionset][type],state.random[thread].nextDouble(),CHECKBOUNDARY);         else return super.pickSize(state,thread);         }     public void preprocess(final EvolutionState state, final int _maxtreesize)         {         state.output.message("Determining Tree Sizes");         maxtreesize = _maxtreesize;         Hashtable functionSetRepository = ((GPInitializer)state.initializer).functionSetRepository;         // Put each function set into the arrays         functionsets = new GPFunctionSet[functionSetRepository.size()];         _functionsets = new Hashtable();         Enumeration e = functionSetRepository.elements();         int count=0;         while(e.hasMoreElements())             {             GPFunctionSet set = (GPFunctionSet)(e.nextElement());             _functionsets.put(set,new Integer(count));             functionsets[count++] = set;             }         // For each function set, assign each GPNode to a unique integer         // so we can keep track of it (ick, this will be inefficient!)         funcnodes = new Hashtable();         Hashtable t_nodes = new Hashtable();         count = 0;         maxarity=0;         GPNode n;         for(int x=0;x<functionsets.length;x++)             {             // hash all the nodes so we can remove duplicates             for(int typ=0;typ<functionsets[x].nodes.length;typ++)                 for(int nod=0;nod<functionsets[x].nodes[typ].length;nod++)                     t_nodes.put(n=functionsets[x].nodes[typ][nod].node,n);             // rehash with Integers, yuck             e = t_nodes.elements();             GPNode tmpn;             while(e.hasMoreElements())                 {                 tmpn = (GPNode)(e.nextElement());                 if (maxarity < tmpn.children.length)                     maxarity = tmpn.children.length;                 funcnodes.put(tmpn,new Integer(count++));                 }             }         numfuncnodes = funcnodes.size();         GPInitializer initializer = ((GPInitializer)state.initializer);         int numAtomicTypes = initializer.numAtomicTypes;         int numSetTypes = initializer.numSetTypes;         // set up the arrays         NUMTREESOFTYPE = new BigInteger[functionsets.length][numAtomicTypes+numSetTypes][maxtreesize+1];         NUMTREESROOTEDBYNODE = new BigInteger[functionsets.length][numfuncnodes][maxtreesize+1];         NUMCHILDPERMUTATIONS = new BigInteger[functionsets.length][numfuncnodes][maxtreesize+1][maxtreesize+1][maxarity];         ROOT_D = new UniformGPNodeStorage[functionsets.length][numAtomicTypes+numSetTypes][maxtreesize+1][];         ROOT_D_ZERO = new boolean[functionsets.length][numAtomicTypes+numSetTypes][maxtreesize+1];         CHILD_D = new double[functionsets.length][numfuncnodes][maxtreesize+1][maxtreesize+1][];         // Go through each function set and determine numbers         // (this will take quite a while! Thankfully it's offline)         _truesizes = new BigInteger[functionsets.length][numAtomicTypes+numSetTypes][maxtreesize+1];         for(int x=0;x<functionsets.length;x++)             for(int y=0;y<numAtomicTypes+numSetTypes;y++)                 for(int z=1;z<=maxtreesize;z++)                     state.output.message("Set: " + x + " Type: " + y + " Size: " + z + " num: " +                                          (_truesizes[x][y][z] = numTreesOfType(initializer,x,y,z)));         state.output.message("Compiling Distributions");         // convert to doubles and organize distribution         truesizes = new double[functionsets.length][numAtomicTypes+numSetTypes][maxtreesize+1];         for(int x=0;x<functionsets.length;x++)             for(int y=0;y<numAtomicTypes+numSetTypes;y++)                 {                 for(int z=1;z<=maxtreesize;z++)                     truesizes[x][y][z] = _truesizes[x][y][z].doubleValue();                 // and if this is all zero (a possibility) we should be forgiving (hence the 'true') -- I *think*                 RandomChoice.organizeDistribution(truesizes[x][y],true);                 }         // compute our percentages         computePercentages();         }     // hopefully this will get inlined     public final int intForNode(GPNode node)         {         return ((Integer)(funcnodes.get(node))).intValue();         }     public BigInteger numTreesOfType(final GPInitializer initializer,             final int functionset, final int type, final int size)         {         if (NUMTREESOFTYPE[functionset][type][size]==null)             {             GPFuncInfo[] nodes = functionsets[functionset].nodes[type];             BigInteger count = BigInteger.valueOf(0);             for(int x=0;x<nodes.length;x++)                 count = count.add(numTreesRootedByNode(initializer,functionset,nodes[x].node,size));             NUMTREESOFTYPE[functionset][type][size] = count;             }         return NUMTREESOFTYPE[functionset][type][size];         }     public BigInteger numTreesRootedByNode(final GPInitializer initializer,             final int functionset, final GPNode node, final int size)         {         if (NUMTREESROOTEDBYNODE[functionset][intForNode(node)][size]==null)             {             BigInteger one = BigInteger.valueOf(1);             BigInteger count = BigInteger.valueOf(0);             int outof = size-1;             if (node.children.length == 0 && outof == 0) // a valid terminal                 count = one;             else if (node.children.length <= outof) // a valid nonterminal                 for (int s=1;s<=outof;s++)                     count = count.add(numChildPermutations(initializer,functionset,node,s,outof,0));             //System.out.println("Node: " + node + " Size: " + size + " Count: " +count);             NUMTREESROOTEDBYNODE[functionset][intForNode(node)][size] = count;             }         return NUMTREESROOTEDBYNODE[functionset][intForNode(node)][size];         }     public BigInteger numChildPermutations( final GPInitializer initializer,         final int functionset, final GPNode parent, final int size,         final int outof, final int pickchild)         {         if (NUMCHILDPERMUTATIONS[functionset][intForNode(parent)][size][outof][pickchild]==null)             {             BigInteger count = BigInteger.valueOf(0);             if (pickchild == parent.children.length - 1 && size==outof)                 count = numTreesOfType(initializer,functionset,parent.constraints(initializer).childtypes[pickchild].type,size);             else if (pickchild < parent.children.length - 1 &&                      outof-size >= (parent.children.length - pickchild-1))                 {                 BigInteger cval = numTreesOfType(initializer,functionset,parent.constraints(initializer).childtypes[pickchild].type,size);                 BigInteger tot = BigInteger.valueOf(0);                 for (int s=1; s<=outof-size; s++)                     tot = tot.add(numChildPermutations(initializer,functionset,parent,s,outof-size,pickchild+1));                 count = cval.multiply(tot);                 }             // System.out.println("Parent: " + parent + " Size: " + size + " OutOf: " + outof +             // " PickChild: " + pickchild + " Count: " +count);             NUMCHILDPERMUTATIONS[functionset][intForNode(parent)][size][outof][pickchild] = count;             }         return NUMCHILDPERMUTATIONS[functionset][intForNode(parent)][size][outof][pickchild];         }     private final double getProb(final BigInteger i)         {         if (i==null) return 0.0f;         else return i.doubleValue();         }     public void computePercentages()         {         // load ROOT_D         for(int f = 0;f<NUMTREESOFTYPE.length;f++)             for(int t=0;t<NUMTREESOFTYPE[f].length;t++)                 for(int s=0;s<NUMTREESOFTYPE[f][t].length;s++)                     {                     ROOT_D[f][t][s] = new UniformGPNodeStorage[functionsets[f].nodes[t].length];                     for(int x=0;x<ROOT_D[f][t][s].length;x++)                         {                         ROOT_D[f][t][s][x] = new UniformGPNodeStorage();                         ROOT_D[f][t][s][x].node = functionsets[f].nodes[t][x].node;                         ROOT_D[f][t][s][x].prob = getProb(NUMTREESROOTEDBYNODE[f][intForNode(ROOT_D[f][t][s][x].node)][s]);                         }                     // organize the distribution                     //System.out.println("Organizing " + f + " " + t + " " + s);                     // check to see if it's all zeros                     for(int x=0;x<ROOT_D[f][t][s].length;x++)                         if (ROOT_D[f][t][s][x].prob != 0.0)                             {                             // don't need to check for negatives here I believe                             RandomChoice.organizeDistribution(ROOT_D[f][t][s],ROOT_D[f][t][s][0]);                             ROOT_D_ZERO[f][t][s] = false;                             break;                             }                         else                             {                             ROOT_D_ZERO[f][t][s] = true;                             }                     }         // load CHILD_D         for(int f = 0;f<NUMCHILDPERMUTATIONS.length;f++)             for(int p=0;p<NUMCHILDPERMUTATIONS[f].length;p++)                 for(int o=0;o<maxtreesize+1;o++)                     for(int c=0;c<maxarity;c++)                         {                         CHILD_D[f][p][o][c] = new double[o+1];                         for(int s=0;s<CHILD_D[f][p][o][c].length;s++)                             CHILD_D[f][p][o][c][s] = getProb(NUMCHILDPERMUTATIONS[f][p][s][o][c]);                         // organize the distribution                         //System.out.println("Organizing " + f + " " + p + " " + o + " " + c);                         // check to see if it's all zeros                         for(int x=0;x<CHILD_D[f][p][o][c].length;x++)                             if (CHILD_D[f][p][o][c][x] != 0.0)                                 {                                 // don't need to check for negatives here I believe                                 RandomChoice.organizeDistribution(CHILD_D[f][p][o][c]);                                 break;                                 }                         }         }     GPNode createTreeOfType(final GPInitializer initializer,             final int functionset, final int type, final int size, final MersenneTwisterFast mt)         throws CloneNotSupportedException         {         //System.out.println("" + functionset + " " + type + " " + size);         int choice = RandomChoice.pickFromDistribution(             ROOT_D[functionset][type][size],ROOT_D[0][0][0][0],             mt.nextDouble(),CHECKBOUNDARY);         GPNode node = (GPNode)(ROOT_D[functionset][type][size][choice].node.protoClone());         //System.out.println("Size: " + size + "Rooted: " + node);         if (node.children.length == 0 && size !=1) // uh oh             {             System.out.println("Size: " + size + " Node: " + node);             for(int x=0;x<ROOT_D[functionset][type][size].length;x++)                 System.out.println("" + x + (GPNode)(ROOT_D[functionset][type][size][x].node) + " " + ROOT_D[functionset][type][size][x].prob );             }         if (size > 1) // nonterminal             fillNodeWithChildren(initializer,functionset,node,ROOT_D[functionset][type][size][choice].node,0,size-1,mt);         return node;         }     void fillNodeWithChildren(final GPInitializer initializer,             final int functionset, final GPNode parent, final GPNode parentc,             final int pickchild, final int outof, final MersenneTwisterFast mt)         throws CloneNotSupportedException         {         if (pickchild == parent.children.length - 1)             {             parent.children[pickchild] =                 createTreeOfType(initializer,functionset,parent.constraints(initializer).childtypes[pickchild].type,outof, mt);             }         else             {             int size = RandomChoice.pickFromDistribution(                 CHILD_D[functionset][intForNode(parentc)][outof][pickchild],                 mt.nextDouble(),CHECKBOUNDARY);             parent.children[pickchild] =                 createTreeOfType(initializer,functionset,parent.constraints(initializer).childtypes[pickchild].type,size,mt);             fillNodeWithChildren(initializer,functionset,parent,parentc,pickchild+1,outof-size,mt);             }         parent.children[pickchild].parent = parent;         parent.children[pickchild].argposition = (byte)pickchild;         }     public GPNode newRootedTree(final EvolutionState state,                                 final GPType type,                                 final int thread,                                 final GPNodeParent parent,                                 final GPFunctionSet set,                                 final int argposition,                                 final int requestedSize) throws CloneNotSupportedException         {         GPInitializer initializer = ((GPInitializer)state.initializer);         if (requestedSize == NOSIZEGIVEN) // pick from the distribution             {             final int BOUNDARY = 20; // if we try 20 times and fail, check to see if it's possible to succeed             int bound=0;             int fset = ((Integer)(_functionsets.get(set))).intValue();             int siz = pickSize(state,thread,fset,type.type);             int typ = type.type;             while(ROOT_D_ZERO[fset][typ][siz])                 {                 if (++bound == BOUNDARY)                     {                     // do the check                     for(int x=0;x<ROOT_D_ZERO[fset][typ].length;x++)                         if (!ROOT_D_ZERO[fset][typ][x]) break;                     // uh oh, we're all zeroes                     state.output.fatal(" was asked to build a tree with functionset " + set + " rooted with type " + type + ", but cannot because for some reason there are no trees of any valid size (within the specified size range) which exist for this function set and type.");                     }                 siz = pickSize(state,thread,fset,typ);                 }             // okay, now we have a valid size.             GPNode n = createTreeOfType(initializer,fset,typ,siz,state.random[thread]);             n.parent = parent;             n.argposition = (byte)argposition;             return n;             }         else if (requestedSize<1)             {             state.output.fatal(" requested to build a tree, but a requested size was given that is < 1.");             return null; // never happens             }         else             {             int fset = ((Integer)(_functionsets.get(set))).intValue();             int typ = type.type;             int siz = requestedSize;             // we need to modify the requestedSize.             if (ROOT_D_ZERO[fset][typ][siz])                 {                 // march up                 for(int x=siz+1;x<ROOT_D_ZERO[fset][typ].length;x++)                     if (ROOT_D_ZERO[fset][typ][siz])                         { siz=x; break; }                 // march down                 for(int x=siz-1;x>=0;x--)                     if (ROOT_D_ZERO[fset][typ][siz])                         { siz=x; break; }                 // issue an error                 state.output.fatal(" was asked to build a tree with functionset " + set + " rooted with type " + type + ", but cannot because for some reason there are no trees of any valid size (within the specified size range) which exist for this function set and type.");                 }             GPNode n = createTreeOfType(initializer,fset,typ,siz,state.random[thread]);             n.parent = parent;             n.argposition = (byte)argposition;             return n;             }         }     } class UniformGPNodeStorage implements RandomChoiceChooserD     {     public GPNode node;     public double prob;     public double getProbability(final Object obj)         { return (((UniformGPNodeStorage)obj).prob); }     public void setProbability(final Object obj, final double _prob)         { ((UniformGPNodeStorage)obj).prob = _prob; }     }
package; import ec.*; import ec.util.*; import java.util.*; import java.util.Enumeration; /*  *  *  * Created: Thu Oct 7 15:38:45 1999  * By: Sean Luke  */ /**  * A GPTreeConstraints is a Clique which defines constraint information  * common to many different GPTree trees, namely the tree type,  * builder, and function set. GPTreeConstraints have unique names  * by which they are identified.  *  * <p>In adding new things to GPTreeConstraints, you should ask yourself  * the following questions: first, is this something that takes up too  * much memory to store in GPTrees themseves? second, is this something  * that needs to be accessed very rapidly, so cannot be implemented as  * a method call in a GPTree? third, can this be shared among different  * GPTrees?  *  <p><b>Parameters</b><br>  <table>  <tr><td valign=top><i>base</i>.<tt>size</tt><br>  <font size=-1>int &gt;= 1</font></td>  <td valign=top>(number of tree constraints)</td></tr>  <tr><td valign=top><i>base.n</i>.<tt>name</tt><br>  <font size=-1>String</font></td>  <td valign=top>(name of tree constraint <i>n</i>)</td></tr>  <tr><td valign=top><i>base.n</i>.<tt>init</tt><br>  <font size=-1>classname, inherits and !=</font></td>  <td valign=top>(GP node builder for tree constraint <i>n</i>)</td></tr>  <tr><td valign=top><i>base.n</i>.<tt>returns</tt><br>  <font size=-1>String</font></td>  <td valign=top>(tree type for tree constraint <i>n</i>)</td></tr>  <tr><td valign=top><i>base.n</i>.<tt>fset</tt><br>  <font size=-1>String</font></td>  <td valign=top>(function set for tree constraint <i>n</i>)</td></tr>  </table>  * @author Sean Luke  * @version 1.0  */ public class GPTreeConstraints implements Clique     {     public static final int SIZE_OF_BYTE = 256;     public final static String P_NAME = "name";     public final static String P_SIZE = "size";     public final static String P_INIT = "init";     public static final String P_RETURNS = "returns";     public static final String P_FUNCTIONSET = "fset";     public String name;     /** The byte value of the constraints -- we can only have 256 of them */     public byte constraintNumber;     /** The builder for the tree */     public GPNodeBuilder init;     /** The type of the root of the tree */     public GPType treetype;     /** The function set for nodes in the tree */     public GPFunctionSet functionset;     public String toString() { return name; }     /** This must be called <i>after</i> the GPTypes and GPFunctionSets         have been set up. */     public final void setup(final EvolutionState state, final Parameter base)         {         // What's my name?         name = state.parameters.getString(base.push(P_NAME),null);         if (name==null)             state.output.fatal("No name was given for this function set.",                                base.push(P_NAME));         // Register me         GPTreeConstraints old_constraints =             (GPTreeConstraints)(((GPInitializer)state.initializer).treeConstraintRepository.put(name,this));         if (old_constraints != null)             state.output.fatal("The GP tree constraint \"" + name + "\" has been defined multiple times.", base.push(P_NAME));         // Load my initializing builder         init = (GPNodeBuilder)(state.parameters.getInstanceForParameter(base.push(P_INIT),null,GPNodeBuilder.class));         init.setup(state,base.push(P_INIT));         // Load my return type         String s = state.parameters.getString(base.push(P_RETURNS),null);         if (s==null)             state.output.fatal("No return type given for the GPTreeConstraints " + name, base.push(P_RETURNS));         treetype = GPType.typeFor(s,state);         // Load my function set         s = state.parameters.getString(base.push(P_FUNCTIONSET),null);         if (s==null)             state.output.fatal("No function set given for the GPTreeConstraints " + name, base.push(P_RETURNS));         functionset = GPFunctionSet.functionSetFor(s,state);         state.output.exitIfErrors(); // otherwise checkFunctionSetValidity might crash below         // Determine the validity of the function set         // the way we do that is by gathering all the types that         // are transitively used, starting with treetype, as in:         Hashtable typ = new Hashtable();         checkFunctionSetValidity(state, typ, treetype);         // next we make sure that for every one of these types,         // there's a terminal with that return type, and *maybe*         // a nonterminal         Enumeration e = typ.elements();         while (e.hasMoreElements())             {             GPType t = (GPType)(e.nextElement());             GPFuncInfo[] i = functionset.terminals[t.type];             if (i.length==0) // uh oh                 state.output.warning("In function set " + functionset + " for the GPTreeConstraints " + this + ", no terminals are given with the return type " + t + " which is required by other functions in the function set.", base);             i = functionset.nonterminals[t.type];             if (i.length==0) // uh oh                 state.output.warning("In function set " + functionset + " for the GPTreeConstraints " + this + ", no *nonterminals* are given with the return type " + t + " which is required by other functions in the function set. This may or may not be a problem for you.", base);             }         state.output.exitIfErrors();         }     // When completed, done will hold all the types which are needed     // in the function set -- you can then check to make sure that     // they contain at least one terminal and (hopefully) at least     // one nonterminal.     private void checkFunctionSetValidity(final EvolutionState state,                                           final Hashtable done,                                           final GPType type)         {         // Grab the array in nodes         GPFuncInfo[] i = functionset.nodes[type.type];         // For each argument type in a node in i, if it's not in done,         // then add it to done and call me on it         GPInitializer initializer = ((GPInitializer)state.initializer);         for (int x=0; x<i.length;x++)             for (int y=0;y<i[x].node.constraints(initializer).childtypes.length;y++)                 if (done.get(i[x].node.constraints(initializer).childtypes[y])==null)                     {                     done.put(i[x].node.constraints(initializer).childtypes[y],                              i[x].node.constraints(initializer).childtypes[y]);                     checkFunctionSetValidity(                         state, done, i[x].node.constraints(initializer).childtypes[y]);                     }         }     /** You must guarantee that after calling constraintsFor(...) one or         several times, you call state.output.exitIfErrors() once. */     public static GPTreeConstraints constraintsFor(final String constraintsName,                                                    final EvolutionState state)         {         GPTreeConstraints myConstraints = (GPTreeConstraints)(((GPInitializer)state.initializer).treeConstraintRepository.get(constraintsName));         if (myConstraints==null)             state.output.error("The GP tree constraint \"" + constraintsName + "\" could not be found.");         return myConstraints;         }     }
Okay, so what is the deal with your error? Your error occurs when the tree builder is asked to create a tree which returns some type (in your case, 'edge'), and such a tree isn't possible to make. Here's the crucial line: Set: 0 Type: 0 Size: 1 num: 0 Set: 0 Type: 0 Size: 2 num: 0 Set: 0 Type: 0 Size: 3 num: 1 Set: 0 Type: 0 Size: 4 num: 0 Set: 0 Type: 0 Size: 5 num: 0 Set: 0 Type: 1 Size: 1 num: 1 Set: 0 Type: 1 Size: 2 num: 0 Set: 0 Type: 1 Size: 3 num: 0 Set: 0 Type: 1 Size: 4 num: 0 Set: 0 Type: 1 Size: 5 num: 0 Set is function set. Type is GPType. Size is the size of a tree using that function set and returning that GPType. num is the number of total tree structures of that size which can do that. As you can see, if you want a tree which returns type#0, there is only a single tree (of size 3) which can do it. Likewise for trees of type #1, there is only a single tree (a terminal -- size 1) which can do it.   Only two possible trees grand total! Perhaps that was more restrictive than you had wanted. :-) The specific complaint is coming about because you asked to build trees from 2-5 (for mutation maybe?), and there ARE no trees of size 2-5 of type #1. You may need to loosen your constraints and/or your tree size options. Here's hoping Uniform doesn't have a bug! :-) Sean