15.2 Command Reference¶
The MOSEK toolbox provides a set of functions to interface to the MOSEK solver.
Main interface
mosekopt
is the main interface to MOSEK.
Helper functions
These functions provide an easy-to-use but less flexible interface than the mosekopt
function. They are just wrappers around the mosekopt
interface written in MATLAB.
Options
Functions for manipulating parameter values.
mskoptimget
: Get the solver parameters.mskoptimset
: Set the solver parameters.
MATLAB Optimization Toolbox compatible functions.
Functions that override standard functions from the MATLAB Optimization Toolbox (the user may choose not to install those).
linprog
: Solves linear optimization problems.quadprog
: Solves quadratic optimization problems.intlinprog
: Solves linear optimization problems with integer variables.lsqlin
: Solves least-squares with linear constraints.lsqnonneg
: Solves least-squares with non-negativity constraints.
15.2.1 Main Interface¶
- rcode, res = mosekopt(cmd, prob, param, callback, optserver)¶
Solves an optimization problem. Data specifying the optimization problem can either be read from a file or be inputted directly from MATLAB. It also makes it possible to write a file and provides other functionalities.
The behavior is specified by the
cmd
parameter which recognizes the following commands:anapro
: Runs the problem analyzer.echo(n)
: Controls how much log information is printed to the screen.n
must be a nonnegative integer, where 0 means silent. See Sec. 7.3.1 (Stream logging).info
: Return the complete task information database inres.info
. See Sec. 7.5 (Retrieving information items).param
: Return the complete parameter database inres.param
. See Sec. 7.4 (Setting solver parameters).primalrepair
: Performs a primal feasibility repair. See Sec. 14.2 (Automatic Repair of Infeasible Problems).maximize
: Maximize the objective.max
: Sets the objective sense (similar tomaximize
), without performing an optimization.minimize
: Minimize the objective.min
: Sets the objective sense (similar tominimize
), without performing an optimization.nokeepenv
: Release resources related to the MOSEK environment. In particular, check in all the licenses currently checked out, see Sec. 10.5 (The license system).read(name)
: Request that data is read from a filename
. See Sec. 7.3.4 (Reading a problem from a file).statuskeys(n)
: Controls the format of status keys (problem status, solution status etc.) in the returned problem:statuskeys(0)
– all the status keys are returned as strings,statuskeys(1)
– all the status keys are returned as numeric codes.
symbcon
: Return the list of symbolic constants inres.symbcon
.write(name)
: Write problem to the filename
. See Sec. 7.3.3 (Saving a problem to a file).log(name)
: Write solver log output to the filename
. See Sec. 7.3.1 (Stream logging).version
: Return the MOSEK version numbers inres.version
.debug(n)
: Prints debug information including license paths.n
must be a nonnegative integer which determines how much to print.toconic prob
: Deprecated! Convert a quadratic problem to conic form.lic
: Provide a license code as the last argument.
- Parameters:
cmd
(string) – The commands to be executed. By default it takes the valueminimize
.prob
(prob
) – A structure containing the problem data. (optional)param
(struct) – A structure specifying MOSEK parameters. See Sec. 7.4 (Setting solver parameters). (optional)callback
(callback
) – A MATLAB structure defining call-back data and functions. See Sec. 7.6 (Progress and data callback). (optional)optserver
(optserver
) – A MATLAB structure specifying the OptServer to be used for remote optimization. (optional)
- Return:
rcode
(rescode
) – A response code. See also Sec. 7.1 (Accessing the solution).res
(res
) – A structure containing solutions and other results from the call. See Sec. 7.1 (Accessing the solution).
15.2.2 Helper Functions¶
- res = msklpopt(c, a, blc, buc, blx, bux, param, cmd)¶
Solves a linear optimization problem of the form
\[\begin{split}\begin{array} {lc} \mbox{minimize} & c^T x \\ \mbox{subject to} & l^c \leq Ax \leq u^c,\\ & l^x \leq x \leq u^x. \end{array}\end{split}\]blc=[]
andbuc=[]
mean that the lower and upper bounds are \(-\infty\) and \(+\infty\), respectively. The same interpretation is used forblx
andbux
. The value-inf
is allowed inblc
andblx
. Similarly,inf
is allowed in buc and bux.- Parameters:
[in]
(string cmd) – The objective function vector.[in]
– A (preferably sparse) matrix.[in]
– Constraints lower bounds.[in]
– Constraints upper bounds.[in]
– Variables lower bounds.[in]
– Variables upper bounds.[in]
– MOSEK parameters. (optional)[in]
– The command list. Seemosekopt
for a list of available commands. (optional)
- Return:
res
(res
) – Solution information.
- res = mskqpopt(q, c, a, blc, buc, blx, bux, param, cmd)¶
Solves the optimization problem
\[\begin{split}\begin{array}{lc} \mbox{minimize} & \half x^T Q x + c^T x\\ \mbox{subject to} & l^c \leq Ax \leq u^c,\\ & l^x\leq x \leq u^x. \end{array}\end{split}\]blc=[]
andbuc=[]
mean that the lower and upper bounds are \(-\infty\) and \(+\infty\), respectively. The same interpretation is used forblx
andbux
. The value-inf
is allowed inblc
andblx
. Similarly,inf
is allowed in buc and bux.- Parameters:
q
(double[]) – The matrix \(Q\), which must be symmetric positive semidefinite.[in]
(string cmd) – The objective function vector.a
(double[][]) – A (preferably) sparse matrix.[in]
– Constraints lower bounds.[in]
– Constraints upper bounds[in]
– Variables lower bounds[in]
– Variables upper bounds[in]
– MOSEK parameters. (optional)[in]
– The command list. Seemosekopt
for a list of available commands. (optional)
- Return:
res
(res
) – Solution information.
15.2.3 Options¶
- val = mskoptimget(options, param, default)¶
Obtains the value of an optimization parameter. See the
mskoptimset
function for which parameters that can be set.- Parameters:
[in]
(string default) – The optimization options structure.[in]
– Name of the optimization parameter for which the value should be obtained.[in]
– Ifparam
is not defined, the value ofdefault
is returned instead. (optional)
- Return:
val
(list) – Value of the required option. If the option does not exist, then[]
is returned unless the valuedefault
is defined in which case the default value is returned.
- options = mskoptimset(arg1, arg2, param1, value1, param2, value2, ...)¶
Obtains and modifies the optimization options structure. Only a subset of the fields in the optimization structure recognized by the MATLAB Optimization Toolbox is recognized by MOSEK. In addition the optimization options structure can be used to modify all the MOSEK specific parameters defined in Sec. 15.5 (Parameters (alphabetical list sorted by type)).
.Diagnostics
Used to control how much diagnostic information is printed. Following values are accepted:off
No diagnostic information is printed.
on
Diagnostic information is printed.
.Display
Defines what information is displayed. The following values are accepted:off
No output is displayed.
iter
Some output is displayed for each iteration.
final
Only the final output is displayed.
.MaxIter
Maximum number of iterations allowed..Write
A file name to write the problem to. If equal to the empty string no file is written. E.g the optionWrite(myfile.opf)
writes the filemyfile.opf
in theopf
format.
- Parameters:
[in]
(None value2) –Is allowed to be any of the following two things (optional):
Any string — The same as using no argument.
A structure — The argument is assumed to be a structure containing options, which are copied to the return options.
[in]
– A string containing the name of a parameter that should be modified. (optional)[in]
– The new value assigned to the parameter with the nameparam1
. (optional)[in]
– Seeparam1
. (optional)[in]
– Seevalue1
. (optional)
- Return:
options
(struct) – The updated optimization options structure.
15.2.4 MATLAB Optimization Toolbox Compatible Functions.¶
- x, fval, exitflag, output = intlinprog(f, intcon, A, b, B, c, l, u, options)¶
- x, fval, exitflag, output = intlinprog(problem)
Solves the mixed-integer linear optimization problem:
\[\begin{split}\begin{array}{lc} \mbox{minimize} & f^T x \\ \mbox{subject to} & A x \leq b,\\ & B x = c,\\ & l \leq x \leq u,\\ & x(\mathrm{intcon}) \in \integral. \end{array}\end{split}\]- Parameters:
[in]
(struct problem) – The objective function.[in]
– The list of variables constrained to the set \(\integral\).[in]
– Constraint matrix for the inequalities. UseA=[]
if there are no inequalities.[in]
– Right-hand side for the inequalities. Useb=[]
if there are no inequalities.[in]
– Constraint matrix for the equalities. (optional)[in]
– Right-hand side for the equalities. (optional)[in]
– Lower bounds for variables. Use-inf
to represent infinite lower bounds. (optional)[in]
– Upper bounds for variables. Useinf
to represent infinite upper bounds. (optional)[in]
–An optimization options structure. See the
mskoptimset
function for the definition of the optimization options structure (optional). This function uses the options.Diagnostics
.Display
.MaxTime
Time limit in seconds..MaxNodes
The maximum number of branch-and-bounds allowed..Write
Name of file to save the problem.
[in]
– A structure containing the fieldsf, intcon, A, b, B, c, l, u
andoptions
.
- Return:
x
(double[]) – The solution \(x\).fval
(double) – The objective \(f^T x\).exitflag
(int) –A number which has the interpretation:
\(1\) The function returned an integer feasible solution.
\(-2\) The problem is infeasible.
\(-4\)
MaxNodes
reached without converging.\(-5\)
MaxTime
reached without converging.
- x, fval, exitflag, output, lambda = linprog(f, A, b, B, c, l, u, options)¶
- x, fval, exitflag, output, lambda = linprog(problem)
Solves the linear optimization problem:
\[\begin{split}\begin{array} {lc} \mbox{minimize} & f^T x \\ \mbox{subject to} & A x \leq b, \\ & B x = c, \\ & l \leq x \leq u. \end{array}\end{split}\]- Parameters:
[in]
(struct lambda) – The objective function.[in]
– Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.[in]
– Right-hand side for the inequalities. Use \(b=[]\) if there are no inequalities.[in]
– Constraint matrix for the equalities. (optional)[in]
– Right-hand side for the equalities. (optional)[in]
– Lower bounds on the variables. Use-inf
to represent infinite lower bounds. (optional)[in]
– Upper bounds on the variables. Useinf
to represent infinite upper bounds. (optional)[in]
–An optimization options structure (optional). See the
mskoptimset
function for the definition of the optimization options structure. This function uses the options.Diagnostics
.Display
.MaxIter
.Simplex
Choose the simplex algorithm:'on'
— the optimizer chooses wither primal or dual simplex (as in"MSK_OPTIMIZER_FREE_SIMPLEX"
),'primal'
— use primal simplex,'dual'
— use dual simplex. The'primal'
and'dual'
values are specific for the MOSEK interface, and not present in the standard MATLAB version..Write
Name of file to save the problem.
[in]
– structure containing the fieldsf
,A
,b
,B
,c
,l
,u
andoptions
.[in]
–A structure with the following fields
.iterations
Number of interior-point iterations spent to reach the optimum..algorithm
Always defined as'MOSEK'
.
[in]
–A struct with the following fields
.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for the inequalities..eqlin
Lagrange multipliers for the equalities.
- Return:
x
(double[]) – The optimal \(x\) solution.fval
(double) – The optimal objective value, i.e. \(f^T x\).exitflag
(int) –A number which has the interpretation [in]:
\(<0\) The problem is likely to be either primal or dual infeasible.
\(=0\) The maximum number of iterations was reached.
\(>0\) \(x\) is an optimal solution.
- x, resnorm, residual, exitflag, output, lambda = lsqlin(C, d, A, b, B, c, l, u, x0, options)¶
Solves the linear least squares problem:
\[\begin{split}\begin{array} {lc} \mbox{minimize} & \half \left\| C x - d\right\|_2^2 \\ \mbox{subject to} & A x \leq b, \\ & B x = c, \\ & l \leq x \leq u. \end{array}\end{split}\]- Parameters:
[in]
(struct options) – The matrix in the objective.[in]
– The vector in the objective.[in]
– Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.[in]
– Right-hand side for the inequalities. Use \(b=[]\) if there are no inequalities.[in]
– Constraint matrix for the equalities. (optional)[in]
– Right-hand side for the equalities. (optional)[in]
– Lower bounds on the variables. Use-inf
to represent infinite lower bounds. (optional)[in]
– Upper bounds on the variables. Useinf
to represent infinite upper bounds. (optional)[in]
– Ignored by MOSEK. (optional)[in]
–An optimization options structure (optional). See the function
mskoptimset
function for the definition of the optimization options structure. This function uses the options.Diagnostics
.Display
.MaxIter
.Write
- Return:
x
(double[]) – The optimal \(x\) solution.resnorm
(double) – The squared norm of the optimal residuals, i.e. \(\left\| Cx-d \right\|_2^2\) evaluated at the optimal solution.residual
(double) – The residual \(C x - d\).exitflag
(int) –A scalar which has the interpretation:
\(<0\) The problem is likely to be either primal or dual infeasible.
\(=0\) The maximum number of iterations was reached.
\(>0\) \(x\) is the optimal solution.
output
(struct) –.iterations
Number of iterations spent to reach the optimum..algorithm
Always defined as'MOSEK'
.
lambda
(struct) –.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for inequalities..eqlin
Lagrange multipliers for equalities.
- x, resnorm, residual, exitflag, output, lambda = lsqnonneg(C, d, x0, options)¶
Solves the linear least squares problem:
\[\begin{split}\begin{array} {lc} \mbox{minimize} & \half \left\|C x - d \right\|_2^2 \\ \mbox{subject to} & x \geq 0. \end{array}\end{split}\]- Parameters:
[in]
(struct options) – The matrix in the objective.[in]
– The vector in the objective.[in]
– Ignored by MOSEK. (optional)[in]
–An optimization options structure (optional). See the
mskoptimset
function for the definition of the optimization options structure. This function uses the options.Diagnostics
.Display
.MaxIter
.Write
- Return:
x
(double[]) – The \(x\) solution.resnorm
(double) – The squared norm of the optimal residuals, i.e. \(\left\| Cx-d \right\|_2^2\) evaluated at the optimal solution.exitflag
(int) –A number which has the interpretation:
\(<0\) The problem is likely to be either primal or dual infeasible.
\(=0\) The maximum number of iterations was reached.
\(>0\) \(x\) is optimal solution.
output
(struct) –.iterations
Number of iterations spend to reach the optimum..algorithm
Always defined to be'MOSEK'
.
lambda
(struct) –.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for inequalities..eqlin
Lagrange multipliers for equalities.
- x, fval, exitflag, output, lambda = quadprog(H, f, A, b, B, c, l, u, x0, options)¶
Solves the quadratic optimization problem:
\[\begin{split}\begin{array} {lc} \mbox{minimize} & \half x^T H x + f^T x \\ \mbox{subject to} & A x \leq b, \\ & B x = c, \\ & l \leq x \leq u. \end{array}\end{split}\]- Parameters:
[in]
(struct options) – Hessian of the objective function. The matrix \(H\) must be symmetric positive semidefinite. Contrary to the MATLAB optimization toolbox, MOSEK handles only the cases where \(H\) is positive semidefinite. On the other hand MOSEK always computes a global optimum.[in]
– The linear term of the objective.[in]
– Constraint matrix for the inequalities. Use \(A=[]\) if there are no inequalities.[in]
– Right-hand side for the inequalities. Use \(b=[]\) if there are no inequalities.[in]
– Constraint matrix for the equalities. (optional)[in]
– Right-hand side for the equalities. (optional)[in]
– Lower bounds on the variables. Use-inf
to represent infinite lower bounds. (optional)[in]
– Upper bounds on the variables. Useinf
to represent infinite upper bounds. (optional)[in]
– Ignored by MOSEK. (optional)[in]
–An optimization options structure (optional). See the
mskoptimset
function for the definition of the optimizations options structure. This function uses the options.Diagnostics
.Display
.MaxIter
.Write
- Return:
x
(double[]) – The \(x\) solution.fval
(double) – The optimal objective value i.e. \(\half x^T H x + f^T x\).exitflag
(int) –A scalar which has the interpretation:
\(<0\) The problem is likely to be either primal or dual infeasible.
\(=0\) The maximum number of iterations was reached.
\(>0\) \(x\) is an optimal solution.
output
(struct) –A structure with the following fields
.iterations
Number of iterations spent to reach the optimum..algorithm
Always defined as'MOSEK'
.
lambda
(struct) –A structure with the following fields
.lower
Lagrange multipliers for lower bounds \(l\)..upper
Lagrange multipliers for upper bounds \(u\)..ineqlin
Lagrange multipliers for inequalities..eqlin
Lagrange multipliers for equalities.