public interface Node { public int subNodeCount(); //number of branches off this node public Node getSubNode (int nodeIndex); //get nth branch public boolean isTerminal(); //true if this is a terminal node public void setSubNode (int nodeIndex, Node value); // set nth branch public Node cloneTree(); //produce a clone for crossover/mutation public int depth(); // max depth of all branches below public int functionNodeCount(); // number of function nodes below public int terminalNodeCount(); // number of terminals below public int nodeCount(); // number of all nodes below public Node getFunctionNode (int index); // get nth function node from tree below public Node getTerminalNode (int index); // get nth terminal node from tree below public Node getNode (int index); // get nth node from tree below public String printPretty(); // string describing this node public Object run(); // do the thing... } //For Add; some of these might look like this: public Double run () { //add the result of run() of the two subnodes return ((Double)(subNodes[0].run()) + (Double)((subNodes[1].run()))); } public Node cloneTree () { // deep clone - IMPORTANT - clone the entire structure, don't copy links // otherwise mutation and crossover will mutate the parents and siblings at the same time! Node result = new Add(); for (int i=0; i max) max = result; } return max + 1; } public String printPretty () { // for printing the evolved expression return "+"; }