-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDIWJAYA.m
161 lines (142 loc) · 5.48 KB
/
DIWJAYA.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
161
%---------------------------------------------------------------------------------------------------------------------------
% DIWJAYA
% DIWJAYA: JAYA driven by individual weights for enhanced photovoltaic model parameter estimation
function [Best_jaya_rate,Best_jaya,Convergence_curve]=DIWJAYA(N,Max_iter,lb,ub,dim,fobj,index)
% initialize position
Best_jaya=zeros(1,dim);
Best_jaya_rate=inf;%change this to -inf for maximization problems
Jayapop=initialization(N,dim,ub,lb);%Initialize the set of random solutions
Lb=lb.*ones(1,dim);% lower boundary
Ub=ub.*ones(1,dim);% upper boundary
it=1;%Number of iterations
Convergence_curve=zeros(1,Max_iter);
Jaya_rates=zeros(1,N);%Initialize the fitness value
newJaya_rates=zeros(1,N);
%Calculate the fitness value of the initial position
for i=1:N
x=Jayapop(i,:);
[Im,Vm]=IVload;
Iph=x(1);
I0=x(2);
Rs=x(3);
Rsh=x(4);
n=x(5);
I02=x(6);
n2=x(7);
I03=x(8);
n3=x(9);
k = 1.380649e-23;
T = 273.15+45;
q = 1.602176634e-19;
Vth= k*T/q;
Ns=36;
a=n*Vth*Ns;
a2=n2*Vth*Ns;
a3=n3*Vth*Ns;
I = -Vm./(Rs + Rsh) - lambertw(Rs.*I0.*Rsh.*exp(Rsh.*(Rs.*Iph + Rs.*I0 + Vm)./(a.*(Rs + Rsh)))./(a.*(Rs + Rsh))).*a./Rs...
- lambertw(Rs.*I02.*Rsh.*exp(Rsh.*(Rs.*Iph + Rs.*I02 + Vm)./(a2.*(Rs + Rsh)))./(a2.*(Rs + Rsh))).*a2./Rs...
- lambertw(Rs.*I03.*Rsh.*exp(Rsh.*(Rs.*Iph + Rs.*I03 + Vm)./(a3.*(Rs + Rsh)))./(a3.*(Rs + Rsh))).*a3./Rs+ (Rsh.*(I0 + Iph + I02 + I03))./(Rs + Rsh);
fit_I=sqrt(sum((Im-I).^2)/length(Im));
Jaya_rates(1,i)=fit_I;
%Make greedy selections
if Jaya_rates(1,i)<Best_jaya_rate
Best_jaya_rate=Jaya_rates(1,i);
Best_jaya=Jayapop(i,:);
end
end
% Main loop
while it <= Max_iter
[Java_worst,worst_position]=max(Jaya_rates);
for i=1:N
if Jaya_rates(1,i)~=0
fai(1,i)=Best_jaya_rate/Jaya_rates(1,i);
else
fai(1,i)=1;
end
end
mean_fai=mean(fai);
for i=1:N
if Jaya_rates(1,i)==Java_worst
Ymin = -10;
Ymax = 10;
n = 10000;
Y = linspace(Ymin, Ymax, n); % Generate Y values uniformly
% Loop through each dimension
for j = 1:dim
mu = 0; % Mean for the Gaussian function
ht = 1 - it / Max_iter; % Adaptation factor based on the current iteration
% Randomly select an index for y_gaussian
iy_gaussian = randi([1, length(Y)]);
y_gaussian = Y(iy_gaussian);
% Calculate the Gaussian term
gauss_term = (1 / (sqrt(2 * pi) * ht)) * exp(-(y_gaussian - mu)^2 / (2 * ht^2));
gauss_term_zero = (1 / (sqrt(2 * pi) * ht)) * exp(-(0 - mu)^2 / (2 * ht^2));
% Calculate the new value for Jaya_new based on a random draw
if rand > 0.5
Jaya_new(i, j) = Best_jaya(1, j) + (Ub(j) - Lb(j)) * (gauss_term / gauss_term_zero);
else
Jaya_new(i, j) = Best_jaya(1, j) - (Ub(j) - Lb(j)) * (gauss_term / gauss_term_zero);
end
end
elseif fai(1,i)<=mean_fai^2
for j=1:dim
c1=rand;
Jaya_new(i,j)=Jayapop(i,j)+rand*(c1*Best_jaya(1,j)+(1-c1)*mean(Jayapop(:,j))-abs(Jayapop(i,j)))-fai(1,i)^2*rand*(Jayapop(worst_position,j)-abs(Jayapop(i,j)));
end
else
Candidates=[1:i-1 i+1:N];
choose_sample =Candidates(randperm(N-1,2));
if fai(choose_sample(1))>fai(choose_sample(2))
xm=Jayapop(choose_sample(1),:);
xn=Jayapop(choose_sample(2),:);
else
xm=Jayapop(choose_sample(2),:);
xn=Jayapop(choose_sample(1),:);
end
Jaya_new(i,:)=Jayapop(i,:)+rand*(xm-xn);
end
end
for i=1:N
for j=1:dim
if Jaya_new(i,j)>ub(j)||Jaya_new(i,j)<lb(j)
Jaya_new(i,j)=(ub(j)+lb(j))/2+(ub(j)-lb(j))/2*(2*rand-1);
end
end
end
for i=1:N
x=Jaya_new(i,:);
[Im,Vm]=IVload;
Iph=x(1);
I0=x(2);
Rs=x(3);
Rsh=x(4);
n=x(5);
I02=x(6);
n2=x(7);
I03=x(8);
n3=x(9);
k = 1.380649e-23;
T = 273.15+45;
q = 1.602176634e-19;
Vth= k*T/q;
Ns=36;
a=n*Vth*Ns;
a2=n2*Vth*Ns;
a3=n3*Vth*Ns;
I = -Vm./(Rs + Rsh) - lambertw(Rs.*I0.*Rsh.*exp(Rsh.*(Rs.*Iph + Rs.*I0 + Vm)./(a.*(Rs + Rsh)))./(a.*(Rs + Rsh))).*a./Rs...
- lambertw(Rs.*I02.*Rsh.*exp(Rsh.*(Rs.*Iph + Rs.*I02 + Vm)./(a2.*(Rs + Rsh)))./(a2.*(Rs + Rsh))).*a2./Rs...
- lambertw(Rs.*I03.*Rsh.*exp(Rsh.*(Rs.*Iph + Rs.*I03 + Vm)./(a3.*(Rs + Rsh)))./(a3.*(Rs + Rsh))).*a3./Rs+ (Rsh.*(I0 + Iph + I02 + I03))./(Rs + Rsh);
fit_I=sqrt(sum((Im-I).^2)/length(Im));
newJaya_rates(1,i)=fit_I;
if newJaya_rates(1,i)<Jaya_rates(1,i)
Jaya_rates(1,i) = newJaya_rates(1,i);
Jayapop(i,:) = Jaya_new(i,:);
if newJaya_rates(1,i)< Best_jaya_rate
Best_jaya_rate=Jaya_rates(1,i);
Best_jaya=Jayapop(i,:);
end
end
end
Convergence_curve(it)=Best_jaya_rate;
it=it+1;
end