15.3 Class Env¶
- mosek.Env¶
The MOSEK global environment.
- Env.Env¶
Env()
Env(String dbgfile)
Constructor of a new environment.
- Parameters:
dbgfile
(String
) – File where the memory debugging log is written. (input)- Groups:
- Env.axpy¶
public synchronized void axpy (int n, double alpha, double[] x, double[] y)
Adds \(\alpha x\) to \(y\), i.e. performs the update
\[y := \alpha x + y.\]Note that the result is stored overwriting \(y\). It must not overlap with the other input arrays.
- Parameters:
n
(int
) – Length of the vectors. (input)alpha
(double
) – The scalar that multiplies \(x\). (input)x
(double
[]
) – The \(x\) vector. (input)y
(double
[]
) – The \(y\) vector. (input/output)
- Groups:
- Env.checkinall¶
public synchronized void checkinall()
Check in all unused license features to the license token server.
- Groups:
- Env.checkinlicense¶
public synchronized void checkinlicense(feature feature)
Check in a license feature to the license server. By default all licenses consumed by functions using a single environment are kept checked out for the lifetime of the MOSEK environment. This function checks in a given license feature back to the license server immediately.
If the given license feature is not checked out at all, or it is in use by a call to
Task.optimize
, calling this function has no effect.Please note that returning a license to the license server incurs a small overhead, so frequent calls to this function should be avoided.
- Parameters:
feature
(feature
) – Feature to check in to the license system. (input)- Groups:
- Env.checkoutlicense¶
public synchronized void checkoutlicense(feature feature)
Checks out a license feature from the license server. Normally the required license features will be automatically checked out the first time they are needed by the function
Task.optimize
. This function can be used to check out one or more features ahead of time.The feature will remain checked out until the environment is deleted or the function
Env.checkinlicense
is called.If a given feature is already checked out when this function is called, the call has no effect.
- Parameters:
feature
(feature
) – Feature to check out from the license system. (input)- Groups:
- Env.computesparsecholesky¶
public synchronized void computesparsecholesky (int numthreads, int ordermethod, double tolsingular, int[] anzc, long[] aptrc, int[] asubc, double[] avalc, int[][] perm, double[][] diag, int[][] lnzc, long[][] lptrc, long[] lensubnval, int[][] lsubc, double[][] lvalc)
The function computes a Cholesky factorization of a sparse positive semidefinite matrix. Sparsity is exploited during the computations to reduce the amount of space and work required. Both the input and output matrices are represented using the sparse format.
To be precise, given a symmetric matrix \(A \in \real^{n\times n}\) the function computes a nonsingular lower triangular matrix \(L\), a diagonal matrix \(D\) and a permutation matrix \(P\) such that
\[LL^T - D = P A P^T.\]If
ordermethod
is zero then reordering heuristics are not employed and \(P\) is the identity.If a pivot during the computation of the Cholesky factorization is less than
\[-\rho\cdot\max((PAP^T)_{jj},1.0)\]then the matrix is declared negative semidefinite. On the hand if a pivot is smaller than
\[\rho\cdot\max((PAP^T)_{jj},1.0),\]then \(D_{jj}\) is increased from zero to
\[\rho\cdot\max((PAP^T)_{jj},1.0).\]Therefore, if \(A\) is sufficiently positive definite then \(D\) will be the zero matrix. Here \(\rho\) is set equal to value of
tolsingular
.- Parameters:
numthreads
(int
) – The number threads that can be used to do the computation. 0 means the code makes the choice. NOTE: API change in version 10: in versions up to 9 the argument in this position indicated whether to use multithreading or not. (input)ordermethod
(int
) – If nonzero, then a sparsity preserving ordering will be employed. (input)tolsingular
(double
) – A positive parameter controlling when a pivot is declared zero. (input)anzc
(int
[]
) –anzc[j]
is the number of nonzeros in the \(j\)-th column of \(A\). (input)aptrc
(long
[]
) –aptrc[j]
is a pointer to the first element in column \(j\) of \(A\). (input)asubc
(int
[]
) – Row indexes for each column stored in increasing order. (input)avalc
(double
[]
) – The value corresponding to row indexed stored inasubc
. (input)perm
(int
[]
by reference) – Permutation array used to specify the permutation matrix \(P\) computed by the function. (output)diag
(double
[]
by reference) – The diagonal elements of matrix \(D\). (output)lnzc
(int
[]
by reference) –lnzc[j]
is the number of non zero elements in column \(j\) of \(L\). (output)lptrc
(long
[]
by reference) –lptrc[j]
is a pointer to the first row index and value in column \(j\) of \(L\). (output)lensubnval
(long
by reference) – Number of elements inlsubc
andlvalc
. (output)lsubc
(int
[]
by reference) – Row indexes for each column stored in increasing order. (output)lvalc
(double
[]
by reference) – The values corresponding to row indexed stored inlsubc
. (output)
- Groups:
- Env.dispose¶
void dispose()
Free the underlying native allocation.
- Groups:
- Env.dot¶
public synchronized void dot (int n, double[] x, double[] y, double[] xty)
Computes the inner product of two vectors \(x,y\) of length \(n\geq 0\), i.e
\[x\cdot y= \sum_{i=1}^n x_i y_i.\]Note that if \(n=0\), then the result of the operation is 0.
- Parameters:
n
(int
) – Length of the vectors. (input)x
(double
[]
) – The \(x\) vector. (input)y
(double
[]
) – The \(y\) vector. (input)xty
(double
by reference) – The result of the inner product between \(x\) and \(y\). (output)
- Groups:
- Env.echointro¶
public synchronized void echointro(int longver)
Prints an intro to message stream.
- Parameters:
longver
(int
) – If non-zero, then the intro is slightly longer. (input)- Groups:
- Env.expirylicenses¶
public synchronized void expirylicenses(long[] expiry)
Reports when the first license feature expires. It reports the number of days to the expiry of the first feature of all the features that were ever checked out from the start of the process, or from the last call to
Env.resetexpirylicenses
, until now.- Parameters:
expiry
(long
by reference) – If nonnegative, then it is the minimum number days to expiry of any feature that has been checked out. (output)- Groups:
- Env.gemm¶
public synchronized void gemm (transpose transa, transpose transb, int m, int n, int k, double alpha, double[] a, double[] b, double beta, double[] c)
Performs a matrix multiplication plus addition of dense matrices. Given \(A\), \(B\) and \(C\) of compatible dimensions, this function computes
\[C:= \alpha op(A)op(B) + \beta C\]where \(\alpha,\beta\) are two scalar values. The function \(op(X)\) denotes \(X\) if transX is
transpose.no
, or \(X^T\) if set totranspose.yes
. The matrix \(C\) has \(m\) rows and \(n\) columns, and the other matrices must have compatible dimensions.The result of this operation is stored in \(C\). It must not overlap with the other input arrays.
- Parameters:
transa
(transpose
) – Indicates whether the matrix \(A\) must be transposed. (input)transb
(transpose
) – Indicates whether the matrix \(B\) must be transposed. (input)m
(int
) – Indicates the number of rows of matrix \(C\). (input)n
(int
) – Indicates the number of columns of matrix \(C\). (input)k
(int
) – Specifies the common dimension along which \(op(A)\) and \(op(B)\) are multiplied. For example, if neither \(A\) nor \(B\) are transposed, then this is the number of columns in \(A\) and also the number of rows in \(B\). (input)alpha
(double
) – A scalar value multiplying the result of the matrix multiplication. (input)a
(double
[]
) – The pointer to the array storing matrix \(A\) in a column-major format. (input)b
(double
[]
) – The pointer to the array storing matrix \(B\) in a column-major format. (input)beta
(double
) – A scalar value that multiplies \(C\). (input)c
(double
[]
) – The pointer to the array storing matrix \(C\) in a column-major format. (input/output)
- Groups:
- Env.gemv¶
public synchronized void gemv (transpose transa, int m, int n, double alpha, double[] a, double[] x, double beta, double[] y)
Computes the multiplication of a scaled dense matrix times a dense vector, plus a scaled dense vector. Precisely, if
trans
istranspose.no
then the update is\[y := \alpha A x + \beta y,\]and if
trans
istranspose.yes
then\[y := \alpha A^T x + \beta y,\]where \(\alpha,\beta\) are scalar values and \(A\) is a matrix with \(m\) rows and \(n\) columns.
Note that the result is stored overwriting \(y\). It must not overlap with the other input arrays.
- Parameters:
transa
(transpose
) – Indicates whether the matrix \(A\) must be transposed. (input)m
(int
) – Specifies the number of rows of the matrix \(A\). (input)n
(int
) – Specifies the number of columns of the matrix \(A\). (input)alpha
(double
) – A scalar value multiplying the matrix \(A\). (input)a
(double
[]
) – A pointer to the array storing matrix \(A\) in a column-major format. (input)x
(double
[]
) – A pointer to the array storing the vector \(x\). (input)beta
(double
) – A scalar value multiplying the vector \(y\). (input)y
(double
[]
) – A pointer to the array storing the vector \(y\). (input/output)
- Groups:
- Env.getcodedesc¶
public static void getcodedesc (rescode code, StringBuffer symname, StringBuffer str)
Obtains a short description of the meaning of the response code given by
code
.- Parameters:
code
(rescode
) – A valid MOSEK response code. (input)symname
(StringBuffer
) – Symbolic name corresponding tocode
. (output)str
(StringBuffer
) – Obtains a short description of a response code. (output)
- Groups:
- Env.getversion¶
public static void getversion (int[] major, int[] minor, int[] revision)
Obtains MOSEK version information.
- Parameters:
major
(int
by reference) – Major version number. (output)minor
(int
by reference) – Minor version number. (output)revision
(int
by reference) – Revision number. (output)
- Groups:
- Env.licensecleanup¶
public static void licensecleanup()
Stops all threads and deletes all handles used by the license system. If this function is called, it must be called as the last MOSEK API call. No other MOSEK API calls are valid after this.
- Groups:
- Env.linkfiletostream¶
public synchronized void linkfiletostream (streamtype whichstream, String filename, int append)
Sends all output from the stream defined by
whichstream
to the file given byfilename
.- Parameters:
whichstream
(streamtype
) – Index of the stream. (input)filename
(String
) – A valid file name. (input)append
(int
) – If this argument is 0 the file will be overwritten, otherwise it will be appended to. (input)
- Groups:
- Env.optimizebatch¶
public synchronized void optimizebatch (boolean israce, double maxtime, int numthreads, Task[] task, rescode[] trmcode, rescode[] rcode)
Optimize a number of tasks in parallel using a specified number of threads. All callbacks and log output streams are disabled.
Assuming that each task takes about same time and there many more tasks than number of threads then a linear speedup can be achieved, also known as strong scaling. A typical application of this method is to solve many small tasks of similar type; in this case it is recommended that each of them is allocated a single thread by setting
iparam.num_threads
to \(1\).If the parameters
israce
ormaxtime
are used, then the result may not be deterministic, in the sense that the tasks which complete first may vary between runs.The remaining behavior, including termination and response codes returned for each task, are the same as if each task was optimized separately.
- Parameters:
israce
(boolean
) – If nonzero, then the function is terminated after the first task has been completed. (input)maxtime
(double
) – Time limit for the function: if nonnegative, then the function is terminated after maxtime (seconds) has expired. (input)numthreads
(int
) – Number of threads to be employed. (input)task
(Task
[]
) – An array of tasks to optimize in parallel. (input)trmcode
(rescode
[]
) – The termination code for each task. (output)rcode
(rescode
[]
) – The response code for each task. (output)
- Groups:
- Env.potrf¶
public synchronized void potrf (uplo uplo, int n, double[] a)
Computes a Cholesky factorization of a real symmetric positive definite dense matrix.
- Parameters:
uplo
(uplo
) – Indicates whether the upper or lower triangular part of the matrix is stored. (input)n
(int
) – Dimension of the symmetric matrix. (input)a
(double
[]
) – A symmetric matrix stored in column-major order. Only the lower or the upper triangular part is used, accordingly with theuplo
parameter. It will contain the result on exit. (input/output)
- Groups:
- Env.putlicensecode¶
public synchronized void putlicensecode(int[] code)
Input a runtime license code. This function has an effect only before the first optimization.
- Parameters:
code
(int
[]
) – A runtime license code. (input)- Groups:
- Env.putlicensedebug¶
public synchronized void putlicensedebug(int licdebug)
Enables debug information for the license system. If
licdebug
is non-zero, then MOSEK will print debug info regarding the license checkout.- Parameters:
licdebug
(int
) – Whether license checkout debug info should be printed. (input)- Groups:
- Env.putlicensepath¶
public synchronized void putlicensepath(String licensepath)
Set the path to the license file. This function has an effect only before the first optimization.
- Parameters:
licensepath
(String
) – A path specifying where to search for the license. (input)- Groups:
- Env.putlicensewait¶
public synchronized void putlicensewait(int licwait)
Control whether MOSEK should wait for an available license if no license is available. If
licwait
is non-zero, then MOSEK will wait forlicwait-1
milliseconds between each check for an available license.- Parameters:
licwait
(int
) – Whether MOSEK should wait for a license if no license is available. (input)- Groups:
- Env.resetexpirylicenses¶
public synchronized void resetexpirylicenses()
Reset the license expiry reporting startpoint.
- Groups:
- Env.set_Stream¶
void set_Stream (mosek.streamtype whichstream, mosek.Stream callback)
Directs all output from an environment stream to a callback object.
Can for example be called as:
env.set_Stream(mosek.streamtype.log, new Stream() { public void stream(String s) { System.out.print(s); } } );
- Parameters:
whichstream
(streamtype
) – Index of the stream. (input)callback
(Stream
) – The callback object. (input)
- Groups:
- Env.sparsetriangularsolvedense¶
public synchronized void sparsetriangularsolvedense (transpose transposed, int[] lnzc, long[] lptrc, int[] lsubc, double[] lvalc, double[] b)
The function solves a triangular system of the form
\[L x = b\]or
\[L^T x = b\]where \(L\) is a sparse lower triangular nonsingular matrix. This implies in particular that diagonals in \(L\) are nonzero.
- Parameters:
transposed
(transpose
) – Controls whether to use with \(L\) or \(L^T\). (input)lnzc
(int
[]
) –lnzc[j]
is the number of nonzeros in columnj
. (input)lptrc
(long
[]
) –lptrc[j]
is a pointer to the first row index and value in columnj
. (input)lsubc
(int
[]
) – Row indexes for each column stored sequentially. Must be stored in increasing order for each column. (input)lvalc
(double
[]
) – The value corresponding to the row index stored inlsubc
. (input)b
(double
[]
) – The right-hand side of linear equation system to be solved as a dense vector. (input/output)
- Groups:
- Env.syeig¶
public synchronized void syeig (uplo uplo, int n, double[] a, double[] w)
Computes all eigenvalues of a real symmetric matrix \(A\). Given a matrix \(A\in\real^{n\times n}\) it returns a vector \(w\in\real^n\) containing the eigenvalues of \(A\).
- Parameters:
uplo
(uplo
) – Indicates whether the upper or lower triangular part is used. (input)n
(int
) – Dimension of the symmetric input matrix. (input)a
(double
[]
) – A symmetric matrix \(A\) stored in column-major order. Only the part indicated byuplo
is used. (input)w
(double
[]
) – Array of length at leastn
containing the eigenvalues of \(A\). (output)
- Groups:
- Env.syevd¶
public synchronized void syevd (uplo uplo, int n, double[] a, double[] w)
Computes all the eigenvalues and eigenvectors a real symmetric matrix. Given the input matrix \(A\in \real^{n\times n}\), this function returns a vector \(w\in \real^n\) containing the eigenvalues of \(A\) and it also computes the eigenvectors of \(A\). Therefore, this function computes the eigenvalue decomposition of \(A\) as
\[A= U V U^T,\]where \(V=\diag(w)\) and \(U\) contains the eigenvectors of \(A\).
Note that the matrix \(U\) overwrites the input data \(A\).
- Parameters:
uplo
(uplo
) – Indicates whether the upper or lower triangular part is used. (input)n
(int
) – Dimension of the symmetric input matrix. (input)a
(double
[]
) – A symmetric matrix \(A\) stored in column-major order. Only the part indicated byuplo
is used. On exit it will be overwritten by the matrix \(U\). (input/output)w
(double
[]
) – Array of length at leastn
containing the eigenvalues of \(A\). (output)
- Groups:
- Env.syrk¶
public synchronized void syrk (uplo uplo, transpose trans, int n, int k, double alpha, double[] a, double beta, double[] c)
Performs a symmetric rank-\(k\) update for a symmetric matrix.
Given a symmetric matrix \(C\in \real^{n\times n}\), two scalars \(\alpha,\beta\) and a matrix \(A\) of rank \(k\leq n\), it computes either
\[C := \alpha A A^T + \beta C,\]when
trans
is set totranspose.no
and \(A\in \real^{n\times k}\), or\[C := \alpha A^T A + \beta C,\]when
trans
is set totranspose.yes
and \(A\in \real^{k\times n}\).Only the part of \(C\) indicated by
uplo
is used and only that part is updated with the result. It must not overlap with the other input arrays.- Parameters:
uplo
(uplo
) – Indicates whether the upper or lower triangular part of \(C\) is used. (input)trans
(transpose
) – Indicates whether the matrix \(A\) must be transposed. (input)n
(int
) – Specifies the order of \(C\). (input)k
(int
) – Indicates the number of rows or columns of \(A\), depending on whether or not it is transposed, and its rank. (input)alpha
(double
) – A scalar value multiplying the result of the matrix multiplication. (input)a
(double
[]
) – The pointer to the array storing matrix \(A\) in a column-major format. (input)beta
(double
) – A scalar value that multiplies \(C\). (input)c
(double
[]
) – The pointer to the array storing matrix \(C\) in a column-major format. (input/output)
- Groups: