Task 1.1: Randomly generate initial population of strings
We are going to write a function buildPopulation that will initialize 200 random strings (all the same
length as the target phrase) containing upper/lowercase letters and spaces. You should store these population members in a single string array, which your function should output. In this function, you should also
define the population size as a variable, an important quantity that we will come back to often in this
To generate random characters, we simply have to generate integers which correspond to text characters in
the ASCII table (more informaition: link), and use the char() typecast to turn them into characters.
Following the biology analogy, our population (string array) now contains organisms (strings) with DNA
bits (individual characters) that were randomly generated. We are going to try and match that DNA to the
target pnhrase’s DNA.
Task 1.2: Calculate the fitness of each member in the population
In this example, we will simply define fitness as how many characters the current member of the population
has correct when compared to our target phrase. For example, if our target phrase is ‘Hello World’, and we
are assessing the fitness of the string ‘qK lfdRoPLd’, we would compare it as follows:
Target: H e l l o W o r l d
Test string: q k l f d R o P L d
DNA match: 0 0 0 1 0 0 0 1 0 0 1
The test string would have a fitness score of 3, due to having 3 DNA matches to the target phrase. A phrase
with 100% fitness (i.e., the phrase ‘Hello World’) would have a fitness score of 11 in this example.
You can see that with a longer target string, the maximum possible fitness goes up. Furthermore, having a
fitness of 3 in a phrase like ‘Hello World’ is much less significant to having a fitness of 3 in a shorter phrase
like ‘Hello’. Therefore, it is going to be more useful for us to look at the string’s fitness as a percentage,
where 0 has no matches, and 1 is completely matching (also known as normalizing the fitness score). In
this case the test string has a fitness of approximately 0.273, or 27.3%.
We will now write a function calculateFitness which calculates the fitness of the entire population in the
manner discussed above.
1.) What do th income effect, the substitution effect, and diminishing marginal utility have in common?A. All are required to explain the utility-maximizing positionof co...May 29 2018
Question: Marketing teams brainstorm together and collect information from widely varying sources in the process of developing products and strategic marketing plans. For...Nov 09 2017
There are three different approaches to safety management - organizational, engineering, and individual. Discuss the focus of each of these approaches, giving examples o...Dec 16 2019
According to monetarism, an increase in the money supply will lead to a rise in real GDP in the long run. Do you agree or disagree with this statement? Explain your answer.May 05 2021
Your landscaping company can lease a truck for $8,200 a year for 5 years. It can instead buy the truck for $35,000. The truck will be valueless after 5 years.a.What is th...May 13 2020
Based on your understanding of capital budgeting, how does capital budgeting relate to the concept of the time value of money? How does understanding capital budgeting ai...Aug 25 2020
Cannibal Hospital Corporation is considering buying a small, local hospital for $125 (all dollars in millions). If the firm makes the investment (today), its cash flows w...Aug 29 2020
Why is the management of user profiles an important aspect of a security policy? How does network authentication work and why is it useful? What is social engineering? Wh...May 07 2020
In each of the following situations, explain how government intervention could improve society’s welfare by changing people’s incentives. In what sense is the market goin...Jun 08 2018
difference between plant layout and plant location. >Aug 04 2020