【优化求解】基于磷虾群算法求解最优目标matlab源码
作者:互联网
1 简介
磷虾群算法(Krill Herd Algorithm,KHA)是 Gandomi 等于2012年提出的一种新型优化算法 。具体原理如下:
2 部分代码
% Krill Herd Algorithm V 1.1 % Main paper: % Gandomi A.H., Alavi A.H., Krill Herd: A New Bio-Inspired Optimization Algorithm. % Communications in Nonlinear Science and Numerical Simulation, function KH clc; close all; clear all format long %% Initial Parameter Setting NR = 10; % Number if Runs NK = 25; % Number if Krills MI = 200; % Maximum Iteration C_flag = 1; % Crossover flag [Yes=1] % Bounds (Normalize search space in case of highly imbalanced search space) UB = 10*ones(1,10); LB = -10*ones(1,10); NP = length(LB); % Number if Parameter(s) Dt = mean(abs(UB-LB))/2; % Scale Factor F = zeros(NP,NK);D = zeros(1,NK);N = zeros(NP,NK); %R = zeros(NP,NK); Vf = 0.02; Dmax = 0.005; Nmax = 0.01; Sr = 0; %% Optimization & Simulation for nr = 1:NR %Initial Krills positions for z1 = 1:NP X(z1,:) = LB(z1) + (UB(z1) - LB(z1)).*rand(1,NK); end for z2 = 1:NK K(z2)=cost(X(:,z2)); end Kib=K; Xib=X; [Kgb(1,nr), A] = min(K); Xgb(:,1,nr) = X(:,A); for j = 1:MI % Virtual Food for ll = 1:NP; Sf(ll) = (sum(X(ll,:)./K)); end Xf(:,j) = Sf./(sum(1./K)); %Food Location Xf(:,j) =findlimits(Xf(:,j)',LB,UB,Xgb(:,j,nr)');% Bounds Checking Kf(j) = cost(Xf(:,j)); if 2<=j if Kf(j-1)<Kf(j) Xf(:,j) = Xf(:,j-1); Kf(j) = Kf(j-1); end end Kw_Kgb = max(K)-Kgb(j,nr); w = (0.1+0.8*(1-j/MI)); for i = 1:NK % Calculation of distances Rf = Xf(:,j)-X(:,i); Rgb = Xgb(:,j,nr)-X(:,i); for ii = 1:NK RR(:,ii) = X(:,ii)-X(:,i); end R = sqrt(sum(RR.*RR)); % % % % % % % % % % % % % Movement Induced % % % % % % % % % % %% Post-Processing [Best, Ron_No] = min(Kgb(end,:)) Xgb(:,end,Ron_No) Mean = mean(Kgb(end,:)) Worst = max(Kgb(end,:)) Standard_Deviation = std(Kgb(end,:)) % Convergence plot of the best run semilogy(1:MI+1,Kgb(:,Ron_No),1:MI+1,mean(Kgb')) xlabel('{\itNo. of Iterations}') ylabel('{\itf}({\bfx_{best}})') legend('Best run values','Average run values') img =gcf; %获取当前画图的句柄 print(img, '-dpng', '-r600', './img.png') %即可得到对应格式和期望dpi的图像
3 仿真结果
4 参考文献
[1]肖雄、高渺、陈功贵. "基于混合混沌磷虾算法的短期水火电调度研究." 计算机工程与科学 42.9(2020):12.
标签:10,NK,LB,求解,源码,matlab,NP,nr,z1 来源: https://blog.csdn.net/qq_59747472/article/details/120939304