AN INTRODUCTION TO OPTIMIZATION USING EVOLUTIONARY ALGORITHMS
Dr B.Srinivas Dept of Chemical Engg GVP Colle e of En En
Introduction to Optimization. Solving optimization optimizatio n problems using MATLAB. MATLAB. Global Optima versus Local Optima. Introduction to GA and SA. . Multi-objective Optimization. Solving Multi-objective Multi-ob jective optimization problems in MATLAB. MATLAB.
Solving optimization problems in MATLAB
Introduction
Function Optimization: p m za za on oo ox Routines / Algorithms available
Minimization Problems
Unconstrained Constrained
The Algorithm Description
Function Optimization
Optimization concerns the minimization or maximization of functions Standard Optimization Problem x
~
~
Subject to:
i
= ~
()
g j x ≤ 0
Inequality Constraints
~
L
x
k
≤ xk ≤ xU k
Side Constraints
Function Optimization
()
f x ~
x ~
is the objective function , which measure . In a standard problem, we are minimizing the function. or max m za on, s equ va en o m n m za on of the –ve of the objective o bjective function.
is a column vector of design of design variables , which can
Function Optimization Constraints Constraints – Limitation Limitation to the design space. space. Can be linear or nonlinear, explicit or implicit functions h x =0
Equality Constraints
g j x ≤ 0
Inequality Constraints
~
~
Algorithms require Less Than
L
U k
k
k
e ons ra n s
Optimization Optimiza tion Toolbox Toolbox
Is a collection of functions that extend the capability of MATLAB MATLAB.. The toolbox includes routines for: Uncons nstr trai aine ned d o timi timiza zati tion on Unco Constrained nonlinear optimization, including goal attainment problems, problems, minimax problems, problems, and semi-infinite minimization problems Quadratic and linear programming cur ve fitting Nonlinear least squares and curve Nonl nlin ine ear s stems tems of e uati uation onss solv olvin No Constrained linear least squares p roblems Specialized algorithms for large scale problems
Minimization Algorithm
Minimization Algorithm (Cont.)
Implementing Opt. Toolbox
Most of these optimization routines require the definition definition of an M-file containing the function, f , to be minimized. –. Optimization options passed to the routines change c hange optimization parameters. parameters. Default optimization parameters can be change c hanged d through an options structure.
Unconstrained Minimization
Consider the problem of finding a set of values [ x1 x2]T that solves
x min f x = e 1 4 x1 + 2 x2 + 4 x1 x2 + 2 x2 + 1 x ~
~
x = [ x1 ~
T
x2 ]
Steps
Create an M-file that returns retur ns the function value (Objective Function)
Call it objfun.m
Then, invoke invoke the unconstrained minimization routine
Use fminunc
Step St ep 1 – Ob Obj. j. Fu Func ncti tion on x = [ x1 =
~
T
x2 ]
f=exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);
Step St ep 2 – In Invo voke ke Rou Routi tine ne Starting Guess x0 = [-1,1];
Optimization parameter Settings
options = optimset(‘LargeScale’,’off’); [xmin,feval,exitflag,output]= fminunc(‘objfun’,x0,options);
Output Arguments
Input Arguments
Results xmin = 0.5000
-1.0000
Minimum point of design variables
feval = 1.3028e-010 exitfl fla a
Objective function value
=
Exitflag tells if Exitflag if the algorit algorithm hm is conver converged. ged. If exitflag exitflag > 0, then then local local minimum minimum is found
1 output = iterations: 7 funcCount: 40 stepsize: 1
Some other information
firstorderopt: 8.1998e-004 algorithm: 'medium-scale: Quasi-Newton line search'
More on fminunc – Input [xmin,feval,exitflag,output,grad,hessian]= m nunc
un,x ,op
ons,
,
,…
. x0: Starts with an initial guess. The guess must be a vector of size of number of design variables. . slides) P1,P2,… : To pass additional parameters. Ref. Manual: Pg. 5-5 to 5-9
More on fminunc – Output [xmin,feval,exitflag,output,grad,hessian]= ,
,
,
,
,…
xmin: Vector of the minimum point (optimal point). The size is the
number of desi n variables. feval: The objective function value of at the optimal point. exitflag : A value shows whether the optimization routine is . output : This structure gives more details about the optimization grad: The gradient value at the optimal point. hessian: e ess an va ue o a e op ma po n Ref. Manual: Pg. 5-5 to 5-9
Options Setting – optimset Options = ‘
’
‘
’
…
The routines in Optimization Toolbox has a set of default optimization parameters. However, the toolbox allows you to alter some of those parameters, for example: the tolerance, the step size, the gradient or hessian values, the max. number of iterations etc. There are also a list of features available, available, for example: displaying the values at each iterations, compare the user supply gradient or hessian, etc. You can also choose the the algorithm you wish wish to use. Ref. Manual: Pg. 5-10 to 5-14
Constrained Minimization Vector of Lagrange Multi lier at o timal point
[xmin,feval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x0,A,B,Aeq,Beq,LB,UB,NONLCON,options, P1,P2,…)
Example
function f = myfun(x)
()
min f x = − x1 x2 x3 x ~
Subject to:
f=-x(1)*x(2)*x(3);
~
2 x12 + x2 ≤ 0
− x1 − 2 x2 − 2 x3 ≤ 0 x1 + 2 x2 + 2 x3 ≤ 72
0 ≤ x1 , x2 , x3 ≤ 30 A =
⎡ −1 −2 −2 ⎤
, B=
⎡0⎤
⎡0⎤ ⎡30 ⎤ ⎢ ⎥ ⎢ ⎥ LB = 0 UB = 30 ⎢⎣ 0 ⎥⎦ ⎢⎣30 ⎥⎦
. For
2 x12 + x2 ≤ 0
Create a function call nonlcon which returns 2 constraint vectors [C,Ceq] function [C,Ceq]=nonlcon(x) C=2*x(1)^2+x(2); Ceq=[];
Remember to return a null Matrix if the constraint does not apply
Example (Cont.) Initial guess (3 design variables)
⎡ −1 −2 −2 ⎤ x0=[10;10;10]; A=[-1 -2 -2 -2;1 2 2]; B= 0 72 ' LB = [0 0 0]'; UB = [30 30 30]';
⎣1
2
⎡0⎤
2⎦
,
⎡0⎤ ⎣72 ⎦ ⎡30 ⎤
LB = 0 , UB = 30
⎢ ⎥ ⎢⎣0 ⎥⎦
⎢ ⎥ ⎢⎣30 ⎥⎦
[x,feval]=fmincon(@myfun,x0,A,B,[],[],LB,UB,@nonlcon)
CAREFUL!!!
fmincon(fun,x0,A,B,Aeq,Beq,LB,UB,NONLCON,options,P1,P2,…)
Conclusion
Easy to use! But, we do not know what is happening behind the routine. Therefore, it is still important to un erstan t e imitation o eac routine. Basic steps:
Define the design variables Create objective function Recognize the constraints Start an initial guess
Analyze the results (it might not make sense)
Local and Global Optima
Basins of attraction behave like local attractors. All initial conditions close to a local attractor reach that point.
o reac a g o a opt ma we have to ensure that the initial guess we provide is lying close to the attractor belonging to the global optima.
But how to give a guess close to the global optima?
Give different initial
Genetic Al orithm , GAs are initialized with a population of guesses. These are usually random and will be spread throughout the search space. A typical algorithm then use us es th thre ree e op ope erat ator orss, selectio cho osen in part by selection, n, crosso crossover ver and mutation (ch analogy with the natural world) to direct the population (over a series of tim ti me st step epss or gene nerrat atio ions ns)) towar ards ds co conv nver erg genc nce e at th the e gl glob obal al op opti timu mum m. Selection attempts to apply pressure upon the population in a manner similar to that of natural selection found in biological systems. Poorer performing individuals are weeded out and better performing, or fitter, inffor in orm mat atio ionn th the ey co cont ntai ainn wi with thin in th the e ne next xt gen ene erat atio ion. n.
You aim to produce a puppy with the loudest bark.
You select dogs which whic h bark loudly and rank them.
barking dogs out of the lot and mate them. Since the parents bark loud its Nat atuural that the pups the th ey gene nerrat ate e wou ould ld ba bark rk loud lo udly ly to too! o!!!
Operations in GA Crossover allows solutions to exc hange information in a way similar to that used by a
natural organism undergoing sexual reproduction. One method (termed single point , cho ch oose a single locus (point) within the binary strings and swap all the inform rma ation (digits) to the right of this locus between the two individuals. cha ange (flip) the value of single bits within individual strings. Mutation is used to randomly ch Mutation is typ ypiically use sed d very spar ariingly. After selection, cros osssover an and d mu muttation have been applied to the initial population, a new population will have been formed and the enerational counter is increased b one. This process of selection, crossover and mutation is continued until a fixed number of generat atiions have elap apssed or some for orm m of convergence criterion has been met.
Crossover
Single point crossov crossover er 0 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1
0 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1
Mutation
0 1 0 0 1 0 1 0 1 0 1 0 1 1 0 1 1
•
utat on can e p escap ng rom oca opt ma in our state space.
An elementary example A trivial problem might be to maximize a function, f(x), where f(x) = x^2 ; for integer x and 0 < x < 4095. There are of course cour se other ways ways of finding the answer (x = 4095) to this problem than using , .
Firstly, the exact form of the algorithm must Firstly, m ust be decided upon. As mentioned earlier, earlier, GAs can take many forms. This allows a wealth of freedom in the details of the algorithm. The following follo wing (Algorithm 1) represents just one possibility.
1. Form a popul populati ation, on, of of eight rando random m binary binary stri strings ngs of length length tw twelv elve e (e.g. 101001101010, 110011001100, ). 2. Decode each binary bi nary string to an integer x (i.e. 000000000111 implies x = 7, 000000000000 = 0, 111111111111 = 4095). 3. Test the these se num number berss as solu solutio tions ns to the ro roble blem m f x = x^2 and assi n a fit fitnes nesss to to each individual equal to the value of fix) (e.g. the solution x = 7 has a fitness of 7^2 = 49). . e ect t e est a next generation.
t ose w t
g est tness o t e popu at on to go or orwar to t e
5. Pick pairs of parent strings at random (with each string being selected exactly once) from these more successful individuals to undergo single point po int crossover. crossover. Taking Taking each eac h pair in turn, choose a random point between the end points of the string, cut the strings at this point and exchange the tails, creating pairs of child strings. . 0 to 1 / or vice versa. 7. Allow these new strings, together with their parents to form the new population, which whic h will still contain only eight members. 8. Return to Step 2, and repeat until fifty generations have have elapsed.
To further fur ther clarify the crossover operator, operator, imagine two strings, 000100011100 and a nd 111001101010, Performing Performing crossover between the third and fourth characters c haracters produces two new strings: parents
children
000 10 1000 0011 1110 100 0 111/001101010
00000 000 0011 1101 0101 010 0 111100011100
It is this roce rocess ss of cross crossove overr which is res onsible for much of the ow ower er of genetic algorithms.
Returning to the example, example, let the initial population be:
string
X
fitness
1 2 3
110101100100 010100010111 101111101110
3428 1303 3054
11751184 1697809 9326916
5 6 7
011101011101 101101001001 101011011010
1885 2889 2778
3553225 8346321 7717284
population member
Population members 1, 3, 6 and 7 have the highest fitness. Deleting those four with the leas le astt fi fitn tnes esss pr prov ovid ide es a te tem mpo porrar ary y re redu duce ced d po popu pula lati tion on re read ady y to un unde derg rgo o cr cros osso sovver:
temp. pop member
String
x
fitness
1 2
110101100100 101111101110
3428 3054
11751184 9326916
4
10101101 10101 1011010 1010
2778
7717284
Temp. population
String
x
fitness
1 2 3 4
110101100100 101111101110 101101011010 111111101110
3428 3054 2906 4078
11751184 9326916 8444836 16630084
This te This temp mpor orar ary y po popu pulat latio ion n do does es no nott co cont ntai ain n a 1 as th the e la last st di digi gitt in an any y of th the e strin str ings( gs(wh wherea ereass th the e in initi itial al pop popul ulati ation on di did) d).. Th This is im impl plies ies th that at no st stri ring ng fr from om thi thiss moment on can contain such a digit and the maximum value that can evolve will be —a er w c po n s s r ng w repro uce so as o om na e e population. This domination of the population by a single sub- optimal string gives a firstt ind firs indicati ication on of wh why y mut mutation ation might be impo important. rtant. An Any y further populations populations will only contain the same, identical string. This is because the crossover operator can only swap bits between strings, not introduce any new information. Mutation can thus be seen in part par t as an operator charged with maintaining maintaining the genetic diversity diversity of the population by preserving the diversit diversity y embodied in the initial generation.
The inclusion of mutation allows the population to leapfrog over this sticking point. It is worth reiterating that the initial population did include a 1 in all positions. Thus the mutation operator is not necessarily inventing new information but simply working as an
.
Reru erunn nning ing th the e al algo gori rith thm m fro from m th the e sa same me in init itia iall po popul pulati ation on,, bu butt wi with th mut mutati ation on,, allows the string 111111111111 to evolve and the global optimum to be found. Mutation has been included by visiting every bit in each new child string, throwing a random number between 0 and 1 and if this number is less than 1/12, flipping the value of the bit.
Summary of GA start
m u at e
nnea ng
Don’t Don’t be too ambitious with this course load. You CANNOT do optimization without a properly posed math problem.
T an You