how to work with strings and integers as bit strings in python?

Posted by Manuel on Stack Overflow See other posts from Stack Overflow or by Manuel
Published on 2010-02-15T05:12:02Z Indexed on 2010/05/17 4:20 UTC
Read the original article Hit count: 369

Hello! I'm developing a Genetic Algorithm in python were chromosomes are composed of strings and integers. To apply the genetic operations, I want to convert these groups of integers and strings into bit strings.

For example, if one chromosome is:

["Hello", 4, "anotherString"]

I'd like it to become something like:

0100100100101001010011110011

(this is not actual translation). So... How can I do this? Chromosomes will contain the same amount of strings and integers, but this numbers can vary from one algorithm run to another.

To be clear, what I want to obtain is the bit representation of each element in the chromosome concatenated.

If you think this would not be the best way to apply genetic operators (such as mutation and simple crossover) just tell me! I'm open to new ideas.

Thanks a lot! Manuel

© Stack Overflow or respective owner

Related posts about genetic-algorithm

Related posts about python