急求遗传算法 变量为整数的整数编码函数的matlab程序

查看: 8934|回复: 16|关注: 0
遗传算法求最优化问题的MATLAB程序实现
<h1 style="color:# 麦片财富积分
新手, 积分 5, 距离下一级还需 45 积分
程序1是随机产生编码种群的Matlab7.0源程序1:
function pop = encoding (popsize, stringlength, dimension)pop = round (rand (popsize, dimension*stringlength+1));
function new_pop = cross_over (pop, popsize, stringlength, dimension)
match = round (rand (1, popsize )*( popsize - 1)) + 1;
for i=i: popsize
[child1, child2] = cross_running (pop (i, :), pop (match (i), :) , stinglength, dimension) ;
new_pop (2*i-1: 2*i, :) = [child1; child2] ;
function [child1, child2] = cross_running ( parent1, parent2, stringlength, dimension)
cpoint = round ((stringlength - 1)* rand (1, dimension))+1;
for j = 1: dimension
child1 ((j-1)*stringlenth+1: j* stringlength) =
[parent1 ((j-1)*stringlength+1: (j-1)* stinglength+ cpoint (j))
partent2 ((j-1)* stinglength+ cpoint (j)+1: j* stinglength)];
child2 ((j-1)* stringlenth+1: j* stringlength) =
[parent1 ((j-1)*stringlength+1: (j-1)* stinglength+ cpoint (j))
partent2 ((j-1)* stinglength+ cpoint (j) +1: j* stinglength)];
Matlab7.0编写的程序2共有两个函数,完成两个个体交叉过程。
<h1 style="color:# 麦片财富积分
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&pm
& && &&&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
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) ;
for i = 1:popsize
& &for j = 1:dimension
& && &m (:, j) = pop (i, stringlength* (j-1)+1: stringlength*j) ;
x=x.*bound+ x_bound (:, 1)’ ;
pop (i, dimension* stringlength+1) = funname (x);
选择程序5:
[temp_generation, k, sign] = constraint_choising (pop, stringlength, dimension, x_bound)
popsize = size (pop, 1) ;
sign = 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) ;
x = x. *bound+ x_ound (:, 1)’ ;
%x = round(x);&&%四舍五入取整
if constraint_fun (x) = = 1
&&temp_generation (ss, :) = pop (i, :) ;
ss = ss+1;
if mark = = k
&&temp_generation = 0;
&&sign = 0;
new_generation = producing (pop, popsize, stringlength, dimension, x_bound, pm)
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_
& &&&signk =
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, :);
<h1 style="color:# 麦片财富积分
程序6是用Matlab编写的main.m主程序。
popsize = 10;
dimension = 3;
stringlength = 8;
x_bound = [0, 1; 0, 1; 0, 1];
以上是初始化数据,对于不同的实例需要重新设置;尤其是x_bound和dimension, n是遗传迭代的代数。此处只是示例。
pop = encoding (popsize, stringlength, dimension) ;
new_generation = producing (pop, popsize, stringlength, dimension, x_bound, pm);
pop = decoding (new_generation, stringlength, dimension, x_bound);
pop = selection (pop, popsize, stringlength, dimension);
[maxval, maxk] = max (pop (:, stinglength* dimension+1)) ;
choice = pop (maxk, :);
for i = 1: n
new_generation = producing (pop, popsize, stringlength, dimension, x_bound, pm) ;
pop = decoding (new_generation, stringlength, dimension, x_bound);
pop = selection (pop, popsize, stringlength, dimension);
[val, k] = max (pop (:, stringlength*dimension+1));
if val & maxval
choice = pop(maxk, :);
[val, k] = min (pop (: , stringlength* dimension+1));
pop (k, :) =
[val, k] = min (pop (: , stringlength* dimension+1));
pop (k, :) =
[value, x] = result (pop, stringlength, dimension, x_bound)
function [value,x] = result(pop, stringlength, dimension, x_bound)
[value,k] = max (pop (: , stringlength* dimension+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 j = 1: dimension
m (: , j) = pop (k, stringlength* (j-1)+1: stringlength* j);
x = temp* m
x = x. * bound+ x_bound (: , 1)’;
value是最大适应值,x是取到最大适应值的个体。result()函数显示算法运行的最终结果。
function y = funname (x)
%此函数是目标函数,对于不同的实例,该函数需要重新编写。此处函数只是示例。
function y = constraint_fun (x)
if x (1)+2*x (2) -x (3) -2 &= 0 & x (1)+4* x (2) -3 &= 0 & 4*x (1)+x (3)-6 &= 0
此函数是检验个体X是否满足约束条件,对于不同的实例,该函数需要重新编写。此处函数只是示例。
<h1 style="color:# 麦片财富积分
关注者: 2
楼主厉害啊
<h1 style="color:# 麦片财富积分
回复 2# xueshou02 的帖子
请问有m文件吗?谢谢!
<h1 style="color:# 麦片财富积分
谢谢楼主,正在学习中
<h1 style="color:# 麦片财富积分
楼主真厉害呢。
<h1 style="color:# 麦片财富积分
请问楼主为什么运行之后显示??? Undefined function or method 'encoding' for input arguments of type 'double'.
是出现了什么问题呢
<h1 style="color:# 麦片财富积分
wobushini2009 发表于
楼主真厉害呢。
请问你运行成功了么???为什么我的显示的是??? Undefined function or method 'encoding' for input arguments of type 'double'.
<h1 style="color:# 麦片财富积分
wade03007 发表于
请问有m文件吗?谢谢!
楼主威武!
站长推荐 /3
利用MATLAB进行投资组合优化
Powered by1 二进制编码的简单遗传算法源程序,很完整,适合初学者学习。 matlab 244万源代码下载-
&文件名称: 11111& & [
& & & & &&]
&&所属分类:
&&开发工具: matlab
&&文件大小: 115 KB
&&上传时间:
&&下载次数: 76
&&提 供 者:
&详细说明:二进制编码的简单遗传算法源程序,很完整,适合初学者学习。-A simple binary encoding genetic algorithm source code, is very complete, suitable for beginners to learn.
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&[]:不是源代码或资料&[]:纯粹是垃圾&[]:和说明完全不符&[]:纯粹是垃圾&[]:纯粹是垃圾&[]:纯粹是垃圾
&近期下载过的用户:
&相关搜索:
&输入关键字,在本站244万海量源码库中尽情搜索:
&[] - 采用二进制编码遗传算法求函数最大值,有遗传算法的仿真程序
&[] - fga.m 为遗传算法的主程序
采用二进制Gray编码,采用基于轮盘赌法的非线性排名选择, 均匀交叉,变异操作,而且还引入了倒位操作
&[] - matlab环境下的遗传算法程序,十进制二进制编码都有
&[] - BP―遗传算法神经网络模型,matlab 源程序。
&[] - 离散二进制粒子群优化算法,非常热门的的新算法,给出几个函数实例,供大家参考
&[] - 一个简单的针对函数优化问题的遗传算法源程序。
&[] - 基于遗传算法的TSP实现,包含仿真出的图像路线图
&[] - 本代码是我写论文用的代码,是一种优化算法CHC算法,基于MATLAB环境运行,1991年由Eshelman提出的一种基于遗传算法的改进进化算法。
&[] - matlab编写的遗传算法,采用二进制编码,有说明文档。
&[] - 包含二进制遗传算法,遗传算法,可直接运行寻优能力强查看: 37461|回复: 207|关注: 0
遗传算法求解函数的极小值的matlab程序(包括程序及试验报告)
<h1 style="color:# 麦片财富积分
新手, 积分 47, 距离下一级还需 3 积分
是我之前的智能优化算法课程的作业,用遗传算法求解函数的极小值问题,有完整的程序和详细的试验报告,和大家分享一下,希望能有用,欢迎顶贴,谢谢
智能优化计算课程试验报告实验要求:用遗传算法解决下面函数的极小值问题:
遗传算法.jpg (8 KB, 下载次数: 1829)
20:28 上传
遗传算法的具体实施策略不限,最好用MATLAB,上交内容包括源程序和运行结果
实验内容:目标函数是一个含有30维变量的复杂型超越函数,决定使用MATLAB7.0下的遗传函数工具箱来寻找函数最小值。一.函数编辑在m文件下编辑目标函数:
function y =fun(x);
y = zeros(size(x,1),1);
%产生一个列向量,(种群数)*1,作为预留解空间
[xSize, Dim] = size(x);
%xSize:种群数;
Dim:变量x的维数
indices = repmat(1:Dim, xSize, 1);
%生成函数中i的空间矩阵,(种群数)*(变量维数)
y = sum(((x.^2) / 4000)')' - prod(cos(x ./ sqrt(indices))')' + 1;
%函数表达式,此处均采用矩阵点乘的形式
完整内容见报告!
20:28 上传
点击文件名下载附件
53.26 KB, 下载次数: 130629
<h1 style="color:# 麦片财富积分
顶:lol :lol :lol :lol :lol :lol
<h1 style="color:# 麦片财富积分
顶了~~下载下来看看
<h1 style="color:# 麦片财富积分
已经下载,学习验证中
<h1 style="color:# 麦片财富积分
dingyi xia~~~~~~~~~~
<h1 style="color:# 麦片财富积分
楼主,能发给我一份吗?我的邮箱是
<h1 style="color:# 麦片财富积分
丁丁丁丁丁丁丁丁丁丁丁丁
<h1 style="color:# 麦片财富积分
太好了,有用啊!好好研究研究!谢谢分享!
<h1 style="color:# 麦片财富积分
能发给我一份吗, 急用谢谢
<h1 style="color:# 麦片财富积分
天啦,怎么下不下来?有人帮忙吗?
站长推荐 /3
利用MATLAB进行投资组合优化
Powered by

我要回帖

更多关于 遗传算法的整数约束 的文章

 

随机推荐