From b367e9bce4c62c4fc1e2bd5838ff9b30d78d9c71 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 18 Mar 2024 12:24:51 +0100 Subject: [PATCH 1/3] Adding preference-based evolutionary multiobjective optimization algorithm WASF-GA --- .../WASFGA/EnvironmentalSelectionW.m | 19 ++++ .../WASFGA/WASFGA.m | 60 +++++++++++ .../WASFGA/WASFGASort.m | 101 ++++++++++++++++++ .../WASFGA/generateWeightVectors2.m | 15 +++ 4 files changed, 195 insertions(+) create mode 100644 PlatEMO/Algorithms/Multi-objective optimization/WASFGA/EnvironmentalSelectionW.m create mode 100644 PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m create mode 100644 PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m create mode 100644 PlatEMO/Algorithms/Multi-objective optimization/WASFGA/generateWeightVectors2.m diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/EnvironmentalSelectionW.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/EnvironmentalSelectionW.m new file mode 100644 index 000000000..ecdfea3a7 --- /dev/null +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/EnvironmentalSelectionW.m @@ -0,0 +1,19 @@ +function [Population, FrontNo, CrowdDis] = EnvironmentalSelectionW(Vectores, Population, nsort, Point, ro) + %% Non-dominated sorting + [FrontNo, MaxFNo] = WASFGASort(Vectores, Population.objs, nsort, Point, ro); + Next = FrontNo < MaxFNo; + + %% Calculate the crowding distance of each solution + CrowdDis = CrowdingDistance(Population.objs, FrontNo); + + %% Select the solutions in the last front by their crowding distances + Last = find(FrontNo == MaxFNo); + [~, Rank] = sort(CrowdDis(Last), 'descend'); + numSelected = min(nsort - sum(Next), numel(Last)); % Avoid selecting more than available + Next(Last(Rank(1:numSelected))) = true; + + %% Population for next generation + Population = Population(Next); + FrontNo = FrontNo(Next); + CrowdDis = CrowdDis(Next); +end diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m new file mode 100644 index 000000000..76eff75df --- /dev/null +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m @@ -0,0 +1,60 @@ +classdef WASFGA < ALGORITHM +% +% g-dominance based NSGA-II +% Point --- --- Preferred point + +%------------------------------- Reference -------------------------------- +% L. B. Said, S. Bechikh, and K. Ghedira, The r-dominance: A new dominance +% relation for interactive evolutionary multicriteria decision making, IEEE +% Transactions on Evolutionary Computation, 2010, 14(5): 801-818. +%------------------------------- 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". +%-------------------------------------------------------------------------- + + methods + function main(Algorithm,Problem) + %% Parameter setting + Point = Algorithm.ParameterSet(zeros(1,Problem.M)+0.5,0.00001); + ro = 0.0001; + %% Generate random population + Population = Problem.Initialization(); + %% Generate a sample of weight vectors + [n,~] = size(Population.objs); + if Problem.M == 2 + + + Vectors = generateWeightVectors2(n, 0.001); + + + else + [Vectors,Problem.N] = UniformPoint(Problem.N,Problem.M); + end + + + FrontNo = WASFGASort(Vectors, Population.objs, inf, Point,ro); + CrowdDis = CrowdingDistance(Population.objs,FrontNo); + [v,~] = size(Vectors); + if v >= n + nsort = 2; + else + nsort = floor(n/v) + 1; + end + + + + + + %% Optimization + while Algorithm.NotTerminated(Population) + MatingPool = TournamentSelection(2,Problem.N,FrontNo,-CrowdDis); + Offspring = OperatorGA(Problem,Population(MatingPool)); + [Population,FrontNo,CrowdDis] = EnvironmentalSelectionW(Vectors, [Population,Offspring],nsort,Point,ro); + end + end + end +end \ No newline at end of file diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m new file mode 100644 index 000000000..c08680496 --- /dev/null +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m @@ -0,0 +1,101 @@ +function [FrontNo,MaxFNo] = WASFGASort(Vectors, PopObj, nsort, Point, ro) + + + + [nvectors, ~] = size(Vectors); + + [Loc,MaxFNo] = frontsclass(Vectors, PopObj,inf, Point, ro); + %disp(Loc) + [popsize, ~] = size(PopObj); + + FrontNo = inf(1,size(PopObj,1)); + for i = 1:popsize + + Position = find(Loc == i); + iter = 0; + while nvectors*iter < Position + iter = iter + 1; + end + if iter == 0 || iter > nsort + FrontNo(i) = inf; + else + FrontNo(i) = iter; + + end + + end + +end + + + + + + + + +function [Loc, Max] = frontsclass(Vectors, PopObj, nsort, Point, ro) + + [nvectors, ~] = size(Vectors); + %N is the population size + [N, ~] = size(PopObj); + FrontG = []; + %SolG will store the different solutions sorted by the achievement + %scalarizing function + SolG = []; + PopObj2 = PopObj; + Max = 0; + while length(FrontG) < N && Max < nsort + + % n will be the size of the population that will be compared in + % each iteration, it will change in every iteration. + [n, ~] = size(PopObj); + + Max = Max + 1; + for i = 1:min(nvectors, n) + + Front = []; + Values = zeros(n, 1); + + for j = 1:n + + Values(j) = max((PopObj(j, :) - Point) .* Vectors(i, :)) + ro * sum(Vectors(i, :) .* (PopObj(j, :) - Point)); + + end + + Vmin = min(Values); + Sol1 = find(Values == Vmin); + + Front = [Front, Sol1']; + FrontG = [FrontG, Front]; + + + valid_Loc = Front(Front <= size(PopObj, 1)); + SolG = [SolG; PopObj(valid_Loc, :)]; + + PopObj(valid_Loc, :) = []; + [n, ~] = size(PopObj); + + end + end + + Loc = find_Loc(SolG, PopObj2); + +end + +%This function will allow us to identify the position in the original +%matrix of the solutions in SolG +function index = find_Loc(rows, initial_matrix) + index = zeros(size(rows, 1), 1); + + for i = 1:size(rows, 1) + + [equalrow, loc] = ismember(rows(i, :), initial_matrix, 'rows'); + + + if equalrow + index(i) = loc; + end + end +end + diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/generateWeightVectors2.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/generateWeightVectors2.m new file mode 100644 index 000000000..31a88d49d --- /dev/null +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/generateWeightVectors2.m @@ -0,0 +1,15 @@ +function weightVectors = generateWeightVectors2(Nmu, epsilon) + % Input: + % - Nmu: Number of weight vectors + % - epsilon: Small positive value (e.g., 0.01) + + % Initialize weight vectors matrix + weightVectors = zeros(Nmu, 2); + + % Generate weight vectors + for j = 1:Nmu + uj1 = epsilon + (j - 1) * (1 - 2 * epsilon) / (Nmu - 1); + uj2 = 1 - uj1; + weightVectors(j, :) = [uj1, uj2]; + end +end From 1eef1a760ab35ede34bce32bde3253d9316d7e3a Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 18 Mar 2024 12:47:53 +0100 Subject: [PATCH 2/3] Adding reference to WASF-GA and formating source code --- .../WASFGA/WASFGA.m | 74 +++++++++---------- .../WASFGA/WASFGASort.m | 31 +------- 2 files changed, 35 insertions(+), 70 deletions(-) diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m index 76eff75df..8b6c064ca 100644 --- a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGA.m @@ -1,54 +1,46 @@ classdef WASFGA < ALGORITHM -% -% g-dominance based NSGA-II -% Point --- --- Preferred point + % + % WASFGA + % Point --- --- Preferred point -%------------------------------- Reference -------------------------------- -% L. B. Said, S. Bechikh, and K. Ghedira, The r-dominance: A new dominance -% relation for interactive evolutionary multicriteria decision making, IEEE -% Transactions on Evolutionary Computation, 2010, 14(5): 801-818. -%------------------------------- 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". -%-------------------------------------------------------------------------- + %------------------------------- Reference -------------------------------- + % Ruiz, A. B., Saborido, R., & Luque, M. (2015). A preference-based + % evolutionary algorithm for multiobjective optimization: the weighting + % achievement scalarizing function genetic algorithm. Journal of Global + % Optimization, 62, 101-129. + %------------------------------- 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". + %-------------------------------------------------------------------------- methods function main(Algorithm,Problem) %% Parameter setting - Point = Algorithm.ParameterSet(zeros(1,Problem.M)+0.5,0.00001); - ro = 0.0001; + Point = Algorithm.ParameterSet(zeros(1,Problem.M)+0.5,0.00001); + ro = 0.0001; %% Generate random population - Population = Problem.Initialization(); + Population = Problem.Initialization(); %% Generate a sample of weight vectors - [n,~] = size(Population.objs); - if Problem.M == 2 - - - Vectors = generateWeightVectors2(n, 0.001); - - - else - [Vectors,Problem.N] = UniformPoint(Problem.N,Problem.M); - end - - - FrontNo = WASFGASort(Vectors, Population.objs, inf, Point,ro); - CrowdDis = CrowdingDistance(Population.objs,FrontNo); - [v,~] = size(Vectors); - if v >= n - nsort = 2; - else - nsort = floor(n/v) + 1; - end + [n,~] = size(Population.objs); + if Problem.M == 2 + Vectors = generateWeightVectors2(n, 0.001); + else + [Vectors,Problem.N] = UniformPoint(Problem.N,Problem.M); + end - + FrontNo = WASFGASort(Vectors, Population.objs, inf, Point,ro); + CrowdDis = CrowdingDistance(Population.objs,FrontNo); + [v,~] = size(Vectors); + if v >= n + nsort = 2; + else + nsort = floor(n/v) + 1; + end - - %% Optimization while Algorithm.NotTerminated(Population) MatingPool = TournamentSelection(2,Problem.N,FrontNo,-CrowdDis); diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m index c08680496..1dc72d96c 100644 --- a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m @@ -1,16 +1,11 @@ function [FrontNo,MaxFNo] = WASFGASort(Vectors, PopObj, nsort, Point, ro) - - - + [nvectors, ~] = size(Vectors); - [Loc,MaxFNo] = frontsclass(Vectors, PopObj,inf, Point, ro); - %disp(Loc) [popsize, ~] = size(PopObj); - FrontNo = inf(1,size(PopObj,1)); + for i = 1:popsize - Position = find(Loc == i); iter = 0; while nvectors*iter < Position @@ -20,22 +15,11 @@ FrontNo(i) = inf; else FrontNo(i) = iter; - end - end - end - - - - - - - function [Loc, Max] = frontsclass(Vectors, PopObj, nsort, Point, ro) - [nvectors, ~] = size(Vectors); %N is the population size [N, ~] = size(PopObj); @@ -58,29 +42,20 @@ Values = zeros(n, 1); for j = 1:n - Values(j) = max((PopObj(j, :) - Point) .* Vectors(i, :)) + ro * sum(Vectors(i, :) .* (PopObj(j, :) - Point)); - end Vmin = min(Values); Sol1 = find(Values == Vmin); - Front = [Front, Sol1']; FrontG = [FrontG, Front]; - - valid_Loc = Front(Front <= size(PopObj, 1)); SolG = [SolG; PopObj(valid_Loc, :)]; - PopObj(valid_Loc, :) = []; [n, ~] = size(PopObj); - end end - Loc = find_Loc(SolG, PopObj2); - end %This function will allow us to identify the position in the original @@ -89,9 +64,7 @@ index = zeros(size(rows, 1), 1); for i = 1:size(rows, 1) - [equalrow, loc] = ismember(rows(i, :), initial_matrix, 'rows'); - if equalrow index(i) = loc; From 16b2e5691444818215134bacf0272894c0e04801 Mon Sep 17 00:00:00 2001 From: antonioborregortega <163560109+antonioborregortega@users.noreply.github.com> Date: Mon, 20 May 2024 14:02:45 +0200 Subject: [PATCH 3/3] Update WASFGASort.m Improved version --- .../Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m index 1dc72d96c..1eb974a0e 100644 --- a/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m +++ b/PlatEMO/Algorithms/Multi-objective optimization/WASFGA/WASFGASort.m @@ -47,7 +47,7 @@ Vmin = min(Values); Sol1 = find(Values == Vmin); - Front = [Front, Sol1']; + Front = [Front, Sol1(1)]; FrontG = [FrontG, Front]; valid_Loc = Front(Front <= size(PopObj, 1)); SolG = [SolG; PopObj(valid_Loc, :)];