## Appendix A
*abs(UD-Lb);  end  vobest=findlimits(1,vobest,Lb,UD);  vd = escala(1,NVAR,vobest,vub,1);  if strcmpi(tip_var,'discrete')  vd = fa_vdc_vdd(vd,BaseV,1,1,1,1);  end  vo(1,:,kloop) = escala(1,NVAR,vd,vub,0);  end  
% Firefly migration between subpopulations % ========================  
if np>1  startmgr=0.0; % Migration start point  if k > round(startmgr*MaxGeneration)  for jloop=2:randi(np-1):np  for iloop=1:randi(n-1):n  vo(iloop,:,Index(jloop))=vo(iloop,:,Index(1));  end  end  
dspl=zeros(n,1,np);  valuel=zeros(1,NVAR);  value2=zeros(1,NVAR);  for kloop=1:np  for iloop=1:n  value1(1,:)=vo_old(iloop,:,kloop);value2(1,:)=vo(iloop,:,kloop); value3=0; forjloop=1:NVAR value3=value3+(value1(1,jloop)-value2(1,jloop)).^2; end value3=sqrt(value3); dspl(iloop,1,kloop)=value3; end time=time+toc; tic end%Endofmainloop functionfactor=factor_alpha(k,kmax,tc,speed) %Functionforthequadraticreductionofthelphaparameter % %Inputarguments: %k(scalar)currentiteration %kmax(scalar)maximumnumberofiterations %tc(scalar)tcparameter %speed(logic)speed=1/0 fast/slowreduction %ofalphaparameter % %outputarguments: %factor(scalar)alphaparameterreductionfactor %  
function [vo,Lightn]=ffa_move(n,vo,Lightn,alpha,gamma,m,Lb,Ub,...  beta0,NVAR,BaseV,vub,tip_var)  % Function for moving fireflies towards the brightest ones  %  % Input arguments:  % n (scalar) number of fireflies in each  % subpopulation  % vo (vector) optimization variables  % Lightn (vector) fitness function (luminosity)  % alpha (scalar) alpha parameter  % gamma (scalar) gamma parameter  % m (scalar) m parameter  % Lb (vector) lower bound for vo  % Ub (vector) upper bound for vo (ones)  % beta0 (scalar) beta0 parameter  % NVAR (scalar) number of variables  % BaseV (vector) number of commercial steel  % shapes, plates and bolts  % vub (vector) upper bound for design  % variables  % tip_var (string) tip_var = 'discrete' or  %  % 'continuous'  %  % Output arguments:  % vo (vector) optimization variables  % Lightn (vector) fitness function (luminosity)  %  %  
d=length(Lb);  ns_ant=zeros(size(vo));  for i=n:-1:2, % the firefly 'i' is the one that moves  coef=0.7;  if isinf(Lightn(i,1)) || isnan(Lightn(i,1))  Lightn(i,1)=10e4;  end  for j=i-1:-1:1, % firefly 'j' is where firefly 'i' moves  if isinf(Lightn(j,1)) || isnan(Lightn(j,1))  Lightn(j,1)=10e3;  end  if Lightn(i,1)>Lightn(j,1)  rij = sqrt(sum( (vo(i,:) - vo(j,:)).^2));  betaij = beta0.*(1./(1+gamma. *rij.^m));  coef = sin(pi. *coef);  tmpf = coef.*alpha. *1 evy(1,d,1.9). *abs(Ub-Lb);  ns_ant(i,:) = vo(i,:) + (vo(j,:) - vo(i,:)). *betaij + tmpf;  vo(i,:) = findlimits(1,ns_ant(i,:),Lb,Ub);  vd = escala(1,NVAR,vo(i,:),vub,1);if strcmpi(tip_var,'discrete')  vd = fa_vdc_vdd(vd,BaseV,1,1,1,1);  vo(i,:) = escala(1,NVAR,vd,vub,0);  end  end  end  end  
function [vo] = findlimits(n,vo,Lb,Ub)  % Function to check that the position of the fireflies is within Lb and Ub  %  % Input arguments:  % n (scalar) number of fireflies in each  % subpopulation  % vo (vector) optimization variables  % Lb (vector) lower bound for vo  % Ub (vector) upper bound for vo (ones)  % Output arguments:  % vo (vector) optimization variables  
for i = 1:n,  vo_tmp = vo(i,:); % Coordinate assignment by rows  
% Check lower limits  % I is a vector (1,d) containing zeros and ones. If any coordinate  % (variable) is outside its lower limit Lb then a one appears in the  % corresponding column of I.  I = vo_tmp < Lb;  vo_tmp(I) = Lb(I); % Assigns the limit value LB to the coordinate  
% Check upper limits  % J is a vector (1,d) containing zeros and ones.