Honors Lab 1 solution

The ProblemA genetic algorithm consists of a population of individuals, where each individual is a bit string (i.e., a list of 0’s and 1’s). For example, 0010101010 could be a genetic algorithm individual. A fitness function interprets an individual and assigns it a fitness that represents how good or bad the solution is. One simple fitness function is counting ones, where an individual’s fitness is simply the number of ones in the bit string. For example, the bit string 011100 would have a fitness of 3. Your Task 1. Create one random individual. The individual should be a list of length 100. Each bit should be assigned randomly to a 0 or a 1. (Hint: Check out the random package for python.) 2. Write a counting ones fitness function. Your function should accept an individual as input and return the number of ones as output. 1
Powered by