0% found this document useful (0 votes)
31 views

Optimization Toolbox

Uploaded by

gec.matlab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Optimization Toolbox

Uploaded by

gec.matlab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Updated on March 19, 2020

MATLAB Optimization Solvers


Prakash Kotecha, Associate Professor
Debasis Maharana, Teaching Assistant &
Remya Kommadath, Teaching Assistant
Indian Institute of Technology Guwahati
MATLAB inbuilt functions: Linear & Mixed Integer Linear Programming: https://www.youtube.com/watch?v=L3J1aIeeWTE
MATLAB inbuilt functions: Nonlinear & Mixed Integer Nonlinear Programming: https://www.youtube.com/watch?v=my-J6YsMTSQ
MATLAB Optimization Tool: Options, Output Function, Vectorization, Parallelization: https://www.youtube.com/watch?v=c9zQY_E75bM
Additional resources: tinyurl.com/sksopti, tinyurl.com/sksoptivid
Optimization solvers (MATLAB 2019a)
Objective Constraint handling Integer
Function Algorithm Remarks Type
function Linear Nonlinear variable

a) 'dual-simplex' (default)
linprog linear    b) 'interior-point-legacy' LP
c) 'interior-point'
intlinprog linear    Branch and bound MILP
a) 'interior-point-
If symmetric matrix is not a positive definite, quadprog issues a
quadprog quadratic    convex' (default) QP
b) 'trust-region-reflective' warning and uses the symmetrized version (H + H')/2 instead

a) 'quasi-newton' (default)
fminunc nonlinear    Suitable for continuous differentiable unbounded problems NLP
b) 'trust-region'
fminsearch nonlinear    'Nelder-Mead simplex' Solve non differentiable, discontinuous unbounded problem NLP
a) 'interior-point' (default)
b) 'trust-region-reflective'
Gradient-based method: objective function and constraints are
fmincon nonlinear    c) 'sqp' NLP
continuous and also have continuous first derivatives
d) 'sqp-legacy'
e) 'active-set'

patternsearch nonlinear    Pattern search Can solve single and multi-objective problems (paretosearch) NLP

particleswarm nonlinear    Particle swarm optimization Can solve single objective optimization problems NLP
simulannealbnd nonlinear    Simulated annealing Can solve single objective optimization problems NLP
Can solve single and multi-objective problems (gamultiobj)
ga nonlinear    Genetic algorithm MINLP
Cannot handle integer variables if equality constraints are present
2
Linear programming

Linear objective function

Linear equality and inequality constraints

Bound constraints

MATLAB function: linprog


Introduced before R2006a

3
Relaxation and tightening of search space
LB relaxation
lb = [100 30] Min f = 3x1 + 2x2 LB tightening
lb = [100 70]

lb = [100 50] ; ub = [700 100]

st. x1 – 3x2 ≥ 400

UB relaxation UB tightening
ub = [800 100] ub = [650 100]

Constraint relaxation Constraint tightening


x1 – 3x2 ≥ 300 x1 – 3x2 ≥ 450

4
Linear programming
Three neighbouring cities discharge pollutants A and B into the river after pollution
treatment. The state government has set up a treatment plant that treats the pollutants
from each city.
Amount of A (in Amount of B (in
tons) per ton tons) per ton Cost
of waste of waste
City 1 0.1 0.45 $15/ton
City 2 0.2 0.25 $10/ton
City 3 0.4 0.3 $20/ton
Required
At least 30 tons At least 40 tons
reduction
Determine the amount of waste treated from each city that will minimize the cost of
pollutants by desired amount.
Adapted from Introduction to Applied Optimization by Urmila Diwekar 5
Linear programming
Reduction Reduction Cost
Let x1 = amount of waste treated from city 1 in A /ton in B /ton

x2 = amount of waste treated from city 2 Decision City 1 0.1 0.45 $15/ton
variables City 2 0.2 0.25 $10/ton
x3 = amount of waste treated from city 3 City 3 0.4 0.3 $20/ton
Required 30 tons 40 tons
reduction

Minimize Cost, Z = 15 x1 + 10 x2 + 20 x3 Objective function

subject to
Reduction in A: 0.1 x1 + 0.2 x2 + 0.4 x3 ≥ 30
Constraints
Reduction in B: 0.45 x1 + 0.25 x2 + 0.3 x3 ≥ 40

Flow rates: x1, x2, x3 ≥ 0 Bound constraints

MATLAB function: linprog


6
linprog
 Ax  b  x1 
 x 
Min Z = 15 x1 + 10 x2 + 20 x3 Min Z = 15 x1 + 10 x2 + 20 x3 min f T x subject to  Aeq x  beq x 2
x
lb  x  ub  
0.1 x1 + 0.2 x2 + 0.4 x3 ≥ 30 – 0.1 x1 – 0.2 x2 – 0.4 x3 ≤ – 30   
0.45 x1 + 0.25 x2 + 0.3 x3 ≥ 40 – 0.45 x1 – 0.25 x2 – 0.3 x3 ≤ – 40  xD 
f , x, b, beq, lb, and ub are vectors
x1, x2, x3 ≥ 0 x1, x2, x3 ≥ 0 and Aand Aeq are matrices

[X,FVAL,EXITFLAG,OUTPUT,LAMBDA] = linprog(Z,A,b,Aeq,beq,lb,ub,options)

Input: Z  15 10 20 Output:


x Solution vector
 0.1 0.2 0.4   30  fval Objective function value at solution
A  b 
 0.45 0.25 0.3   40  exitflag Algorithm stopping condition
output Information such as number of iterations, algorithm used,
lb   0 0 0 exit message etc., of the optimization process
lambda Lagrange multipliers

7
MATLAB code
Create a script file to solve the problem using linprog Input:
Z  15 10 20
clc; clear % Clear command window and workspace respectively
 0.1 0.2 0.4   30 
A  b 
 0.45 0.25 0.3  40 
lb = zeros(1,3);%Lower bounds
lb   0 0 0
A = [-0.1 -0.2 -0.4; -0.45 -0.25 -0.3];% coefficients of inequality constraints
b = -[30 40]';% RHS of inequality constraints

Z = [15 10 20];% Coefficients of objective function

% Calling the solver


[X, FVAL, EXITFLAG, OUTPUT, LAMBDA] = linprog(Z, A, b, [], [], lb);

Output: X [7.6923 146.1538 0]


FVAL 1576.9231
LAMBDA.lower [0 0 6.1538] Shadow price for change in lower bound

LAMBDA.upper [0 0 0] Shadow price for change in upper bound

