Question
please use python language
instruction-
1. Read the code from line 123 to line 137. This is the basically the selection.
Remember how we talk about there are certain things about controlling population?
Please explain how we make sure that the population, when going through a selection, does not shrink over generation. You may simply explain this as comments in a Python file as opposed to in a Word file:.
Note that the code from line 123 to line 137 is divided into two small blocks. Use that as
2. The code we've just examined has one functionality of selection. So, we really should wrap that into one function nanied 'select'. Note that in this file there is no class named
'Population'. So, you should make this function a static method that belongs to the class named 'Individual', or a simple function that resides outside the class named
'Individual'. Please think about what the inputs and output of this function are before you start coding.
Once you have created the function/method, you should
remove the block ot coae from line 123 to line 137.
3. There are two class methods (mutated_genes on line 25, create_gnome on line 35) that belong to the class named 'Individual'. In general, a class method does not apply to an instance but to a class. So, to be perfectly correct, so there should not be 'self in the inputs of any of the two methods just mentioned here. Please modify these two class methods so they confirm to the convention just highlighted. ‹
![122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Otherwise generate new offsprings for new generation
new generation = []
#look over here
s = int((10*POPULATION_SIZE)/100)
new_generation.extend (population [:s])
#look over here
s = int((90*POPULATION_SIZE)/100)
for
in range(s):
parent1 = random.choice (population [:50])
parent2 = random.choice (population [:50])
child = parent1.mate (parent2)
new_generation.append(child)
population = new_generation
-](https://content.bartleby.com/qna-images/question/5b37d6b2-56cf-4f70-90ec-bf3a066c9482/12fb8ff6-2270-4508-8fc9-77e50d2f9fac/sfgqlc_thumbnail.jpeg)
Transcribed Image Text:122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Otherwise generate new offsprings for new generation
new generation = []
#look over here
s = int((10*POPULATION_SIZE)/100)
new_generation.extend (population [:s])
#look over here
s = int((90*POPULATION_SIZE)/100)
for
in range(s):
parent1 = random.choice (population [:50])
parent2 = random.choice (population [:50])
child = parent1.mate (parent2)
new_generation.append(child)
population = new_generation
-

Transcribed Image Text:25
26
27
28
29
30
31
32
33
34
35
36
37
38
def mutated genes (self):
I
create random genes for mutation
global GENES
#Return a random element from a list or a sequence.
gene= random. choice (GENES)
return gene
@classmethod
def create_gnome (self):
11
create chromosome or string of genes
11.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

Knowledge Booster
Similar questions
- Using the Python language answer the following questions below. Please tell me what program you use if it is IDLE or Atom or a python website please provide the website you use.arrow_forwardyour goal is to modify your assignment 6 program to allow the user to pick up a random item and display a sorted list of the contents of the knap sack. note: if you use the built in c++, the most you can make on this assignment is 4 out of 10. you are expected to right your own sort based on one of the algorithms covered in class. your program should have the following: • the name of the program should be assignment 6. • 3 comment lines (description of the program, author, and date). • modify your assignment 5 program to do the following: o display a menu (use a switch statement to implement the menu) of actions ▪ attack: • for now, just display that the user chose to attack ▪ pick up item: • randomly add one of 6 items to an array named knapsack o you get to choose the item names • display which item the user picked up ▪ add an option to the main switch statement: display knap sack contents • the contents of the knap sack must be sorted The knapsack items are bananas, lays,…arrow_forwardMUST BE WRITTEN IN C++ Write a program so that user can use it to compute and display various statistics for a list of at least 3 values and up to 20 positive real values. The main objectives of this project are to work with menu, arrays, file input, and modules/functions. A menu is available and user can select one of the 4 options from the menu. The program will continue until option 4 is selected. For option 1, process a predefined array in the code with 3 values (73.3 83.4 58.0). User will be able to input an array from the keyboard with a sentinel loop with option 2. Use the following values (73.3 83.4 58.0 11.9 25.1 69.9 45.7 95.0 44.4)as one of your test cases (use-1.0 as a sentinel value). When option 3 is selected, input data from a text file. Use the given p2input.txt Download p2input.txt as a test case. The values in the file are shown below. 73.399.0 83.4 58.0 25.1 69.0 11.9 95.0 74.8 55.0 43.5 47.4 95.6 58.9 52.6 37.7 93.8 19.9 23.9 77.2 You can assume that the user will…arrow_forward
- Can you use Python programming language to to this question? Thanksarrow_forwardI have to create a program using python so that when the user inputs a state, it outputs the given info such as capital, state bird, and rank. I have most of it coded, but when I run the program I get an invalid syntax error, I'll attach a screenshot of what I have so far. I'll also attach what it's suppose to look like. Here are the instructions: Your program will initialize lists to store information about the states. You should have one list for the names of the states, one list for the names of the capitals, one list for the names of the state birds per state, and one list for the order number the state joined the union. Alternatively, you can use a db list of lists as demonstrated in the exercises in the book to store the information in one structure or dictionaries. Next ask the user to enter a name of a state. Find the index of that name. Use that index to report back to the user the name of the capital, state bird, and the order the state joined the union.arrow_forwardMust show it in Python: Please show step by step with comments. Please show it in simplest form. Please don't use any functions Please don't use any def func ()arrow_forward
- I need to solve this in C++ code When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by subtracting the smallest value from all the values. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 30 50 10 70 65 the output is: 20 40 0 60 55 For coding simplicity, follow every output value by a space, even the last one. Your program must define and use the following function:int GetMinimumInt(vector<int> listInts) Note: This is a lab from a previous chapter that now requires the use of a function.arrow_forwardFor Loop in Javaarrow_forwardCreate a Python programme that reads a string list from the user and stores it in a dynamic array. The user should be able to insert as many pieces as they want and remove them as needed. Exemplify each sentence, please.arrow_forward
- Looking for python guidance for the code comments. Write a program that replaces words in a sentence. The input begins with word replacement pairs (original and replacement). The next line of input is the sentence where any word on the original list is replaced. Ex: If the input is: automobile car manufacturer maker children kids The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. the output is: The car maker recommends car seats for kids if the car doesn't already have one. Looking for python guidance for the code comments.arrow_forwardInstructions: I need Python help. The problem I am trying to figure out so that when we work a similar problem in class I can do my assignment. Tonights assignment is a participation thing, Friday I need to do a similar assignment in class for a grade. Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements: Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44…arrow_forward
arrow_back_ios
arrow_forward_ios