-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMTDE_MKTA.m
155 lines (140 loc) · 5.81 KB
/
MTDE_MKTA.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
classdef MTDE_MKTA < Algorithm
% <Multi-task/Many-task> <Multi-objective> <None/Constrained>
%------------------------------- Reference --------------------------------
% @Article{Li2025MTDE-MKTA,
% title = {Multiobjective Multitask Optimization With Multiple Knowledge Types and Transfer Adaptation},
% author = {Li, Yanchi and Gong, Wenyin},
% journal = {IEEE Transactions on Evolutionary Computation},
% year = {2025},
% number = {1},
% pages = {205-216},
% volume = {29},
% doi = {10.1109/TEVC.2024.3353319},
% }
%--------------------------------------------------------------------------
%------------------------------- Copyright --------------------------------
% Copyright (c) Yanchi Li. You are free to use the MToP for research
% purposes. All publications which use this platform should acknowledge
% the use of "MToP" or "MTO-Platform" and cite as "Y. Li, W. Gong, F. Ming,
% T. Zhang, S. Li, and Q. Gu, MToP: A MATLAB Optimization Platform for
% Evolutionary Multitasking, 2023, arXiv:2312.08134"
%--------------------------------------------------------------------------
properties (SetAccess = private)
Tau1 = 0.2
Tau2 = 0.1
end
methods
function Parameter = getParameter(Algo)
Parameter = {'Tau1: F-CR', num2str(Algo.Tau1), ...
'Tau2: TR-KP', num2str(Algo.Tau2)};
end
function Algo = setParameter(Algo, Parameter)
i = 1;
Algo.Tau1 = str2double(Parameter{i}); i = i + 1;
Algo.Tau2 = str2double(Parameter{i}); i = i + 1;
end
function run(Algo, Prob)
% Initialization
population = Initialization(Algo, Prob, Individual_MKTA);
for t = 1:Prob.T
for i = 1:Prob.N
population{t}(i).F = 0.2 + rand();
population{t}(i).CR = rand();
population{t}(i).TR = rand(); % Knowledge transfer rate
population{t}(i).KP = rand(); % Knowledge type proportion
end
[population{t}, Fitness{t}] = Selection_SPEA2(population{t}, Prob.N);
decs = population{t}.Decs;
model{t}.mean = mean(decs);
model{t}.std = std(decs) +1e-100;
end
while Algo.notTerminated(Prob, population)
for t = 1:Prob.T
[~, rank{t}] = sort(Fitness{t});
[~, rank{t}] = sort(rank{t});
decs = population{t}.Decs;
alpha = 0.5;
model{t}.mean = alpha * model{t}.mean + (1 - alpha) * mean(decs);
model{t}.std = alpha * model{t}.std + (1 - alpha) * (std(decs)) +1e-100;
end
for t = 1:Prob.T
offspring{t} = Algo.Generation(population, rank, model, t);
end
for t = 1:Prob.T
% Evaluation
offspring{t} = Algo.Evaluation(offspring{t}, Prob, t);
% Selection
population{t} = [population{t}, offspring{t}];
[population{t}, Fitness{t}, Next] = Selection_SPEA2(population{t}, Prob.N);
end
end
end
function offspring = Generation(Algo, population, rank, model, t)
for i = 1:length(population{t})
offspring(i) = population{t}(i);
% Parameter disturbance
offspring(i).F = normrnd(population{t}(i).F, 0.1);
offspring(i).F = min(max(offspring(i).F, 0.2), 1.2);
offspring(i).CR = normrnd(population{t}(i).CR, 0.1);
offspring(i).CR = min(max(offspring(i).CR, 0), 1);
offspring(i).TR = normrnd(population{t}(i).TR, 0.1);
offspring(i).TR = min(max(offspring(i).TR, 0), 1);
offspring(i).KP = normrnd(population{t}(i).KP, 0.1);
if offspring(i).KP < 0
offspring(i).KP = 1 + offspring(i).KP;
elseif offspring(i).KP > 1
offspring(i).KP = offspring(i).KP - 1;
end
% Parameter mutation
if rand() < Algo.Tau1
offspring(i).F = 0.2 + rand();
end
if rand() < Algo.Tau1
offspring(i).CR = rand();
end
if rand() < Algo.Tau2
offspring(i).TR = rand();
end
if rand() < Algo.Tau2
offspring(i).KP = rand();
end
% Select individuals (rank-DE)
Np = length(population{t});
x1 = randi(Np);
while rand() > (Np - rank{t}(x1)) / Np || x1 == i
x1 = randi(Np);
end
x2 = randi(Np);
while rand() > (Np - rank{t}(x2)) / Np || x2 == i || x2 == x1
x2 = randi(Np);
end
x3 = randi(Np);
while x3 == i || x3 == x1 || x3 == x2
x3 = randi(Np);
end
xDeci = population{t}(i).Dec;
xDec1 = population{t}(x1).Dec;
xDec2 = population{t}(x2).Dec;
xDec3 = population{t}(x3).Dec;
% Knowledge transfer
if rand() < offspring(i).TR
k = randi(length(population)); % help task
while (k == t), k = randi(length(population)); end
Np = length(population{k});
rnd = offspring(i).KP;
if rnd > 1/2
xDeck = population{k}(randi(Np)).Dec;
else
xDeck = population{k}(randi(Np)).Dec;
xDeck = (xDeck -model{k}.mean) ./ model{k}.std;
xDeck = model{t}.mean + model{t}.std .* xDeck;
end
xDec2 = xDeck;
end
offspring(i).Dec = xDec1 + offspring(i).F * (xDec2 - xDec3);
offspring(i).Dec = DE_Crossover(offspring(i).Dec, xDeci, offspring(i).CR);
offspring(i).Dec = min(max(offspring(i).Dec, 0), 1);
end
end
end
end