After studying the examples presented in the previous chapter, then it should be possible to use most of facilities in the MOSEK optimization toolbox. Nevertheless a specification of the main data structures employed by MOSEK and a command reference is provided in the present 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. This structure is used to represent an optimization problem using a number of subfields.
Is a MATLAB structure which contain the problem name, the name of the objective, and so forth. See Section7.1.2.
i subscript for element in
. See (7.1.6).
j subscript for element in
. See (7.1.6).
Numerical value for element in
. See (7.1.6).
k subscript for element in
. See (7.1.7).
i subscript for element in
. See (7.1.7).
j subscript for element in
. See (7.1.7).
Numerical value for element in
. See (7.1.7).
Liner term in the objective.
Is the constraint matrix and it must be a sparse matrix having the same number of rows and columns as there are constraints and variables in the problem. This field should always be defined. Even in the case 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 on 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 on 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 which contains the indexes of the integer constrained variables. Hence, ints.sub is identical to the set in (7.1.5). ints.pri is also a one dimensional array of the length as ints.pri. The ints.pri(k) is the branching priority assigned to the variable ints.sub(k).
A MATLAB cell array which used to define the conic constraint (7.1.4). See Section 7.1.3 for a details about this structure.
A MATLAB structure which contains a guess for the optimal solution which some of the optimizers in MOSEK may exploit. See Section 7.1.4 for datails about 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
![]() |
(7.1.1) |
subject to the functional constraints
![]() |
(7.1.2) |
the variable bound constraints
![]() |
(7.1.3) |
and the conic constraint
![]() |
(7.1.4) |
Finally, some variables may be integer constrained i.e.
![]() |
(7.1.5) |
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 nonzeros 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 parts of the decision variables x such that each decision variable is a member of exactly one vector . For example we could have
![]() |
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 7.1.
|
In Table 7.1 all the parameters is assigned a type where the type int means that all the values in this particular field must be integer. Whereas the type double means that the values in the field can be any real number. The relationship between and
and the subfields of the prob structure is as follows:
The quadratic terms in the objective:
![]() |
(7.1.6) |
Due to by assumption is symmetric, then all elements are assumed to belong to the lower triangular part. If the an element is specified multiple times, then the different elements are added together.
The quadratic terms in the constraints:
![]() |
(7.1.7) |
Due to by assumption is symmetric, then all elements are assumed to belong to the lower triangular part. If the an element is specified multiple times, then the different elements are added together.
This structure is used to store all the names on 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 can have either value 'MSK_CT_QUAD' or 'MSK_CT_RQUAD' which implies the cone is quadratic or rotated quadratic cone respectively.
cones{t}.sub is list of variables indexes specifying which variables are member of the cone.
A MATLAB structure which is used store one or more solution to an optimization problem. The structure has subfield for possible solution type.
Interior (point) solution which is computed by the interior-point optimizer.
Basis solution which computed by the simplex optimizers and basis identification procedure.
Integer solution which is computed by the mixed integer optimizer.
Each of the solutions sol.itr, sol.bas, and sol.int may contain one or more the fields:
Problem status. See Section D.34.
Solution status. See Section D.44.
Constraint status keys. See Section 6.1.
Variable status keys. See Section 6.1.
Conic status keys. See Section 6.1.
Constraint activities i.e. where x is the optimal solution.
Variable activities i.e. the optimal x solution.
Identical 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 fields .skn and .snx cannot occur in the .bas .int solutions. In addition the fields .y, .slc, .suc, .slx, and .sux cannot occur in the int solution because integer problems does not have a well-defined dual and hence cannot have a dual solution.
Results of primal sensitivity analysis.
MATLAB structure with 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 subfields:
Left value in the linearity interval for a lower bound on a varable.
Right value in the linearity interval for a lower bound on a varable.
Left shadow price for a lower bound on a varable.
Right shadow price for lower bound on a varable.
Left value in the linearity interval for an upper bound on a varable.
Right value in the linearity interval for an upper bound on a varable.
Left shadow price for an upper bound on a varables.
Right shadow price for an upper bound on a varables.
Results of dual sensitivity analysis.
Left value of linearity interval for an objective coefficient.
Right value of linearity interval for an objective coefficient.
Left shadow price for an objective coefficients .
Right shadow price for an objective coefficients.
info is a MATLAB structure containing a subfield for each item in the MOSEK optimization task database. For instance the field info.MSK_DINF_BI_CPUTIME specifies the amount of time spend in the basis identification in the last optimization. In Sections D.15 and D.11 are all the items in the task information database shown.
symbcon is a MATLAB structure containing a subfield for each item MOSEK symbolic constant. For instance the field symbcon.MSK_DINF_BI_CPUTIME specifies the value of the symbolic constant MSK_DINF_BI_CPUTIME. In Section D are all the symbolic constants shown.
callback is a MATLAB structure containing which contains the subfields (all are optional):
A MATLAB data structure or just [].
Is the name of a user defined function which must accept two input arguments i.e. for instance
function myfunc(handle,str)
handle will be identical to callback.handle when myfunc is called and str is a line of the log file.
A MATLAB data structure or just [].
Is the name of a user defined function which must accept three input arguments i.e. for instance
function myfunc(handle,where,info)
handle will be identical to callback.iterhandle when myfunc is called and str is a line of the log file. info is the current information database. See 7.1.7 for further details about info data structure.
All functions are documented using the format:
somefunction
The purpose of the function is presented.
[ret1,ret2] = somefunction(arg1,arg2)
A description of this argument.
(optional) A description of this argument which is optional. However, if argument number 3 is specified, then 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 about the use of the function is presented.
mosekopt
Solves an optimization problem. Data specifying the optimization problem can either be read from a MPS file or be imputed directly from MATLAB. It is also possible to write a MPS file using mosekopt.
[rcode,res] = mosekopt(cmd,prob,param,callback)
cmd is a string containing commands to MOSEK about what it should be doing. For example 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:
In the case the problem data are read from a MPS file, then this command controls in which format prob.a is returned. (prob is the problem structure returned by mosekopt.) If aformat(0) is used, then prob.a is a sparse matrix. In the case aformat(1) is used, then the constraint matrix is given by
m = % number of constraints n = % number of variables a = sparse(prob.a.subi,... prob.a.subj,... prob.a.val,... m,n);
Hence, aformat(1) means prob.a is returned in a simple coordinate wise format.
Controls how much information is echoed to the screen. Formally, the command is used as
echo(level)
where level is a nonnegative integer. If level is identical to 0 nothing is echoed. If level is equal to 3, then all messages and errors are echoed to the screen.
Data is read from a file. If
read(name)
is used, then data are read from the file name. Otherwise the data file name in the MOSEK parameter database is used.
The command statuskeys(0) means that all the status keys such as the problem status in the solution is reported using string codes. Whereas the command statuskeys(1) means that all the status keys are reported using numeric codes.
The objective is minimized.
The objective is maximized.
The problem data is written to a MPS file. In the case
write(name)
is used, then the problem data is written to the file name. Otherwise if only write is used, then the data is written to the file specified by the MOSEK parameter database.
When this command is present, then the parameter database is returned in res.param.
When this command is present, then the task information database is returned in res.info. This database contains various task specific information. See Section 7.1.7 for details about the info data structure.
When this command is present, then then the data structure symbcon is returned in res.symbcon. See Section 7.1.8 for details about the symbcon data structure.
Delete the MOSEK environment after each run. This can dramaticly increase license checkout overhead and is therefor only intended as a debug feature.
(optional) A MATLAB structure containing the problem data. See Section 7.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 field must be of a valid type. For example the value of an string parameter must be a string.
(optional) A MATLAB structure defining call back data and functions. See Sections 6.21 and 7.1.9 for details.
Return code. The interpretation of the value of the return code is listed in Chapter D.
(optional) Solution obtained by the interior-point algorithm.
The data structure of the type sol is discussed in Section 7.1.
A MATLAB structure containing the task information database which contains various task related information such as about the number of iterations is used to solve the problem. However, this field is only defined if the string info is present in the cmd command when mosekopt is invoked.
A MATLAB structure which contain the complete MOSEK parameter database. However, this field is only defined if the command param is present in the cmd string when mosekopt is invoked.
Contains the problem data if the problem data was read from a MPS file.
In the follow example it is demonstrated how to list the whole MOSEK parameter database and change the default optimizer to the primal simplex optimizer when the problem is optimized.
% Obtains the parameter database. [rcode,res] = mosekopt('param'); % View the parameter database. res.param param = res.param; % Modifying a parameter. param.MSK_IPAR_OPTIMIZER = 3 % Optimizing a problem. [rcode,res]=mosekopt('minimize info',prob,param); % View the info record. res.info
mskscopt
These functions provides an easy to use but less flexible interface than the mosekopt function. In fact these procedures is just a wrapper around the mosekopt interface and they consists of 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\matlab\solvers
Note for example the command
help msklpopt
will produce some information about how to use msklpopt.
Identical to the res structure returned by mosekopt.
mskgpwri
This functions provides an the means of writing gp problem data to a file format compatible with the command line tool mskexpopt.
res = mskgpwri(c,a,map,filename)
c,a,map is data accepted by mskgpopt. filename is the output file name.
Nothing.
mskgpread
This functions provides an the means of reading gp problem data from a file format compatible with the command line tool mskexpopt.
[c,a,map] = mskgpread (filename)
c,a,map is data accepted by mskgpopt. filename is the input file name.
Data c,a,map as accepted by mskgpopt.
The functions presented in this section are provided as a part of both the MOSEK and MATLAB optimization toolboxes. The MOSEK versions are intended to be highly compatible with MATLAB versions and in practice the small differences should 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 inequalities.
(optional) Lower bounds for the variables. Please use -∞ to represent infinite lower bounds.
(optional) Upper bounds for 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 optionset for the definition of the optimizations options structure. linprog uses the options.
The optimal x solution.
Optimal objective value i.e. .
Is 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 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 the inequalities.
Lagrange multipliers for the equalities.
% Optimizes problem only % having linear inequalities. x = linprog(f,A,b);
quadprog
Solves the quadratic optimization problem:
![]() |
(7.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 MATLAB optimization toolbox, then MOSEK only handles the case where H is positive semidefinite. On the hand MOSEK always computes a global optimum i.e. the objective function does have to be strictly convex.
See (7.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 inequalities.
(optional) Right-hand side for the equalities. Use c=[] if there are no inequalities.
(optional) Lower bounds for the variables. Please use -∞ to represent infinite lower bounds.
(optional) Upper bounds for 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 for the definition of the optimizations options structure. quadprog uses the options.
x solution.
Optimal objective value i.e. .
Is 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 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.
% Optimizes problem only % having linear inequalities. x = quadprog(H,f,A,b);
lsqlin
Solves the linear linear least squares problem:
![]() |
(7.4.2) |
[x,resnorm,residual,exitflag,output,lambda] = lsqlin(C,d,A,b,B,c,l,u,x0,options,options)
A matrix. See problem (7.4.2) for the purpose of the argument.
A vector. See problem (7.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 for the variables. Please use -∞ to represent infinite lower bounds.
(optional) Upper bounds for 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 initial guess for the starting point. This information is ignored by MOSEK.
(optional) An optimization options structure. See the function optionset for the definition of the optimizations options structure. lsqprog uses the options.
The optimal x solution.
The squared norm of the residuals i.e. evaluated at the optimal solution.
Is the residual Cx-d.
Is 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 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.
Comments:
% Solves a linear least % squares problem. x = lsqlin(C,d,A,b);
lsqnonneg
Solves the linear least squares problem:
![]() |
(7.4.3) |
[x,resnorm,residual,exitflag,output,lambda] = lsqnonneg(C,d,x0,options,options)
See problem (7.4.3).
See problem (7.4.3).
(optional) An initial guess for the starting point. This information is ignored by MOSEK.
(optional) An optimizations options structure. See the function optionset for the definition of the optimizations options structure. lsqlin uses the options.
x solution.
Squared of the optimal residuals i.e.
![]() |
evaluated at the optimal solution.
Is the residual Cx-d.
Is 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.
% Solves the problem x = lsqnonneg(C,d);
The procedures in the optimization toolbox is in general dependent on some options which for example control the amount of information displayed and the stopping criteria.
In general due to the MOSEK and MATLAB optimization toolboxes employs different algorithms then the toolboxes uses different options. Therefore, the MOSEK optimization toolbox ignores most of the options recognized by the MATLAB toolbox. In the description of the procedure optimset it is shown which MATLAB options MOSEK recoginize.
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, then the value default is returned.
Value of the required option. If the option does not exists, then [] is returned unless the value 'default' is defined in which case the default value is returned.
See the procedure optimset 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.
However, the optimization option structure can be used to modify all the MOSEK parameters. For a discussion of the MOSEK parameters see Section 6.17.
Used to control how much diagnostic information which is print. It can take the following values:
No diagnostic information is printed.
Diagnostic information is printed.
Is a string which can take the following values.
No output is displayed.
Some output is displayed for each iteration.
Only the final output is displayed.
Maximum number of iterations allowed.
options = optionset(arg1,arg2, param1,value1, param2,value2,...)
(optional) Is allowed to be any of the following two things:
Is the same as using no argument.
The argument is assumed to be a structure containing options. These options are copied to the return options.
(optional) Is a string containing the name of a parameter that should be modified.
(optional) 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 % Modifies the value of parameter % display in the optimization % options structure opt = optionset(opt,'display,'off'); % Returns default options opt = optimset('whatever') % Modify a MOSEK parameter. opt = []; opt = optionset(opt,'MSK_DPAR_INTPNT_TOLMURED',1.0e-14);