Yes, if you wanted to perform pruning after each generation then hooks
would be a good way to do this. Something along these lines should
work:
Life.get().addHook(new AbstractHook() {
public List<CandidateProgram> generationHook(List<CandidateProgram>
pop) {
for (CandidateProgram p: pop) {
prune(p);
}
return pop;
}
});
Sometimes it is actually preferable to leave the junk code in though,
because it can provide material for the genetic operators to work
with, and recombine in different configurations. This is probably
problem dependent. Of course you would still probably want to
simplifying the final solutions found though.
To traverse the program tree, get the root node for the
GPCandidateProgram with the getRootNode() method, and then use the
methods available on the Node to get/set its child nodes.
Tom