5. MOSEK and AMPL


AMPL is a modeling language for specifying linear and nonlinear optimization models in a natural way. AMPL also makes it easy to solve the problem and e.g. display the solution or part of it.

We will not discuss the specifics of the AMPL language here but instead refer the reader to [20] and the AMPL website http://www.ampl.com.

AMPL cannot solve optimization problems by itself but requires a link to an appropriate optimizer such as MOSEK. The MOSEK distribution includes an AMPL link which makes it possible to use MOSEK as an optimizer within AMPL.

5.1. Invoking the AMPL shell

The MOSEK distribution by default comes with the AMPL shell installed. To invoke the AMPL shell type:

mampl

5.2. Applicability

It is possible to specify problems in AMPL that cannot be solved by MOSEK. The optimization problem must be a smooth convex optimization problem as discussed in Section 9.4.

5.3. An example

In many instances, you can successfully apply MOSEK simply by specifying the model and data, setting the solver option to MOSEK, and typing solve. First to invoke the AMPL shell type:

mampl

when the AMPL shell has started type the commands:

ampl: model diet.mod;
ampl: data diet.dat;
ampl: option solver mosek;
ampl: solve;

The resulting output is:

MOSEK finished.
Problem status    - PRIMAL_AND_DUAL_FEASIBLE
Solution status   - OPTIMAL
Primal objective  - 14.8557377
Dual objective    - 14.8557377

Objective = Total_Cost

5.4. Determining the outcome of an optimization

The AMPL parameter solve_result_num is used to indicate the outcome of the optimization process. It is used as follows

ampl: display solve_result_num

Please refer to table 5.1 for possible values of this parameter.

Value Message
0 the solution is optimal.
100 suboptimal primal solution.
101 superoptimal (dual feasible) solution.
150 the solution is near optimal.
200 primal infeasible problem.
300 dual infeasible problem.
400 too many iterations.
500 solution status is unknown.
501 ill-posed problem, solution status is unknown.
501 The value - 501 is a MOSEK response code.
  See Appendix I.40 for all MOSEK response codes.
Table 5.1: Interpretation of solve_result_num.

5.5. Optimizer options

5.5.1. The MOSEK parameter database

The MOSEK optimizer has options and parameters controlling such things as the termination criterion and which optimizer is used. These parameters can be modified within AMPL as shown in the example below:

ampl: model diet.mod;
ampl: data diet.dat;
ampl: option solver mosek;
ampl: option mosek_options
ampl? 'msk_ipar_optimizer = msk_optimizer_primal_simplex \
ampl? msk_ipar_sim_max_iterations = 100000';
ampl: solve;

In the example above a string called mosek_options is created which contains the parameter settings. Each parameter setting has the format

parameter name = value

where “parameter name” can be any valid MOSEK parameter name. See Appendix H for a description of all valid MOSEK parameters.

An alternative way of specifying the options is

ampl: option mosek_options
ampl? 'msk_ipar_optimizer = msk_optimizer_primal_simplex'
ampl? ' msk_ipar_sim_max_iterations = 100000';

New options can also be appended to an existing option string as shown below

ampl: option mosek_options $mosek_options
ampl? ' msk_ipar_sim_print_freq = 0 msk_ipar_sim_max_iterations = 1000';

The expression $mosek_optionsexpands to the current value of the option. Line two in the example appends an additional value msk_ipar_sim_max_iterations to the option string.

5.5.2. Options

5.5.2.1. outlev

MOSEK also recognizes the outlev option which controls the amount of printed output. 0 means no printed output and a higher value means more printed output. An example of setting outlev is as follows:

ampl: option mosek_options 'outlev=2';

5.5.2.2. wantsol

MOSEK recognize the option wantsol. We refer the reader to the AMPL manual [20] for details about this option.

5.6. Constraint and variable names

AMPL assigns meaningfull names to all the constraints and variables. Since MOSEK uses item names in error and log messages, it may be useful to pass the AMPL names to MOSEK. Using the command

ampl: option mosek_auxfiles rc;

before the

solve;

command makes MOSEK obtain the constraint and variable names automatically.

5.7. Which solution is returned to AMPL

The MOSEK optimizer can produce three types of solutions: basic, integer, and interior point solutions. For nonlinear problems only an interior solution is available. For linear optimization problems optimized by the interior-point optimizer with basis identification turned on both a basic and an interior point solution are calculated. The simplex algorithm produces only a basic solution. Whenever both an interior and a basic solution are available, the basic solution is returned. For problems containing integer variables, the integer solution is returned to AMPL.

5.8. Hot-start

Frequently, a sequence of optimization problems is solved where each problem differs only slightly from the previous problem. In that case it may be advantageous to use the previous optimal solution to hot-start the optimizer. Such a facility is available in MOSEK only when the simplex optimizer is used.

The hot-start facility exploits the AMPL variable suffix sstatus to communicate the optimal basis back to AMPL, and AMPL uses this facility to communicate an initial basis to MOSEK. The following example demonstrates this feature.

