Optimization Toolbox
Optimization Toolbox
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
Bound constraints
3
Relaxation and tightening of search space
LB relaxation
lb = [100 30] Min f = 3x1 + 2x2 LB tightening
lb = [100 70]
UB relaxation UB tightening
ub = [800 100] ub = [650 100]
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
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
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA] = linprog(Z,A,b,Aeq,beq,lb,ub,options)
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
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]
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
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
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);
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
Bound constraints
&
Integer variables
Daily demand for interior paint cannot exceed that for exterior paint by more than 1 unit.
Determine optimum quantity of interior and exterior paints that maximizes total daily profit.
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 b6
constraints
b = [24; 6; 1]; % RHS of linear inequality constraints 1 1 1
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
Bound constraints
21
Quadratic Programming
Subject to
2 x1 x2 6
Constraints Linear
x1 4 x2 0
x1 0, x2 0 Bound constraints
Output:
2 f 2 f x Solution vector
Input: x 2
2 2 x1x2 fval Objective function value at solution
f 4 0 H H 21
2 4 f 2 f
exitflag Algorithm stopping condition
2 1 6 x2x1 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
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)
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
Input: Output:
29
MATLAB code
Minimize f ( x) 100 x2 x
2 2
x1 1
2
1
30
Bound Constrained Non-linear Programming
Bound constraints
31
Bound Constrained Non-linear Programming
Rastrigin Function
D
f ( x) 10 D xi2 10cos(2 xi ) Non-linear function
i 1
Domain:
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
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
34
particleswarm
min f x
x
lb x ub
.
where lb and ub are scalars / vectors
indicating the bounds of decision variables
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
Bound constraints
37
Constrained Non-linear Programming
Minimize f X x1 x2 x3 Objective function
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
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
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
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
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
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.
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
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
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
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
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.
Machine configuration
Intel core i7 @3.4GHz with 24 GB RAM
63
Optimtool
64
Constrained Multi-objective Optimization
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 xi21
i 1
Objective functions
D 1
minimize f 2 x xi 5sin xi3
0.8
i 1
5 xi 5 i 1, 2,3
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));
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);
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 !!!