From 37df0f8f8e5f48f8197251ae20b38cccbd0f8f5d Mon Sep 17 00:00:00 2001 From: wjq19990427 <12432747@mail.sustech.edu.cn> Date: Thu, 19 Dec 2024 13:48:45 +0800 Subject: [PATCH] Update WeightUpdate.m Try to fix the bug "Fix issue #167: add a judegment to check the number of columns for virable dis2, if there is only one column, use this column instead of the second column" --- .../Multi-objective optimization/AdaW/WeightUpdate.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PlatEMO/Algorithms/Multi-objective optimization/AdaW/WeightUpdate.m b/PlatEMO/Algorithms/Multi-objective optimization/AdaW/WeightUpdate.m index 77589008..85c03642 100644 --- a/PlatEMO/Algorithms/Multi-objective optimization/AdaW/WeightUpdate.m +++ b/PlatEMO/Algorithms/Multi-objective optimization/AdaW/WeightUpdate.m @@ -24,7 +24,13 @@ dis2 = pdist2(Archiveobjs,Archiveobjs); dis2 = sort(dis2,2); % Calculate the niche size(median of the distances from their closest solution in the archive ) - niche_size = median(dis2(:,2)); + if size(dis2, 2) >= 2 + niche_size = median(dis2(:,2)); + else + warning('dis2 只有一列数据,无法访问第二列。'); + % If there is only one column for dis2, use the first column + niche_size = median(dis2(:,1)); + end % Find undeveloped Archive_und = Archive(dis1(:,1) >= niche_size); N_und = length(Archive_und); @@ -97,4 +103,4 @@ B = pdist2(W,W); [~,B] = sort(B,2); B = B(:,1:T); -end \ No newline at end of file +end