Part2B LP Solvers
Part2B LP Solvers
Paula Carroll,
Management Information Systems,
Q250, Belfield, UCD
[email protected]
MIS41160 1
Section Objectives
2
LP Assumptions
When we use LP as an approximate representation of a real-life
situation, the following assumptions are inherent:
• Proportionality - The contribution of each decision variable
to the objective or constraint is directly proportional to the
value of the decision variable.
• Additivity - The contribution to the objective function or
constraint for any variable is independent of the values of the
other decision variables, and the terms can be added together.
• Divisibility - The decision variables are continuous and thus
can take on fractional values.
• Deterministic - All the parameters (objective function
coefficients, right-hand side coefficients, left-hand side, or
technology, coefficients) are known with certainty.
MIS41160 3
Linear Programming Solution Space
A polyhedron is the set of all points
that satisfy a finite set of m linear inequalities:
4
MIS41160
Linear Programming Solution Space
A set is convex if the closed line segment joining any two
points in S belongs to the set
5
MIS41160
Fundamental Theorem of Linear Programming
We can see that the LP solution space is convex
MIS41160 6
LP Outcomes
MIS41160 7
Special Cases; Infeasible Problem
MIS40520 8
Special Cases; Unbounded Problem
MIS40520 9
Special Cases; Degeneracy
MIS40520 10
Multiple Optimal Solutions
MIS40520 11
Some more Maths Revision
Exhibit 3.1
Source, Taylor “Introduction to Management Science” Chapter 3 - Linear Programming:
13
Computer Solution and Sensitivity Analysis
MS Excel LP Solver
“Solver” Parameter Screen
Exhibit 3.2
14
MS Excel LP Solver
Adding Model Constraints
Exhibit 3.3
15
MS Excel LP Solver
Solution Screen
Exhibit 3.4
16
MS Excel LP Solver
Answer Report
Exhibit 3.5
17
Class Exercise: Clothing Production
Problem
A clothing company makes coats and jackets using wool and
labour. There are 150 m2 of wool and 200 hours of labour
available. A coat takes 10 hours to make and uses 3 m2 of wool. A
a jacket takes 4 hours to make and uses 5 m2 of wool. Profit on a
coat is €50 and on a jacket is €40. Find the best combination of
coats and jackets to make to maximise profit.
• Return to your LP model of this problem. Create a
spreadsheet model in MS Excel;
• Solve the Excel LP model and compare the results wit the
solutions you created using the Graphical Solution
technique
• Interpret the MS Excel Answer report in full by writing a
short “aide memoir” to yourself in your Learning Journal.
MIS41160 Optimisation in Business 18
XpressMP Introduction
MIS41160 19
Xpress-MP Product Suite
GUI Xpress-IVE
Language Mosel
Mosel Solver Modules mmxprs, mmxslp, mmsp, mmquad
C, C++, Java Builder Component Libraries (BCL)
System mmsystem
Data Handling mmodbc, mmetc
Graphics mmive
MIS41160 20
Xpress-MP Product Suite
MIS41160 21
Xpress-IVE in action
Toolbar
Colour coded
development Output Window
Window
Explorer Window
MIS41160 22
Example – Chess Set Problem1
1
Taken from “FICO Xpress Optimization – User Guide”,
Task 2
Using the Chess model as a template, amend it to implement the
Pottery problem in Mosel;
Verify the LP solution form you Mosel implementation is the
same as you graphical and MS Excel solutions;
Write the steps and your observations as part of your Learning
Reflection.
MIS41160 26
Class Exercise
Add the following Mosel code to your pottery Mosel model:
!procedure to check problem status
procedure print_status
declarations
status: string
end-declarations
case getprobstat of
XPRS_OPT: status:="LP Optimum found"
XPRS_UNF: status:="Unfinished"
XPRS_INF: status:="Infeasible"
XPRS_UNB: status:="Unbounded"
XPRS_OTH: status:="Failed"
else status:="???"
end-case
writeln("Problem status: ", status)
end-procedure
MIS41160 28
A Product Mix Example Problem
• Four-product T-shirt/sweatshirt manufacturing company.
Must complete production within 72 hours
Truck capacity = 1,200 standard sized boxes.
Standard size box holds 12 T-shirts.
One-dozen sweatshirts box is three times size of standard box.
€25,000 available for a production run.
500 dozen blank T-shirts and sweatshirts in stock.
How many dozens (boxes) of each type of shirt to produce?
MIS41160 29
Product Mix Example - Data
T-shirt - F 0.08 25 45
MIS41160 30
A Product Mix Example - Model Construction
Decision Variables:
x1 = sweatshirts, front printing
x2 = sweatshirts, back and front printing
x3 = T-shirts, front printing
x4 = T-shirts, back and front printing
Model:
Maximise Z := €90x1 + €125x2 + €45x3 + €65x4
Such that:
0.10x1 + 0.25x2+ 0.08x3 + 0.21x4 72 hr
3x1 + 3x2 + x3 + x4 1,200 boxes
36x1 + 48x2 + 25x3 + 35x4 €25,000
x1 + x2 500 doz. Sw/shirts
x3 + x4 500 dozen T-shirts
MIS41160 31
Anything else?
Diet Mix Example - Data and Problem Definition
Design a minimum cost breakfast to include at least 420 calories,
5 milligrams of iron, 400 milligrams of calcium, 20 grams of
protein, 12 grams of fibre, and must have no more than 20 grams
of fat and 30 milligrams of cholesterol.
MIS41160 32
Diet Example Model Construction – Decision
Variables
!Try the Xpress Wizards to
Let create more complicated models
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.
The cost is a linear combination:
Z = 0.18x1 + 0.22x2 + 0.10x3 +…..
Similarly, the constraints are linear combinations of the decision
variables.
MIS41160 33
Diet Example Model Summary
Minimise Z = 0.18x1 + 0.22x2 + 0.10x3 + 0.12x4 + 0.10x5 + 0.09x6 + 0.40x7 +
0.16x8 + 0.50x9 + 0.07x10
subject to:
90x1 + 110x2 + 100x3 + 90x4 + 75x5 + 35x6 + 65x7 + 100x8 + 120x9 + 65x10 420 Cal
2x2 + 2x3 + 2x4 + 5x5 + 3x6 + 4x8 + x10 20 Fat
Chol
270x5 + 8x6 + 12x8 30
Iron
6x1 + 4x2 + 2x3 + 3x4+ x5 + x7 + x10 5
Calc
20x1 + 48x2 + 12x3 + 8x4+ 30x5 + 52x7 + 250x8 + 3x9 + 26x10 400
Prot
3x1 + 4x2 + 5x3 + 6x4 + 7x5 + 2x6 + x7 + 9x8+ x9 + 3x10 20
Fibre
5x1 + 2x2 + 3x3 + 4x4+ x7 + 3x10 12
xi 0
• Notice the relationship between columns and constraint limits.
• Check out CAMP (computer assisted Menu Planning)
• Write the algebraic form of this model
34
MIS41160
Class Exercise
MIS41160 35
Mosel Model General Structure
declarations
x1,x2: mpvar
j: integer
S = “Hello World” !could be done outside declarations since it is unambiguous
p: real
end-declarations
!Do stuff
end-model
MIS41160 36
Mosel Basics
• Case Sensitive
• No end-of-line marker
• Restricted Keywords
• declarations, array, of, real, sum, forall
• etc – See Mosel Language Guide
• Elementary Data Types
• integer, boolean, real, string
• mpvar, linctr
• Additional Data Types
• set (collection of elements of a given type)
• array (collection of labelled elements of a given type)
• All objects (scalars and arrays) declared in Mosel are always
initialised with a default value:
real, integer: 0
boolean: false
string: ''
37
MIS41160
Mosel Basics
• Constants:
Note: Anything that is given a value in a declarations block is a constant.
maxIter = 100 declares a constant called maxIter, and gives it the
value 100, implicitly an integer. Note the syntax.
• Ranges:
ITEMS = 1..10 defines a range set, that is, a set of consecutive
integers from 1 to 10, used as an index set for data arrays
• Arrays:
myArr: array (ITEMS) of real defines a one-dimensional array of real
values indexed by the range set ITEMS.
A1: array(ITEMS, 1..20) of real is an example of a 2-dimensional 10
by 20 array of real values.
• Assigning values:
A2D(1):= 5 assigns the value of 5.0 to the first component of the array
A2D.
MIS41160 38
Modelling with Mosel
• Constructs: Summations:
MIS41160 39
More Mosel
• Logic constructs
• if-then-else … end-if
• if-then-elif …. end-if
• Case …………end-if
• User defined Subroutines
• procedure/end-procedure !No Arguments
• Function/end-function!takes arguments
MIS41160 40
Mosel - Putting it all together!
forall (i in 1..10) do
writeln( “Index i is ", i)
writeln( "Value of ",i,"th item in array is ", team(i))
end-do
MIS41160 41
Mosel – Where to next?
• Documents
– Mosel Language Reference Manual
– Mosel Users Guide
– Getting Started
– Applications of Optimization with Xpress-MP
• Examples
– Getting Started examples
– Mosel Users Guide
– Applications of Optimization with Xpress-MP
MIS41160 42
Class Exercise
1. Compile and run diet.mos to solve the diet mix problem
– Add comments to the model to explain the syntax used
to initialise the data.
– Add comments to the model to explain the syntax used
to create the constraints.
2. If you’re interested in this area, review the sample
journal articles in the area of LP diet and nutrition
applications:
1. Rodin, E. Y., Donaldson, J., Hammann, M., Kittrell, M., & Mindlin, B. (1990).
Optimal nutrition through linear programming. Mathematical and Computer
Modelling, 13(2), 93-104.
2. Skau, J. K., Bunthang, T., Chamnan, C., Wieringa, F. T., Dijkhuizen, M. A., Roos,
N., & Ferguson, E. L. (2014). The use of linear programming to determine whether
a formulated complementary food product can ensure adequate nutrients for 6-to
11-month-old Cambodian infants. The American journal of clinical nutrition, ajcn-
073700.
MIS41160 43
LP Solution Algorithms
In this section we’ll look at the underlying LP solution
algorithms.
n'
Subject to: a x b
i 1
ij i j
j {1, 2, … , m}
and {xi} 0
The standard form of an LP problem as:
• One whose objective function is maximisation
• One whose constraints are expressed as equations and whose right hand
side (RHS) is non-negative (after the introduction of slack and surplus
variables)
• One in which all the decision variables are non-negative
MIS41160 45
The Simplex Method
The Simplex Method is an algebraic, iterative method to solve linear
programming problems.
– Identify an initial basic solution (Corner point),
– Systematically move to an adjacent basic solution, which improves the value of
the objective function. Eventually, this new basic solution will be the optimal
solution.
• The simplex method requires that the problem is expressed as a
standard LP problem. This implies that all the constraints are
expressed as equations by adding slack or surplus variables.
• The method uses Gaussian elimination (sweep out method) to solve
the linear simultaneous equations generated in the process.
MIS41160 46
Steps of the Simplex Algorithm
Step 0: Using the standard form, determine a starting basic
feasible solution by setting n-m variables to zero (non-basic).
Step 1: Select an entering variable from among the current
non-basic variables, which gives the largest per-unit
improvement in the value of the objective function.
If none exists, stop; the current basic solution is optimal.
Otherwise go to Step 2.
Step 2: Select a leaving variable from among the current
basic variables that must now be set to zero (become non-
basic) when the entering variable becomes basic.
Step 3: Determine the new basic solution by making the
entering variable basic; and the leaving variable non-basic,
and return to Step 1.
MIS41160 47
Simplex Method in Tableau Format
The tableau format allows us to represent the problem compactly
and solve it more easily.
We merely record the coefficients of the problem.
In order to use the Tableau Method, we need to do three things:
1. Represent the LP problem in standard form;
2. Represent the objective function as an equation:
n
z c x
i 1
i i 0
MIS41160 48
Example: Setting up the Problem
For instance, the Maximisation Problem: In standard form:
Maximise z = 3x1 + 2x2 z – 3x1 – 2x2 - 0s1 – 0s2 – 0s3- 0s4 = 0
(1)
2x1 + x2 8 (2)
2x1 + x2 + 0s1 + 1s2 + 0s3+ 0s4 = 8
-x1 + x2 1 (3) (2)
Ctr2
2x1 + x2 8 (2) x2
-x1 + x2 1 (3)
6
x2 2 (4)
We select to
x1, x2, 0 Increasing x1 increase the
Increasing x2
Ctr3 by one unit value of x1
by one unit results in an
4
results in an increase of Z
increase of Z Ctr1
of 3 units
of 2 units How much can
we increase x1?
2
Ctr4
x1 =0 The amount of the
x2 =0 increase is limited by
the constraints (One
s1 =6 of the slack variables
s2 =8 2 4 6 x1 becomes zero or non-
s3 =1 MIS41160 basic) 50
s4 =2
Maximisation Example
x2 =0
s1 =6
s2 =8 2 4 6 x1
s3 =1 MIS41160 51
s4 =2
Simplex Tableau
The tabular form of the simplex method uses a simplex tableau to
display the system of equations yielding the current basic feasible
solution
There are different ways to design the tableau, a common design is
as follows:
Initial Tableau for the Max problem (Iteration 0)
Header Basic Eq. Z x1 x2 s1 s2 s3 s4 Rt Side
Var. (Sol)
Objective Function z 0 1 -3 -2 0 0 0 0 0
s1 1 0 1 2 1 0 0 0 6
s2 2 0 2 1 0 1 0 0 8
Constraints
s3 3 0 -1 1 0 0 1 0 1
s4 4 0 0 1 0 0 0 1 2
MIS41160 52
Iteration 0 (Steps 0,1,2)
Iter- Basic Eq. Z x1 x2 s1 s2 s3 s4 RHS
ation Var. (Sol)
z 0 1 -3 -2 0 0 0 0 0
s1 1 0 1 2 1 0 0 0 6 6/1
0 s2 2 0 2 1 0 1 0 0 8 8/2
s3 3 0 -1 1 0 0 1 0 1
s4 4 0 0 1 0 0 0 1 2
Pivot
Element
Entering Variable: Select the variable with Leaving Variable: Smallest
the most negative coefficient in the ratio obtained by dividing
objective function the RHS of each row by the
positive coefficients of the
entering variable (Column)
MIS41160 53
Iteration 0 (Step 3)
• To get the new BFS we perform the following steps:
1. Divide the pivot row by the pivot element and call it the “new pivot row.”
Copy the result in the tableau for the next iteration.
2. For every row of the current tableau (excluding the pivot row), subtract the
product of its pivot-column coefficient times the new pivot row. Copy the
result in the corresponding row of the next-iteration tableau. Make sure to
properly identify the new basic variable.
MIS41160 54
Max Example: New Row 1
Basic Eq. Z x1 x2 s1 s2 s3 s4 RHS
Var. (Sol)
Original Equation 1 s1 1 0 1 2 1 0 0 0 6
Minus (1) times new pivot row s2 2 0 1 1/2 0 1/2 0 0 8/2 (-1)
Iteration 1
z x1 x2 s1 s2 s3 s4 soln Row ratio workings
z 1 0 -0.5 0 1.5 0 0 12 R0
s1 0 0 1.5 1 -0.5 0 0 2 R1 1.333333 min ratio
x1 0 1 0.5 0 0.5 0 0 4 R2 8
s3 0 0 1.5 0 0.5 1 0 5 R3 3.333333
s4 0 0 1 0 0 0 1 2 R4 2
MIS41160 56
Max example
• On this iteration, what does it mean when there is no negative z
coefficient?
Iteration 2
z x1 x2 s1 s2 s3 s4 soln Row
z 1 0 0 0.333333 1.333333 0 0 12.66667 R0
x2 0 0 1 0.666667 -0.33333 0 0 1.333333 R1
x1 0 1 0 -0.33333 0.666667 0 0 3.333333 R2
s3 0 0 0 -1 1 1 0 3 R3
s4 0 0 0 -0.66667 0.333333 0 1 0.666667 R4
MIS41160 57
Class Exercise
1. Recall the pottery problem from week 1.
MIS41160 58
Class Exercise, pottery; Simplex iterations
Initial Tableau
X0 X1 X2 S1 S2 soln Row ratio workings
X0 1 -40 -50 0 0 0 R0
S1 0 1 2 1 0 40 R1 20 min ratio
S2 0 4 3 0 1 120 R2 40
Iteration 1
X0 X1 X2 S1 S2 soln Row ratio workings
X0 1 -15 0 25 0 1000 R0
X2 0 0.5 1 0.5 0 20 R1 40
S2 0 2.5 0 -1.5 1 60 R2 24 min ratio