This is the genetic algorithm.

Source: Internet
Author: User

This is the genetic algorithm.

This article attempts to introduce genetic algorithms through several concise images.

Background

When some problems do not have a deterministic optimal solution method, or the optimal solution method is 1-B for a long period of time, we have to begin to consider other ways.

For example, the traveling salesman problem:

The traveling salesman wants to sell goods in many cities. In order to save time, he can only go to the city once and finally return to the original city because his wife does not allow him to leave for too long.
How is it more cost-effective?

The city distribution may be like the following:

The travel Chamber wants to arrange all the city routes in half and then see which route is the shortest.

Well, if there are only 3 to 5 cities to be visited by the traveling salesman, it is okay to say that if the traveling salesman's business is too good, it may be necessary to go to dozens of cities, then this method will not work.

Why?

O (1) <O (logN) <O (N) <O (N2) <O (N !)

If you are familiar with the time complexity, you must understand what I am talking about, do not believe it, try the 34 factorial to calculate what it is, kiss, if the wallet has so much money that should be good.

Fortunately, Darwin summed up an uncertain truth in the natural world, that is, biology completes evolution through the natural selection process of survival of the fittest.

This process looks like a bunch of random and uncertain minor changes, so that the definite and significant changes to the advantage continue.

Who is strong, who has the right to speak, resources should belong to this strong affinity, and the weak Master is eventually drowned in the evolution process because it cannot resist disasters and tests.

Genetic Algorithm

Since all life can evolve, and all the living creatures are born and killed, there is nothing complicated to solve the point computing problem.

As a result, we want to use quantifiable mathematical methods to express this evolutionary process, and then let computers simulate natural selection and population evolution to see what kind of high-quality individuals (solutions) will appear.

Maybe you cannot get an optimal solution, but the traveling salesman may have to accept a similar solution:

Well, let's get to know the so-called genetic algorithm (genetic algorithms ).

Genetic algorithms are an evolutionary algorithm that everyone understands.
The change of life lies in the changes of genes. What is genes? We don't care about real biological genes. After all, we are not discussing reproductive issues here:

IfGene)As an encoded element, an array or list is used to store a group of genes.Chromosome (chromosome).

/***** Gene */private class Gene {/***** encoding */int value;/***** equigenes (encoded value) */Integer Allele ;} public interface IChromosome {public Genes [];}

Well, with this expression basis, we can describe the evolutionary process well.
To simplify the problem and emphasize its nature, we simplified the population description:

This figure tells us

The population contains several individuals (chromosomes). The population grows, the number of individuals increases, and the number of high-quality individuals increases.

What is the potential of our solutions?

This figure does not tell us the details about evolution. Obviously, we need to understand what evolution is.

You may think that I lied to you, but in fact, evolution only has three dimensions: select, crossover, and mutate ).

Let's continue to understand the evolution.

Select

Select is the choice, why, because the survival of the fittest:

Individuals in the population cannot be idle and have to go to school to raise their wives. Therefore, they need to pass various examinations and assessments.
If you pass the examination, you will be given a higher salary or will leave the house.
The figure above tells us that the choice is for the population operation, and the goal is to ensure the quality of the next generation of population is better.

Crossover

So how are differences between individuals? Let's start with the individual's mom and dad. Aren't they all engaged in high quality genetic artificial D pregnancy? Well, the individual difference is due to reproduction.

People will say, Wow, this kid looks like a flower!
In fact, it may be that the child's mother is very beautiful and excellent genes can be transferred.
Some people may say, oh, the child's eyes are as dark as his father's, which means his father may be a code farmer, and the child has unfortunately inherited his father's...

The following describes the unsuitable links for children:

As for the details of passion, this article does not intend to discuss specific cross-cutting algorithms, but it should be explained:

Crossover is to Crossover the two parent groups to form one or more new gene sequences or chromosomes.
Crossover can be random, but it is best to avoid meaningless crossover.
The purpose of crossover is to increase significant changes in the individual and integrate the superior genes of the parent.
Crossover is the most important step in genetic algorithms.

Mutation

Maybe a child is a rich second generation, maybe a child is an official second generation, but it may be an ordinary child. Unfortunately, he prefers his father, his childish mind thinks that his father is really cool, so he thinks that coannong is cool.

Different, this child prefers to compile ~
This is his personality, and no one can stop it. People will say that this child is not like his mother at all.
This kind of personality is incomplete, but the genetic reasons may be:

Variations are not cross-important, and may produce extremely bad variations.
However, mutation is a supplement and improvement to crossover, and also a risky innovation.

Traveling Salesman

Now, let's go back to the traveling salesman problem. If we number the city, for example 1, 2, 3,..., N , Then a route is like this:

3, 10, 2, 1,..., 20, 3
The number of each city is a gene, and the city arrangement is a chromosome (gene sequence ).

Then, after several evolution, the high-quality chromosomes can be selected, and the traveling salesman gets a travel route that is close to the shortest:

This is the genetic algorithm.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.