After studying the examples presented in the previous chapter, it should be possible to use most of the facilities in the MOSEK optimization toolbox. A more formal specification of the main data structures employed by MOSEK and a command reference are provided in this chapter.
In each of the subsequent sections the most important data structures employed by MOSEK are discussed.
The prob data structure is used to communicate an optimization problem to MOSEK or for MOSEK to return an optimization problem to the user. It defines an optimization problem using a number of subfields.
A MATLAB structure which contains the problem name, the name of the objective, and so forth. See Section 8.1.2.
i subscript for element in
. See (8.1.6).
j subscript for element in
. See (8.1.6).
Numerical value for element in
. See (8.1.6).
k subscript for element in
. See (8.1.7).
i subscript for element in
. See (8.1.7).
j subscript for element in
. See (8.1.7).
Numerical value for element in
. See (8.1.7).
Linear term in the objective.
The constraint matrix. It must be a sparse matrix having the number of rows and columns equivalent to the number of constraints and variables in the problem. This field should always be defined, even if the problem does not have any constraints. In that case a sparse matrix having zero rows and the correct number of columns is the appropriate definition of the field.
Lower bounds of the constraints. -∞ denotes an infinite lower bound. If the field is not defined or blc==[], then all the lower bounds are assumed to be equal to -∞.
Upper bounds of the constraints. ∞ denotes an infinite upper bound. If the field is not defined or buc==[], then all the upper bounds are assumed to be equal to ∞.
Lower bounds on the variables. -∞ denotes an infinite lower bound. If the field is not defined or blx==[], then all the lower bounds are assumed to be equal to -∞.
Upper bounds on the variables. ∞ denotes an infinite upper bound. If the field is not defined or bux==[], then all the upper bounds are assumed to be equal to ∞.
A MATLAB structure which has the subfields
.sub; % Required. .pri; % Subfields.
ints.sub is a one-dimensional array containing the indexes of the integer-constrained variables. Hence, ints.sub is identical to the set in (8.1.5). ints.pri is also a one dimensional array of the same length as ints.sub. The ints.pri(k) is the branching priority assigned to variable index ints.sub(k).
A MATLAB cell array defining the conic constraints (8.1.4). See Section 8.1.3 for details on this structure.
A MATLAB structure containing a guess on the optimal solution which some of the optimizers in MOSEK may exploit. See Section 8.1.4 for details on this structure.
A MATLAB structure which has the subfields:
Indexes of constraints, where upper bounds are analyzed for sensitivity.
Indexes of constraints, where lower bounds are analyzed for sensitivity.
Indexes of variables, where upper bounds are analyzed for sensitivity.
Indexes of variables, where lower bounds are analyzed for sensitivity.
Index of variables where coefficients are analysed for sensitivity.
MOSEK solves an optimization problem which has the form of minimizing or maximizing an objective function
![]() |
(8.1.1) |
subject to the functional constraints
![]() |
(8.1.2) |
the variable bound constraints
![]() |
(8.1.3) |
and the conic constraint
![]() |
(8.1.4) |
Finally, some variables may be integer-constrained, i.e.
![]() |
(8.1.5) |
where x is the decision variables and all the other quantities are the parameters of the problem and they are presented below:
The quadratic terms in the objective are stored in the matrix
as follows
![]() |
In MOSEK it is assumed that is symmetric, i.e.
![]() |
and therefore only the lower triangular part in should be specified.
The quadratic terms in the kth constraint are stored in the
matrix as follows
![]() |
MOSEK assumes that is symmetric, i.e.
![]() |
and therefore only the lower triangular part in should be specified.
The constraint matrix A is given by
![]() |
In MOSEK it is assumed that A is a sparse matrix, i.e. most of the coefficients in A are zero. Therefore, only non-zeros elements in A are stored and worked with. This usually saves a lot of storage and speeds up the computations.
Specifies the conic constraint. Let
![]() |
be vectors comprised of disjoined subsets of the decision variables x (each decision variable is a member of exactly one ), e.g.
![]() |
Next, define
![]() |
where must have one of the following forms
set:
![]() |
Quadratic cone:
![]() |
Rotated quadratic cone:
![]() |
All the parameters of the optimization problem are stored using one or more subfields of the prob structure using the naming convention in Table 8.1.
|
In Table 8.1 all the parameters are listed with their corresponding type. The int type indicates that the field must contain an integer value, double indicates a real number. The relationship between and
and the subfields of the prob structure is as follows:
The quadratic terms in the objective:
![]() |
(8.1.6) |
Since by assumption is symmetric, all elements are assumed to belong to the lower triangular part. If an element is specified multiple times, the different elements are added together.
The quadratic terms in the constraints:
![]() |
(8.1.7) |
Since by assumption is symmetric, all elements are assumed to belong to the lower triangular part. If an element is specified multiple times, the different elements are added together.
This structure is used to store all the names of individual items in the optimization problem such as the constraints and the variables. The structure contains the subfields:
Contains the problem name.
Contains the name of the objective.
Is a MATLAB cell array where names.con{i} contains the name of the ith constraint.
Is a MATLAB cell array where names.var{j} contains the name of the jth constraint.
Is a MATLAB cell array where names.cone{t} contains the name of the tth conic constraint.
cones is a MATLAB cell array containing one structure per cone in the optimization problem, i.e. cones{t} is used to specify the tth cone in the optimization problem.
The structure contains the subfields:
cones{t}.type contains the cone type for the tth cone. The type subfield has one of the values 'MSK_CT_QUAD' or 'MSK_CT_RQUAD', indicating if cone is a quadratic cone or a rotated quadratic cone.
cones{t}.sub is a list of variable indexes specifying which variables are members of the cone.
A MATLAB structure used to store one or more solutions to an optimization problem. The structure has one subfield for each possible solution type.
Interior (point) solution computed by the interior-point optimizer.
Basic solution computed by the simplex optimizers and basis identification procedure.
Integer solution computed by the mixed-integer optimizer.
Each of the solutions sol.itr, sol.bas, and sol.int may contain one or more of the fields:
Problem status. See Appendix F.38.
Solution status. See Appendix F.51.
Constraint status keys. See Table 7.1.
Variable status keys. See Table 7.1.
Conic status keys. See Section 7.1.
Constraint activities, i.e. where x is the optimal solution.
Variable activities, i.e. the optimal x solution.
Identical to sol.slc-sol.suc.
Dual solution corresponding to the lower constraint bounds.
Dual solution corresponding to the upper constraint bounds.
Dual solution corresponding to the lower variable bounds.
Dual solution corresponding to the upper variable bounds.
Dual solution corresponding to the conic constraint.
The primal objective value.
The fields .skn and .snx cannot occur in the .bas and .int solutions. In addition the fields .y, .slc, .suc, .slx, and .sux cannot occur in the .int solution since integer problems does not have a well-defined dual problem, and hence no dual solution.
Results of the primal sensitivity analysis.
MATLAB structure with the subfields:
Left value in the linearity interval for a lower bound.
Right value in the linearity interval for a lower bound.
Left shadow price for a lower bound.
Right shadow price for a lower bound.
Left value in the linearity interval for an upper bound.
Right value in the linearity interval for an upper bound.
Left shadow price for an upper bound.
Right shadow price for an upper bound.
MATLAB structure with the subfields:
Left value in the linearity interval for a lower bound on a variable.
Right value in the linearity interval for a lower bound on a variable.
Left shadow price for a lower bound on a variable.
Right shadow price for a lower bound on a variable.
Left value in the linearity interval for an upper bound on a variable.
Right value in the linearity interval for an upper bound on a variable.
Left shadow price for an upper bound on a variable.
Right shadow price for an upper bound on a variable.
Results of dual the sensitivity analysis.
Left value in linearity interval for an objective coefficient.
Right value in linearity interval for an objective coefficient.
Left shadow price for an objective coefficient.
Right shadow price for an objective coefficient.
info is a MATLAB structure containing a subfield for each item in the MOSEK optimization task database, e.g. the info.MSK_DINF_BI_CPUTIME field specifies the amount of time spent in the basis identification in the last optimization. In Sections F.13 and F.17 all the items in the task information database are listed.
symbcon is a MATLAB structure containing a subfield for each MOSEK symbolic constant, e.g. the field symbcon.MSK_DINF_BI_CPUTIME specifies the value of the symbolic constant “MSK_DINF_BI_CPUTIME”. In Appendix F allthe symbolic constants are listed.
callback A MATLAB structure containing the subfields (all of them are optional):
A MATLAB data structure or just [].
The name of a user-defined function which must accept two input arguments, e.g.
function myfunc(handle,str)
where handle will be identical to callback.handle when myfunc is called, and str is a string of text from the log file.
A MATLAB data structure or just [].
The name of a user-defined function which must accept three input arguments, e.g.
function myfunc(handle,where,info)
where handle will be identical to callback.iterhandle when myfunc is called, where indicates the current progress of the colver and info is the current information database. See 8.1.7 for further details about the info data structure.
All functions are documented using the format:
somefunction
The purpose of the function.
[ret1,ret2] = somefunction(arg1,arg2)
A description of this argument.
(Optional) A description of this argument which is optional. However, if argument 3 is specified, this argument must be specified too.
Another useful argument.
A description of the first return ret1.
(Optional) A description of the second return ret2.
Potentially some comments about the function.
Some examples of the use of the function.
mosekopt
Solves an optimization problem. Data specifying the optimization problem can either be read from a file or be inputted directly from MATLAB. It is also possible to write a file using mosekopt.
[rcode,res] = mosekopt(cmd,prob,param,callback)
cmd is a string containing commands to MOSEK on what to do. E.g. the string `minimize info' means that the objective should be minimized, and information about the optimization process should be returned in res.info. The following commands are recognized by mosekopt:
If the problem data are read from a file, this command controls the format res.prob.a upon return. For aformat(0) res.prob.a is a sparse matrix, and for aformat(1) the constraint matrix is given in coordinate format in which case the sparse matrix can be constructed as
m = % number of constraints n = % number of variables a = sparse(res.prob.a.subi,... res.prob.a.subj,... res.prob.a.val,... m,n);
Runs the problem analyzer.
Controls how much information is echoed to the screen. Here, n must be a nonnegative integer, where 0 means that no information is displayed and 3 means that all information is displayed.
Return the complete task information database in res.info. This database contains various task specific information. See Section 8.1.7 for details the info data structure.
Return the complete parameter database in res.param.
Maximize the objective.
Minimize the objective.
Delete the MOSEK environment after each run. This can increase the license checkout overhead significantly and is therefore only intended as a debug feature.
Request that data is read from a file “name”.
Controls the format of status keys (problem status, solution status etc.) in the returned problem, where statuskeys(0) means that all the status keys are returned as strings, and statuskeys(1) means that all the status keys are returned as numeric codes.
Return the symbcon data structure in res.symbcon. See Section 8.1.8 for details on the symbcon data structure.
Write problem to the file “name”.
(Optional) A MATLAB structure containing the problem data. See Table 8.1 for details.
(Optional) A MATLAB structure which is used to specify algorithmic parameters to MOSEK. The fields of param must be valid MOSEK parameter names. Moreover, the values corresponding to the fields must be of a valid type, i.e. the value of a string parameter must be a string, the value of an integer paramter must be an integer etc.
(Optional) A MATLAB structure defining call-back data and functions. See Sections 7.22 and 8.1.9 for details.
Return code. The interpretation of the value of the return code is listed in Appendix F.
(Optional) Solution obtained by the interior-point algorithm.
The data structure of the type sol is discussed in Section 8.1.
A MATLAB structure containing the task information database which contains various task related information such as the number of iterations used to solve the problem. However, this field is only defined if info appeared in the cmd command when mosekopt is invoked.
A MATLAB structure which contain the complete MOSEK parameter database. However, this field is defined only if the param command is present in cmd when mosekopt is invoked.
Contains the problem data if the problem data was read from a file.
The following example demonstrates how to display the MOSEK parameter database and how to use the primal simplex optimizer instead of the default optimizer.
% Obtain the parameter database. [rcode,res] = mosekopt('param'); % Display the parameter database. res.param param = res.param; % Modify a parameter. param.MSK_IPAR_OPTIMIZER = 3 % Optimize a problem. [rcode,res]=mosekopt('minimize info',prob,param); % Display the information database. res.info
mskscopt
These functions provide an easy-to-use but less flexible interface than the mosekopt function. In fact these procedures is just wrappers around the mosekopt interface and they are defined in MATLAB m-files.
res = msklpopt(c,a,blc,buc,blx,bux,param,cmd); res = mskqpopt(q,c,a,blc,buc,blx,bux,param,cmd); res = mskenopt(d,c,a,blc,buc,blx,bux,param,cmd); res = mskgpopt(d,a,map,param,cmd); res = mskscopt(opr,opri,oprj,oprf,oprg,... c,a,blc,buc,blx,bux,param,cmd)
For a description of the arguments we refer the reader to the actual m files stored in
<root>\mosek\6\toolbox\matlab\solvers
Please note that the MATLAB command help, e.g.
help msklpopt
will produce some usage information for the functions.
Identical to the res structure returned by mosekopt.
mskgpwri
This function writes a Geometric Programming (gp) problem to a file in a format compatible with the mskexpopt command line tool.
res = mskgpwri(c,a,map,filename)
Data in the same format accepted by mskgpopt.
The output file name.
Nothing.
mskgpread
This function reads a Geometric Programming (gp) problem from a file compatible with the mskexpopt command line tool.
[c,a,map] = mskgpread (filename)
The name of the file to read.
Data in the same format accepted by mskgpopt.
The functions presented in this section intents to provide compatibility with the corresponding MATLAB optimization toolbox functions. Although they are not perfectly compatible, the differences usually do not cause any problems.
linprog
Solves the linear optimization problem:
![]() |
[x,fval,exitflag,output,lambda] = linprog(f,A,b,B,c,l,u,x0,options)
The objective function.
Constraint matrix for the less-than equal inequalities. Use A=[] if there are no inequalities.
Right-hand side for the less-than equal inequalities. Use b=[] if there are no inequalities.
(Optional) Constraint matrix for the equalities. Use B=[] if there are no equalities.
(Optional) Right-hand side for the equalities. Use c=[] if there are no equalities.
(Optional) Lower bounds on the variables. Please use -∞ to represent infinite lower bounds.
(Optional) Upper bounds on the variables. Please use ∞ to represent infinite upper bounds.
(Optional) An initial guess for the starting point. This information is ignored by MOSEK.
(Optional) An optimization options structure. See the optimset function for the definition of the optimization options structure. linprog uses the options
The optimal x solution.
The optimal objective value, i.e. .
A number which has the interpretation:
The problem is likely to be either primal or dual infeasible.
The maximum number of iterations was reached.
x is an optimal solution.
Number of iterations spent to reach the optimum.
Always defined as 'large-scale: interior-point'.
Lagrange multipliers for lower bounds l.
Lagrange multipliers for upper bounds u.
Lagrange multipliers for the inequalities.
Lagrange multipliers for the equalities.
% Optimize a problem having only linear inequalities. x = linprog(f,A,b);
quadprog
Solves the quadratic optimization problem:
![]() |
(8.4.1) |
[x,fval,exitflag,output,lambda] = quadprog(H,f,A,b,B,c,l,u,x0,options)
Hessian of the objective function. H must be a symmetric matrix. Contrary to the MATLAB optimization toolbox, MOSEK handles only the cases where H is positive semi-definite. On the other hand MOSEK always computes a global optimum, i.e. the objective function has to be strictly convex.
See (8.4.1) for the definition.
Constraint matrix for the less-than equal inequalities. Use A=[] if there are no inequalities.
Right-hand side for the less-than equal inequalities. Use b=[] if there are no inequalities.
(Optional) Constraint matrix for the equalities. Use B=[] if there are no equalities.
(Optional) Right-hand side for the equalities. Use c=[] if there are no equalities.
(Optional) Lower bounds on the variables. Please use -∞ to represent infinite lower bounds.
(Optional) Upper bounds on the variables. Please use ∞ to represent infinite upper bounds.
(Optional) An initial guess for the starting point. This information is ignored by MOSEK.
(Optional) An optimization options structure. See the optimset function for the definition of the optimizations options structure. quadprog uses the options
The x solution.
The optimal objective value i.e. .
A scalar which has the interpretation:
The problem is likely to be either primal or dual infeasible.
The maximum number of iterations was reached.
x is an optimal solution.
Number of iterations spent to reach the optimum.
Always defined as 'large-scale: interior-point'.
Lagrange multipliers for lower bounds l.
Lagrange multipliers for upper bounds u.
Lagrange multipliers for inequalities.
Lagrange multipliers for equalities.
% Optimizes problem only % having linear inequalities. x = quadprog(H,f,A,b);
lsqlin
Solves the linear least squares problem:
![]() |
(8.4.2) |
[x,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b,B,c,l,u,x0,options)
A matrix. See problem (8.4.2) for the purpose of the argument.
A vector. See problem (8.4.2) for the purpose of the argument.
Constraint matrix for the less-than equal inequalities. Use A=[] if there are no inequalities.
Right-hand side for the less-than equal inequalities. Use b=[] if there are no inequalities.
(Optional) Constraint matrix for the equalities. Use B=[] if there are no equalities.
(Optional) Right-hand side for the equalities. Use c=[] if there are no equalities.
(Optional) Lower bounds on the variables. Please use -∞ to represent infinite lower bounds.
(Optional) Upper bounds on the variables. Please use ∞ to represent infinite lower bounds.
(Optional) An initial guess for the starting point. This information is ignored by MOSEK.
(Optional) An optimization options structure. See the function optimset function for the definition of the optimization options structure. lsqprog uses the options
The optimal x solution.
The squared norm of the optimal residuals, i.e. evaluated at the optimal solution.
The residual Cx-d.
A scalar which has the interpretation:
The problem is likely to be either primal or dual infeasible.
The maximum number of iterations was reached.
x is the optimal solution.
Number of iterations spent to reach the optimum.
Always defined as 'large-scale: interior-point'.
Lagrange multipliers for lower bounds l.
Lagrange multipliers for upper bounds u.
Lagrange multipliers for inequalities.
Lagrange multipliers for equalities.
% Solve a linear least % squares problem. x = lsqlin(C,d,A,b);
lsqnonneg
Solves the linear least squares problem:
![]() |
(8.4.3) |
[x,resnorm,residual,exitflag,output,lambda] = lsqnonneg(C,d,x0,options)
See problem (8.4.3).
See problem (8.4.3).
(Optional) An initial guess for the starting point. This information is ignored by MOSEK.
(Optional) An optimizations options structure. See the optimset function for the definition of the optimization options structure. lsqlin uses the options
The x solution.
The squared norm of the optimal residuals, i.e.
![]() |
evaluated at the optimal solution.
The residual Cx-d.
A number which has the interpretation:
The problem is likely to be either primal or dual infeasible.
The maximum number of iterations was reached.
x is optimal solution.
Number of iterations spend to reach the optimum.
Always defined to be 'large-scale: interior-point'.
Lagrange multipliers for lower bounds l.
Lagrange multipliers for upper bounds u.
Lagrange multipliers for inequalities.
Lagrange multipliers for equalities.
This procedure just provides an easy interface to lsqlin. Indeed all the procedure does is to call lsqlin with the appropriate arguments.
% Solve the problem x = lsqnonneg(C,d);
The procedures in the optimization toolbox accepts some options controlling e.g. the amount of information displayed or the stopping criterion.
In general, due to the fact that MOSEK and MATLAB optimization toolboxes employ different algorithms the toolboxes use different options. Therefore, the MOSEK optimization toolbox ignores most of the options recognized by the MATLAB toolbox. The description of the optimset function lists which MATLAB options MOSEK recoginizes.
optimget
Obtains a value of an optimization parameter.
val = optimget(options,param,default)
The optimization options structure.
Name of the optimization parameter for which the value should be obtained.
(Optional) If param is not defined, the value of default is returned instead.
Value of the required option. If the option does not exist, then [] is returned unless the value 'default' is defined in which case the default value is returned.
See the optimset function for which parameters that can be set.
% Obtain the value of the diagnostics % option. val = optimget(options,'Diagnostics'); % val is equal to the default value. val = optimget(options,'Nopar',1.0e-1);
optimset
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 Appendix E.
Used to control how much diagnostic information is printed. Following values are accepted:
No diagnostic information is printed.
Diagnostic information is printed.
Defines what information is displayed. The following values are accepted:
No output is displayed.
Some output is displayed for each iteration.
Only the final output is displayed.
Maximum number of iterations allowed.
A filename to write the problem to. If equal to the empty string no file is written. E.g the option
Write(myfile.opf)
writes the file myfile.opf in the opf format.
options = optimset(arg1,arg2, param1,value1, param2,value2,...)
(Optional) Is allowed to be any of the following two things:
The same as using no argument.
The argument is assumed to be a structure containing options, which are copied to the return options.
(Optional) A string containing the name of a parameter that should be modified.
(Optional) The new value assigned to the parameter with the name param1.
(Optional) Has the same interpretation as param1.
(Optional) Has the same interpretation as value1.
The updated optimization options structure.
% Obtain the default options. opt = optimset % Modify the value of the parameter % display in the optimization % options structure opt = optimset(opt,'display','on'); % Return default options opt = optimset('whatever') % Modify a MOSEK parameter. opt = []; opt = optimset(opt,'MSK_DPAR_INTPNT_TOLMURED',1.0e-14);