ampl: model diet.mod;
ampl: data diet.dat;
ampl: option solver mosek;
ampl: option mosek_options
ampl? 'msk_ipar_optimizer = msk_optimizer_primal_simplex outlev=2';
ampl: solve;
ampl: display Buy.sstatus;
ampl: solve;

The resulting output is:

Accepted: msk_ipar_optimizer                  = MSK_OPTIMIZER_PRIMAL_SIMPLEX
Accepted: outlev                              = 2

Computer   - Platform               : Linux/64-X86
Computer   - CPU type               : Intel-P4
MOSEK      - task name              :
MOSEK      - objective sense        : min
MOSEK      - problem type           : LO (linear optimization problem)
MOSEK      - constraints            : 7                 variables              : 9
MOSEK      - integer variables      : 0
Optimizer started.
Simplex optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Presolve   - Stk. size (kb) : 0
Eliminator - tries                  : 0                 time                   : 0.00
Eliminator - elim's                 : 0
Lin. dep.  - tries                  : 1                 time                   : 0.00
Lin. dep.  - number                 : 0
Presolve terminated. Time: 0.00
Primal simplex optimizer started.
Primal simplex optimizer setup started.
Primal simplex optimizer setup terminated.
Optimizer  - solved problem         : the primal
Optimizer  - constraints            : 7                 variables              : 9
Optimizer  - hotstart               : no
ITER      DEGITER(%)  PFEAS       DFEAS       POBJ                  DOBJ                  TIME      TOTTIME
0         0.00        1.40e+03    NA          1.2586666667e+01      NA                    0.00      0.01
3         0.00        0.00e+00    NA          1.4855737705e+01      NA                    0.00      0.01
Primal simplex optimizer terminated.
Simplex optimizer terminated. Time: 0.00.
Optimizer terminated. Time: 0.01
Return code - 0  [MSK_RES_OK]
MOSEK finished.
Problem status    : PRIMAL_AND_DUAL_FEASIBLE
Solution status   : OPTIMAL
Primal objective  : 14.8557377
Dual objective    : 14.8557377

Objective = Total_Cost
Buy.sstatus [*] :=
'Quarter Pounder w/ Cheese'  bas
  'McLean Deluxe w/ Cheese'  low
                  'Big Mac'  low
               Filet-O-Fish  low
        'McGrilled Chicken'  low
             'Fries, small'  bas
         'Sausage McMuffin'  low
           '1% Lowfat Milk'  bas
             'Orange Juice'  low
;
Accepted: msk_ipar_optimizer                  = MSK_OPTIMIZER_PRIMAL_SIMPLEX
Accepted: outlev                              = 2
Basic solution
Problem status  : UNKNOWN
Solution status : UNKNOWN
Primal - objective: 1.4855737705e+01   eq. infeas.: 3.97e+03 max bound infeas.: 2.00e+03
Dual   - objective: 0.0000000000e+00   eq. infeas.: 7.14e-01 max bound infeas.: 0.00e+00

Computer   - Platform               : Linux/64-X86
Computer   - CPU type               : Intel-P4
MOSEK      - task name              :
MOSEK      - objective sense        : min
MOSEK      - problem type           : LO (linear optimization problem)
MOSEK      - constraints            : 7                 variables              : 9
MOSEK      - integer variables      : 0
Optimizer started.
Simplex optimizer started.
Presolve started.
Presolve   - Stk. size (kb) : 0
Eliminator - tries                  : 0                 time                   : 0.00
Eliminator - elim's                 : 0
Lin. dep.  - tries                  : 0                 time                   : 0.00
Lin. dep.  - number                 : 0
Presolve terminated. Time: 0.00
Primal simplex optimizer started.
Primal simplex optimizer setup started.
Primal simplex optimizer setup terminated.
Optimizer  - solved problem         : the primal
Optimizer  - constraints            : 7                 variables              : 9
Optimizer  - hotstart               : yes
Optimizer  - Num. basic             : 7                 Basis rank             : 7
Optimizer  - Valid bas. fac.        : no
ITER      DEGITER(%)  PFEAS       DFEAS       POBJ                  DOBJ                  TIME      TOTTIME
0         0.00        0.00e+00    NA          1.4855737705e+01      NA                    0.00      0.01
0         0.00        0.00e+00    NA          1.4855737705e+01      NA                    0.00      0.01
Primal simplex optimizer terminated.
Simplex optimizer terminated. Time: 0.00.
Optimizer terminated. Time: 0.01
Return code - 0  [MSK_RES_OK]
MOSEK finished.
Problem status    : PRIMAL_AND_DUAL_FEASIBLE
Solution status   : OPTIMAL
Primal objective  : 14.8557377
Dual objective    : 14.8557377

Objective = Total_Cost
Please note that the second solve takes fewer iterations since the previous optimal basis is reused.

5.9. Conic constraints

AMPL does not support conic constraints. It is of course possible to specify the conic quadratic constraint

\begin{displaymath}\nonumber{}x\geq{}\left\|z\right\|\end{displaymath}

