際際滷

際際滷Share a Scribd company logo
% ======================================================== %
% Files of the Matlab programs included in the book: %
% Xin-She Yang, Nature-Inspired Metaheuristic Algorithms, %
% Second Edition, Luniver Press, (2010). www.luniver.com %
% ======================================================== %
% -------------------------------------------------------- %
% Firefly Algorithm for constrained optimization using %
% for the design of a spring (benchmark) %
% by Xin-She Yang (Cambridge University) Copyright @2009 %
% -------------------------------------------------------- %
function fa_ndim
% parameters [n N_iteration alpha betamin gamma]
para=[20 500 0.5 0.2 1];
help fa_ndim.m
% Simple bounds/limits for d-dimensional problems
d=15;
Lb=zeros(1,d);
Ub=2*ones(1,d);
% Initial random guess
u0=Lb+(Ub-Lb).*rand(1,d);
[u,fval,NumEval]=ffa_mincon(@cost,u0,Lb,Ub,para);
% Display results
bestsolution=u
bestojb=fval
total_number_of_function_evaluations=NumEval
%%% Put your own cost/objective function here --------%%%
%% Cost or Objective function
function z=cost(x)
% Exact solutions should be (1,1,...,1)
z=sum((x-1).^2);
%%% End of the part to be modified -------------------%%%
%%% --------------------------------------------------%%%
%%% Do not modify the following codes unless you want %%%
%%% to improve its performance etc %%%
% -------------------------------------------------------
% ===Start of the Firefly Algorithm Implementation ======
% Lb = lower bounds/limits
% Ub = upper bounds/limits
% para == optional (to control the Firefly algorithm)
% Outputs: nbest = the best solution found so far
% fbest = the best objective value
% NumEval = number of evaluations: n*MaxGeneration
% Optional:
% The alpha can be reduced (as to reduce the randomness)
% ---------------------------------------------------------
% Start FA
function [nbest,fbest,NumEval]...
=ffa_mincon(fhandle,u0, Lb, Ub, para)
% Check input parameters (otherwise set as default values)
if nargin<5, para=[20 500 0.25 0.20 1]; end
if nargin<4, Ub=[]; end
if nargin<3, Lb=[]; end
if nargin<2,
disp('Usuage: FA_mincon(@cost,u0,Lb,Ub,para)');
end
% n=number of fireflies
% MaxGeneration=number of pseudo time steps
% ------------------------------------------------
% alpha=0.25; % Randomness 0--1 (highly random)
% betamn=0.20; % minimum value of beta
% gamma=1; % Absorption coefficient
% ------------------------------------------------
n=para(1); MaxGeneration=para(2);
alpha=para(3); betamin=para(4); gamma=para(5);
% Total number of function evaluations
NumEval=n*MaxGeneration;
% Check if the upper bound & lower bound are the same size
if length(Lb) ~=length(Ub),
disp('Simple bounds/limits are improper!');
return
end
% Calcualte dimension
d=length(u0);
% Initial values of an array
zn=ones(n,1)*10^100;
% ------------------------------------------------
% generating the initial locations of n fireflies
[ns,Lightn]=init_ffa(n,d,Lb,Ub,u0);
% Iterations or pseudo time marching
for k=1:MaxGeneration, %%%%% start iterations
% This line of reducing alpha is optional
alpha=alpha_new(alpha,MaxGeneration);
% Evaluate new solutions (for all n fireflies)
for i=1:n,
zn(i)=fhandle(ns(i,:));
Lightn(i)=zn(i);
end
% Ranking fireflies by their light intensity/objectives
[Lightn,Index]=sort(zn);
ns_tmp=ns;
for i=1:n,
ns(i,:)=ns_tmp(Index(i),:);
end
%% Find the current best
nso=ns; Lighto=Lightn;
nbest=ns(1,:); Lightbest=Lightn(1);
% For output only
fbest=Lightbest;
% Move all fireflies to the better locations
[ns]=ffa_move(n,d,ns,Lightn,nso,Lighto,nbest,...
Lightbest,alpha,betamin,gamma,Lb,Ub);
end %%%%% end of iterations
% -------------------------------------------------------
% ----- All the subfunctions are listed here ------------
% The initial locations of n fireflies
function [ns,Lightn]=init_ffa(n,d,Lb,Ub,u0)
% if there are bounds/limits,
if length(Lb)>0,
for i=1:n,
ns(i,:)=Lb+(Ub-Lb).*rand(1,d);
end
else
% generate solutions around the random guess
for i=1:n,
ns(i,:)=u0+randn(1,d);
end
end
% initial value before function evaluations
Lightn=ones(n,1)*10^100;
% Move all fireflies toward brighter ones
function [ns]=ffa_move(n,d,ns,Lightn,nso,Lighto,...
nbest,Lightbest,alpha,betamin,gamma,Lb,Ub)
% Scaling of the system
scale=abs(Ub-Lb);
% Updating fireflies
for i=1:n,
% The attractiveness parameter beta=exp(-gamma*r)
for j=1:n,
r=sqrt(sum((ns(i,:)-ns(j,:)).^2));
% Update moves
if Lightn(i)>Lighto(j), % Brighter and more attractive
beta0=1; beta=(beta0-betamin)*exp(-gamma*r.^2)+betamin;
tmpf=alpha.*(rand(1,d)-0.5).*scale;
ns(i,:)=ns(i,:).*(1-beta)+nso(j,:).*beta+tmpf;
end
end % end for j
end % end for i
% Check if the updated solutions/locations are within limits
[ns]=findlimits(n,ns,Lb,Ub);
% This function is optional, as it is not in the original FA
% The idea to reduce randomness is to increase the convergence,
% however, if you reduce randomness too quickly, then premature
% convergence can occur. So use with care.
function alpha=alpha_new(alpha,NGen)
% alpha_n=alpha_0(1-delta)^NGen=10^(-4);
% alpha_0=0.9
delta=1-(10^(-4)/0.9)^(1/NGen);
alpha=(1-delta)*alpha;
% Make sure the fireflies are within the bounds/limits
function [ns]=findlimits(n,ns,Lb,Ub)
for i=1:n,
% Apply the lower bound
ns_tmp=ns(i,:);
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
ns(i,:)=ns_tmp;
end
%% ==== End of Firefly Algorithm implementation ======

