Notice that no verification is done on the validity of the newly created path. The fact that the population may contain invalid solutions implies a slight modification to the genetic algorithm: when the maximum number of generations is reached an additional test has to be done: the path to be returned as a result must be the shortest valid path within the population.