NGPM -- A NSGA-II Program in Matlab
Version 1.4
LIN Song
Aerospace Structural Dynamics Research Laboratory
College of Astronautics, Northwestern Polytechnical University, China
Email: [email protected]
2011-07-26
Contents
Contents...................................................................................................................................... i
1. Introduction ....................................................................................................................... 1
2. How to run the code? ........................................................................................................ 1
2.1. ‘CONSTR’ test problem description..................................................................... 1
2.2. Step1: Specified optimization model .................................................................... 1
2.3. Step2: Create a objective function......................................................................... 2
2.4. Results ................................................................................................................... 3
3. NGPM Options .................................................................................................................. 5
3.1. Coding ................................................................................................................... 5
3.2. Population options................................................................................................. 5
3.3. Population initialization ........................................................................................ 6
3.4. Selection................................................................................................................ 7
3.5. Crossover............................................................................................................... 7
3.6. Mutation ................................................................................................................ 8
3.7. Constraint handling ............................................................................................... 8
3.8. Stopping Criteria ................................................................................................... 8
3.9. Output function ..................................................................................................... 9
3.10. GUI control ........................................................................................................... 9
3.11. Plot interval ......................................................................................................... 11
3.12. Parallel computation............................................................................................ 11
4. R-NSGA-II: Reference-point-based NSGA-II.............................................................. 12
4.1. Introduction ......................................................................................................... 12
4.2. Using the R-NSGA-II.......................................................................................... 12
5. Test Problems................................................................................................................... 13
5.1. TP1: KUR............................................................................................................ 13
5.2. TP2: TNK............................................................................................................ 14
6. Disclaimer ........................................................................................................................ 17
7. Appendix A: Version history .......................................................................................... 17
i
NGPM -- A NSGA-II Program in Matlab
1. Introduction
This document gives a brief description about NGPM. NGPM is the abbreviation of “A
NSGA-II Program in Matlab”, which is the implementation of NSGA-II in Matlab. NSGA-II
is a multi-objective genetic algorithm developed by K. Deb
[1]
. The details of NSGA-II are
not described in this document; please refer to
[1]
. From version 1.3, R-NSGA-II — a
modified procedure of NSGA-II — is implemented, the details of R-NSGA-II please refer to
[2]
.
2. How to run the code?
To use this program to solve a function optimization problem. Optimization model such
as number of design variables, number of objectives, number of constraints, should be
specified in the NSGA-II optimization options structure
1
which is created by function
nsgaopt(). The objective function must be created as a function file (*.m), and specify the
function handle options.objfun to this function. The Matlab file TP_CONSTR.m is a script file
which solves a constrained test function. This test problem is 'CONSTR' in
[1]
.
2.1. ‘CONSTR’ test problem description
(1) Objectives: 2
11
22
()
() (1 )/
fx x
1
f
xxx
(1)
(2) Design variables: 2
12
[0.1,1.0], [0,5]xx
(2)
(3) Constraints: 2
121
221
() 9 6
() 9 1
gx x x
gx x x
(3)
Two steps should be done to solve this problem.
2.2. Step1: Specified optimization model
The file TP_CONSTR.m is a script file which specified the optimization model.
1
In this document, all of the italic options is the structure created by nsgaopt().
1
NGPM -- A NSGA-II Program in Matlab
% TP_CONSTR.m file
% 'CONSTR' test problem
clc; clear; close all
options = nsgaopt(); % create default options structure
options.popsize = 50; % population size
options.maxGen = 100; % max generation
options.numObj = 2; % number of objectives
options.numVar = 2; % number of design variables
options.numCons = 2; % number of constraints
options.lb = [0.1 0]; % lower bound of x
options.ub = [1 5]; % upper bound of x
options.objfun = @objfun; % objective function handle
result = nsga2(options); % start the optimization progress
2.3. Step2: Create a objective function
The file TP_CONSTR_objfun.m is a function file which specified the objective function
evaluation. The objective function is specified by options.objfun parameter created by the
function nsgaopt(). Its prototype is:
[y, cons] = objfun(x, varvargin)
x : Design variables vector, its length must equals options.numVar.
y : Objective values vector, its length must equals options.numObj.
cons : Constraint violations vector. Its length must equals options.numCons. If there is
no constraint, return empty vector [].
varargin : Any variable(s) which are passed to nsga2 function will be finally passed to
this objective function. For example, if you call
result = nsga2(opt, model, param)
The two addition parameter passed to nsga2 — model and param — will be passed to
the objective function as
[y, const]=objfun(x, model, param)
2
NGPM -- A NSGA-II Program in Matlab
In this function optimization problem, there is no other parameter.
function [y, cons] = objfun(x)
% TP_CONSTR_objfun.m file
% 'CONSTR' test problem
y = [0,0];
cons = [0,0];
y(1) = x(1);
y(2) = (1+x(2)) / x(1);
% calculate the constraint violations
c = x(2) + 9*x(1) - 6;
if(c<0)
cons(1) = abs(c);
end
c = -x(2) + 9*x(1) - 1;
if(c<0)
cons(2) = abs(c);
end
2.4. Results
Run the script file TP_CONSTR.m, and you will get the optimization result store in the
result structure. The population will be plotted in a GUI figure. The x-axis is the first
objective, and the y-axis is the second. If user specifies the names of objectives in
options.nameObj, then they will be displayed in the x and y labels.
On the GUI window ‘plotnsga’, the optimization progress could be paused or stop by
press the corresponding buttons. Note that, the progress of optimization would pause or stop
only when the current population evaluation is done!
The Pareto front (or population distribution) of generation 1 and 100 was plot in Fig. 1.
The populations of each generation were outputted to the file ‘populations.txt’ in current path.
3