-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitial.m
More file actions
35 lines (30 loc) · 1.1 KB
/
initial.m
File metadata and controls
35 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
%程序初始化
gen=100; %设置进化代数
popsize=30; %设置种群规模大小
best_in_history(gen)=inf; %初始化全局历史最优解
best_in_history(:)=inf; %初始化全局历史最优解
max_velocity=0.3; %最大速度限制
best_fitness=inf;
%popnum=1; %设置种群数量
pop(popsize,8)=0; %初始化种群,创建popsize行5列的0矩阵
%种群数组第1列为x轴坐标,第2列为y轴坐标,第3列为x轴速度分量,第4列为y轴速度分量
%第5列为个体最优位置的x轴坐标,第6列为个体最优位置的y轴坐标
%第7列为个体最优适值,第8列为当前个体适应值
for i=1:popsize
pop(i,1)=4*rand()-2; %初始化种群中的粒子位置,值为-2—2,步长为其速度
pop(i,2)=4*rand()-2; %初始化种群中的粒子位置,值为-2—2,步长为其速度
pop(i,5)=pop(i,1); %初始状态下个体最优值等于初始位置
pop(i,6)=pop(i,2); %初始状态下个体最优值等于初始位置
pop(i,3)=rand()*0.02-0.01; %初始化种群微粒速度,值为-0.01—0.01,间隔为0.0001
pop(i,4)=rand()*0.02-0.01; %初始化种群微粒速度,值为-0.01—0.01,间隔为0.0001
pop(i,7)=inf;
pop(i,8)=inf;
end
c1=2;
c2=2;
x_min=-2;
y_min=-2;
x_max=2;
y_max=2;
gbest_x=pop(1,1); %全局最优初始值为种群第一个粒子的位置
gbest_y=pop(1,2);