|
第14章基于PSO的机构优化,在处理约束问题时,是否是Deb的可行规则?
代码如下:
for i=1:Np
%若都一个可行,另一个不可行,则无条件选择可行解
if (violent1(x(i,:))<=0&&violent2(x(i,:))<=0) && (violent1(mid(i,:))>0&&violent2(mid(i,:))>0)
NextGeneration(i,:)=x(i,:);
end
%若都可行,选择适应度小的进入下一代
if (violent1(x(i,:))<=0&&violent2(x(i,:))<=0) && (violent1(mid(i,:))<=0&&violent2(mid(i,:))<=0)
if fitness2(x(i,:))<=fitness2(mid(i,:))
NextGeneration(i,:)=x(i,:);
else
NextGeneration(i,:)=mid(i,:);
end
end
%若都一个可行,另一个不可行,则无条件选择可行解
if (violent1(x(i,:))>0&&violent2(x(i,:))>0) && (violent1(mid(i,:))<=0&&violent2(mid(i,:))<=0)
NextGeneration(i,:)=mid(i,:);
end
%若两个都不可行,选择违背约束小的进入下一代
if (violent1(x(i,:))>0&&violent2(x(i,:))>0) && (violent1(mid(i,:))>0&&violent2(mid(i,:))>0)
if violent1(x(i,:))<violent1(mid(i,:))&violent2(x(i,:))<violent2(mid(i,:))
NextGeneration(i,:)=x(i,:);
else
NextGeneration(i,:)=mid(i,:);
end
end
end
|
|