Regina 7.3 Calculation Engine
|
A matrix class for use with linear programming. More...
#include <enumerate/treelp.h>
Public Member Functions | |
LPMatrix () | |
Creates an uninitialised matrix with no memory storage. More... | |
LPMatrix (size_t rows, size_t cols) | |
Creates a fully initialised rows by cols matrix with all elements set to zero. More... | |
LPMatrix (LPMatrix &&src) noexcept | |
Moves the contents of the given matrix into this new matrix. More... | |
~LPMatrix () | |
Destroys this matrix and all of the data it contains. More... | |
LPMatrix & | operator= (LPMatrix &&src) noexcept |
Moves the contents of the given matrix into this matrix. More... | |
void | swap (LPMatrix &other) noexcept |
Swaps the contents of this and the given matrix. More... | |
void | reserve (size_t maxRows, size_t maxCols) |
Reserves enough space to store the elements of a maxRows by maxCols matrix. More... | |
void | initClone (const LPMatrix &clone) |
Initialises this matrix to a copy of the given matrix. More... | |
void | initIdentity (size_t size) |
Initialises this matrix to the identity matrix of the given size. More... | |
IntType & | entry (size_t row, size_t col) |
Returns a read-write reference to the given element of this matrix. More... | |
const IntType & | entry (size_t row, size_t col) const |
Returns a read-only reference to the given element of this matrix. More... | |
void | set (size_t row, size_t col, const IntType &value) |
Python-only routine that sets the given element of this matrix. More... | |
size_t | rows () const |
Returns the number of rows in this matrix. More... | |
size_t | columns () const |
Returns the number of columns in this matrix. More... | |
bool | operator== (const LPMatrix &other) const |
Determines whether this and the given matrix are equal. More... | |
bool | operator!= (const LPMatrix &other) const |
Determines whether this and the given matrix are not equal. More... | |
void | swapRows (size_t r1, size_t r2) |
Swaps the two given rows of this matrix. More... | |
void | combRow (const IntType &destCoeff, size_t dest, const IntType &srcCoeff, size_t src, const IntType &div) |
Applies a particular row operation to this matrix. More... | |
IntType | combRowAndNorm (const IntType &destCoeff, size_t dest, const IntType &srcCoeff, size_t src) |
Applies a particular row operation to this matrix, and then normalises. More... | |
void | negateRow (size_t row) |
Negates all elements in the given row of this matrix. More... | |
void | writeTextShort (std::ostream &out) const |
Writes a short text representation of this object to the given output stream. More... | |
void | writeTextLong (std::ostream &out) const |
Writes a detailed text representation of this object to the given output stream. More... | |
LPMatrix (const LPMatrix &)=delete | |
LPMatrix & | operator= (const LPMatrix &)=delete |
std::string | str () const |
Returns a short text representation of this object. More... | |
std::string | utf8 () const |
Returns a short text representation of this object using unicode characters. More... | |
std::string | detail () const |
Returns a detailed text representation of this object. More... | |
A matrix class for use with linear programming.
This class is used in the tree traversal algorithms for enumerating and locating vertex normal surfaces, as described in "A tree traversal algorithm for decision problems in knot theory and 3-manifold topology", Burton and Ozlen, Algorithmica 65:4 (2013), pp. 772-801, and "A fast branching algorithm for unknot recognition with experimental polynomial-time behaviour", Burton and Ozlen, arXiv:1211.1079. It is also used for locating a single strict angle structure, and for enumerating all taut angle structures.
The operations on this matrix class are tailored and optimised specifically for use with the dual simplex method in the context of a repetitive backtracking search. As a result, the API is cumbersome and highly specialised, which makes this matrix class inappropriate for general use. If you just want a general-use integer matrix class, use MatrixInt instead.
It is critical that, before using an LPMatrix, you reserve space for its elements, and then fix a specific size. A matrix for which both tasks have been done will be called initialised. You can initialise a matrix in one of two ways:
You may call the initialisation initClone() and initIdentity() routines more than once (e.g., during a backtracking search), and you may use different matrix sizes each time. However, you may never use more elements than you originally reserved space for.
This matrix is stored in dense form. All elements are of the integer class IntType, which is supplied as a template argument.
This class implements C++ move semantics and adheres to the C++ Swappable requirement. However, due to the unusual create-reserve-initialise procedure, it does not support copying (either by copy construction or copy assignment). Because of the move semantics, this class avoids deep copies, even when passing or returning objects by value.
|
inline |
Creates an uninitialised matrix with no memory storage.
You must call reserve() and then either initClone() or initIdentity() before this matrix will become initialised.
|
inline |
Creates a fully initialised rows by cols matrix with all elements set to zero.
This routine reserves space for precisely rows * cols elements. In other words, you may later re-initialise the matrix to become smaller if you like, but you cannot re-initialise the matrix to become larger.
rows | the number of rows in the new matrix. This must be strictly positive. |
cols | the number of columns in the new matrix. This must be strictly positive. |
|
inlinenoexcept |
Moves the contents of the given matrix into this new matrix.
This is a fast (constant time) operation.
If the given matrix is uninitialised, then this new matrix will be uninitialised also.
The matrix that is passed (src) will no longer be usable.
src | the matrix to move. |
|
inline |
Destroys this matrix and all of the data it contains.
You can safely destroy a matrix that is uninitialised or only partially initialised (i.e., space has been reserved but the matrix size is not set).
|
inline |
Returns the number of columns in this matrix.
This relates to the currently assigned matrix size, not the total amount of memory that was originally reserved.
void regina::LPMatrix< IntType >::combRow | ( | const IntType & | destCoeff, |
size_t | dest, | ||
const IntType & | srcCoeff, | ||
size_t | src, | ||
const IntType & | div | ||
) |
Applies a particular row operation to this matrix.
Specifically, row dest will be replaced with the linear combination: (destCoeff * row dest - srcCoeff * row src) / div.
destCoeff | the coefficient applied to row dest in the linear combination. |
dest | the index of the row to replace. This must be between 0 and rows()-1 inclusive. |
srcCoeff | the coefficient applied to row src in the linear combination. |
src | the index of the other row used in this linear combination. This must be between 0 and rows()-1 inclusive. |
div | the integer to divide the final row by. This must be non-zero. |
IntType regina::LPMatrix< IntType >::combRowAndNorm | ( | const IntType & | destCoeff, |
size_t | dest, | ||
const IntType & | srcCoeff, | ||
size_t | src | ||
) |
Applies a particular row operation to this matrix, and then normalises.
Specifically, row dest will be replaced with the linear combination: (destCoeff * row dest - srcCoeff * row src); then, if row dest is non-zero, it will be normalised by dividing through by the gcd of its elements. Note that this gcd is always taken to be positive (i.e., the final normalisation will never change the signs of the elements in the row).
destCoeff | the coefficient applied to row dest in the linear combination. |
dest | the index of the row to replace. This must be between 0 and rows()-1 inclusive. |
srcCoeff | the coefficient applied to row src in the linear combination. |
src | the index of the other row used in this linear combination. This must be between 0 and rows()-1 inclusive. |
|
inherited |
Returns a detailed text representation of this object.
This text may span many lines, and should provide the user with all the information they could want. It should be human-readable, should not contain extremely long lines (which cause problems for users reading the output in a terminal), and should end with a final newline. There are no restrictions on the underlying character set.
|
inline |
Returns a read-write reference to the given element of this matrix.
matrix.entry(r, c).negate()
will work, but matrix.entry(r, c) = value
will not; instead you will need to call matrix.set(r, c, value)
.
|
inline |
|
inline |
Initialises this matrix to a copy of the given matrix.
This matrix does not yet need to be initialised, but it does need to have enough space reserved.
You may call this routine on an already-initialised matrix, and you may use this routine to assign it a different size (as long as enough space was originally reserved).
clone | the matrix to copy. |
|
inline |
Initialises this matrix to the identity matrix of the given size.
This matrix does not yet need to be initialised, but it does need to have enough space reserved.
You may call this routine on an already-initialised matrix, and you may use this routine to assign it a different size (as long as enough space was originally reserved).
size | the number of rows, and also the number of columns, that will be assigned to this matrix. This must be strictly positive. |
|
inline |
Negates all elements in the given row of this matrix.
row | the row whose elements should be negated. This must be between 0 and rows()-1 inclusive. |
|
inline |
Determines whether this and the given matrix are not equal.
Two matrices are equal if and only if their dimensions are the same, and the corresponding elements of each matrix are equal.
It is safe to compare matrices of different dimensions, and it is safe to compare matrices that might not yet be initialised. Two uninitialised matrices will compare as equal.
other | the matrix to compare with this. |
true
if and only if the two matrices are not equal.
|
inlinenoexcept |
Moves the contents of the given matrix into this matrix.
This is a fast (constant time) operation.
If the given matrix is uninitialised, then this matrix will become uninitialised also.
The matrix that is passed (src) will no longer be usable.
src | the matrix to move. |
|
inline |
Determines whether this and the given matrix are equal.
Two matrices are equal if and only if their dimensions are the same, and the corresponding elements of each matrix are equal.
It is safe to compare matrices of different dimensions, and it is safe to compare matrices that might not yet be initialised. Two uninitialised matrices will compare as equal.
other | the matrix to compare with this. |
true
if and only if the two matrices are equal.
|
inline |
Reserves enough space to store the elements of a maxRows by maxCols matrix.
This is just an upper bound: your matrix may end up using fewer elements than this, but it cannot use more.
This matrix will still not be initialised until you call either initClone() or initIdentity(). See the class notes for details.
maxRows | an upper bound on the number of rows that you will need for this matrix. This must be strictly positive. |
maxCols | an upper bound on the number of columns that you will need for this matrix. This must be strictly positive. |
|
inline |
Returns the number of rows in this matrix.
This relates to the currently assigned matrix size, not the total amount of memory that was originally reserved.
void regina::LPMatrix< IntType >::set | ( | size_t | row, |
size_t | col, | ||
const IntType & | value | ||
) |
Python-only routine that sets the given element of this matrix.
entry(row, column) = value
.matrix.set(row, column, value)
. The entry() routine does give read-write access to matrix elements in Python, but it does not allow them to be set using the assignment operator. In other words, code such as matrix.entry(r, c).negate()
will work, but matrix.entry(r, c) = value
will not.
|
inherited |
Returns a short text representation of this object.
This text should be human-readable, should use plain ASCII characters where possible, and should not contain any newlines.
Within these limits, this short text ouptut should be as information-rich as possible, since in most cases this forms the basis for the Python __str__()
and __repr__()
functions.
__str__()
will use precisely this function, and for most classes the Python __repr__()
function will incorporate this into its output.
|
inlinenoexcept |
Swaps the contents of this and the given matrix.
It does not matter if the two matrices have different sizes, or if one or both is unintialised; if so then these properties will be swapped also.
other | the matrix whose contents should be swapped with this. |
|
inline |
Swaps the two given rows of this matrix.
The two arguments r1 and r2 may be equal (in which case the matrix will be left unchanged).
|
inherited |
Returns a short text representation of this object using unicode characters.
Like str(), this text should be human-readable, should not contain any newlines, and (within these constraints) should be as information-rich as is reasonable.
Unlike str(), this function may use unicode characters to make the output more pleasant to read. The string that is returned will be encoded in UTF-8.
void regina::LPMatrix< IntType >::writeTextLong | ( | std::ostream & | out | ) | const |
Writes a detailed text representation of this object to the given output stream.
out | the output stream to which to write. |
void regina::LPMatrix< IntType >::writeTextShort | ( | std::ostream & | out | ) | const |
Writes a short text representation of this object to the given output stream.
out | the output stream to which to write. |