1

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
Dan Tang
  • 1,273
  • 2
  • 20
  • 35
  • If you are solving permutation-based problems, I suggest you look at [Random Keys](http://deepblue.lib.umich.edu/bitstream/handle/2027.42/3481/ban1152.0001.001.pdf?sequence=5). It's a really clever way of representing permutations enabling using simple crossover and mutation operators. – zegkljan Sep 23 '14 at 11:06

1 Answers1

1

I found an easy way to produce legitimate offspring in the case of multiple mappings (5 <--> 6 <--> 7).

a) First check if any number outside the substring exchanged ("originalNumber" is contained within the mapping
b) Let the mapped value of "originaNumber" be called "replacement"
c) Check if "replacement" is also contained within the mapping (if it is, this implies that there will be a clash if we set "originalNumber" to "replacement") If it isn't, simply set "originalNumber" to "replacement"
d) Otherwise, find the mapped value of "replacement" and set "originalNumber" to it.
Dan Tang
  • 1,273
  • 2
  • 20
  • 35