Skip to content

Instantly share code, notes, and snippets.

@johntheo
Created March 22, 2018 15:26
Show Gist options
  • Save johntheo/28670affa2a09c55550c14fd042f7657 to your computer and use it in GitHub Desktop.
Save johntheo/28670affa2a09c55550c14fd042f7657 to your computer and use it in GitHub Desktop.
# Definindo a estrutura do indivíduo
IND_SIZE = 20 # Tamanho do individuo - 10 para cada gene
GENES = 2
creator.create("Individual", list, fitness=creator.FitnessMax)
# funcao para gerar o gene com alelos 0 ou 1 randomicamente uniforme
toolbox.register("attr_bool", random.randint, 0, 1)
# funcao para gerar o indivíduo (nome, forma de gerar, Estrutura, funcao geradora, tamanho)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, n=IND_SIZE)
# funcao para gerar a populacao
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment