If anyone is interested, here is the code I wrote to simplify a GPCandidateProgram:
It knows how to simplify functions where both children are literals (replacing it with a literal result of the calculation), and also various boolean operations.
It can be used like this:
Life.get().addHook(new AbstractHook() {
@Override
public List<CandidateProgram> generationHook(final List<CandidateProgram> pop) {
// ensure uniqueness
final Map<String, CandidateProgram> programs = Maps.newHashMap();
for (final CandidateProgram p : pop) {
simplify((GPCandidateProgram) p);
programs.put(p.toString(), p);
}
return Lists.newLinkedList(programs.values());
}
});
I don't know for a fact whether this simplification helps or hurts actual performance, but it just really bugged me to see programs that were unnecessarily complicated :-)
Consider the code to be in the public domain, you can do whatever you like with it.
Ian.