Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Introduction to optimization4GC10 Third year design project
L.F.P. Etman
Department of Mechanical EngineeringEindhoven University of Technology
1 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Outline
1 Problem formulation
2 Visualization & Terminology
3 Problem formulation: classes and properties
4 Optimization algorithms
5 Practicalities
2 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Design optimization
Design optimization is the selection of the best designwithin the available means
[Papalambros & Wilde 2000: Principles of optimal design]
3 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Design optimization
1 Parametrize your design in terms of design variables, that is,define which design parameters you wish to optimize
2 Define objective function in terms of design variables(to minimize or maximize)
3 Define constraint functions in terms of design variables,which must be satisfied
4 Determine design variable values which minimize (maximize)the objective while satisfying all constraints
[Papalambros & Wilde 2000: Principles of optimal design]
4 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Mathematical problem formulationMinimize
xf (x) x = (column) vector of design variables
subject to hj (x) = 0 j = 1; : : : ;mh
gk (x) ≤ ck k = 1; : : : ;mg
x ∈ X ⊆ Rn
In words:
• Find the values for the design variables x such that the objectivecriterion f (x) is minimized while satisfying equality constraintshj (x) = 0; j = 1; : : : ;mh and inequality constraintsgk (x) ≤ ck ; k = 1; : : : ;mg .
Negative null form:
• Reformulate gk (x) ≤ ck into gk (x) ≤ 0
Maximization:
• Minimizex
− f (x)
[Papalambros & Wilde 2000: Principles of optimal design]
5 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Two-bar truss example
F
SS
h
d
Minimizex
f (x)
subject to g(x) ≤ 0x ∈ R+n
Constant parameter:
• width S
Design variables:
• height h
• diameter bars d
Objective criterion:
• mass
Inequality constraints:
• maximum height
• limit on stresses in bars
• limit on buckling forces in bars
6 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Two-bar truss example
minx
f (x) =��
2�2 x22
qS 2 + x2
1
s.t. g1(x) =1
Hmaxx1 − 1 ≤ 0
g2(x) =2F�2
��y
pS 2 + x2
1
x22 x1
− 1 ≤ 0
g3(x) =32F�4
�3E
�S 2 + x2
1
�3=2
x42 x1
− 1 ≤ 0
� : x1; x2 > 0;
• x1 = h is height, x2 = �d is scaled diameter (such that both designvariables operate in same order of magnitude).
• Height constraint g1, stress constraint g2 and bucking constraintg3, are analytically expressed in terms of design variables.
• Constraints are scaled (divided by the bound value).
• � is material density, E is modulus of elasticity, �y is yield strength.
7 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a one-variable optimization problem
ii
“plot1Db˙temp” — 2006/6/26 — 16:21 — page 1 — #1 ii
ii
ii
x
f
f(x)
x
g
g3(x)
0
g6(x)
• Suppose, we have an optimizationproblem in one variable x:
• objective function f (x) is(quadratically) increasing in x,
• one constraint function g6(x) is(linearly) increasing in x,
• another constraint function g3(x)is (linearly) decreasing in x.
8 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a one-variable optimization problem
ii
“plot1De˙temp” — 2006/6/26 — 16:21 — page 1 — #1 ii
ii
ii
x
f
f(x)
x
g
g3(x)
0
g6(x)
g3 = 0
g6 = 0
• There is a certain value of x abovewhich g6(x) > 0 (bottom picture)
• Similarly, there is a value of xbelow which g3(x) > 0.
• Feasible values of x satisfy bothg3(x) ≤ 0 and g6(x) ≤ 0 (greenarea).
• Constraint g3 imposes a lowerbound on x,
• Constraint g6 imposes an upperbound on x.
• The optimum is attained for the xvalue that yields the lowestobjective function value whilesatisfying all constraints (redcircle)
9 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Constrained versus unconstrained optimumi
i“opt˙bnd˙temp” — 2006/6/15 — 21:36 — page 1 — #1 i
i
ii
ii
x
f f(x)
g = 0
• constrained optimum
• bounded optimum
ii
“opt˙unc˙temp” — 2006/6/15 — 21:35 — page 1 — #1 ii
ii
ii
x
ff(x)
g2 = 0g1 = 0
• unconstrained optimum
• interior optimum
10 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Multimodality (multiple local minima)
ii
“multi˙temp” — 2006/6/15 — 17:12 — page 1 — #1 ii
ii
ii
x
f
f(x)
global
local
x
ff(x)
globallocal
• An optimization problem (unconstrained or constrained) may havemultiple minima.
• The minimizer which has the lowest objective function value (whilebeing feasible) is referred as the global minimizer.
• The other minimizers are referred to as local.
11 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a two-variable optimization problem
ii
“plot2Da˙temp” — 2006/6/15 — 21:15 — page 1 — #1 ii
ii
ii
x1
x2
objective function
6 78
9 10
f
x1
x2
constraint g1
g1= 0
g1< 0
feasible
• Consider an optimization problem in two design variables x1 and x2.
• The objective function is a 3-D surface, which may be visualizedusing contour lines of equal objective function value.
• Similarly, each constraint function is also represented by a surface.
• The contour line for which the contraint bound is reached(g(x) = 0) represents the boundary between the feasible(g(x) ≤ 0) and infeasible domain (g(x) > 0).
12 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a two-variable optimization problem
ii
“plot2Db˙temp” — 2006/6/15 — 21:29 — page 1 — #1 ii
ii
ii
x1
x2
g1
• The contour lines of the objective function and the contour linesrepresenting the contraint boundaries are usually plotted in asingle picture.
13 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a two-variable optimization problem
ii
“plot2Dc˙temp” — 2006/6/15 — 21:16 — page 1 — #1 ii
ii
ii
x1
x2
g1
g4
g5
g2 g4 g6
• If there is more than one constraint, for each constraint theconstraint boundary line is included in the picture.
14 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a two-variable optimization problem
ii
“plot2Dd˙temp” — 2006/6/15 — 21:29 — page 1 — #1 ii
ii
ii
x1
x2
g1
g4
g5
g2 g4 g6
feasible
domain
F
• The feasible domain represents the design area where allconstraints are satisfied.
15 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Visualization of a two-variable optimization problem
ii
“plot2De˙temp” — 2006/6/15 — 21:26 — page 1 — #1 ii
ii
ii
x1
x2
g1
g4
g5
g2 g4 g6
optimum
F
• The optimum is located at the (x1; x2) location in the feasibledomain where the objective function attains the lowest value.
16 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Constraint activity
A constraint gj (x) ≤ 0 is active at the optimum implies that
1 if gj (x) ≤ 0 is left out, the location of the optimum changes
2 the constraint is satisfied with strict equality: gj (x) = 0
17 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Formulation classes: linear programming
Linear programming (LP) problem:
• Objective function linear in design variables
• Constraint functions linear in design variables
• Continuous design variables
Example:
minx∈R2
f (x) = −2x1 − x2
s.t. g1(x) = x1 + 2x2 − 8 ≤ 0g2(x) = 2x1 − 2x2 − 3 ≤ 0g3(x) = −2x1 + 1 ≤ 0g4(x) = −2x2 + 1 ≤ 0
ii
“LP˙temp” — 2006/6/23 — 11:29 — page 1 — #1 ii
ii
ii
x1
x2
F
g3
g4
g1
g2
f
If (some) design variables can only take discrete values:
• (Mixed-)integer linear programming problem: (M)ILP
18 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Formulation classes: quadratic programming
Quadratic programming (QP) problem:
• Quadratic objective function
• Linear constraint functions
• Continuous design variables
Example:
minx∈R2
f (x) = 3x21 − 2x1 + 5x2
2 + 30x2
s.t. g1(x) = −2x1 − 3x2 + 8 ≤ 0g2(x) = 3x1 + 2x2 − 15 ≤ 0g3(x) = x2 − 5 ≤ 0
ii
“QP˙temp” — 2006/6/23 — 11:51 — page 1 — #1 ii
ii
ii
x1
x2
g3
g1
f
F g2
(Some) design variables discrete:
• (Mixed-)integer quadratic programming problem: (M)IQP
19 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Formulation classes: nonlinear programming
Nonlinear programming (NLP) problem:
• Non-linear objective function
• Non-linear constraint functions
• Continuous design variables
Example:
minx∈R2
f (x) = 3x1 +√
3x2
s.t. g1(x) = 18x1
+ 6√
3x2− 3 ≤ 0
g2(x) = 5:73− x1 ≤ 0g3(x) = 7:17− x2 ≤ 0
ii
“NLP˙temp” — 2006/6/25 — 10:15 — page 1 — #1 ii
ii
ii
x1
x2 F
g3
g1
g2
f
(Some) design variables discrete:
• (Mixed-)integer nonlinear programming problem: (M)INLP
20 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Formulation properties
Design variables:
• Domain: {0;1}; N ; N+; Z; R; R+
Objective and constraint functions:
• Linearity: linear or nonlinear
• Continuity: none/once/twice-differentiable
Optimization problem:
• Objective: single objective or multi-objective
• Constraints: unconstrained or constrained
• Modality: uni-modal or multi-modal
21 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Optimization in mechanical engineering
Design variables:
• sizing (dimensions)
• shape (geometry of boundary)
• topological (material distribution)
Objective criterion:
• profit (cost, efficiency, weight, ...)
Constraints:
• geometrical (width, length, height, ...)
• structural (stresses, displacements, ...)
• dynamical (accelerations, eigenfrequency, ...)
• physical (temperatures, pressures, ...)
22 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Analytical versus numerical solution
Some optimization problems can be analytically solved:
Minx
f (x) = 2x1 + x−21 + 2x2 + x−2
2
Many optimization problems can only be numerically solved:
Minx
f (x) = x1 + x2 + x1e−x2 + x22 e−x1
An optimization algorithm is an iterative procedure to solve anunconstrained or constrained minimization (maximization)problem.
Choose an optimization algorithm in accordance with theoptimization problem class and properties
[Papalambros & Wilde 2000: Principles of optimal design]
23 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Classification of optimization algorithms
Four classifiers of an optimization algorithm:
• unconstrained / constrained search
• local / global search
• determistic / stochastic search
• 0th / 1th / 2nd -order search
24 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Unconstrained / constrained search
Unconstrained search:
• aims to minimize a nonlinear, possibly multi-modal, objectivefunction in n-dimensional space
Constrained search:
• aims to minimize a (non)linear objective function inn-dimensional space while accounting for (non)linear equalityand/or inequality constraint functions
25 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Local / global search
Local search:
• seeks improvement based on the Taylor series expansion;
in a sufficiently small region around x∗ = [x1; x2; : : : ; xn ]∗ a
nonlinear function can be approximated by a quadratic Taylorseries:
~f (x) = f (x∗)+nX
i=1
@f (x∗)@xi
(xi−x∗i )+
12
nXi=1
nXj=1
@2f (x∗)@xi@xj
(xi−x∗i )(xj−x∗
j )
Global search:
• seeks improvement by design space exploration (sampling ofthe full design space)
26 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Deterministic / stochastic search
Deterministic search:
• gives exactly the same search path when running thealgorithm twice for unchanged algorithmic settings
Stochastic search:
• generates random search paths for every run of the algorithm
27 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
0th / 1th / 2nd -order search
A 0th-order algorithm
• uses only function evaluations of the objective function (andconstraints).
A 1th-order algorithm
• uses function evaluations and gradient evaluations of theobjective function (and constraints),
• the gradient refers to the first-order derivatives with respectto the design variables
A 2nd-order algorithm
• uses function, gradient, and Hessian evaluations of theobjective function (and constraints)
• the Hessian refers to the second-order derivatives withrespect to the design variables
28 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Newton type of algorithms
Characteristics
• unconstrained/constrained
• local
• deterministic
• 2nd-order
Matlab Optimization toolbox
• fminunc
• fmincon
ii
“line2˙temp” — 2006/6/26 — 14:30 — page 1 — #1 ii
ii
ii
x1
x2
x0
x1
x2
x3
s0
s1
s2
s3
Line search
ii
“trust2˙temp” — 2006/6/26 — 20:51 — page 1 — #1 ii
ii
ii
x1
x2
x0
x1 x2
x30
1
2
3
s0 s1 s2
Trust-region
29 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Bio-inspired algorithms
Characteristics
• unconstrained/constrained
• global
• stochastic
• 0th-order
Matlab GA toolbox
• ga
Algorithms
• Particle swarms
• Genetic algorithms (GAs)
• Simulated Annealing
ii
“2Dparticleswarm˙temp” — 2008/9/1 — 14:23 — page 1 — #1 ii
ii
ii
1
2
30 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Direct search algorithms
Characteristics
• unconstrained/constrained
• local
• deterministic
• 0th-order
Matlab Optimization toolbox
• fminsearch
Matlab Direct Search toolbox
• patternsearch
Algorithms
• Nelder-Mead simplex search
• Generalized Pattern Search
ii
“2Dsimplex˙temp” — 2008/9/1 — 14:23 — page 1 — #1 ii
ii
ii
1
2
31 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Gradient
∇f =h@f@x1
; @f@x2
; : : : ; @f@xn
i
Calculating gradients:
• Analytically (by hand)
• Symbolically (e.g. Mathematica)
• Finite differencing (numerical)
• Built-in in the CAE analysis code (e.g. MARC)
Matlab:
• fmincon and fminunc calculate gradients by finitedifferencing if the user does not provide them
• Matlab Symbolic Toolbox
32 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Hessian
H =
2666664
@2f@x2
1
@2f@x1@x2
· · · @2f@x1@xn
@2f@x2@x1
@2f@x2
2· · · @2f
@x2@xn
.... . .
...@2f
@xn@x1
@2f@xn@x2
· · · @2f@x2
n
3777775
Calculating the Hessian:
• usually does not need to be provided by the user, but isestimated by the optimization algorithm itself (from theiteration history)
33 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Conditions for optimality
Karush-Kuhn-Tucker (KKT) conditions
ii
“unc˙infwell2D˙temp” — 2007/4/4 — 15:12 — page 1 — #1 ii
ii
ii
10
9
8
f
x1
x2
P1
P2
ii
“ineq˙opt˙temp” — 2006/6/20 — 10:00 — page 1 — #1 ii
ii
ii
x1
x2
x1
x2
g
g1
g2
g3
f
g22
3 = 0
g11
f
g
F
F
Unconstrained: gradients objective function zero
Constrained: linear combination of gradients objective andgradients active constraints zero (i.e. gradients Lagrange functionL zero)
34 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Termination criteria
Condition on optimality
‖∇L(xk+1)‖ < " (Matlab: TolFun)
gj (xk+1) < " and |hj (xk+1)| < " (Matlab: TolCon)
or a condition on change in x
‖xk+1 − xk‖ < " (Matlab: TolX)
or a condition on the number of iterations
k ≤ kmax (Matlab: MaxIter)
or a combination of these, with " > 0
35 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Nested analysis
• In various engineering optimization problems evaluation of(inequality) constraints (e.g. regarding stresses,displacements, buckling forces, etcetera) requires a call to anexternal computational routine (fem software).
• That is, for every evaluation of the objective function andconstraints, a call is made to the external analysis routine.
• The analysis routine receives the design variable values forwhich the computational analysis has to be carried out, andreturns the desired responses.
• This is referred to as nested analysis• The nested analysis has to be implemented in the objective
function and/or constraint function files.• In your design project, you will be using Matlab for the
structural analysis as well as for the optimization. This meansthe fem analysis becomes a function call within the objectivefunction and/or constraint function m-files.
36 / 37tue
Problem formulation Visualization & Terminology Formulation classes Optimization algorithms Practicalities
Scaling
Scale design variables, objective function and constraintfunctions to avoid numerical difficulties and prematuretermination
37 / 37tue