in AMPL but it will be treated as a general nonlinear constraint. MOSEK cannot analyze the nonlinear constraints and discover that such a constraint is actually quadratic cone constraint. Therefore, an explicit method for specifying a conic constraints are needed.

The AMPL example

suffix cone integer; # Mosek specific suffix
option presolve 0;   # AMPL presolve should be turned off when the problem
                     # has conic constraints

var x;
var y;
var z;

minimize obj: y;
subject to con: x + z = y;

# Represents the conic constraint y >= sqrt(x^2+z^2)
let y.cone := -1;
let x.cone := 1;
let z.cone := 1;

option solver mosek;
option mosek_options 'outlev=2';
solve;

solves the example

\begin{math}\nonumber{}\begin{array}{lccl}\nonumber{}\mbox{minimize} & y &  & \\\nonumber{}\mbox{subject to} & x+z & = & y,\\\nonumber{} & y\geq{}\sqrt{x^{2}+z^{2}}. &  &\end{array}\end{math} (5.9.1)

The idea of the MOSEK specific extension is to use a variable suffix named cone to specify the index of the cone that variable is member of. If a variable is not a member of a cone, then cone suffix of the variable should not be specified. Alternatively the cone suffix can be set to 0. The cone suffix should be negative if the variable is on the left side of

\begin{displaymath}\nonumber{}x\geq{}\left\|z\right\|.\end{displaymath}

For each cone there should be at least one variable having a negative cone suffix and at most two variable can have negative cone suffix. If two variables have negative cone suffix, then a rotated quadratic cone is specified. Hence,

let y.cone := -1;
let x.cone := -1;
let z.cone := 1;

is the same as the rotated quadratic cone constraint

\begin{displaymath}\nonumber{}2xy\geq{}z^{2}\mbox{ and }x,y\geq{}0.\end{displaymath}

Finally, some observations about the MOSEK specific conic extension to AMPL are:

5.10. Sensitivity analysis

MOSEK can calculate sensitivity information for the objective and constraints. To enable sensitivity information set the option:

sensitivity = 1

Results are returned in variable/constraint suffixes as follows:

For ranged constraints sensitivity information is returned only for the lower bound.

The example below returns sensitivity information on the diet model.

ampl: model diet.mod;
ampl: data diet.dat;
ampl: option solver mosek;
ampl: option mosek_options 'sensitivity=1';

ampl: solve;
#display sensitivity information and current solution.
ampl: display _var.down,_var.current,_var.up,_var;
#display sensitivity information and optimal dual values.
ampl: display _con.down,_con.current,_con.up,_con;

The resulting output is:

Return code - 0  [MSK_RES_OK]
MOSEK finished.
Problem status    : PRIMAL_AND_DUAL_FEASIBLE
Solution status   : OPTIMAL
Primal objective  : 14.8557377
Dual objective    : 14.8557377


suffix up OUT;
suffix down OUT;
suffix current OUT;
Objective = Total_Cost
:  _var.down _var.current       _var.up        _var      :=
1   1.37385       1.84             1.86075    4.38525
2   1.8677        2.19      Infinity          0
3   1.82085       1.84      Infinity          0
4   1.35466       1.44      Infinity          0
5   1.57633       2.29      Infinity          0
6   0.094         0.77             0.794851   6.14754
7   1.22759       1.29      Infinity          0
8   0.57559       0.6              0.910769   3.42213
9   0.657279      0.72      Infinity          0
;
ampl: display _con.down,_con.current,_con.up,_con;
:     _con.down    _con.current   _con.up      _con       :=
1   -Infinity           2000      3965.37    0
2         297.6          350       375       0.0277049
3   -Infinity             55       172.029   0
4          63.0531       100       195.388   0.0267541
5   -Infinity            100       132.213   0
6   -Infinity            100       234.221   0
7          17.6923       100       142.821   0.0248361
;

5.11. Using the command line version of the AMPL interface

AMPL can generate a data file containing all the optimization problem and all relevant information which can then be read and solved by the MOSEK command line tool.

When the problem has been loaded into AMPL, the commands

ampl: option auxfiles rc;
ampl: write  bprob;

will make AMPL write the appropriate data files, i.e.

prob.nl
prob.col
prob.row

Then the problem can be solved using the command line version of MOSEK as follows

mosek prob.nl outlev=10 -a

The -a command line option indicates that MOSEK is invoked in AMPL mode. When MOSEK is invoked in AMPL mode the normal MOSEK command line options should appear after the -a option except for the file name which should be the first argument. As the above example demonstrates MOSEK accepts command line options as specified by the AMPL “convention”. Which command line arguments MOSEK accepts in AMPL mode can be viewed by executing

mosek -= -a

For linear, quadratic and quadratic constrained problems a text file representation of the problem can be obtained using one of the commands

mosek prob.nl -a -x -out prob.mps
mosek prob.nl -a -x -out prob.opf
mosek prob.nl -a -x -out prob.lp
Wed Feb 29 16:20:49 2012