遗传算法优化matlab,遗传算法求最优化问题的MATLAB程序实现

Matlab7.0编写的变异过程程序3:

function new_pop = mutation(new_pop, stringlength, dimension, pm)

new_popsize = size (new_pop, 1);

for i = 1: new_popsize

if rand

mpoint = round (rand (1, dimension) * (stringlength -1))+1;

for j =1: dimension

new_pop (i, (j-1)* stringlength+ mpoint (j)) =

1- new_pop (i, (j-1)* stringlength+ mpoint (j));

end

end

end

Matlab7.0编写的解码程序4:

function pop = decoding(pop, stringlength, dimension, x_bound)

popsize = size (pop, 1) ;

temp = 2. ^ (stringlength-1: -1: 0) / (2^ stringlength-1) ;

for i = 1: dimension

bound (i) = x_bound (i,2) -x_bound (i,1) ;

end

for i = 1:popsize

for j = 1:dimension

m (:, j) = pop (i, stringlength* (j-1)+1: stringlength*j) ;

end

x=temp*m;

x=x.*bound+ x_bound (:, 1)’ ;

pop (i, dimension* stringlength+1) = funname (x);

end

选择程序5:

function

[temp_generation, k, sign] = constraint_choising (pop, stringlength, dimension, x_bound)

popsize = size (pop, 1) ;

mark = k ;

sign = 1 ;

ss = 1 ;

temp = 2. ^ (stringlength-1: -1: 0) / (2^ stringlength-1) ;

for i = 1: dimension

bound (i) = x_bound (i,2) -x_bound (i,1) ;

for i = 1: popsize

for j = 1: dimension

m (:, j) = pop (i, stringlength* (j-1)+1: strength*j) ;

end

x = temp* m ;

x = x. *bound+ x_ound (:, 1)’ ;

%x = round(x);  %四舍五入取整

if constraint_fun (x) = = 1

temp_generation (ss, :) = pop (i, :) ;

ss = ss+1;

k = l +1;

end

end

if mark = = k

temp_generation = 0;

sign = 0;

end

function

new_generation = producing (pop, popsize, stringlength, dimension, x_bound, pm)

k = 1;

signk = 1;

while k <= popsize

new_pop = cross_over (pop, popsize, stringlength, dimension);

pop = mutation (new_pop, stinglength, dimension, pm);

[temp_generation, k, sign] = constraint_choising (pop, k, stringlength, dimension, x_bound);

if sign = =1

new_generation (signk: k-1, :) = temp_generation;

signk = k;

end

end

function selected = selection (pop, popsize, stringlength, dimension)

popsize_new = size (pop, 1) ;

r = rand (1, popsize) ;

fitness = pop(:, dimension* stringlength+1) ;

fitness = fitness / sum (fitness);

fitness = cumsum (fitness);

for i = 1: popsize

for j = 1: popsize_new

if r(i) <= fitness(j)

selected (i, :) = pop (j, :);

break;

end

end

end

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值