-
Notifications
You must be signed in to change notification settings - Fork 29
/
initialize_pop.m
46 lines (40 loc) · 1.33 KB
/
initialize_pop.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
function [ pop ] = initialize_pop(rseed)
% This function initializes a whole populaiton, where the populations
% is a matrix with dimension like this --
% nvar nobj ncon constr rank crowd-dist
% indiv[1] ... ... ... ... ... ...
% indiv[2] ... ... ... ... ... ...
% .
% .
% indiv[popsize] ... ... ... ... ... ...
global popsize ;
global nreal ;
global nbits ;
global nbin ;
global nobj ;
global ncon ;
global min_realvar ;
global max_realvar ;
% init rng
rng(rseed, 'twister');
% Knuth's algo, SLOW !!!
% global seed ;
% seed = rseed ;
% randomize(); % SLOW !!!
if(nreal > 0)
% each individual is arranged like this --
% [nvar, nobj, ncon, cv, rank, crowd-dist]
pop = zeros(popsize, nreal + nobj + ncon + 3);
rand_vals = rand(popsize, nreal);
% rand_vals = randompercv(popsize, nreal); % SLOW !!!
rand_vals = bsxfun(@plus, bsxfun(@times, rand_vals, ...
max_realvar'-min_realvar'), ...
min_realvar');
pop(:,1:nreal) = rand_vals;
return ;
elseif(nbin > 0)
pop = zeros(popsize, sum(nbits) + nobj + ncon + 3);
rand_vals = rand(popsize, sum(nbits)) > 0.5 ;
pop(:,1:sum(nbits)) = rand_vals ;
end
end