The article directories
- I. Theoretical basis
- Second, algorithm steps
-
- 1, inspired
- 2. Direction and distance
- 3. Judgment value of odor concentration
- 4. Fitness evaluation
- 5. Find the best individual
- 6, flight
- 7. Iterative optimization
- Iii. Case Background
-
- Problem description
- Four, MATLAB program implementation
-
- 1. Empty environment variables
- 2. Initialize parameters
- 3. Find the initial optimum
- 4. Iterative optimization
- 5. Result display
- 6, drawing
- 5. References
I. Theoretical basis
Fruit Fly Optimization Algorithm (FOA) is an emerging swarm intelligence Optimization Algorithm based on the bionics principle of drosophila foraging behavior. It was first proposed by Professor Pan Wenchao from Huaxia University of Science and Technology in Taiwan in 2011. The fruit fly optimization algorithm (FOA) simulates the hunting process of fruit flies with their keen sense of smell and vision, and FOA realizes the group iterative search of the solution space. FOA principle is easy to understand, simple to operate, easy to implement, has a strong local search ability.
Second, algorithm steps
1, inspired
The fruit fly itself is superior to other species in sense and perception, especially in smell and vision, as shown in Figure 1.
Figure 1 body appearance and group iterative foraging of drosophila melanogaster
The olfactory organ of the fruit fly detects smells floating in the air; It can even smell food up to 40 kilometers away. Then, when it gets close to food, it can also use its keen vision to find where food and companions gather and fly in that direction.
2. Direction and distance
Random initial drosophila population position.
3. Judgment value of odor concentration
Since the location of the food cannot be known, the distance to source (dist) is first estimated, and the odor concentration judgment value (S) is calculated, which is the inverse of the distance.
4. Fitness evaluation
The odor concentration judgment value was substituted into the odor concentration judgment function (or fitness function) to find the odor concentration of individual fruit flies.
5. Find the best individual
Find the fruit fly with the highest scent concentration in the drosophila group (search for the optimal individual).
6, flight
To maintain the optimal odor concentration and x,y, x,yx,y coordinates, the drosophila will use vision to fly to that location.
7. Iterative optimization
Enter iterative optimization and repeat Steps 2 to 5 to determine whether the odor concentration is better than the previous iteration odor concentration. If so, perform Step 6.
Iii. Case Background
Problem description
Four, MATLAB program implementation
1. Empty environment variables
Before the program runs, clear variables in the Workspace and commands in the Command Window. The specific procedures are as follows:
%% Clear the environment variable CLC; clear;Copy the code
2. Initialize parameters
The parameters need to be initialized before calculation. At the same time, in order to speed up the execution of the program, the storage capacity of some process variables involved in the program needs to be pre-allocated. The specific procedures are as follows:
%% randomly initialized drosophila population position X_axis = 10*rand(1, 2); Y_axis = 10*rand(1, 2); %% Set the parameter maxgen = 200; % Number of iterations sizepop = 20; % population sizeCopy the code
- 1
- 2
- 3
- 4
- 5
- 6
3. Find the initial optimum
For I = 1:sizepop % Random direction and distance X(I, :) = X_axis + 2*rand(1, 2)-1; Y(i, :) = Y_axis + 2*rand(1, 2)-1; % distance and odor concentration D(I, :) = SQRT (X(I, :).^2+Y(I, :).^2); S(i, :) = 1./D(i, :); % fitness function Schaffer Smell (I) = 0.5 + (cos (sin (abs (S (I, 1) ^ 2 - (I, 2) S ^ 2)) ^ 2-0.5)/(1 + 0.001 * (S (I, 1) ^ 2 + S (I, 2) ^ 2)) ^ 2); [bestSmell bestindex]=min(Smell); X_axis = X(bestindex, :); Y_axis = Y(bestindex, :); Smellbest = bestSmell; FXbest = S(bestindex, 1); FYbest = S(bestindex, 2);Copy the code
4. Iterative optimization
Iterative optimization is the core of the whole algorithm. The code is as follows:
For gen = 1:maxgen % Particle position and speed update for I = 1:sizepop X(I, :) = X_axis + 2*rand(1, 2)-1; Y(i, :) = Y_axis + 2*rand(1, 2)-1; D(i, :) = sqrt(X(i, :).^2+Y(i, :).^2); S(i, :) = 1./D(i, :); % fitness function Schaffer Smell (I) = 0.5 + (cos (sin (abs (S (I, 1) ^ 2 - (I, 2) S ^ 2)) ^ 2-0.5)/(1 + 0.001 * (S (I, 1) ^ 2 + S (I, 2) ^ 2)) ^ 2); [bestSmell bestindex]=min(Smell); If bestSmell < Smellbest X_axis = X(bestindex, :); Y_axis = Y(bestindex, :); Smellbest = bestSmell; FXbest = S(bestindex, 1); FYbest = S(bestindex, 2); End % The optimal Smell value of each generation was recorded in YY array, and the optimal iterative coordinate YY (Gen) = Smellbest was recorded. Xbest(gen, :) = X_axis; Ybest(gen, :) = Y_axis; endCopy the code
5. Result display
In order to observe and analyze the results more intuitively, the optimal independent variables and their optimal function values are displayed in the Command Window. The specific procedures are as follows:
Disp ([' optimal position for fitness function: ', num2str(FXbest), ',', num2str(FYbest)]); Disp (' yy(end) ', num2str(yy(end)));Copy the code
Because the initial positions of individual flies are randomly generated, the results vary from run to run. The result of a run is as follows:
Optimal position of fitness function: 0.50068,42.8868 Optimal solution of fitness function: 0.61574Copy the code
6, drawing
In order to observe and analyze the results more intuitively, the results are displayed in the form of graphics, and the specific procedures are as follows:
Figure (1) iterated flavor concentration and drosophila flight path trend; plot(yy, 'r', 'linewidth', 2); Title (' optimize process ', 'fontsize', 12) xlabel(' iterations ', 'fontsize', 12); Ylabel (' odor concentration (fitness value)', 'fontsize', 12); figure(2); gen = 1:maxgen; plot(Xbest(:, 1), Ybest(:, 1), 'r.'); Plot changes of drosophila population X_axis, Y_axis hold on; plot(Xbest(:, 2), Ybest(:, 2), 'b.'); Title (' Fruit fly optimization algorithm optimization route ', 'fontsize',14) xlabel('X-axis', 'fontsize', 12); ylabel('Y-axis', 'fontsize', 12);Copy the code
The optimization process of fruit fly optimization algorithm is shown in Figure 3.
FIG. 3 Optimization process of fruit fly optimization algorithm
The optimization route of fruit fly optimization algorithm is shown in FIG. 4.
FIG. 4 Optimization route search by drosophila optimization algorithm
The code download www.cnblogs.com/matlabxiao/…
5. References
[1] Pan W T . A new Fruit Fly Optimization Algorithm: Taking the financial distress model as an example[J]. Knowledge-Based Systems, 2012, 26(2):69-74. Complete code or simulation consulting added QQ1575304183 [2] Songjian Sha Road HBA646333407. Fruit Fly Optimization Algorithm (FOA) -Matlab source code. CSDN blog.