LAMBDA.ineqlin [11.5385 30.7692] Shadow price for change in RHS of inequality constraints
8
Result analysis
LAMBDA.lower = [0 0 6.1538] X [7.6923 146.1538 0]
FVAL 1576.9231
• Optimal value of x3 lies on lower bound
LAMBDA.lower [0 0 6.1538]
• One unit decrease in lb of x3 results in 6.1538 units
LAMBDA.upper [0 0 0]
improvement in objective value
LAMBDA.ineqlin [11.5385 30.7692]
LAMBDA.ineqlin = [11.5385 30.7692] Decreasing the value of lb  Increased the search space
• One unit decrease in b1 results in 11.5385 units Increasing the value of lb  Reduced the search space
improvement in objective value, similarly one unit decrease Decreasing the value of b  Reduced the search space
in b2 causes 30.7692 unit improvement in objective value
Increasing the value of b  Increased the search space
Lagrange
lb3 b1 b2 FVAL
multipliers
lb3 +1 = 1 - - 6.1538 1576.9231 + 6.1538 = 1583.0769
lb = [0 0 0]
lb3 – 1 = –1 - - 6.1538 1576.9231 – 6.1538 = 1570.7692
- b1 + 1 = –29 - 11.5385 1576.9231 – 11.5385 = 1565.3846
 30  - b1 – 1 = –31 - 11.5385 1576.9231 + 11.5385 = 1588.4616
b 
 40  - - b2 + 1 = –39 30.7692 1576.9231 – 30.7692 = 1546.1538
- - b2 – 1 = –41 30.7692 1576.9231 + 30.7692 = 1607.6923
9
Result analysis
Input: X [7.6923 146.1538 0]
Z  15 10 20 FVAL 1576.9231
 0.1 0.2 0.4   30  LAMBDA.lower [0 0 6.1538]
A  b 
 0.45 0.25 0.3  40  LAMBDA.upper [0 0 0]
lb   0 0 0 LAMBDA.ineqlin [11.5385 30.7692]

Z  15 10 20 Z  15 10 20 Z  15 10 20

 0.1 0.2 0.4   30   0.1 0.2 0.4   29   0.1 0.2 0.4   30 
A  b A  b A  b 
   0.45 0.25 0.3
 0.45 0.25 0.3  40   0.45 0.25 0.3  40   39 
lb   0 0 1 lb   0 0 0 lb   0 0 0
FVAL= 1583.08 FVAL= 1565.38 FVAL= 1546.15

Z  15 10 20 Z  15 10 20 Z  15 10 20

 0.1 0.2 0.4   30   0.1 0.2 0.4   31   0.1 0.2 0.4   30 
A  b A  b A  b 
   0.45 0.25 0.3
 0.45 0.25 0.3  40   0.45 0.25 0.3  40   41 
lb   0 0 1 lb   0 0 0 lb   0 0 0
FVAL= 1570.77 FVAL= 1588.46 FVAL= 1607.69

10
Linear programming
linprog
Let X = [x1, x2, x3] be the vector of decision variables.
 Ax  b

Minimize x1 + 2x2 ̶ 3x3 Objective function min f T x subject to  Aeq x  beq
x
lb  x  ub

Subject to
x1 + 2x2 ≤ 3 Inequality
constraints Constraints Input:
x2 + x3 ≤ 2
x1 + x2 + x3 = 4 Equality constraints Z  1 2 3
0 ≤ x1 ≤ 5 1 2 0  3 
Bound A  b 
-1.5 ≤ x2 ≤ 3  0 1 1  2
constraints
0 ≤ x3 ≤ 2 Aeq  1 1 1 beq   4

MATLAB function: linprog lb   0 1.5 0 ub  5 3 2

11
MATLAB code
Create a script file to solve the problem using linprog
clc; clear % Clear the command window and workspace respectively
Z = [1 2 -3]; % Coefficients of objective function Z  1 2 3
A = [1 2 0; 0 1 1]; % coefficients of inequality constraints
b = [3;2]; % RHS of inequality constraints 1 2 0  3 
A  b 
0 1 1  2
Aeq = [1 1 1]; % coefficients of equality constraints
beq = 4; % RHS of equality constraints
Aeq  1 1 1 beq   4
lb = [0 -1.5 0]; % Lower bound of decision variables
ub = [5 3 2]; % Upper bound of decision variables lb   0 1.5 0 ub  5 3 2
% Calling the solver
[X, FVAL, EXITFLAG, OUTPUT, LAMBDA] = linprog(Z, A, b, Aeq, beq, lb, ub);

Output: X [3.5 -1.5 2]


FVAL -5.5
LAMBDA.lower [0 1 0] Shadow price for change in lower bound
LAMBDA.upper [0 0 4] Shadow price for change in upper bound
LAMBDA.ineqlin [0 0] Shadow price for change in RHS of inequality constraints
LAMBDA.eqlin -1 Shadow price for change in RHS of inequality constraints
12
Result analysis
FVAL -5.5
LAMBDA.lower [0 1 0]
LAMBDA.upper [0 0 4]
LAMBDA.eqlin -1

Lagrange
lb2 ub3 beq FVAL
multipliers
lb2 +1 = -0.5 - - 1 –5.5 + 1 = –4.5
lb = [ 0 -1.5 0 ]
lb2 – 1 = -2.5 - - 1 –5.5 – 1 = –6.5
- ub3 + 1 = 3 - 4 –5.5 – 4 = –9.5
ub = [ 5 3 2] - ub3 – 1 = 1 - 4 –5.5 + 4 = –1.5
- - beq + 1 = 5 –1 –5.5 – (–1)= –4.5
beq   4 - - beq – 1 = 3 –1 –5.5 + (–1)= -6.5

13
Result analysis
Z  1 2 3 X [3.5 -1.5 2]
FVAL -5.5
1 2 0  3 
A  b  LAMBDA.lower [0 1 0]
0 1 1  2
Aeq  1 1 1 beq   4 LAMBDA.upper [0 0 4]
LAMBDA.ineqlin [0 0]
lb   0 1.5 0 ub  5 3 2
LAMBDA.eqlin -1

Z  1 2 3 Z  1 2 3 Z  1 2 3


1 2 0  3  1 2 0  3  1 2 0  3 
A  b  A  b  A  b 
0 1 1  2 0 1 1  2 0 1 1  2
Aeq  1 1 1 beq   4 Aeq  1 1 1 beq   4 Aeq  1 1 1 beq  5

lb   0 0.5 0 ub  5 3 2 lb   0 1.5 0 ub  5 3 3 lb   0 1.5 0 ub  5 3 2


FVAL  4.5 FVAL  9.5 FVAL  4.5

Z  1 2 3 Z  1 2 3 Z  1 2 3


