Created
October 30, 2014 19:56
-
-
Save cmd-ntrf/0aed61aad6dd68ca4579 to your computer and use it in GitHub Desktop.
Add method to individual in DEAP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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