📄 gs_ls_chga.m
字号:
%pause
[fristx,fcmax,objopt,xpop]=frist(xpop,tpop,res_flg,pop,gk,hk,cmax,n,tmax); %对xpop评价并输出3个参数
cmax=fcmax;
objoptmal(1,tpop)=objopt; %纪录每代最优目标函数值
if (tpop/20-floor(tpop/20))==0
fprintf('%5.0f代进化已完成\n',tpop);
end
if (tpop>=0.5*tmax|tpop>300)&con_rule==0
if abs(objoptmal(1,tpop)-objoptmal(1,tpop-100))<=1e-8 %100代目标函数值无改善,则认为收敛
tmax1=tpop;
con_flag=1; %收敛标志
break
end
end
%%%%%%%%%%%%%%%%%tmax/3 中的3可调%%%%%%%%%%%%
for i=1:pop,FF(i,:)=f1; end
if nn>nn0
[Ntemp1,Ntemp2]=size(FF);
for j=1:Ntemp2
ftemp1=FF(:,j);ff0=f0(j,1);
for i=1:Ntemp1
if ff0>ftemp1(i,1),ff0=ftemp1(i,1); end
end
f0(j,1)=ff0;
end
end
%%%%%%%%%%%%%%%%%%%%%%
end
if con_flag~=1
tmax1=tmax;
end
%++++++++++对最后群体的目标函数值进行计算++++++++++++++++++%
for i=1:pop % 计算xpop的目标函数值。
objFx(i)=objfunction(xpop(i,:));
end
% close(h);
% 在frist文件中已按惩罚函数值或目标函数值对最后群体xpop排升序
%++++++++++++输出最后优化群体到solution.txt文件+++++++++%
ttime1=cputime;
ttime=ttime1-ttime0;
fid=fopen('solution.txt','wt');
fprintf(fid,'\n\t\t*-----灰熵_混合离散变量-混沌遗传算法数据输出文件solution.txt----*\n');
fprintf(fid,'\t\t*-----------最后群体及其目标函数值、约束函数值-------------*\n');
fprintf(fid,'\n\t\t既定进化代数为:%5.0f\n',tmax);
fprintf(fid,'\t\t实际进化代数为:%5.0f\n',tmax1);
fprintf(fid,'\t\t程序运行占用cup时间为:%5.0f秒\n\n',ttime);
fprintf(fid,'\t以下按从优到劣编号列出各染色体,对有、无约束问题均按适应值排序。\n');
for i=1:pop
%%%%%%%%%%%%%%
fprintf(fid,'#%5.0f号染色体目标函数值(灰色关联度)为%6.8f\t\n',i,objFx(i));
fprintf(fid,'目标函数值f为:\n\n');
x=xpop(i,:);f11=objfunction(x);
[nf,nf1]=size(f1);
for j=1:nf
if j/4-floor(j/4)~=0
fprintf(fid,'\tf(%2.0f)=%6.8f;',j,f1(j));
else
fprintf(fid,'f(%2.0f)=%6.8f;\n',j,f1(j));
end
end
fprintf(fid,'设计变量为:\n\n');
for j=1:n
if j/4-floor(j/4)~=0
fprintf(fid,'\tx(%3.0f)=%6.8f;',j,xpop(i,j));
else
fprintf(fid,'x(%3.0f)=%6.8f;\n',j,xpop(i,j));
end
end
fprintf(fid,'\n\n');
%%%%%%%%%%%%%%%%%
if res_flg
% fprintf(fid,'其约束函数值为:\n');
[res_gx,res_hx]=restrain(fristx,gk,hk);
if gk>0
fprintf(fid,'\n不等式约束函数值:\n');
for i=1:gk
if i/4-floor(i/4)~=0
fprintf(fid,'\tgx(%2.0f)=%6.8f;',i,-res_gx(i,1));
else
fprintf(fid,'gx(%2.0f)=%6.8f;\n',i,-res_gx(i,1));
end
end
else
fprintf(fid,'\n无不等式约束\n');
end
if hk
fprintf(fid,'\n等式约束函数值:\n');
for i=1:hk
if i/4-floor(i/4)~=0
fprintf(fid,'\thx(%2.0f)=%6.8f;',i,res_hx(i,1));
else
fprintf(fid,'hx(%2.0f)=%6.8f;\n',i,res_hx(i,1));
end
end
else
fprintf(fid,'\n无等式约束\n');
end
else
fprintf(fid,'\n属无约束优化设计问题\n');
end
end
%%%%%%%%%%%%%%%%%%%%
fprintf(fid,'函数值f0为:\n\n');
for j=1:nf
if j/4-floor(j/4)~=0
fprintf(fid,'\tf(%2.0f)=%6.8f;',j,f0(j));
else
fprintf(fid,'f(%2.0f)=%6.8f;\n',j,f0(j));
end
end
%%%%%%%%%%%%%%%%%
fprintf(fid,'\n第1号染色体表示最优设计点的设计变量。\n');
if res_flg
fprintf(fid,'其约束函数值为:\n');
[res_gx,res_hx]=restrain(fristx,gk,hk);
if gk
fprintf(fid,'\n不等式约束函数值(注意:大于等于0为满足约束条件):\n');
for i=1:gk
if i/4-floor(i/4)~=0
fprintf(fid,'\tgx(%2.0f)=%6.8f;',i,-res_gx(i,1));
else
fprintf(fid,'gx(%2.0f)=%6.8f;\n',i,-res_gx(i,1));
end
end
else
fprintf(fid,'\n无不等式约束\n');
end
if hk
fprintf(fid,'\n等式约束函数值:\n');
for i=1:hk
if i/4-floor(i/4)~=0
fprintf(fid,'\thx(%2.0f)=%6.8f;',i,res_hx(i,1));
else
fprintf(fid,'hx(%2.0f)=%6.8f;\n',i,res_hx(i,1));
end
end
else
fprintf(fid,'\n无等式约束\n');
end
else
fprintf(fid,'\n属无约束优化设计问题\n');
end
fclose(fid);
%++++++++++++++绘制优化进程目标函数变化图+++++++++++++++++%
xgh=[1:tmax1];
ygh=objoptmal(1,1:tmax1);
plot(xgh,ygh,'r-');
xlabel('进化代数');
if res_flg
ylabel('惩罚函数值(有约束问题)');
else
ylabel('目标函数值(无约束问题)');
end
title('灰色混合离散变量-混沌遗传优化算法进程图');
%+++++++++++++程序运行结束++++++++++++++%
fprintf('\t\t*--------------恭喜您!程序运行成功!----------------*\n');
fprintf('\t\t运行结果请查阅solution.txt文件和GS_LS_ChGA优化算法进程图\n');
fprintf('\t\t请用您喜欢的文件名保存GS_LS_ChGA优化算法进程图\n');
fprintf('\t\t程序运行占用cup时间为%5.0f秒\n',ttime);
fprintf('\t\t谢谢使用灰熵_灰色混合离散变量-混沌遗传复合优化算法软件GS_LS_ChGA1.0!\n')
%%%%
format long;
if GreyEntropy==1 & kg==1,
AA='灰熵_灰色混合离散变量-混沌遗传复合优化算法f=';
elseif GreyEntropy==2 & kg==1,
AA='优度_灰色混合离散变量-混沌遗传复合优化算法f=';
else
AA='灰色混合离散变量-混沌遗传复合优化算法f=';
end
if kg==1
if kdegree==1,BB='absolute degree of grey incidence,第';end
if kdegree==2,BB='Deng Type degree of grey incidencer,要多运行几次,第';end
if kdegree==3,BB='Relative degree of grey incidenc,第';end
if kdegree==4,BB='Compositive degree of grey incidenc,第';end
if kdegree==5,BB='Improved relative degree of grey incidenc,第';end
if kdegree==6,BB='Improved absolue degree of grey incidenc,第';end
if kdegree==7,BB='Improved compositive degree of grey incidenc,第';end
if kdegree==8,BB='B type degree of grey incidenc,要多运行几次,第';end
if kdegree==9,BB='C type degree of grey incidenc,要多运行几次,第';end
else
BB='kg=3 用f(x)单目标计算';
end
disp([AA,num2str(objFx(1),10),',(',BB,num2str(kexample),'题)'])
disp(['变量X=',num2str(xpop(1,:),8)]);
x=xpop(1,:);objFx=objfunction(x);
disp(['目标函数值F=',num2str(f1')]);
[res_gx,res_hx]=restrain(x,gk,hk);
xx=-res_gx';
disp(['约束函数(gx<=0形式),Gx=',num2str(xx)]);
%%%%%%%%%%%%%%%%%%%%%%%%%2007.08.16.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -