-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkktpm_combine_and_reduce_model.m
82 lines (61 loc) · 2.25 KB
/
kktpm_combine_and_reduce_model.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
function pop = kktpm_combine_and_reduce_model(opt, pop1, pop2)
[N, k] = size(pop1); k = k-2; % N = 2 * N_initial
pop2 = [pop2, zeros(N, 2)];
pop2 = evaluate_fitness_model(opt, pop2(:, 1:k));%FIND KKTPM PREDICTION OF CHILDREN POPULATION
pop3 = [pop1; pop2];
%FIND CLUSTER CENTERS
closest_point_index = dsearchn(opt.activearchive(:,1:opt.V),pop3(:,1:opt.V));%for each element in pop, find closest solution in x-space
pop_cluster = opt.activearchiveCluster(closest_point_index,:); %cluster values of those solutions
% START THE COMPETITION
pop = [];%zeros(N, k+2);
temp = zeros(opt.numdir,1);%saves number of elements for each direction
member = (1:opt.numdir)';
for i=1:2*N
temp(pop_cluster(i)) = temp(pop_cluster(i))+1;%find number of members for each cluster
end
[~,index] = sort(temp);
temp = temp(index,:);%total size
member = member(index,:);%cluster number
s=1;
remain = N;
for i=1:opt.numdir
if (opt.numdir-i+1)>remain
h = input('hello');
end
t = floor(remain/(opt.numdir-i+1));
if temp(i)>0 && temp(i)<=t %size of the
r = 0;
for j=1:2*N
if pop_cluster(j)==member(i)
pop(s,1:opt.V+2) = pop3(j,1:opt.V+2);
s = s+1;
r = r+1;
end
end
remain = remain -r;
elseif temp(i)>t %find smallest kktpm values
collect = [];
kktpm = [];
q = 1;
for j=1:2*N
if pop_cluster(j)==member(i)
collect(q,1:opt.V+2) = pop3(j,1:opt.V+2);
kktpm(q,1) = pop3(j,opt.V+1);
q = q+1;
end
end
[~,index] = sort(kktpm);
if i== opt.numdir
collect = collect(index(1:remain),:);
else
collect = collect(index(1:t),:);
end
pop(s:s+t-1,1:opt.V+2) = collect;
s = s + size(collect,1);
remain = remain - t;
end
end
if size(pop,1)<N
disp('here');
end
end