Advertisement
vatman

Untitled

Mar 13th, 2024
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def crossover(selected_vectors_list, potential_offspring, q):
  2.     # Создаем mutant_vectors, равный по размеру selected_vectors
  3.     mutant_vectors = potential_offspring
  4.  
  5.     # Заменяем случайные q векторов mutant_vectors на соответствующие векторы из selected_vectors
  6.  
  7.     # Для оставшихся векторов
  8.     for l in range(q, len(selected_vectors_list)):
  9.         for j in range(len(selected_vectors_list[l])):
  10.             # Выбираем случайное число
  11.             p = np.random.rand()
  12.             # Вычисляем CR_{l,g}
  13.             CR_lg = 0.9 if p > 0.1 else p
  14.             # Для каждой координаты j в векторе
  15.             if np.random.rand() < 1.0 - CR_lg:
  16.                 mutant_vectors[l, j] = selected_vectors_list[l, j]
  17.  
  18.     return mutant_vectors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement