e1,d1,n1\]=eig(JR);%计算矩阵A的特征值和特征向量的函数是eig(A)\[V,D,W\] = eig(A),\[V,D,W\] = eig(A)返回满矩阵 W,其列是对应的左特征向量,使得 W'A = DW'。
%diag(A),若A是一个矩阵,则diag函数的作用是产生提取矩阵的对角线;若a是一个向量,则diag函数的作用是产生一个对角线为a的矩阵
%% 目标2 电压稳定性
f2val=max(1./diag((d1)))\*max(abs(dQ));%目标2,稳定性
del(2:nbus) = dTh + del(2:nbus);
k = 1;
for i = 2:nbus
if type(i) == 3
V(i) = dV(k) + V(i);
k = k+1;
end
end
%% 目标2和目标3
tval=sum(1./diag((d1)));
po_val=flow_cal(nbus,V,del,BMva);
f1val=sum(po_val);%各支路网损和
f3val=sum(datain(5:8));%DG容量和
fout=\[f1val; f2val; f3val\];
for i = 1 : N
% Number of individuals that dominate this individual
individual(i).n = 0;
% Individuals which this individual dominate
individual(i).p = \[\];
for j = 1 : N
dom_less = 0;
dom_equal = 0;
dom_more = 0;
for k = 1 : M
if (x(i,V + k) \< x(j,V + k))
dom_less = dom_less + 1;
elseif (x(i,V + k) == x(j,V + k))
dom_equal = dom_equal + 1;
else
dom_more = dom_more + 1;
end
end
if dom_less == 0 \&\& dom_equal \~= M %大于等于的情况
individual(i).n = individual(i).n + 1;
elseif dom_more == 0 \&\& dom_equal \~= M %小于等于的情况
individual(i).p = \[individual(i).p j\];
end
end
if individual(i).n == 0
x(i,M + V + 1) = 1;
F(front).f = \[F(front).f i\];
end
end
% Find the subsequent fronts
while \~isempty(F(front).f)
Q = \[\];
for i = 1 : length(F(front).f)
if \~isempty(individual(F(front).f(i)).p)
for j = 1 : length(individual(F(front).f(i)).p)
individual(individual(F(front).f(i)).p(j)).n = ...
individual(individual(F(front).f(i)).p(j)).n - 1;
if individual(individual(F(front).f(i)).p(j)).n == 0
x(individual(F(front).f(i)).p(j),M + V + 1) = ...
front + 1;
Q = \[Q individual(F(front).f(i)).p(j)\];
end
end
end
end
front = front + 1;
F(front).f = Q;
end
\[temp,index_of_fronts\] = sort(x(:,M + V + 1));
for i = 1 : length(index_of_fronts)
sorted_based_on_front(i,:) = x(index_of_fronts(i),:);
end
current_index = 0;
%% Crowding distance
%The crowing distance is calculated as below
% ?For each front Fi, n is the number of individuals.
% ?initialize the distance to be zero for all the individuals i.e. Fi(dj ) = 0,
% where j corresponds to the jth individual in front Fi.
% ?for each objective function m
% \* Sort the individuals in front Fi based on objective m i.e. I =
% sort(Fi,m).
% \* Assign infinite distance to boundary values for each individual
% in Fi i.e. I(d1) = ? and I(dn) = ?
% \* for k = 2 to (n ? 1)
% ?I(dk) = I(dk) + (I(k + 1).m ? I(k ? 1).m)/fmax(m) - fmin(m)
% ?I(k).m is the value of the mth objective function of the kth
% individual in I
% Find the crowding distance for each individual in each front
for front = 1 : (length(F) - 1)
% objective = \[\];
distance = 0;
y = \[\];
previous_index = current_index + 1;
for i = 1 : length(F(front).f)
y(i,:) = sorted_based_on_front(current_index + i,:);
end
current_index = current_index + i;
% Sort each individual based on the objective
sorted_based_on_objective = \[\];
for i = 1 : M
\[sorted_based_on_objective, index_of_objectives\] = ...
sort(y(:,V + i));
sorted_based_on_objective = \[\];
for j = 1 : length(index_of_objectives)
sorted_based_on_objective(j,:) = y(index_of_objectives(j),:);
end
f_max = ...
sorted_based_on_objective(length(index_of_objectives), V + i);
f_min = sorted_based_on_objective(1, V + i);
y(index_of_objectives(length(index_of_objectives)),M + V + 1 + i)...
= Inf;
y(index_of_objectives(1),M + V + 1 + i) = Inf;
for j = 2 : length(index_of_objectives) - 1
next_obj = sorted_based_on_objective(j + 1,V + i);
previous_obj = sorted_based_on_objective(j - 1,V + i);
if (f_max - f_min == 0)
y(index_of_objectives(j),M + V + 1 + i) = Inf;
else
y(index_of_objectives(j),M + V + 1 + i) = ...
(next_obj - previous_obj)/(f_max - f_min);
end
end
end
distance = \[\];
distance(:,1) = zeros(length(F(front).f),1);
for i = 1 : M
distance(:,1) = distance(:,1) + y(:,M + V + 1 + i);
end
y(:,M + V + 2) = distance;
y = y(:,1 : M + V + 2);
z(previous_index:current_index,:) = y;
end
f = z();
## ****🎉4**** ****参考文献****
> 部分理论来源于网络,如有侵权请联系删除。
\[1\]周洋,许维胜,王宁,邵炜晖.基于改进粒子群算法的多目标分布式电源选址定容规划\[J\].计算机科学,2015,42(S2):16-18+31.
\[2\]冯元元. 基于多目标规划的分布式发电选址定容研究\[D\].华北电力大学,2015.
\[3\]杨智君. 基于群智能算法的分布式电源选址与定容\[D\].太原科技大学,2019.DOI:10.27721/d.cnki.gyzjc.2019.000065.