FFA Source Code
FFA Source Code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Pan's Original 2D‐FOA
%% EMA Economic Department, Soochow University, Taipei,Taiwan
%
% Copyright by W‐T Pan (2011)
% Revised by W‐Y Lin (2011)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Topic: How to find the max value of a quadratic function
% Clear the operating environment.
tic
clc
clear
% Randomize the initial Drosophila population positions.
X_axis=10*rand();
Y_axis=10*rand();
% Set parameters
maxgen=100; % No.of iterations
sizepop=20; % Population size
% Start the FOA: Flies use the sense of smell to find food
for i=1:sizepop
% The Drosophila uses its olfactory to search the food
% by random direction and distance
X(i)=X_axis+2*rand()‐1;
Y(i)=Y_axis+2*rand()‐1;
% Due to the fly cannot find the exact location of the prey, so we first estimate the distance from the origin (Dist).
% And then calculate the flavor concentration determination value (S), it is the inverse of the distance.
D(i)=(X(i)^2+Y(i)^2)^0.5;
S(i)=1/D(i);
% Concentration determination value (S) is substituted into the fitness function, i.e. the concentration of the flavor
(Smelli) of the flies.
Smell(i)=7‐S(i)^2;
end
% Identify the highest concentration values of this fruit fly Drosophila groups (find the maximum value).