Ant Colony Optimization Algorithm (ACO) in detail

I was fortunate enough to go ashore this year. The instructor is in the direction of swarm intelligence control, which will involve some algorithms, so I learned in advance. I
saw a swarm intelligence video of the Chinese Academy of Sciences this morning https://www.bilibili.com/video/BV1KZ4y137sX/?spm_id_from=333.788 .recommend_more_video.3
talked about the ant colony optimization algorithm, so write a blog while the iron is hot to record the learning results! insert image description here
1. Ant colony foraging process

     1.1 Equal length path foraging

     1.2 Foraging with unequal length paths

     1.3 Analysis of foraging process

2. Formalization of ant colony optimization algorithm

3. Solving the traveling salesman problem
     3.1 Introduction to the traveling salesman problem
     3.2 Ant colony optimization solution to the traveling salesman problem
     3.3 Matlab pseudocode

4. Summary of Ant Colony Optimization Algorithm

1. Ant colony foraging process

In real life, everyone should have seen the scene of ants foraging for food. Ant colonies line up in a dark line and carry food in groups. And there is an interesting phenomenon. At the beginning, the ants carried food on more than one route, but in the end, the ants often carried food along the same route.
This group behavior is based on a unique chemical secreted by ants called pheromones. This is left by the ants during their movement, and their function is to carry out group communication in cooperation.

1.1 Equal length path foraging

Suppose a group of ants go out to look for food from A, the food is in B, and there are only two paths C and D, and the lengths of the two paths are equal, as shown in the figure below:

insert image description here
According to the actual situation, it will be found that the number of ants on the two roads is basically the same.

1.2 Foraging with unequal length paths

To change the situation, if the lengths of the two roads are not equal, a group of ants are still going out for food, and there are only roads C and D, and the length of road D is twice the length of road C (assuming this is the case, it is convenient for analysis), schematic diagram as follows:

insert image description here
According to the actual situation, there are ants on road C and road D at the beginning, and after a period of time, you will find that there are fewer and fewer ants on road D, and finally almost all ants carry food along road C.

1.3 Analysis of foraging process

Taking the non-equal length situation as the analysis object, assuming that the ants do not know the previous situation at the beginning, and then send two ants to explore the path, the ants randomly choose a path to start looking for food, remember that this is random!
For the convenience of analysis, the following assumptions are made:
  • ants have equal speed
  • L is equal to 4 unit lengths, each ant crawls a unit length in a unit time
  • Ants leave a unit of "pheromone" every time they pass by

Process 1:
insert image description here
After 8 units of time, the ants on the C road have arrived at the B site, and left a unit of pheromone in each place on the C road, while the ants on the D road have just walked halfway; after another 8 For a unit of time, the ants taking the C route have already obtained food from B and returned to A, while the ants taking the D route have just arrived at B. After another 16 units of time, the ants on road C made another round trip, and the ants on road D also got food and returned to land A.
Since road C made two round trips, the pheromone at each place is 4 units, while road D only made one round trip, so each pheromone is 2 units, and the final pheromone ratio is 2:1.

Process 2:
insert image description here
Continue to search for food. This time, one more ant (total 2) will be sent on road C, while there will still be one ant on road D. After 32 units of time, the 2 ants on road C have gone back and forth twice. , the ants on road D just made a trip, plus the pheromone from last time, each pheromone in road D is 4+4*2=12 units, and the pheromone in each road D is 2+2*1=4 units , the ratio is 3:1.

Process 3: After the above process, this time C route sends 3 ants and D route sends 1 ant. After 32 unit time, the accumulation of pheromones on C route and D route are 24 and 6 respectively, the ratio is 4: 1.

Afterwards, according to the guidance of pheromone, eventually all ants will choose C route and give up D route.

2. Formalization of ant colony optimization algorithm

insert image description here

The following are the five points of the formalization of the ant colony optimization algorithm:

  1. Each ant corresponds to a computational agent
  2. Ants choose locations to move based on probabilities
  3. Leaving "pheromones" on the path passed
  4. "Pheromone" will volatilize over time
  5. The path with a high concentration of "pheromone" will be selected with a higher probability in the subsequent selection

3. Solving the traveling salesman problem

The general ant colony optimization algorithm is suitable for finding the shortest path problem, such as the most common traveling salesman problem. The following will introduce the solution idea of ​​the traveling salesman problem and the realization of the ant colony optimization algorithm by matlab pseudo code.

3.1 Introduction to the traveling salesman problem

