Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]()
MATLAB实现遗传算法 如何画出进化代数和适应值的图?急求
|
![]() |
![]() |
![]() |
#2 |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]()
测试函数如:F=x^3-60*x^2+900*x+100;
真的很急,忘大神指教 |
![]() |
![]() |
![]() |
#3 |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]() |
![]() |
![]() |
![]() |
#4 | |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]() 引用:
x=zeros(NP,L); for i=1:NP x(i, ![]() fx(i)=fitness(Dec(a,b,x(i, ![]() end for k=1:NG sumfx=sum(fx); %所有个体适应值之和 px=fx/sumfx; %所有个体适应值的平均值 ppx=0; ppx(1)=px(1); for i=2:NP %用于轮盘赌策略的累加 ppx(i)=ppx(i-1)+px(i); end for i=1:NP sita=rand(); for n=1:NP if sita<=ppx(n) SelFather=n; %根据轮盘赌策略确定的父亲 break; end |
|
![]() |
![]() |
![]() |
#5 | |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]() 引用:
Selmother=floor(rand()*(NP-1))+1; %随机选择母亲 posCut=floor(rand()*(L-2))+1; %随机选择交叉点 r1=rand(); if r1<=pc %交叉 nx(i,1 ![]() ![]() nx(i,(posCut+1):L)=x(Selmother,(posCut+1):L); r2=rand(); if r2<=pm %变异 posMut=round(rand()*(L-1)+1); nx(i,posMut)=~nx(i,posMut); end |
|
![]() |
![]() |
![]() |
#6 | |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]() 引用:
nx(i, ![]() ![]() end end x=nx; for i=1:NP |
|
![]() |
![]() |
![]() |
#7 |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]() |
![]() |
![]() |
![]() |
#8 | |
初级会员
注册日期: 2013-03-11
帖子: 9
声望力: 0 ![]() |
![]() 引用:
fv=fitx; %取个体中的最好值作为最终结果 xv=Dec(a,b,x(i, ![]() end end function result=Initial(length) %初始化函数 for i=1:length r=rand(); result(i)=round(r); end function y=Dec(a,b,x,L) %二进制编码转换为十进制编码 base=2.^((L-1):-1:0); y=dot(base,x); y=a+y*(b-a)/(2^L-1); %[xv,fv]=GA(@fitness,0,30,50,100,0.9,0.04,0.01) |
|
![]() |
![]() |