11. Sensitivity analysis


11.1. Introduction

Given an optimization problem it is often useful to obtain information about how the optimal objective value changes when the problem parameters are perturbed. For instance, assume that a bound represents a capacity of a machine. Now, it may be possible to expand the capacity for a certain cost and hence it is worthwhile knowing what the value of additional capacity is. This is precisely the type of questions the sensitivity analysis deals with.

Analyzing how the optimal objective value changes when the problem data is changed is called sensitivity analysis.

11.2. Restrictions

Currently, sensitivity analysis is only available for continuous linear optimization problems. Moreover, MOSEK can only deal with perturbations in bounds and objective coefficients.

11.3. References

The book [19] discusses the classical sensitivity analysis in Chapter 10 whereas the book [9, Chapter 19] presents a modern introduction to sensitivity analysis. Finally, it is recommended to read the short paper [2] to avoid some of the pitfalls associated with sensitivity analysis.

11.4. Sensitivity analysis for linear problems

11.4.1. The optimal objective value function

Assume that we are given the problem

\begin{math}\nonumber{}\begin{array}{rclccccl}\nonumber{}z(l^{c},u^{c},l^{x},u^{x},c) & = & \mbox{minimize} &  &  & c^{T}x &  & \\\nonumber{} &  & \mbox{subject to} & l^{c} & \leq{} & Ax & \leq{} & u^{c},\\\nonumber{} &  &  &  &  & l^{x}\leq{}x\leq{}u^{x}, &  &\end{array}\end{math} (11.4.1)

and we want to know how the optimal objective value changes as [[MathCmd 393]] is perturbed. To answer this question we define the perturbed problem for [[MathCmd 393]] as follows

\begin{math}\nonumber{}\begin{array}{rclcccl}\nonumber{}f_{{l^{c}_{i}}}(\beta ) & = & \mbox{minimize} &  &  & c^{T}x & \\\nonumber{} &  & \mbox{subject to} & l^{c}+\beta e_{i} & \leq{} & Ax & \leq{}u^{c},\\\nonumber{} &  &  &  &  & l^{x}\leq{}x\leq{}u^{x}, &\end{array}\end{math} (11.4.2)

where [[MathCmd 396]] is the ith column of the identity matrix. The function

\begin{math}\nonumber{}f_{{l^{c}_{i}}}(\beta )\end{math} (11.4.3)

shows the optimal objective value as a function of [[MathCmd 398]]. Please note that a change in [[MathCmd 398]] corresponds to a perturbation in [[MathCmd 145]] and hence (11.4.3) shows the optimal objective value as a function of [[MathCmd 393]].

It is possible to prove that the function (11.4.3) is a piecewise linear and convex function, i.e. the function may look like the illustration in Figure 11.1.

Figure 11.1: The optimal value function [[MathCmd 402]]. Left: [[MathCmd 403]] is in the interior of linearity interval. Right: [[MathCmd 403]] is a breakpoint.

Clearly, if the function [[MathCmd 402]] does not change much when [[MathCmd 398]] is changed, then we can conclude that the optimal objective value is insensitive to changes in [[MathCmd 145]]. Therefore, we are interested in the rate of change in [[MathCmd 402]] for small changes in [[MathCmd 398]] — specificly the gradient

\begin{math}\nonumber{}f'_{{l^{c}_{i}}}(0),\end{math} (11.4.4)

which is called the shadow price related to [[MathCmd 393]]. The shadow price specifies how the objective value changes for small changes in [[MathCmd 398]] around zero. Moreover, we are interested in the linearity interval

\begin{math}\nonumber{}\beta \in{}[\beta _{1},\beta _{2}]\end{math} (11.4.5)

for which

\begin{math}\nonumber{}f'_{{l^{c}_{i}}}(\beta )=f'_{{l^{c}_{i}}}(0).\end{math} (11.4.6)

Since [[MathCmd 415]] is not a smooth function [[MathCmd 416]] may not be defined at 0, as illustrated by the right example in figure 11.1. In this case we can define a left and a right shadow price and a left and a right linearity interval.

