I'm developing a genetic algorithm to find the optimal connections between points (minimizing distance). Let's assume we have two lists of points:
sources = {s1, s2, s3}
targets = {t1, t2, t3, t4}
I decided to represent the genome as a 2D binary array, where:
This representation implies that each column and each row in the matrix can have at most one 1s.
Now I'm struggling to find a crossover operator which preserves the integrity of the solution.
example:
parent1 :
[0][1][0][0]
[0][0][1][0]
[1][0][0][0]
parent2 :
[0][0][1][0]
[1][0][0][0]
[0][0][0][1]
offspring : ???
Any suggestions?
Keeping your representation and assuming that there are more targets than sources, you could use a row-swapping crossover operator with a built-in repair algorithm.
i
)i-th
row1
to a free (random or near) columnE.g.
Row 0 randomly selected
PARENT 1 PARENT 2
ROW 0 [0][1][0][0] <-crossover-> [0][0][1][0]
ROW 1 [0][0][1][0] [1][0][0][0]
ROW 2 [1][0][0][0] [0][0][0][1]
Offspring before repair
CHILD 1 CHILD 2
[0][0][1][0] [0][1][0][0]
[0][0][1][0] and [1][0][0][0]
[1][0][0][0] [0][0][0][1]
CHILD2
is ok (for a column-swapping operator this doesn't happen); CHILD1
needs the repair operator
CHILD 1
[0][0][X][0]
[0][0][X][0]
[1][0][0][0]
Keep the swapped row (row 0) and change the other conflicting row (row 1). Move the 1 to a free column (column 1 or 3)
CHILD 1
[0][0][1][0]
[0][1][0][0]
[1][0][0][0]
Offspring
CHILD 1 CHILD 2
[0][0][1][0] [0][1][0][0]
[0][1][0][0] and [1][0][0][0]
[1][0][0][0] [0][0][0][1]