Implementation of genetic algorithm