1 2 0  3  1 2 0  3  1 2 0  3 
A  b  A  b  A  b 
0 1 1  2 0 1 1  2 0 1 1  2
Aeq  1 1 1 beq   4 Aeq  1 1 1 beq   4 Aeq  1 1 1 beq  3

lb   0 2.5 0 ub  5 3 2 lb   0 1.5 0 ub  5 3 1 lb   0 1.5 0 ub  5 3 2


FVAL  6.5 FVAL  1.5 FVAL  6.5
14
Mixed Integer Linear Programming
Linear objective function

Linear equality and inequality constraints

Bound constraints
&
Integer variables

MATLAB function: intlinprog


Introduced in R2014a
15
Mixed Integer Linear Programming
Reddy Mikks company produces interior and exterior paints from raw materials, M1 and M2.

 Daily demand for interior paint cannot exceed that for exterior paint by more than 1 unit.

 Maximum daily demand for the interior paint is 2 units.

 Determine optimum quantity of interior and exterior paints that maximizes total daily profit.

Exterior Interior Availability


paint paint
M1 6 4 24
M2 1 2 6
Profit 5 4

Operations research an introduction, H.A. Taha 16


Mixed Integer Linear Programming
Let x1 = Units of exterior paint produced daily Ext. Int.
Availability
Decision variables paint paint
x2 = Units of interior paints produced daily M1 6 4 24
M2 1 2 6
Maximize Profit, Z = 5x1 + 4x2 Objective function
Profit 5 4

Subject to Daily demand for interior paint


cannot exceed that for exterior
6x1 + 4x2 ≤ 24 Raw material paint by more than 1 Unit.
constraints
x1 + 2x2 ≤ 6 Constraints Input:
x2 ≤ x1 + 1 Demand constraint Z   5 4
x1 , x2 ≥ 0  6 4  24 
Bound
x2 ≤ 2 constraints A   1 2 b6
   
 1 1   1 
MATLAB function: intlinprog
lb   0 0 ub  inf 2
17
intlinprog
 x  intcon  are integers  x1 
 x 
linprog T  Ax  b x   2
min f x subject to   
 Ax  b x
 Aeq x  beq  
  xD 
min f T x subject to  Aeq x  beq
x
lb  x  ub
Max Z = 5x1 + 4x2 lb  x  ub
 f , x, intcon, b, beq, lb,
6x1 + 4x2 ≤ 24
and ub are vectors, and Aand Aeq are matrices
x1 + 2x2 ≤ 6
x2 ≤ x1 + 1 [X, FVAL, EXITFLAG, OUTPUT] = intlinprog(Z,intcon,A,b,Aeq,beq,lb,ub,X0,options)
x1, x2 ≥ 0
x2 ≤ 2 Input: Output:
Z   5 4 x Solution vector
Min Z = –5x1 – 4x2 fval Objective function value at solution
 6 4  24 
6x1 + 4x2 ≤ 24 exitflag Algorithm stopping condition
x1 + 2x2 ≤ 6 A   1 2 b6
    output Information such as number of relative gap,
– x1 + x2 ≤ 1  1 1   1  absolute gap, number of integer feasible points
x1, x2 ≥ 0 determined, number of nodes in branch and bound
x2 ≤ 2 lb   0 0 ub  inf 2 algorithm etc.
18
MATLAB code
Create a script file to solve the problem using intlinprog
clc; clear

Z = -[5 4]; % coefficients of objective function

A = [6 4; 1 2; -1 1]; % coefficients of linear inequality constraints


b = [24; 6; 1]; % RHS of linear inequality constraints
Input:
lb = [0 0]; % lower bounds of the variables Z   5 4
ub = [inf 2];% upper bounds of the variables
 6 4  24 
A   1 2 b6 
intcon = [1 2];% Indices of integer variables    
 1 1   1 

% Calling solver lb   0 0 ub  inf 2


[x, fval] = intlinprog(Z, intcon, A, b, [], [], lb, ub);

Output: X [4 0]
FVAL -20

19
Solve using linprog
Create a script file to solve the problem using linprog Input:
Z   5 4
clc; clear
Z = [-5 -4]; % coefficients of objective function  6 4  24 
A = [6 4; 1 2; -1 1]; %coefficients of linear inequality A   1 2 b6 
constraints    
b = [24; 6; 1]; % RHS of linear inequality constraints  1 1   1 

lb = [0 0]; % lower bounds of the variables lb   0 0 ub  inf 2


ub = [inf 2];% upper bounds of the variables
intcon = [1 2];% Indices of integer variables
% Calling solver
[x, fval] = linprog(Z, A, b, [], [], lb, ub);

X [3 2] Infeasible solution
FVAL -23
AX - b [2 1 -2]
intlinprog solution:
linprog solution: X [4 0]
X [3 1.5] FVAL -20
FVAL -21 X [3 1]
FVAL -19
Sub-optimal
AX - b [-2 -1 -2] solution
20
Quadratic Programming

Quadratic objective function

Linear equality and inequality constraints

Bound constraints

MATLAB function: quadprog


Introduced before R2006a

21
Quadratic Programming

Minimize f  x   4 x1  x12  2 x1 x2  2 x22 Objective function Quadratic

Subject to
2 x1  x2  6
Constraints Linear
x1  4 x2  0
x1  0, x2  0 Bound constraints

MATLAB function: quadprog

Engineering Optimization Theory and Practice, S.S. Rao 22


quadprog
 Ax  b  x1 
1 T  x 
min x Hx  f T x such that  Aeq x  beq x 2
x 2  
min f  x   4 x1  x12  2 x1 x2  2 x22 lb  x  ub  
  xD 
2 x1  x2  6
H , A, and Aeq are matrices, and f , b, beq, lb, ub, and x are vectors.
x1  4 x2  0
If symmetric matrix (H) is not a positive definite, quadprog issues a warning and uses the
x1  0, x2  0 symmetrized version (H + HT)/2 instead

[X, FVAL, EXITFLAG, OUTPUT, LAMBDA] = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options)

Output:
 2 f 2 f  x Solution vector
Input:  x 2
 2 2  x1x2  fval Objective function value at solution
f   4 0 H   H   21
 2 4    f 2 f 
  exitflag Algorithm stopping condition
2 1  6   x2x1 x22 
A  b 
1 4  output Information such as number of iterations, algorithm used,
0 
 2 2  exit message etc., of the optimization process
lb   0 0 H  
 2 4  lambda Lagrange multipliers at the solution
negative of the associated "shadow price."
23
MATLAB code
Create a script file to solve the problem using quadprog
clc; clear % Clear the command window and workspace respectively
f = [-4; 0]; % Linear terms in the objective function
H = [2 -2; -2 4]; % Hessian matrix Input:
A = [2 1; 1 -4]; % Coefficients of linear inequality
f   4 0  2 2 
H  
b = [6; 0]; % RHS of linear inequality  2 4 
Aeq = []; % Coefficients of linear equality 2 1  6 
A  b 
beq = []; % RHS of linear equality 1 4  0 

lb = [0 0]; % Lower bounds of the variables lb   0 0


ub = []; % Upper bounds of the variables
% Calling the solver
[x, fval, exitflag, output, lambda] = quadprog(H, f, A, b, Aeq, beq, lb, ub)

Output: X [2.4615 1.0769]


FVAL -6.7692
LAMBDA.lower [0.3871e-11 0.8824e-11] Shadow price for change in lower bound
LAMBDA.upper [0 0] Shadow price for change in upper bound
LAMBDA.ineqlin [0.6154 0] Shadow price for change in RHS of inequality constraints
24
Unconstrained Non-linear Programming

Non-linear objective function

MATLAB function: fminunc and fminsearch


Introduced before R2006a

25
Unconstrained Non-linear Programming
Rosenbrock’s function

Minimize f ( x)  100  x2  x
2 2
   x  1 2
1 1
Non-linear function

Gradient:
 f 
 x   400  x2  x12  x1  2  x1  1 
f  x    1    
 f  
 x  
200  x 2  x1
2
 

 2
MATLAB function: fminunc f *  0 x*  1 1
Continuous differentiable function
26
fminunc
Objective function file returns a scalar
min f  x 
x If user provides the gradient information of f(x),
where f  x  is the objective function. then the objective function file returns two scalars
(function value and gradient value)

[x, fval, exitflag, output, grad, hessian] = fminunc(fun,x0,options)

Input: Output:
x Solution vector
fun Objective function handle fval Objective function value at solution
x0 Initial point of decision variables exitflag Algorithm stopping condition
options Structure containing the optimization options output Information such as number of
such as choice of algorithms, display options, iterations and function count,
maximum iterations/ function evaluations, plot algorithm used, exit message etc.,
functions, output functions etc. grad Gradient at the solution
hessian Approximate Hessian

27
MATLAB code
Create a function file of the objective Create a script file to solve the problem
function using fminunc
function [f,g] = rosenbrockwithgrad(x) clc;clear
% Calculate objective f
f = 100*(x(2) - x(1)^2)^2 + (1-x(1))^2; x0 = [-1,2]; % Initial guess
fun = @rosenbrockwithgrad; % objective
function handle
% Determination of gradient
g = [-400*(x(2)-x(1)^2)*x(1)+2*(x(1)-1); % calling the solver
200*(x(2)-x(1)^2)]; [x, fval, exitflag, output, grad,
hessian] = fminunc(fun, x0);

Minimize f ( x)  100  x2  x 
2 2
  x1  1
2
1
Output: X FVAL
 400  x2  x  x1  2  x1  1 
2

f  x   
1
 [0.9999 0.9999] 1.2262e-10

 200  x2  x1 
2

28
fminsearch
min f  x 
x Objective function file returns a scalar
where f  x  is the objective function

[x, fval, exitflag, output] = fminsearch(fun, x0, options)

Input: Output:

fun Objective function handle x Solution vector


x0 Initial point of decision variables fval Objective function value at solution
options Structure containing the optimization options exitflag Algorithm stopping condition
such as choice of algorithms, display options, output Information such as number of
maximum iterations/ function evaluations, plot iterations and function count,
functions, output functions etc. algorithm used and exit message.

29
MATLAB code
Minimize f ( x)  100  x2  x
2 2
   x1  1
2
1

Create a function file of the objective


function Output:
function f = rosenbrock(x) X FVAL
[0.9999 0.9999] 1.7062e-10
% Calculate objective f
f = 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;

Create a script file to solve the problem using fminsearch


clc; clear
fun = @rosenbrock; % Objective function
x0 = [-1, 2]; % Initial guess
% Calling the solver
[x, fval, exitflag, output] = fminsearch (fun, x0);

30
Bound Constrained Non-linear Programming

Non-linear objective function

Bound constraints

MATLAB function: simulannealbnd and particleswarm


simulannealbnd: Introduced in R2007a
particleswarm: Introduced in R2014b

31
Bound Constrained Non-linear Programming
Rastrigin Function
D
f ( x)  10 D    xi2  10cos(2 xi )  Non-linear function
i 1

Domain:

5.12  xi  5.12 i 1, 2,..., D

MATLAB function: simulannealbnd, particleswarm

f *  0 x*   0 0 
32
simulannealbnd
min f  x 
x

lb  x  ub
.
where lb and ub are scalars / vectors
indicating the bounds of decision variables

[x, fval, exitflag, output] = simulannealbnd(fun,x0,lb,ub,options)

Input: Output:
fun Objective function handle
x0 Initial point of decision variables x Solution vector
fval Objective function value at solution
lb Lower bounds of decision variables
exitflag Algorithm stopping condition
ub Upper bounds of decision variables
output Information such as number of iterations
options Structure containing options such as display and function count, state of random number
options, maximum iterations/function evaluations, generator and exit message.
plot functions, initial temperature etc.
33
MATLAB code
Create a script file to solve the problem using
simulannealbnd
Create a function file of the objective clc; clear
function rng(1, 'twister') % For reproducibility
function F = Rastrigin(x) FUN = @Rastrigin; % Objective function handle
D = 2; % Dimension of the problem
D = length(x); LB = -5.12*ones(1,D); % Lower bounds
F = 0;
UB = 5.12*ones(1,D); % Upper bounds
for d = 1:D x0 = 2*ones(1,D); % Initial point
F = F + x(d)^2 - 10*cos(2*pi*x(d)) + 10; % Calling the solver
end [X, FVAL, EXITFLAG, OUTPUT] =
simulannealbnd(FUN, x0, LB, UB);

D
f ( x)    xi2  10 cos(2 xi )  10  Output:
i 1

5.12  xi  5.12 i  1, 2,..., D X FVAL


[0.5724e-0.5 0.0168e-0.5] 6.5066e-09

34
particleswarm
min f  x 
x

lb  x  ub
.
where lb and ub are scalars / vectors
indicating the bounds of decision variables

[x, fval, exitflag, output] = particleswarm(fun,nvar,lb,ub,options)

Input: Output:
fun Objective function handle
nvar Dimension of the function x Solution vector
lb Lower bounds of decision variables fval Objective function value at solution
ub Upper bounds of decision variables exitflag Algorithm stopping condition
options Structure containing optimization options such as output Information such as number of iterations
display options, maximum iterations/function and function count, state of random number
evaluations, plot functions, inertia range, social generator and exit message.
and self adjustment coefficients etc.
35
MATLAB code
Create a script file to solve the problem using
Create a function file of the objective particleswarm
clc; clear
function rng(1, 'twister') % For reproducibility
function F = Rastrigin(x) FUN = @Rastrigin; % Objective function handle
D = length(x); D = 2; % Dimension of the problem
F = 0; LB = -5.12*ones(1,D); % Lower bounds
UB = 5.12*ones(1,D); % Upper bounds
for d = 1:D
F = F + x(d)^2 - 10*cos(2*pi*x(d)) + 10;
% Calling the solver
end
[X, FVAL, EXITFLAG, OUTPUT] =
particleswarm(FUN, D, LB, UB)

D
f ( x)    xi2  10 cos(2 xi )  10 
i 1 Output:
5.12  xi  5.12 i  1, 2,..., D
X FVAL
[0. 0876e-0.7 -0. 5884e-0.7] 7.0344e-13

36
Constrained Non-linear Programming

Linear/Non-linear objective function

Linear equality and inequality constraints


Non-linear equality and inequality constraints

Bound constraints

MATLAB function: fmincon, ga, patternsearch


Introduced before R2006a

37
Constrained Non-linear Programming
Minimize f  X   x1  x2  x3 Objective function

Subject to: 0.0025  x4  x6   1  0


Linear
0.0025   x4  x5  x7   1  0 inequality
constraints
0.01  x5  x8   1  0
100 x1  x1 x6  833.33252 x4  83333.333  0 Non-linear
x2 x4  x2 x7  1250 x4  1250 x5  0 inequality
x3 x5  x3 x8  2500 x5  1250000  0 constraints

100  x1  10000
Bound constraints: 1000  x2 , x3  10000 Bound
constraints
10  xi  1000, i  4,5,...,8
0 0 0 0.0025 0 0.0025 0 0  1
A  0 0 0 0.0025 0.0025 0.0025 0  b  1
MATLAB function: fmincon 
0
 
0 0 0 0 0.01 0 0 0.01 1

Engineering Optimization: Theory and Practice, S.S. Rao 38


fmincon
c  x   0

ceq  x   0
[x,fval,exitflag,output,lamda,grad,hessian] =
fmincon(fun,X0,A,b,Aeq,beq,lb,ub,nonlcon,options) 
min f  x  subject to  Ax  b
x
 Aeq x  beq

Input: lb  x  ub

fun Objective function handle
f , x, b, beq, lb, and ub are vectors, and Aand Aeq are matrices
X0 Initial point of the decision variables c( x) and ceq ( x) are functions that return vectors
A Coefficients of linear inequality constraints
b RHS of linear inequality constraints
Output: x Solution vector
Aeq Coefficients of linear equality constraints
fval Objective function value at solution
beq RHS of linear equality constraints
exitflag Algorithm stopping condition
lb Lower bounds of decision variables
output Information such as number of iterations,
ub Upper bounds of decision variables algorithm used, exit message etc.,
nonlcon Non linear constraints function handle lambda Lagrange multipliers at the solution
options Structure containing options such as display grad Gradient at the solution
options, maximum iterations/function evaluations, hessian Approximate Hessian
plot functions, choice of algorithm etc.
39
MATLAB code

Create a function file of the objective function Min f  X   x1  x2  x3


function f = ObjectiveFunction(x)
100 x1  x1 x6  833.33252 x4  83333.333  0
f = sum(x(1:3)); x2 x4  x2 x7  1250 x4  1250 x5  0
x3 x5  x3 x8  2500 x5  1250000  0

Create a function file of the objective function


function [C, Ceq] = NLCon(x)
C(1) = 100*x(1) - x(1)*x(6) + 833.33252*x(4) - 83333.333;
C(2) = x(2)*x(4) - x(2)*x(7) - 1250*x(4) + 1250*x(5);
C(3) = x(3)*x(5) - x(3)*x(8) - 2500*x(5) + 1250000;

Ceq = []; % nonlinear equality constraints are absent

40
MATLAB code
Create a function file of the objective function 0 0 0 0.0025 0 0.0025 0 0  1
clc; clear; A  0 0 0 0.0025 0.0025 0 0.0025 0  b  1
  
A = [0 0 0 0.0025 0 0.0025 0 0; 0 0 0 0 0.01 0 0 0.01 1
0 0 0 -0.0025 0.0025 0 0.0025 0;
0 0 0 0 -0.01 0 0 0.01]; %Linear inequalityconstraints
b = ones(3,1); % RHS of linear inequality constraints
100  x1  10000
lb = [100 1000 1000 10*ones(1,5)]; % Lower bounds
ub = [10000 10000 10000 1000*ones(1,5)]; % Upper bounds
1000  x2 , x3  10000
x0 = lb; % Initial point of variables 10  xi  1000, i  4,5,...,8
fun = @ObjectiveFunction; % Objective function handle
Nonlcon = @NLCon; % Nonlinear constraint function handle
% calling the solver
[X, FVAL] = fmincon(fun, x0, A, b, [], [], lb, ub, Nonlcon);

Output:
X [579.31 1359.97 5109.97 182.02 295.60 217.98 286.42 395.60]
FVAL 7049.25

41
Constrained Non-linear Programming
Maximize f  x   1  x   x 
1
2 2
Objective function
1 2

subject to
x12  x22  4 Non-linear
inequality
x12  x22  16 constraints

x1  x2  3 Linear equality constraints

10  x1 , x2  10 Bound constraints

MATLAB function: ga, patternsearch

Optimization of chemical processes, Edgar 42


ga
[x,fval,exitflag,output,Population,Score] =  x  intcon  are integers

c  x   0
ga(fun,nvar,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)
c x  0
  
min f  x  subject to  eq
Input: x
 Ax  b
fun Objective function handle A x  b
 eq eq

nvar Number of decision variables lb  x  ub


A Coefficients of linear inequality constraints intcon, b, beq, lb, and ub are vectors, and Aand Aeq are matrices
b RHS of linear inequality constraints
c( x) and ceq ( x) are functions that return vectors

Aeq Coefficients of linear equality constraints


Output:
beq RHS of linear equality constraints
x Solution vector
lb Lower bounds of decision variables
fval Objective function value at solution
ub Upper bounds of decision variables
exitflag Algorithm stopping condition
nonlcon Non linear constraints function handle
output Information such as number of iterations,
intcon Indices of integer variables algorithm used, exit message, state of
random number generator etc.,
options Structure containing optimization options such as display
options, maximum iterations/function evaluations, plot Population Final population
functions, choice of algorithm, function and probability
of crossover and mutation, etc. Score Objective function value of final population
43
MATLAB code
Create a function file of the objective Create a script file to solve the problem using ga
function clc; clear;
function f = ObjectiveFn(x) rng(1,’twister’)
fun = @ObjectiveFn; % Objective function handle

f = -((1 + x(1)^2) + x(2)^2)^-1; Aeq = [1 -1]; % Coefficients of equality constraints


beq = 3; % RHS of equality constraints
Create a function file of the objective lb = [-10 -10]; % Lower bound
function ub = [10 10];% Upper bound
function [c, ceq] = NLConstraints(x) nvar = length(lb); % No. of decision variables
nonlcon = @NLConstraints;% Nonlinear constraint
ceq = []; function handle
c(1) = 4 - x(1)^2 - x(2)^2; % Calling the solver
c(2) = x(1)^2 + x(2)^2 - 16; [x, fval] = ga(fun, nvar, [], [], Aeq, beq,
lb, ub, nonlcon);
Output: f  x   1  x12   x22 
1

X [1.4994 -1.4996] x12  x22  4


x12  x22  16
FVAL -0.1819
x1  x2  3
10  x1 , x2  10 44
patternsearch
[x,fval,exitflag,output] = patternsearch(fun,X0, c  x   0
A,b,Aeq,beq,lb,ub,nonlcon,options) 
ceq  x   0

min f  x  subject to  Ax  b
Input: x
A x  b
fun Objective function handle  eq eq

lb  x  ub
X0 Initial point of the decision variables 
f , x, b, beq, lb, and ub are vectors, and Aand Aeq are matrices
A Coefficients of linear inequality constraints
c( x) and ceq ( x) are functions that return vectors
b RHS of linear inequality constraints

Aeq Coefficients of linear equality constraints

beq RHS of linear equality constraints

lb Lower bounds of decision variables


Output:
ub Upper bounds of decision variables
X Solution vector
fval Objective function value at solution
nonlcon Non linear constraints function handle
exitflag Algorithm stopping condition
options Structure containing options such as display options,
maximum iterations/function evaluations, plot functions, output Information such as number of iterations,
choice of algorithm, tolerance and maximum size of algorithm used, exit message etc.,
mesh etc.
45
MATLAB code
Create a function file of the objective Create a script file to solve the problem using
function patternsearch
function f = ObjectiveFn(x) clc; clear
rng(1,'twister') % For reproducibility

f = -((1 + x(1)^2) + x(2)^2)^-1; fun = @ObjectiveFn; % Objective function handle


Aeq = [1 -1]; % Coefficients of equality constraints
Create a function file of the objective beq = 3; % RHS of equality constraints
function lb = [-10 -10]; % Lower bound
ub = [10 10];% Upper bound
function [c, ceq] = NLConstraints(x)
x0 = [-3 -3];% Initial point
nonlcon = @NLConstraints;% Nonlinear constraint function
ceq = []; handle
c(1) = 4 - x(1)^2 - x(2)^2; % Calling the solver
c(2) = x(1)^2 + x(2)^2 - 16; [x, fval] = patternseach(fun, nvar, [], [],
Aeq, beq, lb, ub, nonlcon);
Output: f  x   1  x12   x22 
1

X [1.4995 -1.4995] x12  x22  4


x12  x22  16
FVAL -0.1819 x1  x2  3
10  x1 , x2  10 46
Constrained Mixed Integer Non-linear Programming

Linear/Non-linear objective function

Linear equality and inequality constraints


&
Non-linear equality and inequality constraints

Bound constraints
&
Integer variables

MATLAB function: ga
Introduced before R2006a

47
Constrained Mixed Integer Non-linear Programming
x
Minimize f  x, y    y  2 x  ln  
Non-linear
objective function
2

subject to
Non-linear
x
 x  ln    y  0 inequality
2 constraints

0.5  x  1.5
Bound constraints
y  0,1

 MATLAB function: ga

48
MATLAB code
x
Minimize f  x, y    y  2 x  ln   Create a script file to solve the problem using ga
2
x clc;clear
 x  ln    y  0 rng(1,'twister') % For reproducibility
2
0.5  x  1.5 fun = @ObjFunInt; % objective function handle
y  0,1 lb = [0.5,0]; % Lower bound
ub = [1.5,1]; % Upper bound
Create a function file of the objective
intcon = 2; % Index of integer variable
function nvar = length(lb); % Problem dimension
function f = ObjFunInt(X)
% x = X(1) and y = X(2) nonlcon = @nonlconInt;% Nonlinear constraint function
handle
f = -X(2)+2*X(1)-log(X(1)/2);
[x, fval] = ga(fun, nvar, [], [], [], [], lb,
Create a function file of the objective ub, nonlcon, intcon);
function
function [c,ceq] = nonlconInt(X) Output: X
% x = X(1) and y = X(2) [1.3770 1]
c = -X(1)-log(X(1)/2)+X(2);
ceq = []; FVAL 2.1272
49
Restriction of ga
ga cannot solve a problem with equality constraints and integer variables

No CreationFcn option, CrossoverFcn option, MutationFcn option,


InitialScoreMatrix option.

To obtain integer variables, ga uses special creation, crossover, and mutation functions.

ga uses only the binary tournament selection function (SelectionFcn option)

There are no hybrid functions that support integer constraints. So ga does not use
hybrid functions when there are integer constraints

Mixed Integer Optimization https://in.mathworks.com/help/gads/mixed-integer-optimization.html#bs1cifg 50


Solving MINLP using ga
minimize f  x  minimize f  x 
minimize f  x  minimize f  x 
subject to minimize f  x  subject to
subject to subject to
Ax  b subject to Ax  b
Problem type Ax  b Ax  b
Aeq x  beq Ax  b Aeq x  beq
Aeq x  beq C  x  0
C  x  0 C  x  0 C  x  0
C  x  0 Ceq  x   0
Ceq  x   0 x  intcon  are integer variable Ceq  x   0
x  intcon  areinteger variable x  intcon  are integer variable
x  intcon  areinteger variable x are continuous variable

Solve using ga     

MINLP problem MINLP problem MINLP problem MINLP problem NLP problem
without nonlinear without linear without equality
equality constraints equality constraints constraints No integer variables

51
Input and output arguments of different solvers
[x, fval, exitflag, output, lambda] = linprog(Z, A, b, Aeq, beq, lb, ub, options)
[x, fval, exitflag, output] = intlinprog(Z, intcon, A, b, Aeq, beq, lb, ub, x0, options)
[x, fval, exitflag, output, lambda] = quadprog(H, f, A, b, Aeq, beq, lb, ub, x0, options)
[x, fval, exitflag, output, grad, hessian] = fminunc(fun, x0, options)
[x, fval, exitflag, output] = fminsearch(fun, x0, options)
[x, fval, exitflag, output] = simulannealbnd(fun, x0, lb, ub, options)
[x, fval, exitflag, output] = particleswarm(fun, nvar, lb, ub, options)
[x, fval, exitflag, output, lamda, grad, hessian] = fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options)
[x, fval, exitflag, output] = patternsearch(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options)
[x, fval, exitflag, output, population, score] = ga(fun, nvar, A, b, Aeq, beq, lb, ub, nonlcon, intcon, options)

