def swapped_cities(tour): '''generator to create all possible variations where two cities have been swapped''' for i,j in itertools2.all_pairs(len(tour)): if i < j: copy=tour[:] copy[i],copy[j]=tour[j],tour[i] yield copy
def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in itertools2.all_pairs(len(tour)): if i and j and i < j: copy=tour[:] copy[i:j+1]=reversed(tour[i:j+1]) yield copy