-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICHIO.m
160 lines (135 loc) · 5.89 KB
/
ICHIO.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
159
160
function [Best_pos,Best_score,CHIO_curve]=ICHIO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) %开始优化
if(max(size(ub)) == 1)
ub = ub.*ones(1,dim);
lb = lb.*ones(1,dim);
end
PopSize=SearchAgents_no;
MaxAge = 100;
C0 = 1; % number of solutions have corona virus
Max_iter=Max_iteration; %/*The number of cycles for foraging {a stopping criteria}*/
SpreadingRate = 0.05; % Spreading rate parameter
ObjVal = zeros(1,PopSize);
Age = zeros(1,PopSize);
% Initializing arrays
swarm=zeros(PopSize,dim);
swarm=initializationNew(PopSize,dim,ub,lb);
for i=1:PopSize
ObjVal(i)=fobj(swarm(i,:));
end
[minValue ,index]=min(ObjVal);
Best_score = minValue;
Best_pos = swarm(index,:);
Fitness=calculateFitness(ObjVal);
%% update the status of the swarms (normal, confirmed)
%%the minmum C0 Immune rate will take 1 status which means
%%infected by corona
Status=zeros(1,PopSize);
for i=1:C0
Status(fix(rand*(PopSize))+1)=1;
end
itr=0; % Loop counter
while itr<Max_iter
w = 1-(itr/Max_iter)^2;
for i=1:PopSize
NewSol=swarm(i,:);
% NewSol_f=NewSol(1:131);
% while sum(sum(NewSol_f<0.2))<101
% NewSolConst = initialization(1,dim-1,ub,lb);
% swarm(i,1:131) = NewSolConst(:);
% Status(i) = 0;
% NewSol=swarm(i,:);
% end
CountCornoa = 0;
% find the set of confirmed solutions
confirmed = randperm(size(find(Status==1),2));
confirmed1 = find(Status==1);
%find(Status==1);
% find the set of normal solutions
normal = randperm(size(find(Status==0),2));
normal1 = find(Status==0);
% find the set of recovered solutions
recovered = find(ObjVal & Status==2);
[cost,Index3]=min(recovered);
for j=1: dim
r = rand(); % select a number within range 0 to 1.
if ((r < SpreadingRate/3)&&(size(confirmed1,2)>0))
% select one of the confirmed solutions
z=round(1+(size(confirmed1,2)-1)*rand);
zc= confirmed1(z);
% modify the curent value
NewSol(j) = w*swarm(i,j)+(swarm(i,j)-swarm(zc,j))*(rand-0.5)*2; %引入惯性权重
% manipulate range between lb and ub
NewSol(j)= min(max(NewSol(j),lb(j)),ub(j));
CountCornoa = CountCornoa + 1;
elseif ((r < SpreadingRate/2) &&size(normal1,2)>0)
% select one of the normal solutions
z=round(1+(size(normal1,2)-1)*rand);
zn= normal1(z);
% modify the curent value
NewSol(j) = w*swarm(i,j)+(swarm(i,j)-swarm(zn,j))*(rand-0.5)*2;%引入惯性权重
% manipulate range between lb and ub
NewSol(j)= min(max(NewSol(j),lb(j)),ub(j));
elseif (r < SpreadingRate && size(recovered,2)>0)
% modify the curent value
NewSol(j) = w*swarm(i,j)+(swarm(i,j)-swarm(Index3,j))*(rand-0.5)*2;%引入惯性权重
% manipulate range between lb and ub
NewSol(j)= min(max(NewSol(j),lb(j)),ub(j));
end
end
%evaluate new solution
ObjValSol=fobj(NewSol);
FitnessSol=calculateFitness(ObjValSol);
% Update the curent solution & Age of the current solution
if (ObjVal(i)>ObjValSol)
swarm(i,:)=NewSol;
Fitness(i)=FitnessSol;
ObjVal(i)=ObjValSol;
else
if(Status(i)==1)
Age(i) = Age(i) + 1;
end
end
% change the solution from normal to confirmed
if ((Fitness(i) < mean(Fitness))&& Status(i)==0 && CountCornoa>0)
Status(i) = 1;
Age(i)=1;
end
% change the solution from confirmed to recovered
if ((Fitness(i) >= mean(Fitness))&& Status(i)==1)
Status(i) = 2;
Age(i)=0;
end
% killed the current soluion and regenerated from scratch
if(Age(i)>=MaxAge)
NewSolConst = initialization(1,dim,ub,lb);
swarm(i,:) = NewSolConst(:);
Status(i) = 0;
end
end
itr=itr+1;
[minValue ,index]=min(ObjVal);
if minValue<Best_score
Best_score = minValue;
Best_pos = swarm(index,:);
end
w = 1-(i/Max_iter)^2;
for j = 1:dim
Temp =Best_pos;
Temp(j) = w.*Temp(j) + randn()*Temp(j);
if Temp(j)>ub(j)
Temp(j)=ub(j);
end
if Temp(j)<lb(j)
Temp(j)=lb(j) ;
end
fTemp = fobj(Temp);
if fTemp < Best_score
X(index,:) = Temp;
Best_score = fTemp;
Best_pos = Temp;
end
end
CHIO_curve(itr) = Best_score;
Best_score
end
end