Generic implementation of a genetic algorithm.