Skip to content

Commit

Permalink
platEMO4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
HanLeI187 committed Oct 21, 2023
1 parent 77d9388 commit f8e4246
Show file tree
Hide file tree
Showing 139 changed files with 9,683 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
if CV(i)==0||R(i)==0
Fitness(i)=0;
else
Fitness(i)=CalFitness(PopObj(i,:),PopCon(i,:));
Fitness(i)=CalFitness1(PopObj(i,:),PopCon(i,:));
end
end
end
5 changes: 2 additions & 3 deletions PlatEMO/Algorithms/Multi-objective optimization/DWU/DWU.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
function main(Algorithm,Problem)
%% Generate random population
Population = Problem.Initialization();
[Population,FrontNo] = EnvironmentalSelection(Population,Problem.N);

%% Optimization
while Algorithm.NotTerminated(Population)
MatingPool = TournamentSelection(2,Problem.N,FrontNo);
MatingPool = TournamentSelection(2,Problem.N,sum(max(0,Population.cons),2));
Offspring = OperatorGA(Problem,Population(MatingPool));
[Population,FrontNo,] = EnvironmentalSelection([Population,Offspring],Problem.N);
Population = EnvironmentalSelection([Population,Offspring],Problem.N);
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
% a population P of approximate solutions generated by a multi-objective
% evolutionary algorithm, with cardinality |Population|, according to the
% uniformity measure.

%% Start
B.objs = Population.objs;
B.decs = Population.decs;
B.wgts = Weight;
Next = (1:length(Population));
Next = (1:length(Population));

R.wgts = zeros(N,size(B.wgts,2));
R.decs = zeros(N,size(B.decs,2));
Expand All @@ -33,20 +33,47 @@

% Find xi and xj in NP(non-dominated solutions of Population) with
% maximum wd(xi; xj) (dominance-weighted uniformity function).
ind = Front == 1;
Aux.decs = B.decs(ind,:);
Aux.wgts = B.wgts(ind,:);
[D,I] = distDWU(Aux,Aux,-1);
[~, j] = max(D);
R.decs(ii,:) = B.decs(j,:);
R.wgts(ii,:) = B.wgts(j,:);
ii = ii + 1;
R.decs(ii,:) = B.decs(I(j),:);
R.wgts(ii,:) = B.wgts(I(j),:);
B.decs([j I(j)],:)=[];
B.wgts([j I(j)],:)=[];
Remain = Next([j I(j)]);
Next([j I(j)])=[];
ind = Front == min(Front);
if sum(ind) == 1
Aux.decs = B.decs(ind,:);
Aux.wgts = B.wgts(ind,:);
Aux.next = Next(ind);
%
nFront = Front(~ind);
C.decs = B.decs(~ind,:);
C.wgts = B.wgts(~ind,:);
nNext = Next(~ind);
ind1 = nFront == min(nFront);
Aux.decs = [Aux.decs;C.decs(ind1,:)];
Aux.wgts = [Aux.wgts;C.wgts(ind1,:)];
Aux.next = [Aux.next nNext(ind1)];
[D,I] = distDWU(Aux,Aux,-1);
[~, j] = max(D);
R.decs(ii,:) = Aux.decs(j,:);
R.wgts(ii,:) = Aux.wgts(j,:);
ii = ii + 1;
R.decs(ii,:) = Aux.decs(I(j),:);
R.wgts(ii,:) = Aux.wgts(I(j),:);
B.decs(Aux.next([j I(j)]),:)=[];
B.wgts(Aux.next([j I(j)]),:)=[];
Remain = Next(Aux.next([j I(j)]));
Next(Aux.next([j I(j)]))=[];
else
Aux.decs = B.decs(ind,:);
Aux.wgts = B.wgts(ind,:);
Aux.next = Next(ind);
[D,I] = distDWU(Aux,Aux,-1);
[~, j] = max(D);
R.decs(ii,:) = Aux.decs(j,:);
R.wgts(ii,:) = Aux.wgts(j,:);
ii = ii + 1;
R.decs(ii,:) = Aux.decs(I(j),:);
R.wgts(ii,:) = Aux.wgts(I(j),:);
B.decs(Aux.next([j I(j)]),:)=[];
B.wgts(Aux.next([j I(j)]),:)=[];
Remain = Next(Aux.next([j I(j)]));
Next(Aux.next([j I(j)]))=[];
end

