version 1.8.0.0 (154 KB) by
Aravind Seshadri

A function for multi-objective optimization using evolutionary algorithms

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 http://www.iitk.ac.in/kangal/

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.

Aravind Seshadri (2020). NSGA - II: A multi-objective optimization algorithm (https://www.mathworks.com/matlabcentral/fileexchange/10429-nsga-ii-a-multi-objective-optimization-algorithm), MATLAB Central File Exchange. Retrieved .

Created with
R14SP3

Compatible with any release

**Inspired:**
On the calculation of Crowding Distance, Genetic Algorithm-Jobshop scheduling, NSGA II: A multi-objective optimization program, Single Objective Genetic Algorithm, GODLIKE - A robust single-& multi-objective optimizer, NGPM -- A NSGA-II Program in Matlab v1.4, Multiobjective Differential Evolution Based on Fuzzy Performance Feedback, NSGA-II to Scheduling

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

Murad Alihi, i need NSGA-II-TS with Tabu search code in matlab.

YI CHENdjamel eddineHi, can I ask a question ?!!!

if I want to change the crossover probability (pc) and the mutation probability (pm), how can I do it !!!

Thank you

tomsio johnit was so useful ,but i can't modify the objective function。

kanako machiiHi. Can I ask a question?

If I want to maximize a objective function, can this code do that?

Only minimize?

Pease help.

zaki dahiaHi everyone i am new to optimization. I want to optimize tow objective functions using NSGA - II I couldn't understand how can i implemented my problem because i am not understanding the code properly.my objective functions is

Tp=140 ;Tf= 600;

Cp=5000;Cf=35000;

m=3;n=8000;

H=5*(((x)/n).^m);

f(1)=(Cp+Cf*H)/(x+Tp+Tf*H);

f(2)=x/(x+Tp+Tf*H);

can anyone guide me how to implemented my evaluate_objective .

my email: zaki_dahia@yahoo.fr

mohit bajajI am getting the following error:

Error using save

Unable to write file solution.txt: permission denied.

Please help

Mahtab MunawarBest ever code.

Easy to handle.

Thanks a lot.

Anis YounesHi everyone i have a project Concerning Simulation under ANSYS and Multi-objective Optimization of a Wing Profile by NSGA II Genetic Algorithm.'' The part of Ansys is easy but the Optimization of a Wing Profile by NSGA II Genetic Algorithm can you help me

My email : anisyounes921@gmail.com

Lei Jingsanchit goelhi i am new to optimization. I want to optimize gear parameters but don`t know how to use constraints in this code and also my each variable have different range. Can anyone help me i am in desperate need of help? Plz help sanchitgoel16291@gmail.com

Rui GuoZHENRONG TIANKarthick Kanagarajmuthu pandi scan anyone explain me in details about how to obtain the objective equation from the ANN toolbox

ZIrvingtilfani oussamaI would like to perform this algorithm with the following objective functions, can someone provide me a help for:

Sigma is a known (n,n) matrix

Max R= ∑wici + ∑wiβiRm

Min S= w’Sigmaw

Subject to ∑wi=1 and each wi is smaller than one in absolute value

And ci, βi and Rm are known

We would like to solve for w.

Iuga MihaiNaveed AhmedSKS LabsSKS LabsThanks for this very useful submission. However. there seems to be some issue in the determination of crowding distance.

Not all the solutions with the minimum and maximum objective function value are assigned the value of infinity as crowding distance. The crowding distance is dependent on the ordering of the solutions which should not be the case.

Check with [5 2 6; 4 2 7; 6 2 5; 5 8 1] and [6 2 5; 4 2 7; 5 2 6; 5 8 1] as the objective function values in the function non_domination_sort_mod. Though the points are identical (only with row swapping), the value of crowding distance is different.

Jian YangIt seems that polynomial mutation exist some problem, i.e., in the "function f=genetic_operator", Line 142, where the "child_3(j) = child_3(j) + delta(j)" should be "child_3(j) = child_3(j) +(u_limit(j)-l_limit(j)) delta(j)" . In addtion, the function can not handle the constraints. But thanks for your sharing.

Lahoucine OuhsaineHi, I opt to use this algorithm to optimise my system design. However, i fin a problem in the "non_dominated_sorting_mod.m" where my input variables (i have 5 variables) in the vector x are not all consistent to put it in the same matrix x, so how can you guide me please to fix this problem? Thank you!

Javier GutierrezCan we use parallel computing toolbox to apply this algorithm?

TooBoilingMingxiao Liangi found some mistake in the "function f = genetic_operator", where the "child_3(j) = child_3(j) + delta(j)" should be "child_3(j) = child_3(j) +(u_limit(j)-l_limit(j)) delta(j)" .

GlazioSugandhini Cakra MarutiHello; thank you for this great work.

I was wondering too with V, how if my decision variable are : routing, chosen vehicle and facility to be build. So, should I fill it with 3?

Then, I have a problem about "Subscripted assignment dimension mismatch." at "z(previous_index:current_index,:) = y;" in non_dominated_sort. Would you like to help me with this?

My research is about green vehicle routing problem (multiple objective for minimizing cost and emission), is anyone here can give me any references or teach me how to put the model of NSGA II into routing problem?

Thank you very much.

FADIL RabieHello;

Thank you for sharing this great work.

I need your help to make the code account for integer variables.

Thank you

winshepherdthank you.but it does not work well to DTLZ1.

Yishuai XuAfter reading the whole code, this is a great code for implementing NSGA II algorithm through Matlab.

But, just as user mer ve mentioned on 9 Mar 2012, there was a wrong code in genetic_operator.m file.

According to the definition of polynomial mutation:

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);

please regards guys.

anyway, thanks for the great work :)

liwei kouJonathan RoyGreat code, I use it a lot in past years. Now I get an prob that I cant solve.

-46 parameter to optimize

-2 objectives, "a" and b

"a" is evaluate by the 23 first parameter of my optimisation.

"b" is evaluate by the 23 last parameter + the result of the 23 first parameter

so "a" is a part of the "b" solution... and with std use of NSGA2 if "a" is good but not "b" parameter of "a" will not stop to change...

Any idea for that prob??

Ravindar Reddyhow to run the code??2016b

Tamiru Paulosthank so much you for this

Tamiru Paulosthank you for this

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

Muhammad Ansab AliI am new to optimization, can anyone guide me how to use NSGA-II by using a simple mathematical function.

please email me on ansabsindhu8@gmail.com

Aryan Goyalplayboywang kaithank you very much

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

Wen-Ling LinCan 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!

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

HarryGu MichealIt's very useful, thanks!

Qinyuan XiongI 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

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

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

http://alfonsoycia.blogspot.com.es/2016/01/ya-soy-doctor-ingeniero.html

Marwan Al abasI need it to complete some researches

anil krishnaits required for me

Thainákevin sunWhen 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?

Alfonso de la FuenteSo, apparently jMetal already includes some version of NSGA3 based on this C code:

http://web.ntnu.edu.tw/~tcchiang/publications/nsga3cpp/nsga3cpp.htm

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

Alfonso de la FuenteMarioHow can I learn to analyze the solution file? Since, I want to know what is the best result?

WangI want to know how to download?

lin jianhuaHow to download?

Carlos OliveiraHello to all,

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

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

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

Thank you very much for the code!

varun soniHow to use it for solving multiobjective constrainted problems??

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

Andrésmer veI 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...

mer vehow 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...

AndreasDoes 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

aftab AhmadLiwhen 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.

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

xuezhupigit's nice

Anisuzzaman Shuvothanks

Wafa Ben Yahiapour 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 :)

ANUDid 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);

end

g_x = 1+10*(V-1) + sum;

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

xu kuiwenThank you very much

Aravind Krishnan SHi,

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.

faizalGundian MartinThank you for the code

Please help me that how use it for constrained problems.

Thanks in advance

Wafa Ben YahiaHi, 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 :)

ManuelHI 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.

yousaf ziaThanks arvind.......

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

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

Tuan PhamI 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.

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

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

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

Zhang hua yongIt can not work !

Zhang Tieliangthank 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?

Javed Dhillonali mohammadpourMauro KitoThe code works well with all the test problems. Indeed, C code implementation will have faster performance in computation

Ram NatamoAfter my previous comments I did some head to head testing with this implementation and original c-implementation by Deb's group (downloadable from http://www.iitk.ac.in/kangal/), 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.

Ram NatamoFurther, 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?

Ram NatamoTo 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?!

elty sarviaThis 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!

Slim BechikhHi 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,

pro,pop)

must be

function f = replace_chromosome(intermediate_chromosome,

M,V,pop)

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

Luis Felipe Giraldosegaf huseinJoe Leohadj smailSeth Somannima tavakkolithanx alot,it`s brilliant!

Fenggy Chenthx.

Istadi Istadiwater brucethx, dear friend, you renew my life.

little catthx

shahab shamshirbandHI dear friends

i need a source code for tsp based on quadratic problems

tong hunterthis toolbox is very useful to me .thanks

but,I haven't found there is some bugs

Mohammad Hematithank 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

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

Piotr WozniakGenerally 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!

moh hematiTHanks

Mukiwa ZimbaniThis 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!

hamid ansariZC ZCxunkai weiA good one, yet if you can use a mex interface, it will be more attractive!