This isn't homework, purely for my side project.
I'm implementing the Permutation Crossover Operator for genetic algorithm (solving travelling salesman, where each number represents a city index) and I'm having some problem with the boundary case when there isn't a 1-for-1 mapping.
Consider the two genomes below, and assuming the final two entries are switched. Thus, 5 is mapped to 6, and 6 is mapped to 7. So what happens when I hit a number 6 - should I change it to 5 or 7, and this can lead to an invalid tour where a city is visited twice.
//initial case
GenomeA: [ 2, 3, 1, 4, 0, 7, 5, 6 ]
GenomeB: [ 1, 2, 0, 3, 4, 5, 6, 7 ]
5 <--> 6
6 <--> 7
//after mapping
GenomeA: [ 2, 3, 1, 4, 0, 6, 6, 7 ]
GenomeB: [ 1, 2, 0, 3, 4, 6, 5, 6 ]
Should I randomly select another number if a number is already mapped? Or should I not switchover any numbers that already has been mapped?
For instance,
a) Evaluate first set of numbers (5 <--> 6)
b) Since 5 has not been mapped, map 5 to 6 and vice versa
c) Evaluate second set of numbers (6 <--> 7)
d) Since 6 is already mapped to 7, ignore this set of numbers