% Y_axis=
Y_axis(p1)
% Z_axis=
Z_axis(p1)
X_axis=p1*(rand()-0.5);
Y_axis=p1*(rand()-0.5);
Z_axis=p1*(rand()-0.5);
Step 2: Calculate search
direction, distance and smell concentration value of the fruit fly.
% p2= step parameter (default=2)
% X(i)= X(p1,p2);
% Y(i)= Y(p1,p2);
% Z(i)= Z(p1,p2);
% where i denotes the individual fly.
X(i)=X_axis+
p2*(rand()-0.5);
Y(i)=Y_axis+
p2 (rand()-0.5);
Z(i)=Z_axis+
p2 (rand()-0.5);
The distance (D) of the food is
defined from the origin and depends on parameters p1 and p2, due to the
location of the food with respect to the fly swarm is unknown.
% p3=random
interference parameter (2)
% D1=D1(p1,p2);
% D2=D2(p1,p2);
D(i,1)=(X(i)^2+Y(i)^2+Z(i)^2)^0.5;
D(i,2)=(X(i)^2+Y(i)^2+Z(i)^2)^0.5;
The food’s
smell concentration values (olfactory S or x) are calculated, which is mainly
defined as the reciprocal of distance (D), and perturbed by a small fraction
(gp) of it:
% gp1=gp1(p3);
% gp2=gp1(p3);
gp1=p3*(rand()-0.5);
gp2=p3*(rand()-0.5);
Therefore, the variables (S1,S2) depend on three
parameters (p1.p2, p3):
% S1(i)= S1(gp1,
D1) = x1(i) (p1,p2,p3);
% S2(i)= S2(gp2, D2) = x2(i) (p1,p2,p3);
S1(i)=1/D(i,1)-gp1*D(i,1);
S2(i)=1/D(i,2)-gp2*D(i,2);
Substitute the smell
concentration value S(i) into a Smell judgment function (a.k.a. objective
function f(S)= Smell(i)), i.e. a function of D or S, (g(D) or f(S)), where D=(D(1),D(2)). Here we let S=( S1, S2) = (x1, x2) = x.
% for example: two variables
% Smell(i)=
g(D(i,1),D(i,2))=f(S1(i),S2(i)) =f(x1(i),x2(i)).
% as an example: the quadratic
function of two variables
Smell(i)=
=f(x1(i),x2(i))=(x1(i)+3)^2+(x2(i)+3)^2;
Step 3: Find the highest smell judgment value among the fruit flies.
[bestSmell bestindex]=min(Smell)
Keep the highest smelling concentration value and the best
3-D location (X_axis, Y_axis , Z_axis), and at this moment, all other fruit flies use their visions to fly towards that location. In other words,
the fruit fly smelling the
highest concentration and would like to share its best location with all other flies.
X_axis=X(bestindex);
Y_axis=Y(bestindex);
Z_axis=Z(bestindex);
Smellbest=bestSmell;
Step 4: Update smell judgment value. If the maximal value or maximum number of iterations (maxgen) is reached, the processes are stopped. Otherwise, return
to Step 5.
Step 5: Update the
best location (X_axis, Y_axis, Z_axis) and return to Step 2.
The complete flowchart of FOA is shown in Figure 2.
Fig. 2 Flowchart of the fruit fly optimization algorithm