forked from sumatrae/gatbx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crtrp.M
52 lines (44 loc) · 2.06 KB
/
crtrp.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
% CRTRP.M (CReaTe an initial (Real-value) Population)
%
% This function creates a population of given size of random real-values.
%
% Syntax: Chrom = crtrp(Nind,FieldDR);
%
% Input parameters:
% Nind - A scalar containing the number of individuals in the new
% population.
%
% FieldDR - A matrix of size 2 by number of variables describing the
% boundaries of each variable. It has the following structure:
% [lower_bound; (vector with lower bound for each veriable)
% upper_bound] (vector with upper bound for each veriable)
% [lower_bound_var_1 lower_bound_var_2 ... lower_bound_var_Nvar;
% upper_bound_var_1 upper_bound_var_2 ... upper_bound_var_Nvar]
% example - each individuals consists of 4 variables:
% FieldDR = [-100 -50 -30 -20; % lower bound
% 100 50 30 20] % upper bound
%
% Output parameter:
% Chrom - A matrix containing the random valued individuals of the
% new population of size Nind by number of variables.
%
% Author: Hartmut Pohlheim
% History: 23.11.93 file created
% 25.02.94 clean up, check parameter consistency
% 20.01.03 tested under MATLAB v6 by Alex Shenfield
function Chrom = crtrp(Nind,FieldDR);
% Check parameter consistency
if nargin < 2, error('parameter FieldDR missing'); end
if nargin > 2, nargin = 2; end
[mN, nN] = size(Nind);
[mF, Nvar] = size(FieldDR);
if (mN ~= 1 & nN ~= 1), error('Nind has to be a scalar'); end
if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end
% Compute Matrix with Range of variables and Matrix with Lower value
Range = rep((FieldDR(2,:)-FieldDR(1,:)),[Nind 1]);
Lower = rep(FieldDR(1,:), [Nind 1]);
% Create initial population
% Each row contains one individual, the values of each variable uniformly
% distributed between lower and upper bound (given by FieldDR)
Chrom = rand(Nind,Nvar) .* Range + Lower;
% End of function