generalize genetic algorithm implementation