The function [[MathCmd 415]] considered only changes in [[MathCmd 393]]. We can define similar functions for the remaining parameters of the z defined in (11.4.1) as well:

\begin{math}\nonumber{}\begin{array}{rcll}\nonumber{}f_{{u^{c}_{i}}}(\beta ) & = & z(l^{c},u^{c}+\beta e_{i},l^{x},u^{x},c), & i=1,\ldots ,m,\\\nonumber{}f_{{l^{x}_{j}}}(\beta ) & = & z(l^{c},u^{c},l^{x}+\beta e_{j},u^{x},c), & j=1,\ldots ,n,\\\nonumber{}f_{{u^{x}_{j}}}(\beta ) & = & z(l^{c},u^{c},l^{x},u^{x}+\beta e_{j},c), & j=1,\ldots ,n,\\\nonumber{}f_{{c_{j}}}(\beta ) & = & z(l^{c},u^{c},l^{x},u^{x},c+\beta e_{j}), & j=1,\ldots ,n.\end{array}\end{math} (11.4.7)

Given these definitions it should be clear how linearity intervals and shadow prices are defined for the parameters [[MathCmd 420]] etc.

11.4.1.1. Equality constraints

In MOSEK a constraint can be specified as either an equality constraint or a ranged constraint. If constraint i is an equality constraint, we define the optimal value function for this as

\begin{math}\nonumber{}f_{{e^{c}_{i}}}(\beta )=z(l^{c}+\beta e_{i},u^{c}+\beta e_{i},l^{x},u^{x},c)\end{math} (11.4.8)

Thus for an equality constraint the upper and the lower bounds (which are equal) are perturbed simultaneously. Therefore, MOSEK will handle sensitivity analysis differently for a ranged constraint with [[MathCmd 422]] and for an equality constraint.

11.4.2. The basis type sensitivity analysis

The classical sensitivity analysis discussed in most textbooks about linear optimization, e.g. [19, Chapter 10], is based on an optimal basic solution or, equivalently, on an optimal basis. This method may produce misleading results [9, Chapter 19] but is computationally cheap. Therefore, and for historical reasons this method is available in MOSEK.

We will now briefly discuss the basis type sensitivity analysis. Given an optimal basic solution which provides a partition of variables into basic and non-basic variables, the basis type sensitivity analysis computes the linearity interval [[MathCmd 423]] so that the basis remains optimal for the perturbed problem. A shadow price associated with the linearity interval is also computed. However, it is well-known that an optimal basic solution may not be unique and therefore the result depends on the optimal basic solution employed in the sensitivity analysis. This implies that the computed interval is only a subset of the largest interval for which the shadow price is constant. Furthermore, the optimal objective value function might have a breakpoint for [[MathCmd 403]]. In this case the basis type sensitivity method will only provide a subset of either the left or the right linearity interval.

In summary, the basis type sensitivity analysis is computationally cheap but does not provide complete information. Hence, the results of the basis type sensitivity analysis should be used with care.

11.4.3. The optimal partition type sensitivity analysis

Another method for computing the complete linearity interval is called the optimal partition type sensitivity analysis. The main drawback of the optimal partition type sensitivity analysis is that it is computationally expensive compared to the basis type analysts. This type of sensitivity analysis is currently provided as an experimental feature in MOSEK.

Given the optimal primal and dual solutions to (11.4.1), i.e. [[MathCmd 329]] and [[MathCmd 426]] the optimal objective value is given by

\begin{math}\nonumber{}z^{*}:=c^{T}x^{*}.\end{math} (11.4.9)

The left and right shadow prices [[MathCmd 428]] and [[MathCmd 429]] for [[MathCmd 145]] are given by this pair of optimization problems:

\begin{math}\nonumber{}\begin{array}{rclccl}\nonumber{}\sigma _{1} & = & \mbox{minimize} & e_{i}^{T}s_{l}^{c} &  & \\\nonumber{} &  & \mbox{subject to} & A^{T}(s_{l}^{c}-s_{u}^{c})+s_{l}^{x}-s_{u}^{x} & = & c,\\\nonumber{} &  &  & (l_{c})^{T}(s_{l}^{c})-(u_{c})^{T}(s_{u}^{c})+(l_{x})^{T}(s_{l}^{x})-(u_{x})^{T}(s_{u}^{x}) & = & z^{*},\\\nonumber{} &  &  & s_{l}^{c},s_{u}^{c},s_{l}^{c},s_{u}^{x}\geq{}0 &  &\end{array}\end{math} (11.4.10)

and

\begin{math}\nonumber{}\begin{array}{rclccl}\nonumber{}\sigma _{2} & = & \mbox{maximize} & e_{i}^{T}s_{l}^{c} &  & \\\nonumber{} &  & \mbox{subject to} & A^{T}(s_{l}^{c}-s_{u}^{c})+s_{l}^{x}-s_{u}^{x} & = & c,\\\nonumber{} &  &  & (l_{c})^{T}(s_{l}^{c})-(u_{c})^{T}(s_{u}^{c})+(l_{x})^{T}(s_{l}^{x})-(u_{x})^{T}(s_{u}^{x}) & = & z^{*},\\\nonumber{} &  &  & s_{l}^{c},s_{u}^{c},s_{l}^{c},s_{u}^{x}\geq{}0. &  &\end{array}\end{math} (11.4.11)

These two optimization problems make it easy to interpret the shadow price. Indeed, if [[MathCmd 426]] is an arbitrary optimal solution then

\begin{math}\nonumber{}(s_{l}^{c})_{i}^{*}\in{}[\sigma _{1},\sigma _{2}].\end{math} (11.4.12)

Next, the linearity interval [[MathCmd 423]] for [[MathCmd 145]] is computed by solving the two optimization problems

\begin{math}\nonumber{}\begin{array}{lclccccl}\nonumber{}\beta _{1} & = & \mbox{minimize} &  &  & \beta  &  & \\\nonumber{} &  & \mbox{subject to} & l^{c}+\beta e_{i} & \leq{} & Ax & \leq{} & u^{c},\\\nonumber{} &  &  &  &  & c^{T}x-\sigma _{1}\beta  & = & z^{*},\\\nonumber{} &  &  &  &  & l^{x}\leq{}x\leq{}u^{x}, &  &\end{array}\end{math} (11.4.13)

and

\begin{math}\nonumber{}\begin{array}{lclccccl}\nonumber{}\beta _{2} & = & \mbox{maximize} &  &  & \beta  &  & \\\nonumber{} &  & \mbox{subject to} & l^{c}+\beta e_{i} & \leq{} & Ax & \leq{} & u^{c},\\\nonumber{} &  &  &  &  & c^{T}x-\sigma _{2}\beta  & = & z^{*},\\\nonumber{} &  &  &  &  & l^{x}\leq{}x\leq{}u^{x}. &  &\end{array}\end{math} (11.4.14)

The linearity intervals and shadow prices for [[MathCmd 439]] [[MathCmd 440]] and [[MathCmd 441]] are computed similarly to [[MathCmd 145]].

The left and right shadow prices for [[MathCmd 80]] denoted [[MathCmd 428]] and [[MathCmd 429]] respectively are computed as follows:

\begin{math}\nonumber{}\begin{array}{lclccccl}\nonumber{}\sigma _{1} & = & \mbox{minimize} &  &  & e_{j}^{T}x &  & \\\nonumber{} &  & \mbox{subject to} & l^{c}+\beta e_{i} & \leq{} & Ax & \leq{} & u^{c},\\\nonumber{} &  &  &  &  & c^{T}x & = & z^{*},\\\nonumber{} &  &  &  &  & l^{x}\leq{}x\leq{} & u^{x} &\end{array}\end{math} (11.4.15)

and

\begin{math}\nonumber{}\begin{array}{lclccccl}\nonumber{}\sigma _{2} & = & \mbox{maximize} &  &  & e_{j}^{T}x &  & \\\nonumber{} &  & \mbox{subject to} & l^{c}+\beta e_{i} & \leq{} & Ax & \leq{} & u^{c},\\\nonumber{} &  &  &  &  & c^{T}x & = & z^{*},\\\nonumber{} &  &  &  &  & l^{x}\leq{}x\leq{} & u^{x}. &\end{array}\end{math} (11.4.16)

