资源简介
TLBO 算法是一种新的群智能优化算法,这是关于TLBO基本型的matalb代码,由一个m文件组成。
代码片段和文件信息
clear all
clc
ps= 10; % no of students
nd=2; % no of design variables or no of subjects which are taken by students
ng=50; % no of generations
ni=0; % no of iterations
ub=ones(1nd)*10; %upper boundary to the veriables
lb=ones(1nd)*0; %lower boundary to the veriables
runtime=1;
runtimes=50;
tru=1;
while(tru)
range=repmat((ub-lb)ps1);
lower=repmat(lbps1);
xnewl=rand(psnd).*range+lower; %intial random solution
for i=1:ps % evaluation of objective function
fxnewl(i1)=(xnewl(i1)-xnewl(i2))^2+((xnewl(i1)+xnewl(i2)-10)/3)^2;
end
true=1;
while(true)
ni=ni+1;
%%%%%%%%%%% teacher phase %%%%%%%%
md=mean(xnewl); % mean of the total students
indext=find(fxnewl==min(fxnewl)); % capturing the teacher position using objective function values
bt=indext;
for j=1:nd
bestteacher(1j)=xnewl(bt(11)j);
end
for j=1:nd
diff(1j)=rand*(bestteacher(1j)-md(1j));
end
for i=1:ps
for j=1:nd %%% improving the initial solution in teacher phase
xnew(ij)=xnewl(ij)+diff(1j);
if(xnew(ij)>ub(1j)) % for values goes beyound upper limit
xnew(ij)=ub(1j);
elseif(xnew(ij)
xnew(ij)=lb(1j);
end
end
end
for i=1:ps % evaluating the objective function
fxnew(i1)=(xnew(i1)-xnew(i2))^2+((xnew(i1)+xnew(i2)-10)/3)^2;
fxnewold(i1)=fxnew(i1);
end
for i=1:ps %% applying greedy selection process
if(fxnew(i1)> fxnewl(i1)) % if old value is better then keep it as it is
fxnew(i1)=fxnewl(i1);
% x(i1)=xnew(i1)
%x(i2)=xnew(i2)
%for j=1:nd
% x(ij)=xnew(ij)
%end
xnew(i:)=xnewl(i:);
end
end
%%%%%%%%%%%%%% learner phase %%%%%%%%%%%%%%
indexl=find(fxnew==min(fxnew)); % capturing the best learner position using objective function valuesr
bl=indexl;
for j=1:nd
bestl(1j)=xnew(bl(11)j);
end
for i=1:ps %% improoving the level other learners using best learner
for j=1:nd
xnewl(ij)=xnew(ij)+rand*(bestl(1j)-xnew(ij));
end
end
for i=1:ps % updating the objective function in learner phase
fxnewl(i1)=(xnewl(i1)-xnewl(i2))^2+((xnewl(i1)+xnewl(i2)-10)/3)^2;
globalmin(i1)= fxnewl(i1);
end
if(ni==ng)
ni=0;
true=0;
else
true=1;
end
disp (‘num of iterations‘)
disp (ni)
disp(‘ fxnewl‘)
disp (fxnewl)
end
globalmins(1runtime)=globalmin(ps1)
bgm=min(globalmins)%best global min
wgm=max(globalmins)%worst global min
mgm=mean(globalmins)%mean global min
if(runtime==runtimes)
tru=0;
else
runtime=runtime+1;
end
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2857 2017-11-27 10:32 TLBO基本型\TLBO.m
目录 0 2017-11-27 10:33 TLBO基本型\
- 上一篇:试客系统源码
- 下一篇:2018美赛精美论文模版word版
评论
共有 条评论