Editing
Code Guide
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==GA Module== The GA module contains all the functions required to run the GA as we have for this project. The functions are: generate_parent: Generates a list of specified length containing randomly generated values between 0 and 1. This is a real valued parent that can be used in a fitness function to determine a fitness as required. It is a simple matter to instead make discrete parents if that is what is required. generate_population: Generates a population of parents using the generate_parent function. This population can be any integer value. mutate: This function traverses a parent and mutates genes based on a mutation probability. A mutation involves replacing the gene with a randomly generated new gene. In this case, the genes are real valued in the range [0, 1], but could be modified to discrete as required. crossover: The crossover function takes a population as its main input and outputs a new population of the same size that has undergone the crossover procedure. Crossover requires pairs of parents and each parent is only considered once per generation and so the population size must be divisible by two to ensure all parents are considered. An error will be raised if the population is not divisible by two. tournament_selection: This function takes a population then pairs the parents up at random and compares the fitness of each pair. The parent with the better fitness is kept while the other parent is discarded. This function outputs a population that is half the size of the input population and so should generally be run twice in each generation to ensure population size is consistent throughout the simulation. As the function pairs up parents, the population size must again be divisible by two. fitness: This is the key user determined function for the GA. This function will change depending on the aims, constraints and requirements of each simulation. The function must utilise a parent to determine its output or else the GA will essentially be a fancy random number generator. main: This function puts all the other functions together to allow simple operation of the GA. The steps of the main function are described generally in figure 4.
Summary:
Please note that all contributions to Derek may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Derek:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information