[Path Planning] Path Planning of Artificial Bee Colony Algorithm [Matlab 037]

1. Introduction

Honeybees Collect Honey Bees in
nature can always find high-quality nectar sources with extremely high efficiency in any environment, and can adapt to changes in the environment. The nectar collection system of a bee colony consists of three parts: nectar source, hired bee, and non-employed bee. The pros and cons of a nectar source have many factors, such as the amount of nectar from the nectar source, the distance from the hive, the difficulty of extraction, etc.; employment Bees contact specific nectar sources and inform their peers of nectar source information in a certain probability form; the duty of non-employed bees is to find nectar sources to be mined. They are divided into follower bees and scout bees. Follower bees are waiting in the hive and scout bees are detecting A new source of nectar around the hive. When honeybees collect nectar, some of the bees in the hive act as scout bees and constantly and randomly look for nectar sources near the hive. If a nectar source with nectar content exceeding a certain threshold is found, the scout bee becomes a hired bee and starts collecting honey. After the honey is finished, flies back to the hive and dances to tell the follow peak. Swing dance is a basic form of information exchange between bees. It conveys important information about the nectar source around the hive, such as the direction of the nectar source and the distance from the nest. Follow Peak uses this information to accurately evaluate the quality of the nectar source around the hive. After the hired bees dance the swing dance, they will return to the original nectar source with some follower bees in the hive to collect nectar. The number of follower bees depends on the quality of the nectar source. In this way, the bee colony can quickly and efficiently find the nectar source with the highest amount of nectar.
Insert picture description here
The swarm intelligence of bees collecting nectar is realized through the exchange, conversion and collaboration between different roles. The specific process of collecting honey is shown in the figure. In the initial stage, bees appeared in the form of scout bees and did not know anything about the nectar source around the hive. Due to the different internal motivations and external conditions of bees, scout bees had two choices: ① Become a hired bee and start around the hive Randomly search for nectar sources, the route ② in the picture becomes the following peak, after observing the swing dance, start searching for nectar sources, as shown in the route. Suppose that two sources of nectar are found. After finding the source of nectar, the investigator bee becomes a hired bee. The hired bee uses its own attributes to remember the location of the nectar source and immediately invests in collecting honey. After the nectar collection is completed, the bees return to the hive with a full load of nectar, and unload the nectar to the unloading room. After unloading is complete, there are three possible behaviors for hiring bees to abandon the nectar source that they have found that the amount of nectar is not high, and become an unconstrained non Hire bees, follow the route in the picture; ②Dance in the recruitment area, recruit some to stay in the hive to follow the peak, and lead them back to the route of the discovered nectar source again; ③Do not recruit other bees, continue to return to the original The source of nectar to collect nectar is the route in the picture. In real life, not all bees collect nectar immediately at the beginning. In addition, most bees will choose to return to the recruitment area and dance to recruit more bees to collect nectar.
Algorithm model The
artificial bee colony algorithm is a new type of intelligent optimization algorithm proposed by simulating the honey-gathering process of bees. It is also composed of food sources, hired bees and non-employed bees.
Food sources: Food sources are nectar sources. In any optimization problem, the feasible solution of the problem is given in a certain form. In the artificial bee colony algorithm, the food source is the feasible solution to the optimization problem, which is the basic object to be dealt with in the artificial bee colony algorithm. The quality of the food source can be solved by evaluating the fitness of the nectar of the nectar source.
Hiring bees: Hiring bees means that the lead bee corresponds to the position of the food source. A food source corresponds to a lead bee. In the artificial bee colony algorithm, the number of food sources is equal to the number of lead bees; the task of the lead bee is to discover the food source information and share it with the follower bees with a certain probability; the calculation of the probability is the choice in the artificial bee colony algorithm Strategy is generally calculated by roulette based on fitness value.
Non-hired bees: Non-hired bees include follow bees and scout bees. Follow bees select food sources in the recruitment area of ​​the hive based on the nectar source information provided by the lead bees, while the scout bees look for new food sources near the hive. In the artificial bee colony algorithm, the follower bee searches for a new food source near the food source and makes a greedy choice based on the information transmitted by the leading bee. If a food source has not been renewed after this time, the lead bee becomes a scout bee, and the scout bee looks for a new food source to replace the original food source.
Insert picture description here
Algorithmic search process
Insert picture description here
Artificial bee colony algorithm divides artificial bee colony into three types: lead bee, follow bee and scout bee. In each search process, lead bee and follow bee mine the food source one after another, that is, find the optimal solution. The bee observes whether it falls into a local optimum, and if it falls into a local optimum, it randomly searches for other possible food sources. Each food source represents a possible solution to the problem, and the amount of nectar from the food source corresponds to the quality of the corresponding solution (fitness value fiti).
1. In the search process of artificial bee colony algorithm, initialization is first required, which includes determining the population number, the maximum number of iterations MCN, the control parameter limit and determining the search space that is the range of the solution, and the initial solution xi(i= 1,2,3,...,SN), SN is the number of food sources, each solution xi is a D-dimensional vector, and D is the dimensionality of the problem. After initialization, the entire population will repeat the search process of the lead bee, follow bee and scout bee until the maximum number of iterations MCN or error allowable value ε is reached.
2. At the beginning of the search process, each leading bee generates a new solution, namely a new food source, by formula (2-3),
vij=xij+Φij(xij-xkj) (2-3)
where k∈ ﹛1 ,2,…,SN﹜,j∈{1,2,…,D}, and k ≠i; Φij is a random number between [-1,1]. Calculate the fiti of the new solution and evaluate it. If the fiti of the new solution is better than the old solution, lead the bee to remember the new solution and forget the old solution. Otherwise, it will retain the old solution.
3. After all leading bees have completed the search process, leading bees will dance in the recruitment area to share the solution information and information with follow bees. The follower bee calculates the selection probability of each solution according to the formula,
pi=fiti/∑k=1SNfitk. (2-4)
Then a number is randomly generated in the interval [-1,1]. If the probability value of the solution is greater than the random number, a new solution is generated following the bee-by equation (2-3), and the fiti of the new solution is checked. If the new solution If the fiti is better than before, the following bee will remember the new solution and forget the old solution; otherwise, it will keep the old solution.
4. After all follower bees complete the search process, if a solution has not been further updated after limit cycles, then the solution is considered to fall into a local optimum, and the food source will be discarded. Assuming that the food source xi is discarded, the leading bee corresponding to this food source turns into a detection bee. The scout bee generates a new food source to replace it by the formula (2-5).

                                                             xij=xminj+rand(0,1)(xmaxj-xminj)          (2-5)

