Skip to content

Commit

Permalink
kts
Browse files Browse the repository at this point in the history
  • Loading branch information
HanLeI187 committed Aug 4, 2023
1 parent 5ee6bd7 commit d3d238d
Show file tree
Hide file tree
Showing 16 changed files with 1,354 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
function Offspring01 = Adaptive_sampling(CAobj,DAobj,CAdec,DAdec,DAvar,DA,CA1,mu,p,phi)

%------------------------------- Copyright --------------------------------
% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

% This function is written by Zhenshou Song

Ideal_Point = min([CAobj;DAobj],[],1);

if size(DAdec,1) <= mu
flag = 1;
else
flag = Cal_Convergence(CAobj,DAobj,Ideal_Point);
end

if flag == 1
% convergence sampling strategy
N = size(CAobj,1);
CAobj01 = (CAobj-repmat(min(CAobj),N,1))./(repmat(max(CAobj)-min(CAobj),N,1));
I = zeros(N);
for i = 1:N
for j = 1:N
I(i,j) = max(CAobj01(i,:)-CAobj01(j,:));
end
end
C = max(abs(I));
F = sum(-exp(-I./repmat(C,N,1)/0.05)) + 1;
Choose = 1:N;
while length(Choose) > mu
[~,x] = min(F(Choose));
F = F + exp(-I(Choose(x),:)/C(Choose(x))/0.05);
Choose(x) = [];
end
Offspring01 = CAdec(Choose,:);
else
if size(DAdec,1) <= mu
Offspring01 = DAdec;
else
if PD(DAobj) < PD(DA.objs)
% uncertainty sampling strategy
An = size(DAvar,1);
Choose = zeros(1,5);
for i = 1:mu
A_num = randperm(size(DAvar,1));
Uncertainty = mean(DAvar(A_num(1:ceil(phi*An)),1:size(DAobj,2)),2);
[~,best] = max(Uncertainty);
Choose (i) = A_num(best);
end
Offspring01 = DAdec(Choose ,:);
else
% diversity sampling strategy
DA_Nor = (DA.objs - repmat(min([DAobj;DA.objs],[],1),length(DA),1))...
./repmat(max([DAobj;DA.objs],[],1) - min([DAobj;DA.objs],[],1),length(DA),1);
DA_Nor_pre = (DAobj - repmat(min([DAobj;DA.objs],[],1),size(DAobj,1),1))...
./repmat(max([DAobj;DA.objs],[],1) - min([DAobj;DA.objs],[],1),size(DAobj,1),1);
N = size(DA_Nor,1);
Pop = [DA_Nor;DA_Nor_pre];
Pop_dec = [DA.decs;DAdec];
NN = size(Pop,1);
Choose = false(1,NN);
Choose(1:N) = true;
MaxSize = N+mu;
Distance = inf(N);
for i = 1 : NN-1
for j = i+1 : NN
Distance(i,j) = norm(Pop(i,:)-Pop(j,:),p);
Distance(j,i) = Distance(i,j);
end
end
Offspring01 = [];
while sum(Choose) < MaxSize
Remain = find(~Choose);
[~,x] = max(min(Distance(~Choose,Choose),[],2));
Choose(Remain(x)) = true;
Offspring01 = [Offspring01;Pop_dec(Remain(x),:)];
end
end
end
end
end

function Score = PD(PopObj)
% Pure diversity

N = size(PopObj,1);
C = false(N);
C(logical(eye(size(C)))) = true;
D = pdist2(PopObj,PopObj,'minkowski',0.1);
D(logical(eye(size(D)))) = inf;
Score = 0;
for k = 1 : N-1
while true
[d,J] = min(D,[],2);
[~,i] = max(d);
if D(J(i),i) ~= -inf
D(J(i),i) = inf;
end
if D(i,J(i)) ~= -inf
D(i,J(i)) = inf;
end
P = any(C(i,:),1);
while ~P(J(i))
newP = any(C(P,:),1);
if P == newP
break;
else
P = newP;
end
end
if ~P(J(i))
break;
end
end
C(i,J(i)) = true;
C(J(i),i) = true;
D(i,:) = -inf;
Score = Score + d(i);
end
end
56 changes: 56 additions & 0 deletions PlatEMO/Algorithms/Multi-objective optimization/KTS/CalFitness.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function Fitness = CalFitness(PopObj,PopCon)
% Calculate the fitness of each solution

