- 0
- 0
- 约1.18万字
- 约 13页
- 2019-10-04 发布于湖北
- 举报
%% 清空环境变量
clc
clear
%% 粒子初始化
%粒子群算法中的两个参数
c1=1.49445;
c2=1.49445;
%最大最小权值
wmax=0.9;
wmin=0.1;
%最大最小速度
Vmax=0.03;
Vmin=-0.03;
%最大最小个体
popmax=0.3;
popmin=-0.3;
maxgen=50; % 进化次数
sizepop=20; %种群规模
%随机产生一个种群
for i=1:sizepop
pop(i,:)=0.03*rand(1,45); %个体编码
fitness(i)=fun(pop(i,:)); %染色体的适应度
V(i,:)=0.003*rands(1,45); %初始化速度
end
%% 初始种群极值
%找最好的染色体
[bestfitness bestindex]=min(fitness);
zbest=pop(bestindex,:); %全局最佳
gbest=pop; %个体最佳
fitnessgbest=fitness; %个体最佳适应度值
fitnesszbest=bestfitness; %全局最佳适应度值
%% 迭代寻优
for i=1:maxgen
i
for j=1:sizepop
原创力文档

文档评论(0)