%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%Flower Pollination Algorithm for Multimodal Optimization (MFPA)
%Jorge G醠vez, Erik Cuevas and Omar Avalos
%%This is the line to execute the code:
%%[mem,bestSol,bestFit,optima,FunctionCalls]=FPA([50 0.25 500 2]);
%FitFunc implements the function to be optimized
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [mem,bestSol,bestFit,optima,FunctionCalls]=FPA(para)
% Default parameters
if nargin<1,
para=[50 0.25 500];
end
n=para(1); % Population size
p=para(2); % Probabibility switch
N_iter=para (3); % Number of iterations
phase = 1; %First state
phaseIte= [0.5,0.9,1.01]; %State vector
%Deb Function
d = 1;
Lb = 0;
Ub = 1;
optima = [.1;.3;.5;.7;.9];
% Initialize the population
for i=1:n,
Sol(i,:)=Lb+(Ub-Lb).*rand(1,d);
Fitness(i)=fitFunc(Sol(i,:)); %%Evaluate fitness function
end
% Initialice the memory
[mem,bestSol,bestFit,worstF] = memUpdate(Sol,Fitness, [], zeros(1,d), 100000000, 0, phase,d,Ub,Lb);
S = Sol;
FunctionCalls = 0;
% Main Loop
for ite = 1 : N_iter,
%For each pollen gamete, modify each position acoording
%to local or global pollination
for i = 1 : n,
% Switch probability
if rand>p,
L=Levy(d);
dS=L.*(Sol(i,:)-bestSol);
S(i,:)=Sol(i,:)+dS;
S(i,:)=simplebounds(S(i,:),Lb,Ub);
else
epsilon=rand;
% Find random flowers in the neighbourhood
JK=randperm(n);
% As they are random, the first two entries also random
% If the flower are the same or similar species, then
% they can be pollenated, otherwise, no action.
% Formula: x_i^{t+1}+epsilon*(x_j^t-x_k^t)
S(i,:)=S(i,:)+epsilon*(Sol(JK(1),:)-Sol(JK(2),:));
% Check if the simple limits/bounds are OK
S(i,:)=simplebounds(S(i,:),Lb,Ub);
end
Fitness(i)=fitFunc(S(i,:));
end
%Update the memory
[mem,bestSol,bestFit,worstF] = memUpdate(S,Fitness,mem,bestSol,bestFit,worstF,phase,d,Ub,Lb);
Sol = get_best_nest(S, mem, p);
FunctionCalls = FunctionCalls + n;
if ite/N_iter > phaseIte(phase)
%Next evolutionary process stage
phase = phase + 1;
[m,~]=size(mem);
%Depurate the memory for each stage
mem = cleanMemory(mem);
FunctionCalls = FunctionCalls + m;
end
end
%Plot the solutions (mem) founded by the multimodal framework
x = 0:.01:1;
y = ((sin(5.*pi.*x)).^ 6);
plot(x,y)
hold on
plot(mem(:,1),-mem(:,2),'r*');
% Application of simple constraints
function s=simplebounds(s,Lb,Ub)
% Apply the lower bound
ns_tmp=s;
I=ns_tmp<Lb;
ns_tmp(I)=Lb(I);
% Apply the upper bounds
J=ns_tmp>Ub;
ns_tmp(J)=Ub(J);
% Update this new move
s=ns_tmp;
% Draw n Levy flight sample
function L=Levy(d)
% Levy exponent and coefficient
% For details, see Chapter 11 of the following book:
% Xin-She Yang, Nature-Inspired Optimization Algorithms, Elsevier, (2014).
beta=3/2;
sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta);
u=randn(1,d)*sigma;
v=randn(1,d);
step=u./abs(v).^(1/beta);
L=0.01*step;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.