MOSEK Optimizer API For Python PDF
MOSEK Optimizer API For Python PDF
Release 8.0.0.64
MOSEK ApS
2017
www.EngineeringBooksPdf.com
www.EngineeringBooksPdf.com
CONTENTS
1 Introduction 1
1.1 Why the Optimizer API for Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 License agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Installation 3
2.1 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Testing the Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Basic Tutorials 5
3.1 The Basics Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Linear Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Conic Quadratic Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Semidefinite Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5 Quadratic Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.6 Integer Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.7 Optimizer Termination Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.8 Problem Modification and Reoptimization . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.9 Solution Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.10 Solver Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4 Nonlinear Tutorials 49
4.1 Separable Convex (SCopt) Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5 Advanced Tutorials 53
5.1 The Progress Call-back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.2 Solving Linear Systems Involving the Basis Matrix . . . . . . . . . . . . . . . . . . . . . . 55
5.3 Calling BLAS/LAPACK Routines from MOSEK . . . . . . . . . . . . . . . . . . . . . . . 62
5.4 Computing a Sparse Cholesky Factorization . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.5 Converting a quadratically constrained problem to conic form . . . . . . . . . . . . . . . 69
5.6 MOSEK OptServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6 Guidelines 77
6.1 Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.2 Efficiency Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.3 The license system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7 Case Studies 81
7.1 Portfolio Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
www.EngineeringBooksPdf.com
9.2 File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.3 Verbosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
ii
www.EngineeringBooksPdf.com
17.1 The LP File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
17.2 The MPS File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
17.3 The OPF Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
17.4 The CBF Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
17.5 The XML (OSiL) Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
17.6 The Task Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
17.7 The JSON Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
17.8 The Solution File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Bibliography 391
iii
www.EngineeringBooksPdf.com
iv
www.EngineeringBooksPdf.com
CHAPTER
ONE
INTRODUCTION
The MOSEK Optimization Suite 8.0.0.64 is a powerfull software package capable of solving large-scale
optimization problems of the following kind:
• linear,
• convex quadratic,
• conic quadratic (also known as second-order cone),
• semidefinite,
• and general convex.
Integer constrained variables are supported for all problem classes except for semidefinite and general
convex problems. In order to obtain an overview of features in the MOSEK Optimization Suite consult
the product introduction guide.
The Optimizer API for Python provides an object-oriented interface to the MOSEK optimizers. This
object oriented design is common to Java, Python and .NET and is based on a thin class-based interface
to the native C optimizer API. The overhead introduced by this mapping is minimal.
The Optimizer API for Python can be used with any application running on recent Python 2 and 3
interpreters. It consists of a single mosek package which can be used in Python scripts and interactive
shells making it suited for fast prototyping and inspection of models.
Before using the MOSEK software, please read the license agreement available in the distribu-
tion at <MSKHOME>/mosek/8/mosek-eula.pdf or on the MOSEK website https://mosek.com/sales/
license-agreement.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
MOSEK uses some third-party open-source libraries. Their license details follows.
zlib
MOSEK includes the zlib library obtained from the zlib website. The license agreement for zlib is shown
in Listing 1.1.
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
fplib
MOSEK includes the floating point formatting library developed by David M. Gay obtained from the
netlib website. The license agreement for fplib is shown in Listing 1.2.
2 Chapter 1. Introduction
www.EngineeringBooksPdf.com
CHAPTER
TWO
INSTALLATION
In this section we discuss how to install and setup the MOSEK Optimizer API for Python.
2.1 Compatibility
The MOSEK Optimizer API for Python requires Python with numpy. Below the supported Python
versions are shown
Platform Python PyPy2.7
Linux 64 bit 2.7, 3.4 and newer Yes
Mac OS 64 bit 2.7, 3.4 and newer Yes
Windows 32 and 64 bit 2.7, 3.4 and newer Yes
2.2 Instructions
Instructions for installing MOSEK Optimization Suite can in located in the Installation Guide.
Subsequently, let <MSKHOME> denote where MOSEK is installed
The relevant files of the MOSEK Optimizer API for Python are organized as reported in Table 2.1.
Table 2.1: Relevant files for the MOSEK Optimizer API for Python.
Relative Path Description Label
<MSKHOME>/mosek/8/tools/platform/<PLATFORM>/python/2 Python 2 install PYTHON2DIR
<MSKHOME>/mosek/8/tools/platform/<PLATFORM>/python/3 Python 3 install PYTHON3DIR
<MSKHOME>/mosek/8/tools/examples/python Examples EXDIR
<MSKHOME>/mosek/8/tools/examples/data Additional data MISCDIR
To install MOSEK run the setup.py script located in <PYTHON2DIR> or <PYTHON3DIR> depending on
the Python version you want to use. For instance, to install MOSEK for Python 3 on a user level, i.e.,
with no special system privilegdes needed, type
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
on Windows.
For a system wide installation drop the --user flag.
A simple PIP installer is available on the MOSEK Github repository. Atlthough there is a MOSEK
package in the official PIP repository then it is not created by MOSEK. It cannot be recommended to
use that package.
The MOSEK Optimizer API for Python installation can be tested by running some of the enclosed
examples. Indeed to run one of the distributed examples, open a terminal and change folder to <EXDIR>
i.e.
cd <EXDIR>
then use your Python interpreter to run the example. For instance to execute example lo1 type
python lo1.py
4 Chapter 2. Installation
www.EngineeringBooksPdf.com
CHAPTER
THREE
BASIC TUTORIALS
In this section a number of examples is provided to demonstrate the functionality required for solving
linear, conic, semidefinite and quadratic problems as well as mixed integer problems.
• Basic tutorial : This is the simplest tutorial: it solves a linear optimization problem read from file.
It will show how
– setup the MOSEK environment and problem task,
– run the solver and
– check the optimization results.
• Linear optimization tutorial : It shows how to input a linear program. It will show how
– define variables and their bounds,
– define constraints and their bounds,
– define a linear objective function,
– input a linear program but rows or by column.
– retrieve the solution.
• Conic quadratic optimization tutorial : The basic steps needed to formulate a conic quadratic
program are introduced:
– define quadratic cones,
– assign the relevant variables to their cones.
• Semidefinite optimization tutorial : How to input semidefintite optimization problems is the topic
of this tutorial, and in particular how to
– input semidefinite matrices and in sparse format,
– add semidefinite matrix variable and
– formulate linear constraints and objective function based on matrix variables.
• Mixed-Integer optimization tutorial : This tutorial shows how integrality conditions can be speci-
fied.
• Quadratic optimization tutorial : It shows how to input quadratic terms in the objective function
and constraints.
• Response code tutorial : How to deal with the termination and solver status code is the topic of
this tutorial:
– what are termination and termination code,
– how to check for errors and
– which are the best practice to deal with them.
This is a very important tutorial, every user should go through it.
• Reoptimization tutorial : This tutorial gives information on how to
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The simplest program using the MOSEK Python interface can be described shortly:
1. Create an environment.
2. Set up environment specific data and initialize the environment.
3. Create a task.
4. Load a problem into the task.
5. Optimize the problem.
6. Fetch the result.
7. Delete the environment and task.
The first MOSEK related step in any program that employs MOSEK is to create an environment
object. The environment contains environment specific data such as information about the license file,
streams for environment messages etc. When this is done one or more task objects can be created. Each
task is associated with a single environment and defines a complete optimization problem as well as task
message streams and optimization parameters.
In Python, the creation of an environment and a task would look something like this:
# Create an environment
env = Env()
# Create a task
task = env.Task()
When done, tasks and environments may be disposed explicitly by calling the dispose method. This is
not strictly necessary, but it will free up allocated resources and checked-out licenses immediately instead
of when the garbage collector runs. From Python 2.6 and later the with construction can be used to
dispose objects automatically when they drop of out of the with scope:
# Create an environment
with Env() as env:
# Create a task
with env.Task() as task:
Please note that multiple tasks should, if possible, share the same environment.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The simple example in Listing 3.1 shows a working Python program which
• creates an environment and a task,
• reads a problem from a file,
• optimizes the problem, and
• writes the solution to a file.
def streamprinter(msg):
sys.stdout.write (msg)
sys.stdout.flush ()
if len(sys.argv) <= 1:
print ("Missing argument, syntax is:")
print (" simple inputfile [ solutionfile ]")
else:
# Create the mosek environment.
with mosek.Env () as env:
task.readdata (sys.argv[1])
task.writedata (sys.argv[2])
Use the task.writedata function to write a problem to a file. By default, when not choosing any
specific file format for the parameter iparam.write_data_format , MOSEK will determine the output
file format by the extension of the file name:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.writedata (sys.argv[2])
task.readdata (sys.argv[1])
An optimization problem consists of several components; objective, objective sense, constraints, variable
bounds etc.
Therefore, the interface provides a number of methods to operate on the task specific data, all of which
are listed under the Task class-specification.
Setting parameters
Apart from the problem data, the task contains a number of parameters defining the behavior of
MOSEK. For example the iparam.optimizer parameter defines which optimizer to use. There are
three kinds of parameters in MOSEK
• Integer parameters that can be set with task.putintparam ,
• Double parameters that can be set with task.putdouparam , and
• string parameters that can be set with task.putstrparam ,
The values for integer parameters are either simple integer values or enum values. See Section 3.10 for
more details on how to set parameters.
A complete list of all parameters is found in Section 16.4 .
The simplest optimization problem is a purely linear problem. A linear optimization problem is a problem
of the following form:
Minimize or maximize the objective function
𝑛−1
∑︁
𝑐𝑗 𝑥𝑗 + 𝑐𝑓
𝑗=0
𝑙𝑗𝑥 ≤ 𝑥𝑗 ≤ 𝑢𝑥𝑗 , 𝑗 = 0, . . . , 𝑛 − 1,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
⎡ ⎤
𝑐0
𝑐=⎣ ..
. ⎦,
⎢ ⎥
𝑐𝑛−1
• 𝑐𝑓 which is a constant,
• 𝐴 which is a 𝑚 × 𝑛 matrix of coefficients is given by
⎡ ⎤
𝑎0,0 ··· 𝑎0,(𝑛−1)
𝐴=⎣ .. ..
. . ⎦,
⎢ ⎥
···
𝑎(𝑚−1),0 ··· 𝑎(𝑚−1),(𝑛−1)
• 𝑙𝑐 and 𝑢𝑐 which specify the lower and upper bounds on constraints respectively, and
• 𝑙𝑥 and 𝑢𝑥 which specifies the lower and upper bounds on variables respectively.
Note: Please note the unconventional notation using 0 as the first index rather than 1. Hence, 𝑥0 is
the first element in variable vector 𝑥.
0 ≤ 𝑥0 ≤ ∞,
0 ≤ 𝑥1 ≤ 10,
0 ≤ 𝑥2 ≤ ∞,
0 ≤ 𝑥3 ≤ ∞.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Create an environment.
Before setting up the optimization problem, a MOSEK environment must be created. All tasks in the
program should share the same environment.
We also connect a call-back function to the task log stream. Messages related to the task are passed
to the call-back function. In this case the stream call-back function writes its messages to the standard
output stream.
Before any problem data can be set, variables and constraints must be added to the problem via calls to
the functions task.appendcons and task.appendvars .
New variables can now be referenced from other functions with indexes in 0, . . . , numvar − 1 and new
constraints can be referenced with indexes in 0, . . . , numcon − 1. More variables and/or constraints can
be appended later as needed, these will be assigned indexes from numvar/numcon and up.
Next step is to set the problem data. We loop over each variable index 𝑗 = 0, . . . , numvar − 1 calling
functions to set problem data. We first set the objective coefficient 𝑐𝑗 = c[j] by calling the function
task.putcj .
task.putcj(j,c[j])
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The Bound key stored in bkx specify the type of the bound according to Table 3.1.
For instance bkx[0]= boundkey.lo means that 𝑥0 ≥ 𝑙0𝑥 . Finally, the numerical values of the bounds on
variables are given by
𝑙𝑗𝑥 = blx[j]
and
𝑢𝑥𝑗 = bux[j].
The array aval[j] contains the non-zero values of column 𝑗 and asub[j] contains the row index of
these non-zeros.
Using the function task.putacol we set column 𝑗 of 𝐴
task.putacol(j, # Variable (column) index.
asub[j], # Row index of non-zeros in column j.
aval[j]) # Non-zero Values of column j.
Alternatively, the same 𝐴 matrix can be set one row at a time; please see Listing 3.3.
Finally, the bounds on each constraint are set by looping over each constraint index 𝑖 = 0, . . . , numcon − 1
# Set the bounds on constraints.
# blc[i] <= constraint_i <= buc[i]
for i in range(numcon):
task.putconbound(i,bkc[i],blc[i],buc[i])
task.putconboundslice(0,numcon, bkc,blc,buc);
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Optimization
After the problem is set-up the task can be optimized by calling the function task.optimize .
task.optimize()
After optimizing the status of the solution is examined with a call to task.getsolsta . If the solution
status is reported as solsta.optimal or solsta.near_optimal the solution is extracted in the lines
below:
xx = [0.]*numvar
task.getxx(mosek.soltype.bas, # Request the basic solution.
xx)
The task.getxx function obtains the solution. MOSEK may compute several solutions depending on
the optimizer employed. In this example the basic solution is requested by setting the first argument to
soltype.bas .
Catching exceptions
except mosek.Exception as e:
print ("ERROR: %s" % str(e.errno))
if e.msg is not None:
print ("\t%s" % e.msg)
sys.exit(1)
The types of exceptions that MOSEK can throw can be seen in 16.5 .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
bkc = [mosek.boundkey.fx,
mosek.boundkey.lo,
mosek.boundkey.up]
# Objective coefficients
c = [ 3.0, 1.0, 5.0, 1.0 ]
numvar = len(bkx)
numcon = len(bkc)
for j in range(numvar):
# Set the linear term c_j in the objective.
task.putcj(j,c[j])
# Input column j of A
task.putacol(j, # Variable (column) index.
asub[j], # Row index of non-zeros in column j.
aval[j]) # Non-zero Values of column j.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
if (solsta == mosek.solsta.optimal or
solsta == mosek.solsta.near_optimal):
xx = [0.]*numvar
task.getxx(mosek.soltype.bas, # Request the basic solution.
xx)
print ("Optimal solution: ")
for i in range(numvar):
print ("x["+str(i)+"]="+str(xx[i]))
elif (solsta == mosek.solsta.dual_infeas_cer or
solsta == mosek.solsta.prim_infeas_cer or
solsta == mosek.solsta.near_dual_infeas_cer or
solsta == mosek.solsta.near_prim_infeas_cer):
print("Primal or dual infeasibility certificate found.\n")
elif solsta == mosek.solsta.unknown:
print("Unknown solution status")
else:
print("Other solution status")
Row-wise input
In the previous example the 𝐴 matrix is set one column at a time. Alternatively the same matrix can be
set one row at a time or the two methods can be mixed as in the example in Section 3.8 . The following
example show how to set the 𝐴 matrix by rows
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
sys.stdout.write(text)
sys.stdout.flush()
# Create a task
with env.Task(0,0) as task:
# Attach a printer to the task
task.set_Stream (mosek.streamtype.log, streamprinter)
for j in range(numvar):
# Set the linear term c_j in the objective.
task.putcj(j,c[j])
# Set the bounds on variable j
# blx[j] <= x_j <= bux[j]
task.putbound(mosek.accmode.var,j,bkx[j],blx[j],bux[j])
for i in range(numcon):
task.putbound(mosek.accmode.con,i,bkc[i],blc[i],buc[i])
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# Input row i of A
task.putarow(i, # Row index.
asub[i], # Column indexes of non-zeros in row i.
aval[i]); # Non-zero Values of row i.
prosta = task.getprosta(mosek.soltype.bas)
solsta = task.getsolsta(mosek.soltype.bas)
# Output a solution
xx = [0.]*numvar
task.getxx(mosek.soltype.bas,
xx)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
minimize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐
≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
𝑥 ∈ 𝒦,
where the domain restriction, 𝑥 ∈ 𝒦, implies that all variables are partitioned into convex cones
For convenience, the user only specify subsets of variables 𝑥𝑡 belonging to cones 𝒦𝑡 different from the
set R𝑛𝑡 of real numbers. These cones can be a:
• Quadratic cone:
⎧ ⎯ ⎫
⎨ ⎸𝑛−1 ⎬
⎸ ∑︁
𝒬𝑛 = 𝑥 ∈ R𝑛 : 𝑥0 ≥ ⎷ 𝑥2𝑗 .
⎩ ⎭
𝑗=1
(𝑥4 , 𝑥0 , 𝑥2 ) ∈ 𝒬3 ,
is equivalent to
√︁
𝑥4 ≥ 𝑥20 + 𝑥22 .
Furthermore, each variable may belong to one cone at most. The constraint 𝑥𝑖 − 𝑥𝑗 = 0 would however
allow 𝑥𝑖 and 𝑥𝑗 to belong to different cones with same effect.
minimize 𝑥4 + 𝑥5 + 𝑥6
subject to 𝑥1 + 𝑥2 + 2𝑥3 = 1,
𝑥1√︀
, 𝑥2 , 𝑥3 ≥ 0, (3.2)
𝑥4 ≥ 𝑥21 + 𝑥22 ,
2𝑥5 𝑥6 ≥ 𝑥23
is an example of a conic quadratic optimization problem. The problem involves some linear constraints,
a quadratic cone and a rotated quadratic cone.
Implementation
Problem (3.2) can be implemeted using the MOSEK Python API as follows:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# Create a task
with env.Task(0,0) as task:
# Attach a printer to the task
task.set_Stream (mosek.streamtype.log, streamprinter)
bkc = [ mosek.boundkey.fx ]
blc = [ 1.0 ]
buc = [ 1.0 ]
numvar = len(bkx)
numcon = len(bkc)
NUMANZ = 4
for j in range(numvar):
# Set the linear term c_j in the objective.
task.putcj(j,c[j])
# Set the bounds on variable j
# blx[j] <= x_j <= bux[j]
task.putbound(mosek.accmode.var,j,bkx[j],blx[j],bux[j])
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
for j in range(len(aval)):
# Input column j of A
task.putacol(j, # Variable (column) index.
asub[j], # Row index of non-zeros in column j.
aval[j]) # Non-zero Values of column j.
for i in range(numcon):
task.putbound(mosek.accmode.con,i,bkc[i],blc[i],buc[i])
# Output a solution
xx = [0.]*numvar
task.getxx(mosek.soltype.itr,
xx)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The only new function introduced in the example is task.appendcone , which is called here:
task.appendcone(mosek.conetype.quad,
0.0,
[ 3, 0, 1 ])
The first argument selects the type of quadratic cone. Either conetype.quad for a quadratic cone or
conetype.rquad for a rotated quadratic cone. The cone parameter 0.0 is currently not used by MOSEK
— simply passing 0.0 will work.
The last argument is a list of indexes of the variables in the cone.
Semidefinite optimization is a generalization of conic quadratic optimization, allowing the use of matrix
variables belonging to the convex cone of positive semidefinite matrices
𝑟
= 𝑋 ∈ 𝒮 𝑟 : 𝑧 𝑇 𝑋𝑧 ≥ 0, ∀𝑧 ∈ R𝑟 ,
{︀ }︀
𝒮+
The problem
⟨⎡ 2 1 0 ⎤ ⟩
minimize ⎣ 1 2 1 , 𝑋 + 𝑥0
⎦
0 1 2 ⎤
⟨⎡
1 0 0
⟩
subject to 0 1 0 , 𝑋 + 𝑥0 = 1,
(3.3)
⎣ ⎦
0 0 1 ⎤
⟨⎡
1 1 1
⟩
⎣ 1 1 1 ⎦ , 𝑋 + 𝑥1 + 𝑥2 = 1/2,
1√ 1 1
𝑥0 ≥ 𝑥1 2 + 𝑥2 2 , 𝑋 ⪰ 0,
is a mixed semidefinite and conic quadratic programming problem with a 3-dimensional semidefinite
variable
⎡ ⎤
𝑋 00 𝑋 10 𝑋 20
3
𝑋 = ⎣ 𝑋 10 𝑋 11 𝑋 21 ⎦ ∈ 𝒮+ ,
𝑋 20 𝑋 21 𝑋 22
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
2(𝑋 00 + 𝑋 10 + 𝑋 11 + 𝑋 21 + 𝑋 22 ) + 𝑥0 ,
𝑋 00 + 𝑋 11 + 𝑋 22 + 𝑥0 = 1,
and
𝑋 00 + 𝑋 11 + 𝑋 22 + 2(𝑋 10 + 𝑋 20 + 𝑋 21 ) + 𝑥1 + 𝑥2 = 1/2.
conesub = [0, 1, 2]
barci = [0, 1, 1, 2, 2]
barcj = [0, 0, 1, 1, 2]
barcval = [2.0, 1.0, 2.0, 1.0, 2.0]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
numvar = 3
numcon = len(bkc)
BARVARDIM = [3]
for j in range(numvar):
# Set the bounds on variable j
# blx[j] <= x_j <= bux[j]
task.putvarbound(j, mosek.boundkey.fr, -inf, +inf)
for i in range(numcon):
# Set the bounds on constraints.
# blc[i] <= constraint_i <= buc[i]
task.putconbound(i, bkc[i], blc[i], buc[i])
# Input row i of A
task.putarow(i, # Constraint (row) index.
asub[i], # Column index of non-zeros in constraint j.
aval[i]) # Non-zero values of row j.
task.appendcone(mosek.conetype.quad,
0.0,
conesub)
symc = task.appendsparsesymmat(BARVARDIM[0],
barci,
barcj,
barcval)
syma0 = task.appendsparsesymmat(BARVARDIM[0],
barai[0],
baraj[0],
baraval[0])
syma1 = task.appendsparsesymmat(BARVARDIM[0],
barai[1],
baraj[1],
baraval[1])
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
if (solsta == mosek.solsta.optimal or
solsta == mosek.solsta.near_optimal):
xx = [0.]*numvar
task.getxx(mosek.soltype.itr, xx)
This example introduces several new functions. The first new function task.appendbarvars is used to
append the semidefinite variable:
task.appendbarvars(BARVARDIM)
syma0 = task.appendsparsesymmat(BARVARDIM[0],
barai[0],
baraj[0],
baraval[0])
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
syma1 = task.appendsparsesymmat(BARVARDIM[0],
barai[1],
baraj[1],
baraval[1])
The second argument specifies the dimension of the symmetric variable and the third argument gives the
number of non-zeros in the lower triangular part of the matrix. The next three arguments specify the
non-zeros in the lower-triangle in triplet format, and the last argument will be updated with a unique
index of the created symmetric matrix.
After one or more symmetric matrices have been created using task.appendsparsesymmat , we can
combine them to setup a objective matrix coefficient 𝐶 𝑗 using task.putbarcj , which forms a linear
combination of one more symmetric matrices:
The second argument specify the semidefinite variable index 𝑗; in this example there is only a single
variable, so the index is 0. The next three arguments give the number of matrices used in the linear com-
bination, their indices (as returned by task.appendsparsesymmat ), and the weights for the individual
matrices, respectively. In this example, we form the objective matrix coefficient directly from a single
symmetric matrix.
Similary, a constraint matrix coefficient 𝐴𝑖𝑗 is setup by the function task.putbaraij :
where the second argument specifies the constraint number (the corresponding row of 𝐴), and the third
argument specifies the semidefinite variable index (the corresponding column of 𝐴). The next three
arguments specify a weighted combination of symmetric matrices used to form the constraint matrix
coefficient. After the problem is solved, we read the solution using task.getbarxj :
task.getbarxj(mosek.soltype.itr, 0, barx)
The function returns the half-vectorization of 𝑋 𝑗 (the lower triangular part stacked as a column vector),
where the semidefinite variable index 𝑗 is given in the second argument, and the third argument is a
pointer to an array for storing the numerical values.
MOSEK can solve quadratic and quadratically constrained convex problems. This class of problems
can be formulated as follows:
minimize 1 𝑇 𝑜
2𝑥 𝑄 𝑥 + 𝑐𝑇 𝑥 + 𝑐𝑓
∑︀𝑛−1
subject to 𝑙𝑘𝑐 ≤ 1 𝑇 𝑘
2𝑥 𝑄 𝑥 + 𝑗=0 𝑎𝑘,𝑗 𝑥𝑗 ≤ 𝑢𝑐𝑘 , 𝑘 = 0, . . . , 𝑚 − 1, (3.4)
𝑙𝑗𝑥 ≤ 𝑥𝑗 ≤ 𝑢𝑥𝑗 , 𝑗 = 0, . . . , 𝑛 − 1.
Without loss of generality it is assumed that 𝑄𝑜 and 𝑄𝑘 are all symmetric because
1 𝑇
𝑥𝑇 𝑄𝑥 = 𝑥 (𝑄 + 𝑄𝑇 )𝑥.
2
This implies that a non-symmetric 𝑄 can be replaced by the symmetric matrix 12 (𝑄 + 𝑄𝑇 ).
The problem is required to be convex. More precisely, the matrix 𝑄𝑜 must be positive semi-definite and
the 𝑘th constraint must be of the form
𝑛−1
1 𝑇 𝑘 ∑︁
𝑙𝑘𝑐 ≤ 𝑥 𝑄 𝑥+ 𝑎𝑘,𝑗 𝑥𝑗 (3.5)
2 𝑗=0
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
with a positive semi-definite 𝑄𝑘 . This implies that quadratic equalities are not allowed. Specifying a
non-convex problem will result in an error when the optimizer is called.
A matrix is positive semidefinite if the smallest eigenvalue of the matrix is nonnegative. An alternative
statement of the positive semidefinite requirement is
𝑥𝑇 𝑄𝑥 ≥ 0, ∀𝑥.
If 𝑄 is not positive semidefinite, then MOSEK will not produce reliable results or work at all.
One way of checking whether 𝑄 is positive semidefinite is to check whether all the eigenvalues of 𝑄 are
nonnegative.
and that
⎡⎤ ⎡ ⎤
0 ∞
𝑙𝑐 = 1, 𝑢𝑐 = ∞, 𝑙𝑥 = ⎣ 0 ⎦ and 𝑢𝑥 = ⎣ ∞ ⎦
0 ∞
Please note the explicit 12 in the objective function of (3.4) which implies that diagonal elements must
be doubled in 𝑄, i.e. 𝑄11 = 2, whereas the coefficient in (3.6) is 1 in front of 𝑥21 .
Important: MOSEK assumes that the 𝑄 matrix is symmetric, i.e. 𝑄 = 𝑄𝑇 , and that 𝑄 is positive
semidefinite.
import mosek
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
numvar = len(bkx)
numcon = len(bkc)
for j in range(numvar):
# Set the linear term c_j in the objective.
task.putcj(j,c[j])
# Set the bounds on variable j
# blx[j] <= x_j <= bux[j]
task.putbound(mosek.accmode.var,j,bkx[j],blx[j],bux[j])
# Input column j of A
task.putacol( j, # Variable (column) index.
asub[j], # Row index of non-zeros in column j.
aval[j]) # Non-zero Values of column j.
for i in range(numcon):
task.putbound(mosek.accmode.con,i,bkc[i],blc[i],buc[i])
task.putqobj(qsubi,qsubj,qval)
# Optimize
task.optimize()
# Print a summary containing information
# about the solution for debugging purposes
task.solutionsummary(mosek.streamtype.msg)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
prosta = task.getprosta(mosek.soltype.itr)
solsta = task.getsolsta(mosek.soltype.itr)
# Output a solution
xx = [0.]*numvar
task.getxx(mosek.soltype.itr,
xx)
Most of the functionality in this example has already been explained for the linear optimization example
in Section 3.2 and it will not be repeated here.
This example introduces one new function, task.putqobj , which is used to input the quadratic terms
of the objective function.
Since 𝑄𝑜 is symmetric only the lower triangular part of 𝑄𝑜 is inputted. The upper part of 𝑄𝑜 is computed
by MOSEK using the relation
𝑄𝑜𝑖𝑗 = 𝑄𝑜𝑗𝑖 .
Entries from the upper part may not appear in the input.
The lower triangular part of the matrix 𝑄𝑜 is specified using an unordered sparse triplet format (for
details, see Section 16.1.3 ):
qsubi = [ 0, 1, 2, 2 ]
qsubj = [ 0, 1, 0, 2 ]
qval = [ 2.0, 0.2, -1.0, 2.0 ]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.putqobj(qsubi,qsubj,qval)
In this section describes how to solve a problem with quadratic constraints. Please note that quadratic
constraints are subject to the convexity requirement (3.5).
Consider the problem:
This is equivalent to
minimize 1 𝑇 𝑜 𝑇
2𝑥 𝑄 𝑥 + 𝑐 𝑥 (3.7)
subject to 1 𝑇 0
2 𝑥 𝑄 𝑥 + 𝐴𝑥 ≥ 𝑏,
where
⎡ ⎤
2 0 −1
𝑄𝑜 = ⎣ 0
[︀ ]︀ [︀ ]︀
0.2 0 ⎦ , 𝑐 = 0 − 10 , 𝐴 = 1 1 1 , 𝑏 = 1.
−1 0 2
⎡ ⎤
−2 0 0.2
0
𝑄 = ⎣ 0 −2 0 ⎦.
0.2 0 −0.2
# Create a task
with env.Task(0,0) as task:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
bkx = [ mosek.boundkey.lo,
mosek.boundkey.lo,
mosek.boundkey.lo ]
blx = [ 0.0, 0.0, 0.0 ]
bux = [ inf, inf, inf ]
numvar = len(bkx)
numcon = len(bkc)
NUMANZ = 3
# Append 'numcon' empty constraints.
# The constraints will initially have no bounds.
task.appendcons(numcon)
for j in range(numvar):
# Set the linear term c_j in the objective.
task.putcj(j,c[j])
# Set the bounds on variable j
# blx[j] <= x_j <= bux[j]
task.putbound(mosek.accmode.var,j,bkx[j],blx[j],bux[j])
# Input column j of A
task.putacol(j, # Variable (column) index.
asub[j], # Row index of non-zeros in column j.
aval[j]) # Non-zero Values of column j.
for i in range(numcon):
task.putbound(mosek.accmode.con,i,bkc[i],blc[i],buc[i])
qsubi = [ 0, 1, 2, 2 ]
qsubj = [ 0, 1, 0, 2 ]
qval = [ 2.0, 0.2, -1.0, 2.0 ]
task.putqobj(qsubi,qsubj,qval)
qsubi = [ 0, 1, 2, 2 ]
qsubj = [ 0, 1, 2, 0 ]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
prosta = task.getprosta(mosek.soltype.itr)
solsta = task.getsolsta(mosek.soltype.itr)
# Output a solution
xx = [0.]*numvar
task.getxx(mosek.soltype.itr,
xx)
The only new function introduced in this example is task.putqconk , which is used to add quadratic
terms to the constraints. While task.putqconk add quadratic terms to a specific constraint, it is also
possible to input all quadratic terms in all constraints in one chunk using the task.putqcon function.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
An optimization problem where one or more of the variables are constrained to integer values is denoted
an integer optimization problem.
Section 3.6.2 shows how to input an initial feasible solution to help the solver.
The complete source for the example is listed Listing 3.8. Please note that when
task.getsolutionslice is called, the integer solution is requested by using soltype.itg . No dual
solution is defined for integer optimization problems.
# Create a task
with env.Task(0,0) as task:
# Attach a printer to the task
task.set_Stream (mosek.streamtype.log, streamprinter)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
c = [ 1.0, 0.64 ]
numvar = len(bkx)
numcon = len(bkc)
for j in range(numvar):
# Set the linear term c_j in the objective.
task.putcj(j,c[j])
# Set the bounds on variable j
# blx[j] <= x_j <= bux[j]
task.putvarbound(j,bkx[j],blx[j],bux[j])
# Input column j of A
task.putacol(j, # Variable (column) index.
asub[j], # Row index of non-zeros in column j.
aval[j]) # Non-zero Values of column j.
task.putconboundlist(range(numcon),bkc,blc,buc)
prosta = task.getprosta(mosek.soltype.itg)
solsta = task.getsolsta(mosek.soltype.itg)
# X
# Output a solution
xx = [0.]*numvar
task.getxx(mosek.soltype.itg,xx)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Solving a mixed-integer optimization program could easily result in long running time. It is therefore of
interest to consider a termination criterion based on the maximum running time. This is possible setting
the dparam.mio_max_time . See Section 3.10 for more details on how to set solver parameters.
Integer optimization problems are generally hard to solve, but the solution time can often be reduced by
providing an initial solution for the solver. It is not necessary to specify the whole solution. By setting the
iparam.mio_construct_sol parameter to onoffkey.on and inputting values for the integer variables
only, will force MOSEK to compute the remaining continuous variable values.
If the specified integer solution is infeasible or incomplete, MOSEK will simply ignore it.
Consider the problem
maximize 7𝑥0 + 10𝑥1 + 𝑥2 + 5𝑥3
subject to 𝑥0 + 𝑥1 + 𝑥2 + 𝑥3 ≤ 2.5
(3.9)
𝑥0 , 𝑥1 , 𝑥2 ∈ Z
𝑥0 , 𝑥1 , 𝑥2 , 𝑥3 ≥ 0
The following example demonstrates how to optimize the problem using a feasible starting solution
generated by selecting the integer values as 𝑥0 = 0, 𝑥1 = 2, 𝑥2 = 0.
Solution values can be set using task.putsolution (for inputting a whole solution) or
task.putsolutioni (for inputting solution values related to a single variable or constraint).
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# Create a task
with env.Task(0,0) as task:
# Attach a printer to the task
task.set_Stream (mosek.streamtype.log, streamprinter)
bkc = [ mosek.boundkey.up ]
blc = [ -inf, ]
buc = [ 2.5 ]
bkx = [ mosek.boundkey.lo,
mosek.boundkey.lo,
mosek.boundkey.lo,
mosek.boundkey.lo ]
asub = [ 0, 0, 0, 0 ]
acof = [ 1.0, 1.0, 1.0, 1.0]
ptrb = [ 0, 1, 2, 3 ]
ptre = [ 1, 2, 3, 4 ]
numvar = len(bkx)
numcon = len(bkc)
task.putvartypelist([ 0, 1, 2 ],
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[ mosek.variabletype.type_int,
mosek.variabletype.type_int,
mosek.variabletype.type_int])
# Optimize
task.optimize()
else:
print("Intial integer solution construction failed.");
if task.solutiondef(mosek.soltype.itg):
# Output a solution
xx = [0.]*numvar
task.getxx(mosek.soltype.itg, xx)
print("Integer optimal solution")
for j in range(0,numvar) :
print("\tx[%d] = %e" % (j,xx[j]))
else:
print("No integer solution is available.")
After solving an optimization problem with MOSEK an approriate action must be taken depending on
the outcome. Usually the expected outcome is an optimal solution, but there may be several situations
where this is not the result. E.g., if the problem is infeasible or nearly so or if the solver ran out of
memory or stalled while optimizing, the result may not be as expected.
This section discusses what should be considered when an optimization has ended unsuccessfully.
Before continuing, let us consider the four status codes available in MOSEK that is relevant for the
error handing:
• Termination code: It provides information about why the optimizer terminated. For instance if
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
a time limit has been specfied (this is common for mixed integer problems), the termination code
will tell if this termination limit was the cause of the termination. Note that reaching a prespecfied
time limit is not considered an exceptional case. It must be expected that this occurs occasionally.
• Response code: It is an information about the system status and the outcome of the call to a
MOSEK functionalities. This code is used to report the unexpected failures such as out of space.
MOSEK runs silently when no errors are encountered, while an exception is generated otherwise. See
16.5 for a list of possible exceptions.
• Solution status: It contains information about the status of the solution, e.g., whether the
solution is optimal or a certificate of infeasibility.
• Problem status: It describes what MOSEK knows about the feasibility of the problem, i.e., if
the is problem feasible or infeasible.
The problem status is mostly used for integer problems. For continuous problems a problem status of,
say, infeasible will always mean that the solution is a certificate of infeasibility. For integer problems it
is not possible to provide a certificate, and thus a separate problem status is useful.
Note that if we want to report, e.g., that the optimizer terminated due to a time limit or because it
stalled but with a feasible solution, we have to consider both the termination code, and the solution
status.
The following pseudo code demonstrates a best practice way of dealing with the status codes.
• if ( the solution status is as expected )
– The normal case:
Do whatever that was planned. Note the response code is ignored because the solution has
the expected status. Of course we may check the response anyway if we like.
• else
– Exceptional case:
Based on solution status, response and termination codes take appropriate action.
In Listing 3.10 the pseudo code is implemented. The idea of the example is to read an optimization
problem from a file, e.g., an MPS file and optimize it. Based on status codes an appropriate action is
taken, which in this case is to print a suitable message.
def streamprinter(text):
sys.stdout.write(text)
sys.stdout.flush()
def main(args):
if len(args) < 1:
print ("No input file specified")
return
else:
print ("Inputfile: %s" % args[0])
try:
with mosek.Env() as env:
with env.Task(0,0) as task:
task.set_Stream (mosek.streamtype.log, streamprinter)
task.readdata(args[0])
trmcode = task.optimize()
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
solsta = task.getsolsta(mosek.soltype.itr)
if solsta in [ mosek.solsta.optimal,
mosek.solsta.near_optimal ]:
print ("An optimal basic solution is located.")
task.solutionsummary(mosek.streamtype.log)
elif solsta in [ mosek.solsta.dual_infeas_cer,
mosek.solsta.near_dual_infeas_cer ]:
print ("Dual infeasibility certificate found.")
elif solsta in [ mosek.solsta.prim_infeas_cerl,
mosek.solsta.near_prim_infeas_cer ]:
print("Primal infeasibility certificate found.\n");
elif solsta == mosek.solsta.sta_unknown:
# The solutions status is unknown. The termination code
# indicating why the optimizer terminated prematurely.
print ("The solution status is unknown.")
print ("Termination code: %s" % str(trmcode))
else:
print ("An unexpected solution status is obtained.")
if __name__ == '__main__':
import sys
main(sys.argv[1:])
Often one might want to solve not just a single optimization problem, but a sequence of problem, each
differing only slightly from the previous one. This section demonstrates how to modify and re-optimize
an existing problem. The example we study is a simple production planning model.
Problem modifications regarding variables, cones, objective function and constraints can be grouped in
three categories:
• add/remove,
• coefficient modifications,
• bounds modifications.
These operations may be costly and, especially removing variables and constraints. Special care must
be taken with respect to constraints and variable indexes that may be invalidated.
Depending on the type of modification, MOSEK may be able to optimize the modified problem more
efficiently exploiting the information and internal state from the previous execution.
For instance the former optimal solution may be still feasibile, but no more optimal; or for tiny modifi-
cations of the objective function it may be still optimal. This is a special case that we discuss in Section
15 .
In general, MOSEK exploits dual information and the availablity of an optimal basis from the previous
execution. The simplex optimizer is well suited for exploiting an existing primal or dual feasible solution.
Restarting capabilities for interior-point methods are still not reliable and effective as those for the simplex
algorithm. More information can be found in Chapter 10 of the book [Chv83] .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
A company manufactures three types of products. Suppose the stages of manufacturing can be split into
three parts, namely Assembly, Polishing and Packing. In the table below we show the time required for
each stage as well as the profit associated with each product.
Product no. Assembly (minutes) Polishing (minutes) Packing (minutes) Profit ($)
0 2 3 2 1.50
1 4 2 3 2.50
2 3 3 2 3.00
With the current resources available, the company has 100, 000 minutes of assembly time, 50, 000 minutes
of polishing time and 60, 000 minutes of packing time available per year.
Now the question is how many items of each product the company should produce each year in order to
maximize profit?
Denoting the number of items of each type by 𝑥0 , 𝑥1 and 𝑥2 , this problem can be formulated as the
linear optimization problem:
maximize 1.5𝑥0 + 2.5𝑥1 + 3.0𝑥2
subject to 2𝑥0 + 4𝑥1 + 3𝑥2 ≤ 100000,
(3.10)
3𝑥0 + 2𝑥1 + 3𝑥2 ≤ 50000,
2𝑥0 + 3𝑥1 + 2𝑥2 ≤ 60000,
and
𝑥0 , 𝑥1 , 𝑥2 ≥ 0.
# Create a task
with env.Task(0,0) as task:
# Attach a printer to the task
task.set_Stream (mosek.streamtype.log, streamprinter)
# Objective coefficients
csub = [ 0, 1, 2 ]
cval = [ 1.5, 2.5, 3.0 ]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
0, 1, 2,
0, 1, 2]
# acof contains coefficients
acof = [ 2.0, 3.0, 2.0,
4.0, 2.0, 3.0,
3.0, 3.0, 2.0 ]
# aptrb and aptre contains the offsets into asub and acof where
# columns start and end respectively
aptrb = [ 0, 3, 6 ]
aptre = [ 3, 6, 9 ]
numvar = len(bkx)
numcon = len(bkc)
# Input objective
task.putcfix(0.0)
task.putclist(csub,cval)
# Output a solution
xx = [0.]*numvar
task.getsolutionslice(mosek.soltype.bas,
mosek.solitem.xx,
0,numvar,
xx)
print ("xx =", xx)
Suppose we want to change the time required for assembly of product 0 to 3 minutes. This corresponds
to setting 𝑎0,0 = 3, which is done by calling the function task.putaij as shown below.
task.putaij(0, 0, 3.0)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑥0 , 𝑥1 , 𝑥2 ≥ 0.
After changing the 𝐴 matrix we can find the new optimal solution by calling task.optimize again
# Change objective
task.putcj(task.getnumvar()-1,1.0)
𝑥0 , 𝑥1 , 𝑥2 , 𝑥3 ≥ 0.
3.8.4 Reoptimization
When task.optimize is called MOSEK will store the optimal solution internally. After a task has been
modified and task.optimize is called again the solution will automatically be used to reduce solution
time of the new problem, if possible.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
In this case an optimal solution to problem (3.11) was found and then added a column was added to get
(3.12). We let MOSEK select the suitable simplex algorithm to perform reoptimization.
Now suppose we want to add a new stage to the production called Quality control for which 30000
minutes are available. The time requirement for this stage is shown below:
Product no. Quality control (minutes)
0 1
1 2
2 1
3 1
This corresponds to adding the constraint
𝑥0 + 2𝑥1 + 𝑥2 + 𝑥3 ≤ 30000
arowsub = [0, 1, 2, 3 ]
arowval = [1.0, 2.0, 1.0, 1.0]
The main purpose of MOSEK is to solve optimization problems and therefore the most fundamental
question to be asked is whether the solution reported by MOSEK is a solution to the desired optimization
problem.
There can be several reasons why it might be not case. The most prominent reasons are:
• A wrong problem. The problem inputted to MOSEK is simply not the right problem, i.e. some
of the data may have been corrupted or the model has been incorrectly built.
• Numerical issues. The problem is badly scaled or otherwise badly posed.
• Other reasons. E.g. not enough memory or an explicit user request to stop.
The first step in verifying that MOSEK reports the expected solution is to inspect the solution summary
generated by MOSEK (see Section 3.9.1 ). The solution summary provides information about
• the problem and solution statuses,
• objective value and infeasibility measures for the primal solution, and
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• objective value and infeasibility measures for the dual solution, where applicable.
By inspecting the solution summary it can be verified that MOSEK produces a feasible solution, and,
in the continuous case, the optimality can be checked using the dual solution. Furthermore, the problem
itself ca be inspected using the problem analyzer discussed in Section 13 .
If the summary reports conflicting information (e.g. a solution status that does not match the actual
solution), or the cause for terminating the solver before a solution was found cannot be traced back to
the reasons stated above, it may be caused by a bug in the solver; in this case, please contact MOSEK
support (see Section 1.2 ).
If it has been verified that MOSEK solves the problem correctly but the solution is still not as expected,
next step is to verify that the primal solution satisfies all the constraints. Hence, using the original
problem it must be determined whether the solution satisfies all the required constraints in the model.
For instance assume that the problem has the constraints
𝑥1 + 2𝑥2 + 𝑥3 ≤ 1,
𝑥1 , 𝑥2 , 𝑥3 ≥ 0
𝑥1 = 𝑥2 = 𝑥3 = 1.
Then clearly the solution violates the constraints. The most likely explanation is that the model does
not match the problem entered into MOSEK, for instance
𝑥1 − 2𝑥2 + 𝑥3 ≤ 1
𝑥1 + 2𝑥2 + 𝑥3 ≤ 1.
A good way to debug such an issue is to dump the problem to OPF file and check whether the violated
constraint has been specified correctly.
Verifying that a feasible solution is optimal can be harder. However, for continuous problems, i.e. prob-
lems without any integer constraints, optimality can verified using a dual solution. Normally, MOSEK
will report a dual solution; if that is feasible and has the same objective value as the primal solution,
then the primal solution must be optimal.
An alternative method is to find another primal solution that has better objective value than the one
reported to MOSEK. If that is possible then either the problem is badly posed or there is bug in
MOSEK.
Due to MOSEK employs finite precision floating point numbers then reported solution is an approximate
optimal solution. Therefore after solving an optimization problem it is relevant to investigate how good
an approximation the solution is. For a convex optimization problem that is an easy task because the
optimality conditions are:
• The primal solution must satisfy all the primal constraints.
• The dual solution much satisfy all the dual constraints.
• The primal and dual objective values must be identical.
Therefore, the MOSEK solution summary displays that information that makes it possible to verify the
optimality conditions. Indeed the solution summary reports how much primal and dual solutions violate
the primal and constraints respectively. In addition the objective values assoctaied with each solution
repoted.
In case of a linear optimization problem the solution summary may look like
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
i.e. MOSEK reports that the solution is a certificate of primal infeasibility but a certificate of primal
infeasibility what does that mean? It means that the dual solution is a Farkas type certificate. Recall
Farkas’ Lemma says
𝐴𝑥 = 𝑏,
𝑥 ≥ 0
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Observe when a solution is a certificate of dual infeasibility then the primal solution contains the cer-
tificate. Moreoever, given the problem is a minimization problem the objective value should be negative
and large compared to the worst violation if the certificate is strong.
Listing 3.13 shows how to use these function to determine the quality of the solution.
def streamprinter(msg):
sys.stdout.write (msg)
sys.stdout.flush ()
if len(sys.argv) <= 1:
print ("Missing argument, syntax is:")
print (" solutionquality inputfile")
else:
try:
whichsol= mosek.soltype.bas
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
solsta= task.getsolsta(whichsol)
␣
˓→pobj,pviolcon,pviolvar,pviolbarvar,pviolcones,pviolitg,dobj,dviolcon,dviolvar,dviolbarvar,dviolcones␣
˓→= task.getsolutioninfo(whichsol)
if solsta in [mosek.solsta.optimal,mosek.solsta.near_optimal]:
abs_obj_gap = abs(dobj-pobj)
rel_obj_gap = abs_obj_gap/(1.0 + min(abs(pobj),abs(dobj)))
max_primal_viol = max(pviolcon,pviolvar)
max_primal_viol = max(max_primal_viol ,pviolbarvar)
max_primal_viol = max(max_primal_viol ,pviolcones)
max_dual_viol = max(dviolcon,dviolvar)
max_dual_viol = max(max_dual_viol ,dviolbarvar)
max_dual_viol = max(max_dual_viol ,dviolcones)
print ("\n\n")
print ("Customized solution information.\n")
print (" Absolute objective gap: %e\n"%abs_obj_gap)
print (" Relative objective gap: %e\n"%rel_obj_gap)
print (" Max primal violation : %e\n"%max_primal_viol)
print (" Max dual violation : %e\n"%max_dual_viol)
accepted= True
if rel_obj_gap>1e-6 :
print ("Warning: The relative objective gap is LARGE.")
accepted = False
if max_dual_viol>1e-6 :
print ("Warning: Dual violation is too LARGE.")
accepted = False
if accepted:
numvar = task.getnumvar()
print ("Optimal primal solution")
xj=[0.]
for j in range(numvar):
task.getxxslice(whichsol,j,j+1,xj)
print ("x[%d]: %e\n"%(j,xj[0]))
else:
#Print detailed information about the solution
task.analyzesolution(mosek.streamtype.log,whichsol)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
except mosek.Error as e:
print (e)
The main diffrence compared to thecontinous case covered previously is that no information about
the dual solution is provided. Simply because there is no dual solution available for a mixed integer
problem. In this case it can be seen that the solution is highly feasible because the violations are small.
Moreoever, the solution is denoted integer optimal. Observe itg: 3e-014 implies that all the integer
constrained variables are at most 3𝑒 − 014 from being an exact integer.
The MOSEK API provides many parameters to tune and customize the solver behaviour. Parameters
are grouped depending on their type: integer, double or string. In general, it should not be necessary to
change any of the parameters but if required, it is easily done. A complete list of all parameters is found
in Section 16.4 .
We will show how to access and set the integer parameter that define the logging verbosity of the solver,
i.e. iparam.log , and the algorithm used by MOSEK, i.e. iparam.optimizer .
Note: The very same concepts and procedures apply to string and double valued parameters.
To inspect the current value of a parameter, we can use the task.getintparam . In this example we say
param= task.getintparam(mosek.iparam.log)
To set a parameter the MOSEK API provides several functions that differ in the way the parameter
name and value are specified.
A parameter can be accessed by an identifier using task.putintparam
task.putintparam(mosek.iparam.log,1)
try:
print ('setting to -1 using putintparam...')
task.putintparam(mosek.iparam.log,-1)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
except mosek.Error as e:
print ('-1 rejected as not a valid value')
The values for integer parameters are either simple integer values or enum values. Enumerations are
provided mainly to improve readability and ensure compatibility.
In the next lines we show how to set the algorithm used by MOSEK to solve linear optimization prob-
lem. To that purpose we set the iparam.optimizer parameter using a value from the optimizertype
enumeration: for instance we may decide to use the dual simplex algorithm, and thus
task.putintparam(mosek.iparam.optimizer,mosek.optimizertype.dual_simplex)
For more information about other parameter related functions, please browse the API reference in Section
16 .
The complete code for this tutorial follows in Listing 3.15.
param= task.getintparam(mosek.iparam.log)
print ('default value for parameter mosek.ipar.log= ',param)
try:
print ('setting to -1 using putintparam...')
task.putintparam(mosek.iparam.log,-1)
except mosek.Error as e:
print ('-1 rejected as not a valid value')
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
CHAPTER
FOUR
NONLINEAR TUTORIALS
This chapter provides information about how to solve general convex nonlinear optimization problems
using MOSEK. By general nonlinear problems it is meant problems that cannot be formulated as a
conic quadratic optimization or a convex quadratically constrained optimization problem.
In general it is recommended not to use nonlinear optimizer unless needed. The reasons are
• MOSEK has no way of checking whether the formulated problem is convex and if this assumption
is not satisfied the optimizer will not work.
• The nonlinear optimizer requires 1st and 2nd order derivative information which is hard to provide
correctly i.e. it is nontrivial to program the code that computes the derivative information.
• The algorithm employed for nonlinear optimization problems is not as good as the one employed
for conic problems i.e. conic problems has special that can be exploited to make the optimizer
faster and more robust.
This leads to following advices in decreasing order of importance.
1. Consider reformulating the problem to a conic quadratic optimization problem if at all possible. In
particular many problems involving polynomial terms can easily be reformulated to conic quadratic
form.
2. Consider reformulating the problem to a separable optimization problem because that simplifies
the issue with verifying convexity and computing 1st and 2nd order derivatives significantly. In
most cases problems on separable form also solves faster because of the simpler structure of the
functions.
3. Finally, if the problem cannot be reformulated to separable form then use a modelling language
like AMPL or GAMS. The reason is the modeling language will do all the computing of function
values and derivatives. This eliminates an important source of errors. Therefore, it is strongly
recommended to use a modelling language at the prototype stage.
The MOSEK optimizer API provides a way to add simple non-linear functions composed from a limited
set of non-linear terms. Non-linear terms can be mixed with quadratic terms in objective and constraints.
We consider a normal linear problem with additional non-linear terms 𝑧:
minimize 𝑧0 (𝑥) + 𝑐𝑇 𝑥
subject to 𝑙𝑖𝑐 ≤ 𝑧𝑖 (𝑥) + 𝑎𝑇𝑖 𝑥 ≤ 𝑢𝑐𝑖 , 𝑖 = 1 . . . 𝑚
𝑥
𝑙 ≤ 𝑥 ≤ 𝑢𝑥 ,
𝑥 ∈ R𝑛 𝑧 : R𝑛 → R(𝑚+1)
Using the separable non-linear interface it is possible to add non-linear functions of the form
𝐾𝑖
∑︁
𝑧𝑖 (𝑥) = 𝑤𝑘𝑖 (𝑥𝑝𝑖𝑘 ), 𝑤𝑘𝑖 : R → R
𝑘=1
49
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
In other words, each non-linear function 𝑧𝑖 is a sum of separable functions 𝑤𝑘𝑖 of one variable each. A
limited set of functions are supported; each 𝑤𝑘𝑖 can be one of the separable functions:
Some simple rules can be set up to ensure that the problem satisfies MOSEK‘s convexity and differ-
entiability requirements. First of all, for any variable 𝑥𝑖 used in a separable term, the variable bounds
must define a range within which the function is twice differentiable.
We can define these bounds as follows:
Separable function Operator name Safe 𝑥 bounds
𝑓 𝑥 ln(𝑥) ent 0 < 𝑥.
𝑓 𝑒𝑔𝑥+ℎ exp −∞ < 𝑥 < ∞.
If 𝑔 > 0: −ℎ/𝑔 < 𝑥.
𝑓 ln(𝑔𝑥 + ℎ) log
If 𝑔 < 0: 𝑥 < −ℎ/𝑔.
If 𝑔 > 0 and integer: −∞ < 𝑥 < ∞.
𝑓 (𝑥 + ℎ)𝑔 pow If 𝑔 < 0 and integer: either −ℎ < 𝑥 or 𝑥 < −ℎ.
Otherwise: −ℎ < 𝑥.
To ensure convexity, we require that each 𝑧𝑖 (𝑥) is either a sum of convex terms or a sum of concave
terms. The following table lists convexity for the relevant ranges for 𝑓 > 0 — changing the sign of 𝑓
switches concavity/convexity.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Subsequently, we will use the following example to demonstrate the solution of a separable convex
optimization problem using MOSEK
This problem is obviously separable. Moreover, note that all nonlinear functions are well defined for 𝑥
values satisfying the variable bounds strictly, i.e.
𝑥1 , 𝑥2 > 0.
This assures that function evaluation errors will not occur during the optimization process because
MOSEK will only evaluate ln(𝑥1 ) and 𝑥2 ln(𝑥2 ) for 𝑥1 , 𝑥2 > 0.
The method employed above can often be used to make convex optimization problems separable even
if these are not formulated as such initially. The reader might object that this approach is inefficient
because additional constraints and variables are introduced to make the problem separable. However, in
our experience this drawback is offset largely by the much simpler structure of the nonlinear functions.
Particularly, the evaluation of the nonlinear functions, their gradients and Hessians is much easier in the
separable case.
The complete source code follows in Listing 4.1.
import sys
import mosek
def streamprinter(text):
sys.stdout.write(text)
sys.stdout.flush()
numvar = 2
numcon = 2
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
inf = 0.
bkc = [ mosek.boundkey.up,
mosek.boundkey.lo]
blc = [ -inf, 0.]
buc = [ 0., inf]
task.appendvars(numvar)
task.appendcons(numcon)
task.putaij(1, 1, -1.0)
task.optimize()
main()
www.EngineeringBooksPdf.com
CHAPTER
FIVE
ADVANCED TUTORIALS
Some of the API function calls, notably task.optimize , may take a long time to complete. Therefore,
during the optimization a call-back function is called frequently, to provide information on the progress
of the call. From the call-back function it is possible
• to obtain information on the solution process,
• to report of the optimizer’s progress, and
• to ask MOSEK to terminate, if desired.
The call-back function arguments provide the following information:
• a code that identify the event that caused the call-back to be called,
• an handle to a user-defined data structure and
• the complete set of parameters used by the solver.
The user can force the solver to stop using the return value of the call-back.
Listing 5.1 shows how the progress call-back function can be used.
import mosek
from mosek import *
def makeUserCallback(maxtime):
def userCallback(caller,
douinf,
intinf,
lintinf):
opttime = 0.0
if caller == callbackcode.begin_intpnt:
print ("Starting interior-point optimizer")
elif caller == callbackcode.intpnt:
itrn = intinf[iinfitem.intpnt_iter ]
pobj = douinf[dinfitem.intpnt_primal_obj]
dobj = douinf[dinfitem.intpnt_dual_obj ]
stime = douinf[dinfitem.intpnt_time ]
opttime = douinf[dinfitem.optimizer_time ]
53
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
return 0
return userCallback
def msgPrinter(msg):
sys.stdout.write(msg)
sys.stdout.flush()
def main(args):
filename = "../data/25fv47.mps"
slvr = "intpnt"
if len(args) < 3:
print("Usage: callback ( psim | dsim | intpnt ) filename")
task.set_Stream(streamtype.log, msgPrinter)
if slvr == 'psim':
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.putintparam(iparam.optimizer,optimizertype.primal_simplex)
elif slvr == "dsim":
task.putintparam(iparam.optimizer,optimizertype.dual_simplex)
elif slvr == "intpnt":
task.putintparam(iparam.optimizer,optimizertype.intpnt)
# Turn all MOSEK logging off (note that errors and other messages
# are still sent through the log stream)
task.putintparam(iparam.log, 0)
task.optimize()
task.solutionsummary(streamtype.msg)
if __name__ == '__main__':
main(sys.argv)
Important: Due to the way the Python garbage collector works, it is necessary to hold a reference to
the callback function for the duration of the lifetime of the Task object. This means that a construction
such as
#NOTE: WRONG way to attach callback!
task.set_Progress(lambda caller, dinf, iinf, liinf: print "Caller : %d" % caller)
A linear optimization problem always has an optimal solution which is also a basic solution. In an optimal
basic solution there are exactly 𝑚 basic variables where 𝑚 is the number of rows in the constraint matrix
𝐴. Define
𝐵 ∈ R𝑚×𝑚
det(𝐵) ̸= 0
𝐵𝑥
¯=𝑤 (5.1)
and
𝐵𝑇 𝑥
¯=𝑤 (5.2)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
To use the solutions to (5.1) and (5.2) it is important to know how the basis matrix 𝐵 is constructed.
Internally MOSEK employs the linear optimization problem
maximize 𝑐𝑇 𝑥
subject to 𝐴𝑥 − 𝑥𝑐 = 0,
(5.3)
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
𝑙𝑐 ≤ 𝑥𝑐 ≤ 𝑢𝑐 .
where
𝑥𝑐 ∈ R𝑚 and 𝑥 ∈ R𝑛 .
If variable 𝑥𝑗 is a basis variable, then the 𝑗 ’th column of 𝐴 denoted 𝑎:,𝑗 will appear in 𝐵.Similarly, if
𝑥𝑐𝑖 is a basis variable, then the 𝑖 ’th column of −𝐼 will appear in the basis. The ordering of the basis
variables and therefore the ordering of the columns of 𝐵 is arbitrary. The ordering of the basis variables
may be retrieved by calling the function
task.initbasissolve(basis)
then the 𝑖’th basis variable is 𝑥𝑐𝑖 . Moreover, the 𝑖 ’th column in 𝐵 will be the 𝑖’th column of −𝐼. On the
other hand if
basis[𝑖] ≥ numcon,
𝑥basis[𝑖]−numcon
𝐴:,(basis[𝑖]−numcon) .
For instance if basis[0] = 4 and numcon = 5 , then since basis[0] < numcon , the first basis variable
is 𝑥𝑐4 . Therefore, the first column of 𝐵 is the fourth column of −𝐼. Similarly, if basis[1] = 7, then the
second variable in the basis is 𝑥basis[1]−numcon = 𝑥2 . Hence, the second column of 𝐵 is identical to 𝑎:,2 .
An example
minimize 𝑥0 + 𝑥1
subject to 𝑥0 + 2𝑥1 ≤ 2,
(5.4)
𝑥0 + 𝑥1 ≤ 6,
𝑥0 , 𝑥1 ≥ 0.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
basis[0] = 1,
basis[1] = 2.
Then the basis variables are 𝑥𝑐1 and 𝑥0 and the corresponding basis matrix 𝐵 is
[︂ ]︂
0 1
.
−1 1
def streamprinter(text):
sys.stdout.write(text)
sys.stdout.flush()
def main():
numcon = 2
numvar = 2
c =
[1.0, 1.0]
ptrb =
[0, 2]
ptre =
[2, 3]
asub =
[0, 1,
0, 1]
aval = [1.0, 1.0,
2.0, 1.0]
bkc = [mosek.boundkey.up,
mosek.boundkey.up]
blc = [-infinity,
-infinity]
buc = [2.0,
6.0]
bkx = [mosek.boundkey.lo,
mosek.boundkey.lo]
blx = [0.0,
0.0]
bux = [+infinity,
+infinity]
w1 = [2.0, 6.0]
w2 = [1.0, 0.0]
try:
with mosek.Env() as env:
with env.Task(0,0) as task:
task.set_Stream (mosek.streamtype.log, streamprinter)
task.inputdata(numcon,numvar,
c,
0.0,
ptrb,
ptre,
asub,
aval,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
bkc,
blc,
buc,
bkx,
blx,
bux)
task.putobjsense(mosek.objsense.maximize)
r = task.optimize()
if r != mosek.rescode.ok:
print ("Mosek warning:",r)
for i in range(numcon):
if basis[varsub[i]] < numcon:
print ("Basis variable no %d is xc%d" % (i,basis[i]))
else:
print ("Basis variable no %d is x%d" % (i,basis[i] - numcon))
# solve Bx = w1
# varsub contains index of non-zeros in b.
# On return b contains the solution x and
# varsub the index of the non-zeros in x.
nz = 2
for i in range(nz):
if basis[varsub[i]] < numcon:
print ("xc %s = %s" % (basis[varsub[i]],w1[varsub[i]]))
else:
print ("x%s = %s" % (basis[varsub[i]] - numcon, w1[varsub[i]]))
# Solve B^Tx = w2
nz = 1
varsub[0] = 0
for i in range(nz):
if basis[varsub[i]] < numcon:
print ("xc %s = %s" % (basis[varsub[i]], w2[varsub[i]]))
else:
print ("x %s = %s" % (basis[varsub[i]] - numcon, w2[varsub[i]]) )
except Exception as e:
print (e)
if __name__ == '__main__':
main()
In the example above the linear system is solved using the optimal basis for (5.4) and the original right-
hand side of the problem. Thus the solution to the linear system is the optimal solution to the problem.
When running the example program the following output is produced.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
basis[0] = 1
Basis variable no 0 is xc1.
basis[1] = 2
Basis variable no 1 is x0.
Solution to Bx = b:
x0 = 2.000000e+00
xc1 = -4.000000e+00
Solution to B^Tx = c:
x1 = -1.000000e+00
x0 = 1.000000e+00
is a solution to
𝑥𝑐1
[︂ ]︂ [︂ ]︂ [︂ ]︂
0 1 2
= .
−1 1 𝑥0 6
𝐴𝑥 = 𝑏
using the task.solvewithbasis function without optimizing the problem as in the previous exam-
ple. This is done by setting up an 𝐴 matrix in the task, setting all variables to basic and calling the
task.solvewithbasis function with the 𝑏 vector as input. The solution is returned by the function.
Below we demonstrate how to solve the linear system
[︂ ]︂ [︂ ]︂ [︂ ]︂
0 1 𝑥0 𝑏1
= (5.5)
−1 1 𝑥1 𝑏2
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.appendvars(numvar)
task.appendcons(numvar)
for i in range(len(asub)):
task.putacol(i,asub[i],aval[i])
for i in range(numvar):
task.putconbound(i,mosek.boundkey.fx,0.0,0.0)
for i in range(numvar):
task.putvarbound(i,
mosek.boundkey.fr,
-infinity,
infinity)
for i in range(numvar):
task.putsolutioni (mosek.accmode.var,
i,
mosek.soltype.bas,
skx[i],
0.0,
0.0,
0.0,
0.0)
for i in range(numvar):
task.putsolutioni (mosek.accmode.con,
i,
mosek.soltype.bas,
skc[i],
0.0,
0.0,
0.0,
0.0)
task.initbasissolve(basis)
def main():
numcon = 2
numvar = 2
aval = [ [ -1.0 ],
[ 1.0, 1.0 ] ]
asub = [ [ 1 ],
[ 0, 1 ] ]
ptrb = [ 0,1 ]
ptre = [ 1,3 ]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
put_a(task,
aval,
asub,
ptrb,
ptre,
numvar,
basis)
b[0] = 7
bsub[0] = 0
nz = task.solvewithbasis(0,1,bsub,b);
print("\nSolution to Bx = b:\n")
# Print solution and show correspondents
# to original variables in the problem
for i in range(nz):
if basis[bsub[i]] < numcon:
print ("This should never happen")
else:
print ("x%d = %d" % (basis[bsub[i]] - numcon, b[bsub[i]] ))
if __name__ == "__main__":
try:
main()
except:
import traceback
traceback.print_exc()
The most important step in the above example is the definition of the basic solution using the
task.putsolutioni function, where we define the status key for each variable. The actual values
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
of the variables are not important and can be selected arbitrarily, so we set them to zero. All variables
corresponding to columns in the linear system we want to solve are set to basic and the slack variables
for the constraints, which are all non-basic, are set to their bound.
The program produces the output:
Solution to Bx = b:
x1 = 1
x0 = 3
Solution to Bx = b:
x1 = 7
x0 = 7
Sometimes users need to perform linear algebra operations that involve dense matrices and vectors.
Also MOSEK uses extensively high-performance linear algebra routines from the BLAS and LAPACK
packages and some of this routine are included in the package shipped to the users.
MOSEK makes available to the user some BLAS and LAPACK routines by MOSEK functions that
• use MOSEK data types and response code;
• keep BLAS/LAPACK naming convention.
Therefore the user can leverage on efficient linear algebra routines, with a simplified interface, with no
need for additional packages. In the Table 5.1 we list BLAS functions.
A working example
In Listing 5.3 we provide a simple working example. It has no practical meaning except to show how to
call the provided functions and how the input should be organized.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Listing 5.3: A working example on how to call BLAS and LAPACK routines from MOSEK.
import mosek
for i in range(r):
print([ x[j*r + i] for j in range(c)])
n=3
m=2
k=3
alpha=2.0
beta=0.5
x=[1.0,1.0,1.0]
y=[1.0,2.0,3.0]
z=[1.0,1.0]
v=[0.0,0.0]
#A has m=2 rows and k=3 cols
A=[ 1.0,1.0,2.0,2.0, 3.,3.]
#B has k=3 rows and n=3 cols
B=[ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]
C=[ 0.0 for i in range(n*m)]
D=[ 1.0,1.0,1.0,1.0]
Q=[ 1.0,0.0,0.0,2.0]
# routines
xy = env.dot(n,x,y)
print("dot results= %f\n"%xy);
env.axpy(n,alpha,x,y)
print("\naxpy results is ")
print_matrix(y,1,len(y))
env.gemm(mosek.transpose.no,mosek.transpose.no,m,n,k,alpha,A,B,beta,C)
print("\ngemm results is ")
print_matrix(C,m,n)
# LAPACK routines
env.potrf(mosek.uplo.lo,m,Q)
print("\npotrf results is ")
print_matrix(Q,m,m)
env.syeig(mosek.uplo.lo,m,Q,v)
print("\nsyeig results is")
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
print_matrix(v,1,m)
env.syevd(mosek.uplo.lo,m,Q,v)
print("\nsyevd results is")
print('v: ')
print_matrix(v,1,m)
print('Q: ')
print_matrix(Q,m,m)
print("Exiting...")
𝐴 ∈ R𝑛×𝑛
𝐴 = 𝐿𝐿𝑇 .
𝐴𝑥 = 𝑏
𝐿𝑦 = 𝑏
𝐿𝑇 𝑥 = 𝑦.
For this reason only a Cholesky factorization is useful. Therefore, MOSEK provides function that can
compute a Cholesky factorization of a positive semidefinite matrix. In addition a function for performing
solves with a nonsingular lower triangular matrix and its tranpose is availble.
In practice 𝐴 may be very large e.g. 𝑛 is in the range of millions. However, then 𝐴 is typically
sparse which means that most of the elements in 𝐴 are zero. Fortunately the sparsity can be exploited
during computations of the Cholesky factorization to reduce the computational cost. How large the
computational savings are is dependent of the position of the zeros. This can be demonstrated using the
example
⎡ ⎤
4 1 1 1
⎢ 1 1 0 0 ⎥
𝐴=⎢ ⎣ 1 0 1 0 ⎦.
⎥ (5.6)
1 0 0 1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Next let us permute the rows and columns symmetrically of 𝐴 i.e. we multiply 𝐴 by the permutation
matrix
⎡ ⎤
0 1 0 0
⎢ 0 0 1 0 ⎥
𝑃 =⎢ ⎣ 0 0 0 1 ⎦
⎥
1 0 0 0
as follows
⎡ ⎤
1 0 0 1
⎢ 0 1 0 1 ⎥
𝑃 𝐴𝑃 𝑇 =⎢
⎣ 0
⎥.
0 1 1 ⎦
1 1 1 4
𝑃 𝐴𝑃 𝑇
is
⎡ ⎤
1 0 0 0
⎢ 0 1 0 0 ⎥
𝐿=⎢
⎣ 0
⎥.
0 1 0 ⎦
1 1 1 1
Listing 5.4: How to use the sparse Cholesky factorization routine available in MOSEK.
import sys
import mosek
def sparsecholesky(env,
n,
anzc,
asubc,
aptrc,
avalc):
try:
perm,diag,lnzc,lptrc,lensubnval,lsubc,lvalc = env.computesparsecholesky(multiworker,
order_meth,
tolsingular,
anzc,
aptrc,
asubc,
avalc)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
for i in range(n):
print ( ' '.join( [ "%d perm=%d diag=%.4e :" % (i, perm[i], diag[i])] +
[ " %.4e[%d]" % (lvalc[lptrc[i]+s],lsubc[lptrc[i]+s]) for s in ␣
˓→range(lnzc[i]) ]
)
)
except:
raise
return perm,diag,lnzc,lptrc,lensubnval,lsubc,lvalc
# Let A be
#
# [4.0 1.0 1.0 1.0]
# [1.0 1.0 ]
# [1.0 1.0 ]
# [1.0 1.0]
#
# then
#
# a. Compute a sparse Cholesky factorization A.
# b. Solve the linear system A x = b using the Cholesky factor
#
# Observe that anzc, aptrc, asubc and avalc only specify the lower triangular part.
n = 4
anzc = [4, 1, 1, 1]
asubc = [0, 1, 2, 3, 1, 2, 3]
aptrc = [0, 4, 5, 6]
avalc = [4.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
b = [13.0, 3.0, 4.0, 5.0]
# Permuted b is stored as x.
x = [ b[p] for p in perm ]
# Compute x = inv(L)*x.
env.sparsetriangularsolvedense(mosek.transpose.no,
lnzc,
lptrc,
lsubc,
lvalc,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
x)
# Compute x = inv(L^T)*x.
env.sparsetriangularsolvedense(mosek.transpose.yes,
lnzc,
lptrc,
lsubc,
lvalc,
x)
print("\n\nSolution A x = b")
print('\n'.join([ "x[%d]: %.2e"% (pp,xx) for pp,xx in zip(perm,x) ] ) )
n = 3
anzc = [3, 2, 1]
asubc = [0, 1, 2, 1, 2, 2]
aptrc = [0, 3, 5]
avalc = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
# Let A be
#
# [1.0 1.0 1.0]
# [1.0 1.0 1.0]
# [1.0 1.0 1.0]
#
# then compute a sparse Cholesky factorization A. Observe A is NOT
# positive definite.
#
Solution A x = b
x[3]: 4.00e+000
x[2]: 3.00e+000
x[0]: 1.00e+000
x[1]: 2.00e+000
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
has been employed. Now the Cholesky factorization of the permuted matrix is reported to be
⎡ ⎤
1 0 0 0
⎢ 0 1 0 0 ⎥
⎢ ⎥
⎣ 1 1 1.4142 0 ⎦
0 0 0.7071 0.7071
𝐴𝑥 = 𝑏
where 𝑏 is
[︀ ]︀𝑇
13.0 3.0 4.0 5.0 .
which is correct.
The second example in the source code shows what happens if a sparse Cholesky factorization of a
semidefinite matrix is computed. The example 𝐴 is
⎡ ⎤ ⎡ ⎤⎡ ⎤𝑇
1 1 1 1 1
𝐴=⎣ 1 1 1 ⎦ = ⎣ 1 ⎦⎣ 1 ⎦ (5.7)
1 1 1 1 1
𝑃 𝐴𝑃 𝑇 + 𝐷 = 𝐿𝐿𝑇
where
⎡ ⎤
1 0 0
𝐷=⎣ 0 1.0𝑒 − 14 0 ⎦,
0 0 1.0𝑒 − 14
⎡ ⎤
1 0 0
𝐿=⎣ 1 1.0𝑒 − 7 0 ⎦
1 0 1.0𝑒 − 7
and
⎡ ⎤
1 0 0
𝑃 =⎣ 0 0 1 ⎦.
0 1 0
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Since 𝐴 is only positive semdefinite i.e. not of full rank then some of diagonal elements of 𝐴 are boosted
to make it truely positive definite. The amount of boosting is given as an argument to the function
computing the sparse Cholesky factorization and has been chosen to 1.0e-14.
Note that
𝑃 𝐴𝑃 𝑇 − 𝐿𝐿𝑇 = 𝐷
where 𝐷 is a small matrix so the computed Cholesky factorization is exact of slightly perturbed 𝐴 which
in general is the best we hope for given computations are performed finite precision.
We will end this section by a word of caution. Computing a Cholesky factorization of a matrix that is
not of full rank and that is not suffciently well conditioned may lead to incorrect results i.e. a matrix
that is indefinite may declared positive semidefinite and vice versa.
𝑥 ∈ 𝒬𝑛
𝑥1 ≥ 0.0.
Therefore, it is possible to state conic quadratic problems using quadratic inequalities. Some drawbacks
of specifying conic quadratic problems using quadratic inequalities are
• the elegant duality theory for conic problems is lost.
• reporting accurate dual information for quadratic inequalities is hard and/or compuational expen-
sive.
• the left hand side of (5.8) is nonconvex so the formulation is stricly speaking not convex.
• a computational overhead is introduced when converting the quadratic inequalities to conic form
before optimizing.
• modelling directly on conic form usually leads to a better model [And13] i.e. a faster solution time
and better numerical properties.
In addition quadratic inequalities can not be used to speciffy the semidefinite cone or other more general
cones than quadratic cone. Despite the drawbacks it is not uncommon to state conic quadratic problems
using quadratic inequalities and therefore MOSEK has a function that translate certain quadratic-
cally constrained problems to conic form. Note that the MOSEK interior-point optimizer will do that
automatically for convex quadratic problems automatically. So quadratic to conic form conversion is
primarily useful for problems having conic quadratic constraints embedded.
MOSEK employs the following form of quadratic problems:
minimize 1 𝑇 𝑜
2𝑥 𝑄 𝑥 + 𝑐𝑇 𝑥 + 𝑐𝑓
∑︀𝑛−1
subject to 𝑙𝑘𝑐 ≤ 1 𝑇 𝑘
2𝑥 𝑄 𝑥 + 𝑗=0 𝑎𝑘,𝑗 𝑥𝑗 ≤ 𝑢𝑐𝑘 , 𝑘 = 0, . . . , 𝑚 − 1,
𝑙𝑗𝑥 ≤ 𝑥𝑗 ≤ 𝑢𝑥𝑗 , 𝑗 = 0, . . . , 𝑛 − 1.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The reformulation is not unique. The approach followed by MOSEK is to introduce additional variables,
linear constraints and quadratic cones to obtain a larger but equivalent problem in which the original
variables are preserved.
In particular:
• all variables and constraints are kept in the problem,
• for each reformulated quadratic constraint there will be:
– one rotated quadratic cone for each quadratic constraint,
– one rotated quadratic cone if the objective function is quadratic,
– each quadratic constraint will contain no coefficients and upper/lower bounds will be set to
∞, −∞ respectively.
This allows the user to recover the original variable and constraint values, as well as their dual values,
with no conversion or additional effort.
Note: task.toconic modifies the input task in-place: this means that if the reformulation is not
possible, i.e. the problem is not conic representable, the state of the task is in general undefined. The
user should consider cloning the original task.
in conic form. We first check it must hold either 𝑙 = −∞ or 𝑢 = ∞, otherwise either the constraint can
be dropped, or the constraint is not convex. Thus let us consider the case
𝑛−1
1 𝑇 ∑︁
𝑥 𝑄𝑥 + 𝑎𝑇𝑗 𝑥𝑗 ≤ 𝑢. (5.9)
2 𝑗=0
𝑄 = 𝐹𝐹𝑇 (5.11)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
We report in this section few examples of reformulation of a QCQP problem in conic form. For each
problem we will show its definition before and after the reformulation, using the human-readable OPF
format.
Quadratic problem
[comment]
An example of small QP from Boyd and Vandenberghe, "Convex Optimization", pag 189 ex 4.3
The solution is (1,0.5,-1)
[/comment]
[variables disallow_new_variables]
x0 x1 x2
[/variables]
[objective min]
0.5 (13 x0^2 + 17 x1^2 + 12 x2^2 + 24 x0 * x1 + 12 x1 * x2 - 4 x0 * x2 ) - 22 x0 - 14.5 x1 +␣
˓→12 x2 + 1
[/objective]
[bounds]
[b] -1 <= * <= 1 [/b]
[/bounds]
The objective function is convex, the solution is attained for 𝑥⋆ = (1, 0.5, −1). The conversion will
introduce first a variable 𝑥3 in the objective function such that 𝑥3 ≥ 1/2𝑥𝑇 𝑄𝑥 and then convert the
latter directly in conic form. The converted problem follows:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Time 15:51:41
[/comment]
[variables disallow_new_variables]
x0000_x0 x0001_x1 x0002_x2 x0003 x0004
x0005 x0006 x0007 x0008
[/variables]
[objective minimize]
- 2.2e+01 x0000_x0 - 1.45e+01 x0001_x1 + 1.2e+01 x0002_x2 + x0003
+ 1e+00
[/objective]
[constraints]
[con c0000] 3.605551275463989e+00 x0000_x0 - 5.547001962252291e-01 x0002_x2 + 3.
˓→328201177351375e+00 x0001_x1 - x0006 = 0e+00 [/con]
[bounds]
[b] 0 <= * [/b]
[b] -1e+00 <= x0000_x0,x0001_x1,x0002_x2 <= 1e+00 [/b]
[b] x0003 free [/b]
[b] x0005 = 1e+00 [/b]
[b] x0006,x0007,x0008 free [/b]
[cone rquad k0000] x0005, x0004, x0006, x0007, x0008 [/cone]
[/bounds]
We can clearly see that constraints c0000 to c0002 represent the linear mapping as in (5.11), while (5.10)
corresponds to c0003. The cone roots are x0005 and x0004.
MOSEK provides an easy way to offload optimization problem to a remote server in both synchronous
or asynchronous mode. This section describes the functionalities from the client side, i.e. how a user
can send a given optimization problem to a remote server where a optimization server is listening and
will run MOSEK to solve the problem.
In synchoronous mdoe the client send the optimization problem to the optimization server and wait
for the optimization to end. Once the result has been received, the program can continue. This is the
simplest mode and requires very limited modifications to existing code: instead of task.optimize we
only need to use task.optimizermt instead, passing the host and port on which the server is running
and listening.
The rest of the code remains untouched.
Important: There is no way to recover a job in case the connection has been broken!
In Listing 5.5 we show how to modify tutorial in Section 3.1 so that the computation is off loaded to a
remote machine.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
def streamprinter(msg):
sys.stdout.write (msg)
sys.stdout.flush ()
if len(sys.argv) <= 3:
print ("Missing argument, syntax is:")
print (" opt_server_sync inputfile host port")
else:
inputfile = sys.argv[1]
host = sys.argv[2]
port = sys.argv[3]
Working in asynchronous mode involves more steps. In particular once that the optimization has started,
the user is responsible to check the status and when optimization ends, fetch the results. The user can
also stop the optimization anytime. The relevant functions are:
• task.asyncgetresult : Request a response from a remote job.
• task.asyncoptimize : Offload the optimization task to a solver server.
• task.asyncpoll : Requests information about the status of the remote job.
• task.asyncstop : Request that the job identified by the token is terminated.
In Listing 5.6 the code in Listing 5.5 is extended in order to run asynchronously: after that the opti-
mization is started, the program enters in a polling loop that regularly checks whether the result of the
optimization is available.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
def streamprinter(msg):
sys.stdout.write (msg)
sys.stdout.flush ()
if len(sys.argv) != 5:
print ("Missing argument, syntax is:")
print (" opt-server-async inputfile host port numpolls")
else:
filename = sys.argv[1]
host = sys.argv[2]
port = sys.argv[3]
numpolls = int(sys.argv[4])
token = None
task.readdata (filename)
i = 0
time.sleep(0.1)
print("poll %d...",i)
respavailable, trm, res = task.asyncpoll( host,
port,
token)
print("done!")
if respavailable:
print("solution available!")
respavailable, trm, res = task.asyncgetresult(host,
port,
token)
task.solutionsummary (mosek.streamtype.log)
break
i = i+1
if i == numpolls:
print("max number of polls reached, stopping host.")
task.asyncstop (host, port, token)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
CHAPTER
SIX
GUIDELINES
6.1 Deployment
When redistributing a Python application using the MOSEK Optimizer API for Python 8.0.0.64, the
following libraries must be included:
64-bit Linux 64-bit Windows 32-bit Windows 64-bit Mac OS
libmosek64.so.8.0 mosek64_8_0.dll mosek32_8_0.dll libmosek64.dylib.8.0
libiomp5.lib libiomp5md.dll libomp5md.dll libiomp5.dylib
libcilkrts.so.5 cilkrts20.dll cilkrts20.dll libcilkrts.5.dylib
libmosekxx8_0.so mosekxx8_0.dll mosekxx8_0.dll libmosekxx8_0.dylib
libmosekscopt8_0.so mosekscopt8_0.dll mosekscopt8_0.dll libmosekscopt8_0.dylib
Furthermore, one (or both) of the directories
• python/2/mosek for Python 2.x applications, and
• python/3/mosek for Python 3.x applications.
must be included.
By default the MOSEK Python API will look for the binary libraries in the MOSEK module directory,
i.e. the directory containing __init__.py. Alternative, if the binary libraries reside in another directory,
the application can pre-load the mosekxx library from another located before mosek is imported, e.g.
like this
Although MOSEK is implemented to handle memory efficiently, the user may have valuable knowledge
about a problem, which could be used to improve the performance of MOSEK This section discusses
some tricks and general advice that hopefully make MOSEK process your problem faster.
MOSEK stores the optimization problem in internal data structures in the memory. Initially MOSEK
will allocate structures of a certain size, and as more items are added to the problem the structures are
reallocated. For large problems the same structures may be reallocated many times causing memory
fragmentation. One way to avoid this is to give MOSEK an estimated size of your problem using the
functions:
• task.putmaxnumvar . Estimate for the number of variables.
• task.putmaxnumcon . Estimate for the number of constraints.
• task.putmaxnumcone . Estimate for the number of cones.
77
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
For instance, the functions task.putacol and task.getacol . MOSEK will queue put- commands
internally until a get- function is called. If every put- function call is followed by a get- function call,
the queue will have to be flushed often, decreasing efficiency.
In general get- commands should not be called often during problem setup.
When removing constraints and variables, try to use a LIFO approach, i.e. Last In First out. MOSEK
can more efficiently remove constraints and variables with a high index than a small index.
An alternative to removing a constraint or a variable is to fix it at 0, and set all relevant coefficients to
0. Generally this will not have any impact on the optimization speed.
The cost of adding one constraint or one variable is about the same as adding many of them. Therefore,
it may be worthwhile to add many variables instead of one. Initially fix the unused variable at zero, and
then later unfix them as needed. Similarly, you can add multiple free constraints and then use them as
needed.
When doing re-optimizations, instead of removing a basic variable it may be more efficient to fix the
variable at zero and then remove it when the problem is re-optimized and it has left the basis. This
makes it easier for MOSEK to restart the simplex optimizer.
If possible share the environment (env) between several tasks. For most applications you need to create
only a single env.
The Python interface is a thin wrapper around a native MOSEK library. The layer between the Python
application and the native MOSEK library is made as thin as possible to minimize the overhead from
function calls.
The methods in Env and Task are all written in C and resides in the module pymosek. Each method
converts the call parameter data structures (i.e. creates a complete copy of the data), calls MOSEK
function and converts the returned values back into Python structures.
The following rules will often improve the performance of the MOSEK/ Python API:
78 Chapter 6. Guidelines
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• Reuse Env and Task whenever possible : There may be some overhead involved in creating and
deleting task and environment objects, so if possible reuse these.
• Make sure to delete task and environment when not in use anymore. Using the with-construction
(available in Python 2.6 and later) will allow automatic deletion of the environment and task. If
this is not an option, use Env.__del__() and Task.__del__() to destroy the objects. Failing to
do this may cause memory leaks in some cases.
• Avoid input loops: Whenever possible imput data in large chunks or vectors instead of using loops.
For small put- and get- methods there is a significant overhead, so for example inputting one row
of the A-matrix at the time may be much slower than inputting the whole matrix.
For example, a loop with task.putarow may be replaced with one task.putarowlist , or a loop of
task.putqobjij may be replaced with task.putqobj .
MOSEK is a commercial product that always needs a valid license to work. A license is typically
provided as a license file that allows the user to access the subset of the MOSEK Optimization Suite
functionalities it is entitled for, and for the right amount of time. MOSEK uses a third party license
manager to implement license checking.
By default a license token remains checked out for the duration of the MOSEK session, i.e.
1. a license token is checked out when task.optimize is first called and
2. it is returned when the MOSEK environment is deleted.
Calling task.optimize from different threads using the same MOSEK environment only consumes one
license token.
To change the license systems behavior to returning the license token after each call to MOSEK set the
parameter iparam.cache_license to onoffkey.off .
Additionally license checkout and checkin can be controlled manually with the functions
env.checkinlicense and env.checkoutlicense .
By default an error will be returned if no license token is available. By setting the parameter
iparam.license_wait MOSEK can be instructed to wait until a license token is available.
Usually the license system is stopped automatically when the MOSEK library is unloaded. However,
when the user explicitly unload the library using e.g windows FreeLibrary, the license system must be
stopped before the library is unloaded. This can be done by calling the function env.licensecleanup
as the last function call to MOSEK.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
80 Chapter 6. Guidelines
www.EngineeringBooksPdf.com
CHAPTER
SEVEN
CASE STUDIES
In this section we present some case studies in which the Optimizer API for Python is used to solve
real-life applications. These examples involve some more advanced modeling skills and possibly some
input data. The user is strongly recommended to first read the basic tutorials before going through these
advanced case studies.
Case Studies Type Int. Keywords
Portofolio Optimization CQO NO Markowitz, Slippage, Market Impact
In this section the Markowitz portfolio optimization problem and variants are implemented using the
MOSEK optimizer API.
Subsequently the following MATLAB inspired notation will be employed. The : operator is used as
follows
𝑖 : 𝑗 = {𝑖, 𝑖 + 1, . . . , 𝑗}
and hence
⎡ ⎤
𝑥2
𝑥2:4 = ⎣ 𝑥3 ⎦
𝑥4
If 𝑥 and 𝑦 are two column vectors, then
[︂ ]︂
𝑥
[𝑥; 𝑦] =
𝑦
Furthermore, if 𝑓 ∈ R𝑚×𝑛 then
⎡ ⎤
𝑓1,1
⎢ 𝑓2,1 ⎥
..
⎢ ⎥
.
⎢ ⎥
⎢ ⎥
𝑓 (:) = ⎢
⎢ 𝑓𝑚−1,𝑛
⎥
⎥
..
⎢ ⎥
.
⎢ ⎥
⎣ ⎦
𝑓𝑚,𝑛
i.e. 𝑓 (:) stacks the columns of the matrix 𝑓 .
The classical Markowitz portfolio optimization problem considers investing in 𝑛 stocks or assets held
over a period of time. Let 𝑥𝑗 denote the amount invested in asset 𝑗, and assume a stochastic model
where the return of the assets is a random variable 𝑟 with known mean
𝜇 = E𝑟
81
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
and covariance
The return of the investment is also a random variable 𝑦 = 𝑟𝑇 𝑥 with mean (or expected return)
E𝑦 = 𝜇𝑇 𝑥
(𝑦 − E𝑦)2 = 𝑥𝑇 Σ𝑥.
The problem facing the investor is to rebalance the portfolio to achieve a good compromise between risk
and expected return, e.g., maximize the expected return subject to a budget constraint and an upper
bound (denoted 𝛾) on the tolerable risk. This leads to the optimization problem
maximize 𝜇𝑇 𝑥
subject to 𝑒𝑇 𝑥 = 𝑤 + 𝑒𝑇 𝑥0 ,
(7.1)
𝑥𝑇 Σ𝑥 ≤ 𝛾2,
𝑥 ≥ 0.
The variables 𝑥 denote the investment i.e. 𝑥𝑗 is the amount invested in asset 𝑗 and 𝑥0𝑗 is the initial
holding of asset 𝑗. Finally, 𝑤 is the initial amount of cash available.
A popular choice is 𝑥0 = 0 and 𝑤 = 1 because then 𝑥𝑗 may be interpretated as the relative amount of
the total portfolio that is invested in asset 𝑗.
Since 𝑒 is the vector of all ones then
𝑛
∑︁
𝑒𝑇 𝑥 = 𝑥𝑗
𝑗=1
is the total investment. Clearly, the total amount invested must be equal to the initial wealth, which is
𝑤 + 𝑒𝑇 𝑥0 .
𝑒𝑇 𝑥 = 𝑤 + 𝑒𝑇 𝑥0 .
𝑥𝑇 Σ𝑥 ≤ 𝛾 2
ensures that the variance, or the risk, is bounded by 𝛾 2 . Therefore, 𝛾 specifies an upper bound of the
standard deviation the investor is willing to undertake. Finally, the constraint
𝑥𝑗 ≥ 0
excludes the possibility of short-selling. This constraint can of course be excluded if short-selling is
allowed.
The covariance matrix Σ is positive semidefinite by definition and therefore there exist a matrix 𝐺 such
that
Σ = 𝐺𝐺𝑇 . (7.2)
In general the choice of 𝐺 is not unique and one possible choice of 𝐺 is the Cholesky factorization of Σ.
However, in many cases another choice is better for efficiency reasons as discussed in Section 7.1.3 .
For a given 𝐺 we have that
𝑥𝑇 Σ𝑥 = 𝑥𝑇 𝐺𝐺𝑇 𝑥
⃦ ⃦2
= ⃦𝐺𝑇 𝑥⃦ .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝛾 ≥ ⃦𝐺𝑇 𝑥⃦
⃦ ⃦
or equivalently
[𝛾; 𝐺𝑇 𝑥] ∈ 𝒬𝑛+1 .
where 𝒬𝑛+1 is the 𝑛 + 1 dimensional quadratic cone. Therefore, problem (7.1) can be written as
maximize 𝜇𝑇 𝑥
subject to 𝑒𝑇 𝑥 = 𝑤 + 𝑒𝑇 𝑥0 ,
(7.3)
[𝛾; 𝐺 𝑥] ∈ 𝒬𝑛+1 ,
𝑇
𝑥 ≥ 0,
which is a conic quadratic optimization problem that can easily be solved using MOSEK.
Subsequently we will use the example data
⎡ ⎤
0.1073
𝜇 = ⎣ 0.0737 ⎦
0.0627
and
⎡ ⎤
0.2778 0.0387 0.0021
Σ = 0.1 ⎣ 0.0387 0.1112 −0.0020 ⎦
0.0021 −0.0020 0.0115
This implies
⎡ ⎤
√ 0.5271 0.0734 0.0040
𝐺𝑇 = 0.1 ⎣ 0 0.3253 −0.0070 ⎦
0 0 0.1069
using 5 figures of accuracy. Moreover, let
⎡ ⎤
0.0
𝑥0 = ⎣ 0.0 ⎦
0.0
and
𝑤 = 1.0.
Problem (7.1) is a convex quadratically constrained optimization problems that can be solved directly
using MOSEK, then why reformulate it as a conic quadratic optimization problem? The main reason
for choosing a conic model is that it is more robust and usually leads to a shorter solution times. For
instance it is not always easy to determine whether the 𝑄 matrix in (7.1) is positive semidefinite due to
the presence of rounding errors. It is also very easy to make a mistake so 𝑄 becomes indefinite. These
causes of problems are completely eliminated in the conic formulation.
Moreover, observe the constraint
⃦ 𝑇 ⃦
⃦𝐺 𝑥⃦ ≤ 𝛾
is nicer than
𝑥𝑇 Σ𝑥 ≤ 𝛾 2
for small and values of 𝛾. For instance assume a 𝛾 of 10000 then 𝛾 2 would 1.0e8 which introduces
a scaling issue in the model. Hence, using conic formulation it is possible to work with the standard
deviation instead of the variance, which usually gives rise to a better scaled model.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Model (7.3) can not be implemented as stated using the MOSEK optimizer API because the API
requires the problem to be on the form
maximize 𝑐𝑇 𝑥
ˆ
subject to 𝑙𝑐
≤ 𝐴ˆ𝑥 ≤ 𝑢𝑐 ,
(7.4)
𝑙𝑥 ≤ 𝑥
ˆ ≤ 𝑢𝑥 ,
ˆ ∈ 𝒦.
𝑥
where 𝑥
ˆ is referred to as the API variable.
The first step in bringing (7.3) to the form (7.4) is the reformulation
maximize 𝜇𝑇 𝑥
subject to 𝑒𝑇 𝑥 = 𝑤 + 𝑒𝑇 𝑥0 ,
𝑇
𝐺 𝑥−𝑡 = 0
(7.5)
[𝑠; 𝑡] ∈ 𝒬𝑛+1 ,
𝑥 ≥ 0,
𝑠 0.
where 𝑠 is an additional scalar variable and 𝑡 is a n dimensional vector variable. The next step is to
define a mapping of the variables
⎡ ⎤
𝑥
ˆ = [𝑥; 𝑠; 𝑡] = ⎣ 𝑠 ⎦ .
𝑥 (7.6)
𝑡
Hence, the API variable 𝑥ˆ is concatenation of model variables 𝑥, 𝑠 and 𝑡. In Table 7.1 the details of the
concatenation are specified.
𝑥
ˆ𝑛+2 = 𝑡1 .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The next step is to consider how the columns of 𝐴 is defined. The following pseudo code
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ 𝑗 = 𝑥𝑗
𝐴1,𝑗 = 1.0
𝐴2:(𝑛+1),𝑗 = 𝐺𝑇𝑗,1:𝑛
𝑥
ˆ𝑛+1 = 𝑠
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ𝑛+1+𝑗 = 𝑡𝑗
𝐴𝑛+1+𝑗,𝑛+1+𝑗 = −1.0
def streamprinter(text):
print("%s" % text),
if __name__ == '__main__':
n = 3
gamma = 0.05
mu = [0.1073, 0.0737, 0.0627]
GT = [[0.1667, 0.0232, 0.0013],
[0.0000, 0.1033, -0.0022],
[0.0000, 0.0000, 0.0338]]
x0 = [0.0, 0.0, 0.0]
w = 1.0
rtemp = w
for j in range(0,n):
rtemp += x0[j]
# Constraints.
task.appendcons(1+n)
task.putconbound(0,mosek.boundkey.fx,rtemp,rtemp)
task.putconname(0,"budget")
task.putconboundlist(range(1+0,1+n),n*[mosek.boundkey.fx],n*[0.0],n*[0.0])
for j in range(1,1+n) :
task.putconname(j,"GT[%d]" % j)
# Variables.
task.appendvars(1+2*n)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# x variables.
task.putclist(range(offsetx+0,offsetx+n),mu)
task.putaijlist(n*[0],range(offsetx+0,offsetx+n),n*[1.0])
for j in range(0,n):
task.putaijlist(n*[1+j],range(offsetx+0,offsetx+n),GT[j])
task.putvarboundlist(range(offsetx+0,offsetx+n),n*[mosek.boundkey.lo],n*[0.
˓→ 0],n*[inf])
for j in range(0,n):
task.putvarname(offsetx+j,"x[%d]" % (1+j))
# s variable.
task.putvarbound(offsets+0,mosek.boundkey.fx,gamma,gamma)
task.putvarname(offsets+0,"s")
# t variables.
task.putaijlist(range(1,n+1),range(offsett+0,offsett+n),n*[-1.0])
task.putvarboundlist(range(offsett+0,offsett+n),n*[mosek.boundkey.fr],n*[-
˓→inf],n*[inf])
for j in range(0,n):
task.putvarname(offsett+j,"t[%d]" % (1+j))
task.putobjsense(mosek.objsense.maximize)
task.optimize()
expret = 0.0
x = [0.]*n
task.getxxslice(mosek.soltype.itr,offsetx+0,offsetx+n,x)
for j in range(0,n):
expret += mu[j]*x[j]
stddev = [0.]
task.getxxslice(mosek.soltype.itr,offsets+0,offsets+1,stddev)
The source code should be self-explanatory but a few comments are nevertheless in place.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
In the lines
# Offset of variables into the API variable.
offsetx = 0
offsets = n
offsett = n+1
offsets into the MOSEK API variables are stored and those offsets are used later. The code
task.putclist(range(offsetx+0,offsetx+n),mu)
task.putaijlist(n*[0],range(offsetx+0,offsetx+n),n*[1.0])
for j in range(0,n):
task.putaijlist(n*[1+j],range(offsetx+0,offsetx+n),GT[j])
task.putvarboundlist(range(offsetx+0,offsetx+n),n*[mosek.boundkey.lo],n*[0.0],n*[inf])
for j in range(0,n):
task.putvarname(offsetx+j,"x[%d]" % (1+j))
inputs the objective coefficients for the x variables. Moreover, the code
for j in range(0,n):
task.putvarname(offsetx+j,"x[%d]" % (1+j))
assigns meaningful names to the API variables. This is not needed but it makes debugging easier.
Debugging Tips
Implementing an optimization model in optimizer can be cumbersome and error-prone and it is very
easy to make mistakes. In order to check the implemented code for mistakes it is very useful to dump
the problem to a file in a human readable form for visual inspection. The line
#task.writedata("dump.opf")
does that and this will produce a file with the content
[hints]
[hint NUMVAR] 7 [/hint]
[hint NUMCON] 4 [/hint]
[hint NUMANZ] 12 [/hint]
[hint NUMQNZ] 0 [/hint]
[hint NUMCONE] 1 [/hint]
[/hints]
[variables disallow_new_variables]
'x[1]' 'x[2]' 'x[3]' s 't[1]'
't[2]' 't[3]'
[/variables]
[objective maximize]
1.073e-001 'x[1]' + 7.37e-002 'x[2]' + 6.270000000000001e-002 'x[3]'
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[/objective]
[constraints]
[con 'budget'] 'x[1]' + 'x[2]' + 'x[3]' = 1e+000 [/con]
[con 'GT[1]'] 1.667e-001 'x[1]' + 2.32e-002 'x[2]' + 1.3e-003 'x[3]' - 't[1]' = 0e+000 [/
˓→con]
[bounds]
[b] 0 <= * [/b]
[b] s = 5e-002 [/b]
[b] 't[1]','t[2]','t[3]' free [/b]
[cone quad 'stddev'] s, 't[1]', 't[2]', 't[3]' [/cone]
[/bounds]
Observe that since the API variables have been given meaningful names it is easy to see the model is
correct.
The portfolio computed by the Markowitz model is efficient in the sense that there is no other portfolio
giving a strictly higher return for the same amount of risk. An efficient portfolio is also sometimes called
a Pareto optimal portfolio. Clearly, an investor should only invest in efficient portfolios and therefore it
may be relevant to present the investor with all efficient portfolios so the investor can choose the portfolio
that has the desired tradeoff between return and risk.
Given a nonnegative 𝛼 then the problem
maximize 𝜇𝑇 𝑥 − 𝛼𝑠
subject to 𝑒𝑇 𝑥 = 𝑤 + 𝑒𝑇 𝑥0 ,
𝑇 (7.7)
[𝑠; 𝐺 𝑥] ∈ 𝒬𝑛+1 ,
𝑥 ≥ 0.
computes efficient portfolios. Note that the objective maximizes the expected return while maximizing
−𝛼 times the standard deviation. Hence, the standard deviation is minimized while 𝛼 specifies the
tradeoff between expected return and risk.
Ideally the problem (7.7) should be solved for all values 𝛼 ≥ 0 but in practice that is computationally
too costly.
Using the example data from Section 7.1.1 , the optimal values of return and risk for several 𝛼s are listed
below:
Listing 7.3: Results obtained solving problem (7.7) for different values of 𝛼.
alpha exp ret std dev
0.000e+000 1.073e-001 7.261e-001
2.500e-001 1.033e-001 1.499e-001
5.000e-001 6.976e-002 3.735e-002
7.500e-001 6.766e-002 3.383e-002
1.000e+000 6.679e-002 3.281e-002
1.500e+000 6.599e-002 3.214e-002
2.000e+000 6.560e-002 3.192e-002
2.500e+000 6.537e-002 3.181e-002
3.000e+000 6.522e-002 3.176e-002
3.500e+000 6.512e-002 3.173e-002
4.000e+000 6.503e-002 3.170e-002
4.500e+000 6.497e-002 3.169e-002
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The example code in Listing 7.4 demonstrates how to compute the efficient portfolios for several values
of 𝛼.
def streamprinter(text):
print("%s" % text),
if __name__ == '__main__':
n =3
gamma =0.05
mu =[0.1073, 0.0737, 0.0627]
GT =[[0.1667, 0.0232, 0.0013],
[0.0000, 0.1033, -0.0022],
[0.0000, 0.0000, 0.0338]]
x0 = [0.0, 0.0, 0.0]
w = 1.0
alphas = [0.0, 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
rtemp = w
for j in range(0,n):
rtemp += x0[j]
# Constraints.
task.appendcons(1+n)
task.putconbound(0,mosek.boundkey.fx,rtemp,rtemp)
task.putconname(0,"budget")
task.putconboundlist(range(1+0,1+n),n*[mosek.boundkey.fx],n*[0.0],n*[0.0])
for j in range(1,1+n) :
task.putconname(j,"GT[%d]" % j)
# Variables.
task.appendvars(1+2*n)
# x variables.
task.putclist(range(offsetx+0,offsetx+n),mu)
task.putaijlist(n*[0],range(offsetx+0,offsetx+n),n*[1.0])
for j in range(0,n):
task.putaijlist(n*[1+j],range(offsetx+0,offsetx+n),GT[j])
task.putvarboundlist(range(offsetx+0,offsetx+n),n*[mosek.boundkey.lo],n*[0.
˓→0],n*[inf])
for j in range(0,n):
task.putvarname(offsetx+j,"x[%d]" % (1+j))
# s variable.
task.putvarbound(offsets+0,mosek.boundkey.fr,gamma,gamma)
task.putvarname(offsets+0,"s")
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# t variables.
task.putaijlist(range(1,n+1),range(offsett+0,offsett+n),n*[-1.0])
task.putvarboundlist(range(offsett+0,offsett+n),n*[mosek.boundkey.fr],n*[-
˓→inf],n*[inf])
for j in range(0,n):
task.putvarname(offsett+j,"t[%d]" % (1+j))
task.appendcone(mosek.conetype.quad,0.0,[offsets] + list(range(offsett,offsett+n)))
task.putconename(0,"stddev")
task.putobjsense(mosek.objsense.maximize)
task.putcj(offsets+0,-alpha);
task.optimize()
solsta = task.getsolsta(mosek.soltype.itr)
stddev = [0.]
task.getxxslice(mosek.soltype.itr,offsets+0,offsets+1,stddev)
In practice it is often important to solve the portfolio problem in a short amount of time; this section it
is discusses what can be done at the modelling stage to improve the computational efficiency.
The computational cost is of course to some extent dependent on the number of constraints and variables
in the optimization problem. However, in practice a more important factor is the number nonzeros used
to represent the problem. Indeed it is often better to focus at the number of nonzeros in 𝐺 (see (7.2))
and try to reduce that number by for instance changing the choice of 𝐺.
In other words, if the computational efficiency should be improved then it is always good idea to start
with focusing at the covariance matrix. As an example assume that
Σ=𝐷+𝑉𝑉𝑇
where 𝐷 is positive definite diagonal matrix. Moreover, 𝑉 is a matrix with 𝑛 rows and 𝑝 columns. Such
a model for the covariance matrix is called a factor model factor model and usually 𝑝 tends be a small
number, say less than 100, independent of 𝑛.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
One possible choice for 𝐺 is the Cholesky factorization of Σ which requires storage proportional to
𝑛(𝑛 + 1)/2. However, another choice is
[︂ 1/2 ]︂
𝐷
𝐺𝑇 =
𝑉𝑇
because then
𝐺𝐺𝑇 = 𝐷 + 𝑉 𝑉 𝑇 .
This choice requires storage proportional to 𝑛 + 𝑝𝑛 which is much less than for the Cholesky choice of
𝐺. Indeed assuming 𝑝 is a constant then the difference in storage requirements is a factor of 𝑛.
The example above exploits the so-called factor structure and demonstrates that an alternative choice
of 𝐺 may lead to a significant reduction in the amount of storage used to represent the problem. This
will in most cases also lead to a significant reduction in the solution time.
The lesson to be learned is that it is important to investigate how the covariance is formed. Given this
knowledge it might be possible to make a special choice for 𝐺 that helps reducing the storage requirements
and enhance the computational efficiency.
The basic Markowitz portfolio model assumes that there are no costs associated with trading the assets
and that the returns of the assets is independent of the amount traded. None of those assumptions are
usually valid in practice. Therefore, a more realistic model is
maximize 𝑇
∑︀𝑛𝜇 𝑥
subject to 𝑒 𝑥 + 𝑗=1 𝐶𝑗 (𝑥𝑗 − 𝑥0𝑗 ) = 𝑤 + 𝑒𝑇 𝑥0 ,
𝑇
(7.8)
𝑥𝑇 Σ𝑥 ≤ 𝛾2,
𝑥 ≥ 0,
𝐶𝑗 (𝑥𝑗 − 𝑥0𝑗 )
specifies the transaction costs when the holding of asset 𝑗 is changed from its initial value.
If the initial wealth is fairly small and short selling is not allowed, then the holdings will be small.
Therefore, the amount traded of each asset must also be small. Hence, it is reasonable to assume that
the prices of the assets is independent of the amount traded. However, if a large volume of an assert is
sold or purchased it can be expected that the price change and hence the expected return also change.
This effect is called market impact costs. It is common to assume that market impact costs for asset 𝑗
can be modelled by
√︁
𝑚𝑗 |𝑥𝑗 − 𝑥0𝑗 |
where 𝑚𝑗 is a constant that is estimated in some way. See [GK00] [p. 452] for details. To summarize
then
√︁
𝐶𝑗 (𝑥𝑗 − 𝑥0𝑗 ) = 𝑚𝑗 |𝑥𝑗 − 𝑥0𝑗 | |𝑥𝑗 − 𝑥0𝑗 | = 𝑚𝑗 |𝑥𝑗 − 𝑥0𝑗 |3/2 .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑧𝑗 = |𝑥𝑗 − 𝑥0𝑗 |,
[𝑣
∑︀𝑗𝑛; 𝑐𝑗 ; 𝑧𝑗 ] , [𝑧𝑗 ; 1/8; 𝒬3𝑟 ,
𝑣𝑗 ] ∈ ∑︀
0 𝑛
𝑗=1 𝐶𝑗 (𝑥𝑗 − 𝑥𝑗 ) = 𝑗=1 𝑐𝑗 .
but in many cases that constraint can safely be replaced by the relaxed constraint
which is convex. If for instance the universe of assets contains a risk free asset with a positive return
then
cannot hold for an optimal solution because that would imply the solution is not optimal.
Now assume that the optimal solution has the property that (7.11) holds then the market impact cost
within the model is larger than the true market impact cost and hence money are essentially considered
garbage and removed by generating transaction costs. This may happen if a portfolio with very small
risk is requested because then the only way to obtain a small risk is to get rid of some of the assets by
generating transaction costs. Here it is assumed this is not the case and hence the models (7.9) and
(7.10) are equivalent.
Formula (7.10) is replaced by constraints
𝑧𝑗 ≥ 𝑥𝑗 − 𝑥0𝑗 ,
(7.12)
𝑧𝑗 ≥ −(𝑥𝑗 − 𝑥0𝑗 ).
Now we have
maximize 𝜇𝑇 𝑥
subject to 𝑒 𝑥 + 𝑚𝑇 𝑐
𝑇
= 𝑤 + 𝑒𝑇 𝑥0 ,
𝑧𝑗 ≥ 𝑥𝑗 − 𝑥0𝑗 , 𝑗 = 1, . . . , 𝑛,
𝑧𝑗 ≥ 𝑥0𝑗 − 𝑥𝑗 , 𝑗 = 1, . . . , 𝑛,
(7.13)
[𝛾; 𝐺𝑇 𝑥] ∈ 𝒬𝑛+1 ,
[𝑣𝑗 ; 𝑐𝑗 ; 𝑧𝑗 ] ∈ 𝒬3𝑟 , 𝑗 = 1, . . . , 𝑛,
[𝑧𝑗 ; 1/8; 𝑣𝑗 ] ∈ 𝒬3𝑟 , 𝑗 = 1, . . . , 𝑛,
𝑥 ≥ 0.
𝑒𝑇 𝑥 = 𝑤 + 𝑒𝑇 𝑥0 − 𝑚𝑇 𝑐
specifies that the total investment must be equal to the initial wealth minus the transaction costs.
Moreover, observe the variables 𝑣 and 𝑧 are some auxiliary variables that model the market impact cost.
Indeed it holds
𝑧𝑗 ≥ |𝑥𝑗 − 𝑥0𝑗 |
and
3/2
𝑐𝑗 ≥ 𝑧𝑗 .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
where 𝑝 and 𝑞 are both integers and 𝑝 ≥ 𝑞 can be modelled using quadratic cones. See [MOSEKApS12]
for details.
One more reformulation of (7.13) is needed,
maximize 𝜇𝑇 𝑥
subject to 𝑒 𝑥 + 𝑚𝑇 𝑐
𝑇
= 𝑤 + 𝑒𝑇 𝑥0 ,
𝐺𝑇 𝑥 − 𝑡 = 0,
𝑧𝑗 − 𝑥𝑗 ≥ −𝑥0𝑗 , 𝑗 = 1, . . . , 𝑛,
𝑧𝑗 + 𝑥𝑗 ≥ 𝑥0𝑗 , 𝑗 = 1, . . . , 𝑛,
[𝑣𝑗 ; 𝑐𝑗 ; 𝑧𝑗 ] − 𝑓𝑗,1:3 = 0, 𝑗 = 1, . . . , 𝑛,
(7.14)
[𝑧𝑗 ; 0; 𝑣𝑗 ] − 𝑔𝑗,1:3 = [0; −1/8; 0], 𝑗 = 1, . . . , 𝑛,
[𝑠; 𝑡] ∈ 𝒬𝑛+1 ,
𝑇
𝑓𝑗,1:3 ∈ 𝒬3𝑟 , 𝑗 = 1, . . . , 𝑛,
𝑇
𝑔𝑗,1:3 ∈ 𝒬3𝑟 , 𝑗 = 1, . . . , 𝑛,
𝑥 ≥ 0,
𝑠 = 𝛾,
where 𝑓, 𝑔 ∈ R𝑛×3 . These additional variables 𝑓 and 𝑔 are only introduced to bring the problem on the
API standard form.
The formulation (7.14)) is not the most compact possible. However, the MOSEK presolve will auto-
matically make it more compact and since it is easier to implement (7.14) than a more compact form
then the form (7.14) is preferred.
The first step in developing the optimizer API implementation is to chose an ordering of the variables.
In this case the ordering
⎡ ⎤
𝑥
⎢ 𝑠 ⎥
⎢ ⎥
⎢ 𝑡 ⎥
⎢ ⎥
⎢ 𝑐 ⎥
𝑥
ˆ=⎢ ⎢ ⎥
⎢ 𝑣
⎥
⎥
⎢ 𝑧 ⎥
⎢ 𝑇 ⎥
⎣ 𝑓 (:) ⎦
𝑔 𝑇 (:)
will be used. Note 𝑓 𝑇 (:) means the rows of 𝑓 are transposed and stacked on top of each other to form a
long column vector. Table 7.2 shows the mapping between the 𝑥 ˆ and the model variables.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑥
ˆ𝑛+1 = 𝑠
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ𝑛+1+𝑗 = 𝑡𝑗
𝐴1+𝑗,𝑛+1+𝑗 = −1.0
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ2𝑛+1+𝑗 = 𝑐𝑗
𝐴1,2𝑛+1+𝑗 = 𝑚𝑗
𝐴3𝑛+1+3(𝑗−1)+2,2𝑛+1+𝑗 = 1.0
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ3𝑛+1+𝑗 = 𝑣𝑗
𝐴3𝑛+1+3(𝑗−1)+1,3𝑛+1+𝑗 = 1.0
𝐴6𝑛+1+3(𝑗−1)+3,3𝑛+1+𝑗 = 1.0
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ4𝑛+1+𝑗 = 𝑧𝑗
𝐴1+𝑛+𝑗,4𝑛+1+𝑗 = 1.0
𝐴1+2𝑛+𝑗,4𝑛+1+𝑗 = 1.0
𝐴3𝑛+1+3(𝑗−1)+3,4𝑛+1+𝑗 = 1.0
𝐴6𝑛+1+3(𝑗−1)+1,4𝑛+1+𝑗 = 1.0
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ7𝑛+1+3(𝑗−1)+1 = 𝑓𝑗,1
𝐴3𝑛+1+3(𝑗−1)+1,7𝑛+(3(𝑗−1)+1 = −1.0
𝑥
ˆ7𝑛+1+3(𝑗−1)+2 = 𝑓𝑗,2
𝐴3𝑛+1+3(𝑗−1)+2,7𝑛+(3(𝑗−1)+2 = −1.0
𝑥
ˆ7𝑛+1+3(𝑗−1)+3 = 𝑓𝑗,3
𝐴3𝑛+1+3(𝑗−1)+3,7𝑛+(3(𝑗−1)+3 = −1.0
𝑓 𝑜𝑟 𝑗=1:𝑛
𝑥
ˆ10𝑛+1+3(𝑗−1)+1 = 𝑔𝑗,1
𝐴6𝑛+1+3(𝑗−1)+1,7𝑛+(3(𝑗−1)+1 = −1.0
𝑥
ˆ10𝑛+1+3(𝑗−1)+2 = 𝑔𝑗,2
𝐴6𝑛+1+3(𝑗−1)+2,7𝑛+(3(𝑗−1)+2 = −1.0
𝑥
ˆ10𝑛+1+3(𝑗−1)+3 = 𝑔𝑗,3
𝐴6𝑛+1+3(𝑗−1)+3,7𝑛+(3(𝑗−1)+3 = −1.0
The example code in Listing 7.5 demonstrates how to implement the model (7.14).
def streamprinter(text):
print("%s" % text),
if __name__ == '__main__':
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
n = 3
gamma = 0.05
mu = [0.1073, 0.0737, 0.0627]
GT = [[0.1667, 0.0232, 0.0013],
[0.0000, 0.1033, -0.0022],
[0.0000, 0.0000, 0.0338]]
x0 = [0.0, 0.0, 0.0]
w = 1.0
m = [0.01, 0.01, 0.01]
rtemp = w
for j in range(0,n):
rtemp += x0[j]
# Constraints.
task.appendcons(1+9*n)
task.putconbound(0,mosek.boundkey.fx,rtemp,rtemp)
task.putconname(0,"budget")
task.putconboundlist(range(1+0,1+n),n*[mosek.boundkey.fx],n*[0.0],n*[0.0])
for j in range(1,1+n) :
task.putconname(j,"GT[%d]" % j)
task.putconboundlist(range(1+n,1+2*n),n*[mosek.boundkey.lo],[-x0[j] for j in ␣
˓→range(0,n)],n*[inf])
for i in range(0,n):
task.putconname(1+n+i,"zabs1[%d]" % (1+i))
task.putconboundlist(range(1+2*n,1+3*n),n*[mosek.boundkey.lo],x0,n*[inf])
for i in range(0,n):
task.putconname(1+2*n+i,"zabs2[%d]" % (1+i))
task.putconboundlist(range(1+3*n,1+3*n+3*n),3*n*[mosek.boundkey.fx],3*n*[0.],3*n*[0.
˓→0])
for i in range(0,n):
for k in range(0,n):
task.putconname(1+3*n+3*i+k,"f[%d,%d]" % (1+i,1+k))
task.putconboundlist(range(1+6*n,1+9*n),3*n*[mosek.boundkey.fx],
3*[0.0, -1.0/8.0, 0.0],3*[0.0, -1.0/8.0, 0.0])
for i in range(0,n) :
for k in range(0,n):
task.putconname(1+6*n+3*i+k,"g[%d,%d]" % (1+i,1+k))
# Variables.
task.appendvars(1+11*n)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# x variables.
task.putclist(range(offsetx+0,offsetx+n),mu)
task.putaijlist(n*[0],range(offsetx+0,offsetx+n),n*[1.0])
for j in range(0,n):
task.putaijlist(n*[1+j],range(offsetx+0,offsetx+n),GT[j])
task.putaij(1+n+j,offsetx+j,-1.0)
task.putaij(1+2*n+j,offsetx+j,1.0)
task.putvarboundlist(range(offsetx+0,offsetx+n),n*[mosek.boundkey.lo],n*[0.
˓→ 0],n*[inf])
for j in range(0,n):
task.putvarname(offsetx+j,"x[%d]" % (1+j))
# s variable.
task.putvarbound(offsets+0,mosek.boundkey.fx,gamma,gamma)
task.putvarname(offsets+0,"s")
# t variables.
task.putaijlist(range(1,n+1),range(offsett+0,offsett+n),n*[-1.0])
task.putvarboundlist(range(offsett+0,offsett+n),n*[mosek.boundkey.fr],n*[-
˓→inf],n*[inf])
for j in range(0,n):
task.putvarname(offsett+j,"t[%d]" % (1+j))
# c variables.
task.putaijlist(n*[0],range(offsetc,offsetc+n),m)
task.putaijlist(range(1+3*n+1,1+6*n+1,3),range(offsetc,offsetc+n),n*[1.0])
task.putvarboundlist(range(offsetc,offsetc+n),n*[mosek.boundkey.fr],n*[-inf],n*[inf])
for j in range(0,n):
task.putvarname(offsetc+j,"c[%d]" % (1+j))
# v variables.
task.putaijlist(range(1+3*n+0,1+6*n+0,3),range(offsetv,offsetv+n),n*[1.0])
task.putaijlist(range(1+6*n+2,1+9*n+2,3),range(offsetv,offsetv+n),n*[1.0])
task.putvarboundlist(range(offsetv,offsetv+n),n*[mosek.boundkey.fr],n*[-inf],n*[inf])
for j in range(0,n):
task.putvarname(offsetv+j,"v[%d]" % (1+j))
# z variables.
task.putaijlist(range(1+1*n,1+2*n),range(offsetz,offsetz+n),n*[1.0])
task.putaijlist(range(1+2*n,1+3*n),range(offsetz,offsetz+n),n*[1.0])
task.putaijlist(range(1+3*n+2,1+6*n+2,3),range(offsetz,offsetz+n),n*[1.0])
task.putaijlist(range(1+6*n+0,1+9*n+0,3),range(offsetz,offsetz+n),n*[1.0])
task.putvarboundlist(range(offsetz,offsetz+n),n*[mosek.boundkey.fr],n*[-inf],n*[inf])
for j in range(0,n):
task.putvarname(offsetz+j,"z[%d]" % (1+j))
# f variables.
for j in range(0,n):
for k in range(0,n):
task.putaij(1+3*n+3*j+k,offsetf+3*j+k,-1.0)
task.putvarbound(offsetf+3*j+k,mosek.boundkey.fr,-inf,inf)
task.putvarname(offsetf+3*j+k,"f[%d,%d]" % (1+j,1+k))
# g variables.
for j in range(0,n):
for k in range(0,n):
task.putaij(1+6*n+3*j+k,offsetg+3*j+k,-1.0)
task.putvarbound(offsetg+3*j+k,mosek.boundkey.fr,-inf,inf)
task.putvarname(offsetg+3*j+k,"g[%d,%d]" % (1+j,1+k))
task.appendcone(mosek.conetype.quad,0.0,[offsets] + list(range(offsett,offsett+n)))
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.putconename(0,"stddev")
for k in range(0,n):
task.appendconeseq(mosek.conetype.rquad,0.0,3,offsetf+3*k)
task.putconename(1+k,"f[%d]" % (1+k))
for k in range(0,n):
task.appendconeseq(mosek.conetype.rquad,0.0,3,offsetg+3*k)
task.putconename(1+n+k,"g[%d]" % (1+k))
task.putobjsense(mosek.objsense.maximize)
task.optimize()
expret = 0.0
x = [0.]*n
task.getxxslice(mosek.soltype.itr,offsetx+0,offsetx+n,x)
for j in range(0,n):
expret += mu[j]*x[j]
stddev = [0.]
task.getxxslice(mosek.soltype.itr,offsets+0,offsets+1,stddev)
If the problem is dumped to an OPF formatted file, then it has the following content.
[hints]
[hint NUMVAR] 34 [/hint]
[hint NUMCON] 28 [/hint]
[hint NUMANZ] 60 [/hint]
[hint NUMQNZ] 0 [/hint]
[hint NUMCONE] 7 [/hint]
[/hints]
[variables disallow_new_variables]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[objective maximize]
1.073e-001 'x[1]' + 7.37e-002 'x[2]' + 6.270000000000001e-002 'x[3]'
[/objective]
[constraints]
[con 'budget'] 'x[1]' + 'x[2]' + 'x[3]' + 1e-002 'c[1]' + 1e-002 'c[2]'
+ 1e-002 'c[3]' = 1e+000 [/con]
[con 'GT[1]'] 1.667e-001 'x[1]' + 2.32e-002 'x[2]' + 1.3e-003 'x[3]' - 't[1]' = 0e+000 [/
˓→con]
[bounds]
[b] 0 <= * [/b]
[b] s = 5e-002 [/b]
[b] 't[1]','t[2]','t[3]','c[1]','c[2]','c[3]' free [/b]
[b] 'v[1]','v[2]','v[3]','z[1]','z[2]','z[3]' free [/b]
[b] 'f[1,1]','f[1,2]','f[1,3]','f[2,1]','f[2,2]','f[2,3]' free [/b]
[b] 'f[3,1]','f[3,2]','f[3,3]','g[1,1]','g[1,2]','g[1,3]' free [/b]
[b] 'g[2,1]','g[2,2]','g[2,3]','g[3,1]','g[3,2]','g[3,3]' free [/b]
[cone quad 'stddev'] s, 't[1]', 't[2]', 't[3]' [/cone]
[cone rquad 'f[1]'] 'f[1,1]', 'f[1,2]', 'f[1,3]' [/cone]
[cone rquad 'f[2]'] 'f[2,1]', 'f[2,2]', 'f[2,3]' [/cone]
[cone rquad 'f[3]'] 'f[3,1]', 'f[3,2]', 'f[3,3]' [/cone]
[cone rquad 'g[1]'] 'g[1,1]', 'g[1,2]', 'g[1,3]' [/cone]
[cone rquad 'g[2]'] 'g[2,1]', 'g[2,2]', 'g[2,3]' [/cone]
[cone rquad 'g[3]'] 'g[3,1]', 'g[3,2]', 'g[3,3]' [/cone]
[/bounds]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The file verifies that the correct problem has been setup.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
CHAPTER
EIGHT
Interaction between MOSEK and the user is not always succesfull and critical situation may arise for
several reasons: wrong input data, unexpected numerical issues, not enough memory, etc. MOSEK
reports these events to the user making the following distinction:
• Warning: it informs the user about a non critical but important event that will not prevent the
solver execution. When a warning arises the final results may not be the expected.
• Error : it informs the user about a critical and possibly unrecoverable event. The required operation
will not be performed correctly.
Therefore errors and warnings must be handled carefully to use the solver in a safe way.
8.1 Warnings
Warning messages generated by MOSEK should in general never be ignored. Despite not being critical,
they provide useful information and often are the key to understand how to improve the solver perfor-
mance or solve numerical issues. For this reason, it is a good practice to start working with a verbose
output on the screen (see Section 9 ) in order to spot possible warnings.
Typically warnings involve
• Numerical criticalities in the optimization model: for instance if very large upper bound on a
constraint is specified, the solver will notify the user with a message like the following
MOSEK warning 53: A numerically large upper bound value 6.6e+09 is specified␣
˓→for constraint 'C69200' (46020).
8.2 Errors
101
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Most functions in the MOSEK Optimizer API for Python return a response code which indicates
whether an error occurred. It is recommended to check to the response code and in case it is indicating
an error then an appropriate action should be taken.
If you suspect that MOSEK or your own application incorrectly overwrites memory or leaks memory,
we suggest you use external tools such as Intel Inspector for C and .NET, or Valgrind to pinpoint the
cause of the problem.
Turn on logging
While developing a new application it is recommended to turn on logging, so that error and diagnostics
messages are displayed.
See example in Section 3.2 for instructions on turning log output on. You should also always cache and
handle any exceptions thrown by MOSEK.
Please refer to Section 9 for further information.
If something is wrong with a problem or a solution, one option is to output the problem to an OPF file
and inspect it by hand. Use the task.writedata function to write a task to a file immediately before
optimizing, for example as follows:
task.writedata('taskdump.opf')
task.optimizetrm()
This will write the problem in task to the file taskdump.opf. Inspecting the text file taskdump.opf
may reveal what is wrong in the problem setup.
www.EngineeringBooksPdf.com
CHAPTER
NINE
MANAGING I/O
The main purpose of this chapter is to give an overview on the logging and I/O features provided by the
MOSEK package.
• Section 9.1 contains information about the log streams provided by MOSEK.
• File I/O is discussed in Section 9.2 .
• How to tune the logging verbosity is the topic of Section 9.3 .
MOSEK execution produces a certain amount of loggging at environment and task level. This means
that the logging from each environement and task can be isolated from the others.
The log messages are partitioned in three streams:
• messages
• warnings
• errors
These streams are aggregated in the log stream. See streamtype .
Each stream can be redirected either to a user defined function or to a file.
def myStream(msg):
sys.stdout.write(msg)
sys.stdout.flush()
task.set_Stream(streamtype.log,myStream)
In this example we attached to the log stream; see streamtype for other options.
To attach a stream callback to a Task , use:
The stream can be detached by calling
task.set_Stream(None)
103
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Note: As for Progress callbacks, it is necessary to hold a reference to the callback function for the
duration of the lifetime of the Task or Env object.
A stream can be redirected to a file passing to the solver the file name. The solver creates the file anew
or append the log to an existing one. The file is closed when the task/environment is destroyed.
MOSEK supports a range of problem and solution formats listed in Section 17 . One such format is
MOSEK‘s native binary Task format which supports all features that MOSEK supports.
The file format used in I/O operations is deduced from extension - as in problemname.task - unless the
parameter iparam.write_data_format is specified to something else. Problem files with an additional
.gz extension - as in problemname.task.gz - are moreover assumed to use GZIP compression, and are
automatically compressed, respectively decompressed, when written or read.
Example
If something is wrong with a problem or a solution, one option is to output the problem to the human-
readable OPF format and inspect it by hand. For instance, one may use the task.writedata function
to write the problem to a file immediately before optimizing it:
task.writedata("data.opf")
task.optimize()
9.3 Verbosity
The logging verbosity can be controlled by setting the relevant paramenters, as for instance
• iparam.log ,
• iparam.log_intpnt ,
• iparam.log_mio ,
• iparam.log_cut_second_opt ,
• iparam.log_sim , and
• iparam.log_sim_minor .
Each parameter control the output level of a specific functionality or algorithm. The main switch is
iparam.log which affect the whole output. The actual log level for a specific functionality is determined
as the minimum between iparam.log and the relevant parameter. For instance, the log level for the
output produce by the interior-point algorithm is tuned by the iparam.log_intpnt : the actual log level
is defined by the minimum between iparam.log and iparam.log_intpnt .
Tuning the solver verbosity may require adjusting several parameters. It must be noticed that verbose
logging is supposed to be of interest during debugging and tuning, and it is consider the default setting.
When output is no more of interest, user can easily disable using iparam.log .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Moreover, it must be understood that larger values of iparam.log do not necessarily result in an
increased output.
By default MOSEK will reduce the amount of log information after the first optimization on a given
task. To get full log output on subsequent optimizations set iparam.log_cut_second_opt to zero.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
CHAPTER
TEN
minimize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐
≤ 𝐴𝑥 ≤ 𝑢𝑐 , (10.1)
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
where
• 𝑚 is the number of constraints.
• 𝑛 is the number of decision variables.
• 𝑥 ∈ R𝑛 is a vector of decision variables.
• 𝑐 ∈ R𝑛 is the linear part of the objective function.
• 𝐴 ∈ R𝑚×𝑛 is the constraint matrix.
• 𝑙𝑐 ∈ R𝑚 is the lower limit on the activity for the constraints.
• 𝑢𝑐 ∈ R𝑚 is the upper limit on the activity for the constraints.
• 𝑙𝑥 ∈ R𝑛 is the lower limit on the activity for the variables.
• 𝑢𝑥 ∈ R𝑛 is the upper limit on the activity for the variables.
A primal solution (𝑥) is (primal) feasible if it satisfies all constraints in (10.1). If (10.1) has at least one
primal feasible solution, then (10.1) is said to be (primal) feasible.
In case (10.1) does not have a feasible solution, the problem is said to be (primal) infeasible
107
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
If a bound in the primal problem is plus or minus infinity, the corresponding dual variable is fixed at 0,
and we use the convention that the product of the bound value and the corresponding dual variable is
0. E.g.
This is equivalent to removing variable (𝑠𝑥𝑙 )𝑗 from the dual problem. A solution
to the dual problem is feasible if it satisfies all the constraints in (10.2). If (10.2) has at least one
feasible solution, then (10.2) is (dual) feasible, otherwise the problem is (dual) infeasible.
A solution
is denoted a primal-dual feasible solution, if (𝑥) is a solution to the primal problem (10.1) and
(𝑦, 𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑥𝑙 , 𝑠𝑥𝑢 ) is a solution to the corresponding dual problem (10.2).
Let
(𝑥𝑐 )* := 𝐴𝑥* .
For a primal-dual feasible solution we define the duality gap as the difference between the primal and
the dual objective value,
𝑐𝑇 𝑥* + 𝑐𝑓 − (𝑙𝑐 )𝑇 (𝑠𝑐𝑙 )* − (𝑢𝑐 )𝑇 (𝑠𝑐𝑢 )* + (𝑙𝑥 )𝑇 (𝑠𝑥𝑙 )* − (𝑢𝑥 )𝑇 (𝑠𝑥𝑢 )* + 𝑐𝑓
{︀ }︀
∑︀𝑚−1 𝑐 * 𝑐 *
= 𝑖=0 [(𝑠𝑙 )𝑖 ((𝑥𝑖 ) − 𝑙𝑖𝑐 ) + (𝑠𝑐𝑢 )*𝑖 (𝑢𝑐𝑖 − (𝑥𝑐𝑖 )* )] (10.3)
∑︀𝑛−1 [︀ 𝑥 * 𝑥 𝑥 * 𝑥 *
]︀
+ 𝑗=0 (𝑠𝑙 )𝑗 (𝑥𝑗 − 𝑙𝑗 ) + (𝑠𝑢 )𝑗 (𝑢𝑗 − 𝑥𝑗 ) ≥ 0
where the first relation can be obtained by transposing and multiplying the dual constraints (10.2) by
𝑥* and (𝑥𝑐 )* respectively, and the second relation comes from the fact that each term in each sum
is nonnegative. It follows that the primal objective will always be greater than or equal to the dual
objective.
An Optimal Solution
It is well-known that a linear optimization problem has an optimal solution if and only if there exist fea-
sible primal and dual solutions so that the duality gap is zero, or, equivalently, that the complementarity
conditions
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
If the problem (10.1) is infeasible (has no feasible solution), MOSEK will report a certificate of primal
infeasibility: The dual solution reported is the certificate of infeasibility, and the primal solution is
undefined.
A certificate of primal infeasibility is a feasible solution to the modified dual problem
maximize (𝑙𝑐 )𝑇 𝑠𝑐𝑙 − (𝑢𝑐 )𝑇 𝑠𝑐𝑢 + (𝑙𝑥 )𝑇 𝑠𝑥𝑙 − (𝑢𝑥 )𝑇 𝑠𝑥𝑢
subject to
𝐴𝑇 𝑦 + 𝑠𝑥𝑙 − 𝑠𝑥𝑢 = 0, (10.4)
−𝑦 + 𝑠𝑐𝑙 − 𝑠𝑐𝑢 = 0,
𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑥𝑙 , 𝑠𝑥𝑢 ≥ 0,
such that the objective value is strictly positive, i.e. a solution
to (10.4) so that
Such a solution implies that (10.4) is unbounded, and that its dual is infeasible. As the constraints to
the dual of (10.4) are identical to the constraints of problem (10.1), we thus have that problem (10.1) is
also infeasible.
If the problem (10.2) is infeasible (has no feasible solution), MOSEK will report a certificate of dual
infeasibility: The primal solution reported is the certificate of infeasibility, and the dual solution is
undefined.
A certificate of dual infeasibility is a feasible solution to the modified primal problem
minimize 𝑐𝑇 𝑥
subject to ˆ𝑙𝑐 ≤ 𝐴𝑥 ˆ𝑐 ,
≤ 𝑢 (10.5)
ˆ𝑙𝑥 ≤ 𝑥 ˆ𝑥 ,
≤ 𝑢
where
if 𝑙𝑖𝑐 > −∞, 0 if 𝑢𝑐𝑖 < ∞,
{︂ }︂ {︂ }︂
ˆ𝑙𝑐 = 0
and 𝑢
ˆ𝑐𝑖 :=
𝑖 −∞ otherwise, ∞ otherwise,
and
if 𝑙𝑗𝑥 > −∞, if 𝑢𝑥𝑗 < ∞,
{︂ }︂ {︂ }︂
ˆ𝑙𝑥 = 0 0
and 𝑢
ˆ𝑥𝑗 :=
𝑗
−∞ otherwise, ∞ otherwise,
such that
𝑐𝑇 𝑥 < 0.
Such a solution implies that (10.5) is unbounded, and that its dual is infeasible. As the constraints to
the dual of (10.5) are identical to the constraints of problem (10.2), we thus have that problem (10.2) is
also infeasible.
In case that both the primal problem (10.1) and the dual problem (10.2) are infeasible, MOSEK will
report only one of the two possible certificates — which one is not defined (MOSEK returns the first
certificate found).
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
maximize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐
≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
the objective sense of the dual problem changes to minimization, and the domain of all dual variables
changes sign in comparison to (10.2). The dual problem thus takes the form
This means that the duality gap, defined in (10.3) as the primal minus the dual objective value, becomes
nonpositive. It follows that the dual objective will always be greater than or equal to the primal objective.
The primal infeasibility certificate will be reported by MOSEK as a solution to the system
𝐴𝑇 𝑦 + 𝑠𝑥𝑙 − 𝑠𝑥𝑢 = 0,
−𝑦 + 𝑠𝑐𝑙 − 𝑠𝑐𝑢 = 0, (10.6)
𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑥𝑙 , 𝑠𝑥𝑢 ≤ 0,
Similarly, the certificate of dual infeasibility is an 𝑥 satisfying the requirements of (10.5) such that
𝑐𝑇 𝑥 > 0.
Conic quadratic optimization is an extension of linear optimization (see Section 10.1 ) allowing conic
domains to be specified for subsets of the problem variables. A conic quadratic optimization problem
can be written as
minimize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐 ≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
(10.7)
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
𝑥 ∈ 𝒦,
where set 𝒦 is a Cartesian product of convex cones, namely 𝒦 = 𝒦1 × · · · × 𝒦𝑝 . Having the domain
restriction, 𝑥 ∈ 𝒦, is thus equivalent to
𝑥𝑡 ∈ 𝒦𝑡 ⊆ R𝑛𝑡 ,
where 𝑥 = (𝑥1 , . . . , 𝑥𝑝 ) is a partition of the problem variables. Please note that the 𝑛-dimensional
Euclidean space R𝑛 is a cone itself, so simple linear variables are still allowed.
MOSEK supports only a limited number of cones, specifically:
• The R𝑛 set.
• The quadratic cone:
⎧ ⎯ ⎫
⎨ 𝑛
⎸∑︁ ⎬
𝒬𝑛 = 𝑥 ∈ R𝑛 : 𝑥1 ≥ ⎷
⎸
𝑥2𝑗 .
⎩ ⎭
𝑗=2
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
⎧ ⎫
⎨ 𝑛
∑︁ ⎬
𝒬𝑛r = 𝑥 ∈ R𝑛 : 2𝑥1 𝑥2 ≥ 𝑥2𝑗 , 𝑥1 ≥ 0, 𝑥2 ≥ 0 .
⎩ ⎭
𝑗=3
Although these cones may seem to provide only limited expressive power they can be used to model a
wide range of problems as demonstrated in [MOSEKApS12] .
The dual problem corresponding to the conic quadratic optimization problem (10.7) is given by
𝒦* = 𝒦1* × · · · × 𝒦𝑝* ,
where each 𝒦𝑡* is the dual cone of 𝒦𝑡 . For the cone types MOSEK can handle, the relation between the
primal and dual cone is given as follows:
• The R𝑛 set:
𝒦𝑡 = R𝑛𝑡 ⇔ 𝒦𝑡* = {𝑠 ∈ R𝑛𝑡 : 𝑠 = 0} .
• The quadratic cone:
⎧ ⎯ ⎫
⎸ 𝑛𝑡 2 ⎬
⎨ ⎸∑︁
𝒦𝑡 = 𝒬𝑛𝑡 ⇔ 𝒦𝑡* = 𝒬𝑛𝑡 = 𝑠 ∈ R 𝑛𝑡 : 𝑠1 ≥ ⎷ 𝑠𝑗 .
⎩ ⎭
𝑗=2
Please note that the dual problem of the dual problem is identical to the original primal problem.
In case MOSEK finds a problem to be infeasible it reports a certificate of infeasibility. This works
exactly as for linear problems (see Section 10.1.2 ).
If the problem (10.7) is infeasible, MOSEK will report a certificate of primal infeasibility: The dual
solution reported is the certificate of infeasibility, and the primal solution is undefined.
A certificate of primal infeasibility is a feasible solution to the problem
maximize (𝑙𝑐 )𝑇 𝑠𝑐𝑙 − (𝑢𝑐 )𝑇 𝑠𝑐𝑢 + (𝑙𝑥 )𝑇 𝑠𝑥𝑙 − (𝑢𝑥 )𝑇 𝑠𝑥𝑢
subject to
𝐴𝑇 𝑦 + 𝑠𝑥𝑙 − 𝑠𝑥𝑢 + 𝑠𝑥𝑛 = 0,
−𝑦 + 𝑠𝑐𝑙 − 𝑠𝑐𝑢 = 0,
𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑥𝑙 , 𝑠𝑥𝑢 ≥ 0,
𝑠𝑥𝑛 ∈ 𝒦* ,
such that the objective value is strictly positive.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
If the problem (10.8) is infeasible, MOSEK will report a certificate of dual infeasibility: The primal
solution reported is the certificate of infeasibility, and the dual solution is undefined.
A certificate of dual infeasibility is a feasible solution to the problem
minimize 𝑐𝑇 𝑥
subject to ˆ𝑙𝑐 ≤ 𝐴𝑥 ˆ𝑐 ,
≤ 𝑢
ˆ𝑙𝑥 ≤ 𝑥 ˆ𝑥 ,
≤ 𝑢
𝑥 ∈ 𝒦,
where
if 𝑙𝑖𝑐 > −∞, 0 if 𝑢𝑐𝑖 < ∞,
{︂ }︂ {︂ }︂
ˆ𝑙𝑐 = 0
and 𝑢
ˆ𝑐𝑖 :=
𝑖 −∞ otherwise, ∞ otherwise,
and
if 𝑙𝑗𝑥 > −∞, if 𝑢𝑥𝑗 < ∞,
{︂ }︂ {︂ }︂
ˆ𝑙𝑥 = 0 0
and 𝑢
ˆ𝑥𝑗 :=
𝑗
−∞ otherwise, ∞ otherwise,
Semidefinite optimization is an extension of conic quadratic optimization (see Section 10.2 ) allowing
positive semidefinite matrix variables to be used in addition to the usual scalar variables. A semidefinite
optimization problem can be written as
∑︀𝑛−1 ∑︀𝑝−1 ⟨︀
minimize
⟩︀
𝑗=0 𝑐𝑗 𝑥𝑗 + 𝑗=0 𝐶 𝑗 , 𝑋 𝑗 + 𝑐𝑓
∑︀𝑛−1 ∑︀𝑝−1
subject to 𝑙𝑖𝑐 ≤
⟨︀ ⟩︀
𝑗=0 𝑎𝑖𝑗 𝑥𝑗 + 𝑗=0 𝐴𝑖𝑗 , 𝑋 𝑗 ≤ 𝑢𝑐𝑖 , 𝑖 = 0, . . . , 𝑚 − 1
𝑥
(10.9)
𝑙𝑗 ≤ 𝑥𝑗 ≤ 𝑢𝑥𝑗 , 𝑗 = 0, . . . , 𝑛 − 1
𝑟𝑗
𝑥 ∈ 𝒦, 𝑋 𝑗 ∈ 𝒮+ , 𝑗 = 0, . . . , 𝑝 − 1
𝑟
where the problem has 𝑝 symmetric positive semidefinite variables 𝑋 𝑗 ∈ 𝒮+𝑗 of dimension 𝑟𝑗 with
symmetric coefficient matrices 𝐶 𝑗 ∈ 𝒮 𝑟𝑗 and 𝐴𝑖,𝑗 ∈ 𝒮 𝑟𝑗 . We use standard notation for the matrix inner
product, i.e., for 𝑈, 𝑉 ∈ R𝑚×𝑛 we have
𝑚−1
∑︁ 𝑛−1
∑︁
⟨𝑈, 𝑉 ⟩ := 𝑈𝑖𝑗 𝑉𝑖𝑗 .
𝑖=0 𝑗=0
The dual problem corresponding to the semidefinite optimization problem (10.9) is given by
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
where 𝐴 ∈ R𝑚×𝑛 , 𝐴𝑖𝑗 = 𝑎𝑖𝑗 , which is similar to the dual problem for conic quadratic optimization (see
Section 10.2.1 ), except for the addition of dual constraints
(︃ 𝑚
)︃
𝑟
∑︁
𝐶𝑗 − 𝑦𝑖 𝐴𝑖𝑗 ∈ 𝒮+𝑗 .
𝑖=0
Note that the dual of the dual problem is identical to the original primal problem.
In case MOSEK finds a problem to be infeasible it reports a certificate of the infeasibility. This works
exactly as for linear problems (see Section 10.1.2 ).
If the problem (10.9) is infeasible, MOSEK will report a certificate of primal infeasibility: The dual
solution reported is a certificate of infeasibility, and the primal solution is undefined.
A certificate of primal infeasibility is a feasible solution to the problem
If the problem (10.10) is infeasible, MOSEK will report a certificate of dual infeasibility: The primal
solution reported is the certificate of infeasibility, and the dual solution is undefined.
A certificate of dual infeasibility is a feasible solution to the problem
∑︀𝑛−1 ∑︀𝑝−1 ⟨︀
minimize
⟩︀
𝑗=0 𝑐𝑗 𝑥𝑗 + ∑︀𝑗=0 ⟨︀𝐶 𝑗 , 𝑋 𝑗 ⟩︀
𝑛 𝑝−1
subject to ˆ𝑙𝑖𝑐 ≤ ˆ𝑐𝑖 , 𝑖 = 0, . . . , 𝑚 − 1
∑︀
𝑗=1 𝑎𝑖𝑗 𝑥𝑗 + 𝑗=0 𝐴𝑖𝑗 , 𝑋 𝑗 ≤ 𝑢
ˆ𝑙𝑥 ≤ 𝑥 ˆ𝑥 ,
≤ 𝑢
𝑟𝑗
𝑥 ∈ 𝒦, 𝑋 𝑗 ∈ 𝒮+ , 𝑗 = 0, . . . , 𝑝 − 1
where
if 𝑙𝑖𝑐 >; −∞, 0 if 𝑢𝑐𝑖 <; ∞,
{︂ {︂
ˆ𝑙𝑐 = 0
and 𝑢
ˆ𝑐𝑖 :=
𝑖 −∞ otherwise, ∞ otherwise,
and
if 𝑙𝑗𝑥 >; −∞, if 𝑢𝑥𝑗 <; ∞,
{︂ {︂
ˆ𝑙𝑥 = 0 0
and ˆ𝑥𝑗
𝑢 :=
𝑗
−∞ otherwise, ∞ otherwise,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
where 𝑄𝑜 and all 𝑄𝑘 are symmetric matrices. Moreover for convexity, 𝑄𝑜 must be a positive semidefinite
matrix and 𝑄𝑘 must satisfy
The convexity requirement is very important and MOSEK checks whether it is fullfiled.
10.4.1 A Recommendation
Any convex quadratic optimization problem can be reformulated as a conic quadratic optimization prob-
lem, see [MOSEKApS12] and in particular [And13] . In fact MOSEK does such conversion internally
as a part of the solution process for the following reasons:
• the conic optimizer is numerically more robust than the one for quadratic problems.
• the conic optimizer is usually faster because quadratic cones are simpler than quadratic functions,
even though the conic reformulation usually has more constraints and variables than the original
quadratic formulation.
• it is easy to dualize the conic formuation if deemed worthwhile potentially leading to (huge) com-
putational savings.
However, instead of relying on the automatic reformulation we recommend to formulate the problem as
conic problem from scratch because:
• it saves the computational overhead of the reformulation including the convexity check. A conic
problem is convex by construction and hence no convexity check is neeeded for conic problems.
• usually the modeller can do a better reformulation than the automatic method because the modeller
can exploit the knowledge of what is being modelled.
To summarize we recommend to formulate quadratic problems and in particular quadratically constrained
problems directly in conic form.
The dual problem corresponding to the quadratic and quadratically constrained optimization problem
(10.11) is given by
{︁∑︀ }︁
𝑚−1
maximize (𝑙𝑐 )𝑇 𝑠𝑐𝑙 − (𝑢𝑐 )𝑇 𝑠𝑐𝑢 + (𝑙𝑥 )𝑇 𝑠𝑥𝑙 − (𝑢𝑥 )𝑇 𝑠𝑥𝑢 + 12 𝑥𝑇 𝑘
𝑘=0 𝑦𝑘 𝑄 − 𝑄
𝑜
𝑥 + 𝑐𝑓
subject to
(10.12)
{︁∑︀ }︁
𝑚−1
𝐴𝑇 𝑦 + 𝑠𝑥𝑙 − 𝑠𝑥𝑢 + 𝑘=0 𝑦𝑘 𝑄𝑘
− 𝑄 𝑜
𝑥 = 𝑐,
−𝑦 + 𝑠𝑐𝑙 − 𝑠𝑐𝑢 = 0,
𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑥𝑙 , 𝑠𝑥𝑢 ≥ 0.
The dual problem is related to the dual problem for linear optimization (see Section 10.1.1 ), but depends
on the variable 𝑥 which in general can not be eliminated. In the solutions reported by MOSEK, the
value of 𝑥 is the same for the primal problem (10.11) and the dual problem (10.12).
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
In case MOSEK finds a problem to be infeasible it reports a certificate of infeasibility. This works
exactly as for linear problems (see Section 10.1.2 ).
If the problem (10.11) with all 𝑄𝑘 = 0 is infeasible, MOSEK will report a certificate of primal infeasi-
bility. As the constraints are the same as for a linear problem, the certificate of infeasibility is the same
as for linear optimization (see Section 10.1.2.1 ).
If the problem (10.12) with all 𝑄𝑘 = 0 is infeasible, MOSEK will report a certificate of dual infeasibility.
The primal solution reported is the certificate of infeasibility, and the dual solution is undefined.
A certificate of dual infeasibility is a feasible solution to the problem
minimize 𝑐𝑇 𝑥
subject to ˆ𝑙𝑐 ≤ 𝐴𝑥 ≤ ˆ𝑐 ,
𝑢
0 ≤ 𝑄𝑜 𝑥 ≤ 0,
ˆ𝑙𝑥 ≤ 𝑥 ≤ ˆ𝑥 ,
𝑢
where
if 𝑙𝑖𝑐 > −∞, 0 if 𝑢𝑐𝑖 < ∞,
{︂ }︂ {︂ }︂
ˆ𝑙𝑐 = 0
and ˆ𝑐𝑖
𝑢 :=
𝑖 −∞ otherwise, ∞ otherwise,
and
if 𝑙𝑗𝑥 > −∞, if 𝑢𝑥𝑗 < ∞,
{︂ }︂ {︂ }︂
ˆ𝑙𝑥 = 0 0
and ˆ𝑥𝑗
𝑢 :=
𝑗
−∞ otherwise, ∞ otherwise,
MOSEK is capable of solving smooth (twice differentiable) convex nonlinear optimization problems of
the form
minimize 𝑓 (𝑥) + 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑐
𝑙 ≤ 𝑔(𝑥) + 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
where
• 𝑚 is the number of constraints.
• 𝑛 is the number of decision variables.
• 𝑥 ∈ R𝑛 is a vector of decision variables.
• 𝑐 ∈ R𝑛 is the linear part objective function.
• 𝐴 ∈ R𝑚×𝑛 is the constraint matrix.
• 𝑙𝑐 ∈ R𝑚 is the lower limit on the activity for the constraints.
• 𝑢𝑐 ∈ R𝑚 is the upper limit on the activity for the constraints.
• 𝑙𝑥 ∈ R𝑛 is the lower limit on the activity for the variables.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The linear term 𝐴𝑥 is included in 𝑔(𝑥) since it can be handled much more efficiently as a separate entity
when optimizing.
The nonlinear functions 𝑓 and 𝑔 must be smooth in all 𝑥 ∈ [𝑙𝑥 ; 𝑢𝑥 ]. Moreover, 𝑓 (𝑥) must be a convex
function and 𝑔𝑖 (𝑥) must satisfy
Similar to the linear case, MOSEK reports dual information in the general nonlinear case. Indeed in
this case the Lagrange function is defined by
which is equivalent to
www.EngineeringBooksPdf.com
CHAPTER
ELEVEN
The most essential part of MOSEK is the optimizers. Each optimizer is designed to solve a particular
class of problems, i.e. linear, conic, or general nonlinear problems. The purpose of the present chapter
is to discuss which optimizers are available for the continuous problem classes and how the performance
of an optimizer can be tuned, if needed. This chapter deals with the optimizers for continuous problems
with no integer variables.
When the optimizer is called, it roughly performs the following steps:
1. Presolve: Preprocessing to reduce the size of the problem.
2. Dualizer : Choosing whether to solve the primal or the dual form of the problem.
3. Scaling: Scaling the problem for better numerical stability.
4. Optimize: Solve the problem using selected method.
The first three preprocessing steps are transparent to the user, but useful to know about for tuning
purposes. In general, the purpose of the preprocessing steps is to make the actual optimization more
efficient and robust.
The interior-point optimizers in MOSEK have been parallelized. This means that if you solve linear,
quadratic, conic, or general convex optimization problem using the interior-point optimizer, you can take
advantage of multiple CPU’s.
By default MOSEK will automatically select the number of threads to be employed when solving
the problem. However, the number of threads employed can be changed by setting the parameter
iparam.num_threads . This should never exceed the number of cores on the computer.
The speed-up obtained when using multiple threads is highly problem and hardware dependent, and
consequently, it is advisable to compare single threaded and multi threaded performance for the given
problem type to determine the optimal settings.
For small problems, using multiple threads is not be worthwhile and may even be counter productive.
11.1 Presolve
Before an optimizer actually performs the optimization the problem is preprocessed using the so-called
presolve. The purpose of the presolve is to
1. remove redundant constraints,
2. eliminate fixed variables,
3. remove linear dependencies,
4. substitute out (implied) free variables, and
117
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
During the presolve the problem is reformulated so that it hopefully solves faster. However, in rare cases
the presolved problem may be harder to solve then the original problem. The presolve may also be
infeasible although the original problem is not.
If it is suspected that presolved problem is much harder to solve than the original then it is suggested
to first turn the eliminator off by setting the parameter iparam.presolve_eliminator_max_num_tries
to 0. If that does not help, then trying to turn presolve off may help.
Since all computations are done in finite prescision then the presolve employs some tolerances when
concluding a variable is fixed or constraint is redundant. If it happens that MOSEK incorrectly con-
cludes a problem is primal or dual infeasible, then it is worthwhile to try to reduce the parameters
dparam.presolve_tol_x and dparam.presolve_tol_s . However, if reducing the parameters actually
helps then this should be taken as an indication that the problem is badly formulated.
Eliminator
The purpose of the eliminator is to eliminate free and implied free variables from the problem using
substitution. For instance, given the constraints
∑︀
𝑦 = 𝑗 𝑥𝑗 ,
𝑦, 𝑥 ≥ 0,
y is an implied free variable that can be substituted out of the problem, if deemed worthwhile. If the
eliminator consumes too much time or memory compared to the reduction in problem size gained it may
be disabled. This can be done by setting the parameter iparam.presolve_eliminator_max_num_tries
to 0. In rare cases the eliminator may cause that the problem becomes much hard to solve.
The purpose of the linear dependency check is to remove linear dependencies among the linear equalities.
For instance, the three linear equalities
𝑥1 + 𝑥2 + 𝑥3 = 1,
𝑥1 + 0.5𝑥2 = 0.5,
0.5𝑥2 + 𝑥3 = 0.5
contain exactly one linear dependency. This implies that one of the constraints can be dropped without
changing the set of feasible solutions. Removing linear dependencies is in general a good idea since it
reduces the size of the problem. Moreover, the linear dependencies are likely to introduce numerical
problems in the optimization phase.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
It is best practise to build models without linear dependencies. If the linear dependencies are removed
at the modeling stage, the linear dependency check can safely be disabled by setting the parameter
iparam.presolve_lindep_use to onoffkey.off .
Dualizer
All linear, conic, and convex optimization problems have an equivalent dual problem associated with
them. MOSEK has built-in heuristics to determine if it is most efficient to solve the primal or dual
problem. The form (primal or dual) solved is displayed in the MOSEK log. Should the internal heuristics
not choose the most efficient form of the problem it may be worthwhile to set the dualizer manually by
setting the parameters:
• iparam.intpnt_solve_form : In case of the interior-point optimizer.
• iparam.sim_solve_form : In case of the simplex optimizer.
Note that currently only linear problems may be dualized.
Scaling
Problems containing data with large and/or small coefficients, say 1.0𝑒 + 9 or 1.0𝑒 − 7, are often hard
to solve. Significant digits may be truncated in calculations with finite precision, which can result
in the optimizer relying on inaccurate calculations. Since computers work in finite precision, extreme
coefficients should be avoided. In general, data around the same order of magnitude is preferred, and
we will refer to a problem, satisfying this loose property, as being well-scaled. If the problem is not well
scaled, MOSEK will try to scale (multiply) constraints and variables by suitable constants. MOSEK
solves the scaled problem to improve the numerical properties.
The scaling process is transparent, i.e. the solution to the original problem is reported. It is important
to be aware that the optimizer terminates when the termination criterion is met on the scaled problem,
therefore significant primal or dual infeasibilities may occur after unscaling for badly scaled problems.
The best solution of this issue is to reformulate the problem, making it better scaled.
By default MOSEK heuristically chooses a suitable scaling. The scaling for interior-point and simplex
optimizers can be controlled with the parameters iparam.intpnt_scaling and iparam.sim_scaling
respectively.
Two different types of optimizers are available for linear problems: The default is an interior-point
method, and the alternatives are simplex methods. The optimizer can be selected using the parameter
iparam.optimizer .
The purpose of this section is to provide information about the algorithm employed in MOSEK interior-
point optimizer.
In order to keep the discussion simple it is assumed that MOSEK solves linear optimization problems
of standard form
minimize 𝑐𝑇 𝑥
subject to 𝐴𝑥 = 𝑏, (11.1)
𝑥 ≥ 0.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
This is in fact what happens inside MOSEK; for efficiency reasons MOSEK converts the problem to
standard form before solving, then converts it back to the input form when reporting the solution.
Since it is not known beforehand whether problem (11.1) has an optimal solution, is primal infeasible or
is dual infeasible, the optimization algorithm must deal with all three situations. This is the reason that
MOSEK solves the so-called homogeneous model
𝐴𝑥 − 𝑏𝜏 = 0,
𝐴𝑇 𝑦 + 𝑠 − 𝑐𝜏 = 0,
(11.2)
−𝑐𝑇 𝑥 + 𝑏𝑇 𝑦 − 𝜅 = 0,
𝑥, 𝑠, 𝜏, 𝜅 ≥ 0,
where 𝑦 and 𝑠 correspond to the dual variables in (11.1), and 𝜏 and 𝜅 are two additional scalar variables.
Note that the homogeneous model (11.2) always has solution since
(𝑥, 𝑦, 𝑠, 𝜏, 𝜅) = (0, 0, 0, 0, 0)
(𝑥* , 𝑦 * , 𝑠* , 𝜏 * , 𝜅* )
𝜏 * + 𝜅* > 0.
or
𝑏𝑇 𝑦 * > 0 (11.4)
is satisfied. If (11.3) is satisfied then 𝑥* is a certificate of dual infeasibility, whereas if (11.4) is satisfied
then 𝑦 * is a certificate of dual infeasibility.
In summary, by computing an appropriate solution to the homogeneous model, all information required
for a solution to the original problem is obtained. A solution to the homogeneous model can be computed
using a primal-dual interior-point algorithm [And09] .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
For efficiency reasons it is not practical to solve the homogeneous model exactly. Hence, an exact optimal
solution or an exact infeasibility certificate cannot be computed and a reasonable termination criterion
has to be employed.
In every iteration, 𝑘, of the interior-point algorithm a trial solution
(𝑥𝑘 , 𝑦 𝑘 , 𝑠𝑘 , 𝜏 𝑘 , 𝜅𝑘 )
𝑥𝑘 , 𝑠𝑘 , 𝜏 𝑘 , 𝜅𝑘 > 0.
(𝑥𝑘 , 𝑦 𝑘 , 𝑠𝑘 )
𝜏𝑘
is reported as the primal-dual optimal solution. The interpretation of (11.5) is that the optimizer is
terminated if
𝑥𝑘
• 𝜏𝑘
is approximately primal feasible,
{︁ }︁
𝑦 𝑘 𝑠𝑘
• ,
𝜏𝑘 𝜏𝑘
is approximately dual feasible, and
‖𝑐‖∞
−𝜖𝑖 𝑐𝑇 𝑥𝑘 >
⃦ 𝑘⃦
⃦𝐴𝑥 ⃦
max (1, ‖𝑏‖∞ ) ∞
certificate of dual infeasibility. Next assume that this is not the case, i.e.
⃦ 𝑘⃦
⃦𝐴𝑥 ⃦ > 0,
∞
and define
max (1, ‖𝑏‖∞ ) 𝑘
𝑥
¯ := 𝜖𝑖 𝑥 .
‖𝐴𝑥𝑘 ‖∞ ‖𝑐‖∞
which shows 𝑥
¯ is an approximate certificate of dual infeasibility where 𝜀𝑖 controls the quality of the
approximation. A smaller value means a better approximation.
Finally, if
‖𝑏‖∞
𝜖𝑖 𝑏𝑇 𝑦 𝑘 >
⃦ 𝑇 𝑘
⃦𝐴 𝑦 + 𝑠𝑘 ⃦
⃦
max (1, ‖𝑐‖∞ ) ∞
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Basis Identification
An interior-point optimizer does not return an optimal basic solution unless the problem has a unique
primal and dual optimal solution. Therefore, the interior-point optimizer has an optional post-processing
step that computes an optimal basic solution starting from the optimal interior-point solution. More
information about the basis identification procedure may be found in [AY96] . In the following we provide
an overall idea of the procedure.
There are some cases in which a basic solution could be more valuable:
• a basic solution is often more accurate than an interior-point solution,
• a basic solution can be used to warm-start the simplex algorithm in case of reoptimization,
• a basic solution is in general more sparse, i.e. more variables are fixed to zero. This is partic-
ularly appealing when solving continuous relaxation of mixed integer problems, as well as in all
applications in which sparser solutions are preferred.
To illustrate how the basis identification routine works, we use the following trivial example:
minimize 𝑥+𝑦
subject to 𝑥+𝑦 = 1,
𝑥, 𝑦 ≥ 0.
It is easy to see that all feasible solutions are also optimal. In particular, there are two basic solutions
namely
(𝑥*1 , 𝑦1* ) = (1, 0),
(𝑥*2 , 𝑦2* ) = (0, 1).
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The interior point algorithm will actually converge to the center of the optimal set, i.e. to (𝑥* , 𝑦 * ) =
(1/2, 1/2) (to see this in MOSEK deactivate Presolve).
In practice, when the algorithm gets close to the optimal solution, it is possible to construct in polynomial
time an initial basis for the simplex algorithm from the current interior point solution. This basis is used
to warm-start the simplex algorithm that will provide the optimal basic solution.
In most cases the constructed basis is optimal, or very few iterations are required by the simplex algorithm
to make it optimal and hence the final clean phase be short. However, in some cases for nasty problems
e.g. ill-conditioned problems the additional simplex clean up phase may take of lot a time.
By default MOSEK performs a basis identification. However, if a basic solution is not needed, the basis
identification procedure can be turned off. The parameters
• iparam.intpnt_basis ,
• iparam.bi_ignore_max_iter , and
• iparam.bi_ignore_num_error
control when basis identification is performed.
The type of simplex algorithm to be used can be tuned by the iparam.bi_clean_optimizer pa-
rameter i.e. primal or dual simplex, and the maximum number of iterations can be set by the
iparam.bi_max_iterations .
Finally, it should be mentioned that there is no guarantee on which basic solution will be returned.
Optimizer - threads : 1
Optimizer - solved problem : the dual
Optimizer - Constraints : 2
Optimizer - Cones : 0
Optimizer - Scalar variables : 6 conic : 0
Optimizer - Semi-definite variables: 0 scalarized : 0
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 3 after factor : 3
Factor - dense dim. : 0 flops : 7.00e+001
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 1.0e+000 8.6e+000 6.1e+000 1.00e+000 0.000000000e+000 -2.208000000e+003 1.0e+000 0.00
1 1.1e+000 2.5e+000 1.6e-001 0.00e+000 -7.901380925e+003 -7.394611417e+003 2.5e+000 0.00
2 1.4e-001 3.4e-001 2.1e-002 8.36e-001 -8.113031650e+003 -8.055866001e+003 3.3e-001 0.00
3 2.4e-002 5.8e-002 3.6e-003 1.27e+000 -7.777530698e+003 -7.766471080e+003 5.7e-002 0.01
4 1.3e-004 3.2e-004 2.0e-005 1.08e+000 -7.668323435e+003 -7.668207177e+003 3.2e-004 0.01
5 1.3e-008 3.2e-008 2.0e-009 1.00e+000 -7.668000027e+003 -7.668000015e+003 3.2e-008 0.01
6 1.3e-012 3.2e-012 2.0e-013 1.00e+000 -7.667999994e+003 -7.667999994e+003 3.2e-012 0.01
The first line displays the number of threads used by the optimizer and second line tells that the optimizer
chose to solve the dual problem rather than the primal problem. The next line displays the problem
dimensions as seen by the optimizer, and the Factor... lines show various statistics. This is followed
by the iteration log.
Using the same notation as in Section 11.2.2 the columns of the iteration log have the following meaning:
• ITE: Iteration index.
• PFEAS: ⃦𝐴𝑥𝑘 − 𝑏𝜏 𝑘 ⃦∞ . The numbers in this column should converge monotonically towards to
⃦ ⃦
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The simplex optimizer terminates when it finds an optimal basic solution or an infeasibility certifi-
cate. A basic solution is optimal when it is primal and dual feasible; see Section 10.1 and 10.1.1 for
a definition of the primal and dual problem. Due to the fact that computations are performed in fi-
nite precision MOSEK allows violation of primal and dual feasibility within certain tolerances. The
user can control the allowed primal and dual tolerances with the parameters dparam.basis_tol_x and
dparam.basis_tol_s .
When using the simplex optimizer it may be possible to reuse an existing solution and thereby reduce
the solution time significantly. When a simplex optimizer starts from an existing solution it is said to
perform a warm-start. If the user is solving a sequence of optimization problems by solving the problem,
making modifications, and solving again, MOSEK will warm-start automatically.
Setting the parameter iparam.optimizer to optimizertype.free_simplex instructs MOSEK to se-
lect automatically between the primal and the dual simplex optimizers. Hence, MOSEK tries to choose
the best optimizer for the given problem and the available solution.
By default MOSEK uses presolve when performing a warm-start. If the optimizer only needs very few
iterations to find the optimal solution it may be better to turn off the presolve.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
a situation try to reformulate into a better scaled problem. Then, if a lot of set-backs still occur, trying
one or more of the following suggestions may be worthwhile:
• Raise tolerances for allowed primal or dual feasibility: Hence, increase the value of
– dparam.basis_tol_x , and
– dparam.basis_tol_s .
• Raise or lower pivot tolerance: Change the dparam.simplex_abs_tol_piv parameter.
• Switch optimizer: Try another optimizer.
• Switch off crash: Set both iparam.sim_primal_crash and iparam.sim_dual_crash to 0.
• Experiment with other pricing strategies: Try different values for the parameters
– iparam.sim_primal_selection and
– iparam.sim_dual_selection .
• If you are using warm-starts, in rare cases switching off this feature may improve stability. This is
controlled by the iparam.sim_hotstart parameter.
• Increase maximum set backs allowed controlled by iparam.sim_max_num_setbacks .
• If the problem repeatedly becomes infeasible try switching off the special degeneracy handling. See
the parameter iparam.sim_degen for details.
Given a linear optimization problem, which optimizer is the best: The primal simplex, the dual simplex
or the interior-point optimizer?
It is impossible to provide a general answer to this question. However, the interior-point optimizer
behaves more predictably: it tends to use between 20 and 100 iterations, almost independently of problem
size, but cannot perform warm-start, while simplex can take advantage of an initial solution, but is less
predictable for cold-start. The interior-point optimizer is used by default.
MOSEK provides both a primal and a dual simplex optimizer. Predicting which simplex optimizer
is faster is impossible, however, in recent years the dual optimizer has seen several algorithmic and
computational improvements, which, in our experience, makes it faster on average than the primal
simplex optimizer. Still, it depends much on the problem structure and size.
Setting the iparam.optimizer parameter to optimizertype.free_simplex instructs MOSEK to
choose which simplex optimizer to use automatically.
To summarize, if you want to know which optimizer is faster for a given problem type, you should try
all the optimizers.
For conic optimization problems only an interior-point type optimizer is available. The interior-point
optimizer is an implementation of the so-called homogeneous and self-dual algorithm. For a detailed
description of the algorithm, please see [ART03] .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The parameters controlling when the conic interior-point optimizer terminates are shown in Table 11.2.
For quadratic, quadratically constrained, and general convex optimization problems an interior-point
type optimizer is available. The interior-point optimizer is an implementation of the homogeneous and
self-dual algorithm. For a detailed description of the algorithm, please see [AY98] , [AY99] .
Continuous nonlinear problems are required to be convex. For quadratic problems MOSEK test this
requirement before optimizing. Specifying a non-convex problem results in an error message.
The following parameters are available to control the convexity check:
• iparam.check_convexity : Turn convexity check on/off.
• dparam.check_convexity_rel_tol : Tolerance for convexity check.
• iparam.log_check_convexity : Turn on more log information for debugging.
The nonlinear optimizer in MOSEK requires both first order and second order derivatives. This of
course implies care should be taken when solving problems involving non-differentiable functions.
For instance, the function
𝑓 (𝑥) = 𝑥2
is only differentiable for 𝑥 > 0 . In order to make sure that MOSEK evaluates the functions at points
where they are differentiable, the function domains must be defined by setting appropriate variable
bounds.
In general, if a variable is not ranged MOSEK will only evaluate that variable at points strictly within
the bounds. Hence, imposing the bound
𝑥≥0
√
in the case of 𝑥 is sufficient to guarantee that the function will only be evaluated in points where it is
differentiable.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
However, if a function is differentiable on a closed range, specifying the variable bounds is not sufficient.
Consider the function
1 1
𝑓 (𝑥) = + . (11.6)
𝑥 1−𝑥
In this case the bounds
0≤𝑥≤1
will not guarantee that MOSEK only evaluates the function for 𝑥 between 0 and 1 . To force MOSEK
to strictly satisfy both bounds on ranged variables set the parameter iparam.intpnt_starting_point
to startpointtype.satisfy_bounds .
For efficiency reasons it may be better to reformulate the problem than to force MOSEK to observe
ranged bounds strictly. For instance, (11.6) can be reformulated as follows
𝑓 (𝑥) = 𝑥1 + 𝑦1
0 = 1−𝑥−𝑦
0 ≤ 𝑥
0 ≤ 𝑦.
The parameters controlling when the general convex interior-point optimizer terminates are shown in
Table 11.3.
If multiple cores are available then it is possible for MOSEK to take advantage of them to speed up
the computation. However, please note the speedup achieved is going to be dependent on the problem
characteristics e.g. the size of problem. Typically for smallish problems no speedup is obtained by
exploiting multiple cores. In fact forcing MOSEK to use one core can increase speed because parallel
overhead is avoided.
The MOSEK API is thread-safe provided that a task is only modified or accessed from one thread at
any given time. Also accessing two or more separate tasks from threads at the same time is safe. Sharing
an environment between threads is safe.
11.5.2 Determinism
The optimizers are run-to-run deterministic which means if a problem is solved twice on the same
computer using the same parameter setting and exactly the same input then exactly the same results is
obtained. One qualification is that no time limits must be imposed because the time taken to perform
an operation on a computer is dependent on many factors such as the current workload.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
By default the interior-point optimizer exploits multiple cores using multithreading. Hence, big tasks
such as large dense matrix multiplication may be divided into several independent smaller tasks that
can be computed independently. However, there is a computational overhead associated with exploiting
multiple threads e.g. cost of the additional coordination etc. Therefore, it may be advantageous to turn
off the mutithreading for smallish problem using the parameter iparam.intpnt_multi_thread .
Moreover, when the interior-point optimizer is allowed to exploit multiple threads, then the parameter
iparam.num_threads controls the maximum number of threads (and therefore the number of cores) that
MOSEK will employ.
www.EngineeringBooksPdf.com
CHAPTER
TWELVE
A problem is a mixed-integer optimization problem when one or more of the variables are constrained
to be integer valued. MOSEK can solve mixed-integer
• linear,
• quadratic and quadratically constrained, and
• conic qudratic
problems.
Readers unfamiliar with integer optimization are recommended to consult some relevant literature, e.g.
the book [Wol98] by Wolsey.
It is important to understand that in a worst-case scenario, the time required to solve integer optimization
problems grows exponentially with the size of the problem. For instance, assume that a problem contains
𝑛 binary variables, then the time required to solve the problem in the worst case may be proportional
to 2𝑛 . The value of 2𝑛 is huge even for moderate values of 𝑛 .
In practice this implies that the focus should be on computing a near optimal solution quickly rather
than on locating an optimal solution. Even if the problem is only solved approximately, it is important
to know how far the approximate solution is from an optimal one. In order to say something about the
quality of an approximate solution the concept of relaxation is important.
The mixed-integer optimization problem
𝑧* = minimize 𝑐𝑇 𝑥
subject to 𝐴𝑥 = 𝑏,
(12.1)
𝑥≥0
𝑥𝑗 ∈ Z, ∀𝑗 ∈ 𝒥 ,
The continuos relaxation is identical to the mixed-integer problem with the restriction that some variables
must be integers removed.
There are two important observations about the continuous relaxation. First, the continuous relaxation
is usually much faster to optimize than the mixed-integer problem. Secondly if 𝑥
ˆ is any feasible solution
to (12.1) and
𝑧¯ := 𝑐𝑇 𝑥
ˆ
129
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
then
𝑧 ≤ 𝑧 * ≤ 𝑧¯.
This is an important observation since if it is only possible to find a near optimal solution within a
reasonable time frame then the quality of the solution can nevertheless be evaluated. The value 𝑧 is a
lower bound on the optimal objective value. This implies that the obtained solution is no further away
from the optimum than 𝑧¯ − 𝑧 in terms of the objective value.
Whenever a mixed-integer problem is solved MOSEK reports this lower bound so that the quality of
the reported solution can be evaluated.
The mixed-integer optimizer can handle problems with linear, quadratic objective and constraints and
conic constraints. However, a problem can not contain both quadratic objective or constraints and conic
constraints.
The mixed-integer optimizer is specialized for solving linear and conic optimization problems. It can also
solve pure quadratic and quadratically constrained problems; these problems are automatically converted
to conic problems before being solved.
The mixed-integer optimizer is run-to-run deterministic. This means that if a problem is solved twice
on the same computer with identical options then the obtained solution will be bit-for-bit identical for
the two runs. However, if a time limit is set then this may not be case since the time taken to solve
a problem is not deterministic. The mixed-integer optimizer is parallelized i.e. it can exploit multiple
cores during the optimization.
The solution process can be split into these phases:
1. Presolve: In this phase the optimizer tries to reduce the size of the problem and improve
the formulation using preprocessing techniques. The presolve stage can be turned off using the
iparam.presolve_use parameter
2. Cut generation: Valid inequalities (cuts) are added to improve the lower bound
3. Heuristic: Using heuristics the optimizer tries to guess a good feasible solution. Heuristics can
be controlled by the parameter iparam.mio_heuristic_level
4. Search: The optimal solution is located by branching on integer variables
In general, it is time consuming to find an exact feasible and optimal solution to an integer optimization
problem, though in many practical cases it may be possible to find a sufficiently good solution. Therefore,
the mixed-integer optimizer employs a relaxed feasibility and optimality criterion to determine when a
satisfactory solution is located.
A candidate solution that is feasible for the continuous relaxation is said to be an integer feasible solution
if the criterion
𝑧¯ − 𝑧 ≤ max(𝛿2 , 𝛿3 max(10−10 , |¯
𝑧 |))
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
is satisfied. If this is the case, the integer optimizer terminates and reports the integer feasible solution
as an optimal solution. Please note that 𝑧 is a valid lower bound determined by the integer optimizer
during the solution process, i.e.
𝑧 ≤ 𝑧*.
If an optimal solution cannot be located within a reasonable time, it may be advantageous to employ a
relaxed termination criterion after some time. Whenever the integer optimizer locates an integer feasible
solution and has spent at least the number of seconds defined by the dparam.mio_disable_term_time
parameter on solving the problem, it will check whether the criterion
𝑧¯ − 𝑧 ≤ max(𝛿4 , 𝛿5 max(10−10 , |¯
𝑧 |))
is satisfied. If it is satisfied, the optimizer will report that the candidate solution is near optimal and
then terminate. Please note that since this criterion depends on timing, the optimizer will not be run to
run deterministic.
All 𝛿 tolerances can be adjusted using suitable parameters — see Table 12.1.
Table 12.2: Other parameters affecting the integer optimizer termination criterion.
Parameter name De- Explanation
layed
iparam.mio_max_num_branches Yes Maximum number of branches allowed.
iparam.mio_max_num_relaxs Yes Maximum number of relaxations allowed.
iparam.mio_max_num_solutions Yes Maximum number of feasible integer solutions
allowed.
As mentioned previously, in many cases it is not possible to find an optimal solution to an integer
optimization problem in a reasonable amount of time. Some suggestions to reduce the solution time are:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• Relax the termination criterion: In case the run time is not acceptable, the first thing to do is to
relax the termination criterion — see Section 12.3 for details.
• Specify a good initial solution: In many cases a good feasible solution is either known or easily
computed using problem specific knowledge. If a good feasible solution is known, it is usually
worthwhile to use this as a starting point for the integer optimizer.
• Improve the formulation: A mixed-integer optimization problem may be impossible to solve in one
form and quite easy in another form. However, it is beyond the scope of this manual to discuss good
formulations for mixed-integer problems. For discussions on this topic see for example [Wol98] .
To determine the quality of the solution one should check the following:
• The solution status key returned by MOSEK
• The optimality gap: A measure of how much the located solution can deviate from the optimal
solution to the problem
• Feasibility. How much the solution violates the constraints of the problem
The optimality gap is a measure for how close the solution is to the optimal solution. The optimality
gap is given by
The objective value of the solution is guarantied to be within 𝜖 of the optimal solution.
The optimality gap can be retrieved through the solution item dinfitem.mio_obj_abs_gap . Often it
is more meaningful to look at the optimality gap normalized with the magnitude of the solution. The
relative optimality gap is available in dinfitem.mio_obj_rel_gap .
www.EngineeringBooksPdf.com
CHAPTER
THIRTEEN
PROBLEM ANALYZER
-------------------------------------------------------------------------------
Objective, min cx
range: min |c|: 0.00000 min |c|>0: 11.0000 max |c|: 500.000
distrib: |c| vars
0 421
[11, 100) 150
[100, 500] 271
-------------------------------------------------------------------------------
133
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
A nonzeros, A(ij)
range: min |A(ij)|: 1.00000 max |A(ij)|: 100.000
distrib: A(ij) coeffs
[1, 10) 1670
[10, 100] 421
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
The survey is divided into six different sections, each described below. To keep the presentation short
with focus on key elements the analyzer generally attempts to display information on issues relevant for
the current model only: E.g., if the model does not have any conic constraints (this is the case in the
example above) or any integer variables, those parts of the analysis will not appear.
The first part of the survey consists of a brief summary of the model’s linear and quadratic constraints
(indexed by 𝑖) and variables (indexed by 𝑗). The summary is divided into three subsections:
Constraints
∑︀𝑛−1
• upper bd The number of upper bounded constraints, 𝑎𝑖𝑗 𝑥𝑗 ≤ 𝑢𝑐𝑖
𝑗=0
∑︀𝑛−1
• lower bd The number of lower bounded constraints, 𝑙𝑖𝑐 ≤ 𝑗=0 𝑎𝑖𝑗 𝑥𝑗
∑︀𝑛−1
• ranged The number of ranged constraints, 𝑙𝑖𝑐 ≤ 𝑗=0 𝑎𝑖𝑗 𝑥𝑗 ≤ 𝑢𝑐𝑖
∑︀𝑛−1
• fixed The number of fixed constraints, 𝑙𝑖𝑐 = 𝑗=0 𝑎𝑖𝑗 𝑥𝑗 = 𝑢𝑐𝑖
• free The number of free constraints
Bounds
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Variables
13.2 Objective
The second part of the survey focuses on (the linear part of) the objective, summarizing the optimization
sense and the coefficients’ absolute value range and distribution. The number of 0 (zero) coefficients is
singled out (if any such variables are in the problem).
The range is displayed using three terms:
• min |c| The minimum absolute value among all coeffecients
• min |c|>0 The minimum absolute value among the nonzero coefficients
• max |c| The maximum absolute value among the coefficients
If some of these extrema turn out to be equal, the display is shortened accordingly:
• If min |c| is greater than zero, the min |c|>0 term is obsolete and will not be displayed
• If only one or two different coefficients occur this will be displayed using all and an explicit listing
of the coefficients
The absolute value distribution is displayed as a table summarizing the numbers by orders of magnitude
(with a ratio of 10). Again, the number of variables with a coefficient of 0 (if any) is singled out. Each line
of the table is headed by an interval (half-open intervals including their lower bounds), and is followed
by the number of variables with their objective coefficient in this interval. Intervals with no elements are
skipped.
The third part of the survey displays information on the nonzero coefficients of the linear constraint
matrix.
Following a brief summary of the matrix dimensions and the number of nonzero coefficients in total,
three sections provide further details on how the nonzero coefficients are distributed by row-wise count
(A_i), by column-wise count (A|j), and by absolute value (|A(ij)|). Each section is headed by a brief
display of the distribution’s range (min and max), and for the row/column-wise counts the corresponding
densities are displayed too (in parentheses).
The distribution tables single out three particularly interesting counts: zero, one, and two nonzeros per
row/column; the remaining row/column nonzeros are displayed by orders of magnitude (ratio 2). For
each interval the relative and accumulated relative counts are also displayed.
Note that constraints may have both linear and quadratic terms, but the empty rows and columns
reported in this part of the survey relate to the linear terms only. If empty rows and/or columns
are found in the linear constraint matrix, the problem is analyzed further in order to determine if the
corresponding constraints have any quadratic terms or the corresponding variables are used in conic or
quadratic constraints.
The distribution of the absolute values, |A(ij)|, is displayed just as for the objective coefficients de-
scribed above.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The fourth part of the survey displays distributions for the absolute values of the finite lower and upper
bounds for both constraints and variables. The number of bounds at 0 is singled out and, otherwise,
displayed by orders of magnitude (with a ratio of 10).
The fifth part of the survey displays distributions for the nonzero elements in the gradient of the quadratic
constraints, i.e. the nonzero row counts for the column vectors 𝑄𝑥 . The table is similar to the tables
for the linear constraints’ nonzero row and column counts described in the survey’s third part.
Note: Quadratic constraints may also have a linear part, but that will be included in the linear
constraints survey; this means that if a problem has one or more pure quadratic constraints, part three
of the survey will report anleq al number of linear constraint rows with 0 (zero) nonzeros. Likewise,
variables that appear in quadratic terms only will be reported as empty columns (0 nonzeros) in the
linear constraint report.
The last part of the survey summarizes the model’s conic constraints. For each of the two types of cones,
quadratic and rotated quadratic, the total number of cones are reported, and the distribution of the
cones’ dimensions are displayed using intervals. Cone dimensions of 2, 3, and 4 are singled out.
www.EngineeringBooksPdf.com
CHAPTER
FOURTEEN
When developing and implementing a new optimization model, the first attempts will often be either
infeasible, due to specification of inconsistent constraints, or unbounded, if important constraints have
been left out.
In this section we will
• go over an example demonstrating how to locate infeasible constraints using the MOSEK infeasi-
bility report tool,
• discuss in more general terms which properties may cause infeasibilities, and
• present the more formal theory of infeasible and unbounded problems.
A problem is said to be primal infeasible if no solution exists that satisfies all the constraints of the
problem.
As an example of a primal infeasible problem consider the problem of minimizing the cost of transporta-
tion between a number of production plants and stores: Each plant produces a fixed number of goods,
and each store has a fixed demand that must be met. Supply, demand and cost of transportation per
unit are given in Fig. 14.1.
Supply Demand
1 Store 1 1100
200
Plant 1
2
Store 2 200
1
1000 Plant 2
5
Store 3 500
2
2
1000 Plant 3 1
Store 4 500
The problem represented in Fig. 14.1 is infeasible, since the total demand
137
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
If we denote the number of transported goods from plant 𝑖 to store 𝑗 by 𝑥𝑖𝑗 , the problem can be
formulated as the LP:
minimize 𝑥11 + 2𝑥12 + 5𝑥23 + 2𝑥24 + 𝑥31 + 2𝑥33 + 𝑥34
subject to 𝑥11 + 𝑥12 ≤ 200,
𝑥23 + 𝑥24 ≤ 1000,
𝑥31 + 𝑥33 + 𝑥34 ≤ 1000,
𝑥11 + 𝑥31 = 1100,
𝑥12 = 200,
𝑥23 + 𝑥33 = 500,
𝑥24 + 𝑥34 = 500,
𝑥𝑖𝑗 ≥ 0.
(14.1)
Solving problem (14.1) using MOSEK will result in a solution, a solution status and a problem status.
Among the log output from the execution of MOSEK on the above problem are the lines:
Basic solution
Problem status : PRIMAL_INFEASIBLE
Solution status : PRIMAL_INFEASIBLE_CER
The first line indicates that the problem status is primal infeasible. The second line says that a certificate
of the infeasibility was found. The certificate is returned in place of the solution to the problem.
Usually a primal infeasible problem status is caused by a mistake in formulating the problem and therefore
the question arises: What is the cause of the infeasible status? When trying to answer this question, it
is often advantageous to follow these steps:
• Remove the objective function. This does not change the infeasibility status but simplifies the
problem, eliminating any possibility of issues related to the objective function.
• Consider whether your problem has some necessary conditions for feasibility and examine if these
are satisfied, e.g. total supply should be greater than or equal to total demand.
• Verify that coefficients and bounds are reasonably sized in your problem.
If the problem is still primal infeasible, some of the constraints must be relaxed or removed completely.
The MOSEK infeasibility report (Section 14.4 ) may assist you in finding the constraints causing the
infeasibility.
Possible ways of relaxing your problem nclude:
• Increasing (decreasing) upper (lower) bounds on variables and constraints.
• Removing suspected constraints from the problem.
Returning to the transportation example, we discover that removing the fifth constraint
𝑥12 = 200
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
A problem may also be dual infeasible. In this case the primal problem is often unbounded, meaning that
feasbile solutions exists such that the objective tends towards infinity. An example of a dual infeasible
and primal unbounded problem is:
minimize 𝑥1
subject to 𝑥1 ≤ 5.
To resolve a dual infeasibility the primal problem must be made more restricted by
• Adding upper or lower bounds on variables or constraints.
• Removing variables.
• Changing the objective.
The problem
minimize 0
subject to 0 ≤ 𝑥1 ,
𝑥𝑗 ≤ 𝑥𝑗+1 , 𝑗 = 1, . . . , 𝑛 − 1,
𝑥𝑛 ≤ −1
is clearly infeasible. Moreover, if any one of the constraints is dropped, then the problem becomes
feasible.
This illustrates the worst case scenario where all, or at least a significant portion of the constraints
are involved in causing infeasibility. Hence, it may not always be easy or possible to pinpoint a few
constraints responsible for infeasibility.
MOSEK includes functionality for diagnosing the cause of a primal or a dual infeasibility. It can be
turned on by setting the iparam.infeas_report_auto to onoffkey.on . This causes MOSEK to print
a report on variables and constraints involved in the infeasibility.
The iparam.infeas_report_level parameter controls the amount of information presented in the
infeasibility report. The default value is 1.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
is a certificate of dual infeasibility (see Section 10.1.2.2 ) as we can see from this report:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
This section discusses the theory of infeasibility certificates and how MOSEK uses a certificate to
produce an infeasibility report. In general, MOSEK solves the problem
minimize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐
≤ 𝐴𝑥 ≤ 𝑢𝑐 , (14.2)
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥
We use the convension that for any bound that is not finite, the corresponding dual variable is fixed at
zero (and thus will have no influence on the dual problem). For example
𝑙𝑗𝑥 = −∞ ⇒ (𝑠𝑥𝑙 )𝑗 = 0
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
(𝑙𝑐 )𝑇 𝑠𝑐* 𝑐 𝑇 𝑐* 𝑥 𝑇 𝑥* 𝑥 𝑇 𝑥*
𝑙 − (𝑢 ) 𝑠𝑢 + (𝑙 ) 𝑠𝑙 − (𝑢 ) 𝑠𝑢 > 0
and
𝐴𝑇 𝑦 + 𝑠𝑥*𝑙 − 𝑠𝑢
𝑥*
= 0,
𝑐* 𝑐*
−𝑦 + 𝑠𝑙 − 𝑠𝑢 = 0,
𝑠𝑐* 𝑐* 𝑥* 𝑥*
𝑙 , 𝑠𝑢 , 𝑠𝑙 , 𝑠𝑢 ≤ 0.
The well-known Farkas Lemma tells us that (14.2) is infeasible if and only if a certificate of primal
infeasibility exists.
Let (𝑠𝑐*
𝑙 , 𝑠𝑢 , 𝑠𝑙 , 𝑠𝑢 ) be a certificate of primal infeasibility then
𝑐* 𝑥* 𝑥*
(𝑠𝑐* 𝑐*
𝑙 )𝑖 > 0((𝑠𝑢 )𝑖 > 0)
implies that the lower (upper) bound on the 𝑖 th constraint is important for the infeasibility. Furthermore,
(𝑠𝑥* 𝑥*
𝑙 )𝑗 > 0((𝑠𝑢 )𝑖 > 0)
implies that the lower (upper) bound on the 𝑗 th variable is important for the infeasibility.
minimize 𝑐𝑇 𝑥
subject to ¯𝑐
𝑙 ≤ 𝐴𝑥 ¯𝑐 ,
≤ 𝑢
¯𝑙𝑥 ≤ 𝑥 ¯𝑥
≤ 𝑢
and
𝑙𝑖𝑥 > −∞, 0, 𝑢𝑥𝑖 < ∞,
{︂ }︂ {︂ }︂
¯𝑙𝑥 := 0,
and ¯𝑥𝑖
𝑢 :=
𝑖 −∞, otherwise, ∞, otherwise.
𝑐𝑇 𝑥* < 0,
¯𝑙𝑐 ≤ 𝐴𝑥* ¯𝑐 ,
≤ 𝑢 (14.4)
¯𝑙𝑥 ≤ 𝑥* ¯𝑥
≤ 𝑢
The well-known Farkas Lemma tells us that (14.3) is infeasible if and only if a certificate of dual infea-
sibility exists.
Note that if 𝑥* is a certificate of dual infeasibility then for any 𝑗 such that
𝑥*𝑗 ≤ 0,
www.EngineeringBooksPdf.com
CHAPTER
FIFTEEN
SENSITIVITY ANALYSIS
Given an optimization problem it is often useful to obtain information about how the optimal objective
value changes when the problem parameters are perturbed. E.g, assume that a bound represents the
capacity of a machine. Now, it may be possible to expand the capacity for a certain cost and hence it is
worthwhile knowing what the value of additional capacity is. This is precisely the type of questions the
sensitivity analysis deals with.
Analyzing how the optimal objective value changes when the problem data is changed is called sensitivity
analysis.
References
The book [Chv83] discusses the classical sensitivity analysis in Chapter 10 whereas the book [RTV97]
presents a modern introduction to sensitivity analysis. Finally, it is recommended to read the short
paper [Wal00] to avoid some of the pitfalls associated with sensitivity analysis.
Warning: Currently, sensitivity analysis is only available for continuous linear optimization prob-
lems. Moreover, MOSEK can only deal with perturbations of bounds and objective function coeffi-
cients.
𝑧(𝑙𝑐 , 𝑢𝑐 , 𝑙𝑥 , 𝑢𝑥 , 𝑐) = minimize 𝑐𝑇 𝑥
subject to 𝑐
𝑙 ≤ 𝐴𝑥 ≤ 𝑢𝑐 , (15.1)
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
and we want to know how the optimal objective value changes as 𝑙𝑖𝑐 is perturbed. To answer this question
we define the perturbed problem for 𝑙𝑖𝑐 as follows
shows the optimal objective value as a function of 𝛽. Please note that a change in 𝛽 corresponds to a
perturbation in 𝑙𝑖𝑐 and hence (15.2) shows the optimal objective value as a function of varying 𝑙𝑖𝑐 with
the other bounds fixed.
143
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
It is possible to prove that the function (15.2) is a piecewise linear and convex function, i.e. its graph
may look like in Fig. 15.1 and Fig. 15.2.
f( β )
β β β
1 0 2
Clearly, if the function 𝑓𝑙𝑖𝑐 (𝛽) does not change much when 𝛽 is changed, then we can conclude that the
optimal objective value is insensitive to changes in 𝑙𝑖𝑐 . Therefore, we are interested in the rate of change
in 𝑓𝑙𝑖𝑐 (𝛽) for small changes in 𝛽 — specifically the gradient
𝑓𝑙′𝑖𝑐 (0),
which is called the shadow price related to 𝑙𝑖𝑐 . The shadow price specifies how the objective value changes
for small changes of 𝛽 around zero. Moreover, we are interested in the linearity interval
𝛽 ∈ [𝛽1 , 𝛽2 ]
for which
Since 𝑓𝑙𝑖𝑐 is not a smooth function 𝑓𝑙′𝑐 may not be defined at 0, as illustrated in Fig. 15.2. In this case
𝑖
we can define a left and a right shadow price and a left and a right linearity interval.
The function 𝑓𝑙𝑖𝑐 considered only changes in 𝑙𝑖𝑐 . We can define similar functions for the remaining
parameters of the 𝑧 defined in (15.1) as well:
Given these definitions it should be clear how linearity intervals and shadow prices are defined for the
parameters 𝑢𝑐𝑖 etc.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
f( β )
β 0 β β
1 2
Equality Constraints
In MOSEK a constraint can be specified as either an equality constraint or a ranged constraint. If some
constraint 𝑒𝑐𝑖 is an equality constraint, we define the optimal value function for this constraint as
Thus for an equality constraint the upper and the lower bounds (which are equal) are perturbed simul-
taneously. Therefore, MOSEK will handle sensitivity analysis differently for a ranged constraint with
𝑙𝑖𝑐 = 𝑢𝑐𝑖 and for an equality constraint.
The classical sensitivity analysis discussed in most textbooks about linear optimization, e.g. [Chv83] ,
is based on an optimal basic solution or, equivalently, on an optimal basis. This method may produce
misleading results [RTV97] but is computationally cheap. Therefore, and for historical reasons, this
method is available in MOSEK.
We will now briefly discuss the basis type sensitivity analysis. Given an optimal basic solution which
provides a partition of variables into basic and non-basic variables, the basis type sensitivity analysis
computes the linearity interval [𝛽1 , 𝛽2 ] so that the basis remains optimal for the perturbed problem. A
shadow price associated with the linearity interval is also computed. However, it is well-known that
an optimal basic solution may not be unique and therefore the result depends on the optimal basic
solution employed in the sensitivity analysis. This implies that the computed interval is only a subset
of the largest interval for which the shadow price is constant. Furthermore, the optimal objective value
function might have a breakpoint for 𝛽 = 0. In this case the basis type sensitivity method will only
provide a subset of either the left or the right linearity interval.
In summary, the basis type sensitivity analysis is computationally cheap but does not provide complete
information. Hence, the results of the basis type sensitivity analysis should be used with care.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Another method for computing the complete linearity interval is called the optimal partition type sen-
sitivity analysis. The main drawback of the optimal partition type sensitivity analysis is that it is
computationally expensive compared to the basis type analysis. This type of sensitivity analysis is
currently provided as an experimental feature in MOSEK.
Given the optimal primal and dual solutions to (15.1), i.e. 𝑥* and ((𝑠𝑐𝑙 )* , (𝑠𝑐𝑢 )* , (𝑠𝑥𝑙 )* , (𝑠𝑥𝑢 )* ) the optimal
objective value is given by
𝑧 * := 𝑐𝑇 𝑥* .
The left and right shadow prices 𝜎1 and 𝜎2 for 𝑙𝑖𝑐 are given by this pair of optimization problems:
Next, the linearity interval [𝛽1 , 𝛽2 ] for 𝑙𝑖𝑐 is computed by solving the two optimization problems
𝛽1 = minimize 𝛽
subject to 𝑙𝑐 + 𝛽𝑒𝑖 ≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑐𝑇 𝑥 − 𝜎 1 𝛽 = 𝑧*,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
and
𝛽2 = maximize 𝛽
subject to 𝑙𝑐 + 𝛽𝑒𝑖 ≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑐𝑇 𝑥 − 𝜎 2 𝛽 = 𝑧*,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 .
The linearity intervals and shadow prices for 𝑢𝑐𝑖 , 𝑙𝑗𝑥 , and 𝑢𝑥𝑗 are computed similarly to 𝑙𝑖𝑐 .
The left and right shadow prices for 𝑐𝑗 denoted 𝜎1 and 𝜎2 respectively are computed as follows:
𝜎1 = minimize 𝑒𝑇𝑗 𝑥
subject to 𝑙𝑐 + 𝛽𝑒𝑖 ≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑐𝑇 𝑥 = 𝑧*,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
and
𝜎2 = maximize 𝑒𝑇𝑗 𝑥
subject to 𝑙𝑐 + 𝛽𝑒𝑖 ≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑐𝑇 𝑥 = 𝑧*,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 .
Once again the above two optimization problems make it easy to interpret the shadow prices. Indeed, if
𝑥* is an arbitrary primal optimal solution, then
𝑥*𝑗 ∈ [𝜎1 , 𝜎2 ].
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝛽1 = minimize 𝛽
subject to 𝐴𝑇 (𝑠𝑐𝑙 − 𝑠𝑐𝑢 ) + 𝑠𝑥𝑙 − 𝑠𝑥𝑢 = 𝑐 + 𝛽𝑒𝑗 ,
(𝑙𝑐 )𝑇 (𝑠𝑐𝑙 ) − (𝑢𝑐 )𝑇 (𝑠𝑐𝑢 ) + (𝑙𝑥 )𝑇 (𝑠𝑥𝑙 ) − (𝑢𝑥 )𝑇 (𝑠𝑥𝑢 ) − 𝜎1 𝛽 ≤ 𝑧*,
𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑐𝑙 , 𝑠𝑥𝑢 ≥ 0
and
𝛽2 = maximize 𝛽
subject to 𝐴𝑇 (𝑠𝑐𝑙 − 𝑠𝑐𝑢 ) + 𝑠𝑥𝑙 − 𝑠𝑥𝑢 = 𝑐 + 𝛽𝑒𝑗 ,
(𝑙𝑐 )𝑇 (𝑠𝑐𝑙 ) − (𝑢𝑐 )𝑇 (𝑠𝑐𝑢 ) + (𝑙𝑥 )𝑇 (𝑠𝑥𝑙 ) − (𝑢𝑥 )𝑇 (𝑠𝑥𝑢 ) − 𝜎2 𝛽 ≤ 𝑧*,
𝑠𝑐𝑙 , 𝑠𝑐𝑢 , 𝑠𝑐𝑙 , 𝑠𝑥𝑢 ≥ 0.
As an example we will use the following transportation problem. Consider the problem of minimizing the
transportation cost between a number of production plants and stores. Each plant supplies a number of
goods and each store has a given demand that must be met. Supply, demand and cost of transportation
per unit are shown in Fig. 15.3.
Supply Demand
1 Store 1 800
400 Plant 1
2
Store 2 100
1
1200 Plant 2
5
Store 3 500
2
2
1000 Plant 3 1
Store 4 500
If we denote the number of transported goods from location 𝑖 to location 𝑗 by 𝑥𝑖𝑗 , problem can be
formulated as the linear optimization problem of minimizing
subject to
The sensitivity parameters are shown in Table 15.1 and Table 15.2 for the basis type analysis and in
Table 15.3 and Table 15.4 for the optimal partition type analysis.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Examining the results from the optimal partition type sensitivity analysis we see that for constraint
number 1 we have 𝜎1 = 3, 𝜎2 = 1 and 𝛽1 = −300, 𝛽2 = 500. Therefore, we have a left linearity interval
of [−300, 0] and a right interval of [0, 500]. The corresponding left and right shadow prices are 3 and 1
respectively. This implies that if the upper bound on constraint 1 increases by
𝜎2 𝛽 = 1𝛽.
𝛽 ∈ [0, 300]
𝜎1 𝛽 = 3𝛽.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Listing 15.1: Example of sensitivity analysis with the MOSEK Optimizer API for Python.
import sys
import mosek
# Create a task
with env.Task(0,0) as task:
# Attach a printer to the task
task.set_Stream (mosek.streamtype.log, streamprinter)
# Set up data
bkc = [ mosek.boundkey.up,mosek.boundkey.up,
mosek.boundkey.up,mosek.boundkey.fx,
mosek.boundkey.fx,mosek.boundkey.fx,
mosek.boundkey.fx ]
blc = [ -inf, -inf, -inf, 800., 100., 500., 500. ]
buc = [ 400., 1200., 1000., 800., 100., 500., 500. ]
bkx = [ mosek.boundkey.lo,mosek.boundkey.lo,
mosek.boundkey.lo,mosek.boundkey.lo,
mosek.boundkey.lo,mosek.boundkey.lo,
mosek.boundkey.lo ]
c = [ 1.0,2.0,5.0,2.0,1.0,2.0,1.0 ]
blx = [ 0.0,0.0,0.0,0.0,0.0,0.0,0.0 ]
bux = [ inf,inf,inf,inf,inf,inf,inf ]
val = [ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,
1.0,1.0,1.0,1.0,1.0,1.0,1.0 ]
numcon = len(bkc)
numvar = len(bkx)
numanz = len(val)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# Optimize
task.optimize();
task.primalsensitivity( subi,
marki,
subj,
markj,
leftpricei,
rightpricei,
leftrangei,
rightrangei,
leftpricej,
rightpricej,
leftrangej,
rightrangej)
for i in range(2):
print ('\t%10f %10f %10f %10f' % (leftpricei[i],
rightpricei[i],
leftrangei[i],
rightrangei[i]))
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.dualsensitivity( subc,
leftprice,
rightprice,
leftrange,
rightrange)
for i in range(2):
print ('\t%10f %10f %10f %10f' % (leftprice[i],
rightprice[i],
leftrange[i],
rightrange[i]))
return None
www.EngineeringBooksPdf.com
CHAPTER
SIXTEEN
API REFERENCE
This section contains the complete reference of the MOSEK Optimizer API for Python. It is organized
as follows:
• General API conventions.
• API functionalities either grouped by topic or accessable via the complete class list:
– Env
– Task
• Exceptions
• SCopt interface
• Optimizer parameters
• Response codes
• Constants
In the definition of the MOSEK Optimizer API for Python a consistent naming convention has been
used. This implies that whenever for example numcon is an argument in a function definition it indicates
the number of constraints. In Table 16.1 the variable names used to specify the problem parameters are
listed.
153
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Table 16.1: Naming convensions used in the MOSEK Optimizer API for
Python.
API name API type Dimension Related problem parameter
numcon int 𝑚
numvar int 𝑛
numcone int 𝑡
numqonz int 𝑜
𝑞𝑖𝑗
qosubi int[] numqonz 𝑜
𝑞𝑖𝑗
qosubj int[] numqonz 𝑜
𝑞𝑖𝑗
qoval float[] numqonz 𝑜
𝑞𝑖𝑗
c float[] numvar 𝑐𝑗
cfix float 𝑐𝑓
numqcnz int 𝑘
𝑞𝑖𝑗
qcsubk int[] qcnz 𝑘
𝑞𝑖𝑗
qcsubi int[] qcnz 𝑘
𝑞𝑖𝑗
qcsubj int[] qcnz 𝑘
𝑞𝑖𝑗
qcval float[] qcnz 𝑘
𝑞𝑖𝑗
aptrb int[] numvar 𝑎𝑖𝑗
aptre int[] numvar 𝑎𝑖𝑗
asub int[] aptre[numvar-1] 𝑎𝑖𝑗
aval float[] aptre[numvar-1] 𝑎𝑖𝑗
bkc int[] numcon 𝑙𝑘𝑐 and 𝑢𝑐𝑘
blc float[] numcon 𝑙𝑘𝑐
buc float[] numcon 𝑢𝑐𝑘
bkx int[] numvar 𝑙𝑘𝑥 and 𝑢𝑥𝑘
blx float[] numvar 𝑙𝑘𝑥
bux float[] numvar 𝑢𝑥𝑘
The relation between the variable names and the problem parameters is as follows:
• The quadratic terms in the objective: 𝑞qosubi[t],qosubj[t]
𝑜
= qoval[t], 𝑡 = 0, . . . , numqonz − 1.
• The linear terms in the objective : 𝑐𝑗 = c[j], 𝑗 = 0, . . . , numvar − 1
• The fixed term in the objective : 𝑐𝑓 = cfix.
• The quadratic terms in the constraints: 𝑞qcsubi[t],qcsubj[t] = qcval[t],
qcsubk[t]
𝑡 = 0, . . . , numqcnz − 1
• The linear terms in the constraints: 𝑎asub[t],j = aval[t], 𝑡 = ptrb[j], . . . , ptre[j] − 1, 𝑗 =
0, . . . , numvar − 1
The bounds on the constraints are specified using the variables bkc, blc, and buc. The components of
the integer array bkc specify the bound type according to Table 16.2
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
and
The bounds on the variables are specified using the variables bkx, blx, and bux. The components in the
integer array bkx specify the bound type according to Table Table 16.2. The numerical values for the
lower bounds on the variables are given by
The numerical values for the upper bounds on the variables are given by
Bounds
A bound on a variable or on a constraint in MOSEK consists of a bound key, as defined in Table 16.2,
a lower bound value and an upper bound value. Even if a variable or constraint is bounded only from
below, e.g. 𝑥 ≥ 0 , both bounds are inputted or extracted; the value inputted as upper bound for (𝑥 ≥ 0)
is ignored.
Full vector
This is simply an array where the first element corresponds to the first item, the second element to the
second item etc. For example to get the linear coefficients of the objective in task, one would write
c = zeros(numvar,float)
task.getc(c)
Vector slice
A vector slice is a range of values. For example, to get the bounds associated constraint 3 through 10
(both inclusive) one would write
upper_bound = zeros(8,float)
lower_bound = zeros(8,float)
bound_key = array([None] * 8)
task.getboundslice(accmode.con, 2, 10,
bound_key,lower_bound,upper_bound)
Please note that items in MOSEK are numbered from 0 , so that the index of the first item is 0 , and
the index of the 𝑛’th item is 𝑛 − 1.
Sparse vector
A sparse vector is given as an array of indexes and an array of values. For example, to input a set of
bounds associated with constraints number 1, 6, 3, and 9, one might write
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
bound_index = [ 1, 6, 3, 9]
bound_key = [boundkey.fr,boundkey.lo,boundkey.up,boundkey.fx]
lower_bound = [ 0.0, -10.0, 0.0, 5.0]
upper_bound = [ 0.0, 0.0, 6.0, 5.0]
task.putboundlist(accmode.con, bound_index,
bound_key,lower_bound,upper_bound)
The coefficient matrices in a problem are inputted and extracted in a sparse format, either as complete
or a partial matrices. Basically there are two different formats for this.
Unordered Triplets
In unordered triplet format each entry is defined as a row index, a column index and a coefficient. For
example, to input the 𝐴 matrix coefficients for 𝑎1,2 = 1.1, 𝑎3,3 = 4.3 , and 𝑎5,4 = 0.2 , one would write
as follows:
subi = array([ 1, 3, 5 ])
subj = array([ 2, 3, 4 ])
cof = array([ 1.1, 4.3, 0.2 ])
task.putaijlist(subi,subj,cof)
Please note that in some cases (like task.putaijlist ) only the specified indexes remain modified —
all other are unchanged. In other cases (such as task.putqconk ) the triplet format is used to modify
all entries — entries that are not specified are set to 0.
In a sparse matrix format only the non-zero entries of the matrix are stored. MOSEK uses a sparse
packed matrix format ordered either by columns or rows. In the column-wise format the position of the
non-zeros are given as a list of row indexes. In the row-wise format the position of the non-zeros are
given as a list of column indexes. Values of the non-zero entries are given in column or row order.
𝑗 = 0, . . . , 𝑛𝑢𝑚𝑐𝑜𝑙 − 1.
We define
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Fig. 16.1 illustrates how the matrix 𝐴 in (16.1) is represented in column ordered sparse matrix format.
ptrb 0 2 3 5
ptre 2 3 5 7
asub 0 2 1 0 3 0 1 2
Column 0 Column 1
Fig. 16.1: The matrix 𝐴 (16.1) represented in column ordered packed sparse matrix format.
The matrix 𝐴 (16.1) can also be represented in the row ordered sparse matrix format as:
16.2.1 Bounds
• task.getconbound
• task.getvarbound
• task.getbound
• task.getconboundslice
• task.getvarboundslice
• task.getboundslice
• task.putboundslice
• task.putbound
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.putboundlist
• task.putconboundlist
• task.putvarboundlist
• task.getinfeasiblesubproblem
• task.putskc
• task.putskx
• task.putxc
• task.putxx
• task.puty
• task.putslc
• task.putsuc
• task.putslx
• task.putsux
• task.putsnx
• task.putskcslice
• task.putskxslice
• task.putxcslice
• task.putxxslice
• task.putyslice
• task.putslcslice
• task.putsucslice
• task.putslxslice
• task.putsuxslice
• task.putsnxslice
• task.putsolution
• task.putsolutioni
16.2.4 Linear algebra utility functions for performing linear algebra operations
• env.computesparsecholesky
• env.sparsetriangularsolvedense
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.getnumparam
• task.isdouparname
• task.isintparname
• task.isstrparname
• task.setdefaults
• env.checkoutlicense
• env.checkinlicense
• env.putlicensedebug
• env.putlicensecode
• env.putlicensewait
• env.putlicensepath
• task.checkmem
• task.getmemusage
16.2.8 Naming
• task.getbarvarnamelen
• task.getbarvarname
• task.getbarvarnameindex
• task.putconname
• task.putvarname
• task.putconename
• task.getvarnamelen
• task.getvarname
• task.getconnamelen
• task.getconname
• task.getconnameindex
• task.getvarnameindex
• task.getconenamelen
• task.getconename
• task.getconenameindex
• task.getobjname
• task.gettasknamelen
• task.gettaskname
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.putobjname
• task.puttaskname
• task.getdualobj
• task.getsolsta
• task.getprosta
• task.getsolutioninfo
• task.solutiondef
• task.getsolution
• task.getsolutioni
• task.getskc
• task.getskx
• task.getxc
• task.getxx
• task.gety
• task.getslc
• task.getsuc
• task.getslx
• task.getsux
• task.getsnx
• task.getskcslice
• task.getskxslice
• task.getxcslice
• task.getxxslice
• task.getyslice
• task.getslcslice
• task.getsucslice
• task.getslxslice
• task.getsuxslice
• task.getsnxslice
• task.getsolutionslice
• task.getreducedcosts
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.getdouparam
• task.getintparam
• task.getstrparam
• task.getstrparamlen
• task.putcfix
• task.putobjsense
• task.getobjsense
• task.appendvars
• task.removevars
• task.getaij
• task.getacolnumnz
• task.getacol
• task.getarownumnz
• task.getarow
• task.getaslice
• task.getarowslicetrip
• task.getacolslicetrip
• task.getc
• task.getcfix
• task.getcslice
• task.getmaxnumanz
• task.getmaxnumvar
• task.getnumanz
• task.getnumanz64
• task.getnumintvar
• task.getnumqconknz
• task.getnumqobjnz
• task.getnumvar
• task.getlenbarvarj
• task.getqconk
• task.getqobj
• task.getqobjij
• task.getvartype
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.getvartypelist
• task.commitchanges
• task.putaij
• task.putacol
• task.putarow
• task.putarowslice
• task.putarowlist
• task.putacolslice
• task.putacollist
• task.putvarbound
• task.putvarboundslice
• task.putclist
• task.putcslice
• task.getsymmatinfo
• task.getnumsymmat
• task.getsparsesymmat
• task.putmaxnumvar
• task.putmaxnumanz
• task.putmaxnumqnz
• task.getmaxnumqnz
• task.putqcon
• task.putqconk
• task.putqobj
• task.putqobjij
• task.putvartype
• task.putvartypelist
• task.removebarvars
• task.appendbarvars
• task.getmaxnumbarvar
• task.getdimbarvarj
• task.getbarcidxj
• task.appendsparsesymmat
• task.putmaxnumbarvar
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.removecones
• task.appendcone
• task.appendconeseq
• task.appendconesseq
• task.getcone
• task.getconeinfo
• task.getnumcone
• task.getnumconemem
• task.putcone
• task.appendcons
• task.removecons
• task.getmaxnumcon
• task.getnumcon
• task.putconbound
• task.putconboundslice
• task.initbasissolve
• task.solvewithbasis
• task.basiscond
16.2.18 Optimization
• task.optimize
• task.getdouinf
• task.getintinf
• task.getlintinf
• task.linkfiletostream
• env.linkfiletostream
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.readdataformat
• task.readdata
• task.readparamfile
• task.readsolution
• task.writedata
• task.writeparamfile
• task.writesolution
• task.writejsonsol
• task.primalsensitivity
• task.sensitivityreport
• task.dualsensitivity
• task.putdouparam
• task.putintparam
• task.putnadouparam
• task.putnaintparam
• task.putnastrparam
• task.putparam
• task.putstrparam
• task.analyzeproblem
• task.getprobtype
• task.printdata
• task.readsummary
• task.optimizersummary
• task.checkconvexity
• env.echointro
• task.inputdata
• task.putmaxnumcon
• task.putmaxnumcone
• task.getmaxnumcone
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• task.deletesolution
• env.getcodedesc
SCopt is an easy-to-use interface to the nonlinear optimizer when solving separable convex problems. As
currently implemented, SCopt is not capable of handling arbitrary nonlinear expressions. In fact SCopt
can handle only the nonlinear expressions 𝑥 log(𝑥), 𝑒𝑥 , log(𝑥), and 𝑥𝑔 . However, it should be fairly easy
to extend the interface to other nonlinear function of a single variable if needed.
All the linear data of the problem, such as 𝑐 and 𝐴, is inputted to MOSEK as usual, i.e. using the
relevant functions in the MOSEK API.
The nonlinear part of the problem is specified using some arrays which indicate the type of the nonlinear
expressions and where these should be added.
For example given the three int arrays — oprc, opric, and oprjc — and the three double arrays —
oprfc, oprgc and oprhc — the nonlinear expressions in the constraints can be coded in those arrays
using the following table:
oprc[k] opric[k] oprjc[k] oprfc[k] oprgc[k] oprhc[k] Expression added to constraint
𝑖
0 i j 𝑓 𝑔 ℎ 𝑓 𝑥𝑗 ln(𝑥𝑗 )
1 i j 𝑓 𝑔 ℎ 𝑓 𝑒𝑔𝑥𝑗 +ℎ
2 i j 𝑓 𝑔 ℎ 𝑓 ln(𝑔𝑥𝑗 + ℎ)
3 i j 𝑓 𝑔 ℎ 𝑓 (𝑥𝑗 + ℎ)𝑔
Hence, oprc[k] specifies the nonlinear expression type, opric[k] indicates to which constraint the
nonlinear expression should be added. oprfc[k], oprgc[k] and oprhc[k] are parameters used when the
nonlinear expression is evaluated. This implies that nonlinear expressions can be added to an arbitrary
constraint and hence you can create multiple nonlinear constraints.
Using the same method all the nonlinear terms in the objective can be specified using opro[k], oprjo[k],
oprfo[k], oprgo[k] and oprho[k] as shown below:
opro[k] oprjo[k] oprfo[k] oprgo[k] oprho[k] Expression added in objective
0 j 𝑓 𝑔 ℎ 𝑓 𝑥𝑗 ln(𝑥𝑗 )
1 j 𝑓 𝑔 ℎ 𝑓 𝑒𝑔𝑥𝑗 +ℎ
2 j 𝑓 𝑔 ℎ 𝑓 ln(𝑔𝑥𝑗 + ℎ)
3 j 𝑓 𝑔 ℎ 𝑓 (𝑥𝑗 + ℎ)𝑔
16.4 Parameters
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• Overall solver
• Mixed-integer optimization
• Output information
• Optimization system
• Simplex optimizer
• Logging
• Data check
• Progress call-back
• Analysis
• Conic interior-point method
• Nonlinear convex method
• Solution input/output
• Interior-point method
• Dual simplex optimizer
• Termination criterion
• Primal simplex optimizer
• Basis identification
• License manager
• Presolve
• Debugging
• Data input/output
• Infeasibility report
Double Parameters
dparam.ana_sol_infeas_tol
If a constraint violates its bound with an amount larger than this value, the constraint name, index
and violation will be printed by the solution analyzer.
Accepted Values: [0.0 ;+inf ]
Default Value: 1e-6
Groups: Analysis
dparam.basis_rel_tol_s
Maximum relative dual bound violation allowed in an optimal basic solution.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-12
Groups: Simplex optimizer , Termination criterion
dparam.basis_tol_s
Maximum absolute dual bound violation in an optimal basic solution.
Accepted Values: [1.0e-9 ;+inf ]
Default Value: 1.0e-6
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑑𝑖 ≤ −|𝑄𝑖𝑖 |check_convexity_rel_tol
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dparam.data_tol_aij_huge
An element in 𝐴 which is larger than this value in absolute size causes an error.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e20
Groups: Data check
dparam.data_tol_aij_large
An element in 𝐴 which is larger than this value in absolute size causes a warning message to be
printed.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e10
Groups: Data check
dparam.data_tol_bound_inf
Any bound which in absolute value is greater than this parameter is considered infinite.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e16
Groups: Data check
dparam.data_tol_bound_wrn
If a bound value is larger than this value in absolute size, then a warning message is issued.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e8
Groups: Data check
dparam.data_tol_cj_large
An element in 𝑐 which is larger than this value in absolute terms causes a warning message to be
printed.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e8
Groups: Data check
dparam.data_tol_c_huge
An element in 𝑐 which is larger than the value of this parameter in absolute terms is considered to
be huge and generates an error.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e16
Groups: Data check
dparam.data_tol_qij
Absolute zero tolerance for elements in 𝑄 matrices.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-16
Groups: Data check
dparam.data_tol_x
Zero tolerance for constraints and variables i.e. if the distance between the lower and upper bound
is less than this value, then the lower and upper bound is considered identical.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-8
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dparam.intpnt_qo_tol_mu_red
Relative complementarity gap feasibility tolerance used when interior-point optimizer is applied to
a quadratic optimization problem.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-8
Groups: Interior-point method , Termination criterion
dparam.intpnt_qo_tol_near_rel
If MOSEK cannot compute a solution that has the prescribed accuracy, then it will multiply the
termination tolerances with value of this parameter. If the solution then satisfies the termination
criteria, then the solution is denoted near optimal, near feasible and so forth.
Accepted Values: [1.0 ;+inf ]
Default Value: 1000
Groups: Interior-point method , Termination criterion
dparam.intpnt_qo_tol_pfeas
Primal feasibility tolerance used when the interior-point optimizer is applied to a quadratic opti-
mization problem.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-8
Groups: Interior-point method , Termination criterion
dparam.intpnt_qo_tol_rel_gap
Relative gap termination tolerance used when the interior-point optimizer is applied to a quadratic
optimization problem.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-8
Groups: Interior-point method , Termination criterion
dparam.intpnt_tol_dfeas
Dual feasibility tolerance used for linear and quadratic optimization problems.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-8
Groups: Interior-point method , Termination criterion
dparam.intpnt_tol_dsafe
Controls the initial dual starting point used by the interior-point optimizer. If the interior-point
optimizer converges slowly and/or the constraint or variable bounds are very large, then it might
be worthwhile to increase this value.
Accepted Values: [1.0e-4 ;+inf ]
Default Value: 1.0
Groups: Interior-point method
dparam.intpnt_tol_infeas
Controls when the optimizer declares the model primal or dual infeasible. A small number means
the optimizer gets more conservative about declaring the model infeasible. A value of 0.0 means
the optimizer must have an exact certificate of infeasibility and this is very unlikely to happen.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-10
Groups: Interior-point method , Termination criterion, Nonlinear convex method
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dparam.intpnt_tol_mu_red
Relative complementarity gap tolerance.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-16
Groups: Interior-point method , Termination criterion
dparam.intpnt_tol_path
Controls how close the interior-point optimizer follows the central path. A large value of this
parameter means the central is followed very closely. On numerical unstable problems it may be
worthwhile to increase this parameter.
Accepted Values: [0.0 ;0.9999 ]
Default Value: 1.0e-8
Groups: Interior-point method
dparam.intpnt_tol_pfeas
Primal feasibility tolerance used for linear and quadratic optimization problems.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-8
Groups: Interior-point method , Termination criterion
dparam.intpnt_tol_psafe
Controls the initial primal starting point used by the interior-point optimizer. If the interior-point
optimizer converges slowly and/or the constraint or variable bounds are very large, then it may be
worthwhile to increase this value.
Accepted Values: [1.0e-4 ;+inf ]
Default Value: 1.0
Groups: Interior-point method
dparam.intpnt_tol_rel_gap
Relative gap termination tolerance.
Accepted Values: [1.0e-14 ;+inf ]
Default Value: 1.0e-8
Groups: Termination criterion, Interior-point method
dparam.intpnt_tol_rel_step
Relative step size to the boundary for linear and quadratic optimization problems.
Accepted Values: [1.0e-4 ;0.999999 ]
Default Value: 0.9999
Groups: Interior-point method
dparam.intpnt_tol_step_size
If the step size falls below the value of this parameter, then the interior-point optimizer assumes
that it is stalled. In other words the interior-point optimizer does not make any progress and
therefore it is better stop.
Accepted Values: [0.0 ;1.0 ]
Default Value: 1.0e-6
Groups: Interior-point method
dparam.lower_obj_cut
If either a primal or dual feasible solution is found proving that the optimal objective value is
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dparam.mio_rel_gap_const
This value is used to compute the relative gap for the solution to an integer optimization problem.
Accepted Values: [1.0e-15 ;+inf ]
Default Value: 1.0e-10
Groups: Mixed-integer optimization, Termination criterion
dparam.mio_tol_abs_gap
Absolute optimality tolerance employed by the mixed-integer optimizer.
Accepted Values: [0.0 ;+inf ]
Default Value: 0.0
Groups: Mixed-integer optimization
dparam.mio_tol_abs_relax_int
Absolute relaxation tolerance of the integer constraints. I.e. min(|𝑥| − ⌊𝑥⌋, ⌈𝑥⌉ − |𝑥|) is less than
the tolerance then the integer restrictions assumed to be satisfied.
Accepted Values: [1e-9 ;+inf ]
Default Value: 1.0e-5
Groups: Mixed-integer optimization
dparam.mio_tol_feas
Feasibility tolerance for mixed integer solver.
Accepted Values: [1e-9 ;1e-3 ]
Default Value: 1.0e-6
Groups: Mixed-integer optimization
dparam.mio_tol_rel_dual_bound_improvement
If the relative improvement of the dual bound is smaller than this value, the solver will terminate
the root cut generation. A value of 0.0 means that the value is selected automatically.
Accepted Values: [0.0 ;1.0 ]
Default Value: 0.0
Groups: Mixed-integer optimization
dparam.mio_tol_rel_gap
Relative optimality tolerance employed by the mixed-integer optimizer.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-4
Groups: Mixed-integer optimization, Termination criterion
dparam.optimizer_max_time
Maximum amount of time the optimizer is allowed to spent on the optimization. A negative number
means infinity.
Accepted Values: [-inf ;+inf ]
Default Value: -1.0
Groups: Termination criterion
dparam.presolve_tol_abs_lindep
Absolute tolerance employed by the linear dependency checker.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-6
Groups: Presolve
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dparam.presolve_tol_aij
Absolute zero tolerance employed for 𝑎𝑖𝑗 in the presolve.
Accepted Values: [1.0e-15 ;+inf ]
Default Value: 1.0e-12
Groups: Presolve
dparam.presolve_tol_rel_lindep
Relative tolerance employed by the linear dependency checker.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-10
Groups: Presolve
dparam.presolve_tol_s
Absolute zero tolerance employed for 𝑠𝑖 in the presolve.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-8
Groups: Presolve
dparam.presolve_tol_x
Absolute zero tolerance employed for 𝑥𝑗 in the presolve.
Accepted Values: [0.0 ;+inf ]
Default Value: 1.0e-8
Groups: Presolve
dparam.qcqo_reformulate_rel_drop_tol
This parameter determines when columns are dropped in incomplete Cholesky factorization during
reformulation of quadratic problems.
Accepted Values: [0 ;+inf ]
Default Value: 1e-15
Groups: Interior-point method
dparam.semidefinite_tol_approx
Tolerance to define a matrix to be positive semidefinite.
Accepted Values: [1.0e-15 ;+inf ]
Default Value: 1.0e-10
Groups: Data check
dparam.simplex_abs_tol_piv
Absolute pivot tolerance employed by the simplex optimizers.
Accepted Values: [1.0e-12 ;+inf ]
Default Value: 1.0e-7
Groups: Simplex optimizer
dparam.sim_lu_tol_rel_piv
Relative pivot tolerance employed when computing the LU factorization of the basis in the simplex
optimizers and in the basis identification procedure.
A value closer to 1.0 generally improves numerical stability but typically also implies an increase
in the computational work.
Accepted Values: [1.0e-6 ;0.999999 ]
Default Value: 0.01
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Integer Parameters
iparam.ana_sol_basis
Controls whether the basis matrix is analyzed in solution analyzer.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Analysis
iparam.ana_sol_print_violated
Controls whether a list of violated constraints is printed when calling task.analyzesolution .
All constraints violated by more than the value set by the parameter dparam.ana_sol_infeas_tol
will be printed.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Analysis
iparam.auto_sort_a_before_opt
Controls whether the elements in each column of 𝐴 are sorted before an optimization is performed.
This is not required but makes the optimization more deterministic.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Debugging
iparam.auto_update_sol_info
Controls whether the solution information items are automatically updated after an optimization
is performed.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Optimization system
iparam.basis_solve_use_plus_one
If a slack variable is in the basis, then the corresponding column in the basis is a unit vector with
-1 in the right position. However, if this parameter is set to onoffkey.on , -1 is replaced by 1.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
This has significance for the results returned by the task.solvewithbasis function.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Simplex optimizer
iparam.bi_clean_optimizer
Controls which simplex optimizer is used in the clean-up phase.
Accepted Values: optimizertype
Default Value: optimizertype.free
Groups: Basis identification, Overall solver
iparam.bi_ignore_max_iter
If the parameter iparam.intpnt_basis has the value basindtype.no_error and the interior-
point optimizer has terminated due to maximum number of iterations, then basis identification is
performed if this parameter has the value onoffkey.on .
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Interior-point method , Basis identification
iparam.bi_ignore_num_error
If the parameter iparam.intpnt_basis has the value basindtype.no_error and the interior-
point optimizer has terminated due to a numerical problem, then basis identification is performed
if this parameter has the value onoffkey.on .
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Interior-point method , Basis identification
iparam.bi_max_iterations
Controls the maximum number of simplex iterations allowed to optimize a basis after the basis
identification.
Accepted Values: [0 ;+inf ]
Default Value: 1000000
Groups: Basis identification, Termination criterion
iparam.cache_license
Specifies if the license is kept checked out for the lifetime of the mosek environment (onoffkey.on )
or returned to the server immediately after the optimization (onoffkey.off ).
By default the license is checked out for the lifetime of the MOSEK environment by the first call
to task.optimize .
Check-in and check-out of licenses have an overhead. Frequent communication with the license
server should be avoided.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: License manager
iparam.check_convexity
Specify the level of convexity check on quadratic problems
Accepted Values: checkconvexitytype
Default Value: checkconvexitytype.full
Groups: Data check , Nonlinear convex method
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.compress_statfile
Control compression of stat files.
Accepted Values: onoffkey
Default Value: onoffkey.on
iparam.infeas_generic_names
Controls whether generic names are used when an infeasible subproblem is created.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Infeasibility report
iparam.infeas_prefer_primal
If both certificates of primal and dual infeasibility are supplied then only the primal is used when
this option is turned on.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Overall solver
iparam.infeas_report_auto
Controls whether an infeasibility report is automatically produced after the optimization if the
problem is primal or dual infeasible.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Data input/output, Solution input/output
iparam.infeas_report_level
Controls the amount of information presented in an infeasibility report. Higher values imply more
information.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Infeasibility report, Output information
iparam.intpnt_basis
Controls whether the interior-point optimizer also computes an optimal basis.
Accepted Values: basindtype
Default Value: basindtype.always
Groups: Interior-point method , Basis identification
iparam.intpnt_diff_step
Controls whether different step sizes are allowed in the primal and dual space.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Interior-point method
iparam.intpnt_hotstart
Currently not in use.
Accepted Values: intpnthotstart
Default Value: intpnthotstart.none
Groups: Interior-point method
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.intpnt_max_iterations
Controls the maximum number of iterations allowed in the interior-point optimizer.
Accepted Values: [0 ;+inf ]
Default Value: 400
Groups: Interior-point method , Termination criterion
iparam.intpnt_max_num_cor
Controls the maximum number of correctors allowed by the multiple corrector procedure. A neg-
ative value means that MOSEK is making the choice.
Accepted Values: [-1 ;+inf ]
Default Value: -1
Groups: Interior-point method
iparam.intpnt_max_num_refinement_steps
Maximum number of steps to be used by the iterative refinement of the search direction. A negative
value implies that the optimizer chooses the maximum number of iterative refinement steps.
Accepted Values: [-inf ;+inf ]
Default Value: -1
Groups: Interior-point method
iparam.intpnt_multi_thread
Controls whether the interior-point optimizers are allowed to employ multiple threads if more
threads is available.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Optimization system
iparam.intpnt_off_col_trh
Controls how many offending columns are detected in the Jacobian of the constraint matrix.
0 no detection
1 aggressive detection
>1 higher values mean less aggressive detection
Accepted Values: [0 ;+inf ]
Default Value: 40
Groups: Interior-point method
iparam.intpnt_order_method
Controls the ordering strategy used by the interior-point optimizer when factorizing the Newton
equation system.
Accepted Values: orderingtype
Default Value: orderingtype.free
Groups: Interior-point method
iparam.intpnt_regularization_use
Controls whether regularization is allowed.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Interior-point method
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.intpnt_scaling
Controls how the problem is scaled before the interior-point optimizer is used.
Accepted Values: scalingtype
Default Value: scalingtype.free
Groups: Interior-point method
iparam.intpnt_solve_form
Controls whether the primal or the dual problem is solved.
Accepted Values: solveform
Default Value: solveform.free
Groups: Interior-point method
iparam.intpnt_starting_point
Starting point used by the interior-point optimizer.
Accepted Values: startpointtype
Default Value: startpointtype.free
Groups: Interior-point method
iparam.license_debug
This option is used to turn on debugging of the license manager.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: License manager
iparam.license_pause_time
If iparam.license_wait = onoffkey.on and no license is available, then MOSEK sleeps a num-
ber of milliseconds between each check of whether a license has become free.
Accepted Values: [0 ;1000000 ]
Default Value: 100
Groups: License manager
iparam.license_suppress_expire_wrns
Controls whether license features expire warnings are suppressed.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: License manager , Output information
iparam.license_trh_expiry_wrn
If a license feature expires in a numbers days less than the value of this parameter then a warning
will be issued.
Accepted Values: [0 ;+inf ]
Default Value: 7
iparam.license_wait
If all licenses are in use MOSEK returns with an error code. However, by turning on this parameter
MOSEK will wait for an available license.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Overall solver , Optimization system, License manager
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.log
Controls the amount of log information. The value 0 implies that all log information is suppressed.
A higher level implies that more information is logged.
Please note that if a task is employed to solve a sequence of optimization problems the value of
this parameter is reduced by the value of iparam.log_cut_second_opt for the second and any
subsequent optimizations.
Accepted Values: [0 ;+inf ]
Default Value: 10
Groups: Output information, Logging
iparam.log_ana_pro
Controls amount of output from the problem analyzer.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Analysis, Logging
iparam.log_bi
Controls the amount of output printed by the basis identification procedure. A higher level implies
that more information is logged.
Accepted Values: [0 ;+inf ]
Default Value: 4
Groups: Basis identification, Output information, Logging
iparam.log_bi_freq
Controls how frequent the optimizer outputs information about the basis identification and how
frequent the user-defined call-back function is called.
Accepted Values: [0 ;+inf ]
Default Value: 2500
Groups: Basis identification, Output information, Logging
iparam.log_check_convexity
Controls logging in convexity check on quadratic problems. Set to a positive value to turn logging
on. If a quadratic coefficient matrix is found to violate the requirement of PSD (NSD) then a list
of negative (positive) pivot elements is printed. The absolute value of the pivot elements is also
shown.
Accepted Values: [0 ;+inf ]
Default Value: 0
Groups: Data check , Nonlinear convex method
iparam.log_cut_second_opt
If a task is employed to solve a sequence of optimization problems, then the value of the log levels
is reduced by the value of this parameter. E.g iparam.log and iparam.log_sim are reduced by
the value of this parameter for the second and any subsequent optimizations.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_expand
Controls the amount of logging when a data item such as the maximum number constrains is
expanded.
Accepted Values: [0 ;+inf ]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Default Value: 0
Groups: Output information, Logging
iparam.log_factor
If turned on, then the factor log lines are added to the log.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_feas_repair
Controls the amount of output printed when performing feasibility repair. A value higher than one
means extensive logging.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_file
If turned on, then some log info is printed when a file is written or read.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Data input/output, Output information, Logging
iparam.log_head
If turned on, then a header line is added to the log.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_infeas_ana
Controls amount of output printed by the infeasibility analyzer procedures. A higher level implies
that more information is logged.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Infeasibility report, Output information, Logging
iparam.log_intpnt
Controls amount of output printed by the interior-point optimizer. A higher level implies that
more information is logged.
Accepted Values: [0 ;+inf ]
Default Value: 4
Groups: Interior-point method , Output information, Logging
iparam.log_mio
Controls the log level for the mixed-integer optimizer. A higher level implies that more information
is logged.
Accepted Values: [0 ;+inf ]
Default Value: 4
Groups: Mixed-integer optimization, Output information, Logging
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.log_mio_freq
Controls how frequent the mixed-integer optimizer prints the log line. It will print line every time
iparam.log_mio_freq relaxations have been solved.
Accepted Values: [-inf ;+inf ]
Default Value: 10
Groups: Mixed-integer optimization, Output information, Logging
iparam.log_optimizer
Controls the amount of general optimizer information that is logged.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_order
If turned on, then factor lines are added to the log.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_presolve
Controls amount of output printed by the presolve procedure. A higher level implies that more
information is logged.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Interior-point method , Logging
iparam.log_response
Controls amount of output printed when response codes are reported. A higher level implies that
more information is logged.
Accepted Values: [0 ;+inf ]
Default Value: 0
Groups: Output information, Logging
iparam.log_sensitivity
Controls the amount of logging during the sensitivity analysis.
0.Means no logging information is produced.
1.Timing information is printed.
2.Sensitivity results are printed.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Output information, Logging
iparam.log_sensitivity_opt
Controls the amount of logging from the optimizers employed during the sensitivity analysis. 0
means no logging information is produced.
Accepted Values: [0 ;+inf ]
Default Value: 0
Groups: Output information, Logging
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.log_sim
Controls amount of output printed by the simplex optimizer. A higher level implies that more
information is logged.
Accepted Values: [0 ;+inf ]
Default Value: 4
Groups: Simplex optimizer , Output information, Logging
iparam.log_sim_freq
Controls how frequent the simplex optimizer outputs information about the optimization and how
frequent the user-defined call-back function is called.
Accepted Values: [0 ;+inf ]
Default Value: 1000
Groups: Simplex optimizer , Output information, Logging
iparam.log_sim_minor
Currently not in use.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Simplex optimizer , Output information
iparam.log_storage
When turned on, MOSEK prints messages regarding the storage usage and allocation.
Accepted Values: [0 ;+inf ]
Default Value: 0
Groups: Output information, Optimization system, Logging
iparam.max_num_warnings
Each warning is shown a limit number times controlled by this parameter. A negative value is
identical to infinite number of times.
Accepted Values: [-inf ;+inf ]
Default Value: 10
Groups: Output information
iparam.mio_branch_dir
Controls whether the mixed-integer optimizer is branching up or down by default.
Accepted Values: branchdir
Default Value: branchdir.free
Groups: Mixed-integer optimization
iparam.mio_construct_sol
If set to onoffkey.on and all integer variables have been given a value for which a feasible mixed
integer solution exists, then MOSEK generates an initial solution to the mixed integer problem
by fixing all integer values and solving the remaining problem.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Mixed-integer optimization
iparam.mio_cut_clique
Controls whether clique cuts should be generated.
Accepted Values: onoffkey
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Default Value: -1
Groups: Mixed-integer optimization, Termination criterion
iparam.mio_max_num_relaxs
Maximum number of relaxations allowed during the branch and bound search. A negative value
means infinite.
Accepted Values: [-inf ;+inf ]
Default Value: -1
Groups: Mixed-integer optimization
iparam.mio_max_num_solutions
The mixed-integer optimizer can be terminated after a certain number of different feasible solutions
has been located. If this parameter has the value 𝑛 > 0, then the mixed-integer optimizer will be
terminated when 𝑛 feasible solutions have been located.
Accepted Values: [-inf ;+inf ]
Default Value: -1
Groups: Mixed-integer optimization, Termination criterion
iparam.mio_mode
Controls whether the optimizer includes the integer restrictions when solving a (mixed) integer
optimization problem.
Accepted Values: miomode
Default Value: miomode.satisfied
Groups: Overall solver
iparam.mio_mt_user_cb
It true user callbacks are called from each thread used by this optimizer. If false the user callback
is only called from a single thread.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Optimization system
iparam.mio_node_optimizer
Controls which optimizer is employed at the non-root nodes in the mixed-integer optimizer.
Accepted Values: optimizertype
Default Value: optimizertype.free
Groups: Mixed-integer optimization
iparam.mio_node_selection
Controls the node selection strategy employed by the mixed-integer optimizer.
Accepted Values: mionodeseltype
Default Value: mionodeseltype.free
Groups: Mixed-integer optimization
iparam.mio_perspective_reformulate
Enables or disables perspective reformulation in presolve.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Mixed-integer optimization
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.mio_probing_level
Controls the amount of probing employed by the mixed-integer optimizer in presolve.
-1. The optimizer chooses the level of probing employed
0.Probing is disabled
1.A low amount of probing is employed
2.A medium amount of probing is employed
3.A high amount of probing is employed
Accepted Values: [-inf ;+inf ]
Default Value: -1
Groups: Mixed-integer optimization
iparam.mio_rins_max_nodes
Controls the maximum number of nodes allowed in each call to the RINS heuristic. The default
value of -1 means that the value is determined automatically. A value of zero turns off the heuristic.
Accepted Values: [-1 ;+inf ]
Default Value: -1
Groups: Mixed-integer optimization
iparam.mio_root_optimizer
Controls which optimizer is employed at the root node in the mixed-integer optimizer.
Accepted Values: optimizertype
Default Value: optimizertype.free
Groups: Mixed-integer optimization
iparam.mio_root_repeat_presolve_level
Controls whether presolve can be repeated at root node.
•-1 The optimizer chooses whether presolve is repeated
•0 Never repeat presolve
•1 Always repeat presolve
Accepted Values: [-1 ;1 ]
Default Value: -1
Groups: Mixed-integer optimization
iparam.mio_vb_detection_level
Controls how much effort is put into detecting variable bounds.
-1. The optimizer chooses
0.No variable bounds are detected
1.Only detect variable bounds that are directly represented in the problem
2.Detect variable bounds in probing
Accepted Values: [-1 ;+2 ]
Default Value: -1
Groups: Mixed-integer optimization
iparam.mt_spincount
Set the number of iterations to spin before sleeping.
Accepted Values: [0 ;1000000000 ]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Default Value: 0
Groups: Optimization system
iparam.num_threads
Controls the number of threads employed by the optimizer. If set to 0 the number of threads used
will be equal to the number of cores detected on the machine.
Accepted Values: [0 ;+inf ]
Default Value: 0
Groups: Optimization system
iparam.opf_max_terms_per_line
The maximum number of terms (linear and quadratic) per line when an OPF file is written.
Accepted Values: [0 ;+inf ]
Default Value: 5
Groups: Data input/output
iparam.opf_write_header
Write a text header with date and MOSEK version in an OPF file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
iparam.opf_write_hints
Write a hint section with problem dimensions in the beginning of an OPF file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
iparam.opf_write_parameters
Write a parameter section in an OPF file.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Data input/output
iparam.opf_write_problem
Write objective, constraints, bounds etc. to an OPF file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
iparam.opf_write_solutions
Enable inclusion of solutions in the OPF files.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Data input/output
iparam.opf_write_sol_bas
If iparam.opf_write_solutions is onoffkey.on and a basic solution is defined, include the basic
solution in OPF files.
Accepted Values: onoffkey
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Default Value: -1
Groups: Overall solver , Presolve
iparam.presolve_lindep_abs_work_trh
The linear dependency check is potentially computationally expensive.
Accepted Values: [-inf ;+inf ]
Default Value: 100
Groups: Presolve
iparam.presolve_lindep_rel_work_trh
The linear dependency check is potentially computationally expensive.
Accepted Values: [-inf ;+inf ]
Default Value: 100
Groups: Presolve
iparam.presolve_lindep_use
Controls whether the linear constraints are checked for linear dependencies.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Presolve
iparam.presolve_max_num_reductions
Controls the maximum number of reductions performed by the presolve. The value of the parameter
is normally only changed in connection with debugging. A negative value implies that an infinite
number of reductions are allowed.
Accepted Values: [-inf ;+inf ]
Default Value: -1
iparam.presolve_use
Controls whether the presolve is applied to a problem before it is optimized.
Accepted Values: presolvemode
Default Value: presolvemode.free
Groups: Overall solver , Presolve
iparam.primal_repair_optimizer
Controls which optimizer that is used to find the optimal repair.
Accepted Values: optimizertype
Default Value: optimizertype.free
Groups: Overall solver
iparam.read_data_compressed
If this option is turned on,it is assumed that the data file is compressed.
Accepted Values: compresstype
Default Value: compresstype.free
Groups: Data input/output
iparam.read_data_format
Format of the data file to be read.
Accepted Values: dataformat
Default Value: dataformat.extension
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.sim_primal_crash
Controls whether crashing is performed in the primal simplex optimizer.
In general, if a basis consists of more than (100-this parameter value)% fixed variables, then a crash
will be performed.
Accepted Values: [0 ;+inf ]
Default Value: 90
Groups: Primal simplex optimizer
iparam.sim_primal_phaseone_method
An experimental feature.
Accepted Values: [0 ;10 ]
Default Value: 0
Groups: Simplex optimizer
iparam.sim_primal_restrict_selection
The primal simplex optimizer can use a so-called restricted selection/pricing strategy to chooses
the outgoing variable. Hence, if restricted selection is applied, then the primal simplex optimizer
first choose a subset of all the potential incoming variables. Next, for some time it will choose the
incoming variable only among the subset. From time to time the subset is redefined.
A larger value of this parameter implies that the optimizer will be more aggressive in its restriction
strategy, i.e. a value of 0 implies that the restriction strategy is not applied at all.
Accepted Values: [0 ;100 ]
Default Value: 50
Groups: Primal simplex optimizer
iparam.sim_primal_selection
Controls the choice of the incoming variable, known as the selection strategy, in the primal simplex
optimizer.
Accepted Values: simseltype
Default Value: simseltype.free
Groups: Primal simplex optimizer
iparam.sim_refactor_freq
Controls how frequent the basis is refactorized. The value 0 means that the optimizer determines
the best point of refactorization.
It is strongly recommended NOT to change this parameter.
Accepted Values: [0 ;+inf ]
Default Value: 0
Groups: Simplex optimizer
iparam.sim_reformulation
Controls if the simplex optimizers are allowed to reformulate the problem.
Accepted Values: simreform
Default Value: simreform.off
Groups: Simplex optimizer
iparam.sim_save_lu
Controls if the LU factorization stored should be replaced with the LU factorization corresponding
to the initial basis.
Accepted Values: onoffkey
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.sol_filter_keep_ranged
If turned on, then ranged constraints and variables are written to the solution file independent of
the filter setting.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Solution input/output
iparam.sol_read_name_width
When a solution is read by MOSEK and some constraint, variable or cone names contain blanks,
then a maximum name width much be specified. A negative value implies that no name contain
blanks.
Accepted Values: [-inf ;+inf ]
Default Value: -1
Groups: Data input/output, Solution input/output
iparam.sol_read_width
Controls the maximal acceptable width of line in the solutions when read by MOSEK.
Accepted Values: [0 ;+inf ]
Default Value: 1024
Groups: Data input/output, Solution input/output
iparam.timing_level
Controls the a amount of timing performed inside MOSEK.
Accepted Values: [0 ;+inf ]
Default Value: 1
Groups: Optimization system
iparam.write_bas_constraints
Controls whether the constraint section is written to the basic solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_bas_head
Controls whether the header section is written to the basic solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_bas_variables
Controls whether the variables section is written to the basic solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_data_compressed
Controls whether the data file is compressed while it is written. 0 means no compression while
higher values mean more compression.
Accepted Values: [0 ;+inf ]
Default Value: 0
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.write_int_variables
Controls whether the variables section is written to the integer solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_lp_full_obj
Write all variables, including the ones with 0-coefficients, in the objective.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
iparam.write_lp_line_width
Maximum width of line in an LP file written by MOSEK.
Accepted Values: [40 ;+inf ]
Default Value: 80
Groups: Data input/output
iparam.write_lp_quoted_names
If this option is turned on, then MOSEK will quote invalid LP names when writing an LP file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
iparam.write_lp_strict_format
Controls whether LP output files satisfy the LP format strictly.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Data input/output
iparam.write_lp_terms_per_line
Maximum number of terms on a single line in an LP file written by MOSEK. 0 means unlimited.
Accepted Values: [0 ;+inf ]
Default Value: 10
Groups: Data input/output
iparam.write_mps_format
Controls in which format the MPS is written.
Accepted Values: mpsformat
Default Value: mpsformat.free
Groups: Data input/output
iparam.write_mps_int
Controls if marker records are written to the MPS file to indicate whether variables are integer
restricted.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iparam.write_precision
Controls the precision with which double numbers are printed in the MPS data file. In general it
is not worthwhile to use a value higher than 15.
Accepted Values: [0 ;+inf ]
Default Value: 15
Groups: Data input/output
iparam.write_sol_barvariables
Controls whether the symmetric matrix variables section is written to the solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_sol_constraints
Controls whether the constraint section is written to the solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_sol_head
Controls whether the header section is written to the solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_sol_ignore_invalid_names
Even if the names are invalid MPS names, then they are employed when writing the solution file.
Accepted Values: onoffkey
Default Value: onoffkey.off
Groups: Data input/output, Solution input/output
iparam.write_sol_variables
Controls whether the variables section is written to the solution file.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output, Solution input/output
iparam.write_task_inc_sol
Controls whether the solutions are stored in the task file too.
Accepted Values: onoffkey
Default Value: onoffkey.on
Groups: Data input/output
iparam.write_xml_mode
Controls if linear coefficients should be written by row or column when writing in the XML file
format.
Accepted Values: xmlwriteroutputtype
Default Value: xmlwriteroutputtype.row
Groups: Data input/output
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
String Parameters
sparam.bas_sol_file_name
Name of the bas solution file.
Accepted Values: Any valid file name.
Groups: Data input/output, Solution input/output
sparam.data_file_name
Data are read and written to this file.
Accepted Values: Any valid file name.
Groups: Data input/output
sparam.debug_file_name
MOSEK debug file.
Accepted Values: Any valid file name.
Groups: Data input/output
sparam.int_sol_file_name
Name of the int solution file.
Accepted Values: Any valid file name.
Groups: Data input/output, Solution input/output
sparam.itr_sol_file_name
Name of the itr solution file.
Accepted Values: Any valid file name.
Groups: Data input/output, Solution input/output
sparam.mio_debug_string
For internal use only.
Accepted Values: Any valid string.
Groups: Data input/output
sparam.param_comment_sign
Only the first character in this string is used. It is considered as a start of comment sign in the
MOSEK parameter file. Spaces are ignored in the string.
Accepted Values: Any valid string.
Default Value: %%
Groups: Data input/output
sparam.param_read_file_name
Modifications to the parameter database is read from this file.
Accepted Values: Any valid file name.
Groups: Data input/output
sparam.param_write_file_name
The parameter database is written to this file.
Accepted Values: Any valid file name.
Groups: Data input/output
sparam.read_mps_bou_name
Name of the BOUNDS vector used. An empty name means that the first BOUNDS vector is used.
Accepted Values: Any valid MPS name.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
sparam.sol_filter_xx_upr
A filter used to determine which variables should be listed in the solution file. A value of “0.5”
means that all constraints having xx[j]<0.5 should be printed, whereas “-0.5” means all constraints
having xx[j]<=bux[j]-0.5 should be listed. An empty filter means no filter is applied.
Accepted Values: Any valid file name.
Groups: Data input/output, Solution input/output
sparam.stat_file_name
Statistics file name.
Accepted Values: Any valid file name.
Groups: Data input/output
sparam.stat_key
Key used when writing the summary file.
Accepted Values: Any valid XML string.
Groups: Data input/output
sparam.stat_name
Name used when writing the statistics file.
Accepted Values: Any valid XML string.
Groups: Data input/output
sparam.write_lp_gen_var_name
Sometimes when an LP file is written additional variables must be inserted. They will have the
prefix denoted by this parameter.
Accepted Values: Any valid string.
Default Value: xmskgen
Groups: Data input/output
• iparam.bi_clean_optimizer
• iparam.infeas_prefer_primal
• iparam.license_wait
• iparam.mio_mode
• iparam.optimizer
• iparam.presolve_level
• iparam.presolve_use
• iparam.primal_repair_optimizer
• iparam.sensitivity_all
• iparam.sensitivity_optimizer
• iparam.sensitivity_type
• iparam.solution_callback
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.log_mio
• iparam.log_mio_freq
• iparam.mio_branch_dir
• iparam.mio_construct_sol
• iparam.mio_cut_clique
• iparam.mio_cut_cmir
• iparam.mio_cut_gmi
• iparam.mio_cut_implied_bound
• iparam.mio_cut_knapsack_cover
• iparam.mio_cut_selection_level
• dparam.mio_disable_term_time
• iparam.mio_heuristic_level
• iparam.mio_max_num_branches
• iparam.mio_max_num_relaxs
• iparam.mio_max_num_solutions
• dparam.mio_max_time
• dparam.mio_near_tol_abs_gap
• dparam.mio_near_tol_rel_gap
• iparam.mio_node_optimizer
• iparam.mio_node_selection
• iparam.mio_perspective_reformulate
• iparam.mio_probing_level
• dparam.mio_rel_gap_const
• iparam.mio_rins_max_nodes
• iparam.mio_root_optimizer
• iparam.mio_root_repeat_presolve_level
• dparam.mio_tol_abs_gap
• dparam.mio_tol_abs_relax_int
• dparam.mio_tol_feas
• dparam.mio_tol_rel_dual_bound_improvement
• dparam.mio_tol_rel_gap
• iparam.mio_vb_detection_level
• iparam.infeas_report_level
• iparam.license_suppress_expire_wrns
• iparam.log
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.log_bi
• iparam.log_bi_freq
• iparam.log_cut_second_opt
• iparam.log_expand
• iparam.log_factor
• iparam.log_feas_repair
• iparam.log_file
• iparam.log_head
• iparam.log_infeas_ana
• iparam.log_intpnt
• iparam.log_mio
• iparam.log_mio_freq
• iparam.log_optimizer
• iparam.log_order
• iparam.log_response
• iparam.log_sensitivity
• iparam.log_sensitivity_opt
• iparam.log_sim
• iparam.log_sim_freq
• iparam.log_sim_minor
• iparam.log_storage
• iparam.max_num_warnings
• iparam.auto_update_sol_info
• iparam.intpnt_multi_thread
• iparam.license_wait
• iparam.log_storage
• iparam.mio_mt_user_cb
• iparam.mt_spincount
• iparam.num_threads
• iparam.timing_level
• dparam.basis_rel_tol_s
• iparam.basis_solve_use_plus_one
• dparam.basis_tol_s
• dparam.basis_tol_x
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.log_sim
• iparam.log_sim_freq
• iparam.log_sim_minor
• iparam.sensitivity_optimizer
• iparam.sim_basis_factor_use
• iparam.sim_degen
• iparam.sim_dual_phaseone_method
• iparam.sim_exploit_dupvec
• iparam.sim_hotstart
• iparam.sim_integer
• dparam.sim_lu_tol_rel_piv
• iparam.sim_max_iterations
• iparam.sim_max_num_setbacks
• iparam.sim_non_singular
• iparam.sim_primal_phaseone_method
• iparam.sim_refactor_freq
• iparam.sim_reformulation
• iparam.sim_save_lu
• iparam.sim_scaling
• iparam.sim_scaling_method
• iparam.sim_solve_form
• iparam.sim_stability_priority
• iparam.sim_switch_optimizer
• dparam.simplex_abs_tol_piv
• iparam.log
• iparam.log_ana_pro
• iparam.log_bi
• iparam.log_bi_freq
• iparam.log_cut_second_opt
• iparam.log_expand
• iparam.log_factor
• iparam.log_feas_repair
• iparam.log_file
• iparam.log_head
• iparam.log_infeas_ana
• iparam.log_intpnt
• iparam.log_mio
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.log_mio_freq
• iparam.log_optimizer
• iparam.log_order
• iparam.log_presolve
• iparam.log_response
• iparam.log_sensitivity
• iparam.log_sensitivity_opt
• iparam.log_sim
• iparam.log_sim_freq
• iparam.log_storage
• iparam.check_convexity
• dparam.data_sym_mat_tol
• dparam.data_sym_mat_tol_huge
• dparam.data_sym_mat_tol_large
• dparam.data_tol_aij
• dparam.data_tol_aij_huge
• dparam.data_tol_aij_large
• dparam.data_tol_bound_inf
• dparam.data_tol_bound_wrn
• dparam.data_tol_c_huge
• dparam.data_tol_cj_large
• dparam.data_tol_qij
• dparam.data_tol_x
• iparam.log_check_convexity
• dparam.semidefinite_tol_approx
• iparam.solution_callback
• iparam.ana_sol_basis
• dparam.ana_sol_infeas_tol
• iparam.ana_sol_print_violated
• iparam.log_ana_pro
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• dparam.intpnt_co_tol_dfeas
• dparam.intpnt_co_tol_infeas
• dparam.intpnt_co_tol_mu_red
• dparam.intpnt_co_tol_near_rel
• dparam.intpnt_co_tol_pfeas
• dparam.intpnt_co_tol_rel_gap
• iparam.check_convexity
• dparam.intpnt_nl_merit_bal
• dparam.intpnt_nl_tol_dfeas
• dparam.intpnt_nl_tol_mu_red
• dparam.intpnt_nl_tol_near_rel
• dparam.intpnt_nl_tol_pfeas
• dparam.intpnt_nl_tol_rel_gap
• dparam.intpnt_nl_tol_rel_step
• dparam.intpnt_tol_infeas
• iparam.log_check_convexity
• sparam.bas_sol_file_name
• iparam.infeas_report_auto
• sparam.int_sol_file_name
• sparam.itr_sol_file_name
• iparam.sol_filter_keep_basic
• iparam.sol_filter_keep_ranged
• sparam.sol_filter_xc_low
• sparam.sol_filter_xc_upr
• sparam.sol_filter_xx_low
• sparam.sol_filter_xx_upr
• iparam.sol_read_name_width
• iparam.sol_read_width
• iparam.write_bas_constraints
• iparam.write_bas_head
• iparam.write_bas_variables
• iparam.write_int_constraints
• iparam.write_int_head
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.write_int_variables
• iparam.write_sol_barvariables
• iparam.write_sol_constraints
• iparam.write_sol_head
• iparam.write_sol_ignore_invalid_names
• iparam.write_sol_variables
• iparam.bi_ignore_max_iter
• iparam.bi_ignore_num_error
• dparam.check_convexity_rel_tol
• iparam.intpnt_basis
• dparam.intpnt_co_tol_dfeas
• dparam.intpnt_co_tol_infeas
• dparam.intpnt_co_tol_mu_red
• dparam.intpnt_co_tol_near_rel
• dparam.intpnt_co_tol_pfeas
• dparam.intpnt_co_tol_rel_gap
• iparam.intpnt_diff_step
• iparam.intpnt_hotstart
• iparam.intpnt_max_iterations
• iparam.intpnt_max_num_cor
• iparam.intpnt_max_num_refinement_steps
• dparam.intpnt_nl_merit_bal
• dparam.intpnt_nl_tol_dfeas
• dparam.intpnt_nl_tol_mu_red
• dparam.intpnt_nl_tol_near_rel
• dparam.intpnt_nl_tol_pfeas
• dparam.intpnt_nl_tol_rel_gap
• dparam.intpnt_nl_tol_rel_step
• iparam.intpnt_off_col_trh
• iparam.intpnt_order_method
• dparam.intpnt_qo_tol_dfeas
• dparam.intpnt_qo_tol_infeas
• dparam.intpnt_qo_tol_mu_red
• dparam.intpnt_qo_tol_near_rel
• dparam.intpnt_qo_tol_pfeas
• dparam.intpnt_qo_tol_rel_gap
• iparam.intpnt_regularization_use
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.intpnt_scaling
• iparam.intpnt_solve_form
• iparam.intpnt_starting_point
• dparam.intpnt_tol_dfeas
• dparam.intpnt_tol_dsafe
• dparam.intpnt_tol_infeas
• dparam.intpnt_tol_mu_red
• dparam.intpnt_tol_path
• dparam.intpnt_tol_pfeas
• dparam.intpnt_tol_psafe
• dparam.intpnt_tol_rel_gap
• dparam.intpnt_tol_rel_step
• dparam.intpnt_tol_step_size
• iparam.log_intpnt
• iparam.log_presolve
• dparam.qcqo_reformulate_rel_drop_tol
• iparam.sim_dual_crash
• iparam.sim_dual_restrict_selection
• iparam.sim_dual_selection
• dparam.basis_rel_tol_s
• dparam.basis_tol_s
• dparam.basis_tol_x
• iparam.bi_max_iterations
• dparam.intpnt_co_tol_dfeas
• dparam.intpnt_co_tol_infeas
• dparam.intpnt_co_tol_mu_red
• dparam.intpnt_co_tol_near_rel
• dparam.intpnt_co_tol_pfeas
• dparam.intpnt_co_tol_rel_gap
• iparam.intpnt_max_iterations
• dparam.intpnt_nl_tol_dfeas
• dparam.intpnt_nl_tol_mu_red
• dparam.intpnt_nl_tol_near_rel
• dparam.intpnt_nl_tol_pfeas
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• dparam.intpnt_nl_tol_rel_gap
• dparam.intpnt_qo_tol_dfeas
• dparam.intpnt_qo_tol_infeas
• dparam.intpnt_qo_tol_mu_red
• dparam.intpnt_qo_tol_near_rel
• dparam.intpnt_qo_tol_pfeas
• dparam.intpnt_qo_tol_rel_gap
• dparam.intpnt_tol_dfeas
• dparam.intpnt_tol_infeas
• dparam.intpnt_tol_mu_red
• dparam.intpnt_tol_pfeas
• dparam.intpnt_tol_rel_gap
• dparam.lower_obj_cut
• dparam.lower_obj_cut_finite_trh
• dparam.mio_disable_term_time
• iparam.mio_max_num_branches
• iparam.mio_max_num_solutions
• dparam.mio_max_time
• dparam.mio_near_tol_rel_gap
• dparam.mio_rel_gap_const
• dparam.mio_tol_rel_gap
• dparam.optimizer_max_time
• iparam.sim_max_iterations
• dparam.upper_obj_cut
• dparam.upper_obj_cut_finite_trh
• iparam.sim_primal_crash
• iparam.sim_primal_restrict_selection
• iparam.sim_primal_selection
• iparam.bi_clean_optimizer
• iparam.bi_ignore_max_iter
• iparam.bi_ignore_num_error
• iparam.bi_max_iterations
• iparam.intpnt_basis
• iparam.log_bi
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.log_bi_freq
• dparam.sim_lu_tol_rel_piv
• iparam.cache_license
• iparam.license_debug
• iparam.license_pause_time
• iparam.license_suppress_expire_wrns
• iparam.license_wait
• iparam.presolve_eliminator_max_fill
• iparam.presolve_eliminator_max_num_tries
• iparam.presolve_level
• iparam.presolve_lindep_abs_work_trh
• iparam.presolve_lindep_rel_work_trh
• iparam.presolve_lindep_use
• dparam.presolve_tol_abs_lindep
• dparam.presolve_tol_aij
• dparam.presolve_tol_rel_lindep
• dparam.presolve_tol_s
• dparam.presolve_tol_x
• iparam.presolve_use
• iparam.auto_sort_a_before_opt
• sparam.bas_sol_file_name
• sparam.data_file_name
• sparam.debug_file_name
• iparam.infeas_report_auto
• sparam.int_sol_file_name
• sparam.itr_sol_file_name
• iparam.log_file
• sparam.mio_debug_string
• iparam.opf_max_terms_per_line
• iparam.opf_write_header
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.opf_write_hints
• iparam.opf_write_parameters
• iparam.opf_write_problem
• iparam.opf_write_sol_bas
• iparam.opf_write_sol_itg
• iparam.opf_write_sol_itr
• iparam.opf_write_solutions
• sparam.param_comment_sign
• iparam.param_read_case_name
• sparam.param_read_file_name
• iparam.param_read_ign_error
• sparam.param_write_file_name
• iparam.read_data_compressed
• iparam.read_data_format
• iparam.read_debug
• iparam.read_keep_free_con
• iparam.read_lp_drop_new_vars_in_bou
• iparam.read_lp_quoted_names
• sparam.read_mps_bou_name
• iparam.read_mps_format
• sparam.read_mps_obj_name
• sparam.read_mps_ran_name
• sparam.read_mps_rhs_name
• iparam.read_mps_width
• iparam.read_task_ignore_param
• sparam.sensitivity_file_name
• sparam.sensitivity_res_file_name
• sparam.sol_filter_xc_low
• sparam.sol_filter_xc_upr
• sparam.sol_filter_xx_low
• sparam.sol_filter_xx_upr
• iparam.sol_read_name_width
• iparam.sol_read_width
• sparam.stat_file_name
• sparam.stat_key
• sparam.stat_name
• iparam.write_bas_constraints
• iparam.write_bas_head
• iparam.write_bas_variables
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.write_data_compressed
• iparam.write_data_format
• iparam.write_data_param
• iparam.write_free_con
• iparam.write_generic_names
• iparam.write_generic_names_io
• iparam.write_ignore_incompatible_items
• iparam.write_int_constraints
• iparam.write_int_head
• iparam.write_int_variables
• iparam.write_lp_full_obj
• sparam.write_lp_gen_var_name
• iparam.write_lp_line_width
• iparam.write_lp_quoted_names
• iparam.write_lp_strict_format
• iparam.write_lp_terms_per_line
• iparam.write_mps_format
• iparam.write_mps_int
• iparam.write_precision
• iparam.write_sol_barvariables
• iparam.write_sol_constraints
• iparam.write_sol_head
• iparam.write_sol_ignore_invalid_names
• iparam.write_sol_variables
• iparam.write_task_inc_sol
• iparam.write_xml_mode
• iparam.infeas_generic_names
• iparam.infeas_report_level
• iparam.log_infeas_ana
• Termination codes
• Error codes
• Warning codes
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.ok (0)
No error occurred.
rescode.trm_internal (10030)
The optimizer terminated due to some internal reason. Please contact MOSEK support.
rescode.trm_internal_stop (10031)
The optimizer terminated for internal reasons. Please contact MOSEK support.
rescode.trm_max_iterations (10000)
The optimizer terminated at the maximum number of iterations.
rescode.trm_max_num_setbacks (10020)
The optimizer terminated as the maximum number of set-backs was reached. This indicates %
serious numerical problems and a possibly badly formulated problem.
rescode.trm_max_time (10001)
The optimizer terminated at the maximum amount of time.
rescode.trm_mio_near_abs_gap (10004)
The mixed-integer optimizer terminated because the near optimal absolute gap tolerance was sat-
isfied.
rescode.trm_mio_near_rel_gap (10003)
The mixed-integer optimizer terminated because the near optimal relative gap tolerance was sat-
isfied.
rescode.trm_mio_num_branches (10009)
The mixed-integer optimizer terminated as to the maximum number of branches was reached.
rescode.trm_mio_num_relaxs (10008)
The mixed-integer optimizer terminated as the maximum number of relaxations was reached.
rescode.trm_num_max_num_int_solutions (10015)
The mixed-integer optimizer terminated as the maximum number of feasible solutions was reached.
rescode.trm_numerical_problem (10025)
The optimizer terminated due to numerical problems.
rescode.trm_objective_range (10002)
The optimizer terminated on the bound of the objective range.
rescode.trm_stall (10006)
The optimizer is terminated due to slow progress.
Stalling means that numerical problems prevent the optimizer from making reasonable progress
and that it make no sense to continue. In many cases this happens if the problem is badly scaled
or otherwise ill-conditioned. There is no guarantee that the solution will be (near) feasible or near
optimal. However, often stalling happens near the optimum, and the returned solution may be of
good quality. Therefore, it is recommended to check the status of then solution. If the solution
near optimal the solution is most likely good enough for most practical purposes.
Please note that if a linear optimization problem is solved using the interior-point optimizer with
basis identification turned on, the returned basic solution likely to have high accuracy, even though
the optimizer stalled.
Some common causes of stalling are a) badly scaled models, b) near feasible or near infeasible
problems and c) a non-convex problems. Case c) is only relevant for general non-linear problems.
It is not possible in general for MOSEK to check if a specific problems is convex since such a
check would be NP hard in itself. This implies that care should be taken when solving problems
involving general user defined functions.
rescode.trm_user_callback (10007)
The optimizer terminated due to the return of the user-defined call-back function.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_ad_invalid_codelist (3102)
The code list data was invalid.
rescode.err_api_array_too_small (3001)
An input array was too short.
rescode.err_api_cb_connect (3002)
Failed to connect a callback object.
rescode.err_api_fatal_error (3005)
An internal error occurred in the API. Please report this problem.
rescode.err_api_internal (3999)
An internal fatal error occurred in an interface function.
rescode.err_arg_is_too_large (1227)
The value of a argument is too small.
rescode.err_arg_is_too_small (1226)
The value of a argument is too small.
rescode.err_argument_dimension (1201)
A function argument is of incorrect dimension.
rescode.err_argument_is_too_large (5005)
The value of a function argument is too large.
rescode.err_argument_lenneq (1197)
Incorrect length of arguments.
rescode.err_argument_perm_array (1299)
An invalid permutation array is specified.
rescode.err_argument_type (1198)
Incorrect argument type.
rescode.err_bar_var_dim (3920)
The dimension of a symmetric matrix variable has to greater than 0.
rescode.err_basis (1266)
An invalid basis is specified. Either too many or too few basis variables are specified.
rescode.err_basis_factor (1610)
The factorization of the basis is invalid.
rescode.err_basis_singular (1615)
The basis is singular and hence cannot be factored.
rescode.err_blank_name (1070)
An all blank name has been specified.
rescode.err_cannot_clone_nl (2505)
A task with a nonlinear function call-back cannot be cloned.
rescode.err_cannot_handle_nl (2506)
A function cannot handle a task with nonlinear function call-backs.
rescode.err_cbf_duplicate_acoord (7116)
Duplicate index in ACOORD.
rescode.err_cbf_duplicate_bcoord (7115)
Duplicate index in BCOORD.
rescode.err_cbf_duplicate_con (7108)
Duplicate CON keyword.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_cbf_duplicate_int (7110)
Duplicate INT keyword.
rescode.err_cbf_duplicate_obj (7107)
Duplicate OBJ keyword.
rescode.err_cbf_duplicate_objacoord (7114)
Duplicate index in OBJCOORD.
rescode.err_cbf_duplicate_var (7109)
Duplicate VAR keyword.
rescode.err_cbf_invalid_con_type (7112)
Invalid constraint type.
rescode.err_cbf_invalid_domain_dimension (7113)
Invalid domain dimension.
rescode.err_cbf_invalid_int_index (7121)
Invalid INT index.
rescode.err_cbf_invalid_var_type (7111)
Invalid variable type.
rescode.err_cbf_no_variables (7102)
No variables are specified.
rescode.err_cbf_no_version_specified (7105)
No version specified.
rescode.err_cbf_obj_sense (7101)
An invalid objective sense is specified.
rescode.err_cbf_parse (7100)
An error occurred while parsing an CBF file.
rescode.err_cbf_syntax (7106)
Invalid syntax.
rescode.err_cbf_too_few_constraints (7118)
Too few constraints defined.
rescode.err_cbf_too_few_ints (7119)
Too few ints are specified.
rescode.err_cbf_too_few_variables (7117)
Too few variables defined.
rescode.err_cbf_too_many_constraints (7103)
Too many constraints specified.
rescode.err_cbf_too_many_ints (7120)
Too many ints are specified.
rescode.err_cbf_too_many_variables (7104)
Too many variables specified.
rescode.err_cbf_unsupported (7122)
Unsupported feature is present.
rescode.err_con_q_not_nsd (1294)
The quadratic constraint matrix is not negative semidefinite as expected for a con-
straint with finite lower bound. This results in a nonconvex problem. The parameter
dparam.check_convexity_rel_tol can be used to relax the convexity check.
rescode.err_con_q_not_psd (1293)
The quadratic constraint matrix is not positive semidefinite as expected for a con-
straint with finite upper bound. This results in a nonconvex problem. The parameter
dparam.check_convexity_rel_tol can be used to relax the convexity check.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_cone_index (1300)
An index of a non-existing cone has been specified.
rescode.err_cone_overlap (1302)
One or more of the variables in the cone to be added is already member of another cone. Now
assume the variable is 𝑥𝑗 then add a new variable say 𝑥𝑘 and the constraint
𝑥𝑗 = 𝑥𝑘
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_file_read (1053)
File read error.
rescode.err_file_write (1054)
File write error.
rescode.err_first (1261)
Invalid first.
rescode.err_firsti (1285)
Invalid firsti.
rescode.err_firstj (1287)
Invalid firstj.
rescode.err_fixed_bound_values (1425)
A fixed constraint/variable has been specified using the bound keys but the numerical value of the
lower and upper bound is different.
rescode.err_flexlm (1014)
The FLEXlm license manager reported an error.
rescode.err_global_inv_conic_problem (1503)
The global optimizer can only be applied to problems without semidefinite variables.
rescode.err_huge_aij (1380)
A numerically huge value is specified for an 𝑎𝑖,𝑗 element in 𝐴. The parameter
dparam.data_tol_aij_huge controls when an 𝑎𝑖,𝑗 is considered huge.
rescode.err_huge_c (1375)
A huge value in absolute size is specified for one 𝑐𝑗 .
rescode.err_identical_tasks (3101)
Some tasks related to this function call were identical. Unique tasks were expected.
rescode.err_in_argument (1200)
A function argument is incorrect.
rescode.err_index (1235)
An index is out of range.
rescode.err_index_arr_is_too_large (1222)
An index in an array argument is too large.
rescode.err_index_arr_is_too_small (1221)
An index in an array argument is too small.
rescode.err_index_is_too_large (1204)
An index in an argument is too large.
rescode.err_index_is_too_small (1203)
An index in an argument is too small.
rescode.err_inf_dou_index (1219)
A double information index is out of range for the specified type.
rescode.err_inf_dou_name (1230)
A double information name is invalid.
rescode.err_inf_int_index (1220)
An integer information index is out of range for the specified type.
rescode.err_inf_int_name (1231)
An integer information name is invalid.
rescode.err_inf_lint_index (1225)
A long integer information index is out of range for the specified type.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_inf_lint_name (1234)
A long integer information name is invalid.
rescode.err_inf_type (1232)
The information type is invalid.
rescode.err_infeas_undefined (3910)
The requested value is not defined for this solution type.
rescode.err_infinite_bound (1400)
A numerically huge bound value is specified.
rescode.err_int64_to_int32_cast (3800)
An 32 bit integer could not cast to a 64 bit integer.
rescode.err_internal (3000)
An internal error occurred. Please report this problem.
rescode.err_internal_test_failed (3500)
An internal unit test function failed.
rescode.err_inv_aptre (1253)
aptre[j] is strictly smaller than aptrb[j] for some j.
rescode.err_inv_bk (1255)
Invalid bound key.
rescode.err_inv_bkc (1256)
Invalid bound key is specified for a constraint.
rescode.err_inv_bkx (1257)
An invalid bound key is specified for a variable.
rescode.err_inv_cone_type (1272)
Invalid cone type code is encountered.
rescode.err_inv_cone_type_str (1271)
Invalid cone type string encountered.
rescode.err_inv_marki (2501)
Invalid value in marki.
rescode.err_inv_markj (2502)
Invalid value in markj.
rescode.err_inv_name_item (1280)
An invalid name item code is used.
rescode.err_inv_numi (2503)
Invalid numi.
rescode.err_inv_numj (2504)
Invalid numj.
rescode.err_inv_optimizer (1550)
An invalid optimizer has been chosen for the problem. This means that the simplex or the conic
optimizer is chosen to optimize a nonlinear problem.
rescode.err_inv_problem (1500)
Invalid problem type. Probably a nonconvex problem has been specified.
rescode.err_inv_qcon_subi (1405)
Invalid value in qcsubi.
rescode.err_inv_qcon_subj (1406)
Invalid value in qcsubj.
rescode.err_inv_qcon_subk (1404)
Invalid value in qcsubk.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_inv_qcon_val (1407)
Invalid value in qcval.
rescode.err_inv_qobj_subi (1401)
Invalid value in qosubi.
rescode.err_inv_qobj_subj (1402)
Invalid value in qosubj.
rescode.err_inv_qobj_val (1403)
Invalid value in qoval.
rescode.err_inv_sk (1270)
Invalid status key code.
rescode.err_inv_sk_str (1269)
Invalid status key string encountered.
rescode.err_inv_skc (1267)
Invalid value in skc.
rescode.err_inv_skn (1274)
Invalid value in skn.
rescode.err_inv_skx (1268)
Invalid value in skx.
rescode.err_inv_var_type (1258)
An invalid variable type is specified for a variable.
rescode.err_invalid_accmode (2520)
An invalid access mode is specified.
rescode.err_invalid_aij (1473)
𝑎𝑖,𝑗 contains an invalid floating point value, i.e. a NaN or an infinite value.
rescode.err_invalid_ampl_stub (3700)
Invalid AMPL stub.
rescode.err_invalid_barvar_name (1079)
An invalid symmetric matrix variable name is used.
rescode.err_invalid_compression (1800)
Invalid compression type.
rescode.err_invalid_con_name (1076)
An invalid constraint name is used.
rescode.err_invalid_cone_name (1078)
An invalid cone name is used.
rescode.err_invalid_file_format_for_cones (4005)
The file format does not support a problem with conic constraints.
rescode.err_invalid_file_format_for_general_nl (4010)
The file format does not support a problem with general nonlinear terms.
rescode.err_invalid_file_format_for_sym_mat (4000)
The file format does not support a problem with symmetric matrix variables.
rescode.err_invalid_file_name (1056)
An invalid file name has been specified.
rescode.err_invalid_format_type (1283)
Invalid format type.
rescode.err_invalid_idx (1246)
A specified index is invalid.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_invalid_iomode (1801)
Invalid io mode.
rescode.err_invalid_max_num (1247)
A specified index is invalid.
rescode.err_invalid_name_in_sol_file (1170)
An invalid name occurred in a solution file.
rescode.err_invalid_obj_name (1075)
An invalid objective name is specified.
rescode.err_invalid_objective_sense (1445)
An invalid objective sense is specified.
rescode.err_invalid_problem_type (6000)
An invalid problem type.
rescode.err_invalid_sol_file_name (1057)
An invalid file name has been specified.
rescode.err_invalid_stream (1062)
An invalid stream is referenced.
rescode.err_invalid_surplus (1275)
Invalid surplus.
rescode.err_invalid_sym_mat_dim (3950)
A sparse symmetric matrix of invalid dimension is specified.
rescode.err_invalid_task (1064)
The task is invalid.
rescode.err_invalid_utf8 (2900)
An invalid UTF8 string is encountered.
rescode.err_invalid_var_name (1077)
An invalid variable name is used.
rescode.err_invalid_wchar (2901)
An invalid wchar string is encountered.
rescode.err_invalid_whichsol (1228)
whichsol is invalid.
rescode.err_json_data (1179)
Inconsistent data in JSON Task file
rescode.err_json_format (1178)
Error in an JSON Task file
rescode.err_json_missing_data (1180)
Missing data section in JSON task file.
rescode.err_json_number_overflow (1177)
Invalid number entry - wrong type or value overflow.
rescode.err_json_string (1176)
Error in JSON string.
rescode.err_json_syntax (1175)
Syntax error in an JSON data
rescode.err_last (1262)
Invalid index last. A given index was out of expected range.
rescode.err_lasti (1286)
Invalid lasti.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_lastj (1288)
Invalid lastj.
rescode.err_lau_arg_k (7012)
Invalid argument k.
rescode.err_lau_arg_m (7010)
Invalid argument m.
rescode.err_lau_arg_n (7011)
Invalid argument n.
rescode.err_lau_arg_trans (7018)
Invalid argument trans.
rescode.err_lau_arg_transa (7015)
Invalid argument transa.
rescode.err_lau_arg_transb (7016)
Invalid argument transb.
rescode.err_lau_arg_uplo (7017)
Invalid argument uplo.
rescode.err_lau_invalid_lower_triangular_matrix (7002)
An invalid lower triangular matrix.
rescode.err_lau_invalid_sparse_symmetric_matrix (7019)
An invalid sparse symmetric matrix is specfified. Note only the lower triangular part with no
duplicates is specifed.
rescode.err_lau_not_positive_definite (7001)
A matrix is not positive definite.
rescode.err_lau_singular_matrix (7000)
A matrix is singular.
rescode.err_lau_unknown (7005)
An unknown error.
rescode.err_license (1000)
Invalid license.
rescode.err_license_cannot_allocate (1020)
The license system cannot allocate the memory required.
rescode.err_license_cannot_connect (1021)
MOSEK cannot connect to the license server. Most likely the license server is not up and running.
rescode.err_license_expired (1001)
The license has expired.
rescode.err_license_feature (1018)
A requested feature is not available in the license file(s). Most likely due to an incorrect license
system setup.
rescode.err_license_invalid_hostid (1025)
The host ID specified in the license file does not match the host ID of the computer.
rescode.err_license_max (1016)
Maximum number of licenses is reached.
rescode.
The MOSEKLM license manager daemon is not up and running.
rescode.err_license_no_server_line (1028)
There is no SERVER line in the license file. All non-zero license count features need at least one
SERVER line.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_license_no_server_support (1027)
The license server does not support the requested feature. Possible reasons for this error include:
•The feature has expired.
•The feature’s start date is later than today’s date.
•The version requested is higher than feature’s the highest supported version.
•A corrupted license file.
Try restarting the license and inspect the license server debug file, usually called lmgrd.log.
rescode.err_license_server (1015)
The license server is not responding.
rescode.err_license_server_version (1026)
The version specified in the checkout request is greater than the highest version number the daemon
supports.
rescode.err_license_version (1002)
The license is valid for another version of MOSEK.
rescode.err_link_file_dll (1040)
A file cannot be linked to a stream in the DLL version.
rescode.err_living_tasks (1066)
All tasks associated with an enviroment must be deleted before the environment is deleted. There
are still some undeleted tasks.
rescode.err_lower_bound_is_a_nan (1390)
The lower bound specified is not a number (nan).
rescode.err_lp_dup_slack_name (1152)
The name of the slack variable added to a ranged constraint already exists.
rescode.err_lp_empty (1151)
The problem cannot be written to an LP formatted file.
rescode.err_lp_file_format (1157)
Syntax error in an LP file.
rescode.err_lp_format (1160)
Syntax error in an LP file.
rescode.err_lp_free_constraint (1155)
Free constraints cannot be written in LP file format.
rescode.err_lp_incompatible (1150)
The problem cannot be written to an LP formatted file.
rescode.err_lp_invalid_con_name (1171)
A constraint name is invalid when used in an LP formatted file.
rescode.err_lp_invalid_var_name (1154)
A variable name is invalid when used in an LP formatted file.
rescode.err_lp_write_conic_problem (1163)
The problem contains cones that cannot be written to an LP formatted file.
rescode.err_lp_write_geco_problem (1164)
The problem contains general convex terms that cannot be written to an LP formatted file.
rescode.err_lu_max_num_tries (2800)
Could not compute the LU factors of the matrix within the maximum number of allowed tries.
rescode.err_max_len_is_too_small (1289)
An maximum length that is too small has been specified.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_maxnumbarvar (1242)
The maximum number of semidefinite variables specified is smaller than the number of semidefinite
variables in the task.
rescode.err_maxnumcon (1240)
The maximum number of constraints specified is smaller than the number of constraints in the
task.
rescode.err_maxnumcone (1304)
The value specified for maxnumcone is too small.
rescode.err_maxnumqnz (1243)
The maximum number of non-zeros specified for the 𝑄 matrices is smaller than the number of
non-zeros in the current 𝑄 matrices.
rescode.err_maxnumvar (1241)
The maximum number of variables specified is smaller than the number of variables in the task.
rescode.err_mio_internal (5010)
A fatal error occurred in the mixed integer optimizer. Please contact MOSEK support.
rescode.err_mio_invalid_node_optimizer (7131)
An invalid node optimizer was selected for the problem type.
rescode.err_mio_invalid_root_optimizer (7130)
An invalid root optimizer was selected for the problem type.
rescode.err_mio_no_optimizer (1551)
No optimizer is available for the current class of integer optimization problems.
rescode.err_mio_not_loaded (1553)
The mixed-integer optimizer is not loaded.
rescode.err_missing_license_file (1008)
MOSEK cannot license file or a token server. See the MOSEK installation manual for details.
rescode.err_mixed_conic_and_nl (1501)
The problem contains nonlinear terms conic constraints. The requested operation cannot be applied
to this type of problem.
rescode.err_mps_cone_overlap (1118)
A variable is specified to be a member of several cones.
rescode.err_mps_cone_repeat (1119)
A variable is repeated within the CSECTION.
rescode.err_mps_cone_type (1117)
Invalid cone type specified in a CSECTION.
rescode.err_mps_duplicate_q_element (1121)
Duplicate elements is specfied in a 𝑄 matrix.
rescode.err_mps_file (1100)
An error occurred while reading an MPS file.
rescode.err_mps_inv_bound_key (1108)
An invalid bound key occurred in an MPS file.
rescode.err_mps_inv_con_key (1107)
An invalid constraint key occurred in an MPS file.
rescode.err_mps_inv_field (1101)
A field in the MPS file is invalid. Probably it is too wide.
rescode.err_mps_inv_marker (1102)
An invalid marker has been specified in the MPS file.
rescode.err_mps_inv_sec_name (1109)
An invalid section name occurred in an MPS file.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_mps_inv_sec_order (1115)
The sections in the MPS data file are not in the correct order.
rescode.err_mps_invalid_obj_name (1128)
An invalid objective name is specified.
rescode.err_mps_invalid_objsense (1122)
An invalid objective sense is specified.
rescode.err_mps_mul_con_name (1112)
A constraint name was specified multiple times in the ROWS section.
rescode.err_mps_mul_csec (1116)
Multiple CSECTIONs are given the same name.
rescode.err_mps_mul_qobj (1114)
The Q term in the objective is specified multiple times in the MPS data file.
rescode.err_mps_mul_qsec (1113)
Multiple QSECTIONs are specified for a constraint in the MPS data file.
rescode.err_mps_no_objective (1110)
No objective is defined in an MPS file.
rescode.err_mps_non_symmetric_q (1120)
A non symmetric matrice has been speciefied.
rescode.err_mps_null_con_name (1103)
An empty constraint name is used in an MPS file.
rescode.err_mps_null_var_name (1104)
An empty variable name is used in an MPS file.
rescode.err_mps_splitted_var (1111)
All elements in a column of the 𝐴 matrix must be specified consecutively. Hence, it is illegal to
specify non-zero elements in 𝐴 for variable 1, then for variable 2 and then variable 1 again.
rescode.err_mps_tab_in_field2 (1125)
A tab char occurred in field 2.
rescode.err_mps_tab_in_field3 (1126)
A tab char occurred in field 3.
rescode.err_mps_tab_in_field5 (1127)
A tab char occurred in field 5.
rescode.err_mps_undef_con_name (1105)
An undefined constraint name occurred in an MPS file.
rescode.err_mps_undef_var_name (1106)
An undefined variable name occurred in an MPS file.
rescode.err_mul_a_element (1254)
An element in 𝐴 is defined multiple times.
rescode.err_name_is_null (1760)
The name buffer is a NULL pointer.
rescode.err_name_max_len (1750)
A name is longer than the buffer that is supposed to hold it.
rescode.err_nan_in_blc (1461)
𝑙𝑐 contains an invalid floating point value, i.e. a NaN.
rescode.err_nan_in_blx (1471)
𝑙𝑥 contains an invalid floating point value, i.e. a NaN.
rescode.err_nan_in_buc (1462)
𝑢𝑐 contains an invalid floating point value, i.e. a NaN.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_nan_in_bux (1472)
𝑢𝑥 contains an invalid floating point value, i.e. a NaN.
rescode.err_nan_in_c (1470)
𝑐 contains an invalid floating point value, i.e. a NaN.
rescode.err_nan_in_double_data (1450)
An invalid floating point value was used in some double data.
rescode.err_negative_append (1264)
Cannot append a negative number.
rescode.err_negative_surplus (1263)
Negative surplus.
rescode.err_newer_dll (1036)
The dynamic link library is newer than the specified version.
rescode.err_no_bars_for_solution (3916)
There is no 𝑠¯ available for the solution specified. In particular note there are no 𝑠¯ defined for the
basic and integer solutions.
rescode.err_no_barx_for_solution (3915)
There is no 𝑋 available for the solution specified. In particular note there are no 𝑋 defined for the
basic and integer solutions.
rescode.err_no_basis_sol (1600)
No basic solution is defined.
rescode.err_no_dual_for_itg_sol (2950)
No dual information is available for the integer solution.
rescode.err_no_dual_infeas_cer (2001)
A certificate of infeasibility is not available.
rescode.err_no_init_env (1063)
env is not initialized.
rescode.err_no_optimizer_var_type (1552)
No optimizer is available for this class of optimization problems.
rescode.err_no_primal_infeas_cer (2000)
A certificate of primal infeasibility is not available.
rescode.err_no_snx_for_bas_sol (2953)
𝑠𝑥𝑛 is not available for the basis solution.
rescode.err_no_solution_in_callback (2500)
The required solution is not available.
rescode.err_non_unique_array (5000)
An array does not contain unique elements.
rescode.err_nonconvex (1291)
The optimization problem is nonconvex.
rescode.err_nonlinear_equality (1290)
The model contains a nonlinear equality which defines a nonconvex set.
rescode.err_nonlinear_functions_not_allowed (1428)
An operation that is invalid for problems with nonlinear functions defined has been attempted.
rescode.err_nonlinear_ranged (1292)
Nonlinear constraints with finite lower and upper bound always define a nonconvex feasible set.
rescode.err_nr_arguments (1199)
Incorrect number of function arguments.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_null_env (1060)
env is a NULL pointer.
rescode.err_null_pointer (1065)
An argument to a function is unexpectedly a NULL pointer.
rescode.err_null_task (1061)
task is a NULL pointer.
rescode.err_numconlim (1250)
Maximum number of constraints limit is exceeded.
rescode.err_numvarlim (1251)
Maximum number of variables limit is exceeded.
rescode.err_obj_q_not_nsd (1296)
The quadratic coefficient matrix in the objective is not negative semidefinite as expected for a
maximization problem. The parameter dparam.check_convexity_rel_tol can be used to relax
the convexity check.
rescode.err_obj_q_not_psd (1295)
The quadratic coefficient matrix in the objective is not positive semidefinite as expected for a
minimization problem. The parameter dparam.check_convexity_rel_tol can be used to relax
the convexity check.
rescode.err_objective_range (1260)
Empty objective range.
rescode.err_older_dll (1035)
The dynamic link library is older than the specified version.
rescode.err_open_dl (1030)
A dynamic link library could not be opened.
rescode.err_opf_format (1168)
Syntax error in an OPF file
rescode.err_opf_new_variable (1169)
Introducing new variables is now allowed. When a [variables] section is present, it is not allowed
to introduce new variables later in the problem.
rescode.err_opf_premature_eof (1172)
Premature end of file in an OPF file.
rescode.err_optimizer_license (1013)
The optimizer required is not licensed.
rescode.err_overflow (1590)
A computation produced an overflow i.e. a very large number.
rescode.err_param_index (1210)
Parameter index is out of range.
rescode.err_param_is_too_large (1215)
The parameter value is too large.
rescode.err_param_is_too_small (1216)
The parameter value is too small.
rescode.err_param_name (1205)
The parameter name is not correct.
rescode.err_param_name_dou (1206)
The parameter name is not correct for a double parameter.
rescode.err_param_name_int (1207)
The parameter name is not correct for an integer parameter.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_param_name_str (1208)
The parameter name is not correct for a string parameter.
rescode.err_param_type (1218)
The parameter type is invalid.
rescode.err_param_value_str (1217)
The parameter value string is incorrect.
rescode.err_platform_not_licensed (1019)
A requested license feature is not available for the required platform.
rescode.err_postsolve (1580)
An error occurred during the postsolve. Please contact MOSEK support.
rescode.err_pro_item (1281)
An invalid problem is used.
rescode.err_prob_license (1006)
The software is not licensed to solve the problem.
rescode.err_qcon_subi_too_large (1409)
Invalid value in qcsubi.
rescode.err_qcon_subi_too_small (1408)
Invalid value in qcsubi.
rescode.err_qcon_upper_triangle (1417)
An element in the upper triangle of a 𝑄𝑘 is specified. Only elements in the lower triangle should
be specified.
rescode.err_qobj_upper_triangle (1415)
An element in the upper triangle of 𝑄𝑜 is specified. Only elements in the lower triangle should be
specified.
rescode.err_read_format (1090)
The specified format cannot be read.
rescode.err_read_lp_missing_end_tag (1159)
Syntax error in LP file. Possibly missing End tag.
rescode.err_read_lp_nonexisting_name (1162)
A variable never occurred in objective or constraints.
rescode.err_remove_cone_variable (1310)
A variable cannot be removed because it will make a cone invalid.
rescode.err_repair_invalid_problem (1710)
The feasibility repair does not support the specified problem type.
rescode.err_repair_optimization_failed (1711)
Computation the optimal relaxation failed. The cause may have been numerical problems.
rescode.err_sen_bound_invalid_lo (3054)
Analysis of lower bound requested for an index, where no lower bound exists.
rescode.err_sen_bound_invalid_up (3053)
Analysis of upper bound requested for an index, where no upper bound exists.
rescode.err_sen_format (3050)
Syntax error in sensitivity analysis file.
rescode.err_sen_index_invalid (3055)
Invalid range given in the sensitivity file.
rescode.err_sen_index_range (3052)
Index out of range in the sensitivity analysis file.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_sen_invalid_regexp (3056)
Syntax error in regexp or regexp longer than 1024.
rescode.err_sen_numerical (3058)
Numerical difficulties encountered performing the sensitivity analysis.
rescode.err_sen_solution_status (3057)
No optimal solution found to the original problem given for sensitivity analysis.
rescode.err_sen_undef_name (3051)
An undefined name was encountered in the sensitivity analysis file.
rescode.err_sen_unhandled_problem_type (3080)
Sensitivity analysis cannot be performed for the specified problem. Sensitivity analysis is only
possible for linear problems.
rescode.err_server_connect (8000)
Failed to connect to remote solver server. The server string or the port string were invalid, or the
server did not accept connection.
rescode.err_server_protocol (8001)
Unexpected message or data from solver server.
rescode.err_server_status (8002)
Server returned non-ok HTTP status code
rescode.err_server_token (8003)
The job ID specified is incorrect or invalid
rescode.err_size_license (1005)
The problem is bigger than the license.
rescode.err_size_license_con (1010)
The problem has too many constraints to be solved with the available license.
rescode.err_size_license_intvar (1012)
The problem contains too many integer variables to be solved with the available license.
rescode.err_size_license_numcores (3900)
The computer contains more cpu cores than the license allows for.
rescode.err_size_license_var (1011)
The problem has too many variables to be solved with the available license.
rescode.err_sol_file_invalid_number (1350)
An invalid number is specified in a solution file.
rescode.err_solitem (1237)
The solution item number solitem is invalid. Please note that solitem.snx is invalid for the
basic solution.
rescode.err_solver_probtype (1259)
Problem type does not match the chosen optimizer.
rescode.err_space (1051)
Out of space.
rescode.err_space_leaking (1080)
MOSEK is leaking memory. This can be due to either an incorrect use of MOSEK or a bug.
rescode.err_space_no_info (1081)
No available information about the space usage.
rescode.err_sym_mat_duplicate (3944)
A value in a symmetric matric as been specified more than once.
rescode.err_sym_mat_huge (1482)
A symmetric matrix contains a huge value in absolute size. The parameter
dparam.data_sym_mat_tol_huge controls when an 𝑒𝑖,𝑗 is considered huge.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_sym_mat_invalid (1480)
A symmetric matrix contains an invalid floating point value, i.e. a NaN or an infinite value.
rescode.err_sym_mat_invalid_col_index (3941)
A column index specified for sparse symmetric matrix is invalid.
rescode.err_sym_mat_invalid_row_index (3940)
A row index specified for sparse symmetric matrix is invalid.
rescode.err_sym_mat_invalid_value (3943)
The numerical value specified in a sparse symmetric matrix is not a value floating value.
rescode.err_sym_mat_not_lower_tringular (3942)
Only the lower triangular part of sparse symmetric matrix should be specified.
rescode.err_task_incompatible (2560)
The Task file is incompatible with this platform. This results from reading a file on a 32 bit
platform generated on a 64 bit platform.
rescode.err_task_invalid (2561)
The Task file is invalid.
rescode.err_task_write (2562)
Failed to write the task file.
rescode.err_thread_cond_init (1049)
Could not initialize a condition.
rescode.err_thread_create (1048)
Could not create a thread. This error may occur if a large number of environments are created
and not deleted again. In any case it is a good practice to minimize the number of environments
created.
rescode.err_thread_mutex_init (1045)
Could not initialize a mutex.
rescode.err_thread_mutex_lock (1046)
Could not lock a mutex.
rescode.err_thread_mutex_unlock (1047)
Could not unlock a mutex.
rescode.err_toconic_constr_not_conic (7153)
The constraint is not conic representable.
rescode.err_toconic_constr_q_not_psd (7150)
The matrix defining the quadratric part of constraint is not positive semidefinite.
rescode.err_toconic_constraint_fx (7151)
The quadratic constraint is an equality, thus not convex.
rescode.err_toconic_constraint_ra (7152)
The quadratic constraint has finite lower and upper bound, and therefore it is not convex.
rescode.err_toconic_objective_not_psd (7155)
The matrix defining the quadratric part of the objective function is not positive semidefinite.
rescode.err_too_small_max_num_nz (1245)
The maximum number of non-zeros specified is too small.
rescode.err_too_small_maxnumanz (1252)
The maximum number of non-zeros specified for 𝐴 is smaller than the number of non-zeros in the
current 𝐴.
rescode.err_unb_step_size (3100)
A step size in an optimizer was unexpectedly unbounded. For instance, if the step-size becomes
unbounded in phase 1 of the simplex algorithm then an error occurs. Normally this will happen
only if the problem is badly formulated. Please contact MOSEK support if this error occurs.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_undef_solution (1265)
MOSEK has the following solution types:
•an interior-point solution,
•an basic solution,
•and an integer solution.
Each optimizer may set one or more of these solutions; e.g by default a successful optimization
with the interior-point optimizer defines the interior-point solution, and, for linear problems, also
the basic solution. This error occurs when asking for a solution or for information about a solution
that is not defined.
rescode.err_undefined_objective_sense (1446)
The objective sense has not been specified before the optimization.
rescode.err_unhandled_solution_status (6010)
Unhandled solution status.
rescode.err_unknown (1050)
Unknown error.
rescode.err_upper_bound_is_a_nan (1391)
The upper bound specified is not a number (nan).
rescode.err_upper_triangle (6020)
An element in the upper triangle of a lower triangular matrix is specified.
rescode.err_user_func_ret (1430)
An user function reported an error.
rescode.err_user_func_ret_data (1431)
An user function returned invalid data.
rescode.err_user_nlo_eval (1433)
The user-defined nonlinear function reported an error.
rescode.err_user_nlo_eval_hessubi (1440)
The user-defined nonlinear function reported an invalid subscript in the Hessian.
rescode.err_user_nlo_eval_hessubj (1441)
The user-defined nonlinear function reported an invalid subscript in the Hessian.
rescode.err_user_nlo_func (1432)
The user-defined nonlinear function reported an error.
rescode.err_whichitem_not_allowed (1238)
whichitem is unacceptable.
rescode.err_whichsol (1236)
The solution defined by whichsol does not exists.
rescode.err_write_lp_format (1158)
Problem cannot be written as an LP file.
rescode.err_write_lp_non_unique_name (1161)
An auto-generated name is not unique.
rescode.err_write_mps_invalid_name (1153)
An invalid name is created while writing an MPS file. Usually this will make the MPS file unread-
able.
rescode.err_write_opf_invalid_var_name (1156)
Empty variable names cannot be written to OPF files.
rescode.err_writing_file (1166)
An error occurred while writing file
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_xml_invalid_problem_type (3600)
The problem type is not supported by the XML format.
rescode.err_y_is_undefined (1449)
The solution item 𝑦 is undefined.
rescode.wrn_ana_almost_int_bounds (904)
This warning is issued by the problem analyzer if a constraint is bound nearly integral.
rescode.wrn_ana_c_zero (901)
This warning is issued by the problem analyzer, if the coefficients in the linear part of the objective
are all zero.
rescode.wrn_ana_close_bounds (903)
This warning is issued by problem analyzer, if ranged constraints or variables with very close upper
and lower bounds are detected. One should consider treating such constraints as equalities and
such variables as constants.
rescode.wrn_ana_empty_cols (902)
This warning is issued by the problem analyzer, if columns, in which all coefficients are zero, are
found.
rescode.wrn_ana_large_bounds (900)
This warning is issued by the problem analyzer, if one or more constraint or variable bounds are
very large. One should consider omitting these bounds entirely by setting them to +inf or -inf.
rescode.wrn_construct_invalid_sol_itg (807)
The initial value for one or more of the integer variables is not feasible.
rescode.wrn_construct_no_sol_itg (810)
The construct solution requires an integer solution.
rescode.wrn_construct_solution_infeas (805)
After fixing the integer variables at the suggested values then the problem is infeasible.
rescode.wrn_dropped_nz_qobj (201)
One or more non-zero elements were dropped in the Q matrix in the objective.
rescode.wrn_duplicate_barvariable_names (852)
Two barvariable names are identical.
rescode.wrn_duplicate_cone_names (853)
Two cone names are identical.
rescode.wrn_duplicate_constraint_names (850)
Two constraint names are identical.
rescode.wrn_duplicate_variable_names (851)
Two variable names are identical.
rescode.wrn_eliminator_space (801)
The eliminator is skipped at least once due to lack of space.
rescode.wrn_empty_name (502)
A variable or constraint name is empty. The output file may be invalid.
rescode.wrn_ignore_integer (250)
Ignored integer constraints.
rescode.wrn_incomplete_linear_dependency_check (800)
The linear dependency check(s) is incomplete. Normally this is not an important warning unless
the optimization problem has been formulated with linear dependencies. Linear dependencies may
prevent MOSEK from solving the problem.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.wrn_large_aij (62)
A numerically large value is specified for an 𝑎𝑖,𝑗 element in 𝐴. The parameter
dparam.data_tol_aij_large controls when an 𝑎𝑖,𝑗 is considered large.
rescode.wrn_large_bound (51)
A numerically large bound value is specified.
rescode.wrn_large_cj (57)
A numerically large value is specified for one 𝑐𝑗 .
rescode.wrn_large_con_fx (54)
An equality constraint is fixed to a numerically large value. This can cause numerical problems.
rescode.wrn_large_lo_bound (52)
A numerically large lower bound value is specified.
rescode.wrn_large_up_bound (53)
A numerically large upper bound value is specified.
rescode.wrn_license_expire (500)
The license expires.
rescode.wrn_license_feature_expire (505)
The license expires.
rescode.wrn_license_server (501)
The license server is not responding.
rescode.wrn_lp_drop_variable (85)
Ignored a variable because the variable was not previously defined. Usually this implies that a
variable appears in the bound section but not in the objective or the constraints.
rescode.wrn_lp_old_quad_format (80)
Missing ‘/2’ after quadratic expressions in bound or objective.
rescode.wrn_mio_infeasible_final (270)
The final mixed-integer problem with all the integer variables fixed at their optimal values is
infeasible.
rescode.wrn_mps_split_bou_vector (72)
A BOUNDS vector is split into several nonadjacent parts in an MPS file.
rescode.wrn_mps_split_ran_vector (71)
A RANGE vector is split into several nonadjacent parts in an MPS file.
rescode.wrn_mps_split_rhs_vector (70)
An RHS vector is split into several nonadjacent parts in an MPS file.
rescode.wrn_name_max_len (65)
A name is longer than the buffer that is supposed to hold it.
rescode.wrn_no_dualizer (950)
No automatic dualizer is available for the specified problem. The primal problem is solved.
rescode.wrn_no_global_optimizer (251)
No global optimizer is available.
rescode.wrn_no_nonlinear_function_write (450)
The problem contains a general nonlinear function in either the objective or the constraints. Such
a nonlinear function cannot be written to a disk file. Note that quadratic terms when inputted
explicitly can be written to disk.
rescode.wrn_nz_in_upr_tri (200)
Non-zero elements specified in the upper triangle of a matrix were ignored.
rescode.wrn_open_param_file (50)
The parameter file could not be opened.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.wrn_param_ignored_cmio (516)
A parameter was ignored by the conic mixed integer optimizer.
rescode.wrn_param_name_dou (510)
The parameter name is not recognized as a double parameter.
rescode.wrn_param_name_int (511)
The parameter name is not recognized as a integer parameter.
rescode.wrn_param_name_str (512)
The parameter name is not recognized as a string parameter.
rescode.wrn_param_str_value (515)
The string is not recognized as a symbolic value for the parameter.
rescode.wrn_presolve_outofspace (802)
The presolve is incomplete due to lack of space.
rescode.wrn_quad_cones_with_root_fixed_at_zero (930)
For at least one quadratic cone the root is fixed at (nearly) zero. This may cause problems such as
a very large dual solution. Therefore, it is recommended to remove such cones before optimizing
the problems, or to fix all the variables in the cone to 0.
rescode.wrn_rquad_cones_with_root_fixed_at_zero (931)
For at least one rotated quadratic cone at least one of the root variables are fixed at (nearly) zero.
This may cause problems such as a very large dual solution. Therefore, it is recommended to
remove such cones before optimizing the problems, or to fix all the variables in the cone to 0.
rescode.wrn_sol_file_ignored_con (351)
One or more lines in the constraint section were ignored when reading a solution file.
rescode.wrn_sol_file_ignored_var (352)
One or more lines in the variable section were ignored when reading a solution file.
rescode.wrn_sol_filter (300)
Invalid solution filter is specified.
rescode.wrn_spar_max_len (66)
A value for a string parameter is longer than the buffer that is supposed to hold it.
rescode.wrn_sym_mat_large (960)
A numerically large value is specified for an 𝑒𝑖,𝑗 element in 𝐸. The parameter
dparam.data_sym_mat_tol_large controls when an 𝑒𝑖,𝑗 is considered large.
rescode.wrn_too_few_basis_vars (400)
An incomplete basis has been specified. Too few basis variables are specified.
rescode.wrn_too_many_basis_vars (405)
A basis with too many variables has been specified.
rescode.wrn_undef_sol_file_name (350)
Undefined name occurred in a solution.
rescode.wrn_using_generic_names (503)
Generic names are used because a name is not valid. For instance when writing an LP file the
names must not contain blanks or start with a digit.
rescode.wrn_write_changed_names (803)
Some names were changed because they were invalid for the output file format.
rescode.wrn_write_discarded_cfix (804)
The fixed objective term could not be converted to a variable and was discarded in the output file.
rescode.wrn_zero_aij (63)
One or more zero elements are specified in A.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.wrn_zeros_in_sparse_col (710)
One or more (near) zero elements are specified in a sparse column of a matrix. It is redundant to
specify zero elements. Hence, it may indicate an error.
rescode.wrn_zeros_in_sparse_row (705)
One or more (near) zero elements are specified in a sparse row of a matrix. Since, it is redundant
to specify zero elements then it may indicate an error.
16.6 Enumerations
language
Language selection constants
language.eng
English language selection
language.dan
Danish language selection
accmode
Constraint or variable access modes
accmode.var
Access data by columns (variable oriented)
accmode.con
Access data by rows (constraint oriented)
basindtype
Basis identification
basindtype.never
Never do basis identification.
basindtype.always
Basis identification is always performed even if the interior-point optimizer terminates abnor-
mally.
basindtype.no_error
Basis identification is performed if the interior-point optimizer terminates without an error.
basindtype.if_feasible
Basis identification is not performed if the interior-point optimizer terminates with a problem
status saying that the problem is primal or dual infeasible.
basindtype.reservered
Not currently in use.
boundkey
Bound keys
boundkey.lo
The constraint or variable has a finite lower bound and an infinite upper bound.
boundkey.up
The constraint or variable has an infinite lower bound and an finite upper bound.
boundkey.fx
The constraint or variable is fixed.
boundkey.fr
The constraint or variable is free.
boundkey.ra
The constraint or variable is ranged.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
mark
Mark
mark.lo
The lower bound is selected for sensitivity analysis.
mark.up
The upper bound is selected for sensitivity analysis.
simdegen
Degeneracy strategies
simdegen.none
The simplex optimizer should use no degeneration strategy.
simdegen.free
The simplex optimizer chooses the degeneration strategy.
simdegen.aggressive
The simplex optimizer should use an aggressive degeneration strategy.
simdegen.moderate
The simplex optimizer should use a moderate degeneration strategy.
simdegen.minimum
The simplex optimizer should use a minimum degeneration strategy.
transpose
Transposed matrix.
transpose.no
No transpose is applied.
transpose.yes
A transpose is applied.
uplo
Triangular part of a symmetric matrix.
uplo.lo
Lower part.
uplo.up
Upper part
simreform
Problem reformulation.
simreform.on
Allow the simplex optimizer to reformulate the problem.
simreform.off
Disallow the simplex optimizer to reformulate the problem.
simreform.free
The simplex optimizer can choose freely.
simreform.aggressive
The simplex optimizer should use an aggressive reformulation strategy.
simdupvec
Exploit duplicate columns.
simdupvec.on
Allow the simplex optimizer to exploit duplicated columns.
simdupvec.off
Disallow the simplex optimizer to exploit duplicated columns.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
simdupvec.free
The simplex optimizer can choose freely.
simhotstart
Hot-start type employed by the simplex optimizer
simhotstart.none
The simplex optimizer performs a coldstart.
simhotstart.free
The simplex optimize chooses the hot-start type.
simhotstart.status_keys
Only the status keys of the constraints and variables are used to choose the type of hot-start.
intpnthotstart
Hot-start type employed by the interior-point optimizers.
intpnthotstart.none
The interior-point optimizer performs a coldstart.
intpnthotstart.primal
The interior-point optimizer exploits the primal solution only.
intpnthotstart.dual
The interior-point optimizer exploits the dual solution only.
intpnthotstart.primal_dual
The interior-point optimizer exploits both the primal and dual solution.
callbackcode
Progress call-back codes
callbackcode.begin_root_cutgen
The call-back function is called when root cut generation is started.
callbackcode.im_root_cutgen
The call-back is called from within root cut generation at an intermediate stage.
callbackcode.end_root_cutgen
The call-back function is called when root cut generation is is terminated.
callbackcode.begin_optimizer
The call-back function is called when the optimizer is started.
callbackcode.end_optimizer
The call-back function is called when the optimizer is terminated.
callbackcode.begin_presolve
The call-back function is called when the presolve is started.
callbackcode.update_presolve
The call-back function is called from within the presolve procedure.
callbackcode.im_presolve
The call-back function is called from within the presolve procedure at an intermediate stage.
callbackcode.end_presolve
The call-back function is called when the presolve is completed.
callbackcode.begin_intpnt
The call-back function is called when the interior-point optimizer is started.
callbackcode.intpnt
The call-back function is called from within the interior-point optimizer after the information
database has been updated.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
callbackcode.im_intpnt
The call-back function is called at an intermediate stage within the interior-point optimizer
where the information database has not been updated.
callbackcode.end_intpnt
The call-back function is called when the interior-point optimizer is terminated.
callbackcode.begin_conic
The call-back function is called when the conic optimizer is started.
callbackcode.conic
The call-back function is called from within the conic optimizer after the information database
has been updated.
callbackcode.im_conic
The call-back function is called at an intermediate stage within the conic optimizer where the
information database has not been updated.
callbackcode.end_conic
The call-back function is called when the conic optimizer is terminated.
callbackcode.primal_simplex
The call-back function is called from within the primal simplex optimizer.
callbackcode.dual_simplex
The call-back function is called from within the dual simplex optimizer.
callbackcode.begin_bi
The basis identification procedure has been started.
callbackcode.im_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point.
callbackcode.end_bi
The call-back function is called when the basis identification procedure is terminated.
callbackcode.begin_primal_bi
The call-back function is called from within the basis identification procedure when the primal
phase is started.
callbackcode.im_primal_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the primal phase.
callbackcode.update_primal_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the primal phase.
callbackcode.end_primal_bi
The call-back function is called from within the basis identification procedure when the primal
phase is terminated.
callbackcode.begin_dual_bi
The call-back function is called from within the basis identification procedure when the dual
phase is started.
callbackcode.im_dual_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the dual phase.
callbackcode.update_dual_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the dual phase.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
callbackcode.end_dual_bi
The call-back function is called from within the basis identification procedure when the dual
phase is terminated.
callbackcode.begin_simplex_bi
The call-back function is called from within the basis identification procedure when the simplex
clean-up phase is started.
callbackcode.im_simplex_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the simplex clean-up phase. The frequency of the call-backs is controlled by the
iparam.log_sim_freq parameter.
callbackcode.begin_primal_simplex_bi
The call-back function is called from within the basis identification procedure when the primal
simplex clean-up phase is started.
callbackcode.update_primal_simplex_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the primal simplex clean-up phase. The frequency of the call-backs is controlled
by the iparam.log_sim_freq parameter.
callbackcode.end_primal_simplex_bi
The call-back function is called from within the basis identification procedure when the primal
clean-up phase is terminated.
callbackcode.begin_primal_dual_simplex_bi
The call-back function is called from within the basis identification procedure when the primal-
dual simplex clean-up phase is started.
callbackcode.update_primal_dual_simplex_bi
The call-back function is called from within the basis identification procedure at an inter-
mediate point in the primal-dual simplex clean-up phase. The frequency of the call-backs is
controlled by the iparam.log_sim_freq parameter.
callbackcode.end_primal_dual_simplex_bi
The call-back function is called from within the basis identification procedure when the primal-
dual clean-up phase is terminated.
callbackcode.begin_dual_simplex_bi
The call-back function is called from within the basis identification procedure when the dual
simplex clean-up phase is started.
callbackcode.update_dual_simplex_bi
The call-back function is called from within the basis identification procedure at an interme-
diate point in the dual simplex clean-up phase. The frequency of the call-backs is controlled
by the iparam.log_sim_freq parameter.
callbackcode.end_dual_simplex_bi
The call-back function is called from within the basis identification procedure when the dual
clean-up phase is terminated.
callbackcode.end_simplex_bi
The call-back function is called from within the basis identification procedure when the simplex
clean-up phase is terminated.
callbackcode.begin_mio
The call-back function is called when the mixed-integer optimizer is started.
callbackcode.im_mio
The call-back function is called at an intermediate point in the mixed-integer optimizer.
callbackcode.new_int_mio
The call-back function is called after a new integer solution has been located by the mixed-
integer optimizer.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
callbackcode.end_mio
The call-back function is called when the mixed-integer optimizer is terminated.
callbackcode.begin_simplex
The call-back function is called when the simplex optimizer is started.
callbackcode.begin_dual_simplex
The call-back function is called when the dual simplex optimizer started.
callbackcode.im_dual_simplex
The call-back function is called at an intermediate point in the dual simplex optimizer.
callbackcode.update_dual_simplex
The call-back function is called in the dual simplex optimizer.
callbackcode.end_dual_simplex
The call-back function is called when the dual simplex optimizer is terminated.
callbackcode.begin_primal_simplex
The call-back function is called when the primal simplex optimizer is started.
callbackcode.im_primal_simplex
The call-back function is called at an intermediate point in the primal simplex optimizer.
callbackcode.update_primal_simplex
The call-back function is called in the primal simplex optimizer.
callbackcode.end_primal_simplex
The call-back function is called when the primal simplex optimizer is terminated.
callbackcode.begin_primal_dual_simplex
The call-back function is called when the primal-dual simplex optimizer is started.
callbackcode.im_primal_dual_simplex
The call-back function is called at an intermediate point in the primal-dual simplex optimizer.
callbackcode.update_primal_dual_simplex
The call-back function is called in the primal-dual simplex optimizer.
callbackcode.end_primal_dual_simplex
The call-back function is called when the primal-dual simplex optimizer is terminated.
callbackcode.end_simplex
The call-back function is called when the simplex optimizer is terminated.
callbackcode.begin_infeas_ana
The call-back function is called when the infeasibility analyzer is started.
callbackcode.end_infeas_ana
The call-back function is called when the infeasibility analyzer is terminated.
callbackcode.im_primal_sensivity
The call-back function is called at an intermediate stage of the primal sensitivity analysis.
callbackcode.im_dual_sensivity
The call-back function is called at an intermediate stage of the dual sensitivity analysis.
callbackcode.im_mio_intpnt
The call-back function is called at an intermediate point in the mixed-integer optimizer while
running the interior-point optimizer.
callbackcode.im_mio_primal_simplex
The call-back function is called at an intermediate point in the mixed-integer optimizer while
running the primal simplex optimizer.
callbackcode.im_mio_dual_simplex
The call-back function is called at an intermediate point in the mixed-integer optimizer while
running the dual simplex optimizer.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
callbackcode.begin_primal_setup_bi
The call-back function is called when the primal BI setup is started.
callbackcode.end_primal_setup_bi
The call-back function is called when the primal BI setup is terminated.
callbackcode.begin_dual_setup_bi
The call-back function is called when the dual BI phase is started.
callbackcode.end_dual_setup_bi
The call-back function is called when the dual BI phase is terminated.
callbackcode.begin_primal_sensitivity
Primal sensitivity analysis is started.
callbackcode.end_primal_sensitivity
Primal sensitivity analysis is terminated.
callbackcode.begin_dual_sensitivity
Dual sensitivity analysis is started.
callbackcode.end_dual_sensitivity
Dual sensitivity analysis is terminated.
callbackcode.begin_license_wait
Begin waiting for license.
callbackcode.end_license_wait
End waiting for license.
callbackcode.im_license_wait
MOSEK is waiting for a license.
callbackcode.begin_qcqo_reformulate
Begin QCQO reformulation.
callbackcode.end_qcqo_reformulate
End QCQO reformulation.
callbackcode.im_qo_reformulate
The call-back function is called at an intermediate stage of the conic quadratic reformulation.
callbackcode.begin_to_conic
Begin conic reformulation.
callbackcode.end_to_conic
End conic reformulation.
callbackcode.begin_full_convexity_check
Begin full convexity check.
callbackcode.end_full_convexity_check
End full convexity check.
callbackcode.im_full_convexity_check
The call-back function is called at an intermediate stage of the full convexity check.
callbackcode.begin_primal_repair
Begin primal feasibility repair.
callbackcode.end_primal_repair
End primal feasibility repair.
callbackcode.begin_read
MOSEK has started reading a problem file.
callbackcode.im_read
Intermediate stage in reading.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
callbackcode.end_read
MOSEK has finished reading a problem file.
callbackcode.begin_write
MOSEK has started writing a problem file.
callbackcode.end_write
MOSEK has finished writing a problem file.
callbackcode.read_opf_section
A chunk of 𝑄 non-zeros has been read from a problem file.
callbackcode.im_lu
The call-back function is called from within the LU factorization procedure at an intermediate
point.
callbackcode.im_order
The call-back function is called from within the matrix ordering procedure at an intermediate
point.
callbackcode.im_simplex
The call-back function is called from within the simplex optimizer at an intermediate point.
callbackcode.read_opf
The call-back function is called from the OPF reader.
callbackcode.write_opf
The call-back function is called from the OPF writer.
callbackcode.solving_remote
The call-back function is called while the task is being solved on a remote server.
checkconvexitytype
Types of convexity checks.
checkconvexitytype.none
No convexity check.
checkconvexitytype.simple
Perform simple and fast convexity check.
checkconvexitytype.full
Perform a full convexity check.
compresstype
Compression types
compresstype.none
No compression is used.
compresstype.free
The type of compression used is chosen automatically.
compresstype.gzip
The type of compression used is gzip compatible.
conetype
Cone types
conetype.quad
The cone is a quadratic cone.
conetype.rquad
The cone is a rotated quadratic cone.
nametype
Name types
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
nametype.gen
General names. However, no duplicate and blank names are allowed.
nametype.mps
MPS type names.
nametype.lp
LP type names.
symmattype
Cone types
symmattype.sparse
Sparse symmetric matrix.
dataformat
Data format types
dataformat.extension
The file extension is used to determine the data file format.
dataformat.mps
The data file is MPS formatted.
dataformat.lp
The data file is LP formatted.
dataformat.op
The data file is an optimization problem formatted file.
dataformat.xml
The data file is an XML formatted file.
dataformat.free_mps
The data a free MPS formatted file.
dataformat.task
Generic task dump file.
dataformat.cb
Conic benchmark format,
dataformat.json_task
JSON based task format.
dinfitem
Double information items
dinfitem.bi_time
Time spent within the basis identification procedure since its invocation.
dinfitem.bi_primal_time
Time spent within the primal phase of the basis identification procedure since its invocation.
dinfitem.bi_dual_time
Time spent within the dual phase basis identification procedure since its invocation.
dinfitem.bi_clean_time
Time spent within the clean-up phase of the basis identification procedure since its invocation.
dinfitem.bi_clean_primal_time
Time spent within the primal clean-up optimizer of the basis identification procedure since
its invocation.
dinfitem.bi_clean_primal_dual_time
Time spent within the primal-dual clean-up optimizer of the basis identification procedure
since its invocation.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dinfitem.bi_clean_dual_time
Time spent within the dual clean-up optimizer of the basis identification procedure since its
invocation.
dinfitem.intpnt_time
Time spent within the interior-point optimizer since its invocation.
dinfitem.intpnt_order_time
Order time (in seconds).
dinfitem.intpnt_primal_obj
Primal objective value reported by the interior-point optimizer.
dinfitem.intpnt_dual_obj
Dual objective value reported by the interior-point optimizer.
dinfitem.intpnt_primal_feas
Primal feasibility measure reported by the interior-point optimizers. (For the interior-point
optimizer this measure does not directly related to the original problem because a homoge-
neous model is employed).
dinfitem.intpnt_dual_feas
Dual feasibility measure reported by the interior-point optimizer. (For the interior-point op-
timizer this measure does not directly related to the original problem because a homogeneous
model is employed.)
dinfitem.intpnt_opt_status
This measure should converge to +1 if the problem has a primal-dual optimal solution, and
converge to −1 if problem is (strictly) primal or dual infeasible. If the measure converges to
another constant, or fails to settle, the problem is usually ill-posed.
dinfitem.sim_time
Time spent in the simplex optimizer since invoking it.
dinfitem.sim_primal_time
Time spent in the primal simplex optimizer since invoking it.
dinfitem.sim_dual_time
Time spent in the dual simplex optimizer since invoking it.
dinfitem.sim_primal_dual_time
Time spent in the primal-dual simplex optimizer since invoking it.
dinfitem.sim_obj
Objective value reported by the simplex optimizer.
dinfitem.sim_feas
Feasibility measure reported by the simplex optimizer.
dinfitem.mio_time
Time spent in the mixed-integer optimizer.
dinfitem.mio_root_presolve_time
Time spent in while presolving the root relaxation.
dinfitem.mio_root_optimizer_time
Time spent in the optimizer while solving the root relaxation.
dinfitem.mio_optimizer_time
Total time spent in the optimizer.
dinfitem.mio_heuristic_time
Total time spent in the optimizer.
dinfitem.to_conic_time
Time spent in the last to conic reformulation.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dinfitem.mio_construct_solution_obj
If MOSEK has successfully constructed an integer feasible solution, then this item contains
the optimal objective value corresponding to the feasible solution.
dinfitem.mio_obj_int
The primal objective value corresponding to the best integer feasible solution. Please
note that at least one integer feasible solution must have located i.e. check |
iinfitem.mio_num_int_solutions |.
dinfitem.mio_obj_bound
The best known bound on the objective function. This value is undefined until at least one
relaxation has been solved: To see if this is the case check that | iinfitem.mio_num_relax |
is strictly positive.
dinfitem.mio_obj_rel_gap
Given that the mixed-integer optimizer has computed a feasible solution and a bound on the
optimal objective value, then this item contains the relative gap defined by
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dinfitem.presolve_lindep_time
Total time spent in the linear dependency checker since the presolve was invoked.
dinfitem.rd_time
Time spent reading the data file.
dinfitem.sol_itr_primal_obj
Primal objective value of the interior-point solution.
dinfitem.sol_itr_pviolcon
Maximal primal bound violation for 𝑥𝑐 in the interior-point solution.
dinfitem.sol_itr_pviolvar
Maximal primal bound violation for 𝑥𝑥 in the interior-point solution.
dinfitem.sol_itr_pviolbarvar
Maximal primal bound violation for 𝑋 in the interior-point solution.
dinfitem.sol_itr_pviolcones
Maximal primal violation for primal conic constraints in the interior-point solution.
dinfitem.sol_itr_dual_obj
Dual objective value of the interior-point solution.
dinfitem.sol_itr_dviolcon
Maximal dual bound violation for 𝑥𝑐 in the interior-point solution.
dinfitem.sol_itr_dviolvar
Maximal dual bound violation for 𝑥𝑥 in the interior-point solution.
dinfitem.sol_itr_dviolbarvar
Maximal dual bound violation for 𝑋 in the interior-point solution.
dinfitem.sol_itr_dviolcones
Maximal dual violation for dual conic constraints in the interior-point solution.
dinfitem.sol_itr_nrm_xc
Infinity norm of 𝑥𝑐 in the interior-point solution.
dinfitem.sol_itr_nrm_xx
Infinity norm of 𝑥𝑥 in the interior-point solution.
dinfitem.sol_itr_nrm_barx
Infinity norm of 𝑋 in the interior-point solution.
dinfitem.sol_itr_nrm_y
Infinity norm of 𝑦 in the interior-point solution.
dinfitem.sol_itr_nrm_slc
Infinity norm of 𝑠𝑐𝑙 in the interior-point solution.
dinfitem.sol_itr_nrm_suc
Infinity norm of 𝑠𝑐𝑢 in the interior-point solution.
dinfitem.sol_itr_nrm_slx
Infinity norm of 𝑠𝑥𝑙 in the interior-point solution.
dinfitem.sol_itr_nrm_sux
Infinity norm of 𝑠𝑋
𝑢 in the interior-point solution.
dinfitem.sol_itr_nrm_snx
Infinity norm of 𝑠𝑥𝑛 in the interior-point solution.
dinfitem.sol_itr_nrm_bars
Infinity norm of 𝑆 in the interior-point solution.
dinfitem.sol_bas_primal_obj
Primal objective value of the basic solution.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dinfitem.sol_bas_pviolcon
Maximal primal bound violation for 𝑥𝑐 in the basic solution.
dinfitem.sol_bas_pviolvar
Maximal primal bound violation for 𝑥𝑥 in the basic solution.
dinfitem.sol_bas_dual_obj
Dual objective value of the basic solution.
dinfitem.sol_bas_dviolcon
Maximal dual bound violation for 𝑥𝑐 in the basic solution.
dinfitem.sol_bas_dviolvar
Maximal dual bound violation for 𝑥𝑥 in the basic solution.
dinfitem.sol_bas_nrm_xc
Infinity norm of 𝑥𝑐 in the basic solution.
dinfitem.sol_bas_nrm_xx
Infinity norm of 𝑥𝑥 in the basic solution.
dinfitem.sol_bas_nrm_barx
Infinity norm of 𝑋 in the basic solution.
dinfitem.sol_bas_nrm_y
Infinity norm of 𝑦 in the basic solution.
dinfitem.sol_bas_nrm_slc
Infinity norm of 𝑠𝑐𝑙 in the basic solution.
dinfitem.sol_bas_nrm_suc
Infinity norm of 𝑠𝑐𝑢 in the basic solution.
dinfitem.sol_bas_nrm_slx
Infinity norm of 𝑠𝑥𝑙 in the basic solution.
dinfitem.sol_bas_nrm_sux
Infinity norm of 𝑠𝑋
𝑢 in the basic solution.
dinfitem.sol_itg_primal_obj
Primal objective value of the integer solution.
dinfitem.sol_itg_pviolcon
Maximal primal bound violation for 𝑥𝑐 in the integer solution.
dinfitem.sol_itg_pviolvar
Maximal primal bound violation for 𝑥𝑥 in the integer solution.
dinfitem.sol_itg_pviolbarvar
Maximal primal bound violation for 𝑋 in the integer solution.
dinfitem.sol_itg_pviolcones
Maximal primal violation for primal conic constraints in the integer solution.
dinfitem.sol_itg_pviolitg
Maximal violation for the integer constraints in the integer solution.
dinfitem.sol_itg_nrm_xc
Infinity norm of 𝑥𝑐 in the integer solution.
dinfitem.sol_itg_nrm_xx
Infinity norm of 𝑥𝑥 in the integer solution.
dinfitem.sol_itg_nrm_barx
Infinity norm of 𝑋 in the integer solution.
dinfitem.intpnt_factor_num_flops
An estimate of the number of flops used in the factorization.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dinfitem.qcqo_reformulate_time
Time spent with conic quadratic reformulation.
dinfitem.qcqo_reformulate_max_perturbation
Maximum absolute diagonal perturbation occuring during the QCQO reformulation.
dinfitem.qcqo_reformulate_worst_cholesky_diag_scaling
Worst Cholesky diagonal scaling.
dinfitem.qcqo_reformulate_worst_cholesky_column_scaling
Worst Cholesky column scaling.
dinfitem.primal_repair_penalty_obj
The optimal objective value of the penalty function.
feature
License feature
feature.pts
Base system.
feature.pton
Nonlinear extension.
liinfitem
Long integer information items.
liinfitem.mio_presolved_anz
Number of non-zero entries in the constraint matrix of presolved problem.
liinfitem.mio_simplex_iter
Number of simplex iterations performed by the mixed-integer optimizer.
liinfitem.mio_intpnt_iter
Number of interior-point iterations performed by the mixed-integer optimizer.
liinfitem.bi_primal_iter
Number of primal pivots performed in the basis identification.
liinfitem.bi_dual_iter
Number of dual pivots performed in the basis identification.
liinfitem.bi_clean_primal_iter
Number of primal clean iterations performed in the basis identification.
liinfitem.bi_clean_primal_dual_iter
Number of primal-dual clean iterations performed in the basis identification.
liinfitem.bi_clean_dual_iter
Number of dual clean iterations performed in the basis identification.
liinfitem.bi_clean_primal_deg_iter
Number of primal degenerate clean iterations performed in the basis identification.
liinfitem.bi_clean_primal_dual_sub_iter
Number of primal-dual subproblem clean iterations performed in the basis identification.
liinfitem.bi_clean_primal_dual_deg_iter
Number of primal-dual degenerate clean iterations performed in the basis identification.
liinfitem.bi_clean_dual_deg_iter
Number of dual degenerate clean iterations performed in the basis identification.
liinfitem.intpnt_factor_num_nz
Number of non-zeros in factorization.
liinfitem.rd_numanz
Number of non-zeros in A that is read.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
liinfitem.rd_numqnz
Number of Q non-zeros.
liinfitem.mio_sim_maxiter_setbacks
Number of times the the simplex optimizer has hit the maximum iteration limit when re-
optimizing.
iinfitem
Integer information items.
iinfitem.ana_pro_num_con
Number of constraints in the problem.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_con_lo
Number of constraints with a lower bound and an infinite upper bound.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_con_up
Number of constraints with an upper bound and an infinite lower bound.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_con_ra
Number of constraints with finite lower and upper bounds.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_con_eq
Number of equality constraints.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_con_fr
Number of unbounded constraints.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var
Number of variables in the problem.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_lo
Number of variables with a lower bound and an infinite upper bound.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_up
Number of variables with an upper bound and an infinite lower bound. This value is set by
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_ra
Number of variables with finite lower and upper bounds.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_eq
Number of fixed variables.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_fr
Number of free variables.
This value is set by task.analyzeproblem .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iinfitem.ana_pro_num_var_cont
Number of continuous variables.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_bin
Number of binary (0-1) variables.
This value is set by task.analyzeproblem .
iinfitem.ana_pro_num_var_int
Number of general integer variables.
This value is set by task.analyzeproblem .
iinfitem.optimize_response
The response code returned by optimize.
iinfitem.intpnt_iter
Number of interior-point iterations since invoking the interior-point optimizer.
iinfitem.intpnt_factor_dim_dense
Dimension of the dense sub system in factorization.
iinfitem.intpnt_solve_dual
Non-zero if the interior-point optimizer is solving the dual problem.
iinfitem.mio_node_depth
Depth of the last node solved.
iinfitem.mio_numcon
Number of constraints in the problem solved by the mixed-integer optimizer.
iinfitem.mio_numvar
Number of variables in the problem solved by the mixed-integer optimizer.
iinfitem.mio_numint
Number of integer variables in the problem solved be the mixed-integer optimizer.
iinfitem.mio_presolved_numcont
Number of continuous variables in the problem solved be the mixed-integer optimizer.
iinfitem.mio_presolved_numbin
Number of binary variables in the problem solved be the mixed-integer optimizer.
iinfitem.mio_presolved_numcon
Number of constraints in the presolved problem.
iinfitem.mio_presolved_numvar
Number of variables in the presolved problem.
iinfitem.mio_presolved_numint
Number of integer variables in the presolved problem.
iinfitem.mio_clique_table_size
Size of the clique table.
iinfitem.mio_construct_solution
If this item has the value 0, then MOSEK did not try to construct an initial integer feasible
solution. If the item has a positive value, then MOSEK successfully constructed an initial
integer feasible solution.
iinfitem.mio_construct_num_roundings
Number of values in the integer solution that is rounded to an integer value.
iinfitem.mio_num_int_solutions
Number of integer feasible solutions that has been found.
iinfitem.mio_obj_bound_defined
Non-zero if a valid objective bound has been found, otherwise zero.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iinfitem.mio_num_active_nodes
Number of active branch bound nodes.
iinfitem.mio_num_relax
Number of relaxations solved during the optimization.
iinfitem.mio_num_branch
Number of branches performed during the optimization.
iinfitem.mio_total_num_cuts
Total number of cuts generated by the mixed-integer optimizer.
iinfitem.mio_num_cmir_cuts
Number of Complemented Mixed Integer Rounding (CMIR) cuts.
iinfitem.mio_num_clique_cuts
Number of clique cuts.
iinfitem.mio_num_implied_bound_cuts
Number of implied bound cuts.
iinfitem.mio_num_knapsack_cover_cuts
Number of clique cuts.
iinfitem.mio_num_gomory_cuts
Number of Gomory cuts.
iinfitem.mio_num_repeated_presolve
Number of times presolve was repeated at root.
iinfitem.mio_initial_solution
Is non-zero if an initial integer solution is specified.
iinfitem.mio_user_obj_cut
If it is non-zero, then the objective cut is used.
iinfitem.mio_relgap_satisfied
Non-zero if relative gap is within tolerances.
iinfitem.mio_absgap_satisfied
Non-zero if absolute gap is within tolerances.
iinfitem.mio_near_relgap_satisfied
Non-zero if relative gap is within relaxed tolerances.
iinfitem.mio_near_absgap_satisfied
Non-zero if absolute gap is within relaxed tolerances.
iinfitem.rd_protype
Problem type.
iinfitem.rd_numcon
Number of constraints read.
iinfitem.rd_numvar
Number of variables read.
iinfitem.rd_numbarvar
Number of variables read.
iinfitem.rd_numintvar
Number of integer-constrained variables read.
iinfitem.rd_numq
Number of nonempty Q matrices read.
iinfitem.sim_dual_deg_iter
The number of dual degenerate iterations.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iinfitem.sim_dual_inf_iter
The number of iterations taken with dual infeasibility.
iinfitem.sim_dual_hotstart_lu
If 1 then a valid basis factorization of full rank was located and used by the dual simplex
algorithm.
iinfitem.sim_primal_iter
Number of primal simplex iterations during the last optimization.
iinfitem.sim_dual_iter
Number of dual simplex iterations during the last optimization.
iinfitem.sim_primal_dual_iter
Number of primal dual simplex iterations during the last optimization.
iinfitem.intpnt_num_threads
Number of threads that the interior-point optimizer is using.
iinfitem.sim_primal_inf_iter
The number of iterations taken with primal infeasibility.
iinfitem.sim_primal_dual_inf_iter
The number of master iterations with dual infeasibility taken by the primal dual simplex
algorithm.
iinfitem.sim_primal_deg_iter
The number of primal degenerate iterations.
iinfitem.sim_primal_dual_deg_iter
The number of degenerate major iterations taken by the primal dual simplex algorithm.
iinfitem.sim_primal_hotstart
If 1 then the primal simplex algorithm is solving from an advanced basis.
iinfitem.sim_primal_hotstart_lu
If 1 then a valid basis factorization of full rank was located and used by the primal simplex
algorithm.
iinfitem.sim_dual_hotstart
If 1 then the dual simplex algorithm is solving from an advanced basis.
iinfitem.sim_primal_dual_hotstart
If 1 then the primal dual simplex algorithm is solving from an advanced basis.
iinfitem.sim_primal_dual_hotstart_lu
If 1 then a valid basis factorization of full rank was located and used by the primal dual
simplex algorithm.
iinfitem.sol_itr_prosta
Problem status of the interior-point solution. Updated after each optimization.
iinfitem.sol_itr_solsta
Solution status of the interior-point solution. Updated after each optimization.
iinfitem.sol_bas_prosta
Problem status of the basic solution. Updated after each optimization.
iinfitem.sol_bas_solsta
Solution status of the basic solution. Updated after each optimization.
iinfitem.sol_itg_prosta
Problem status of the integer solution. Updated after each optimization.
iinfitem.sol_itg_solsta
Solution status of the integer solution. Updated after each optimization.
iinfitem.sim_numcon
Number of constraints in the problem solved by the simplex optimizer.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
iinfitem.sim_numvar
Number of variables in the problem solved by the simplex optimizer.
iinfitem.opt_numcon
Number of constraints in the problem solved when the optimizer is called.
iinfitem.opt_numvar
Number of variables in the problem solved when the optimizer is called
iinfitem.sto_num_a_realloc
Number of times the storage for storing 𝐴 has been changed. A large value may indicates
that memory fragmentation may occur.
iinfitem.rd_numcone
Number of conic constraints read.
iinfitem.sim_solve_dual
Is non-zero if dual problem is solved.
inftype
Information item types
inftype.dou_type
Is a double information type.
inftype.int_type
Is an integer.
inftype.lint_type
Is a long integer.
iomode
Input/output modes
iomode.read
The file is read-only.
iomode.write
The file is write-only. If the file exists then it is truncated when it is opened. Otherwise it is
created when it is opened.
iomode.readwrite
The file is to read and written.
branchdir
Specifies the branching direction.
branchdir.free
The mixed-integer optimizer decides which branch to choose.
branchdir.up
The mixed-integer optimizer always chooses the up branch first.
branchdir.down
The mixed-integer optimizer always chooses the down branch first.
branchdir.near
Branch in direction nearest to selected fractional variable.
branchdir.far
Branch in direction farthest from selected fractional variable.
branchdir.root_lp
Chose direction based on root lp value of selected variable.
branchdir.guided
Branch in direction of current incumbent.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
branchdir.pseudocost
Branch based on the pseudocost of the variable.
miocontsoltype
Continuous mixed-integer solution type
miocontsoltype.none
No interior-point or basic solution are reported when the mixed-integer optimizer is used.
miocontsoltype.root
The reported interior-point and basic solutions are a solution to the root node problem when
mixed-integer optimizer is used.
miocontsoltype.itg
The reported interior-point and basic solutions are a solution to the problem with all integer
variables fixed at the value they have in the integer solution. A solution is only reported in
case the problem has a primal feasible solution.
miocontsoltype.itg_rel
In case the problem is primal feasible then the reported interior-point and basic solutions are
a solution to the problem with all integer variables fixed at the value they have in the integer
solution. If the problem is primal infeasible, then the solution to the root node problem is
reported.
miomode
Integer restrictions
miomode.ignored
The integer constraints are ignored and the problem is solved as a continuous problem.
miomode.satisfied
Integer restrictions should be satisfied.
mionodeseltype
Mixed-integer node selection types
mionodeseltype.free
The optimizer decides the node selection strategy.
mionodeseltype.first
The optimizer employs a depth first node selection strategy.
mionodeseltype.best
The optimizer employs a best bound node selection strategy.
mionodeseltype.worst
The optimizer employs a worst bound node selection strategy.
mionodeseltype.hybrid
The optimizer employs a hybrid strategy.
mionodeseltype.pseudo
The optimizer employs selects the node based on a pseudo cost estimate.
mpsformat
MPS file format type
mpsformat.strict
It is assumed that the input file satisfies the MPS format strictly.
mpsformat.relaxed
It is assumed that the input file satisfies a slightly relaxed version of the MPS format.
mpsformat.free
It is assumed that the input file satisfies the free MPS format. This implies that spaces are
not allowed in names. Otherwise the format is free.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
mpsformat.cplex
The CPLEX compatible version of the MPS format is employed.
msgkey
Message keys
msgkey.reading_file
msgkey.writing_file
msgkey.mps_selected
objsense
Objective sense types
objsense.minimize
The problem should be minimized.
objsense.maximize
The problem should be maximized.
onoffkey
On/off
onoffkey.on
Switch the option on.
onoffkey.off
Switch the option off.
optimizertype
Optimizer types
optimizertype.free
The optimizer is chosen automatically.
optimizertype.intpnt
The interior-point optimizer is used.
optimizertype.conic
The optimizer for problems having conic constraints.
optimizertype.primal_simplex
The primal simplex optimizer is used.
optimizertype.dual_simplex
The dual simplex optimizer is used.
optimizertype.free_simplex
One of the simplex optimizers is used.
optimizertype.mixed_int
The mixed-integer optimizer.
orderingtype
Ordering strategies
orderingtype.free
The ordering method is chosen automatically.
orderingtype.appminloc
Approximate minimum local fill-in ordering is employed.
orderingtype.experimental
This option should not be used.
orderingtype.try_graphpar
Always try the graph partitioning based ordering.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
orderingtype.force_graphpar
Always use the graph partitioning based ordering even if it is worse than the approximate
minimum local fill ordering.
orderingtype.none
No ordering is used.
presolvemode
Presolve method.
presolvemode.off
The problem is not presolved before it is optimized.
presolvemode.on
The problem is presolved before it is optimized.
presolvemode.free
It is decided automatically whether to presolve before the problem is optimized.
parametertype
Parameter type
parametertype.invalid_type
Not a valid parameter.
parametertype.dou_type
Is a double parameter.
parametertype.int_type
Is an integer parameter.
parametertype.str_type
Is a string parameter.
problemitem
Problem data items
problemitem.var
Item is a variable.
problemitem.con
Item is a constraint.
problemitem.cone
Item is a cone.
problemtype
Problem types
problemtype.lo
The problem is a linear optimization problem.
problemtype.qo
The problem is a quadratic optimization problem.
problemtype.qcqo
The problem is a quadratically constrained optimization problem.
problemtype.geco
General convex optimization.
problemtype.conic
A conic optimization.
problemtype.mixed
General nonlinear constraints and conic constraints. This combination can not be solved by
MOSEK.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
prosta
Problem status keys
prosta.unknown
Unknown problem status.
prosta.prim_and_dual_feas
The problem is primal and dual feasible.
prosta.prim_feas
The problem is primal feasible.
prosta.dual_feas
The problem is dual feasible.
prosta.near_prim_and_dual_feas
The problem is at least nearly primal and dual feasible.
prosta.near_prim_feas
The problem is at least nearly primal feasible.
prosta.near_dual_feas
The problem is at least nearly dual feasible.
prosta.prim_infeas
The problem is primal infeasible.
prosta.dual_infeas
The problem is dual infeasible.
prosta.prim_and_dual_infeas
The problem is primal and dual infeasible.
prosta.ill_posed
The problem is ill-posed. For example, it may be primal and dual feasible but have a positive
duality gap.
prosta.prim_infeas_or_unbounded
The problem is either primal infeasible or unbounded. This may occur for mixed-integer
problems.
xmlwriteroutputtype
XML writer output mode
xmlwriteroutputtype.row
Write in row order.
xmlwriteroutputtype.col
Write in column order.
rescodetype
Response code type
rescodetype.ok
The response code is OK.
rescodetype.wrn
The response code is a warning.
rescodetype.trm
The response code is an optimizer termination status.
rescodetype.err
The response code is an error.
rescodetype.unk
The response code does not belong to any class.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
scalingtype
Scaling type
scalingtype.free
The optimizer chooses the scaling heuristic.
scalingtype.none
No scaling is performed.
scalingtype.moderate
A conservative scaling is performed.
scalingtype.aggressive
A very aggressive scaling is performed.
scalingmethod
Scaling method
scalingmethod.pow2
Scales only with power of 2 leaving the mantissa untouched.
scalingmethod.free
The optimizer chooses the scaling heuristic.
sensitivitytype
Sensitivity types
sensitivitytype.basis
Basis sensitivity analysis is performed.
sensitivitytype.optimal_partition
Optimal partition sensitivity analysis is performed.
simseltype
Simplex selection strategy
simseltype.free
The optimizer chooses the pricing strategy.
simseltype.full
The optimizer uses full pricing.
simseltype.ase
The optimizer uses approximate steepest-edge pricing.
simseltype.devex
The optimizer uses devex steepest-edge pricing (or if it is not available an approximate steep-
edge selection).
simseltype.se
The optimizer uses steepest-edge selection (or if it is not available an approximate steep-edge
selection).
simseltype.partial
The optimizer uses a partial selection approach. The approach is usually beneficial if the
number of variables is much larger than the number of constraints.
solitem
Solution items
solitem.xc
Solution for the constraints.
solitem.xx
Variable solution.
solitem.y
Lagrange multipliers for equations.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
solitem.slc
Lagrange multipliers for lower bounds on the constraints.
solitem.suc
Lagrange multipliers for upper bounds on the constraints.
solitem.slx
Lagrange multipliers for lower bounds on the variables.
solitem.sux
Lagrange multipliers for upper bounds on the variables.
solitem.snx
Lagrange multipliers corresponding to the conic constraints on the variables.
solsta
Solution status keys
solsta.unknown
Status of the solution is unknown.
solsta.optimal
The solution is optimal.
solsta.prim_feas
The solution is primal feasible.
solsta.dual_feas
The solution is dual feasible.
solsta.prim_and_dual_feas
The solution is both primal and dual feasible.
solsta.near_optimal
The solution is nearly optimal.
solsta.near_prim_feas
The solution is nearly primal feasible.
solsta.near_dual_feas
The solution is nearly dual feasible.
solsta.near_prim_and_dual_feas
The solution is nearly both primal and dual feasible.
solsta.prim_infeas_cer
The solution is a certificate of primal infeasibility.
solsta.dual_infeas_cer
The solution is a certificate of dual infeasibility.
solsta.near_prim_infeas_cer
The solution is almost a certificate of primal infeasibility.
solsta.near_dual_infeas_cer
The solution is almost a certificate of dual infeasibility.
solsta.prim_illposed_cer
The solution is a certificate that the primal problem is illposed.
solsta.dual_illposed_cer
The solution is a certificate that the dual problem is illposed.
solsta.integer_optimal
The primal solution is integer optimal.
solsta.near_integer_optimal
The primal solution is near integer optimal.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
soltype
Solution types
soltype.bas
The basic solution.
soltype.itr
The interior solution.
soltype.itg
The integer solution.
solveform
Solve primal or dual form
solveform.free
The optimizer is free to solve either the primal or the dual problem.
solveform.primal
The optimizer should solve the primal problem.
solveform.dual
The optimizer should solve the dual problem.
stakey
Status keys
stakey.unk
The status for the constraint or variable is unknown.
stakey.bas
The constraint or variable is in the basis.
stakey.supbas
The constraint or variable is super basic.
stakey.low
The constraint or variable is at its lower bound.
stakey.upr
The constraint or variable is at its upper bound.
stakey.fix
The constraint or variable is fixed.
stakey.inf
The constraint or variable is infeasible in the bounds.
startpointtype
Starting point types
startpointtype.free
The starting point is chosen automatically.
startpointtype.guess
The optimizer guesses a starting point.
startpointtype.constant
The optimizer constructs a starting point by assigning a constant value to all primal and dual
variables. This starting point is normally robust.
startpointtype.satisfy_bounds
The starting point is chosen to satisfy all the simple bounds on nonlinear variables. If this
starting point is employed, then more care than usual should employed when choosing the
bounds on the nonlinear variables. In particular very tight bounds should be avoided.
streamtype
Stream types
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
streamtype.log
Log stream. Contains the aggregated contents of all other streams. This means that a message
written to any other stream will also be written to this stream.
streamtype.msg
Message stream. Log information relating to performance and progress of the optimization is
written to this stream.
streamtype.err
Error stream. Error messages are written to this stream.
streamtype.wrn
Warning stream. Warning messages are written to this stream.
value
Integer values
value.max_str_len
Maximum string length allowed in MOSEK.
value.license_buffer_length
The length of a license key buffer.
variabletype
Variable types
variabletype.type_cont
Is a continuous variable.
variabletype.type_int
Is an integer variable.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
dparam
double parameter type. See Double Parameters
sparam
string parameter type. See String Parameters
rescode
The return code type.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝐿𝐿𝑇 − 𝐷 = 𝑃 𝐴𝑃 𝑇
where 𝑃 is a permutation matrix. If a pivot during the computation of the Cholesky factorization
is less than
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
then the matrix is declared negative semidefinite. On the hand if a pivot is smaller than
Therefore, if 𝐴 is suffciently positive definite then 𝐷 will be the zero matrix. 𝜌 is set equal to value
of tolsingular.
Parameters
•[in] multithread (int) – If nonzero then the function may exploit multiple threads.
•[in] ordermethod (int) – If nonzero, then a sparsity preservering ordering will be employed.
•[in] tolsingular (double) – A positive parameter controling when a pivot is declared
zero.
•[in] anzc (int[]) – anzc[j] is the number of nonzeros in the jth column of A.
•[in] aptrc (long[]) – aptrc[j] is a pointer to the first element in column j.
•[in] asubc (int[]) – Row subscripts in each column stored in increasing order.
•[in] avalc (double[]) – Values stores column wise.
Return
•perm (int) – Is permutation array used to specify the permutation matrix 𝑃 computed by
the function.
•diag (double) – The diagonal elements of matrix 𝐷.
•lnzc (int) – lnzc[j] is the number of non zero elements in column j.
•lptrc (long) – lptrc[j] is a pointer to the first row index and value in column j.
•lensubnval (long) – Number of elements in lsubc and lvalc.
•lsubc (int) – Row indexes for each column stored sequentially. Must be stored increasing
order for each column.
•lvalc (double) – The value corresponding to row indexed stored lsubc.
xty = Env.dot(n, x, y)
Computes the inner product of two vectors 𝑥, 𝑦 of lenght 𝑛 ≥ 0, i.e
𝑛
∑︁
𝑥·𝑦 = 𝑥𝑖 𝑦𝑖 .
𝑖=1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝐶 := 𝛼𝑜𝑝(𝐴)𝑜𝑝(𝐵) + 𝛽𝐶
where 𝛼, 𝛽 are two scalar values. The function 𝑜𝑝(𝑋) return 𝑋 if transX is YES, or 𝑋 𝑇 if set to
NO. Dimensions of 𝐴, 𝑏 must therefore match those of 𝐶.
The result of this operation is stored in 𝐶.
Parameters
•[in] transa (transpose ) – Indicates whether the matrix 𝐴 must be transposed.
•[in] transb (transpose ) – Indicates whether the matrix 𝐵 must be transposed.
•[in] m (int) – Indicates the number of rows of matrices 𝐴 and 𝐶.
•[in] n (int) – Indicates the number of columns of matrices 𝐵 and 𝐶.
•[in] k (int) – Specifies the number of columns of the matrix 𝐴 and the number of rows of
the matrix 𝐵.
•[in] alpha (double) – A scalar value multipling the result of the matrix multiplication.
•[in] a (double[]) – The pointer to the array storing matrix 𝐴 in a column-major format.
•[in] b (double[]) – Indicates the number of rows of matrix 𝐵 and columns of matrix 𝐴.
•[in] beta (double) – A scalar value that multiplies 𝐶.
•[io] c (double[]) – The pointer to the array storing matrix 𝐶 in a column-major format.
Env.gemv(transa, m, n, alpha, a, x, beta, y)
Computes the multiplication of a scaled dense matrix times a dense vector product, plus a scaled
dense vector. In formula
𝑦 = 𝛼𝐴𝑥 + 𝛽𝑦,
𝑦 = 𝛼𝐴𝑇 𝑥 + 𝛽𝑦,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•[in] licwait (int) – If this argument is non-zero, then MOSEK will wait for a license if
no license is available. Moreover, licwait-1 is the number of milliseconds to wait between
each check for an available license.
Env.set_Stream(whichstream, callback)
Directs all output from a env stream to a callback function.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
•[in] callback (none) – The callback function.
Env.sparsetriangularsolvedense(transposed, lnzc, lptrc, lsubc, lvalc, b)
The function can be used to a triangular system of the form
𝐿𝑥 = 𝑏
or
𝐿𝑇 𝑥 = 𝑏
where 𝐿 is a sparse lower triangular nonsingular matrix. This implies in particular that diagonals
in 𝐿 are nonzero.
Parameters
•[in] transposed (transpose ) – Controls whether the solve is with 𝐿 or 𝐿𝑇 .
•[in] lnzc (int[]) – lnzc[j] is the number of nonzeros in column j.
•[in] lptrc (long[]) – lptrc[j] is a pointer to the first row index and value in column j.
•[in] lsubc (int[]) – Row indexes for each column stored sequentially. Must be stored
increasing order for each column.
•[in] lvalc (double[]) – The value corresponding to row indexed stored lsubc.
•[io] b (double[]) – The right-hand side of linear equation system to be solved.
Env.syeig(uplo, n, a, w)
Computes all eigenvalues of a real symmetric matrix 𝐴. Eigenvalues are stored in the 𝑤 array.
Parameters
•[in] uplo (uplo ) – Indicates whether the upper or lower triangular part is used.
•[in] n (int) – Dimension of the symmetric input matrix.
•[in] a (double[]) – A symmetric matrix stored in column-major order. Only the lower-
triangular part is used.
•[out] w (double[]) – Array of minimum dimension n where eigenvalues will be stored.
Env.syevd(uplo, n, a, w)
Computes all the eigenvalues and eigenvectors a real symmetric matrix.
Given the input matrix 𝐴 ∈ R𝑛×𝑛 , this function returns a vector 𝑤 ∈ R𝑛 containing the eigenvalues
of 𝐴 and the corresponding eigenvectors, stored in 𝐴 as well.
Therefore, this function compute the eigenvalue decomposition of 𝐴 as
𝐴 = 𝑈𝑉 𝑈𝑇 ,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•[out] w (double[]) – An array where eigenvalues will be stored. Its lenght must be at least
the dimension of the input matrix.
Env.syrk(uplo, trans, n, k, alpha, a, beta, c)
Performs a symmetric rank-𝑘 update for a symmetric matrix.
Given a symmetric matrix 𝐶 ∈ R𝑛×𝑛 , two scalars 𝛼, 𝛽 and a matrix 𝐴 of rank 𝑘 ≤ 𝑛, it computes
either
𝐶 = 𝛼𝐴𝐴𝑇 + 𝛽𝐶,
or
𝐶 = 𝛼𝐴𝑇 𝐴 + 𝛽𝐶.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
task.putmaxnumanz – The function changes the size of the preallocated storage for linear coeffi-
cients.
task.putmaxnumbarvar – Sets the number of preallocated symmetric matrix variables in the op-
timization task.
task.putmaxnumcon – Sets the number of preallocated constraints in the optimization task.
task.putmaxnumcone – Sets the number of preallocated conic constraints in the optimization task.
task.putmaxnumqnz – Changes the size of the preallocated storage for quadratic terms.
task.putmaxnumvar – Sets the number of preallocated variables in the optimization task.
task.putnadouparam – Sets a double parameter.
task.putnaintparam – Sets an integer parameter.
task.putnastrparam – Sets a string parameter.
task.putobjname – Assigns a new name to the objective.
task.putobjsense – Sets the objective sense.
task.putparam – Modifies the value of parameter.
task.putqcon – Replaces all quadratic terms in constraints.
task.putqconk – Replaces all quadratic terms in a single constraint.
task.putqobj – Replaces all quadratic terms in the objective.
task.putqobjij – Replaces one coefficient in the quadratic term in the objective.
task.putskc – Sets the status keys for the constraints.
task.putskcslice – Sets the status keys for the constraints.
task.putskx – Sets the status keys for the scalar variables.
task.putskxslice – Sets the status keys for the variables.
task.putslc – Sets the slc vector for a solution.
task.putslcslice – Sets a slice of the slc vector for a solution.
task.putslx – Sets the slx vector for a solution.
task.putslxslice – Sets a slice of the slx vector for a solution.
task.putsnx – Sets the snx vector for a solution.
task.putsnxslice – Sets a slice of the snx vector for a solution.
task.putsolution – Inserts a solution.
task.putsolutioni – Sets the primal and dual solution information for a single constraint or
variable.
task.putsolutionyi – Inputs the dual variable of a solution.
task.putstrparam – Sets a string parameter.
task.putsuc – Sets the suc vector for a solution.
task.putsucslice – Sets a slice of the suc vector for a solution.
task.putsux – Sets the sux vector for a solution.
task.putsuxslice – Sets a slice of the sux vector for a solution.
task.puttaskname – Assigns a new name to the task.
task.putvarbound – Changes the bound for one variable.
task.putvarboundlist – Changes the bounds of a list of variables.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Task.Task(env)
Task.Task(other)
Create a new Task in the given environment.
Parameters
•[in] env (Env ) – Parent environment.
•[in] other (Task) – The task to copy.
Task.analyzenames(whichstream, nametype)
The function analyzes the names and issue an error if a name is invalid.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
•[in] nametype (nametype ) – The type of names e.g. valid in MPS or LP files.
Task.analyzeproblem(whichstream)
The function analyzes the data of task and writes out a report.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
Task.analyzesolution(whichstream, whichsol)
Print information related to the quality of the solution and other solution statistics.
By default this function prints information about the largest infeasibilites in the solution, the
primal (and possibly dual) objective value and the solution status.
Following parameters can be used to configure the printed statistics:
•iparam.ana_sol_basis enables or disables printing of statistics specific to the basis solution
(condition number, number of basic variables etc.). Default is on.
•iparam.ana_sol_print_violated enables or disables listing names of all constraints (both
primal and dual) which are violated by the solution. Default is off.
•dparam.ana_sol_infeas_tol is the tolerance defining when a constraint is considered vio-
lated. If a constraint is violated more than this, it will be listed in the summary.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
•[in] whichsol (soltype ) – Selects a solution.
Task.appendbarvars(dim)
Appends a positive semidefinite matrix variable of dimension dim to the problem.
Parameters
•[in] dim (int[]) – Dimension of symmetric matrix variables to be added.
Task.appendcone(ct, conepar, submem)
Appends a new conic constraint to the problem. Hence, add a constraint
ˆ∈𝒦
𝑥
𝑥
ˆ = 𝑥submem[0] , . . . , 𝑥submem[nummem−1] .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Please note that the sets of variables appearing in different conic constraints must be disjoint.
For an explained code example see Section 3.3 .
Parameters
•[in] ct (conetype ) – Specifies the type of the cone.
•[in] conepar (double) – This argument is currently not used. It can be set to 0
•[in] submem (int[]) – Variable subscripts of the members in the cone.
Task.appendconeseq(ct, conepar, nummem, j)
Appends a new conic constraint to the problem. The function assumes the members of cone are
sequential where the first member has index j and the last j+nummem-1.
Parameters
•[in] ct (conetype ) – Specifies the type of the cone.
•[in] conepar (double) – This argument is currently not used. It can be set to 0
•[in] nummem (int) – Dimension of the conic constraint to be appended.
•[in] j (int) – Index of the first variable in the conic constraint.
Task.appendconesseq(ct, conepar, nummem, j)
Appends a number conic constraints to the problem. The 𝑘th cone is assumed to be of dimension
nummem[k]. Moreover, is assumed that the first variable of the first cone has index 𝑗 and the index
of the variable in each cone are sequential. Finally, it assumed in the second cone is the last index
of first cone plus one and so forth.
Parameters
•[in] ct (conetype ) – Specifies the type of the cone.
•[in] conepar (double[]) – This argument is currently not used. It can be set to 0
•[in] nummem (int[]) – Number of member variables in the cone.
•[in] j (int) – Index of the first variable in the first cone to be appended.
Task.appendcons(num)
Appends a number of constraints to the model. Appended constraints will be declared free. Please
note that MOSEK will automatically expand the problem dimension to accommodate the addi-
tional constraints.
Parameters
•[in] num (int) – Number of constraints which should be appended.
idx = Task.appendsparsesymmat(dim, subi, subj, valij)
MOSEK maintains a storage of symmetric data matrixes that is used to build the 𝑐¯ and 𝐴. The
storage can be thought of as a vector of symmetric matrixes denoted 𝐸. Hence, 𝐸𝑖 is a symmetric
matrix of certain dimension.
This function appends a general sparse symmetric matrix on triplet form to the vector 𝐸 of sym-
metric matrixes. The vectors subi, subj, and valij contains the row subscripts, column subscripts
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
and values of each element in the symmetric matrix to be appended. Since the matrix that is ap-
pended is symmetric then only the lower triangular part should be specified. Moreover, duplicates
are not allowed.
Observe the function reports the index (position) of the appended matrix in 𝐸. This index should
be used for later references to the appended matrix.
Parameters
•[in] dim (int) – Dimension of the symmetric matrix that is appended.
•[in] subi (int[]) – Row subscript in the triplets.
•[in] subj (int[]) – Column subscripts in the triplets.
•[in] valij (double[]) – Values of each triplet.
Return
•idx (long) – Each matrix that is appended to 𝐸 is assigned a unique index i.e. idx that can
be used for later reference.
Task.appendvars(num)
Appends a number of variables to the model. Appended variables will be fixed at zero. Please note
that MOSEK will automatically expand the problem dimension to accommodate the additional
variables.
Parameters
•[in] num (int) – Number of variables which should be appended.
respavailable, resp, trm = Task.asyncgetresult(server, port, token)
Request a response from a remote job. If successful, solver response, termination code and solutions
are retrieved.
Parameters
•[in] server (str) – Name or IP address of the solver server
•[in] port (str) – Network port of solver service
•[in] token (str) – The task token
Return
•respavailable (int) – Indicates if a remote response is available. If this is not true, res and
trm should be ignored.
•resp (int) – Is either the response code from from the remote solver.
•trm (int) – Is either rescodetype.ok or a termination response code.
token = Task.asyncoptimize(server, port)
Offload the optimization task to a solver server defined by server:port. The call will return
immediately and not wait for the result.
If the string parameter sparam.remote_access_token is not blank, it will be passed to the server
as authentication.
Parameters
•[in] server (str) – Name or IP address of the solver server
•[in] port (str) – Network port of solver service
Return
•token (str) – Returns the task token
respavailable, resp, trm = Task.asyncpoll(server, port, token)
Requests information about the status of the remote job.
Parameters
•[in] server (str) – Name or IP address of the solver server
•[in] port (str) – Network port of solver service
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝒦1 (𝐵) := ‖𝐵‖1 ‖𝐵 −1 |.
Moreover, the larger the condition number is the harder it is to solve linear equation systems
involving 𝐵. Given estimates for ‖𝐵‖1 and ‖𝐵 −1 ‖1 it is also possible to estimate 𝜅1 (𝐵).
Return
•nrmbasis (double) – An estimate for the 1 norm of the basis.
•nrminvbasis (double) – An estimate for the 1 norm of the inverse of the basis.
Task.checkconvexity()
This function checks if a quadratic optimization problem is convex. The amount of checking is
controlled by iparam.check_convexity .
The function reports an error if the problem is not convex.
Task.checkmem(file, line)
Checks the memory allocated by the task.
Parameters
•[in] file (str) – File from which the function is called.
•[in] line (int) – Line in the file from which the function is called.
Task.chgbound(accmode, i, lower, finite, value)
Changes a bound for one constraint or variable. If accmode equals 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:
{︂
−∞, finite = 0,
new lower bound =
value otherwise.
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.
Parameters
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
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.
Parameters
•[in] i (int) – Index of the constraint for which the bounds should be changed.
•[in] lower (int) – If non-zero, then the lower bound is changed, otherwise the upper bound
is changed.
•[in] finite (int) – If non-zero, then value is assumed to be finite.
•[in] value (double) – New value for the bound.
Task.chgvarbound(j, lower, finite, value)
Changes a bound for on variable.
If lower is non-zero, then the lower bound is changed as follows:
{︂
−∞, finite = 0,
new lower bound =
value otherwise.
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.
Parameters
•[in] j (int) – Index of the variable for which the bounds should be changed.
•[in] lower (int) – If non-zero, then the lower bound is changed, otherwise the upper bound
is changed.
•[in] finite (int) – If non-zero, then value is assumed to be finite.
•[in] value (double) – New value for the bound.
Task.commitchanges()
Commits all cached problem changes to the task. It is usually not necessary explicitly to call this
function since changes will be committed automatically when required.
Task.deletesolution(whichsol)
Undefine a solution and frees the memory it uses.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] whichsol (soltype ) – Selects a solution.
Task.dualsensitivity(subj, leftpricej, rightpricej, leftrangej, rightrangej)
Calculates sensitivity information for objective coefficients. The indexes of the coefficients to
analyze are
{subj[𝑖]|𝑖 ∈ 0, . . . , numj − 1}
The results are returned so that e.g leftprice[𝑗] is the left shadow price of the objective coefficient
with index subj[𝑗].
The type of sensitivity analysis to perform (basis or optimal partition) is controlled by the param-
eter iparam.sensitivity_type .
For an example, please see Section 15.1.4 .
Parameters
•[in] subj (int[]) – Index of objective coefficients to analyze.
•[out] leftpricej (double[]) – leftpricej[𝑗] is the left shadow price for the coefficients
with index subj[j].
•[out] rightpricej (double[]) – rightpricej[𝑗] is the right shadow price for the coefficients
with index subj[j].
•[out] leftrangej (double[]) – leftrangej[𝑗] is the left range 𝛽1 for the coefficient with
index subj[j].
•[out] rightrangej (double[]) – rightrangej[𝑗] is the right range 𝛽2 for the coefficient
with index subj[j].
nzj = Task.getacol(j, subj, valj)
Obtains one column of 𝐴 in a sparse format.
Parameters
•[in] j (int) – Index of the column.
•[out] subj (int[]) – Index of the non-zeros in the row obtained.
•[out] valj (double[]) – Numerical values of the column obtained.
Return
•nzj (int) – Number of non-zeros in the column obtained.
nzj = Task.getacolnumnz(i)
Obtains the number of non-zero elements in one column of 𝐴.
Parameters
•[in] i (int) – Index of the column.
Return
•nzj (int) – Number of non-zeros in the 𝑗th row or column of 𝐴.
Task.getacolslicetrip(first, last, subi, subj, val)
Obtains a sequence of columns from 𝐴 in a sparse triplet format.
Parameters
•[in] first (int) – Index of the first column in the sequence.
•[in] last (int) – Index of the last column in the sequence plus one.
•[out] subi (int[]) – Constraint subscripts.
•[out] subj (int[]) – Column subscripts.
•[out] val (double[]) – Values.
aij = Task.getaij(i, j)
Obtains a single coefficient in 𝐴.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] i (int) – Row index of the coefficient to be returned.
•[in] j (int) – Column index of the coefficient to be returned.
Return
•aij (double) – The required coefficient 𝑎𝑖,𝑗 .
numnz = Task.getapiecenumnz(firsti, lasti, firstj, lastj)
Obtains the number non-zeros in a rectangular piece of 𝐴, i.e. the number
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•[in] accmode (accmode ) – Defines whether a column slice or a row slice is requested.
•[in] first (int) – Index of the first row or column in the sequence.
•[in] last (int) – Index of the last row or column in the sequence plus one.
•[out] ptrb (long[]) – ptrb[t] is an index pointing to the first element in the 𝑡th row or
column obtained.
•[out] ptre (long[]) – ptre[t] is an index pointing to the last element plus one in the 𝑡th
row or column obtained.
•[out] sub (int[]) – Contains the row or column subscripts.
•[out] val (double[]) – Contains the coefficient values.
numnz = Task.getaslicenumnz(accmode, first, last)
Obtains the number of non-zeros in a slice of rows or columns of 𝐴.
Parameters
•[in] accmode (accmode ) – Defines whether non-zeros are counted in a column slice or a
row slice.
•[in] first (int) – Index of the first row or column in the sequence.
•[in] last (int) – Index of the last row or column plus one in the sequence.
Return
•numnz (long) – Number of non-zeros in the slice.
num = Task.getbarablocktriplet(subi, subj, subk, subl, valijkl)
Obtains 𝐴 in block triplet form.
Parameters
•[out] subi (int[]) – Constraint index.
•[out] subj (int[]) – Symmetric matrix variable index.
•[out] subk (int[]) – Block row index.
•[out] subl (int[]) – Block column index.
•[out] valijkl (double[]) – A list indexes of the elements from symmetric matrix storage
that appears in the weighted sum.
Return
•num (long) – Number of elements in the block triplet form.
i, j, num = Task.getbaraidx(idx, sub, weights)
Obtains information about an element in 𝐴. Since 𝐴 is a sparse matrix of symmetric matrixes
then only the nonzero elements in 𝐴 are stored in order to save space. Now 𝐴 is stored vectorized
form i.e. as one long vector. This function makes it possible to obtain information such as the row
index and the column index of a particular element of the vectorized form of 𝐴.
Please observe if one element of 𝐴 is inputted multiple times then it may be stored several times
in vectorized form. In that case the element with the highest index is the one that is used.
Parameters
•[in] idx (long) – Position of the element in the vectorized form.
•[out] sub (long[]) – A list indexes of the elements from symmetric matrix storage that
appears in the weighted sum.
•[out] weights (double[]) – The weights associated with each term in the weighted sum.
Return
•i (int) – Row index of the element at position idx.
•j (int) – Column index of the element at position idx.
•num (long) – Number of terms in weighted sum that forms the element.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
i, j = Task.getbaraidxij(idx)
Obtains information about an element in 𝐴. Since 𝐴 is a sparse matrix of symmetric matrixes only
the nonzero elements in 𝐴 are stored in order to save space. Now 𝐴 is stored vectorized form i.e.
as one long vector. This function makes it possible to obtain information such as the row index
and the column index of a particular element of the vectorized form of 𝐴.
Please note that if one element of 𝐴 is inputted multiple times then it may be stored several times
in vectorized form. In that case the element with the highest index is the one that is used.
Parameters
•[in] idx (long) – Position of the element in the vectorized form.
Return
•i (int) – Row index of the element at position idx.
•j (int) – Column index of the element at position idx.
num = Task.getbaraidxinfo(idx)
Each nonzero element in 𝐴𝑖𝑗 is formed as a weighted sum of symmetric matrices. Using
this function the number terms in the weighted sum can be obtained. See description of
task.appendsparsesymmat for details about the weighted sum.
Parameters
•[in] idx (long) – The internal position of the element that should be obtained information
for.
Return
•num (long) – Number of terms in the weighted sum that forms the specified element in 𝐴.
numnz = Task.getbarasparsity(idxij)
The matrix 𝐴 is assumed to be a sparse matrix of symmetric matrices. This implies that many of
elements in 𝐴 is likely to be zero matrixes. Therefore, in order to save space only nonzero elements
in 𝐴 are stored on vectorized form. This function is used to obtain the sparsity pattern of 𝐴 and
the position of each nonzero element in the vectorized form of 𝐴.
Parameters
•[out] idxij (long[]) – Position of each nonzero element in the vectorized form of 𝐴𝑖𝑗 .
Hence, idxij[k] is the vector position of the element in row subi[k] and column subj[k]
of 𝐴𝑖𝑗 .
Return
•numnz (long) – Number of nonzero elements in 𝐴.
num = Task.getbarcblocktriplet(subj, subk, subl, valijkl)
Obtains 𝐶 in block triplet form.
Parameters
•[out] subj (int[]) – Symmetric matrix variable index.
•[out] subk (int[]) – Block row index.
•[out] subl (int[]) – Block column index.
•[out] valijkl (double[]) – A list indexes of the elements from symmetric matrix storage
that appears in the weighted sum.
Return
•num (long) – Number of elements in the block triplet form.
j, num = Task.getbarcidx(idx, sub, weights)
Obtains information about an element in 𝑐¯.
Parameters
•[in] idx (long) – Index of the element that should be obtained information about.
•[out] sub (long[]) – Elements appearing the weighted sum.
•[out] weights (double[]) – Weights of terms in the weighted sum.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Return
•j (int) – Row index in 𝑐¯.
•num (long) – Number of terms in the weighted sum.
num = Task.getbarcidxinfo(idx)
Obtains information about the 𝑐¯𝑖𝑗 .
Parameters
•[in] idx (long) – Index of element that should be obtained information about. The value
is an index of a symmetric sparse variable.
Return
•num (long) – Number of terms that appears in weighted that forms the requested element.
j = Task.getbarcidxj(idx)
Obtains the row index of an element in 𝑐¯.
Parameters
•[in] idx (long) – Index of the element that should be obtained information about.
Return
•j (int) – Row index in 𝑐¯.
numnz = Task.getbarcsparsity(idxj)
Internally only the nonzero elements of 𝑐¯ is stored
in a vector. This function returns which elements 𝑐¯ that are nonzero (in subj) and their internal
position (in idx). Using the position detailed information about each nonzero 𝐶 𝑗 can be obtained
using task.getbarcidxinfo and task.getbarcidx .
Parameters
•[out] idxj (long[]) – Internal positions of the nonzeros elements in 𝑐¯.
Return
•numnz (long) – Number of nonzero elements in 𝐶.
Task.getbarsj(whichsol, j, barsj)
Obtains the dual solution for a semidefinite variable. Only the lower triangle part of 𝑠¯𝑗 is returned
because the matrix by construction is symmetric. The format is that the columns are stored
sequentially in the natural order.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] j (int) – Index of the semidefinite variable.
•[out] barsj (double[]) – Value of 𝑠¯𝑗 .
name = Task.getbarvarname(i)
Obtains a name of a semidefinite variable.
Parameters
•[in] i (int) – Index.
Return
•name (str) – The requested name is copied to this buffer.
asgn, index = Task.getbarvarnameindex(somename)
Obtains the index of name of semidefinite variable.
Parameters
•[in] somename (str) – The requested name is copied to this buffer.
Return
•asgn (int) – Is non-zero if the name somename is assigned to a semidefinite variable.
•index (int) – If the name somename is assigned to a semidefinite variable, then index is the
name of the constraint.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
len = Task.getbarvarnamelen(i)
Obtains the length of a name of a semidefinite variable.
Parameters
•[in] i (int) – Index.
Return
•len (int) – Returns the length of the indicated name.
Task.getbarxj(whichsol, j, barxj)
Obtains the primal solution for a semidefinite variable. Only the lower triangle part of 𝑥
¯𝑗 is
returned because the matrix by construction is symmetric. The format is that the columns are
stored sequentially in the natural order.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] j (int) – Index of the semidefinite variable.
•[out] barxj (double[]) – Value of 𝑋 𝑗 .
bk, bl, bu = Task.getbound(accmode, i)
Obtains bound information for one constraint or variable.
Parameters
•[in] accmode (accmode ) – Defines if operations are performed row-wise (constraint-
oriented) or column-wise (variable-oriented).
•[in] i (int) – Index of the constraint or variable for which the bound information should
be obtained.
Return
•bk (int) – Bound keys.
•bl (double) – Values for lower bounds.
•bu (double) – Values for upper bounds.
Task.getboundslice(accmode, first, last, bk, bl, bu)
Obtains bounds information for a sequence of variables or constraints.
Parameters
•[in] accmode (accmode ) – Defines if operations are performed row-wise (constraint-
oriented) or column-wise (variable-oriented).
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
•[out] bk (boundkey ) – Bound keys.
•[out] bl (double[]) – Values for lower bounds.
•[out] bu (double[]) – Values for upper bounds.
Task.getc(c)
Obtains all objective coefficients 𝑐.
Parameters
•[out] c (double[]) – Linear terms of the objective as a dense vector. The lengths is the
number of variables.
cfix = Task.getcfix()
Obtains the fixed term in the objective.
Return
•cfix (double) – Fixed term in the objective.
cj = Task.getcj(j)
Obtains one coefficient of 𝑐.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] j (int) – Index of the variable for which 𝑐 coefficient should be obtained.
Return
•cj (double) – The value of 𝑐𝑗 .
bk, bl, bu = Task.getconbound(i)
Obtains bound information for one constraint.
Parameters
•[in] i (int) – Index of the constraint for which the bound information should be obtained.
Return
•bk (int) – Bound keys.
•bl (double) – Values for lower bounds.
•bu (double) – Values for upper bounds.
Task.getconboundslice(first, last, bk, bl, bu)
Obtains bounds information for a slice of the constraints.
Parameters
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
•[out] bk (boundkey ) – Bound keys.
•[out] bl (double[]) – Values for lower bounds.
•[out] bu (double[]) – Values for upper bounds.
ct, conepar, nummem = Task.getcone(k, submem)
Obtains a conic constraint.
Parameters
•[in] k (int) – Index of the cone constraint.
•[out] submem (int[]) – Variable subscripts of the members in the cone.
Return
•ct (int) – Specifies the type of the cone.
•conepar (double) – This argument is currently not used. It can be set to 0
•nummem (int) – Number of member variables in the cone.
ct, conepar, nummem = Task.getconeinfo(k)
Obtains information about a conic constraint.
Parameters
•[in] k (int) – Index of the conic constraint.
Return
•ct (int) – Specifies the type of the cone.
•conepar (double) – This argument is currently not used. It can be set to 0
•nummem (int) – Number of member variables in the cone.
name = Task.getconename(i)
Obtains a name of a cone.
Parameters
•[in] i (int) – Index.
Return
•name (str) – Is assigned the required name.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Return
•dimbarvarj (int) – The dimension of the j’th semidefinite variable.
dvalue = Task.getdouinf(whichdinf)
Obtains a double information item from the task information database.
Parameters
•[in] whichdinf (dinfitem ) – A double float information item.
Return
•dvalue (double) – The value of the required double information item.
parvalue = Task.getdouparam(param)
Obtains the value of a double parameter.
Parameters
•[in] param (dparam ) – Which parameter.
Return
•parvalue (double) – Parameter value.
dualobj = Task.getdualobj(whichsol)
Computes the dual objective value associated with the solution. Note if the solution is a primal inf
Moreover, since there is no dual solution associated with integer solution, then an error will
be reported if the dual objective value is requested for the integer solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
Return
•dualobj (double) – Objective value corresponding to the dual solution.
nrmy, nrmslc, nrmsuc, nrmslx, nrmsux, nrmsnx, nrmbars = Task.getdualsolutionnorms(whichsol)
Compute norms of the primal solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
Return
•nrmy (double) – The norm of the y vector.
•nrmslc (double) – The norm of the slc vector.
•nrmsuc (double) – The norm of the suc vector.
•nrmslx (double) – The norm of the slx vector.
•nrmsux (double) – The norm of the sux vector.
•nrmsnx (double) – The norm of the snx vector.
•nrmbars (double) – The norm of the bars vector.
Task.getdviolbarvar(whichsol, sub, viol)
Let (𝑆¯𝑗 )* be the value of variable 𝑆¯𝑗 for the specified solution. Then the dual violation of the
solution associated with variable 𝑆¯𝑗 is given by
Both when the solution is a certificate of primal infeasibility or when it is dual feasibleness solution
the violation should be small.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of 𝑋 variables.
•[out] viol (double[]) – viol[k] is violation of the solution for the constraint 𝑆¯sub[𝑘] ∈ 𝒮+ .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
max(𝜌((𝑠𝑐𝑙 )*𝑖 , (𝑏𝑐𝑙 )𝑖 ), 𝜌((𝑠𝑐𝑢 )*𝑖 , −(𝑏𝑐𝑢 )𝑖 ), | − 𝑦𝑖 + (𝑠𝑐𝑙 )*𝑖 − (𝑠𝑐𝑢 )*𝑖 |)
where
{︂
−𝑥, 𝑙 > −∞,
𝜌(𝑥, 𝑙) =
|𝑥|, otherwise
Both when the solution is a certificate of primal infeasibility or it is a dual feasibleness solution the
violation should be small.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of constraints.
•[out] viol (double[]) – viol[k] is the violation of dual solution associated with the con-
straint sub[k].
Task.getdviolcones(whichsol, sub, viol)
Let (𝑠𝑥𝑛 )* be the value of variable (𝑠𝑥𝑛 ) for the specified solution. For simplicity let us assume that
𝑠𝑥𝑛 is a member of quadratic cone, then the violation is computed as follows
√
max(0, ‖(𝑠𝑥𝑛 ‖*2;𝑛 − (𝑠𝑥𝑛 )*1 )/ 2, (𝑠𝑥𝑛 )* ≥ −‖(𝑠𝑥𝑛 )*2:𝑛 ‖,
{︂
‖(𝑠𝑥𝑛 )* ‖, otherwise.
Both when the solution is a certificate of primal infeasibility or when it is a dual feasibleness
solution the violation should be small.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of 𝑋 variables.
•[out] viol (double[]) – viol[k] violation of the solution associated with sub[k]‘th dual
conic constraint.
Task.getdviolvar(whichsol, sub, viol)
The violation of the dual solution associated with the 𝑗‘th variable is computed as follows
⎛ ⎞
𝑛𝑢𝑚𝑐𝑜𝑛−1
∑︁
max ⎝𝜌((𝑠𝑥𝑙 )*𝑖 , (𝑏𝑥𝑙 )𝑖 ), 𝜌((𝑠𝑥𝑢 )*𝑖 , −(𝑏𝑥𝑢 )𝑖 ), | 𝑎𝑖𝑗 𝑦𝑖 + (𝑠𝑥𝑙 )*𝑖 − (𝑠𝑥𝑢 )*𝑖 − 𝜏 𝑐𝑗 |⎠
𝑗=0
where
{︂
−𝑥, 𝑙 > −∞,
𝜌(𝑥, 𝑙) =
|𝑥|, otherwise
𝜏 = 0 if the solution is certificate of dual infeasibility and 𝜏 = 1 otherwise. The formula for
computing the violation is only shown for linear case but is generalized appropriately for the more
general problems.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of 𝑥 variables.
•[out] viol (double[]) – viol[k] is the maximal violation of the solution for the constraints
(𝑠𝑥𝑙 )sub[𝑘] ≥ 0 and (𝑠𝑥𝑢 )sub[𝑘] ≥ 0.
inftask = Task.getinfeasiblesubproblem(whichsol)
Given the solution is a certificate of primal or dual infeasibility then a primal or dual infeasible
subproblem is obtained respectively. The subproblem tend to be much smaller than the original
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
problem and hence it easier to locate the infeasibility inspecting the subproblem than the original
problem.
For the procedure to be useful then it is important to assigning meaningful names to constraints,
variables etc. in the original task because those names will be duplicated in the subproblem.
The function is only applicable to linear and conic quadratic optimization problems.
For more information see Section 14 .
Parameters
•[in] whichsol (soltype ) – Which solution to use when determining the infeasible sub-
problem.
Return
•inftask (Task) – A new task containing the infeasible subproblem.
ivalue = Task.getintinf(whichiinf)
Obtains an integer information item from the task information database.
Parameters
•[in] whichiinf (iinfitem ) – Specifies an information item.
Return
•ivalue (int) – The value of the required integer information item.
parvalue = Task.getintparam(param)
Obtains the value of an integer parameter.
Parameters
•[in] param (iparam ) – Which parameter.
Return
•parvalue (int) – Parameter value.
lenbarvarj = Task.getlenbarvarj(j)
Obtains the length of the 𝑗th semidefinite variable i.e. the number of elements in the triangular
part.
Parameters
•[in] j (int) – Index of the semidefinite variable whose length if requested.
Return
•lenbarvarj (long) – Number of scalar elements in the lower triangular part of the semidefinite
variable.
ivalue = Task.getlintinf(whichliinf)
Obtains an integer information item from the task information database.
Parameters
•[in] whichliinf (liinfitem ) – Specifies an information item.
Return
•ivalue (long) – The value of the required integer information item.
maxnumanz = Task.getmaxnumanz()
Obtains number of preallocated non-zeros in 𝐴. When this number of non-zeros is reached
MOSEK will automatically allocate more space for 𝐴.
Return
•maxnumanz (long) – Number of preallocated non-zero linear matrix elements.
maxnumbarvar = Task.getmaxnumbarvar()
Obtains maximum number of symmetric matrix variables that is reservered room for.
Return
•maxnumbarvar (int) – Maximum number of symmetric matrix variables currently that is
reservered room for.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
maxnumcon = Task.getmaxnumcon()
Obtains the number of preallocated constraints in the optimization task. When this number of
constraints is reached MOSEK will automatically allocate more space for constraints.
Return
•maxnumcon (int) – Number of preallocated constraints in the optimization task.
maxnumcone = Task.getmaxnumcone()
Obtains the number of preallocated cones in the optimization task. When this number of cones is
reached MOSEK will automatically allocate space for more cones.
Return
•maxnumcone (int) – Number of preallocated conic constraints in the optimization task.
maxnumqnz = Task.getmaxnumqnz()
Obtains the number of preallocated non-zeros for 𝑄 (both objective and constraints). When this
number of non-zeros is reached MOSEK will automatically allocate more space for 𝑄.
Return
•maxnumqnz (long) – Number of non-zero elements preallocated in quadratic coefficient matri-
ces.
maxnumvar = Task.getmaxnumvar()
Obtains the number of preallocated variables in the optimization task. When this number of
variables is reached MOSEK will automatically allocate more space for constraints.
Return
•maxnumvar (int) – Number of preallocated variables in the optimization task.
meminuse, maxmemuse = Task.getmemusage()
Obtains information about the amount of memory used by a task.
Return
•meminuse (long) – Amount of memory currently used by the task.
•maxmemuse (long) – Maximum amount of memory used by the task until now.
numanz = Task.getnumanz()
Obtains the number of non-zeros in 𝐴.
Return
•numanz (int) – Number of non-zero elements in the linear constraint matrix.
numanz = Task.getnumanz64()
Obtains the number of non-zeros in 𝐴.
Return
•numanz (long) – Number of non-zero elements in the linear constraint matrix.
num = Task.getnumbarablocktriplets()
Obtains an upper bound on the number of elements in the block triplet form of 𝐴.
Return
•num (long) – Number elements in the block triplet form of 𝐴.
nz = Task.getnumbaranz()
Get the number of nonzero elements in 𝐴.
Return
•nz (long) – The number of nonzero elements in 𝐴 i.e. the number of 𝑎
¯𝑖𝑗 elements that is
nonzero.
num = Task.getnumbarcblocktriplets()
Obtains an upper bound on the number of elements in the block triplet form of 𝐶.
Return
•num (long) – An upper bound on the number elements in the block trip let form of 𝑐¯.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
nz = Task.getnumbarcnz()
Obtains the number of nonzero elements in 𝑐¯.
Return
•nz (long) – The number of nonzeros in 𝑐¯ i.e. the number of elements 𝑐¯𝑗 that is different from
0.
numbarvar = Task.getnumbarvar()
Obtains the number of semidefinite variables.
Return
•numbarvar (int) – Number of semidefinite variable in the problem.
numcon = Task.getnumcon()
Obtains the number of constraints.
Return
•numcon (int) – Number of constraints.
numcone = Task.getnumcone()
Obtains the number of cones.
Return
•numcone (int) – Number conic constraints.
nummem = Task.getnumconemem(k)
Obtains the number of members in a cone.
Parameters
•[in] k (int) – Index of the cone.
Return
•nummem (int) – Number of member variables in the cone.
numintvar = Task.getnumintvar()
Obtains the number of integer-constrained variables.
Return
•numintvar (int) – Number of integer variables.
numparam = Task.getnumparam(partype)
Obtains the number of parameters of a given type.
Parameters
•[in] partype (parametertype ) – Parameter type.
Return
•numparam (int) – Identical to the number of parameters of the type partype.
numqcnz = Task.getnumqconknz(k)
Obtains the number of non-zero quadratic terms in a constraint.
Parameters
•[in] k (int) – Index of the constraint for which the number quadratic terms should be
obtained.
Return
•numqcnz (long) – Number of quadratic terms.
numqonz = Task.getnumqobjnz()
Obtains the number of non-zero quadratic terms in the objective.
Return
•numqonz (long) – Number of non-zero elements in the quadratic objective terms.
num = Task.getnumsymmat()
Get the number of symmetric matrixes stored in the vector 𝐸.
Return
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
max(−𝜆min (𝑋 𝑗 ), 0.0).
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of 𝑋 variables.
•[out] viol (double[]) – viol[k] is how much the solution violate the constraint 𝑋 sub[𝑘] ∈
𝒮+ .
Task.getpviolcon(whichsol, sub, viol)
The primal violation of the solution associated of constraint is computed by
𝑛𝑢𝑚𝑣𝑎𝑟−1
∑︁
max(𝑙𝑖𝑐 𝜏 − (𝑥𝑐𝑖 )* ), (𝑥𝑐𝑖 )* 𝜏 − 𝑢𝑐𝑖 𝜏, | 𝑎𝑖𝑗 𝑥*𝑗 − 𝑥𝑐𝑖 |)
𝑗=0
where 𝜏 is defined as follows. If the solution is a certificate of dual infeasibility, then 𝜏 = 0 and
otherwise 𝜏 = 1. Both when the solution is a valid certificate of dual infeasibility or when it is
primal feasibleness solution the violation should be small. The above is only shown for linear case
but is appropriately generalized for the other cases.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of constraints.
•[out] viol (double[]) – viol[k] associated with the solution for the sub[k]‘th constraint.
Task.getpviolcones(whichsol, sub, viol)
Let 𝑥* be the value of variable 𝑥 for the specified solution. For simplicity let us assume that 𝑥 is
a member of quadratic cone, then the violation is computed as follows
{︂ √
max(0, ‖𝑥2;𝑛 ‖ − 𝑥1 )/ 2, 𝑥1 ≥ −‖𝑥2:𝑛 ‖,
‖𝑥‖, otherwise.
Both when the solution is a certificate of dual infeasibility or when it is a primal feasibleness
solution the violation should be small.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of 𝑋 variables.
•[out] viol (double[]) – viol[k] violation of the solution associated with sub[k]‘th conic
constraint.
Task.getpviolvar(whichsol, sub, viol)
Let 𝑥*𝑗 be the value of variable 𝑥𝑗 for the specified solution. Then the primal violation of the
solution associated with variable 𝑥𝑗 is given by
where 𝜏 is defined as follows. If the solution is a certificate of dual infeasibility, then 𝜏 = 0 and
otherwise 𝜏 = 1. Both when the solution is a valid certificate of dual infeasibility or when it is
primal feasibleness solution the violation should be small.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] sub (int[]) – An array of indexes of 𝑥 variables.
•[out] viol (double[]) – viol[k] is the violation associated the solution for variable 𝑥𝑗 .
numqcnz = Task.getqconk(k, qcsubi, qcsubj, qcval)
Obtains all the quadratic terms in a constraint. The quadratic terms are stored sequentially qcsubi,
qcsubj, and qcval.
Parameters
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – See formula (16.2) for the definition.
•[in] last (int) – See formula (16.2) for the definition.
•[out] redcosts (double[]) – The reduced costs in the required sequence of variables are
stored sequentially in redcosts starting at redcosts[\idxbeg].
Task.getskc(whichsol, skc)
Obtains the status keys for the constraints.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[out] skc (stakey ) – Status keys for the constraints.
Task.getskcslice(whichsol, first, last, skc)
Obtains the status keys for the constraints.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
•[out] snx (double[]) – Dual variables corresponding to the conic constraints on the vari-
ables.
solsta = Task.getsolsta(whichsol)
Obtains the solution status.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
Return
•solsta (int) – Solution status.
prosta, solsta = Task.getsolution(whichsol, skc, skx, skn, xc, xx, y, slc, suc, slx, sux,
snx)
Obtains the complete solution.
Consider the case of linear programming. The primal problem is given by
minimize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐
≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 .
In this case the mapping between variables and arguments to the function is as follows:
•xx : Corresponds to variable 𝑥.
•y : Corresponds to variable 𝑦.
•slc: Corresponds to variable 𝑠𝑐𝑙 .
•suc: Corresponds to variable 𝑠𝑐𝑢 .
•slx: Corresponds to variable 𝑠𝑥𝑙 .
•sux: Corresponds to variable 𝑠𝑥𝑢 .
•xc : Corresponds to 𝐴𝑥.
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:
•solsta.optimal : An optimal solution satisfying the optimality criteria for continuous prob-
lems is returned.
•solsta.integer_optimal : An optimal solution satisfying the optimality criteria for integer
problems is returned.
•solsta.prim_feas : A solution satisfying the feasibility criteria.
•solsta.prim_infeas_cer : A primal certificate of infeasibility is returned.
•solsta.dual_infeas_cer : A dual certificate of infeasibility is returned.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•pviolitg (double) – Maximal violation in the integer constraints. The violation for an integer
constrained variable 𝑥𝑗 is given by
This number is always zero for the interior-point and the basic solutions.
•dobj (double) – Dual objective value as computed as computed by task.getdualobj .
•dviolcon (double) – Maximal violation of the dual solution associated with the 𝑥𝑐 variable
as computed by as computed by task.getdviolcon .
•dviolvar (double) – Maximal violation of the dual solution associated with the 𝑥 variable as
computed by as computed by task.getdviolvar .
•dviolbarvar (double) – Maximal violation of the dual solution associated with the 𝑠¯ variable
as computed by as computed by task.getdviolbarvar .
•dviolcone (double) – Maximal violation of the dual solution associated with the dual conic
constraints as computed by task.getdviolcones .
Task.getsolutionslice(whichsol, solitem, first, last, values)
Obtains a slice of the solution.
Consider the case of linear programming. The primal problem is given by
minimize 𝑐𝑇 𝑥 + 𝑐𝑓
subject to 𝑙𝑐
≤ 𝐴𝑥 ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 .
This introduces one additional dual variable 𝑠𝑥𝑛 . This variable can be acceded by selecting solitem
as solitem.snx .
The meaning of the values returned by this function also depends on the solution status which can
be obtained with task.getsolsta . Depending on the solution status value will be:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•solsta.optimal A part of the optimal solution satisfying the optimality criteria for contin-
uous problems.
•solsta.integer_optimal A part of the optimal solution satisfying the optimality criteria
for integer problems.
•solsta.prim_feas A part of the solution satisfying the feasibility criteria.
•solsta.prim_infeas_cer A part of the primal certificate of infeasibility.
•solsta.dual_infeas_cer A part of the dual certificate of infeasibility.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] solitem (solitem ) – Which part of the solution is required.
•[in] first (int) – Index of the first value in the slice.
•[in] last (int) – value of the last index+1 in the slice, e.g. if 𝑥𝑥[5, . . . , 9] is required last
should be 10.
•[out] values (double[]) – The values in the required sequence are stored sequentially in
values starting at values[\idxbeg].
Task.getsparsesymmat(idx, subi, subj, valij)
Get a single symmetric matrix from the matrix store.
Parameters
•[in] idx (long) – Index of the matrix to get.
•[out] subi (int[]) – Row subscripts of the matrix non-zero elements.
•[out] subj (int[]) – Column subscripts of the matrix non-zero elements.
•[out] valij (double[]) – Coefficients of the matrix non-zero elements.
len, parvalue = Task.getstrparam(param)
Obtains the value of a string parameter.
Parameters
•[in] param (sparam ) – Which parameter.
Return
•len (int) – The length of the parameter value.
•parvalue (str) – If this is not NULL, the parameter value is stored here.
len = Task.getstrparamlen(param)
Obtains the length of a string parameter.
Parameters
•[in] param (sparam ) – Which parameter.
Return
•len (int) – The length of the parameter value.
Task.getsuc(whichsol, suc)
Obtains the 𝑠𝑐𝑢 vector for a solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[out] suc (double[]) – The 𝑠𝑐𝑢 vector.
Task.getsucslice(whichsol, first, last, suc)
Obtains a slice of the 𝑠𝑐𝑢 vector for a solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•[in] wux (double[]) – (𝑤𝑙𝑥 )𝑖 is the weight associated with relaxing the upper bound on
variable 𝑗. If the weight is negative, then the upper bound is not relaxed. Moreover, if the
argument is NULL, then all the weights are assumed to be 1.
Task.primalsensitivity(subi, marki, subj, markj, leftpricei, rightpricei, leftrangei,
rightrangei, leftpricej, rightpricej, leftrangej, 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
Section 15 .
The constraints for which sensitivity analysis is performed are given by the data structures:
1.subi Index of constraint to analyze.
2.marki Indicate for which bound of constraint subi[i] sensitivity analysis is performed. If
marki[i] = mark.up the upper bound of constraint subi[i] is analyzed, and if marki[i] =
mark.lo the lower bound is analyzed. If subi[i] is an equality constraint, either mark.lo
or mark.up can be used to select the constraint for sensitivity analysis.
Consider the problem:
minimize 𝑥1 + 𝑥2
subject to − 1 ≤ 𝑥1 − 𝑥2 ≤ 1,
𝑥1 = 0,
𝑥1 ≥ 0, 𝑥2 ≥ 0
Suppose that
•numi = 1;
•subi = [0];
•marki = [mark.up ]
then
leftpricei[0], rightpricei[0], leftrangei[0] and rightrangei[0] will contain the sensitiv-
ity information for the upper bound on constraint 0 given by the expression:
𝑥1 − 𝑥2 ≤ 1
Similarly, the variables for which to perform sensitivity analysis are given by the structures:
1.subj Index of variables to analyze.
2.markj Indicate for which bound of variable subi[j] sensitivity analysis is performed. If
markj[j] = mark.up the upper bound of constraint subi[j] is analyzed, and if markj[j] =
mark.lo the lower bound is analyzed.
3.If subi[j] is an equality constraint, either mark.lo or mark.up can be used to select the
constraint for sensitivity analysis.
For an example, please see Section 15.1.4 .
The type of sensitivity analysis to be performed (basis or optimal partition) is controlled by the
parameter iparam.sensitivity_type .
Parameters
•[in] subi (int[]) – Indexes of bounds on constraints to analyze.
•[in] marki (mark ) – The value of marki[i] specifies for which bound (upper or lower) on
constraint subi[i] sensitivity analysis should be performed.
•[in] subj (int[]) – Indexes of bounds on variables to analyze.
•[in] markj (mark ) – The value of markj[j] specifies for which bound (upper or lower) on
variable subj[j] sensitivity analysis should be performed.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•[out] leftpricei (double[]) – leftpricei[i] is the left shadow price for the upper/lower
bound (indicated by marki[i]) of the constraint with index subi[i].
•[out] rightpricei (double[]) – rightpricei[i] is the right shadow price for the up-
per/lower bound (indicated by marki[i]) of the constraint with index subi[i].
•[out] leftrangei (double[]) – leftrangei[i] is the left range for the upper/lower bound
(indicated by marki[i]) of the constraint with index subi[i].
•[out] rightrangei (double[]) – rightrangei[i] is the right range for the upper/lower
bound (indicated by marki[i]) of the constraint with index subi[i].
•[out] leftpricej (double[]) – leftpricej[j] is the left shadow price for the upper/lower
bound (indicated by marki[j]) on variable subj[j].
•[out] rightpricej (double[]) –
rightpricej[j] is the right shadow price for the upper/lower bound (indicated by marki[j])
on variable subj[j].
•[out] leftrangej (double[]) –
leftrangej[j] is the left range for the upper/lower bound (indicated by marki[j])
on variable subj[j].
•[out] rightrangej (double[]) – rightrangej[j] is the right range for the upper/lower
bound (indicated by marki[j]) on variable subj[j].
Task.printdata(whichstream, firsti, lasti, firstj, lastj, firstk, lastk, c, qo, a, qc, bc,
bx, vartype, cones)
Prints a part of the problem data to a stream. This function is normally used for debugging
purposes only, e.g. to verify that the correct data has been inputted.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
•[in] firsti (int) – Index of first constraint for which data should be printed.
•[in] lasti (int) – Index of last constraint plus 1 for which data should be printed.
•[in] firstj (int) – Index of first variable for which data should be printed.
•[in] lastj (int) – Index of last variable plus 1 for which data should be printed.
•[in] firstk (int) – Index of first cone for which data should be printed.
•[in] lastk (int) – Index of last cone plus 1 for which data should be printed.
•[in] c (int) – If non-zero 𝑐 is printed.
•[in] qo (int) – If non-zero 𝑄𝑜 is printed.
•[in] a (int) – If non-zero 𝐴 is printed.
•[in] qc (int) – If non-zero 𝑄𝑘 is printed for the relevant constraints.
•[in] bc (int) – If non-zero the constraints bounds are printed.
•[in] bx (int) – If non-zero the variable bounds are printed.
•[in] vartype (int) – If non-zero the variable types are printed.
•[in] cones (int) – If non-zero the conic data is printed.
Task.putacol(j, subj, valj)
Resets all the elements in column 𝑗 to zero and then do
Parameters
•[in] j (int) – Index of column in 𝐴.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
for 𝑖 = 0, . . . , 𝑛𝑢𝑚 − 1
𝑎asub[𝑘],sub[𝑖] = aval[𝑘], 𝑘 = aptrb[𝑖], . . . , aptre[𝑖] − 1.
Parameters
•[in] sub (int[]) – Indexes of columns that should be replaced. comp should not contain
duplicate values.
•[in] ptrb (long[]) – Array of pointers to the first element in the columns stored in comp
and comp.
For an explanation of the meaning of comp see Section 16.1.3.2 .
•[in] ptre (long[]) – Array of pointers to the last element plus one in the columns stored
in comp and comp.
For an explanation of the meaning of comp see Section 16.1.3.2 .
•[in] asub (int[]) – comp contains the new variable indexes.
•[in] aval (double[]) – Coefficient values.
Task.putacolslice(first, last, ptrb, ptre, asub, aval)
Replaces all elements in a set of columns of 𝐴.
Parameters
•[in] first (int) – First column in the slice.
•[in] last (int) – Last column plus one in the slice.
•[in] ptrb (long[]) – Array of pointers to the first element in the columns stored in comp
and comp.
For an explanation of the meaning of comp see Section 16.1.3.2 .
•[in] ptre (long[]) – Array of pointers to the last element plus one in the columns stored
in comp and comp.
For an explanation of the meaning of comp see Section 16.1.3.2 .
•[in] asub (int[]) – comp contains the new variable indexes.
•[in] aval (double[]) – Coefficient values.
Task.putaij(i, j, aij)
Changes a coefficient in 𝐴 using the method
𝑎ij = aij.
Parameters
•[in] i (int) – Index of the constraint in which the change should occur.
•[in] j (int) – Index of the variable in which the change should occur.
•[in] aij (double) – New coefficient for 𝑎𝑖,𝑗 .
Task.putaijlist(subi, subj, valij)
Changes one or more coefficients in 𝐴 using the method
Parameters
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
•[in] subi (int[]) – Constraint indexes in which the change should occur.
•[in] subj (int[]) – Variable indexes in which the change should occur.
•[in] valij (double[]) – New coefficient values for 𝑎𝑖,𝑗 .
Task.putarow(i, subi, vali)
Resets all the elements in row 𝑖 to zero and then do
Parameters
•[in] i (int) – Index of row in 𝐴.
•[in] subi (int[]) – Row indexes of non-zero values in row 𝑖 of 𝐴.
•[in] vali (double[]) – New non-zero values of row 𝑖 in 𝐴.
Task.putarowlist(sub, ptrb, ptre, asub, aval)
Replaces all elements in a set of rows of 𝐴. The elements are replaced as follows
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] num (long) – Number of elements in the block triplet form.
•[in] subi (int[]) – Constraint index.
•[in] subj (int[]) – Symmetric matrix variable index.
•[in] subk (int[]) – Block row index.
•[in] subl (int[]) – Block column index.
•[in] valijkl (double[]) – The numerical value associated with the block triplet.
Task.putbaraij(i, j, sub, weights)
This function puts one element associated with 𝑋 𝑗 in the 𝐴 matrix.
Each element in the 𝐴 matrix is a weighted sum of symmetric matrixes, i.e. 𝐴𝑖𝑗 is a symmetric
matrix with dimensions as 𝑋 𝑗 . By default all elements in 𝐴 are 0, so only non-zero elements need
be added.
Setting the same elements again will overwrite the earlier entry.
The symmetric matrixes themselves are defined separately using the function
task.appendsparsesymmat .
Parameters
•[in] i (int) – Row index of 𝐴.
•[in] j (int) – Column index of 𝐴.
•[in] sub (long[]) – See argument weights for an explanation.
•[in] weights (double[]) – weights[k] times sub[k]‘th term of 𝐸 is added to 𝐴𝑖𝑗 .
Task.putbarcblocktriplet(num, subj, subk, subl, valjkl)
Inputs the 𝐶 in block triplet form.
Parameters
•[in] num (long) – Number of elements in the block triplet form.
•[in] subj (int[]) – Symmetric matrix variable index.
•[in] subk (int[]) – Block row index.
•[in] subl (int[]) – Block column index.
•[in] valjkl (double[]) – The numerical value associated with the block triplet.
Task.putbarcj(j, sub, weights)
This function puts one element associated with 𝑋 𝑗 in the 𝑐¯ vector.
Each element in the 𝑐¯ vector is a weighted sum of symmetric matrixes, i.e. 𝑐¯𝑗 is a symmetric matrix
with dimensions as 𝑋 𝑗 . By default all elements in 𝑐¯ are 0, so only non-zero elements need be added.
Setting the same elements again will overwrite the earlier entry.
The symmetric matrixes themselves are defined separately using the function
task.appendsparsesymmat .
Parameters
•[in] j (int) – Index of the element in 𝑐¯ that should be changed.
•[in] sub (long[]) – sub is list of indexes of those symmetric matrices appearing in sum.
•[in] weights (double[]) – The weights of the terms in the weighted sum that forms c𝑗 .
Task.putbarsj(whichsol, j, barsj)
Sets the dual solution for a semidefinite variable.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑐j = cj.
Parameters
•[in] j (int) – Index of the variable for which 𝑐 should be changed.
•[in] cj (double) – New value of 𝑐𝑗 .
Task.putclist(subj, val)
Modifies elements in the linear term 𝑐 in the objective using the principle
If a variable index is specified multiple times in subj only the last entry is used.
Parameters
•[in] subj (int[]) – Index of variables for which 𝑐 should be changed.
•[in] val (double[]) – New numerical values for coefficients in 𝑐 that should be modified.
Task.putconbound(i, bk, bl, bu)
Changes the bounds for one constraint.
If the a bound value specified is numerically larger than dparam.data_tol_bound_inf it is consid-
ered infinite and the bound key is changed accordingly. If a bound value is numerically larger than
dparam.data_tol_bound_wrn , a warning will be displayed, but the bound is inputted as specified.
Parameters
•[in] i (int) – Index of the constraint.
•[in] bk (boundkey ) – New bound key.
•[in] bl (double) – New lower bound.
•[in] bu (double) – New upper bound.
Task.putconboundlist(sub, bkc, blc, buc)
Changes the bounds for a list of constraints. If multiple bound changes are specified for a constraint,
then only the last change takes effect.
Parameters
•[in] sub (int[]) – List constraints indexes.
•[in] bkc (boundkey ) – New bound keys.
•[in] blc (double[]) – New lower bound values.
•[in] buc (double[]) – New upper bound values.
Task.putconboundslice(first, last, bk, bl, bu)
Changes the bounds for a slice of the constraints.
Parameters
•[in] first (int) – Index of the first constraint in the slice.
•[in] last (int) – Index of the last constraint in the slice plus 1.
•[in] bk (boundkey ) – New bound keys.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Parameters
•[in] first (int) – First element in the slice of 𝑐.
•[in] last (int) – Last element plus 1 of the slice in 𝑐 to be changed.
•[in] slice (double[]) – New numerical values for coefficients in 𝑐 that should be modified.
Task.putdouparam(param, parvalue)
Sets the value of a double parameter.
Parameters
•[in] param (dparam ) – Which parameter.
•[in] parvalue (double) – Parameter value.
Task.putintparam(param, parvalue)
Sets the value of an integer parameter.
Parameters
•[in] param (iparam ) – Which parameter.
•[in] parvalue (int) – Parameter value.
Task.putmaxnumanz(maxnumanz)
MOSEK stores only the non-zero elements in 𝐴. Therefore1 MOSEK cannot predict how much
storage is required to store 𝐴. Using this function it is possible to specify the number of non-zeros
to preallocate for storing 𝐴.
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 𝐴 is inputted in
many small chunks, setting this value may speed up the data input phase.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
It is not mandatory to call this function, since MOSEK will reallocate internal structures whenever
it is necessary.
Observe the function call has no effect if both maxnumcon and maxnumvar is zero.
Parameters
•[in] maxnumanz (long) – New size of the storage reserved for storing 𝐴.
Task.putmaxnumbarvar(maxnumbarvar)
Sets the number of preallocated symmetric matrix variables in the optimization task. When this
number of variables is reached MOSEK will automatically allocate more space for variables.
It is not 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 maxnumbarvar must be larger than the current number of variables in the task.
Parameters
•[in] maxnumbarvar (int) – The maximum number of semidefinite variables.
Task.putmaxnumcon(maxnumcon)
Sets the number of preallocated constraints in the optimization task. When this number of con-
straints 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.
Parameters
•[in] maxnumcon (int) – Number of preallocated constraints in the optimization task.
Task.putmaxnumcone(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.
Parameters
•[in] maxnumcone (int) – Number of preallocated conic constraints in the optimization task.
Task.putmaxnumqnz(maxnumqnz)
MOSEK stores only the non-zero elements in 𝑄. Therefore, MOSEK cannot predict how much
storage is required to store 𝑄. Using this function it is possible to specify the number non-zeros to
preallocate for storing 𝑄 (both objective and constraints).
It may be advantageous to reserve more non-zeros for 𝑄 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 𝑄.
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.
Parameters
•[in] maxnumqnz (long) – Number of non-zero elements preallocated in quadratic coefficient
matrices.
Task.putmaxnumvar(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.
Parameters
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
and
qcsubk[t]
𝑞qcsubj[t],qcsubi[t] = qcval[t], 𝑡 = 0, . . . , numqcnz − 1.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑛𝑢𝑚𝑣𝑎𝑟−1
∑︁ 𝑛𝑢𝑚𝑣𝑎𝑟−1 𝑛𝑢𝑚𝑣𝑎𝑟−1
1 ∑︁ ∑︁
𝑙𝑘𝑐 ≤ 𝑘
𝑞𝑖𝑗 𝑥𝑖 𝑥𝑗 + 𝑎𝑘𝑗 𝑥𝑗 ≤ 𝑢𝑐𝑘 .
2 𝑖=0 𝑗=0 𝑗=0
1. 𝑄𝑘 = 0
2. for 𝑡 = 0 to 𝑛𝑢𝑚𝑞𝑐𝑛𝑧 − 1
𝑘 𝑘
3. 𝑞qcsubi[t],qcsubj[t] = 𝑞qcsubi[t],qcsubj[t] + qcval[t]
𝑘 𝑘
3. 𝑞qcsubj[t],qcsubi[t] = 𝑞qcsubj[t],qcsubi[t] + qcval[t]
1. 𝑄𝑜 = 0
2. for 𝑡 = 0 to 𝑛𝑢𝑚𝑞𝑜𝑛𝑧 − 1
𝑜 𝑜
3. 𝑞qosubi[t],qosubj[t] = 𝑞qosubi[t],qosubj[t] + qoval[t]
𝑜 𝑜
3. 𝑞qosubj[t],qosubi[t] = 𝑞qosubj[t],qosubi[t] + qoval[t]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Only the elements in the lower triangular part are accepted. Setting 𝑞𝑖𝑗 with 𝑗 > 𝑖 will cause an
error.
Please note that replacing all quadratic element, one at a time, is more computationally expensive
than replacing all elements at once. Use task.putqobj instead whenever possible.
Parameters
•[in] i (int) – Row index for the coefficient to be replaced.
•[in] j (int) – Column index for the coefficient to be replaced.
•[in] qoij (double) – The new value for 𝑞𝑖𝑗
𝑜
.
Task.putskc(whichsol, skc)
Sets the status keys for the constraints.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] skc (stakey ) – Status keys for the constraints.
Task.putskcslice(whichsol, first, last, skc)
Sets the status keys for the constraints.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
•[in] skc (stakey ) – Status keys for the constraints.
Task.putskx(whichsol, skx)
Sets the status keys for the scalar variables.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] skx (stakey ) – Status keys for the variables.
Task.putskxslice(whichsol, first, last, skx)
Sets the status keys for the variables.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Task.putvarname(j, name)
Puts the name of a variable.
Parameters
•[in] j (int) – Index of the variable.
•[in] name (str) – The variable name.
Task.putvartype(j, vartype)
Sets the variable type of one variable.
Parameters
•[in] j (int) – Index of the variable.
•[in] vartype (variabletype ) – The new variable type.
Task.putvartypelist(subj, vartype)
Sets the variable type for one or more variables, i.e. variable number subj[𝑘] is assigned the variable
type vartype[𝑘].
If the same index is specified multiple times in subj only the last entry takes effect.
Parameters
•[in] subj (int[]) – A list of variable indexes for which the variable type should be changed.
•[in] vartype (variabletype ) – A list of variable types that should be assigned to the
variables specified by subj. See variabletype for the possible values of vartype.
Task.putxc(whichsol, xc)
Sets the 𝑥𝑐 vector for a solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[out] xc (double[]) – The 𝑥𝑐 vector.
Task.putxcslice(whichsol, first, last, xc)
Sets a slice of the 𝑥𝑐 vector for a solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
•[in] xc (double[]) – Primal constraint solution.
Task.putxx(whichsol, xx)
Sets the 𝑥𝑥 vector for a solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] xx (double[]) – The 𝑥𝑥 vector.
Task.putxxslice(whichsol, first, last, xx)
Obtains a slice of the 𝑥𝑥 vector for a solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] first (int) – First index in the sequence.
•[in] last (int) – Last index plus 1 in the sequence.
•[in] xx (double[]) – Primal variable solution.
Task.puty(whichsol, y)
Sets the 𝑦 vector for a solution.
Parameters
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Task.removecones(subset)
Removes a number conic constraint from the problem. In general, it is much more efficient to
remove a cone with a high index than a low index.
Parameters
•[in] subset (int[]) – Indexes of cones which should be removed.
Task.removecons(subset)
The function removes a subset of the constraints from the optimization task. This implies that
the existing constraints are renumbered, for instance if constraint 5 is removed then constraint 6
becomes constraint 5 and so forth.
Parameters
•[in] subset (int[]) – Indexes of constraints which should be removed.
Task.removevars(subset)
The function removes a subset of the variables from the optimization task. This implies that the
existing variables are renumbered, for instance if constraint 5 is removed then constraint 6 becomes
constraint 5 and so forth.
Parameters
•[in] subset (int[]) – Indexes of variables which should be removed.
Task.resizetask(maxnumcon, maxnumvar, maxnumcone, maxnumanz, 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.
Parameters
•[in] maxnumcon (int) – New maximum number of constraints.
•[in] maxnumvar (int) – New maximum number of variables.
•[in] maxnumcone (int) – New maximum number of cones.
•[in] maxnumanz (long) – New maximum number of non-zeros in 𝐴.
•[in] maxnumqnz (long) – New maximum number of non-zeros in all 𝑄 matrices.
Task.sensitivityreport(whichstream)
Reads a sensitivity format file from a location given by sparam.sensitivity_file_name and
writes the result to the stream whichstream. If sparam.sensitivity_res_file_name is set to a
non-empty string, then the sensitivity report is also written to a file of this name.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
Task.set_Progress(callback)
Recieve callbacks about current status of the solver during optimization.
For example:
Returns non-zero to request that the solver terminates.
Parameters
•[in] callback (none) – The callback function.
Task.set_Stream(whichstream, callback)
Directs all output from a task stream to a callback function.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
•[in] callback (none) – The callback function.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Task.setdefaults()
Resets all the parameters to their default values.
isdef = Task.solutiondef(whichsol)
Checks whether a solution is defined.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
Return
•isdef (int) – Is non-zero if the requested solution is defined.
Task.solutionsummary(whichstream)
Prints a short summary of the current solutions.
Parameters
•[in] whichstream (streamtype ) – Index of the stream.
numnz = Task.solvewithbasis(transp, numnz, sub, val)
If a basic solution is available, then exactly numcon basis variables are defined. These numcon
basis variables are denoted the basis. Associated with the basis is a basis matrix denoted 𝐵. This
function solves either the linear equation system
𝐵𝑋 = 𝑏 (16.3)
or the system
𝐵𝑇 𝑋 = 𝑏 (16.4)
Given the knowledge of how 𝐵 is constructed it is possible to interpret the solution 𝑋 correctly.
Please note that this function exploits the sparsity in the vector 𝑏 to speed up the computations.
Parameters
•[in] transp (int) – If this argument is non-zero, then (16.4) is solved. Otherwise the
system (16.3) is solved.
•[io] numnz (int) – As input it is the number of non-zeros in 𝑏. As output it is the number
of non-zeros in 𝑋.
•[io] sub (int[]) – As input it contains the positions of the non-zeros in 𝑏, i.e.
𝑏[sub[𝑘]] ̸= 0, 𝑘 = 0, . . . , 𝑛𝑢𝑚𝑛𝑧[0] − 1.
As output it contains the positions of the non-zeros in 𝑋. It is important that sub has room
for numcon elements.
•[io] val (double[]) – As input it is the vector 𝑏. Although the positions of the non-zero
elements are specified in sub it is required that val[𝑖] = 0 if 𝑏[𝑖] = 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.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Return
•numnz (int) – As input it is the number of non-zeros in 𝑏. As output it is the number of
non-zeros in 𝑋.
conetype = Task.strtoconetype(str)
Obtains cone type code corresponding to a cone type string.
Parameters
•[in] str (str) – String corresponding to the cone type code codetype.
Return
•conetype (int) – The cone type corresponding to the string str.
sk = Task.strtosk(str)
Obtains the status key corresponding to an explanatory string.
Parameters
•[in] str (str) – Status key string.
Return
•sk (int) – Status key corresponding to the string.
Task.toconic()
This function tries to reformulate a given Quadratically Constrained Quadratic Optimization prob-
lem (QCQP) as a Conic Quadratic Optimization problem (CQO). The first step of the reformulation
is to convert the quadratic term of the objective function as a constraint, if any. Then the following
steps are repeated for each quadratic constraint:
•a conic constraint is added along with a suitable number of auxiliary variables and constraints;
•the original quadratic constraint is not removed, but all its coefficients are zeroed out.
Note that the reformulation preserves all the original variables.
The conversion is performed in-place, i.e. the task passed as argument is modified on exit. That
also means that if the reformulation fails, i.e. the given QCQP is not representable as a CQO, then
the task has an undefined state. In some cases, users may want to clone the task to ensure a clean
copy is preserved.
Task.updatesolutioninfo(whichsol)
Update the information items related to the solution.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
Task.writeSC(scfilename, taskfilename)
Write problem to an SCopt file and a normal problem file.
Parameters
•[in] scfilename (str) – Name of SCopt terms file.
•[in] taskfilename (str) – Name of problem file.
Task.writedata(filename)
Writes problem data associated with the optimization task to a file in one of the supported formats.
See Section 17 for the complete list.
By default the data file format is determined by the file name extension. This behaviour can be
overridden by setting the iparam.write_data_format parameter.
MOSEK is able to read and write files in a compressed format (gzip). To write in the compressed
format append the extension .gz. E.g to write a gzip compressed MPS file use the extension
mps.gz.
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 automatically generated anonymous names
by setting the iparam.write_generic_names parameter to onoffkey.on .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Please note that if a general nonlinear function appears in the problem then such function cannot
be written to file and MOSEK will issue a warning.
Parameters
•[in] filename (str) – Data is written to the file filename if it is a nonempty string.
Otherwise data is written to the file specified by sparam.data_file_name .
Task.writejsonsol(filename)
Saves the current solutions and solver information items in a JSON file.
Parameters
•[in] filename (str) – A valid file name.
Task.writeparamfile(filename)
Writes all the parameters to a parameter file.
Parameters
•[in] filename (str) – The name of parameter file.
Task.writesolution(whichsol, filename)
Saves the current basic, interior-point, or integer solution to a file.
Parameters
•[in] whichsol (soltype ) – Selects a solution.
•[in] filename (str) – A valid file name.
Task.writetask(filename)
Write a binary dump of the task data. This format saves all problem data, but not callback-
functions and general non-linear terms.
See section 17.6 for a description of the Task format.
Parameters
•[in] filename (str) – Output file name.
Task.writetasksolverresult_file(filename)
Internal
Parameters
•[in] filename (str) – A valid file name.
16.10 Exceptions
Exception
Base exception class for all MOSEK exceptions.
Implements
Exception
Error
Exception class used for all error response codes from MOSEK.
Implements
Exception
Warning
Exception class used for all warning response codes from MOSEK.
Implements
Exception
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
CHAPTER
SEVENTEEN
MOSEK supports a range of problem and solution formats listed in Table 17.1 and Table 17.2. The Task
format is MOSEK‘s native binary format and it supports all features that MOSEK supports. The
OPF format is MOSEK‘s human-readable alternative that supports nearly all features (everything
except semidefinite problems). In general, text formats are significantly slower to read, but can be
examined and edited directly in any text editor.
Problem formats
Solution formats
Compression
MOSEK supports GZIP compression of files. Problem files with an additional .gz extension are assumed
to be compressed when read, and are automatically compressed when written. For example, a file called
329
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
problem.mps.gz
MOSEK supports the LP file format with some extensions. The LP format is not a completely well-
defined standard and hence different optimization packages may interpret the same LP file in slightly
different ways. MOSEK tries to emulate as closely as possible CPLEX’s behavior, but tries to stay
backward compatible.
The LP file format can specify problems on the form
minimize/maximize 𝑐𝑇 𝑥 + 12 𝑞 𝑜 (𝑥)
subject to 𝑐
𝑙 ≤ 𝐴𝑥 + 12 𝑞(𝑥) ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
𝑥𝒥 integer,
where
• 𝑥 ∈ R𝑛 is the vector of decision variables.
• 𝑐 ∈ R𝑛 is the linear term in the objective.
• 𝑞 𝑜 :∈ R𝑛 → R is the quadratic term in the objective where
𝑞 𝑜 (𝑥) = 𝑥𝑇 𝑄𝑜 𝑥
and it is assumed that
𝑄𝑜 = (𝑄𝑜 )𝑇 .
𝑄𝑖 = (𝑄𝑖 )𝑇 .
An LP formatted file contains a number of sections specifying the objective, constraints, variable bounds,
and variable types. The section keywords may be any mix of upper and lower case letters.
Objective Function
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
max
maximum
maximize
min
minimum
minimize
myname:
before the expressions. If no name is given, then the objective is named obj.
The objective function contains linear and quadratic terms. The linear terms are written as:
4 x1 + x2 - 0.1 x3
and so forth. The quadratic terms are written in square brackets ([ ]) and are either squared or multiplied
as in the examples
x1^2
and
x1 * x2
minimize
myobj: 4 x1 + x2 - 0.1 x3 + [ x1^2 + 2.1 x1 * x2 ]/2
If the same variable occurs more than once in the linear part, the coefficients are added, so that 4 x1 +
2 x1 is equivalent to 6 x1. In the quadratic expressions x1 * x2 is equivalent to x2 * x1 and, as in the
linear part, if the same variables multiplied or squared occur several times their coefficients are added.
Constraints
subj to
subject to
s.t.
st
subject to
con1: x1 + x2 + [ x3^2 ]/2 <= 5.1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The bound type (here <=) may be any of <, <=, =, >, >= (< and <= mean the same), and the bound may
be any number.
In the standard LP format it is not possible to define more than one bound, but MOSEK supports
defining ranged constraints by using double-colon (::) instead of a single-colon (:) after the constraint
name, i.e.
−5 ≤ 𝑥1 + 𝑥2 ≤ 5 (17.1)
may be written as
𝑥1 + 𝑥2 − 𝑠𝑙1 = 0, −5 ≤ 𝑠𝑙1 ≤ 5.
Bounds
Bounds on the variables can be specified in the bound section beginning with one of the keywords
bound
bounds
The bounds section is optional but should, if present, follow the subject to section. All variables listed
in the bounds section must occur in either the objective or a constraint.
The default lower and upper bounds are 0 and +∞ . A variable may be declared free with the keyword
free, which means that the lower bound is −∞ and the upper bound is +∞ . Furthermore it may be
assigned a finite lower and upper bound. The bound definitions for a given variable may be written in
one or two lines, and bounds can be any number or ±∞ (written as +inf/-inf/+infinity/-infinity)
as in the example
bounds
x1 free
x2 <= 5
0.1 <= x2
x3 = 42
2 <= x4 < +inf
Variable Types
The final two sections are optional and must begin with one of the keywords
bin
binaries
binary
and
gen
general
Under general all integer variables are listed, and under binary all binary (integer variables with bounds
0 and 1) are listed:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
general
x1 x2
binary
x3 x4
Again, all variables listed in the binary or general sections must occur in either the objective or a
constraint.
Terminating Section
end
\ File: lo1.lp
maximize
obj: 3 x1 + x2 + 5 x3 + x4
subject to
c1: 3 x1 + x2 + 2 x3 = 30
c2: 2 x1 + x2 + 3 x3 + x4 >= 15
c3: 2 x2 + 3 x4 <= 25
bounds
0 <= x1 <= +infinity
0 <= x2 <= 10
0 <= x3 <= +infinity
0 <= x4 <= +infinity
end
maximize
obj: x1 + 6.4e-01 x2
subject to
c1: 5e+01 x1 + 3.1e+01 x2 <= 2.5e+02
c2: 3e+00 x1 - 2e+00 x2 >= -4e+00
bounds
0 <= x1 <= +infinity
0 <= x2 <= +infinity
general
x1 x2
end
Comments
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Names
A name for an objective, a constraint or a variable may contain the letters a-z, A-Z, the digits 0-9 and
the characters
!"#$%&()/,.;?@_'`|~
The first character in a name must not be a number, a period or the letter e or E. Keywords must not
be used as names.
MOSEK accepts any character as valid for names, except \0. A name that is not allowed in LP file will
be changed and a warning will be issued.
The algorithm for making names LP valid works as follows: The name is interpreted as an utf-8 string.
For a unicode character c:
• If c==_ (underscore), the output is __ (two underscores).
• If c is a valid LP name character, the output is just c.
• If c is another character in the ASCII range, the output is _XX, where XX is the hexadecimal code
for the character.
• If c is a character in the range 127-65535, the output is _uXXXX, where XXXX is the hexadecimal
code for the character.
• If c is a character above 65535, the output is _UXXXXXXXX, where XXXXXXXX is the hexadecimal
code for the character.
Invalid utf-8 substrings are escaped as _XX', and if a name starts with a period, e or E, that character
is escaped as _XX.
Variable Bounds
Specifying several upper or lower bounds on one variable is possible but MOSEK uses only the tightest
bounds. If a variable is fixed (with =), then it is considered the tightest bound.
Some optimization software packages employ a more strict definition of the LP format than the one used
by MOSEK. The limitations imposed by the strict LP format are the following:
• Quadratic terms in the constraints are not allowed.
• Names can be only 16 characters long.
• Lines must not exceed 255 characters in length.
If an LP formatted file created by MOSEK should satisfy the strict definition, then the parameter
• iparam.write_lp_strict_format
should be set; note, however, that some problems cannot be written correctly as a strict LP formatted
file. For instance, all names are truncated to 16 characters and hence they may loose their uniqueness
and change the problem.
To get around some of the inconveniences converting from other problem formats, MOSEK allows lines
to contain 1024 characters and names may have any length (shorter than the 1024 characters).
Internally in MOSEK names may contain any (printable) character, many of which cannot be used in
LP names. Setting the parameters
• iparam.read_lp_quoted_names and
• iparam.write_lp_quoted_names
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
allows MOSEK to use quoted names. The first parameter tells MOSEK to remove quotes from
quoted names e.g, "x1", when reading LP formatted files. The second parameter tells MOSEK to put
quotes around any semi-illegal name (names beginning with a number or a period) and fully illegal name
(containing illegal characters). As double quote is a legal character in the LP format, quoting semi-illegal
names makes them legal in the pure LP format as long as they are still shorter than 16 characters. Fully
illegal names are still illegal in a pure LP file.
The LP format is not a formal standard and different vendors have slightly different interpretations of
the LP format. To make MOSEK’s definition of the LP format more compatible with the definitions
of other vendors, use the parameter setting
• iparam.write_lp_strict_format = onoffkey.on
This setting may lead to truncation of some names and hence to an invalid LP file. The simple solution
to this problem is to use the parameter setting
• iparam.write_generic_names = onoffkey.on
which will cause all names to be renamed systematically in the output file.
A few parameters control the visual formatting of LP files written by MOSEK in order to make it easier
to read the files. These parameters are
• iparam.write_lp_line_width
• iparam.write_lp_terms_per_line
The first parameter sets the maximum number of characters on a single line. The default value is 80
corresponding roughly to the width of a standard text document.
The second parameter sets the maximum number of terms per line; a term means a sign, a coefficient,
and a name (for example + 42 elephants). The default value is 0, meaning that there is no maximum.
Unnamed Constraints
Reading and writing an LP file with MOSEK may change it superficially. If an LP file contains
unnamed constraints or objective these are given their generic names when the file is read (however
unnamed constraints in MOSEK are written without names).
MOSEK supports the standard MPS format with some extensions. For a detailed description of the
MPS format see the book by Nazareth [Naz87] .
The version of the MPS format supported by MOSEK allows specification of an optimization problem
of the form
𝑙𝑐 ≤ 𝐴𝑥 + 𝑞(𝑥) ≤ 𝑢𝑐 ,
𝑙𝑥 ≤ 𝑥 ≤ 𝑢𝑥 ,
(17.2)
𝑥 ∈ 𝒦,
𝑥𝒥 integer,
where
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑄𝑖 = (𝑄𝑖 )𝑇 .
Here the names in capitals are keywords of the MPS format and names in brackets are custom defined
names or values. A couple of notes on the structure:
• Fields: All items surrounded by brackets appear in fields. The fields named “valueN” are numerical
values. Hence, they must have the format
[+|-]XXXXXXX.XXXXXX[[e|E][+|-]XXX]
where
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
.. code-block:: text
X = [0|1|2|3|4|5|6|7|8|9].
• Sections: The MPS file consists of several sections where the names in capitals indicate the begin-
ning of a new section. For example, COLUMNS denotes the beginning of the columns section.
• Comments: Lines starting with an * are comment lines and are ignored by MOSEK.
• Keys: The question marks represent keys to be specified later.
• Extensions: The sections QSECTION and CSECTION are specific MOSEK extensions of the MPS
format. The sections QMATRIX, QUADOBJ and QCMATRIX are included for sake of compatibility with
other vendors extensions to the MPS format.
The standard MPS format is a fixed format, i.e. everything in the MPS file must be within certain fixed
positions. MOSEK also supports a free format. See Section 17.2.9 for details.
* File: lo1.mps
NAME lo1
OBJSENSE
MAX
ROWS
N obj
E c1
G c2
L c3
COLUMNS
x1 obj 3
x1 c1 3
x1 c2 2
x2 obj 1
x2 c1 1
x2 c2 1
x2 c3 2
x3 obj 5
x3 c1 2
x3 c2 3
x4 obj 1
x4 c2 1
x4 c3 3
RHS
rhs c1 30
rhs c2 15
rhs c3 25
RANGES
BOUNDS
UP bound x2 10
ENDATA
Section NAME
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
OBJSENSE (optional)
This is an optional section that can be used to specify the sense of the objective function. The OBJSENSE
section contains one line at most which can be one of the following
MIN
MINIMIZE
MAX
MAXIMIZE
OBJNAME (optional)
This is an optional section that can be used to specify the name of the row that is used as objective
function. The OBJNAME section contains one line at most which has the form
objname
ROWS
? [cname1]
COLUMNS
In this section the elements of 𝐴 are specified using one or more records having the form:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
RHS (optional)
RANGES (optional)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The records in this section are used to modify the bound vectors for the constraints, i.e. the values in 𝑙𝑐
and 𝑢𝑐 . A record has the following interpretation:[name] is the name of the RANGE vector and [cname1]
is a valid constraint name. Assume that [cname1] is assigned to the 𝑖 th constraint and let 𝑣1 be the
value specified by [value1], then a record has the interpretation:
Constraint type Sign of 𝑣1 𝑙𝑖𝑐 𝑢𝑐𝑖
E − 𝑢𝑐𝑖 + 𝑣1
E + 𝑙𝑖𝑐 + 𝑣1
G − or + 𝑙𝑖𝑐 + |𝑣1 |
L − or + 𝑢𝑐𝑖 − |𝑣1 |
N
QSECTION (optional)
Within the QSECTION the label [cname1] must be a constraint name previously specified in the ROWS
section. The label [cname1] denotes the constraint to which the quadratic term belongs. A record in
the QSECTION has the form
[vname1] [vname2] [value1] [vname3] [value2]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
QMATRIX/QUADOBJ (optional)
The QMATRIX and QUADOBJ sections allow to define the quadratic term of the objective function. They
differ in how the quadratic term of the objective function is stored:
• QMATRIX It stores all the nonzeros coefficients, withouot taking advantage of the symmetry of the
𝑄 matrix.
• QUADOBJ It only store the upper diagonal nonzero elements of the 𝑄 matrix.
A record in both sections has the form:
* File: qo1_matrix.mps
NAME qo1_qmatrix
ROWS
N obj
G c1
COLUMNS
x1 c1 1.0
x2 obj -1.0
x2 c1 1.0
x3 c1 1.0
RHS
rhs c1 1.0
QMATRIX
x1 x1 2.0
x1 x3 -1.0
x3 x1 -1.0
x2 x2 0.2
x3 x3 2.0
ENDATA
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
A QCMATRIX section allows to specify the quadratic part of a given constraints. Within the QCMATRIX the
label [cname1] must be a constraint name previously specified in the ROWS section. The label [cname1]
denotes the constraint to which the quadratic term belongs. A record in the QSECTION has the form
[vname1] [vname2] [value1]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
x1 c1 1.0
x2 obj -1.0
x2 c1 1.0
x3 c1 1.0
RHS
rhs c1 1.0
rhs q1 10.0
QCMATRIX q1
x1 x1 2.0
x1 x3 -1.0
x3 x1 -1.0
x2 x2 0.2
x3 x3 2.0
ENDATA
In the BOUNDS section changes to the default bounds vectors 𝑙𝑥 and 𝑢𝑥 are specified. The default bounds
vectors are 𝑙𝑥 = 0 and 𝑢𝑥 = ∞ . Moreover, it is possible to specify several sets of bound vectors. A
record in this section has the form
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑥 ∈ 𝒦.
be vectors comprised of parts of the decision variables 𝑥 so that each decision variable is a member of
exactly one vector 𝑥𝑡 , for example
⎡ ⎤
⎡ ⎤ 𝑥6
𝑥1 ⎢ 𝑥5 ⎥
𝑥1 = ⎣ 𝑥4 ⎦ and 𝑥2 = ⎢ ⎣ 𝑥3 ⎦ .
⎥
𝑥7
𝑥2
Next define
𝒦 := 𝑥 ∈ R𝑛 : 𝑥𝑡 ∈ 𝒦𝑡 ,
{︀ }︀
𝑡 = 1, . . . , 𝑘
{︁ 𝑡
}︁
𝒦𝑡 = 𝑥 ∈ R𝑛 .
• Quadratic cone:
⎧ ⎯ ⎫
⎨ ⎸ 𝑛𝑡
𝑡 ⎸∑︁ ⎬
𝒦𝑡 = 𝑥 ∈ R𝑛 : 𝑥1 ≥ ⎷ 𝑥2𝑗 . (17.3)
⎩ ⎭
𝑗=2
⎧ 𝑡
⎫
⎨ 𝑛 ⎬
𝑡 ∑︁
𝒦𝑡 = 𝑥 ∈ R𝑛 : 2𝑥1 𝑥2 ≥ 𝑥2𝑗 , 𝑥1 , 𝑥2 ≥ 0 . (17.4)
⎩ ⎭
𝑗=3
In general, only quadratic and rotated quadratic cones are specified in the MPS file whereas membership
of the R set is not. If a variable is not a member of any other cone then it is assumed to be a member
of an R cone.
Next, let us study an example. Assume that the quadratic cone
√︁
𝑥4 ≥ 𝑥25 + 𝑥28
𝑥3 𝑥7 ≥ 𝑥21 + 𝑥20 , 𝑥3 , 𝑥7 ≥ 0,
should be specified in the MPS file. One CSECTION is required for each cone and they are specified as
follows:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
* 1 2 3 4 5 6
*23456789012345678901234567890123456789012345678901234567890
CSECTION konea 0.0 QUAD
x4
x5
x8
CSECTION koneb 0.0 RQUAD
x7
x3
x1
x0
This first CSECTION specifies the cone (17.3) which is given the name konea. This is a quadratic cone
which is specified by the keyword QUAD in the CSECTION header. The 0.0 value in the CSECTION header
is not used by the QUAD cone.
The second CSECTION specifies the rotated quadratic cone (17.4). Please note the keyword RQUAD in the
CSECTION which is used to specify that the cone is a rotated quadratic cone instead of a quadratic cone.
The 0.0 value in the CSECTION header is not used by the RQUAD cone.
In general, a CSECTION header has the format
[vname1]
17.2.5 ENDATA
Using special bound keys in the BOUNDS section it is possible to specify that some or all of the variables
should be integer-constrained i.e. be members of 𝒥 . However, an alternative method is available.
This method is available only for backward compatibility and we recommend that it is not used. This
method requires that markers are placed in the COLUMNS section as in the example:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
COLUMNS
x1 obj -10.0 c1 0.7
x1 c2 0.5 c3 1.0
x1 c4 0.1
* Start of integer-constrained variables.
MARK000 'MARKER' 'INTORG'
x2 obj -9.0 c1 1.0
x2 c2 0.8333333333 c3 0.66666667
x2 c4 0.25
x3 obj 1.0 c6 2.0
MARK001 'MARKER' 'INTEND'
Several issues related to the MPS format are not well-defined by the industry standard. However,
MOSEK uses the following interpretation:
• If a matrix element in the COLUMNS section is specified multiple times, then the multiple entries are
added together.
• If a matrix element in a QSECTION section is specified multiple times, then the multiple entries are
added together.
MOSEK supports a free format variation of the MPS format. The free format is similar to the MPS file
format but less restrictive, e.g. it allows longer names. However, it also presents two main limitations:
• A name must not contain any blanks.
• By default a line in the MPS file must not contain more than 1024 characters. However, by
modifying the parameter iparam.read_mps_width an arbitrary large line width will be accepted.
To use the free MPS format instead of the default MPS format the MOSEK parameter
iparam.read_mps_format should be changed.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The Optimization Problem Format (OPF) is an alternative to LP and MPS files for specifying optimiza-
tion problems. It is row-oriented, inspired by the CPLEX LP format.
Apart from containing objective, constraints, bounds etc. it may contain complete or partial solutions,
comments and extra information relevant for solving the problem. It is designed to be easily read and
modified by hand and to be forward compatible with possible future extensions.
Intended use
The format uses tags to structure data. A simple example with the basic sections may look like this:
[comment]
This is a comment. You may write almost anything here...
[/comment]
[constraints]
[con 'con01'] 4 &<= x + y [/con]
[/constraints]
[bounds]
[b] -10 &<= x,y &<= 10 [/b]
A scope is opened by a tag of the form [tag] and closed by a tag of the form [/tag]. An opening tag
may accept a list of unnamed and named arguments, for examples:
Unnamed arguments are identified by their order, while named arguments may appear in any order, but
never before an unnamed argument. The value can be a quoted, single-quoted or double-quoted text
string, i.e.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Sections
[comment]
A comment section. This can contain almost any text: Between single quotes (’) or double quotes (")
any text may appear. Outside quotes the markup characters ([ and ]) must be prefixed by backslashes.
Both single and double quotes may appear alone or inside a pair of quotes if it is prefixed by a backslash.
[objective]
The objective function: This accepts one or two parameters, where the first one (in the above example
min) is either min or max (regardless of case) and defines the objective sense, and the second one (above
myobj), if present, is the objective name. The section may contain linear and quadratic expressions. If
several objectives are specified, all but the last are ignored.
[constraints]
This does not directly contain any data, but may contain the subsection con defining a linear constraint.
[con] defines a single constraint; if an argument is present ([con NAME]) this is used as the name of
the constraint, otherwise it is given a null-name. The section contains a constraint definition written as
linear and quadratic expressions with a lower bound, an upper bound, with both or with an equality.
Examples:
[constraints]
[con 'con1'] 0 <= x + y [/con]
[con 'con2'] 0 >= x + y [/con]
[con 'con3'] 0 <= x + y <= 10 [/con]
[con 'con4'] x + y = 10 [/con]
[/constraints]
Constraint names are unique. If a constraint is specified which has the same name as a previously defined
constraint, the new constraint replaces the existing one.
[bounds]
This does not directly contain any data, but may contain the subsections b (linear bounds on variables)
and cone (quadratic cone).
[b]. Bound definition on one or several variables separated by comma (,). An upper or lower bound
on a variable replaces any earlier defined bound on that variable. If only one bound (upper or lower) is
given only this bound is replaced. This means that upper and lower bounds can be specified separately.
So the OPF bound definition:
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
𝑛
∑︁
𝑥1 𝑥2 > 𝑥2𝑖 .
𝑖=3
A [bounds]-section example:
[bounds]
[b] 0 <= x,y <= 10 [/b] # ranged bound
[b] 10 >= x,y >= 0 [/b] # ranged bound
[b] 0 <= x,y <= inf [/b] # using inf
[b] x,y free [/b] # free variables
# Let (x,y,z,w) belong to the cone K
[cone quad] x,y,z,w [/cone] # quadratic cone
[cone rquad] x,y,z,w [/cone] # rotated quadratic cone
[/bounds]
[variables]
This defines an ordering of variables as they should appear in the problem. This is simply a space-
separated list of variable names.
[integer]
This contains a space-separated list of variables and defines the constraint that the listed variables must
be integer values.
[hints]
This may contain only non-essential data; for example estimates of the number of variables, constraints
and non-zeros. Placed before all other sections containing data this may reduce the time spent reading
the file.
In the hints section, any subsection which is not recognized by MOSEK is simply ignored. In this
section a hint in a subsection is defined as follows:
where ITEM may be replaced by numvar (number of variables), numcon (number of linear/quadratic
constraints), numanz (number of linear non-zeros in constraints) and numqnz (number of quadratic non-
zeros in constraints).
[solutions]
This section can contain a set of full or partial solutions to a problem. Each solution must be specified
using a [solution]-section, i.e.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[solutions]
[solution]...[/solution] #solution 1
[solution]...[/solution] #solution 2
#other solutions....
[solution]...[/solution] #solution n
[/solutions]
Note that a [solution]-section must be always specified inside a [solutions]-section. The syntax of
a [solution]-section is the following:
KEYWORD=value
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• [vendor] This contains solver/vendor specific data. It accepts one argument, which is a vendor
ID – for MOSEK the ID is simply mosek – and the section contains the subsection parameters
defining solver parameters. When reading a vendor section, any unknown vendor can be safely
ignored. This is described later.
Comments using the # may appear anywhere in the file. Between the # and the following line-break any
text may be written, including markup characters.
Numbers
Numbers, when used for parameter values or coefficients, are written in the usual way by the printf
function. That is, they may be prefixed by a sign (+ or -) and may contain an integer part, decimal part
and an exponent. The decimal point is always . (a dot). Some examples are
1
1.0
.0
1.
1e10
1e+10
1e-10
More formally, the following standard regular expression describes numbers as used:
[+|-]?([0-9]+[.][0-9]*|[.][0-9]+)([eE][+|-]?[0-9]+)?
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Names
Variable names, constraint names and objective name may contain arbitrary characters, which in some
cases must be enclosed by quotes (single or double) that in turn must be preceded by a backslash.
Unquoted names must begin with a letter (a-z or A-Z) and contain only the following characters: the
letters a-z and A-Z, the digits 0-9, braces ({ and }) and underscore (_).
Some examples of legal names:
an_unquoted_name
another_name{123}
'single quoted name'
"double quoted name"
"name with \\"quote\\" in it"
"name with []s in it"
In the vendor section solver parameters are defined inside the parameters subsection. Each parameter
is written as
where PARAMETER_NAME is replaced by a MOSEK parameter name, usually of the form MSK_IPAR_...,
MSK_DPAR_... or MSK_SPAR_..., and the value is replaced by the value of that parameter; both integer
values and named values may be used. Some simple examples are
[vendor mosek]
[parameters]
[p MSK_IPAR_OPF_MAX_TERMS_PER_LINE] 10 [/p]
[p MSK_IPAR_OPF_WRITE_PARAMETERS] MSK_ON [/p]
[p MSK_DPAR_DATA_TOL_BOUND_INF] 1.0e18 [/p]
[/parameters]
[/vendor]
To write an OPF file set the parameter iparam.write_data_format to dataformat.op as this ensures
that OPF format is used.
Then modify the following parameters to define what the file should contain:
iparam.opf_write_sol_bas Include basic solution, if defined.
iparam.opf_write_sol_itg Include integer solution, if defined.
iparam.opf_write_sol_itr Include interior solution, if defined.
iparam.opf_write_solutions Include solutions if they are defined. If this is off, no solutions are
included.
iparam.opf_write_header Include a small header with comments.
iparam.opf_write_problem Include the problem itself — objective, constraints and bounds.
iparam.opf_write_parametersInclude all parameter settings.
iparam.opf_write_hints Include hints about the size of the problem.
17.3.4 Examples
This section contains a set of small examples written in OPF and describing how to formulate linear,
quadratic and conic problems.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
0 ≤ 𝑥0 ≤ ∞,
0 ≤ 𝑥1 ≤ 10,
0 ≤ 𝑥2 ≤ ∞,
0 ≤ 𝑥3 ≤ ∞.
[hints]
[hint NUMVAR] 4 [/hint]
[hint NUMCON] 3 [/hint]
[hint NUMANZ] 9 [/hint]
[/hints]
[variables disallow_new_variables]
x1 x2 x3 x4
[/variables]
[constraints]
[con 'c1'] 3 x1 + x2 + 2 x3 = 30 [/con]
[con 'c2'] 2 x1 + x2 + 3 x3 + x4 >= 15 [/con]
[con 'c3'] 2 x2 + 3 x4 <= 25 [/con]
[/constraints]
[bounds]
[b] 0 <= * [/b]
[b] 0 <= x2 <= 10 [/b]
[/bounds]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[hints]
[hint NUMVAR] 3 [/hint]
[hint NUMCON] 1 [/hint]
[hint NUMANZ] 3 [/hint]
[hint NUMQNZ] 4 [/hint]
[/hints]
[variables disallow_new_variables]
x1 x2 x3
[/variables]
[constraints]
[con 'c1'] 1.0 <= x1 + x2 + x3 [/con]
[/constraints]
[bounds]
[b] 0 <= * [/b]
[/bounds]
minimize 𝑥3 + 𝑥4 + 𝑥5
subject to 𝑥0 + 𝑥1 + 2𝑥2 = 1,
𝑥0√︀
, 𝑥1 , 𝑥2 ≥ 0,
2
𝑥3 ≥ 𝑥0 + 𝑥1 , 2
2𝑥4 𝑥5 ≥ 𝑥22 .
Please note that the type of the cones is defined by the parameter to [cone ...]; the content of the
cone-section is the names of variables that belong to the cone. The resulting OPF file is in Listing 17.3.
[hints]
[hint NUMVAR] 6 [/hint]
[hint NUMCON] 1 [/hint]
[hint NUMANZ] 3 [/hint]
[/hints]
[variables disallow_new_variables]
x1 x2 x3 x4 x5 x6
[/variables]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[constraints]
[con 'c1'] x1 + x2 + 2e+00 x3 = 1e+00 [/con]
[/constraints]
[bounds]
# We let all variables default to the positive orthant
[b] 0 <= * [/b]
maximize 𝑥0 + 0.64𝑥1
subject to 50𝑥0 + 31𝑥1 ≤ 250,
3𝑥0 − 2𝑥1 ≥ −4,
𝑥0 , 𝑥1 ≥ 0 and integer
[hints]
[hint NUMVAR] 2 [/hint]
[hint NUMCON] 2 [/hint]
[hint NUMANZ] 4 [/hint]
[/hints]
[variables disallow_new_variables]
x1 x2
[/variables]
[constraints]
[con 'c1'] 5e+1 x1 + 3.1e+1 x2 <= 2.5e+2 [/con]
[con 'c2'] -4 <= 3 x1 - 2 x2 [/con]
[/constraints]
[bounds]
[b] 0 <= * [/b]
[/bounds]
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[integer]
x1 x2
[/integer]
This document constitutes the technical reference manual of the Conic Benchmark Format with file exten-
sion: .cbf or .CBF. It unifies linear, second-order cone (also known as conic quadratic) and semidefinite
optimization with mixed-integer variables. The format has been designed with benchmark libraries in
mind, and therefore focuses on compact and easily parsable representations. The problem structure is
separated from the problem data, and the format moreover facilitates benchmarking of hotstart capability
through sequences of changes.
This section defines the spectrum of conic optimization problems that can be formulated in terms of the
keywords of the CBF format.
In the CBF format, conic optimization problems are considered in the following form:
• Variables are either scalar variables, 𝑥𝑗 for 𝑗 ∈ 𝒥 , or variables, 𝑋 𝑗 for 𝑗 ∈ 𝒥 𝑃 𝑆𝐷 . Scalar variables
can also be declared as integer.
• Constraints are affine expressions of the variables, either scalar-valued 𝑔𝑖 for 𝑖 ∈ ℐ, or matrix-
valued 𝐺𝑖 for 𝑖 ∈ ℐ 𝑃 𝑆𝐷
∑︁ ∑︁
𝑔𝑖 = ⟨𝐹𝑖𝑗 , 𝑋𝑗 ⟩ + 𝑎𝑖𝑗 𝑥𝑗 + 𝑏𝑖 ,
𝑗∈𝒥 𝑃 𝑆𝐷 𝑗∈𝒥
∑︁
𝐺𝑖 = 𝑥𝑗 𝐻𝑖𝑗 + 𝐷𝑖 .
𝑗∈𝒥
• The objective function is a scalar-valued affine expression of the variables, either to be minimized
or maximized. We refer to this expression as 𝑔 𝑜𝑏𝑗
∑︁ ∑︁ 𝑜𝑏𝑗
𝑔 𝑜𝑏𝑗 = ⟨𝐹𝑗𝑜𝑏𝑗 , 𝑋𝑗 ⟩ + 𝑎𝑗 𝑥𝑗 + 𝑏𝑜𝑏𝑗 .
𝑗∈𝒥 𝑃 𝑆𝐷 𝑗∈𝒥
{𝑥 ∈ R𝑛 }, for 𝑛 ≥ 1.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
{︂(︂ )︂ }︂
𝑝
∈R×R 𝑛−1
, 𝑝 ≥ 𝑥 𝑥, 𝑝 ≥ 0 , for 𝑛 ≥ 2.
2 𝑇
𝑥
⎧⎛ ⎞ ⎫
⎨ 𝑝 ⎬
⎝ 𝑞 ⎠ ∈ R × R × R𝑛−2 , 2𝑝𝑞 ≥ 𝑥𝑇 𝑥, 𝑝 ≥ 0, 𝑞 ≥ 0 , for 𝑛 ≥ 3.
𝑥
⎩ ⎭
This section defines how information is written in the CBF format, without being specific about the type
of information being communicated.
All information items belong to exactly one of the three groups of information. These information groups,
and the order they must appear in, are:
1. File format.
2. Problem structure.
3. Problem data.
The first group, file format, provides information on how to interpret the file. The second group, problem
structure, provides the information needed to deduce the type and size of the problem instance. Finally,
the third group, problem data, specifies the coefficients and constants of the problem instance.
Information items
The format is composed as a list of information items. The first line of an information item is the
KEYWORD, revealing the type of information provided. The second line - of some keywords only - is the
HEADER, typically revealing the size of information that follows. The remaining lines are the BODY holding
the actual information to be specified.
KEYWORD
BODY
KEYWORD
HEADER
BODY
The KEYWORD determines how each line in the HEADER and BODY is structured. Moreover, the number of
lines in the BODY follows either from the KEYWORD, the HEADER, or from another information item required
to precede it.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Embedded hotstart-sequences
A sequence of problem instances, based on the same problem structure, is within a single file. This
is facilitated via the CHANGE within the problem data information group, as a separator between the
information items of each instance. The information items following a CHANGE keyword are appending
to, or changing (e.g., setting coefficients back to their default value of zero), the problem data of the
preceding instance.
The sequence is intended for benchmarking of hotstart capability, where the solvers can reuse their
internal state and solution (subject to the achieved accuracy) as warmpoint for the succeeding instance.
Whenever this feature is unsupported or undesired, the keyword CHANGE should be interpreted as the
end of file.
The format is based on the US-ASCII printable character set with two extensions as listed below. Note,
by definition, that none of these extensions can be misinterpreted as printable US-ASCII characters:
• A line feed marks the end of a line, carriage returns are ignored.
• Comment-lines may contain unicode characters in UTF-8 encoding.
The line width is restricted to 512 bytes, with 3 bytes reserved for the potential carriage return, line feed
and null-terminator.
Integers and floating point numbers must follow the ISO C decimal string representation in the standard
C locale. The format does not impose restrictions on the magnitude of, or number of significant digits
in numeric data, but the use of 64-bit integers and 64-bit IEEE 754 floating point numbers should be
sufficient to avoid loss of precision.
The problem structure defines the objective sense, whether it is minimization and maximization. It also
defines the index sets, 𝒥 , 𝒥 𝑃 𝑆𝐷 , ℐ and ℐ 𝑃 𝑆𝐷 , which are all numbered from zero, {0, 1, . . .}, and empty
until explicitly constructed.
• Scalar variables are constructed in vectors restricted to a conic domain, such as (𝑥0 , 𝑥1 ) ∈ R2+ ,
(𝑥2 , 𝑥3 , 𝑥4 ) ∈ 𝒬3 , etc. In terms of the Cartesian product, this generalizes to
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
VAR
n k
K1 n1
K2 n2
...
Kk nk
where 𝑖 𝑛𝑖 = 𝑛 is the total number of scalar variables. The list of supported cones is found in
∑︀
Table 17.3. Integrality of scalar variables can be specified afterwards.
• PSD variables are constructed one-by-one. That is, 𝑋𝑗 ⪰ 0𝑛𝑗 ×𝑛𝑗 for 𝑗 ∈ 𝒥 𝑃 𝑆𝐷 , constructs a
matrix-valued variable of size 𝑛𝑗 × 𝑛𝑗 restricted to be symmetric positive semidefinite. In the CBF
format, this list of constructions becomes:
PSDVAR
N
n1
n2
...
nN
CON
m k
K1 m1
K2 m2
..
Kk mk
where 𝑖 𝑚𝑖 = 𝑚 is the total number of scalar constraints. The list of supported cones is found
∑︀
in Table 17.3.
• PSD constraints are constructed one-by-one. That is, 𝐺𝑖 ⪰ 0𝑚𝑖 ×𝑚𝑖 for 𝑖 ∈ ℐ 𝑃 𝑆𝐷 , constructs a
matrix-valued affine expressions of size 𝑚𝑖 × 𝑚𝑖 restricted to be symmetric positive semidefinite.
In the CBF format, this list of constructions becomes
PSDCON
M
m1
m2
..
mM
Problem data
The problem data defines the coefficients and constants of the affine expressions of the problem instance.
These are considered zero until explicitly defined, implying that instances with no keywords from this
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
information group are, in fact, valid. Duplicating or conflicting information is a failure to comply with
the standard. Consequently, two coefficients written to the same position in a matrix (or to transposed
positions in a symmetric matrix) is an error.
The affine expressions of the objective, 𝑔 𝑜𝑏𝑗 , of the scalar constraints, 𝑔𝑖 , and of the PSD constraints,
𝐺𝑖 , are defined separately. The following notation uses the standard trace inner product for matrices,
⟨𝑋, 𝑌 ⟩ = 𝑖,𝑗 𝑋𝑖𝑗 𝑌𝑖𝑗 .
∑︀
List of cones
The format uses an explicit syntax for symmetric positive semidefinite cones as shown above. For scalar
variables and constraints, constructed in vectors, the supported conic domains and their minimum sizes
are given as follows.
VER
Description: The version of the Conic Benchmark Format used to write the file.
HEADER: None
BODY: One line formatted as:
INT
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
OBJSENSE
STR
having MIN indicates minimize, and MAX indicates maximize. Capital letters are required.
Must appear exactly once in a file.
PSDVAR
INT
INT
This indicates the number of rows (equal to the number of columns) in the matrix-valued PSD variable.
The number of lines should match the number stated in the header.
VAR
INT INT
This is the number of scalar variables, followed by the number of conic domains they are restricted to.
BODY: A list of lines formatted as:
STR INT
This indicates the cone name (see Table 17.3), and the number of scalar variables restricted to this cone.
These numbers should add up to the number of scalar variables stated first in the header. The number
of lines should match the second number stated in the header.
INT
INT
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
INT
This indicates the scalar variable index 𝑗 ∈ 𝒥 . The number of lines should match the number stated in
the header.
Can only be used after the keyword VAR.
PSDCON
INT
INT
This indicates the number of rows (equal to the number of columns) in the matrix-valued affine expression
of the PSD constraint. The number of lines should match the number stated in the header.
Can only be used after these keywords: PSDVAR, VAR.
CON
INT INT
This is the number of scalar constraints, followed by the number of conic domains they restrict to.
BODY: A list of lines formatted as:
STR INT
This indicates the cone name (see Table 17.3), and the number of affine expressions restricted to this
cone. These numbers should add up to the number of scalar constraints stated first in the header. The
number of lines should match the second number stated in the header.
Can only be used after these keywords: PSDVAR, VAR
OBJFCOORD
Description: Input sparse coordinates (quadruplets) to define the symmetric matrices 𝐹𝑗𝑜𝑏𝑗 , as used in
the objective.
HEADER: One line formatted as:
INT
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
This indicates the PSD variable index 𝑗 ∈ 𝒥 𝑃 𝑆𝐷 , the row index, the column index and the coefficient
value. The number of lines should match the number stated in the header.
OBJACOORD
INT
INT REAL
This indicates the scalar variable index 𝑗 ∈ 𝒥 and the coefficient value. The number of lines should
match the number stated in the header.
OBJBCOORD
REAL
FCOORD
Description: Input sparse coordinates (quintuplets) to define the symmetric matrices, 𝐹𝑖𝑗 , as used in the
scalar constraints.
HEADER: One line formatted as:
INT
This indicates the scalar constraint index 𝑖 ∈ ℐ, the PSD variable index 𝑗 ∈ 𝒥 𝑃 𝑆𝐷 , the row index, the
column index and the coefficient value. The number of lines should match the number stated in the
header.
ACOORD
Description: Input sparse coordinates (triplets) to define the scalars, 𝑎𝑖𝑗 , as used in the scalar constraints.
HEADER: One line formatted as:
INT
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
This indicates the scalar constraint index 𝑖 ∈ ℐ, the scalar variable index 𝑗 ∈ 𝒥 and the coefficient value.
The number of lines should match the number stated in the header.
BCOORD
Description: Input sparse coordinates (pairs) to define the scalars, 𝑏𝑖 , as used in the scalar constraints.
HEADER: One line formatted as:
INT
This indicates the scalar constraint index 𝑖 ∈ ℐ and the coefficient value. The number of lines should
match the number stated in the header.
HCOORD
Description: Input sparse coordinates (quintuplets) to define the symmetric matrices, 𝐻𝑖𝑗 , as used in
the PSD constraints.
HEADER: One line formatted as:
INT
This indicates the PSD constraint index 𝑖 ∈ ℐ 𝑃 𝑆𝐷 , the scalar variable index 𝑗 ∈ 𝒥 , the row index, the
column index and the coefficient value. The number of lines should match the number stated in the
header.
DCOORD
Description: Input sparse coordinates (quadruplets) to define the symmetric matrices, 𝐷𝑖 , as used in
the PSD constraints.
HEADER: One line formatted as
INT
This indicates the PSD constraint index 𝑖 ∈ ℐ 𝑃 𝑆𝐷 , the row index, the column index and the coefficient
value. The number of lines should match the number stated in the header.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
CHANGE
Start of a new instance specification based on changes to the previous. Can be interpreted as the end of
file when the hotstart-sequence is unsupported or undesired.
BODY: None
Header: None
The conic optimization problem (17.6) , has three variables in a quadratic cone - first one is integer -
and an affine expression in domain 0 (equality constraint).
minimize 5.1 𝑥0
subject to 6.2 𝑥1 + 7.3 𝑥2 − 8.4 ∈ {0} (17.6)
𝑥 ∈ 𝒬3 , 𝑥0 ∈ Z.
Its formulation in the Conic Benchmark Format begins with the version of the CBF format used, to
safeguard against later revisions.
VER
1
Next follows the problem structure, consisting of the objective sense, the number and domain of variables,
the indices of integer variables, and the number and domain of scalar-valued affine expressions (i.e., the
equality constraint).
OBJSENSE
MIN
VAR
3 1
Q 3
INT
1
0
CON
1 1
L= 1
Finally follows the problem data, consisting of the coefficients of the objective, the coefficients of the
constraints, and the constant terms of the constraints. All data is specified on a sparse coordinate form.
OBJACOORD
1
0 5.1
ACOORD
2
0 1 6.2
0 2 7.3
BCOORD
1
0 -8.4
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
The conic optimization problem (17.7), has a semidefinite cone, a quadratic cone over unordered
subindices, and two equality constraints.
⟨⎡ 2 1 0 ⎤ ⟩
minimize ⎣ 1 2 1 , 𝑋1 + 𝑥1
⎦
0 1 2
⟨⎡ 1 0 0 ⎤ ⟩
subject to ⎣ 0 1 0 , 𝑋1 + 𝑥1
⎦ = 1.0 ,
0 0 1 (17.7)
⟨⎡ 1 1 1 ⎤ ⟩
⎣ 1 1 1 ⎦ , 𝑋1 + 𝑥0 + 𝑥2 = 0.5 ,
1√︀ 1 1
𝑥1 ≥ 𝑥20 + 𝑥22 ,
𝑋1 ⪰ 0 .
The equality constraints are easily rewritten to the conic form, (𝑔0 , 𝑔1 ) ∈ {0}2 , by moving constants such
that the right-hand-side becomes zero. The quadratic cone does not fit under the VAR keyword in this
variable permutation. Instead, it takes a scalar constraint (𝑔2 , 𝑔3 , 𝑔4 ) = (𝑥1 , 𝑥0 , 𝑥2 ) ∈ 𝒬3 , with scalar
variables constructed as (𝑥0 , 𝑥1 , 𝑥2 ) ∈ R3 . Its formulation in the CBF format is reported in the following
list
# File written using this version of the Conic Benchmark Format:
# | Version 1.
VER
1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
0 2 1 1.0
0 2 2 2.0
The standard forms in semidefinite optimization are usually based either on semidefinite variables or
linear matrix inequalities. In the CBF format, both forms are supported and can even be mixed as
shown in.
⟨[︂ ]︂ ⟩
1 0
minimize , 𝑋1 + 𝑥1 + 𝑥2 + 1
⟨[︂ 0 1 ]︂ ⟩
0 1
subject to , 𝑋1 − 𝑥1 − 𝑥2 ≥ 0.0 ,
[︂ 1 0 ]︂ [︂ ]︂ [︂ ]︂ (17.8)
0 1 3 1 1 0
𝑥1 + 𝑥2 − ⪰ 0,
1 3 1 0 0 1
𝑋1 ⪰ 0 .
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# One scalar constraint with an affine expression in this one conic domain:
# | One is greater than or equal to zero.
CON
1 1
L+ 1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# | a[0,1] = -1.0
ACOORD
2
0 0 -1.0
0 1 -1.0
The linear optimization problem (17.9), is defined for a sequence of objectives such that hotstarting from
one to the next might be advantages.
maximize𝑘 𝑔𝑘𝑜𝑏𝑗
subject to 50 𝑥0 + 31 ≤ 250 ,
(17.9)
3 𝑥0 − 2𝑥1 ≥ −4 ,
𝑥 ∈ R2+ ,
given,
1. 𝑔0𝑜𝑏𝑗 = 𝑥0 + 0.64𝑥1 .
2. 𝑔1𝑜𝑏𝑗 = 1.11𝑥0 + 0.76𝑥1 .
3. 𝑔2𝑜𝑏𝑗 = 1.11𝑥0 + 0.85𝑥1 .
Its formulation in the CBF format is reported in Listing 17.5.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
# Two scalar constraints with affine expressions in these two conic domains:
# | One is in the nonpositive domain.
# | One is in the nonnegative domain.
CON
2 2
L- 1
L+ 1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
MOSEK can write data in the standard OSiL xml format. For a definition of the OSiL format please
see http://www.optimizationservices.org/.
Only linear constraints (possibly with integer variables) are supported. By default output files with the
extension .xml are written in the OSiL format.
The parameter iparam.write_xml_mode controls if the linear coefficients in the 𝐴 matrix are written
in row or column order.
The Task format is MOSEK‘s native binary format. It contains a complete image of a MOSEK task,
i.e.
• Problem data: Linear, conic quadratic, semidefinite and quadratic data
• Problem item names: Variable names, constraints names, cone names etc.
• Parameter settings
• Solutions
There are a few things to be aware of:
• The task format does not support General Convex problems since these are defined by arbitrary
user-defined functions.
• Status of a solution read from a file will always be unknown.
The format is based on the TAR (USTar) file format. This means that the individual pieces of data in
a .task file can be examined by unpacking it as a TAR file. Please note that the inverse may not work:
Creating a file using TAR will most probably not create a valid MOSEK Task file since the order of
the entries is important.
Warning: Despite being text-based human-readable formats, jtask and jsol files will include no
indentation and no new-lines, in order to keep the files as compact as possible. We therefore strongly
advise to use JSON viewer tools to inspect jtask and jsol files.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
It stores a problem instance. The jtask format contains the same information as a task format.
Even though a jtask file is human-readable, we do not recommend users to create it by hand, but to rely
on MOSEK.
It stores a problem solution. The jsol format contains all solutions and information items.
You can write a jsol file using task.writejsonsol . You can not read a jsol file into MOSEK.
In Listing 17.6 we present a file in the jtask format that corresponds to the sample problem from lo1.lp.
The listing has been formatted for readability.
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
1e+30
],
"type":[
"cont",
"cont",
"cont",
"cont"
]
},
"con":{
"name":[
"c1",
"c2",
"c3"
],
"bk":[
"fx",
"lo",
"up"
],
"bl":[
3e+1,
1.5e+1,
-1e+30
],
"bu":[
3e+1,
1e+30,
2.5e+1
]
},
"objective":{
"sense":"max",
"name":"obj",
"c":{
"subj":[
0,
1,
2,
3
],
"val":[
3e+0,
1e+0,
5e+0,
1e+0
]
},
"cfix":0.0
},
"A":{
"subi":[
0,
0,
0,
1,
1,
1,
1,
2,
2
],
"subj":[
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
0,
1,
2,
0,
1,
2,
3,
1,
3
],
"val":[
3e+0,
1e+0,
2e+0,
2e+0,
1e+0,
3e+0,
1e+0,
2e+0,
3e+0
]
}
},
"Task/parameters":{
"iparam":{
"ANA_SOL_BASIS":"ON",
"ANA_SOL_PRINT_VIOLATED":"OFF",
"AUTO_SORT_A_BEFORE_OPT":"OFF",
"AUTO_UPDATE_SOL_INFO":"OFF",
"BASIS_SOLVE_USE_PLUS_ONE":"OFF",
"BI_CLEAN_OPTIMIZER":"OPTIMIZER_FREE",
"BI_IGNORE_MAX_ITER":"OFF",
"BI_IGNORE_NUM_ERROR":"OFF",
"BI_MAX_ITERATIONS":1000000,
"CACHE_LICENSE":"ON",
"CHECK_CONVEXITY":"CHECK_CONVEXITY_FULL",
"COMPRESS_STATFILE":"ON",
"CONCURRENT_NUM_OPTIMIZERS":2,
"CONCURRENT_PRIORITY_DUAL_SIMPLEX":2,
"CONCURRENT_PRIORITY_FREE_SIMPLEX":3,
"CONCURRENT_PRIORITY_INTPNT":4,
"CONCURRENT_PRIORITY_PRIMAL_SIMPLEX":1,
"FEASREPAIR_OPTIMIZE":"FEASREPAIR_OPTIMIZE_NONE",
"INFEAS_GENERIC_NAMES":"OFF",
"INFEAS_PREFER_PRIMAL":"ON",
"INFEAS_REPORT_AUTO":"OFF",
"INFEAS_REPORT_LEVEL":1,
"INTPNT_BASIS":"BI_ALWAYS",
"INTPNT_DIFF_STEP":"ON",
"INTPNT_FACTOR_DEBUG_LVL":0,
"INTPNT_FACTOR_METHOD":0,
"INTPNT_HOTSTART":"INTPNT_HOTSTART_NONE",
"INTPNT_MAX_ITERATIONS":400,
"INTPNT_MAX_NUM_COR":-1,
"INTPNT_MAX_NUM_REFINEMENT_STEPS":-1,
"INTPNT_OFF_COL_TRH":40,
"INTPNT_ORDER_METHOD":"ORDER_METHOD_FREE",
"INTPNT_REGULARIZATION_USE":"ON",
"INTPNT_SCALING":"SCALING_FREE",
"INTPNT_SOLVE_FORM":"SOLVE_FREE",
"INTPNT_STARTING_POINT":"STARTING_POINT_FREE",
"LIC_TRH_EXPIRY_WRN":7,
"LICENSE_DEBUG":"OFF",
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
"LICENSE_PAUSE_TIME":0,
"LICENSE_SUPPRESS_EXPIRE_WRNS":"OFF",
"LICENSE_WAIT":"OFF",
"LOG":10,
"LOG_ANA_PRO":1,
"LOG_BI":4,
"LOG_BI_FREQ":2500,
"LOG_CHECK_CONVEXITY":0,
"LOG_CONCURRENT":1,
"LOG_CUT_SECOND_OPT":1,
"LOG_EXPAND":0,
"LOG_FACTOR":1,
"LOG_FEAS_REPAIR":1,
"LOG_FILE":1,
"LOG_HEAD":1,
"LOG_INFEAS_ANA":1,
"LOG_INTPNT":4,
"LOG_MIO":4,
"LOG_MIO_FREQ":1000,
"LOG_OPTIMIZER":1,
"LOG_ORDER":1,
"LOG_PRESOLVE":1,
"LOG_RESPONSE":0,
"LOG_SENSITIVITY":1,
"LOG_SENSITIVITY_OPT":0,
"LOG_SIM":4,
"LOG_SIM_FREQ":1000,
"LOG_SIM_MINOR":1,
"LOG_STORAGE":1,
"MAX_NUM_WARNINGS":10,
"MIO_BRANCH_DIR":"BRANCH_DIR_FREE",
"MIO_CONSTRUCT_SOL":"OFF",
"MIO_CUT_CLIQUE":"ON",
"MIO_CUT_CMIR":"ON",
"MIO_CUT_GMI":"ON",
"MIO_CUT_KNAPSACK_COVER":"OFF",
"MIO_HEURISTIC_LEVEL":-1,
"MIO_MAX_NUM_BRANCHES":-1,
"MIO_MAX_NUM_RELAXS":-1,
"MIO_MAX_NUM_SOLUTIONS":-1,
"MIO_MODE":"MIO_MODE_SATISFIED",
"MIO_MT_USER_CB":"ON",
"MIO_NODE_OPTIMIZER":"OPTIMIZER_FREE",
"MIO_NODE_SELECTION":"MIO_NODE_SELECTION_FREE",
"MIO_PERSPECTIVE_REFORMULATE":"ON",
"MIO_PROBING_LEVEL":-1,
"MIO_RINS_MAX_NODES":-1,
"MIO_ROOT_OPTIMIZER":"OPTIMIZER_FREE",
"MIO_ROOT_REPEAT_PRESOLVE_LEVEL":-1,
"MT_SPINCOUNT":0,
"NUM_THREADS":0,
"OPF_MAX_TERMS_PER_LINE":5,
"OPF_WRITE_HEADER":"ON",
"OPF_WRITE_HINTS":"ON",
"OPF_WRITE_PARAMETERS":"OFF",
"OPF_WRITE_PROBLEM":"ON",
"OPF_WRITE_SOL_BAS":"ON",
"OPF_WRITE_SOL_ITG":"ON",
"OPF_WRITE_SOL_ITR":"ON",
"OPF_WRITE_SOLUTIONS":"OFF",
"OPTIMIZER":"OPTIMIZER_FREE",
"PARAM_READ_CASE_NAME":"ON",
"PARAM_READ_IGN_ERROR":"OFF",
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
"PRESOLVE_ELIMINATOR_MAX_FILL":-1,
"PRESOLVE_ELIMINATOR_MAX_NUM_TRIES":-1,
"PRESOLVE_LEVEL":-1,
"PRESOLVE_LINDEP_ABS_WORK_TRH":100,
"PRESOLVE_LINDEP_REL_WORK_TRH":100,
"PRESOLVE_LINDEP_USE":"ON",
"PRESOLVE_MAX_NUM_REDUCTIONS":-1,
"PRESOLVE_USE":"PRESOLVE_MODE_FREE",
"PRIMAL_REPAIR_OPTIMIZER":"OPTIMIZER_FREE",
"QO_SEPARABLE_REFORMULATION":"OFF",
"READ_DATA_COMPRESSED":"COMPRESS_FREE",
"READ_DATA_FORMAT":"DATA_FORMAT_EXTENSION",
"READ_DEBUG":"OFF",
"READ_KEEP_FREE_CON":"OFF",
"READ_LP_DROP_NEW_VARS_IN_BOU":"OFF",
"READ_LP_QUOTED_NAMES":"ON",
"READ_MPS_FORMAT":"MPS_FORMAT_FREE",
"READ_MPS_WIDTH":1024,
"READ_TASK_IGNORE_PARAM":"OFF",
"SENSITIVITY_ALL":"OFF",
"SENSITIVITY_OPTIMIZER":"OPTIMIZER_FREE_SIMPLEX",
"SENSITIVITY_TYPE":"SENSITIVITY_TYPE_BASIS",
"SIM_BASIS_FACTOR_USE":"ON",
"SIM_DEGEN":"SIM_DEGEN_FREE",
"SIM_DUAL_CRASH":90,
"SIM_DUAL_PHASEONE_METHOD":0,
"SIM_DUAL_RESTRICT_SELECTION":50,
"SIM_DUAL_SELECTION":"SIM_SELECTION_FREE",
"SIM_EXPLOIT_DUPVEC":"SIM_EXPLOIT_DUPVEC_OFF",
"SIM_HOTSTART":"SIM_HOTSTART_FREE",
"SIM_HOTSTART_LU":"ON",
"SIM_INTEGER":0,
"SIM_MAX_ITERATIONS":10000000,
"SIM_MAX_NUM_SETBACKS":250,
"SIM_NON_SINGULAR":"ON",
"SIM_PRIMAL_CRASH":90,
"SIM_PRIMAL_PHASEONE_METHOD":0,
"SIM_PRIMAL_RESTRICT_SELECTION":50,
"SIM_PRIMAL_SELECTION":"SIM_SELECTION_FREE",
"SIM_REFACTOR_FREQ":0,
"SIM_REFORMULATION":"SIM_REFORMULATION_OFF",
"SIM_SAVE_LU":"OFF",
"SIM_SCALING":"SCALING_FREE",
"SIM_SCALING_METHOD":"SCALING_METHOD_POW2",
"SIM_SOLVE_FORM":"SOLVE_FREE",
"SIM_STABILITY_PRIORITY":50,
"SIM_SWITCH_OPTIMIZER":"OFF",
"SOL_FILTER_KEEP_BASIC":"OFF",
"SOL_FILTER_KEEP_RANGED":"OFF",
"SOL_READ_NAME_WIDTH":-1,
"SOL_READ_WIDTH":1024,
"SOLUTION_CALLBACK":"OFF",
"TIMING_LEVEL":1,
"WRITE_BAS_CONSTRAINTS":"ON",
"WRITE_BAS_HEAD":"ON",
"WRITE_BAS_VARIABLES":"ON",
"WRITE_DATA_COMPRESSED":0,
"WRITE_DATA_FORMAT":"DATA_FORMAT_EXTENSION",
"WRITE_DATA_PARAM":"OFF",
"WRITE_FREE_CON":"OFF",
"WRITE_GENERIC_NAMES":"OFF",
"WRITE_GENERIC_NAMES_IO":1,
"WRITE_IGNORE_INCOMPATIBLE_CONIC_ITEMS":"OFF",
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
"WRITE_IGNORE_INCOMPATIBLE_ITEMS":"OFF",
"WRITE_IGNORE_INCOMPATIBLE_NL_ITEMS":"OFF",
"WRITE_IGNORE_INCOMPATIBLE_PSD_ITEMS":"OFF",
"WRITE_INT_CONSTRAINTS":"ON",
"WRITE_INT_HEAD":"ON",
"WRITE_INT_VARIABLES":"ON",
"WRITE_LP_FULL_OBJ":"ON",
"WRITE_LP_LINE_WIDTH":80,
"WRITE_LP_QUOTED_NAMES":"ON",
"WRITE_LP_STRICT_FORMAT":"OFF",
"WRITE_LP_TERMS_PER_LINE":10,
"WRITE_MPS_FORMAT":"MPS_FORMAT_FREE",
"WRITE_MPS_INT":"ON",
"WRITE_PRECISION":15,
"WRITE_SOL_BARVARIABLES":"ON",
"WRITE_SOL_CONSTRAINTS":"ON",
"WRITE_SOL_HEAD":"ON",
"WRITE_SOL_IGNORE_INVALID_NAMES":"OFF",
"WRITE_SOL_VARIABLES":"ON",
"WRITE_TASK_INC_SOL":"ON",
"WRITE_XML_MODE":"WRITE_XML_MODE_ROW"
},
"dparam":{
"ANA_SOL_INFEAS_TOL":1e-6,
"BASIS_REL_TOL_S":1e-12,
"BASIS_TOL_S":1e-6,
"BASIS_TOL_X":1e-6,
"CHECK_CONVEXITY_REL_TOL":1e-10,
"DATA_TOL_AIJ":1e-12,
"DATA_TOL_AIJ_HUGE":1e+20,
"DATA_TOL_AIJ_LARGE":1e+10,
"DATA_TOL_BOUND_INF":1e+16,
"DATA_TOL_BOUND_WRN":1e+8,
"DATA_TOL_C_HUGE":1e+16,
"DATA_TOL_CJ_LARGE":1e+8,
"DATA_TOL_QIJ":1e-16,
"DATA_TOL_X":1e-8,
"FEASREPAIR_TOL":1e-10,
"INTPNT_CO_TOL_DFEAS":1e-8,
"INTPNT_CO_TOL_INFEAS":1e-10,
"INTPNT_CO_TOL_MU_RED":1e-8,
"INTPNT_CO_TOL_NEAR_REL":1e+3,
"INTPNT_CO_TOL_PFEAS":1e-8,
"INTPNT_CO_TOL_REL_GAP":1e-7,
"INTPNT_NL_MERIT_BAL":1e-4,
"INTPNT_NL_TOL_DFEAS":1e-8,
"INTPNT_NL_TOL_MU_RED":1e-12,
"INTPNT_NL_TOL_NEAR_REL":1e+3,
"INTPNT_NL_TOL_PFEAS":1e-8,
"INTPNT_NL_TOL_REL_GAP":1e-6,
"INTPNT_NL_TOL_REL_STEP":9.95e-1,
"INTPNT_QO_TOL_DFEAS":1e-8,
"INTPNT_QO_TOL_INFEAS":1e-10,
"INTPNT_QO_TOL_MU_RED":1e-8,
"INTPNT_QO_TOL_NEAR_REL":1e+3,
"INTPNT_QO_TOL_PFEAS":1e-8,
"INTPNT_QO_TOL_REL_GAP":1e-8,
"INTPNT_TOL_DFEAS":1e-8,
"INTPNT_TOL_DSAFE":1e+0,
"INTPNT_TOL_INFEAS":1e-10,
"INTPNT_TOL_MU_RED":1e-16,
"INTPNT_TOL_PATH":1e-8,
"INTPNT_TOL_PFEAS":1e-8,
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
"INTPNT_TOL_PSAFE":1e+0,
"INTPNT_TOL_REL_GAP":1e-8,
"INTPNT_TOL_REL_STEP":9.999e-1,
"INTPNT_TOL_STEP_SIZE":1e-6,
"LOWER_OBJ_CUT":-1e+30,
"LOWER_OBJ_CUT_FINITE_TRH":-5e+29,
"MIO_DISABLE_TERM_TIME":-1e+0,
"MIO_MAX_TIME":-1e+0,
"MIO_MAX_TIME_APRX_OPT":6e+1,
"MIO_NEAR_TOL_ABS_GAP":0.0,
"MIO_NEAR_TOL_REL_GAP":1e-3,
"MIO_REL_GAP_CONST":1e-10,
"MIO_TOL_ABS_GAP":0.0,
"MIO_TOL_ABS_RELAX_INT":1e-5,
"MIO_TOL_FEAS":1e-6,
"MIO_TOL_REL_DUAL_BOUND_IMPROVEMENT":0.0,
"MIO_TOL_REL_GAP":1e-4,
"MIO_TOL_X":1e-6,
"OPTIMIZER_MAX_TIME":-1e+0,
"PRESOLVE_TOL_ABS_LINDEP":1e-6,
"PRESOLVE_TOL_AIJ":1e-12,
"PRESOLVE_TOL_REL_LINDEP":1e-10,
"PRESOLVE_TOL_S":1e-8,
"PRESOLVE_TOL_X":1e-8,
"QCQO_REFORMULATE_REL_DROP_TOL":1e-15,
"SEMIDEFINITE_TOL_APPROX":1e-10,
"SIM_LU_TOL_REL_PIV":1e-2,
"SIMPLEX_ABS_TOL_PIV":1e-7,
"UPPER_OBJ_CUT":1e+30,
"UPPER_OBJ_CUT_FINITE_TRH":5e+29
},
"sparam":{
"BAS_SOL_FILE_NAME":"",
"DATA_FILE_NAME":"examples/tools/data/lo1.mps",
"DEBUG_FILE_NAME":"",
"INT_SOL_FILE_NAME":"",
"ITR_SOL_FILE_NAME":"",
"MIO_DEBUG_STRING":"",
"PARAM_COMMENT_SIGN":"%%",
"PARAM_READ_FILE_NAME":"",
"PARAM_WRITE_FILE_NAME":"",
"READ_MPS_BOU_NAME":"",
"READ_MPS_OBJ_NAME":"",
"READ_MPS_RAN_NAME":"",
"READ_MPS_RHS_NAME":"",
"SENSITIVITY_FILE_NAME":"",
"SENSITIVITY_RES_FILE_NAME":"",
"SOL_FILTER_XC_LOW":"",
"SOL_FILTER_XC_UPR":"",
"SOL_FILTER_XX_LOW":"",
"SOL_FILTER_XX_UPR":"",
"STAT_FILE_NAME":"",
"STAT_KEY":"",
"STAT_NAME":"",
"WRITE_LP_GEN_VAR_NAME":"XMSKGEN"
}
}
}
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
MOSEK provides several solution files depending on the problem type and the optimizer used:
• basis solution file (extension .bas) if the problem is optimized using the simplex optimizer or basis
identification is performed,
• interior solution file (extension .sol) if a problem is optimized using the interior-point optimizer
and no basis identification is required,
• integer solution file (extension .int) if the problem contains integer constrained variables.
All solution files have the format:
? <name> ?? <a value> <a value> <a value> <a value> <a value> <a value>
In the example the fields ? and <> will be filled with problem and solution specific information. As can
be observed a solution report consists of three sections, i.e.
• HEADER In this section, first the name of the problem is listed and afterwards the problem and
solution status are shown. Next the primal and dual objective values are displayed.
• CONSTRAINTS For each constraint 𝑖 of the form
𝑛
∑︁
𝑙𝑖𝑐 ≤ 𝑎𝑖𝑗 𝑥𝑗 ≤ 𝑢𝑐𝑖 , (17.10)
𝑗=1
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
– DUAL LOWER: the dual multiplier corresponding to the lower limit on the constraint.
– DUAL UPPER: the dual multiplier corresponding to the upper limit on the constraint.
• VARIABLES The last section of the solution report lists information about the variables. This
information has a similar interpretation as for the constraints. However, the column with
the header CONIC DUAL is included for problems having one or more conic constraints. This
column shows the dual variables corresponding to the conic constraints.
Example: lo1.sol
In Listing 17.7 we show the solution file for the lo1.opf problem.
CONSTRAINTS
INDEX NAME AT ACTIVITY LOWER LIMIT UPPER LIMIT ␣
˓→DUAL LOWER DUAL UPPER
0 c1 EQ 3.00000000000000e+01 3.00000000e+01 3.00000000e+01 -0.
˓→00000000000000e+00 -2.49999999741654e+00
1 c2 SB 5.33333333049188e+01 1.50000000e+01 NONE 2.
˓→09157603759397e-10 -0.00000000000000e+00
2 c3 UL 2.49999999842049e+01 NONE 2.50000000e+01 -0.
˓→00000000000000e+00 -3.33333332895110e-01
VARIABLES
INDEX NAME AT ACTIVITY LOWER LIMIT UPPER LIMIT ␣
˓→DUAL LOWER DUAL UPPER
0 x1 LL 1.67020427073508e-09 0.00000000e+00 NONE -4.
˓→49999999528055e+00 -0.00000000000000e+00
1 x2 LL 2.93510446280504e-09 0.00000000e+00 1.00000000e+01 -2.
˓→16666666494916e+00 6.20863861687316e-10
2 x3 SB 1.49999999899425e+01 0.00000000e+00 NONE -8.
˓→79123177454657e-10 -0.00000000000000e+00
3 x4 SB 8.33333332273116e+00 0.00000000e+00 NONE -1.
˓→69795978899185e-09 -0.00000000000000e+00
www.EngineeringBooksPdf.com
CHAPTER
EIGHTEEN
INTERFACE CHANGES
The section show interface-specific changes to the MOSEK Optimizer API for Python in version 8. See
the release notes for general changes and new features of the MOSEK Optimization Suite.
18.1 Compatibility
• All input functions of the form putXXXlist now perform strict dimensional checking. That means
all input arrays must have the same size. In previous release they were allowed to differs and
MOSEK would have used the shortest dimension.
• Compatibility guarantees for this interface has been updated. See the new state of compatibility.
18.2 Functions
Added
Changed
Removed
• Env.putdllpath
• Env.putkeepdlls
• Task.getdbi
• Task.getdcni
• Task.getdeqi
• Task.getinti
• Task.getnumqconknz64
• Task.getpbi
• Task.getpcni
• Task.getpeqi
• Task.getqobj64
• Task.getsolutioninf
• Task.getvarbranchdir
• Task.getvarbranchpri
• Task.optimizeconcurrent
381
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• Task.putvarbranchorder
• Task.readbranchpriorities
• Task.relaxprimal
• Task.writebranchpriorities
18.3 Parameters
Added
• dparam.data_sym_mat_tol
• dparam.data_sym_mat_tol_huge
• dparam.data_sym_mat_tol_large
• dparam.intpnt_qo_tol_dfeas
• dparam.intpnt_qo_tol_infeas
• dparam.intpnt_qo_tol_mu_red
• dparam.intpnt_qo_tol_near_rel
• dparam.intpnt_qo_tol_pfeas
• dparam.intpnt_qo_tol_rel_gap
• dparam.semidefinite_tol_approx
• iparam.intpnt_multi_thread
• iparam.license_trh_expiry_wrn
• iparam.log_ana_pro
• iparam.mio_cut_clique
• iparam.mio_cut_gmi
• iparam.mio_cut_implied_bound
• iparam.mio_cut_knapsack_cover
• iparam.mio_cut_selection_level
• iparam.mio_perspective_reformulate
• iparam.mio_root_repeat_presolve_level
• iparam.mio_vb_detection_level
• iparam.presolve_eliminator_max_fill
Removed
• dparam.feasrepair_tol
• dparam.mio_heuristic_time
• dparam.mio_max_time_aprx_opt
• dparam.mio_rel_add_cut_limited
• dparam.mio_tol_max_cut_frac_rhs
• dparam.mio_tol_min_cut_frac_rhs
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• dparam.mio_tol_rel_relax_int
• dparam.mio_tol_x
• dparam.nonconvex_tol_feas
• dparam.nonconvex_tol_opt
• iparam.alloc_add_qnz
• iparam.concurrent_num_optimizers
• iparam.concurrent_priority_dual_simplex
• iparam.concurrent_priority_free_simplex
• iparam.concurrent_priority_intpnt
• iparam.concurrent_priority_primal_simplex
• iparam.feasrepair_optimize
• iparam.intpnt_factor_debug_lvl
• iparam.intpnt_factor_method
• iparam.lic_trh_expiry_wrn
• iparam.log_concurrent
• iparam.log_nonconvex
• iparam.log_param
• iparam.log_sim_network_freq
• iparam.mio_branch_priorities_use
• iparam.mio_cont_sol
• iparam.mio_cut_cg
• iparam.mio_cut_level_root
• iparam.mio_cut_level_tree
• iparam.mio_feaspump_level
• iparam.mio_hotstart
• iparam.mio_keep_basis
• iparam.mio_local_branch_number
• iparam.mio_optimizer_mode
• iparam.mio_presolve_aggregate
• iparam.mio_presolve_probing
• iparam.mio_presolve_use
• iparam.mio_strong_branch
• iparam.mio_use_multithreaded_optimizer
• iparam.nonconvex_max_iterations
• iparam.presolve_elim_fill
• iparam.presolve_eliminator_use
• iparam.qo_separable_reformulation
• iparam.read_anz
• iparam.read_con
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• iparam.read_cone
• iparam.read_mps_keep_int
• iparam.read_mps_obj_sense
• iparam.read_mps_relax
• iparam.read_qnz
• iparam.read_var
• iparam.warning_level
• iparam.write_ignore_incompatible_conic_items
• iparam.write_ignore_incompatible_nl_items
• iparam.write_ignore_incompatible_psd_items
• sparam.feasrepair_name_prefix
• sparam.feasrepair_name_separator
• sparam.feasrepair_name_wsumviol
18.4 Constants
Added
• branchdir.far
• branchdir.guided
• branchdir.near
• branchdir.pseudocost
• branchdir.root_lp
• callbackcode.begin_root_cutgen
• callbackcode.begin_to_conic
• callbackcode.end_root_cutgen
• callbackcode.end_to_conic
• callbackcode.im_root_cutgen
• callbackcode.solving_remote
• dataformat.json_task
• dinfitem.mio_clique_separation_time
• dinfitem.mio_cmir_separation_time
• dinfitem.mio_gmi_separation_time
• dinfitem.mio_implied_bound_time
• dinfitem.mio_knapsack_cover_separation_time
• dinfitem.qcqo_reformulate_max_perturbation
• dinfitem.qcqo_reformulate_worst_cholesky_column_scaling
• dinfitem.qcqo_reformulate_worst_cholesky_diag_scaling
• dinfitem.sol_bas_nrm_barx
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• dinfitem.sol_bas_nrm_slc
• dinfitem.sol_bas_nrm_slx
• dinfitem.sol_bas_nrm_suc
• dinfitem.sol_bas_nrm_sux
• dinfitem.sol_bas_nrm_xc
• dinfitem.sol_bas_nrm_xx
• dinfitem.sol_bas_nrm_y
• dinfitem.sol_itg_nrm_barx
• dinfitem.sol_itg_nrm_xc
• dinfitem.sol_itg_nrm_xx
• dinfitem.sol_itr_nrm_bars
• dinfitem.sol_itr_nrm_barx
• dinfitem.sol_itr_nrm_slc
• dinfitem.sol_itr_nrm_slx
• dinfitem.sol_itr_nrm_snx
• dinfitem.sol_itr_nrm_suc
• dinfitem.sol_itr_nrm_sux
• dinfitem.sol_itr_nrm_xc
• dinfitem.sol_itr_nrm_xx
• dinfitem.sol_itr_nrm_y
• dinfitem.to_conic_time
• iinfitem.mio_absgap_satisfied
• iinfitem.mio_clique_table_size
• iinfitem.mio_near_absgap_satisfied
• iinfitem.mio_near_relgap_satisfied
• iinfitem.mio_node_depth
• iinfitem.mio_num_cmir_cuts
• iinfitem.mio_num_implied_bound_cuts
• iinfitem.mio_num_knapsack_cover_cuts
• iinfitem.mio_num_repeated_presolve
• iinfitem.mio_presolved_numbin
• iinfitem.mio_presolved_numcon
• iinfitem.mio_presolved_numcont
• iinfitem.mio_presolved_numint
• iinfitem.mio_presolved_numvar
• iinfitem.mio_relgap_satisfied
• liinfitem.mio_presolved_anz
• liinfitem.mio_sim_maxiter_setbacks
• mpsformat.cplex
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• solsta.dual_illposed_cer
• solsta.prim_illposed_cer
Changed
• solsta.integer_optimal
• solsta.near_integer_optimal
Removed
• constant.callbackcode.begin_concurrent
• constant.callbackcode.begin_network_dual_simplex
• constant.callbackcode.begin_network_primal_simplex
• constant.callbackcode.begin_network_simplex
• constant.callbackcode.begin_nonconvex
• constant.callbackcode.begin_simplex_network_detect
• constant.callbackcode.end_concurrent
• constant.callbackcode.end_network_dual_simplex
• constant.callbackcode.end_network_primal_simplex
• constant.callbackcode.end_network_simplex
• constant.callbackcode.end_nonconvex
• constant.callbackcode.end_simplex_network_detect
• constant.callbackcode.im_mio_presolve
• constant.callbackcode.im_network_dual_simplex
• constant.callbackcode.im_network_primal_simplex
• constant.callbackcode.im_nonconvex
• constant.callbackcode.noncovex
• constant.callbackcode.update_network_dual_simplex
• constant.callbackcode.update_network_primal_simplex
• constant.callbackcode.update_nonconvex
• constant.dinfitem.concurrent_time
• constant.dinfitem.mio_cg_seperation_time
• constant.dinfitem.mio_cmir_seperation_time
• constant.dinfitem.sim_network_dual_time
• constant.dinfitem.sim_network_primal_time
• constant.dinfitem.sim_network_time
• constant.feature.ptom
• constant.feature.ptox
• constant.iinfitem.concurrent_fastest_optimizer
• constant.iinfitem.mio_num_basis_cuts
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• constant.iinfitem.mio_num_cardgub_cuts
• constant.iinfitem.mio_num_coef_redc_cuts
• constant.iinfitem.mio_num_contra_cuts
• constant.iinfitem.mio_num_disagg_cuts
• constant.iinfitem.mio_num_flow_cover_cuts
• constant.iinfitem.mio_num_gcd_cuts
• constant.iinfitem.mio_num_gub_cover_cuts
• constant.iinfitem.mio_num_knapsur_cover_cuts
• constant.iinfitem.mio_num_lattice_cuts
• constant.iinfitem.mio_num_lift_cuts
• constant.iinfitem.mio_num_obj_cuts
• constant.iinfitem.mio_num_plan_loc_cuts
• constant.iinfitem.sim_network_dual_deg_iter
• constant.iinfitem.sim_network_dual_hotstart
• constant.iinfitem.sim_network_dual_hotstart_lu
• constant.iinfitem.sim_network_dual_inf_iter
• constant.iinfitem.sim_network_dual_iter
• constant.iinfitem.sim_network_primal_deg_iter
• constant.iinfitem.sim_network_primal_hotstart
• constant.iinfitem.sim_network_primal_hotstart_lu
• constant.iinfitem.sim_network_primal_inf_iter
• constant.iinfitem.sim_network_primal_iter
• constant.iinfitem.sol_int_prosta
• constant.iinfitem.sol_int_solsta
• constant.iinfitem.sto_num_a_cache_flushes
• constant.iinfitem.sto_num_a_transposes
• constant.miomode.lazy
• constant.optimizertype.concurrent
• constant.optimizertype.mixed_int_conic
• constant.optimizertype.network_primal_simplex
• constant.optimizertype.nonconvex
• constant.optimizertype.primal_dual_simplex
Added
• rescode.err_duplicate_aij (1385)
• rescode.err_json_data (1179)
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• rescode.err_json_format (1178)
• rescode.err_json_missing_data (1180)
• rescode.err_json_number_overflow (1177)
• rescode.err_json_string (1176)
• rescode.err_json_syntax (1175)
• rescode.err_lau_invalid_lower_triangular_matrix (7002)
• rescode.err_lau_invalid_sparse_symmetric_matrix (7019)
• rescode.err_lau_not_positive_definite (7001)
• rescode.err_mixed_conic_and_nl (1501)
• rescode.err_server_connect (8000)
• rescode.err_server_protocol (8001)
• rescode.err_server_status (8002)
• rescode.err_server_token (8003)
• rescode.err_sym_mat_huge (1482)
• rescode.err_sym_mat_invalid (1480)
• rescode.err_task_write (2562)
• rescode.err_toconic_constr_not_conic (7153)
• rescode.err_toconic_constr_q_not_psd (7150)
• rescode.err_toconic_constraint_fx (7151)
• rescode.err_toconic_constraint_ra (7152)
• rescode.err_toconic_objective_not_psd (7155)
• rescode.wrn_sym_mat_large (960)
Removed
• rescode.err_ad_invalid_operand
• rescode.err_ad_invalid_operator
• rescode.err_ad_missing_operand
• rescode.err_ad_missing_return
• rescode.err_concurrent_optimizer
• rescode.err_inv_conic_problem
• rescode.err_invalid_branch_direction
• rescode.err_invalid_branch_priority
• rescode.err_invalid_network_problem
• rescode.err_mbt_incompatible
• rescode.err_mbt_invalid
• rescode.err_mixed_problem
• rescode.err_no_dual_info_for_itg_sol
• rescode.err_ord_invalid
• rescode.err_ord_invalid_branch_dir
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
• rescode.err_toconic_conversion_fail
• rescode.err_too_many_concurrent_tasks
• rescode.wrn_too_many_threads_concurrent
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
BIBLIOGRAPHY
391
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
[MOSEKApS12] MOSEK ApS. The MOSEK Modeling Cookbook. MOSEK ApS, Fruebjergvej 3, Boks
16, 2100 Copenhagen O, 2012. Last revised September 2015. URL: http://docs.mosek.com/generic/
modeling-a4.pdf.
392 Bibliography
www.EngineeringBooksPdf.com
API INDEX
393
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_cbf_no_variables rescode.err_feasrepair_solving_relaxed
(err_cbf_no_variables), 216 (err_feasrepair_solving_relaxed), 217
rescode.err_cbf_no_version_specified rescode.err_file_license (err_file_license),
(err_cbf_no_version_specified), 216 217
rescode.err_cbf_obj_sense rescode.err_file_open (err_file_open), 217
(err_cbf_obj_sense), 216 rescode.err_file_read (err_file_read), 218
rescode.err_cbf_parse (err_cbf_parse), 216 rescode.err_file_write (err_file_write), 218
rescode.err_cbf_syntax (err_cbf_syntax), 216 rescode.err_first (err_first), 218
rescode.err_cbf_too_few_constraints rescode.err_firsti (err_firsti), 218
(err_cbf_too_few_constraints), 216 rescode.err_firstj (err_firstj), 218
rescode.err_cbf_too_few_ints rescode.err_fixed_bound_values
(err_cbf_too_few_ints), 216 (err_fixed_bound_values), 218
rescode.err_cbf_too_few_variables rescode.err_flexlm (err_flexlm), 218
(err_cbf_too_few_variables), 216 rescode.err_global_inv_conic_problem
rescode.err_cbf_too_many_constraints (err_global_inv_conic_problem), 218
(err_cbf_too_many_constraints), 216 rescode.err_huge_aij (err_huge_aij), 218
rescode.err_cbf_too_many_ints rescode.err_huge_c (err_huge_c), 218
(err_cbf_too_many_ints), 216 rescode.err_identical_tasks
rescode.err_cbf_too_many_variables (err_identical_tasks), 218
(err_cbf_too_many_variables), 216 rescode.err_in_argument (err_in_argument),
rescode.err_cbf_unsupported 218
(err_cbf_unsupported), 216 rescode.err_index (err_index), 218
rescode.err_con_q_not_nsd rescode.err_index_arr_is_too_large
(err_con_q_not_nsd), 216 (err_index_arr_is_too_large), 218
rescode.err_con_q_not_psd rescode.err_index_arr_is_too_small
(err_con_q_not_psd), 216 (err_index_arr_is_too_small), 218
rescode.err_cone_index (err_cone_index), 217 rescode.err_index_is_too_large
rescode.err_cone_overlap (err_cone_overlap), (err_index_is_too_large), 218
217 rescode.err_index_is_too_small
rescode.err_cone_overlap_append (err_index_is_too_small), 218
(err_cone_overlap_append), 217 rescode.err_inf_dou_index
rescode.err_cone_rep_var (err_inf_dou_index), 218
(err_cone_rep_var), 217 rescode.err_inf_dou_name
rescode.err_cone_size (err_cone_size), 217 (err_inf_dou_name), 218
rescode.err_cone_type (err_cone_type), 217 rescode.err_inf_int_index
rescode.err_cone_type_str (err_inf_int_index), 218
(err_cone_type_str), 217 rescode.err_inf_int_name
rescode.err_data_file_ext (err_inf_int_name), 218
(err_data_file_ext), 217 rescode.err_inf_lint_index
rescode.err_dup_name (err_dup_name), 217 (err_inf_lint_index), 218
rescode.err_duplicate_aij rescode.err_inf_lint_name
(err_duplicate_aij), 217 (err_inf_lint_name), 218
rescode.err_duplicate_barvariable_names rescode.err_inf_type (err_inf_type), 219
(err_duplicate_barvariable_names), 217 rescode.err_infeas_undefined
rescode.err_duplicate_cone_names (err_infeas_undefined), 219
(err_duplicate_cone_names), 217 rescode.err_infinite_bound
rescode.err_duplicate_constraint_names (err_infinite_bound), 219
(err_duplicate_constraint_names), 217 rescode.err_int64_to_int32_cast
rescode.err_duplicate_variable_names (err_int64_to_int32_cast), 219
(err_duplicate_variable_names), 217 rescode.err_internal (err_internal), 219
rescode.err_end_of_file (err_end_of_file), rescode.err_internal_test_failed
217 (err_internal_test_failed), 219
rescode.err_factor (err_factor), 217 rescode.err_inv_aptre (err_inv_aptre), 219
rescode.err_feasrepair_cannot_relax rescode.err_inv_bk (err_inv_bk), 219
(err_feasrepair_cannot_relax), 217 rescode.err_inv_bkc (err_inv_bkc), 219
rescode.err_feasrepair_inconsistent_bound rescode.err_inv_bkx (err_inv_bkx), 219
(err_feasrepair_inconsistent_bound), rescode.err_inv_cone_type
217 (err_inv_cone_type), 219
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_inv_cone_type_str rescode.err_invalid_format_type
(err_inv_cone_type_str), 219 (err_invalid_format_type), 220
rescode.err_inv_marki (err_inv_marki), 219 rescode.err_invalid_idx (err_invalid_idx),
rescode.err_inv_markj (err_inv_markj), 219 220
rescode.err_inv_name_item rescode.err_invalid_iomode
(err_inv_name_item), 219 (err_invalid_iomode), 220
rescode.err_inv_numi (err_inv_numi), 219 rescode.err_invalid_max_num
rescode.err_inv_numj (err_inv_numj), 219 (err_invalid_max_num), 221
rescode.err_inv_optimizer rescode.err_invalid_name_in_sol_file
(err_inv_optimizer), 219 (err_invalid_name_in_sol_file), 221
rescode.err_inv_problem (err_inv_problem), rescode.err_invalid_obj_name
219 (err_invalid_obj_name), 221
rescode.err_inv_qcon_subi rescode.err_invalid_objective_sense
(err_inv_qcon_subi), 219 (err_invalid_objective_sense), 221
rescode.err_inv_qcon_subj rescode.err_invalid_problem_type
(err_inv_qcon_subj), 219 (err_invalid_problem_type), 221
rescode.err_inv_qcon_subk rescode.err_invalid_sol_file_name
(err_inv_qcon_subk), 219 (err_invalid_sol_file_name), 221
rescode.err_inv_qcon_val (err_inv_qcon_val), rescode.err_invalid_stream
219 (err_invalid_stream), 221
rescode.err_inv_qobj_subi rescode.err_invalid_surplus
(err_inv_qobj_subi), 220 (err_invalid_surplus), 221
rescode.err_inv_qobj_subj rescode.err_invalid_sym_mat_dim
(err_inv_qobj_subj), 220 (err_invalid_sym_mat_dim), 221
rescode.err_inv_qobj_val (err_inv_qobj_val), rescode.err_invalid_task (err_invalid_task),
220 221
rescode.err_inv_sk (err_inv_sk), 220 rescode.err_invalid_utf8 (err_invalid_utf8),
rescode.err_inv_sk_str (err_inv_sk_str), 220 221
rescode.err_inv_skc (err_inv_skc), 220 rescode.err_invalid_var_name
rescode.err_inv_skn (err_inv_skn), 220 (err_invalid_var_name), 221
rescode.err_inv_skx (err_inv_skx), 220 rescode.err_invalid_wchar
rescode.err_inv_var_type (err_inv_var_type), (err_invalid_wchar), 221
220 rescode.err_invalid_whichsol
rescode.err_invalid_accmode (err_invalid_whichsol), 221
(err_invalid_accmode), 220 rescode.err_json_data (err_json_data), 221
rescode.err_invalid_aij (err_invalid_aij), 220 rescode.err_json_format (err_json_format),
rescode.err_invalid_ampl_stub 221
(err_invalid_ampl_stub), 220 rescode.err_json_missing_data
rescode.err_invalid_barvar_name (err_json_missing_data), 221
(err_invalid_barvar_name), 220 rescode.err_json_number_overflow
rescode.err_invalid_compression (err_json_number_overflow), 221
(err_invalid_compression), 220 rescode.err_json_string (err_json_string),
rescode.err_invalid_con_name 221
(err_invalid_con_name), 220 rescode.err_json_syntax (err_json_syntax),
rescode.err_invalid_cone_name 221
(err_invalid_cone_name), 220 rescode.err_last (err_last), 221
rescode.err_invalid_file_format_for_cones rescode.err_lasti (err_lasti), 221
(err_invalid_file_format_for_cones), rescode.err_lastj (err_lastj), 221
220 rescode.err_lau_arg_k (err_lau_arg_k), 222
rescode.err_invalid_file_format_for_general_nl rescode.err_lau_arg_m (err_lau_arg_m), 222
(err_invalid_file_format_for_general_nl),rescode.err_lau_arg_n (err_lau_arg_n), 222
220 rescode.err_lau_arg_trans
rescode.err_invalid_file_format_for_sym_mat (err_lau_arg_trans), 222
(err_invalid_file_format_for_sym_mat), rescode.err_lau_arg_transa
220 (err_lau_arg_transa), 222
rescode.err_invalid_file_name rescode.err_lau_arg_transb
(err_invalid_file_name), 220 (err_lau_arg_transb), 222
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_mps_mul_qobj rescode.err_no_primal_infeas_cer
(err_mps_mul_qobj), 225 (err_no_primal_infeas_cer), 226
rescode.err_mps_mul_qsec rescode.err_no_snx_for_bas_sol
(err_mps_mul_qsec), 225 (err_no_snx_for_bas_sol), 226
rescode.err_mps_no_objective rescode.err_no_solution_in_callback
(err_mps_no_objective), 225 (err_no_solution_in_callback), 226
rescode.err_mps_non_symmetric_q rescode.err_non_unique_array
(err_mps_non_symmetric_q), 225 (err_non_unique_array), 226
rescode.err_mps_null_con_name rescode.err_nonconvex (err_nonconvex), 226
(err_mps_null_con_name), 225 rescode.err_nonlinear_equality
rescode.err_mps_null_var_name (err_nonlinear_equality), 226
(err_mps_null_var_name), 225 rescode.err_nonlinear_functions_not_allowed
rescode.err_mps_splitted_var (err_nonlinear_functions_not_allowed),
(err_mps_splitted_var), 225 226
rescode.err_mps_tab_in_field2 rescode.err_nonlinear_ranged
(err_mps_tab_in_field2), 225 (err_nonlinear_ranged), 226
rescode.err_mps_tab_in_field3 rescode.err_nr_arguments
(err_mps_tab_in_field3), 225 (err_nr_arguments), 226
rescode.err_mps_tab_in_field5 rescode.err_null_env (err_null_env), 226
(err_mps_tab_in_field5), 225 rescode.err_null_pointer (err_null_pointer),
rescode.err_mps_undef_con_name 227
(err_mps_undef_con_name), 225 rescode.err_null_task (err_null_task), 227
rescode.err_mps_undef_var_name rescode.err_numconlim (err_numconlim), 227
(err_mps_undef_var_name), 225 rescode.err_numvarlim (err_numvarlim), 227
rescode.err_mul_a_element rescode.err_obj_q_not_nsd
(err_mul_a_element), 225 (err_obj_q_not_nsd), 227
rescode.err_name_is_null rescode.err_obj_q_not_psd
(err_name_is_null), 225 (err_obj_q_not_psd), 227
rescode.err_name_max_len rescode.err_objective_range
(err_name_max_len), 225 (err_objective_range), 227
rescode.err_nan_in_blc (err_nan_in_blc), 225 rescode.err_older_dll (err_older_dll), 227
rescode.err_nan_in_blx (err_nan_in_blx), 225 rescode.err_open_dl (err_open_dl), 227
rescode.err_nan_in_buc (err_nan_in_buc), rescode.err_opf_format (err_opf_format), 227
225 rescode.err_opf_new_variable
rescode.err_nan_in_bux (err_nan_in_bux), (err_opf_new_variable), 227
225 rescode.err_opf_premature_eof
rescode.err_nan_in_c (err_nan_in_c), 226 (err_opf_premature_eof ), 227
rescode.err_nan_in_double_data rescode.err_optimizer_license
(err_nan_in_double_data), 226 (err_optimizer_license), 227
rescode.err_negative_append rescode.err_overflow (err_overflow), 227
(err_negative_append), 226 rescode.err_param_index (err_param_index),
rescode.err_negative_surplus 227
(err_negative_surplus), 226 rescode.err_param_is_too_large
rescode.err_newer_dll (err_newer_dll), 226 (err_param_is_too_large), 227
rescode.err_no_bars_for_solution rescode.err_param_is_too_small
(err_no_bars_for_solution), 226 (err_param_is_too_small), 227
rescode.err_no_barx_for_solution rescode.err_param_name (err_param_name),
(err_no_barx_for_solution), 226 227
rescode.err_no_basis_sol (err_no_basis_sol), rescode.err_param_name_dou
226 (err_param_name_dou), 227
rescode.err_no_dual_for_itg_sol rescode.err_param_name_int
(err_no_dual_for_itg_sol), 226 (err_param_name_int), 227
rescode.err_no_dual_infeas_cer rescode.err_param_name_str
(err_no_dual_infeas_cer), 226 (err_param_name_str), 227
rescode.err_no_init_env (err_no_init_env), rescode.err_param_type (err_param_type), 228
226 rescode.err_param_value_str
rescode.err_no_optimizer_var_type (err_param_value_str), 228
(err_no_optimizer_var_type), 226
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
rescode.err_platform_not_licensed rescode.err_size_license_con
(err_platform_not_licensed), 228 (err_size_license_con), 229
rescode.err_postsolve (err_postsolve), 228 rescode.err_size_license_intvar
rescode.err_pro_item (err_pro_item), 228 (err_size_license_intvar), 229
rescode.err_prob_license (err_prob_license), rescode.err_size_license_numcores
228 (err_size_license_numcores), 229
rescode.err_qcon_subi_too_large rescode.err_size_license_var
(err_qcon_subi_too_large), 228 (err_size_license_var), 229
rescode.err_qcon_subi_too_small rescode.err_sol_file_invalid_number
(err_qcon_subi_too_small), 228 (err_sol_file_invalid_number), 229
rescode.err_qcon_upper_triangle rescode.err_solitem (err_solitem), 229
(err_qcon_upper_triangle), 228 rescode.err_solver_probtype
rescode.err_qobj_upper_triangle (err_solver_probtype), 229
(err_qobj_upper_triangle), 228 rescode.err_space (err_space), 229
rescode.err_read_format (err_read_format), rescode.err_space_leaking
228 (err_space_leaking), 229
rescode.err_read_lp_missing_end_tag rescode.err_space_no_info
(err_read_lp_missing_end_tag), 228 (err_space_no_info), 229
rescode.err_read_lp_nonexisting_name rescode.err_sym_mat_duplicate
(err_read_lp_nonexisting_name), (err_sym_mat_duplicate), 229
228 rescode.err_sym_mat_huge
rescode.err_remove_cone_variable (err_sym_mat_huge), 229
(err_remove_cone_variable), 228 rescode.err_sym_mat_invalid
rescode.err_repair_invalid_problem (err_sym_mat_invalid), 230
(err_repair_invalid_problem), 228 rescode.err_sym_mat_invalid_col_index
rescode.err_repair_optimization_failed (err_sym_mat_invalid_col_index), 230
(err_repair_optimization_failed), 228 rescode.err_sym_mat_invalid_row_index
rescode.err_sen_bound_invalid_lo (err_sym_mat_invalid_row_index),
(err_sen_bound_invalid_lo), 228 230
rescode.err_sen_bound_invalid_up rescode.err_sym_mat_invalid_value
(err_sen_bound_invalid_up), 228 (err_sym_mat_invalid_value), 230
rescode.err_sen_format (err_sen_format), 228 rescode.err_sym_mat_not_lower_tringular
rescode.err_sen_index_invalid (err_sym_mat_not_lower_tringular),
(err_sen_index_invalid), 228 230
rescode.err_sen_index_range rescode.err_task_incompatible
(err_sen_index_range), 228 (err_task_incompatible), 230
rescode.err_sen_invalid_regexp rescode.err_task_invalid (err_task_invalid),
(err_sen_invalid_regexp), 228 230
rescode.err_sen_numerical rescode.err_task_write (err_task_write), 230
(err_sen_numerical), 229 rescode.err_thread_cond_init
rescode.err_sen_solution_status (err_thread_cond_init), 230
(err_sen_solution_status), 229 rescode.err_thread_create
rescode.err_sen_undef_name (err_thread_create), 230
(err_sen_undef_name), 229 rescode.err_thread_mutex_init
rescode.err_sen_unhandled_problem_type (err_thread_mutex_init), 230
(err_sen_unhandled_problem_type), rescode.err_thread_mutex_lock
229 (err_thread_mutex_lock), 230
rescode.err_server_connect rescode.err_thread_mutex_unlock
(err_server_connect), 229 (err_thread_mutex_unlock), 230
rescode.err_server_protocol rescode.err_toconic_constr_not_conic
(err_server_protocol), 229 (err_toconic_constr_not_conic), 230
rescode.err_server_status rescode.err_toconic_constr_q_not_psd
(err_server_status), 229 (err_toconic_constr_q_not_psd), 230
rescode.err_server_token (err_server_token), rescode.err_toconic_constraint_fx
229 (err_toconic_constraint_fx), 230
rescode.err_size_license (err_size_license), rescode.err_toconic_constraint_ra
229 (err_toconic_constraint_ra), 230
www.EngineeringBooksPdf.com
MOSEK Optimizer API for Python, Release 8.0.0.64
Types
booleant, 261
dparam, 261
env_t, 261
int32t, 261
int64t, 261
iparam, 261
www.EngineeringBooksPdf.com