算法 matlab_MATLAB遗传算法及其实现

点击上方蓝字关注“公众号”

a06308e366ca3c80f03bcda54463b660.gif

MATLAB遗传算法及其实现

遗传算法以一种群体中的所有个体为对象,并利用随机化技术指导对一个被编码的参数空间进行高效搜索。

其中,选择、交叉和变异构成了遗传算法的遗传操作;参数编码初始群体的设定适应度函数的设计遗传操作设计控制参数设定等5个要素组成了遗传算法的核心内容。

09f92f2ecb10292c1d018063454180aa.gif

主要步骤如下所示:    

(1)编码:GA在进行搜索之前先将解空间的解数据表示成遗传空间的基因型串结构数据,这些串结构数据的不同组合便构成了不同的点。

(2)初始群体的生成:随机产生N个初始串结构数据,每个串结构数据称为一个个体,N个个体构成了—个群体。 

GA以这N个串结构数据作为初始点开始迭代。

(3)适应性值评估检测:适应性函数表明个体或解的优劣性。对于不同的问题,适应性函数的定义方式也不同。

(4)选择:选择的目的是为了从当前群体个选出优良的个体,使它们有机会作为父代为下一代繁殖子孙。

遗传算法通过选择过程体现这一思想,进行选择的原则是适应性强的个体为下一代贡献一个或多个后代的概率大。

选择实现了达尔文的适者生存原则。

(5)交叉:交叉操作是遗传算法中最主要的遗传操作。

通过交叉操作可以得到新一代个体,新个体组合了其父辈个体的特性。交叉体现了信息交换的思想。

(6)变异:变异首先在群体中随机选择一个个体,对于选中的个体以一定的概率随机地改变串结构数据中某个串的值。

同生物界一样,GA中变异发生的概率很低,通常取值在0.001~0.01之间。变异为新个体的产中提供了机会。

d717bc326a6ba1ec8124284dbaab0c1f.gif 8949f581678cf7ee587ae50ab44b43ab.png 1fc1dbaa1d1411462b486dd691bc07e9.png

遗传算法的MATLAB实现

需要如下主函数:

   编码和种群生成

 function [pop] = initializega(num,bounds,evalFN,evalOps,options)

% pop    - the initial, evaluated, random population

% num    - the size of the population, i.e. the number to create

% bounds - the number of permutations in an individual (e.g., number

%          of cities in a tsp

% evalFN - the evaluation fn, usually the name of the .m file for evaluation

% evalOps- any options to be passed to the eval function defaults [ ]

% options- options to the initialize function, ie. [eps, float/binary, prec]

%        where eps is the epsilon value and the second option is 1 for

%     orderOps, prec is the precision of the variables defaults [1e-6 1]

01

交叉

function [c1,c2] = arithXover(p1,p2,bounds,Ops)

% Arith crossover takes two parents P1,P2 and performs an interpolation

% along the line formed by the two parents.

%

% function [c1,c2] = arithXover(p1,p2,bounds,Ops)

% p1      - the first parent ( [solution string function value] )

% p2      - t

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值