Where j∈{1,2...,D}. Then return to lead the bee search process, and start to repeat the cycle.
5. The food source quality of artificial bee colony algorithm is generally the larger the better, that is, the larger the fitness value, the better, and corresponding to the problem to be optimized, it needs to be considered in two cases: the minimum problem and the maximum problem. Let fi be the objective function of the optimization problem, so when optimizing the minimum problem, the fitness function is a modification of fi, which is generally expressed by equation (2-6); if the maximum problem is optimized, the fitness function is the objective function.

fiti={1+abs(fi) fi>=01/1+fi fi>0 (2-6) When the
artificial bee colony algorithm evaluates food sources, it generally makes greedy selection according to formula (2-7).

vi={xi ​​fit(xi)<=fit(vi)vi fit(vi)>fit(xi) (2-7) The
artificial bee colony algorithm is to find the optimal food source or optimal solution through circular search.
Algorithm steps The
specific implementation steps of the artificial bee colony algorithm:
Step 1: Initialize the population: initialize each parameter, the total number of bee colonies SN, the number of times the food source is collected, the maximum number of iterations MCN and the control parameter limit, determine the problem search range, and within the search range Randomly generate the initial solution xi(i=1,2,...SN).
Step 2: Calculate and evaluate the fitness of each initial solution.
Step 3: Set the cycle conditions and start the cycle.
Step 4: Lead the bee to perform a neighborhood search for the solution xi according to formula (2-3) to generate a new solution (food source) vi, and calculate its fitness value;
Step 5: follow the formula (2-7) Carry out greedy selection: if the fitness value of vi is better than xi, replace xi with vi and use vi as the current best solution, otherwise keep xi unchanged;
Step 6: According to formula (2-4) Calculate the probability pi of the food source;
Step 7: Follow the bee to select the solution or food source according to the probability pi, search for a new solution (food source) vi according to formula (2-3), and calculate its fitness.
Step 8: Perform greedy selection according to formula (2-7); if the fitness of vi is better than xi, use vi instead of xi, and use vi as the current best solution, otherwise leave xi unchanged;
Step 9: determine whether there is a need Abandoned solution. If yes, the investigating bee randomly generates a new solution according to formula (2-5) and replaces it;
Step 10: Record the best solution so far;

Step 11: Determine whether the loop termination condition is met, if it is satisfied, the loop ends, and the optimal solution is output; otherwise, return to step 4 to continue searching.

Second, the source code

global radar1
global radar2
global R
% radar1 = [350 105 305 105 175 245 415 480 40 470];
% baili = size(radar1,2);
% radar2 = [200 0 -150 110 110 110 0 110 100 -50];
% R = [140 70 150 30 25 25 25 90 40 30];
 
 
radar1 = [100 200 300 400 150 250 350 150 250 350 0 466 250 250 466 30];
baili = size(radar1,2);
radar2 = [0 0 0 0 50 50 50 -50 -50 -50 40 40 -300 300 -40 -20];
R = [40 40 40 40 40 40 40 40 40 40 20 20 260 277 20 30];
 
NP=40; %/* The number of colony size (employed bees+onlooker bees)*/
FoodNumber=NP/2; %/*The number of food sources equals the half of the colony size*/
maxCycle=10; %/*The number of cycles for foraging {a stopping criteria}*/
limit=0.1*maxCycle; %/*A food source which could not be improved through "limit" trials is abandoned by its employed bee*/
D= 30;
ub=ones(1,D).*50; %/*lower bounds of the parameters. */
lb=ones(1,D).*-50;%/*upper bound of the parameters.*/
runtime=1;%/*Algorithm can be run many times in order to see its robustness*/
GlobalMins=zeros(1,runtime);
Range = repmat((ub-lb),[FoodNumber 1]);
Lower = repmat(lb, [FoodNumber 1]);
Foods = rand(FoodNumber,D) .* Range + Lower;
 
for r=1:runtime
for i = 1:FoodNumber
    ObjVal(i) = calcu(Foods(i,:));
end
Fitness = calculateFitness(ObjVal);
trial=zeros(1,FoodNumber);
BestInd=find(ObjVal==min(ObjVal));
BestInd=BestInd(end);
GlobalMin = ObjVal(BestInd);
GlobalParams=Foods(BestInd,:);
iter=1;
 
 
 
while ((iter <= maxCycle)),
    for i=1:(FoodNumber)
        Param2Change=fix(rand*D)+1;
        neighbour=fix(rand*(FoodNumber))+1;     
            while(neighbour==i)
                neighbour=fix(rand*(FoodNumber))+1;
            end;  
       sol=Foods(i,:);
       sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
        %
        ind=find(sol<lb);
        libai = rand(1,D).*(ub-lb)+lb;
        sol(ind)=libai(ind);
        ind=find(sol>ub);
        libai = rand(1,D).*(ub-lb)+lb;
        sol(ind)=libai(ind);
        %
        ObjValSol = calcu(sol);
        FitnessSol=calculateFitness(ObjValSol);
       if (FitnessSol>Fitness(i)) 
            Foods(i,:)=sol;
            Fitness(i)=FitnessSol;
            ObjVal(i)=ObjValSol;
            trial(i)=0;
        else
            trial(i)=trial(i)+1;
       end;
     end;
prob=(0.9.*Fitness./max(Fitness))+0.1;
i=1;
t=0;
while(t<FoodNumber)
    if(rand<prob(i))
        t=t+1;
        Param2Change=fix(rand*D)+1;
        neighbour=fix(rand*(FoodNumber))+1;     
            while(neighbour==i)
                neighbour=fix(rand*(FoodNumber))+1;
            end;
        
       sol=Foods(i,:);
       sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
        %
        ind=find(sol<lb);
        libai = rand(1,D).*(ub-lb)+lb;
        sol(ind)=libai(ind);
        ind=find(sol>ub);
        libai = rand(1,D).*(ub-lb)+lb;
        sol(ind)=libai(ind);
        %
        ObjValSol = calcu(sol);
        FitnessSol=calculateFitness(ObjValSol);
       if (FitnessSol>Fitness(i)) 
            Foods(i,:)=sol;
            Fitness(i)=FitnessSol;
            ObjVal(i)=ObjValSol;
            trial(i)=0;
        else
            trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
       end;
    end;
    
    i=i+1;
    if (i==(FoodNumber)+1) 
        i=1;
    end;   
end; 
         ind=find(ObjVal==min(ObjVal));
         ind=ind(end);
         if (ObjVal(ind)<GlobalMin)
         GlobalMin=ObjVal(ind);
         GlobalParams=Foods(ind,:);
         end;
 
         
         
 
ind=find(trial==max(trial));
ind=ind(end);
if (trial(ind)>limit)
    trial(ind)=0;
    sol=(ub-lb).*rand(1,D)+lb;
    ObjValSol = calcu(sol);
    FitnessSol=calculateFitness(ObjValSol);
    Foods(ind,:)=sol;
    Fitness(ind)=FitnessSol;
    ObjVal(ind)=ObjValSol;
end;
fprintf('iteration = %d ObjVal=%g\n',iter,GlobalMin);
aaaaa(iter) = GlobalMin;
iter=iter+1;
end % End of ABC
storeer(r,:) = aaaaa;
end
 
 
% 
% figure (1)
% a = mean(storeer);
% plot(a)
 
figure (2)
hold on
plot(0,0,'k*')
plot(500,0,'ks')
 
for i = 1:baili
hold on
plot(radar1(i),radar2(i),'ko');
cir_plot([radar1(i),radar2(i)],R(i));
end
legend('starting point','target point','threat center')
 
axis equal
axis([-100,620,-400,400])
for i = 1:(D-1)
    plot([500/(D+1)*i,500/(D+1)*(i+1)],[GlobalParams(i),GlobalParams(i+1)],'LineWidth',2);
    hold on
end
plot([0,500/(D+1)*(1)],[0,GlobalParams(1)],'LineWidth',2);
plot([500/(D+1)*D,500],[GlobalParams(D),0],'LineWidth',2);

Three, running results

Insert picture description here

Four, remarks

Add QQ912100926 for complete code or writing.
Review >>>>>>
[Path Planning] Particle Swarm Optimization Algorithm for 3D UAV Path Planning [Matlab 012]
[Path Planning] Genetic Algorithm for Open Vehicle Path Planning for Multiple Logistics Centers [Matlab 013]
[Path planning] Robot grid path planning based on particle swarm algorithm [Matlab 014]
[Path planning] Ant colony algorithm to solve the shortest path [Matlab 015]
[Path planning] Immune algorithm for logistics center location selection [Matlab 016]
[Path planning] Three-dimensional path planning for drones
based on artificial bee colony [Matlab 017] [Path planning] Genetic algorithm for robot path planning based on grid map [Matlab 018]
[Path planning] Ant colony algorithm for multiple drones Attack scheduling [Matlab 019]
[Path planning] Genetic algorithm based on grid map robot optimal path planning [Matlab 020]
[Path planning] Genetic algorithm for multi-UAV cooperative target allocation modeling considering the allocation order [ Matlab 021 issue]
[path planning] ant colony algorithm multi-center vrp problem [Matlab 022]
[path planning] ant colony algorithm to solve multi-center VRP with time window [Matlab 023 issue]
[path planning] many genetic algorithms Central VRP solution [Matlab 024]
[Path planning] Simulated annealing to solve the VRP problem [Matlab 025]
[Path planning] A star grid path planning [Matlab 026]
[Path planning] Based on a two-way cross factor Optimizing particle swarm grid map path planning [Matlab 027]
[Path Planning] [TSP] Ant Colony Algorithm for Solving TSP Problem with GUI [Matlab 028]
[Path Planning] Ant Colony Algorithm for Raster Map Path Planning [Matlab 029]
[Path Planning] Genetic Algorithm for Traveling Salesman TSP [ Matlab Issue 030]
[Path Planning] Traveling Salesman TSP Problem of Simulated Annealing Algorithm [Matlab 031]
[Path Planning] Smart Car Path Planning of Ant Colony Algorithm [Matlab 032]
[Path Planning] Huawei Cup: UAV based on matlab Optimized application in emergency rescue and disaster relief [Matlab 033]
[Path planning] MATLAB's minimum cost and maximum flow calculation problem [Matlab 034]
[Path planning] A* algorithm to solve the three-dimensional path planning problem [Matlab 035]
[Path planning] People Path planning of worker bee colony algorithm [Matlab036 issue]

Guess you like

Origin blog.csdn.net/m0_54742769/article/details/113090896