View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
NSGA - II: A multi-objective optimization algorithm

4.1 | 54 ratings Rate this file 221 Downloads (last 30 days) File Size: 154 KB File ID: #10429 Version: 1.8

NSGA - II: A multi-objective optimization algorithm



19 Mar 2006 (Updated )

A function for multi-objective optimization using evolutionary algorithms

| Watch this File

File Information

NSGA-II is a very famous multi-objective optimization algorithm. I submitted an example previously and wanted to make this submission useful to others by creating it as a function. Even though this function is very specific to benchmark problems, with a little bit more modification this can be adopted for any multi-objective optimization.

The function is nsga_2(pop,gen). The input arguments for the function are population size and number of generations. For customization purposes the user is free to modify the objective function (function of several decision variables) by modifying an m file (evaluate_objective.m). Couple of sample objective functions is already described in the file. The user also has the freedom to define the decision space.

For more information on NSGA-II visit Kanpur Genetic Algorithm Laboratory at

One of the main applications of multi-objective optimization that I am currently working on is tuning PID controllers using MOEA. I am hoping to share that work with everyone soon.

Update (January 27, 2009): I am unable to support user's request to modify this program to incorporate constraints in the optimization program since I have no time to delve into this field. Hence effective today (January 27, 2009) I release this program under GPLv3. This means that anyone and everyone can modify this code as and how they wish. Enjoy! But do remember to contribute the code back to the community.

Effective July 17, 2009 this code is re-licensed under BSD license to comply with Mathworks policy on submissions to MATLAB central.

Note: I no longer have the resources to maintain this code.


This file inspired Multiobjective Differential Evolution Based On Fuzzy Performance Feedback, Ngpm A Nsga Ii Program In Matlab V1.4, Nsga Ii: A Multi Objective Optimization Program, and Godlike A Robust Single & Multi Objective Optimizer.

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements Evolutionary algorithms are CPU and memory intensive. Recommended CPU clock speed is 1.6GHz with atleast 512MB RAM.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (84)
11 Feb 2017 Tamiru Paulos

thank so much you for this

Comment only
11 Feb 2017 Tamiru Paulos

thank you for this

Comment only
26 Dec 2016 Swapna Prajoth

Can anyone help me in modifying the code when the decision variable is an array

Comment only
22 Dec 2016 Muhammad Ansab Ali

I am new to optimization, can anyone guide me how to use NSGA-II by using a simple mathematical function.
please email me on

23 Nov 2016 Aryan Goyal

08 Nov 2016 playboy

04 Nov 2016 wang kai

thank you very much

28 Oct 2016 mohamed fahmy

i need to max. or min. the objective to find the best solution, can anyone help me

Comment only
24 Oct 2016 Wen-Ling Lin

Can I use this for a single objective optimization problem? If so, Does anyone know what changes I would need to make to make it be a single optimization? I skimmed through the documentation in particular the objective_description_function.m and it seems that an error will be thrown if the number of objectives is less than 2, however, I read online that the ngsa2 algorithm can be modified to handle single objective optimizations. I'm a little confused about where to start as this is quite new to me. Thank you very much!

Comment only
18 Oct 2016 lindayl

06 Oct 2016 Abhinav

Having problem in running ZDT-4 test function. This algorithm is not giving the desired results and converging to local pareto optimal

Comment only
08 Aug 2016 Harry

Harry (view profile)

23 Jul 2016 Gu Micheal

It's very useful, thanks!

29 Jun 2016 Qinyuan Xiong

I was wondering that V-the number of the decision variables. If the decision variable is entered as in the binary form or in the real value? and what is the meaning of number? is it like the digit of the decision variable or the real value of the decision variable?
Many thanks

27 Apr 2016 asdwe

asdwe (view profile)

I need it to complete some researches, and I want to konw how to download?

Comment only
06 Apr 2016 Alfonso de la Fuente

This algorithm was also featured in my PhD thesis on Applied Multiobjective Optimization Heuristics for Logistic Routing (Spanish, with Summary and conclusions in English):

Comment only
05 Apr 2016 Marwan Al abas

I need it to complete some researches

22 Feb 2016 anil krishna

its required for me

Comment only
14 Jan 2016 Thainá

08 Nov 2015 kevin sun

When I employ this code in ZDT1 and ZDT3, I found that this code did not work well and cannot find the best true Pareto front. Does any one know the reason?

Comment only
06 Oct 2015 Alfonso de la Fuente

So, apparently jMetal already includes some version of NSGA3 based on this C code:

Oh BTW, please stop using roman numerals in acronyms for MH algorithms, as it becomes confusing. Better to use arabic numerals.

07 Sep 2015 Alfonso de la Fuente

