Dr Jasmina Lazić - MathWorks
Transcript of Dr Jasmina Lazić - MathWorks
1© 2014 The MathWorks, Inc.
Best Practices for Optimisation
Dr Jasmina Lazić
Application Engineer, MathWorks Inc.
2
Agenda
What’s new?
Choose your solver
How to set up optimisation problems
Cutting-edge solvers in action: demonstrating the new
algorithms
Accelerate your optimisation by:
– Using parallel computing
– Tuning solver options
3
Demo: Global Optimization
4
What’s New?
Particle Swarm Optimization (particleswarm) R2014b
Dual-simplex algorithm in linear programming solver (linprog) R2014b
Interior-point algorithm in linear least-squares solver (lsqlin) R2014b
Mixed Integer Linear Programming solver (intlinprog) R2014a
– Plot functions and output functions for monitoring progress of intlinprog solver R2014b
5
Optimization Problems
• Managing Portfolios
• Supply Chain
• Engine Calibration
• Power Generation
6
Anatomy of an Optimization Problem
General Form for MATLAB Solvers
Objective Function
uxl
eqbxeqA
bAx
)(min xfx
Typically a linear or nonlinear function
Linear constraints
• inequalities
• equalities
• bounds
Nonlinear constraints
• inequalities
• equalities
Decision variables
0)(
0)(
xeq
c
xc
Subject to Constraints
7
OptimizationFind optimal solutions, analyze tradeoffs
• General (nonlinear)
• Linear
• Quadratic
• Least-squares
• Multiobjective
min𝑥
fcn(𝑥)
min𝑥
𝑓′𝑥
min𝑥
1
2𝑥′𝐻𝑥 + 𝑐′𝑥
min𝑥
𝐹(𝑥) 22
min𝑥
[𝐹1 𝑥 , 𝐹2 𝑥 ,… ]
Objective Types
• Unconstrained
• General (nonlinear)
• Bound
• Linear
• Discrete (integer)
Constraint Types
𝐿𝐵 ≤ 𝑥 ≤ 𝑈𝐵
𝐴𝑥 ≤ 𝑏, 𝐴𝑒𝑞𝑥 = 𝑏𝑒𝑞
𝑐(𝑥) ≤ 0, 𝑐𝑒𝑞 (𝑥) ≤ 0
𝑥𝑖 ∈ ℤ
Global Algorithms
• Multistart
• Direct Search
• Particle Swarm
• Genetic Algorithm
• Interior Point
• Trust Region
• Simplex
• Levenberg Marquardt
• Sequential Quadratic Programming
Gradient-based Algorithms
8
Item Nuts Bolts
Gadget 5 2 3.00$
Widget 3 8 10.00$
Requirements Revenue
per Item
How to Set Up an Optimisation Problem: Modelling Example
Overview
Challenge
– Current inventory 28 nuts / 30 bolts
– How many gadgets / widgets to make to maximize revenue?
9
How to Set Up an Optimisation Problem
Variables:
𝑥 = number of gadgets
𝑦 = number of widgets
Objective - maximise revenue:
max𝑥,𝑦
3𝑥 + 10𝑦
Subject to constraints:
5𝑥 + 3𝑦 ≤ 28 (nuts total)
2𝑥 + 8𝑦 ≤ 30 (bolts total)
10
Demo: Barge Container Ship Routing
11
Shipping Company Objective
Profit RevenueTransport
Costs
Empty container handling
Fuel Costs
Other Costs…Service of
loaded containers
12
Ship Routing: Problem Characteristics
Decision Variables Given Constants
𝑛: number of ports
𝑙: distance between ending ports
𝑣1, 𝑣2: upstream/downstream speed
𝑠𝑐𝑓, 𝑠𝑐𝑙: fuel/lubricant consumption
𝐶: ship carrying capacity
𝑑𝑐𝑐: daily time charter cost
𝑝𝑒𝑐𝑖: entry cost at port 𝑖
𝑡𝑚𝑖𝑛, 𝑡𝑚𝑎𝑥: min/max turnaround time
𝑧𝑟𝑖𝑗: expected number of loaded
containers between ports 𝑖 and 𝑗
𝑟𝑖𝑗: freight rate per container from port 𝑖
to port 𝑗
𝑢𝑓𝑡𝑖 , 𝑙𝑓𝑡𝑖: avg. loading/unloading time
per container at port 𝑖
…
𝑥𝑖𝑗 = 1, if ports 𝑖 and 𝑗 are directly
connected in the route0, otherwise
𝑤𝑖𝑗 = the number of empty containers
transported from port 𝑖 to port 𝑗
𝑧𝑖𝑗 = the number of loaded containers
transported from port 𝑖 to port 𝑗
13
Ship Routing: Key Constraints
The ship must visit the ending
ports
Can transport from 𝑖 to 𝑗 only if
both ports are on the route
Cannot transport more than
the expected number of
containers
Total number of containers on-
board cannot exceed ship
carrying capacity
…
14
Problem Characteristics and Solution Times
#Ports
𝒏#Variables
𝟑𝒏𝟐 + 𝟓𝒏 + 𝟗#Constraints
𝟑𝒏𝟐 + 𝟗𝒏 + 𝟖
10 359 398
15 759 722
20 1309 1388
Minimum
solution time
Maximum
solution time
1 sec 6 sec
3 min 23 min
> 5 h > 5 h
15
How Can Parallel Computing Speed
Optimisation Up?
Computing the gradient numerically requires the objective
function and non-linear constraints to be evaluated at
N + 1 points each iteration (N = number of dimensions)
Compute function evaluations in parallel by setting
‘UseParallel’ option to be ‘always’
2-Dimensional Problem (peaks)
x
xfxxfxf
)()()( forward
difference
16
Demo: Running an Optimization Algorithm
in Parallel
17
Summary
Optimisation workflow in MATLAB:
Optimise, post-process and visualise results on the same platform
What is new in R2014a and R2014b:
– Mixed Integer Linear Programming
– Particle Swarm
Boost the solver
performance
Choose the right solver
Set your problem up
NEW !!
18
For more information…
Documentation:
Optimization Toolbox
Webinar: Getting Started
Using Optimization with
MATLAB
Video: Mathematical
Modeling with
Optimization, Part 1
Video: Mathematical
Modeling with
Optimization, Part 2
MATLAB Digest: Using Symbolic
Gradients for Optimization
MATLAB Digest: Improving
Optimization Performance with
Parallel Computing