forked from UoS-CODeM/GA-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpandpop.m
86 lines (68 loc) · 2.92 KB
/
expandpop.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
74
75
76
77
78
79
80
81
82
83
84
85
86
function [mpgaoptions, mpgastate] = expandpop(method, n, mpgaoptions, mpgastate)
% expands the population of a ga
%
% Syntax
%
% [mpgaoptions, mpgastate] = expandpop(method, n, mpgaoptions, mpgastate)
%
% Input
%
% method - A string containing the method by which the population may be
% expanded. This can be either 'subpops' or 'nind'.
%
% If 'subpops', entire subpopulations of new individuals are added to
% the population, each containing the same number of individuals as are
% present in the existing subpopulations (i.e. the value in
% mpgaoptions.NIND). The number of the populations added is the value
% supplied in 'n'.
%
% If 'nind' new individuals are added to every subpopulation already
% present. 'n' new individuals are added to every subpopulation.
%
% n - Either the number of subpopulations to be added, or the number of
% individuals to be added to each subpopulation depending on the value of
% 'method'.
%
% mpgaoptions - The existing mpgaoptions structure for the ga.
%
% mpgastate - The existing mpgastate structure for the ga.
%
%
if strcmpi(method, 'subpops')
% Create new individuals
newChrom = crtrp(n * mpgaoptions.NIND, mpgastate.FieldDR);
% evaluate the new individuals
objargs = [{newChrom, []}, mpgastate.ObjectiveArgs];
newObjV = feval(mpgaoptions.OBJ_F, objargs{:});
mpgastate.Chrom = [ mpgastate.Chrom; newChrom ];
mpgastate.ObjV = [ mpgastate.ObjV; newObjV ];
mpgaoptions.SUBPOP = mpgaoptions.SUBPOP + n;
elseif strcmpi(method, 'nind')
% Create new individuals
newChrom = crtrp(mpgaoptions.SUBPOP * n, mpgastate.FieldDR);
% evaluate the new individuals
objargs = [{newChrom, []}, mpgastate.ObjectiveArgs];
newObjV = feval(mpgaoptions.OBJ_F, objargs{:});
newpopChrom = [];
newpopObjV = [];
% perform insertion for each subpopulation
for ind = 0:(mpgaoptions.SUBPOP-1)
% Calculate positions in old subpopulation, where offspring are
% inserted
newpopChrom = [ newpopChrom;
mpgastate.Chrom(((ind*mpgaoptions.NIND)+1):((ind+1)*mpgaoptions.NIND));
newChrom(((ind*n)+1):((ind+1)*n));
];
newpopObjV = [ newpopObjV;
mpgastate.ObjV(((ind*mpgaoptions.NIND)+1):((ind+1)*mpgaoptions.NIND));
newObjV(((ind*n)+1):((ind+1)*n));
];
end
mpgastate.Chrom = newpopChrom;
mpgastate.ObjV = newpopObjV;
% note the new subpopulation sizes in the mpgaoptions structure
mpgaoptions.NIND = mpgaoptions.NIND + n;
else
error('Unrecognised expansion method.');
end
end