?? frist.m
字號:
function [fristx,fcmax,objopt,xpop]=frist(xpop,tpop,res_flg,pop,gk,hk,cmax,n,tmax)
% 確定群體xpop(pop,n)中的最優(yōu)染色體fristx。
% 求最優(yōu)染色體的目標函數(shù)值或罰函數(shù)值fitopt(tpop)。
% 求最差染色體的目標函數(shù)值或罰函數(shù)值fcmax。
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
if res_flg>0
%---------------------------------%
fenFx=zeros(1,pop);
chxyy=zeros(1,n);
for i=1:pop % 計算xpop的罰函數(shù)值。
fenFx(1,i)=fenelize(xpop(i,:),gk,hk,tpop+1,tmax);
end
for i=1:pop-1 % 冒泡法把染色體按罰函數(shù)值排升序。
nm=pop-i;
for j=1:nm
if fenFx(1,j)>fenFx(1,j+1)
chxyy(1,:)=xpop(j,:);
xpop(j,:)=xpop(j+1,:);
xpop(j+1,:)=chxyy(1,:);
changefen=fenFx(1,j);
fenFx(1,j)=fenFx(1,j+1);
fenFx(1,j+1)=changefen;
end
end
end
%---------------------------------%
for i=pop:-1:1
if fenFx(1,i)~=inf
%fenFx(1,i)=inf時說明該染色體超過目標函數(shù)定義域
fcmax=fenFx(1,i);
break
end
end
fristx=xpop(1,:);
objopt=fenFx(1,1); % 輸出最優(yōu)染色體的懲罰函數(shù)值
% objopt=objfunction(fristx); % 用于程序調試,輸出最優(yōu)染色體的目標函數(shù)值
else
%---------------------------------%
chxyy=zeros(1,n);
for i=1:pop % 計算xpop的目標函數(shù)。
objFx(1,i)=objfunction(xpop(i,:));
end
for i=1:pop-1 % 冒泡法把染色體按目標函數(shù)排升序。
nm=pop-i;
for j=1:nm
if objFx(1,j)>objFx(1,j+1)
chxyy(1,:)=xpop(j,:);
xpop(j,:)=xpop(j+1,:);
xpop(j+1,:)=chxyy(1,:);
changeobj=objFx(1,j);
objFx(1,j)=objFx(1,j+1);
objFx(1,j+1)=changeobj;
end
end
end
%---------------------------------%
fcmax=objFx(1,pop);
objopt=objFx(1,1);
fristx(1,:)=xpop(1,:);
end
% fitfunction為求染色體適應值的函數(shù)
% objfuncction為求目標函數(shù)值的函數(shù)。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -