⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crtbp.m

📁 matlab的遗传算法的一个工具箱
💻 M
字号:
% CRTP.m - Create an initial population%% This function creates a binary population of given size and structure.%% Syntax: [Chrom Lind BaseV] = crtbp(Nind, Lind, Base)%% Input Parameters:%%		Nind	- Either a scalar containing the number of individuals%			  in the new population or a row vector of length two%			  containing the number of individuals and their length.%%		Lind	- A scalar containing the length of the individual%			  chromosomes.%%		Base	- A scalar containing the base of the chromosome %			  elements or a row vector containing the base(s) %			  of the loci of the chromosomes.%% Output Parameters:%%		Chrom	- A matrix containing the random valued chromosomes %			  row wise.%%		Lind	- A scalar containing the length of the chromosome.%%		BaseV	- A row vector containing the base of the %			  chromosome loci.% Author: Andrew Chipperfield% Date:	19-Jan-94function [Chrom, Lind, BaseV] = crtbp(Nind, Lind, Base)nargs = nargin ;% Check parameter consistencyif nargs >= 1, [mN, nN] = size(Nind) ; endif nargs >= 2, [mL, nL] = size(Lind) ; endif nargs == 3, [mB, nB] = size(Base) ; endif nN == 2   if (nargs == 1)       Lind = Nind(2) ; Nind = Nind(1) ; BaseV = crtbase(Lind) ;   elseif (nargs == 2 & nL == 1)       BaseV = crtbase(Nind(2),Lind) ; Lind = Nind(2) ; Nind = Nind(1) ;    elseif (nargs == 2 & nL > 1)       if Lind ~= length(Lind), error('Lind and Base disagree'); end      BaseV = Lind ; Lind = Nind(2) ; Nind = Nind(1) ;    endelseif nN == 1   if nargs == 2      if nL == 1, BaseV = crtbase(Lind) ;      else, BaseV = Lind ; Lind = nL ; end   elseif nargs == 3      if nB == 1, BaseV = crtbase(Lind,Base) ;       elseif nB ~= Lind, error('Lind and Base disagree') ;       else BaseV = Base ; end   endelse   error('Input parameters inconsistent') ;end% Create a structure of random chromosomes in row wise order, dimensions% Nind by Lind. The base of each chromosomes loci is given by the value% of the corresponding element of the row vector base.Chrom = floor(rand(Nind,Lind).*BaseV(ones(Nind,1),:)) ;% End of file 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -