2. Overview
The slides are meant for those who are interested to
learn linear programming application but have no
time for proper graduate study
The emphasis is on practical model building and
solving the models using solvers
The slides are free preview of 3-day “Decision
Optimization” training offered by the author
The author has 27 years semiconductor manufacturing
experience, of which 18 years are in Industrial
Engineering and Operations Research
A Primer on Optimization Using Solvers - Anwar Ali 2
3. Agenda
Introduction to Analytics and Operations Research
Optimization Modeling with Textbook Examples
Formulating and Solving Mathematical Models
Optimization Applications in Industry
How to Get Started
A Primer on Optimization Using Solvers - Anwar Ali 3
4. Analytics Landscape
Descriptive
Prescriptive
Predictive
Degree of Complexity
CompetitiveAdvantage
Standard Reporting
Ad hoc reporting
Query/drill down
Alerts
Simulation
Forecasting
Predictive modeling
Optimization
What exactly is the problem?
What will happen next if ?
What if these trends continue?
What could happen…. ?
What actions are needed?
How many, how often, where?
What happened?
Stochastic Optimization
How can we achieve the best outcome?
How can we achieve the best outcome
including the effects of variability?
Source: IBM, Based on: Competing on Analytics,
Davenport and Harris, 2007
A Primer on Optimization Using Solvers - Anwar Ali 4
5. Analytics
Descriptive analytics (what has occurred)
The simplest class of analytics, condense big data into
smaller, more useful nuggets of information
e.g. counts, likes, posts, views, sales, finance
Predictive analytics (what will occur)
Use available data to predict data we don’t have using
variety of statistical, modeling, data mining, and
machine learning techniques
Prescriptive analytics (what should occur)
Recommend one or more courses of action and showing
the likely outcome of each decision so that the business
decision-maker can take this information and act
Adapted from Information Week, definitions by Dr Michael Wu
http://www.informationweek.com/big-data/big-data-analytics/big-data-analytics-descriptive-vs-predictive-vs-prescriptive/d/d-id/1113279
A Primer on Optimization Using Solvers - Anwar Ali 5
6. Business Intelligence Framework
Back in Business, by Ronald K. Klimberg and Virginia Miori, OR/MS Today, Vol 37, No 5, October 2010,
[http://www.informs.org/ORMS-Today/Public-Articles/October-Volume-37-Number-5/Back-in-Business]
OR/MS =
Operations Research/
Management Science
A Primer on Optimization Using Solvers - Anwar Ali 6
7. What is Operations Research?
O.R. is the discipline of applying advanced analytical
methods to help make better decisions
Also called Management Science or Decision Science,
O.R. is the science of Decision-Making
Employing techniques from mathematical sciences,
O.R. arrives at optimal or near-optimal solutions to
complex decision-making problems
Determine the maximum (e.g. profit, performance, or
yield) or minimum (e.g. loss, risk, or cost)
A Primer on Optimization Using Solvers - Anwar Ali 7
8. Analytics Landscape
Descriptive
Prescriptive
Predictive
Degree of Complexity
CompetitiveAdvantage
Standard Reporting
Ad hoc reporting
Query/drill down
Alerts
Simulation
Forecasting
Predictive modeling
Optimization
What exactly is the problem?
What will happen next if ?
What if these trends continue?
What could happen…. ?
What actions are needed?
How many, how often, where?
What happened?
Stochastic Optimization
How can we achieve the best outcome?
How can we achieve the best outcome
including the effects of variability?
Adapted from: IBM, Based on: Competing on Analytics,
Davenport and Harris, 2007
Operations Research
A Primer on Optimization Using Solvers - Anwar Ali 8
9. O.R. Leading Edge Techniques
Simulation
Giving you the ability to try out approaches and test
ideas for improvement
Optimization
Narrowing your choices to the very best where there are
virtually innumerable feasible options and comparing
them is difficult
Probability and statistics
Helping you measure risk, mine data to find valuable
connections and insights, test conclusions, and make
reliable forecasts
A Primer on Optimization Using Solvers - Anwar Ali 9
10. O.R. Leading Edge Techniques
Simulation (predictive)
Giving you the ability to try out approaches and test
ideas for improvement
Optimization (prescriptive)
Narrowing your choices to the very best where there are
virtually innumerable feasible options and comparing
them is difficult
Probability and statistics (predictive)
Helping you measure risk, mine data to find valuable
connections and insights, test conclusions, and make
reliable forecasts
A Primer on Optimization Using Solvers - Anwar Ali 10
11. O.R. Leading Edge Techniques
Simulation
Giving you the ability to try out approaches and test
ideas for improvement
Optimization – THIS TRAINING
Narrowing your choices to the very best where there
are virtually innumerable feasible options and
comparing them is difficult
Probability and statistics
Helping you measure risk, mine data to find valuable
connections and insights, test conclusions, and make
reliable forecasts
A Primer on Optimization Using Solvers - Anwar Ali 11
12. Examples of O.R. Application
Deciding where to invest capital in order to grow
Figuring out the best way to run a call center
Locating a warehouse or depot to deliver materials
over shorter distances at reduced cost
Solving complex scheduling problems
Deciding when to discount, and how much
Getting more out of manufacturing equipment
Optimizing a portfolio of investments
A Primer on Optimization Using Solvers - Anwar Ali 12
13. Terminology Evolved
Previous Current
Operations Research
Statistics
Decision Support
Data sets (structured)
Data Analyst
Business Analytics
Data Science
Business Intelligence / Analytics
Big Data (unstructured)
Data Scientist
A Primer on Optimization Using Solvers - Anwar Ali 13
14. What are the Benefits of O.R.?
Operations Research is called “The Science of Better”,
i.e. using science to make:
bold decisions and run everyday operations with less
risk and better outcomes (no more gut-feel)
repeatable, quantitative decision analysis
Adapted from: The Guide to Operational Research, http://www.scienceofbetter.co.uk/
A Primer on Optimization Using Solvers - Anwar Ali 14
15. Signs O.R. Could Be Beneficial
The management face complex decision making
The management is not sure what the main problem is
The management is uncertain about potential
outcomes
The organization is having problems with decision
making processes
Management is troubled by risk
The organization is not making the most of its data
The organization needs to beat stiff competition
The Guide to Operational Research, http://www.scienceofbetter.co.uk/
A Primer on Optimization Using Solvers - Anwar Ali 15
16. Agenda
Introduction to Analytics and Operations Research √
Optimization Modeling with Textbook Examples
Formulating and Solving Mathematical Models
Optimization Applications in Industry
How to Get Started
A Primer on Optimization Using Solvers - Anwar Ali 16
17. Optimization Modeling
Optimization models have
Objective function
Decision variables
Constraints
Formulated as mathematical equations
Solved graphically (for problems with 2 decision
variables) or using ‘Solver’ (will be explained later)
We will start with simple Linear Programming (LP)
model examples from textbooks
A Primer on Optimization Using Solvers - Anwar Ali 17
18. Example 1: Dorian Auto
Operations Research:
Applications and Algorithms
Wayne L. Winston
Duxbury Press; 4th edition
(2003)
A Primer on Optimization Using Solvers - Anwar Ali 18
19. Example 1: Dorian Auto
Dorian Auto manufactures luxury cars and trucks
The company believes that its most likely customers
are high-income women and men
To reach these groups, Dorian Auto has embarked on
an ambitious TV advertising campaign and will
purchase 1-minute commercial spots on two type of
programs: comedy shows and football games
A Primer on Optimization Using Solvers - Anwar Ali 19
20. Example 1: Dorian Auto
Each comedy commercial is seen by 7 million high
income women and 2 million high-income men and
costs $50,000
Each football game is seen by 2 million high-income
women and 12 million high-income men and costs
$100,000
Dorian Auto would like for commercials to be seen by
at least 28 million high-income women and 24 million
high-income men
We will use LP to determine how Dorian Auto can
meet its advertising requirements at minimum cost
A Primer on Optimization Using Solvers - Anwar Ali 20
21. Example 1: Solution
Decision variables:
x = the number of 1-minute comedy ads
y = the number of 1-minute football ads
The objective is to minimize advertising cost
Minimize z = 50x + 100y
Constraints:
Ads must be seen by at least 28 million high-income
women; 7x + 2y ≥ 28
Ads must be seen by at least 24 million high-income
men; 2x + 12y ≥ 24
Sign restrictions; x ≥ 0 and y ≥ 0
A Primer on Optimization Using Solvers - Anwar Ali 21
22. Graphical Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
A Primer on Optimization Using Solvers - Anwar Ali 22
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
23. Graphical Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint; 7x + 2y ≥ 28
A Primer on Optimization Using Solvers - Anwar Ali 23
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
24. Graphical Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint; 7x + 2y ≥ 28
High-income men constraint; 2x + 12y ≥ 24
A Primer on Optimization Using Solvers - Anwar Ali 24
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
25. Unbounded
feasible region
Graphical Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint
High-income men constraint
A Primer on Optimization Using Solvers - Anwar Ali 25
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
26. Unbounded
feasible region
Graphical Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint
High-income men constraint
A Primer on Optimization Using Solvers - Anwar Ali 26
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
27. Unbounded
feasible region
Graphical Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint
High-income men constraint
x = 3.6
y = 1.4
A Primer on Optimization Using Solvers - Anwar Ali 27
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
28. Optimal Answer
To minimize advertising cost, purchase
3.6 slots of comedy ads (x)
1.4 slots of football ads (y)
The total advertising cost (in thousands) is
z = 50x + 100 y
z = 50(3.6) + 100(1.4)
z = 320
But in reality, it is not possible to purchase fractional
number of 1-minute ads. The decision variables x and
y must be integers
A Primer on Optimization Using Solvers - Anwar Ali 28
29. Integer Programming
When an LP model has integer decision variable(s), it
is called integer linear programming (ILP). Why ILP?
We cannot buy 3.6 slots of ads, must be either 3 or 4
Yes/no decisions can be modeled as 0 or 1 variables
When an LP model has mixture of continuous and
integer variables, it is called mixed integer linear
programming (MILP)
ILP and MILP models are harder and take longer to
solve compared to LP models
We will use the term “math programming” to refer to
LP, ILP, and MILP
A Primer on Optimization Using Solvers - Anwar Ali 29
30. Unbounded
feasible region
Graphical Integer Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint
High-income men constraint Feasible integer solutions
A Primer on Optimization Using Solvers - Anwar Ali 30
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
x, y integers
31. Unbounded
feasible region
Graphical Integer Solution
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
High-income women constraint
High-income men constraint
Lowest z value
in feasible region
Optimal integer solutions
Feasible integer solutions
A Primer on Optimization Using Solvers - Anwar Ali 31
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
x, y integers
32. Unbounded
feasible region
Graphical Integer Solutions
x (comedy ads)
y (football ads)
4 8 12 16
4
12
16
8
2
6
10
14
2 6 10 14
x = 6, y = 1
x = 4, y = 2
2 solutions with
z = 400
A Primer on Optimization Using Solvers - Anwar Ali 32
Min z = 50x + 100y
subject to:
7x + 2y ≥ 28
2x + 12y ≥ 24
x, y ≥ 0
x, y integers
33. Graphical Integer Solutions
There are 2 solutions with z = 400
4 slots of comedy ads (x) and 2 slots of football ads (y); z
= 50(4) + 100(2) = 400
6 slots of comedy ads (x) and 1 slot of football ads (y); z
= 50(6) + 100(1) = 400
For more complex problems which cannot be solve
graphically, branch-and-bound method is used
A Primer on Optimization Using Solvers - Anwar Ali 33
34. Example 2: Diet Problem
Introduction to
Management Science
Bernard W. Taylor III
Prentice Hall, 7th edition
(2002); the diet problem is
from this edition
Latest is 11th edition (2012)
A Primer on Optimization Using Solvers - Anwar Ali 34
35. Example 2: Diet Problem
Breakfast to include at least 420 calories, 5 milligrams of
iron, 400 milligrams of calcium, 20 grams of protein, 12
grams of fiber, and must have no more than 20 grams of
fat and 30 milligrams of cholesterol
A Primer on Optimization Using Solvers - Anwar Ali 35
36. Example 2: Diet Problem
The objective is to minimize meal cost while meeting
the following nutritional requirement:
Calories ≥ 420
Iron ≥ 5
Calcium ≥ 400
Protein ≥ 20
Fiber ≥ 12
Fat ≤ 20
Cholesterol ≤ 30
A Primer on Optimization Using Solvers - Anwar Ali 36
37. Example 2: Decision Variables
x1 = cups of bran cereal
x2 = cups of dry cereal
x3 = cups of oatmeal
x4 = cups of oat bran
x5 = eggs
x6 = slices of bacon
x7 = oranges
x8 = cups of milk
x9 = cups of orange juice
x10 = slices of wheat toast
A Primer on Optimization Using Solvers - Anwar Ali 37
39. Example 2: Solution
The diet problem cannot be solved graphically as it has
10 decision variables
We will use ‘Solver’ to find solution for the problem
A Primer on Optimization Using Solvers - Anwar Ali 39
40. Solver
Mathematical software, either stand-alone or library,
that 'solves' a mathematical programming problem
Uses algorithms such as SIMPLEX and branch-and-
bound to solve the problem
May include Integrated Development Environment
(IDE), e.g. GUI and editor
Solvers used in this training:
Excel Solver, free Excel ad-in with limited capability
IBM ILOG CPLEX and LPSolve have complete IDE
LPSolve is free (GNU lesser general public license) and
can be downloaded from sourceforge.net
A Primer on Optimization Using Solvers - Anwar Ali 40
41. Decision Modeling with Excel
Knowledge on the following is required: named range
and SUMPRODUCT() function
Named ranges can help make Excel spreadsheet
formulas more readable
SUMPRODUCT() can simplify lengthy formulas if the
worksheet is designed properly
We will explain how the Diet problem Excel Solver
model is developed using named ranges and
SUMPRODUCT() function
We also need to enable Excel Solver Add-in
41A Primer on Optimization Using Solvers - Anwar Ali
42. Enabling Excel Solver Add-in
Start Excel
From File, Options,
highlight Add-Ins
From Manage, select
Excel Add-ins drop down
menu and hit Go button
Note: Excel Solver interface
screenshots are from Excel 2010.
Other screenshots are from
Excel 2007 & Excel 2010
42A Primer on Optimization Using Solvers - Anwar Ali
43. Enabling Excel Solver Add-In
Check the box for Solver
Add-in, then hit OK
43A Primer on Optimization Using Solvers - Anwar Ali
44. Enter diet data into Excel
44A Primer on Optimization Using Solvers - Anwar Ali
45. Name B3:B12 as serving
A Primer on Optimization Using Solvers - Anwar Ali 45
These cells are the decision variables x1 to x10
46. Name D3:D12 as cost
46A Primer on Optimization Using Solvers - Anwar Ali
47. Name E3:E12 as calories
47A Primer on Optimization Using Solvers - Anwar Ali
48. Naming Ranges: Continue with
F3:F12 as fat
G3:G12 as cholesterol
H3:H12 as iron
I3:I12 as calcium
J3:J12 as protein
K3:K12 as fiber
A Primer on Optimization Using Solvers - Anwar Ali 48
49. Add SUMPRODUCT() to col E:K
49A Primer on Optimization Using Solvers - Anwar Ali
50. What is SUMPRODUCT()?
Given that serving is defined as B3:B12 and calories is defined as E3:E12,
SUMPRODUCT(serving,calories) equals to B3*E3 + B4*E4 + B5*E5 +
B6*E6 + B7*E7 + B8*E8 + B9*E9 + B10*E10 + B11*E11 + B12*E12
50A Primer on Optimization Using Solvers - Anwar Ali
51. Enter SUMPRODUCT() @ cells
E14 =SUMPRODUCT(serving,calories)
F14 =SUMPRODUCT(serving,fat)
G14 =SUMPRODUCT(serving,cholesterol)
H14 =SUMPRODUCT(serving,iron)
I14 =SUMPRODUCT(serving,calcium)
J14 =SUMPRODUCT(serving,protein)
K14 =SUMPRODUCT(serving,fiber)
51A Primer on Optimization Using Solvers - Anwar Ali
52. Adding Constraints
The ≥ and ≤ signs in row 15 are optional
To make the spreadsheet more readable
Add Nutritional Requirement values in row 16
52A Primer on Optimization Using Solvers - Anwar Ali
54. Objective Function
Name cell B18 as meal_cost
Enter =SUMPRODUCT(serving,cost) into cell B18
The objective function is to minimize cell B18,
meal_cost
Now, we need to enter the objective function and the
constraints into Excel Solver
54A Primer on Optimization Using Solvers - Anwar Ali
55. Excel Solver Interface
From Excel menu, select Data. Solver should be visible
on the right. Select Solver
55A Primer on Optimization Using Solvers - Anwar Ali
56. Excel Solver Interface
Objective (Min)
Enter meal_cost
Select Min radio button
By Changing Variable Cells
(Decision Variables)
Enter serving
Subject to the Constraints:
Add the constraints one at
a time
56A Primer on Optimization Using Solvers - Anwar Ali
58. Solving….
Hit Solve button and the
dialog box should
appear, with the answers
in cells serving
Hit OK
58A Primer on Optimization Using Solvers - Anwar Ali
60. Excel Solver
Excel Solver has
determined these are the
optimal answers
60A Primer on Optimization Using Solvers - Anwar Ali
61. Excel Solver
But the solution requires
fractional cups and/or
slices of food
How to make them as
round number?
We will show how to
make the answer for
wheat toast slice as a
round number
61A Primer on Optimization Using Solvers - Anwar Ali
62. Mixed-Integer Diet Problem
Add another constraint
with type integer
62A Primer on Optimization Using Solvers - Anwar Ali
72. Key Take Away
In university, we were taught how to model and then
solve the problem by hand
In practice, solvers like Excel Solver, ILOG CPLEX and
LPSolve can find the solution(s) very quickly
SIMPLEX used for linear programming
Brand-and-bound used for integer model
It is important to understand the modeling concepts
and able to formulate the problems correctly
But real-world models are a lot more complex than the
textbook examples
May have multiple conflicting objectives
Many (thousands) decision variables and constraints
A Primer on Optimization Using Solvers - Anwar Ali 72
74. Choice of Solver
The choice of solver depends on the problem size and
the ability to integrate with enterprise system
Excel Solver is recommended for rapid prototyping
and quick-wins
Demonstrate the concept to users and management
Can be used if the problem is small
When all data is local and no database interface is required
Commercial solver is required for large problems and
data integration with enterprise system
Scalable with powerful database interfaces
A Primer on Optimization Using Solvers - Anwar Ali 74
75. Agenda
Introduction to Analytics and Operations Research √
Optimization Modeling with Textbook Examples √
Formulating and Solving Mathematical Models
Optimization Applications in Industry
How to Get Started
A Primer on Optimization Using Solvers - Anwar Ali 75
76. Problem Formulation
Problem formulation is the most challenging part in
math programming
Once the problem has been formulated correctly,
putting the problem into solvers is easy
Need to use the correct approach in developing the
mathematical equations of a problem
The more experience we have in problem formulation,
the easier it becomes
A Primer on Optimization Using Solvers - Anwar Ali 76
77. The formulation of a
problem is often more
essential than its
solution, which may be
merely a matter of
mathematical or
experimental skill
Albert Einstein
A Primer on Optimization Using Solvers - Anwar Ali 77
Picture from Wikipedia
78. Recommended Modeling Approach
First, must understand the problem well
e.g. business rules, objective(s), constraints, input data
and output/decisions required
Talk to the experts how decisions are made without a
model
Relate the problem to the relevant model types
Look at examples of the relevant model types
Many Excel Solver examples are downloadable from
Frontline Systems
IBM ILOG CPLEX has examples of different complexity
Develop and refine the model until it represents the
problem faithfully
A Primer on Optimization Using Solvers - Anwar Ali 78
79. Additional Reference – Williams
Model Building in
Mathematical Programming
H. Paul Williams
John Wiley & Sons, Ltd.
5th edition (2013)
A Primer on Optimization Using Solvers - Anwar Ali 79
80.
81. Bin packing / knapsack problem
A Primer on Optimization Using Solvers - Anwar Ali 81
82. Cut into different sizes and shapes and minimize the waste
Cutting stock problem
A Primer on Optimization Using Solvers - Anwar Ali 82
83. Start from a city, visit each city only once, and return to the original city
after all cities visited. Minimize the travel distance / cost
Traveling salesman problem (TSP)
A Primer on Optimization Using Solvers - Anwar Ali 83
84. Assign gates to planes considering plane type, schedule, domestic/international, airlines
Assignment problemA Primer on Optimization Using Solvers - Anwar Ali 84
86. Minimize breakfast cost and include at least 420
calories, 5 milligrams of iron, 400 milligrams of
calcium, 20 grams of protein, 12 grams of fiber, and
must have no more than 20 grams of fat and 30
milligrams of cholesterol
Diet problem
A Primer on Optimization Using Solvers - Anwar Ali 86
87. Summary of Problems
Linear Programming
Blending problem
Diet problem
Integer Programming
Bin packing / knapsack problem
Cutting stock problem
Traveling salesman problem (TSP)
Assignment problem
We pick the interesting TSP problem and demonstrate
how it is formulated and solved
A Primer on Optimization Using Solvers - Anwar Ali 87
88. TSP Described
You are given a set of n cities
You are given the distances between the cities
You start and terminate your tour at your home city
You must visit each other city exactly once
Your mission is to determine the shortest tour
A Primer on Optimization Using Solvers - Anwar Ali 88
89. TSP LP Formulation
Set of cities 𝑁 = 1,2, … , 𝑛
Decision variables, 𝑥𝑖𝑗
𝑥𝑖𝑗 = 1 if we go from city i to city j
𝑥𝑖𝑗 = 0 otherwise, 𝑖 ≠ 𝑗
𝑑𝑖𝑗 = direct distance from between city i and city j
Example: 𝑛 = 4, 𝑥 =
0 1 0 0
0 0 1 0
0 0 0 1
1 0 0 0
represents the tour (1,2,3,4,1)
A Primer on Optimization Using Solvers - Anwar Ali 89
90. TSP Objective Function
𝑚𝑖𝑛 𝑧 =
𝑛
𝑖=1
𝑑𝑖𝑗 𝑥𝑖𝑗
𝑛
𝑗=1
𝑖≠𝑗
A Primer on Optimization Using Solvers - Anwar Ali 90
91. TSP Constraints
Each city must be “entered” exactly once and “exited” exactly once
𝑥𝑖𝑗
𝑛
𝑗=1
𝑗≠𝑖
= 1, ∀𝑖 ∈ 𝑁
𝑥𝑖𝑗
𝑛
𝑖=1
𝑖≠𝑗
= 1, ∀𝑗 ∈ 𝑁
Subject to:
A Primer on Optimization Using Solvers - Anwar Ali 91
92. But it may create sub-tours
Example solution, 𝑥 =
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0
represents two sub-tours (1,2,1) and (3,4,3)
This is not feasible for TSP
1
2
3
4
A Primer on Optimization Using Solvers - Anwar Ali 92
93. Sub-tour Elimination Constraint
The various methods of adding sub-tour elimination
constraints were summarized by Orman, A. J. and
Williams, H. Paul
http://eprints.lse.ac.uk/22747/
For implementation in Excel, we select the Sequential
Formulation by Miller, Tucker and Zemlin as it has the
least number of decision variables and constraints
A Primer on Optimization Using Solvers - Anwar Ali 93
94. Sub-tour Elimination Constraint
Add continuous variables,
𝑢𝑖= sequence in which city i is visited (𝑖 ≠ 1)
And add constraints
𝑢𝑖 − 𝑢𝑗 + 𝑛𝑥𝑖𝑗 ≤ 𝑛 − 1, ∀𝑖, 𝑗 ∈ 𝑁 − 1 , 𝑖 ≠ 𝑗
The simpler, layman version:
𝑢𝑖 − 𝑢𝑗 + 𝑛𝑥𝑖𝑗 ≤ 𝑛 − 1, ∀𝑖, 𝑗 ∈ 2,3, . . , 𝑛 , 𝑖 ≠ 𝑗
A Primer on Optimization Using Solvers - Anwar Ali 94
96. TSP Demo
Due to limitations of free Excel Solver, we can only
solve a 10-city problem. Excel 2007 is used here
Let’s travel to 10 capital cities of ASEAN
Start and terminate the tour at a city
Must visit each other city exactly once
Objective: minimize the total air travel distance
A Primer on Optimization Using Solvers - Anwar Ali 96
Country Capital Airport BWN PNH CGK VTE KUL NYT MNL SIN BKK HAN
Brunei Bandar Seri Begawan BWN 1330 1534 1977 1487 2603 1255 1278 1833 2060
Cambodia Phnom Penh PNH 1330 1975 757 1038 1289 1782 1138 504 1081
Indonesia Jakarta CGK 1534 1975 2719 1129 3083 2788 882 2297 3042
Laos Vientiane VTE 1977 757 2719 1697 694 2007 1857 517 495
Malaysia Kuala Lumpur KUL 1487 1038 1129 1697 1970 2490 297 1221 2102
Myanmar Naypyidaw NYT 2603 1289 3083 694 1970 2696 2202 819 1016
Philippines Manila MNL 1255 1782 2788 2007 2490 2696 2375 2188 1773
Singapore Singapore SIN 1278 1138 882 1857 297 2202 2375 1417 2218
Thailand Bangkok BKK 1833 504 2297 517 1221 819 2188 1417 995
Vietnam Hanoi HAN 2060 1081 3042 495 2102 1016 1773 2218 995
97. A Primer on Optimization Using Solvers - Anwar Ali 97
98. Setup the Excel worksheet
A Primer on Optimization Using Solvers - Anwar Ali 98
99. Name D2:M11 as distance
A Primer on Optimization Using Solvers - Anwar Ali 99
100. Name D13:M22 as var_X
A Primer on Optimization Using Solvers - Anwar Ali 100
104. Name N13:N22 as constraint2
A Primer on Optimization Using Solvers - Anwar Ali 104
105. Name E25:M25 as var_U
A Primer on Optimization Using Solvers - Anwar Ali 105
106. Sub-tour elimination constraint
We need to implement this into the Excel model
While the equation looks simple, the indexing of
variable u makes it more challenging in Excel
Use INDEX() function; row = index i, column = index j
Name top left cell as ref_cell (where i, j = 1)
Name the constraint range as subtour_elim with i, j ≥ 2
Each cell in subtour_elim needs to calculate its i and j
indices by referencing to ref_cell
We cannot exclude i ≠ j in the named ranges; the
model in Excel is not 100% correct but will still work
A Primer on Optimization Using Solvers - Anwar Ali 106
𝑢𝑖 − 𝑢𝑗 + 𝑛𝑥𝑖𝑗 ≤ 𝑛 − 1
∀𝑖, 𝑗 ∈ 𝑁 − {1 , 𝑖 ≠ 𝑗
107. Name D29 as ref_cell
A Primer on Optimization Using Solvers - Anwar Ali 107
109. Copy to the range, subtour_elim
A Primer on Optimization Using Solvers - Anwar Ali 109
110. Name D40 as total_distance,
=SUMPRODUCT(distance,var_X)
A Primer on Optimization Using Solvers - Anwar Ali 110
111. Solver Parameters
A Primer on Optimization Using Solvers - Anwar Ali 111
Under Options, select the checkboxes
Assume Linear Model
Assume Non-Negative
113. Solution
A Primer on Optimization Using Solvers - Anwar Ali 113
BWN CGK SIN KUL PNH BKK NYT VTE HAN MNL BWN
Total distance = 9291 km
115. CPLEX OPL TSP Model
A Primer on Optimization Using Solvers - Anwar Ali 115
dvar boolean x[cities][cities];
dvar float+ u[uvar];
minimize
sum(i in cities, j in cities: i!=j) x[i][j]*dist[i][j];
subject to {
forall(i in cities) sum(j in cities: j!=i) x[i][j] == 1;
forall(j in cities) sum(i in cities: i!=j) x[i][j] == 1;
forall(i in uvar, j in uvar: i!=j) u[i] - u[j] + n*x[i][j] <= n - 1;
}
execute {
var from;
var dest;
from = 1;
for (var cnt=1; cnt<=10; cnt++) {
for (dest=1; dest<=n; dest++)
if (x[from][dest]==1) {
write(city[from]," --> ");
from = dest;
break;
}
}
writeln(city[dest]);
}
116. CPLEX OPL Solution
// solution (optimal) with objective 9291
BWN --> CGK --> SIN --> KUL --> PNH --> BKK -->
NYT --> VTE --> HAN --> MNL --> BWN
A Primer on Optimization Using Solvers - Anwar Ali 116
118. A Primer on Optimization Using Solvers - Anwar Ali 118
119. TSP Key Learning
Textbook TSP formulation can be directly used to solve
real-world problems
As the formulation gets more complex, it becomes
harder to model in Excel, but still easy in OPL
Excel named ranges are only for rectangles
Some tricks required for indexing of variables
A Primer on Optimization Using Solvers - Anwar Ali 119
120. Agenda
Introduction to Analytics & Operations Research √
Optimization Modeling with Textbook Examples √
Formulating and Solving Mathematical Models √
Optimization Applications in Industry
How to Get Started
A Primer on Optimization Using Solvers - Anwar Ali 120
121. Waste neither time nor
money, but make the
best use of both
Benjamin Franklin
A Primer on Optimization Using Solvers - Anwar Ali 121
Picture from Wikipedia
122. Supply Chain Optimization
Plan
Facilities
Resources required
Source
Make vs Buy
Materials
Make
Prod planning
Deliver
Warehouse
Transportation
Location (where to open)
Min capital & headcount, max usage
Make in-house or sub-con?
How much to buy? Which supplier?
Who does what? How much to make?
Sequencing, batching decisions
Location and inventory level
Which air, sea & ground network
A Primer on Optimization Using Solvers - Anwar Ali 122
123. Supply Chain Optimization
This can be very complex depending on company’s size
For large companies, it is recommended to get
complete solutions from various solution providers
It is not just system implementation, but business
processes changes as well
It is better to start with small wins (phase-by-phase)
instead of big bang approach
A Primer on Optimization Using Solvers - Anwar Ali 123
124. Airline Industry Optimization
Crew scheduling
Aircraft scheduling
Airport gates assignment
Baggage handling
Tickets pricing
A Primer on Optimization Using Solvers - Anwar Ali 124
125. TSP Application Examples
Vehicle routing problem
Modified (more complex) TSP. Find the optimal route
to deliver goods from central depot to customers who
placed orders for such goods
Design and fabrication of integrated circuits (IC)
Minimize time spent during lithography to reduce the
capital cost of semiconductor factory
Design and manufacturing of printed circuit board
(PCB) and substrates
Placement of components, routing, drilling
A Primer on Optimization Using Solvers - Anwar Ali 125
129. PCB Holes Drilling
Without TSP
Less travel distance with TSP,
hence less drill time
A Primer on Optimization Using Solvers - Anwar Ali 129
130. Agenda
Introduction to Analytics and Operations Research √
Optimization Modeling with Textbook Examples √
Formulating and Solving Mathematical Models √
Optimization Applications in Industry √
How to Get Started
A Primer on Optimization Using Solvers - Anwar Ali 130
131. Getting Started with Optimization
Get management sponsors
Convince management the benefits of optimization
Identify the challenges in decision making process
Unable to predict the outcome?
Complexity in decision making
Drill down the decision making process
Objectives, rules, and boundary conditions
Input data required
What kind of outcomes/decisions needed
Build and demo quick-win optimization model(s)
Refine it until it can replace the current process
A Primer on Optimization Using Solvers - Anwar Ali 131
132. Competencies Required
Spreadsheet modeling
Mathematical optimization
Data integration
Business acumen
Hire consultant and/or upskill employees
Read this:
http://www.scienceofbetter.co.uk/
A Primer on Optimization Using Solvers - Anwar Ali 132
133. Training & Consulting
Current training offered:
3-day “Decision Optimization”
1-day “Decision Optimization for Managers”
If you need help with optimization modeling for your
business, I will be happy to offer my service. More
details here:
www.theoptimizationexpert.com
My profile: https://www.linkedin.com/pub/anwar-ali-mohamed/54/2bb/57b
A Primer on Optimization Using Solvers - Anwar Ali 133