如何使用模拟退火优化实现Kreisselmeier Steinhauser(KS)功能? 我的带KS函数的SA代码如下:
while (Gen < GenMax )
while iter > 0 %PerturbIter
NewZ = PerturbZ(CurZ);
NewX = lb + (ub-lb).*(sin(NewZ)).^2;
x0 = NewX;
NewFitness = KS(NewX,x0);
Delta_Cost = NewFitness - CurFitness;
if Delta_Cost <= 0
CurZ = NewZ; CurX = NewX;
CurCost = NewFitness;
if NewFitness < BestFitness
BestZ = NewZ; BestX = NewX;
BestFitness = NewFitness;
end
else
if rand() < exp(-Delta_Cost/T)
CurZ = NewZ; CurX = NewX;
CurFitness = NewFitness;
end
end
iter = iter - 1;
%x0 = BestX;
end
figure(1), hold on
plot(Gen,BestFitness,'-md','MarkerEdgeColor','b','MarkerFaceColor','b','MarkerSize',3)
T = Cooling(T);
Gen = Gen+1;
iter = PerturbIter;
end
KS功能实现如下:
function fun = ksfunc(x, x0, objfun, confun, rho)
obj = objfun(x);
[con,coneq] = confun(x);
[con0,coneq] = confun(x0);
temp = obj./objfun(x0) - 1 - max(con0);
temp = [temp; con];
fmax = max(temp);
summ = sum( exp( rho*(temp - fmax) ));
fun = fmax + log(summ)/rho;