-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcrtbp.m
73 lines (65 loc) · 2.15 KB
/
crtbp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% CRTBP.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-94
%
% Tested under MATLAB v6 by Alex Shenfield (20-Jan-03)
function [Chrom, Lind, BaseV] = crtbp(Nind, Lind, Base)
nargs = nargin ;
% Check parameter consistency
if nargs >= 1, [mN, nN] = size(Nind) ; end
if nargs >= 2, [mL, nL] = size(Lind) ; end
if nargs == 3, [mB, nB] = size(Base) ; end
if 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) ;
end
elseif 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
end
else
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