【优化算法】世界杯优化算法(WCOA)【含Matlab源码 1427期】

举报
海神之光 发表于 2022/05/29 01:28:09 2022/05/29
【摘要】 一、获取代码方式 获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。 获取代码方式2: 通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。 ...

一、获取代码方式

获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

获取代码方式2:
通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。

获取代码方式3:
完整代码已上传我的资源:【优化算法】世界杯优化算法(WCOA)【含Matlab源码 1427期】

备注:开通CSDN会员,仅只能免费获得1份代码(有效期为开通日起,三天内有效);
订阅紫极神光博客付费专栏,可免费获得2份代码(有效期为订阅日起,三天内有效);

二、部分源代码

function y=my_cost_function(x)
% y=1/x;
% y=x(1)+x(2)+x(3)
% y=sum(x.^2-10*cos(2*pi*x)+10);
% y=sum(-x(1).*sin(sqrt(abs(x(2)))));
% y=abs(sum(abs(x.^2+x).*sin(x)));
% y=sum(x.^2);
% y=x^4+5*x^3+6*x^2+7;
% y=sum(x.^2-10*cos(2*pi*x)+10);
% y=-((sin(x(1)).*(sin(x(1)^2/pi))^(20)+sin(x(2)).*(sin(2*x(2)^2/pi))^(20)));
% y = [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).*(2)+27*x(2).^2)];
%%
% y = (x(1).^2 + x(2) - 11).^2 + (x(1) + x(2).^2 - 7).^2; %himmelblau
% y=(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)); %goldstein & price
y = -cos(x(1)).*cos(x(2)).*exp(-((x(1)-pi).^2 + (x(2)-pi).^2));  % easom
% y=x(1).^2 + x(2).^2 - 10*cos(2*pi*x(1)) - 10*cos(2*pi*x(2)) + 20;% rastrigin
% y=100*(x(2) - x(1).^2).^2 + (1 - x(1)).^2;  %rosenbruck
% y=-((sin(x(1)).*(sin(x(1)^2/pi))^(20)+sin(x(2)).*(sin(2*x(2)^2/pi))^(20)));  % beale
% y=(x(1) + 2*x(2) - 7).^2 + (2*x(1) + x(2) - 5).^2; %booth
% y=100*(x(2) - 0.01*x(1).^2 + 1) + 0.01*(x(1) + 10).^2;  %bukin2
% y=-((cos(x(1)).*cos(x(2)).*exp(abs(1 - sqrt(x(1).^2 + x(2).^2)/pi))).^2)/30;
% y=x(1).^2 - 12*x(1) + 11 + 10*cos(pi*x(1)/2) + 8*sin(5*pi*x(1)/2) - ...
%             1/sqrt(5)*exp(-((x(2) - 0.5).^2)/2);  %chichinzade
% y = 0.6 + sum(sin(16*x/15 - 1) + sin(16*x/15 - 1).^2 + sin(4*16*x/15 - 1)/50, 2); %giunta
% y=(abs(sin(x(1)).*sin(x(2)).*exp(abs(100 - sqrt(x(1).^2 + x(2).^2)/pi))) + 1).^(-0.1);  %crossfun
% y=-0.0001*(abs(sin(x(1)).*sin(x(2)).*exp(abs(100 - sqrt(x(1).^2 + x(2).^2)/pi))) + 1).^(0.1);  %crossintary
% y=-(abs(sin((x(1))).*sin((x(2))).*exp(abs(100 - sqrt((x(1)).^2 + (x(2)).^2)/pi))) + 1).^(-0.1);  %crosslegtable
% y = (x(1).^2 + x(2).^2)/200 - cos(x(1)).*cos(x(2)/sqrt(2)) + 1;%griewank
% y=-abs(sin(x(1)).*cos(x(2)).*exp(abs(1 - sqrt(x(1).^2 + x(2).^2)/pi)));   %holdertable
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Portion of MATLAB Code for                                   %
%                                                               %
%    World Cup Optimization Algorithm (WCO)                     %
%            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ! Caution
%  This program is written for minimizing the ERROR; for different Uses abs
%  command should be elliminater from column 128 to column 156
%% ---------------------------Function-------------------------------------
%1.wca                       Main Function
%2.my_cost_function          Fitness (Cost) Function

%% ------------------INITIALIZATION OF PARAMETERS--------------------------
commandwindow
clear all;
close all;
clc;
disp('**************************************        ')
disp('   World Cup Optimization Algorithm    ')
disp('**************************************        ')
tic
warning('off')
itr=0;
iter=100;                      %no_competition_periods
no_par=2;
% countries=4;
% continents=5;
% popsize=countries*continents;
popsize=50;                   % popsize=no_Rank  
ra=3;                         % Percentage of random countries rise as play-off teams [0 6]
co=rand;
ur=10;                       % Up countries rating
dr=round(co*10);               % Down countries rating
D=10;                          %constant
alpha=.9;                      %exploration_coefficient in the range [0 1]_0 gives Max exploitation & 1 give max exploration 
UB=10*ones(no_par,popsize);     %Upward bound condition
LB=-10*zeros(no_par,popsize);   %Downward bound condition

%% -----------MAIN PROGRAM STARTS------------------------------------------

% ------------Initializing--6 countries ----------------------------------- 