28 Oct 2014 Mario

Mario (view profile)

How can I learn to analyze the solution file? Since, I want to know what is the best result?

09 Sep 2014 Wang

Wang (view profile)

I want to know how to download?

22 Jun 2014 lin jianhua

How to download?

07 Feb 2014 Carlos Oliveira

Hello to all,
I want to maximize an objective and minimize other? How can I make this code? I'm having some difficulties.

Comment only
13 Jan 2014 Melissa

Can anyone give me an example of how to do a maximization problem?

Comment only
09 Dec 2013 jamosquera

agree with 'mer ve', mutation operator requires a correction

Thank you very much for the code!

20 Oct 2013 varun soni

How to use it for solving multiobjective constrainted problems??

Comment only
01 Jul 2013 Andrés

Thanks, the code has been very useful for my research on the implementation of a multi objective Harmony Seach technique

Comment only
01 Jul 2013 Andrés

09 Mar 2012 mer ve

mer ve (view profile)

I think in genetic_operator.m,
child_3(j) = child_3(j) + delta(j); line
should be replaced by
child_3(j) = child_3(j) + (u_limit(j)-l_limit(j))*delta(j);
according to the attached file...

Comment only
02 Mar 2012 mer ve

mer ve (view profile)

how can we add a rule like, final chromosomes(the solutions) should be divisable by 100? It would be so nice of you if you can help. Thanks in advance...

Comment only
14 Dec 2011 Andreas

Does anyone know how to solve the problem "Error: File: ndsort.m Line: 259 Column: 10"?
It would be nice if you could help me. Thanks in advance

Comment only
04 Nov 2011 aftab Ahmad

08 Aug 2011 Li

Li (view profile)

when I run the program one error "Error: File: ndsort.m Line: 259 Column: 10" appeared. The error place is "[~,ix]". I hope you can help me.

Comment only
10 Jul 2011 xiaoping wu

It's great.But I want to know how to use it for constrained problems.I need the help.

Comment only
24 Jun 2011 xuezhupig

it's nice

06 Jun 2011 Anisuzzaman Shuvo


Comment only
13 May 2011 Wafa Ben Yahia

pour travailler avec l'implémentation en langage C de Mr Deb, tu dois écrire le suivant dans l'espace réservé à la fonction objective:

f1 = xreal[0];
g = 0.0;
for (i=1; i<10; i++)
g += xreal[i]*xreal[i] - 10.0*cos(4.0*PI*xreal[i]);
g += 91.0;
h = 1.0 - sqrt(f1/g);
f2 = g*h;
f[0] = f1;
f[1] = f2;

si tu veux autre chose, tu peux me contacter :)

Comment only
12 May 2011 ANU

ANU (view profile)

Did anyone try running problem ZDT4 described in paper "AFastandElitstMulti-Objetive Geneti Algorithm:NSGA-II"?

It doesn't give the correct or even close to Deb's original implementation in c language. I did this:

f(1) = x(1);
sum = 0;
for (i = 2:V)
sum = sum + x(i)^2-10*roundn(cos(4*pi*x(i)),-4);
g_x = 1+10*(V-1) + sum;

f(2) = g_x*(1-sqrt(x(1)/g_x));

Comment only
05 May 2011 xu kuiwen

Thank you very much

Comment only
18 Apr 2011 Aravind Krishnan S


Can you please advise me on how to use the code. As to which file to run? When I ran the objective_description_function, I could input the number of objectives, the number of decision variables and also the range of decision variables. But the code finished running just to display "ans=2". How do I rectify this problem? Thank you.

24 Mar 2011 faizal

faizal (view profile)

03 Feb 2011 Gundian Martin

Thank you for the code
Please help me that how use it for constrained problems.

Thanks in advance

25 Jan 2011 Wafa Ben Yahia

Hi, thanks, it's a good work
I want to ask "Ram Natamo" if c-implementation by Deb's group is faster than Matlab?
In my problem i have many constraints, so how to imput it.
thanks for answer :)

04 Mar 2010 Manuel

Manuel (view profile)

HI Arvind.
Really great work. Thank you for the code.Please help me that how use it for constrained problems.

In other way, I think the code could have more consistency in variables declaration.

31 Dec 2009 yousaf zia

Thanks arvind.......
Great work is the knowledge which gives the benefit to other..........i would like to be same as you in this regard.........thanking you

11 Jul 2009 liheng liu

great job! It can work well on my project! just a little modification to suit my constraint problem! thank you!

12 May 2009 Tuan Pham

I had solved my problem with this NSGA-II codes but it does cost computer resources. However as I know latest Matlab versions have "gamultiobj" dealing with multiobjective optimization with genetic algorithm. I haven't worked with gamultiobj so I don't know what will be different between these two.

