The MOSEK API is developed in the C programming language and in general it is easy to interface the API from C programs. However, on most platforms it is also possible to call the MOSEK API from Fortran and other programming languages such as Java.
The MOSEK API is build around the concept of an optimization task. An optimization task is a data structure which contains:
The purpose of the functions provided by the MOSEK API is to allow the user in a safe and clean way to:
The simplest optimization problem that can be solved using the MOSEK API
is the following form. Minimize or maximize the objective function
![]() |
(1.1) |
![]() |
(1.2) |
![]() |
(1.3) |
Note the unconventional notation that
the first index is and not
. Hence,
and not
is the first variable. The reason for this is that MOSEK is
programmed in C which uses zero as index origin.
Subsequently, we will present each parameter of the optimization problem in some detail.
A conic optimization problem is a generalization of linear optimization where
a constraint of the form
The set is never specified explicitly, because if a variable is not a member of any other cone,
then it is member of this cone.
In addition to linear to conic optimization problems, then MOSEK is
also capable os solving general nonlinear convex optimization problems. A nonlinear
optimization problem is to minimize or maximize an objective function
of the form
Observe this problem is a generalization of linear optimization problem. This implies that
the linear parameters ,
and so forth has the same meaning as in the case of linear
optimization problem. Therefore, subsequently we will present the nonlinear functions and
their parameters.
MOSEK makes two assumptions about the optimization problem.
The first assumption is that all functions are at least twice differentiable.
This can be stated more precisely as and
must be at least twice
differentiable for all
such that
The second assumption is that
![]() |
(1.7) |
![]() |
(1.8) |
If these two assumptions are not satisfied, then it cannot be guaranteed that MOSEK produces correct results or works at all.
Some optimization problems contain the additional restriction that
In the definition of the MOSEK API a consistent naming convention has been used. This implies that whenever for example numcon is an argument in a function definition then it means the number of constraints.
In Table the C variables used to specify the problem parameters are presented.
The relation between the C variables and the problem parameters is as follows:
![]() |
(1.11) |
![]() |
(1.14) |
![]() |
(1.15) |
![]() |
(1.16) |
![]() |
(1.17) |
The central MOSEK data structure is the optimization task. The optimization task is essentially a representation of an optimization problem plus additional information related to the optimization. I.e. the task contains information about whether the objective should be minimized or maximized.
In general the user of MOSEK API cannot change the optimization task directly but must use the functions available in the MOSEK API. MOSEK allocates the space it needs for its internal data structures. Hence, MOSEK and the user application never share space. This implies the user application can freely deallocate space used while inputting data to MOSEK as showed in the following code fragment
r = MSK_inputdata(task, numcon,numvar, numcon,numvar, c,0.0, ptrb, ptre, subj, val, bkc, blc, buc, bkx, blx, bux); free(c); free(ptrb); /* ... */
Initially when an optimization is created, then user must supply some defaults for the number of constraints and variables. In general it is recommended to supply values which close to expected values. However, if constraints and variables later are added, then the optimization task will expand the task dimensions as needed.
All definitions in the MOSEK API are prefixed with an MSK. Hence, if the user's application avoids names and definitions starting with MSK, then name clashes should not occur.
All functions in the MOSEK API returns
a so-called response value. The possible response values and their interpretation
can be seen in Section .
Type definition | Description |
MSKcallbackfunc | Definition of the progress call-back function. |
MSKctrlcfunc | A ctrl-c callback function. |
MSKexitfunc | A user defined exit function which is called in case of fatal errors. |
MSKfreefunc | A user defined free function. |
MSKmallocfunc | A user defined malloc function. |
MSKnlgetspfunc | Definition of structural nonlinear function call-back. |
MSKnlgetvafunc | Definition of numerical nonlinear function call-back. |
MSKstreamfunc | A function of this type can be linked to any stream. |
Definition of the progress call-back function. The progress call-back function is a user defined function which will be called by MOSEK occasionally during the optimization process. In particular the call-back function is called at the beginning of each iteration in interior-point optimizer. For the simplex optimizers then MSK_IPAR_SIM_LOG_FREQ controls how frequent the call-back is called.
Typically the user defined call-back function displays information about the solution process. The call-back function can also be used to terminate the optimization process because if the progress call-back function returns a nonzero value, then the optimization process is aborted.
It is important that the user defined call-back function does not modify the optimization task, this will lead to undefined and incorrect results. The only MOSEK functions that can be called safely from within the user defined call-back function are MSK_getdouinf and MSK_getintinf which accesses the task information database. The items in task information database are updated during the optimization process.
MSKintt MSKcallbackfunc (MSKtask_t task, void * usrptr, MSKcallbackcodee caller);
If the return is nonzero, then MOSEK terminates whatever it is doing and returns control to the calling application.
Definition of a user defined ctrl-c function. If the function returns a nonzero value, then MOSEK assumes ctrl-c has been pressed.
MSKintt MSKctrlcfunc (void * usrptr);
If the return is nonzero, then MOSEK terminates whatever it is doing and returns control to the calling application.
A user defined exit function which is called in case of fatal errors.
void MSKexitfunc (void * usrptr, MSKCONST MSKchart * file, MSKintt line, MSKCONST MSKchart * msg);
A user defined free function.
void MSKfreefunc (MSKvoid_t usrptr, MSKCONST void * buffer);
A user defined malloc function.
void * MSKmallocfunc (MSKvoid_t usrptr, size_t size);
A pointer to the allocated memory.
Type definition of the call-back function which is used to provide
structural information about the nonlinear functions and
in the optimization problem.
Hence, it is the user's responsibility to provide a function satisfying the definition. The function is inputted to MOSEK using the API function MSK_putnlfunc.
MSKintt MSKnlgetspfunc (void * nlhandle, MSKintt * numgrdobjnz, MSKidxt * grdobjsub, MSKidxt i, MSKintt * convali, MSKintt * grdconinz, MSKidxt * grdconisub, MSKintt yo, MSKintt numycnz, MSKCONST MSKidxt * ycsub, MSKlintt maxnumhesnz, MSKlintt * numhesnz, MSKidxt * hessubi, MSKidxt * hessubj);
![]() |
(1.19) |
If the return is nonzero, then MOSEK assumes an error during the structure computation.
Type definition of the call-back function which is used to
provide structural as well as numerical information about
the nonlinear functions and
in the optimization
problem.
For later use we need the definition of the Lagrangian which is given by
MSKintt MSKnlgetvafunc (void * nlhandle, MSKCONST MSKrealt * xx, MSKrealt yo, MSKCONST MSKrealt * yc, MSKrealt * objval, MSKintt * numgrdobjnz, MSKidxt * grdobjsub, MSKrealt * grdobjval, MSKintt numi, MSKCONST MSKidxt * subi, MSKrealt * conval, MSKCONST MSKlidxt * grdconptrb, MSKCONST MSKlidxt * grdconptre, MSKidxt * grdconsub, MSKrealt * grdconval, MSKrealt * grdlag, MSKlintt maxnumhesnz, MSKlintt * numhesnz, MSKidxt * hessubi, MSKidxt * hessubj, MSKrealt * hesval);
Observe both grdconsub and grdconval should be updated when required.
The gradient data are stored as follows
The following data structure
If the return is nonzero, then MOSEK assumes an error happend during the function evaluation.
A function of this type can be linked to any of the MOSEK streams. This implies if a message is send to the stream to which the function is linked, then the function is called by MOSEK and the argument str will be identical to the message. Hence, the user can decide what should happen to message.
void MSKstreamfunc (void * handle, MSKCONST MSKstring_t str);
As already mentioned the MOSEK API consists of a number of data structures and functions which operates on the data structures.
In Section all functions available in the MOSEK API are listed in
alphabetic order together with a brief description. This Section is followed by detail description
of MOSEK functions.
Another way to learn about the parameters and functions included in MOSEK API is to study the file mosek.h supplied with all versions of the MOSEK API. This file contains the definition of all the data structures and functions definitions provided by the MOSEK API.
For each function available in the MOSEK API then a summary of the following form is provided.
A description of the purpose of the function presented.
int somefunction(int arg1, char *arg2, char *arg3)The syntax for the function call is presented.
Some comments about the function may be presented.
Presents the possible return values.