while ii < N
ii = ii + 1;
Expand Down
10 changes: 6 additions & 4 deletions PlatEMO/Algorithms/Multi-objective optimization/HEA/HEA.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef HEA < ALGORITHM
% <multi/many> <real/binary/permutation>
% Hyper-dominance based evolutionary algorithm
% MaxT --- 0.05 --- The maximum value of tolerance
% MaxT --- 0.05 --- The maximum value of tolerance

%------------------------------- Reference --------------------------------
% Z. Liu, F. Han, Q. Ling, H. Han, and J. Jiang, A many-objective
Expand All @@ -20,16 +20,19 @@

methods
function main(Algorithm,Problem)

%% Parameter setting
MaxT = Algorithm.ParameterSet(0.05);
[W, Problem.N] = UniformPoint(Problem.N,Problem.M);
T = 0;
step = MaxT/(Problem.maxFE / Problem.N);

%% Generate random population
Population = Problem.Initialization();
Solutions = Population;
zmin = min(Population.objs,[],1);
zmax = max(max(Population.objs, [], 1), zmin + 1e-6);

%% Optimization
while Algorithm.NotTerminated(Solutions)
MatingPool = randperm(length(Population));
Expand All @@ -43,7 +46,7 @@ function main(Algorithm,Problem)
T = T + step;
[Solutions, hd] = EnvironmentalSelection_HEA(Population, hd, zmin, zmax, Problem.N, W);

%% Population reselection strategy
%% Population reselection strategy
Population = Solutions;
r = unidrnd(Problem.N,[1,Problem.N]);
for i = 1: Problem.N
Expand All @@ -54,5 +57,4 @@ function main(Algorithm,Problem)
end
end
end
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function Fitness = CalFitness1(PopObj,PopCon,processcon,epsilon)
% 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);
CV = PopCon(:,processcon);
CV = sum(max(0,CV),2);
CV(find(CV<=epsilon)) = 0;
%% 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,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,81 @@
function [PopDec,PopObj,Fitness] = EnvironmentalSelection(PopDec,PopObj,NI,M,status)
% Environmental selection

%------------------------------- 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".
%--------------------------------------------------------------------------

%% Delete the duplicated points
[~, Unduplicated] = unique(PopObj(:,1:M),'rows');
PopDec = PopDec(Unduplicated,:);
PopObj = PopObj(Unduplicated,:);

%% Calculate the fitness of each solution
if nargin == 4
Fitness = CalFitness(PopObj);
else
if status == 1
RealObj = PopObj(:,1:M);
CV = PopObj(:,end);
Fitness = CalFitness(RealObj,max(0,CV));
elseif status == 2
RealObj = PopObj(:,1:M);
PopCon = PopObj(:,M+1:end);
CV = sum(max(0,PopCon),2);
Fitness = CalFitness([RealObj,CV]);
elseif status == 3
Fitness = CalFitness(PopObj);
end
end

%% Environmental selection
if nargin == 4
Next = Fitness < 1;
if sum(Next) < NI
[~,Rank] = sort(Fitness);
Next(Rank(1:NI)) = true;
elseif sum(Next) > NI
Del = Truncation(PopObj(Next,:),sum(Next)-NI);
Temp = find(Next);
Next(Temp(Del)) = false;
end
else
Next = Fitness < 1;
if sum(Next) < NI
[~,Rank] = sort(Fitness);
Next(Rank(1:NI)) = true;
elseif sum(Next) > NI
if status ~=3
RealObj = PopObj(:,1:M);
else
RealObj = PopObj;
end
Del = Truncation(RealObj(Next,:),sum(Next)-NI);
Temp = find(Next);
Next(Temp(Del)) = false;
end
end
PopDec = PopDec(Next,:);
PopObj = PopObj(Next,:);
Fitness = Fitness(Next);
end

function Del = Truncation(PopObj,K)
% Select part of the solutions by truncation

%% Truncation
Distance = pdist2(PopObj,PopObj);
Distance(logical(eye(length(Distance)))) = inf;
Del = false(1,size(PopObj,1));
while sum(Del) < K
Remain = find(~Del);
Temp = sort(Distance(Remain,Remain),2);
[~,Rank] = sortrows(Temp);
Del(Remain(Rank(1))) = true;
end
end
Loading

0 comments on commit f8e4246

Please sign in to comment.