Once again the above two optimization problems make it easy to interpret the shadow prices. Indeed, if [[MathCmd 329]] is an arbitrary primal optimal solution, then

\begin{math}\nonumber{}x_{j}^{*}\in{}[\sigma _{1},\sigma _{2}].\end{math} (11.4.17)

The linearity interval [[MathCmd 423]] for a [[MathCmd 80]] is computed as follows:

\begin{math}\nonumber{}\begin{array}{rclccl}\nonumber{}\beta _{1} & = & \mbox{minimize} & \beta  &  & \\\nonumber{} &  & \mbox{subject to} & A^{T}(s_{l}^{c}-s_{u}^{c})+s_{l}^{x}-s_{u}^{x} & = & c+\beta e_{j},\\\nonumber{} &  &  & (l_{c})^{T}(s_{l}^{c})-(u_{c})^{T}(s_{u}^{c})+(l_{x})^{T}(s_{l}^{x})-(u_{x})^{T}(s_{u}^{x})-\sigma _{1}\beta  & \leq{} & z^{*},\\\nonumber{} &  &  & s_{l}^{c},s_{u}^{c},s_{l}^{c},s_{u}^{x}\geq{}0 &  &\end{array}\end{math} (11.4.18)

and

\begin{math}\nonumber{}\begin{array}{rclccl}\nonumber{}\beta _{2} & = & \mbox{maximize} & \beta  &  & \\\nonumber{} &  & \mbox{subject to} & A^{T}(s_{l}^{c}-s_{u}^{c})+s_{l}^{x}-s_{u}^{x} & = & c+\beta e_{j},\\\nonumber{} &  &  & (l_{c})^{T}(s_{l}^{c})-(u_{c})^{T}(s_{u}^{c})+(l_{x})^{T}(s_{l}^{x})-(u_{x})^{T}(s_{u}^{x})-\sigma _{2}\beta  & \leq{} & z^{*},\\\nonumber{} &  &  & s_{l}^{c},s_{u}^{c},s_{l}^{c},s_{u}^{x}\geq{}0. &  &\end{array}\end{math} (11.4.19)

11.4.4. Example: Sensitivity analysis

As an example we will use the following transportation problem. Consider the problem of minimizing the transportation cost between a number of production plants and stores. Each plant supplies a number of goods and each store has a given demand that must be met. Supply, demand and cost of transportation per unit are shown in Figure 11.2.

Figure 11.2: Supply, demand and cost of transportation.

If we denote the number of transported goods from location i to location j by [[MathCmd 324]], the problem can be formulated as the linear optimization problem

minimize

\begin{math}\nonumber{}\begin{array}{ccccccccccccccl}\nonumber{}1x_{{11}} & + & 2x_{{12}} & + & 5x_{{23}} & + & 2x_{{24}} & + & 1x_{{31}} & + & 2x_{{33}} & + & 1x_{{34}}\end{array}\end{math} (11.4.20)

subject to

\begin{math}\nonumber{}\begin{array}{ccccccccccccccl}\nonumber{}x_{{11}} & + & x_{{12}} &  &  &  &  &  &  &  &  &  &  & \leq{} & 400,\\\nonumber{} &  &  &  & x_{{23}} & + & x_{{24}} &  &  &  &  &  &  & \leq{} & 1200,\\\nonumber{} &  &  &  &  &  &  &  & x_{{31}} & + & x_{{33}} & + & x_{{34}} & \leq{} & 1000,\\\nonumber{}x_{{11}} &  &  &  &  &  &  & + & x_{{31}} &  &  &  &  & = & 800,\\\nonumber{} &  & x_{{12}} &  &  &  &  &  &  &  &  &  &  & = & 100,\\\nonumber{} &  &  &  & x_{{23}} & + &  &  &  &  & x_{{33}} &  &  & = & 500,\\\nonumber{} &  &  &  &  &  & x_{{24}} & + &  &  &  &  & x_{{34}} & = & 500,\\\nonumber{}x_{{11}}, &  & x_{{12}}, &  & x_{{23}}, &  & x_{{24}}, &  & x_{{31}}, &  & x_{{33}}, &  & x_{{34}} & \geq{} & 0.\end{array}\end{math} (11.4.21)

The basis type and the optimal partition type sensitivity results for the transportation problem are shown in Table 11.1 and 11.2 respectively.

Basis type
Con. [[MathCmd 457]] [[MathCmd 458]] [[MathCmd 428]] [[MathCmd 429]]
1 -300.00 0.00 3.00 3.00
2 -700.00 + 0.00 0.00
3 -500.00 0.00 3.00 3.00
4 -0.00 500.00 4.00 4.00
5 -0.00 300.00 5.00 5.00
6 -0.00 700.00 5.00 5.00
7 -500.00 700.00 2.00 2.00
Var. [[MathCmd 457]] [[MathCmd 458]] [[MathCmd 428]] [[MathCmd 429]]
[[MathCmd 465]] - 300.00 0.00 0.00
[[MathCmd 466]] - 100.00 0.00 0.00
[[MathCmd 467]] - 0.00 0.00 0.00
[[MathCmd 468]] - 500.00 0.00 0.00
[[MathCmd 469]] - 500.00 0.00 0.00
[[MathCmd 470]] - 500.00 0.00 0.00
[[MathCmd 471]] -0.000000 500.00 2.00 2.00
Optimal partition type
Con. [[MathCmd 457]] [[MathCmd 458]] [[MathCmd 428]] [[MathCmd 429]]
1 -300.00 500.00 3.00 1.00
2 -700.00 + -0.00 -0.00
3 -500.00 500.00 3.00 1.00
4 -500.00 500.00 2.00 4.00
5 -100.00 300.00 3.00 5.00
6 -500.00 700.00 3.00 5.00
7 -500.00 700.00 2.00 2.00
Var. [[MathCmd 457]] [[MathCmd 458]] [[MathCmd 428]] [[MathCmd 429]]
[[MathCmd 465]] - 300.00 0.00 0.00
[[MathCmd 466]] - 100.00 0.00 0.00
[[MathCmd 467]] - 500.00 0.00 2.00
[[MathCmd 468]] - 500.00 0.00 0.00
[[MathCmd 469]] - 500.00 0.00 0.00
[[MathCmd 470]] - 500.00 0.00 0.00
[[MathCmd 471]] - 500.00 0.00 2.00
Table 11.1: Ranges and shadow prices related to bounds on constraints and variables. Left: Results for the basis type sensitivity analysis. Right: Results for the optimal partition type sensitivity analysis.

Basis type
Var. [[MathCmd 457]] [[MathCmd 458]] [[MathCmd 428]] [[MathCmd 429]]
[[MathCmd 491]] - 3.00 300.00 300.00
[[MathCmd 492]] - 100.00 100.00
[[MathCmd 493]] -2.00 0.00 0.00
[[MathCmd 494]] - 2.00 500.00 500.00
[[MathCmd 495]] -3.00 500.00 500.00
[[MathCmd 496]] - 2.00 500.00 500.00
[[MathCmd 497]] -2.00 0.00 0.00
Optimal partition type
Var. [[MathCmd 457]] [[MathCmd 458]] [[MathCmd 428]] [[MathCmd 429]]
[[MathCmd 491]] - 3.00 300.00 300.00
[[MathCmd 492]] - 100.00 100.00
[[MathCmd 493]] -2.00 0.00 0.00
[[MathCmd 494]] - 2.00 500.00 500.00
[[MathCmd 495]] -3.00 500.00 500.00
[[MathCmd 496]] - 2.00 500.00 500.00
[[MathCmd 497]] -2.00 0.00 0.00
Table 11.2: Ranges and shadow prices related to the objective coefficients. Left: Results for the basis type sensitivity analysis. Right: Results for the optimal partition type sensitivity analysis.

Examining the results from the optimal partition type sensitivity analysis we see that for constraint number 1 we have [[MathCmd 509]] and [[MathCmd 510]]. Therefore, we have a left linearity interval of [-300,0] and a right interval of [0,500]. The corresponding left and right shadow prices are 3 and 1 respectively. This implies that if the upper bound on constraint 1 increases by

\begin{math}\nonumber{}\beta \in{}[0,\beta _{1}]=[0,500]\end{math} (11.4.22)

then the optimal objective value will decrease by the value

\begin{math}\nonumber{}\sigma _{2}\beta =1\beta .\end{math} (11.4.23)

Correspondingly, if the upper bound on constraint 1 is decreased by

\begin{math}\nonumber{}\beta \in{}[0,300]\end{math} (11.4.24)

then the optimal objective value will increase by the value

\begin{math}\nonumber{}\sigma _{1}\beta =3\beta .\end{math} (11.4.25)

11.5. Sensitivity analysis from the MOSEK API

MOSEK provides the functions Task.primalsensitivity and Task.dualsensitivity for performing sensitivity analysis. The code below gives an example of its use.

Example code from:

mosek/5/tools/examp/sensitivity.py

## # Copyright: Copyright (c) 1998-2007 MOSEK ApS, Denmark. All rights reserved. # # File: sensitivity.cs # # Purpose: To demonstrate how to perform sensitivity # analysis from the API on a small problem: # # minimize # # obj: +1 x11 + 2 x12 + 5 x23 + 2 x24 + 1 x31 + 2 x33 + 1 x34 # st # c1: + x11 + x12 <= 400 # c2: + x23 + x24 <= 1200 # c3: + x31 + x33 + x34 <= 1000 # c4: + x11 + x31 = 800 # c5: + x12 = 100 # c6: + x23 + x33 = 500 # c7: + x24 + x34 = 500 # # The example uses basis type sensitivity analysis. ## import sys import pymosek as mosek try: from Numeric import array, Float, zeros, ones except ImportError: from mosekarr import array, Float, zeros, ones # Since the actual value of Infinity is ignores, we define it solely # for symbolic purposes: inf = 0.0 # Define a stream printer to grab output from MOSEK def streamprinter(text): sys.stdout.write(text) sys.stdout.flush() # We might write everything directly as a script, but it looks nicer # to create a function. def main (): # Create a handle to MOSEK mskhandle = mosek.mosek () # Create a MOSEK environment env = mskhandle.Env () # Attach a printer to the environment env.set_Stream (mosek.streamtype.log, streamprinter) # Initialize the environment env.init () # Create a task task = env.Task(0,0) # Attach a printer to the task task.set_Stream (mosek.streamtype.log, streamprinter) # Set up data bkc = array([ mosek.boundkey.up,mosek.boundkey.up, mosek.boundkey.up,mosek.boundkey.fx, mosek.boundkey.fx,mosek.boundkey.fx, mosek.boundkey.fx ]) blc = array([ -inf, -inf, -inf, 800., 100., 500., 500. ]) buc = array([ 400., 1200., 1000., 800., 100., 500., 500. ]) bkx = array([ mosek.boundkey.lo,mosek.boundkey.lo, mosek.boundkey.lo,mosek.boundkey.lo, mosek.boundkey.lo,mosek.boundkey.lo, mosek.boundkey.lo ]) c = array([ 1.0,2.0,5.0,2.0,1.0,2.0,1.0 ]) blx = array([ 0.0,0.0,0.0,0.0,0.0,0.0,0.0 ]) bux = array([ inf,inf,inf,inf,inf,inf,inf ]) ptrb = array([ 0,2,4,6, 8,10,12 ]) ptre = array([ 2,4,6,8,10,12,14 ]) sub = array([ 0,3,0,4,1,5,1,6,2,3,2,5,2,6 ]) val = array([ 1.0,1.0,1.0,1.0,1.0,1.0,1.0, 1.0,1.0,1.0,1.0,1.0,1.0,1.0 ]) numcon = len(bkc) numvar = len(bkx) numanz = len(val) # Input linear data task.inputdata(numcon,numvar, c,0.0, ptrb, ptre, sub, val, bkc, blc, buc, bkx, blx, bux) # Set objective sense task.putobjsense(mosek.objsense.minimize) # Optimize task.optimize(); # Analyze upper bound on c1 and the equality constraint on c4 subi = array([ 0, 3 ]) marki = array([ mosek.mark.up, mosek.mark.up ]) # Analyze lower bound on the variables x12 and x31 subj = array([ 1, 4 ]) markj = array([ mosek.mark.lo, mosek.mark.lo ]) leftpricei = zeros(2,Float) rightpricei = zeros(2,Float) leftrangei = zeros(2,Float) rightrangei = zeros(2,Float) leftpricej = zeros(2,Float) rightpricej = zeros(2,Float) leftrangej = zeros(2,Float) rightrangej = zeros(2,Float) task.primalsensitivity( subi, marki, subj, markj, leftpricei, rightpricei, leftrangei, rightrangei, leftpricej, rightpricej, leftrangej, rightrangej) print 'Results from sensitivity analysis on bounds:' print '\tleftprice | rightprice | leftrange | rightrange ' print 'For constraints:' for i in range(2): print '\t%10f %10f %10f %10f' % (leftpricei[i], rightpricei[i], leftrangei[i], rightrangei[i]) print 'For variables:' for i in range(2): print '\t%10f %10f %10f %10f' % (leftpricej[i], rightpricej[i], leftrangej[i], rightrangej[i]) leftprice = zeros(2,Float) rightprice = zeros(2,Float) leftrange = zeros(2,Float) rightrange = zeros(2,Float) subc = array([ 2, 5 ]) task.dualsensitivity( subc, leftprice, rightprice, leftrange, rightrange) print 'Results from sensitivity analysis on objective coefficients:' for i in range(2): print '\t%10f %10f %10f %10f' % (leftprice[i], rightprice[i], leftrange[i], rightrange[i]) return None # call the main function try: main () except mosek.Exception, e: print "ERROR: %s" % str(e.errno) if e.msg is not None: print "\t%s" % e.msg sys.exit(1) except: import traceback traceback.print_exc() sys.exit(1)

11.6. Sensitivity analysis with the command line tool

A sensitivity analysis can be performed with the MOSEK command line tool using the command

mosek myproblem.mps -sen sensitivity.ssp

where sensitivity.ssp is a file in the format described in the next section. The ssp file describes which parts of the problem the sensitivity analysis should be performed on.

By default results are written to a file named myproblem.sen. If necessary, this filename can be changed by setting the
MSK_SPAR_SENSITIVITY_RES_FILE_NAME
parameter By default a basis type sensitivity analysis is performed. However, the type of sensitivity analysis (basis or optimal partition) can be changed by setting the parameter
MSK_IPAR_SENSITIVITY_TYPE
appropriately. Following values are accepted for this parameter:

It is also possible to use the command line

mosek myproblem.mps -d MSK_IPAR_SENSITIVITY_ALL MSK_ON

in which case a sensitivity analysis on all the parameters is performed.

11.6.1. Sensitivity analysis specification file

MOSEK employs an MPS like file format to specify on which model parameters the sensitivity analysis should be performed. As the optimal partition type sensitivity analysis can be computationally expensive it is important to limit the sensitivity analysis.

* A comment
BOUNDS CONSTRAINTS
 U|L|UL [cname1]
 U|L|UL [cname2]-[cname3]
BOUNDS VARIABLES
 U|L|UL [vname1]
 U|L|UL [vname2]-[vname3]
OBJECTIVE VARIABLES
 [vname1]
 [vname2]-[vname3]
Figure 11.3: The sensitivity analysis file format.

The format of the sensitivity specification file is shown in figure 11.3, where capitalized names are keywords, and names in brackets are names of the constraints and variables to be included in the analysis.

The sensitivity specification file has three sections, i.e.

  • BOUNDS CONSTRAINTS: Specifies on which bounds on constraints the sensitivity analysis should be performed.
  • BOUNDS VARIABLES: Specifies on which bounds on variables the sensitivity analysis should be performed.
  • OBJECTIVE VARIABLES: Specifies on which objective coefficients the sensitivity analysis should be performed.

A line in the body of a section must begin with a whitespace. In the BOUNDS sections one of the keys L, U, and LU must appear next. These keys specify whether the sensitivity analysis is performed on the lower bound, on the upper bound, or on both the lower and the upper bound respectively. Next, a single constraint (variable) or range of constraints (variables) is specified.

Recall from Section 11.4.1.1 that equality constraints are handled in a special way. Sensitivity analysis of an equality constraint can be specified with either L, U, or LU, all indicating the same, namely that upper and lower bounds (which are equal) are perturbed simultaneously.

As an example consider

BOUNDS CONSTRAINTS
 L  "cons1"
 U  "cons2"
 LU "cons3"-"cons6"

which requests that sensitivity analysis is performed on the lower bound of the constraint named cons1, on the upper bound of the constraint named cons2, and on both lower and upper bound on the constraints named cons3 to cons6.

It is allowed to use indexes instead of names, for instance

BOUNDS CONSTRAINTS
 L  "cons1"
 U  2
 LU 3 - 6

The character “*” indicates that the line contains a comment and is ignored.

11.6.2. Example: Sensitivity analysis from command line

As an example consider the sensitivity.ssp file shown in Figure 11.4.

* Comment 1

BOUNDS CONSTRAINTS
 U "c1"         * Analyze upper bound for constraint named c1
 U 2            * Analyze upper bound for the second constraint
 U 3-5          * Analyze upper bound for constraint number 3 to number 5

BOUNDS VARIABLES
 L 2-4          * This section specifies which bounds on variables should be analyzed
 L "x11"
OBJECTIVE VARIABLES
 "x11"          * This section specifies which objective coefficients should be analyzed
 2

Figure 11.4: Example of the sensitivity file format.

The command

mosek transport.lp -sen sensitivity.ssp  -d MSK_IPAR_SENSITIVITY_TYPE MSK_SENSITIVITY_TYPE_BASIS

produces the transport.sen file shown below.

BOUNDS CONSTRAINTS
INDEX    NAME             BOUND    LEFTRANGE        RIGHTRANGE       LEFTPRICE        RIGHTPRICE
0        c1               UP       -6.574875e-18    5.000000e+02     1.000000e+00     1.000000e+00
2        c3               UP       -6.574875e-18    5.000000e+02     1.000000e+00     1.000000e+00
3        c4               FIX      -5.000000e+02    6.574875e-18     2.000000e+00     2.000000e+00
4        c5               FIX      -1.000000e+02    6.574875e-18     3.000000e+00     3.000000e+00
5        c6               FIX      -5.000000e+02    6.574875e-18     3.000000e+00     3.000000e+00

BOUNDS VARIABLES
INDEX    NAME             BOUND    LEFTRANGE        RIGHTRANGE       LEFTPRICE        RIGHTPRICE
2        x23              LO       -6.574875e-18    5.000000e+02     2.000000e+00     2.000000e+00
3        x24              LO       -inf             5.000000e+02     0.000000e+00     0.000000e+00
4        x31              LO       -inf             5.000000e+02     0.000000e+00     0.000000e+00
0        x11              LO       -inf             3.000000e+02     0.000000e+00     0.000000e+00

OBJECTIVE VARIABLES
INDEX    NAME                      LEFTRANGE        RIGHTRANGE       LEFTPRICE        RIGHTPRICE
0        x11                       -inf             1.000000e+00     3.000000e+02     3.000000e+02
2        x23                       -2.000000e+00    +inf             0.000000e+00     0.000000e+00

11.6.3. Controlling log output

Setting the parameter

MSK_IPAR_LOG_SENSITIVITY

to 1 or 0 (default) controls whether or not the results from sensitivity calculations are printed to the message stream.

The parameter

MSK_IPAR_LOG_SENSITIVITY_OPT

controls the amount of debug information on internal calculations from the sensitivity analysis.

Mon Sep 14 15:53:07 2009