MCPcopy Index your code
hub / github.com/Hrishikesh332/Gen-TSP / crossover

Function crossover

streamlit_solver.py:15–35  ·  view source on GitHub ↗
(parent1, parent2)

Source from the content-addressed store, hash-verified

13
14
15def 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
38def evaluate_fitness(individual):

Callers 1

breedFunction · 0.85

Calls 1

random_intervalFunction · 0.90

Tested by

no test coverage detected