Program simplification

43 views
Skip to first unread message

Ian Clarke

unread,
Jun 9, 2011, 1:56:08 PM6/9/11
to epo...@googlegroups.com
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.

Ian Clarke

unread,
Jun 9, 2011, 1:58:08 PM6/9/11
to epo...@googlegroups.com
Ugh, Google Groups screwed up my formatting, sorry about that.

Ian.

Tom Castle

unread,
Jun 9, 2011, 5:49:32 PM6/9/11
to EpochX
Ian,

Thanks for posting this.
Reply all
Reply to author
Forward
0 new messages