Traveling Salesman Problem (TSP: Traveling Salesman Problem)
  • The directed graph of n cities G=(V,E)
    V={1,2,...,n} E={(i,j)|i,j ϵ \epsilonϵ V}
  • The distance between cities is expressed as
    dij d_{ij}dij  is the distance between nodes i and j
  • Objective function
    f ( w ) = ∑ m = 0 ∞ dildil + 1 f(w)=\sum_{m=0}^\infty d_{i_l}d_{i_{l+1}}f(w)=m=0dildil+1
    w = ( i 1 , i 2 , . . . , i n ) w=(i_1,i_2,...,i_n) In=(i1,i2,. . . ,in) is any feasible solution to the TSP problem, wherein + 1 = i 1 i_{n+1}=i_1in+1=i1
    The objective function is the total distance that each city passes through once, and its optimal solution is solved, that is, the total distance is the smallest.
    i 1 , i 2 i_1,i_2i1,i2Represents the first and second arrival cities, dildil + 1 d_{i_l}d_{i_{l+1}}dildil+1That is, the lth and l+1th and the lth and l+1thNo. l and No. l+1 distance between cities

3.2 Ant colony optimization solution to traveling salesman problem

  • First of all, we randomly place m ants in n cities. We need to let the ants move, then we need to calculate the probability that the ants choose the next city to move to. The kth ant located in city i chooses the next city j The probability is:
    insert image description here
    don’t be afraid to see such a formula, just figure out the meaning of the single variable in it.
    τ i , j ( t ) \tau_{i,j}(t)ti,j( t ) means edge( i , j ) (i,j)(i,pheromone concentration on j )
    , j ( t ) = 1 / di , j n_{i,j}(t)=1/d_{i,j}ni,j(t)=1/di,jis the heuristic information α \alpha defined according to the distance
    αβ \betaβ reflects the relative importance of pheromone and heuristic information.
    Explain the composition of this formula:
    First, it can be preliminarily judged that the probability of an ant choosing the next city is directly proportional to pheromone, because the denser the pheromone is, the more likely it is to be selected bigger.
    Secondly, it is the distance between cities. The closer the distance, the greater the chance of being selected, so the sum probability anddi , j d_{i,j}di,jInversely proportional to ni , j ( t ) n_{i,j}(t)ni,j( t ) is proportional, becauseni , j ( t ) = 1 / di , j n_{i,j}(t)=1/d_{i,j}ni,j(t)=1/di,j
    So the molecule appears τ i , j ( t ) \tau_{i,j}(t)ti,j(t) n i , j ( t ) n_{i,j}(t) ni,j( t ) are multiplied, but there is always a weight in the selection factor, so the power is introduced, usingα \alphaαβ \betaβ reflects the relative importance of pheromone and heuristic information.
    The final denominator is the sum of the numerators, and the ratio is the final probabilityP i , j K ( t ) P^K_{i,j}(t)Pi,jK(t)
  • Pheromone Renewal
    Why should pheromone be renewed? From the above formula, it can be observed that the distance between cities is fixed, so if the pheromone remains unchanged, each ant will have the same choice after arriving in the same city. This is not our purpose, so it needs to be updated Probability can only update τ i , j ( t ) \tau_{i,j}(t)ti,j( t ) (pheromone)
    When all the ants have passed through all the cities, the update of pheromone starts, according to the following formula:
    insert image description here

Among them: QQQ is a constant,wk w_kInkIndicates the path traveled by the kth ant in the current iteration, L k L_kLkis the path length, ρ \rhoρ is a constant less than 1, which reflects the volatilization speed of pheromone.
Pheromone update can be simply understood as: at this momentijijThe pheromone concentration on the i j path is equal to the pheromone concentration at the previous moment multiplied by the volatilization speedρ \rhoρ (less than 1 and greater than 0), plus the sum of the pheromone concentrations left by all ants on the path in the previous period, that is,Δ τ i , j \Delta\tau_{i,j}D ti,j
Q / L k Q/L_k Q/LkRepresents the average pheromone left by the kth ant on the path

3.3 matlab pseudocode

Understand the principle of ant colony optimization algorithm, the following is the pseudo code of matlab (excerpted from the video)
ant colony optimization algorithm matlab code implementation, see my next blog

https://blog.csdn.net/HuangChen666/article/details/115913181

insert image description here
The general optimization algorithm uses the number of iterations or the optimal solution to keep a certain number of times as the termination condition.

  • Termination condition
    Set the number of iterations
    Set the number of iterations that the optimal solution remains unchanged continuously

4. Summary of Ant Colony Optimization Algorithm

  • Idea
    Local random search (with P i , j K ( t ) P^K_{i,j}(t)Pi,jK( t ) selection among candidate nodes) and self-enhancement (pheromone update)
    There is no way in the world, and there will be a way if there are more ants walking
  • Disadvantages
    Slow convergence speed (because you need to wait, but the rhythm can be controlled by yourself)
    It is easy to fall into local optimum (it can be improved by increasing the randomness of the jump target)
    It is not suitable for optimization problems where the solution space is continuous (the ant colony optimization algorithm is suitable for discrete problem, particle swarm optimization is suitable for solving continuous space problems, particle swarm optimization will write a blog next time)

Guess you like

Origin blog.csdn.net/HuangChen666/article/details/115827732