-
Notifications
You must be signed in to change notification settings - Fork 2
/
ccde.m
80 lines (61 loc) · 2.35 KB
/
ccde.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
function [bestCC] = ccde(D, maxFe, minFit, nPop, f, varMin, varMax)
global dimIndex;
global curBest;
global sp;
dim(1:D) = 1; % Dimension broken down
maxIt = 100; % Maximum iterations for subpopulation
% Helps in creating the subpopulation
dimIndex = zeros(1, length(dim));
dimIndex(1) = 1;
for i=2:(length(dim)+1)
dimIndex(i) = dimIndex(i-1) + dim(i-1);
end
empty_individual2.Position = [];
empty_individual2.Cost = [];
pop = repmat(empty_individual2, nPop, 1);
curBest.Position = (varMin + (varMax + varMax)*rand(D, 1))';
% Intializing Population
for i = 1:nPop
% Generate a 100-by-1 row vector of uniformly distributed numbers in the
% interval [-5 5]
pop(i).Position = (varMin + (varMax + varMax)*rand(D, 1))';
pop(i).Cost = benchmark_func(pop(i).Position, f);
if (pop(i).Cost < benchmark_func(curBest.Position, f))
curBest.Position = pop(i).Position;
end
end
BestCost = [];
%% Each dimension is evolved separately for certain FE's
fe = 2*nPop;
flag = 0;
while ( fe < maxFe)
for sp = 1:length(dim)
% Intializing Sub-Population
empty_individual.Position = [];
empty_individual.Cost = [];
subpop = repmat(empty_individual, nPop, 1);
for i = 1:nPop
subpop(i).Position = pop(i).Position( dimIndex(sp) : (dimIndex(sp+1) - 1) );
% collaboration for fitness evaluation
evalPos = curBest.Position;
evalPos(dimIndex(sp) : (dimIndex(sp+1) - 1)) = subpop(i).Position;
subpop(i).Cost = benchmark_func(evalPos, f);
end
[best, nsubpop] = de(dim(sp), subpop, nPop, f, varMin, varMax, maxIt);
BestCost = [BestCost best];
if (BestCost(end) < minFit)
flag = 1;
break;
end
% updating pop with new subpop
for i = 1:nPop
pop(i).Position( dimIndex(sp) : (dimIndex(sp+1) - 1) ) = nsubpop(i).Position;
end
end
fe = fe + (length(dim) * (nPop + maxIt*nPop));
if (flag == 1)
break;
end
end
bestCC = BestCost(end);
end