(parent1, parent2)
| 13 | |
| 14 | |
| 15 | def crossover(parent1, parent2): |
| 16 | size = len(parent1) |
| 17 | |
| 18 | i, j = random_interval(parent1) |
| 19 | |
| 20 | c1 = parent1[i:j] |
| 21 | c2 = parent2[i:j] |
| 22 | |
| 23 | for k in range(size): |
| 24 | child_pos = (j + k) % size |
| 25 | |
| 26 | if parent2[child_pos] not in c1: |
| 27 | c1.append(parent2[child_pos]) |
| 28 | |
| 29 | if parent1[child_pos] not in c2: |
| 30 | c2.append(parent1[child_pos]) |
| 31 | |
| 32 | c1 = c1[-i:] + c1[:-i] |
| 33 | c2 = c2[-i:] + c2[:-i] |
| 34 | |
| 35 | return c1, c2 |
| 36 | |
| 37 | |
| 38 | def evaluate_fitness(individual): |
no test coverage detected