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)
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.
getcslice ( int first, int last, array(double) c)
double getdouparam (mosek.dparam param)
getdualobj ( mosek.soltype whichsol, List|None dualobj)
Task getinfeasiblesubproblem (mosek.soltype whichsol)
Creates a problem that finds the minimal change to the bounds that makes an infeasible problem feasible.
int getintinf (mosek.iinfitem whichiinf)
int getintparam (mosek.iparam param)
getmaxnamelen (List|None maxlen)
int getmaxnumanz ()
getmaxnumcon (List|None maxnumcon)
getmaxnumcone (List|None maxnumcone)
getmaxnumqnz (List|None maxnumqnz)
getmaxnumvar (List|None maxnumvar)
getmemusagetask ( List|None meminuse, List|None maxmemuse)
str getname ( mosek.problemitem whichitem, int i, List|None len)
Obtains the maximum length of any objective, constraint, variable or cone name.
int getnameindex ( mosek.problemitem whichitem, str name, List|None asgn)
int getnumanz ()
int getnumcon ()
int getnumcone ()
getnumconemem ( int k, List|None nummem)
getnumintvar (List|None numintvar)
getnumparam ( mosek.parametertype partype, List|None numparam)
int getnumqconnz (int i)
int getnumqobjnz ()
int getnumvar ()
str getobjname (List|None len)
int getobjsense ()
Sets the objective sense.
double getprimalobj (mosek.soltype whichsol)
getprobtype (List|None probtype)
int getqconk ( int k, List|None qcsurp, array(int) qcsubi, array(int) qcsubj, array(double) qcval)
getqobj ( List|None qosurp, List|None numqonz, array(int) qosubi, array(int) qosubj, array(double) qoval)
getqobjij ( int i, int j, List|None qoij)
getsolution ( mosek.soltype whichsol, List|None prosta, List|None solsta, array(int) skc, array(int) skx, array(int) skn, array(double) xc, array(double) xx, array(double) y, array(double) slc, array(double) suc, array(double) slx, array(double) sux, array(double) snx)
Obtains the complete solution.
Consider the case of linear programming. The primal problem is given by
![]() |
(13.6.6) |
and the corresponding dual problem is
![]() |
(13.6.7) |
In this case the mapping between variables and arguments to the function is as follows:
xx: Corresponds to variable x.
y: Corresponds to variable y.
slc: Corresponds to variable .
suc: Corresponds to variable .
slx: Corresponds to variable .
sux: Corresponds to variable .
xc: Corresponds to Ax.
The meaning of the values returned by this function depend on the solution status returned in the argument solsta. The most important possible values of solsta are:
mosek.solsta.optimal An optimal solution satisfying the optimality criteria for continuous problems is returned.
mosek.solsta.integer_optimal An optimal solution satisfying the optimality criteria for integer problems is returned.
mosek.solsta.prim_infeas_cer A primal certificate of infeasibility is returned.
mosek.solsta.dual_infeas_cer A dual certificate of infeasibility is returned.
Obtains the solution for a single constraint or variable.
Obtains a slice of the solution.
getsolutioni ( mosek.accmode accmode, int i, mosek.soltype whichsol, List|None sk, List|None x, List|None sl, List|None su, List|None sn)
Obtains the complete solution.
Obtains a slice of the solution.
getsolutioninf ( mosek.soltype whichsol, List|None prosta, List|None solsta, List|None primalobj, List|None maxpbi, List|None maxpcni, List|None maxpeqi, List|None maxinti, List|None dualobj, List|None maxdbi, List|None maxdcni, List|None maxdeqi)
getsolutionslice ( mosek.soltype whichsol, mosek.solitem solitem, int first, int last, array(double) values)
Obtains a slice of the solution.
Consider the case of linear programming. The primal problem is given by
![]() |
(13.6.8) |
and the corresponding dual problem is
![]() |
(13.6.9) |
The solitem argument determines which part of the solution is returned:
mosek.solitem.xx: The variable values return x.
mosek.solitem.y: The variable values return y.
mosek.solitem.slc: The variable values return .
mosek.solitem.suc: The variable values return .
mosek.solitem.slx: The variable values return .
mosek.solitem.sux: The variable values return .
A conic optimization problem has the same primal variables as in the linear case. Recall that the dual of a conic optimization problem is given by:
![]() |
(13.6.10) |
This introduces one additional dual variable . This variable can be acceded by selecting solitem as mosek.solitem.snx.
The meaning of the values returned by this function also depends on the solution status which can be obtained with Task.getsolutionstatus. Depending on the solution status value will be:
mosek.solsta.optimal A part of the optimal solution satisfying the optimality criteria for continuous problems.
mosek.solsta.integer_optimal A part of the optimal solution satisfying the optimality criteria for integer problems.
mosek.solsta.prim_infeas_cer A part of the primal certificate of infeasibility.
mosek.solsta.dual_infeas_cer A part of the dual certificate of infeasibility.
Obtains the complete solution.
Obtains the solution for a single constraint or variable.
getsolutionstatuskeyslice ( mosek.accmode accmode, mosek.soltype whichsol, int first, int last, array(int) sk)
Obtains the complete solution.
Obtains the solution for a single constraint or variable.
str getstrparam ( mosek.sparam param, List|None len)
str gettaskname (List|None len)
int getvarbranchdir (int j)
int getvarbranchpri (int j)
str getvarname (int i)
Obtains the maximum length of any objective, constraint, variable or cone name.
int getvartype (int j)
getvartypelist ( array(int) subj, array(int) vartype)
Obtains the variable type of one or more variables.
Upon return vartype[k] is the variable type of variable subj[k].
initbasissolve (array(int) basis)
The array of basis indexes to use.
The array is interpreted as follows: If , then
is in the basis at position i, otherwise
is in the basis at position i.
Prepare a task for use with the Task.solvewithbasis function.
This function should be called
inputdata ( int maxnumcon, int maxnumvar, array(double) c, double cfix, array(int) aptrb, array(int) aptre, array(int) asub, array(double) aval, array(int) bkc, array(double) blc, array(double) buc, array(int) bkx, array(double) blx, array(double) bux)
Input the linear part of an optimization problem.
The non-zeros of A are inputted column-wise in the format described in section 5.8.3.2.
For an explained code example see section 5.2 and section 5.8.3.
isdouparname ( str parname, List|None param)
isintparname ( str parname, List|None param)
isstrparname ( str parname, List|None param)
linkfiletotaskstream ( mosek.streamtype whichstream, str filename, int append)
makesolutionstatusunknown (mosek.soltype whichsol)
optimize ()
Optimize a given task with several optimizers concurrently.
Obtains the complete solution.
Obtains the solution for a single constraint or variable.
Obtains information about a solution.
optimizeconcurrent (array(Task) taskarray)
Solves several instances of the same problem in parallel, with unique parameter settings for each task. The argument task contains the problem to be solved. taskarray is a pointer to an array of num empty tasks. The task task and the num tasks pointed to by taskarray are solved in parallel. That is threads are started with one optimizer in each. Each of the tasks can be initialized with different parameters, e.g different selection of solver.
All the concurrently running tasks are stopped when the optimizer successfully terminates for one of the tasks. After the function returns task contains the solution found by the task that finished first.
After Task.optimizeconcurrent returns task holds the optimal solution of the task which finished first. If all the concurrent optimizations finished without providing an optimal solution the error code from the solution of the task task is returned.
In summary a call to Task.optimizeconcurrent does the following:
For an explained code example see section 7.6.4.
optimizetrm (List|None trmcode)
This function is equivalent to Task.optimize except in the case where Task.optimize would have returned a termination response code such as
primalsensitivity ( array(int) subi, array(int) marki, array(int) subj, array(int) markj, array(double) leftpricei, array(double) rightpricei, array(double) leftrangei, array(double) rightrangei, array(double) leftpricej, array(double) rightpricej, array(double) leftrangej, array(double) rightrangej)
Calculates sensitivity information for bounds on variables and constraints.
For details on sensitivity analysis and the definitions of shadow price and linearity interval see chapter 11.
The constraints for which sensitivity analysis is performed are given by the data structures:
Consider the problem:
![]() |
(13.6.11) |
Suppose that
numi = 1; subi = [0]; marki = [mosek.mark.up]
then
leftpricei[0], rightpricei[0], leftrangei[0] and rightrangei[0] will contain the sensitivity information for the upper bound on constraint 0 given by the expression:
![]() |
(13.6.12) |
Similarly, the variables for which to perform sensitivity analysis are given by the structures:
For an example, please see section 11.5.
The type of sensitivity analysis to be performed (basis or optimal partition) is controlled by the parameter mosek.iparam.sensitivity_type.
Performs sensitivity analysis on objective coefficients.
Creates a sensitivity report.
printdata ( mosek.streamtype whichstream, int firsti, int lasti, int firstj, int lastj, int firstk, int lastk, int c, int qo, int a, int qc, int bc, int bx, int vartype, int cones)
printparam ()
putaij ( int i, int j, double aij)
Changes a coefficient in A using the method
![]() |
Replaces all elements in one row or column of A.
Changes one or more coefficients in A.
putaijlist ( array(int) subi, array(int) subj, array(double) valij)
Changes one or more coefficients in A using the method
![]() |
If the same entry appears multiple times only the last one will be used.
Replaces all elements in one row or column of A.
Changes a single value in the linear coefficient matrix.
The function changes the size of the preallocated storage for linear coefficients.
putavec ( mosek.accmode accmode, int i, array(int) asub, array(double) aval)
Replaces all elements in one row or column of A.
Assuming that there are no duplicate subscripts in asub, assignment is performed as follows:
If accmode is mosek.accmode.con, then
![]() |
and all other .
If accmode is mosek.accmode.var, then
![]() |
and all other .
If asub contains duplicates, the corresponding coefficients will be added together.
For an explanation of the meaning of ptrb and ptre see 5.8.3.2 and .
Changes a single value in the linear coefficient matrix.
The function changes the size of the preallocated storage for linear coefficients.
putaveclist ( mosek.accmode accmode, array(int) sub, array(int) ptrb, array(int) ptre, array(int) asub, array(double) aval)
Replaces all elements in a set of rows or columns of A.
The elements are replaced as follows.
If accmode is mosek.accmode.con, then for
![]() |
If accmode is mosek.accmode.var, then for
![]() |
If the same row or column appears multiple times only the last one will be used.
Replaces all elements in one row or column of A.
Changes a single value in the linear coefficient matrix.
The function changes the size of the preallocated storage for linear coefficients.
putbound ( mosek.accmode accmode, int i, mosek.boundkey bk, double bl, double bu)
Changes the bounds for either one constraint or one variable.
If the a bound value specified is numerically larger than mosek.dparam.data_tol_bound_inf it is considered infinite and the bound key is changed accordingly. If a bound value is numerically larger than mosek.dparam.data_tol_bound_wrn, a warning will be displayed, but the bound is inputted as specified.
Changes the bounds for one constraint or variable.
Changes the bounds of constraints or variables.
putboundlist ( mosek.accmode accmode, array(int) sub, array(int) bk, array(double) bl, array(double) bu)
Changes the bound for either one constraint or one variable.
putboundslice ( mosek.accmode con, int first, int last, array(int) bk, array(double) bl, array(double) bu)
Changes the bound for either one constraint or one variable.
putcfix (double cfix)
putcj ( int j, double cj)
Modifies one coefficient in the linear objective vector c, i.e.
![]() |
putclist ( array(int) subj, array(double) val)
Modifies elements in the linear term c in the objective using the principle
![]() |
If a variable index is specified multiple times in subj only the last entry is used.
putcone ( int k, mosek.conetype conetype, double conepar, array(int) submem)
putdouparam ( mosek.dparam param, double parvalue)
putintparam ( mosek.iparam param, int parvalue)
putmaxnumanz (int maxnumanz)
MOSEK stores only the non-zero elements in A. Therefore, MOSEK cannot predict how much storage is required to store A. Using this function it is possible to specify the number of non-zeros to preallocate for storing A.
If the number of non-zeros in the problem is known, it is a good idea to set maxnumanz slightly larger than this number, otherwise a rough estimate can be used. In general, if A is inputted in many small chunks, setting this value may speed up the the data input phase.
It is not mandatory to call this function, since MOSEK will reallocate internal structures whenever it is necessary.
putmaxnumcon (int maxnumcon)
Sets the number of preallocated constraints in the optimization task. When this number of constraints is reached MOSEK will automatically allocate more space for constraints.
It is never mandatory to call this function, since MOSEK will reallocate any internal structures whenever it is required.
Please note that maxnumcon must be larger than the current number of constraints in the task.
putmaxnumcone (int maxnumcone)
Sets the number of preallocated conic constraints in the optimization task. When this number of conic constraints is reached MOSEK will automatically allocate more space for conic constraints.
It is never mandatory to call this function, since MOSEK will reallocate any internal structures whenever it is required.
Please note that maxnumcon must be larger than the current number of constraints in the task.
putmaxnumqnz (int maxnumqnz)
MOSEK stores only the non-zero elements in Q. Therefore, MOSEK cannot predict how much storage is required to store Q. Using this function it is possible to specify the number non-zeros to preallocate for storing Q (both objective and constraints).
It may be advantageous to reserve more non-zeros for A than actually needed since it may improve the internal efficiency of MOSEK, however, it is never worthwhile to specify more than the double of the anticipated number of non-zeros in A.
It is never mandatory to call this function, since its only function is to give a hint of the amount of data to preallocate for efficiency reasons.
putmaxnumvar (int maxnumvar)
Sets the number of preallocated variables in the optimization task. When this number of variables is reached MOSEK will automatically allocate more space for variables.
It is never mandatory to call this function, since its only function is to give a hint of the amount of data to preallocate for efficiency reasons.
Please note that maxnumvar must be larger than the current number of variables in the task.
putnadouparam ( str paramname, double parvalue)
putnaintparam ( str paramname, int parvalue)
putname ( mosek.problemitem whichitem, int i, str name)
putnastrparam ( str paramname, str parvalue)
putobjname (str objname)
putobjsense (mosek.objsense sense)
Gets the objective sense.
putparam ( str parname, str parvalue)
putqcon ( array(int) qcsubk, array(int) qcsubi, array(int) qcsubj, array(double) qcval)
Replaces all quadratic entries in the constraints. Consider constraints on the form:
![]() |
(13.6.13) |
The function assigns values to q such that:
![]() |
(13.6.14) |
and
![]() |
(13.6.15) |
Values not assigned are set to zero.
Replaces all quadratic terms in a single constraint.
Changes the size of the preallocated storage for Q.
putqconk ( int k, array(int) qcsubi, array(int) qcsubj, array(double) qcval)
Replaces all the quadratic entries in one constraint k of the form:
![]() |
(13.6.16) |
It is assumed that is symmetric, i.e.
, and therefore, only the values of
for which i≥j should be inputted to MOSEK. To be precise, MOSEK uses the following procedure
![]() |
Please note that:
For a code example see section 5.3.2.
Replaces all quadratic terms in constraints.
Changes the size of the preallocated storage for Q.
putqobj ( array(int) qosubi, array(int) qosubj, array(double) qoval)
Replaces all the quadratic terms in the objective
![]() |
(13.6.17) |
It is assumed that is symmetric, i.e.
, and therefore, only the values of
for which i≥j should be specified. To be precise, MOSEK uses the following procedure
![]() |
Please note that:
For a code example see section 5.3.1.
putqobjij ( int i, int j, double qoij)
Replaces one of the coefficients in the quadratic term in the objective. The function performs the assignment
![]() |
putsolution ( mosek.soltype whichsol, array(int) skc, array(int) skx, array(int) skn, array(double) xc, array(double) xx, array(double) y, array(double) slc, array(double) suc, array(double) slx, array(double) sux, array(double) snx)
putsolutioni ( mosek.accmode accmode, int i, mosek.soltype whichsol, mosek.stakey sk, double x, double sl, double su, double sn)
Sets the primal and dual solution information for a single constraint or variable.
To define a solution or a significant part of a solution, first call the Task.makesolutionstatusunknown function, then for each relevant function and variable, call Task.putsolutioni to set the solution information.
Sets the solution status to unknown.
putsolutionyi ( int i, mosek.soltype whichsol, double y)
Sets the solution status to unknown.
Sets the primal and dual solution information for a single constraint or variable.
putstrparam ( mosek.sparam param, str parvalue)
puttaskname (str taskname)
putvarbranchorder ( int j, int priority, mosek.branchdir direction)
putvartype ( int j, mosek.variabletype vartype)
putvartypelist ( array(int) subj, array(int) vartype)
Sets the variable type for one or more variables, i.e. variable number is assigned the variable type
.
If the same index is specified multiple times in subj only the last entry takes effect.
readbranchpriorities (str filename)
Writes branching priority data to a file.
readdata (str filename)
Reads an optimization data and associated data from a file.
The data file format is determined by the mosek.iparam.read_data_format parameter. By default the parameter has the value mosek.dataformat.extension indicating that the extension of the input file should determine the file type, where the extension is interpreted as follows:
Writes problem data to a file.
readparamfile ()
readsolution ( mosek.soltype whichsol, str filename)
readsummary (mosek.streamtype whichstream)
Task relaxprimal ( array(double) wlc, array(double) wuc, array(double) wlx, array(double) wux)
Creates a problem that computes the minimal (weighted) relaxation of the bounds that will make an infeasible problem feasible.
Given an existing task describing the problem
![]() |
(13.6.18) |
the function forms a new task relaxedtask having the form
![]() |
(13.6.19) |
Hence, the function adds so-called elasticity variables to all the constraints which relax the constraints, for instance and
relax
and
respectively. It should be obvious that (13.6.19) is feasible. Moreover, the function adds the constraint
![]() |
to the problem which makes the variable p bigger than the total weighted sum of the relaxation to the bounds. ,
,
and
are user-defined weights which normally should be nonnegative. If a weight is negative, then the corresponding elasticity variable is fixed to zero.
Hence, when the problem (13.6.19) is optimized, the weighted minimal change to the bounds such that the problem is feasible is computed.
One can specify that a bound should be strictly enforced by assigning a negative value to the corresponding weight, i.e if then
is fixed to zero.
Now let be the optimal objective value to (13.6.19), then a natural thing to do is to solve the optimization problem
![]() |
(13.6.20) |
where the original objective function is minimized subject to the constraint that the total weighted relaxation is minimal.
The parameter mosek.iparam.feasrepair_optimize controls whether the function returns the problem (13.6.19) or the problem (13.6.20).The parameter can take one of the following values.
: The returned task relaxedtask contains problem (13.6.19) and is not optimized.
: The returned task relaxedtask contains problem (13.6.19) and is optimized.
: The returned task relaxedtask contains problem (13.6.20) and is optimized.
Please note that the v variables are appended to the x variables ordered as
![]() |
in the returned task.
If NAME_CON (NAME_VAR) is the name of the ith constraint (variable) then the new variables are named as follows:
where “*” can be replaced by a user-defined string by setting the mosek.sparam.feasrepair_name_separator parameter.
Please note that if or
then the feasibility repair problem becomes infeasible. Such trivial conflicts must therefore be removed manually before using Task.relaxprimal.
The above discussion shows how the function works for a linear optimization problem. However, the function also works for quadratic and conic optimization problems but it cannot be used for general nonlinear optimization problems.
remove ( mosek.accmode accmode, array(int) sub)
Appends a number of variables or constraints to the optimization task.
removecone (int k)
Removes a conic constraint from the problem. This implies that all the conic constraints appearing after cone number k are renumbered, decresing their indexes by one.
In general, it is much more efficient to remove a cone with a high index than a low index.
resizetask ( int maxnumcon, int maxnumvar, int maxnumcone, int maxnumanz, int maxnumqnz)
Sets the amount of preallocated space assigned for each type of data in an optimization task.
It is never mandatory to call this function, since its only function is to give a hint of the amount of data to preallocate for efficiency reasons.
Please note that the procedure is destructive in the sense that all existing data stored in the task is destroyed.
Sets the number of preallocated variables in the optimization task.
Sets the number of preallocated constraints in the optimization task.
Sets the number of preallocated conic constraints in the optimization task.
The function changes the size of the preallocated storage for linear coefficients.
Changes the size of the preallocated storage for Q.
sensitivityreport (mosek.streamtype whichstream)
Performs sensitivity analysis on objective coefficients.
Perform sensitivity analysis on bounds.
set_Stream (mosek.streamtype whichstream)
setdefaults ()
int solutiondef (mosek.soltype whichsol)
solutionsummary (mosek.streamtype whichstream)
int solvewithbasis ( int transp, int numnz, array(int) sub, array(double) val)
As input it contains the positions of the non-zeros in b, i.e.
![]() |
As output it contains the positions of the non-zeros in . It is important that sub has room for numcon elements.
As input it is the vector b. Although the positions of the non-zero elements are specified in sub it is required that if b[i]=0. As output val is the vector
.
Please note that val is a dense vector — not a packed sparse vector. This implies that val has room for numcon elements.
If a basic solution is available, then exactly basis variables are defined. These
basis variables are denoted the basis. Associated with the basis is a basis matrix denoted B. This function solves either the linear equation system
![]() |
(13.6.21) |
or the system
![]() |
(13.6.22) |
for the unknowns , with b being a user-defined vector.
In order to make sense of the solution it is important to know the ordering of the variables in the basis because the ordering specifies how B is constructed. When calling Task.initbasissolve an ordering of the basis variables is obtained, whicd can be used to deduce how MOSEK has constructed B. Indeed if the kth basis variable is variable
it implies that
![]() |
Otherwise if the kth basis variable is variable it implies that
![]() |
Given the knowledge of how B is constructed it is possible to interpret the solution correctly.
Please note that this function exploits the sparsity in the vector b to speed up the computations.
Prepare a task for use with the Task.solvewithbasis function.
startstat ()
stopstat ()
strtoconetype ( str str, List|None conetype)
strtosk ( str str, List|None sk)
undefsolution (mosek.soltype whichsol)
writebranchpriorities (str filename)
Reads branching priority data from a file.
writedata (str filename)
Writes problem data associated with the optimization task to a file in one of four formats:
LP : A text based row oriented format. File extension .lp. See Appendix B.
MPS : A text based column oriented format. File extension .mps. See Appendix A.
OPF : A text based row oriented format. File extension .opf. Supports more problem types than MPS and LP. See Appendix C.
MBT : A binary format for fast reading and writing. File extension .mbt.
By default the data file format is determined by the file name extension. This behaviour can be overridden by setting the mosek.iparam.write_data_format parameter.
Please note that MPS, LP and OPF files require all variables to have unique names. If a task contains no names, it is possible to write the file with automaticly generated anonymous names by setting the mosek.iparam.write_generic_names parameter to mosek.onoffkey.on.
Reads problem data from a file.
writeparamfile (str filename)
writesolution ( mosek.soltype whichsol, str filename)
mosek.Exception
This is an exception class representing MOSEK warnings.
Syntax:
Warning (mosek.rescode code)
Arguments: