Skip to content

Instantly share code, notes, and snippets.

@cmd-ntrf
Created October 30, 2014 19:56
Show Gist options
  • Save cmd-ntrf/0aed61aad6dd68ca4579 to your computer and use it in GitHub Desktop.
Save cmd-ntrf/0aed61aad6dd68ca4579 to your computer and use it in GitHub Desktop.
Add method to individual in DEAP
from deap import base
from deap import creator
def hash_ind_list(self):
return hash(tuple(self))
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
creator.create("Individual", list, fitness=creator.FitnessMin, __hash__=hash_ind_list)
ind1 = creator.Individual([1,2,3,4,5])
ind2 = creator.Individual([1,2,3,4,5])
ind3 = creator.Individual([1,3,4,5,6])
pop = set([ind1, ind2, ind3])
print(pop)
print(len(pop))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment