Created
June 3, 2014 01:45
-
-
Save oamado/373e6dbae9837192e5ec to your computer and use it in GitHub Desktop.
A Fast Elitist Non-Dominated Sorting Genetic Algorithm for Multi-Objective Optimization: NSGA-II in Matlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% FUNCTION TO FIND THE PARETO FRONT | |
function s = optimalfront(j) | |
L=length(j); % Number of elements to compare | |
n=zeros(1,L); % Number of times an object is dominated | |
h=[]; % First Pareto front | |
s=zeros(L); % Show which elements are dominated by p | |
for p=1:1:L | |
for q=1:1:L | |
% P domina a Q | |
if (j(1,p)<=j(1,q) && j(2,p)<=j(2,q)) && (j(1,p)<j(1,q) || j(2,p)<j(2,q)) | |
s(q,p)=1; | |
% Q domina a P | |
elseif (j(1,q)<=j(1,p) && j(2,q)<=j(2,p)) && (j(1,q)<j(1,p) || j(2,q)<j(2,p)) | |
n(p)=n(p)+1; | |
end | |
end | |
if n(p)==0 | |
temp=[p;j(1,p);j(2,p)]; | |
h=[h temp]; | |
end | |
end | |
fop={h}; | |
i=1; | |
flag=1; % Indicates that there is an optimal front i | |
while flag==1 | |
h=[]; | |
for p=1:1:size(fop{i},2); | |
for q=1:1:L | |
a=fop{i}; | |
a=a(1,p); | |
if s(q,a)==1 | |
n(q)=n(q)-1; | |
if n(q)==0 | |
temp=[q;j(1,q);j(2,q)]; | |
h=[h temp]; | |
end | |
end | |
end | |
end | |
i=i+1; | |
if size(h,1)~=0 | |
fop{i}=h; | |
else | |
flag=0; | |
end | |
end |
Thanks for the code. It helped a lot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This algorithm was created by Kalyanmoy Deb, Samir Agrawal, Amrit Pratap, and T Meyarivan in this paper http://link.springer.com/chapter/10.1007%2F3-540-45356-3_83. This gist is only the implementation in Matlab