Genetic algorithm calculates the shortest distance