This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Find minima of multiple functions using genetic algorithm


X = gamultiobj(FITNESSFCN,NVARS)
X = gamultiobj(FITNESSFCN,NVARS,A,b)
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq)
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB)
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB,nonlcon)
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB,options)
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB,nonlcon,options)
X = gamultiobj(problem)
[X,FVAL] = gamultiobj(FITNESSFCN,NVARS, ...)


gamultiobj implements the genetic algorithm at the command line to minimize a multicomponent objective function.

X = gamultiobj(FITNESSFCN,NVARS) finds a local Pareto set X of the objective functions defined in FITNESSFCN. For details on writing FITNESSFCN, see Compute Objective Functions. NVARS is the dimension of the optimization problem (number of decision variables). X is a matrix with NVARS columns. The number of rows in X is the same as the number of Pareto solutions. All solutions in a Pareto set are equally optimal; it is up to the designer to select a solution in the Pareto set depending on the application.

X = gamultiobj(FITNESSFCN,NVARS,A,b) finds a local Pareto set X of the objective functions defined in FITNESSFCN, subject to the linear inequalities Axb, see Linear Inequality Constraints. Linear constraints are supported only for the default PopulationType option ('doubleVector'). Other population types, e.g., 'bitString' and 'custom', are not supported.

X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq) finds a local Pareto set X of the objective functions defined in FITNESSFCN, subject to the linear equalities Aeqx=beq as well as the linear inequalities Axb, see Linear Equality Constraints. (Set A=[] and b=[] if no inequalities exist.) Linear constraints are supported only for the default PopulationType option ('doubleVector'). Other population types, e.g., 'bitString' and 'custom', are not supported.

X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB) defines a set of lower and upper bounds on the design variables X so that a local Pareto set is found in the range LBxUB, see Bound Constraints. Use empty matrices for LB and UB if no bounds exist. Bound constraints are supported only for the default PopulationType option ('doubleVector'). Other population types, e.g., 'bitString' and 'custom', are not supported.

X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB,nonlcon) subjects the minimization to the constraints defined in nonlcon. The function nonlcon accepts x and returns vectors C and Ceq, representing the nonlinear inequalities and equalities respectively. gamultiobj minimizes the fitnessfcn such that C(x)  0 and Ceq(x) = 0. (Set LB=[] and UB=[] if no bounds exist.)

X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB,options) or X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,LB,UB,nonlcon,options) finds a Pareto set X with the default optimization parameters replaced by values in the structure options. Create options using optimoptions (recommended) or gaoptimset.

X = gamultiobj(problem) finds the Pareto set for problem, where problem is a structure containing the following fields:


Fitness functions


Number of design variables


A matrix for linear inequality constraints


b vector for linear inequality constraints


Aeq matrix for linear equality constraints


beq vector for linear equality constraints


Lower bound on x


Upper bound on x


Nonlinear constraint function (optional)




Optional field to reset the state of the random number generator


Options created using optimoptions or gaoptimset, or exported from the Optimization app

Create the structure problem by exporting a problem from Optimization app, as described in Importing and Exporting Your Work in the Optimization Toolbox™ documentation.

[X,FVAL] = gamultiobj(FITNESSFCN,NVARS, ...) returns a matrix FVAL, the value of all the objective functions defined in FITNESSFCN at all the solutions in X. FVAL has numberOfObjectives columns and same number of rows as does X.

[X,FVAL,EXITFLAG] = gamultiobj(FITNESSFCN,NVARS, ...) returns EXITFLAG, which describes the exit condition of gamultiobj. Possible values of EXITFLAG and the corresponding exit conditions are listed in this table.

EXITFLAG ValueExit Condition

Average change in value of the spread over options.MaxStallGenerations generations less than options.FunctionTolerance, and the final spread is less than the average spread over the past options.MaxStallGenerations generations


Maximum number of generations exceeded


Optimization terminated by an output function or plot function


No feasible point found


Time limit exceeded