%------------------------------- Copyright --------------------------------
% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

N = size(PopObj,1);
if nargin == 1
CV = zeros(N,1);
else
CV = sum(max(0,PopCon),2);
end

%% Detect the dominance relation between each two solutions
Dominate = false(N);
for i = 1 : N-1
for j = i+1 : N
if CV(i) < CV(j)
Dominate(i,j) = true;
elseif CV(i) > CV(j)
Dominate(j,i) = true;
else
k = any(PopObj(i,:)<PopObj(j,:)) - any(PopObj(i,:)>PopObj(j,:));
if k == 1
Dominate(i,j) = true;
elseif k == -1
Dominate(j,i) = true;
end
end
end
end

%% Calculate S(i)
S = sum(Dominate,2);

%% Calculate R(i)
R = zeros(1,N);
for i = 1 : N
R(i) = sum(S(Dominate(:,i)));
end

%% Calculate D(i)
Distance = pdist2(PopObj,PopObj);
Distance(logical(eye(length(Distance)))) = inf;
Distance = sort(Distance,2);
D = 1./(Distance(:,floor(sqrt(N)))+2);

%% Calculate the fitnesses
Fitness = R + D';
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function flag = Cal_Convergence(PopObj1,PopObj2,Zmin)

%------------------------------- Copyright --------------------------------
% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

% This function is written by Zhenshou Song

N1 = size(PopObj1,1);
N2 = size(PopObj2,1);
if N1 ~= N2
flag = 0;
else
PopObj = [PopObj1;PopObj2] - repmat(Zmin,size(PopObj1,1)+size(PopObj2,1),1);
PopObj = (PopObj)./repmat(max(PopObj,[],1) - Zmin,size(PopObj,1),1);
Distance1 = zeros(1,N1);
Distance2 = zeros(1,N2);
% calculate the distance sets of CCA and CDA
for i = 1:N1
Distance1(i) = sqrt(sum(PopObj(i,:),2));
end
for i = 1: N2
Distance2(i) = sqrt(sum(PopObj(N1+i,:),2));
end
% rank-sum test, alpha = 0.05
[~,flag,~,r1,r2]=signrank_new(Distance1, Distance2,'alpha',0.05);
if flag == 1 && (r1-r2 <0)
flag = 0;
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function [Population,Fitness1] = KCCMO_sampling(Population,CA1,N)

%------------------------------- Copyright --------------------------------
% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

CA = CA1.best.objs;
if isempty(CA)
CA = CA1.objs;
end

Fitness = CalFitness_new(Population.obj,Population.con,CA);

NCluster = N;
[IDX,~] = kmeans(Population.obj,NCluster);
Next = false(size(Population.obj,1),1);
for i = 1:NCluster
select = find(IDX == i);
Fitness1 = Fitness(select);
[~,index] = min(Fitness1);
Next(select(index)) = true;
end
Population = givevalue(Population,Next);
end

function Fitness = CalFitness_new(PopObj,PopCon,CCA)

N = size(PopObj,1);
if isempty(PopCon)
CV = zeros(N,1);
else
CV = sum(max(0,PopCon),2);
end

%% Detect the dominance relation between each two solutions
Dominate = false(N);
for i = 1 : N-1
for j = i+1 : N
if CV(i) < CV(j)
Dominate(i,j) = true;
elseif CV(i) > CV(j)
Dominate(j,i) = true;
else
k = any(PopObj(i,:)<PopObj(j,:)) - any(PopObj(i,:)>PopObj(j,:));
if k == 1
Dominate(i,j) = true;
elseif k == -1
Dominate(j,i) = true;
end
end

end
end

S = sum(Dominate,2);

R = zeros(1,N);
for i = 1 : N
R(i) = sum(S(Dominate(:,i)));
end

Distance = pdist2(PopObj,CCA);
Distance1 = min(Distance,[],2);
D = 1./(Distance1+2);
Fitness = R + D';
end
Loading

0 comments on commit d3d238d

Please sign in to comment.