-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunExperiment1.m
147 lines (144 loc) · 5.17 KB
/
RunExperiment1.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
function IsSucceeded = RunExperiment1(dimensionSize,populationSize,simulationTimes)
%this function while invoke GA/PSO/DE/EDA to be tested on 14 benchmark functions
definitionDomain = [[-100,100];[-100,100];[-100,100];[-100,100];[-100,100];[-100,100];
[0,600];[-32,32];[-5,5];[-5,5];[-0.5,0.5];[-pi,pi];[-5,-5];[-100,100]];
globalOptimum = [-450;-450;-450;-450;-310;390;-180;-140;-330;-330;90;-460;-130;-300];
%dimensionSize = 3;
%populationSize = 100;
%simulationTimes = 1;
lambdaForEDA = populationSize;
divition = 2;
miuForEDA = lambdaForEDA/divition;
for i = 1:14,
fprintf('=======================F%d==============================\n',i);
GABestIndividual=[];
GABestFitness = 0;
PSOBestIndividual=[];
PSOBestFitness = 0;
DEBestIndividual=[];
DEBestFitness = 0;
EDABestIndividual=[];
EDABestFitness = 0;
GAAve = 0;
PSOAve = 0;
DEAve =0;
EDAAve = 0;
GATime = 0;
PSOTime = 0;
DETime = 0;
EDATime = 0;
recursiveTimes = 3;
%benchmark function encapsulation, use anonymouse function
benchmarkForMinimization = @(theX) applyAlgToBenchmark(theX,i);
benchmarkForMaximization = @(theX) -1*applyAlgToBenchmark(theX,i);
%run the algorithm
%GA
j=1;
tic;
[GABestIndividual,GABestFitness]= GA(dimensionSize,benchmarkForMaximization,definitionDomain(i,:),populationSize,simulationTimes);%j=1 so this is the firt term
GAAve = GAAve + GABestFitness;
while j < recursiveTimes,
j = j+1;
[tempind,tempfit] = GA(dimensionSize,benchmarkForMaximization,definitionDomain(i,:),populationSize,simulationTimes);
GAAve = GAAve + tempfit;
%guarantee the GAResults is the best among all the results
if tempfit > GABestFitness,
GABestFitness = tempfit;
GABestIndividual = tempind;
end
end
GATime = toc / recursiveTimes;
GAAve = GAAve / recursiveTimes;
%the default GA search for max,but benchmark search for min, so we
%change the return value of bechmark to fit the GA, now we retrieve the
%original result from benchmark
GABestFitness = -GABestFitness;
GAAve = -GAAve;
%PSO
j=1;
tic;
[PSOBestIndividual,PSOBestFitness] = PSO(dimensionSize,benchmarkForMaximization,definitionDomain(i,:),populationSize,simulationTimes);
PSOAve = PSOAve + PSOBestFitness;
while j < recursiveTimes,
j = j+1;
[tempind,tempfit] = PSO(dimensionSize,benchmarkForMaximization,definitionDomain(i,:),populationSize,simulationTimes);
PSOAve = PSOAve + tempfit;
if tempfit > PSOBestFitness,
PSOBestFitness = tempfit;
PSOBestIndividual = tempind;
end
end
PSOTime = toc / recursiveTimes;
PSOAve = PSOAve / recursiveTimes;
PSOBestFitness = -PSOBestFitness;
PSOAve = -PSOAve;
%DE
j=1;
tic;
[DEBestIndividual,DEBestFitness]= DE(dimensionSize,benchmarkForMinimization,definitionDomain(i,:),populationSize,simulationTimes);
DEAve = DEAve + DEBestFitness;
while j < recursiveTimes,
j = j+1;
[tempind,tempfit] = DE(dimensionSize,benchmarkForMinimization,definitionDomain(i,:),populationSize,simulationTimes);
DEAve = DEAve + tempfit;
if tempfit < DEBestFitness,
DEBestFitness = tempfit;
DEBestIndividual = tempind;
end
end
DETime = toc / recursiveTimes;
DEAve = DEAve / recursiveTimes;
%EDA
j=1;
tic;
[EDABestIndividual,EDABestFitness] = EDA(dimensionSize,benchmarkForMaximization,definitionDomain(i,:),lambdaForEDA,miuForEDA,simulationTimes);
EDAAve = EDAAve + EDABestFitness;
while j < recursiveTimes,
j = j+1;
[tempind,tempfit] = EDA(dimensionSize,benchmarkForMaximization,definitionDomain(i,:),lambdaForEDA,miuForEDA,simulationTimes);
EDAAve = EDAAve + tempfit;
if tempfit > EDABestFitness,
EDABestFitness = tempfit;
EDABestIndividual = tempind;
end
end
EDATime = toc / recursiveTimes;
EDAAve = EDAAve / recursiveTimes;
EDABestFitness = -EDABestFitness;
EDAAve = -EDAAve;
%show the results
fprintf('benchmark f%d results:\n',i);
%GA
fprintf('\t GA\n');
fprintf('globa best ---|\n');
fprintf('\tINDIVIDUAL:');
disp(GABestIndividual);
fprintf('\tFITNESS:%d\n',GABestFitness);
fprintf('Average Error:%d\n', GAAve - globalOptimum(i));
fprintf('Average Time:%d\n',GATime);
%PSO
fprintf('\t PSO\n');
fprintf('globa best ---|\n');
fprintf('\tINDIVIDUAL:');
disp(PSOBestIndividual);
fprintf('\tFITNESS:%d\n',PSOBestFitness);
fprintf('Average Error:%d\n', PSOAve - globalOptimum(i));
fprintf('Average Time:%d\n',PSOTime);
%DE
fprintf('\t DE\n');
fprintf('globa best ---|\n');
fprintf('\tINDIVIDUAL:');
disp(DEBestIndividual);
fprintf('\tFITNESS:%d\n',DEBestFitness);
fprintf('Average Error:%d\n', DEAve - globalOptimum(i));
fprintf('AVerage Time:%d\n',DETime);
%EDA
fprintf('\t EDA\n');
fprintf('globa best ---|\n');
fprintf('\tINDIVIDUAL:');
disp(EDABestIndividual);
fprintf('\tFITNESS:%d\n',EDABestFitness);
fprintf('Average Error:%d\n', EDAAve - globalOptimum(i));
fprintf('Average Time:%d\n',EDATime);
end
end