-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGEA improvement.txt
151 lines (136 loc) · 5.85 KB
/
GEA improvement.txt
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
%___________________________________________________________________%
% Geyser Algorithm (GEA) source codes version 1.1 %
% %
% %
% Homepages:https://www.optim-app.com %
% %
% Authors: Mojtaba Ghasemi, Mohsen Zare, Amir Zahed %
% Mohammad‑Amin Akbari, Seyedali Mirjalili,Laith Abualigah %
% Title: Geyser Inspired Algorithm: %
% A New Geological‑inspired Meta‑heuristic %
% for Real‑parameter and Constrained Engineering Optimization %
% %
% Journal of Bionic Engineering (2023 %
% https://doi.org/10.1007/s42235-023-00437-8 %
%___________________________________________________________________%
clc;
close all
clear all;
% Parameters
VarMin = -100; % Decision Variables Lower Bound
VarMax = -VarMin; % Decision Variables Upper Bound
nVar = 30; % Number of Decision Variables
VarSize = [1 nVar]; % Decision Variables Matrix Size
Nc = 40; % Number of Channels
FEs = 5000; % Maximum Number of Function Evaluations (Changed to 5000)
nPop = 60; % Number of Geysers (Swarm Size)
tournamentSize = 5; % Tournament selection parameter
epsilon = 1e-6; % Epsilon for CostFunction
% Function to be optimized
CostFunction = @(x) sum(log(epsilon + x.^2), 2); % Modified CostFunction
% Initialization
Geyser.Position = []; % Empty Geyser Structure
Geyser.Cost = [];
pop = repmat(Geyser, nPop, 1); % Initialize Population Array
BestSol.Cost = inf; % Initialize Best Solution Ever Found
BestCost = zeros(FEs, 1); % Array to store best cost history
% Create Initial population of Geysers
for i=1:nPop
pop(i).Position = unifrnd(VarMin, VarMax, VarSize);
pop(i).Cost = CostFunction(pop(i).Position);
if pop(i).Cost <= BestSol.Cost
BestSol = pop(i);
end
BestCost(i) = BestSol.Cost;
end
it = nPop;
while it <= FEs
for i=1:nPop
%%%%%%%%%%%%%%% Implementing Eq(3) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ii=1:nPop
D1(ii) = sum(pop(i).Position.*pop(ii).Position) / (((sum(pop(i).Position.^2)*sum(pop(ii).Position.^2)))^0.5); % Eq(3)
if ii == i
D1(ii) = inf;
end
end
S1 = min(D1);
[~,j1] = find(S1 == D1);
%%%% Calculating the pressure value in Eq(6) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[CS, Sortorder] = sort([pop.Cost]);
dif = (CS(end)-CS(1)); % fmax-fmin Eq(6)
G = ((pop(i).Cost-CS(1))/dif); % f(i)-fmin Eq(6)
if dif == 0;
G = 0;
end
if it == 1
it = 2;
end
P_i(i) = (((G^(2/it))-(G^((it+1)/it)))^0.5)*((it/(it-1))^0.5); % Pi Eq(6)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% Search for channels using Tournament Selection %%%%%
ImpFitness = 0;
for ii=1:Nc
ImpFitness = ImpFitness + pop(ii).Cost;
end
p = [];
if ImpFitness == 0
ImpFitness = 1e-320;
end
for ii=1:Nc
p(ii) = pop(ii).Cost/ImpFitness; % Eq(1)
end
% Tournament Selection
i1 = TournamentSelection(pop, p, tournamentSize);
flag = 0;
%%%%%%%%%%%%%%% Implementing Eq(5) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
newsol.Position = pop(j1(1)).Position + (rand(VarSize)).*(pop(i1).Position - pop(j1(1)).Position) + (rand(VarSize)).*(pop(i1).Position - pop(i).Position);
newsol.Position = max(newsol.Position, VarMin);
newsol.Position = min(newsol.Position, VarMax);
newsol.Cost = CostFunction(newsol.Position);
it = it + 1;
if newsol.Cost <= pop(i).Cost
pop(i) = newsol;
flag = 0;
end
if newsol.Cost <= BestSol.Cost
BestSol = newsol;
end
BestCost(it) = BestSol.Cost;
if flag == 0
% Implement Roulette Wheel Selection with Elitism
i2 = RouletteWheelSelection(1 - p);
%%%%%%%%%%%%%%% Implementing Eq(8) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
newsol.Position = pop(i2).Position + rand*(P_i(i)-rand)*unifrnd(1*VarMin,1*VarMax,VarSize);
newsol.Position = max(newsol.Position, VarMin);
newsol.Position = min(newsol.Position, VarMax);
newsol.Cost = CostFunction(newsol.Position);
it = it + 1;
if newsol.Cost <= pop(i).Cost
pop(i) = newsol;
end
if newsol.Cost <= BestSol.Cost
BestSol = newsol;
end
BestCost(it) = BestSol.Cost;
end
end
[~, Sortorder] = sort([pop.Cost]);
pop = pop(Sortorder);
if mod(it, 100) == 0
disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]);
end
end
% ... (các phần code sau) ...
% Function to perform Tournament Selection
function selectedChannel = TournamentSelection(pop, p, tournamentSize)
tournament = randi(length(p), 1, tournamentSize);
[~, index] = min(p(tournament));
selectedChannel = tournament(index);
end
% Function to perform Roulette Wheel Selection
function selectedChannel = RouletteWheelSelection(p)
c = cumsum(p);
r = rand();
selectedChannel = find(r <= c, 1, 'first');
end
169