|
改进的人工蜂群算法(自适应柯西变异的人工蜂群算法)的函数优化
百度网盘链接:
链接:https://pan.baidu.com/s/1qlatOJFlC7ddyqkVe348zg
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
- % 自适应柯西分布的人工蜂群算法函数寻优
- % Improved - ABC算法
- clc,clear,close all
- warning off
- format longG
- %*************** 待优化求解函数 **************
- % fun=@Ackley_Fun;
- fun=@Griewank_Fun;
- % fun=@Rastrigin_Fun;
- % fun=@Shaffer_Fun;
- %*********** 函数在(0,0)处有极小值0 ***********
- % ABC 参数初始化
- maxiter = 100; % 迭代次数
- sizepop = 50; % 种群数量
- popmin1 = -1; popmax1 = 1; % x1
- popmin2 = -1; popmax2 = 1; % x2
- trail(1:sizepop,1) = 0; % 未找到更优解的迭代次数
- limit = sizepop; % 拖尾最大次数
- wmin = 0.25;
- wmax = 0.75;
- %% 初始化种群
- for i=1:sizepop
- x1 = popmin1+(popmax1-popmin1)*rand;
- x2 = popmin2+(popmax2-popmin2)*rand;
- pop(i,:) = [x1, x2];
- fitness(i) = fun([x1,x2]); % 适应度函数值--目标函数值--最小目标函数值
- end
- % 记录一组最优值
- [bestfitness,bestindex]=min(fitness);
- zbest=pop(bestindex,:); %全局最佳
- fitnesszbest=bestfitness; %全局最佳适应度值
- %% 迭代寻优
- for i=1:maxiter
-
- % 采蜜峰开始工作
- for j=1:sizepop
-
- % 自适应权重
- w = wmin+(wmax-wmin)*( fitness(j)-min(fitness) ) ./ (mean(fitness)-min(fitness)+eps);
-
- % 选择采蜜的个体
- x2y = randi(2); % 两个未知数
- % 选择相连的种群
- neighbour = randi(sizepop);
- % neighbour != j
- while( neighbour==j )
- neighbour = randi(sizepop);
- end
-
- % 种群更新(解)
- tempx = pop(j,:); % 当前的解
- tempx(x2y) = pop(j,x2y) + (pop(j,x2y)-pop(neighbour,x2y))*(rand-0.5)*w;
-
- % x1 越界限制
- if tempx(1)>popmax1
- tempx(1)=popmax1;
- end
- if tempx(1)<popmin1
- tempx(1)=popmin1;
- end
- % x2 越界限制
- if tempx(2)>popmax2
- tempx(2)=popmax2;
- end
- if tempx(2)<popmin2
- tempx(2)=popmin2;
- end
-
- % 适应度更新
- temp_fitness = fun( tempx ); % 当前的适应度函数值--目标函数值--最小目标函数值
- % 比较 个体间比较
- if temp_fitness<fitness(j)
- fitness(j) = temp_fitness;
- pop(j,:) = tempx;
- end
- if temp_fitness<bestfitness
- bestfitness = temp_fitness;
- zbest = tempx;
- end
- end
-
- % 观察峰
- % 计算概率
- prob = 0.9*fitness./max(fitness) + 0.1;
- for j=1:sizepop
- if(rand<prob(j))
-
- % 自适应权重
- w = wmin+(wmax-wmin)*( fitness(j)-min(fitness) ) ./ (mean(fitness)-min(fitness)+eps);
- % 选择采蜜的个体
- x2y = randi(2); % 两个未知数
- % 选择相连的种群
- neighbour = randi(sizepop);
- % neighbour != j
- while( neighbour==j )
- neighbour = randi(sizepop);
- end
- % 种群更新(解)
- tempx = pop(j,:); % 当前的解
- tempx(x2y) = pop(j,x2y) + (pop(j,x2y)-pop(neighbour,x2y))*(rand-0.5)*w;
- % x1 越界限制
- if tempx(1)>popmax1
- tempx(1)=popmax1;
- end
- if tempx(1)<popmin1
- tempx(1)=popmin1;
- end
- % x2 越界限制
- if tempx(2)>popmax2
- tempx(2)=popmax2;
- end
- if tempx(2)<popmin2
- tempx(2)=popmin2;
- end
- % 适应度更新
- temp_fitness = fun( tempx ); % 当前的适应度函数值--目标函数值--最小目标函数值
- % 比较 个体间比较
- if temp_fitness<fitness(j)
- fitness(j) = temp_fitness;
- pop(j,:) = tempx;
- end
- if temp_fitness<bestfitness
- bestfitness = temp_fitness;
- zbest = tempx;
- else
- trail(j) = trail(j)+1;
- end
- end
- end
-
- % 侦察峰开始工作
- [maxTrial, index] = max(trail);
- index = index(1);
- if(maxTrial(1)>limit)
- x1 = popmin1+(popmax1-popmin1)* cauchypdf( rand );
- x2 = popmin2+(popmax2-popmin2)* cauchypdf( rand );
- pop(index,:) = [x1, x2];
- fitness(index) = fun([x1,x2]); % 适应度函数值--目标函数值--最小目标函数值
- end
-
- fitness_iter(i) = bestfitness;
- end
- %% 结果显示
- disp('最优解')
- disp(zbest)
- fprintf('\n')
- disp(['最优解对应的适应度值:', num2str(min(fitness_iter))])
- figure('color',[1,1,1])
- plot(fitness_iter,'ro-','linewidth',2)
复制代码
|
|