5 The Command Line Tool¶
5.1 Introduction¶
The MOSEK command line tool is used to solve optimization problems from the operating system command line. It is invoked as follows
mosek [options] [filename]
where both [options]
and [filename]
are optional arguments:
[options]
consists of command line arguments that modify the behavior of MOSEK. They are listed in Sec. 5.5 (Command Line Arguments). In particular, options can be used to set optimizer parameters.[filename]
is a file describing the optimization problem. The MOSEK command line accepts files in any of the supported file formats or in the AMPL.nl
format.
If no arguments are given, MOSEK will display a splash screen and exit.
user@host:~$ mosek/8/tools/platform/linux64x86/bin/mosek
MOSEK Version 8.0.0.32(BETA) (Build date: 2016-7-12 10:29:26)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Linux/64-X86
*** No input file specified. No optimization is performed.
Return code - 0 [MSK_RES_OK]
5.2 Files¶
The MOSEK command line tool communicates with the user via files and prints some execution logs and solution summary to the terminal.
Input files
Optimization problems are read from files. See Sec. 11 (Supported File Formats) for details.
File format conversion
To convert between two file formats supported by MOSEK use the option -x
together with -out
to specify the target file name. The target file type must support the problem type of the source file, otherwise the conversion will be partial. For instance in case a MPS file must be converted in a more readable OPF format, the following line can be used
mosek -x -out lo1.opf lo1.mps
With the -x
option the solver will not actually solve the problem.
Output files
Solutions are written to files:
.bas
- basic solution,.sol
- interior point solution,.itg
- integer solution (the only available solution for mixed-integer problems).
For linear problems both the basic and interior point solution may be present. Infeasibility certificates are stored in the same files. See Sec. 11.8 (The Solution File Format) for details.
5.3 Example¶
To solve a problem stored in file, say lo1.mps
, write:
mosek lo1.mps
The solver will
read
lo1.mps
from disk,solve the problem and display the solution log and
store the relevant solution files if any solution exists; file content explained in Sec. 11.8 (The Solution File Format).
MOSEK Version 8.0.0.34(BETA) (Build date: 2016-8-24 00:51:13)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Linux/64-X86
Open file '/home/andrea/mosek/8/tools/examples/data/lo1.mps'
Reading started.
Using 'obj' as objective vector
Read 13 number of A nonzeros in 0.00 seconds.
Using 'rhs' as rhs vector
Using 'bound' as bound vector
Reading terminated. Time: 0.00
Read summary
Type : LO (linear optimization problem)
Objective sense : max
Scalar variables : 4
Matrix variables : 0
Constraints : 3
Cones : 0
Time : 0.0
Problem
Name : lo1
Objective sense : max
Type : LO (linear optimization problem)
Constraints : 3
Cones : 0
Scalar variables : 4
Matrix variables : 0
Integer variables : 0
Optimizer started.
Interior-point optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Optimizer - threads : 2
Optimizer - solved problem : the primal
Optimizer - Constraints : 3
Optimizer - Cones : 0
Optimizer - Scalar variables : 6 conic : 0
Optimizer - Semi-definite variables: 0 scalarized : 0
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 6 after factor : 6
Factor - dense dim. : 0 flops : 1.06e+02
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 8.0e+00 3.2e+00 3.5e+00 1.00e+00 1.000000000e+01 0.000000000e+00 1.0e+00 0.01
1 4.2e+00 2.5e+00 4.7e-01 0.00e+00 3.093970927e+01 2.766058702e+01 2.6e+00 0.01
2 4.2e-01 2.5e-01 4.6e-02 -1.82e-02 6.511676243e+01 6.308843559e+01 2.6e-01 0.01
3 3.6e-02 2.1e-02 3.9e-03 5.84e-01 8.096141239e+01 8.061962333e+01 2.2e-02 0.01
4 1.5e-05 9.1e-06 1.7e-06 9.43e-01 8.333280389e+01 8.333241803e+01 9.2e-06 0.01
5 1.5e-09 9.1e-10 1.7e-10 1.00e+00 8.333333328e+01 8.333333324e+01 9.2e-10 0.01
Basis identification started.
Primal basis identification phase started.
ITER TIME
0 0.00
Primal basis identification phase terminated. Time: 0.00
Dual basis identification phase started.
ITER TIME
0 0.00
Dual basis identification phase terminated. Time: 0.00
Basis identification terminated. Time: 0.00
Interior-point optimizer terminated. Time: 0.01.
Optimizer terminated. Time: 0.02
Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 8.3333333280e+01 nrm: 5e+01 Viol. con: 1e-08 var: 0e+00
Dual. obj: 8.3333333242e+01 nrm: 4e+00 Viol. con: 2e-10 var: 5e-09
Basic solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 8.3333333333e+01 nrm: 5e+01 Viol. con: 7e-15 var: 0e+00
Dual. obj: 8.3333333245e+01 nrm: 4e+00 Viol. con: 2e-10 var: 5e-09
Optimizer summary
Optimizer - time: 0.02
Interior-point - iterations : 5 time: 0.01
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00
Open file '/home/andrea/mosek/8/tools/examples/data/lo1.sol'
Start writing.
done writing. Time: 0.00
Open file '/home/andrea/mosek/8/tools/examples/data/lo1.bas'
Start writing.
done writing. Time: 0.00
Return code - 0 [MSK_RES_OK]
5.4 Solver Parameters¶
MOSEK comes with a large number of parameters that allows the user to tune the behavior of the optimizer. The typical settings which can be changed with solver parameters include:
choice of the optimizer for linear problems,
choice of primal/dual solver,
turning presolve on/off,
turning heuristics in the mixed-integer optimizer on/off,
level of multi-threading,
feasibility tolerances,
solver termination criteria,
behaviour of the license manager,
and more. All parameters have default settings which will be suitable for most typical users. Each parameter is identified by a unique string name and it can accept either integers or symbolic names, floating point values or symbolic strings. Please refer to Sec. 10.2 (Parameters (alphabetical list sorted by type)) for the complete list of available solver parameters.
5.4.1 Setting from command line¶
Setting solver parameters is possible using the command line option -d
.If multiple parameters must be specified, option -d
must be repeated for each one. For example, the next command will switch off presolve, set a feasibility tolerance and solve the problem from lo1.opf
:
mosek -d MSK_IPAR_PRESOLVE_USE MSK_OFF -d MSK_DPAR_INTPNT_TOL_PFEAS 1.0e-8 lo1.opf
5.4.2 Using the Parameter File¶
Solver parameters can also be set using a parameter file, for example:
BEGIN MOSEK
% This is a comment.
% The subsequent line tells MOSEK that an optimal
% basis should be computed by the interior-point optimizer.
MSK_IPAR_PRESOLVE_USE MSK_OFF
MSK_DPAR_INTPNT_TOL_PFEAS 1.0e-9
END MOSEK
The syntax of the parameter file must obey a few simple rules:
The file must begin with
BEGIN MOSEK
and end withEND MOSEK
.Empty lines and lines starting from a
%
sign are ignored.Each line contains a valid MOSEK parameter name followed by its value.
The parameter file can have any name. Assuming it has been called mosek.par
, it can be used using the -p
option as follows:
mosek -p mosek.par afiro.mps
Command-line parameters override those from the parameter file in case of repetition. For instance
mosek -p mosek.par -d MSK_DPAR_INTPNT_TOL_PFEAS 1.0e-8 afiro.mps
will set MSK_DPAR_INTPNT_TOL_PFEAS
to \(10^{-8}\) using the value provided on the command line.
5.5 Command Line Arguments¶
The following list shows the available command-line arguments for MOSEK:
- -anapro¶
Analyze the problem data.
- -anasoli <name>¶
Analyze the initial solution name e.g.
-anasoli bas
.
- -anasolo <name>¶
Analyze the final solution name e.g.
-anasolo itg
.
- -basi <name>¶
Input basic solution file name.
- -baso <name>¶
Output basic solution file name.
- -d <name> <value>¶
Define the value
value
for the MOSEK parametername
.
- -dbgmem <name>¶
Name of memory debug file.
- -dualout <name>¶
Output dual problem file name.
- -f¶
Complete license information is printed.
- -h, -?¶
Help.
- -inti <name>¶
Input integer solution file name.
- -into <name>¶
Output integer solution file name.
- -itri <name>¶
Input interior point solution file name.
- -itro <name>¶
Output interior point solution file name.
- -info <name>¶
Infeasible subproblem output file name.
- -infrepo <name>¶
Feasibility reparation output file.
- -jsoli <name>¶
Input JSON format solution file name.
- -jsolo <name>¶
Output JSON format solution file name.
- -l,-L <dir>¶
dir
is the directory where the MOSEK license filemosek.lic
is located.
- -max¶
The problem is maximized.
- -min¶
The problem is minimized.
- -n¶
Ignore errors in subsequent parameter settings.
- -optserv <url>¶
Use an OptServer specified by an URL of the form
http://host:port
.
- -out <name>¶
Write the task to a data file named
name
. See Sec. 11 (Supported File Formats).
- -p <name>, -pari <name>¶
Name of the input parameter file.
- -paro <name>¶
Name of the output parameter file.
- -primalrepair¶
Repair a primal infeasible problem. See Sec. 9.2 (Automatic Repair of Infeasible Problems).
- -r¶
If the option is present, the program returns \(-1\) if an error occurred, otherwise \(0\).
- -removeitg¶
Removes all integer constraints after reading the problem.
- -rout <name>¶
If the option is present, the program writes the return code to file
name
.
- -q <name>¶
Name of an optional log file.
- -sen <file>¶
Perform sensitivity analysis based on file.
- -silent¶
As little information as possible is send to the terminal.
- -toconic¶
Translate to conic form after reading.
- -v¶
MOSEK version is printed and no optimization is performed.
- -w¶
If this options is on, then MOSEK will wait for a license.
- -x¶
Do not run the optimizer. Useful for converting between file formats.
- -=¶
List all possible solver parameters with default value, lower bound and upper bound (if applicable).
5.6 The license system¶
MOSEK is a commercial product that always needs a valid license to work. MOSEK uses a third party license manager to implement license checking. The number of license tokens provided determines the number of optimizations that can be run simultaneously.
By default a license token remains checked out for the whole execution of the command line tool. If the license is not unlimited, then the number of tokens determines the maximal number of processes that can run simultaneously. In this case setting the license wait flag with the parameter MSK_IPAR_LICENSE_WAIT
will force MOSEK to wait until a license token becomes available instead of returning with an error.