Genetic Algorithm from student 1st grade.
image is from freepik
The subject that when hear makes you think as “How can you combine genetic and algorithm each other?”. Yes, i thought exactly same. When i was in first programming class, teacher started to ask about biology. I was thought “Are we in biology class?”. He asked like “A child can be made with 2+ parents, can’t it?”. What.. How? You think it is impossible. But here is f*cking computer world. Everything may be possible. He asked a few weird questions then showed our final examination PDF. In PDF, genetic algorithm is explained how does it work.
Example:
Let’s think that a child exist with just 4 qualifications. Those are hair color, eye color, height and gender. We should determine qualifications of child we want. And every generation can keep max 5 children. Every children have fitness score. What is fitness score? Let’s say we have a child who has brown hair, black eyes, tall and female. The child we want should have brown hair, blue eyes, tall and male. Which qualifications are same? Hair color and height. So fitness score of child’s who have brown hair, black eyes, tall and female is 2. Only random binary combinations of 3 person who most have fitness score(healthy) will be chosen to breed in every generation. A child can take gene from mother with 45% possibility and father with 45% possibility. They will make 5 children -so they make a generation- then they will not able to breed anymore. We do it because we will be more close to child we want. Just think, if you want a brown hair child, you should choose parents who have brown hair, right? By the way, there is mutation factor. Because mutation is in life, right? Let’s say possibility of mutation factor is 10%. When you get parents who both of them have brown hair breed you can have pink hair child. In first generation there can be 2 parent with determined genes or you can make random 5 children from gene pool. That’s up to you.
Everything is ready! So let’s begin.
Color gene pool={a,b,c,d,e,f,g} (Every word presents a color)
Gender gene pool={F,M} (F=Female, M=Male)
Height gene pool={S,M,T} (S=Short,M=Medium,T=Tall)
Definition a Chromosome:
a c S F | This is a example person (chromosome)
First gene presents hair color. Second gene presents eye color.Third gene presents height. 4th gene presents gender.
Every gene only can take gene from own gene pool. First and second gene can’t be F,M,S,M,T.
I’m gonna select specific mother and father.
Mother = d f S F
Father = a d T M
They make 5 children.
Second generation= { a f S M , d f T M , c a M F , a d M F , g b S F } (Mutations is remarked by bold.)
Then 2 of person most have fitness score are gonna make 5 children and they will make third generation. It will be continue again and again until we found the child we want.
When we found the child we want everything is gonna stop. We Achived!
I coded genetic algorithm in C programming language. But you can code in different languages too.
I hope it will be helpful for you :)