Advertisement
11eimilia11

vsfBEM

Feb 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # seleção por torneio gera aleatoriamente dois
  2. # pais e retorna o melhor deles
  3. def tournament_selection(acuracias, cromossomos):
  4.     melhor = []
  5.     aux = []
  6.     for i in range(0,2):
  7.         rand = randint(0,20)
  8.         if acuracias[rand] == 0:
  9.             rand = randint(0,20)
  10.         elif acuracias[rand] != 0:
  11.             aux.append(rand)
  12.  
  13.     if acuracias[aux[0]] > acuracias[aux[1]]:
  14.         melhor.append(cromossomos[aux[0]])
  15.         cromossomos[aux[0]] = 0
  16.     elif acuracias[aux[1]] > acuracias[aux[0]]:
  17.         melhor.append(cromossomos[aux[1]])
  18.         cromossomos[aux[0]] = 0
  19.  
  20.     return melhor, cromossomos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement