Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use this code as a skeleton: PROJECT HEADER GOES HERE import random #DO NOT CHANGE THIS random.seed ( 1

use this code as a skeleton: """
PROJECT HEADER GOES HERE
"""
import random
#DO NOT CHANGE THIS
random.seed(10)
NUM_GENERATIONS =200
NUM_POPULATION =100
PROBABILITY_MUTATION =0.2
PROBABILITY_CROSSOVER =0.8
ALPHABET = 'abcdefghijklmnopqrstuvwxyz '
BANNER ="""
**************************************************************
Welcome to GeneticGuess Sentencer!
This program will attempt to guess a sentence that you input.
Simply input a sentence and the program will attempt to guess it!
**************************************************************
"""
INPUT ="
Would you like to continue? (y/n)"
"
Please input the sentence you would like the program to guess: "
"
Incorrect input. Please try again.
"
"
GeneticGuess results:"
"Generation: "
"I found the sentence early!"
"
Best Individual: "
"
Thank you for using GeneticGuess Sentencer!"
def fitness(target, individual):
"""
DOCSTRING
"""
pass
def five_tournament_selection(population, target):
"""
DOCSTRING
"""
pass
def make_population(target):
"""
DOCSTRING
"""
pass
def mutation(individual):
"""
DOCSTRING
"""
pass
def single_point_crossover(individual1, individual2):
"""
DOCSTRING
"""
pass
def find_best_individual(population, target):
"""
DOCSTRING
"""
pass
def main():
pass
# These two lines allow this program to be imported into other codes
# such as our function tests code allowing other functions to be run
# and tested without 'main' running. However, when this program is
# run alone, 'main' will execute.
# DO NOT CHANGE THESE 2 lines or Do NOT add code to them. Everything
# you add should be in the 'main' function above.
if __name__=='__main__':
main() also, You are not allowed to use advanced data structures such as lists, Tuples, Sets, Dictionaries, Classes,
etc. Use of these prohibited concepts earns zero points for the whole project.5.5 Mutation
Mutation is exactly how it sounds - sometimes genes randomly mutate and one piece of them will change.
In our case, we have a chance of this mutation occurring (PROBABILITY_MUTATION). First, we iterate
through every character over our individual. Then, we randomly choose a number between 0 and 1(using
random. random ()). If our value is less than or equal to PROBABILITY_MUTATION, the letter will be
replaced by a randomly selected letter from the ALPHABET string (use the random. choice () similar to
make_population() function). If the number is above the probability, then we will keep the letter.
5.6 Crossover
Crossover is the same as breeding - you take two individuals and cross them to create offspring (new
individuals). There are a ton of ways to do this, but we will do a single-point crossover. This type works by
first checking that crossover happens. Similar to above, we choose a random number using
random. random () and make sure it is less than or equal to PROBAILITY_CROSSOVER. If it is, we can
do our crossover.
Next, we need a random point to crossover our strings (Use random. randint ()). We want a number
between 1 and the length of our individual. Then, we "cross" the strings at this point. The first half of the
visual is below, with the cross-point set to 3. The first half of individual 1 and last half of individual 2
makes up the new individual 1. The reverse happens for new individual 2, and both are returned.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

22 Employer marketing and branding techniques.

Answered: 1 week ago