【优化算法】吉萨金字塔建造优化算法(GPC)【含Matlab源码 1438期】
【摘要】
一、获取代码方式
获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2: 完整代码已上传我的资源:【优化算法】吉萨金字塔建造优化算法(GPC)【含Mat...
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【优化算法】吉萨金字塔建造优化算法(GPC)【含Matlab源码 1438期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
% Giza Pyramids Construction (GPC) Algorithm
%
%
% -------------------------------------------------
clc;
clear;
close all;
%% Problem Definition
CostFunction=@(x) Sphere(x); % Cost Function
nVar=30; % Number of Decision Variables
VarSize=[1 nVar]; % Decision Variables Matrix Size
VarMin=-5.12; % Decision Variables Lower Bound
VarMax= 5.12; % Decision Variables Upper Bound
%% Giza Pyramids Construction (GPC) Parameters
MaxIteration=1000; % Maximum Number of Iterations (Days of work)
nPop=20; % Number of workers
G = 9.8; % Gravity
Tetha = 14; % Angle of Ramp
MuMin = 1; % Minimum Friction
MuMax = 10; % Maximum Friction
pSS= 0.5; % Substitution Probability
%% Initialization
% Empty Stones Structure
stone.Position=[];
stone.Cost=[];
% Initialize Population Array
pop=repmat(stone,nPop,1);
% Initialize Best Solution Ever Found
best_worker.Cost=inf;
% Create Initial Stones
for i=1:nPop
pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
pop(i).Cost=CostFunction(pop(i).Position);
if pop(i).Cost<=best_worker.Cost
best_worker=pop(i); % as Pharaoh's special agent
end
end
% Array to Hold Best Cost Values
BestCost=zeros(MaxIteration,1);
%% Giza Pyramids Construction (GPC) Algorithm Main Loop
for it=1:MaxIteration
newpop=repmat(stone,nPop,1);
for i=1:nPop
newpop(i).Cost = inf;
V0= rand(1,1); % Initial Velocity
Mu= MuMin+(MuMax-MuMin)*rand(1,1); % Friction
d = (V0^2)/((2*G)*(sind(Tetha)+(Mu*cosd(Tetha)))); % Stone Destination
x = (V0^2)/((2*G)*(sind(Tetha))); % Worker Movement
epsilon=unifrnd(-((VarMax-VarMin)/2),((VarMax-VarMin)/2),VarSize); % Epsilon
newsol.Position = (pop(i).Position+d).*(x*epsilon); % Position of Stone and Worker
% newsol.Position = (pop(i).Position+d)+(x*epsilon); % Note: In some cases or some problems use this instead of the previous line to get better results
newsol.Position=max(newsol.Position,VarMin);
newsol.Position=min(newsol.Position,VarMax);
% Substitution
z=zeros(size(pop(i).Position));
k0=randi([1 numel(pop(i).Position)]);
for k=1:numel(pop(i).Position)
if k==k0 || rand<=pSS
z(k)=newsol.Position(k);
else
z(k)=pop(i).Position(k);
end
end
newsol.Position=z;
newsol.Cost=CostFunction(newsol.Position);
if newsol.Cost <= newpop(i).Cost
newpop(i) = newsol;
if newpop(i).Cost<=best_worker.Cost
best_worker=newpop(i);
end
end
end
% Merge
pop=[pop
newpop]; %#ok
% Sort
[~, SortOrder]=sort([pop.Cost]);
pop=pop(SortOrder);
% Truncate
pop=pop(1:nPop);
% Store Best Cost Ever Found
BestCost(it)=pop(1).Cost;
% Show Iteration Information
disp(['It:' num2str(it) ', Cost => ' num2str(BestCost(it))]);
end
figure;
%plot(BestCost,'LineWidth',2);
semilogy(BestCost,'LineWidth',2);
xlabel('Iteration');
ylabel('Best Cost');
%grid on;
- 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
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/120915065
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)