当前位置:金星文档 > 所有分类 > IT/计算机 > 三个遗传算法matlab程序实例
侵权投诉

三个遗传算法matlab程序实例

遗传算法 matlab pid参数优化 自动控制理论

遗传算法程序(一):

说明: fga.m 为遗传算法的主程序; 采用二进制Gray编码,采用基于轮盘赌法的非线性排名选择, 均匀交叉,变异操作,而且还引入了倒位操作!

function [BestPop,Trace]=fga(FUN,LB,UB,eranum,popsize,pCross,pMutation,pInversion,options) % [BestPop,Trace]=fmaxga(FUN,LB,UB,eranum,popsize,pcross,pmutation) % Finds a maximum of a function of several variables.

% fmaxga solves problems of the form:

% max F(X) subject to: LB <= X <= UB % BestPop - 最优的群体即为最优的染色体群 % Trace - 最佳染色体所对应的目标函数值 % FUN - 目标函数 % LB - 自变量下限 % UB - 自变量上限

% eranum - 种群的代数,取100--1000(默认200)

% popsize - 每一代种群的规模;此可取50--200(默认100) % pcross - 交叉概率,一般取0.5--0.85之间较好(默认0.8) % pmutation - 初始变异概率,一般取0.05-0.2之间较好(默认0.1) % pInversion - 倒位概率,一般取0.05-0.3之间较好(默认0.2)

% options - 1*2矩阵,options(1)=0二进制编码(默认0),option(1)~=0十进制编 %码,option(2)设定求解精度(默认1e-4)

%

% ------------------------------------------------------------------------

T1=clock;

if nargin<3, error('FMAXGA requires at least three input arguments'); end

if nargin==3, eranum=200;popsize=100;pCross=0.8;pMutation=0.1;pInversion=0.15;options=[0 1e-4];end

if nargin==4, popsize=100;pCross=0.8;pMutation=0.1;pInversion=0.15;options=[0 1e-4];end if nargin==5, pCross=0.8;pMutation=0.1;pInversion=0.15;options=[0 1e-4];end if nargin==6, pMutation=0.1;pInversion=0.15;options=[0 1e-4];end if nargin==7, pInversion=0.15;options=[0 1e-4];end if find((LB-UB)>0)

error('数据输入错误,请重新输入(LB<UB):');

end

s=sprintf('程序运行需要约%.4f 秒钟时间,请稍等......',(eranum*popsize/1000)); disp(s);

global m n NewPop children1 children2 VarNum

bounds=[LB;UB]';bits=[];VarNum=size(bounds,1);

precision=options(2);%由求解精度确定二进制编码长度

bits=ceil(log2((bounds(:,2)-bounds(:,1))' ./ precision));%由设定精度划分区间 [Pop]=InitPopGray(popsize,bits);%初始化种群

第1页

猜你喜欢

返回顶部