52
Optimization options
Optimization options are specified as the output of the structure ‘optimoptions’.

Can be used to modify or view the default setting of any optimization solvers.

Consider minimization of Rastrigin function using ga.


D
Using optimoptions, f ( x)    xi2  10 cos(2 xi )  10 
i 1

 change crossover probability to 0.6, 5.12  xi  5.12 i  1, 2,..., D

 include plot function to plot best iteration versus objective value.

53
Optimization options

54
MATLAB code
Create a script file to solve the problem using
Create a function file of the objective ga
function clc; clear
function F = Rastrigin(x) rng(1, 'twister') % For reproducibility

D = length(x); FUN = @Rastrigin; % Objective function handle


F = 0;
D = 2; % Dimension of the problem
for d = 1:D LB = -5.12*ones(1,D); % Lower bounds
F = F + x(d)^2 - 10*cos(2*pi*x(d)) UB = 5.12*ones(1,D); % Upper bounds
+ 10; % Change the default settings
end options = optimoptions('ga','PlotFcn',
@gaplotbestf,'CrossoverFraction',0.6);
% Calling the solver
[x, fval] = ga(FUN, D, [], [], [], [], LB,
UB, [], [], options);
D
f ( x)    xi2  10cos(2 xi )  10 
i 1

5.12  xi  5.12 i 1, 2,..., D 55


Results

Output:
X [0.7856e-05 -0.0458e-05]
FVAL 1.2287e-08

56
OutputFcn in optimization toolbox
To retrieve output from an optimization algorithm in every iteration

Syntax: options = optimoptions(@solvername, ‘OutputFcn’, @outputfunction)

For ga, MATLAB passes the options, state, and flag data to the output function, and it returns
state, options, and optchanged data.
 options: structure containing the settings used in ga.
 state: Structure containing information such as generation, start time, stop flag, best score in each
generation, current population and scores etc. about the current generation.
 flag: current status (‘init’, ‘iter’, ‘done’ etc.) of the algorithm

Output function syntax: [state,options,optchanged] = outputfunction(options,state,flag)

optchanged: flag indicating changes to options (if options are changed, optchanged = 1 else
optchanged = 0)

57
MATLAB code

