Mahmut Parlar (Auth.) - Interactive Operations Research With Maple - Methods and Models-Birkhäuser Basel (2000)
Mahmut Parlar (Auth.) - Interactive Operations Research With Maple - Methods and Models-Birkhäuser Basel (2000)
Parlar.~ut. 1952-
Interactive operations research with Maple: methods and models! Mahmut Parlar.
p. cm.
Includes bibliographical references and index.
ISBN 978-1-4612-7110-9 ISBN 978-1-4612-1356-7 (eBook)
DOI 10.1007/978-1-4612-1356-7
1. Operations research-Data processing. 2. Maple (Computer file) I. Title.
T57.6.P38 2000
658.4'034'0285-dc21 00-031232
CIP
All rights reserved. This work may not be translated or copied in whole or in part without the written
permission of the publisher Springer Science+Business Media, LLC,
except for brief excerpts in connection with reviews or
scholarly analysis. Use in connection with any form of information storage and retrieval, electronic
adaptation, computer software, or by similar or dissimilar methodology now known or hereafter
developed is forbidden.
The use of general descriptive names, trade names, trademarks, etc., in this publication, even if the
former are not especially identified, is not to be taken as a sign that such names, as understood by the
Trade Marks and Merchandise Marks Act, may accordingly be used freely by anyone.
ISBN 978-1-4612-7110-9
9 8 7 6 5 4 321
Contents
4 Linear Programming 99
4.1 Introduction.................... .. . . . . . . . 99
4.2 Graphical Solution . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.3 The Simplex Method . . . . . . . . . . . . . . . . . . . . . . . .
104
4.3.1 Manual Solution of the Production Problem . . . . . . . 107
4.3.2 Solution Using Maple's simplex Package . . . . . . . . 113
Contents vii
10 Simulation 417
10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
10.2 Generating (pseudo-) Random Numbers . . . . . . . . . . .423 . . .
10.2.1 Mixed-Congruential Method . . . . . . . . . . . . . . . . 424
10.2.2 Maple's Unifonn Random Number Generator . . . . . . . 426
10.2.3 Kolmogorov-Smimov Test for Unifonnity . . . . . . . .426 .
10.3 Generating Random Variates from Other Distributions . . . . . . 428
10.3.1 Exponential Random Variates . . . . . . . . . . . . . . . 429
10.3.2 Maple's Random Variate Generators . . . . . . . . . . . . 430
10.4 Monte Carlo Simulation . . . . . . . . . ... ... . . . . . . . 432
10.4.1 Numerical Evaluation of Definite Integrals ... ... .. 432
10.4.2 Simulation of a Static (Single-Period) Problem . . . . . 434 .
10.5 Dynamic Simulation Models . . . . . . . . . . . . . . . . . . . . 435
10.5.1 Simulation of an Inventory System with Random Yield . . 436
x Contents
References 449
Index 463
Preface
Interactive Operations Research with Maple: Methods and Models has two ob-
jectives: to provide an accelerated introduction to the computer algebra system
Maple and, more importantly, to demonstrate Maple's usefulness in modeling and
solving a wide range of operations research (OR) problems.
This book is written in a format that makes it suitable for a one-semester course
in operations research, management science, or quantitative methods. A nwnber
of students in the departments of operations research, management science, oper-
ations management, industrial and systems engineering, applied mathematics and
advanced MBA students who are specializing in quantitative methods or opera-
tions management will find this text useful. Experienced researchers and practi-
tioners of operations research who wish to acquire a quick overview of how Maple
can be useful in solving OR problems will find this an excellent reference.
Maple's mathematical knowledge base now includes calculus, linear algebra,
ordinary and partial differential equations, nwnber theory, logic, graph theory,
combinatorics, statistics and transform methods. Although Maple's main strength
lies in its ability to perform symbolic manipulations, it also has a substantial
knowledge of a large nwnber of nwnerical methods and can plot many different
types of attractive-looking two-dimensional and three-dimensional graphs. After
almost two decades of continuous improvement of its mathematical capabilities,
Maple can now boast a user base of more than 300,000 academics, researchers
and students in different areas of mathematics, science and engineering.
My goal in writing this book has been to show that Maple can be immensely
useful in the type of modeling work that is common in operations research, man-
agement science and related disciplines of operations management and industrial
and systems engineering. There are several excellent texts on OR and on Maple,
xii Preface
but none of them describe the use of Maple in solving OR problems. This book
fills the gap and provides the missing link between Maple and its successful use
in OR.
Chapter I starts with an introduction to operations research. Chapter 2 is an
accelerated introduction to Maple that covers the most important commands that
are relevant in OR applications. This is followed in Chapter 3 by a treatment of
some of the mathematical techniques useful in OR modeling: algebra and calcu-
lus, ordinary and partial differential equations, linear algebra, transform methods
and probability theory.
Chapter 4 discusses linear programming, one of the oldest and perhaps the
most frequently used OR technique. In this chapter Maple's symbolic manipula-
tion capabilities are not used since linear programming problems must be solved
numerically. After describing the graphical method to solve linear programming
problems (which is simplified by using Maple's capability to plot regions of in-
equalities) we proceed to a discussion ofthe simplex method, which is algebraic in
nature. Maple's own implementation of the simplex method is also demonstrated
and integer linear programming is mentioned briefly.
Chapter 5 presents an exposition of nonlinear programming and many prob-
lems in unconstrained and constrained optimization are solved explicitly. Chapter
6 covers dynamic programming, in which Maple can be useful in finding opti-
mal policies for dynamic optimization problems in closed form. After describing
a simple numerical example (the "stagecoach problem"), several models with a
linear system and quadratic costs in both discrete and continuous time are exam-
ined. An exact solution of a workforce planning model is followed by the analysis
of some stochastic dynamic programming models, including a gambling problem
that gives rise to a myopic policy. The chapter ends with a discussion of stopping
time problems. Stochastic processes is presented in Chapter 7 where exponen-
tiaVPoisson duality, renewal theory and discrete- and continuous-time Markov
chains are described in detail. These chapters amply demonstrate the success of
Maple in obtaining analytic solutions to many OR models.
Chapters 8 and 9 are concerned with the application of OR methods to inven-
tory management and queueing models, respectively. Here, Maple's symbolic ma-
nipulation capabilities are used extensively to obtain optimal solutions in c1osed-
form. For example, in the chapter on inventory models, implied backorder costs
and optimal base-stock policy for a dynamic stochastic inventory problem are
computed explicitly. In the chapter on queueing models, the operating charac-
teristics of Markovian bulk arrival systems and the transient solutions for some
queues are found in closed form. Where symbolic analysis becomes impossible
to use, we employ Maple's extensive knowledge of numerical analysis. For ex-
ample, solution of the exact model for the continuous-review inventory problem
with backorders requires intensive numerical computations. Similarly, dynamic
optimization of a Markovian queue involves solving differential equations nu-
merically. These computations are performed easily by stringing together a few
lines of Maple code.
Preface xiii
Internet Resources
Every Maple worksheet displayed in the book has been tested with Maple RS.l
and R6. These worksheets can be downloaded from my personal Web page at the
addresswww.business.mcmaster.ca/msis/profs/parlar/.
Waterloo Maple's Web site www.maplesoft.com/is always worth a look
for announcements of new products, demos and Maple support information.
The following yahoo.com page has links to interesting sites concerned with
Maple: dir. yahoo. com/Science/Mathematics/Software/MAPLE.
Readers interested in following the lively Internet discussions on symbolic al-
gebra packages such as Maple and Mathematica may wish to peruse the sci.
math. symbolic newsgroup. A recently established newsgroup that carries
Maple-specific postings is comp. soft-sys .math . maple.
Acknowledgments
During the last three years of writing this book, I received feedback from many
friends and colleagues. First and foremost, I would like to thank Ray Vickson
(University of Waterloo) who encouraged me to undertake this project and pr0-
vided useful comments on early drafts. Martin von Mohrenschildt (McMaster
University) saved me many hours of work by quickly directing me to the correct
Maple commands to solve some of the problems presented in the book. Elkafi
Hassini (University of Waterloo) read many chapters and sent comments. George
Wesolowsky (McMaster University), Paul Stephenson (Acadia University) and
Mustafa Karakul (University of Toronto) are friends and colleagues who took the
time to read parts of the manuscript and comment on its style.
I consider myself fortunate in having acquired my early training in OR under
the guidance of two eminent operations researchers: I took many OR courses
xiv Preface
from Halim DogrusOz and izzet ~ahinl who, in the mid-l 970s, were professors
in the graduate program in Operations Research and Statistics at the Middle East
Technical University, Ankara. I learned from Dr. DogrusOz that there is more
to OR than just high-powered mathematics, and I learned from Dr. ~ahin (who
directed my master's thesis on renewal theory) that there is more to modeling
than just deterministic analysis. I am grateful to both.
My editors Ann Kostant and Tom Grasso at Birkhluser have always been very
encouraging and positive about this project and I thank them for that.
Finally, a big thank you to my wife and children for their understanding during
the long process of writing this book.
I would be delighted to hear from readers who have found the Maple work-
sheets contained in this book useful in their OR-type work.
MAHMUT PARLAR
[email protected]
www.business . mcmaster.ca/msis/profs/parlar/
May 2000
Hamilton, Canada
3The first fonnal OR textbook was written by Churchman, AckotT and ArnotT [45J and appeared
in 1958. This was followed by Sasieni, Yaspan and Friedman's book [164J, published in 1959. A
collection of notes on OR topics (such as probability, search theory, Markov processes, queueing,
sequential decision processes and production scheduling) assembled by the OR Center at MIT [139J
based on a summer program of OR lectures also appeared in 1959.
4In the 19905, The Operations Research Society of America and The Institute of Management
Sciences merged to fonn INFORMS (Institute for Operations Research and the Management Sci-
ences), which has a total of approximately 12,000 members including some Nobel prize winners; see
www. informs. org.
1.2 The Method of OR 3
costs. In this case, an OR analyst would fonnulate the problem while interacting
with the decision maker (i.e., the retailer). This would involve specifying the ob-
jectives (e.g., cost minimization) and identifying those aspects of the inventory
system that can be controlled by the retailer (e.g., magnitude and frequency of or-
ders placed). Problem fonnulation is perhaps similar to a medical diagnosis since
in this stage of an OR study, one usually observes the symptoms (such as high
inventory) and then attempts to make a diagnosis of the problem (such as very
large order quantities).
The next step involves the construction 01a model that represents the behavior
of the system. In OR, mathematical models usually assume the fonn V = I(x, y)
where V is the perfonnance measure (value function) of the organization, sys-
tem or decision maker under study (e.g., average cost, profit per month, etc.). The
set x = {XI, ... , xm} is the set of variables that can be controlled by the deci-
sion maker, y = {YI, . .. , Yn} is the set of parameters that nonnally cannot be
controlled by the decision maker and 1 is the relationship between V and (x, y).
Additionally, there may be equality and/or inequality constraints limiting the val-
ues that can be assumed by the decision variables.
In the inventory example, the OR analyst attempting to solve the retailer's prob-
lem constructs a mathematical model of the inventory system and the ordering
policy used by the retailer. As a very simple example, if the annual demand A for
the item is detenninistic and unifonn, a reasonable model of the average annual
cost C may be expressed as C = K AI Q + !h Q where K is the (fixed) cost of or-
dering, Q is the order quantity (the decision variable) and h is the cost of holding
inventory per unit per year. Once such a mathematical model is constructed, it be-
comes relatively easy to use calculus to find the optimal order quantity that would
minimize the cost function C. In this example, Q is the decision variable, K, A,
and h are the uncontrollable parameters in the problem and C is the perfonnance
measure of the system.
Assuming that the model is properly validated (i.e., that it does represent the
system under study reasonably accurately), the OR analyst must derive a solution
from the model. In the simple case discussed here, in order to optimize (i.e., min-
imize) the average cost, one can use calculus and find the optimal order quantity.
This involves differentiating the cost function, equating the result to zero and solv-
ing for the unknown decision variable Q. As we will show in Chapter 8, Inventory
Models, the optimal solution Q. for this model is
and the minimum average annual cost under this decision is C· = J2AK h.
In the next stage of an OR analysis, an evaluation 01 the solution is perfonned
and the solution is compared to the policy or decision it is expected to replace. At
this stage, the analysts can highlight the differences between the current practice
and the recommended optimal solution. In the inventory example, the analysis
may reveal that under the current policy, the retailer was ordering unnecessarily
4 1. Introduction to Operations Research
large amounts (say, 2Q* units instead of the optimal Q* units) that resulted in
high inventories and carrying costs.
In the final stage of an OR study, the solution is implemented in order to im-
prove the performance of the system. For example, in the inventory problem, the
order decision is revised to Q* (say, down from the nonoptimal 2Q*) to reflect
the optimality of the solution found. This assumes that the decision makers have
accepted the results of the study and are willing to revise their current policy.
Normally, the five stages of an OR study are initiated in the order given. But
very often each stage interacts with others before the termination of the study. For
example, the analyst solving the inventory problem may discover that the demand
is not quite deterministic but exhibits a fair degree of randomness. In that case, the
model construction stage must be revisited and a more accurate model reflecting
the randomness of demand must be constructed.
These nontechnical and philosophical--but important-issues were discussed
and debated in great detail in the 1950s and 1960s by OR pioneers such as Ackoff
and Churchman. For their views on problem formulation, model construction,
systems approach and so on, see [3], [4] and [44].
2.1 Introduction
Maple is a mathematical problem-solving environment that combines symbolic,
numerical and graphical methods used in different areas of mathematics. This
chapter provides an introduction to Maple and presents those aspects of it that can
be useful in operations research applications.
Maple has more than 2700 commands and nearly 40 mathematical packages
(such as linear algebra, integral transforms, Boolean logic, numerical approxima-
tions, financial mathematics and algebraic curves) that can be used to solve prob-
lems from basic arithmetic to general relativity theory. As we will see through-
out this book, the solution of many challenging operations research problems be-
comes extremely easy by loading a package and simply combining a few Maple
commands.
Maple has an extensive on-line help facility. To obtain help about a command,
it is sufficient to type a question mark and then the name of the command. For
example, typing? in t (and pressing the < ENTER> key) provides information on
definite and indefinite integration, including a large number of examples where
the in t command is used. Readers who are new to Maple can take a ''tour'' by
clicking on Help and then New User's Tour on the Maple menu bar.
We start this chapter by discussing some aspects of basic symbolic computa-
tions and expression manipulations such as simplifications. This is followed by
numerical computations such as finding roots, computing definite integrals, solv-
ing differential equations. In many cases important insights about a problem can
be obtained by a graphical representation of, for example, the implicit curves
2.2 Symbolics
2. 2.1 Expanding, Factoring and Simplifications
Maple's main strength is in its ability to manipulate symbolic expressions. For
example, it can expand an expression such as (x+y)lO. When asked to factor
the result, Maple gives the original expression.
As a simple example, consider the expansion of the expression (x + y) 10. Note
that, in Maple, all characters which follow a sharp character (#) on a line are
considered to be part of a comment. Thus, in the following example, the file name
of the worksheet (i.e., Expand.mws) is understood by Maple to be a comment.
Note that each Maple command must end with a semicolon (;) or a colon (:).
Termination by a semicolon informs Maple to display the results. When the results
are expected to be very long, the colon can be used to terminate the command thus
suppressing the output.
> restart: # Expand.mws
> expand((x+y)A10);
x lO + IOx 9 Y
+ 45x 8 y2 + 120x 7 y3 + 21Ox 6 y4 + 252x 5 y5 + 210x4 y6
+ 120x 3 y7 + 45x2 y8 + lOx y9 + ylO
> factor (%) ;
(x + y)IO
Note that the ditto operator, %, is a shorthand notation for the result of the previ-
ous, i.e., the last, command.
2.2 Symbolics 7
w2 +3w+2
y'-
.- w2 +Sw+6
> normal (y) ;
w+ 1
w+3
Note that x, y and z were the names assigned to the preceding two expres-
sions. If we wish Maple to "forget" these assignments, we can ''unassign'' them
by placing the name inside single forward quotes:
> x :=' x': y :=' y': z: =' z' :
The combine () command attempts to combine terms into a single term. In
some sense, this is-like the factor () command-the opposite of the ex-
pand () command.
> A : =XAy*XAZ;
A :=x'x=
> combine (A) ;
x'x=
In this case combine () did nothing since very often one needs to specify an
option such as power, In, or symbolic to help combine () recognize the
expressions and do the simplification.
> combine(A,power);
x (y+=>
> B:=log(x)/2+log(y)-log(z);
8 2. A Quick Tour of Maple
I
B := 21n(x) + In(y) -In(z)
> combine(B,ln);
I
2ln(x) + In(y) -In(z)
> combine(B,ln,syrnbolic);
> C:=sqrt(x)*sqrt(y);
C:=..(i ,jY
In the following example, the combination of ..;x,jY into ,JXY becomes pos-
sible only after informing Maple---using assurne-that both x and yare posi-
tive quantities since ..(i,jY is not equal to ,JXY for all values of x and y, e.g.,
RR i= J(-I)(-I).
> combine(C);
> assurne(x>O,y>O);
> combine(C);
1
! :=x -+ - +x
x
> f (1) ;
2
> f:=unapply(l/x+x,x);
1
!:=x -+ -+x
x
Now the function !(x) can be evaluated at different values of x.
> f(l); f(a); f((a+b)"2);
2
I
-+a
a
I 2
(a+b)2 +(a+b)
The unapply () command can be useful if, for example, in the middle of a
Maple session, we find an expression that we want to define as a function:
> restart: # Unapply.mws
> Result:=int(int(lambda*exp(-lambda*u),u=O .. t),
lambda) ;
e(-J.t)
Result := - - + A-
t
Here, we create a function out of the Result that depends on two variables
lambda and t.
> F:=unapply(Result,lambda,t);
e(-J.t)
F := (A-, t) -+ - -
t
+ A-
> F(1,5); F(a,b);
~ e(-S) + I
5
e(-ab)
--+a
b
Lists
A Maple list can be created by simply enclosing any number of expressions or
other Maple objects in square brackets.
> restart: # Lists.mws
> L:={ a,b,sin(x),int(x"2,x)];
L := [a, b, sin(x), ~ x 3]
The number of elements of the list can be counted using nops () and the
membership of an element can be checked with member ().
> nops (L) ;
4
> member(b,L); member(cos(x),L);
true
false
To access, say, the first and the fourth elements of the list, we enter I.{ 1] and
u: 4] .
> I.{ 1]; I.{ 4] ;
a
1 3
-x
3
The ordered elements of the list L can be converted to an expression sequence
by op (L).
> op (L) ;
a, b, sin(x), ~ x3
Sets
A mathematical set is an unordered collection of elements. In Maple a set is cre-
ated by enclosing the elements in curly brackets.
> restart: # Sets.mws
> A: ={ a, b, 2, Q" 2, 1 / x} ;
1
A := {2, -, a, b, (f)
x
> B:={c,f,10!};
B := {e, J, 3628800}
Operations on sets can be performed with union and intersect.
> A union B;
2.2 Symbolics II
1
{2, -, a, b, c, f, (fl, 3628800}
x
Since A and B do not have any elements in common, their intersection A nB
is the empty set 0, which Maple denotes by {}.
> A intersect B;
{}
Solving a system of two equations in two unknowns gives the solution using
the set notation. Before the expressions involving x and y can be manipulated, the
solution found here must be assigned.
> Sol:=solve({ a*x+b*y=c,d*x+e*y=f},{ x,y} );
af-cd -ec+ f b}
Sol := {y =
ae-bd
,x = ae-bd
> x; y;
x
y
> assign(Sol); x; y;
-ec+fb
ae-bd
af-cd
ae-bd
It is possible to convert () a list to a set and perform set operations on it.
> L: =[ 9, 6, t, 4, 2] ;
L := [9, 6, I, 4, 2]
> LSet:=convert(L,set);
LSeI := {2, 4, 6, 9, I}
> LSet intersect A;
{2}
Arrays
As a data structure, an array is an extension of a list that is indexed by positive
integers ranging from 1 to nops (list). In an array, one can have many
dimensions and the indices can be negative or zero. Arrays are also related to
objects such as vectors and matrices.
> restart:. Arrays.rows
Here A is a 2 x 2 array with negative and zero indices.
> A:=array(-l •. O,O •. l);
A := array( -1 .. 0, 0.. 1, [])
12 2. AQuick Tour of Maple
Let us make assignments to the first three entries but leave the last one unas-
signed. (The presence of the comment symbol # before A[ 0, 1] : =d indicates
that this is treated as a comment, not as an assignment.)
> A[ -1,0] :=a; A[ -1,1] :=b; A[ 0,0] :=C; #A[ 0,1] :=d;
A_I,o := a
A_I,I :=b
Ao,o:= c
> print (A);
array( - 1..0, 0 .. 1, [
(-1,0) = a
(-I,I)=b
(0,0) =c
(0, I) = AO,I
])
Since A has nonpositive indices, it is not treated as a matrix. But the following
2 x 2 array B acts like a matrix and thus one can manipulate it using matrix
operations with the command evalm ().
> B:=array(1..2,1..2,[[ 3,4] ,[ 2,k]]);
B:= [~ :]
> with (linalg) :
Warning, new definition for norm
[ 17 12+4kJ
6+2k 8+k 2
Thus, 1'0(/) = e- A1 •
2.3 Numerics
In many practical problems the user may be interested in obtaining only a nu-
merical solution to a problem. For example, finding the sample mean or sample
variance of a data set or computing the probability of a specific event may re-
quire numerical (not symbolic) computations. In those cases, we can make use of
Maple's abilities to perform the necessary numerics and obtain the results.
Although Maple's symbolic manipulation and solution capabilities can be very
impressive, there are certain instances where it becomes impossible to find solu-
tions analytically. In those cases, we again resort to numerics to find the solution.
Maple can also be used as an interactive calculator that can add and subtract
real numbers.
> restart: * BasicNurnerics.mws
> 2+3; evalf(3452.51-sqrt(Pi»;
5
3450.737546
It knows about complex numbers and their manipulation.
> sqrt(-l); (1+6*I)* (3-5*I)*7*I;
1
-91 +2311
16 2. AQuick Tour of Maple
Maple can deal with very large numbers and manipulate them using (almost)
infinite precision. It can also do integer factorizations with i factor () and per-
form floating-point evaluations to (almost) any precision with evalf ( ) .
> Big:=100!;
Big:=933262154439441526816992388562667004907159682643\
81621468592963895217599993229915608941463976156\
51828625369792082722375825118521091686400000000\
0000000000000000
> ifactor(Big);
(2)97 (3)48 (5)24 (7)16 (11)9 (13)7 (17)5 (19)5 (23)4 (29)3 (31)3 (37)2
(41i (43)2 (47)2 (53) (59) (61) (67) (71) (73) (79) (83) (89)
(97)
> evalf(10g(Big),35);
363.73937555556349014407999336965564
In the following examples we present additional Maple commands that can aid
in numerical analysis.
e<-1/2¥> II
f:=x-+
~
v21(;q
> F:=unapply(int(f(u),u=O .. t),t);
+ 2 .Jii7i ,Jii P)
> mu:=100i sigma:=10i beta:=.7i
Jl := 100
(1 := 10
P:=·7
> solve(l-F(Q)=beta,Q)i
86.88641461
Note that the same solution can also be obtained by using the fsolve ()
command that solves equations only numerically. Here, the argument o.. 150
informs Maple that it should search for the numerical solution in the interval
[0,150].
> fsolve(1-F(Q)=beta,Q,0 .. 150)i
86.88641461
Maple's random number generation facilities will be useful in Chapter 10, Sim-
ulation.
2.4 Graphics
The third important aspect of Maple is its capability to plot impressive-looking
two- and three-dimensional graphs. The dictum "one picture is worth one thou-
sand words" also applies in operations research modeling and graphing curves on
20 2. A Quick Tour of Maple
the plane or surfaces in space may reveal important information about a problem's
characteristics.
In this section we will consider several two- and three-dimensional Maple
graphs that can be useful in modeling and analysis.
0,(,
os
004
0.3
0.2
0.1
O-¥-~~~--r"~·-· . . :2 .. . . :;
x
FIGURE 2.1. Plot of the Weibull density with shape parameter a = 2.5 and scale parameter
p = 1.7.
3xy-x+y, i.e., the set of points that satisfy the necessary conditionszx = Zy = o.
Before analyzing the problem mathematically, it may be useful to plot the neces-
sary conditions as implicitly defined curves in the xy-plane.
> restart: # ImplicitPlot.mws
> z:=-x A 3-2*y A 3+3*x*y-x+y;
z := _x 3 - 2 y 3 + 3x y - x +y
> zx:=normal(diff(z,x»;
zx:= -3x 2 +3y-1
> zy:=normal(diff(z,y»;
zy := -6 + 3 x + Ir
> with(plots):
> implicitplot({ zx,zy} ,x=-l •• l,y=-l .• l,
numpoints=lOOO,color=black);
We see in Figure 2.2 that the two curves for Zx = 0 and Zy = 0 intersect at two
points.
1
0.8
-0.6
-0.8
{x = .5875626256, y = .6785631723},
{y = .3429560780, x = -.0980955898}, {
y = -.5107596261 - .4653767156/,
+
x = -.2447335179 .9507825483 I}, {
x = -.2447335179 - .9507825483/,
y = - .5107596261 + .4653767156 I}
Example 9 Contour plot and implicit plot displayed jointly. Consider the prob-
lem of minimizing the quadratic function f(x, y) = (x - 2)2 + (y - 3)2 subject
to the linear constraint g(x, y) = x + y ~ 4 for x, y ~ O. In order to obtain in-
sight into the behavior of the objective function and its relation to the constraint,
we can plot the contours of the function f(x,y) using contourplot () along
with the constraint boundary g(x, y) = 0 using implici tplot (). The graph
in Figure 2.3 reveals that since the unconstrained optimal solution is outside the
feasible region, the constrained optimal solution for this problem will be on the
constraint boundary x + y = 4.
> restart : # ContourPlot.mws
> with (plots) :
> f:=(x-2)A2+(y-3)A2i
f := (x - 2)2 + (y - 3)2
> g :=X+y=4i
g :=X +y=4
> fCP:=contourplot(f,x=O .. 5,y=O •• 5,color=black,
scaling=constrained,contours~ 1,2,3,4,~ ,
numpoints=1000) :
> gIP : =implicitplot(g,x=O •. 5,y=O .. 5,color=black,
scaling=constrained) :
> display({ fCP,gIP} ) i
3
Y
2
FIGURE 2.3. The contours of the objective function f(x,y) displayed with the con-
straint boundary g(x,y) = O.
0.99
0.'J8
0.'T1
x
0.%
0.CJ5
0 .')4
FIGURE 2.4. Graph of the solution trajectory for dx(t)/dt = -1 (t)x (t), x (0) = 1 where
l(t) = log(t2 + e- t\
FIGURE 2.5. Objective function of the inventory problem where backorders are permitted.
Example 12 Bivariate normal density. Now we consider the surface plot of the
density f(x,y) of the bivariate normal random vector (X, Y). We will plot the
density using the plot3d () command.
> restart: * BivariateNormalPlot.mws
26 2. A Quick Tour of Maple
FIGURE 2.6. The surface plot of the bivariate normal density f(x,y) with PI = 10,
P2 = 5,111 = 7,112 = 12 andp = .7.
qO :=0
ql := 1000
q2:= 2000
28 2. A Quick Tour of Maple
q3 := 3000
The piecewise unit cost function C(Q) is defined in tenns of the break-points.
> C:=piecewise (Q<q[ 1] ,5, Q<q[ 2] ,4,
Q< q[ 3] , 3, 2);
5 Q < 1000
C'= { 4 Q < 2000
. 3 Q < 3000
2 otherwise
> eval(C,Q=1234);
4
The total cost QC(Q) is also a piecewise function as plotted in Figure 2.7.
8000
6000
4000
2000
FIGURE 2.7. Plot of the total purchase cost function QC(Q) in an inventory model with
quantity discounts.
2 x-a a-x<Oudx-b<O
{ (b - c-x
a)(c - a) - -
2 b - x < 0 and x - c < 0
(c-b)(c-a) - -
with assumptions ona, b andc
We check and see that the density indeed integrates to I, i.e., .r: f (x ) dx = 1.
> int(f(x),x=a .. c);
f:
Evaluating the integral x f(x) dx to compute the mean of X gives E(X) =
!(a+b+c).
> EX:=int(x*f(x),x=a .. c);
1 1 1
EX := 3" b + 3" a + 3" c
with assumptions on b, a and c
We can easily compute the cumulative distribution function F (x) = f: f (u) du,
a ~ x ~ c and display the result as another piecewise function.
> F:=normal(convert(int(f(u),u=a .. x),
piecewise,x»;
o x~a
x 2 -2ax +a2
x~b
F .-
·- (-b + a)(a - c)
-a c + a b - x 2 + 2 ex - c b
x ~ c
(-c + b)(a - c)
c<x
with assumptions on a, b andc
_e(-At) +1
Example 16 Solution ofa differential equation To follow Maple's steps in solv-
ing a differential equation, we enter infolevel[ dsol vel : =5; . Consider the
problem of solving dx/dt = ax (t), x(O) = xo.
> infolevel[ dsol vel : =5;
infoleveldsotve := 5
> dsol ve ({ di ff (x (t) , t) =a* x (t) , x (0) =x[ 0] } ,x (t» ;
Methods for first order ODEs:
trying a quadrature
f := 1C sin(O x) 1n(..(;3)
> C(f);
to = O.3141592653589793El*sin(theta*x)*log(sqrt
(x*x*x» ;
> fortran(f);
to = O.3141593El*sin(theta*x)*alog(sqrt(x**3»
32 2. A Quick Tour of Maple
Output from C and fortran can also be written to an external file for further
processing; see? C and? fortran .
If a complete Maple worksheet is to be exported to LaTeX, it is preferable to
do it by choosing Iile/&xport As/LaTeX from the Maple menu bar. To format
and print documents exported and saved in this manner, the LaTeX style package
maple2e. sty is needed. In Wmdows installations, this file is located in the
Etc folder where Maple is installed.2
> latex(f);
t2 sin(theta*x);
t4 x* x;
t6 sqrt (t4* x) ;
t7 log(t6);
t8 O.3141592653589793El*t2*t7;
> fortran(f,optimized);
t2 = sin(theta*x)
t4 = x** 2
t6 = sqrt(t4*x)
t7 = alog (t6)
t8 = O.3141593El*t2*t7
2Maple worksheets used in this book were produced with maple2e . sty, mapleenv. def,
mapleenv. sty, mapleplots. sty, maplestyle. sty, mapletab. sty and maple-
uti! . sty. These style files are written by Stan Dewitt ofWaterJoo Maple, Inc.
2.5 Other Useful Commands and Packages 33
For example, suppose we wish to write a program to compute the factorial n!.
This is done by creating a procedure, naming it (say, f) and then entering the
statements that define the factorial function.
> restart: # Program.mws
> f:=proc(n) if n=O then 1 else n*f(n-l) fi end;
f:= proe(n) ifn = othen 1 elsen x f(n - I)fiend
Once the program is written, we can run it by simply evaluating the ftmction
fen) for different values of n.
> seq(f(n),n=O .. 5);
I, 1,2, 6,24, 120
As another example, the next procedure called Di f fIn t computes the deriva-
tive and the indefinite integral of a given ftmction y(x).
> Difflnt:=proc(y,x)
> local yDiff, ylnt;
> yDiff:=diff(y,x);
> ylnt:=int(y,x);
> [ y,yDiff,ylnt]
> end;
Di.fI1nt := proe(y, x)
IoealyD(tf, ylnt;
yD(tf:= diff(y, x); ylnt := int(y, x); [y, yD(tf, ylnt]
end
x
The input ftmction 2 , its derivative 2x and integral -lx 3 follow.
> Difflnt(x A 2,x);
, 2x '3"!'x ]
[X2 3
Basic Finance
> restart: # Finance.mws
> with(finance);
34 2. A Quick Tour of Maple
Option Pricing
Maple's blackscholes () command computes the arbitrage-free value of a
European-style call option. If the spot price of a stock is $20, the strike price of
the option is $ 18, risk-free interest rate is 7%, time to maturity of the option is 90
days and the volatility of the stock is .09, then the correct value of the option now
using the Black/Scholes formula [34] is $2.63. Maple also finds that the option
seller should hold 0.81 units of the stock now in order to hedge and eliminate the
risk in his portfolio (consisting of the option and the stock).
> BS:=blackscholes(20,18,0.07,90/365,sqrt(0.09),
hedge) ;
+ 1.154009520 - 8.845990480erf(~(
.1851851852 (In( I:) + .02835616438) ~v'73
- .004109589041 ~v'73)-/2)
> evalf(BS); evalf(hedge);
2.630815160
.8153042532
2.6 Summary 35
2.6 Summary
Maple's ability to perfonn symbolic and numeric computations and its two- and
three-dimensional plotting features can be helpful in modeling and solving OR
problems. In this chapter we provided a brief introduction to those Maple com-
mands that will be used in subsequent chapters. In particular, we used exam-
ples to describe the following features of Maple: function definitions, lists, sets
and arrays, algebraic simplifications and expression manipulations, solution of
equations symbolically or numerically, perfonning statistical and financial com-
putations, plotting graphs, obtaining infonnation about Maple's internal opera-
tions and exporting the Maple output to other programming languages such as C
and FORTRAN. Although Maple's individual commands are powerful enough to
solve a wide range of OR problems by just pasting together a few commands, we
also described briefly Maple's powerful programming language. With this basic
Maple background, the reader should now be able to follow the solution of OR
problems that will be covered throughout the book.
2.7 Exercises
1. Simplify
X4-I
x -I
using normal ( ) . Is it always a good idea to use normal () to simplify
expressions? Would you use normal () to simplify (x 50 - I)/(x - I)?
Why, or why not?
3. Let L be a list defined as [tfl, I, eel'] where a and b are real numbers. Find
the logarithm of the elements of this list using the map command.
use a 11 val u e s () to generate all the roots. Find the floating point ap-
proximation for the root in the first quadrant using evalf (). For addi-
tional information on these functions, use Maple's help facility by entering
a question mark followed by the command name, e.g., ? sol ve.
5. Generate 50 random variates distributed uniformly between 0 and 100 and
find their mean. Is the computed sample mean close to the true mean? Now
plot these numbers in a histogram with five intervals [0,20), [20,40), ...,[80,
100).
6. Maximize the linear objective function z = XI +X2 +X3 subject to the linear
constraints 2x1 + 3X2 ~ 8 and 2x2 + 5X3 ~ 10 where the decision variables
Xi, i = I, 2, 3 are required to take nonnegative values. Find the optimal Xi,
i=I,2,3andz.
7. Consider the differential equation N(t) = [hIN(t) -m]N(t), with N(O) =
No a given constant. Let hI = 0.4, m = 50 and N = 100. Solve this dif-
ferential equation and plot its solution. Now increase hI = 10 and resolve
the problem. What happens to the trajectory of N(t) as hI increases? (This
is a simplified model of a population growth--or decline-where the birth
rate is proportional to the population size and m is the death rate; see e.g.,
Bellman and Cooke [25, p. 13].)
8. Consider the differential equation x(t) = u(t)x(t) with x(O) = 1 where
u(t) is a piecewise defined function given by
.2, if 0 ~ t < 1
u(t) = { .2, if2 ~ t < 3
.1, otherwise.
Solve this DE and plot the solution trajectory for t E [0, 5]. Can you assign
an economic interpretation to this problem?
3
Maple and Mathematical Foundations
of Operations Research
3.1 Introduction
Although there have been some isolated cases I of successful applications of oper-
ations research that did not involve any mathematics, operations research model-
ing generally requires a good understanding of basic university-level mathematics
such as algebra, calculus, linear algebra, differential equations, transfonn methods
and probability theory.
In this chapter we review these important mathematical topics and describe the
Maple statements that can be used to perfonn the required operations in order to
solve equations and inequalities, evaluate integrals and derivatives, find the solu-
tion oflinear systems, solve ordinary and partial differential equations and differ-
ence (recurrence) equations, invert Laplace transfonns and generating functions
and find the joint probability distribution of functions of random variables.
JWhen the human element is involved in a decision environment, it may be impractical or impossi-
ble to construct a mathematical model of the decision problem. A case in point is the widely circulated
"elevator problem" (Taba, [182, pp. 1-2]). This problem involved elevators in an office building with
slow service and waiting times that were perceived to be long by the users who complained loudly.
A mathematical solution based on queueing theory Wlfl found unsatisfactory. But after a careful ex-
amination of the problem, it Wlfl discovered that the users' complaints were due to boredom since
the actual waiting times were not that long. A nonmathematical solution for this problem Wlfl pro-
posed that involved installing full-length mirrors at the entrances to the elevators. Once the mirrors
were installed, the users' complaints disappeared IfI they kept occupied by watching the others (and
themselves) while waiting for the elevators.
We will see that Maple's ability to perfonn symbolic manipulations will pennit
us to easily solve difficult mathematical problems that are relevant in OR. For ex-
ample, evaluating manually an integral such as f(k log(x) - 2x 3 + 3x 2 + b)4 dx
is a nontrivial task since expanding the integrand results in 35 tenns such as
-l44k log(x)x s and 12k3[log(x)]3x 2. While integrating each of these tenns may
not be very difficult, the sheer task of mathematical bookkeeping that involves
collecting the tenns, simplitying them makes this an error-prone operation ifper-
fonned manually. We will see that Maple can evaluate this integral (and many
others) symbolically and produce the correct result in a fraction of a second. As
always, it is important to check the results obtained, but that too can be achieved
relatively easily with Maple's help.
3.2 Algebra
In this section we describe the use of the sol ve () function which can success-
fully solve a large class of equations and inequalities.
Quadratic := a x 2 + b x +c
> SolQ:=solve(Quadratic,x);
1 -b + ./b2 - 4 a c I -b - .Jb2 - 4ac
SolQ := 2' a ' 2' a
> Sol<1 1]; Sol<1 2] ;
I -b + .Jb2 - 4ac
2 a
I -b -.Jb2 - 4ac
2 a
Next, we attemptto solve a cubic equation given by x 3-2x 2+x+21 = O. The
exact solution of this cubic involves complex numbers (denoted by I in Maple).
The solution is simplified using the evalf () command. The correctness of the
solution is also checked by substituting it back into the original equation.
> Cubic:=x~3-2*x~2+x+21;
Cubic:= x 3 - 2x2 +x + 21
> SolC:=solve(Cubic,x);
3.2 Algebra 39
Solving the inequality Ps > P4 manually would clearly be a challenging task. But
using Maple's sol ve ( ) command and then evaluating the result with eval f ( ) ,
we find that p > .586.
40 3. Maple and Mathematical Foundations of Operations Research
P4 := 6 p2 (I - p)2 + 4 p3 (1- p) + p4
> Sol: =sol ve (p[ 8) > p[ 4) ,{ p} ) :
> evalf(Sol);
{p < -.238776}, {p < I., .586886 < pI, {1.22332 < p}
The graphs of both Ps and P4 as a function of p E (0, I) can be plotted after
removing the # sign before the plot command.
> #plot ([ p[ 8) ,p[ 4) ) ,p=O .. 1) ;
Of course, sometimes it may be impossible for Maple to find the solution
of an equation using the solve () command. But in some cases where there
are no symbolic parameters, using the floating point version of the solver, i.e.,
fsol ve (), may result in a solution.
> line:=y=a*x;
line:= y = ax
> Sol: =sol ve ({ circle, line} ,{ x, y} );
I A2
-h2 - '1-
2 ~
= 0
AI A2
-
QI
+ -
Q2
= B
with unknowns QI, Q2 and 'I. This problem arises in the optimization of a con-
strained multi-item inventory system where there is a constraint on the total num-
ber of orders that can be placed. The parameters hi correspond to the holding
costs, Ai are the annual demands and B is the maximum number of orders that can
be placed per year; see Hadley and Whitin [81, pp. 56-57]. We assume hi = 10,
h2 = 5, AI = 100, A2 = 150 and B = 50 and solve the system with Maple.
> restart: # ThreeEqns.rnws
> h[ 1] :=10; h[ 2] :=5; lambda( 1] :=100;
larnbda[ 2] : =150; B: =50;
hi := 10
42 3. Maple and Mathematical Foundations of Operations Research
h2:= 5
A.I := 100
A.2 := 150
B :=50
> ecJ 1] :=(1/2)*' h[ 1]' -eta*' lambda{ 1]' 1\1.. 1] "2=0;
1 'IA.I
eql:= -hl- - 2 =0
2 QI
> eq 2] :=(1/2)*' h[ 2]' -eta*' lambda{ 2]' 1\1.. 2] "2=0;
1 'I A.2
eq2 := - h2 - - 2 = 0
2 Q2
> ecJ 3] : =' lambda{ 1] , 1\1.. 1] +' lambda{ 2] , 1\1.. 2] =' B' ;
A.I A.2
eq3 :=-+-=B
QI Q2
> solve({ ecJ 1] ,eq[ 2] ,eet 3]} ,{ \1.. 1] ,\1.. 2] ,eta} );
1 1
(Q2 = RootOf(-3 - 6_Z + _Z2), QI = 2RootOf(-3 -6_Z + _Z2) + 2'
1
'I = - (RootOf(-3 - 6 Z + Z2) + 1)2}
80 - -
> Sol:=evalf(allvalues(%));
Sa;x;
i = 1,2.
Suppose that the gross profit of each company is g;, i = 1, 2, so the profit P; of
company i is obtained as
PI. -_ g;Sa;x;
-X;, i = 1,2
alXI + a2X2
3.2 Algebra 43
The solution to this competitive problem can be obtained by computing each com-
pany's ''reaction curve"
R. _ ap;
,- ax;
and solving for XI and X2 from RI = R2 = o.
> restart: # Marketing.mws
> p[ 1] : =g[ 1] * S* alpha[ 1] * x[ 1] / (alpha[ 1] * x[ 1]
+alpha[ 2] * x[ 2] ) -x[ 1] ;
R2 := K2 S a2 K2 S a2 2 X2 _ 1= 0
al XI + a2X2 (al XI + a2 x2)2
The optimal advertising amounts XI, X2 and the profits PI, 1'2 are found as
follows.
> assign(sol);
al 2 Sgl3
(gl al + g2 a2)2
a2 2 Sg2 3
44 3. Maple and Mathematical Foundations of Operations Research
3.3 Calculus
Calculus plays an important role in mathematical modeling of operations re-
search problems. In this section we describe some examples of calculus tech-
niques whose implementation can be substantially simplified using Maple.
3.3.1 Limits
Computing the limits using 1 imi t () is easy with Maple. Consider the following
examples.
> restart: # Limits.mws
Maple knows that one dollar invested now that compounds continuously at a
rate of r% per annum will grow to e"t dollars in I years.
> f{1]:=(1+r/n)A(n*t);
r
II := (l + _)(nt)
n
> limit (f{ 1] , n=infinity) ;
e(rt)
The next limit operation needs I'Hopital's rule, which Maple supplies.
> f{ 2] :=(a"'x-1)/x;
tr - I
12:=--
x
> limit (f{ 2] , x=O);
In(a)
Maple recognizes that the next limit does not exist. However, if the direction is
specified as right or left, then Maple finds the limits.
> f{ 3] : =abs (x) / x;
/J:=~
x
> limit (f{ 3] , x=O) ;
undefined
> limit (f{ 3] , x=O, left) ;
-I
> limit (f{ 3] , x=O, right) ;
8.!.
1r
In the next example Maple appears to be unable to find the result since its initial
attempt fails to produce a limit. However, we realize that Maple has done the right
thing since it does not know the sign of the parameter b. As soon as we inform
Maple that b > 0, the limit is correctly found as O.
> f[ 4] :=sin(a*x)*exp(-b*x);
14 := sin(ax)e(-bx)
> limit (f[ 4] , x=infinity);
lim sin(ax)e(-bx)
X-HXl
> assurne(b>O);
> limit (f[ 4] , x=infinity) ;
o
3.3.2 Derivatives
Partial Derivatives
Maple has two means of performing ordinary and partial differentiation: either it
uses the diff () function or the D () operator. The main (and subtle) difference
between the two is that the D operator computes derivatives of mappings (Le.,
functions), while di f f () computes derivatives of expressions.
Here are some examples.
We first define an expression in two variables f: =a* x"2* y+b* x* y"2; and
differentiate it with respect to x and y using di f f ( ). We also find the mixed
partial derivative di ff ( f, x, y) ; of f.
> restart: # Derivatives.mws
> f:=a*x"2*y+b*x*y"2;
f
:= a x 2 y + bxI
> diff(f,x); diff(f,y);
2axy+b y 2
ax 2 +2bxy
> di ff ( f, x, y) ;
2ax+2by
Next, we define a mapping 9 (i.e., a function) involving the same expression as
in f and perform differentiation using the D operator. Note that the output is also
obtained as a function.
> g:=(x,y)->a*x"2*y+b*x*y"2;
46 3. Maple and Mathematical Foundations of Operations Research
(x, y) --+ 2 a x y + br
(x, y) --+ ax 2 + 2bx y
> q 1,2] (g);
(x, y) --+ 2 a x + 2 by
Finally, we see that using the 0 operator, one can differentiate composite func-
tions.
> f : =' f': g :=' g' :
> f:=g->COS(gA2);
f := g --+ coseg2)
> u:=v->cos(vA2);
Example 21 Inventory model with lost sales. As another example, consider the
objective function of a deterministic inventory problem where lost sales are al-
lowed. Defining Q as the order quantity and T as the length of time during which
sales are lost, Hadley and Whitin [81, p. 48] show that the average annual cost C
is obtained as a function of Q and T. This cost function and its partial derivatives
are easily found as follows.
> restart: # LostSales.mws
> C:=lambda*K/(Q+lambda*T)+(1/2)*h*Q A2/(Q+lambda*T)
+pi*lambda A2*T/(Q+lambda*T);
C ._ A K h g2 ! 1C A. 2 T
.- Q + A T + 2 Q + A. T + Q + A. T
> CQ:=normal(diff(C,Q»;
CT '= _! A. (2 A. K + h g2 - 21C A. Q)
. 2 (Q + A. T)2
3.3 Calculus 47
We can even solve for the (Q, T) pair satisfying the necessary conditions. It is
clear that the sign of (1r Ai - 2A.Kh plays an important role in the detennination
of the optimal solution. For details, see Hadley and Whitin [81, p. 49].
> solve({ numer(CQ) ,numer(CT)} ,{ Q,T} );
-2 K +%I1r}
{Q=%I, T=
%1 h -1r A.
%1 := RootOf(2 A. K + h _Z2 - 21r A._Z)
> allvalues(%);
Leibniz's Rule
In some operations research problems (especially those arising in inventory the-
ory) the objective function involves an integral whose upper and/or lower limits
may be a function of the decision variable. Such integrals must be differentiated
using Leibniz's rule of differentiation under the integral sign. Fortunately, Maple
is aware of this rule as the following statements demonstrate.
> restart: *
Leibniz.mws
> C:=Int(g(Q,t),t=a(Q) .. b(Q));
C := l
a(Q)
b(Q)
g(Q, t) dt
> diff (C, Q) ;
l b(Q)
a(Q)
fa g(Q, t) dt + (fa b(Q» g(Q, b(Q»
- (fa a(Q» g(Q, a(Q»
> C:='C':
As an example, consider the following cost function that appears in the analy-
sis of a continuous-review inventory model where lead-time randomness can be
reduced by investment; see Gerchak and Parlar [70]. The decision variables are Q
(order quantity), r (reorder point) and a (investment amount). The partial deriva-
48 3. Maple and Mathematical Foundations of Operations Research
tives of the cost function w.r.t. the three variables are easily computed using the
dif f () function.
> C:=K*lambda/Q+h* (Q/2+r-mu)+b*lambda*alpha
*Int(FBar(x),x=u(r,alpha) .. infinity)/Q
+G(Q,alpha);
u(r.a)
FBar(x) dx
. Q 2 Q
+G(Q, a)
> CQ:=diff(C,Q);
CQ := - ~; + ~ h _
b ). a 1~ 00
u(r.
FBar(x) dx
+ (~G(Q, a»
> Cr:=diff(C,r);
b).a (t,. u(r, a»FBar(u(r, a»
Cr:= h - --~--~---~
Q
> Calpha:=diff(C,alpha);
Calpha :=
b ).1 00
FBar(x) dx
_..:.....;;;;u(:;.:r•..:;;a'-)_ _ __
Q
b).a (%0. u(r, a»FBar(u(r, a» iJ
Q + (iJa G(Q, a»
As discussed in Gerchak and Parlar [70], these equations are solved numeri-
cally to find the optimal decisions.
Implicit Differentiation
In some problems it may be impossible to express uniquely the dependent vari-
able in terms of the independent variable. For example, the expression (i.e., the
r
relation) x 2+ = r2 represents a circle of radius r, but solving for the dependent
variable y one obtains y = ±Jr2 - x 2, indicating that y is not a function of x. In
those cases, to compute the derivative of y w.r.t. x, we use implicit differentiation
that has been implemented by the Maple function implicitdi ff (f, y, x) ,
which computes dy / dx, the (implicit partial) derivative of y with respect to x.
In the first example, we implicitly differentiate x 2 + = r2 and obtain r
dy/dx = -x/yo
> restart: # ImplicitDiff.mws
> implicitdiff(x A 2+y A 2=r A 2,y,x);
3.3 Calculus 49
x
y
Example 22 Continuous-review inventory problem. A more difficult case involves
(yet another) inventory example where the partial derivatives of a particular cost
function C(Q, r) are found as
I
CQ = + 7r: B(r)] + "2hgl = 0
-)'[A
Cr = hQ -7r:).K(r) = 0
where B(r) and K(r) are functions ofr. Implicitly differentiating CQ and Cr to
compute dr/dQ, we obtain the following.
> CQ:=-lambda* (A+pi*B(r))+h*Q A 2/2;
1
CQ:= -). (A + 7r: B(r» +"2 h gl
> Cr:=h*Q+pi*lambda* (-K(r));
Cr := h Q - 7r: ). K(r)
> implicitdiff(CQ,r,Q);. r (Q) in CQ
hQ
). 7r: O(B)(r)
> implicitdiff(Cr,r,Q);. r (Q) in Cr
h
). 7r: O(K)(r)
These results can be used to investigate the shape of the curves represented by
CQ = 0 and Cr = 0 in the Qr-plane to see if there is a unique solution to the
problem; see Hadley and Whitin [81, p. 170].
Maple can also compute the second-order implicit derivatives d 2r /dgl for
each relation and obtain the following results.
> implicitdiff(CQ,r,Q$2);. r'(Q) in CQ
h «O(2»(B)(r) h g2 -). 7r: O(B)(r)2)
).2 7r:2 O(B)(r)3
> implicitdiff(Cr,r,Q$2);. r'(Q) in Cr
(O(2»(K)(r) h2
).2 7r:2 O(K)(r)3
3.3.3 Integrals
J:
Maple possesses a truly impressive knowledge of integration. A symbolic integral
such as x 2 dx can easily be evaluated to obtain (b 3 - a 3)/3:
> restart:. Integrals.mws
50 3. Maple and Mathematical Foundations of Operations Research
> value(%);
!bl _ !al
3 3
This is, of course, a very simple problem that could have been quickly solved
by anyone who has some passing knowledge of integrals. But consider the fol-
lowing problem that arose in aerospace engineering in the study of turbulence
and boundary layers. 2
2Tbis problem appeared in a Macsyma advertisement in the September 1984 issue of ScienJijic
American.
3Legend has it that the engineer who was working on this problem tried to evaluate the integral
for more than three weeks with pencil and paper, always arriving at a different result. With Maple the
correct solution is found in a fraction of a second.
3.3 Calculus 51
> Result:=int(f,x);
- !9 k 3 x 3 _ ~ Jc2 x 6 -
3
2 b3 x4 + 27 k x 8 - ~ Jc2 b x4
8 4
_ ~ kxl0ln(x) - 48 kbx7 + ~ k b2 x4
5 49 2
+ - k bx7In(x) + 24k4 x - 8x l2 + -216 xII
48
7 II
108 lO 54
- - x - 12Jc2In(x)2 x 6 + - Jc2ln(x)2 x 5
5 5
+ 4k 3 1n(x)3 x 3 _ 27 x 8 b _ 12x 6 ~ + 108 x 7 b
7
54
+ _x 5 b2 +4x 3 b 3 + 9x 9 - 24kln(x)x6 b
5
108
+ -5- kln(x)x 5 b + 12kln(x)x 3 b2
+ 12Jc2ln(x)2 x 3 b + 16k In(x)x 9 - 27 k In(x) x 8
108 3
+ -;;- kln(x)x7 + 16x9 b + 16 k 3 x4
> simplify(diff(Result,x)-f);
o
Differentiating the (horrendous looking) result and subtracting it from the orig-
inal expression gives 0, indicating that Maple was able to find the correct solution.
52 3. Maple and Mathematical Foundations of Operations Research
-0.5
t/J dz
where
I
t/J = --e-~-.
1.2
-.Iii
Since functions of the form e-~ cannot be evaluated analytically, this integral has
to be computed numerically.
> restart: # NormalDensity.mws
> phi:=(1/ (' sqrt(2*Pi)' ) )*exp(-z"2/2);
e(-1/2=2)
t/J._-=-
.- .ffi
> Int('phP ,z=-0.5 . . . 35); evalf(%);
1 ·35
- .5
t/Jdz
.3282931124
Thus, Pr( -0.5 ~ Z ~ 0.35) = .3282931124. The fact that this is the correct
result can be seen by finding the probability by an alternative method that uses
Maple's knowledge of the distribution of the normal density. Defining <I>(z) =
J:oo t/J(u) du, we find the same result from <1>(0.35) - <1>(-0.5) = .3282931124.
> with(stats):
> Phi:=z->statevalf{ cdf,normalc{ 0,1]] (z);
<I> := stateva/fcdj, norma/do, 1
> Phi(.35)-Phi(-0.50);
.3282931124
Naturally, Maple is unable to evaluate the integral since we have not specified
the sign of the parameter A.. As soon as we indicate, using assume ( ) , that A. > 0,
Jo
Maple correctly integrates the density and finds oo A.e- At dl = I.
> assume(lambda>O);
> int(f,t=O .. infinity);
1a1a
double integral
Fw(w) = 1- 1
1.dxdy,
wla wlya
We find the result using Maple's help:
> restart: *
Doublelntegral.mws
> F:=1-Int(Int(1/a A 2,x=w/y .. a),y=w/a .. a);
F:=unapply(value(F),w);
F := 1 - lla
- -a
a y
a
w w 1.
1 dx dy
w
_a2 + w + wIn(a) - wIn(-)
F~w~l+ a
a2
> simplify(F(w));
w
w (I + In(a) -In(-))
a
a2
> limit(F(w),w=O); F(a A 2);
°
54 3. Maple and Mathematical Foundations of Operations Research
ax n a
- -
x-I
- - -
x-I
The next sum is obtained correctly, but one should be careful in using it, as the
result applies only when -I < x < I.
> Sum(a*xAk,k=O .. infinity); value(%);
00
Lax le
1e=O
a
x -I
> Sum(k A3*x Ak,k=1 .. infinity); value(%);
Lk x
00
3 le
Ie=\
I x x2
x «x _ 1)2 - 6 (x _ 1)3 + 6 (x - 1)4)
> Sum(xAk/k,k=l .• infinity); value(%);
x le
t;T
00
-1n(I - x)
> factor(simplify(sum(k,k=l .• n)));
I
2 n (n+l)
> factor(simplify(sum(k A2,k=1 .. n)));
I
6n(n+ 1)(2n+ I)
> factor(simplify(sum(k A3,k=1 .• n)));
4I n2 (n+I)2
3.4 Linear Algebra 55
Example 27 Geometric random variable. The next example concerns the sum
of the probabilities of the geometric random variable N such that Pr(N = k) =
p(1- p)k for k = 0, 1,2, ... Provided that 0 < p < I, the sum L~P(1- p)k
converges to I. Since Maple does not check for the correct interval of conver-
gence of these infinite sums, it is up to the user to find out about the convergence
properties.
> Surn(rho* (l-rho)Ak,k=O .. infinity); value(%);
k=O
> assurne(n,integer); sirnplify(value(rngf));
A := [ ; !]
> B: =matrix (2, 2,[ b, 4,3,7] ) ;
B:= [~ ~]
> evalm(gamma*A);
3Y ]
ya
> transpose (A) ;
> evalm(A+B);
[ I +h 7 ]
5 a+7
The detenninant of a matrix is computed with the det () command. We see in
this example that as long as the parameter a "# 6, the A matrix should possess an
inverse, A-I, which we compute with the inverse () command. The result is
checked by multiplying the inverse by the original matrix.
> det (A);
a-6
> AI: =inverse (A) ;
Ab[ ]
a I
-3--
a-6 a-6
I I
-2--
a-6 a-6
> simplify(evalm(A &* AI));
[~ ~]
An easy way to input an n x n identity matrix is to use the array (identi ty
,1 •. n, 1 .. n) command.
> ID:= array(identity,1 .. 2,1 .. 2);
ID := array(itientity, 1..2, 1..2, [])
3.4 Linear Algebra 57
C:= [ !]
> evalm(A &* C);
[ 3+3C]
6+ca
> C:=matrix(1,2,[ 3,c] );
C:= [3 c]
> evalm(C &* A);
[3+2c 9+ca]
[9+6c+(9+ca)c]
58 3. Maple and Mathematical Foundations of Operations Research
A := [i ~ :]
1 1 7
We find (before solving the problem) that the inverse of A exists; hence we
should be able to compute the solution vector x.
> inverse (A) ;
13 -3 -I
32 16 32
-3 5 -I
-
16 8 16
-I -I 5
32 16 32
> b : =vector([10,20,30);
b := [10, 20, 30]
Using the geneqns () function, we can view the linear equations arising from
the system Ax = b.
> geneqns (A,[ x, y, z) ,b);
{3x + y + z =
10, x + 2y + z = 20, x + y + 7 z = 30}
> linsolve(A,b) ;
[ -5 35 25J
8 ' 4' 8
Thus, we find x = (-5/8,35/4,25/8) as the solution of the system.
It is, of course, possible that some linear systems may have infinitely many
solutions or no solutions at all. This is determined by computing the rank of a
matrix. The rank ofa matrix A [denoted by r(A)] is defined as follows: If there
3.4 Linear Algebra 59
exists at least one nonsingular square submatrix in A of order k and if all square
submatrices of order k + i, i ~ 1 (ifany) are singular, then r(A) = k.
Consider an n x n matrix A and an n x 1 vector b. The A matrix augmented
with b is denoted by (A I b). The following rules are useful in determining the
nature of the solution:
• Finally, ifr(A) < r(A I b), then the system has no solution.
Ab:= [l ~ ! ~~]
1 7 30
> rank(A); rank(Ab);
3
3
For the next example with n = 2, we see that r(A) = r(A I b) = 1 < 2; thus
the system has infinitely many solutions.
> A:=matrix([[ 3,1],[ 6,2]]);
A := [~ ~]
> b :=vector ([ 4, 8] ) ;
b := [4,8]
> geneqns(A,[ x,y,z] ,b); linsolve(A,b);
{3x+y=4,6x+2y=8}
LIt. -3 _1\ + 4J
> Ab:=augment(A,b);
Ab:= [~ ~ :]
> rank(A); rank(Ab);
60 3. Maple and Mathematical Foundations of Operations Research
The final example with n = 2 involves a system that has no solution. This is
observed by the fact that r(A) = I < r(A I b) = 2.
> A:=matrix([[ 1,1),[ 1,1)));
A := [! !]
> b: =vector ([ 2, 4) ); linsol ve (A, b) ;
b:= [2,4]
> geneqns (A,[ x, y) , b); linsol ve (A, b) ;
{x + y = 2, x + Y = 4}
> Ab:=augment(A,b);
Ab:= [ 12]
I 4
> rank(A); rank(Ab);
> b: =vector ([ 0, 0, 0] ) ;
b := [0,0,0]
> geneqns (A,[ x, y, z] ,b);
{x + 5 Y + 3 z = 0, 5x + y - z = 0, x + 2 y + z = O}
> linsolve(A,b);
!
o
I tI)
! .
! 0
62 3. Maple and Mathematical Foundations of Operations Research
We wish to compute, say, the 10th power of this matrix to find the probability
that the chain will be in some state j = 1, 2, 3 after 10 transitions given that it
is in some state i = 1, 2, 3 now. In order to do this, we find the eigenvalues and
the corresponding eigenvectors of A, diagonalize it as D and form the Q matrix.
Computing Q IY' Q-I then gives the nth power of A.
> restart: # EigensMC3.rnws
> with(linalg):
Warning, new definition for norm
CharacteristicPoiynomiai := A3 - 43 A - 41
> solve(CharacteristicPolynornial);
-1 -1
I'T'T
However, it is easier to use the eigenvectors () function to find all eigen-
values and the corresponding eigenvectors v[ 1] and v[ 2] .
> v:~eigenvectors(A)];
-1
v := [[1, 1, HI, 1, 1m, [T' 2, H-l, 0, 1], [-1, 1, Om]
> v[ 1]; v[ 2] ;
[1, 1, ([1, 1, 1m
-1
[T' 2, ([-1,0, 1], [-1, 1, om
Note here that the list v[ 1] contains the information related to the eigenvalue
1 and its eigenvector: This eigenvalue's multiplicity is 1, and its eigenvector is
3.4 Linear Algebra 63
1
Q:=
1
[! -~ -!]
0
> Diagona1izedA:=evalrn(inverse(Q) &* A &* Q);
10
~1 1
-1
DiagonalizedA := [ 0 T
o 0
Next, we evaluate QDIOQ-I to find the 10th power of A. As a check, we also
compute A 10 directly and see that the results agree.
> evalrn(Q &* (DiagonalizedA)A10 &* inverse (Q) ) ;
171 341 341
-
512 1024 1024
341 171 341
1024 512 1024
341 341 171
1024 1024 512
> evalrn(AA10);
171 341 341
512 1024 1024
341 171 341
-
1024 512 1024
341 341 171
1024
--
1024
-512
y =( ~I )
Yn nxl
X = (I
I
X:I)
Xn nx2
, a=(~) 2xl .
Thus, for collinear data points, we would have y - Xa = O. However, when the
data are not collinear, it is impossible to find a and b that satisfy y = Xa. In this
case one attempts to find a vector a that minimizes the Euclidean length of the
difference (deviation) lIy-Xall 2 = :L7=1[Y; - (a + bx;)j2. It can be shown [7,
Section 8.3] that the vector minimizing the deviations is given by
a = (X'X)-IX'y.
Thus, the coefficients a and b can be found by matrix algebra that involves ma-
trix inversion and matrix multiplications. This has been implemented by Maple,
as we will demonstrate.
The same technique can be generalized to fitting a polynomial of degree m, i.e.,
Y = ao + alx + ... + amxm to the n data points (XI, YI), (X2, n), ... , (xn, Yn).
In this case the X becomes an n x (m + I) matrix and a an (m + I) x I vector.
The optimal solution is again found as a = (X'X)-I X'y.
Maple's implementation of the least squares solution is provided in the fi t ()
subpackage of the stats package. Thus both of these packages must be loaded
before doing least squares computations.
> restart: # LeastSquares.mws
> with(stats); with(fit);
The next example finds the analytic solution for the coefficients a and b in
linear regression.
> solve({fa,fb},{a,b}):
66 3. Maple and Mathematical Foundations of Operations Research
n n n n
b= (~x; y;) (~I) - (~x;) (~Y;)
_(t (t (t
{
x ;)2 + X;2) I)
This is a rather impressive result since Maple was not given the specific value
of n for the number of data points. This approach can be used even for fitting data
to a higher-order polynomial such as the quadratic, cubic, etc.
H= (Z: fzx
7~
f,y
Z:)
/zz
.
In our example, I(x, y, z) = x 2yz + 3xrz and the Hessian is
> f:=x"2*y*z+3*x*y"2*z;
I := x 2 y z + 3 x rz
> hessian(f,[x,y,z));
2yz
[ 2xz+6yz
2xz+6yz 2X Y +3
6xz x 2 +6xy
r]
2xy+3r x 2 +6xy o
3.4 Linear Algebra 67
(i I),
In our example, A = [r cos(8), r sin(8)] and the Jacobian is
> A:= vector([ r*cos(theta) , r*sin(theta)));
A := [r cos(8), r sin(8)]
> jacobian (A, [ r, theta) ) ;
[ cos(8) -r sin(8) ]
sin(8) r cos(8)
> simplify(det(%));
r
Using the function I, we find its gradient VI = th, Iy , 1=] as
> grad(f, [x,y, z) );
[2xyz+3,rz, x 2 z+6xyz, x 2 y+3x,r]
o o
with assumptions on x and y
> definite(H,'positive_def');
{{z = 0, x = 0, y = On
with assumptions onz, x andy
Analytic Solutions
Example 31 Savings account. One of the simplest ordinary differential equations
arises in the modeling of growth of cash deposited in a bank account. If the ini-
tial deposit in a savings account is So dollars and the savings grows at r percent
per annwn compounded continuously, then the first-order homogeneous linear
ordinary differential equation with a constant coefficient representing the level of
savings 8(t) at time t is given by
Example 32 Van der Pol's nonlinear differential equation. One interesting ex-
ample is the well-known van der Pol equation that represents the behavior of an
electronic circuit used in radars, or the behavior of the heart; see Bellman and
Cooke [25, p. 128]. This nonlinear ODE is given by
y" - (1 -l)y' +y = 0
where the initial conditions y(O) and y'(0) must be specified. We attempt to solve
this ODE (with y(O) = 1 and y'(O) = 0) hoping for an analytic solution, but
Maple fails to produce any results. But using the type=numeric option of
dsol ve ( ) we are able to find the numerical solution for the problem.
> restart: # VanDerPol.mws
> DE:=diff(y(t),t$2)-(1-y(t)A2)*diff(y(t),t)
+y(t)=O;
[I = 1, y(t) = .4976154397782068,
-/; y(t) = -1.044238324424431]
3.5 Differential Equations 71
To plot the solution we convert the numerical solution into a function. Plotting
the solution for t e [0, 15] in Figure 3.1 indicates the periodic nature of the
solution.
> Y:=t->rhs(op(2,F(t)));
Y := t ~ rhs(op(2, F(t»)
> pIot(Y,0 •. 15);
FIGURE 3.1. Solution of van der Pol's nonlinear ODE for 0 ~ t ~ 15.
If it is known that the ODE does not have an analytic solution (or that Maple
cannot find it), then one can use an easier method to plot the numerical solution of
the ODE. This method requires loading the differential equations tools package
(DEtools) and using the DEpIot () function. Removing the "i" sign before
DEpIot () and executing the worksheet produces the same graph as obtained in
Figure 3.1.
> restart: i vanderPolDETools.rnws
> with(DEtools):
> iDEpIot(diff(y(t),t$2)-(1-y(t)A2)*diff(y(t),t)
+y(t)=0,y(t),t=0 .. 15,[[ y(O)=l,D(y) (0)=0]],
y=-3 .• 3,stepsize=.05);
sinb(%I)xoa
Sol:= { Y(/) = cosh(%I)~ - ...;ap ,
...;ap(Sinh(%I)~a- coSh~XOa)]
X(/) =
%1 :=k...;apt
We use odetest () and see that the solution found does satisfY the original
system of ODEs.
> odetest (Sol,{ System) ) ;
{OJ
Another important class of systems of ODEs that can be solved using dsol ve ( )
is the two-point boundary value problem (TPBVP) arising in optimal control ap-
plications; see Kamien and Schwartz [99] and Sethi and Thompson [169].
3.5 Differential Equations 73
subject to the state equationx(t) = u(t)-S(t), with the initial condition x (0) as a
given constant.4 The parameters h and c represent the costs of deviations from the
target levels and S(t) is the estimated sales (demand) rate. Applying the maximum
principle we find the (unconstrained) optimal production rate as u(t) = ii + A,(t)
and
x(t) = x + ~A,(t)
c
- S(t), x(O) = xo
l(t) = h[x(t) - x], A,(T) = O.
where A,(t) is the adjoint variable. This TPBVP where x(t) is specified at t = 0
and A,(t) is specified at t = T is solved by Maple as follows.
> restart: # TPBVP.rnws
We first assign values to the parameters and specify the exact form of the de-
mand rate S(t). (The parameters uH and xH correspond to uand x, respectively.)
> uH:=50; xH:=25; T:=8; h:=5; c:=l; xO:=20;
uH:= 50
xH:=25
T:=8
h :=5
c:= 1
xO:= 20
> S:=t->t* (t-4)* (t-8)+40; #plot(S(t),t=O .• T);
S := t ~ t (t - 4) (t - 8) + 40
> inventory:=diff(x(t),t)=uH+larnbda(t)/c-S(t);
inventory := f, x(t) = 10 + A,(t) - t (t - 4) (t - 8)
> adjoint:=diff(larnbda(t),t)=h* (x(t)-xH);
adjoint := %t A,(t) = 5 x(t) - 125
> sys:=inventory,adjoint;
4The dot (.) above x(t) denotes the time derivative of x(t).
74 3. Maple and Mathematical Foundations of Operations Research
> #u : =unapply(uH+lambda(t)/e,t);
where P(t) = [Po(t), ... , P4(t)], P'(t) = [PQ<t), ... , p"(t)] and
-l(t) l(t)
/J -[l(t) + /J] l(t)
Q(t) =( /J -[l(t) + /J] l(t)
/J -[l(t) + /J] l(t) ).
/J -/J
which arises in queueing analysis of computer systems; see Kao [10 I, Section
2.3]. Assuming, for example, that l(t) = lOOt (1-t) is the time-dependent arrival
rate and that /J = 7, the problem is to solve this system offive ODEs in order to
compute the transient (time-dependent) probabilities of being in different states.
ICSystem := {
pO(O) = I, pl(O) = 0, p2(0) = 0, p3(0) = 0, p4(0) = 0
}
After trying very hard, Maple fails to find the exact solution for this problem.
> #dsolve(DESystern union ICSystern,
{seq(p.i(t) ,i=O .. 4)}); #This fails
But using the type=nurneric option of dsol ve (), we can compute the s0-
lution numerically and plot the transient probability trajectory for the loss proba-
bility P4(t) as given Figure 3.2.
> F:=dsolve(DESystern union
ICSystern, [ seq (p. i (t) , i=O .. 4)] , type=nurneric) ;
F := proc(rkf45y) ... end
> F(O);
[I = 0, pO(/) = 1., pi (I) = 0, p2(/) = 0, p3(/) = 0, p4(t) = 0]
> F ( .25) ;
0.7
0.£
05
OA
0.3
0.2
0.1
It is interesting to note that the loss probability trajectory P4(/) has a shape that
resembles the time-dependent arrival rate function ..1.(1) = 100/(1 - I), which is
concave and reaching its maximum at 1 = 0.5. This resemblance is not a coin-
cidence since the increasing arrival rates result in a higher probability of a busy
system.
> pdsolve(PDE);
I e(·J+2y) eX + 4 FI(y - x)
u(x, y) = 4 ----ex--=:.-~~
Maple finds the general solution that involves an unknown function _FI(·) that
must be detennined using the initial condition.
> Sol:=combine(expand(%»;
-
Fl := x -+
4
-! e(-2x)
Thus,_FI(x) = -e- /4 and so _Fl(y - x) = _e-2y+2x /4.
2x
Example 36 Ample server queue. The following POE arises in the transient anal-
ysis of the Markovian ample server queueing system M / M /00 with exponen-
tial interarrival times (rate l) and exponential service times (rate J.l). Defining
G(z, t) = L~ Pn(t)zn as the generating function of the transient probability
Pn(t) of having n customers in the system at time I, it can be shown that G(z, I)
satisfies
aG aG
at = J.l(l - z) az - l(l - z)G(z, I)
3.5 Differential Equations 79
with the initial condition G(z, 0) = I assuming that at time I = 0 the system is
empty.
Maple solves this POE as follows.
> restart: *
AmpleServer.mws
> PDE:=diff(G(z,t),t)=mu* (l-z)*diff(G(z,t),z)
-lambda* (l-z)*G(z,t);
PDE := f, G(z, I) = Il (I - z) (;= G(z, I» -). (I - z) G(z, I)
> Sol:=pdsolve(PDE,G(z,t»;
-11l+in(-I+z) (ll)
Sol:= G(z, I) = ]I( )e P
Il
> pdetest(Sol,PDE);
o
Using the initial condition, it can be shown that the exact solution of this POE
is
- -.t(=-I)(e-'P-I)/p .
G(z, I) -e
f:= proc(n)
locali, s, I, bipow;
bipow:= proc(n) ... end;
ifl < nargs or not type(n, integer) tben 'procname'(args)
else
s := bipow(n - I);
1:=0;
fori to2dol := I +SI,; x (array(l .. 2,[(2)=1,(1)=1])); od;
I
fi
end
> f(1); f(2); f(5); f(10);
I
2
8
89
Example 38 Coin loss. In this more complicated example, consider a biased coin
for which p = Pr(Heads) and q = Pr(Tails) . The coin is tossed repeatedly and
stopped when two heads (HH) occur in succession for the first time. Ifwe let X
denote the number of such trials needed, and an = Pr(X = n), then it follows that
for n = 1,2 and 3, we have al = 0, 02 = p2, a3 = p2q as the initial conditions.
Using probabilistic arguments as in Kao [10 I, Chapter I], one can show that
Next, we solve the same problem with the' genfunc' (z) option that pro-
duces the generating fimction Px(z) of the distribution. Since the mean E(X) can
be found by differentiating the generating fimction and substituting z = 1, i.e.,
E(X) = Px(l), we find that the mean of X is E(X) = (1 + p)/ p2.
> restart:
> PXz:=rsolve({a(n)=q*a(n-l)+p*q*a(n-2),a(1)=O,
a(2)=p"2,a(3)=p"2*q} ,a,' genfunc' (z));
PXz:= _
-1+qz+ pqz2
rzl
> simplify (subs (q=l-p,normal (subs(z=l,
diff(PXz,z)))));
I+p
IT
l(s) = 10 00
e-st f(t)dt
provided that the integral exists. When f(t) is the p.d.f. of a nonnegative random
variable, l(s) = E(e-Sx ), i.e., the LT of the density is the expected value of
e-sx . Thus, it follows that f(n)(s) = (_l)n E(xne-Sx ), so the nth moment of X
is E(xn) = (_l)n f(n) (0).
Example 39 Erlang density with four stages. Consider the Erlang density with
k = 4 stages, i.e.,
le-.b (lti- I
f(t) = (k _ I)! ' t > O.
> restart: # ErlangLT.mws
> with(inttrans);
82 3. Maple and Mathematical Foundations of Operations Research
lee-AI) (It)(k-I)
f:= (k _ I)!
The LT of this density is found using laplace () as
l(s) = (_l )4
l+s
> fLT:=laplace(f,t,s);
l4
jLT:= (s + l)4
Inverting the transfonn gives the original density, as expected.
> invlaplace(fLT,s,t);
~ l4 e(-A I) t 3
6
Finally, the expected value of the Erlang is obtained as E(X) = 4/ l using the
fact that E(X) = (-I)f'(O).
> EX:=-subs(s=O,diff(fLT,s));
EX:=4±
If we were solving this problem manually, we would first find the partial fraction
expansion of the LT and then invert each tenn by referring to tables of Laplace
transfonns. We see below that by simply using the invlaplace () function on
l(s) we immediately obtain the function f(t).
> restart: # LT.mws
> with(inttrans):
> fLT:=s"3/((s+1)"2* (s-1)"3);
s3
.- ~--:-:;--:----:-:-:;"
JLT .- (s + 1)2 (s _ 1)3
3.6 Transfonn Methods 83
> PF:=convert(fLT,parfrac,s);
11 3111 I I 31
PF:=- ----+- +- +---
8 (s + 1)2 16 s + I 4 (s - 1)3 2 (s - 1)2 16 s - I
> invlaplace(PF,s,t);
Maple makes a valiant attempt to invert this LT but finds only an integral in-
volving the complementary error function erfc () and the exponential function.
Plotting the resulting function (which we do not display) reveals that f(l) ~ 0
as 1 -+ 00.
1
> for t from 0.01 to 1 by .1 do [t,evalf(f(t}},
fNumer(t}] od;
3.6 Transfonn Methods 85
Example 41 The use of rgf encode () and rgf expand (). We start with
the density of the geometric r~. an = Pr(X = n) = .0(1 - p)n, n = 0, I, ...
SSome authors (including Kleinrock [110, p.327» use the tenn ":-transfonn" for generating ftmc-
tions. Maple also ha a procedure called ztrans (), but it should not be confused with generating
functions. Maple's ztrans () is defined a ~oQn:-n , which is not used very frequendy in oper-
ations research applications.
86 3. Maple and Mathematical Foundations of Operations Research
Maple finds the generating function o(z) easily using rgf _encode ( ). To
compute the mean and variance we find 0'(1) and 0"(1) and see that E(X) =
(1- p)jp and Var(X) = (1- p)jp2.
> aGF:=rgf_encode(p* (I-p) An, n, z); *Geometric
aGF:= p
1- (1- p)z
> aGFz:=eval(diff(aGF,z),z=l);
aGFz:= -I+p
p
> aGFzz:=eval(diff(aGF,z$2),z=1);
A( 8
a z) = (2 _ z)(3 _ z)3'
6It is easy to see that since g(l) = I, this must be the generating function of a proper discrete
random variable.
3.6 Transfonn Methods 87
Finally, we also compute the mean in two different ways and find that it equals
512.
> eval(diff(aGF,z),z=I);
5
2
> sum(a*n,n=O .. infinity);
5
-2
I
an - an
Numerical I
~
r2n
I _ r2n .
Example 42 Numerical inversion ofa generating function. We invert the gener-
ating function discussed in Example 41
~( 8
a z) = (2 -z)(3 -z)3
and compare the results to what we already have obtained as the exact expressions.
> restart: * NumericalGF.mws
> v : =5;
v:=5
> aGF:=z->8/«2-z)* (3-Z)A3);
I
aGF := z ~ 8 (2 _ z) (3 _ z)3
> aNumer:=n->(I/(2*n*r An))* (aGF(r)+(-I)A n*aGF(-r)
+2* Sum ( (-1) Aj* Re (aGF(r*exp (Pi* j* I/n))), j=1. .n-l));
aNumer :=
> r:=lOA(-v/(2*n»;
r := 1O(-5/2~)
We see that for this problem the numerical inversion gives results that are very
close to what we had found in Example 41.
> seq([ n,evalf(value(aNurner(n»)] ,n=1. .25);
3.7 Probability
Maple recognizes a large number of continuous and discrete random variables
whose density function, cumulative distribution function and inverse cumulative
distribution function can be evaluated numerically. These functions are loaded
by entering the command wi th (stats) ;. By using Maple's symbolic manip-
ulation capabilities, one can also perform certain types of probabilistic analysis
such as computing expectations and finding the joint probability distribution of
functions of random variables.
Weibull. To evaluate (or plot) the density function of a continuous random vari-
able, we use s ta teval f[ pdf, name] (). To evaluate the cumulative distribu-
tion function, the first argument is replaced by edf, and to evaluate the inverse
cumulative distribution function, the first argument is replaced by iedf.
Maple also knows about the binomial, discrete uniform, hypergeometric, nega-
tive binomial and Poisson discrete random variables. To evaluate the density func-
tion of ad iscrete random variable, we use statevalf[ pf, name] (). The first
argument is replaced with dedf and idedf to evaluate the cumulative distribu-
tion and inverse cumulative distribution functions, respectively.
Detailed information about the evaluation of these functions can be obtained
with? stats.
Example 43 Normal random variable. In this example we evaluate and plot the
density, distribution function and inverse distribution function of the unit normal
random variable with mean 0 and variance 1. The density
1
5
I 2
f(x} = e -'1. X • -oo<x<oo
1.51
1
I
j .. _-_..-..__.._-_.
.•........ ...../ -
0.. . .!
~~ ; ..
-3 -2 -1 • i 1 x 2 3
i
-0.5 !
I
:
!
-1 !
:
-1.5/
FIGURE 3.3. The density f(x), cumulative distribution function F(x) and inverse cumu-
lative distribution function F-I (x) of the unit nonnal random variable drawn as a solid
line, dotted line and dashed line, respectively.
0.8
0,,(,
OA
0.2
0~~~~~2~~~3~~4~~T5~~'~~7~~8
n
FIGURE 3.4. The density p(n) and the cumulative distribution function P(n) of Poisson
with parameter l = 3 drawn as a solid line and a dotted line, respectively.
. 1008188134
.9160820583
3.
> pPlot:=plot(p(floor(n)),n=O •. 8,linestyle=1,
color=black,thickness=2) :
> PPlot:=plot(P(floor(n)),n=O .. 8,linestyle=2,
color=black,thickness=2):
> with(plots):
> display ([ pPlot, PPlot] ) ;
> #plot(iP(n),n=O .. 1,O •. 8):
In addition to the nearly 20 frequently used distributions, Maple also allows the
definition of arbitrary discrete empirical distributions defined over the integers
1, ... , N. This is made possible by using the empirical command.
3.7.2 Expectation
Since the computation of moments of a random variable requires evaluating inte-
grals or sums, Maple is well suited for performing such operations.
Example 46 Mean and the variance ofthe normal distribution. For example, let
us consider the normally distributed random variable X with parameters Jl and (12
and compute its mean E(X) and variance Var(X).
> restart:. NormalMoments.mws
> interfaee(showassumed=2); assume(sigma>O);
> f:=(l/(sigma* (2*Pi)A(1/2)))*exp(-(x-mu)A21
(2* sigma A2));
I v'2e(-1/2~)
f := 1. (1 ,.fii
with assumptions on (1
> Int(f,x=-infinity •• infinity);
3.7 Probability 93
1 00
-002
1 J2e(-)!2~)
-
(1-JiC
dx
with assumptions on (1
Maple easily evaluates the integral of density and finds the result as I. It also
finds that E(X) = f.l and Var(X) = (12.
> value(%);
VarX:= (12
with assumptions on (1
Example 47 A discrete random variable takingjinitely many values. Suppose a
random variable X takes the value x with probability ax, x = I, ... , N. We wish
to find the mean E(X) and variance Var(X) after detennining the proper value of
a.
> restart: * Expectation.mws
> f:=a*x;
!:=ax
> a:=solve(sum(a*x,x=l •• N)=l,a);
1
a :=2 N(N + I)
Thus, a is found to be2/[N(N + I)].
> f;
x
2 N(N + I)
> EX:=normal(sum(x*f,x=l .• N));
2 1
EX:=3"N+3"
> EX2:=normal(sum(x A2*f,x=1 .. N));
I
EX2 := "2 N (N + I)
> VarX:=normal(EX2-EX A2);
1 2 1 1
VarX := 18 N + 18 N - 9
94 3. Maple and Mathematical Foundations of Operations Research
p:= l a
b
-1--2 dx
+x
c
To do this, we solve J:
c(a, b)(l + x 2 )-1 dx = I for c(a, b) and find that
c(a, b) = [arctan(b)-arctan(a)r l . When x e (-I, I), we havec(-I, I) = 211C
and when x e (-00, 00), we obtain c( -00, 00) = II 1C which gives the Cauchy
density
I
f(x) = 1C(l +x2)' -00 < x < 00.
> c:=solve(value(p)=l,c);
I
c·-------------~
.- arctan(b) - arctan(a)
> lirnit(limit(c,b=l),a=-l);
2.!.
1C
> lirnit(limit(c,b=infinity),a=-infinity);
1C
The fact that the Cauchy density has no expected value can be shown as follows.
We write E(X) = i-oo x f(x) dx + Iaoo xf(x) dx . The second integral evaluates
to ~ In(l +02), which diverges to infinity as a ~ 00. Thus, E(X) does not exist.
> f:=l/(Pi* (1+x"2));
I
f:= 1C 0 +x2)
> Integral[ 2] : =Int (x* f, x=O .. a) ;
value (Integral[ 2] );
[nJegral2 := loa 1C 0 : x 2) dx
I InO +a2 )
2 1C
> lirnit(%,a=infinity);
00
3.7 Probability 95
where
J(u, v) = det (iiou ~)
iJo
is the determinant of the Jacobian of the transformation; see Harris [82, p. 169]
and Stirzaker [181, p. 270].
Example 49 Joint distribution ofa random vector. We assume that the joint den-
sity of the random vector (X, Y) is fx,Y(x,y) =
12 e -Ax e -Ay, i.e., X and Yare
individually distributed as exponential random variables with parameter I .
> restart: # JointDensity.rnws
> with (linalg) :
Warning, new definition for norm
> J:=det(%);
J:=-u
> fXY(x,y)*abs(J);
,l2 e(-Ao II) e(-·HII-olI» lui
Applying (3.3) gives fu,v(u, v) = ,l2e-Alllul, u > 0, which integrates to I, as
expected.
> fUV:=sirnplify(%);
jUV := ,l2 e (-AII) lui
> int(fUV,u=O • • infinity);
3.8 Summary
Modeling and solution of many operations research problems requires a knowl-
edge of a wide spectrwn of mathematical topics such as algebra and calculus,
linear algebra, differential equations, transfonn methods and probability theory.
This chapter covered these topics and their treatment with Maple. We surveyed
these mathematical topics by providing a large number of examples. With the
detailed explanation of the useful mathematical techniques as presented in this
chapter, we are now ready to begin our study of OR techniques and models.
3.9 Exercises
I. Find the values of x that satisfy the inequality x 2 + x + 1 ~ 3. Check your
result by comparing the plots of x 2 + x + 1 and 3 on the same graph.
5. Consider the function G(u) = I: f6(u -x)dx + I~o f6(x - u)dx. Find
the derivative of this function in two different ways and locate the point that
minimizes G(u).
A [~ ~ ~6]' b ~
=
3 6 -9
= [
0
]
has a unique solution by comparing the ranks ofr(A) and r(A I b). If the
system has a unique solution, find it by (i) evaluating A-\ b, and (ii) using
linsol ve ( ) .
p=[t tJ
after diagonalizing it. Does your result agree with ptO obtained directly?
A( )
az =----~
18
(3 - z)(4 - z)2
using rgf _expand () to find the sequence a". Is the resulting sequence
a probability density of a discrete random variable? If it is, find its mean
using two different methods.
14. Consider two random variables X and Y with joint density given by f(x, y)
= e-(x+y) for 0 < x < 00 and 0 < y < 00 and zero otherwise. Find the
distribution function and the density of the ratio XI Y.
15. The Euclidean distance R of a random point (X, Y) from the origin is given
by R = JX2 + y2. If the joint density of (X, Y) is f(x, y) = 1/(1rz?) for
x 2 + y2 ~ u 2 and zero otherwise, find the mean distance E(R).
17. Consider two random variables X and Y distributed jointly with density
f(x,y) = 21rIU 2 exp ( x22:t) , - 00 <x < 00, - 00 <y < 00.
4.1 Introduction
Linear programming (LP) is a flexible and powerful optimization technique that is
used to detennine the nonnegative values of n decision variables x j, which satisfy
m linear constraints
n
LaijXj{~,=,~}bi' ;= 1,2, . .. ,m
j=)
IIn late 1930s the Russian mathematician Kantorovich [100] had, however, studied linear program-
ming models for production planning.
Any textbook on operations research published since the 1950s has at least one
chapter describing LP. Linear programming is now a very important and estab-
lished branch of operations research that has found wide applicability in business
and governmental decisions.
Despite the mathematical nature of the simplex method, which requires a good
understanding of linear algebra, LP has become one of the most useful operations
research techniques and is frequently used by practitioners-perhaps due to the
proliferation of easy-to-use PC software such as LINDO and the inclusion of the
simplex algorithm in almost every spreadsheet software such as Excel and Quat-
troPro. A recent survey by Lane, Mansour and Harpell [116] indicates that along
with simulation and statistical methods, LP has found its way as an important
technique into the practitioner's toolkit of analytical methods.
In this chapter, we will briefly describe the mathematics of the simplex method
and present some examples of LP modeling and solution using Maple. Since LP
problems cannot be solved symbolically (i.e., the parameters ajj, bj and Cj must
be real nwnbers), Maple's symbolic manipulation capabilities will not be used in
this chapter. However, since Maple can plot regions of linear inequalities with the
command inequal ( ) , this plotting feature will be very useful in identifying the
feasible region and the optimal solution of an LP with n = 2 decision variables.
In this simple case, it is possible to plot the feasible region F (i.e., the set of all
points (XI, X2) satisfYing all constraints) and find the point that maximizes the
objective function z = 30xI + 40X2. We do this using Maple's inequal ( )
function that can plot linear inequalities and hence the feasible region F.
At this point we introduce the concepts of a convex set and an extreme point
that play an important role in the theory of linear programming.
Definition 1 A set:F is said to be convex if, for any two points x I, X2 E :F, tire line
segmentjoining the two points lies entirely within the set, i.e., .hI +(I-l)X2 E :F
forO~l~1.
Intuitively, a convex set cannot have any "holes" in it and its boundaries are
always "flat" or "bent away" from the set, as we will see in the current example.
Definition 2 A point x is said to be an extreme point ofa convex set if and only
if there do not exist other points XI, X2 (XI i= X2) in the set such that X = Axl +
(I - l)x2for 0 < l < I.
Intuitively, an extreme point cannot be "between" any other two points of the
set.
We start by introducing the constraints, which are placed in a list named CS
(Constraint Set). The feasible region is plotted (but not yet displayed) using the
inequal () function. We also plot-but do not yet display-three iso-profit
lines corresponding to profit levels of z = 1200, 2400 and 3600. These lines will
be useful when we attempt to identifY the optimal solution. The feasible region :F
(and the iso-profit lines) are displayed with the display () command. We find
that the feasible region is a convex set bounded by the lines X2 = 0, XI = 90,
5xI + 6X2 = 600, X2 = 60 and XI = 0 with the comer points at 0, A, B, C and D.
> restart: # ToyLP.mws
> with (plots) :
> CS: ={ xC 1] <=90, xC 2] <=60,5* xC 1] +6* xC 2] <=600,
xC 1] >=0, xC 2] >=0] i
CS:= [XI ~ 90, X2 ~ 60, 5xI +6X2 ~ 600, 0 ~ XI, 0 ~ X2]
> FeasibleRegion:=inequal(CS, xC 1]=0 •• 120,
xC 2)=0 .• 120,optionsfeasible=(color=white),
optionsexcluded=(color=yellow)):
102 4. Linear Programming
120
FIGURE 4.1. The feasible region with extreme points 0, A, B, C and D and the iso-profit
=
lines for z 1200,2400 and 3600.
°
Returning to our problem, we observe that the extreme points of the feasible
region----except the uninteresting point at the origin where there is no produc-
tion activity-are easily computed by Maple as follows.
> with(sirnplex):
Warning, new definition for display
Although in this example it was not too difficult to examine each extreme point
individually and find the optimal solution, this method is not very efficient if com-
putations are being performed manually. In problems with several constraints, the
number of extreme points may be quite large, which makes the computation of
the coordinates of the extreme points and the corresponding profit values unnec-
essarily cumbersome. In those cases, it would be preferable to use a visual method
whereby an iso-profit line is drawn on the feasible region for an arbitrary value of
z and moved in a direction to maximize the profit.
We start by arbitrarily assigning a fixed value to the daily profit z, say, z =
1200, and ask whether it is possible to find at least one feasible production com-
104 4. Linear Programming
bination (XI, X2) that gives rise to the value of z = 1200. We see in Figure 4.1
that for z = 1200, the lowest iso-profit line passes through the points (40,0) and
(0, 30), and hence eve!)' point between and including these points gives a profit
ofz = 1200.
Increasing the value of z (say, doubling it to 2400) and redrawing the line, we
see that it is still possible to find some feasible production combinations. Hence,
by visual inspection (perhaps by using a ruler and sliding it upward parallel to the
first two iso-profit lines) we find that the optimal point must be at the intersection
of the boundary lines 5xI + 6X2 = 600 and X2 = 60. Since the solution of this
system can be found easily, we conclude that the optimal result is at point C with
coordinates XI = 48 and X2 = 60 with a maximum profit of z = 3840. It is
important to note that with the iso-profit line method it is not necessary to solve
for the coordinates of eve!)' extreme point. Once we visually identify the optimal
extreme point, its coordinates can then be found by solving a system of two linear
equations in X I and X2. '
It should be clear that when there are only n = 2 decision variables, this
graphical method (while cumbersome) can always be used to locate the opti-
mal solution-when it exists. If there are n = 3 decision variables, the graphical
method can stilI be used but it becomes vel)' difficult to identify the feasible re-
gion as it becomes a solid geometrical figure (a polytope) bounded by planes in
three dimensions. When there are four or more variables, the graphical method
can no longer be used to find the optimal solution since it becomes impossible
to plot objects in dimensions higher than three. Real-life models that may have
thousands of variables and constraints are commonly solved using the simplex
method.
It is usually assumed that the slack variables make no contribution to the ob-
jective function nor do they result in any cost. Thus, in this example X3, X4 and
xs appear in the objective function with zero coefficients. Of course, if there is
a profit or cost associated with the slack variables it should be reflected in the
objective function. See Ignizio [96, p. 115] for a more detailed discussion of this
issue.
Note that the constraint equations XI + X3 = 90, X2 + X4 = 60 and SXI +
6X2 + XS = 600 form a system of m = 3 equations in n = 5 unknowns. Thus,
the optimal solution of the optimization problem must be a solution to this set
of linear equations. But since m < n, this system will have an infinite number of
solutions.2 However, in the simplex method only a finite number of these solutions
(known as the basic solution set) will be of interest.
Given a system Ax = b, we may select any m x m nonsingular submatrix of A
(termed the basis matrix), set the remaining n - m nonbasic variables to zero and
solve the resulting system for the m basic variables. This gives a basic solution
denoted by XB.
Denoting the basis matrix by B, the resulting system after setting n - m vari-
ables to zero may be written as BXB = b or XB = B- 1b. Thus, finding the basic
solution XB involves a matrix inversion that can be easily performed by Maple.
Since the decision variables must be nonnegative, the simplex method examines
only the basic feasible points for which XB ~ O. We see that the number of basic
solutions must be limited by n!J[m!(n - m)!] since this is the number of combi-
nations of n variables taken m at a time. For example, as we will show, the toy
manufacturing problem with n = 5 and m = 3 has a total of eight basic solutions,
which is less than the maximum possible of5!J[3!(S - 3)!] = 10.
Suppose we set X4 = XS = o. In this case the basic variables would be XI, X2
and X3 for which the basis matrix B and the basis XB are obtained as follows.
> restart: # BasicSols.rnws
> with (linalg) :
Warning, new definition for norm
=
2More accurately, if the system AI b is consistent (i.e., the rank of the coefficient matrix, r(A),
is equal to the rank of the augmented matrix, r(A I b» and ifr(A) < n, then the system has an infinite
number of solutions; see Ignizio [96, Chapter 3].
106 4. Linear Programming
1 0 I 00]
A := [ 0 I 0 I 0
5 600 I
> b:=evalm(RHS);
b := [90, 60, 600]
> for j from 1 to 5 do a[ j] :=col (A, j) od:
> B:=augment(a[ 1] ,a[ 2] ,a[ 3]);
B = ( 05I 00I 0)
0
I
whose inverse does not exist since X2 + X4 = 0 + 0 =F 60.
> B:=augment (a[ 1] ,a[ 3] ,a[ 5] ) ;
10
B:= [ 0 1
5 6
> xB:=evalm(inverse(B) &* b);
xB:= [90, 60, -210]
The following table swnmarizes results for all possible solutions, some of which
do not exist and some of which are infeasible. The five comer points 0, A, B, C
and D as shown in Figure 4.1 are indicated in the first colwnn labelled "POINTS."
POINTS,!. Xl X2 X3 X4 xs PROPERTY
1 (C) 48 60 42 0 0 Feasible
2 (B) 90 25 0 35 0 Feasible
3 90 60 0 0 -210 Infeasible
4 120 0 -30 60 0 Infeasible
5 ? 0 ? 0 ? Singular B
6 (A) 90 0 0 60 150 Feasible
7 0 100 90 -40 0 Infeasible
8 (D) 0 60 90 0 240 Feasible
9 0 ? 0 ? ? Singular B
10(0) 0 0 90 60 600 Feasible
Essentially, the simplex method locates the optimal solution by examining only
a small fraction of the basic feasible solution generated using the procedure de-
scribed. It is well known that most linear programming problems are solved within
the range of 105m to 3m iterations (i.e., comer point evaluations) where m is the
nwnber of constraints; see Wagner [190, p. 116].
10 I 0 0 ]
A := [ 0 I 0 I 0
5 600 I
> b:=evalm(RHS);
b := [90, 60, 600]
> c:=vector (5,[ 30,40,0,0,0] );
C := [30, 40, 0, 0, 0]
Next, we fonn a basis matrix B from A by using the last three columns in the
order B = [a3, 84, as]. Thus, bl = a3, h2 = 84 and b3 = as.
> ft a[ 3], a[ 4] and a[ 5] are in basis
> for j from 1 to 5 do a[ j] :=col(A,j) od:
> B:=augment(a[ 3] ,a[ 4] ,a[ 5]):
B := [~0 0~ 1~]
The basic solution XB = (XBI,XB2,XB3)' = (X3, X4, xs)' given by this basis
matrix B is found as XB = B-1 b = (90,60,600)'. This implies that if XI = X2 =
0, then X3 = 90, X4 = 60 and xs = 600; i.e., if nothing is produced, then there
will be an idle capacity of 90 units and 60 units in the car department and train
department, respectively. With no production, the 600 parts will also not be used.
This corresponds to Point 0 in Figure 4.1.
The basic solution XB is also associated with a I xm vector(B = (CBI, CB2, ••• ,
CBm) of the objective function coefficients of the basic variables X B I , X B2, ..• ,
XBm. In this example, (B = (0,0,0) since the coefficients of the slack variables
are all zero. Hence, given a basic feasible solution XB ~ 0, the value of the ob-
jective function, z, is found as z = (BXB . In our case, we find z = 0 since
(B = (0,0,0) and "B = (90,60,600)'.
> xB:=evalm(inverse(B) &* b);
xB := [90, 60, 600]
> cB: =vector ( 3, [ c[ 3] ,C[ 4] ,C[ 5]] ) ;
cB := [0, 0, 0]
> z:=evalm(cB &* xB);
z :=0
4.3 The Simplex Method 109
Since the basis matrix B consists of linearly independent vectors bl, h7, ... , bm ,
any column 8j of the coefficient matrix can be written as a linear combination of
the columns ofB, i.e.,
m
8j = LY;jb;
;=1
= BYj
where Yj = (Ylj,Y2j, . . . ,Ymj )'. Since the inverse ofB exists, we can also write
Yj = B- 18 j. In our example we find YI = (I, 0, 5)' and Y2 = (0, I, 6)'. Note that
the entries of the Yj vectors correspond to an amount by which a basic variable's
value will change if one unit of a nonbasic variable x j is introduced into the
solution. For example, if we decide to produce one car (i.e., increase XI from to °
I while keeping X2 at 0), then YI3 = 5 implies that the value of xs will be reduced
by 5 units since
ZI :=0
Z2:=0
Now we are faced with the important question of improving the currently avail-
able solution. To do this we define Cj - Zj as the net contribution resulting from
introducing one unit of a nonbasic variable x j into the solution. The x j that gives
the highest Cj - Z j value is chosen as a new basic variable. (Ties can be broken
arbitrarily.) In our example, we see that since CI - ZI = 30 and C2 - Z2 = 40, we
decide to make X2 a new basic variable-i.e., include the column vector 82 in the
basis matrix ~and assign X2 the highest possible value in order to increase the
profit Z as much as possible.
110 4. Linear Programming
> c[ 1] - z[ 1]; c[ 2] - z[ 2] ;
30
40
> .. So, a{ 2] enters
However, this cannot be done arbitrarily. For example, the parts constraint is
5XI + 6X2 + XS = 600, which can be written as xs = 600 - 6X2 since XI = o.
Thus, the highest possible value that X2 can take without making xs infeasible is
600/6 = 100. But recalling that the train production constraint was X2 + X4 = 60,
or X4 = 60 - X2, we see that the value of X2 = 100 cannot be allowed. Thus, the
highest value that X2 can take would be 60 units, which is the minimum of the two
ratios 60/1 = 60 for X4 and 600/6 = 100 for xs.
These results can be summarized using a table that indicates that the nonbasic
variable X2 should enter the basis and X4 should leave the basis (i.e., the vector a2
should replace the vector 84 in the basis matrix B).
XI X2 X3 X4 xs
Basis Cj 30 40 0 0 0 b Ratio
X3 0 1 0 1 0 0 90 -
X4 0 0 I 0 1 0 60 60/1 = 60 (out)
xs 0 5 6 0 0 1 600 600/6 = 100
Zj 0 0 0 0 0
Cj -Zj 30 40 0 0 0 0
(in)
> i f y( 2] [ 1] >0 then print (xB[ 1] Iy( 2] [ 1]) else
print("No Ratio") fi;
''No Ratio"
> if y( 2] [ 2] >0 then print (xB[ 2] Iy( 2] [ 2]) else
print("No Ratio") fi;
60
> i f y( 2] [ 3] >0 then print (xB[ 3] Iy( 2] [ 3]) else
print("No Ratio") fi;
100
> .. So, a{ 4] leaves
This example suggests that the column (say, b,.) of the basis matrix B that
should be replaced by a j is the one that satisfies
XBr
Yrj
= min (XBi,
I Yij
Yij > 0). (4.1)
The rest of the Maple worksheet implements the simplex procedure until the
optimal solution is reached. Now with (a3. a2, as) in the basis, we find that IB =
(X3, X2. xs) = (90,60,240)' with an objective fimction value as Z = 30 x 0 +
40 x 60 = 2400 since Xl = 0 and X2 = 60. This corresponds to Point D in Figure
4.1.
4.3 The Simplex Method III
B:= [~o 6~ ~]
1
> xB:=evalm(inverse(B) &* b);
xB := [90, 60, 240]
> cB:=vector (3,[ c[ 3] , c[ 2] , c[ 5]] ) ;
cB := [0, 40, 0]
> z:=evalm(cB &* xB);
z:= 2400
> y[ 1] : =evalm (inverse (B) &* a[ 1] ) ;
y[ 3] :=evalm(inverse (B) &* a[ 3] );
YI := [I, 0, 5]
Y3 := [1,0, 0]
> z[ 1] :=evalm(cB &* y[ 1] );
z[ 3] :=evalm(cB &* y[ 3] );
ZI := 0
Z3 :=0
> c[ 1] - z[ 1]; c[ 3] - z[ 3] ;
30
o
In this iteration we find that al should enter and as should leave the basis.
> ..So, a[ 1] enters
> if y[ 1] [ 1] >0 then print (xB[ 1] /y[ 1] [ 1]) else
print("No Ratio") fi.
90
> if y[ 1] [ 2] >0 then print (xB[ 2] /y[ 1] [ 2]) else
print("No Ratio") fi;
"No Ratio"
> if y[ 1] [ 3] >0 then print (xB[ 3] /y[ 1] [ 3]) else
print("No Ratio") fi;
48
> .. So, a[ 5] leaves
Now, with (a3, a2, al) in the basis, the basis vector is found as llB = (X3, X2, XI)
= (42,60,48), which gives rise to an objective function value of Z = 30 x 48 +
40 x 60 = 3840 since XI = 48 and X2 = 60. This corresponds to Point C in
Figure 4.1.
> B:=augment(a[ 3],a[ 2],a[ 1]);
112 4. Linear Programming
oI 1]
0
6 5
> xB:=evalm(inverse(B) &* b);
xB := [42, 60, 48]
> cB: =vector ( 3, [ c[ 3] ,C[ 2] ,C[ 1] ] ) ;
cB := [0, 40, 30]
> z:=evalm(cB &* xB);
z:= 3840
> y[ 4] :=evalm(inverse (B) &* a[ 4] );
y[ 5] : =evalm (inverse (B) &* a[ 5] ) ;
Y4 := [~, I, ~1
YS := [~I ,0, ~J
> z[ 4] :=evalm(cB &* y[ 4] );
z[ 5] :=evalm(cB &* y[ 5]);
Z4 :=4
ZS :=6
We also find that C4 - Z4 = -4 and cs - zs = -6. This implies that we have
found the optimal solution since introducing any of the nonbasic variables (X4 or
xs) back into the basis would lower the objective function.
> c[ 4] - z[ 4]; c[ 5] - z[ 5] ;
-4
-6
> * Optimal solution reached!
In summary, the optimal solution is to produce XI = 48 cars and X2 = 60 trains
that would result in a maximum profit of Z = $3840. The final simplex table
follows.
XI X2 X3 X4 xs
Basis c· 30 40 0 0 0 b
X3 0 0 0 I 6/5 -1/5 42
X2 40 0 I 0 I 0 60
XI 30 I 0 0 -6/5 1/5 48
30 40 U 4
~~ 3840
Zj
Cj -Zj 0 0 0 -4 -6
4.3 The Simplex Method 113
maximize: eqns =
maximize : trans =
114 4. Linear Programming
{}
simplex/max: eqns = [_SL1 = 90-x[ 1), _SL2 = 60-x[ 2) ,
_SL3 =600-5*x[ 1) -6* x[ 2))
XI
_SLl =90-XI
I 5
eqns =, [XI = - _SLl + 90, _SL2 = 35 + 6_SL3 - 6_SL1,
I 5
X2 = -- SL3 + 25 + - SLl]
6- 6-
. to 20
obJ =, 3" _SLl + 3700 - 3" _SL3
pivot variable =, _SLl
Pivot equation =, - SL2 = 35 +!6-SL3 - 5 SLl
-6 -
simplex[ pivot) working on
4.3 The Simplex Method 115
I 5
[XI = -_SLJ + 90, _SL2 = 35 + -6-SL3 - - SLJ
6-'
I 5
X2 = -6 _SL3 + 25 + 6_SLJ]
SLJ
I 5
SL2 = 35 + - SL3 - - SLJ
- 6- 6-
simplex/max: tttttt final description tttilt
6 I 6 I
eqns =, [XI = -5 - SL2 + 48 - -5-SL3, - SLJ = --
5-SL2 + 42 + -5 - SL3,
X2 = 60 - _SL2]
6 I
XI = - SL2+48-- SL3
5- 5-
6 I
_SLI = -- SL2 +42 + - SL3
5- 5-
X2 = 60- SL2.
6 I
XI - -X4 + -xs = 48
5 5
X2+X4 = 60
6 I
X) + -X4 - -xs = 42.
5 5
116 4. Linear Programming
This is exactly the same set of equations that is implied by the infonnation pre-
sented in the final table at the end of Section 4.3.1. Moreover, infonnation about
the objective function that is given as obj =, -4_SL2 + 3840 - 6_SL3 corre-
sponds to the Cj - Zj row in the final simplex table: If _S L2(= X4) is made a basic
variable, the objective function decreases by $4 and if_SL3(= xs) is made a basic
variable, the objective function decreases by $6. Since _SL2 = 0 and _SL3 = 0
in the optimal solution, the maximum value of the objective is Z = $3840.
Using the graphical method, it can be shown that this problem has the optimal
solution where XI = 10, X2 = 0 with the minimum value of the objective function
Z =20.
If we want to solve this problem using the "manual" version of the simplex
method as demonstrated in Section 4.3.1, we need to convert the inequalities to
equalities. The first constraint is converted by introducing a slack variable, say,
X3 ~ 0, which results in X I + 5X2 + X3 = 80. By introducing a "surplus" variable,
say, X4 ~ 0, and subtracting it from the left-hand side of the second constraint,
we obtain 4xI + 2x2 - X4 = 20. Since the last constraint is already an equality,
we obtain the linear system and the objective function as
in the following coefficient matrix A with columns (a I, a2, a), 114, as, 116).
= 80
- X4 + xs = 20
+ X6 = lO
=
It is now easy to see that the initial basis matrix can be chosen as B (a), as, 116),
which results in the initial solution of XB = = =
B- 1b (X), xs, X6) (80,20, 10).
But we note that the artificial variables must eventually be eliminated from the
basis, i.e., they must be forced to take a value of 0 in the optimal solution. In order
to assure this outcome, we assign a very high cost of keeping these variables in
the solution. That is, we rewrite the objective function as
and solve this problem as a maximization. We leave the solution of this problem
to the reader as an exercise.
Fortunately, if Maple is used to solve this problem with the simplex pack-
age, there is obviously no need to introduce the slack, surplus or the artificial
variables as Maple takes care of this step automatically. Following is the solu-
tion using simplex where we have chosen to minimize the original objective
function min z = 2x1 + 4X2.
> restart: *
MixedConstraints.mws
> with(simplex}:
Warning, new definition for maximize
3The "big" M could be approximately ten times larger than the largest parameter in the problem.
118 4. Linear Programming
4.4.1 Infoasibility
It is sometimes possible to formulate LP problems that do not have any feasible
points! As an example, consider the following formulation and an attempt to solve
the problem using Maple.
> restart: # Infeasible.rnws
> with (sirnplex) :
Warning, new definition for maximize
*
In this case Maple does not even attempt to make a statement about the exis-
tence of the solution and gives Sol: =. If the symbol before infolevel[ sim-
plex] statement is removed and the problem is solved again, one would see that
Maple correctly identifies the unboundedness of the solution and flags it.
4.4.3 Degeneracy
Normally, in an LP problem with m constraints, the optimal basis consists of m
basic feasible variables all assuming strictly positive values. In some "degenerate"
cases, the optimal basis may contain fewer than m positive basic variables as the
following example demonstrates.
> restart: * Degeneracy.mws
> with (simplex) :
Warning, new definition for maximize
2 1 2 1
eqns =, LSLl = 3" _SL2 + 3"XI' X2 = -3"XI - 3" _SL2 + 10,
2 1
- SLJ = -XI
3 + -3-SL2]
obj =, -2_SL2+6O-2xl
Sol := {XI = 0, X2 = IO}
> assign(Sol); z;
60
Thus, in this case with m = 3 constraints, we would expect three basic variables
taking strictly positive values. But as we see in the final simplex table, the optimal
basis consists of the variables LSL1,X2,_SL3) = (0,10,0). Thus, two basic
variables are equal to zero, implying degeneracy.
Unlike the cases of infeasibility and unboundedness, problems having a degen-
erate solution do not present any serious difficulties. In the simplex method of
solution, degeneracy arises when the ratio test (4.1) produces a result whereby
the minimum ratio is not unique and the variable that is to leave the basis is not
immediately obvious. In such a case an arbitrary choice is made and the ties are
broken according to a specific rule such as choosing the variable with largest Yij
or selecting the variable with the smallest i index. For a good discussion of this
issue, see the classical text by Hadley [79, p. 113].
we considered problems with only a few variables and constraints, the examples
in this section involve problems that can potentially have a very large number of
variables and constraints.
To solve this problem as a linear program, we define Xij as the munber of units
shipped from factory i to warehouse j for factories; = I, ... , m and warehouses
j = I, ... , n. Thus, the LP model of the transportation problem takes the follow-
ing fonn:
m n
min LL CijXij
i=1 j=1
subject to
n
LXij = Si, ; = I, ... ,m
j=1
m
LXij = db j = I, ... ,n
j=1
122 4. Linear Programming
subject to
19
13 7
8]
c := [ 15 21
18 6
II 3
12 20
> z:=sum(sum(c[ i,j] *x[ i,j] ,j=1. .n) ,i=1. .m):
> s:=array([ 100,300,200] ); sum(s[ i] ,i=1. .m);
S := [100, 300, 200]
600
4.5 Other Examples 123
Sol:= {XI, I = 0, XI,2 = 0, X3,4 = 0, XI,4 = 0, X2,2 = 0, XI,3 = 100, X3,3 = 100,
X3,2 = 100, X2,3 = 0, X3,I = 0, X2,I = ISO, X2,4 = ISO}
> assign (Sol) :
> z;
5950
Thus, the optimal solution is obtained with a minimum cost of z = $5, 950. We
summarize the optimal solution in the following table.
dummy origin with an artificial supply equal ~j=1 dj - ~~I Si, the difference
between the total demand and total supply. The optimal "shipment" amounts from
the dummy origin to a particular destination would then correspond to the amount
by which the destination's demand is unsatisfied.
When the number of origins and destinations is not excessively large, moderate-
size transportation problems can be solved using the simplex package. But for
a realistic problem with, say, m = 200 origins and n = 500 destinations, we
would have m + n = 700 constraints (less one due to redundancy) and m x n =
100000 variables! Thus, to solve these problems one would need more efficient
procedures. Such special-purpose procedures for solving transportation problems
indeed exist, but they have not been implemented by Maple. For a discussion of
these procedures see, for example, HiHier and Lieberman [92, Chapter 7].
as
m
EI = LX;Yjp;j.
;=1
We now assume that PI will choose XI, ... , Xm in such a way that regardless of
how P2 chooses YI, ... , Yn, the gain to PI is at least equal to some value v where
v is to be made as large as possible. Thus, PI should choose XI, ... , Xm such that
m
LX;P;j ~ v, j = I, ... ,n
;=1
and that v is maximized. Note that the variable v is, in general, unrestricted in
sign. Additionally, since the XI, ... , Xm constitute a probability distribution, we
must have L7=1 X; = I with X; ~ 0,; = 1, ... , m.
For example, in the case of the coin-matching game, PI's problem would be to
max v
s.t. XI - X2 ~ v
-XI +X2 ~ v (4.2)
XI +X2 I =
XI,X2 ~ 0
where v is unrestricted in sign. Solving this problem (as we show below using
Maple) gives the optimal solution as XI = X2 = and v = o. !
Now considering P2's problem, we see that by using the same arguments em-
ployed for PI's strategy, P2 would choose YI, ... , Yn so that the gain to PI is at
most equal to some value u where u is to be made as small as possible where
variable u is, in general, unrestricted in sign. (Note that minimizing the gain to
PI maximizes P2's gain in zero-sum games.) Thus, P2 should choose YI, ... , Yn
such that
n
LYjP;j~U, ;=I, ... ,m
j=1
and that u is minimized. As before, since the YI, ... , Yn constitute a probability
distribution, we must have Lj=1 Yj = I with Yj ~ 0, j = 1, ... , n.
For the case of the coin-matching game, P2's problem would be to
min u
s.t. YI - Y2 ~ u
-YI + Y2 ~ u (4.3)
YI+Y2=1
YI,Y2 ~ 0
where u is unrestricted in sign. Solving this problem (as follows) gives the optimal
!
solution as YI = Y2 = and u = O. Hence, for this game the maximum PI can
expect to gain is equal to the minimum P2 can expect to lose, that is, u = v.
126 4. Linear Programming
The following Maple worksheet solves this simple coin-matching game for
each player. Note that the variables v and u in the first problem and second
problem, respectively, are allowed to take any positive or negative value since
they are not restricted. Normally, such unrestricted variables must be represented
as the difference of two nonnegative variables in a problem formulation, e.g.,
u = u' - u" where u' ::: 0 and u" ::: O. If the option NONNEGATIVE is not
included in simplex, all variables are asswned to be unrestricted in sign by
default-unless otherwise indicated as in { seq (x[ iJ >=0, i=1. .m)} .
> restart: * CoinTossGame.mws
> with (simplex) :
Warning, new definition for maximize
P:= [ 1-I]
-I 1
> m:=2; n:=2;
m:=2
n :=2
> * Player l' s problem
> for j from 1 to n do
Player1[ j] : =add (x[ iJ * p[ i, j] , i=1. .m) >=v od;
Playerl l := v ~ XI - X2
Player12 := v ~ -XI + X2
> Unity:=add(x[ iJ ,i=1..m)=l;
Unity:= XI +X2 = 1
> maximize (v,{ seq (Player1[ j] ,j=1. .n)} union
{Unity} union { seq(x[ iJ >=0, i=1. .m)} );
1 1
{X2 = 2' XI = 2' v = O}
> * Player 2' s problem
> for i from 1 to m do
Player2[ i] : =add(y[ j]*P[ i,jJ ,j=1..n)<=u od;
Player2 1 := YI - Y2 ~ u
Player22 := -YI + Y2 ~ u
> Unity:=add(y[ j] ,j=1. .n)=l;
Unity := YI + Y2 = 1
> minimize (u, { seq (Player2[ i) , i=1. .m)} union
{Unity} union {seq(y[ j] >=O,j=1. .n)} );
4.5 Other Examples 127
I I
{u = 0, Y2 = -, YI = -}
2 2
AM AA EM EA EE
MMM XI
I~
60
Y2
45
13
45
Y4
35
Y5
20
Y6
35
AMM X2 65 60 45 50 35 50
AAM Xl 55 65 60 40 50 50
AAA X4 55 55 65 30 40 40
EMM X5 75 70 70 60 45 35
EAM X6 80 75 70 65 60 50
EAA X7 80 80 75 55 65 40
EEM X8 65 60 70 75 70 60
EEA X9 80 65 60 80 75 65
EEE XIO I 65 50 60 65 60 75
TABLE 4.1. The market share matrix for player PI.
128 4. Linear Programming
Note that this is a constant-sum (not a zero-sum) game since the sum of both
players' market shares equals 1000/0. However, as both players still have diamet-
rically opposed interests the game can be reduced to a zero-sum game and solved
using the procedure described.
A careful examination of the payoff table reveals that EEM (xs) dominates the
three strategies AMM (X2), MMM (XI) and AAA (X4), and EAM (X6) dominates
EMM (xs) and AAM (X3). Thus, we could discard PI's first five strategies. If this
is done, then the P2's strategy AM en) dominates MM (YI). The game could
then be reduced to one with only five strategies for each player. We leave this
as an exercise and solve the complete problem with ten strategies for PI and six
strategies for P2.
> restart: * MarketingGame.mws
> with (simplex) :
Warning, new definition for maximize
{XI= 0, X2 = 0, X3 = 0, X4 = 0, xs = 0, X7 = 0, XIO = 0, X6 = 0,
2 I 190
X9 = -, xs = -, v = -}
3 3 3
> * Player 2' s problem
> for i from 1 to m do
Player2[ i) :=add(y[ j] *P[ i,j] ,j=1. .n)<=u od:
> Unity:=add(y[ j] ,j=1..n)=l:
> minimize (u,{ seq (Player2[ i) ,i=1..m)} union
{Unity} union { seq(y[ j] >=0, j=1. .n)} );
4.5 Other Examples 129
2 4 I 190
{YS = 0, Y6 = 5" .Y2 = Is' Y3 = 3" YI = 0, Y4 = 0, U = 3"}
Clearly, the dominated states; = I, ... , 5 for PI and j = I for P2 do not
appear in the solution indicating that they would never be used. As in the coin-
tossing game, the maximum PI can expect to gain is equal to the minimum P2
= =
can expect to lose, i.e., U v 190/3.
proc(n)
description 'Reset the seed for the random number generator'
end
943045446
130 4. Linear Programming
and X2 = 60 toy trains that would result in a daily profit of z = $3840. With
this solution the capacity in the train department is utilized completely since the
constraint X2 ~ 60 is satisfied as an equality. Thus, we now wish to detennine if
it would be desirable to acquire additional resources and increase the production
capacity in the train department.
Let us suppose that the train production capacity is increased by 10 units to 70.
Re-solving the problem using Maple gives
> restart : # ToyLPRHS70.rnws
> with(sirnplex):
Warning, new definition for maximize
Const2 := X2 ~ 70
Const3 := 5xI +6X2 ~ 600
> Sol:=rnaxirnize(z,{ seq(Const[ i] ,i=1..3)},
NONNEGATIVE);
Sol := {XI = 36, X2 = 70)
> assign(Sol); z;
3880
Train Department
Production Capacity XI X2 Z($)
60 48 60 3840
70 36 70 3880
80 24 80 3920
90 12 90 3960
100 0 100 4000
110 0 100 4000
120 0 100 4000
We see that if, for example, the new capacity is In. = 120, the optimal solution
is found as XI = 0, X2 = 100 and Z = $4000. Thus, for an increase of 60 units in
the capacity, the maximum profit increases by $4000 - $3840 = $160, implying
that the marginal benefit per unit is now only $160/60 = $2.67 instead of $4.
Why is the dual price no longer equal to $4? Using the graph of the feasible
region as in Figure 4.1, the reader can easily show that for such a substantial
increase in the train department capacity, this department's constraint becomes
redundant and thus increases in this capacity no longer add to the profit beyond a
certain threshold level.
If this is the case, there must be some range of values for the train department
capacity for which the dual price would still be $4. This is indeed the case as we
now demonstrate using Maple's help.
First, recall from the analysis of the problem in Section 4.3.1 that in the optimal
solution, the basic variables are XI = 48, X2 = 60 and X3 = 42 with the basis
matrix B = (aI, a2, a3). Now, let us introduce a parameter ~2 corresponding to
the change in the train department production capacity so that the RHS vector b
assumes the form b = (90,60+ ~2, 600)'.
With this change in the train production capacity, Maple tells us that the new
values of the optimal basic variables are now XB = B-Ib = (48 - ~~2' 60 +
~2, 42 + ~ ~2)' provided that XB ~ o. It is an easy matter to solve the resulting
set of inequalities for ~2, which gives -35 ~ ~2 ~ 40 as we shall see. This
result implies that as long as the train department capacity is not increased by
more than 40 units or is not decreased by more than 35 units, the optimal basis
(XI, X2, X3) remains optimal. Hence, for this range of ~2 values, the dual price of
$4 is still valid. Equivalently, this implies that as long as the new capacity in the
train department is between 25(= 60-35) and 100(= 60+40) units, the optimal
basis does not change and the dual price is still $4. These results are presented in
the following Maple worksheet.
> restart: * ToyLPRHSDelta2.mws
> with (linalg) :
Warning, new definition for norm
Using the approach described, it can also be shown that the dual price for the toy
car department production capacity is $0 and for the special parts constraint is $6.4
Moreover, it is easy to show that for the car production capacity, the pennissible
range of values for the change a I is -42 ~ a I, and for the special parts the range
is - 240 ~ a3 ~ 210. These findings are summarized in the following table.
4Note that if there is any unused capacity in the car department (in this case, X3 = 42 units), adding
more capacity would not improve the profit since the new units would also not be used.
134 4. Linear Programming
range of CI values (the range ofoptimality) does the original optimal solution not
change?
Suppose that the profit from each car is 30 + 0 I dollars where 0 I is the amount
by which the unit profit changes. Thus, the objective coefficient vector now be-
comes C = (30 + 01,40,0,0,0) and since (XI, X2, X3) constitute the optimal ba-
sis, we have CB = (30 + 01, 40,0). This change in CB affects the Zj = CBB-Iaj
values and hence the Cj - Zj row in the final simplex table. Indeed, as the fol-
lowing Maple worksheet demonstrates, we find that C4 - Z4 = -4 + ~Ol and
°
C5 - Z5 = -6 - !Ol. In order for the original solution to remain optimal, we must
of course have C4 - Z4 ::: and C5 - Z5 ::: 0 for these nonbasic variables X4 and
X5 . Maple easily solves the inequalities and finds that for -30 ::: 01 ::: lj, the
original basis remains optimal.
> restart: # ToyLPCosttheta1.mws
> with (linalg) :
Warning, new definition for norm
°: : °: : °
0, 0,
6 1
< 0, -4 + -5 01 ::: 0, -6 - -5 01 ::: °
> solve({ seq(c[ j] -z[ j] <=0,j=1..5)});
10
{-30::: 01 , 01 ::: T}
4.6 Sensitivity Analysis and Duality 135
Next, writing 40 + fh as the new value of the unit profit from each toy train
(where fh is the change in this unit profit), it can be shown that as long as -4 :::
fh, the original optimal solution (XI = 48, X2 = 60 and z = $3840) remains
optimal. These results are summarized in the following table.
Allowable Current Allowable
Variable Decrease Coefficient Increase
XI (Car) 30 30 3.33
X2 (Train) 4 40 00
> b:=evalm(RHS):
> for j from 1 to 5 do a[ j] :=col(A,j) od:
> B:=augment (a[ 1] , a[ 2] , a[ 3] ) :
> c[p] :=50;
cp:= 50
> a[ p] :=vector (3,[ 1/2,1,10] );
Qp := [~, I, 10]
> y[ p] : =evalm (inverse (B) &* a[ p] );
YP := [~, I, ~~]
> cB: =vector (3,[ 30,40,0] ) ;
cD := [30, 40, 0]
> z[ p] :=evalm(cB &* y[ p] );
zp:= 64
> c[ p] - z[ p] ;
-14
These arguments also imply that while it is not optimal to produce bulldozers,
iffor some reason the management has to produce one unit (i.e., if the constraint
x p ~ I is introduced, which would result in x p = I), then the optimal profit
would decrease by S14. This amount is also known as the reduced cost associated
with the nonbasic variable xp.
4.6.4 Duality
In Section 4.6.1 we learned that the dual prices of the car and train production de-
partment resources and the special parts resource were SO, $4 and S6, respectively.
As we discussed, these dual prices can be found by increasing the right-hand side
of a particular constraint by one unit (thereby increasing the associated resource
by one unit) and re-solving the problem. The change in the objective function with
the higher value of the resource was the dual price for that resource constraint.
We now follow a different route and attempt to compute the dual prices as
the optimal solution to a linear programming problem ("dual program") that is
intimately related to the original problem (''primal program.")
Example 53 Furniture production. In this example, we consider a simplified ver-
sion of a furniture manufacturing problem where only tables (XI) and chairs (X2)
are made by using wood and labor as resources. The problem data are summarized
in the following table.
4.6 Sensitivity Analysis and Duality 137
Following is the primal program for this problem and its solution using Maple.
>
restart:
* FurnitureDual.mws
infolevel[ simplex] :=2;
info/eve/Simpla := 2
> with (simplex) :
Warning, new definition for maximize
ZD = 240uI + 130U2
and satisfying the two constraints (4.4) and (4.5).5
SIfthc constraints are not satisfied, company management would not sell the resources.
4.6 Sensitivity Analysis and Duality 139
6It is not clear why Maple gives obj =, -480 - 48_SL I - 34u2, which would in<:orrectly imply
that the minimum value of the dual objective is =D = -480 instead of +480.
140 4. Linear Programming
This example demonstrates several important properties of the primal and dual
problems that are true in general:
• The optimal objective function value for both problems is the same, i.e.,
zp=zD=480.
• The optimal values of the primal decision variables (x j) are the negatives
of Cj - Zj entries for the _SL.i variables in the final dual table. For the
primal, XI = 48 and X2 = O. These values could also be deduced from the
information in the final table in the dual: Cj - Zj = -48 for _SL 1 so that
XI = -(-48) = 48, and Cj - Zj = 0 for _SL2 so that X2 = -0 = o.
• The optimal values of the dual variables (u;) are the negatives of Cj - Zj
entries for the _SL.i variables in the final primal table. These values could
also be deduced from the information in the final table in the primal: Cj -
Zj = -2 for _SLI so that UI = -(-2) = 2, and Cj -Zj = 0 for _SL2 so
that U2 = -0 = o.
We can now generalize these ideas by presenting the concept of duality in a for-
mal manner. We first assume that the primal problem has been written in the form
of maximization with :s constraints. This is always possible since a ~ constraint
can be written as a :s constraint by multiplying both sides of the former by -1,
for example, XI +X2 ~ 3 can be written as -XI -X2 :s -3. Similarly, an equality
constraint can be converted to two inequality constraints; XI + 2x2 = 1 can be
written equivalently as XI + 2x2 :s 1 and XI + 2x2 ~ 1 (or, -XI - 2x2 :s -1).
The primal program is stated as
max Zp = ex
s.t. Ax :s b
x ~ O.
We now present some of the main theoretical results associated with the pair of
primal/dual programs.
• Suppose x and u are feasible solutions to the primal and dual programs,
respectively. Given x and u, the value of the primal objective function is
always less than or equal to the value of the dual objective function. This
result easily follows by noting that the inequality Ax :s b can be written as
x' A' :s b/. MUltiplying both sides on the right by any feasible u ~ 0 gives
x' A/u :s b/u = ZD. Now, writing A/u ~ c' as e' :s A/u and multiplying
both sides on the left by x ~ 0, we get zp = xc' x
:s A/u. But since
x' A/u :s b'u = ZD, we obtain zp :s ZD.
4.6 Sensitivity Analysis and Duality 141
Returning again to the furniture example, we see that the optimal primal basis
is IB = (XI, _SL2) = (XI, X4). The solution for the dual variables u' = cBB- 1 =
(UI, U2) = (2,0) is given by the following Maple worksheet.
> restart: # DualForrnula.rnws
> cB: =vector (2,[ 10,0] ) ;
cB:= [10,0]
> B: =rna t r ix (2, 2, [ 5, 0, 2, 1] ) ;
ConstraintsPStandard :=
[XI + 5 X2 ::: 80, -4 XI - 2 X2 ::: -20, XI
+ X2 ::: 10, -XI - X2 ::: -10]
> PrimalSol:=maximize(zPrimal,ConstraintsPStandard,
NONNEGATIVE) ;
PrimalSoI := {X2 = 0, XI = 1O}
4.6 Sensitivity Analysis and Duality 143
where the original objective function min u = min (u' - u") is converted to a
maximization objective as max -(u' - u").
At this stage, we let Maple take over and find the dual of Player 2's problem.
> restart: # CoinTossDual.mws
> with (simplex) :
Warning, new definition for maximize
144 4. Linear Programming
xJ -x4, [0 ~ xl -x2 +xJ -x4, 0 ~ -xl +x2 +xJ -x4, -I ~ -xl -x2,
I ~ xl +x2]
Maple finds the dual as follows:
Letting v = Xl -X4 and noting that the two constraints XI +X2 ~ I and XI +X2 ~ 1
imply XI +X2 = I, we obtain the problem for Player 1 as given in (4.2).
Thus, since the two players' problems are the duals of each other, it is sufficient
to solve only one player's problem and deduce the solution for the other player
using the Cj - Z j values from the final optimal table.
4.7 Integer Linear Programming 145
The company has a budget of$24,OOO,000 available for the purchases of these
aircraft, and the annual maintenance time available per year is 1,300 hours. The
problem is to find the optimal number of Boeings (XI) and Airbuses (X2) to pur-
chase in order to maximize the annual profit.
We first solve this problem as an ordinary linear program using Maple's sim-
plex package and find that the solution is not integer since XI = 4.8 and X2 = 0
withz = 960.
> restart: * AircraftLP.mws
> with (simplex) :
Warning, new definition for maximize
960.0000000
At this stage one may be tempted to round the non integer solution up and down
to the nearest integer with the hope of obtaining an optimal integer result. This
usually does not work, as we see in the following lines. Rounding XI = 4.8 up to
5, we find an infeasible solution, and rounding down to 4 gives an integer result
that is not optimal!
> x[ 1] : =5; x[ 2] :=0; Z; Constraints;
XI :=5
X2 :=0
1000
{25 :'S 24., 1000 :'S l300}
> x[ 1] :=4; x[ 2] :=0; Z; Constraints;
XI :=4
X2 :=0
800
{20 :'S 24., 800 :'S l300}
Although Maple has not implemented any algorithms to solve integer linear
programs, it includes a share package written by Anu Pathria in its share folder. 7
This package is named i 1P () and it can be loaded by using the commands
with (share) ; and with (ilp) ;.
The ilp () function's syntax is identical to that used in simplex as can be
seen in the following Maple worksheet. Note that i 1 P () maximizes the objective
function in an integer programming problem. For minimization problems, the user
must first multiply the original objective function by -I and then maximize the
resulting function subject to the usual constraints. Once the optimal solution is
found, taking the negative value of the objective function would give the minimum
of the original objective.
> restart: * AircraftIP.rnws
> with (share) : with(ilp);
See ?share and ?share,contents for information about the
share library
7Anu Pathria's ilp () is available with Release 5.1 .ld it implements the branch-and-bound algo-
rithm for solving integer programming problems. A good reference on this algorithm is Zionts [198,
Chapter IS).
4.8 Summary 147
> ilp(z,Constraints,NONNEGATIVE);
{XI = 4, X2 = I}
> assign(%); z; Constraints;
900
{24 ~ 24., 1300 ~ 1300}
4.8 Summary
Linear programming (LP) is one of the oldest and most thoroughly studied OR
technique. We started this chapter by introducing a simple example ofLP model-
ing with two decision variables and solved the resulting problem using the graphi-
cal method. For larger problems with four or more variables the graphical method
fails since plotting the feasible set becomes geometrically impossible. In that case,
the (algebraic) simplex method can be used to locate the optimal solution. We
provided a step-by-step description of the simplex method that involves inverting
matrices. This was made relatively painless by using Maple's inverse () com-
mand. We also explained the implementation of Maple's own simplex package
and discussed certain types of problems that may have unusual characteristics
such as infeasibility and unbounded solutions. Sensitivity analysis is always an
important component of any application of LP. This topic was also discussed in
some detail. The chapter ended with a very brief description of a share package
known as ilp () that can be used to solve integer linear programming problems.
148 4. Linear Programming
4.9 Exercises
1. Consider the following LP problem with two decision variables.
(a) Solve this problem graphically using Maple's inequality plotting fa-
cilities.
(b) Solve the same problem manually (but with Maple's help) using the
simplex method.
(c) Now solve the problem using Maple's simplex.
(d) Formulate and solve the dual problem and interpret its solution.
2. The Kingdom of Albricol's national oil company that produces oil special-
ity additives purchases three grades of petroleum distillates A, B and C.
The company then combines the three according to King Peter the First's
specifications of the maximum and minimum percentages of grades B and
C, respectively, in each blend.
Max % Min % Selling Priee of
Blend Allowed for B Allowed for C Mixture (SIL)
Royal Deluxe 60% 10% 3.75
Princely Standard 20010 30% 3.10
Pauper's Special 1% 65% 1.99
The supply of the three additives and their costs are:
Maximum Quantity Cost of Distillate
Distillate Available per day (L) (SIL)
A 16000 .37
B 19000 .29
C 12000 .24
Formulate a linear program to determine the daily production policy that
will maximize profits for King Peter and his Kingdom. Solve using sim-
plex.
3. The Claus Cookie Manufacturing Society packages three types of cookies
into two different one pound assortment packages. Each week, 1000 pounds
of chocolate chip cookies, 2000 pounds of peanut butter cookies and 1500
pounds of coconut crispies are available. Assortment A contains 50 percent
chocolate chip cookies, 25 percent peanut butter cookies and 25 percent
4.9 Exercises 149
4. Captain's Boats Inc. makes three different kinds of boats. All of these
boats can be made profitably, but the company's monthly production is con-
strained by the limited amount of wood, screws, and labor available each
month. The director will choose the combination of boats that maximizes
his revenue in view of the following infonnation:
Requirements per boat
Input Row BOAT CANOE KAYAK Available/month
Labour (hr.) 12 7 9 1,260 hrs.
Wood (board ft.) 22 18 16 19,008 bd. ft.
Screws (lb.) 2 4 3 3961bs.
Selling Price $400 $200 $500
Fonnulate this problem and solve using Maple's simplex.
(a) How many boats of each type will be produced and what will be the
resulting revenue?
(b) How much wood will be used to make all of these boats? If extra
wood were to become available, how much would Captain's Boats be
willing to pay for some?
(c) You will find that very few canoes are made because their selling price
is so small. Suppose someone offered to buy canoes for $x each. For
.what value of x, would Captain's Boats produce any canoes?
(d) Suppose Kayaks were sold for $y per unit rather than $500. For what
value of y, fewer Kayaks would be produced?
(e) What is the highest hourly wage Captain's Boats would be willing to
pay for extra workers?
5. Smart Bucks, Inc., an investment agency, has been asked to advise one of
its clients from the province of Kebek on how to invest all of his $100,000
among the 3 assets described below:
Units of Risk Rate of
Assets per Dollar Invested Retum
1. Northern Mines Shares 4 0.13
2. Royal Bank of Commerce Shares 3 0.12
3. Kebek Savings Bonds I 0.14
150 4. Linear Programming
The client would like as high an annual return as is possible to receive while
incurring an average of no more than 2.9 risk units per dollar invested. Ke-
bek Savings Bonds unfortunately are available only up to a value ofSl5,OOO
per Kebek resident.
Fonnulate and solve this problem using Maple's simplex and answer the
following questions.
(a) How much of each asset will be bought and what will be the average
rate of return on these?
(b) How much risk is being incurred on average? What is its shadow
(dual) price?
(c) Obviously Kebek Savings Bonds are paying an excessive rate of re-
turn in view of their relatively low level of risk. How low a rate of
return could the province of Kebek have offered for its bonds without
this investor having invested differently than he did?
(d) If the Royal Bank of Commerce raised the rate ofreturn on its shares
to 12.9%, would it be able to increase its sale of shares to the particular
investor we are discussing? What would be the new average rate of
return on this investor's portfolio?
(e) Fonnulate and solve the dual problem and interpret its solution.
5.1 Introduction
As we discussed in Chapter 4, in linear programming (LP) applications, our pur-
pose is to optimize (i.e., maximize or minimize) a linear objective function subject
to linear constraints. Although a large number of practical decision problems can
be accurately modeled as linear programs, it should be emphasized that in some
cases using LP to formulate an inherently nonlinear decision problem (i.e., forcing
the world to fit the model) may not provide an accurate representation of reality.
In many OR problems due to economies/diseconomies of scale (e.g., quantity
discounts), interaction among decision variables (e.g., variance ofa portfolio) or
transformations that result in nonlinearities (e.g., a linear stochastic programming
formulation transformed into an equivalent nonlinear deterministic one), an LP
formulation becomes impossible to use. In these cases, we would need to utilize
the techniques of nonlinear programming (NLP) that can deal with both nonlinear
objective functions and nonlinear constraints.
A general NLP problem with both inequality and equality constraints is ex-
pressed as follows:
min I(x)
s.t. g; (x)~ 0, i = I, . .. , m
hj(x) = 0, i = I, ... , P
XE s.
Here, I(x) is the objective function with x = (XI, ... , Xn)' as the column
vector of n decision variables; g;(x) ~ 0, i = 1, . . . , m, are the m inequality
which must be at least equal to 0.09, that is, O.lOxl +0.05X2 ~ 900. The variance
of the portfolio is computed as
Example 58 Convexity 0/x 2 -4x -8. Using the foregoing definition of convexity,
we now use Maple's assume () facility and is () function to check whether the
function /(x) = x 2 - 4x - 8 is convex. We let XI = a and X2 = b.
>
>
restart: *
convex.mws
assume (lambda>=O, lambda<=l, lambda, real,
a,real,b,real);
> f:=x->x A 2-4*x-8;
/ := X ~ x 2 - 4 X - 8
> LHS:=f(lambda*a+(l-lambda)*b);
LHS := (A. a + (I - A.) b)2 - 4 A. a - 4 (I - A.) b - 8
> RHS:=lambda*f(a)+(l-lambda)*f(b);
RHS := A. (02 - 4 a - 8) + (I - A.) (b 2 - 4 b - 8)
> is (LHS<=RHS) ;
Maple indicates that the condition LHS ::: RHS is always true indicating that
/ (A.a + (I - A.)b) ::: A./(a) + (I - A.)/(b), for all A. e (0, I) and all real a and
b. This proves the convexity of /(x) = x 2 - 4x - 8.
The following intuitive result is concerned with the sum of convex functions.
Theorem 1 Let the functions I; (x), i = I, ... , k be convex over some convex set
S eRn. Then the function /(x) = L~=I I; (x) is also convex over S.•
A useful theorem that relates the convexity of functions to the convexity of sets
is the following.
Theorem 2 [80, p. 86J If /(x) is a convex function over the nonnegative orthant
0/ R n, then if the set o/points S satisfying /(x)
::: b and x ::: 0 is not empty, Sis
a convex set. •
Let the nonempty set S be a subset of Rn and let f : S ~ R'. If the function
f is differentiable at some point i e S, then its gradient vector at i is
0 2 f(x) 0 2 f(x)
,
aT ox,oxn
H(x) =
a2 f(x) a2 f(x)
oxnox, a;r
n
5.2 Convexity of Sets and Functions 157
]
> H:=hessian(f,[x,y));
-I
[ -25
H:= 215 ~y-~
5 5
I >0
Sign oftbe Quadratic Form x'Qx
~O <0 ~O Mixed
-'Jo~X=FO for all x for x =F 0 for all x
Property Positive -PosltlVe-- Negative--- Negative Indefinite
of Q Definite Semidefinite Definite Semidefinite
I °
Sign oftbe ~k'S, k = 1, ... , n
°
Q
~k >
Property of Positive
Definite
(_I)k ~k >
Negative
Definite
Mixed
Indefinite •
These results must be interpreted and used with care since merely replacing the
> sign by ~ (or < by:::) does not mean that the Q matrix is positive (or negative)
semidefinite. For example, if
> restart: * notsemi.mws
> Q:=rnatrix (3,3,[ 2,2,2,
> 2,2,2,
> 2,2,1]);
Q:= [ ; ; ;]
221
x := [~, ~, -1].
we obtain x'Qx as
> eva 1m (x &* Q &* x);
-I
implying that Q is not positive semidefinite.
There is, however, a special case where it can be shown that if ~k > 0, k =
1, ... , n - I, and ~n = 0, then Q is positive semidefinite [148, p. 19]. Similarly,
if ( _I)k ~k > 0, k = 1, ... , n - I but ~n = 0, then Q is negative semidefinite.
In general, in order to determine the positive semidefiniteness of a symmetric
matrix, the following procedure is used: Let Qr be the matrix obtained by remov-
ing the first r rows and r columns of the original matrix Q, r = 0, ... , n - I (with
°
Qo == Q). Define ~rk to be the kth principal minor of Qr. Then, Q is positive
semidefinite if and only if ~rk ~ for r = 0, ... , n - 1, k = I, ... , n - r;
°
and negative semidefinite if and only if (-1 i ~rk ~ for r = 0, ... , n - 1,
k = 1, ... , n - r. For example, if n = 3 and
Q= [:~: :~ :~!],
q31 q32 q33
Provided that the eigenvalues' signs can be easily determined, this test is sim-
•
pler to implement than the principal minor test. We should also note that although,
in general, the eigenvalues may asswne complex values, due to the symmetric na-
ture of the Q matrix that we are assuming, it can be shown that its eigenvalues are
always real [91, p. 32].
160 5. Nonlinear Programming
Ialse
> definite(H,'negative de~);
definite(H,'negative=semide~ );
125y - 83 < 0
125 y - 83 $ 0 and 3 y - 2 $ 0
Thus, we see that only in some regions, the terrain is negative definite (or nega-
tive semidefinite), and hence 1 is strictly concave (or concave). We can ask Maple
to solve these inequalities to obtain the region over which the terrain is, say, neg-
ative semidefinite:
> solve({definite(H,'negative_semide~)} ,y);
83
{y $ 125}
Since the defini te () function would not be directly useful to determine
where the Hessian is indefinite, (i.e., where 1 is neither convex nor concave) we
make use of the eigenvalue test and obtain the eigenvalues ofB as
> s:=eigenvalues(H);
7 3 1
s := - 10 + 10 Y + 50 J229 + 450 Y + 225 y2,
7 3 1
--
10
+ -10 y - - J229 +450y +225r
50
The two eigenvalues are given in terms of the variable y; thus, we ask Maple
to solve for the region of values of this variable for which the eigenvalues assume
opposite signs:
> solve ({ s[ 1] >0, s[ 2] <O} , y) ;
83
{125 < y}
This result implies that for {(x,y) : y > 83/125}, the terrain of the surtace
beneath the water resembles a part of a saddle without any convex or concave
regions. See Figure 5.1 for the plot of the surtace of the terrain of function 1
produced by the following Maple three-dimensional plotting command.
> plot3d(f,x=-15 .• 15,y=-15 •• 15,axes=boxed,
shading=none, orientation=[ -33,76] );
B(Q,r) ..1.1r
=Q 00
(x-r)k(x)dx
162 5. Nonlinear Programming
where Q is the order quantity, r is the reorder point, A. is the average demand per
year, and k(x) is the density of demand during the leadtime. It is easy to show that
the B(Q, r) function is separately convex in Q and convex inr, but despite H-W's
claim it is not jointly convex in both Q and r. Let us use Maple to demonstrate
this fact.
> restart: *backord.mws
> B:=lambda*int((x-r)*k(x),x=r •. infinity)/Q;
B .-
.-
A. 1 00
(x - r) k(x) dx
.....:!.!..r_ _ _ _ __
Q
> with (linalg) :
Warning, new definition for norm
2
A. 1
r
00
(x -r)k(x)dx
Q3
A. 1
00
- k(x)dx
Q2
H .-
·-
1
A.
00
- k(x) dx A. k(r)
Q2 Q
In order for B to be positive semidefinite, the diagonal elements and the de-
terminant must be nonnegative. The diagonal elements are nonnegative, but the
determinant is computed as
> det(H);
5.2 Convexity of Sets and Functions 163
Q4
Since A.2 / (t > 0, we see that if at r = 0 the density fimction has the prop-
erty that k(O) = 0, the detenninant assumes a negative value as it reduces to
-(A.2 / (t) [- CO k(x )dx]2 < O. Thus, contrary to H-W's claim, it is not, in gen-
eral, true that the backorder cost fimction is always convex.
However, as has been shown by Brooks and Lu [38], if ~ is a number such that
k(x) is nonincreasing for x ~ {, then B(Q, r) is convex in the region {(Q, r) :
o < Q < 00 and ~ =:; r < oo}.
Example 64 Convex;tyo/ /(a, b) = Ja 2 + 1J2. The Euclidean distance fimction
/(a, b) = Ja 2 + IJ2 (also known as the t2 distance fimction) plays a very im-
portant role in location theory. In this example we will show using Maple that
this fimction is convex over the real plane R2 except at the origin where it has no
derivative.
> restart: * sqrt.mws
> f:=sqrt(a A 2+b A 2);
> diff(f,a);
a
Ja 2 + IJ2
> limit (%,{ a=O,b=O) );
undefined
> with (linalg) :
Warning, new definition for norm
a2
H22 := (a2 + b2)(3/2)
164 5. Nonlinear Programming
> assume(a<O,a>O,b<O,b>O);
> is(Hll>O); is(H22>O);
true
true
> det(H);
o
Since the first principal minor of the Hessian is 111 = HII > 0 for 0 =
{(a, b) : aE RI " (OJ, be RI " {OJ} and the determinant of the Hessian is zero,
it fo]]ows that the Hessian is positive semidefinite over O. Thus, the function
f(a, b) = Ja 2 + j)2 is convex in o.
f:=x2+l
g:= (x + y)2
5.2 Convexity of Sets and Functions 165
h :=x 2 - y2
> Hf:=hessian(f,[ x,y]); Hg:=hessian(g,[ x,y]);
Hh: =hessian (h, [ x, y] );
HI:= [~ ~]
Hg:= [ ; ; ]
Hh:= [~ _~]
> cholesky(Hf);
[ ../i 0 ]
o ../i
> cholesky(Hg);
Error, (in cholesky) matrix not positive definite
> cholesky(Hh);
Error, (in cholesky) matrix not positive definite
In the next example, Maple is able to compute the lower triangular matrix L of
a 3 x 3 symmetric matrix Q, which, by implication, is positive definite.
[=! -~ -n
> Q:=matrix([[ 2,-1,-3], [-1,2,4], [-3,4,9]]);
Q:=
> L:=cholesky(Q);
o
!J6
2
~J6
6
As a check of the results, when we ask Maple whether LL' is equal to the
original matrix Q, the answer is obtained in the affinnative.
> equal(L &* transpose(L), Q);
true
166 5. Nonlinear Programming
(b) a local minimizer of f(x) if there exists an e > 0 such that f(x) ~ f(x)
for all XES for which x E Nc(x) = {y : lIy - xII ~ e}.
Note that replacing the inequality sign (~) by the strict inequality sign «)
gives the definitions for strict global minimizer and strict local minimizer.
The next two theorems, which give the necessary and sufficient conditions for
the optimality, are proved in Bazaraa and Shetty [18, Section 4.1].
This theorem provides the necessary conditions for the local optimality of i;
these conditions are true for every local optimum, but a point satisfYing these
conditions does not have to be a local minimum, the classical example being
f(x) = x3. The following theorem provides a sufficient condition for the lo-
cal minimum.
IThe points of f(x) obtained as a solution of Vf(i) = 0 are called the critical (or statioaary)
poiats.
5.3 Unconstrained Optimization 167
Let us now illustrate the necessary and sufficient conditions using a specific
function.
of the function f(x) = (x - 4)4(x + 3)3 obtained using the Maple command
plot(f(x),x=-4 .. 5).
10000
8000
x
-2000
-4000
S:= LC;
" m; J(a -x;)2 + (b - y;)2
;=1
> Sa:=diff(S,a);
The optimal location of the source is thus found to be at the coordinates (a, b) =
(6.96,8.53) with a total minimum cost of $min = $12,216.13.
. 3 2 3 2 7
f .= 20 XI + 50 X2 + 50 XI X2
> g:=900-(1/10)*x[l]-(5/100)*x[2]; # 9 <= 0
I I
g := 900 -10 XI - 20 X2
> h:=10000-x[ 1] -x[ 2]; # h = 0
h:= 10OOO-xl -X2
> vars: =[ x[ 1] ,x[ 2]] :
> H:=hessian(f,vars); definite(H,' positive_def' );
H:= [I: ~]
50 25
true
> grad_f:=grad(f,vars):
> grad_g:=grad(g,vars):
> grad_h:=grad(h,vars):
> eq[ 1] :=grad_f[ 1] +lambda*grad_g( 1] +mu*grad_h[ 1] ;
371
eql := 10 XI + 50 X2 -10 1 - p
> eq[ 2] :=grad_f[ 2] +lambda*grad_g( 2] +mu*grad_h[ 2] ;
371
eq2 := 25 X2 + 50 XI - 20 1 - p
> comp_slack:=lambda*g=O;
I I
comp_slack := 1 (900 - 10 XI - 20 X2) = 0
> structural[ 1] :=g<=O;
5.4 Inequality and Equality Constrained Optimization 173
1 1
Structurall := 900 - -XI - -X2<0
10 20-
> structural[ 2] :=h=O;
structurah := 10000 - XI - X2 = 0
> solve({ eq 1] ,eq 2] ,cornp slack,larnbda>=O,
structural[ 1] , structuraI[ 2] ,
xi 1] >=0, xi 2] >=O} ) ;
{A. = 26400, P = 40, XI = 8000, X2 = 2000}
> sol:=assign(%):
> subs(sol,f);
12080000
The results indicate that it is optimal to invest XI = $8000 in the first stock and
X2 = $2000 in the second stock, giving rise to a portfolio variance of 12080000.
In other words, the (negative) of the gradient vector V/(i) of the objective func-
tion / is a linear combination of the gradient vectors Vg; (i), i E B of the binding
inequality constraints and the gradient vectors Vh; (i) of the equality constraints.
(If any of the inequality constraints were not binding, then the corresponding mul-
tiplier would be zero due to the complementary slackness conditions.)
For the portfolio problem, at the optimal solution i = (8000, 2000) we have
A. [ ~-I] + [ P
-1 ]
-1 = -
[ 2680 ]
1360 '
As shown on the graph of the feasible region and the objective function in
Figure 5.3, the optimal solution for this problem is clearly at x = 1, y = O. But
let us attempt to solve this problem using Maple.
> restart: # CONSQUAL.MWS
> f:=-x; #Minimize
!:=-x
> gl:=-{1-x)A3+y; #gl <= 0
gJ := _(l-x)3 +y
> g2:=-y; #g2 <= 0
g2:= -y
> with{linalg):
Warning, new definition for norm
I I
p 2 = 0, y = 1 - 3 x + 3 x 2 -
o x 3 , AI = 3' (x _ 1)2' x = X)
-1
-2
As we see, Maple tries its best to find a solution and produces one. But due
to the unusual nature of this problem, the solution found by Maple (using Kuhn-
Tucker conditions) does not seem right, especially when we note that at x = I,
the multiplier AI = 00. What went wrong?
What happened in this problem was the lack of linear independence of the
gradient vectors Vg; (i), i = I, 2 at the point i = (I, 0). Since
AI [ ~ ] + A2 [ ~I ] = _ [ ~I ]
* This
has no solution, as can be seen from the following Maple output:
> sol:~x=l,y=O}; is known to be the optimal
solution
sol := {y = 0, x = I}
> grad_gl:=subs(sol,evalrn(grad_gl»;
grad...x1 := [0, I]
> grad_g2:=subs(sol,evalrn(grad_g2»;
grad...x2 := [0, -I]
> grad_f:=subs(sol,evalrn(grad_f»;
gradJ:= [-1,0]
> vector_space:=stackrnatrix(grad_gl,grad_g2)i
176 5. Nonlinear Programming
vector_space:= [~ _!]
> linsolve(transpose(vector_space),-grad_f)i
Maple finds no solution!
The fact that the vectors [0, I]' and [0, -I]' are linearly dependent is shown
in the next set of commands where Maple indicates that the matrix fonned by
these vectors has rank 1 and the solution of the linear system for AI, and A2 gives
AI = A2 = _tl:
> rank(vector_space)i
where..\ = (AI, ... , Am) and I' = (JIb . .. , Jlp). The K-T conditions can now be
expressed in tenns of the Lagrangian as
gl := XI 2 +X2 2 - 5
> g( 2] : =x[ 1] +2* x[ 2] -4; .. g( 2] <= 0
g2 := XI + 2 X2 - 4
> vars:=[x[l],x[2]];
vars := [XI, X2]
and generate the K-T conditions with the following commands:
> L:=f+sum(lambda[ k] *g( k] , k=1. .2);
> grad_f:=grad(f,vars);
gradJ:= (2xl - 6, 2X2 - 4J
> grad_g[ 1] : =grad (g[ 1] , vars) ;
grad...E1 := (2xl, 2xiJ
> grad_g[ 2] : =grad (g[ 2] , vars) ;
grad...E2 := [1, 2]
> Opt:={ x[ 1] =2,x[ 2] =1} ;
Opt := {X2 = I, XI = 2}
> grad_f:=subs(Opt,evalm(grad_f));
gradJ := [-2, -2]
> grad_g[ 1] :=subs(Opt,evalm(grad_g[ 1] ));
grad...E1 := [4, 2]
> grad_g[ 2] :=subs(Opt,evalm(grad_g[ 2] ));
grad...E2 := [1, 2]
> A:=transpose(matrix(2,2,[ grad_g[ 1] ,grad_g[ 2]] ));
5.4 Inequality and Equality Constrained Optimization 179
A:= [i ~]
> linsolve(A,-grad_f);
[i, ~]
The final result indicates that the gradient of the objective ftmction can be ex-
pressed as a linear combination of the gradients of the constraints evaluated at
i = (2, I) when ~ = (.l, j). The graph of the feasible set, the objective function
and the optimal solution presented in Figure 5.4 are plotted using the next set of
Maple commands.
> with(plots):
> f: =subs ({ x[ 1] =x, x[ 2] =y} , f) ;
f := (x - 3)2 + (y - 2)2
> g1: =subs ({ xC 1] =x, x[ 2] =y} , g[ 1] ) ;
gJ:=x 2 +r-5
> g2: =subs ({ x[ 1] =x, x[ 2] =y} , g[ 2] ) ;
g2 :=X +2y-4
> solve({g1,g2});
II -2
(y = I, x = 2), (y = 5' x = 5)
> feas_g1:=implicitplot(g1,x=2 •• 3,y=-1 •• 1):
> feas_g2:=implicitplot(g2,x=-1 •• 2,y=1 •. 3):
> obj:=contourplot(f,x=-2 .• 6,y=-2 •• 3,contours=
[0.5,1,1.5,2,2.5] ,coloring=[ white,blue]):
> display({ feas g1,feas g2,obj},
scaling=constrained);-
FIGURE 5.4. The feasible set, objective function and the optimal solution of the problem
with a quadratic objective function and mixed constraints.
to minimize the total cost C = CIXI + C2X2 of producing q units subjcct to the
constraint that Axfl x~ = q.
We first fonn the Lagrangian as L = CIXI + C2X2 + Jl(q - Axfl x~). Using
Maple's implicit differentiation function, we observe that the curve q = Axfl x~
in the (XI, X2) plane is decreasing and strictly convex. Since the cost function
C = CIXI +C2X2 is linear, this implies that the solution found from the application
of the Kuhn-Tucker theorem will give the unique minimizing point.
>
>
restart: * cobbdouglas.rnws
L: =c[ 1] * x[ 1] +c[ 2] * x[ 2]
+rnu* (q-A*x[ 1] "a( 1] *x[ 2] "a( 2] );
L := CI XI + C2 X2 + Jl (q - A XI Q1 X2D2)
The first-order implicit derivative is obtained as a negative quantity implying
that X2 is decreasing in XI,
> irnplicitdiff (q-A* x[ 1] "a( 1] * x[ 2] "a( 2] ,
x[ 1] ,x[ 2] );
02 XI
°IX2
whereas the second order implicit derivative is always positive implying that X2 is
a strictly convex function of XI.
> irnplici tdiff (q-A* x[ 1] "a( 1] * x[ 2] "a( 2] ,
x[ 1] ,x[ 2] $2);
02 XI (02 + 01)
012 x2 2
> e1:=diff(L,x[ 1] )=0;
Jl A XI Q1 01 X2 D2
el :=CI - =0
XI
5.4 Inequality and Equality Constrained Optimization 181
(_-ID(1)':;~(iffi))1
X2 =e
Expanding to clear the logarithms and simplifying gives the analytic solution
for the optimal values of the inputs XI and X2 and the Lagrange multiplier J.l .
> expand(simplify(Sol,power,symbolic));
If, for example, in the portfolio problem we were to increase the RHS of the
first constraint by one unit, i.e., 900 - 0.10xl - 0.05X2 ::: lor, equivalently,
gl (XI, X2) = 899 - 0.1 OXI - 0.05X2 ::: 0, and solve the problem again, we would
obtain the optimal solution as XI = 7980, X2 = 2020, and f = 12053628,
a reduction (improvement) in the objective function (i.e., portfolio variance) of
12,080,000 - 12,053, 628 = 26,372 units. This difference is very close to the
value of the Lagrange mUltiplier A. = 26400 found as the solution of the original
problem.
We formalize this important result in the following theorem.
Theorem 9 [127, p. 317] Consider the problem
Problem P: min f(x)
s.t. g;(x):::a;,i=I, ... ,m
h; (x) = b;, i = 1, ... , p.
Suppose that for a = (al, ... , am) = 0, b = (b), ... , bp) = 0 there is a so-
lution i that satisfies the constraint qualification with the Lagrange multipliers
A.; ~ 0, i = 1, ... , m, and p;, i =1, ... , p. Thenfor every (a, b) E Rm+p in
the neighborhood of (0, 0) there is a solution x(a, b) depending continuously on
(a, b) such that x(O, 0) = i and such that x(a, b) is a relative minimum of the
problem P. Moreover,
af (x(a,
aa;
b»] 0,0
= -A.;, i = 1, ... ,m
: ( (x(a, b» 1,0 = -p;, i = 1, ... , p.
gl := XI 2 +X2 2 - 5.1
> g[2] :=x[l]+2*x[2]-4: * g[2] <= 0
> vars:={ x[ 1] ,x[ 2]] :
> L:=f+surn(larnbda{ k] *g[ k] ,k=1. .2):
> L_x:=seq(diff(L,x[ k] ),k=1..2):
5.5 Lagrangian Duality 183
without providing any geometric interpretation for this function. In this section we
show that the Lagrangian has the important geometric property that it has a saddle
point at the optimal solution (i, ..x, j.&). To motivate the discussion, we first present
a very simple example and plot the surface of L to observe its three-dimensional
shape.
Consider the problem of minimizing f(x) = (x - 2)2 + I subject to g(x) =
x - I !S 0 for which the obvious optimal solution is i = 1. The Lagrangian
is formed as L(x, A) = (x - 2)2 + 1 + A(X - 1), which is a function of two
variables (x, A). Using Maple's plot3d () function, we plot the surface of the
Lagrangian for the range x=- 2 .. 3 and lambda =0 •. 4 and obtain the graph of
the Lagrangian depicted in Figure 5.5.2
> restart: *
saddle.rnws
> L:=(x-2)A2+1+lambda* (x-1);
L := (x - 2i + 1 + A (x - 1)
> plot3d(L,x=-2 .. 3,lambda=0 .. 4,axes=boxed,
shading=none,orientation~ -152,70],
labels=[ "", "" , ""] ) ;
This graph suggests that the Lagrangian appears to have a saddle point at
around (x, A) = (1,2), i.e., that L(1,A) !S L(1,2) !S L(x,2). Indeed, when
2Maple cannot use different fonts (such as the Roman x and Greek 1) to display the labels in the
same graph. For this reason, the axis labels in Figure S.S are suppressed. Note, however, that x takes
values between -2 and 3 and .4 between 0 and 4.
184 5. Nonlinear Programming
16r---r::::.____ _
14
12
10
8
6
4
2
FIGURE 5.5. The Lagrangian function L = (x - 2)2 + I + l(x - I) has a saddle point at
(x, 1) = (1,2).
we apply the eigenvalue test to the Hessian of L, we obtain one positive and one
negative eigenvalue, implying that the Lagrangian does have a saddle point:
> with (linalg) :
Warning, new definition for norm
H:= [i ~]
> eigenvalues(H);
I +.J2, I - .J2
We should now be able to compute the saddle point of the Lagrangian, i.e., the
x value that minimizes L and the 1 value that maximizes L. We do this using the
following Maple commands:
> restart: # SADDUAL.MWS
> f:=(x-2)A2+1; # Minimize
f := (x - 2)2 +1
> g:=x-l; # 9 <= 0
g :=x-l
> L:=f+lambda*g;
5.5 Lagrangian Duality 185
2x -4+A.
> xsol:=solve(%,x)i
1
xsol := 2 - - A.
2
> subs(x=xsol,L);
!4 A.2 + 1 + A. (l - !2 A.)
> diff(%,larnbda);
1 -!2 A.
> lambdasol:=solve(%,lambda);
lambdosol := 2
> xsol:=subs(lambda=larnbdasol,xsol);
xsol:= 1
These computations show that L(l, A.) ~ L(l, 2) ~ L(x, 2).
To compare the results obtained by our graph based on heuristic arguments, we
re-solve the same problem using Kuhn-Tucker conditions (5.1 )-{5.5):
restart: * SADDLEKT.MWS
*
>
> f:=(x-2)A2+1i Minimize
f := (x - 2)2 + 1
> g:=x-l; * g <= 0
g :=x-l
> L:=f+lambda*gi
L := (x - 2)2 + I + A. (x - I)
> L_x:=diff(L,x)i
L_x := 2x - 4 + A.
> eq:=lambda*diff(L,larnbda)i
eq := A. (x - l)
> ineq_lambda:=lambda>=Oi
ineq_lambda:= 0 ~ A.
> ineq_g:=diff(L,lambda)<=Oi
ineq..s := x - I ~ 0
> sol:=solve({L x,eq,ineq g, ineq lambda},
{ x, lambda} ) i - - -
sol := (A. = 2, x = I)
186 5. Nonlinear Programming
Interestingly, for this problem the solution obtained using the saddle-point anal-
ysis of the Lagrangian and the Kuhn-Tucker conditions agree. This is not a coinci-
dence and when the objective function and the constraint satisfy certain regularity
conditions (e.g., convexity of the functions involved), there is a valid intimate re-
lationship between the saddle-point criteria and the K-T conditions. This is stated
in the following theorem:
Theorem 10 [18, Section 6.2) The feasible point ifor Problem P and the La-
grange multipliers .oX ::: 0 and p satisfy the Kuhn-Tucker conditions (5.1H5.5), if
and only if(i,.oX, p) satisfy the saddle-point conditions L(i,..\, 1') ~ L(i,.oX, p)
~ L(x, .oX, p). • .
Moreover, the function l("\, 1') is concave over any convex subset of its domain.
substituted back into L to obtain the Lagrangian dual function l()', 1'), which is
shown to be concave; hence its global maximum can be found using the standard
methods. Finally, once the optimal (X, ji.) are computed, they can be substituted
back into x to generate the optimal value of the decision vector.
As an application of the Lagrangian duality, we now discuss the solution of
a discrete-time optimal control problem with quadratic objective and linear state
dynamics.
Example 71 A discrete linear quadratic control problem. The problem is to min-
imize the objective
N-I
J = L(q;x; +r;u~) +qNx~
;=0
subject to the state dynamics
Co := qO x02 + ro u02
CI := ql XI 2 + rl Ul 2
> f:=sum(c{ n] ,n=O •. l)+q[ 2] *x[ 2] "2;
h2 := X2 - XI - UI
The Lagrangian L is introduced as
> L:=f+sum(mu[ n] *h[ n] ,n=1. .2);
lxI := 2 ql XI + PI - P2
> Lu[ 1] : =diff (L, u[ 1] ) ;
LUI := 2rl UI - P2
> Lx[ 2] : =di ff (L, x[ 2] ) ;
Lx2 := 2q2 x2 + P2
The decision variables are computed in tenns of the two Lagrange multipliers
Pi'; = 1,2.
> s01xu: =s01 ve ({ Lx[ 1] ,Lx[ 2] ,Lu[ 0] ,Lu[ 1] } ,
{ u[ 0] ,x[ 1] ,u[ 1] ,x[ 2] } ) ;
1,,2 I ( )2 1 2 1,,2
el:=qox02+-_rl_+- PI-P2 +_P2 + __r2_
4 ro 4 ql 4 TI 4 q2
1 P2
+pd--1 PI - P2 1 PI
-xo---)+P2(---+-
1 P2 1 PI - P2
---)
2 ql 2 TO 2 q2 2 ql 2 TI
> e1mu[ 1] :=diff(e1,mu[ 1] );
1 1 1 1 1 P2
eimul :=-XO+PI(------)+--
2 ql 2 TO 2 ql
> e1mu[ 2] : =di ff (e1 ,mu[ 2] ) ;
1 PIli 1 1 1 1
elmU2:= - - +P2(--- - - - - - - )
2 ql 2 q2 2 ql 2 TI
The Lagrange multipliers are found in tenns of the model parameters as fol-
lows.
> s01mu: =s01 ve ({ e1mu[ 1] ,e1mu[ 2] } ,{ mu[ 1] ,mu[ 2] } ) ;
uOpto :=
ql rl +q2 rl +rl rO +q2 rO+q2ql
> xOpt[ 1] :=simplify(x[ 1] );
xoro (rJ + q2)
XQ'Ptl := ----;.....;......:.....;-...:.;;.;----
ql rl +q2rl +rl ro +q2 rO+q2ql
> uOpt[ 1] :=simplify(u[ 1] );
xOrOq2
uQ'Ptl :=
ql rl +q2 +rl ro +q2 rO+q2ql
rl
> xOpt[ 2] : =simplify (x[ 2] );
XOrOrl
X Opt2:= -----..;,..,..;;.....;.-----
ql rl +q2 rl +rl ro +q2 rO+q2ql
Although the solution obtained is of an "open-loop" variety, a careful look at
the structure of the optimal decision vector reveals that the optimal controls U; are
linear functions of the optimal states X; at each time; i.e., in this problem we also
have a closed-loop feedback control.
> uOpt[ 0] Ix[ 0] ;
ql rl + q2 rl + rl ro + q2 ro + q2 ql
> uOpt[ 1] IxOpt[ 1] ;
-~
rl +q2
For another application of this duality theorem, consider a discrete-time vector
optimal control problem with piecewise-quadratic objective function containing
dead-zones, i.e.,
N-I
minJ = QN(XN, iN) + L[Q;(X;, i;) + (u; - u;)' R;(u; - u;)]
;=0
subject to
X;+I = A; x; +B;u; +e;,i =O, . .. ,N-I
where
Qij[x;j - (x;j - aij)f, ifxij::; X;j - a;j
Q;j (xij, X;j) = { 0, ifx;j E [xij - aij, xij + Pij]
Qt[x;j - (x;j + p;j)]2, ifx;j ~ X;j + P;j .
programming problem using the Lagrangian duality. For details of the solution
method and numerical examples with N = 25 periods, we refer the reader to the
paper by Parlar and Vickson [146].
5.6 Summary
Many realistic decision problems are nonlinear in the sense that the objective
function and/or some of the constraints may not be linear. In those cases one
would need to use nonlinear programming (NLP) techniques to model and solve
the problem. This chapter started with an introduction of the fundamental con-
cepts ofNLP such as the convexity of sets and functions. This was followed by a
discussion of unconstrained nonlinear optimization. Next, the important problem
of optimizing a nonlinear objective function subject to nonlinear constraint(s) was
presented. Kuhn-Tucker conditions, constraint qualification and the economic in-
terpretation of the Lagrange multipliers were described with several examples.
Once more, Maple's ability to manipulate symbolic quantities was found useful
in presenting and solving relevant problems.
5.7 Exercises
1. Let the functions f; (x), ; = 1, ... , k be convex over some convex set S c
Rn. Prove that the function f(x) = L:=t f;(x) is also convex over S.
2. Consider the function f(x, y) = xy. Show that f is not convex over R2
but it is convex over a line passing through the origin.
3. The average number of backorders function in the continuous-review (Q, r)
inventory model is given by
7. Consider the objective function f (x, y) = x 2 +4y3. Find all the points that
are local maxima and local minima for f subject to the equality constraint
x 2 +2r = 1.
8. Is the constraint qualification satisfied for the problem of minimizing the
r
distance from the origin to the implicitly defined curve = (x - 1)31
9. Consider the following problem.
min
s.t. -x +y = I
!
x+y ~ 1
x,y ~ 0
(a) Solve this problem graphically.
(b) Check your answer using the Kuhn-Tucker theory.
(c) Find the dual function t(>",,.,,) and show that it is concave.
1O. Minimize
N
J = L(qx; + ruf) + qxj
;=0
subject to the state dynamics
6.1 Introduction
Dynamic programming (DP) is a simple yet powerful approach for solving certain
types of sequential optimization problems. Most real-life decision problems are
sequential (dynamic) in nature since a decision made now usually affects future
outcomes and payoffs. An important aspect of optimal sequential decisions is the
desire to balance present costs with the future costs. A decision made now that
minimizes the current cost only without taking into account the future costs may
not necessarily be the optimal decision for the complete multiperiod problem.
For example, in an inventory control problem it may be optimal to order more
than the current period's demand and incur high inventory carrying costs now in
order to lower the costs of potential shortages that may arise in the future. Thus,
in sequential problems it may be optimal to have some "short-term pain" for the
prospect of "long-term gain."
Dynamic programming is based on relatively few concepts. The state variables
of a dynamic process completely specifY the process and provide information
on all that needs to be known in order to make a decision. For example, in an
inventory control problem the state variable X, may be the inventory level of the
product at the start of period t. Additionally, if the supplier of the product is not
always available, then the supplier's availability status may also be another state
variable describing the inventory system.
In the inventory control example, ordering decisions are made at certain times.
Such times are called stages and they may be discrete or continuous. If the inven-
tory is managed using a periodic-review system where decisions are made, say,
once every week, then the stage variable would be discrete and it may be sequen-
tially numbered by the integers t = 0, I, 2, .... If, however, a continuous-review
(transactions reporting) system is in place, then the order decisions may be made
at any time and the stage variable would be continuous.
Having defined the state and stage variables, we now introduce the concept of
a decision, which is an opportunity to change the state variable. For example, if
the inventory level at time t is x, units, then ordering u, units is a decision that
increases the current inventory to x, + u, units. The decision to order u, units
in period t results in a cost in the current period and depending on the demand
w" period t may end with negative or positive inventory resulting in shortages
or surpluses that may give rise to additional costs for the current period t. If the
process continues for, say, N periods into the future, the optimization problem
is to find the best order policy that will minimize the total cost of the inven-
to~ ~stem. In general, the total cost incurred over N periods can be written as
1:,::0 L,(x" u" w,) + LN(XN) where L,(·) is the cost incurred in period t.
The processes that are studied by dynamic programming pass from stage to
stage and thus the states undergo a transformation represented by the equation
Xt+1 = f(x" u" w,). In the inventory example, after a demand realization of w,
units in period t, the next period's state is computed from Xt+1 = x, + u, - w,
where the transformation function takes the form f(x" u" w,) = x, + u, - w,.
Depending on the nature of the demand w" the transformation may be determinis-
tic or stochastic. In the former case, the next period's state variable Xt+ I is known
with certainty, but in the latter case Xt+1 is a random variable whose distribution
can be obtained as a function ofx" u" and w,.
Finally, we define an optimal policy as a decision rule that computes an op-
timal decision u, for each conceivable value of the state variable x, at stage
t = 0, I, ... , N - I, i.e., 1r = [po(xo), PI(XI), ... , PN-I(XN-I)]. Using the
optimal policy 1r, the optimal decision is computed from u, = p,(x,). For ex-
ample, in the inventory problem, an optimal policy may be shown to be of the
form
p,(x,) = °
{ s, -x, ifx, < S,.
otherwise
where S, is the "base-stock" level computed using the problem parameters [166].
At any stage, the optimal decision (a number) is computed using the above policy.
If at the start of period 4 we have X4 = 3 and, say, S4 = 10, then the optimal order
quantity U4 in period 4 is obtained as U4 = P4(3) = to - 3 = 7 units.
6.1 Introduction 195
Using the "principle of optimality" I that was first enunciated by Richard BeIl-
man [21], [23, p. 83], dynamic programming is used to "divide and conquer" a
sequential optimization problem by decomposing it into a series of smaller prob-
lems. Once the smaller problems are solved, they are combined to obtain the s0-
lution of the complete problem.
For example, consider a three-period inventory problem with t = 0 as the be-
ginning of December, t = I as the beginning January and t = 2 as the beginning
February. Using the "backward-recursion" approach ofDP, we would first find the
optimal solution for February-the last stage-and compute the optimal decision
U2 = ,u2(X2) as a fimction of any possible value of the inventory X2 at the start
of February. With the information on the optimal decision available, we would
then compute the minimum cost V2(X2) for February. Stepping back one month,
the optimal policy ,u I (XI) for January would be found by adding the costs for that
month to the minimum cost V2(X2) that was found for February. This solution
would then be used to compute the minimum cost VI (XI) ("cost to go") for peri-
ods I and 2 (January and February). Finally, the optimal solution for December
would be computed taking into account the costs for that month plus the cost to
go VI (XI) for the remaining months of January and February. Once the optimal
policy is found for each month as a fimction of the entering inventory for that
month, as time progresses and state variables X, are observed, actual decisions
would be computed using the optimal policy fimctions ,u,(x,), t = 0, 1,2.
As we indicated, the three-month inventory control example uses the backward-
recursion approach of DP. For an interesting discussion of a puzzle and a mathe-
matical proof using the backward approach, see Nemhauser [138, pp. 19-22 ].
When the process studied is deterministic, it may also be possible to use the
"forward-recursion" approach, which can sometimes be more intuitive. For de-
tails of the forward approach, we refer the reader to Bertsekas [31, p. 52], Cooper
and Cooper [49, p. 114-122], Dane [57, pp. ISO-ISS] and Larson and Casti [117,
p.233].
Sequential optimization problems with discrete stages can be conveniently for-
mulated using the state-equation approach as in Bertsekas [31]. The state trans-
formation of the basic problem is represented by a discrete-time dynamic system
where X, is the state (with xo a given constant), u, is the control and w, is the
uncontrol1able exogenous disturbance parameter that may be deterministic or ran-
dom. There may be constraints on the control variables such as u, ~ 0 so that u,
may have to be an element of a constraint space C,. When the problem is deter-
ministic, there may also be constraints on the state variables so that X, may have
to be an element of the constraint space S,. If L,(x" u" w,) is the cost incurred
JUAn optimal policy has the property that whatever the initial state and initial decision are, the
remaining decisions must constitute an optimal policy with regard to the state resulting from the first
decision."
196 6. Dynamic Programming
N-I
L Lt(xt, Ut, Wt) + LN(XN),
t=O
(6.2)
which is the total cost function for the N -stage sequential problem. Note that if
the disturbance Wt is a random variable, then the proper statement of the objective
would involve expectations with respect to all the random variables, i.e.,
N-I
EWO.WI ••••• WN_1 L Lt(x" U" w,) + LN(XN).
t=O
VN(X) = LN(XN)
where the decision U; must be chosen from the feasible set C;, ; = t, ... , N - I.
Using the separability properties of this additive cost function and the princi-
ple of optimality, it can be shown that (see, for example, Bertsekas [31, p. 19],
Nemhauser [138, pp. 28-31], Larson and Casti [117, pp. 45-47]) the value func-
tion J't(Xt) is the solution ofa functional equation given as
= LN(XN).
We note here that when Wt is random, we minimize the expected value of the
term inside the brackets, i.e., E w, {Lt(x" u" w,) + J't+I[ft(X" u" w,)]}, where,
of course, the expectation is taken with respect to the probability distribution of
W,. In this case J't(Xt) is defined as the minimum expected cost to go for stages
t,t+I, ... ,N.
If the objective function is in the multiplicative form, i.e., if we are trying to
optimize n~ Lt(xt. Ut. Wt), then the functional equations for the value function
are obtained as
For details of this problem, see Larson and Casti [117, pp. 48-49] and Nemhauser
[138, p. 37]. The multiplicative objective was originally used by Bellman and
Dreyfus [26] to model some types of reliability problems.
We will now discuss some examples of sequential decision problems and present
their analytic solution using Maple. We will see that Maple's ability to manipulate
symbolic expressions makes it an ideal tool for extracting the optimal policies for
these problems.
The nodes in the diagram in Table 6.1 are denoted by (i, j) where i corresponds
to a stage (i = I, 2, ... , 5) and j corresponds to a state in state i. Given the state
j in stage i, the decision to travel to state k in the next stage i + I results in a cost
(i.e., insurance premium) of cij(k). These costs are indicated next to the arrows
corresponding to each decision. For example, clI(2) = 4 and C21(3) = 6. The
problem is to find the route that results in the minimum cost.
For this problem, the value function V;j is the minimum cost from state (i, j)
to the final state (5, I) using the optimal policy. Thus, the dynamic programming
recursive equations are written as
VSI =0
VS,I :=0
Stage 4 computations are also trivial since, once in stage 4, the stagecoach must
travel to the last state.
> i:=4;
; :=4
> for j from 1 to 2 do
> V[ i,j] : =min (seq(c[ i,j][ k] +V[ i+l,k] ,k=1. .1));
> Tq i,j] :={ seq(c[ i,j][ k] +V[ i+1,k] ,k=1..1)];
> for k from 1 to 1 do
u[ i, j, k] :=is (Tq i, j] [ k] =V[ i, j]) od od;
V4,I :=4
TC4,I := [4]
V4,2 := 5
TC4,2 := [5]
> for j from 1 to 2 do for k from 1 to 1 do
print([ i,j,k,u[ i,j,k] ,Tq i,j][ k]]) od od;
[4, 1, 1, true, 4]
[4, 2, 1, true, 5]
For stage 3, we find the value function for each state and the corresponding
optimal decision. For example, [3,1,1, true, 7] means that in state [3, 1] it is
optimal to choose k = 1, which results in a minimum overall cost of 7. Thus,
the word true next to a decision (the third component in the list) implies the
optimality of that decision. On the other hand, the word false implies that the
corresponding decision is not optimal.
> i: =3;
;:= 3
> for j from 1 to 3 do
> V[ i, j] : =min (seq (c[ i, j] [ k] +V[ i+1, k] ,k=1. .2) ) ;
> Tq i,j] :={ seq(c[ i,j][ k] +V[ i+1,k] ,k=1. .2)];
> for k from 1 to 2 do
u[ i, j, k] : =is (Tq i, j][ k] =V[ i, j]) od od;
V3,I :=7
TC3,I := [7, 8]
V3,2 := 7
V3,3 := 6
200 6. Dynamic Programming
1'C3.3 := [8, 6]
> for j from 1 to 3 do for k from 1 to 2 do
print([ i,j,k,u[ i,j,k] ,Tq i,j][ k))) od od;
[3, I, I, true, 7]
[3, I, 2,false, 8]
[3, 2, I, true, 7]
[3,2, 2,false, 1I]
[3,3, I,false, 8]
[3, 3, 2, true, 6]
Stage 2 and stage I calculations are perfonoed in a similar manner:
> i:=2;
i :=2
> for j from 1 to 3 do
> V[ i,j] :=rnin(seq(c[ i,j][ k] +V[ i+l,k] ,k=1. .3»;
> Tq i,j] :={ seq(c[ i,j][ k] +V[ i+1,k] ,k=1..3)];
> for k from 1 to 3 do
u[ i, j, k] :=is (Tq i, j] [ k] =V[ i, j]) od od;
V2.) :=8
1'C2.2 := [lI, 9, 9]
V2. 3 := II
We can now extract the optimal solution from the results. From the initial
state (1,1), it is optimal to travel to (2,1) at a one-stage cost of 3 since we find
[1,1,1,lrue,II].2 Next, from (2,1) it is optimal to go to (3,2) at a cost of I since
[2,1,2,lrue,8].3 From (3,2), the stagecoach should travel to (4,1) at a cost of 3,
and finally from (4,1) it will go to (5,1) at a cost of 4. Adding the one-stage costs
we find 3 + I + 3 + 4 = II as we found from [1,1,I,true,II].
are penalized using quadratic terms. We will assume that xo =F (otherwise the °
possible way. Deviations from the origin for both the state X, and the decision u,
solution would be trivial) and that there are no constraints on the state and the
control.
Although this model with linear system and quadratic cost appears simple, its
generalizations have found applications in economics and operations research;
see Bensoussan, Hurst and Naslund [29, Chapter 3], Holt, Modigliani, Muth and
Simon [93], Parlar [140], Parlar and Gerchak [144] and Parlar and Rempala (145).
Forming the DP functional equation, we have
V, (x,) = min[x;+u;+v,+I(x,+u/)],
u,
1=0,1,2
We will now use Maple to solve this functional equation and generate the opti-
mal policy for the problem.
> restart: * LQ2.rnws
We begin by infonning Maple that the boundary condition is V3(X) = x 2•
> V[ 3] :=x->x"2;
V3 :=X ~ x 2
Now, for period 2 the cost expression that should be minimized is C2 = x~ +,q +
V3(X2 + U2), i.e., the sum of the current cost and the future minimum cost with
X3 = X2 + U2 as the state for stage 3.
> e[ 2] : =x"2+u"2+V[ 3] (x+u);
C2 := x 2 + u2 + (x + u)2
Differentiating this expression, equating the result to zero and solving gives the
optimal policy in period 2 as P2 = -!x.
> deriv[ 2] :=diff(e[ 2] ,u);
deriV2, := 4u + 2x
> rnu[ 2] : =so1ve(deriv[ 2] ,u);
1
P2:= --x
2
Using these results, the value function V2 (x) for period 2 is found as a quadratic
function of the state variable.
> V[ 2] :=unapp1y(subs(u=rnu[ 2] ,e[ 2] ) ,x);
3
V2 :=x ~ _x 2
2
Repeating the same procedure for the other stages, the optimal decision and the
value function is computed explicitly as a function of the state variable in each
stage:
> e[ 1] : =x"2+u"2+V[ 2] (x+u);
CI := x 2 + u2 + ~2 (x + u)2
> deriv[ 1] :=diff (e[ 1] ,u) ;
derivl := 5 u + 3x
> rnu[ 1] :=so1ve(deriv[ 1] ,u);
3
PI :=-5 x
> V[ 1] : =unapp1y (subs (u=rnu[ 1] ,e[ 1] ) ,x) ;
8
VI :=X ~ _x 2
5
> e[ 0] : =x"2+u"2+V[ 1] (x+u);
6.3 Models with a Linear System and Quadratic Cost 203
co := X2 + U2 + ! (x + u)2
5
> derive 0] :=diff(c[ 0] ,u);
26 16
derivo:= Su+Sx
> rnu[ 0] :=solve(deriv[ 0] ,u);
8
Ilo:= -Ox
> V[ 0] :=unapply(subs(u=rnu[ 0] ,c[ 0] ),x);
21
Vo :=X ~ _x2
13
The results (to three significant digits) are summarized in the table below.
t 1l,(X) v, (x)
0 -0.615x 1.615x 2
1 -0.6x 1.6x 2
2 -0.5x 1.5x 2
3 x2
Thus, if the initial value of the state is, say, xo = 1, then using the optimal
decisions prescribed by the policy
one would obtain a total minimum cost of Vo(l) = 1.615 for the periods 0, 1,2
and 3. For this case, the numerical values of the optimal decisions are obtained as
follows:
t x, u,
o 1 -0.615
1 0.385 -0.231
2 0.154 -0.077.
3 0.077
Now suppose that the initial decision is not made optimally and instead of uo =
-0.615 we use, say, uo = -0.5, which brings the system to XI = 1 - 0.5 = 0.5.
What is the best decision now at the start of period 1 given this value of the
state? As the principle of optimality states, "An optimal policy has the property
that whatever the initial state and initial decision are, the remaining decisions
must constitute an optimal policy with regard to the state resulting from the first
decision." Thus, in period 1 we make the optimal decision for that period using
UI = III (0.5) = -0.6 x 0.5 = -0.3. This is the power and elegance of the
dynamic programming approach: Regardless of what may have transpired in the
past, at the start of any period we know exactly what to do since DP makes the
optimal policy available for all periods and for any value of the state.
204 6. Dynamic Programming
In this example we can see another aspect of the power and flexibility of dy-
namic programming. Now consider the following case: After applying the correct
decision uo = -0.615, what happens if for some reason there is an unexpected
random disturbance on the system and we find XI = 0.4 (instead of 0.385)1
The answer is fortunately very simple. Since we have the optimal policy avail-
able to us as P.I (XI) = -0.6XI, we just compute the new (optimal) decision as
UI = -0.6 x 0.4 = -0.24. Even though the correct initial decision uo = -0.615
resulted in an unexpected value of the state XI = 0.4, we can still make the next
decision in stage I optimally using the optimal policy P.I (x I) for that stage.
Naturally, the solution here is the same as the one we fotmd before. However,
note that the NLP solution is in some sense "frozen" because tmlike the DP s0-
lution it cannot directly deal with a situation where after applying uo = -0.615
there is an tmexpected random disturbance on the system and we find XI = 0.4
(instead of 0.385). To answer this question, the NLP problem must be re-solved
for stages I, 2 and 3 with XI = 0.4 as the initial value of the state in stage
I. This shows that the DP approach is, in general, much more powerful than a
competing optimization technique since the DP solution is obtained in terms of
dynamic policies rather than the static-frozen---decisions produced by the com-
peting techniques. 4
The simple model described and solved using DP can easily be generalized us-
ing Maple. For example, one may assume that there are ideal (i.e., target) levels
{x" t = 1,2, ... , N} and {il" t = 0, I, ... , N - I} for the states and deci-
sions, respectively, and that deviations from these trajectories are to be penalized
quadratically at a cost of q, for the states and r, for the decisions. If the dis-
turbances also follow a particular trajectory {WIt t = 0, ... , N - I}, then the
sequential optimization problem can be written
N-I
min L{q,(x,-x,)2 +r,(u, - u,)2} +qN(XN -XN)2
,=0
V3 := x ~ 2 (x _ 1)2
> for t from N-1 by -1 to 0 do
> e[ t] :=q( t] * (x-xHat[ t] ) "2+r[ t] * (u-uHat[ t] ) "2
+V[ t+1] (a[ t] * x+b[ t] * u+~ t]
) ;
> deriv[ t] :=diff(e[ t] ,u);
> mu[ t] :=evalf(solve(deriv[ t] ,u»;
> V[ t] : =
unapply(evalf (simplify (subs (u=mu[ t] ,e[ t] »),x);
> od;
The results for the optimal policy and the value function for each period t =
0, ... ,3 are summarized in the following table.
t p,(x) V,(x)
o -0.249x - 0.494 l.12xl - 6.5 Ix + 50.3
I -3.2Ix + 1.13 24.6x 2 +0.192x + 29.S
2 -O.Sx + I.S 5.S0x 2 + lO.4x + 14.S
3 2(x _ 1)2
It is worth noting that in this more general problem the optimal policy is linear
and the value function is quadratic in the state variable. This result would be valid
even when the states and the controls are multidimensional and the disturbances
6.3 Models with a Linear System and Quadratic Cost 207
are random provided that the cost is quadratic and the system equations are linear
with no constraints on the states and controls. For a discussion of this issue, see
Bertsekas [31, Section 4.1].
subject to
Xt+) = Xt + u" t = 0, I, . .. .
For such a problem, the functional equations V,(Xt) for, say, t = 100 and t = 99
would be given by
VIOO(XIOO) = min
11100
[xfoo + u~oo + VIOI(XIOI)]
and
V99(X99) = min [x~ +';99 + VIOO(XIOO)].
1199
Since there is some regularity in the system equations Xt+ I = f, (Xt, Ut) = Xt + Ut
and the cost function L t = xi-
+ u~ (i.e., that t does not appear explicitly in f, or
L t ), under certain conditions the functional equation for the value function can be
written as
V(X) =min {L(x, u) + V[f(x, u)]},
II
Successive Approximations
One of the methods that can be used to solve this problem is known as "successive
approximations" or "approximation in function space." The method starts with a
SIn order for Vex) to remain finite, three conditions an:: required: (i) L(x, u) must be bounded for
finite x and II, (ii) a state i and control ii must exist such that L(i, ii) = 0 and (iii) the specified state
i must be reachable from any admissible state by applying a finite number of admissible controls; see,
Larson and Casti [117, p. 222].
208 6. Dynamic Programming
guess V(O)(x) for the solution V(x). Using this guess, a new value of the function
V(I) (x) is computed from
Vo := x -+ 2.x 2
> for n from 0 to 5 do
> c[ n] :=(x,u)->L(x,u)+V[ n] (x+u):
> diff (c[ n] (x, u), u) :
> uApp:=solve(%,u);
> subs (u=uApp, c[ n] (x, u) ) :
> V[ n+1] :=unapply(simplify(%),x);
> od;
co := (x, u) -+ L(x, u) + Vn(x + u)
6.u +4.x
uApp:= -.6667x
1.667x 2
VI :=x -+ 1.667x 2
CI := (x, u) -+ L(x, u) + Vn(x + u)
5.334u + 3.334x
6.3 Models with a Linear System and Quadratic Cost 209
uApp:= -.6250x
1.625x 2
V2 := X ~ 1.625x 2
C2 := (x, u) ~ L(x, u) + Vn(x + u)
5.250u + 3.250x
uApp := -.6190x
1.619x 2
V3 := x ~ 1.619x 2
C3 := (x, U) ~ L(x, u) + Vn(x + u)
5.238u + 3.238x
uApp := - .6182x
1.618x 2
V4 := x ~ 1.618x 2
C4 := (x, U) ~ L(x, u) + Vn(x + u)
5.236u + 3.236x
uApp := -.6180x
1.618x 2
Vs := x ~ 1.618x 2
cs := (x, u) ~ L(x, u) + Vn(x + u)
5.236u +3.236x
uApp := -.6180x
1.618x 2
V6 := x ~ 1.618x 2
We thus see that, after about five iterations, the solution quickly converges to
V(x) = 1.618x 2 and p(x) = -0.6ISx .
structure of the optimal policy and the fonn of the value function, we assume that
V (x) = Ax2 and attempt to find a closed-fonn fonnula for the coefficient A. The
symbolic manipulation of the expressions to solve this problem is relegated to
Maple, which finds the solution easily.
> restart: *LQClosedForm.mws
> V:=x->A*x"2;
V :=x ~ Ax2
> c:=Q*x"2+R*u"2+V(x+u);
c := Q x 2 + R'; + A (x + ui
> cu:=diff(c,u);
cu:= 2Ru +2A (x + u)
> usol:=solve(cu,u);
Ax
usol:=---
R+A
> RHS:=normal(subs(u=usol,c));
RHS := x 2 (A Q + R A + Q R)
R+A
> Asol:=solve(V(x)=RHS,A);
1 1 1 1
Asol:= 2 Q + 2 JQ2 +4 QR, 2 Q- 2JQ2 +4Q R
> subs (A=Asol[ 1] , usol) ;
1 1
(2 Q+ 2 JQ2 +4Q R)x
R+~Q+~JQ2+4QR
2 2
Note that since Q - JQ2 +4QR < 0 and since the minimum cost V(x)
must be nonnegative, we choose the first solution Asol[ 1] for A in the above
computations.
> V:=subs (A=Asol[ 1] , V (x) ) ;
1 1
V := (2 Q + 2 JQ2 +4 Q R)x 2
To summarize, the optimal policy and the value function for this general case
are obtained as p(x) = -Ax/(R + A) and V(x) = Ax2 where
A= ~ (Q + J Q2 + 4Q R) .
Naturally, for the special case when Q = R = I, we obtain A = 1.618 so that
V(x) = 1.618x 2 and p(x) = -O.6ISx as we had found previously.
6.4 Continuous-Time Dynamic Programming 211
00
subject to
Xt+1 = x, + u" 1 = 0, I, .. ..
For example, assuming Q = 2, i = I, R = 3, 14 = 1.5, and P = 0.9 and starting
with the initial guess of V(O) = 4x 2 + 2x + 60, after about seven iterations the
method converges to the value function V(x) = 3.SSx2 + l.lSx + 61.6 and to
policy ",(x) = 0.642 - 0.516x.
subject to
x = I(x, u, r), X(I) = x
with the condition that at the final time I = T, we have V[x(T), T] = S[x(T), T].
Ifwe write the integral in (6.4) as
subject to
x = I(x, u, r), X(I + al) = x + ax.
This follows from the principle of optimality because the control u( r) for 1+ al ~
r ~ T is optimal for the problem starting at time 1+ al in state x(1 + At) =
x+ax.
Now using the definition of V(I , x), we can rewrite (6.5) as
t+41 ]
V(I, x) = muin [[ Ldr + V(I + al,X + ax) .
ISfSt+4t I
with the boundary condition V[x(T), T] = S[x(T), T]. The resulting PDE is
known as the Hamillon-Jacobi-Bellman (HJB) equation since it was originally
developed by Bellman [22] to solve problems in the calculus of variations. For
discussions of the development of this PDE and examples of its solution, see
Bertsekas [31, p. 91-92], Bryson and Ho [39, p. 135], Kamien and Schwartz [99,
pp. 238-240], Kirk [108, pp. 86-90] and Sage and White [162, pp. 76-77].
A Remark on Discounting
Note that if we have an infinite horizon problem and if continuous discounting is
applied with a discount factor e-rt , then the optimization problem would be to
minimize.roo e-rt L(x, u, I)dl subject to the state equation x = f(x, u) with the
initial state as x (0) = xo. In this case, the HJB equation would be written as
- V, (I, x) = min[e-
u
rt L(x, u, I) + Vx(/, x)f(x, u, I)]
without any boundary condition on the value function. Here the value function is
defined as the minimum cost discounled 10 lime zero that can be obtained starting
at time I in state x and using the optimal policy. However, it can be shown that for
"autonomous" systems where time does not appear in the cost function (except
for the discount term) and in the system equations, a similar ordinary differential
equation (ODE) can be found for the HJB problem where the value function V (x)
would be defined as the minimum cost discounted to the current lime.
In autonomous systems, the problem is to minimize .roo e-rt L (x, u) dl subject
to x = f(x, u). For this problem we write the HJB equation where discounting is
to the current time (rather than to time zero) as
V(/,x) = min[L(x,
u
u) + e-rM V(t + M,x + ~x)].
Since e-r Ilt ~ 1 - r ~I and the value function at (I + ~/, x + ~x) is expanded
as
V(t + M,x + ~x) ~ V(/,x) + V,~I + Vx~x,
after simplifications and usual limiting operations the HJB equation is obtained
as an ODE in terms of V (x) as follows: 6
r V(x) = min[L(x,
u
u) + V'(x)f(x, u)].
For a more detailed discussion of this issue, see Beckmann [19, Part IV] and
Kamien and Schwartz [99, pp. 241-242].
We now consider two examples where the HJB partial differential equation can
be solved explicitly to find the value function and the optimal policy.
6Notc that in the limiting operations we have limAI-+O Ilx/Ilt =i = f(x, u).
214 6. Dynamic Programming
10 00
e-"(Qx 2 + Ru2)dt
subject to i = u with the initial condition x (0) = xo > o. We now solve the HJB
equation - Vi = minu[e-rl (Qx 2 + Ru2) + Vxu] for this problem using Maple.
> restart: *
LQPDE.rnws
> L:=(x,u)->exp(-r*t)* (Q*x"2+R*u"2);
L := (x, u) ~ e(-rl) (Qx 2 + Ru2)
> f:=u;
! :=u
> RHS:=L(x,u)+diff(V(t,x),x)*f;
RHS:= e(-rl) (Qx 2 + Ru2) + (/x V(t, x»u
The optimal policy is obtained in terms of Vx as follows.
> uSol:=cornbine(solve(diff(RHS,u),u),exp);
V(t, x»e(rl)
•. cool .=
UI.J<.
__2I ...(.Q.
0:::::;(:.-_ _ __
R
Using this policy we develop the HJB partial differential equation and attempt
to solve it using Maple's pde () function.
> HJB:=-diff(V(t,x),t)=L(x,uSol)
+diff(V(t,x),x)*uSol;
4 R 2 R
> pdesolve(HJB, V(t,x»;
Error, (in pdesolve/exact/charac) dsolved returned
multiple answers,
[{ t ( Fl) = - Fl+ C4}, {p[ 2] ( Fl) =
DESoI({ (diff(diff( Y( FI), FI), Fl)*R
+r*diff(t( FI), FI)*dIff( Y( Fl),
Fl)*R+Q* Y( Fl»/R},{ Y(-Fl)})
* C3, x( FI)-=-1/2*exp(r*t( FI»/Q
*diff (DESol ({ (diff (diff ( Y (-Fl), FI), FI)*R
+r*diff(t( FI), FI)*diff( Y( FI); FI)*R
+Q* Y ( FI» IR} , r
Y ( FI)}); Fl> * C3},
{P[I] (-Fl) =Int(I/4*r*(4*exp(-2*r*t( FI»
*Q*x (_FI) "2*R+P[ 2] (_FI) "2)*exp(r*t (_FI» I
6.4 Continuous-Time Dynamic Programming 215
VI := -r e(-r t) A x 2
Vx:= 2e(-rt) A x
> HJB;
re(-rt) Ax2 =
e(-rt) x 2 (_Q R + A2)
R
Substituting and simplifying, we finally reduce the problem to the solution of a
quadratic equation in terms of the unknown A:
> ASol:=solve(HJB,A);
1 1 1 1 ~~~---
ASoI := -2: r R + 2: Jr2 R2 + 4 Q R, -2: r R - 2: Jr2 R2 + 4 Q R
Since the value function must be positive, we choose the first solution ofASol
so that we have A = -!r R + !Jr2 R2 + 4QR. The optimal policy is then 0b-
tained as u = -(A / R)x.
> uSol:=combine(uSol);
Ax
uSo/:= - - -
R
> HJB:=-diff(V(t,x),t)=L(x,uSol)
+diff(V(t,x),x)*uSol;
I (..£. V(/, x»2
HJB:= -(I; V(/, x» = --4 OX
C)
+C2X
An attempt to solve the PDE explicitly using Maple fails.
> pdesolve(HJB, V(t,x));
Error, (in pdesolve/exact/charac) dsolved returned
multiple answers,
[ { p[ 1] ( F1) = C4}, {P[ 2] ( F1) = -c( 2] * Fl + C3} ,
{U( Fl)-=Int«=p[ 1] ( F1)*c(-1] - -
+1/2*P[2] (F1)"2)/c(1], F1)+ C2}, {x(J1)
Int(1/2/c[ l]*p[ 2] ( F1),-F1)+-C1},
{t(J1) = -J1+_csfl - -
At this stage we make use of the trial form of the value function and compute
its derivatives with respect to I and x.
> V: = (t, x) ->a+b* x* t+h* x"2/t+ k* t "3;
Vt:=diff(V(t,x),t); Vx:=diff(V(t,x),x);V(T,B);
hx 2
V := (I, x) -+ a + b x I + - + k 13
I
6.4 Continuous-Time Dynamic Programming 217
hx 2
VI := b x - -2- + 3 k 12
I
hx
Vx:=bl+2-
I
a+bBT+ rhB2 + kT 3
> HJB:=lhs(HJB)-rhs(HJB);
hx 2
hx2 I (bl +2-)
HJB:= -bx + - -3k1 2 + - I -C2X
12 4 Ct
The HJB equation is now reduced to a nonlinear algebraic equation in tenns of
x, 12 and x 2/ 12 with unknown constants A, B, H and K, which we now compute
analytically.
The coefficients of x and 12 are easily extracted using the Maple eoe f f ( )
function.
> ex:=eoeff(HJB,x);
bh
ex := -b + - - C2
Ct
> et2:=eoeff(HJB,t A 2);
I b2
cI2 := -3 k + - -
4 Ct
2
To extract the coefficient of x / 12 , we use a somewhat obscure Maple function
algsubs () that perfonns more general algebraic substitutions than the substi-
tutions subs () function can make. This substitution will have a temporary effect
of defining x 2/1 2 as z2, thus making the expression a polynomial so that the eo-
e f f () function can be applied.
> x2t2:=algsubs(x A 2/t A 2=z A 2,expand(HJB));
(bCt-bh+C2Ct)X I (l2kCt-b2)/2 hz2(c1 +h)
x212 := - - + -......;...~--'-
Ct 4 CI CI
> ex2t2:=eoeff(x2t2,z A 2);
ex212 := h (Ct + h)
Ct
To make sure that we have not missed any tenns while extracting the coeffi-
cients, we perfonn a simple check and observe that everything is in order.
> simplify (ex* (x)+et2*(t A 2)+ex2t2* (x A 2/t A 2)-HJB);
o
Now that we have the algebraic expressions for the coefficients of x, 12 and
ex, et2 and ex2t2) and the final time condition that V[T, x(T)] =
X 2 /1 2 , (i.e.,
218 6. Dynamic Programming
1 C2 2
48 e)
The value ftmction V (I, x) and the optimal production rate x= U are now
easily computed as ftmctions of the stage I and state x .
> V(t,x); * Value function
1 -24C2 B T2 C) - 48c)2 B2 + C2 2 T4 1 C) x 2 1 C2 2 13
-- --C2XI---+---
48 T e) 2 I 48 C)
> Vx;
1 C) x
--C21 - 2 -
> expand(sirnplify(uSol));
2
* Optimal production rate
I
1 IC2 x
--+-
4 C) I
To obtain an analytic expression for the optimal production rate u(l) and for the
optimal inventory level X(I), we solve x(l) = U(I) using the form of the optimal
policy just determined.
> dsolve({diff(x(t),t)=(t*c[ 2] /(4*c[ 1] ))+x(t)/t,
x(O)=O, x(T)=B} ,x(t));
> xOpt:=unapply(normal(x(t)),t);
uOpt:=unapply(normal(diff(x(t),t)),t);
UOpI:=I-"7 _~ -202IT+02T2_4Bcl
4 TCI
V,(x,) = min
r/~II/~r4
[100(u, _x,)2 + l000(u, -r,)+ Vt+I(Xt+I)],t = 1, ... ,4
with the boundary condition
For stage 4 the value function V4(X4) is defined as the boundary condition.
> V[ 4] : =unapply (s* (r[ 4] -x) "2, x) ;
V4 := x ~ 100(260 - x)2
For stage 3 the recursive relationship is
where C2 (X2 , U2) = 100(U2 -X2)2 + lOOO(U2 -250) + V3(X3). Here the analysis
becomes more complicated.
222 6. Dynamic Programming
/
",
/
255 /
250
221.67 -
252.5 260
The value function V2(X2) and C) are easily computed in terms of the piece-
wise () function. But we suppress the output of these functions in order to con-
serve space.
> c[ 2] :=s* (u-x) "2+w* (u-r[ 2] ) +V[ 3] (u);
1 255
C2 := l00(u -x)2 + 1500u - 312500 + 100(-2 u + 2)2
+ 100 (265 _ ~ u)2
2 2
> cp[ 2] :=diff(c{ 2] ,u); cpP[ 2] :=diff(c{ 2] ,u$2);
cP2 := 300 u - 200 x - 24500
6.5 A Constrained Work Force Planning Model 223
CPP2:= 300
> mu( 2J : =501 ve (CP[ 2J ,U) ;
2 245
1l2:=3"x+T
> i u( 2J is feasible from r[ 2J =250 to R=260
> evalf (subs (x=r[ 1J ,mu( 2] ) ); evalf (subs (x=R, mu( 2J ) ) ;
221.6666667
255.
> xLow:=evalf(solve(mu( 2]=2S0,x));
xLow := 252.5000000
> xHigh:=evalf(min(R,solve(mu( 2J=260,x)));
xHigh := 260.
> uLow:=subs(x=xLow,mu( 2J);
uLow:= 250.0000000
> uHigh:=subs (x=xHigh,mu( 2] );
uHigh := 255.0000000
> mu( 2] :=piecewise(x<=xLow,r[ 2] ,x<R,mu( 2] );
250 x ~ 252.5000000
1l2:= { 2 245 260
3"x+T x <
> cp[ 2J ;
300 U - 200 x - 24500
> assume(210<x,x<252.S,250<u,u<260); is(cP[ 2J>0);
true
> x : =' x'; u : =' u' ;
x :=x
U:=U
> VI 2] : =unapply (subs (u=mu( 2] ,c[ 2J ) ,x) :
> c[ 1J :=5* (u-r[ 4] ) "2+w* (u-r[ 1] ) +V[ 2] (u):
Although we do not present the graph of the CI function here, we include a
Maple command plot (c[ 1] ,u=190 .. 260) that can be used to note that CI
is convex in UI. Thus differentiating this function using the Maple diff () com-
mand and solving gives the optimal numerical value of the first period's decision
as UI = 252.5. The minimum total cost for all four periods is now easily found as
VI = 117500 by substituting the optimal UI into CI.
> iplot(c[ 1J ,u=190 .. 260,discont=true);
> cp[ 1J : =dif f (c[ 1J ,u) :
224 6. Dynamic Programming
PI := 252.5000000
"I := 252.5000000
> V[ 1) : =evalf (subs (u=rnu[ 1) ,C( 1) »;
VI := 117500.0000
The optimal employment levels for the other periods are easily computed as
"2 = 250, "3 = 252.5 and "4 = 260.
> x: =rnu[ 1) ; u[ 2) : =rnu[ 2) ;
x := 252.5000000
"2 := 250
> x: =rnu[ 2) ; u( 3) : =evalf (rnu[ 3) );
x := 250
"3 := 252.5000000
> x: =evalf (rnu[ 3) ) ; u[ 4) : =r{ 4) ;
x := 252.5000000
260
"4 :=
The following table summarizes the solution.
t I 2 3 4
~ 210 250 190 260
", 252.5 250 252.5 260
2p - 1 - u
CI,I :=
(l+u)(-l+u)
> is(c{1,1]<=0);
true
> V[ 1] :=simplify(subs(u=O,c{ 1]»;
VI := In(x)
We now tum to the case where p > !.
> restart: * Gamble.mws (Part 2)
> assume(x>O,p>O);
> q:=1-p;
q:= 1- P
The boundary condition is the utility of the final fortune, which is defined as
the logarithmic function in x.
> V[ 0] :=x->log(x);
Vo:= log
When there is one play left, we find that it is optimal to bet 1'1 = 2p - 1 =
P - (l - p) = p - q fraction of the current wealth:
> c[ 1] : =p* log (x+u* x) +q* log (x-u* x) ;
derivl:=
px (1 - p)x
x+ux x-ux
> mu[ 1] :=solve(deriv[ 1] ,u);
1'1 := 2 p - 1
The value function VI (x) is obtained in tenns of logarithms that can be written as
VI (x) = C +Iog(x) where C = log(2)+ p 10g(p)+log(1- p)- p 10g(1- p) =
log(2) + p log(p) + q log(q).
> V[ 1] :=unapply(expand(simplify(
subs (u=mu[ 1] , c{ 1] » ) , x) ;
VI := x ~ p In(p) + In(2) + In(x-) + In(1 - p) - p In(1 - p)
When there are two plays left, the optimal fraction to bet is again 1'2 =P - q
with the value function assuming the fonn V2(X) = 2C + log(x).
> c{ 2] : =p* V[ 1] (x+u* x) +q* V[ 1] (x-u* x) ;
deriv2:=
px (1 - p)x
x+ux x-ux
> mu[ 2] :=solve(deriv[ 2] ,u);
#2:=2p-1
> ~ 2] :=unapply(expand(simplify(
subs (u=mu[ 2] ,e{ 2] ))) ,x);
V2 := x -+ 2 P In(p) - 2 p In(1 - p) + 2 In(2) + In(x-) + 2 In(1 - p)
This procedure can be automated to produce similar results.
> for n from 3 to 4 do:
> e{ n] :=p*~ n-l] (x+u*x)+q*~ n-l] (x-u*x):
> deriv[ n] :=diff(e{ n] ,u):
> mu[ n] :=solve (deriv[ n] ,u) :
> ~ ~ : =unapply (expand (simplify (
subs (u=mu[ n] ,e{ n] ))) ,x):
> od;
deriv4 := px (I - p)x
x+ux x-ux
#4:= 2p-1
V4 := x -+ 4 P In(p) - 4 p In(l - p) + 4 In(2) + In(x-) + 4 In(1 - p)
!
Using induction, it can then be shown that when p > the optimal policy is
to bet #n = P - q fraction of the current wealth at any stage of the game. This
gives rise to a value function that is in the form Vn(x) = nC(p) + log(x) where
C(p) = q In(q) + p In(p) + In(2).
One of the most interesting features of this problem is the nature of its solution:
The optimal strategy is myopic (invariant) in the sense that regardless of the num-
ber of bets left to place (n) and the current wealth (x), the optimal (nonnegative)
!
fraction to bet in each period is the same, i.e., u = p - q when p > and u = 0
228 6. Dynamic Programming
!.
when p ~ Optimal myopic policies of this type are usually difficult to obtain,
but they exist for some models. For example, in some periodic-review inventory
problems with random demand it has been shown that provided that some terminal
cost is appended to the objective function, the optimal order quantity is the same
for all periods; i.e., the policy is myopic (Veinott (188], Heyman and Sobel [89,
Chapter 3]). In some dynamic portfolio problems (Mossin [133], Bertsekas [31,
pp. 152-157]) myopic policy is also optimal provided that the amount invested is
not constrained and the investor's utility function satisfies certain conditions.
In a recent paper, C;etinkaya and Parlar [41] argue that the assumption of the
simple logarithmic function in the Kelly-Bellman-Kalaba model is somewhat un-
realistic and that the problem should ideally be solved with a more generalloga-
rithmic utility function. They thus assume that, in general, the gambler's terminal
utility is given as Vo(x) = log(b + x) where b is a positive constant. This gener-
alization results in the disappearance of the myopic nature of the solution and the
optimal strategy assumes a form that depends on the stage (n) and the state (x) of
the gambling process.
Note that if the last offer W,_I is accepted, then at the start of period t, the pro-
fessor will have a revenue of x, and the process will "stop." If the offer is re-
jected, then V,(x,) is equal to the expected value of continuing optimally in peri-
ods t + I, t + 2, ... , N, i.e., E[V,+I (w,)] = .io
V,+I (w) dF(w) where F(w) is
the distribution function of the offer w.
Thus, the optimal policy is to accept the offer x, = W,_I in period t if x,
exceeds a critical threshold level of(J, = E[V,+I(W,)] and reject the offer if it
falls below (J" i.e.,
{ Accept if x, > 8,
JJ,(x,) = Reject if x, < (J" (6.6)
with either acceptance or rejection being optimal if x, = (J,. Hence the value
function is V,(x,) = max (x" (J,). Note that since xo == 0, we have Vo(O) =
max(O, (Jo) = (Jo.
As the threshold value (J, at time t is obtained in terms of E[V,+I(W,)], we
can develop a difference equation in terms of this value and compute (J" t =
0, I, ... , N recursively using Maple.
To obtain the difference equation, we write
(J, = E[ V,+I (w,)] = E[max(xt+l, (Jt+I)] = E[max(w" (Jt+I)]
= (Jt+1 t
(01+1 dF(w) + JO wdF(w)
10 101+1
= (Jt+IF«(J'+I) + roo wdF(w)
10/+1
with the boundary condition being (IN = 0 (since the professor would be willing
to accept any offer on his last day). Thus, the threshold levels are found as the
solution of the nonlinear difference equation
Since 0, = (1 + r)-I E[Vt+1 (w»), we obtain 0, ~ 0t+I . This means that as the
end of horizon gets one period closer, the professor would be willing to accept
a lower offer since he has one less chance of getting an improved offer. For the
discounted case, the nonlinear difference equation assumes the form
For the uniformly distributed offers with a discount rate of r = 0.10, the limit-
ing result is obtained simply as the solution of a quadratic equation:
> restart: *UniformDP.mws (Part 2)
> r:=O.10;
r := .10
> F:=theta;
F:=O
> A:=int(w,w=theta .. l);
1 1
A := 2 - 202
> Asy:=(l+r)*theta=theta*F+A;
1 1
Asy:= 1.100 = _02 +-
2 2
> solve(Asy,theta);
.6417424305, 1.558257570
Thus, we obtain 0 = 0.641 as the number of opportunities (periods) to receive
offers approaches infinity.
Let us now consider a more general case where the offers have a beta distribu-
tion so that the density f(w) assumes the form
where f(y) is the gamma function defined by f(y) = 10 uy-Ie-u du.lt is well
known that when y is a positive integer, we obtain f(y) = (y - I)', and that
when a = b = 1, the beta density reduces to the uniform so that f(w) = 1 for
O~w~1.
The Maple output for a = 5 and b = 2 follows where for N = 5, we compute
the threshold levels 0" t = 0, I, ... , 4 .
232 6. Dynamic Programming
F:= -506 + 60 5
> A: =int (w* f, w=theta •. 1) ;
A := ~ + 370 07 - 506
> Asy:=(l+r)*theta=theta*F+A;
5 30
Asy:= 1.100 = 0(-506 + 6( 5 ) + 7 + 1"87 - 506
> fsolve(Asy,theta);
.704
6.8 Summary
Dynamic programming (OP) is useful in solving different types of sequential de-
cision problems with Bellman's principle of optimality. We started this chapter
by introducing a simple discrete-time, discrete-state sequential decision problem
known as the stagecoach problem. Sequential decision problems with a quadratic
performance criterion and a linear system normally give rise to closed-form s0-
lutions that may require an iterative process of solving a sequence of recursive
equations. Using Maple's symbolic manipulation capabilities, we were able to
develop closed-form solutions for a large class of such problems. A finite horizon
workforce planning problem with constraints was solved with the help of Maple's
piecewise () function. A gambling problem modeled using stochastic DP was
solved that gave rise to a myopic policy. Finally, optimal stopping problems were
considered where the stopping boundary was computed by solving a nonlinear
difference equation numerically.
6.9 Exercises
1. Consider the following road network where a driver can travel only on the
one-way streets as indicated by arrows. The driver starts at the intersection
labelled ''A;' and must reach the final destination at the intersection labelled
"H". The travel distances between any two intersections are indicated next
to the arrows. Define the states and decisions and find the optimal route for
234 6. Dynamic Programming
the driver.
A ~S D ~3 E ~7 H
,1.3 t6 ,1. 1 t2
B ~8 C ~2 F ~3 G
N
min J = L(qx; +ru;) +qxj
;=0
D N K 1r q
3 5 20 100 0.95
7
Stochastic Processes
7.1 Introduction
Operations research models can be categorized broadly as deterministic and prob-
abilistic. When the variable of interest-e.g., the number of customers in a service
system or the number of units in inventory-randomly evolves in time, a proba-
bilistic model provides a more accurate representation of the system under study.
A collection of random variables indexed by a parameter T (such as time) is
called a slochaslic process (or "random" process). When the process is observed
at discrete time points 0, 1,2, .. . , the process is usually denoted by {Xn, n =
0,1, ... }. The number of students enrolled in an MBA-level operations research
course at the start of each academic year is an example of a discrete-time stochas-
tic process. When the index parameter is continuous the process is usually denoted
by (X(/), 1 ~ OJ. An example of a continuous-time stochastic process is the price
of a company's stock observed at time I.
Stochastic processes are also characterized by their state space S, i.e., the val-
ues taken by Xn (or by X(/». If the set S is countable, then the process has a
discrete state space. For example, if X(/) represents the number of customers in
the system at time I, then S is countable and X(t) has a discrete state space. If Sis
a subinterval of the real line (an uncountable set), then the process has continuous
state space. For example, if X(/) measures the water content ofa dam, then X(t)
has a continuous state-space. Thus, a stochastic process can be placed in one of
four possible categories depending on the nature of its parameter set T (discrete
vs. continuous) and state space S (discrete vs. continuous).
[(I) = A.e-J.t, 1 ~ O.
As the following Maple results demonstrate, for the exponential r.v., the cumula-
tive distribution function is Pr(T ~ I) == F(/) = f~ A.e- Ax dx = 1 - e-A.t and
the survivor probability is Pr(T > I) == F(/) = 1,00 A.e- Ax dx = e-A.t. If, for
example, T is the lifetime of a component, then F(/) gives the probability that
the component will fail at or before 1 time units and the survival probability F(/)
gives the probability that the component will fail after 1 time units.
> restart: * exponential.mws
> assume(lambda>O);
> f:=unapply(larnbda*exp(-lambda*t),t);
[:= 1 -+ A.e(-A.t)
> F:=unapply(int(f(x),x=O .. t),t);
F:= 1 -+ _e(-A.t) + 1
> FBar:=unapply(l-F(t),t);
7.2 Exponential Distribution and Poisson Process 239
FBar := t ~ e(-A I)
Comparing this to the probability Pr(T > s) that the (new) component will fail
after s time units, we find
> FBar(s);
e(-As)
This implies that for the exponential random variable we have the interesting
property that
where r(/) = /(/)/ F(/) is the hazard (failure) rate function of the component.
Naturally, if /(/) = Ae- At , then we find that r(/) = A, a constant. For most
mechanical equipment, the hazard rate function would be an increasing func-
tion of time (Shaked and Shantikumar [170)). In manpower planning applica-
tions, Bartholomew [16] has shown that the hazard rate function for the completed
length of service (CLS) distributions estimated for the British Civil Service is a
decreasing function of time. This implies that the longer a civil servant works for
the government, the smaller is the probability that he will resign his job and move
elsewhere.
Clearly, for a given density /(/), the hazard rate function r(/) can be uniquely
detennined from the equation r(/) = /(/)/ F(/). For example, suppose T is a
Weibull r. v. with distribution F and density /:
> restart: *
weibull.mws
> F: =unapply(l-exp(-lambda*xAa),x);
F :=x ~ I-e(-h")
> f:=unapply(diff(F(x),x),x);
AXQ ae(-Ax")
/:=x~-----
x
Using r(/) = /(/)/ F(t) the hazard rate function r is found as
> r:=unapply(f(x)/(l-F(x)),x);
AxQ a
r : =x~-
x
7.2 Exponential Distribution and Poisson Process 241
We now deal with the inverse problem: Does the hazard rate function r(t)
uniquely determine the density /(t)? The answer to this is in the affirmative and
it is obtained by solving a simple ordinary differential equation.
Recall that F(t)= 1,00 /(u) du, which implies F' (t) =-
/(t). Rewriting
r(t) = /(t)/ F(t) we obtain an ordinary differential equation F'(t) = -r(t)F(t)
with the initial condition F(O) = 1. Solving this ODE using Maple's dsol ve ( )
function, we find the expression F(t) in terms of the hazard rate function r(t).
> restart: i rODE.mws
> ODE:=diff(FBar(t),t)=-r(t)*FBar(t);
ODE := f, FBar(t) = -r(t) FBar(t)
> Solution:= dsolve({ODE,FBar(O)=l} ,FBar(t»;
Solution := FBar(t) = e(- f~ r(II)dll)
> assign(Solution);
Next, differentiating -F'(t) gives the unique solution for the density /(1) in
terms of the hazard rate function r(t).
> f:=unapply(-diff(FBar(t),t),t);
1 := 1 ~ r(l) e(- J~ r(II)dll)
Thus, given the hazard rate function r(t), the density 1(1) is obtained uniquely
by evaluating an expression involving an integral.
Returning to the Weibull example, we see that with the hazard rate function
r(l) = A.Xa-1a, the correct density /(t) of the Weibull is obtained from (7.2), as
expected.
> restart: i weibul12.mws
> F:=unapply(l-exp(-lambda*xAa),x):
> f:=unapply(diff(F(x),x),x):
> r:=unapply(f(x)/(l-F(x»,x):
> assume(a>O,lambda>O);
> f:=r(t)*exp(-int(r(x),x=O .. t»;
A. t a a e(-t" A)
/:=----
t
stages, each of these r.v.'s could correspond to the time spent in one stage of the
system. The total time spent in the system is then S2 = T, + T2.
To find the distribution of the new random variable S2, we load the int-
trans () package and compute the Laplace transfonn (LT) of the exponential
r.v., which we denote by fLT[ 1) .
> restart:. Erlang.mws
> with(inttrans);
Continuing with this approach, we now fonn the new sum S3 = 2.7=, T; whose
LT-denoted by fLT[ 3) -is found as
> fLT[ 3) :=(fLT[ 1) )"3;
l3
fLT3 := (s + l)3
Inverting this LT, we find
> invlaplace(fLT[ 3) ,s,t);
~ l3 t2 e(-At)
2
7.2 Exponential Distribution and Poisson Process 243
as the density of Erlang with parameters (3, A.). Thus, we see that the r.v. S2 has
density
/~(I) = ~A.312e-At, I ~ O.
2
Generalizing these results to a positive integer n by using induction it can be
shown that the finite sum Sn = "L7=1 T; has the Erlang density
A.e- At (A.I)n-1
/s,,(I) = (n-I)! ' I ~0
with the initial condition po(O) = I since we assume that initially the system is
empty, i.e., N (0) = O. Solving this ODE with Maple gives
> restart: *
Poisson.mws
> de.O:=diff(p.O(t),t)=-lambda*p.O(t);
deO := f, pO(/) = -). pO(/)
> IC.O:=p.O(O)=I;
ICO := pOcO) = I
> assign(dsolve({de.O,IC.O} ,{p.O(t)} ));
> p.O(t);
e(-At)
We now again use Maple to solve these ODEs and obtain the solution for a few
small values of n:
> for n from 2 to 10 do
> de.n:=diff(p.n(t),t)=-lambda*p.n(t)
Tlambda*p. (n-1) (t);
> IC.n:=p.n(O)=O;
> assign (dsolve ({ de.n, IC.n} ,{ p.n (t)} »;
> p.n(t);
> od:
> p.2(t); p.3(t); p.4(t); p.5(t);
! e(-J.t) .(2 t2
2
! e(-J.t) ,l.lt3
6
J.. e(-J. t) ,l4 t 4
24
_1_ e(-J. t) ,l S tS
120
To show the general result, we use mathematical induction and assume that the
result is true for n = k, i.e., that
is true.
> p.k(t) :=exp (-lambda* t)* (lambda*t)Ak/k!;
e(-J.t) (,It)k
pk(t) := k!
With this assumption we attempt to solve the ODE for n = k + 1, i.e.,
ICkPlusl := pkPlusl(O) = 0
> assign(dsolve({de. (kPlusl),IC. (kPlusl)},
{p. (kPlusl) (t)} ));
> p. (kPlusl) (t);
e(-At) (A I)(HI)
f(k + I)(k + I)
Maple solves the ODE with the initial condition PH 1(0) = I and finds the correct
result
e- At (Ali+) e- At (Ali+ 1
PHI (I) = f(k + I)(k + I) = (k + I)! '
thus proving the proposition.
00 (..tty
Fs,,(t) = Pr(S" ~ t) = Pr[N(t) 2: n] = ~::e-.l.t-.,-.
j=" J.
Differentiating Fs,,(t) w.r.t. t and simplifying we find the density /s,,(t) = Fs.. (t)
as
> restart: # Erlang2.mws
> FSn:=Sum(exp(-lambda*t)* (lambda*t)Aj/j!,
j=n .. infinity) ;
00 e(-.l.t) (..t tY
FSn:= ~ .,
j=n J.
> fSn:=simplify(diff(value(FSn),t));
e(-.l.t) (A t)"
jSn:= t r(n)
Rewriting the result in a more familiar format, we obtain the density /s,,(t) of the
Erlang r.v. with parameters (n, A).
'Note that an ordinary (homogeneous) Poisson process with constant). has stationary increments.
248 7. Stochastic Processes
For the NHP, the probability distribution of the number of arrivals in the interval
(t, t+ s] is still Poisson but with parameter M(t + s) - M(t), i.e.,
Pr{N(t+s)-N(t) = n] = e-[M(Hs)-M(t)] [M(t +s) - M(t)1 n , n = 0, 1,2, ...
n!
As in ordinary Poisson processes, we show this result using induction.
= =
For afixed t, define Pn(S) Pr{N(t + s) - N(t) n]. For n 0 we have =
pO(s + h) = Pr{N(t + s) - N(t) = 0]
= pO(s)[I - A.(t + s)h + o(h)]
Thus, we find that pO(s) = e- J~ l(Hu) du. It is not immediately obvious how the
function M(t) appears in this result, so we attempt to convert it to a different fonn
using a change of variable that requires the student package.
> with(student);
[D, Diff, Doubleint, Int, Limit, Lineint, Product, Sum, Tripleint, changevar,
combine, completesquare, distance, equate, extrema, integrand,
intercept, intparts, isolate, leftbox, leftsum, makeproc, maximize,
middJebox, middJesum, midpoint, minimize, powsubs, rightbox,
rightsum, showtangent, simpson, slope, summand, trapezoid, value
]
> Integral:=int(lambda(t+u),u=O .• s);
11
1+$
A(Z) dz
10
o 2 4 t 6 8
In this example, we assume that the restaurant opens at 8 a.m. and stays open
for 9 hours. Thus, t = 0 corresponds to 8 a.m. and t = 9 corresponds to 5 p.m.
Maple easily computes the integrated arrival rate function M(t) (denoted by
MIn t) as follows:
> MInt:=int(lambda(u),u=O .. t);
250 7. Stochastic Processes
+ ~ t 2 Heaviside(t - 9) + 6 t Heaviside(t - 3)
I
Since the result is in tenns of Heaviside ftmctions defined as
0 ift < 0
Heaviside(t) = undefined if I = 0
1 ift > 0,
we convert it to the piecewise fonn and use the unapply () ftmction so that
M(/) can be evaluated for different values of I.
> M:=unapply(convert(Mlnt,piecewise,t),t);
I-t/2
Thus, we find that
12 +4/, 0~/~3
M(t) = 10/ - 9, 3~t~5
+ 131- ¥, 5~/~9
60
50
40
30
20
10
t
could be computed using the average arrival rate of AAvg = f~ A( r) dr = 7.22
customers. The Poisson probability formula. which would provide on1y an ap-
proximation to the true probability, gives 0.10 I.
> lambda[Avg] :=evalf(int(lambda(t),t=O •. 9)/9);
AAvg := 7.222222222
> Poisson:=(t,n)->exp(-lambd~Av~*t)
* (lambda[ Avg] * t) "n/n! ;
e( -).A>w t) (A t)n
Poisson:= (t, n) ~ , Avg
n.
> Poisson(2,15);
.10 13609134
> Error:=evalf((Poisson(2,15)-PrNHP(2,2,15))
/PrNHP(2,2,15));
Ernor:=.5583365914
This results in an error of about 55.8%, indicating that the Poisson model pro-
vides a poor approximation to the nonhomogeneous Poisson process.
By combining the Poisson process N (I) and the sequence {Y;} in a particular
way, we obtain a new process
N(t)
X(t) = LY;. (7.3)
;=0
= L[E(zY)t Pr[N(/) = i)
;=0
= f[Gy(z)t e - At ()...~); .
;=0 I.
Hence, we see that the p.g.f. of the compound Poisson process X(/) is obtained
as GX(t)(z) = e-AteGy(=)At.
Now consider the case where Y follows the geometric distribution an = Pr(Y =
n) = (I - p)~-I, n = 1,2, ... :
7.2 Exponential Distribution and Poisson Process 253
(I - p)z
pz-I
Next, evaluating the expression for the p.g.f. GX(t)(z) = e- At eGy(=)At of X(t).
we find
> G[ X] :=unapply(suro( (Q: ~ (z» "n
*exp (-larnbda* t)* (larnbda*t) "n/n!,
n=O .. infinity),z);
( -zAt+zAlp)
Gx:=z~e(-At)e pz I
Variance of X(t)
To compute the variance of X(t) we need the second factorial moment of X(t).
which is found by evaluating G X(t)(1) . The second derivative GX(t)(z) (denoted
by G[ X, 2] ) is a very complicated expression and it would be rather difficult to
compute it manually. But using Maple, this is achieved relatively easily. Comput-
ing GX(t)(z). substituting z = I and simplifYing, we find
> ~ X, 2] :=unapply (diff (Q: X] (z), z$2), z);
254 7. Stochastic Processes
Distribution of X(/)
The results found in the preceding paragraphs provide the exact expressions for
the first few moments of the compound Poisson process for geometrically dis-
tributed Y . When Y is a nonnegative integer random variable, it is also possible to
compute symbolically the exact distribution of the X(/) process using a recursive
scheme due to Adelson [5]. Also see TIjms [187, pp. 29--30] who provides a faster
method based on the fast Fourier transform.
As before, let an = Pr(Y = n), n = 1,2, .. . be the density of Y . Defining
rn(/) = Pr[X(/) = n], n = 0, I, .. . as the probability density of X(/), Adelson's
method computes these probabilities as
ro(/) = e-AI(I-ao),
). n-l
rn(/) = ..!.. ~(n - j)an-jrj. n = 1, 2, ...
nj=O
Note that if, for example, Y corresponds to the number of units of a product pur-
chased by customers who arrive according to a Poisson process with rate )., then
X(/) is the total number of units purchased until time I andrn(/) is the probability
that exactly n units will be purchased by time I.
The recursive equations for, say, n = 0, I, 2, 3 are easily formed and computed
with Maple.
> restart : *
Adelson.mws
> Total:= 3;
7.2 Exponential Distribution and Poisson Process 255
Tola/:= 3
> r[ 0] :=exp (-lambda* t* (l-a[ 0] ));
ro := e(-At(\-ao»
> for n from 1 to Total do
r[ n] := (lambda* t/n)* sum( (n-j)* a[ n"';'j] * r[ j] ,
j=O .. n-l) od:
The expressions for r) (I), r2(/) and r3(/) are found in tenns of the as yet un-
specified values of an, n = 0, 1,2,3.
> r[ 1]; r[ 2]; r[ 3] ;
A. 1 al e( -A t (\-ao»
1
- A. 1 (2Q2 e(-At (\-ao» + al 2 A. 1 e(-At (\-ao»)
2
1 1
3" A. 1 (3 a3 %1 + 2 Q2 A. 1 al %1 + 2" al A. 1 (2 Q2 %1 + al 2 A. t %1»
%1 := e(-At(\-ao»
If we asswne that Y is geometric, i.e., that an = Pr( Y = n) = (I _ p)p"-I ,
n = 1,2, ... , we can obtain the exact fonns of the probabilities rn(/), n = 1,2,3.
> a[ 0] :=0;
ao :=0
> for n from 1 to Total do a[ n] :=(l-p)*p"(n-l) od;
al := 1- p
Q2 := (I - p) p
Q):= (1- p)p2
> r[ 1]; r[ 2]; r[ 3] ;
A. 1 (l - p) e(-At)
1
-1t(3 (1 - p) p2 e(-At) + 2 (1 - pi pA.l e(-At)
3
+ ~ (1 -p)A. 1 (2 (1 - p) pe(-At) + (1 - p)2 A. 1 e(-At»)
2
We now let A. = 1 and p = 0.6 and plot the probability functions for rn(/),
n = 0,1,2,3. These functions are displayed in Figure 7.3.
> lambda:=l; p:=0.6;
A. := 1
256 7. Stochastic Processes
p:=.6
> plot ([ r[ 0] , seq (r[ n] , n=l .. 3)] , t=O .. 4, color=black) ;
0.8
0.6
0.4
0.2
o 3 4
FIGURE 7.3. Probability functions rn(t) = Pr[X(t) = n] for n = 0, 1,2,3 and 0 :5; t :5; 4
where rO(O) = I.
7.3.1 Preliminaries
We consider a sequence ofi.i.d. random variables {Xn, n = 1,2, ... } with com-
mon distribution F, density I, mean Il = E(Xn) and variance q2. The r.v. Xn de-
notes the interarrival time between the nth and (n-I)st events (arrivals/renewals).
We assume F(O) = Pr(Xn = 0) < I, so the mean time between events Il > o.
The quantity 1/ Il is the arrival rate of the process.
We define Sn = :L7=1 Xi, n = 1,2, ... as the arrival time of the nth event with
So = 0 indicating that there is an event at time t = O. As before, we define N (t) as
the number of renewals in the interval (0, t] and write N(t) = max{n ; Sn ::; t}.
In Section 7.2.6 we argued that the two events {Sn ::; t} and {N(t) ~ n} were
equivalent since the nth event takes place at or before time t if and only if the
number of events until t is at least equal to n. These arguments are still valid even
if the interarrival times are non exponential. Thus to compute the distribution of
the process N (I), we can write
Pn(/) = Pr[N(/) n]=
= Pr[N(/) ~ n] - Pr[N(/) ~ n + I]
= Pr(Sn::; t) - Pr(Sn+1 ::; t)
= Fn(/) - Fn+1 (t) (7.4)
where Fn(t) = FI (I) ® Fn- I(t) = Jooo FI (I - U)/n-1 (u) du is the n-fold convo-
lution of F with itself.
1:= l2 t e(-lt)
We load the integral transfonns package inttrans () in order to use the
inverse transfonnation facilities of Maple.
> with(inttrans);
A2
._ A6 (1- (S + A)2)
p LT3 .- S (s + A)6
> p[ 3] : =invlaplace (pL'I1 3] , s, t) ;
I I
P3:= A6 (--At 7 e(-lt) + _ t6 e(-lt»
5040 720
It is worth noting that if the interarrival density were /(t) = Ae-lt , i.e., ex-
ponential, then the distribution of the counting process N(t) would be Poisson,
as expected. The reader is invited to check this result by setting k = I on the
second line of the Maple worksheet and executing the worksheet with \Edi t
\Execute \Worksheet.
00
= Ln[Fn(t) - Fn+!(t)]
n=1
00
= LFn(t)
n=1
where the last equality is obtained using telescopic cancellations.
It is usually easier to work with renewal density m(t), which is the first deriva-
tive of the renewal function, i.e., m(t) = M'(t) = L:'1 /n(t). The renewal den-
sity has an interesting and useful interpretation: Since /n(t)dt is approximately
the probability that the nth renewal occurs in (t, t + dt), the sum m(t) dt =
L:'1 /n(t) dt is the probability that one renewal (the 1st or the 2nd or 3rd and
so on) occurs in (t, t + dt).
Defining ,;;(s) = £{m(t)} as the LT of m(t), and performing the usual opera-
tions on m(t) = L:'1 /n(t), we find
00 00
l(s)
= I -1(s)
(7.5)
0< l(s) = 10 00
e-st /(/)dl < 10 00
/(/)dl = 1.
mLT:= I
(1 +s)3 (1- (l +s)3)
The resulting transfonn ;;,(s) appears complicated, but Maple easily inverts it
and finds the renewal density m(/). Since the renewal function M(/) = J~ m(u)du
is computed by integrating the renewal density m(/), we also find M(/) as follows.
> m:=unapply(invlaplace(mLT,s,t),t)i
We note that the M(t) function has a linear asymptotic tenn (jt), two transient
tenns that approach zero as t ~ 0 and a bias tenn (the constant -i).
We find that
> lirnit(M/t,t=infinity);
i.e.,
lim M(t)
,-too-t- = -; = 3'
This limiting result holds in general and it is known as the elementary renewal
theorem.
Now, plotting the renewal function M(t) and its asymptote it -i
on the same
graph, we see that the latter approximates the fonner very accurately for t ~ 2.
These results are displayed in Figure 7.4.
> *plot ({ M, t/3-1/3} ,t=O •• 4) ;
0.8
0.6
0.4
0.2
o
-0.2
FIGURE 7.4. The renewal function M(t) and its asymptote it - i for Erlang(3,1) inter-
arrival times.
lim [M(t)
,-too
-!.] = _!.
3 3
lim
,-too
[M(t) - -J.lt] = q22-J.l 2J.l2 '
which can be seen to be true from the following Maple statements.
> rnu:=k/larnbda; sigrna:=sqrt(k/larnbda A 2);
262 7. Stochastic Processes
J.L :=3
(I :=,J3
> limit(M-t/mu,t=infinity);
-I
3
> (sigma A 2-mu A 2)/(2*mu A 2);
-I
3
Renewal Equation
Suppose we fix t and condition on the occurrence of the first renewal time XI.
Thus
M(t) = E[N(t)] = 10 00
E[N(t) I XI = x] f(x)dx.
or
M(t) = F(t) + 10' M(t-x)f(x)dx.
This is known as the renewal equation (or the integral equation ofrenewal theory)
and it is a computationally more useful result than M(t) = L~I Fn(t), which is
given in tenns of the n-fold convolutions of the distribution F.
7.3 Renewal Theory 263
where h(t) and /(t) are known functions and g(t) is the unknown function. If we
let h(t) = F(t) and g(t) = M(t), then the integral equation for g(t) reduces to
the renewal equation in (7.6). We now solve (7.7) using Laplace transforms.
Let g(s) and h(s) be the Laplace transforms of g(t) and h(t), respectively.
Taking the LT of equation (7.7), we obtain
g(s) = h(s) -
_ = h(s) [I + j(S)] - + h(s),;,(s)
_ = h(s) - (7.8)
I - /(s) I - /(s)
where the last equality is obtained from (7.5). Inversion of(7.8) gives
as the solution for M(t}. Provided that the renewal density is not too complicated,
the integral may be evaluated explicitly. We now provide an example of this result
using Maple.
Example 75 Solution o/the renewal equation with Erlang(2, 2) interarrival times.
In this example the interarrivaI times are Erlang(k,A.} with k = 2 and A. = 2. This
implies that the mean interarrival time is Jl = k/ A. = I. After defining the density
/(t), we easily find the distribution F(t) = J~ /(u) du using Maple's int ()
function.
> restart: * RenewalEqn.mws
> with{inttrans):
> k: =2;
k:=2
> lambda:=2;
A.:= 2
> f:=unapply{lambda* (lambda*t) A (k-l)
*exp{-lambda*t)/{k-l) !,t);
/:= t -+ 4te(-2,)
264 7. Stochastic Processes
mLT:=4 I
(s + 2)2 (I - 4 (s + 2)2)
> m:=unapply(invlaplace(rnLT,s,t),t);
m := I ~ I - e(-4t)
Now using the solution M(/) = F(/) + J~ F(I - x )m(x) dx, we compute the
renewal function M(/).
> M: =unapply(F(t)+int(F(t-x)*m(x),x=O •• t),t);
lim g(t) = -1
t~oo Il 0
10 00
h(t)dt. (7.9)
For example, Ross [157, p. 67] discusses an application of this result to find
the limiting probability that an alternating renewal process (ARP) will be found
in one of its two possible states. An alternating renewal process can be in either
ON state (for example, working) or in OFF state (for example, idle). Initially the
system is ON and it stays there for a random length of time XI; after that it stays
idle for YI. Then it goes to the ON state and stays there for X2 time units and
then switches to OFF state and stays OFF for a length Y2. This process continues
forever. Assuming that the vectors (Xn , Yn ), n = 1,2, ... are i.i.d., Ross shows
that if P(t) is defined as the probability that the system is ON at time t, then
kx:= I
> lambda[ X] : =3;
A.X := 3
> mu{ X] : =k[ Xl /lambda[ X] ;
I
Ilx:= -
3
> k[ Y] :=1;
ky := I
> lambda[ Y] : =2;
2Sufficient conditions for h(t) to be DRI are as follows: (i) h(t) ~ 0, (ii) h(t) is nonincreasing,
roo
and (iii) h(t)dt < 00; see Ross [157, p. 64] and Feller [65, pp. 362-363].
266 7. Stochastic Processes
ly:=2
> mu( Y] : =k[ Yl /lambda[ Y] ;
1
f.Jy:=-
2
> mu( zl : =mu( Xl +mu( Y] ;
5
f.Jz :=-
6
For the ON period, we have the density lx, distribution Fx, survivor function
Fx and the Laplace transfonn ix as follows:
> f[ xl : =unapply (lambda[ Xl * (lambda[ Xl * t) " (k[ Xl -1)
* exp (-lambda[ Xl * t ) / (k[ X] -1) ! , t) ;
Ix := t -+ 3 e(-3t)
> F{X] :=unapply(int(f[Xl (u),u=O •• t),t);
Fx := t -+ _e(-3t) +1
> FBar[ xl :=t->l-F{ Xl (t); FBar[ Xl (t);
FBarx:= t -+ 1 - Fx(t)
e(-3t)
1
ftT x := 3 s +3
Similarly, for the OFF period we define the density Iy and distribution Fy, and
find the survivor function Fy and the Laplace transfonn iy:
> f[ Y] : =unapply (lambda[ Y] * (lambda[ Y] * t) " (k[ Y] -1)
* exp (-lambda[ Y] * t) / (k[ Y] -1) ! , t) ;
Iy := t -+ 2e(-2t)
Fy := t -+ _e(-2t) +1
> FBar[ Yl :=t->l-F{ Y] (t); FBar[ Y] (t);
FBary := t -+ 1 - Fy(t)
e(-2t)
1
ftT y :=2 s +2
Since Z = X + Y, with independent X and Y, the LTof Z is the product of the
LTs ix and iy.
> fLT[ zl : =fLT[ Xl * fLT[ Y] ;
7.3 Renewal Theory 267
fLT z := 6 (s + 3)(s + 2)
Using the expression for the LT of the renewal density ,;,(s) in (7.5) we find the
LT of the renewal density for Z:
> mLT( ZJ :=fLT( Z] I (l-fLT( ZJ);
I
mLTz :=6 1
(s + 3)(s + 2)(1 - 6 (s + 3)(s + 2»
Inversion of the LT gives the renewal density mz(t) as
> ~ zJ :=unapply(invlaplace(mLT( Z] ,s,t),t);
6 6
mz := t -+ 5 - 5e(-SI)
The probability P(t) is computed using equation (7.10). We see that P(t) =
~ + ie-sl and limHoo P(t) = ~; i.e., the limiting probability of being in the ON
state is 215.
> P:=unapply(FBar( X] (t)+int(FBar( Xl (t-x)*~ Z] (x),
x=O • • t) , t) ;
.
11m P(t) = -
1 10 00
-
Fx(t)dt =
Px
= l =
-'-I 2
-5'
HOO Pz 0 Px +Py 1 +!
where R(t) denotes the total reward earned until t. Computing the limiting values
of the average reward is an extremely important problem in stochastic optimiza-
tion applications found in, for example, inventory theory and queueing processes
and it is given by the following theorem; see, Ross (157, pp. 78-79].
Theorem 12 Renewal Reward Theorem (RRT): If E(R) and Jl = E(X) are both
finite, then the long-run average expected reward per unit time is
. R(t) E(R)
hm - = (X) with probability 1.
t~oo t E
E(L) = Iroo
Tf(x)dx + foT xf(x)dx
Bonom·=..!. T2
. 12
+ T(~3 -!6 T)
> C:=unapply(Top/Bottom,T);
12 T2 + T(3" - 6 T)
When the cost function is plotted-which we leave to the reader-one observes
that it is a strictly convex function with a unique minimum in the interior of the
interval [a, b) = [2,8].
> iplot(C(T),T=a •• b);
7.4 Discrete-Time Markov Chains 271
Differentiating the cost function, equating the result to zero and solving-using
fsol ve () -gives the optimal replacement time as T* = 5.15 years.
> CT:=normal(diff(C(T),T));
CT := 2 3 T2 + 28 T - 224
T2 (T - 16)2
> TStar:=fsolve(CT(T),T,a .. b);
TStar:= 5.153946575
As a final check we find the second derivative C"(T) of the cost function and
evaluate it at T* = 5.15, which results in a positive value implying that the solu-
tion we just found is indeed the global minimum. A comparison of the value of
the cost function at the end points a and b with T* also indicates that we have
located the true optimal solution.
> CTT:=unapply(normal(diff(C(T),T$2)),T);
CIT ._ T _ 3 T3 + 42 T2 - 672 T + 3584
.- ~ 4 T3 (T _ 16)3
> CTT(TStar);
.03771347490
> evalf(C(a)); C(TStar); evalf(C(b));
3.428571429
3.054091250
3.187500000
The renewal reward theorem was popularized by Ross [156] and it has been ap-
plied successfully in different areas of operations research. For example, Gilrler
and Parlar [78] and Parlar [143] use the RRT to model a stochastic inventory sys-
tem with two unreliable suppliers who may be unavailable for random durations.
Taylor (184] uses it to model a repair problem for a deteriorating item and Tijms
[186, Ch. 1] describes different applications ofRRT in queueing theory.
=
transition . Pij'
I Itles (n n+l) are constant over tune;
. .
I.e., lor °
for n 0, I, 2, .... A time-homogeneous Markov chain has the property that the
. . probab·l· ~ a II n = , I , 2 , ...
We assume throughout this chapter that the Markov chains we consider are time
°
homogeneous. The transition probabilities Pij form the one-step transition matrix
P = [Pij] and they satisfy (i) Pij 2: for i, } E S and (ii) LjeS Pij = I for
i E S, thus making P a "stochastic matrix." The distribution of the initial state Xo
and the transition matrix P completely determine the distribution of a future state
X n, n = 1,2, ... of the Markov chain.
Pij = Pr(Xn+1 =} I Xn = i)
= Pr(X" + Z,,+I = j I XII = i)
= Pr(i + Zn+1 =})
= Pr(Zn+1 =} - i).
7' -2 -1 0 2
-2 0 P
-1 q 0 P
0 q 0 P
1 q 0 P
2 q 0
q q q q
31t is interesting to note that the Russian mathematician Andrei Andreivich Markov (1856-1922)
arrived at the notion of Markov chains when he investigated the alteration of vowels and consonants
in Pushkin's poem Onegin and discovered that there was indeed some kind of dependency between
the occurrence of these vowels and consonants (TaUcs [183, p. 6]).
274 7. Stochastic Processes
Ifwe now define p<n) = [p~)] as the matrix ofn-step transition probabilities, we
see that Chapman-Kolmogorov equations in (7.11) can be written conveniently in
matrix notation as
p(n) = p x p<n-I).
7.4 Discrete-Time Markov Chains 277
Since p(2) = P X p(l) = p2, p(3) = P X p(2) = p3 and SO on. we find that the
n-step transition matrix p(n) is simply the nth power P" of the one-step transition
matrix P, i.e.,
p(n) = pn.
Eumple 80 A periodic-review (s, S) inventory system (continued). Using Ma-
ple's eva 1m ( ) function we compute the nth power of the transition matrix for
different values of n. First, we set Digi ts: =4 in order to fit the output on a
printed page. (Note that Digits is an environment variable that specifies the
number of digits carried in floating point calculations with a default of 10.)
> Digits:=4i * PeriodicsS.mws (continued)
Digits:= 4
For n = 2, 8 and 64 we compute P" and note that for n = 64 the probabilities
seem to have (almost) converged to the same values in each row. This is not a
coincidence and as we will discuss later, for a large class of Markov chains this
convergence is achieved regardless of the initial state.
> eva1m(P"2) i
.1817 .2743 .2777
[ .1241
.2444 .1742 .1163 .2325 .14n ]
.2325
.3347 .2870 .1840 .09720 .09720
.2445 .2757 .2856 .1649 .02951
.1241 .1817 .2743 .2777 .1423
> eva1m (P"8) i
.2225 .2220 .2051
.2220 .2223 .2209 .2051 .1293]
[ .n17 .1303
.2231 .2231 .2212 .2041 .1293
.2226 .2233 .2220 .2043 .1287
.2217 .2225 .2220 .2051 .1293
> eva1m(P"64)i
1C;n) = LPr(Xn=jIXo=i)Pr(Xo=i)
ieS
= ~P~'.')1C~O). (7.12)
~ '1 I
ieS
)
becomes independent of the initial state i. This implies that there exists the limit
lim p(n) = 2
n-+oo
~ (:~1Co ::
1C1
:~ :• ::.•
1C2
··· ...
where {1C j} are the limiting (steady-state) probabilities.
Now consider the n-step unconditional probabilities 1C ;n) = LieS'" :0)pt).
Taking the limit of both sides, we have
lim 1C (~)
n-+oo 1
= lim ~ 1C ~O) p~'.')
n-+oo ~ I '1
ieS
7.4 Discrete-Time Markov Chains 279
Thus, 1tjn) converges to the same limit as p~) and it is independent of the initial
probabilities.
When they exist, the unconditional probabilities 1t j can be found solving n =
np with the nonnalizing condition ne = I where e = [I, I, . . . , 1]' is a column
vector of Is. The solution to n = np and ne = I (when it exists) gives the
stationary distribution of the Markov chain.
°
od od;
> for i from to S do
evalf(sum(~ 0, column] ,column=O .. S»
od:
> for i from °
to S do
Row[ i) :=evalf([ seq(~ i,j) ,j=O •. S)] ,4)
od:
> PArray:=array(O •. S, 0 .. S,[ seq (Row[ iJ ,i=O •• S)] ):
> P:=convert(PArray,matrix,4);
280 7. Stochastic Processes
> pi : =vector ( 5, [] );
lC := array(l ..5. [])
and evaluate II = IIP.
> EqnList:=evalm(pi - pi &* P);
> EqnSetR:=convert(EqnList,set);
We should note that since we had to define n as a vector with five entries
indexed as 1,2,3,4, 5, the indices of the solution must be adjusted by shifting
them by -I, i.e., Pr(stationary inventory level is j - I) = H j, j = I, 2, ... , 5.
The fact that one of the equations in the linear system n = np is redundant
can be illustrated as follows.
First consider a Markov chain with two states and the transition matrix given
by
P _ I (0.7 0.3)
- 2 0.4 0.6 .
Expanding the system n = np we find
HI = 0.7H I + 0.4H2
H2 = 0.3H I + O.6H2.
P=
.3 .2 .5) .
( .4.3.3
.1.2 .7
> restart: # RedundantEqn.mws
> with (linalg) :
Warning, new definition for norm
> with(plots):
> Row[ 1) : ={ • 3, .2, . 5) ; Row[ 2) : ={ • 4, . 3, . 3) ;
Row[ 3] : ={ • 1, • 2, . 7] ;
Row I := [.3, .2, .5]
ROW2 := [A, .3, .3]
RowJ := [.I, .2, .7]
> P:=array(1. .3,1. .3,[ seq (Row[ i] ,i=1. .3)] );
> EqnSetR:=convert(EqnList,set);
EqnSetR:={.7x-.4y-.lz, .7y-.2x-.2z, .3z-.5x-.3y}
> for k from 1 to 3 do
Planer k] :=solve(EqnList[ k] ,z) od;
Plane 1 := 7.x -4.y
Plaf1e2 := 3.500000000 y - 1. x
Plane3 := 1.666666667 x +y
> p[ 1] :=plot3d (Plane[ 1] , x=O •. 1, y=O •. 1) :
> p[ 2] : =plot3d (Plane[ 2] , x=O •. 1, y=O •. 1) :
> p[ 3] :=plot3d(Plane[ 3] ,x=O •. l,y=O .. 1):
> idisplay ({ p[ 1] , p[ 2] , p[ 3]
} ,axes=boxed,shading=none,orientation~ 52,47]);
After introducing the nonnalizing condition ne = I, the new system is solved
to give the unique stationary probabilities as x = .2083, y = .222 and z = .5694.
> EqnSet:=EqnSetR minus {EqnList[ 1]};
EqnSet:= {.7 y - .2x - .2z, .3z -.5x -.3 y}
> SumProb:={ sum (pi[ j] ,j=1. .3)=1} ;
SumProb:= {x + y +z = I}
> Sys:=EqnSet union SumProb;
Sys:= {.7y - .2x - .2z, .3z -.5x - .3y, x + y+z = I}
> Solution:=solve(Sys);
Solution:= {z = .5694444444, Y = .2222222222, x = .2083333333}
> assign (Solution) ; sum (pi[ , k'] ,'k' =1. .3);
.9999999999
We define X" to be the state of the machine on day n and show that X" is a
Markov chain by using the memoryless property of the geometric distribution.
First, suppose the machine is in state O. The length of time the machine is in
this perfectly working state is independent of the states before it entered this state.
When X" = 0, it does not matter how long the machine has been in state 0; the
probability that it will stay in the same state is u, i.e.,
since the probability of making a transition to 1 from 0 requires that (i) the ma-
chine makes a transition out of state 0, and (ii) it moves into state 1 with prob-
ability 1 - I. Using the same argument, the transition from state 0 to state 2 is
obtained as
(1-~r)W
(l - u)(1 - 1) (l - u) / ]
d I-d
p ,= [ (I-r)(l- w) r
> pi : =vector ( 3, [ ] ) ;
1C := array(1..3, [])
> EqnList:=evalm(pi - pi &* P);
p=(~ ~).
When we compute the higher powers of P, we observe an interesting result:
> restart: # Pathological.mws
> Row{ 1] : =( 0, 1] ; Row{ 2] : =( 1, 0] ;
Row) := [0, 1]
:= [1, 0]
ROW2
> P:=matrix(2,2,[ seq (Row{ k] ,k=1..2)]);
P:= [~ ~]
> evalm(P"2);
> evalm(P"3);
> evalm(P"4);
I~
These imply that
p(n) = ~ ~~ if n is even
o1 01 ' fn 'IS odd;
1
thus the limit limn-+oo p(n) does not exist. Hence, this Markov chain has no limit-
ing probabilities.
However, if we solve the linear system TI = TIP with TIe = 1, we find 1r) =
1r2 = !
as the stationary distribution of this pathological Markov chain:
> pi : =vector ( 2 , [] ) ;
7.4 Discrete-Time Markov Chains 287
What is interesting about this case is that although Iimn--+oo pen) does not exist,
the process periodically visits states I and 2 in a deterministic fashion. Thus, the
process spends 50010 of the time in state I and 50% of the time in state 2, implying
that the long-run proportion of time the system stays in state j = I, 2 is !. It
can be shown that, in general, the probabilities 1r j found by solving II = llP
and lle = I can be interpreted as the long-run proportion of time the (periodic)
Markov chain is in state j; see Ross [157, p. Ill].
o (\ \)
P2 = I fi i '
then state I is reachable from 0 (0 ~ I) but 0 is not reachable from I (I ..... 0).
States i and j are said to communicate (denoted by i ~ j) if they are
reachable from each other. For example, if
x
x
288 7. Stochastic Processes
then states to, I} and {2, 3, 4} form two distinct equivalence classes. When a
Markov chain has a large number of states it may be difficult to identify its equiv-
alence classes by visual inspection. For an efficient algorithm for identifying the
equivalence classes, see Kao [101, pp. 172-173].
If all the states of a Markov chain belong to one equivalence class, the chain
is said to be irreducible. In such a Markov chain all states communicate. For
example, the Markov chain representing the (s, S) inventory system is irreducible
since all its states communicate. The three Markov chains with transition matrices
P2, P3 and P4 are not irreducible.
The equivalence classification of states takes into account the external (i.e.,
between "neighbors") relationship between states. The following concepts of pe-
riodicity and recurrence identify states with respect to their internal nature.
The period d(i) of a state i is the greatest common divisor (g.c.d.) of all in-
tegers n = I, 2, ... for which pf;)
> O. When the period of a state is I, the
' calied apen·od·IC. For exampIe, suppose Pii(I) > 0,Pii(2) > 0,Pii(3) = 0,
state IS
pf:) > 0, .... Since the g.c.d. of I, 2, 4, ... is I, the state i is aperiodic. In the
random walk model in Example 78, for all i we have pf~) > 0 and n+l ) = 0 p::
for n = 0, I, 2, .... Thus, d(i) = 2 for all i and the chain is periodic.
Now define the first passage time probability as
for 0 < P < 1. In this chain all states communicate, thus all states are either
recurrent or transient. We therefore consider state 0 and examine its properties.
Since it is impossible to return to 0 in an odd number of transitions, we have
(2n+I) _ 0 n = 0,1,2, ....
Poo -,
(2n)
Poo = (2n)
n
n n (2n)! n n
P q = - - P q.
n!n!
n = 1,2, ....
This expression is simplified using Stirling's approximation of a factorial as n! '"
nn+! e-n£ where '",' is a shorthand notation for "approximated in the ratio."
> restart: *
RecurrenceRW.rnws
> Stirling:=n->n A(n+l/2)*exp(-n)*sqrt(2*Pi);
Stirling := n -+ n(n+I/2) e(-n) .../2i
Substituting and simplifying, Maple finds that the probability pg:) of returning
to 0 in an even number of transitions is
(2n) (4pq)n
,Jnii.
Poo =
> Even:=(Stirling(2*n)/(Stirling(n)*Stirling(n)))
*pAn*qAn;
1 (2 n)(2n+If2) e(-2n) .,fi ~ qn
Even·- -
"""""'--'-::=-~~~:-:--:--~";""'-
.- 2 ,jii (n(n+I/2»2 (e(-n»2
> c:=sirnplify(Even);
4n ~qn
c:= .;n,jii
We now analyze the properties of the infinite sum L:'I pfr).
Ifit converges,
then we conclude that the state 0 is transient; otherwise it is recurrent.
To simplify the analysis, we write r = 4 pq and first assume that 0 < r < I, i.e.,
!.
p '" Using the ratio test of calculus we compute Iimn -+ oo lan+ 1/an I. Intuitively,
!
when p '" there is a positive probability that the process, initially at the origin,
will drift to plus (or minus) infinity when p > q (or, p < q) without returning to
the origin.
> assurne(O<r,r<l);
> a:=n->rAn/sqrt(Pi*n);
290 7. Stochastic Processes
r"
a:= n -+ C7:
v 7rn
> limit(abs(a(n+l)/a(n)),n=infinity);
r
Since the limit converges to r e (0,1), we conclude that when p =f:. the sum !,
~I p:r)
converges and hence the chain is transient.
When r = 1 (or p = !),
the integral test of calculus reveals that the integral
(X>_I_ dn
11 .,f1in
diverges to infinity. Thus, in this case, the chain is recurrent.
> b:=n->l/sqrt(Pi*n);
1
b:= n -+ r=-=
v 7rn
> int(b(n),n=l .. infinity);
00
> evalf(int(b(n),n=1 .. 100000));
355.6964440
!,
Intuitively, when p = the process fluctuates around the origin and even if strays
away, it eventually returns to state O.
For a recurrent state i, mean recurrence time P;; is defined as the expected
number of transitions needed to return to i, i.e., Pii = L~I nJ/;"). If P;; < 00,
the state i is said to be positive recurrent, and if Pii = 00 the state i is null
recurrent.
Finally, we define a state to be ergodic if it is (i) aperiodic and (ii) positive
recurrent.
With these definitions, we are now ready to present a very important theorem
that identifies the long-run behavior of a Markov chain. For a proof, see Ross
[157, p. 109].
Theorem 13 An irreducible Markov chain belongs to one of the following three
classes:
Periodicity
Aperiodic Periodic
p;j
Transient
Null-Recurrent
Positive-Recurrent
-+ 0 and 7r j
do not exist
p;j -+ 7r j are uniquely p;j -+?
•
found from 7r j are long-run
II = llP and lle = I fraction of time in j
7.4 Discrete-Time Markov Chains 291
We now discuss some examples where this theorem can be used to identifY the
limiting properties of the Markov chains.
Example 85 A recurrent and periodic chain. Consider the Markov chain with the
transition matrix
p=~(Hn).
! j4 0 0
First, we note that all states of the chain commWlicate; hence the chain is irre-
ducible and Theorem 13 can be applied.
After finding P" and printing the first few values of p~~) for n = 2, 3, ... , 50,
we see that p~~) = 0 for n = 1,2,3 and p~~) > 0 for n = 4,6, 8, .... This implies
that the chain is periodic with dO) = 2.
> restart: # PeriodicChain.mws
> Row[ 1] : ={ 0, 1, 0, 0]; Row[ 2] : ={ 0, 0, 1, 0] ;
Row[ 3] : ={ 0, 0, 0, 1]; Row[ 4] : ={ .2, 0, . 8, 0] ;
Row) := [0, 1, 0, 0]
Ro'W2 := [0, 0, 1, 0]
Row) := [0, 0, 0, 1]
ROW4 := [.2,0, .8, 0]
> P:=matrix(4,4,[ seq (Row[ i] ,i=1..4)]);
p:=[H! ~].2 0 .8 0
> for n from 2 to 50 do
Rn] :=evalm(PAn) od: n:~n':
> for n from 2 to 15 do
print (n,R n] [ 1,1]) od; n:~ n' :
2,0
3,0
4, .2
5,0
6, .16
7,0
8, .168
9,0
292 7. Stochastic Processes
10, .1664
11, 0
12, .16672
13, 0
14, .166656
IS, 0
Next, we define the partial sum SA: = L!=1 p~~) and find that the difference
SA:+ 1 - SA: approaches the constant 0.166. This has the implication that the infinite
sum L~1 p~~) diverges; hence all states of the chain are recurrent.
.1~67 o .S333 0 ]
[ .1667 o .S333
.1667 o .S333 0
o o.1667 .S333
However, the linear system n = np with ne = I does have a solution imply-
ing that the stationary distribution exists. We find this distribution with Maple's
help as follows.
> pi: =vector ( 4 ,[] );
1r := array(1..4, [])
> EqnList:=evalm(pi - pi &* P);
EqnList := J.1r I - .2 1r 4, 1r 2 - 1r I, 1r J - 1r 2 - .S 1r 4, 1r 4 - 1r J]
> EqnSetR:=convert(EqnList,set);
EqnSetR:= {1rJ .S1r4, 1r1 - .21r4, 1r2 -1rI, 1f4 -1rJ}
-1r2 -
> EqnSet:=EqnSetR minus {EqnList[ 1]}; k:~ ~:
EqnSet := {1rJ - 1r2 - .S1r 4, 1r2 - 1r I, 1r4 - 1fJ}
> SumProb: ={ sum (pi[ k] ,k=1 •. 4) =1} ;
SumProb:= {1r1 + 1r2 + 1rJ + 1r4 = I}
> Sys:=EqnSet union SumProb;
Sys:= {1r1 + 1r2 + 1rJ + 1r4 = I, 1rJ -1r2 - .S1r4, 1f2 -1fI, 1f4 -1rJ}
In this case 1r I = 1r2 = 0.OS3, 1rJ = 1r 4 = 0.4166, indicating that the process
spends about S.3% of its time in states I and 2 and about 42% of its time in states
3 or 4.
> Solution:=solve(Sys);
4As we will discuss in more detail in Chapter 9, Queueing Systems, this queue is denoted by the
shorthand notation M / G/ I .
294 7. Stochastic Processes
Naturally, this process is not a (discrete-time) Markov chain since its time index
t is continuous. The process X(/) is not even Markovian since the knowledge of
the system at time 1 is not sufficient to determine the distribution of the state at
time 1 + s. For example, suppose we wish to determine the probability that there
is one customer present in the system at time 1 + M given that there was one
customer present at time I. This probability can be written as
X { Yn+l ifXn =0
n+l = Xn - 1 + Yn+l if Xn > 0,
indicating that the process Xn is now a Markov chain since Xn+l depends only
onXn .
To develop the transition probabilities Pij for this Markov chain, we need to
find the probability distribution of the number of customers that arrive during an
arbitrary customer's service interval. Conditioning on the length of the service
time we find
Pr(Yn =j) = 10 00
Pr(Yn =j I S=s)dB(s)
= roo
Jo
e-).s (1~;
J.
dB(s), j = 0, 1,2, ....
For i = 0, we have
poo = Pr(Xn+l = 0 I Xn = 0) = Pr(Yn+l = 0) = 10 00
e- As dB(s) = ao
7.4 Discrete-Time Markov Chains 295
= J. I Xn = 0) = . 10 e- As (AS Y
00
pOj = Pr{Xn+1 Pr{Yn+1 = J) = . dB{s) = aj .
o J!
Proceeding in a similar manner for i = 1, 2, ... , we obtain the transition matrix
P of the imbedded Markov chain for the M / G /1 queue as
o ao al 02 a3
1 ao al 02 a3
P= 2 o ao al 02
3 o 0 ao al
FIGURE 7.S. The digraph for the transition matrix of the embedded Markov chain of the
MIGII queue.
Inspection of the transition matrix and the digraph reveals when aj > 0 U =
0, 1,2, ...) the chain is irreducible and aperiodic. Since the chain has infinitely
many states, we need to examine its recurrence and transience properties to de-
tennine whether it is ergodic. We define p = E(Yn ) to be the mean number of
arrivals during service time of an arbitrary customer.5 Prabhu [152, p. 62] has
shown that the chain is positive recurrent, null recurrent or transient according to
p < 1, p = 1 or p > 1. We assume that p < 1 and proceed to find the stationary
distribution of the imbedded Markov chain using TI = TIP and TIe = 1.
00
A := z -+ La"z"
,,=0
> G:=z-> (pi[ 0] *A(z)* (z-l» / (z-A(z»;
G := z -+ HO A(z)(z - I)
z -A(z)
> subs(z=l,numer(G(z»);
o
> subs(z=l,denom(G(z»);
00
1 - (La,,)
,,=0
Thus, with the hope offinding the limit of G(z) as z -+ I, we use I'Hopital's
rule and compute the following:
00
I_(tan;nn)
00
Bottom:= 1 - (Lan n)
n=O
Thus,1 = 1£'0/(1 - p) since L~an = 1 and L~nan = E(Y) = p
implying that 1£'0 = I - p.
> solve (l=Top/Bottom, pie 0] ) ;
00
-I + (Lann)
n=O
n=O n=O
Maple evaluates this infinite sum as
> restart: # pgfA.mws
> A:=z->Int(exp(-lambda*t)*b(t),t=O .. infinity)
* Sum ( (lambda* t* z) "n/n! , n=O .. infinity) ;
298 7. Stochastic Processes
(A. t Z)n)
A := z --+ 10o 00
e(-At) b(t)dt L --,
COO
=0
-
n.
> value(A(z));
> rgf_expand(G(z),z,n);
#
The exact values of 1C n for n = 1, 2, 3 and the expected number of customers in
the system E(X) = ).1(# -).) are also easily computed using (7.15) and (7.16),
respectively.
> for k from 1 to 3 do
pi[ k] :=subs(z=O,normal(diff(G(z),z$k)))/k!
od;
1C1 :=
EX .-
·-
The next example deals with a more complicated case where the service time
S is Erlang with k stages (with mean ) 1#).
Example 87 The MI Ek/} model. Here we have essentially the same set of com-
mands as in the previous example except that the density bet) of k-stage Erlang
r. v. S is given by6
(#kltk-le-kl'l
bet) = (k _ I)! , t > O.
We set k = 2 and again find that Maple successfully inverts the resulting p.g.f.
G (z) and finds the stationary probabilities exactly.
> restart: # PKErlang.mws
> rho : =lambda/mu;
).
p:=-
#
> G: =z-> ((l-rho)*bLT(lambda-lambda*z)* (z-l))
/(z-bLT(lambda-lambda*z));
6This is a slighdy different but an equivalent way of writing the density of the Erlang r.v. with k
stages. Here, each stage is exponential with rate k I' and the mean duration of the Erlang is k[ I / (kl') ] =
1/Il; see Kleinrock [110, pp. 119-126].
300 7. Stochastic Processes
G := z ~ (I - p) bLT(A. - A.z)(z - 1)
z - bLT(A. - A. z)
> with(inttrans):
> k:=2;
k :=2
> b:= (rou* k) Ak* tA (k-l)*exp (-k*rou*t) / (k-l) !;
b := 41-'21 e(-2p t)
> bLT:=unapply(laplace(b,t,z),Z);
1-'2
bLT := z ~ 4 (z + 2 1-')2
> norroal(G(z));
4 I-' (I-' - A.)
A. 2 Z 2 -4A.zl-' -A.2z+41-'2
> with (genfunc) :
> pi:=unapply(rgf_expand(G(z),z,n),n);
1000 (
~
112 J305(10 I
33 + v305
MM)n 112 J305(-1O I
-33 + v305
MM)n)
~ - 305 33 + J305 - 305 -33 + J305
1.000000000
> 1 ambda : =' 1 ambda' ; rou: =' rou' ;
A. := A.
1-':=1-'
7.4 Discrete-Time Markov Chains 301
The first few tenns in {tr n} and the expected mnnber of customers E(X) are
also found exactly as follows.
> for k from 1 to 3 do
pi[ k] :=subs (z=O,normal (diff(G(z), z$k))) /k!
od;
1 {Jl - l)A. (4 Jl + ;')
'1'1 := 4' Jl3
Since pen) = p(O)pn and G(z) is the generating fimction ofp(n), the matrix ex-
pression (I -zpr l must be the generating fimction of the nth power pn as the
following diagram indicates:
G(z) = p(O) (I - zp)-I
~ ~ ~
pen) = P(O) P"
Thus, to compute the n-step transient probability matrix pn, one only needs to
invert the matrix-generating fimction (I -zP)-I. We now present an example of
this method.
Example 88 Transient solution ofa three-state Markov chain. Consider a Markov
chain with the transition matrix given as
p = (1~2 ~ 1~2).
3/10 1/2 1/5
After loading Maple's linalg () and genfunc () packages, we find the in-
verse of the matrix (J -zpr l whose entries are fimctions ofz.
> restart: # TransientMC.rnws
> with (linalg) :
Warning, new definition for norm
1
!~~
01 01 01
[
P:=
> IDminuszP:=evalm(ID-z*P);
1 -z
1
[ --z
IDminuszp := ;
I
- - z --z
10 2
> inv:=inverse(IDminuszp);
> Pn:=map(rgf_expand,inv,z,n);
304 7. Stochastic Processes
PI,I :=n ~
98 262 /'1i" 1 n 262 /'1i" 98 1 n
11 (n-407 vll )( 8-2ffi) + (407 vll +n)( 8+2ffi)
37 + 8 - 2ffi 8 +2ffi
> evalf (p[ 1,1] (5));
.218500000 1
Taking the limit as n ~ 00 of each entry gives the limiting probabilities of
the Markov chain. The reader would appreciate that performing these inversions
manually without the help of Maple would be very difficult, if not impossible.
> rnap(lirnit,Pn,n=infinity);
_55%1 80 50
--%1 --%1
37 37 37
_ 55 %1 _ 80 %1 _ 50 %1
37 37 37
55 80 50
--%1 --%1 --%1
37 37 37
1
%1 := ------::=---=_
(-4 + ffi) (4 + ffi)
> evalf(%);
.2972972971 .4324324322 .2702702701]
[ .2972972971 .4324324322 .2702702701
.2972972971 .4324324322 .2702702701
ofT; is !r;(/) = v;e-v;t, I ~ 0 with mean duration E(T;) = I/v;. The parameter
V; of the exponential distribution is the transition rate out of state i per unit time.
When the process leaves state i, it enters state j with probability P;j where Pii =
o and L.j# P;j = I for all i. Hence, the process (X(/), I ~ O} goes from state
to state according to a Markov chain with transition matrix P = [p;j], but each
time it visits a state, it stays there a random length (exponential) of time that
is independent of the past behavior. Now consider two states i and j such that
i '" j. Since the process leaves state i with rate V; and goes into state j with
probability P;j, we define q;j = V; P;j as the trans ilion role from i to j. Note that
as Ljji P;j = I we have L.j# % = v;. The q;j values constitute the entries of
the i~nilesimal generalor matrix Q = [%] of the CTMC.
Such a process (X(/), I ~ O} is a continuous-time Markov chain (CTMC) with
state space S. The process has the property that for i, j E S,
Pr[X(1 + s) = j X(s) = i, X(u) = x(u), 0 su < s]
= Pr[X(1 +s) = j I X(s) = i)
for all s, I ~ 0 andx(u), 0 SuS s.
Analogous to a discrete-time Markov chain, in a CTMC the conditional distri-
bution of X(I + s) given the past history over 0 SuS s depends only on the
current state X(s) at time s. We say that (X(/), I ~ O} is a lime-homogeneous
CTMC if the conditional probability Pr[X(1 + s) = j I X(s) = i) is independent
of s. In this case we write
where P;j(t) is called the transitionjunction from state i to state j. This quantity
is analogous to the transition probability P&)of a discrete-time Markov chain.
Many realistic problems arising in manufacturing and communication systems
are commonly modeled using continuous time Markov chains. The Markovian
queueing models that will be presented in Chapter 9, Queueing Systems, are all
CTMCs since, in those models, one assumes that interarrival and service times
are exponential, thus making the process Markovian.
We now discuss some examples of continuous-time Markov chains.
Example 89 Birth and dealh processes. Consider a CTMC that can make transi-
tions from state i only to its neighboring states i-lor i + I for i E S = {O, I, ... }.
When the process is in state i, the transition rates are given by q;,;+\ = At for
i = 0, I, ... and q;,;_1 = p; for i = 1,2, .... Usually, the state X(t) of the pro-
cess represents the size of some population (e.g., customers in a queueing system).
In the case of a queueing system with a single server this corresponds to the fol-
lowing: When there are i customers in the system, the customers arrive according
to a Poisson process with rate A; and the service time is exponential with rate p;,
meaning that the arrival and service rates can be, in general, state dependent. The
parameters A; and p; are called the birth rates and the death rates, respectively.
Note that since Lj# q;j = V;, the transition rate out of state i is
7.5 Continuous-Time Markov Chains 307
Vi = { AO, for ~ = 0
Ai + Pi' for I = 1,2, ...
and the infinitesimal generator Q is given by
~ (:\ A?O AI
Q= 2 P2? A2
·· .. ..
· . .
The entries with question marks (?) in the infinitesimal generator matrix Q will
be identified shortly.
To compute the transition probabilities Pij we first define Xi as the time until
the next birth (exponential with rate Ai) and Yi as the time until the next death
(also exponential but with rate Pi)' Thus, pOI = Pr(a birth at some time in the
future) = Pr(Xo < 00) = 1. To compute PI2 = Pr(a birth before a death) =
Pr(XI < YI), we proceed by conditioning on the occurrence of the time of death,
Y\, which gives
PI.2:= 10 00
{l-e(-At>)pe(-pt>dt
> value(%);
Example 91 A self-service car wash and vacuum facility. Consider a small self-
service car wash and vacuum facility where the service on a car is perfonned in
two stages, (i) wash and (ii) vacuum. We assume that there is only space for one
car at the facility, i.e., that queues are not permitted. Potential customers arrive
according to a Poisson process with rate ..t. If the facility is empty, the customer
enters, washes his car (time required distributed exponentially with rate #1), vac-
uums it (time required distributed exponentially with rate #2) and then departs. If
the facility is busy, the arriving customer goes elsewhere since there is no space
for waiting.
The stochastic process X(t) representing the status of the facility at time t is
a CTMC with state space S = to, 1,2} where state 0 corresponds to the empty
system and states I and 2 correspond to car being washed and being vacuumed,
respectively. Thus, the transition rates are vo = ..t, VI = #1 and V2 = #2. Since
the operations are perfonned sequentially, the states are visited in the order 0 --+
I --+ 2, implying that the transition matrix P = [Pij] for this CTMC is
p-! (H !)
The infinitesimal generator Q = [qij] is then
Q= ~ (~#2
2
;
0
:1).
?
i.e., the limit is equal 10 the transition rate Vi oUl ofstate i. Additionally, for any
two slates i and j in S,
I .un -
Pij(h)
h-+O h- -q ..
- IJ,
i.e., the limit is equal 10 the transition rate qij from i 10 j.
00
P;j(l) = LqijPkj(I),
k=O
or, using matrix notation,
P'(I) = QP(I), with P(O) = I
where I is the identity matrix. We see that with this definition, the diagonal ele--
ments of the ith row of the infinitesimal generator Q matrix is the negative of the
sum of all other elements in row i. For example, for the birth-death process of
Example 89, the Q matrix is
-AO AO
Q=:
( PI
7
-(PI + AI) AI
-(PI:+AI) ~2
Q= (~A _~I
P2 0
:1).
-P2
We first discuss a simple example with N = 2 states.
Example 92 A Markovian queue wilh no wailing space. Consider a machine that
works (stays ON in state I) for a random length oftime distributed exponentially
with rate p. When the machine breaks down and moves to the OFF state 0, it takes
a random length of time to repair it that is distributed exponentially with rate A.
This two state CTMC (N = 2) is thus a Markovian queue with a single server and
no waiting space. It is clear that for this model the transition rates from 0 and 1
are Vo = A and VI = p, respectively. It then follows that qOI = A and qlO = p.
For i = j = 0 the KoImogorov differential equation is written as
7For a CfMC with N states, this system has N 2 ordinary differential equations. Its solution, if
available, gives the transient probabilities Plj(/) for I ~ 0 and i, j e (1,2, ... , N) .
7.5 Continuous-Time Markov Chains 311
with POO(O) = 1. The other three differential equations are obtained in a similar
manner, which gives
Q := [-A.# -#A. ]
> Sol:=matrixDE(Q,t);
e(-(A+Jl)I) ] ~
e(-(A~)I) # ,[0, O]J
> K: =Sol[ 1] ;
8Since POO{I) + POI (I) = 1 and PIO{I) + PII (I) = I, we could have considerably simplified the
solution of this system by solving the lower dimensional system with the unknown functions POO{I)
and PIO{I) as
The present Maple worksheet is more straightforward since it solves the system P' (I) = QP{I) di-
recdy.
312 7. Stochastic Processes
eC-CA+Jl)I) ]
K:= [ eC-C)'~)I) p
> q 0) :=simplify(subs(t=O,inverse(K)));
Co:= [ 1 ~P
A.+p
> P:=evalm(K &* q 0) );
p %1 A.
- A.- - -
%1-A. ]
P := [ A. + p + A. + p A.+p A.+p
p %Ip A. %1 p
-----
A.+p
- -
A.+p A.+p
+ --
A.+p
%1 := eC-CA+Jl)I)
To summarize, the explicit solution P(t) for the linear system of differential
equations P'(t) = QP(t), P(o) = I for this two state CTMC is obtained as fol-
lows:
As a check, we see that the solution found satisfies the original systems of
ODEs.
> RHS:=evalm(Q &* P);
RHS:=
[ -A.(-P-+ %U)+A.(_p__ %Ip),
A.+p A.+p A.+p A.+p
_A.(_A.__ %U)+A.(_A._+ %IP)]
A.+p A.+p A.+p A.+p
p %U p %Ip
[
p(A.+p + A.+p)-p(A.+p - A.+p)'
A. %U A. %1 p ]
p(A.+p - A.+p)-p(A.+p + A.+p)
%1 := eC-CA+Jl)I)
> seq (seq (normal (diff(P[ i,j) ,t)-RHS[ i,j)),
i=1..2),j=1..2);
0, 0, 0, °
7.5 Continuous-Time Markov Chains 313
= LPik(t)qkj - VjPij(t)
k::Fj
9For the Markovian queue example with no waiting space, the forward equations look different but
their solution is the same as the backward equations.
314 7. Stochastic Processes
Q := [-A. A.]
/l -/l
> P:=exponential(Q,t);
' '1
PL Iml '-
.-
[ A.:
/l /l ~
A. A. /l ]
- - --
A.+/l A.+/l
As another-and more impressive----example of the use of exponen tial ( ) ,
consider the car wash facility of Example 91 represented by a CTMC with three
states. In this case, following the same steps we compute the transient probability
matrix P(I) as follows.
> restart: # CarWashExpQt.rnws
> with(linalg): with(DEtools):
Warning, new definition for norm
Q := [~A. _~I
/l2 0 -/l2
:1 ]
7.5 Continuous-Time Markov Chains 315
In this problem the solution P(I) takes up several pages of output. In order
to obtain a view of the general structure of the solution, we use the sprint ()
facility in the \share folder. This utility allows the user to look at the ''toJrlevel''
structure of an expression to obtain a bird's-eye view of the expression. 10
> P:=exponential(Q,t):
> with(share): with (sprint) :
See ?share and ?share,contents for information about the
share library
> is(value(%)=l);
true
Ifwe specify the parameter values by letting, say, A = 10, III = 5 and 112 = 30,
the conditional probability that the system is empty at time 1 given that it was
l~ote that the share library must be installed before this utility [and other share () utilities]
can be used. Once installed, entering with (share) ; followed by? share, contents gives a
complete list of all available share utilities.
IlNote that the states 0, 1,2 in the CfMC correspond to the rows 1,2 and 3 of the Q matrix.
316 7. Stochastic Processes
#2:= 30
> p[ 1,1] ;
...!..«-11500e(-1/2(45+JiS)I) + 11500e(-1/2(4s-JiS)I)
25
+ 700 v'25 e(-1/2 (4S-Ji5)I) + 600 v'25 + 700 v'25 e(-I/2 (45+JiS) I»
v'25) /«45 + v'25) (45 - v'25»
> evalf(subs(t=0 . 12,p[ 1,1] »;
.3962472752
Finally, as 1 -+ 00, the limiting probabilities are found as [0.3,0.6,0.1] for
each row.
> PLirnit:=evalf(rnap(lirnit,P,t=infinity»;
TI'(/) = TI(/)Q
Here is the Maple solution of the unconditional probabilities for the Markovian
queue problem of Example 92 where n(O) = [co, clF is not specified but co +
CJ = 1. We solve this system of ODEs using the dsol ve command.
> restart:# TwoStateUncond.mws
> Q:=matrix(2,2,[ -lambda,lambda,mu,-mu] );
Q:=
-p,
[-Ap,
A ]
> pi : =vector (2, [ seq (pi. j (t) , j =0 .. 1)] ) ;
tr := [trO(/), tr 1(I)]
> RHS:=evalm(pi&*Q);
RHS:= [-trO(/) A + tr 1(/) p" trO(/) A - 1C 1(1) p,]
> for j from 0 to 1 do
DE. j : =di ff (pi. j (t) , t) =RHS[ j +1] od;
DESys := (i; tr 1(/) = trO(/) A-tr 1(1) p" i; trO(/) = -trO(/) A+ tr 1(/) p,}
> for j from 0 to 1 do IC.j:=pi.j(O)=q j] od;
ICO:= trO(O) = co
ICI := tr 1(0) = CI
> ICSys:={ seq(IC.j,j=O .. 1)} ;
ICSys := (trO(O) = co, tr 1(0) = cd
> dsolve(DESys union
I -
ICSys,{ seq(pi.j (t) ,j=O .• 1)} );
trO(/) = CI P, + co p, + %1 Aco - %1 CI P, }
A+p,
%1 := e(-(Hp)I)
318 7. Stochastic Processes
> expand(%);
l C) l co
{1C 1(t=--+---
) l co CI P
+~--:---7:--:-:--:~
l+p l+p (l+p)e(IA.)e(lp) (l+p)e(tA.)e(lp)'
CI P COP lco CI P
1C
O()
t = --+--+
l+p l+p (l+p)e(IA.)e(lp) (l+p)e(IA.)e(lp)
}
To summarize, the explicit solution TI(/) for the linear system of DEs TI'(t)
= TI Q is obtained as
TI(t) -
o( Hp
+ co~e-(Hp)1
....iL
A.+P
- cl....iLe-(Hp)1 )
I+Ii
- I l~p - Co l~p e-(Hp)1 + C) l+p e-(Hp)1 ,
*),
which, as t ~ 00, becomes
as expected.
Although the three-state car wash model of Example 91 is more complicated,
Maple can still solve explicitly for the unconditional probabilities TI (I). However,
the solution is very long and does not reveal any insights. Thus, we leave the
analysis of this example to the reader who can easily solve the model by replacing
the definition of the Q matrix in the Maple worksheet TwoStateUncond.mws
to (3,3,[ -lambda, lambda, 0, 0, -mul,mul,mu2, 0, -mu2] ) ; and by
changing all the limits on the index j from 0. • 1 to 0. . 2.
Ifwe assume that the limiting probabilities 1C j = lim Hoo Pij(/) exist, 12 then the
derivative P:j(t) must converge to o. This gives
(7.20)
12They will exist provided that the transition matrix of the embedded Markov chain for the CfMC
is irreducible and positive recurrent
7.5 Continuous-Time Markov Chains 319
Before using the balance equation approach to find the limiting probabilities
for some of the models discussed previously, we note the following.
As before, if we define qjj = -v j, the system of equations in (7.20) can be re-
written more compactly as 0 = nQ where Q is the infinitesimal generator matrix
oftheCTMC.
It should be interesting to note that for discrete-time Markov chains, the limit-
ing probabilities are also found using a similar expression, i.e., by writing n =
np as 0 = nQ where Q = P - I is a matrix with rows adding up to 0 (as in the
infinitesimal generator matrix Q of the CTMC).
Example 93 A Markovian queue with no waiting space revisited We know from
our previous discussion that the limiting probabilities for this model are
Noting, as usual, that L]=o 1r j = I and following the steps used in the Marko-
vian queue example, Maple finds that limiting probabilities are given by
In this example, we entered each balance equation explicitly and then solved
the resulting equations after including L~=O n j = I to illustrate the use of the
"Rate Out = Rate In" approach. Some readers may feel that since the infinitesimal
generator Q of this CTMC is already available, it may be simpler to generate the
equation using the system 0 = IIQ. This is true, and the reader is invited to try
this approach to solve the problem with Maple's help.
Example 9S The self-service car wash and vacuum facility with extra capacity.
In order to increase the profitability of the car wash facility, the owner is con-
sidering increasing the capacity of the facility to two cars at a time-one at the
washing location, the other at the vacuuming location. \3 As before, there is no
possibility of forming a queue and the cars are first washed and then vacuumed.
With the additional capacity, a customer arriving when the wash space is free
can enter the system. After the customer finishes washing his car, he must wait
until the vacuuming space is free. This, of course, blocks the access to the wash
space for other potential customers. Once the vacuuming space is freed up, the
customer waiting in the wash space moves to the vacuum space and completes the
service. The arrival and service rates ..t, JlI and Jl2 have the same interpretation as
before. 14
In this more complicated problem, the states must be defined as a vector since
a knowledge of the number of customers in the facility, X(t), is not sufficient to
describe the system. Hence we define the system as (XI (t), X2(t» where XI (t)
is the state of the wash space (idle, busy or blocked) and X2(t) is the state of
the vacuuming position (idle or busy). With this definition of the state vector, we
obtain five possible values describing the system:
STATE DESCRIPTION
(0,0) Empty system
(1,0) Busy car wash, idle vacuum
(0,1) Idle car wash, busy vacuum
(1,1) Busy car wash, busy vacuum
(b, 1) Idle car wash blocked by busy vacuum
With this description of state space we can now generate the balance equations
by equating the "out" rate to the "in" rate.
Maple finds explicitly the solution of the system [minus the equation for State
(0,0)] with the equation 1r00 + 1r01 + 1r 10 + 1r II + 1r hi = I:
> restart: # CarWashExtraCTMCLimit.mws
> eq[ 0] : =lambda* piC 0,0] =mu[ 2] * piC 0, 1] ;
eqo := ..t 1ro, 0 = Jl2 1ro, I
> eq[ 1] := (mu[ 2] +lambda)*pi[ 0,1] =mu[ 1] *pi[ 1,0]
+mu[ 2] *pi[ b, 1] ;
eql := (Jl2 + ..t) 1r 0, I = JlI 1r 1,0 + Jl2 1r h, I
> eq[ 2] : =mu[ 1] * pie 1, 0] =lambda* pie 0,0]
+mu[ 2] *piC 1,1] ;
eq2 := JlI1r 1,0 = ..t 1ro,o + Jl21r 1,1
> eq[ 3] : = (mu[ 1] +mu[ 2] ) * piC 1,1] =lambda* pie 0,1] ;
14This could also be the description of a sboeshine shop or a barbershop with two chairs. In the
shoeshine shop, the first chair is used to polish shoes and the second chair used to buff them. In the
barbershop, the first chair is used to wash the customers' hair and the second chair is used to cut it;
see, Goodman [74, Section 11 4. ] and Ross [158, Section 3.3].
7.5 Continuous-Time Markov Chains 323
Eqns := {(J.l2 +..t) 1rO,1 = J.l11r 1,0 + J.l21rb, " J.l11rI,O =..t 1rO,o + J.l21r 1, 1,
(.ul +J.l2) 1r I,1 =..t 1r O,I, J.l2 1r b, I =J.lI 1r I,I,
1rO,O+1rO,1 +1rI,O+1rI,1 +1rb,1 = I}
> Vars:={pi[ 0,0] ,pi[ 0,1] ,pi[ 1,0] ,pi[ 1,1] ,pi[b,l]};
Vars := {1rO,O, 1rO, " 1r b,l, 1r 1,1, 1r I, O}
> with (linalg) :
Warning, new definition for norm
{1r _ J.l2 2 J.l1 (J.l1 + J.l2) _ J.l 22 ..t (.ul + J.l2 + ..t)
0,0 - %1 ' 1rI,O - %1
1r _(J.l1+J.l2)..tJ.l2J.l1 _J.l1 2 ..t 2 _..t 2 J.l2J.l1}
0, I - %1 ' 1r b, I - %1 ,1r I, I - %1
%1 :=J.l22 J.l1 2 +J.l2 3 J.l1 +2J.ll..tJ.l1 +J.l23 ..t +J.l22 ..t 2 + J.l2 J.l1 2 ..t
+..t 2 J.l2J.l1 +..t 2 J.l1 2
> normal (pi[ 0, 0] +pi[ 0,1] +pi[ 1, 0] +pi[ 1,1] +pi[ b, 1] ) ;
Since Maple collects many of the tenns in the solution, we print the 1rOO value
in a sJightly more detailed fonn.
> pi[ 0,0];
J.l2 2 J.l1 (J.l1 + J.l2) /(J.ll J.l1 2 + J.l2 3 J.l1 + 2J.l22 ..t J.l1 + J.l 23 ..t + J.l22 ..t2
Example 96 Response areas for emergency units. Consider two emergency units
i = 1,2 (e.g., ambulances) that serve two areas j = A, B, in a city. Nonnally,
units I and 2 respond to emergencies in their respective areas A and B. However,
if a call arrives from either area when only one unit is available the call is served
by the available unit. When both units are busy, the arriving calls are lost (i.e.,
alternative measures are taken to deal with the emergency).
324 7. Stochastic Processes
We assume that arrivals of calls from area j follow a Poisson process with rate
Aj. Service times in the areas are independent random variables where the time
required to serve a call from area j = A, B by unit ; = 1, 2 is exponential with
rate Jl;j.
As in Example 95, this model requires the state to be represented by a vector
(XI (I), X2(1» where
0 if uniti is idle
X;(I) = { 21 if unit ; is serving area 1
ifuniti is serving area 2.
Thus the vector process (XI (I), X2(1» is a eTMe with state space S = {(O, 0),
(0, 1), (0, 2), (1, 0), (1, 1), (1,2), (2,0), (2, 1), (2, 2)} that consists of nine states.
Let 1C;j, ;, j = 0, 1, 2 be the limiting probabilities of this eTMe. Using the
balance equation approach we find the nine equations for this process and enter
them in the Maple worksheet as follows: IS
>
>
restart: *
Ambulances.mws
eq[ 1] := (lambda( 1] +lambda( 2] )*pi[ 0,0]
=mu[ 2,1] *pi[ 0,1] +mu[ 2,2] *pi[ 0,2] +
mu[ 1,1] *pi[ 1,0] +mu[ 1,2] *pi[ 2,0] ;
eql := (AI + A2) 1C O,O = Jl2,I1CO,1 + Jl2,2 1C O,2 + JlI,I1CI,O + JlI,21C2,O
> eq[ 2] : = (lambda( 1] + lambda( 2] +mu[ 2, 1] ) * piC 0, 1]
=rou[ 1, 1] * piC 1, 1] +mu[ 1, 2] * piC 2, 1] ;
eq2 := (AI +A2 + Jl2,1) 1C O,1 = JlI,I1CI,1 + Jll,2 1C 2,1
> eq[ 3] : = (lambda( 1] +lambda( 2] +mu[ 2,2] ) * piC 0,2]
=lambda( 2] *pi[ 0,0] +mu[ 1,1] *pi[ 1,2]
+mu[ 1,2] *pi[ 2,2] ;
eq3:= (AI + A2 + Jl2,2) 1CO,2 = A2 1C O,O + JlI,I1C 1,2 + JlI,2 1C 2,2
> eq( 4] : = (lambda( 1] + lambda( 2] +mu[ 1, 1] ) * piC 1, 0]
=lambda( 1] * piC 0,0] +mu[ 2, 1] * piC 1,1]
+mu[ 2,2] * piC 1,2] ;
ISFor the infinitesimal generator matrix Q of this process, see KIlO [101, p. 245]
7.5 Continuous-Time Markov Chains 325
Next, we introduce the equation L:=O L]=O 1r ij = I, define the nine equations
of the system and solve the resulting system using sol ve () .
> Unity:=sum(sum(pi[ i,j] ,j=O . . 2),i=0 •• 2)=1;
Unity := 1rO,O + 1rO,1 + 1rO,2 + 1r 1,0 + 1r 1,1 + 1r 1,2 + 1r2,O + 1r2,1 + lr2,2 = 1
> Eqns: ={ seq (eq[ k] , k=1. .8)} union { Unity} i
Eqns := {(AI + A2) 1rO,O = Jl2,I1rO,1 + Jl2,21rO,2 + JlI,I1r 1,0 + JlI,2 lr 2,O,
(AI + A2 + Jl2,1) 1rO,1 = JlI,I1r 1,1 + JlI,2 lr 2,1,
(AI + A2 + JlI,2) 1r2,O = Jl2,1 1r 2,1 + Jl2,21r2,2,
(JlI,2 + Jl2, I) 1r2, I = A2 1rO, I + AI 1r2,O,
(AI + A2 + Jl2,2) 1rO,2 = A2 1r O,O + JlI,I1r 1,2 + JlI,2 lr 2,2,
(AI + A2 + JlI,I) 1r 1,0 = AI 1r O,O + Jl2,11r 1,1 + Jl2,2 1r 1,2,
(JlI, I + Jl2, I) 1r I, I = AI 1r O,1 + AI 1r I, 0,
(JlI, I + Jl2,2) 1r 1,2 = AI 1r O,2 + A21r 1,0,
1rO,O + 1rO,1 + 1rO,2 + 1rI,O + 1rI,1 + 1rI,2 + 1r2,O + 1r2,1 + 1r2,2 = I}
> Vars:={ seq(seq(pi[ i,j] ,j=0 •• 2),i=0 •• 2)};
Vars:= (1rO,O, 1rO,I, 1rO,2, 1rI,O, 1r2,O, 1r2,1, 1rI,)' 1rI,2, lr2,2}
> with (linalg) :
Warning, new definition for norm
Finally, note that the sum L.T=I L.]=I1f;j is the probability that both units are
busy and thus the incoming call is lost to the system. This probability can now be
computed easily as 10.48%.
> Surn(Surn(pi[ i,j] ,j=1..2),i=1..2); value(%);
2 2
L(L 1f ;,j)
;=1 j=1
.1048372876
Using the model presented in this example, one can analyze decision problems
such as the optimal number of units to assign in each location in order to minimize
the probability of lost calls or the optimal number of designated areas to serve
within the city boundaries.
7.6 Summary
This chapter started with a detailed description of the exponentiaVPoisson dual-
ity. Building on this duality, we presented renewal theory where the renewal func-
tion was computed explicitly using Maple's invlaplace () function that in-
verts a large class of Laplace transforms. Next, discrete-time Markov chains were
discussed and their limiting and transient behavior was analyzed using Maple's
sol ver and generating function inverter rgf expand ( ). We completed the
chapter with an analysis of continuous-time M3rlcov chains. Limiting probabili-
ties were again computed analytically using the solve () function. To compute
the transient probabilities, we used Maple's rna trixDE ( ) ,dsol ve () and ex-
ponen tial () functions. We can now start our analysis of specific applications
in inventory management and queueing processes.
7.7 Exercises
1. Provide a reasonable definition of the memoryless property for a nonnega-
tive discrete random variable N. Based on your definition show that P {N =
n} = (1 - p)p"-I, n = 1, 2, .. . is the unique discrete memoryless distri-
bution.
0 3/4 1/4]
P = [ 1/4 0 3/4 .
1/4 1/4 1/2
Using Maple's genfunc () function, find the transient probabilities for
this chain, i.e., find pen) for finite n. Next, find the stationary distribution
{1r it j = I, 2, 3} and compare it to above when n ~ 00.
9. Let {Xn , n = 0, I, ... } be a Markov chain with state space S = {I, 2, 3}.
The transition probability matrix for this chain is given as
p= [ !pp q! !q 0]
o p q
7.7 Exercises 329
with p + q = 1 and 0 < p < 1. Find the transient probabilities for this
chain. Med, 103
10. Let {Xn, n = 1,2, ... } be an irreducible and aperiodic MC with state space
S = {t, 2, ... , m} and Pij = Pji, i,j E S. Find lim Pr(Xn = k). (This
n-+oo
is an example of a doubly-stochastic matrix.)
11. Consider a CTMC with three states 0, 1 and 2. This CTMC has the infinites-
imal generator
where the values assumed by the diagonal entries denoted by • are such
that the row sums are zero. Find the long-run probability that the system is
in state O.
Q= [-;1 !;1
Il 0 -Il
2~].
Let 1 =
1 and Il = 8 and determine the transient probabilities of this
CTMC. Next, let t -+ 00 and find the limiting probabilities.
8
Inventory Models
8.1 Introduction
According to recent estimates the total value of inventories in the United States is
in excess oUI trillion [135, p. 184]. Abnost 80% of this investment in invento-
ries is in manufacturing, wholesale and retail sectors. Many of the mathematical
models that we will discuss in this chapter have proved very useful in manag-
ing inventories and their applications have resulted in substantial savings for the
companies employing them.
The term "inventory" can be defined as a stock of commodity that will be used
to satisfy some future demand for commodity. Due to the random nature of cus-
tomer arrivals and the amount required by the customers, future demand is usually
not known in advance. Inventory processes are influenced by the customers gener-
ating the demand, the management making the inventory order decisions and the
supplier(s) providing the required amount of the commodity to the management.
In order to satisfy ·future demands, management has to answer two basic ques-
tions relating to timing and magnitude: (I) When should an inventory replenish-
ment order be placed? (2) How much should be ordered? In the last 50 years,
thousands of inventory models have been developed to answer these questions
under different assumptions on the demand process, cost structure and the char-
acteristics of the inventory system. For recent reviews, see Barancsi et al. [15],
Porteus [151] and Lee and Nahmias [120]. The objective in almost all of these
models is to minimize the total costs of operating the system. This is achieved by
finding the optimal values of timing and magnitude decision variables that mini-
mize the objective function. (When the model involves random components such
1While in North America a weekly grocery list may include several loaves of bread that may last
the family many meals, in many other countries bread is still purchased daily from the local bakery.
8.2 Classification of Inventory Models 333
Among the classifications published in recent years, the one by Silver [174] is
probably the most detailed. In his scheme, Silver lists a nwnber of factors that
can each take on two or more values. For example, inventory models are clas-
sified according to the nwnber of items involved (single vs. multiple), nature of
demand (deterministic vs. probabilistic), length of decision horizon (single pe-
riod vs. multiperiod), time variability of the demand process (stationary vs. time
varying), nature of the supply process (deterministic or random lead time), pro-
curement cost structure (discount possibility), backorders vs. lost sales when there
is a shortage, shelf-life considerations (obsolescence or perishability) and single
vs. multiple stocking points.
One can define a set of "standard problems" that have mathematically devel-
oped optimal solutions. These problems have found wide applicability or have
potential applications with minor modifications. Among these problems, EOQ-
type models are classified as single item with deterministic demand and stationary
conditions. In multi-items problems, deterministic and stationary demand under
budget or space constraints are normally solved using the Lagrange multiplier
technique. The single-item problem with deterministic but time-varying param-
eters (also known as the dynamic lot size problem) was solved by Wagner and
Whitin [191] using dynamic programming.
In continuous-review models it is asswned that the inventory level is known at
all times. In many supermarkets that have scanning devices at the checkout coun-
ters, it is possible to keep track of the inventory level of any item. Hence, in these
systems transaction information is easily available that makes the application of
continuous-review models possible. In periodic-review models the inventory level
is measured only in discrete time points when inventory is physically counted.
The continuous-review (Q, r) policy where r is the fixed order point and Q is
the fixed order quantity is used to control the single-item problem with stationary,
probabilistic demand with known distribution. Variants of this policy such as the
(R, S) periodic replenishment system where R is the review interval and S is
the order-up-to level, and the (R, r, S) policy are also used, for which efficient
solution techniques have been developed. Decision rules are also available for
multi-item probabilistic stationary problem under a budget constraint. The single-
item, single-product problem (i.e., the classical newsvendor model) is the simplest
of the probabilistic inventory models and its variants with multi-items with budget
constraints are solved using the Lagrangian technique. The coordinated control
of items under deterministic or probabilistic stationary demand with or without
discounts and multiechelon stationary situations are more complicated models
for which decision rules are available.
For a description of the solution of these and other inventory models, we refer
the reader to the books by Banks and Fabrycky [13], Hax and Candea [84], Silver
and Peterson [175], and Tersine [185].
334 8. Inventory Models
(y) _ { K + cy if y > 0
(8.1)
c - 0 ify = 0
is a procurement cost function that has a fixed setup cost component K that is
incurred when an order is placed. When demand is probabilistic and a periodic-
review system is in place, such a cost structure results in the optimality of the
well-known (s, S) policy, as proved by Scarf [166].2
21n inventory literature the symbol s appears under different disguises. In Hadley and Whitin's
[8\, Chapter 4] continuous-review (Q, r) model where Q is the lotsize and r is the reorder point, s
is used to denote the safety stock, which is defined a<I the expected value of the inventory level when
a procurement arrives. In Scarf's [\66] periodic-review (s, S) model, s denotes the reorder point. In
this chapter, in order to present a development parallel to those in Hadley and Whitin and Scarf, we
use s as the safety stock when we discuss the continuous-review models. But when a periodic-review
model is under consideration, s corresponds to the reorder point.
8.4 Detenninistic Inventory Models 335
dependent per unit backorder cost with dimension $Iunit/time and 1C 2 is the per
unit backorder cost with dimension $Iunit. [Here 1C, plays a role similar to the
holding cost h (S/unit/time) that is used in the computation of the holding cost
component.]
Let b(t) be the number of units on backorder at time t during a shortage interval
of [0, T]. Then Jei 1r ,b(t) dt + 1r2b(T) is the total penalty cost incurred during
[0, T]. In practice both 1r, and 1r2 are difficult to estimate since they usually
represent intangible factors such as the loss of goodwill resulting from a delay in
meeting demands. In a recent paper, <;etinkaya and Parlar [42] consider the two
backorder costs indirectly by introducing two safety-stock type constraints. Thus
in their form the problem becomes one of minimizing the ordering and holding
costs subject to two appropriate constraints.
1. The demand rate is known and constant (stationary) at 1 units per unit
time. 3
(a) Purchase cost is c dollars per unit and setup (order) cost is K dollars
per order.
(b) Holding cost is h dollars per unit per unit time. This cost is usually
defined as h = i c where i is the inventory carrying charge, the cost in
dollars of carrying $1 of inventory per unit time.
(c) Since shortages are not allowed, the shortage cost is infinitely high.
It should be clear that since leadtime is zero and demand is known with cer-
tainty, it is optimal to order only when the inventory level 1(/) at time I reaches
zero.4 As each order must be of the same size, we assume that the order quantity
is always Q units.
Referring to Figure 8.1, we see that a regenerative cycle starts when the in-
ventory level is increased to Q units. Since demand is 1 units per time, it takes
T = Q/ 1 time units for the cycle to end. Thus the deterministic cycle length is
simply
=
E(Cycle length) Cycle length Q/1. =
The cycle cost computation is slightly more complicated as we need to account
for the total cost of ordering and holding in a given cycle. At any time I E [0, T),
the inventory level is 1(/) = Q -11. Thus, during each cycle the total holding
cost is
The total cycle cost is found by adding the order cost K to the holding cost: s
3In this chapter the "unit time" will normally correspond to one year.
4For a rigorous proof of this result, see ArrC1W, Harris and Marschak [II).
SSince the demands must be met ultimately (and there is no quantity discount for larger orders),
we do not include the procurement cost per cycle cQ in the cycle cost If this cost were included,
then dividing it by the cycle length Q/l would give d, a constant that would not affect the optimal
decision.
8.4 Deterministic Inventory Models 337
Inventory /(t)
--T=Q -+ Timet
A.
> EL:=Q/larnbda;
EL:= Q
I
> G:=expand(EC/EL);
I K I
G:=Q+'2 Qh
Differentiating G once and then twice to find GQ and GQQ, we see that the
unique positive solution of the necessary condition will be the global optimal
solution since the second derivative is always positive for Q > O.
> GQ:=diff(G,Q);
I K I
GQ:=-Q2+'2 h
> GQQ:=norrnal(diff(G,Q$2»;
IK
GQQ:=2 Q3
Solving the necessary condition and recalling that every parameter is positive,
we pick +J2Kl/h as the optimal solution.
338 8. Inventory Models
sol:= ,Ji..r:rx,
> QOpt : =simplify(sol[ 1] ,power,symbolic);
-
2
In this model, we retain every assumption we made while discussing the basic
EOQ model except the requirement that there must be no shortages. Here we as-
sume that the demands occurring when the system is out of stock are backordered
until a new shipment arrives. At that time all backorders are satisfied before the
shipment can be used to meet other demands.
We let s ~ 0 be the number of backorders on the books when an order is placed
and a shipment of Q units arrives immediately.6 After satisfying the backorders,
the cycle will start with Q - S lDlits, which will be depleted to zero after TI =
(Q - s)/ A. time units. If T is the cycle length, then T2 = T - TI is the length of
a subcycle during which backorders will be incurred. The inventory process for
this model is depicted in Figure 8.2.
Invemay /(/)
Q-s
1
L
8
-8 .
Avenge W81t w = -
r
2AQ
h loo
TI h
(Q -s - A.1)dl = -(Q _s)2
2A.
6This is essentially a continuous-review model with zero leadtime and deterministic demand.
Hence the reorder point s in this model is also the safety stock.
340 8. Inventory Models
since T2 = s /1. Noting that the procurement cost can again be ignored (since the
demands will ultimately be satisfied), the average cost is found as
G
1K
=Q 1
+ 2Qh(Q 2 1 (I 2
-s) + Q !1fIS + 1f21S
)
These expressions are entered in Maple and the optimal solution is computed
as follows:
> restart: # EOQBackOrder.mws
> T1:=(Q-s)/lambda;
Tl:= Q-s
1
> HoldingC:=normal(h*int(Q-s-lambda*t,t=O .. T1));
> T2:=normal(T-T1);
s
T2:= ;:
> BackorderC:=pi[ 1] * int (lambda*t, t=O .. T2) +pi[ 2] * s;
1 1f 1 s2
BackorderC := 2: -1- + 1f2 s
> EC:=K+HoldingC+BackorderC;
EC K 1 h ( - Q + S )2 1 1f 1 s2
:= +2: 1 +2:-1-+ 1f2S
> EL:=T;
Q
EL:=-
1
> G:=expand(EC/EL);
1K 1 1 h s2 1 1f 1 s2 1 1f2 S
G:= Q+2:Qh-hs+2:Q+2:Q+Q
For ease of exposition, we consider the simpler case of this problem with 1f2 =
o.
> G:=subs(pU ~ =O,G);
1K 1 1 h s2 1 1f 1 s2
G:=Q+2: Qh - hs +2:Q+2:Q
The necessary conditions are found by differentiating the objective function.
8.4 Detenninistic Inventory Models 341
hs ll'IS
Gs:=-h+ Q + Q
Here we check to see if the objective function is strictly convex in the decision
variables (Q, s). First we load the linalg () package and compute the Hessian
matrixofG.
> with (linalg) :
Warning, new definition for norm
> H:=hessian(G,[Q,s]);
-~~-~:]
h 1r I
-+-
Q Q
Maple gives two conditions in order for G to be positive definite.
> definite(H,positive_def);
). K h s2 1r 1 s2
- 2 - - - - - - <Oand
Q3 Q3 Q3
h s2 1r 1 s2 ) ( h
(2 ). K ll' 1 ) ( hs ll' 1 s )2 0
- Q3+Q3+Qr Q+"Q+-Q2-Q2 <
A further simplification shows that the second term is also negative, indicating
that G is positive definite. 7
> Condition2 : =-(2*lambda*K/(Q A3)+h*sA2/(Q A3)
+pi[ 1] * sA2/ (Q A3) ) * (h/Q+pi[ 1] /Q)
+ (-h* s/ (QA2) -pi[ 1] * s/ (QA2)) A2;
.. ). K h s2 1f 1 s2 h 1f 1 hs 1f 1 S 2
Cond,t,on2:= -(2 Q3 + Q3 + Qr)(Q +"Q) + (- Q2 - Q2)
> sirnplify(Condition2);
-2 (h + ll' I»). K
Q4
Solution of the necessary conditions gives the values of Q and s.
7We should note that we have not reentered the second tenD manually but simply copied it to the
clipboard using the mouse and then pasted it to the next line.
342 8. Inventory Models
J2 $+1iI../I,JK
Fi./h
> simplify(s,power,syrnbolic);
J2../I,JK./h
.;;rJ $+1iI
As the backorder cost 1C I approaches infinity, the solution should converge to
the one we found for the basic EOQ model, which is indeed the case.
> limit (Q, pi[ 1) =infinity) ;
~J2
h
> limit (s,pi[ 1) =infinity);
o
Note that since lim s = 0 since for very large backorder costs, it would not
lrl~OO
solution, Maple computes the optimal values of the decision variables Q and s
as approximately 115 and 29, respectively. The minimum cost is computed as
$866.02.
> lambda:=2000; K:=25; pi[ 1] :=30; h:=10;
A := 2000
K :=25
1r 1 := 30
h:= 10
> Q:=evalf(Q); s:=evalf(s);
Q := 115.4700538
s := 28.86751346
> G;
866.0254037
Note that in this formulation the backorder cost 1r 1 does not appear.
It is clear that W must be positive; otherwise the problem reduces to the basic
EOQ model with optimal s = 0 and optimal Q = J2Kl/h.
344 8. Inventory Models
Since the objective function and the feasible set is convex, the Kuhn-Tucker (KT)
conditions are necessary and sufficient for optimality.
The KT conditions are o.c;os = 0, o.c;oQ = 0, o£/ofJ ~ 0, fJ· (o£/ofJ) =
and fJ ~ 0. The first three of these are easily obtained by Maple as follows.
°
> restart: # ImpliedBO.mws
> L:=K*lambda/Q+(1/2)*h* (Q-s)A2/Q
+mu* ((1/2)* sA2/Q-lambda*W);
Ls .- h(Q-s) fJS
.- Q +0-
> LQ:=diff(L,Q);
LQ .__ K ). + h (Q - s) _ ~ h (Q - s)2 _ ~ fJ s2
.- Q2 Q 2 Q2 2 Q2
> Lmu:=diff(L,mu);
1 s2
Lmu := 2" Q -). W
Solving for the first two equations we find the optimal values of the decision
variables (s, Q). Comparing this solution with the one we found in Section 8.4.2,
we see that they are the same with 1C I = fJ and that s / Q = h / (h + fJ).
> sol :=solve ({ Ls, LQ) ,{ s, Q) );
e := ~ K ). h2 ,J2 = ). W
q 2 (h+ p.)Jp. (h + p.)Klh
We note that if p. = 0, no solution can exist for this problem since the first KT
condition aClas = 0 implies s = Q, thus reducing the second KT condition to
- K).I ~ = 0, which is impossible. Hence p. > 0 and the constraint s2 1(2). Q) ~
W must be satisfied as an equality.
Substituting the optimal values of sand Q into s2/(2).Q) = W gives a nonlin-
ear equation (a fourth-order polynomial) in p.. This equation has a unique solution
since the term in its left-hand side is a strictly decreasing function of p. that re-
duces from infinity to zero.
> LHSeq:=lhs(eq);
LHSe ._ ~ K ). h2 ,J2
q .- 2 (h + p.) J p. (h + p.) K ). h
> norrnal(diff(LHSeq,rnu));
1 (4 p. + h),J2 hJ ).2 K2
-4 (h + p.)(p. (h + p.) K ). h)(3/2)
> assurne(h>O, K>O, larnbda>O);
> lirnit(LHSeq,rnu=O,right);
00
> lirnit(LHSeq,rnu=infinity);
o
Since larger order quantities are associated with lower prices, we have PI > P2 >
... > Pn. Recalling the definition of the holding cost h = ie, we see that since
c is a function of Q, the order-quantity-dependent order cost would be h(Q) =
ic(Q). With this definition, and retaining every other assumption we made when
we introduced the basic EOQ model, the new objective function G (Q) is obtained
as
)'K 1
G(Q) = Q + "2h(Q)Q + ).c(Q). (8.3)
The objective is to compute the optimal Q that will minimize the average cost
function G(Q) in (8.3). Since the holding and procurement costs are both discon-
tinuous functions of Q, the objective function G(Q) is also discontinuous - see
Figure 8.3 - and its minimum value has to be obtained using a procedure that is
more complicated than the one we employed for the basic EOQ model.
Essentially, the procedure for computing the optimal order quantity involves
three steps.
I. For each region bk-I ::; Q < bk, k = I, . .. , n defined in (8.2), compute an
order quantity Q using the EOQ formula with the unit cost associated for
that category.
2. It is possible that some of the Q's found in Step 1 may be too small to
qualify for the related discount price; i.e., they may be infeasible. In that
8.4 Detenninistic Inventory Models 347
case adjust the order quantity upward to the nearest order quantity point at
which the unit price will be reduced.
3. For each of the order quantities found in Steps 1 and 2, compute the average
cost G(Q) in (8.3) using the unit price that is appropriate for that quantity.
The order quantity yielding the lowest cost is the optimal one.
When there is a large number of break points, this procedure outlined above
may be cumbersome to implement manually. However, using Maple's graphical
and numerical capabilities, the optimal solution to the quantity discount problem
can be found very easily.
As an example, consider a problem with an annual demand of A. = 1000 units,
inventory carrying charge of i = 0.10 and order cost of K = $100 per order.
> restart: *
QuanDisc.mws
> lambda:=1000; i:=0.10; K:=100;
A. := 1000
i:= .10
K:= 100
There are two break points at hI = 100 and In = 300 with prices PI = 50,
Pl = 49 and 1'3 = 48.50. Thus, the procurement cost function is
50, if bo = 0 ::: Q < 100
c(Q) ={ 49, if 100 ::: Q < 300
48.50, if 300 ::: Q < 00.
> b[l]:=100; b[2]:=300;
p[ 1] :=50; p[ 2] :=49; p[ 3] :=48.50;
hI := 100
h2:= 300
PI := 50
Pl:= 49
P3 :=48.50
We enter this information in Maple using the piecewise () function and
form the objective function G(Q).
> c: =Q->piecewise (Q<b[ 1] ,p[ 1] ,Q<b[ 2] ,p[ 2], p[ 3] ) ;
c := Q -+ piecewise(Q < hI, PI, Q < In, Pl, 1'3)
> C (Q) ;
150
49
Q < 100
Q < 300
48.50 otherwise
> h : =Q-> i * c (Q) ;
348 8. Inventory Models
h:=
ic(Q) Q~
> G:=Q->K*lambda/Q+(l/2)*h(Q)*Q+lambda*c(Q);
K)' I
G:= Q ~ Q + 2h(Q) Q+).c(Q)
A visual inspection of the plot of G(Q) in Figure 8.3 reveals that the optimal
solution is at the last break point h]. = 300.
> iplot(G(Q),Q=50 .. 500,discont=true);
51500
51000
50000
202.0305089
At this EOQ point, the cost function assumes the value G(202.03) = $49989.94.
> G (ct 2] ) ;
49989.94949
However, the order quantity at the next break point h]. = 300 gives a lower
cost as G(300) = $49560.83, indicating that the optimal order quantity must be
= =
Q In 300 units.
> G (b[ 2] ) ;
49560.83333
8.5 Probabilistic Inventory Models 349
I. Since the system is continuous review, the on-hand inventory level is known
at all times.
3. There is never more than one order outstanding. This means that when the
reorder point r is reached. there are no outstanding orders so that the inven-
tory position (IP)s is equal to the inventory level (IL), implying that order
quantity Q will always be the same.
81nventory position is defined as the amount on hand plus the amOlDlt on order minus the number
of backorders. Inventory level is the 8I11OIDIt on hand minus backorders. Some authors (e.g., Hadley
and Whitin [SI, p. 163]) use the tenn "net inventory" instead of "inventory level."
350 8. Inventory Models
(a) Purchase cost is c dollars per unit and order (setup) cost is K dollars
per order.
(b) Holding cost is h dollars per unit per year.
(c) There is a shortage cost of tr (= 1C I) per unit of unsatisfied demand.
The time-dependent part of the shortage cost is tr2 = O.
In deterministic inventory models such as the basic EOQ model, the inventory
level at the time of an order arrival can be determined with certainty. In stochastic
inventory models this is not possible since the demand during leadtime is also a
random quantity. The expected value of the inventory level at the time of an order
arrival is defined as the safety stock and it is denoted by s. Since the expected
demand during leadtime is p, we can write s = r - p.
In this model, the regenerative cycles are of random length and they commence
when the inventory position is raised to Q + r. Figure 8.4 depicts a sample real-
ization of the expected (average) behavior of the inventory position and inventory
level processes. The sample paths of these processes are drawn as lines since we
had asswne that the demand is stationary with a constant expected value of). units
per year. By using the renewal reward theorem we can construct the average cost
per year as follows.
Cycle Length
Since the IP fluctuates between r and Q + r, and Q units are used at an average
rate of). units per year, the expected cycle length is E (length) = Q / )..
Cycle Cost
We examine the cycle cost in three parts.
• Order Cost: Since each cycle starts with an order, the order cost in a cycle
is K dollars.
9 As we indicated previously, in this chapter the unit time is normally taken as one year.
8.5 Probabilistic Inventory Models 351
FIGURE 8.4. A sample realization of the expected (average) behavior ofinventory position
and inventory level processes in the continuous-review model with backorders.
= AK 1CA
g+h(!Q+r-p)+Q 1r
00
(x-r)f(x)dx.
352 8. Inventory Models
The third tenn B(Q, r) = (1r AI Q) ir(x -r)f(x) dx in the objective function
is the expected backorder cost per year. As we showed in Chapter 5, Nonlinear
Programming, despite the claim made by Hadley and Whitin [81, p. 221, problem
4-6] this function is not, in general, jointly convex in Q and r. But, as we also in-
dicated, if t; is a number such that f(x) is nonincreasing for x ~ t;, then B(Q, r)
is convex in the region {(Q, r) : 0 < Q < 00 and t; ::; r < oo}. Thus, if r is
restricted to be suitably large, then B(Q, r) -and the objective function G(Q, r)
- is convex within such a region. For example, if f(x) is nonnal, then B(Q, r)
is convex when r exceeds the expected demand during lead time. When f(x)
is a strictly decreasing density such as the exponential, then B(Q,r) is convex
everywhere.
We now use Maple to find the necessary conditions minimizing G(Q, r) and
present an example using an exponential demand density f(x) = Oe-J:x, x ~ o.
> restart: # Qr.mws
The objective function G (Q, r) and its derivatives G Q and G r are entered and
evaluated to give the necessary conditions.
> G:=lambda*K/Q+h* (Q/2+r-mu)
+(pi*lambda/Q)*int«x-r)*f(x),x=r .. infinity
) ;
G :=
AK I
Q + h (2 Q + r - Jl) +
1r A 1r
00
(x - r) f(x) dx
Q
> GQ:=diff(G,Q);
AK
GQ := --Q-2
I
+ 2h -
1r )'1 00
(x - r) f(x) dx
_..::..;r:......-_-:2
,....---
Q
> Gr:=diff(G,r);
Gr:= h +
1r A1 00
- f(x)dx
_....::...:.r_ _ __
Q
An attempt to solve for the unknowns Q and r directly from the necessary
conditions fails. This is understandable since it is impossible to find a c1osed-fonn
solution for the unknowns from expressions involving integrals whose lower limit
includes r. Thus the necessary conditions must be solved numerically once the
density f(x) is specified.
> solve({ GQ,Gr} ,{ Q,r} );
Error, (in solve) cannot solve expressions with,
int(-(-x+r)*f(x),x =r .. infinity), for, r
> Qsol:=solve(GQ,Q);
8.5 Probabilistic Inventory Models 353
h
Although we cannot solve the necessary conditions for the Q and r values
explicitly, we can at least express Q in tenns ofr (denoted in the Maple worksheet
by Qr) and r in tenns of Q (denoted by rQ) easily as follows:
> Qr: =Qsol[ 1] ;
h
> readlib(isolate);
p~(etpr, x, n) ... end
> rQ:=isolate(Gr,int(-f(x),x=r .. infinity»:
00 hQ
rQ:= [
r
- f(x)dx =--
ltA.
Following is an example illustrating the solution of the approximate (Q, r)
model with an exponential density for the demand during lead time.
> K:=100: h:=.15; pi:=l; lambda:=10000;
delta:=1/1000; mu:=l/delta;
fIx) :=delta*exp(-delta*x);
K:= 100
h:= .15
It := I
A. := 10000
I
t5:= 1000
p. := 1000
I
f(x) := 1000 e(-I/IOOOx)
The cost function G and its partials now assume specific fonns.
> G;
I e(-I/IOOOr)
1000000 Q + .07500000000 Q + .15r - 150.00 + 10000000 Q
354 8. Inventory Models
> GQi
1 e(-I/IOOOr)
-1000000 Q2 + .07500000000 - 10000000 Q2
> Gri
e(-I/IOOOr)
.15 -10000 Q
Since the data and the density f(x) are specified. Maple easily finds the opti-
mal Q and r values as 4785 and 2634, respectively. The minimum value of the
objective fimction is obtained as $962.99.
> sol:=solve({ GQ,Gr},{ Q,r} ) i
1 2- - 1 -
P(v) = 2(AL) F(v - 1; AL) - ALvF(v; AL) + 2v(v + I)F(v + 1; AL)
a(v) = ALF(v; AL) - vF(v + 1; AL).
In these expressions,
00 u-I
F(u; AL) = LfV; AL) = 1 - LfV; AL)
j=u j=O
FBar:= u -+ 1 - C
L -I e(-H) (A
.f
LY)
.=0 }.
The expressions for a(v), P(v), b(Q, r), B(Q, r) and S(Q, r) are also defined
using the unapply () ftmction so that they may be evaluated when we compute
the G (Q, r) ftmction.
> alpha:=unapply(' lambda*L*FBar (v)-v* FBar (v+l)' ,v) i
a := v -+ A L FBar(v) - v FBar(v + I)
> beta:=unapply(' ((lambda*L)A2/2)*FBar(v-l)
-lambda* L*v* FBar (v)
+(1/2)*v* (v+1)*FBar(v+1)' ,v) i
1 1
P := v -+ 2 A2 L2 FBar(v - 1) - A L v FBar(v) + 2 v (v + 1) FBar(v + 1)
> b:=unapply(' (lambda/Q)* (alpha (r)-alpha (Q+r) )' ,
Q,r)i
._ (Q)
b .- A(a(r) - a(Q + r»
,r -+ Q
> B:=unapply(' (l/Q)* (beta(r)-beta(Q+r»' ,Q,r)i
356 8. Inventory Models
120
100
80
reo
40
20
o 5 10 15 a 20 25 30
FIGURE 8.5. Contour curves of the G(Q, r) function in the exact formulation of the con-
tinuous-review model. Note that although G (Q, r) is a discrete function of discrete vari-
ables Q and r, the graph is drawn using continuous variables.
all 861 integer points in the [15,35] x [80,120] region. The optimal solution is
found as Q = 18, r = 96 and G = $32.89.
> evalf(G(19,96»;
32.9419609
We should note in closing that the same problem was also solved by Hadley
and Whitin [81, Section 4-10), who obtained a slightly different-and incorrect-
"optimal" solution as (go, rO, G(go, rO» = (19,96, $31.75). Although this is
an incorrect result IO due to the flatness of the objective function, using Hadley
and Whitin's solution (19,96) would give G(l9, 96) = $32.94 - an increase of
only 4 cents, or 0.15%.
lOA Quick BASIC program written to check the results found that Maple's solution was correct.
358 8. Inventory Models
= (s - v)p- (c - v)Q - (s +p - v) 10
00
(x - Q)/(x)dx
P := (s - v) p - (c - v) Q - (s +p - v) 10
00
(x - Q) f(x) dx
8.5 Probabilistic Inventory Models 359
Since PQQ < 0, the expected profit function P(Q) is a strictly concave. Thus
the solution of the necessary condition PQ = 0 would give the unique maximizing
value.
> PQ:=diff(P,Q)i
PQ := -c + v - (s +p - v) 10
00
- f(x) dx
> PQQ:=diff(P,Q$2)i
PQQ:= -(s +p - v)f(Q)
In order to isolate the term containing the integral term, we use the iso-
late () function.
> i:=op(3,op(3,PQ))i
; := 1000
- f(x)dx
> readlib(isolate)i
proe(expr, x, n) ... end
> isolate(PQ,i)i
fOO _ f(x) dx = c- v
1Q -s - p+v
The necessary condition is thus obtained as
- =1
F(Q)
Q
00
f(x)dx = s+p-v
c-v . (8.4)
Since v < c and c < p, the right-hand side of this expression is always less than
unity.
We now solve a numerical example assuming that the demand is a two-stage
Erlang random variable with a mean of 100 units.
> c:=15i s:=55i V:=lOi p:=20i
lambda:=l/lOOi rnu:=l/lambda:
f:=x->2*lambda* (2*lambda)*x*exp(-2*lambda*x)i
c:= 15
s:= 55
v:= 10
p:=20
1
1:= 100
-S + ~ Qe(-I/SOQ) + 6Se(-I/soQ)
10
Solving the necessary condition gives two solutions, but the correct one is the
positive solution that is equal to 210.82. The maximum value of the expected
profit is found as $3,147.86.
> sol:=evalf(solve(PQ,Q));
sol := -48.S4324892, 210.84207S0
> evalf (subs (Q=sol[ 2) , P) ) ;
3147.867908
It is useful to note that the same problem can be restated in terms of expected
cost minimization as follows. Define Co = C- v to be the cost of overage, i.e., the
loss per unit on any remaining units. Similarly, let Cu = (s - c) + p as the cost of
underage, i.e., cost per unit incurred if a demand occurs when the system is out
of stock. Here Cu is the sum of the potential profit lost s - c, and the cost of lost
"goodwill" p . With these definitions, the condition in (8.4) can be rewritten as
This suggests that minimizing a relevant expected cost function (of overage
plus underage) is equivalent to maximizing the expected profit function. This fol-
lows since the realized value of cost is
and hence
Differentiating G(Q) and equating the result to zero gives C'(Q) = co-coF(Q)-
cuF(Q) = 0 so that
F(Q) = Co .
Cu +co
This is the same result as in (8.5).
A review by Khouja (107] lists nearly 100 papers that deal with applications
and ramifications of the single-period inventory model. Some of the recent work
on coordination in supply chain management also involves the use of the single-
period model; see, Parlar and Weng [147] and Weng and Parlar (193].
8.5 Probabilistic Inventory Models 361
I
the expected cost that must be minimized is
min {cu/c
Uk~O
+ L(x/c + U/c) + E[Vk+I(x/C + U/c - W/c)]}
= min {CU/c
Uk~O
+ L(x/c + U/c) +
Jotx) Vk+I(X/c + u/c - w/c)!/c(W/c)dW/c}
362 8. Inventory Models
The L (y) function can be interpreted as the expected loss per period due to pos-
sible overages or underages. It can be shown that L (y) is strictly convex since
L"(y) = (h + b)f(y) > O.
We now state an important theorem concerning the structure of the optimal
policy for this problem.
Theorem 14 Assuming c > 0, h ~ 0, b > c and linear order cost c(u) = CU, the
optimal policy p (x) is ofthe form
min
YN-I~XN-I
[CYN-l + L(YN-l)] -CXN-l
= min GN-l(YN-l) - CXN-l
YN-I~XN-I
II Convexity ofG(y) = cy + L(y) follows from the fact that cy is linear and L(y) is convex.
8.5 Probabilistic Inventory Models 363
• If the initial inventory XN-I < SN-I, thenYN-1 = XN-I +UN-I = SN-I;
i.e., we must order up to SN-I. This implies that the optimal order quantity
must be UN-I = SN-I-XN-I. Note that in this case GN-I (SN-J) 5 G(y)
for all Y ~ XN-I .
• If the initial inventory XN-I ~ SN-I, then YN-I = XN-I + UN-I = XN-I;
i.e., UN-I = 0, thus no units should ne ordered.
In summary, for period N - 1, the optimal policy J-l N _I (x N -I) is state depen-
dent and it assumes the form
SN-I -XN-I ifxN-1 < SN-I
(
J-lN-1 XN-I
)
={ 0 ifxN-1 ~ SN-I.
The value function now becomes
where GN-2(Y) = cy+ L(y)+ E[VN-I (y - w)). We recall that since VN-I was
convex, so is E[VN-I(Y - w)], implying that GN-2(Y) is also convex. 12 Thus,
there exists an SN-2 that minimizes GN-2(Y) that results in the same policy, i.e.,
Hence,
12It is easy to see that if, say, g(y) is convex, then t/J(y) = £[g(y - w)) is also convex since
t/J"(y)=.roo g"(y - w)dF(w) ~ o.
364 8. Inventory Models
levels .so,
SI, .. . ,SN-I for each period. The exact computation of these values
is usually very difficult since they require the analytic solution of the dynamic
programming functional equations for each period. We now describe an example
where Maple is used to compute the exact values of the base-stock levels.
We assume that N = 2 and the demand in each period is uniformly distributed
with density f(w) = 1/15. The relevant cost parameters are c = 4, h = 7 and
b= 10.
We start by defining the input data.
> restart : *
BaseStock . mws
> c:=4; h : =7; b:=10;
Low:=O; Hi:=15; f:=w->1/(Hi-Low);
c :=4
h :=7
b:= 10
Low:=O
Hi:= 15
I
f:=w-+ - - -
Hi-Low
=
The value function for the terminal period N 2 is Y2(X2) = O. The function
L (y) is defined in the usual manner for each period.
> EV[ 2] : =unapply(O,x);
EY2 :=0
> L:=unapply(h*int((y-w)*f(x),w=O •• y)
+b*int((w-y)*f(x),w=y .• 10),y);
. . 40 1540 17 100 20
VI := X ~ Plecewlse(X < - - - - 4 x - X2
17' 51 ' 30
+ - 3 - -3 X)
> V[ 1] (x);
1540 -4x 40
X <-
{ 51 17
17 x2 + 100 _ 20 X otherwise
30 3 3
> Vyw:=V[ 1] (y-w);
1540 -4y+4w 40
y-w<-
JF.yw ._ { 51 17
r .- 17 100 20 20
_(y-w)2+_ --y+-w otherwise
30 3 3 3
> op(l,Vyw); op{2,Vyw); op(3,Vyw);
40
y-w<-
17
1540
5l- 4y + 4w
.!2 (y _ wi + 100 _ 20 Y + 20 w
30 3 3 3
The expectation of the value function E[ VI (y - w)] is now evaluated as a swn
of two integrals which results in a cubic equation.
> EV[ 1] :=unapply(int(op(3,Vyw)*f(w),w=O •• y-S[ 1])
+int(op(2,Vyw)*f(w),w=y-S[ 1] •• 10),y);
EV .-
I .-y~ 1350
.1Z... (y _40 3 ~ _E..
~
17) +2( 225 Y +9)(Y
_ 40 2 E.. ..2 (y _
17) + 450 Y
40)
17
32 85760 4 40 4 210 2 40 2
+ 153 Y + 2601 -9 Y (Y-17)-TS Y (17- Y )-TS(Y-17)
> simplify (EV[ 1] (y»;
17 3 4 . .2 376 259840
1350 y - 45 Y - 153 Y + 7803
For period k = 0, the Go(y) function is computed explicitly. Minimizing this
function gives the optimal base-stock level as So = 4.54.
> G[ 0] :=unapply(c*y+L(y)+EV[ 1] (y) ,y);
366 8. Inventory Models
jointly with lot sizing decisions. Recently Yano and Lee [197] have published a
survey in which they review these and other random yield models.
In this section we consider the issue of source (supplier) diversification under
yield randomness and examine the conditions for choosing two suppliers with
different yield distributions over a single source. Our exposition parallels the dis-
cussion of the second model presented in Gerchak and Parlar (69).
As in the basic EOQ model, we let h be the holding cost per unit per time and A.
be the known and constant demand per time. When Q units are ordered, a random
number of units are received, denoted by YQ. It is assumed that E(YQ) = #Q
and Var(YQ) = a 2 (f for Q 2: O. In production-related applications, YQ usually
represents the number of usable units in a lot of Q units. However, for the sake of
generality, we assume that # does not have to be less than unity and we let # 2: O.
First let us suppose that two independent sources are available with K as the
cost of setup (ordering) when both sources are used simultaneously. Hence, if
Qi > 0 units are ordered and YQ; are received from source i = I, 2, we have
(~ +~ )2
Cost per cycle = K + QI Q2
2A.
and
~Q +~Q
Length of cycle = 1 2•
A.
If the moments are specified as #i, a~, i = 1,2, then using the renewal reward
theorem, we obtain the average cost G(QI, Q2) = E(Cost per Cycle)/ E(Length
of Cycle) as
I
GQ}:= "2(h QI 2 0"12 PI +2h QI 0"1 2 P2 Q2 +h QI2 PI 3
+2h QI PI 2 P2 Q2 +h Q2 2 PI P2 2 -2PI K A
- PI h Q2 2 0"22) /(PI QI + P2 Q2)2
122 2
GQ2:=-"2(-hQI PI P2- 2h QIPIP2 Q2
- 2 h Q2 0" 22 PI QI - h Q2 2 0"22 P2 - h Q2 2 P2 3
> Sol:=allvalues(Sol);
The results still look very unappealing, but we note that there is a relationship
between the complicated terms defined by %1 and %2. Maple informs us that these
terms are a constant multiple of each other. \3
> sirnplify(%1/%2);
h
The solution for QI and Q2 are assigned in order to manipulate them.
> Sol[ 1] ;
13Note that in order \0 see the output in terms of %1 and %2, one should set \Option \Output
Display \Typeset Notation. Otherwise Maple gives an error message.
370 8. Inventory Models
. U)2 P2
Ratlo := - 2 -
U2 p)
This discovery helps in rewriting the expression for Q2 in a fonn that is a mirror
imageofQ) .
> Q2Sol:=simplify(Ratio*Q1Sol);
(8.7)
> nops(GOpt);
6
> seq(op(i,GOpt),i=l • . nops(GOpt));
Gerchak and Parlar [69] show that if a single source were used - where the
setup cost would be lower - the corresponding optimal costs for each source
i = 1, 2 would be
(8.8)
8.6 Summary
Inventory management is one of the oldest and most thoroughly studied areas
of operations research. In this relatively short chapter we covered deterministic
and probabilistic inventory models. These models ranged from the simplest de-
tenninistic demand economic order-quantity model to dynamic inventory mod-
els with random demand. Maple's ability to manipulate expressions symbolically
simplified the analysis of many nontrivial inventory problems such as the optimal
base-stock levels that are obtained by solving a dynamic programming problem.
Maple's numerical analysis facilities also helped in computing the optimal deci-
sions for the exact fonnulation of the continuous-review model with backorders.
Maple's graphics were also useful in visualizing some of the objective functions
including the discontinuous cost function of the quantity discount problem.
8.7 Exercises
1. Consider the basic EOQ model presented in Section 8.4. Now assume that
the demand is an integer quantity; i.e., the units are demanded one at a time
and the time between demands r is deterministic implying that the demand
rate is A = 1/ r. Show that the optimal integer order quantity is the largest
positive integer Q such that
UK
Q(Q-l) < T'
2. In the EOQ models we have discussed, it was implicitly assumed that the
supplier was always available, i.e., we would always receive our order (after
a possibly positive lead-time). In the classical EOQ model now assume that
the supplier is not always available and he can be ON (available) or OFF
(unavailable) for random durations.
(a) Without loss of generality, let the demand rate Abe equal to 1 unit/time.
Let us assume that the exponential random variables X and Y corre-
spond to the lengths of the ON and OFF periods, with parameters a
372 8. Inventory Models
and p, respectively. When an order is placed and the state is ON, an or-
der cost ofSKlorder is incurred. The holding cost is Shlunitltime and
the shortage (backorder) cost is SIr lunit when the state is OFF and the
demand cannot be met. For the sake of generality, also assume that
the time dependent part of the backorder cost is Si lunitltime.
When the inventory level reaches the reorder point r and if the sup-
plier is ON an order for Qunits is placed. This brings the inventory up
to Q+ r. If the supplier is OFF when the inventory reaches r, then the
decision maker has to wait until the supplier becomes available (ON)
before an order can be placed which increases the inventory to Q+ r.
Note that, with Q as the order quantity (which is received immedi-
ately if the state is ON), inventory will reach the reorder point rafter
exactly Q time units since demand rate A = I as we had assumed.
Develop the objective function for this model. Find the optimal solu-
tion for the problem with data given as K = 10, h = 5, 1C = 250,
i = 25, a = 0.25, P = 2.50. Compare the results you would obtain
for the classical EOQ model where the supplier is always available.
HINT: To compute the expected cycle length and expected cycle cost,
condition on the state of the system when inventory reaches the level
r.
(b) For the case of two suppliers suggest ways of dealing with the prob-
lem.
Write down the expressions for expected profit per period. i.e., E(n).
HINT: For given values of U and v, and depending on the values taken by
the random variables X = x, Y = y, one has to consider four different
possibilities.
4. Consider a stochastic inventory system where unit demand for items arrive
in a renewal process at time points To, T\, ... Let Tn - Tn-\ (n = 1,2, ... )
be i.i.d. random variables with mean 1/ A., i.e., the demand rate is A.. Assume
that we use an (s, S) policy, that is, when the inventory level falls to s, we
order S - s units which are received immediately. Order cost is $K per
order and the purchase cost is $c per unit. The inventory holding cost is $h
per unit per time.
Find the best values of s and Q so that the average cost is minimized.
5. Consider the last period of the dynamic inventory problem discussed in
Section 8.5.4. Now assume that the cost of purchasing U units is
( ) _ { K + CU, if U > 0
C U - 0, 1·f U= 0.
Show that the optimal policy is now of the (s, S)-type, i.e., it is given in the
form
S-x, if X < s
Jl(x) = { 0, ifx ~ s.
6. Consider the optimization problem
N-\
min E
Ilk 2:0
L
Ie=O
CUie + h max(O, Xle + Ule - WIe) + p max(O, Wle - Xle - UIe)
where Xle is the inventory at the start of period k, Ule is the order quantity
at the start of period k (lead-time is assumed zero) and Wle is the random
demand with given c.d.f. F(wIe) for k = 0, I, ... , N - I. The parameters
c, h and p are the unit costs of purchase, holding and shortage penalty,
respectively.
(a) Find the optimal solution for this problem with f(w) = F'(w) = 1,
o ~ W ~ 1, C = 1, h = I, P = 2, N = I.
(b) Find the optimal solution for the problem
N-\
min lim E
IIk2:0N-+oo
L
Ie=O
(i[cule + h max(O, Xle + Ule - WIe)
9.1 Introduction
The English poet Milton once wrote, "They also serve who only stand and wait,"
[178, Sonnet 19] but he never elaborated on the average number of people who
would wait and the average time spent waiting for service. Of course, as a poet
he had no interest in such technicalities and even ifhe did, the mathematical tools
available to him and his contemporaries in the 17th century would not have been
of much help in analyzing the queueing processes arising in his day. I
Modern queueing theory had its origins in the early 1900s when the Danish
engineer A. K. Erlang published his seminal work on congestion in telephone
traffic. Since Erlang's time, the number of published (and unpublished) papers
and books on queueing theory has shown a tremendous growth. In 1987, Disney
and Kiessler [62] estimated at least 5000; given the high growth rate we would
estimate the present number around 10,000.
When does a customer requiring service have to "stand and wait"? Queues
form when current demand for a service exceeds the current capacity to provide
the service. As an example let us consider a simple (and naiVe) deterministic
queueing system, e.g., an assembly line operated by a robot. If we assume that
1 Milton, of course, WM not referring to a physical queueing system when he wrote his Sonnet 19
that mentions "[those] ... who ... wail" Instead, he WM comparing angels who serve God and devout
people on earth who wait with patience for the fulfillment of God's purposes. We have included the
reference to Milton since this famous quotation is a favorite of many queueing theorists; see Cox and
Smith [54, p. vii).
the time between arrivals of items requiring processing is, say, a = 3 minutes
and the service (i.e., assembly) time is s = 2 minutes, then there will never be
any queue in this system and for s :::; a, the robot will be idle for (a - s)/a =
I - sla fraction of the time. However, if s > a, then due to demand exceeding
the capacity, arriving items will pile up and the queue size will grow to infinity.2
If the arrival and service processes are stochastic, then even when the average
time s to serve a customer is shorter than the average time ii between the arrivals
of customers, due to the variability in the system, a queue may form. Such con-
gestion phenomena are commonly observed in daily life where customers have to
wait for service at a bank, at a restaurant or at the airport checkout counters or
jobs arriving at a job shop have to wait for processing or telephone calls arriving
at a switchboard may have to wait until the busy signal is cleared.
A shorthand notation has been developed by Kendall [106] to describe a queue-
ing process. The notation involves a series of symbols and slashes such as A I B I X
I YI Z. Here, A indicates the interarrival distribution [e.g., M for Memoryless (or
exponential or Markovian), D for deterministic]; B indicates the service-time dis-
tribution (e.g., G for general, Elc for Erlang with k stages); X indicates the number
of (parallel) servers which could be any integer between I and 00; Y indicates the
system capacity and Z indicates the queue discipline [e.g., first come, first served
(FC FS), priority (P R)). For example, MI MI I 1001 FCFS is the simplest queue-
ing system with exponential interarrival times, exponential service times, with a
single server, no restrictions on the system capacity and a FCFS service disci-
pline. As another example, MI E2/3/151 PR may represent the emergency de-
partment of a hospital with three doctors and a capacity of 15 where the patients'
interarrival times is exponential and they have to go through two stages (Erlang
with k = 2) before service is completed. Normally, if Y = 00 and Z = FCF S,
these symbols are dropped from the notation and only the first three are used.
Thus, M 1MI I would be used to represent the single-server Markovian system
MI MI I 1001 FCFS.
Queueing processes are studied in order to gain an understanding of their oper-
ating characteristics such as the average number of customers in the system or the
average time a customer must spend in the system. Once these descriptive analy-
ses are complete, a normative analysis of the system may also be conducted in or-
der to analyze such questions as "How many servers should be available?" "How
fast should the servers be?" or "How should the system be designedr' Queueing
theory as it has been developed in the last several decades attempts to answer such
questions using detailed mathematical analyses. In this chapter we will provide a
description of some types of queueing models and demonstrate the usefulness of
Maple in solving several queueing problems.
2The reader who is familiar with the I Love Lucy TV shows of the 1950s will recognize dial the
'Chocolate Factory' episode corresponds to the C$e where $ > Q.
9.2 Markovian Queueing Systems 377
3We could also have included the probability of I birth and I death in the time interval At as
p"(t)(1,,6t){Jl,,At). But the result is of the order o(At), and thus it can be safely ignored in the
subsequent development.
378 9. Queueing Systems
gives
A
mml := {O = -(A + Il)p(n) + A p(n - 1) + Il p(n + 1), p(n = 0.. 1) = (_)n PO
Il
)
Solving the system for the unknown Pn gives
> sol:=rsolve(mrnl,p(n));
> p : =unapply(sol,n);
A
P := n ~ (_)n PO
Il
Thus, Pn is obtained as a function of n and the model parameters A and Il and
the (as yet) unknown po. Let us now check the solution for the first few values of
n:
> p(O); p(l); p(2);
9.2 Markovian Queueing Systems 379
po
ApO
J.l
A2 po
7
Before finding the value of the unknown po in tenns of the model parameters,
we develop fonnulas for some of the operating characteristics of the M 1M11
queue, e.g., the expected number of customers in the system, L = L~ npn, and
the expected queue size Lq = L~I (n - 1)Pn. Since the initial state probability
po is not yet computed, the results for L and Lq are obtained in tenns of this
unknown value.
> L:=sum(n*p(n),n=O .• infinity);
Lq:=sum((n-l)*p(n),n=l •. infinity);
L.- po J.l A
.- (-A+J.l)2
POA2
Lq:= (-A + J.l)2
Now, using the fact that L:;O=o p" = 1, we can finally compute the unknown
po as
> p[ 0] :=solve(l=sum(p(n),n=O .• infinity),p[ 0]);
-A + J.l
po := ----''-
J.l
The expressions for Land Lq can now be obtained in tenns of the parameters
Aand J.l.
> L; Lq;
(-A+J.l)J.l
Since the quantity AI J.l appears frequently in many queueing fonnulas, we in-
troduce a new symbol p, which is defined as AI J.l. This dimensionless quantity is
known as the "traffic intensity" or the "utilization factor" of the service facility.4
Note that for the M 1M11 queue, the expected system size L and the expected
queue size Lq are related through the utilization factor p, i.e., L = p + Lq.
4In multiple-server queueing systems the utilization factor is defined as p = J./(cp) where c is the
number of servers present in a service facility and p is the service rate of each server.
380 9. Queueing Systems
Having developed the expressions for the expected number ofcustomers present
in the system and in the queue, we now present the formulas for the distributions
and the means of the waiting time random variables of the M / M / I model.
Let Tq be the random time a customer spends waiting in the queue and Wq{t)
its distribution function. To develop Wq{t), we argue as follows: It is possible that
a customer may not have to wait in the queue at all if the system is empty at the
time of his arrival. Thus, for t = 0,
Wq{O) = Pr{Tq = 0)
= Pr{system empty at time of arrival)
= pO = I-p.
For t > 0, we condition on the number of customers found in the system at the
time of the arrival and write
Wq{t) = Pr{Tq::S t)
=
n=l
customers in system) x Pn + Wq{O)
Since each service time is exponential, the distribution of the completion of n
services is Erlang with n stages. Hence, as pn = (I - p )pn, the distribution
Wq{t) can be written as follows:
Wq{t) = t; [f'10
00
Jl
(Jl~)n-l
_ I;!
-JJX
dx
]
x {I - p)pn + (l - p)
f'
= (1- p)p 10 Jle-JJX t;
00 {JlX P)n-l
(n _ I)! dx + (l - p).
I - p, t = 0
Wq{t) ={ I _ pe-JJ(l-p)t, t > o.
9.2 Markovian Queueing Systems 381
ETq:= 10 00
-tp(-/l+/lp)e(-Pt+ptp)dt
> simplify(value(ETq));
P
/l(-l+p)
Finally, substituting the definition of p = )./ /l, the expected time spent waiting
in the queue is obtained in terms of the model parameters.
> Wq:=normal(subs(rho=lambda/mu,%));
).
Wq := ----:-~
/l (/l - ).)
So far we have found expressions for L, Lq and Wq as the expected number of
customers in the system, the expected number of customers in the queue and the
expected time spent in the queue, respectively. It should now be easy to see that
the expected time spent in the system is W = Wq + 1//l = 1/ (Jl - ).) since Wq
is the expected time spent in the queue and 1/ /l is the expected time spent in the
service. (Recall that the service time distribution was assumed exponential with
parameter /l; hence its mean is 1/ /l.)
By this time the observant reader may have noticed that there is a certain rela-
tionship among the expressions for L, L q , Wq and W. In fact, it turns out that, as
we see in the following Maple output, L =).W (and Lq = ).Wq).
> W:=normal(Wq+l/mu);
1
W:= /l-).
> L:=lambda/(mu-lambda);
Lq:=lambda A 2/(mu* (mu-lambda));
L := /l ~).
).2
Lq'---
.- /l (/l - ).)
> is(L=lambda*W);
382 9. Queueing Systems
true
> is(Lq=larnbda*Wq);
true
This is known as Little's fonnula [125] and it can be shown that the fonnula is
not specific to the M / M /1 queue, but under very mild assumptions, it is true in
general for any queue; see [180] and Wolff [196, p. 236].
MMlcap:= {
A.
0= -(A. + p.) p(n) + A. p(n - I) + p. p(n + I), p(n = 0 .. 1) = (_)n
p.
po}
> sol:=rsolve(MMlcap,p(n));
A.
sol:= (_)n po
p.
> p:=unapply(sol,n);
-A + Jl
.-
pO ' -
A
Jl «_)(K+I) - 1)
Jl
> L:=factor(L);
-A + Jl
It should be noted that since the system capacity is finite (Le., K) and the queue
size cannot grow without bound, the results hold not only for A < Jl but also for
A > Jl. When A = Jl, it is easy to show that pn = I/(K + I), n = 0, ... , K and
L =!K.
AOpO
JlI
> eq[ 1] : =- (lambda{ 1] +mu{ 1] ) * p[ 1] +mu{ 2] * p[ 2]
+ lambda{ 0] * p[ 0] ;
384 9. Queueing Systems
eql := -
0·1 + JlI) AO pO + Jl2 P2 + AO pO
JlI
> assign (sol ve ({ eq[ 1) } ,( p( 2) } ) ) ;
> p( 2) ;
AOpOAI
JlIJl2
> eq[ 2) : =- (lambda[ 2) +mu( 2) ) * p( 2) +mu( 3) * p( 3)
+ lambda[ 1) * p( 1) ;
eq2 := -
(A2 + Jl2) AO pO AI + Jl3 P3 + .-;....::....;;.....;.
AO pO AI
JlIJl2 JlI
> assign (solve ({ eq[ 2) } ,( p( 3) } ) ) ;
> p( 3) ;
AOpOAI 12
JlIJl2Jl3
For the first few values of n, there does appear to be a structure to the solution
of this system. Next. we automate this solution procedure to compute the p" for
higher values of n.
> for n from 3 to 10 do
> eel n) :=- (lambda[ n) +mu( n) )*p( n) +mu( n+1) *p( n+1)
+lambda[ n-1) *p( n-1) ;
> assign (solve ({ eq[ n)} ,( p( n+1)} »;
> p( n) ;
> od:
> p( 2); p( 3); p( 4); p( 5); p( 6) ;
10pOAI
JlIJl2
10pOl112
JlIJl2Jl3
10pOl112 1 3
JlIJl2Jl3Jl4
10 pO 1112 1 3 1 4
Jl I Jl2 Jl3 Jl4 Jls
AOpOAI A2 A3 A4 AS
JlIJl2Jl3Jl4JlSJl6
9.2 Markovian Queueing Systems 385
Again, we note that the interesting pattern that has emerged so far suggests that
the probabilities p,. are in the fonn
P,.=PO n,.
;=1
,.1.;_1
-.-,
p,
n ~ I. (9.7)
Naturally, this result must be proved using mathematical induction (for which
we refer the reader to Gross and Harris [76, p. 85]). Since L~ I p,. = I, i.e.,
np, n = I, ... , c
Pn = { cp, n = c, c + I , ....
Using An and Pn in (9.7), one obtains [76, p. 86] the following expressions as the
solution for Pn.
~={
n=I, ... ,c
n=c,c+I, ....
(9.8)
thus completing the analysis of the steady-state probabilities of the M 1MI c model. S
We now compute the expected queue length Lq = L~=c(n - c)Pn using
Maple's sum () function.
Sit should be noted here that the condition for the existerK:e of PO is p = A./(cp) < I, implying
that the mean arrival rate A. must be less than the maximum potential service rate cp o
386 9. Queueing Systems
> evalf(Lq);
.03980099502
> L:=evalf(Lq+lambda/mu);
L := 2.039800995
> W:=evalf(L/larnbda);
VV:=.5099502488
To solve this system, we introduce the generating ftmction G(z) = ~=O pnzn.
Multiplying (9.9) by zn for n = 1,2 ... , adding the result to (9.10) and simplify-
ing (see, [129, p. 3] and [130, p. 182]) we obtain
We now apply these results to a specific model where it is assumed that the
random variable X has the truncated geometric density, i.e., Ok =
Pr(X =
k) =
c(l - c)k-l, 0 < c < I, k = 1,2, ....
> restart: # bulkgeom.mws
We define the density of X and check that the probabilities add up to unity.
> pdfX:=c* (l-c)A(n-I);
pdjX:= c (l - c)(n-l)
> sum(pdfX,n=I .. infinity);
The next three commands define the generating function A(z) of X, compute the
mean of X using the property that E (X) = L~ 1 kOk = A' (z) 1== \' and write the
generating function G(z) of the steady-state probabilities Pn.
> A:=sum(pdfX*zAn,n=I .. infinity);
cz
A·-----
.- -z+zc+ 1
> EX:=normal(subs(z=l,diff(A,z)));
1
EX:=-
c
> G:=mu*p[ 0] * (I-z) / (mu* (I-z) -lambda* z* (I-A));
G ._ p pO (l - z)
.- cz
p(l-z)-lz(l- )
-z+zc+ 1
Since G(z) is given in terms of the unknown po, we find this value using the
property that po = lim G(z).
=~l
> pO:=limit(G,z=I);
cpop
pO:=
-pc+l
> p[ 0] :=normal (solve (l=pO,p[ 0] ));
-pc+l
po .-
.-
cp
Once po is found, the traffic intensity p can be computed as
> rho:=lambda/(c*mu);
1
p:=-
pc
In order to invert the resulting generating functions we load the genfunc li-
brary and display G(z), which no longer depends on the probability po.
> with(genfunc);
9.3 Transient Solutions 389
).(-pc+).)(p - PC+).)n
pn:=-------------~p-----
c (p - p c +).) p
As a check of the results found, the next command adds all the probabilities and
finds that they sum to one, i.e., 1:~ Pn = I.
> norrnal(R 0] +surn(pn,n=l .. infinity));
The expected number of customers in this bulk queueing system, L, can now
be easily computed using the property that L = E(customers in system) =
1::'1 nPn = G'(z)I==I·
> L:=lirnit(diff(G,z),z=l);
).
L .-
·-
(-pc+).)c
(i.e., the rate at which the process departs state 0) and P is the service rate of the
server (i.e., the rate at which the process departs state 1), then 1I A is the average
time the machine is in operation and 1I P is the average time it takes to repair
the machine. Using the steps for developing differential equations for birth-death
processes, it is easy to show that we have two differential equations representing
the evolution of the transient probabilities for the finite capacity M1M11 I K queue
with K = 1.
> assign(sol);
> p{ 0] :=unapply(simplify(pO(t)) ,t);
p{ 1] : =unapply (simplify (pI (t) ) , t) ;
P + Ae(-().+P)t)
pO := t -+ ~-:----
A+P
A (-1 + e(-().+p) t»
PI := t-+
A+P
The last line of the Maple output gives the transient solution for the M1M11/1
system. To find the steady-state solution, we let t -+ 00 and obtain the steady-
state probabilities as pO = pl(A + p) and PI = AI(A + p).
> assume (larnbda>O, mu>O); interface(showassumed=2);
9.3 Transient Solutions 391
Jl
1+Jl
with assumptions on Jl and 1
1
1+Jl
with assumptions on 1 and Jl
To solve these equations, we make use of the generating function of the tran-
sient probabilities defined by
00
G(z, I) = LPn(I)?
n=O
Multiplying both sides of (9.11) by z", summing from 1 to 00 and adding the
equation in (9.12) gives
00 00 00 00
Since L:'.
Pn(l)nz"-1 = fJG(z, 1)/fJz and L:;O=o p~(I)z" = oG(z, 1)/01, these
equations can be rewritten as a partial differential equation (PDE) in terms of the
unknown generating function G(z, I); see Gross and Harris [76, Section 2.10.3]:
The next four Maple statements use this infonnation and detennine the fonn of
the unknown function.
First, we give a name to the tenn inside _Fl.
> inside:=(t*mu-ln(-l+z))/mu;
"de Ip-ln(-I+z)
Insl := ......:....----=---...:...
p
At 1 = 0, this tenn takes the value
> subs(t=O,inside);
In(-I +z)
p
which, when equated to, say, y and solved for z gives
> solve(%=y,z);
e(-YIl) +1
Substituting the expression for z into inside, we obtain the functional fonn of
FI:
> fl:=y->exp(-lambda* (exp(-y*mu)+l)/mu);
_1 (e(-Y P)+I))
(
fJ :=y ~ e I'
i.e.,
_FI(y) = exp ( A.exP(-;p) + I).
Now that the fonn of the unknown function _ F I is detennined, we can explic-
itly compute the generating function G(z, I) as follows.
> fl(inside)*exp(lambda/mu*z);
l(e(-II'+ln<-I+:»+I)) 1:
(
e I' e(p)
. (A(-I+=><;<-I/ll_11)
G(Z, t).= e
With the explicit fonn of the generating function available, the transient proba-
bilities (p,,(t)} can be obtained by expanding G(z, t) in a power series L~=oa"z"
where, of course, the a" coefficients are the required transient probabilities p,,(t)
since the generating function was defined as G(z, t) = L~=O p,,(t)z".
Using the Maclaurin series, i.e.,
the first few coefficients are computed with Maple's help as follows.
> a[ 0] :=(1/0!)*subs(z=0,G(z,t));
( A<e<-I/ll-n)
ao :=e /I
> a[ 1] :=(l/1!)*subs(z=O,diff(G(z,t),z$l));
a[ ~=(1/2!)*subs(z=0,diff(G(z,t),z$2));
a[ 3]=(1/3!)*subs(z=0,diff(G(z,t),z$3));
(
A lel-I/ll-n)
l (e(-t II) - 1) e /I
a) :=
Jl
1
p,,(t) = n! [l;(1 - J" [l
-;(1 -
e-Il t ) exp e-lit ),
] n ~ O.
6An example of such a system is a car wash with two stages-in the first stage the car is washed,
and in the second stage it is vacuumed. This was first discussed in Example 91 of Chapter 7, Stochastic
Processes.
9.4 Queueing Networks 395
deo, I := §; pO, I (I) = -(A + 1l2) pO, I (I) + III PI, 0(1) + 112 Pb, I (I)
> de[ 1,1] :=diff(P[ 1,1] (t),t)=
- (rnu( 1] +rnu( 2] ) * p[ 1, 1] (t)
+lambda*p[ 0,1] (t);
0.8
0.6
0.4
0.2
o 2 3 4
FIGURE 9.1. Transient solution for the empty system and blocked system probabilities
= I and Pbl (0) = O.
POO(I) and Pbl (I), respectively, with POO(O)
2 P,;'
4 P, ;. + 2 p,2 + 3;.2
;.2
The first step in analyzing a Jackson network is the computation of the total
input rate A; into node i. Before their final departure, the customers may be cycled
between different nodes within the network as a result of, say, rework of an item in
a manufacturing process. Hence, the total input rate into node i may be different
from the arrival rate from outside into node i. Thus, we have
A; = y; + "'2::/jPji
j
since y; is the arrival rate to node i from outside the network and Pj; is the
probability that the customer leaving node j enters node i . (If node i has C; servers
and if p; = A;/(C;jJ.;) < I for all nodes, then Jackson has shown that node i can
be treated as a multiple server Mj Mjc; system [98J.)
This system may be rewritten in vector/matrix form as .oX = 'Y + .oXP and when
solved for .oX gives
0 PI.2 PI.3]
PMatrix:= [ Pl. I 0 Pl. 3
Pl. I P3.2 0
> IdentityMatrix:= array(identity, 1 .. 3,1 •. 3);
IdentityMatrix := array (identity, 1.. 3, 1.. 3, m
400 9. Queueing Systems
> IminusP:=evalm(IdentityMatrix-PMatrix);
IminusP := [ -~. I I
-PI.2
-Pl. 3
-PI.3]
-P3. 1 -PJ.2 I
> IminusPinv:=inverse(IminusP);
IminusPinv :=
-I +%3 PI.2 + P1,3 P3.2 PI.2 Pl. 3 + PI.3
0/04 0/04 0/04
Pl. I + Pl. 3 P3. 1 -I +%1 Pl. 3 + PI . 3 Pl. I
0/04 0/04 0/04
Pl. I P3.2 + P3.1 P3.2 + P1.2 P3. I -I +%2
0/04 0/04 0/04
%1 := P3.1 PI . 3
%2:= Pl. I PI . 2
%3 := Pl. 3 P3.2
0/04 := -I +%3 +%2 + Pl,I P1,3 P3,2 + P3.1 PI,2 Pl,3 +%1
The total input rate vector ~ is found as follows:
> lambdaVector:=evalm(gammaVector&*IminusPinv);
lambdaVector:= [
)/ I (-I + %3) )/2 (Pl,1 + Pl,3 P3,1) )/3 (Pl. I P3, 2 + PJ.I)
0/04 0/04 0/04
_)/1 (PI,2+PI,3P3 , 2) + )/2(-1 +%1) _ )/3(P3,2+PI.2P3.1)
0/04 0/04 0/04
_)/dPI.2Pl.3+PI,3) _ )/2(Pl.3+PI,3Pl, I) + )/3(-1+%2)]
0/04 0/04 0/04
%1 := P3.1 PI.3
%2:= Pl. I PI,2
%3 := Pl. 3 P3.2
0/04 := -I + %3 + %2 + Pl. I PI. 3 P3,2 + P3. I PI. 2 Pl. 3 + % I
As an example, let us now compute numerically the value of ~ assuming that
"y = (4,2, I) and
0 0 5. 5 0.25]
P = [ 0.3 0 0.65.
0.05 0.1 0
Substituting these values into the formulas for ~ we developed, Maple gives
9.5 Optimization of Queueing Systems 401
i.e., AI = 6.126, A2 = 6.013 and A3 = 6.440. These values can now be used
in conjunction with the service rate values Pi to compute the traffic intensities
Pi = A;/(CiPi)·
Assuming that (PbP2, P3) = (10,4,12) and (CI,C2,C3) = (1,2,1), we ob-
tainpl = 0.6126, P2 = 0.751 and P3 = 0.5366. Using these values, the expected
number of customers in the network can be computed as a sum of the individual
Li values for each node. Since the first and third nodes are M / M /1 and the second
node is an M/M/2queue, it can be shown that (LI, L2, L3~ = (1.58,3.45,1.15);
thus the expected number of customers in the system is Li=1 Li = 6.18.
> sol:=solve(%,mu);
For the general Q(/) process Bhat identifies the renewal periods, and using
renewal arguments he finds that the limiting expected number of taxis waiting is
where Q = lim Q(/),,t is the rate of taxi arrivals and V is the interarrival time
t~oo
3
to= w+2' o <k:::::w-1.
The following Maple commands compute the expected number of lost cus-
tomers in a renewal period (ELos t). Using the expression for the expected num-
ber of taxis waiting (ETaxis) with CI as the cost of making a taxi wait and C2
as the cost of losing a customer, the total cost C to the system is obtained and
optimized to find the optimal value of w:
> restart: # bhat.mws
> Sum(k/(w+2),k=1 •. w-l);
w-I k
~w+2
> ELost:=normal(value(%»;
E'Lo ._.!. w(w - I)
'SI.- 2 w +2
> ETaxis:=3/(w+2)+lambda A 2*EV2
/ (2*rho* (I-rho»;
I 1,t2 EV2
ETaxi'S := 3 w + 2 + 2 p (I _ p)
> C:=c[ 1] *ETaxis+c[ 2] *ELost;
Thus, the optimal solution is w· = J6(I + CI/C2) - 2. Here we note that as the
cost oflosing a customer approaches infinity (C2 ~ 00), then w· is obtained as a
value close to zero, as expected:
> evalf (limit (wOpt, c{ 2] =infinity) ) ;
.449489743
A _( A forn<k (9.13)
n- A/2 for n 2! k .
Using the results presented for the steady-state solution of the birth-death pro-
cesses in Section 9.2.4 with c = I, An as in (9.13) and Pn = P for all n and
assuming that p = A/(2p) < I, we obtain the steady-state probabilities Pn as
Here, (} = Jl(1 - pO) is the steady-state processing rate that is equal to the rate at
which customers depart the system and
L = ~np.=p<>[~n(2p)'+2'~np.]
*-1 2* *-1]
= pO [ Ln(2p)n + (1 _ )2 - 2* Lnpn
n=O p p n=O
is the average number of customers in the system which, according to Pliska, "is
not a pretty expression but is straightforward to compute."
Since f is not known to be necessarily concave with respect to k, Pliska sug-
gests an exhaustive search procedure to find the optimal value of k. The develop-
ment of the model and the solution of an example with A. = 16, Jl = 14, r = 10,
e = 3 using an exhaustive search is presented in the following Maple worksheet.
> restart: # pliska.rnws
> p{ 0] :=1/(' sum' ((2*rho)"n,n=0 •. k-l)
+(2*rho)"k/(l-rho))i
*
pO:=
n=O
(i: 1
(2p)n) + (2p)*
1- p
> L:='p{ 0]'* (' sum' (n* (2*rho)"n,n=0 •• k-l)
+2"k*rho/(l-rho)"2
-2"k*' sum' (n*rho"n,n=O .• k-l)) i
*-1 2* *-1
L :=pO«Ln(2p)n)+ (1_~)2 -2* (Lnpn»
n=O n=O
> theta:=rnu*' (l-P{ 0] )' i
(} := Jl (1 - pO)
> f: =' r* theta -c* L' i
f :=r(} -e L
> larnbda:=l6i rnu:=l4i r:=lOi
C:=3i rho:=(larnbda/2)/rnui
A. := 16
Jl := 14
r:= 10
e :=3
4
p '--
'-7
> Digits:=6i
Digits:= 6
406 9. Queueing Systems
by Koopman [113] and scheduling police patrol cars in New York City by Kolesar
et al. [112]. As described in Gross and Harris [76], the state probabilities for this
system are obtained from the Kolmogorov equations (9.1 }-{9.2) of the birth-death
processes as follows: For n = 0,
for n = 1, ... , S - 1,
For this system, the initial condition is 'L:=o Xn (0) = 1. Also, since Xn (I) are
probabilities, we also have the point constraints 'L:=oXn(l) = 1, xn(l) ~ 0, n =
°
0, ... , N for all 1 E [0, T]. However, if U(I) ~ then the point constraints are sat-
isfied automatically; see Klein and Gruver [109]. Defining P'(I) = [Xo(I), ... ,
Xn(I)] where prime denotes transposition, we can write the system more com-
pactly as P(I) = u(I)F P(I) + A, (I)G P(I) with the constant matrices F and G
having dimension (N + 1) x (N + 1). (For details, see Parlar (141).)
A performance criterion incorporating the cost of waiting customers (for exam-
ple, fires burning in Bookbinder and Martell's forestry model or aircraft awaiting
landing clearance in Koopman's model) and the cost of service rate over [0, T]
seems to be a reasonable objective for M(I)/M(I)/S/N queues. Since the state
variable xn(t) is the probability of n customers in the system at time I, and since
the system capacity is N units, the expected number of customers L(I) at time 1
is
N
L(I) = LnXn(l) = C' P(I)
n=O
where C' = (0, 1, 2, ... ,N). We now introduce a service rate cost function
q[u(I)] and add a desired (target) expected queue size at the final time T and pe-
nalize deviations from this level. Thus, the objective functional to be minimized
with a proper choice of U(I) is
°
cost of deviating from desired k. Although each state variable xn(l) is restricted
to take values between and 1, it is not necessary to introduce these constraints
408 9. Queueing Systems
explicitly into our fonnulation since they will be automatically satisfied-as ex-
plained above-if u(t) ~ 0, for t e [0, T). Since it may be physically impossible
u
to exceed some upper bound on the control, this implies that we must add to
the fonnulation constraints on the control function in the fonn 0 ::: u(t) ::: u,
t e [0, T]. Now the optimal control problem is given as
subject to
Pet) = u(t)F pet) + ).(t)G pet)
e' P(O) = I, e' = (I, I, ... , I)
o ::: U(I) ::: u.
Introducing a new (N + 2)nd state variable XN+l as XN+l (t) J~[C' per) + =
dr so that XN+l (t) = C' pet) + O"(u) and XN+l (0) = 0, the problem can
0" (u)]
be refonnulated in Mayer fonn [162, p. 28] as follows:
min J
U(I)
= !b[C' peT) - k]2 + XN+l (T)
subject to
= u(I)F pet) + ).(I)G pet), e' P(O) = I
P(I)
XN+l (I) = C' P(I) + 0" (u), XN+l (0) = 0
o ::: u(t) ::: U.
Using Pontryagin's maximum principle [169], it can be shown that [141] to find
the optimal service rate u(t) in an M(I)/M(I)/S/N queue one has to solve the
two-point boundary-value problem (TPBVP) given by the following differential
and algebraic equations:
I
X2(/) = XI (I) + !a[U(/)]2, X2(0) =0
0, if WI (/)XI (I)/a < 0
U(/) = WI (t)XI (t)/a, if 0 :s WI (t)XI (t)/a :s 1
1, if WI (t)XI (t)/a > 1.
For the time-dependent arrival rate we choose ).(t) = 20t 2(1 - t)3. Note that as
t ~ 0 or t ~ 1 the arrival rate approaches zero. The values of other parameters
are given as a = 0.4, b = 2.5, k = 0.1, T = 1, Xl (0) = 0.8 and X2(0) = 0.0.
We now solve this TPBVP numerically using Maple's piecewise () func-
tion and its knowledge of numerical solution of differential equations.
> restart: # mmsncont.rnws
We first define u(t) as a piecewise function in terms of the unknown functions
and Xl (t):
WI (t)
> u: =unapply (piecewise (w{ 1] (t) * x[ 1] (t) / a<O,
O,w{ 1] (t)*x[ 1] (t)/a>=O and w{ 1] (t)*x[ 1] (t)/a<=l,
w{ 1] (t) * x[ 1] (t) / a, w{ 1] (t) * x[ 1] (t) / a> 1, 1) , t) ;
state[ 2] ;
-I; XI (I) = l(l) (I - XI (I» - 0/02 XI (I), -I; X2(1) = XI (I) + 2"1 a 0/022
%1 := WI(I)XI(I)
a
o %1<0
0/02:= { %1-%1:5 0 and %1 - 1 :5 0
1 1 < %1
> funes:={ wi: 1] (t) I x[ 1] (t) I x[ 2] (t)} ;
Junes := (X2(1), WI (I), XI (I)}
Our TPBVP where WI (T) = b[xl (T) - kJ is nonnally solved using the "initial
value shooting method," which starts with a guess for the value of WI (0), say
WIO. With this method, using the initial conditions WI (0) = WIO, XI (0) = 0.8 and
X2(0) = 0, the differential equation system is solved numerically. (Maple con-
veniently incorporates the piecewise algebraic relation for U(I) in the numerical
solution of the system.) If at T we observe that WI (T) = b[xl (T) - k J, then the
solution of the TPBVP has been found; otherwise the initial guess is modified
and the system is re-solved. For a detailed description of shooting methods see
Roberts and Shipman [155J. Sethi and Thompson [169, Ch. IIJ provide a sum-
mary description of the initial value shooting method for problems that require
guessing for a single state variable (which is the case in this example).
In our problem, we manually implemented the initial value shooting method
and found the value of WI (0) as .7475 for which the final time difference is
WI(T) - b[xl(T) - kJ = .00074165-an acceptable error. With the definition
of l(I), the system is solved numerically using the output=listproeedure
option so that the resulting numerical trajectory can be used in plotting the re-
quired graphs.
> init : =w[ 1] (0) =. 7475 I x[ 1] (0) = . 8 I
x[ 2] (0) =0;
inil := WI (0) = .7475, XI (0) = .8, X2(0) = 0
> lambda:=t->20*t"2* (1-t)"3;
a:=.4; b:=2.5; k:=.1; T:=1;
9.5 Optimization of Queueing Systems 411
A. := 1-4201 2 (I - 1)3
a:= .4
b:= 2.5
k:= .1
T:= I
> Sol:=dsolve({desystern,init} ,funes,
type=nurnerie,output=listproeedure);
0.8
0.6
0.4
0.2
FIGURE 9.2. Optimal trajectories of WI (I) and X2(t) for 1 e [0, IJ with WI (0) = 0.7475
and X2 (0) = o.
412 9. Queueing Systems
FIGURE 9.3. Optimal trajectories of U(/), XO(/) and XI (I) for 1 E [0, I] with u(O) = I,
xo(O) = 0.2 and XI (0) = 0.8.
Finally, since J = !b[xl (T) - k]2 +x2(T), this value of the objective functional
is computed as follows:
> J:=(1/2)*b* (xSol[ 1) (T)-k) "2+xSol[ 2) (T);
J := .8562668471
8For details of an alternative solution method for this control problem, the "Newton-Raphson
boundary condition iteration,» see Parlar [141].
9.6 Summary 413
9.6 Summary
The main goal of this chapter was to present a survey of Markovian queueing
systems.9 The limiting distribution and the related operating characteristics of
different types of Markovian queues were discussed. Using Maple's ordinary and
partial differential equation solvers [i.e., dsol ve () and pdsol ve ( )] we were
able to find the transient solutions for a finite capacity queue and for the am-
ple server queue. Next, a serial queue and Jackson networks were analyzed. The
chapter ended with a detailed discussion of optimization of some types of queue-
ing systems. In particular, Maple's ability to solve differential equations defined
by piecewise functions was helpful in determining the optimal control (i.e., ser-
vice rate) trajectory in a time-dependent queueing system.
9.7 Exercises
I. Yule process is a pure birth process with state-dependent birth rate An = nA,
n = 0, I, .... This process represents the growth of a population where each
member gives birth at an exponential rate A. Let X(t) denote the population
size at time t and assume that the population starts with a single member,
i.e., X(O) = I. Find the transient solution Pn(t) = Pr[X(t) = n] for this
process.
2. Consider a queueing system where both arrival and service rates are state
dependent. Assume that the arrival rate An decreases and service rate Jl.n
increases as the number n in the system increases, i.e.,
An = { (N - n)A, n:::: N
0, n> N,
_ (n p , n:::: N
Pn - 0, n> N.
What are the differential equations for the probability Pn(t) = Pr(n in the
system at time t)?
3. Consider a Markovian queue with two servers where the arrival and service
rates are given as
An = A, n ~ 0
= (p, n=1
Jl.n 2p, n ~ 2.
where p = AI J.l. Note that Pc(P) is a ftmction of both the traffic intensity p
and the number of servers c.
5. The transient solution Pn(t), t ::: 0, n = 1,2, . .. for the MI Mil queue
with an initially empty system is given as
where In(x) is the modified Bessel ftmction of the first kind, p = AI J.l and
HINT: In Maple the modified Bessel ftmction of the first kind is represented
by Bessell.
6. Let Wn, n ::: I be the waiting time of the nth customer in a GIGII queue.
Show that Wn+1 = max(O, Wn + Vn - Un) where Vn is the service time
of the nth customer and Un is the interarrival time between the nth and
(n + I)st customer.
7. Consider a closed queueing network with three nodes and two customers.
Assume that a customer chooses the next node which has the fewest num-
ber of customers and ties are broken by flipping an unbiased coin. Departure
rate from node j is J.l j' j = I, 2, 3. The state space of the stochastic process
representing this queue can be described by a vector with three components
(nl, n2, n3). Write down the infinitesimal generator for this stochastic pro-
cess and compute the steady state probabilities.
8. Consider the MI Mlclc model presented in Exercise 4. Since Pc(P) is the
probability that an arriving customer is lost to the system, the effective ar-
rival rate is Aetf = [I - Pc(P»)A. If each arriving customer generates an
average ofr dollars of profit and each server costs kJ.l dollars per hour, the
average profit rate can be written as A = r..tetf - ckJ.l. Let p = 1 (i.e.,
9.7 Exercises 415
10.1 Introduction
Simulation I is a computer-based probabilistic modeling tool that is used to imitate
the behavior of an existing or a proposed system. If an existing system such as a
bank branch is experiencing long queues and long customer waiting times, the
manager of the branch may use simulation to examine different alternatives for
improving service without actually making any physical changes in the system.
For example, the effect of increasing the number of available tellers and/or
changing the queue design (e.g., combining parallel queues into a single queue) on
the average queue length and the average waiting times can be examined without
physically altering the system. Behavior of the proposed system can be observed
by running computer simulations of different alternatives over time and measuring
the operating characteristics of the system.
Of course, in some cases the system under study may be simple enough so
that the queueing models that were presented in Chapter 9 may be used to model
it. But, if the random variables representing the arrival and/or service processes
are not exponential (thus making the system non-Markovian) and if the proposed
design is complex (e.g., the bank branch may be a complicated queueing network)
none of the available queueing models may be useful in modeling the problem.
In those cases, simulation becomes a necessity in order to model and analyze the
system.
I "Simulation" is derived from the Latin word simulare which means "10 copy, imitate or represent."
Along with linear programming and statistical methods, simulation has become
one of the most important operations research techniques used to solve practical
problems.2 There are now several very powerful and flexible simulation software
programs-such as Arena [104] and Visual SLAM [I 53]-that simplifY the mod-
eling and simulation of almost any real-life system that exhibits probabilistic be-
havior.
The most basic computational ingredient in simulation involves the generation
of random variables distributed uniformly between 0 and I. These are then used
to generate other random variables-such as the Weibull or Erlang random vari-
ables that may represent a teller's service time-and the simulation is run long
enough to obtain an estimate of the operating characteristics of the system, e.g.,
average waiting time of customers and the percentage of time the fucility is idle.
Since the result of each run is a random sample, a simulation study is a statistical
experiment that must be conducted using statistical tools such as point estimation,
confidence intervals, hypothesis testing. For a discussion of these important sta-
tistical issues, the reader should consult specialized simulation textbooks such as
Law and Kelton [118, Chs. 8-9] and Banks, Carson and Nelson [12, Ch. 12].
Clearly, Maple is not designed to be used as a full-fledged simulation language.
However, Maple's ability to generate random variates from nearly 20 continuous
and discrete random variables (such as the exponential, gamma, Weibull, normal,
binomial and Poisson) makes it a useful teaching tool for presenting many inter-
esting simulation examples.
2See the paper by Lane, Mansour and Harpell [116] that describes the results of a survey of ed-
ucators and practitioners who teach and use operations research techniques. The survey found that
the three techniques mentioned in this paragraph were consistently rated by the OR educators and
practitioners as the most important
10.1 Introduction 419
In this case, it is not too difficult to see that if we define X t as the total number
of delayed tankers at the beginning of day t, then we can write
3 Actually, it is also possible to model this problem as a discrete-time Matkov chain. Once the tran-
sition probability matrix of the chain is identified, the steady-state distribution of XI can be computed
numerically.
420 10. Simulation
could first compute the cumulative distribution function P(k) = L:=O p(i) of X
as given in the following table.
k 0 2 3 4 5
p(k) 1.00243 .02835 .1323 .3087 .3603 .1681
P(k) .00243 .03078 .1631 .4718 .8319 1.0
> od:
> seq([ t,l x[ t) ,a[ t)) ,l x[ t+1))) ,t=1. .T);
4There are more efficient methods for generating binomial random variates; see, for example, Ross
[160, pp. SO-51).
10.1 Introduction 421
[1, [2, 3.0], [1.0)), [2, [1.0, 3.0], [0)), [3, [0, 4.0], [0)), [4, [0, 4.0], [0)),
[5, [0, 4.0], [0)), [6, [0, 2.0], [0)), [7, [0, 4.0], [0)), [8, [0, 4.0], [0)),
[9, [0, 4.0], [0]], [10, [0, 3.0], [0)), [II, [0, 3.0], [0)),
[12, [0, 4.0], [0)), [13, [0, 2.0], [0)), [14, [0, 2.0], [0]],
[15, [0, 5.0], [1.0)), [16, [l.0, 4.0], [1.0)), [17, [1.0,3.0], [0)),
[18, [0, 4.0], [0)), [19, [0, 5.0], [1.0)), [20, [1.0, 5.0], [2.0)),
[21, [2.0,2.0], [0)), [22, [0, 2.0], [0)), [23, [0, 3.0], [0)),
[24, [0, 4.0], [0]], [25, [0, 3.0], [0))
The simulated number of delayed tankers for T days is as follows.
> Delayed:={ seq(x[ t] ,t=1..T)];
FIGURE 10.1. Distribution of delayed tankers obtained by simulating the process for a run
length of T = 25 days.
Here, X is the sample mean obtained from an initial sample of, say, Ro runs and
h is the half-width of the desired confidence interval
h _ Za/2 S (10.1)
- ,JR'
In equation (10.1), s is the sample standard deviation obtained from the initial
runs and (for a large R) Za/2 is the Z-score, which bounds a right tail equal to
a /2. If we want to choose R such that h :s t5, then
R ~ ea~2S)2 (10.2)
We choose ~ = 0.01, a = 0.05 and find that z = 1.9599. The sample standard
deviation is s = 0.0495. Using (10.2) gives R ~ 94 runs.
> delta:=.Ol;
.01 ~:=
> s:=describe[ standarddeviation] (Means);
s := .04954432359
> alpha:=.05;
a:= .05
> z:=stateval~ icdf,normal~ (1-alpha/2);
z := 1.959963985
> R:=(s*z/delta)A2;
R := 94.29398485
For a careful discussion of determining the number of runs, see Banks, Carson
and Nelson [12, Sec. 12.4] and Law and Kelton [118, Chapter 8].
We continue this chapter with a discussion of the techniques for generating
(pseudo-) random numbers and the "quality" of Maple's unifonn random number
generator. This is followed by some examples of sIalic Monte Carlo simulation
where time plays no role. The chapter ends with examples of dynamic simulation
models that represent systems evolving over time (such as the port operations in
Example 97).
f(u) = { I, O::s U ~ I
0, Otherwise.
It is easy to show that this r.v. has mean £(U) = !, second moment £(U 2) = l,
!
third moment £(U 3 ) = and variance Var(U) = -b.
> restart: # Uniform.mws
> f:=u->l;
f:= I
> EU:=int(u*f(u),u=O .. l);
I
£U:=-
2
424 10. Simulation
ZI = (5 x 4 + 1) mod 16
= 21 mod 16
= 5
and
Z2 = (5 x 5 + 1) mod 16
= 26 mod 16
= 10,
etc. Since each Zn value is an element of the set to, 1, ... , m - I}, the (n + I)st
random number rn+1 that is in the interval [0, I) is computed as rn+1 = Zn+l/m,
n = 0,1, ... For example, using the above data, we would find rl = zl/m =
5/16 = .313 and~ = Z2/m = 10/16 = .625.
10.2 Generating (Pseudo-) Random Numbers 425
Such methods produce random numbers that always start cycling after some
finite number p (called the period of the generator) not exceeding m. Since the
selection of the parameters zo, a, b and m affects the cycle length, it is important
to choose these parameters carefully in designing random number generators.
[1, .313], [2, .625], [3, .188], [4,0], [5, .0625], [6, .375], [7, .938],
[8, .750], [9, .813], [10, .125], [11, .688], [12, .500], [13, .563],
[14, .875], [15, .438], [16, .250], [17, .313], [18, .625], [19, .188],
[20, 0], [21, .0625], [22, .375], [23, .938], [24, .750], [25, .813]
It has been shown by Fishman [66] that when c t- 0, for a B-bit word computer
the maximal (full) period of Pmax = m = 2 8 can be achieved provided that b is
relatively prime to m (in other words, I is the only positive integer that exactly
divides both b and m) and a = I + 4k where k is an integer. When c = 0, for a
32-bit word computer a satisfactory choice for the modulus and the multiplier are
m = 231 - I and a = 75 . These values have been tested and used extensively;
see, Banks, Carson and Nelson [12, p. 295].
426 10. Simulation
We start by ranking the observations UI, U2, .. " UN in increasing order, i.e.,
U[I], U[2], .. . , UrN] where Uri] ~ U[i+I]. The test statistic dmax measures the
deviation of the random numbers from the theoretical distribution and it is defined
as
dmax = max(tti" , a)
where
d+ = max
19~N
(.!....
N
- Uri]) and a = max (U[i] _
l~i~N
i-I).
N
Note that i / N - Uri] is the deviation of Ge(u) above F(i / N) = i / N and Uri] -
(i - 1)/ N is the deviation of Ge(u) below F ((i - 1)/N) = (i - 1)/N. Thus,
d+ and d- correspond to the largest deviation of Ge(u) above and below F(u),
10.2 Generating (Pseudo-) Random Numbers 427
.....
0.8
0.6
FIGURE 10.2. Comparison of the empirical distribution Ge(u) drawn as a solid curve and
the theoretical unifonn distribution F(u) drawn as a dotted line.
Consider a random variable X with density f(x) and distribution F(x). If the
inverse F-I of the distribution function can be easily computed, then the inverse
transform method can be used to generate a random variate from the distribution
of X. This is done by setting F(X) = U where U is a uniform number and solving
for X = F-1(U).
f:= x ~ A.ehh )
> F:=x->int(f(t),t=O .. x);
After inverting the distribution (i.e., solving F(X) = U for X), we find that
X = -log(1 - U)/ A.. Letting A. = 3 and generating uniform random numbers,
we can now sample from the exponential distribution.
> X:=unapply(solve(F(X)=U,X),U);
X := U ~ _ In(1 - U)
A.
> larnbda:=3;
A. := 3
> X(.3562);
.1467890534
> with(stats);
[anova, describe, fit, importdata, random, stateva/f, statplots, transform]
Maple's randorr( uniform] (10) command generates 10 uniform random
numbers. After mapping X to them, we obtain 10 samples from the exponential
distribution.
> U:={ randorr( uniform] (10)] ;
430 10. Simulation
Example 101 Random variates from some distributions. The next set of com-
mands generates random variates from beta, exponential, gamma, nonnal, uni-
fonn and Weibull continuous distributions.
> restart: # MapleRandornVariates.rnws
> with(stats); #with(randorn); nops(with(randorn));
[anova, describe, fit, importdata, random, statevaJf, statp/ots, transform]
> randorr( beta[ 1,2]] (5);
.1586913674, .4696943744, .01327905798, .4781283152, .04138715231
> randorr( exponential[ 2]] (5);
.9336948690, .5642329350, .1651826067, .7863020910, .6955721300
> randorr( garnrna[ 2, 4]] (5);
10.3 Generating Random Variates from Other Distributions 431
Maple can also generate random variates from discrete empirical probability
distributions defined over the integers I, . . . , N. Once these distributions are de-
fined, their random variates can be generated using the random command. In
the next example, we define an empirical distribution p(k) that can take 6 values
k=I, ... ,6:
0.30, fork = I
0.20, fork=2
0.10, fork = 3
p(k) =
0.25, fork=4
0.05, fork=5
0.10, fork = 6.
> Probs:=.3, .2, .1, .25, .05, .1;
sum ([ Probs] [ i) , i=l . . nops ([ Probs] ) ) ;
Probs := .3, .2, .1, .25, .05, .I
1.00
> p:=ernpirical[ Probs] ;
p := empirical.3, .2,.1, .25, .05,.1
The next command generates 10 random variates from this empirical distribu-
tion.
> randorr( p] (10);
1.0, 3.0, 1.0, 2.0, 4.0, 4.0, 1.0, 4.0, 1.0, 1.0
J.l = 10 1 g(x) dx
where g(x) is a given function-such as g(x) = log(x2 + e-x 2 )-whose integral
cannot be computed directly. To evaluate this integral by simulation, we proceed
as follows.
10.4 Monte Carlo Simulation 433
First note that if V is uniform over (0, I}-Le., if V's density is fu(u) = 1,
o< u < I-then we can write
1 k
lim -k Lg(V;) = E[g(U)] = J.l
k-.+oo ;=,
where the g(VJ), ... , g(Vk) are also independent and identically distributed ran-
dom variables. The result follows by using the strong law of large numbers.
Generating a sufficiently large number of uniform random numbers u" ... , Uk
and taking the average of g(u,), ... ,g(Uk) gives the value of the integral.
Example 102 Evaluation ofa definite integral. Consider the problem of evaluat-
ing the definite integral Jo' g(x) dx where g(x) = log(x2 + e-x \ We generate
1000 uniform random numbers and evaluate the integral using Monte Carlo.
> restart: # MonteCarloIntegral.mws
> with(stats,random); with(stats,describe);
[random]
[describe]
> u: ={ randorr( uniform] (1000)]
> g:=u->log(u A 2+exp(-u A 2));
g := u ~ log(u2 + e<-u 2»
> #plot(g(x),x=O .. l);
> mu:=map(g,u):
We find 0.07401 as the simulated value of the integral.
> describe[ mean] (mu);
.07401925167
Maple is unable to evaluate the integral using the int () command. But nu-
merical integration of the function-using evalf (int ( ) ) -gives a result that
is close to what we found using Monte Carlo simulation.
> int(g(x),x=O .. l);
Example 103 The car and goats problem-The Monty Hall Dilemma. Suppose
you are on Monty Hall's TV game show "Let's Make a Deal," and Monty gives
you a choice of three doors. Behind one door is a shiny new car, and behind each
of the other two doors is a smelly goat. You choose a door, say, number I, and
Monty, who knows what is behind the doors, opens another door, say number 3,
which has a goat. He says to you, "Do you want to pick door number 2?" Is it
to your advantage to switch your choice of doors? That is, do you have a better
chance of winning the car if you switch?
This problem created a lot of an excitement in 1991 when it appeared in Mar-
ilyn vos Savant's column "Ask Marilyn" in Parade magazine and received many
wrong answers from readers--many people, including some professional mathe-
maticians, thought that after Monty reveals the goat, the probability of winning is
112; see vos Savant's book The Power ofLogical Thinking [165] for transcripts of
the readers' letters. Vos Savant answered the question correctly by stating that if
the contestant switches doors then the probability of winning is 213, not 112. 5
To solve this problem using simulation we will assume, without loss of gener-
ality, that you pick door I. Monty knows where the car is and will open an empty
door. Here are the outcomes if you always switch.
• If the car is really behind door I, Monty is equally likely to open door 2 or
3.
Thus, using the policy of always switching, you would win the car if it is behind
door 2 or 3. With the policy of never switching, you would win the car if it is
behind door 1.6
SShe argued as follows: Suppose there are 1 million doors and the contestant picks door I. Monty,
who knows what is behind all the doors and always avoids the one with the car, opens all except door
number 777,777. In this case, the contestant would surely pick door number 777,777.
6ft is perhaps now obvious (even without using simulation) that, if you switch, the probability of
winning the car is 213.
10.5 Dynamic Simulation Models 435
At the start of the game, the car is equally likely to be behind any of the three
doors. We generate unifonn random numbers using discreteuniforrrf 1,3)
to simulate the actual location of the car.
> restart: # MontyHall.mws
> with(stats); #readlib(randomize): randomize():
Canova, describe, fit, importtiata, random, statevalJ, statp/ots, transform]
> p:=discreteuniform 1,3) ;
P := discreteunijormt. 3
We simulate the game 1000 times and find that 67.5% of the time the contes-
tant wins the car under the policy of always switching and 34% of the time the
contestant wins under the policy of never switching. Marilyn was right!
> N:=1000;
N:= 1000
> # Policy 1: Always Switch
> Win:=O:
> for n from 1 to N do
CarBehindDoor: =random p) (1);
if CarBehindDoor=1.0 then Win:=Win+O;
elif (CarBehindDoor=2.0 or CarBehindDoor=3.0)
then Win:=Win+1;
fi od:
> evalf (Win/N) ;
.6750000000
> # Policy 2: Never Switch
> Win:=O:
> for n from 1 to N do
CarBehindDoor: =random p) (1);
if CarBehindDoor=1.0
then Win:=Win+1;
elif (CarBehindDoor=2.0 or CarBehindDoor=3.0)
then Win:=Win+O;
fi od:
> evalf(Win/N);
.3400000000
7Modeling the randomness of yield has recently become an important research area in operations
management; see Gerchak and Parlar [69] and Yano and Lee [197].
10.5 Dynamic Simulation Models 437
and the random yield fraction P is taken as beta with parameters (a, b) = (6,2),
i.e., g(p) = 42 p 5(1 - p), 0 < p < 1. In the simulation of the inventory process,
random variates from both the Poisson and beta distributions are generated using
Maple's random function.
> S:=15; s:=5; lambda:=10; x[ 0] :=15;
S:= 15
s:= 5
A. := 10
xo := 15
We perform the simulation for a total of 100 weeks and generate the values of
Xn in equation (l0.3) using the following Maple commands.
> N:=100;
N:= 100
> #plot (statevalff pdf, beta[ 6,2]] (x), x=O .. 1) ;
> for n from 0 to N do
y[ n+1] :=randon( poisson[ lambda]] (1);
if x[ n] <s then
b:=randon( beta[ 6,2]] (1);
x[ n+1] :=floor (b* (S-y[ n+l] ) )
elif x[ n] >=s then
x[ n+ 1] : =x[ n] -y[ n+l]
fi od:
The simulated inventory levels (and demand) for the first 10 weeks are found
as follows.
> seq([ n,[ x[ n] ,y[ n+1]] ,x[ n+1]] ,n=1. .10);
[I, [6.0, 8.0], -2.0], [2, [-2.0, 9.0], 4], [3, [4, 12.0], 2],
[4, [2, 13.0], I], [5, [I, 15.0],0], [6, [0, 7.0], 6],
[7, [6, 13.0], -7.0], [8, [-7.0, 12.0], 2], [9, [2, 11.0], 2],
[10, [2, 10.0], 3]
> IL:={ seq (x[ n] ,n=1. .N)] : nops (IL):
In order to compute the average number of units in inventory and the average
number backordered, we need to isolate the nonnegative and negative inventory
levels. This is done easily with the select () command.
> ILNonNegative:=select(type,IL,nonneg);
ILNegative:= [-2.0, -7.0, -4.0, -2, -3.0, -5.0, -5.0, -3.0, -4.0, -5.0,
-2.0, -2, -2.0, -1.0, -4.0, -6.0, -5.0, -3, -8.0, -4, -1.0, -11.0,
-1.0]
The average inventory level and the average number backordered are found as
3.29 and 3.91, respectively.
> with(describe):
> describe[ mean] (ILNonNegative):
describe[ mean] (ILNegative):
3.298701299
-3.913043478
The distribution of the inventory level is found as follows.
> for n from min(op(IL)) to max(op(IL)) do
k[ n] : = (n. . (n +1)) od :
> Intervals:~ seq(k[n] ,n=min(op(IL)) .. max(op(IL)))];
FIGURE 10.3. Distribution of the inventory level Xn in the periodic-review inventory prob-
lem random yield for a simulation length of N = 100 weeks. Weekly demands are assumed
Poisson with parameter A = 10 and the random yield fraction p is beta sitributed with pa-
rameters (a, b) = (6,2).
W = 2/[.u(.u - 2)] where ;. is the rate of the Poisson arrival process and .u
is the rate of the exponentially distributed service times. s When Markovian as-
sumptions are no longer valid, i.e., when the arrival process is no longer Poisson
and/or service time is not exponential, such simple formulas no longer apply.
However, there is a very general set of recursive equations that relate the ran-
dom queue waiting time Wn of the nth customer to the interarrival time An be-
tween the (n - 1)st and nth customer and the service time Sn-I of the (n - l)st
customer.9 As shown originally by Lindley (122] (see also, Kleinrock [110, p.
277] and Gaver and Thompson [68, p. 572]), we can write
8Generally, waiting time in the queue is denoted by Wq . In this example we will use the notation
W in order not to complicate the notation.
9Note that we do not make any probability assumptions about the distributions of An and Sn.
440 10. Simulation
[0,
[6.854839338, 3.733992340], 0], [I, [6.687266147,4.811016670],0],
[2,
[7.116917438, 7.031511744], 0],
[3,
[6.064124444, 6.797881782], .733757338],
[4,
[7.208611228, 7.019664048], .544810158],
[6.519623905, 3.655438579], 0]
[5,
> wList:=[ seq(w[ n] ,n=O .. N)] :
> for n from min(op(wList)) to max(op(wList)) do
k[ n] : = (n .. (n + 1)) od:
> Intervals:=[ seq(k[ n] ,n=min(op(wList)) .•
max (op(wList) ))] :
> with(describe):
We see that the mean waiting time in queue is obtained as 2.004 with a standard
deviation of3.1 0 1.
> describe{ mean] (wList);
describe[ standarddeviation] (wList);
2.004485394
3.101872397
> with (transform) :
Following is the complete distribution of the waiting times where we find that
out of 100 observations, 64 fall in the interval [0,1), 7 fall into interval [1,2) and
soon.
> Distribution:=statsort(tallyinto(wList,
Intervals));
FIGURE 10.4. Distribution of the waiting time in queue, Wn , for the G / G / I queue with
uniform interarrival times and Wei bull service times for a simulation length of N = 100
customers. The uniform distribution has parameters (6, 8) and the Weibull has parameters
(2,6).
see, e.g., Gottfried and Weisman [7S, Section 3.4] for a description of ARS and
Laarhoven and Aarts [lIS] for a detailed account of simulated annealing.
For a problem With, say, two decision variables x and y, starting with a feasible
point in the two-dimensional region that is known to contain the optimal solution
(x·, y.), ARS randomly generates the next feasible point and compares it to the
previous point. If the new point is better than the previous one and it is feasible,
it is kept; otherwise, the new point is discarded. lo For example, if x· is known to
be in the interval [Xmin, xmax] and if Xold is the previous point, then the new point
is generated using the formula Xnew = Xold + (xmax - x min)(2r - I)V where r is
a random number between 0 and I and v is an odd integer. As recommended by
Gall [67], initially, v is chosen as 3 or S and later, when the improvements in the
objective function become smaller, it is increased to 7 or 9. Note that the larger the
interval of uncertainty (xmax - Xmin), the larger the step size (xmax - xmin)(2r -l)v .
But increased values of v have the effect of shortening the step size since -1 <
2r-I<1.
Example 106 Minimization of a discontinuous and nondifferentiable junction
with two local minima. Consider a function z(x, y) defined as
z := proc(x, y)
if(x - 2)2 + (y - 2)2 :5: 4 then S x sqrt«x - 2)2 + (y - 2)2)
else 3 x abs(x - S) + abs(y - S) + 3
fi
end
> z(2,2); z(S,S);
o
3
> plot3d(z,0 .. 10,0 .. 10,axes=boxed,
orientation={ 140,68] , shading=none) ;
While a visual inspection in this case reveals that the global minimum of z(x, y)
is at (x, y) = (2,2) with z(O, 0) = 0, the complicated nature of this type of
lOIn simulated annealing, the new point that is worse than the old one is not immediately discarded,
but it is kept with a specific probability.
10.6 Optimization by Random Search 443
function nonnally makes it very difficult to find the global optimum with the
standard optimization methods.
20
15
10
z := proc(x, y)
if(x - 2)2 + (y - 2)2 ~ 4 tben 5 x sqrt«x - 2)2 + (y - 2)2)
else 3 x abs(x - 5) + abs(y - 5) + 3
fi
end
> for i from 1 to N do:
r:=randorr( uniform] () :
> x:=xOpt+(xMax-xMin)* (2*r-1)A3:
r: =randorr( uniform] ():
> y:=yOpt+(yMax-yMin)* (2*r-1)A3:
> if (x<xMin or x>xMax or y<yMin or y>yMax) then
next fi:
> if z(x,y»zOpt then next fi:
> xOpt:=x; yOpt:=y; zOpt:=z(x,y);
n:=n+1:
I( n] : ={ xOpt, yOpt, zOpt] ;
Delta{ n] :=I( n] -I( n-1] ;
if abs(Delta{ n][ 3] )<epsilon then break fi;
> od:
Once the iterations end, we check the final values of n and i. The value of
n = 23 indicates that out of 10000 iterations only 23 "good" points were found
that improved the objective function. However, the value of i = 1000 1 signals
that the convergence criterion was not yet satisfied. But, examining the values of
Ln and Ln - Ln-I, we note that the solution found by ARS, i.e.,
10.7 Summary
Many interesting and important problems in operations research cannot (yet) be
solved analytically. For example, a large number of problems in queueing net-
446 10. Simulation
works are not amenable to solution since the available mathematical theory is
not sophisticated enough to find a closed-form solution for the operating char-
acteristics of such systems. Simulation is a very flexible (albeit time-consuming)
solution technique that has found wide applicability. We started this chapter by
describing Maple's uniform random number generator. We also gave examples
of using Maple's nearly 20 continuous and discrete random variate generators
including the exponential, normal, binomial and Poisson. Next, Monte Carlo sim-
ulation was used to estimate the definite integral of a complicated function and to
simulate the optimal policy in the "car and goats" TV game. Maple's random vari-
ate generators were then used to simulate an inventory system with random yield
and a non-Markovian queue. The chapter ended with an optimization application
where the global optimum of a discontinuous and nondifferentiable function was
located using the method of adaptive random search.
10.8 Exercises
I. Two friends who have unpredictable lunch hours agree to meet for lunch
at their favorite restaurant whenever possible. Neither wishes to eat at that
particular restaurant alone and each dislikes waiting for the other, so they
agree that:
• Each will arrive at a random time between noon and I :00 p.m.
• Each will wait for the other either for 15 minutes or until I :00 p.m. at
the latest. For example, if one arrives at 12:50, he will stay until 1:00
p.m.
(a) Use simulation to find the probability that the friends will meet.
(b) Use your knowledge of probability to find the exact solution for this
problem.
R2 = Zf + zi
Z2
tana = ZI.
s = zT +~
o = tan-I (;~)
and show that
(c) Since R2 is exponential with mean 2, and 9 is unifonn over (0, 21f),
argue that the vector (Z I, Z2) can be generated using the fonnula
ZI = Rcos(9) = J-210gUI COS(21fU2)
Z2 = Rsin(9) = J-210gUI sin(21fU2)
where UI and U2 are random numbers between 0 and 1. This method
is due to Box and Muller [36].
4. Consider the function f(x) = 20x 2 (1 - x)3.
be written as llZ(t) =
y,JKi where Y ' V N(O, I), E[llZ(t)] 0 and =
Var[llZ(t)] = llt. Simulate the standard Brownian motion over the unit
time interval [0, I] by taking a step size of t:.t = 0.00 I and plot the result-
ing sample path.
7. The function/(x, y) = lOO(y-x 2)2+(I _x)2 is known as Rosenbrock's
banana function since its contours near the minimum point resemble a ba-
nana.
8. Consider a dam that generates electricity and supplies water for irrigation.
Define X n as the water level at the start of period n and let r n be the amount
of water released in period n. Let t; n be the random amount of rainfall
during period n distributed as Poisson with parameter..t, i.e., Pr(t;n = k) =
e-). At / kL Assume that there is a dam capacity of M units.
[94] I. Horowitz. Decision Making and the Theory of the Firm. Holt, Rinehart
and Winston, New York. 1970.
[97] R. B. Israel. Calculus the Maple Way. Addison-Wesley, Don Mills, On-
tario, 1996.
[Ill] G. Klimek and M. Klimek. Discovering Curves and Surfaces with Maple.
Springer-Verlag, New York, 1997.
[119] H. Lee and C. A. Yano. Production control for multi-stage systems with
variable yield losses. Operations Research, 36:269-278, 1988.
References 457
[166] H. Scarf. The optimality of (S, s) policies in the dynamic inventory prob-
lem. In K. J. Arrow, S. Karlin, and P. Suppes, editors, Mathematical
Methods in the Social Sciences. Stanford University Press, Stanford, Calif.,
1960.
[173] E. A. Silver. Establishing the reorder quantity when the amount received
is uncertain. INFOR, 14:32-29, 1976.
[I79] M. J. Sobel. Optimal average cost policy for a queue with start-up and
shut-down costs. Operations Research, 17:145-162, 1969.