-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain5.m
158 lines (133 loc) · 4.49 KB
/
main5.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
156
157
158
%%直接运行Main函数
clear all
clc
fhd=str2func('cec17_func');
Number=100;
dim=100;
Max_iter=500;
lb=-100.*ones(1,dim);
ub=100.*ones(1,dim);
%runs=30;
runs = 5;
%for i=4:30
for i = 1:25
func_num=i
runs=runs
for j=1:runs
run=j
[Best_pos{j,i},Best_score(j,i),curve{j,i}]=RHSSA1(fhd,Number,Max_iter,lb,ub,dim,func_num);
Best_Score=Best_score(j,i);
% [Best_pos1{j,i},Best_score1(j,i),curve1{j,i}]=SSA(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score1=Best_score1(j,i);
% [Best_pos2{j,i},Best_score2(j,i),curve2{j,i}]=SSA1(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score2=Best_score2(j,i);
% [Best_pos3{j,i},Best_score3(j,i),curve3{j,i}]=SSA2(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score3=Best_score3(j,i);
% [Best_pos4{j,i},Best_score4(j,i),curve4{j,i}]=SSA4(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score4=Best_score4(j,i);
% [Best_pos5{j,i},Best_score5(j,i),curve5{j,i}]=SSA6(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score5=Best_score5(j,i);
% [Best_pos6{j,i},Best_score6(j,i),curve6{j,i}]=SSA_GLS_Scale(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score6=Best_score6(j,i);
% [Best_pos7{j,i},Best_score7(j,i),curve7{j,i}]=SSA_GLS_Scale1(fhd,Number,Max_iter,lb,ub,dim,func_num);
% Best_Score7=Best_score7(j,i);
end
%% 将元胞数组的值复制到矩阵当中。
A=zeros(runs,Max_iter);
for s=1:runs
A(s,:)=curve{s,func_num};
end
%B=zeros(runs,Max_iter);
%for s=1:runs
% B(s,:)=curve1{s,func_num};
%end
%
% C=zeros(runs,Max_iter);
% for s=1:runs
% C(s,:)=curve2{s,func_num};
% end
%
% D=zeros(runs,Max_iter);
% for s=1:runs
% D(s,:)=curve3{s,func_num};
% end
%
% E=zeros(runs,Max_iter);
% for s=1:runs
% E(s,:)=curve4{s,func_num};
% end
%
% F=zeros(runs,Max_iter);
% for s=1:runs
% F(s,:)=curve5{s,func_num};
% end
%
% G=zeros(runs,Max_iter);
% for s=1:runs
% G(s,:)=curve6{s,func_num};
% end
% H=zeros(runs,Max_iter);
% for s=1:runs
% H(s,:)=curve7{s,func_num};
% end
%% 结果对比
% 创建一个较大的图形窗口
figure('Position', [100, 70, 1200, 800]);
% 画多条半对数曲线
semilogy(mean(A), 'Color', 'r', 'LineWidth', 1.5, 'Marker', '+', 'MarkerIndices', 1:50:length(mean(A)));
%hold on
%semilogy(mean(B), 'Color', 'g', 'LineWidth', 1.5, 'Marker', 'x', 'MarkerIndices', 1:50:length(mean(B)));
%hold on
%semilogy(mean(C), 'Color', 'y', 'LineWidth', 1.5, 'Marker', 'o', 'MarkerIndices', 1:50:length(mean(C)));
%hold on
%semilogy(mean(D), 'Color', 'b', 'LineWidth', 1.5, 'Marker', '.', 'MarkerIndices', 1:50:length(mean(D)));
%hold on
%semilogy(mean(E), 'Color', 'c', 'LineWidth', 1.5, 'Marker', '*', 'MarkerIndices', 1:50:length(mean(E)));
%hold on
%semilogy(mean(F), 'Color', 'k', 'LineWidth', 1.5, 'Marker', '^', 'MarkerIndices', 1:50:length(mean(F)));
%hold on
%semilogy(mean(G), 'Color', 'm', 'LineWidth', 1.5, 'Marker', 's', 'MarkerIndices', 1:50:length(mean(G)));
%hold on
%semilogy(mean(H), 'Color', 'm', 'LineWidth', 1.5, 'Marker', '<', 'MarkerIndices', 1:50:length(mean(H)));
% 设置网格和轴
grid on;
axis tight;
box on;
% 添加标题和标签
title(func_num, 'FontSize', 18, 'FontWeight', 'bold');
xlabel('Iteration', 'FontSize', 16);
ylabel('Fitness', 'FontSize', 16);
% 设置图例
legend({'RHSSA1'}, 'FontSize', 14, 'Location', 'best');
% 设置坐标轴属性
set(gca, 'FontSize', 14, 'LineWidth', 1.5);
end
%平均值
best_Score=mean(Best_score);
% best_Score1=mean(Best_score1);
% best_Score2=mean(Best_score2);
% best_Score3=mean(Best_score3);
% best_Score4=mean(Best_score4);
% best_Score5=mean(Best_score5);
% best_Score6=mean(Best_score6);
% best_Score7=mean(Best_score7);
%标准差
std0=std(Best_score);
% std1=std(Best_score1);
% std2=std(Best_score2);
% std3=std(Best_score3);
% std4=std(Best_score4);
% std5=std(Best_score5);
% std6=std(Best_score6);
% std7=std(Best_score7);
%% 打印结果
fprintf('Function Number: %d\n', func_num);
% 打印每个算法的平均值和标准差
fprintf('RHSSA1: Best Score = %.4e, Std Dev = %.4e\n', best_Score, std0);
% fprintf('SSA: Best Score = %.4e, Std Dev = %.4e\n', best_Score1, std1);
% fprintf('SSA1: Best Score = %.4e, Std Dev = %.4e\n', best_Score2, std2);
% fprintf('SSA2: Best Score = %.4e, Std Dev = %.4e\n', best_Score3, std3);
% fprintf('SSA4: Best Score = %.4e, Std Dev = %.4e\n', best_Score4, std4);
% fprintf('SSA6: Best Score = %.4e, Std Dev = %.4e\n', best_Score6, std6);
% fprintf('SSA_GLS_Scale: Best Score = %.4e, Std Dev = %.4e\n', best_Score6, std6);
% fprintf('SSA_GLS_Scale1: Best Score = %.4e, Std Dev = %.4e\n', best_Score7, std7);