Create a function file of the Create an output function which plots the population
objective function in every generation
function F = Rastrigin(x) function [state, options, optchanged] =
outputFnExample(options, state, flag)
D = length(x);
F = 0;
optchanged = false; % Flag to indicate the change in options
for d = 1:D
F = F + x(d)^2 - currentPop = state.Population;% current population
10*cos(2*pi*x(d)) + 10; plot(currentPop(:,1), currentPop(:,2), ‘b.');
end hold on;
drawnow
D xlabel('x_1')
f ( x)    xi2  10cos(2 xi )  10  ylabel('x_2')
i 1 end

58
MATLAB code
Create a script file to solve the problem using ga
clc;clear
rng(1, 'twister') % For reproducibility
FUN = @Rastrigin; % Objective function handle
D = 2; % Dimension of the problem
LB = -5.12*ones(1,D); % Lower bounds of the problem
UB = 5.12*ones(1,D); % Upper bounds of the problem
% Change the default settings using optimoptions
options = optimoptions('ga', 'OutputFcn',
@outputFnExample, 'CrossoverFraction', 0.6);
% Calling the solver
[x, fval] = ga(FUN, D, [], [], [], [],LB, UB,
[], [], options);

Output:
5.12  xi  5.12 i 1, 2,..., D x [0.7856e-05 -0.0458e-05]
fval 1.2287e-08

59
Vectorization of fitness function
Vectorization increases the speed of execution.
For using the vectorized option, the fitness function must
 accept a matrix with arbitrary number of rows (population) D

 return the fitness vector (fitness of the population) f ( x)  10 D    xi2  10cos(2 xi ) 


i 1

Vectorized code of Rastrigin function 5.12  xi  5.12 i  1, 2,..., D


function F = RastriginVectorized(X)
[N,D] = size(X); % Number of decision variables Accepts X matrix (N x D)
Vectorized Code
F = zeros(N,1); % Initial value of fitness Returns F vector (N x 1)
for n = 1:N
for d = 1:D
F(n) = F(n) + X(n, d)^2 - 10*cos(2*pi*X(n,d)) + 10;
end
end

function F = Rastrigin(x)
D = length(x); % Number of decision variables
Accepts x vector (1 x D)
F = 0; % Initial value of fitness Not a vectorized Code
for d = 1:D Returns F scalar (1 x 1)
F = F + x(d)^2 - 10*cos(2*pi*x(d)) + 10;
end
60
MATLAB code
Create a script file to solve the problem using ga
Comparison of elapsed time
clc;clear
rng(1, 'twister') % For reproducibility Use vectorized false true
D = 20; % Dimension of the problem Elapsed time 17.28 13.65
LB = -5.12*ones(1,D); % Lower bounds of the problem
UB = 5.12*ones(1,D); % Upper bounds of the problem
% Calling the solver without vectorization option
options = optimoptions('ga','PopulationSize',2000);
FUN = @Rastrigin; % Objective function handle
tic
[x,fval] = ga(FUN, D , [], [], [], [], LB, UB,[],[],options);
noVec = toc
% Calling the solver with vectorization option
options = optimoptions('ga','UseVectorized',true,'PopulationSize',2000);
FUN = @RastriginVectorized; % Objective function handle
tic
[x, fval] = ga(FUN, D, [], [], [], [], LB, UB, [], [], options);
vec = toc

Machine configuration
Intel core i7 @3.4GHz with 24 GB RAM
61
Parallel evaluation of fitness function
Option is available to compute the fitness and non-linear constraint function in parallel.
Cannot use vectorized and parallel computation options simultaneously.
UseVectorized = false UseVectorized = true
UseParallel = false Serial Vectorized
UseParallel = true Parallel Vectorized

For using the parallel option, the fitness and non-linear constraint functions need not be
vectorized.

Syntax: options = optimoptions(@SolverName, 'UseParallel', true, 'UseVectorized', false);

Parallel option available in solvers such as ga, particleswarm, patternsearch, etc.

Demo of optimizing an ODE in parallel: https://in.mathworks.com/help/gads/optimize-an-


ode-in-parallel.html
https://in.mathworks.com/help/gads/genetic-algorithm-options.html#f17234 62
MATLAB code
Create a function file of the Create a script file to solve the problem using ga
objective function clc;clear
rng(1, 'twister') % For reproducibility
function F = Rastrigin(x)
D = length(x); FUN = @Rastrigin; % Objective function handle
F = 0; D = 20; % Dimension of the problem
LB = -5.12*ones(1,D); % Lower bounds of the problem
for d = 1:D UB = 5.12*ones(1,D); % Upper bounds of the problem
F = F + x(d)^2 - 10*
cos(2*pi*x(d)) + 10; tic
[x, fval] = ga(FUN, D , [], [], [], [], LB, UB);
end woPar = toc;
pause(0.01) % simulate an
options = optimoptions('ga', 'UseParallel', true,
expensive function by pausing
'UseVectorized', false);

Comparison of elapsed time parpool % To start parallel pool


Use parallel false true tic
[x, fval] = ga(FUN, D, [], [], [], [], LB, UB, [], [], options);
Elapsed time 853.026 123.61 wPar = toc;

Machine configuration
Intel core i7 @3.4GHz with 24 GB RAM
63
Optimtool

64
Constrained Multi-objective Optimization

Linear/Non-linear objective function

Linear equality and inequality constraints


&
Non-linear equality and inequality constraints

Bound constraints

MATLAB functions:
gamultiobj (Introduced in R2007b)
paretosearch (Introduced in R2018b)

65
gamultiobj
[x,fval,exitflag,output,Population,Score] = min fi  x  i  1, 2,..., M
x
gamultiobj(fun,nvar,A,b,Aeq,beq,lb,ub,nonlcon,options)
c  x   0

ceq  x   0
Input: 
subject to  Ax  b
fun Objective function handle A x  b
 eq eq
nvar Number of decision variables lb  x  ub

A Coefficients of linear inequality constraints b, beq, lb, and ub are vectors, and Aand Aeq are matrices
b RHS of linear inequality constraints c( x) and ceq ( x) are functions that return vectors
Aeq Coefficients of linear equality constraints
Output:
beq RHS of linear equality constraints
x Solution vector
lb Lower bounds of decision variables
fval Objective function value at solution
ub Upper bounds of decision variables
exitflag Algorithm stopping condition
nonlcon Non linear constraints function handle
output Information such as number of iterations,
options Structure containing optimization options such as display algorithm used, exit message, state of
options, maximum iterations/function evaluations, plot random number generator etc.,
functions, choice of algorithm, function and probability
of crossover and mutation, etc. Population Final population
Score Objective function value of final population
66
Multi-objective optimization problem (KUR)

 
D 1
minimize f1  x    10exp 0.2 xi2  xi21
i 1
Objective functions
D 1
minimize f 2  x    xi  5sin  xi3 
0.8

i 1

5  xi  5 i  1, 2,3

Multi-objective Optimization using evolutionary algorithms, Wiley


https://in.mathworks.com/help/gads/gamultiobj.html 67
MATLAB code
Create a function file of the objective function
 
D 1

function f = kur_MO(x) minimize f1  x    10exp 0.2 xi2  xi21


i 1
D 1
minimize f 2  x    xi  5sin  xi3 
D = length(x); 0.8

i 1
f(1) = sum(-10*exp(-0.2*sqrt(x(1:D-1).^2 + x(2:D).^2)));
f(2) = sum(abs(x(1:D)).^0.8 + 5*sin(x(1:D).^3));

Create a script file to solve the problem using gamultiobj


clc;clear

ub = [5 5 5];
lb = -ub;
nvars = length(lb);
fitnessfcn = @kur_MO;

[x,fval,exitflag,output,population,scores] = ...
gamultiobj(fitnessfcn,nvars,[],[],[],[],lb,ub);

plot(fval(:,1),fval(:,2),'b*')
xlabel('Minimize f_1')
ylabel('Minimize f_2')
68
paretoseach
[x,fval,exitflag,output,residuals]= min fi  x  i  1,2,...M
x
paretosearch(fun,nvar,A,b,Aeq,beq,lb,ub,nonlcon,options)
c  x   0

ceq  x   0
Input: 
subject to  Ax  b
fun Objective function handle A x  b
 eq eq
nvar Number of decision variables lb  x  ub

A Coefficients of linear inequality constraints b, beq, lb, and ub are vectors, and Aand Aeq are matrices
b RHS of linear inequality constraints c( x) and ceq ( x) are functions that return vectors
Aeq Coefficients of linear equality constraints
Output:
beq RHS of linear equality constraints
x Solution vector
lb Lower bounds of decision variables
fval Objective function value at solution
ub Upper bounds of decision variables
exitflag Algorithm stopping condition
nonlcon Non linear constraints function handle
output Information such as number of iterations,
options Structure containing optimization options such as display algorithm used, exit message, state of
options, maximum iterations/function evaluations, plot random number generator etc.,
functions, choice of algorithm, function and probability
of crossover and mutation, etc. residuals structure containing the constraint values at
the solution points x
69
MATLAB code
Create a function file of the objective function
function f = kur_MO(x)

D = length(x);

f(1) = sum(-10*exp(-0.2*sqrt(x(1:D-1).^2 + x(2:D).^2)));


f(2) = sum(abs(x(1:D)).^0.8 + 5*sin(x(1:D).^3));

Create a script file to solve the problem using paretosearch


clc;clear

ub = [5 5 5];
lb = -ub;
nvars = length(lb);
fitnessfcn = @kur_MO;

[x,fval,exitflag,output,residuals] = ...
paretosearch(fitnessfcn,nvars,[],[],[],[],lb,ub);

plot(fval(:,1),fval(:,2),'b*')
xlabel('Minimize f_1')
ylabel('Minimize f_2')
70
Closure
MATLAB optimization solvers for
 LP problems – linprog
 MILP problems – intlinprog
 Unconstrained NLP problems – fminunc and fminsearch
 Bound constrained NLP problems – simulannealbnd and particleswarm
 Constrained NLP problems – fmincon, patternsearch and ga
 MINLP problems (without equality constraints) – ga
Options in optimization toolbox
Output function in optimization toolbox
Vectorization of fitness function
Parallel evaluation of fitness function
Multi-objective optimization problems – gamultiobj and paretosearch
71
Optimization software
Constraint
Solver LP MILP NLP MINLP
Programming
IBM ILOG CPLEX Optimization Studio     
GAMS     
MATLAB Optimization Toolbox    * 
* MINLP solver in MATLAB (ga) cannot solve an MINLP problem if integer constraints are present

MATLAB: https://in.mathworks.com/products/get-matlab.html?s_tid=gn_getml
GAMS: https://www.gams.com/download/
IBM ILOG CPLEX : https://www.ibm.com/in-en/products/ilog-cplex-optimization-studio

72
Thank You !!!

You might also like