0. It sounds like what you really want is to just use
ec.gp.koza.MutationPipeline, with the grow-builder's min-depth and
max-depth set to 0. In the standard mutation builder, one way to do
it is?
gp.koza.mutate.build.0.min-depth= 0
gp.koza.mutate.build.0.max-depth= 0
1. You can get a GPNode by taking a node out of your GPFunctionSet
and clone()ing it. The function set can be found at
yourGPTree.constraints((GPInitializer)yourInitializer).functionset
2. Your node needs to be type-compatable with its parents and
children if you're using typed GP. You can pick nodes with certain
return types from your function set. You can also test for type
compatability between some old child and some new child with the
GPNode function swapCompatibleWith().
3. ECJ trees are pretty plain, except that the nodes have back
pointers which you need to remember to set. Once you have a GPNode,
you can weave it into your tree along these lines:
// to set your node to be the parent of some other node n, which will
be the j'th child of your node...
n.argposition = j;
n.parent = node;
node.child[j] = n;
// to set the node to be a child of a parent 'theParent' at index i
node.argposition = i;
node.parent = theParent; // theParent will be either a GPTree (if
node is the root) or a GPNode
if (theParent instanceof GPTree)
theParent.child = node; // i better be 0!
else theParent.children[i] = node;
As you can see, it's relatively straightforward.
Sean
On Oct 5, 2007, at 9:43 AM, ghada wrote:
> Hi,
>
>
>
> I need to create a NEW GPNode (initialize it properly, and set its
> value), to use it afterwards to replace a sub-tree in a constructed
> GPTree.
>
>
>
> How can I do that in a proper ecj way, so the node will be suitable
> for the replacement?
>
>
>
> Ghada
>
>
|