[X,FVAL,EXITFLAG,OUTPUT] = gamultiobj(FITNESSFCN,NVARS, ...) returns a structure OUTPUT with the following fields:

OUTPUT FieldMeaning
problemtypeType of problem:
  • 'unconstrained' — No constraints

  • 'boundconstraints' — Only bound constraints

  • 'linearconstraints' — Linear constraints, with or without bound constraints


State of the MATLAB® random number generator, just before the algorithm started. You can use the values in rngstate to reproduce the output of ga. See Reproduce Results.

generationsTotal number of generations, excluding HybridFcn iterations
funccountTotal number of function evaluations
messagegamultiobj termination message
averagedistanceAverage "distance," which by default is the standard deviation of the norm of the difference between Pareto front members and their mean
spreadCombination of the "distance," and a measure of the movement of the points on the Pareto front between the final two iterations
maxconstraintMaximum constraint violation at the final Pareto set

[X,FVAL,EXITFLAG,OUTPUT,POPULATION] = gamultiobj(FITNESSFCN, ...) returns the final POPULATION at termination.



This example optimizes two objectives defined by Schaffer's second function, which has two objectives and a scalar input argument. The Pareto front is disconnected. Define this function in a file:

function y = schaffer2(x) % y has two columns

% Initialize y for two objectives and for all x
y = zeros(length(x),2); % ready for vectorization

% Evaluate first objective. 
% This objective is piecewise continuous.
for i = 1:length(x)
    if x(i) <= 1
        y(i,1) = -x(i);
    elseif x(i) <=3 
        y(i,1) = x(i) -2; 
    elseif x(i) <=4 
        y(i,1) = 4 - x(i);
        y(i,1) = x(i) - 4;

% Evaluate second objective
y(:,2) = (x -5).^2;

First, plot the two objectives:

x = -1:0.1:8;
y = schaffer2(x);

plot(x,y(:,1),'.r'); hold on

The two component functions compete in the range [1, 3] and [4, 5]. But the Pareto-optimal front consists of only two disconnected regions: [1, 2] and [4, 5]. This is because the region [2, 3] is inferior to [1, 2].

Next, impose a bound constraint on x, setting

lb = -5;
ub = 10;

The best way to view the results of the genetic algorithm is to visualize the Pareto front directly using the @gaplotpareto option. To optimize Schaffer's function, a larger population size than the default (15) is needed, because of the disconnected front. This example uses 60. Set the optimization options as:

options = optimoptions('gamultiobj','PopulationSize',60,'PlotFcn',@gaplotpareto);

Now call gamultiobj, specifying one independent variable and only the bound constraints:

[x,f,exitflag] = gamultiobj(@schaffer2,1,[],[],[],[],...

Optimization terminated: average change in the spread of
Pareto solutions less than options.FunctionTolerance.

exitflag = 1

The vectors x, f(:,1), and f(:,2) respectively contain the Pareto set and both objectives evaluated on the Pareto set.

Examples Included in the Toolbox

The gamultiobjfitness example solves a simple problem with one decision variable and two objectives.

The gamultiobjoptionsdemo example shows how to set options for multiobjective optimization.

More About

collapse all


gamultiobj uses a controlled elitist genetic algorithm (a variant of NSGA-II [1]). An elitist GA always favors individuals with better fitness value (rank). A controlled elitist GA also favors individuals that can help increase the diversity of the population even if they have a lower fitness value. It is important to maintain the diversity of population for convergence to an optimal Pareto front. Diversity is maintained by controlling the elite members of the population as the algorithm progresses. Two options, ParetoFraction and DistanceFcn, control the elitism. ParetoFraction limits the number of individuals on the Pareto front (elite members). The distance function, selected by DistanceFcn, helps to maintain diversity on a front by favoring individuals that are relatively far away on the front. The algorithm stops if the spread, a measure of the movement of the Pareto front, is small.


[1] Deb, Kalyanmoy. Multi-Objective Optimization Using Evolutionary Algorithms. John Wiley & Sons, 2001.

Introduced in R2007b

Was this topic helpful?