Regina Calculation Engine
|
A base class for searches that employ the tree traversal algorithm for enumerating and locating vertex normal surfaces and taut angle structures. More...
#include <enumerate/ntreetraversal.h>
Public Member Functions | |
bool | constraintsBroken () const |
Indicates whether or not the extra constraints from the template parameter LPConstraints were added successfully to the infrastructure for the search tree. More... | |
unsigned long | nVisited () const |
Returns the total number of nodes in the search tree that we have visited thus far in the tree traversal. More... | |
void | dumpTypes (std::ostream &out) const |
Writes the current type vector to the given output stream. More... | |
NNormalSurface * | buildSurface () const |
Reconstructs the full normal surface that is represented by the type vector at the current stage of the search. More... | |
NAngleStructure * | buildStructure () const |
Reconstructs the full taut angle structure that is represented by the type vector at the current stage of the search. More... | |
bool | verify (const NNormalSurface *s, const NMatrixInt *matchingEqns=0) const |
Ensures that the given normal or almost normal surface satisfies the matching equations, as well as any additional constraints from the template parameter LPConstraint. More... | |
bool | verify (const NAngleStructure *s, const NMatrixInt *angleEqns=0) const |
Ensures that the given angle structure satisfies the angle equations, as well as any additional constraints from the template parameter LPConstraint. More... | |
Static Public Member Functions | |
static bool | supported (NormalCoords coords) |
Indicates whether the given coordinate system is supported by this tree traversal infrastructure. More... | |
Protected Member Functions | |
NTreeTraversal (const NTriangulation *tri, NormalCoords coords, int branchesPerQuad, int branchesPerTri, bool enumeration) | |
Initialises a new base object for running the tree traversal algorithm. More... | |
~NTreeTraversal () | |
Destroys this object. More... | |
void | setNext (int nextType) |
Rearranges the search tree so that nextType becomes the next type that we process. More... | |
int | nextUnmarkedTriangleType (int startFrom) |
Returns the next unmarked triangle type from a given starting point. More... | |
int | feasibleBranches (int quadType) |
Determines how many different values we could assign to the given quadrilateral or angle type and still obtain a feasible system. More... | |
double | percent () const |
Gives a rough estimate as to what percentage of the way the current type vector is through a full enumeration of the search tree. More... | |
Protected Attributes | |
const LPInitialTableaux< LPConstraint > | origTableaux_ |
The original starting tableaux that holds the adjusted matrix of matching equations, before the tree traversal algorithm begins. More... | |
const NormalCoords | coords_ |
The coordinate system in which we are enumerating or searching for normal surfaces, almost normal surfaces, or taut angle structures. More... | |
const int | nTets_ |
The number of tetrahedra in the underlying triangulation. More... | |
const int | nTypes_ |
The total length of a type vector. More... | |
const int | nTableaux_ |
The maximum number of tableaux that we need to keep in memory at any given time during the backtracking search. More... | |
char * | type_ |
The current working type vector. More... | |
int * | typeOrder_ |
A permutation of 0,...,nTypes_-1 that indicates in which order we select types: the first type we select (at the root of the tree) is type_[typeOrder_[0]], and the last type we select (at the leaves of the tree) is type_[typeOrder_[nTypes_-1]]. More... | |
int | level_ |
The current level in the search tree. More... | |
int | octLevel_ |
The level at which we are enforcing an octagon type (with a strictly positive number of octagons). More... | |
LPData< LPConstraint, Integer > * | lp_ |
Stores tableaux for linear programming at various nodes in the search tree. More... | |
LPData< LPConstraint, Integer > ** | lpSlot_ |
Recall from above that the array lp_ stores tableaux for the current node in the search tree and all of its ancestors. More... | |
LPData< LPConstraint, Integer > ** | nextSlot_ |
Points to the next available tableaux in lp_ that is free to use at each level of the search tree. More... | |
unsigned long | nVisited_ |
Counts the total number of nodes in the search tree that we have visited thus far. More... | |
LPData< LPConstraint, Integer > | tmpLP_ [4] |
Temporary tableaux used by the function feasibleBranches() to determine which quadrilateral types or angle types have good potential for pruning the search tree. More... | |
A base class for searches that employ the tree traversal algorithm for enumerating and locating vertex normal surfaces and taut angle structures.
Users should not use this base class directly; instead use one of the subclasses NTreeEnumeration (for enumerating all vertex normal surfaces), NTautEnumeration (for enumerating all taut angle structures), or NTreeSingleSoln (for locating a single non-trivial solution under additional constraints, such as positive Euler characteristic).
For normal surfaces, the full algorithms are described respectively 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.
This base class provides the infrastructure for the search tree, and the subclasses handle the mechanics of the moving through the tree according to the backtracking search. The domination test is handled separately by the class NTypeTrie, and the feasibility test is handled separately by the class LPData.
This class holds the particular state of the tree traversal at any point in time, as described by the current level (indicating our current depth in the search tree) and type vector (indicating which branches of the search tree we have followed). For details on these concepts, see the Algorithmica paper cited above. The key details are summarised below; throughout this discussion n represents the number of tetrahedra in the underlying triangulation.
In the original Algorithmica paper, we choose types in the order type_[0], type_[1] and so on, working from the root of the tree down to the leaves. Here we support a more flexible system: there is an internal permutation typeOrder_, and we choose types in the order type_[typeOrder_[0]], type_[typeOrder_[1]] and so on. This permutation may mix quadrilateral and triangle processing, and may even change as the algorithm runs.
This class can also support octagon types in almost normal surfaces. However, we still do our linear programming in standard or quadrilateral coordinates, where we represent an octagon using two conflicting quadrilaterals in the same tetrahedron (which meet the tetrahedron boundary in the same set of arcs as a single octagon would). As with the almost normal coordinate systems in NNormalSurfaceList, we allow multiple octagons of the same type, but only one octagon type in the entire tetrahedron. In the type vector, octagons are indicated by setting a quadrilateral type to 4, 5 or 6.
There is optional support for adding extra linear constraints (such as a constraint on Euler characteristic), supplied by the template parameter LPConstraint. If there are no additional constraints, simply use the template parameter LPConstraintNone.
Also, there is optional support for banning coordinates (i.e., insisting that certain coordinates must be set to zero), and/or marking coordinates (for normal and almost normal surfaces this affects what is meant by a "non-trivial" surface for the NTreeSingleSoln algorithm; the concept of marking may be expanded further in future versions of Regina). These options are supplied by the template parameter BanConstraint. If there are no coordinates to ban or mark, simply use the template parameter BanNone.
In some cases, it is impossible to add the extra linear constraints that we would like (for instance, if they require additional preconditions on the underlying triangulation). If this is a possibility in your setting, you should call constraintsBroken() to test for this once the NTreeTraversal object has been constructed.
The template argument Integer indicates the integer type that will be used throughout the underlying linear programming machinery. Unless you have a good reason to do otherwise, you should use the arbitrary-precision NInteger class (in which integers can grow arbitrarily large, and overflow can never occur).
|
protected |
Initialises a new base object for running the tree traversal algorithm.
This routine may only be called by subclass constructors; for more information on how to create and run a tree traversal, see subclasses such as NTreeEnumeration, NTautEnumeration or NTreeSingleSoln instead.
tri | the triangulation in which we wish to search for normal surfaces or taut angle structures. |
coords | the coordinate system in which wish to search for normal surfaces or taut angle structures. This must be one of NS_QUAD, NS_STANDARD, NS_AN_QUAD_OCT, NS_AN_STANDARD, or NS_ANGLE. |
branchesPerQuad | the maximum number of branches we spawn in the search tree for each quadrilateral or angle type (e.g., 4 for a vanilla normal surface tree traversal algorithm, or 3 for enumerating taut angle structures). |
branchesPerTri | the maximum number of branches we spawn in the search tree for each triangle type (e.g., 2 for a vanilla normal surface tree traversal algorithm). If the underlying coordinate system does not support triangles then this argument will be ignored. |
enumeration | true if we should optimise the tableaux for a full enumeration of vertex surfaces or taut angle structures, or false if we should optimise the tableaux for an existence test (such as searching for a non-trivial normal disc or sphere). |
|
protected |
Destroys this object.
NAngleStructure* regina::NTreeTraversal< LPConstraint, BanConstraint, Integer >::buildStructure | ( | ) | const |
Reconstructs the full taut angle structure that is represented by the type vector at the current stage of the search.
This routine is for use only with taut angle structures, not normal or almost normal surfaces.
The angle structure that is returned will be newly constructed, and it is the caller's responsibility to destroy it when it is no longer required.
There will always be a unique taut angle structure corresponding to this type vector (this follows from the preconditions below).
true
, or any time that NTautEnumeration::run() calls its callback function.NNormalSurface* regina::NTreeTraversal< LPConstraint, BanConstraint, Integer >::buildSurface | ( | ) | const |
Reconstructs the full normal surface that is represented by the type vector at the current stage of the search.
This routine is for use only with normal (or almost normal) surfaces, not taut angle structures.
The surface that is returned will be newly constructed, and it is the caller's responsibility to destroy it when it is no longer required.
If the current type vector does not represent a vertex normal surface (which may be the case when calling NTreeSingleSoln::find()), then there may be many normal surfaces all represented by the same type vector; in this case there are no further guarantees about which of these normal surfaces you will get.
true
, or any time that NTreeEnumeration::run() calls its callback function.
|
inline |
Indicates whether or not the extra constraints from the template parameter LPConstraints were added successfully to the infrastructure for the search tree.
This query function is important because some constraints require additional preconditions on the underlying triangulation, and so these constraints cannot be added in some circumstances. If it is possible that the constraints might not be added successfully, this function should be tested as soon as the NTreeTraversal object has been created.
If the extra constraints were not added successfully, the search tree will be left in a consistent state but will give incorrect results (specifically, the extra constraints will be treated as zero functions).
true
if the constraints were not added successfully, or false
if the constraints were added successfully.
|
inline |
Writes the current type vector to the given output stream.
There will be no spaces between the types, and there will be no final newline.
out | the output stream to which to write. |
|
protected |
Determines how many different values we could assign to the given quadrilateral or angle type and still obtain a feasible system.
This will involve solving three or four linear programs, all based on the current state of the tableaux at the current level of the search tree. These assign 0, 1, 2 and 3 to the given quadrilateral or angle type in turn (here 0 is not used for angle types), and then enforce the corresponding constraints. For quadrilateral types, we count types 0 and 1 separately as in NTreeEnumeration, not merged together as in NTreeSingleSoln.
quadType | the quadrilateral or angle type to examine. |
|
inlineprotected |
Returns the next unmarked triangle type from a given starting point.
Specifically, this routine returns the first unmarked triangle type whose type number is greater than or equal to startFrom. For more information on marking, see the BanConstraintBase class notes.
This routine simply searches through types by increasing index into the type vector; in particular, it does not make any use of the reordering defined by the typeOrder_ array.
startFrom | the index into the type vector of the triangle type from which we begin searching. |
|
inline |
Returns the total number of nodes in the search tree that we have visited thus far in the tree traversal.
This figure might grow much faster than the number of solutions, since it also counts traversals through "dead ends" in the search tree.
This counts all nodes that we visit, including those that fail any or all of the domination, feasibility and zero tests. The precise way that this number is calculated is subject to change in future versions of Regina.
If you called an "all at once" routine such as NTreeEnumeration::run() or NTreeSingleSoln::find(), then this will be the total number of nodes that were visited in the entire tree traversal. If you are calling an "incremental" routine such as NTreeEnumeration::next() (i.e., you are generating one solution at time), then this will be the partial count of how many nodes have been visited so far.
|
protected |
Gives a rough estimate as to what percentage of the way the current type vector is through a full enumeration of the search tree.
This is useful for progress tracking.
This routine only attemps to determine the percentage within a reasonable range of error (at the time of writing, 0.01%). This allows it to be more efficient (in particular, by only examining the branches closest to the root of the search tree).
|
protected |
Rearranges the search tree so that nextType becomes the next type that we process.
Specifically, this routine will set typeOrder_[level_ + 1] to nextType_, and will move other elements of typeOrder_ back by one position to make space as required.
nextType | the next type to process. |
|
inlinestatic |
Indicates whether the given coordinate system is supported by this tree traversal infrastructure.
Currently this is true only for NS_STANDARD and NS_QUAD (for normal surfaces), NS_AN_STANDARD and NS_AN_QUAD_OCT (for almost normal surfaces), and NS_ANGLE (for taut angle structures). Any additional restrictions imposed by LPConstraint and BanConstraint will also be taken into account.
coords | the coordinate system being queried. |
true
if and only if this coordinate system is supported. bool regina::NTreeTraversal< LPConstraint, BanConstraint, Integer >::verify | ( | const NNormalSurface * | s, |
const NMatrixInt * | matchingEqns = 0 |
||
) | const |
Ensures that the given normal or almost normal surface satisfies the matching equations, as well as any additional constraints from the template parameter LPConstraint.
This routine is for use only with normal (or almost normal) surfaces, not angle structures.
This routine is provided for diagnostic, debugging and verification purposes.
Instead of using the initial tableaux to verify the matching equations, this routine goes back to the original matching equations matrix as constructed by regina::makeMatchingEquations(). This ensures that the test is independent of any potential problems with the tableaux. You are not required to pass your own matching equations (if you don't, they will be temporarily reconstructed for you); however, you may pass your own if you wish to use a non-standard matching equation matrix, and/or reuse the same matrix to avoid the overhead of reconstructing it every time this routine is called.
s | the normal surface to verify. |
matchingEqns | the matching equations to check against the given surface; this may be 0, in which case the matching equations will be temporarily reconstructed for you using regina::makeMatchingEquations(). |
true
if the given surface passes all of the tests described above, or false
if it fails one or more tests (indicating a problem or error). bool regina::NTreeTraversal< LPConstraint, BanConstraint, Integer >::verify | ( | const NAngleStructure * | s, |
const NMatrixInt * | angleEqns = 0 |
||
) | const |
Ensures that the given angle structure satisfies the angle equations, as well as any additional constraints from the template parameter LPConstraint.
This routine is for use only with angle structures, not normal (or almost normal) surfaces.
This routine is provided for diagnostic, debugging and verification purposes.
Instead of using the initial tableaux to verify the angle equations, this routine goes back to the original angle equations matrix as constructed by NAngleStructureVector::makeAngleEquations(). This ensures that the test is independent of any potential problems with the tableaux. You are not required to pass your own angle equations (if you don't, they will be temporarily reconstructed for you); however, you may pass your own if you wish to use a non-standard angle equation matrix, and/or reuse the same matrix to avoid the overhead of reconstructing it every time this routine is called.
s | the angle structure to verify. |
angleEqns | the angle equations to check against the given angle structure; this may be 0, in which case the angle equations will be temporarily reconstructed for you using NAngleStructureVector::makeMatchingEquations(). |
true
if the given angle structure passes all of the tests described above, or false
if it fails one or more tests (indicating a problem or error).
|
protected |
The coordinate system in which we are enumerating or searching for normal surfaces, almost normal surfaces, or taut angle structures.
This must be one of NS_QUAD or NS_STANDARD if we are only supporting normal surfaces, one of NS_AN_QUAD_OCT or NS_AN_STANDARD if we are allowing octagons in almost normal surfaces, or NS_ANGLE if we are searching for taut angle structures.
|
protected |
The current level in the search tree.
As the search runs, this holds the index into typeOrder_ corresponding to the last type that we chose.
|
protected |
Stores tableaux for linear programming at various nodes in the search tree.
We only store a limited number of tableaux at any given time, and as the search progresses we overwrite old tableaux with new tableaux.
More precisely, we store a linear number of tableaux, essentially corresponding to the current node in the search tree and all of its ancestores, all the way up to the root node. In addition to these tableaux, we also store other immediate children of these ancestores that we have pre-prepared for future processing. See the documentation within routines such as NTreeEnumeration::next() for details of when and how these tableaux are constructed.
|
protected |
Recall from above that the array lp_ stores tableaux for the current node in the search tree and all of its ancestors.
This means we have one tableaux for the root node, as well as additional tableaux at each level 0,1,...,level_.
The array lpSlot_ indicates which element of the array lp_ holds each of these tableaux. Specifically: lpSlot_[0] points to the tableaux for the root node, and for each level i in the range 0,...,level_, the corresponding tableaux is *lpSlot_[i+1]. Again, see the documentation within routines such as NTreeEnumeration::next() for details of when and how these tableaux are constructed and later overwritten.
|
protected |
Points to the next available tableaux in lp_ that is free to use at each level of the search tree.
Specifically: nextSlot_[0] points to the next free tableaux at the root node, and for each level i in the range 0,...,level_, the corresponding next free tableaux is *nextSlot_[i+1].
The precise layout of the nextSlot_ array depends on the order in which we process quadrilateral, triangle and/or angle types.
|
protected |
The maximum number of tableaux that we need to keep in memory at any given time during the backtracking search.
|
protected |
The number of tetrahedra in the underlying triangulation.
|
protected |
The total length of a type vector.
|
protected |
Counts the total number of nodes in the search tree that we have visited thus far.
This may grow much faster than the number of solutions, since it also counts traversals through "dead ends" in the search tree.
|
protected |
The level at which we are enforcing an octagon type (with a strictly positive number of octagons).
If we are working with angle structures or normal surfaces only (and so we do not allow octagons at all), then octLevel_ = nTypes_. If we are allowing almost normal surfaces but we have not yet chosen an octagon type, then octLevel_ = -1.
|
protected |
The original starting tableaux that holds the adjusted matrix of matching equations, before the tree traversal algorithm begins.
|
protected |
Temporary tableaux used by the function feasibleBranches() to determine which quadrilateral types or angle types have good potential for pruning the search tree.
Other routines are welcome to use these temporary tableaux also (as "scratch space"); however, be aware that any call to feasibleBranches() will overwrite them.
|
protected |
The current working type vector.
As the search runs, we modify this type vector in-place. Any types beyond the current level in the search tree will always be set to zero.
|
protected |
A permutation of 0,...,nTypes_-1 that indicates in which order we select types: the first type we select (at the root of the tree) is type_[typeOrder_[0]], and the last type we select (at the leaves of the tree) is type_[typeOrder_[nTypes_-1]].
This permutation is allowed to change as the algorithm runs (though of course you can only change sections of the permutation that correspond to types not yet selected).