local_best_fitness1=inf;
local_best_fitness2=inf;
local_best_fitness3=inf;
local_best_fitness4=inf;
local_best_fitness5=inf;
local_best_fitness6=inf;

    for i=1:no_par
        for j=1:popsize        
            current_position1(i,j)=(UB(i)-LB(i))*rand+LB(i);
        end
    end
    
    for i=1:no_par
        for j=1:popsize
            current_position2(i,j)=(UB(i)-LB(i))*rand+LB(i);
        end
    end
    
    for i=1:no_par
        for j=1:popsize
            current_position3(i,j)=(UB(i)-LB(i))*rand+LB(i);
        end
    end
    
    for i=1:no_par
        for j=1:popsize
            current_position4(i,j)=(UB(i)-LB(i))*rand+LB(i);
        end
    end
    
    for i=1:no_par
        for j=1:popsize
            current_position5(i,j)=(UB(i)-LB(i))*rand+LB(i);
        end
    end
    
    for i=1:no_par
        for j=1:popsize
            current_position6(i,j)=(UB(i)-LB(i))*rand+LB(i);
        end
    end
    
% --------------------Evaluate initial population--------------------------

while itr<iter 
itr=itr+1;

    for jj=1:popsize
    current_fitness1(jj) = my_cost_function(current_position1(:,jj));    
    end
    

    for jj=1:popsize
    current_fitness2(jj) = my_cost_function(current_position2(:,jj));    
    end

    for jj=1:popsize
    current_fitness3(jj) = my_cost_function(current_position3(:,jj));    
    end

        for jj=1:popsize
    current_fitness4(jj) = my_cost_function(current_position4(:,jj));    
        end

        for jj=1:popsize
    current_fitness5(jj) = my_cost_function(current_position5(:,jj));    
        end

        for jj=1:popsize
    current_fitness6(jj) = my_cost_function(current_position6(:,jj));    
        end

if abs(min(current_fitness1))<abs(min(local_best_fitness1))
    local_best_fitness1=current_fitness1;
    local_best_position1=current_position1;
end

if abs(min(current_fitness2))<abs(min(local_best_fitness2))
    local_best_fitness2=current_fitness2;
    local_best_position2=current_position2;
end

if abs(min(current_fitness3))<abs(min(local_best_fitness3))
    local_best_fitness3=current_fitness3;
    local_best_position3=current_position3;
end

if abs(min(current_fitness4))<abs(min(local_best_fitness4))
    local_best_fitness4=current_fitness4;
    local_best_position4=current_position4;
end

if abs(min(current_fitness5))<abs(min(local_best_fitness5))
    local_best_fitness5=current_fitness5;
    local_best_position5=current_position5;
end

if abs(min(current_fitness6))<abs(min(local_best_fitness6))
    local_best_fitness6=current_fitness6;
    local_best_position6=current_position6;
end


l_b_p=[local_best_position1 local_best_position2 local_best_position3 local_best_position4 local_best_position5 local_best_position6];
l_b_f=[local_best_fitness1;local_best_fitness2;local_best_fitness3;local_best_fitness4;local_best_fitness5;local_best_fitness6];        
        
% ----Evaluate best fittness , position-&-Sorting-for-the next-play-off----

[global_best_fitness1,g1] = min(local_best_fitness1);
[global_best_fitness2,g2] = min(local_best_fitness2);
[global_best_fitness3,g3] = min(local_best_fitness3);
[global_best_fitness4,g4] = min(local_best_fitness4);
[global_best_fitness5,g5] = min(local_best_fitness5);
[global_best_fitness6,g6] = min(local_best_fitness6);


f_b_f=[global_best_fitness1 global_best_fitness2 global_best_fitness3 global_best_fitness4 global_best_fitness5 global_best_fitness6];
[final_best_fitness,no]= min(f_b_f);
% final_best_fitness

global_best_position1 = local_best_position1(:,g1);
global_best_position2 = local_best_position2(:,g2);
global_best_position3 = local_best_position3(:,g3);
global_best_position4 = local_best_position4(:,g4);
global_best_position5 = local_best_position5(:,g5);
global_best_position6 = local_best_position6(:,g6);


f_b_p=[global_best_position1 global_best_position2 global_best_position3 global_best_position4 global_best_position5 global_best_position6];
final_best_position=f_b_p(:,no);                                                                        %%%%%%%%%%%%%

[sort_best_fitness1]= sort(local_best_fitness1,'descend');
[sort_best_fitness2]= sort(local_best_fitness2,'descend');
[sort_best_fitness3]= sort(local_best_fitness3,'descend');
[sort_best_fitness4]= sort(local_best_fitness4,'descend');
[sort_best_fitness5]= sort(local_best_fitness5,'descend');
[sort_best_fitness6]= sort(local_best_fitness6,'descend');
s_b_f=[sort_best_fitness1;sort_best_fitness2;sort_best_fitness3;sort_best_fitness4;sort_best_fitness5;sort_best_fitness6];

pf1=find(local_best_fitness1==sort_best_fitness1(end));
pf2=find(local_best_fitness2==sort_best_fitness2(end));
pf3=find(local_best_fitness3==sort_best_fitness3(end));
pf4=find(local_best_fitness4==sort_best_fitness4(end));
pf5=find(local_best_fitness5==sort_best_fitness5(end));
pf6=find(local_best_fitness6==sort_best_fitness6(end));

%----------Rating----------------------------------------------------------
s=abs(std((l_b_f)'));           % Standard deviation of the local best fitness
m=abs(min((l_b_f)'));           % Mean Value of the local best fitness
mm=(s+m)/2;                     % Rating
[so cn]=sort(mm);               % Sort & country number  

ucn=cn(1:ra);                   % Up Country No.
dcn=cn(ra+1:end);               % Down Country No.

n1=s_b_f(ucn,end-ra+1:end);
n2=s_b_f(dcn,end-ra+1:end);
n=[n1(:);n2(:)];

if length(n)<popsize
t=popsize-length(n);  
n3=s_b_f(1:t);
    n=[n1(:);n2(:);n3(:)];
else if length(n)>popsize
        n=n(1:popsize,:);
    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

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/120914937

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。