This chapter lists all functionality in the MOSEK Python API.
Functions in the interface grouped by functionality.
Reading and writing data files.
mosek.Task.readbranchpriorities
Reads branching priority data from a file.
mosek.Task.readdata
Reads problem data from a file.
mosek.Task.readparamfile
Reads a parameter file.
mosek.Task.readsolution
Reads a solution from a file.
mosek.Task.readsummary
Prints information about last file read.
mosek.Task.writebranchpriorities
Writes branching priority data to a file.
mosek.Task.writeparamfile
Writes all the parameters to a parameter file.
mosek.Task.writesolution
Write a solution to a file.
Obtain or define a solution.
mosek.Task.deletesolution
Undefines a solution and frees the memory it uses.
mosek.Task.getdualobj
Obtains the dual objective value.
mosek.Task.getprimalobj
Obtains the primal objective value.
mosek.Task.getreducedcosts
Obtains the difference of slx-sux for a sequence of variables.
mosek.Task.getsolution
Obtains the complete solution.
mosek.Task.getsolutioni
Obtains the solution for a single constraint or variable.
mosek.Task.getsolutioninf
Obtains information about a solution.
mosek.Task.getsolutionslice
Obtains a slice of the solution.
mosek.Task.getsolutionstatus
Obtains information about the problem and solution statuses.
mosek.Task.getsolutionstatuskeyslice
Obtains a slice of the solution status keys.
mosek.Task.makesolutionstatusunknown
Sets the solution status to unknown.
mosek.Task.putsolution
Inserts a solution.
mosek.Task.putsolutioni
Sets the primal and dual solution information for a single constraint or variable.
mosek.Task.readsolution
Reads a solution from a file.
mosek.Task.solutiondef
Checks whether a solution is defined.
mosek.Task.solutionsummary
Prints a short summary of a solution.
mosek.Task.undefsolution
Undefines a solution.
mosek.Task.writedata
Writes problem data to a file.
Memory allocation and deallocation.
mosek.Task.checkmemtask
Checks the memory allocated by the task.
mosek.Task.getmemusagetask
Obtains information about the amount of memory used by a task.
Input or change problem specification
mosek.Task.append
Appends a number of variables or constraints to the optimization task.
mosek.Task.appendcone
Appends a new cone constraint to the problem.
mosek.Task.appendcons
Appends one or more constraints and specifies bounds and A coefficients.
mosek.Task.appendvars
Appends one or more variables and specifies bounds on variables, c coefficients and A coefficients.
mosek.Task.chgbound
Changes the bounds for one constraint or variable.
mosek.Task.clonetask
Creates a clone of an existing task.
mosek.Task.commitchanges
Commits all cached problem changes.
mosek.Task.inputdata
Input the linear part of an optimization task in one function call.
mosek.Task.putaij
Changes a single value in the linear coefficient matrix.
mosek.Task.putaijlist
Changes one or more coefficients in A.
mosek.Task.putavec
Replaces all elements in one row or column of A.
mosek.Task.putaveclist
Replaces all elements in one or more rows or columns in A by new values.
mosek.Task.putbound
Changes the bound for either one constraint or one variable.
mosek.Task.putboundlist
Changes the bounds of constraints or variables.
mosek.Task.putboundslice
Modifies bounds.
mosek.Task.putcfix
Replaces the fixed term in the objective.
mosek.Task.putcj
Modifies one linear coefficient in the objective.
mosek.Task.putclist
Modifies a part of c.
mosek.Task.putcone
Replaces a conic constraint.
mosek.Task.putobjsense
Sets the objective sense.
mosek.Task.putqcon
Replaces all quadratic terms in constraints.
mosek.Task.putqconk
Replaces all quadratic terms in a single constraint.
mosek.Task.putqobj
Replaces all quadratic terms in the objective.
mosek.Task.putqobjij
Replaces one of the coefficients in the quadratic term in the objective.
mosek.Task.putvartype
Sets the variable type of one variable.
mosek.Task.putvartypelist
Sets the variable type for one or more variables.
Functionality for deleting problem elements such as variables, constraints or cones.
mosek.Task.remove
The function removes a number of constraints or variables.
mosek.Task.removecone
Removes a conic constraint from the problem.
Functionality for adding problem elements such as variables, constraints or cones.
mosek.Task.append
Appends a number of variables or constraints to the optimization task.
mosek.Task.appendcone
Appends a new cone constraint to the problem.
Functionality for inspecting the problem specification (A,Q, bounds, objective e.t.c).
mosek.Task.getaij
Obtains a single coefficient in A.
mosek.Task.getaslice
Obtains a sequence of rows or columns from A.
mosek.Task.getaslicetrip
Obtains a sequence of rows or columns from A in triplet format.
mosek.Task.getavec
Obtains one row or column of A.
mosek.Task.getavecnumnz
Obtains the number of non-zero elements in one row or column of A.
mosek.Task.getbound
Obtains bound information for one constraint or variable.
mosek.Task.getboundslice
Obtains bounds information for a sequence of variables or constraints.
mosek.Task.getc
Obtains all objective coefficients c.
mosek.Task.getcfix
Obtains the fixed term in the objective.
mosek.Task.getcone
Obtains a conic constraint.
mosek.Task.getconeinfo
Obtains information about a conic constraint.
mosek.Task.getcslice
Obtains a part of c.
mosek.Task.getnumanz
Obtains the number of non-zeros in A.
mosek.Task.getnumcon
Obtains the number of constraints.
mosek.Task.getnumcone
Obtains the number of cones.
mosek.Task.getnumconemem
Obtains the number of members in a cone.
mosek.Task.getnumintvar
Obtains the number of integer constrained variables.
mosek.Task.getnumqconnz
Obtains the number of non-zero quadratic terms in a constraint.
mosek.Task.getnumqobjnz
Obtains the number of non-zero quadratic terms in the objective.
mosek.Task.getnumvar
Obtains the number of variables.
mosek.Task.getobjsense
Gets the objective sense.
mosek.Task.getprobtype
Obtains the problem type.
mosek.Task.getqconk
Obtains all the quadratic terms in a constraint.
mosek.Task.getqobj
Obtains all the quadratic terms in the objective.
mosek.Task.getqobjij
Obtains one coefficient from the quadratic term of the objective
mosek.Task.getvartype
Gets the variable type of one variable.
mosek.Task.getvartypelist
Obtains the variable type for one or more variables.
Functionality related to conic terms in the problem.
mosek.Task.appendcone
Appends a new cone constraint to the problem.
mosek.Task.getcone
Obtains a conic constraint.
mosek.Task.getconeinfo
Obtains information about a conic constraint.
mosek.Task.getnumcone
Obtains the number of cones.
mosek.Task.putcone
Replaces a conic constraint.
mosek.Task.removecone
Removes a conic constraint from the problem.
Functionality related to changing or inspecting bounds on variables or constraints.
mosek.Task.chgbound
Changes the bounds for one constraint or variable.
mosek.Task.getbound
Obtains bound information for one constraint or variable.
mosek.Task.getboundslice
Obtains bounds information for a sequence of variables or constraints.
mosek.Task.putbound
Changes the bound for either one constraint or one variable.
mosek.Task.putboundlist
Changes the bounds of constraints or variables.
mosek.Task.putboundslice
Modifies bounds.
Output stream functions.
mosek.Env.echointro
Prints an intro to message stream.
mosek.Env.linkfiletoenvstream
Directs all output from a stream to a file.
mosek.Task.linkfiletotaskstream
Directs all output from a task stream to a file.
mosek.Task.printdata
Prints a part of the problem data to a stream.
mosek.Task.printparam
Prints the current parameter settings.
mosek.Task.readsummary
Prints information about last file read.
mosek.Task.solutionsummary
Prints a short summary of a solution.
Change or inspect objective function.
mosek.Task.getc
Obtains all objective coefficients c.
mosek.Task.getcfix
Obtains the fixed term in the objective.
mosek.Task.getcslice
Obtains a part of c.
mosek.Task.getdualobj
Obtains the dual objective value.
mosek.Task.getnumqobjnz
Obtains the number of non-zero quadratic terms in the objective.
mosek.Task.getobjname
Obtains the name assigned to the objective function.
mosek.Task.getobjsense
Gets the objective sense.
mosek.Task.getprimalobj
Obtains the primal objective value.
mosek.Task.getqobj
Obtains all the quadratic terms in the objective.
mosek.Task.getqobjij
Obtains one coefficient from the quadratic term of the objective
mosek.Task.putcfix
Replaces the fixed term in the objective.
mosek.Task.putcj
Modifies one linear coefficient in the objective.
mosek.Task.putclist
Modifies a part of c.
mosek.Task.putobjsense
Sets the objective sense.
mosek.Task.putqobj
Replaces all quadratic terms in the objective.
mosek.Task.putqobjij
Replaces one of the coefficients in the quadratic term in the objective.
Inspect statistics from the optimizer.
mosek.Task.appendstat
Appends a record the statistics file.
mosek.Task.getdouinf
Obtains a double information item.
mosek.Task.getintinf
Obtains an integer information item.
mosek.Task.startstat
Starts the statistics file.
mosek.Task.stopstat
Stops the statistics file.
Setting and inspecting solver parameters.
mosek.Task.getdouparam
Obtains a double parameter.
mosek.Task.getintparam
Obtains an integer parameter.
mosek.Task.getnumparam
Obtains the number of parameters of a given type.
mosek.Task.getstrparam
Obtains the value of a string parameter.
mosek.Env.getsymbcondim
Obtains dimensional information for the defined symbolic constants.
mosek.Task.isdouparname
Checks a double parameter name.
mosek.Task.isintparname
Checks an integer parameter name.
mosek.Task.isstrparname
Checks a string parameter name.
mosek.Task.putdouparam
Sets a double parameter.
mosek.Task.putintparam
Sets an integer parameter.
mosek.Task.putnadouparam
Sets a double parameter.
mosek.Task.putnaintparam
Sets an integer parameter.
mosek.Task.putnastrparam
Sets a string parameter.
mosek.Task.putparam
Modifies the value of parameter.
mosek.Task.putstrparam
Sets a string parameter.
mosek.Task.setdefaults
Resets all parameters values.
Functionality related to naming.
mosek.Task.getconname
Obtains a name of a constraint.
mosek.Task.getmaxnamelen
Obtains the maximum length of any objective, constraint, variable or cone name.
mosek.Task.getname
Obtains the name of a cone, a variable or a constraint.
mosek.Task.getnameindex
Checks whether a name has been assigned and returns the index corresponding to the name.
mosek.Task.getobjname
Obtains the name assigned to the objective function.
mosek.Task.gettaskname
Obtains the task name.
mosek.Task.getvarname
Obtains a name of a variable.
mosek.Task.putname
Assigns the name name to a problem item such as a constraint.
mosek.Task.putobjname
Assigns a new name to the objective.
mosek.Task.puttaskname
Assigns a new name to the task.
Functionality related to preallocating space for problem data.
mosek.Task.getmaxnumanz
Obtains number of preallocated non-zeros for A.
mosek.Task.getmaxnumcon
Obtains the number of preallocated constraints in the optimization task.
mosek.Task.getmaxnumcone
Obtains the number of preallocated cones in the optimization task.
mosek.Task.getmaxnumqnz
Obtains the number of preallocated non-zeros for Q (both objective and constraints).
mosek.Task.getmaxnumvar
Obtains the maximum number variables allowed.
mosek.Task.putmaxnumanz
The function changes the size of the preallocated storage for linear coefficients.
mosek.Task.putmaxnumcon
Sets the number of preallocated constraints in the optimization task.
mosek.Task.putmaxnumcone
Sets the number of preallocated conic constraints in the optimization task.
mosek.Task.putmaxnumqnz
Changes the size of the preallocated storage for Q.
mosek.Task.putmaxnumvar
Sets the number of preallocated variables in the optimization task.
Functionality related to integer variables.
mosek.Task.getnumintvar
Obtains the number of integer constrained variables.
mosek.Task.getvarbranchdir
Obtains the branching direction for a variable.
mosek.Task.getvarbranchpri
Obtains the branching priority for a variable.
mosek.Task.getvartype
Gets the variable type of one variable.
mosek.Task.getvartypelist
Obtains the variable type for one or more variables.
mosek.Task.putvarbranchorder
Assigns a branching priority and direction to a variable.
mosek.Task.putvartype
Sets the variable type of one variable.
mosek.Task.putvartypelist
Sets the variable type for one or more variables.
Functionality related to quadratic terms.
mosek.Task.getqconk
Obtains all the quadratic terms in a constraint.
mosek.Task.getqobj
Obtains all the quadratic terms in the objective.
mosek.Task.getqobjij
Obtains one coefficient from the quadratic term of the objective
mosek.Task.putqcon
Replaces all quadratic terms in constraints.
mosek.Task.putqconk
Replaces all quadratic terms in a single constraint.
mosek.Task.putqobj
Replaces all quadratic terms in the objective.
mosek.Task.putqobjij
Replaces one of the coefficients in the quadratic term in the objective.
Functions for diagnosing infeasibility.
mosek.Task.getinfeasiblesubproblem
Obtains an infeasible sub problem.
mosek.Task.relaxprimal
Creates a problem that finds the minimal change to the bounds that makes an infeasible problem feasible.
Functions for optimization.
mosek.Task.checkdata
Checks data of the task.
mosek.Task.optimize
Optimizes the problem.
mosek.Task.optimizeconcurrent
Optimize a given task with several optimizers concurrently.
mosek.Task.optimizetrm
Optimizes the problem.
Functions for sensitivity analysis.
mosek.Task.dualsensitivity
Performs sensitivity analysis on objective coefficients.
mosek.Task.primalsensitivity
Perform sensitivity analysis on bounds.
mosek.Task.sensitivityreport
Creates a sensitivity report.
Functions for testing data validity.
mosek.Task.checkconvexity
Checks if a quadratic optimization problem is convex.
Functions for solving linear systems with the basis matrix.
mosek.Task.initbasissolve
Prepare a task for use with the Task.solvewithbasis function.
mosek.Task.solvewithbasis
Solve a linear equation system involving a basis matrix.
Creation and initialization of environment.
mosek.Env.initenv
Initialize a MOSEK environment.
mosek.Env.putlicensedefaults
Set defaults used by the license manager.
Change elements in the coefficient (A) matrix.
mosek.Task.appendcons
Appends one or more constraints and specifies bounds and A coefficients.
mosek.Task.appendvars
Appends one or more variables and specifies bounds on variables, c coefficients and A coefficients.
mosek.Task.commitchanges
Commits all cached problem changes.
mosek.Task.putaij
Changes a single value in the linear coefficient matrix.
mosek.Task.putaijlist
Changes one or more coefficients in A.
mosek.Task.putavec
Replaces all elements in one row or column of A.
mosek.Task.putaveclist
Replaces all elements in one or more rows or columns in A by new values.
__builtin__.Exception
This exception is raised is an input or output array was shorter than required.
A Mosek Environment
Syntax:
Env ()
Syntax:
Env (str dbgfile)
Arguments:
echointro (int longver)
getsymbcondim (
List|None num,
List|None maxlen)
getversion (
List|None major,
List|None minor,
List|None build,
List|None revision)
initenv ()
isinfinity (double value)
linkfiletoenvstream (
mosek.streamtype whichstream,
str filename,
int append)
putcpudefaults (
mosek.cputype cputype,
int sizel1,
int sizel2)
putdllpath (str dllpath)
putkeepdlls (int keepdlls)
putlicensedefaults (
str licensefile,
array(int) licensebuf,
int licwait,
int licdebug)
set_Stream (mosek.streamtype whichstream)
mosek.Exception
This is an exception class representing MOSEK errors.
Syntax:
Error (mosek.rescode code)
Arguments:
Syntax:
Error (
mosek.rescode code,
str msg)
Arguments:
__builtin__.Exception
This is the base class for exceptions based on MOSEK response codes.
Syntax:
Exception (mosek.rescode code)
Arguments:
A Mosek Optimization task
Syntax:
Task (
int maxnumcon,
int maxnumvar)
Arguments:
append (
mosek.accmode accmode,
int num)
The function removes a number of constraints or variables.
appendcone (
mosek.conetype conetype,
double conepar,
array(int) submem)
Appends a new conic constraint to the problem. Hence, add a constraint
![]() |
to the problem where
is a convex cone.
is a subset of the variables which will be specified by the argument submem. Please note that the sets of variables appearing in different conic constraints must be disjoint.
For an explained code example see section 5.4.
appendcons (
array(int) aptrb,
array(int) aptre,
array(int) asub,
array(double) aval,
array(int) bkc,
array(double) blc,
array(double) buc)
The function appends one or more constraints to the optimization task. The bounds and A are modified as follows
![]() |
(13.6.1) |
and
![]() |
(13.6.2) |
Sets the number of preallocated constraints in the optimization task.
appendstat ()
appendvars (
array(double) cval,
array(int) aptrb,
array(int) aptre,
array(int) asub,
array(double) aval,
array(int) bkx,
array(double) blx,
array(double) bux)
The function appends one or more variables to the optimization problem. Moreover, the function initializes c, A and the bounds corresponding to the appended variables as follows
![]() |
(13.6.3) |
and
![]() |
(13.6.4) |
where numvar is the number variables before the new variables are appended.
Sets the number of preallocated variables in the optimization task.
checkconvexity ()
checkdata ()
checkmemtask (
str file,
int line)
chgbound (
mosek.accmode accmode,
int i,
int lower,
int finite,
double value)
Changes a bound for one constraint or variable. If accmode equals mosek.accmode.con, a constraint bound is changed, otherwise a variable bound is changed.
If lower is non-zero, then the lower bound is changed as follows:
![]() |
Otherwise if lower is zero, then
![]() |
Please note that this function automatically updates the bound key for bound, in particular, if the lower and upper bounds are identical, the bound key is changed to fixed.
Changes the bound for either one constraint or one variable.
Task clonetask ()
commitchanges ()
deletesolution (mosek.soltype whichsol)
dualsensitivity (
array(int) subj,
array(double) leftpricej,
array(double) rightpricej,
array(double) leftrangej,
array(double) rightrangej)
is the left shadow price for the coefficients with index
.
is the right shadow price for the coefficients with index
.
is the left range
for the coefficient with index
.
is the right range
for the coefficient with index
.Calculates sensitivity information for objective coefficients. The indexes of the coefficients to analyze are
![]() |
The results are returned so that e.g
is the left shadow price of the objective coefficient with index
.
The type of sensitivity analysis to perform (basis or optimal partition) is controlled by the parameter mosek.iparam.sensitivity_type.
For an example, please see section 11.5.
Perform sensitivity analysis on bounds.
Creates a sensitivity report.
double getaij (
int i,
int j)
int getapiecenumnz (
int firsti,
int lasti,
int firstj,
int lastj)
Obtains the number non-zeros in a rectangular piece of A, i.e. the number
![]() |
where
means the number of elements in the set
.
This function is not an efficient way to obtain the number of non-zeros in one row or column. In that case use the function Task.getavecnumnz.
Obtains the number of non-zero elements in one row or column of A.
Obtains the number of non-zeros in a row or column slice of A.
getaslice (
mosek.accmode accmode,
int first,
int last,
List|None surp,
array(int) ptrb,
array(int) ptre,
array(int) sub,
array(double) val)
Obtains the number of non-zeros in a row or column slice of A.
int getaslicenumnz (
mosek.accmode accmode,
int first,
int last)
getaslicetrip (
mosek.accmode accmode,
int first,
int last,
List|None surp,
array(int) subi,
array(int) subj,
array(double) val)
Obtains the number of non-zeros in a row or column slice of A.
getavec (
mosek.accmode accmode,
int i,
List|None nzi,
array(int) subi,
array(double) vali)
Obtains one row or column of A in a sparse format. If accmode equals mosek.accmode.con a row is returned and hence:
![]() |
If accmode equals mosek.accmode.var a column is returned, that is:
![]() |
int getavecnumnz (
mosek.accmode accmode,
int i)
getbound (
mosek.accmode accmode,
int i,
List|None bk,
List|None bl,
List|None bu)
getboundslice (
mosek.accmode accmode,
int first,
int last,
array(int) bk,
array(double) bl,
array(double) bu)
getc (array(double) c)
double getcfix ()
getcone (
int k,
List|None conetype,
List|None conepar,
List|None nummem,
array(int) submem)
getconeinfo (
int k,
List|None conetype,
List|None conepar,
List|None nummem)
str getconname (int i)
Obtains the maximum length of any objective, constraint, variable or cone name.