10 May 2009 Tuan Pham

10 Feb 2009 hailiang shen

The author seems to be used to c programming language. If implemented with more vector operation, the performance (speed) should be better.

29 Dec 2008 Deepak santhanakrishnan

Thnks for this. Where do i call the input arguments for the function popsize and number of arguments in the main file?

Comment only
23 Oct 2008 lin deng

the code can work well, and it can be used for constrained problems by little modification, thank u for the author!

20 Oct 2008 Zhang hua yong

It can not work !

Comment only
04 Sep 2008 Zhang Tieliang

thank you for the code.Please help me that how use it for constrained problems. If not, would you know other matlab code that can do these contraints?

07 Aug 2008 Javed Dhillon

03 Aug 2008 ali mohammadpour

02 Jul 2008 Mauro Kito

The code works well with all the test problems. Indeed, C code implementation will have faster performance in computation

19 Apr 2008 Ram Natamo

After my previous comments I did some head to head testing with this implementation and original c-implementation by Deb's group (downloadable from, and this implementation is converging really slowly (in terms of objective function evaluations)! That's a pity, I could have used Matlab implementation... :(
My recommendation is that you should use this version only if you dont care a bit about performance.

09 Apr 2008 Ram Natamo

Further, it seems that performance of this implementation is not even close to that of Deb's original implementation, with regard to generations.
Probably there is something wrong with this code?

09 Apr 2008 Ram Natamo

To me it seems there is some room for improvement. In file genetic_operator.m line
was_cossover = 0;
should probably be
was_crossover = 0;

Even worse, in the same file, child_3 is of different size than V before call:
child_3(:,V + 1: M + V) = evaluate_objective(child_3, M, V);
This must be an error?!

15 Feb 2008 elty sarvia

This is a very helpful set of files! It seems like this implementation does not handle constraints though. Deb's NSGA-II paper mentions a scheme for handling constraints (i.e. not just bound constraints on the decision variables, but "constraint functions"). If this is implemented in this version, could you point me towards whereI acn specify the constraints? If not, would you know of a matlab version that implements these contraints? Thanks!

17 Dec 2007 Slim Bechikh

Hi Arvind, I am Slim Bechikh a tunisian student, i thank you for your efforts to develop such program but there is a small mistake in your code:
function f = replace_chromosome(intermediate_chromosome,
must be
function f = replace_chromosome(intermediate_chromosome,

I tried your program on MATLAB 7.0 and it did not run and after correcting this mistake it has run with succes.

13 Dec 2007 Luis Felipe Giraldo

29 Jun 2007 segaf husein

17 Jun 2007 Joe Leo

12 Jun 2007 hadj smail

07 May 2007 Seth Soman

20 Mar 2007 nima tavakkoli

thanx alot,it`s brilliant!

09 Mar 2007 Fenggy Chen


Comment only
25 Jan 2007 Istadi Istadi

18 Jan 2007 water bruce

thx, dear friend, you renew my life.

19 Nov 2006 little cat


11 Nov 2006 shahab shamshirband

HI dear friends
i need a source code for tsp based on quadratic problems

Comment only
18 Oct 2006 tong hunter

this toolbox is very useful to me .thanks
but,I haven't found there is some bugs

Comment only
13 Oct 2006 Mohammad Hemati

thank you for this report,but these codes don't use for decition variables space,please guide me ,How I get the variables value (x1,x2,.....).Also How use it for constrained problems.
Very thanks

12 Oct 2006 Varun Aggarwal

this code is buggy, use at own risk. sbx is wrong, selection is not done the right way and others...

22 Sep 2006 Piotr Wozniak

Generally a pleasure to work with, has been very useful to my work. The one minor thing I'd recommend would be ensure consistency in variable declarations in the m-files.

Great work!

22 Sep 2006 moh hemati


Comment only
28 Aug 2006 Mukiwa Zimbani

This is a very helpful set of files!
It seems like this implementation does not handle constraints though. Deb's NSGA-II paper mentions a scheme for handling constraints (i.e. not just bound constraints on the decision variables, but "constraint functions"). If this is implemented in this version, could you point me towards whereI acn specify the constraints? If not, would you know of a matlab version that implements these contraints?


Comment only
05 Aug 2006 hamid ansari

22 May 2006 ZC ZC

07 May 2006 xunkai wei

A good one, yet if you can use a mex interface, it will be more attractive!

27 Jan 2009 1.4

Changed the license to GPLv3

16 Jul 2009 1.6

Modified the license to BSD

16 Jul 2009 1.7

Modified the license to BSD

19 Jul 2009 1.8

Updated the description

Contact us