More Related Content

Similar to Firefly algorithm (20)

Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
amanabr
?
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
?
Matlab kod tasla??
Matlab kod tasla??Matlab kod tasla??
Matlab kod tasla??
Merve Cvdr
?
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
AmirParnianifard1
?
Project management
Project managementProject management
Project management
Avay Minni
?
Adjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORTAdjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORT
Subhajit Sahu
?
Ann a Algorithms notes
Ann a Algorithms notesAnn a Algorithms notes
Ann a Algorithms notes
Prof. Neeta Awasthy
?
scientific computing
scientific computingscientific computing
scientific computing
saurabhramteke7
?
Mnistauto 5
Mnistauto 5Mnistauto 5
Mnistauto 5
Ali R?za SARAL
?
Svm vs ls svm
Svm vs ls svmSvm vs ls svm
Svm vs ls svm
Pulipaka Sai Ravi Teja
?
Adjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORTAdjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORT
Subhajit Sahu
?
Adjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORTAdjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORT
Subhajit Sahu
?
Thesis
ThesisThesis
Thesis
Yehia ABD ALRahman
?
Data Analysis
Data AnalysisData Analysis
Data Analysis
Assignmentpedia
?
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical Engineering
Debarun Banerjee
?
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
ESUG
?
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
ijfls
?
Python faster for loop
Python faster for loopPython faster for loop
Python faster for loop
? Radek Fabisiak
?
Using the Pade Technique to Approximate the Function.pptx
Using the Pade Technique to Approximate the Function.pptxUsing the Pade Technique to Approximate the Function.pptx
Using the Pade Technique to Approximate the Function.pptx
MasoudIbrahim3
?
a a a a a a a a a a a a a a a a aa a a a a 41520z
a a a a a a a a a a a a a a a a aa a a a a 41520za a a a a a a a a a a a a a a a aa a a a a 41520z
a a a a a a a a a a a a a a a a aa a a a a 41520z
MasoudIbrahim3
?
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
amanabr
?
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
?
Matlab kod tasla??
Matlab kod tasla??Matlab kod tasla??
Matlab kod tasla??
Merve Cvdr
?
Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...Computational Intelligence Assisted Engineering Design Optimization (using MA...
Computational Intelligence Assisted Engineering Design Optimization (using MA...
AmirParnianifard1
?
Project management
Project managementProject management
Project management
Avay Minni
?
Adjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORTAdjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORT
Subhajit Sahu
?
Adjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORTAdjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORT
Subhajit Sahu
?
Adjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORTAdjusting PageRank parameters and comparing results : REPORT
Adjusting PageRank parameters and comparing results : REPORT
Subhajit Sahu
?
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical Engineering
Debarun Banerjee
?
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
ESUG
?
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
A LEAST ABSOLUTE APPROACH TO MULTIPLE FUZZY REGRESSION USING Tw- NORM BASED O...
ijfls
?
Using the Pade Technique to Approximate the Function.pptx
Using the Pade Technique to Approximate the Function.pptxUsing the Pade Technique to Approximate the Function.pptx
Using the Pade Technique to Approximate the Function.pptx
MasoudIbrahim3
?
a a a a a a a a a a a a a a a a aa a a a a 41520z
a a a a a a a a a a a a a a a a aa a a a a 41520za a a a a a a a a a a a a a a a aa a a a a 41520z
a a a a a a a a a a a a a a a a aa a a a a 41520z
MasoudIbrahim3
?

More from Xin-She Yang (20)

Cuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionCuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An Introduction
Xin-She Yang
?
Metaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical AnalysisMetaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical Analysis
Xin-She Yang
?
Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms
Xin-She Yang
?
A Biologically Inspired Network Design Model
A Biologically Inspired Network Design ModelA Biologically Inspired Network Design Model
A Biologically Inspired Network Design Model
Xin-She Yang
?
Flower Pollination Algorithm (matlab code)
Flower Pollination Algorithm (matlab code)Flower Pollination Algorithm (matlab code)
Flower Pollination Algorithm (matlab code)
Xin-She Yang
?
Nature-Inspired Metaheuristic Algorithms
Nature-Inspired Metaheuristic AlgorithmsNature-Inspired Metaheuristic Algorithms
Nature-Inspired Metaheuristic Algorithms
Xin-She Yang
?
Metaheuristics and Optimiztion in Civil Engineering
Metaheuristics and Optimiztion in Civil EngineeringMetaheuristics and Optimiztion in Civil Engineering
Metaheuristics and Optimiztion in Civil Engineering
Xin-She Yang
?
A Biologically Inspired Network Design Model
A Biologically Inspired Network Design ModelA Biologically Inspired Network Design Model
A Biologically Inspired Network Design Model
Xin-She Yang
?
Introduction to Computational Mathematics (2nd Edition, 2015)
Introduction to Computational Mathematics (2nd Edition, 2015)Introduction to Computational Mathematics (2nd Edition, 2015)
Introduction to Computational Mathematics (2nd Edition, 2015)
Xin-She Yang
?
Memetic Firefly algorithm for combinatorial optimization
Memetic Firefly algorithm for combinatorial optimizationMemetic Firefly algorithm for combinatorial optimization
Memetic Firefly algorithm for combinatorial optimization
Xin-She Yang
?
Two-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential EvolutionTwo-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential Evolution
Xin-She Yang
?
Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...
Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...
Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...
Xin-She Yang
?
Bat Algorithm for Multi-objective Optimisation
Bat Algorithm for Multi-objective OptimisationBat Algorithm for Multi-objective Optimisation
Bat Algorithm for Multi-objective Optimisation
Xin-She Yang
?
Are motorways rational from slime mould's point of view?
Are motorways rational from slime mould's point of view?Are motorways rational from slime mould's point of view?
Are motorways rational from slime mould's point of view?
Xin-She Yang
?
Review of Metaheuristics and Generalized Evolutionary Walk Algorithm
Review of Metaheuristics and Generalized Evolutionary Walk AlgorithmReview of Metaheuristics and Generalized Evolutionary Walk Algorithm
Review of Metaheuristics and Generalized Evolutionary Walk Algorithm
Xin-She Yang
?
Test Problems in Optimization
Test Problems in OptimizationTest Problems in Optimization
Test Problems in Optimization
Xin-She Yang
?
Engineering Optimisation by Cuckoo Search
Engineering Optimisation by Cuckoo SearchEngineering Optimisation by Cuckoo Search
Engineering Optimisation by Cuckoo Search
Xin-She Yang
?
A New Metaheuristic Bat-Inspired Algorithm
A New Metaheuristic Bat-Inspired AlgorithmA New Metaheuristic Bat-Inspired Algorithm
A New Metaheuristic Bat-Inspired Algorithm
Xin-She Yang
?
Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...
Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...
Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...
Xin-She Yang
?
Fractals in Small-World Networks With Time Delay
Fractals in Small-World Networks With Time DelayFractals in Small-World Networks With Time Delay
Fractals in Small-World Networks With Time Delay
Xin-She Yang
?
Cuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionCuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An Introduction
Xin-She Yang
?
Metaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical AnalysisMetaheuristic Algorithms: A Critical Analysis
Metaheuristic Algorithms: A Critical Analysis
Xin-She Yang
?
Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms
Xin-She Yang
?
A Biologically Inspired Network Design Model
A Biologically Inspired Network Design ModelA Biologically Inspired Network Design Model
A Biologically Inspired Network Design Model
Xin-She Yang
?
Flower Pollination Algorithm (matlab code)
Flower Pollination Algorithm (matlab code)Flower Pollination Algorithm (matlab code)
Flower Pollination Algorithm (matlab code)
Xin-She Yang
?
Nature-Inspired Metaheuristic Algorithms
Nature-Inspired Metaheuristic AlgorithmsNature-Inspired Metaheuristic Algorithms
Nature-Inspired Metaheuristic Algorithms
Xin-She Yang
?
Metaheuristics and Optimiztion in Civil Engineering
Metaheuristics and Optimiztion in Civil EngineeringMetaheuristics and Optimiztion in Civil Engineering
Metaheuristics and Optimiztion in Civil Engineering
Xin-She Yang
?
A Biologically Inspired Network Design Model
A Biologically Inspired Network Design ModelA Biologically Inspired Network Design Model
A Biologically Inspired Network Design Model
Xin-She Yang
?
Introduction to Computational Mathematics (2nd Edition, 2015)
Introduction to Computational Mathematics (2nd Edition, 2015)Introduction to Computational Mathematics (2nd Edition, 2015)
Introduction to Computational Mathematics (2nd Edition, 2015)
Xin-She Yang
?
Memetic Firefly algorithm for combinatorial optimization
Memetic Firefly algorithm for combinatorial optimizationMemetic Firefly algorithm for combinatorial optimization
Memetic Firefly algorithm for combinatorial optimization
Xin-She Yang
?
Two-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential EvolutionTwo-Stage Eagle Strategy with Differential Evolution
Two-Stage Eagle Strategy with Differential Evolution
Xin-She Yang
?
Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...
Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...
Accelerated Particle Swarm Optimization and Support Vector Machine for Busine...
Xin-She Yang
?
Bat Algorithm for Multi-objective Optimisation
Bat Algorithm for Multi-objective OptimisationBat Algorithm for Multi-objective Optimisation
Bat Algorithm for Multi-objective Optimisation
Xin-She Yang
?
Are motorways rational from slime mould's point of view?
Are motorways rational from slime mould's point of view?Are motorways rational from slime mould's point of view?
Are motorways rational from slime mould's point of view?
Xin-She Yang
?
Review of Metaheuristics and Generalized Evolutionary Walk Algorithm
Review of Metaheuristics and Generalized Evolutionary Walk AlgorithmReview of Metaheuristics and Generalized Evolutionary Walk Algorithm
Review of Metaheuristics and Generalized Evolutionary Walk Algorithm
Xin-She Yang
?
Test Problems in Optimization
Test Problems in OptimizationTest Problems in Optimization
Test Problems in Optimization
Xin-She Yang
?
Engineering Optimisation by Cuckoo Search
Engineering Optimisation by Cuckoo SearchEngineering Optimisation by Cuckoo Search
Engineering Optimisation by Cuckoo Search
Xin-She Yang
?
A New Metaheuristic Bat-Inspired Algorithm
A New Metaheuristic Bat-Inspired AlgorithmA New Metaheuristic Bat-Inspired Algorithm
A New Metaheuristic Bat-Inspired Algorithm
Xin-She Yang
?
Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...
Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...
Eagle Strategy Using Levy Walk and Firefly Algorithms For Stochastic Optimiza...
Xin-She Yang
?
Fractals in Small-World Networks With Time Delay
Fractals in Small-World Networks With Time DelayFractals in Small-World Networks With Time Delay
Fractals in Small-World Networks With Time Delay
Xin-She Yang
?

Recently uploaded (20)

Environmental impact assessments ppt.doc
Environmental impact assessments ppt.docEnvironmental impact assessments ppt.doc
Environmental impact assessments ppt.doc
BonsaHailu
?
Application of Artificial Neural Networks.pdf
Application of Artificial Neural Networks.pdfApplication of Artificial Neural Networks.pdf
Application of Artificial Neural Networks.pdf
JeveshMagnani
?
move curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptx
move curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptxmove curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptx
move curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptx
CarlosFernandez289274
?
Material Handling : Scope , Importance, Objectives, Principles, Classificatio...
Material Handling : Scope , Importance, Objectives, Principles, Classificatio...Material Handling : Scope , Importance, Objectives, Principles, Classificatio...
Material Handling : Scope , Importance, Objectives, Principles, Classificatio...
VirajPasare
?
SF_Urban_Transformation_Enhanced for sanfranciccio
SF_Urban_Transformation_Enhanced for sanfranciccioSF_Urban_Transformation_Enhanced for sanfranciccio
SF_Urban_Transformation_Enhanced for sanfranciccio
ianlesteronifa1
?
2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf
2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf
2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf
MuhammadToyeb
?
HISTORY Module (Revised).pdf fershman student module
HISTORY Module (Revised).pdf fershman student moduleHISTORY Module (Revised).pdf fershman student module
HISTORY Module (Revised).pdf fershman student module
ABERE YINEBEB
?
METAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFET
METAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFETMETAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFET
METAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFET
punithaece
?
UNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdf
UNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdfUNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdf
UNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdf
2022EE30SadeedUrRehm
?
Battery charging technology for electric vehicle.pptx
Battery charging technology for electric vehicle.pptxBattery charging technology for electric vehicle.pptx
Battery charging technology for electric vehicle.pptx
VirajPasare
?
b29e51b5-c830-4877-a978-a6b308ea8c5f.ppt
b29e51b5-c830-4877-a978-a6b308ea8c5f.pptb29e51b5-c830-4877-a978-a6b308ea8c5f.ppt
b29e51b5-c830-4877-a978-a6b308ea8c5f.ppt
dashrimi0
?
optical fibres ppt on its full details.pptx
optical fibres ppt on its full details.pptxoptical fibres ppt on its full details.pptx
optical fibres ppt on its full details.pptx
sashiP
?
Introduction-to-Stack-Instruction.pptxpptppt
Introduction-to-Stack-Instruction.pptxpptpptIntroduction-to-Stack-Instruction.pptxpptppt
Introduction-to-Stack-Instruction.pptxpptppt
suhas060606
?
芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models
芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models
芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models
鰻粥京晦粥皆幄塀氏芙
?
How to start and then move forward in IT
How to start and then move forward in ITHow to start and then move forward in IT
How to start and then move forward in IT
Marian Marinov
?
Smart Manufacturing with Unified Namespace
Smart Manufacturing with Unified NamespaceSmart Manufacturing with Unified Namespace
Smart Manufacturing with Unified Namespace
Ponraj RK
?
chapter 6.Construction project scheduling techniques pdf
chapter 6.Construction project scheduling techniques pdfchapter 6.Construction project scheduling techniques pdf
chapter 6.Construction project scheduling techniques pdf
Jimma Technology Institute,Jimma University
?
study of impact behaviour of dual material for energy absorption
study of impact behaviour of dual material for energy absorptionstudy of impact behaviour of dual material for energy absorption
study of impact behaviour of dual material for energy absorption
AmitChauhan352669
?
The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...
The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...
The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...
ivargarud
?
Electronic Commerce - 21 and 22 Sept 2024 (3) (1).pptx
Electronic Commerce - 21 and 22 Sept 2024 (3) (1).pptxElectronic Commerce - 21 and 22 Sept 2024 (3) (1).pptx
Electronic Commerce - 21 and 22 Sept 2024 (3) (1).pptx
livacoh815
?
Environmental impact assessments ppt.doc
Environmental impact assessments ppt.docEnvironmental impact assessments ppt.doc
Environmental impact assessments ppt.doc
BonsaHailu
?
Application of Artificial Neural Networks.pdf
Application of Artificial Neural Networks.pdfApplication of Artificial Neural Networks.pdf
Application of Artificial Neural Networks.pdf
JeveshMagnani
?
move curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptx
move curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptxmove curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptx
move curriculum guidennnnnnnnnnnnnnnnnnnnnnnoriginal.pptx
CarlosFernandez289274
?
Material Handling : Scope , Importance, Objectives, Principles, Classificatio...
Material Handling : Scope , Importance, Objectives, Principles, Classificatio...Material Handling : Scope , Importance, Objectives, Principles, Classificatio...
Material Handling : Scope , Importance, Objectives, Principles, Classificatio...
VirajPasare
?
SF_Urban_Transformation_Enhanced for sanfranciccio
SF_Urban_Transformation_Enhanced for sanfranciccioSF_Urban_Transformation_Enhanced for sanfranciccio
SF_Urban_Transformation_Enhanced for sanfranciccio
ianlesteronifa1
?
2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf
2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf
2. KONSEP EKONOMI TEKNIK & PERANCANGAN TEKNIK.pdf
MuhammadToyeb
?
HISTORY Module (Revised).pdf fershman student module
HISTORY Module (Revised).pdf fershman student moduleHISTORY Module (Revised).pdf fershman student module
HISTORY Module (Revised).pdf fershman student module
ABERE YINEBEB
?
METAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFET
METAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFETMETAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFET
METAL OXIDE FIELD EFFECT SEMICONDUCTOR-MOSFET
punithaece
?
UNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdf
UNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdfUNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdf
UNIT 03 Alan_Morris_EMI_Chap_03 Measurement Uncertainty.pdf
2022EE30SadeedUrRehm
?
Battery charging technology for electric vehicle.pptx
Battery charging technology for electric vehicle.pptxBattery charging technology for electric vehicle.pptx
Battery charging technology for electric vehicle.pptx
VirajPasare
?
b29e51b5-c830-4877-a978-a6b308ea8c5f.ppt
b29e51b5-c830-4877-a978-a6b308ea8c5f.pptb29e51b5-c830-4877-a978-a6b308ea8c5f.ppt
b29e51b5-c830-4877-a978-a6b308ea8c5f.ppt
dashrimi0
?
optical fibres ppt on its full details.pptx
optical fibres ppt on its full details.pptxoptical fibres ppt on its full details.pptx
optical fibres ppt on its full details.pptx
sashiP
?
Introduction-to-Stack-Instruction.pptxpptppt
Introduction-to-Stack-Instruction.pptxpptpptIntroduction-to-Stack-Instruction.pptxpptppt
Introduction-to-Stack-Instruction.pptxpptppt
suhas060606
?
芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models
芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models
芙坪茶氏Y創_Data-Centric AI in The Age of Large Language Models
鰻粥京晦粥皆幄塀氏芙
?
How to start and then move forward in IT
How to start and then move forward in ITHow to start and then move forward in IT
How to start and then move forward in IT
Marian Marinov
?
Smart Manufacturing with Unified Namespace
Smart Manufacturing with Unified NamespaceSmart Manufacturing with Unified Namespace
Smart Manufacturing with Unified Namespace
Ponraj RK
?
study of impact behaviour of dual material for energy absorption
study of impact behaviour of dual material for energy absorptionstudy of impact behaviour of dual material for energy absorption
study of impact behaviour of dual material for energy absorption
AmitChauhan352669
?
The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...
The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...
The Mumbai Metropolitan Region Development Authority (MMRDA) was established ...
ivargarud
?
Electronic Commerce - 21 and 22 Sept 2024 (3) (1).pptx
Electronic Commerce - 21 and 22 Sept 2024 (3) (1).pptxElectronic Commerce - 21 and 22 Sept 2024 (3) (1).pptx
Electronic Commerce - 21 and 22 Sept 2024 (3) (1).pptx
livacoh815
?

Firefly algorithm

  • 1. % ======================================================== % % Files of the Matlab programs included in the book: % % Xin-She Yang, Nature-Inspired Metaheuristic Algorithms, % % Second Edition, Luniver Press, (2010). www.luniver.com % % ======================================================== % % -------------------------------------------------------- % % Firefly Algorithm for constrained optimization using % % for the design of a spring (benchmark) % % by Xin-She Yang (Cambridge University) Copyright @2009 % % -------------------------------------------------------- % function fa_ndim % parameters [n N_iteration alpha betamin gamma] para=[20 500 0.5 0.2 1]; help fa_ndim.m % Simple bounds/limits for d-dimensional problems d=15; Lb=zeros(1,d); Ub=2*ones(1,d); % Initial random guess u0=Lb+(Ub-Lb).*rand(1,d); [u,fval,NumEval]=ffa_mincon(@cost,u0,Lb,Ub,para); % Display results bestsolution=u bestojb=fval total_number_of_function_evaluations=NumEval %%% Put your own cost/objective function here --------%%% %% Cost or Objective function function z=cost(x) % Exact solutions should be (1,1,...,1) z=sum((x-1).^2); %%% End of the part to be modified -------------------%%% %%% --------------------------------------------------%%% %%% Do not modify the following codes unless you want %%% %%% to improve its performance etc %%% % ------------------------------------------------------- % ===Start of the Firefly Algorithm Implementation ====== % Lb = lower bounds/limits % Ub = upper bounds/limits % para == optional (to control the Firefly algorithm) % Outputs: nbest = the best solution found so far % fbest = the best objective value % NumEval = number of evaluations: n*MaxGeneration % Optional: % The alpha can be reduced (as to reduce the randomness) % --------------------------------------------------------- % Start FA function [nbest,fbest,NumEval]... =ffa_mincon(fhandle,u0, Lb, Ub, para) % Check input parameters (otherwise set as default values) if nargin<5, para=[20 500 0.25 0.20 1]; end if nargin<4, Ub=[]; end if nargin<3, Lb=[]; end if nargin<2,
  • 2. disp('Usuage: FA_mincon(@cost,u0,Lb,Ub,para)'); end % n=number of fireflies % MaxGeneration=number of pseudo time steps % ------------------------------------------------ % alpha=0.25; % Randomness 0--1 (highly random) % betamn=0.20; % minimum value of beta % gamma=1; % Absorption coefficient % ------------------------------------------------ n=para(1); MaxGeneration=para(2); alpha=para(3); betamin=para(4); gamma=para(5); % Total number of function evaluations NumEval=n*MaxGeneration; % Check if the upper bound & lower bound are the same size if length(Lb) ~=length(Ub), disp('Simple bounds/limits are improper!'); return end % Calcualte dimension d=length(u0); % Initial values of an array zn=ones(n,1)*10^100; % ------------------------------------------------ % generating the initial locations of n fireflies [ns,Lightn]=init_ffa(n,d,Lb,Ub,u0); % Iterations or pseudo time marching for k=1:MaxGeneration, %%%%% start iterations % This line of reducing alpha is optional alpha=alpha_new(alpha,MaxGeneration); % Evaluate new solutions (for all n fireflies) for i=1:n, zn(i)=fhandle(ns(i,:)); Lightn(i)=zn(i); end % Ranking fireflies by their light intensity/objectives [Lightn,Index]=sort(zn); ns_tmp=ns; for i=1:n, ns(i,:)=ns_tmp(Index(i),:); end %% Find the current best nso=ns; Lighto=Lightn; nbest=ns(1,:); Lightbest=Lightn(1); % For output only fbest=Lightbest; % Move all fireflies to the better locations [ns]=ffa_move(n,d,ns,Lightn,nso,Lighto,nbest,... Lightbest,alpha,betamin,gamma,Lb,Ub); end %%%%% end of iterations % -------------------------------------------------------
  • 3. % ----- All the subfunctions are listed here ------------ % The initial locations of n fireflies function [ns,Lightn]=init_ffa(n,d,Lb,Ub,u0) % if there are bounds/limits, if length(Lb)>0, for i=1:n, ns(i,:)=Lb+(Ub-Lb).*rand(1,d); end else % generate solutions around the random guess for i=1:n, ns(i,:)=u0+randn(1,d); end end % initial value before function evaluations Lightn=ones(n,1)*10^100; % Move all fireflies toward brighter ones function [ns]=ffa_move(n,d,ns,Lightn,nso,Lighto,... nbest,Lightbest,alpha,betamin,gamma,Lb,Ub) % Scaling of the system scale=abs(Ub-Lb); % Updating fireflies for i=1:n, % The attractiveness parameter beta=exp(-gamma*r) for j=1:n, r=sqrt(sum((ns(i,:)-ns(j,:)).^2)); % Update moves if Lightn(i)>Lighto(j), % Brighter and more attractive beta0=1; beta=(beta0-betamin)*exp(-gamma*r.^2)+betamin; tmpf=alpha.*(rand(1,d)-0.5).*scale; ns(i,:)=ns(i,:).*(1-beta)+nso(j,:).*beta+tmpf; end end % end for j end % end for i % Check if the updated solutions/locations are within limits [ns]=findlimits(n,ns,Lb,Ub); % This function is optional, as it is not in the original FA % The idea to reduce randomness is to increase the convergence, % however, if you reduce randomness too quickly, then premature % convergence can occur. So use with care. function alpha=alpha_new(alpha,NGen) % alpha_n=alpha_0(1-delta)^NGen=10^(-4); % alpha_0=0.9 delta=1-(10^(-4)/0.9)^(1/NGen); alpha=(1-delta)*alpha; % Make sure the fireflies are within the bounds/limits function [ns]=findlimits(n,ns,Lb,Ub) for i=1:n, % Apply the lower bound ns_tmp=ns(i,:); 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
  • 4. ns(i,:)=ns_tmp; end %% ==== End of Firefly Algorithm implementation ======