Introduction to genetic algorithm
Introduction
Genetic algorithm is an artificial intelligence (AI) algorithm used to
solve problems that can't be solved with a mathematic formula.
It is inspired by the theory of evolution which uses genes and chromosomes to evolve. The generations that evolve are your solutions to the problem. To understand how this algorithm works, it is good
if you have some knowledge about evolution and DNA and how the 'mom' and 'dad' pass their DNA to their children.
Values
Genes: A string of binary numbers (0 and 1).
Chromosomes: A group of genes.
Population/Generation: A group of chromosomes.
To setup your values, you must first look at your problem and find what are the values required. Let's take a simple example, we want to find what equation gives us the number 30. What we need here
are numbers and operators and let's say we want to have an equation with 3 numbers in it. We would setup our genes like this (note that you can give them the value you want):
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = +
1011 = -
1100 = *
1101 = /
These are our genes. To generate a chromosome, we need to choose random genes and put them together. When you generate a chromosome, you can make it completely random which could give something like
"1+-+3" or make it generate valid equation from the beginning like "1+2+3". Now, we need 5 genes (3 numbers + 2 operators), so we would have a chromosome like:
00111100011110101001 <- which is 3 * 7 + 9
You can see the genes as values in the DNA, every pair of bits have their own value. We generate a population using the same function. The population can have as many chromosomes as you want. In this
example, you can generate 100 chromosomes, it would be enough. To save your chromosomes you can create a string and consider every 0 and 1 as a character, or save it in an array of short (8 bits)
/int (32 bits depending on your OS) which will take less memory.
Analysis
Once you have your generation, loop through every generated chromosomes and see if one of them gives you the solution you seek (in this case, 30). For every chromosome, set a fitness score which is a
value that specifies how far the chromosome is to the solution. An example of a fitness score for our problem would be:
01011010011110110111 <- we will calculate the fitness score of this chromosome, which is 5 + 7 - 7
5 + 7 - 7 = 5
1/(30-5) = 0.04 <- this is the fitness score of our chromosome, in our case, the closer it is to 1, the closer it is to the solution.
If you don't find the solution, you need to generate a new generation by creating babies.
Generate New Population
There are many ways to generate a new population. We will use the one called 'Crossover Rate'. First you need to choose 2 chromosomes at random (this is where the fitness score comes handy, if you
match 2 chromosomes that are near your solution, it increases the chance to find the solution) and generate a random number between 1 and the length of your chromosomes (in this case, 20). Take the 2
chromosomes and switch each parts:
1. 00111100 011110101001
2. 01011010 011110110111
---------------------------------
1. 00111100 011110110111
2. 01011010 011110101001
You can see here the random number was 8 and we switched every parts (before and after 8) and created 2 babies using their parents' DNA. Do the same until you made babies with all the chromosomes.
You will now have a population of 200 chromosomes.
You can set a mutation rate for every gene, which should be at a very low level, such as 1%. If a gene mutates, you need to change it to a random gene, which can go better or worse.
Invalid Chromosomes
You can either keep them or kill them. I prefer to kill them as when they are invalid they become very useless, but you can make a function that fixes an invalid chromosome.
Conclusion
This is the very basic of the algorithm. Using this algo, you can solve many problems such as where can we fit the biggest circle in a given GUI or how many boxes can fit in a containers. It is an
algo that you must program yourself to understand it well, so open your IDE and start coding!
Tags: Algorithms, genetic algorithm, AI
Comments
Avinash Singh, May 3, 2010 7:03 pm
NICE WORK DEAR.......................... ............
Account deleted, Jun 16, 2010 12:57 am
If you want to save some time and start working with GA, I suggest using the Python package PyEvolve http://pyevolve.sourceforge.ne t/
Andre Vesta, Jun 17, 2010 5:33 pm
Great work. Found similar research work in International Journal of Computer Applications at http://www.ijcaonline.org/arch ives/volume2/number3/651-908
Ga Tsp, Jan 10, 2011 7:07 am
Can anyone suggest me as how to generate initial population for finding the shortest collision free path by making use of a genetic algorithm?
Andrew Webb, Jun 29, 2011 9:52 am
Interesting article. I have recently been investigating the use of genetic algorithms as a means of optimizing routes in telecommunications networks.
/2011/06/genetic-algorithm-bas ed-routing.html
Feel free to try the application and see what you think:
http://andyuk2010.blogspot.com
Add New Comment
New to ResearchGate?
Follow updates in your field and connect with other researchers.Create Free Account »Already a member? Log in here.About this author
Mehran Parhebafieh
Author's blog
Categories
Followers of this author
Hashim Ali
Università degli Studi di Milano-Bi...
Hoda Javadi
Rajaei Cardiovascular Medical and R...
Arvind Kumar
Allahabad University
Anujit Khutia
Self
Hessam Parchebafieh
Gnanajeyaraman Rajaram
Kongunadu college of engineering &...
Sudhasarath Somasundaram
BSA university
Bishwo Bhattarai
St. Xavier's College
Our authors
Topics
Agricultural Science
Philosophy
Political Science
Social Science
Literature
Geoscience
Education
Psychology
Medicine
History
Biology
Other
Space Science
Computer Science
Chemistry
Mathematics
Law
Physics