Mutating integer list individuals using mutUniformInt

292 views
Skip to first unread message

Herman Carstens

unread,
Oct 19, 2016, 9:11:49 PM10/19/16
to deap-users
I'm new to DEAP, so this is super-basic a noob question, for which I apologise. I'm trying to create individuals defined as a 10-element list of integers between 0 and 150. As a minimal working example, I modified the OneMax example (code here), using mutUniformInt as the mutation function. I get the error: TypeError: object of type 'int' has no len() (Traceback here). When I use binaries with mutFlipBit, everything is fine.
It seems to me that after the first generation, the individuals are integers rather than lists of integers, and so len(individual) in mutation.py is invalid, although this doesn't make sense to me that this could change. What am I doing wrong?

Any help would be greatly appreciated!
Herman

François-Michel De Rainville

unread,
Oct 19, 2016, 9:23:18 PM10/19/16
to deap-users
The problem is when you register the mutation, since you don't use keyword arguments, the 0 gets confounded with the individual. Change mutation register to:

toolbox.register("mutate", tools.mutUniformInt, low=0, up=150, indpb=0.05)

Regards,
 

--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Herman Carstens

unread,
Oct 20, 2016, 2:19:03 AM10/20/16
to deap-users
Many thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages