📄 main.m
字号:
clear all;
num=10;
bounds=[1 35];
N=1000;
cp=0.25;
p=0.04;
L=bounds(2)-bounds(1);
p1=rand(1,num);
for i=1:num
p2(i)=round(p1(i)*L);
x1(i)= p2(i)+bounds(1);
end
n=0;
m=bounds(2);
while m>=1
if mod(m,2)==1
m=round(m/2)-1;
else m=m/2;
end
n=n+1;
end
ymax(1)=min(x1);
x=tetotw (x1,n);
k=2;
while k<=N
[child,y]=select(x,bounds);
if zlfun(y)<zlfun(ymax(k-1))
i=round(rand*(num-1))+1;
child(i)=ymax(k-1);
y=ymax(k-1);
end
ymax(k)=y;
if k==N;
break;
end
q1=tetotw(child,n);
q2=crossover(q1,cp);
x=mutation(q2,p);
k=k+1;
end
subplot(2,1,1)
plot(ymax);
axis ([1,N,bounds(1),bounds(2)]);
title( '极值变化曲线');
for i=1:N
fx=zlfun(ymax(i));
end
subplot(2,1,2)
plot(1:N,fx);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -