【优化算法】树种优化算法(TSA)【含Matlab源码 1429期】
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【优化算法】树种优化算法(TSA)【含Matlab源码 1429期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、树种优化算法简介
树种算法是一种通过模拟大树的繁殖方式来寻找最优解的元启发式优化算法。
在基本树种算法中,首先利用式(1)在搜索空间中生成一批树木:
Ti,j=Lj,min+ri,j(Hj,min-Lj,min) (1)
其中,Ti,j为树木的位置;Lj,min为搜索空间的下界;HLj,min为搜索空间的上界;ri,j是一个随机数,取值范围为[0,1]。
通过式(1)随机生成的树木中,并不是所有的树木产生种子的能力都一样强,针对最小化问题,需要利用式(2)找出位置最优的树。
接着,位置最优的树木会产生新的种子。在TSA中,为了平衡算法全局搜索和局部搜索的能力,提出两种机制来产生新的种子,如式(3)和式(4)所示。式(3)侧重于全局搜索,全局搜索可以避免算法在迭代过程中陷入局部最优。式(4)侧重于局部搜索,局部搜索有利于算法的收敛。
Si,j=Ti,j+αi,j(Ti,j-Tr,j) (3)
Si,j=Ti,j+αi,j(Bj-Tr,j) (4)
其中,Si,j为第i颗树上繁殖的第i颗种子的第j个元素,Ti,j是第i颗树上的第j个元素,是当前位置最优的树上的第j个元素,αi,j是步长因子,是一个属于[-1,1]的随机数。
位置最优树木在产生新种子的过程中,由搜索趋势常数ST来决定采用式(3)还是式(4),ST为一常数。
三、部分源代码
%%%
clear all
clc
SearchAgents=30;
Fun_name='F1';
Max_iterations=1000;
[lowerbound,upperbound,dimension,fitness]=fun_info(Fun_name);
[Best_score,Best_pos,TSA_curve]=tsa(SearchAgents,Max_iterations,lowerbound,upperbound,dimension,fitness);
figure('Position',[400 400 560 190])
subplot(1,2,1);
func_plot(Fun_name);
title('Objective space')
xlabel('x_1');
ylabel('x_2');
zlabel([Fun_name,'( x_1 , x_2 )'])
subplot(1,2,2);
plots=semilogx(TSA_curve,'Color','g');
set(plots,'linewidth',2)
hold on
title('Objective space')
xlabel('Iterations');
ylabel('Best score');
axis tight
grid on
box on
legend('TSA')
display(['The best solution obtained by TSA is : ', num2str(Best_pos)]);
display(['The best optimal value of the objective funciton found by TSA is : ', num2str(Best_score)]);
%%% Designed and Developed by Dr. Gaurav Dhiman (http://dhimangaurav.com/) %%%
function [lowerbound,upperbound,dimension,fitness] = fun_info(F)
switch F
case 'F1'
fitness = @F1;
lowerbound=-100;
upperbound=100;
dimension=30;
case 'F2'
fitness = @F2;
lowerbound=-10;
upperbound=10;
dimension=30;
case 'F3'
fitness = @F3;
lowerbound=-100;
upperbound=100;
dimension=30;
case 'F4'
fitness = @F4;
lowerbound=-100;
upperbound=100;
dimension=30;
case 'F5'
fitness = @F5;
lowerbound=-30;
upperbound=30;
dimension=30;
case 'F6'
fitness = @F6;
lowerbound=-100;
upperbound=100;
dimension=30;
case 'F7'
fitness = @F7;
lowerbound=-1.28;
upperbound=1.28;
dimension=30;
case 'F8'
fitness = @F8;
lowerbound=-500;
upperbound=500;
dimension=30;
case 'F9'
fitness = @F9;
lowerbound=-5.12;
upperbound=5.12;
dimension=30;
case 'F10'
fitness = @F10;
lowerbound=-32;
upperbound=32;
dimension=30;
case 'F11'
fitness = @F11;
lowerbound=-600;
upperbound=600;
dimension=30;
case 'F12'
fitness = @F12;
lowerbound=-50;
upperbound=50;
dimension=30;
case 'F13'
fitness = @F13;
lowerbound=-50;
upperbound=50;
dimension=30;
case 'F14'
fitness = @F14;
lowerbound=-65.536;
upperbound=65.536;
dimension=2;
case 'F15'
fitness = @F15;
lowerbound=-5;
upperbound=5;
dimension=4;
case 'F16'
fitness = @F16;
lowerbound=-5;
upperbound=5;
dimension=2;
case 'F17'
fitness = @F17;
lowerbound=[-5,0];
upperbound=[10,15];
dimension=2;
case 'F18'
fitness = @F18;
lowerbound=-2;
upperbound=2;
dimension=2;
case 'F19'
fitness = @F19;
lowerbound=0;
upperbound=1;
dimension=3;
case 'F20'
fitness = @F20;
lowerbound=0;
upperbound=1;
dimension=6;
case 'F21'
fitness = @F21;
lowerbound=0;
upperbound=10;
dimension=4;
case 'F22'
fitness = @F22;
lowerbound=0;
upperbound=10;
dimension=4;
case 'F23'
fitness = @F23;
lowerbound=0;
upperbound=10;
dimension=4;
end
end
% F1
function R = F1(x)
R=sum(x.^2);
end
% F2
function R = F2(x)
R=sum(abs(x))+prod(abs(x));
end
% F3
function R = F3(x)
dimension=size(x,2);
R=0;
for i=1:dimension
R=R+sum(x(1:i))^2;
end
end
% F4
function R = F4(x)
R=max(abs(x));
end
% F5
function R = F5(x)
dimension=size(x,2);
R=sum(100*(x(2:dimension)-(x(1:dimension-1).^2)).^2+(x(1:dimension-1)-1).^2);
end
% F6
function R = F6(x)
R=sum(abs((x+.5)).^2);
end
% F7
function R = F7(x)
dimension=size(x,2);
R=sum([1:dimension].*(x.^4))+rand;
end
% F8
function R = F8(x)
R=sum(-x.*sin(sqrt(abs(x))));
end
% F9
function R = F9(x)
dimension=size(x,2);
R=sum(x.^2-10*cos(2*pi.*x))+10*dimension;
end
% F10
function R = F10(x)
dimension=size(x,2);
R=-20*exp(-.2*sqrt(sum(x.^2)/dimension))-exp(sum(cos(2*pi.*x))/dimension)+20+exp(1);
end
% F11
function R = F11(x)
dimension=size(x,2);
R=sum(x.^2)/4000-prod(cos(x./sqrt([1:dimension])))+1;
end
% F12
function R = F12(x)
dimension=size(x,2);
R=(pi/dimension)*(10*((sin(pi*(1+(x(1)+1)/4)))^2)+sum((((x(1:dimension-1)+1)./4).^2).*...
(1+10.*((sin(pi.*(1+(x(2:dimension)+1)./4)))).^2))+((x(dimension)+1)/4)^2)+sum(Ufun(x,10,100,4));
end
% F13
function R = F13(x)
dimension=size(x,2);
R=.1*((sin(3*pi*x(1)))^2+sum((x(1:dimension-1)-1).^2.*(1+(sin(3.*pi.*x(2:dimension))).^2))+...
((x(dimension)-1)^2)*(1+(sin(2*pi*x(dimension)))^2))+sum(Ufun(x,5,100,4));
end
% F14
function R = F14(x)
aS=[-32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32;,...
-32 -32 -32 -32 -32 -16 -16 -16 -16 -16 0 0 0 0 0 16 16 16 16 16 32 32 32 32 32];
for j=1:25
bS(j)=sum((x'-aS(:,j)).^6);
end
R=(1/500+sum(1./([1:25]+bS))).^(-1);
end
% F15
function R = F15(x)
aK=[.1957 .1947 .1735 .16 .0844 .0627 .0456 .0342 .0323 .0235 .0246];
bK=[.25 .5 1 2 4 6 8 10 12 14 16];bK=1./bK;
R=sum((aK-((x(1).*(bK.^2+x(2).*bK))./(bK.^2+x(3).*bK+x(4)))).^2);
end
% F16
function R = F16(x)
R=4*(x(1)^2)-2.1*(x(1)^4)+(x(1)^6)/3+x(1)*x(2)-4*(x(2)^2)+4*(x(2)^4);
end
% F17
function R = F17(x)
R=(x(2)-(x(1)^2)*5.1/(4*(pi^2))+5/pi*x(1)-6)^2+10*(1-1/(8*pi))*cos(x(1))+10;
end
% F18
function R = F18(x)
R=(1+(x(1)+x(2)+1)^2*(19-14*x(1)+3*(x(1)^2)-14*x(2)+6*x(1)*x(2)+3*x(2)^2))*...
(30+(2*x(1)-3*x(2))^2*(18-32*x(1)+12*(x(1)^2)+48*x(2)-36*x(1)*x(2)+27*(x(2)^2)));
end
% F19
function R = F19(x)
aH=[3 10 30;.1 10 35;3 10 30;.1 10 35];cH=[1 1.2 3 3.2];
pH=[.3689 .117 .2673;.4699 .4387 .747;.1091 .8732 .5547;.03815 .5743 .8828];
R=0;
for i=1:4
R=R-cH(i)*exp(-(sum(aH(i,:).*((x-pH(i,:)).^2))));
end
end
% F20
function R = F20(x)
aH=[10 3 17 3.5 1.7 8;.05 10 17 .1 8 14;3 3.5 1.7 10 17 8;17 8 .05 10 .1 14];
cH=[1 1.2 3 3.2];
pH=[.1312 .1696 .5569 .0124 .8283 .5886;.2329 .4135 .8307 .3736 .1004 .9991;...
.2348 .1415 .3522 .2883 .3047 .6650;.4047 .8828 .8732 .5743 .1091 .0381];
R=0;
for i=1:4
R=R-cH(i)*exp(-(sum(aH(i,:).*((x-pH(i,:)).^2))));
end
end
- 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
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
[3]彭浩,和丽芳.基于改进树种算法的彩色图像多阈值分割[J].计算机科学. 2020,47(S1)
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/120915009
- 点赞
- 收藏
- 关注作者
评论(0)