Added evolutionary optimization code.

This is very messy and needs a cleanup.