Jake, I presume you're talking about GP. GPNodes, GPTrees, and
GPIndividuals all basically work like this: after a population is
evaluated, typically the individuals undergo breeding to create new
individuals, and then are usually eliminated. Breeding works by
cloning subtrees, and ultimately nodes, from the old individuals to
form new individuals. The clone method used is lightClone(), which
ultimately calls clone() underneath.
So let's say you've made got a GPNode called 'foo' which has an
ArrayList called foo.bar. 'foo' is located in some GPIndividual, and
the GP system has decided to copy that individual, and the subtree
where 'foo' is located, to create a new child for the next
generation. We call foo.clone(). This creates a new object (call it
foo2). foo2.bar is pointing to the same ArrayList as foo.bar now.
Now we create another new child from foo (foo's lucky!) called foo3.
foo3.bar and foo2.bar BOTH are pointing to the same ArrayList as
This may be what you want, but I'm guessing it's not. Because now you
evaluate the new child individual that holds foo2. It adds something
to the foo2.bar ArrayList. When you get around to evaluating the
individual that has foo3, it ALSO will have that thing added into its
ArrayList because it's the same ArrayList. You probably were hoping
them to have separate ArrayLists is my guess.
To do that, you override the GPNode clone method for your particular
GPNode subclass to call super.clone(), and then say something like:
bar = (ArrayList)(bar.clone());
Now foo2 and foo3 have their own copies of the ArrayList, different
from the original one in foo, each storing what foo.bar had inside it,
but able to add their own independent stuff without stepping on each
On Jan 22, 2010, at 5:13 PM, Jake Pacheco wrote:
> Specifically, I have a node that is meant to calculate the zero lag
> exponential moving average of its child's value. This requires the
> having access to its own value on the previous evaluation, as well
> as the
> child's value for several evaluations back. The way I implemented
> this, the
> node stores its value in a variable after calculation, and adds the
> value to an ArrayList. However, I am not sure if these are preserved
> to the next evaluation, or, if they are preserved through evaluations,
> whether they will be empty once the next generation starts.