CMR  1.3.0
Classes | Functions
tu.c File Reference
#include <cmr/tu.h>
#include "matrix_internal.h"
#include "block_decomposition.h"
#include "camion_internal.h"
#include "regularity_internal.h"
#include "hereditary_property.h"
#include <stdlib.h>
#include <assert.h>
#include <time.h>

Classes

struct  CMR_TU_ENUMERATION
 Data for enumeration. More...
 

Functions

CMR_ERROR CMRtuParamsInit (CMR_TU_PARAMS *params)
 Initializes the default parameters for recognition of totally unimodular matrices. More...
 
CMR_ERROR CMRtuStatsInit (CMR_TU_STATS *stats)
 Initializes all statistics for recognition algorithm for totally unimodular matrices. More...
 
CMR_ERROR CMRtuStatsPrint (FILE *stream, CMR_TU_STATS *stats, const char *prefix)
 Prints statistics for recognition algorithm for totally unimodular matrices. More...
 
static CMR_ERROR tuDecomposition (CMR *cmr, CMR_CHRMAT *matrix, void *data, bool *pisTotallyUnimodular, CMR_SUBMAT **psubmatrix, double timeLimit)
 
static CMR_ERROR tuEulerianColumns (CMR_TU_ENUMERATION *enumeration, size_t numColumns)
 Recursive enumeration of column subsets and subsequent testing of Eulerian submatrix. More...
 
static bool tuEulerianRows (CMR_TU_ENUMERATION *enumeration, size_t numRows)
 Recursive enumeration of row subsets and subsequent testing of total unimodularity. More...
 
static CMR_ERROR tuEulerian (CMR *cmr, CMR_CHRMAT *matrix, bool isTransposed, bool *pisTotallyUnimodular, CMR_SUBMAT **psubmatrix, CMR_TU_STATS *stats, double timeLimit)
 Submatrix test. More...
 
static bool tuPartitionSearch (CMR *cmr, CMR_CHRMAT *matrix, int8_t *selection, size_t current, int *columnSum)
 Recursively assigns +1 or -1 to each row that is part of the subset to test Ghouila-Houri. More...
 
static int tuPartitionSubset (CMR *cmr, CMR_CHRMAT *matrix, bool transposed, int8_t *selection, size_t current, int *columnSum, CMR_TU_STATS *stats, clock_t startClock, double timeLimit)
 Recursively selects a row subset and tests Ghouila-Houri for each. More...
 
static CMR_ERROR tuPartition (CMR *cmr, CMR_CHRMAT *matrix, bool transposed, bool *pisTotallyUnimodular, CMR_TU_STATS *stats, double timeLimit)
 Partition test based on Ghouila-Houri. More...
 
CMR_ERROR CMRtuTest (CMR *cmr, CMR_CHRMAT *matrix, bool *pisTotallyUnimodular, CMR_MATROID_DEC **pdec, CMR_SUBMAT **psubmatrix, CMR_TU_PARAMS *params, CMR_TU_STATS *stats, double timeLimit)
 Tests a matrix \( M \) for being totally unimodular. More...
 
CMR_ERROR CMRtuCompleteDecomposition (CMR *cmr, CMR_MATROID_DEC *dec, CMR_TU_PARAMS *params, CMR_TU_STATS *stats, double timeLimit)
 Completes a subtree of an existing decomposition tree. More...
 

Function Documentation

◆ CMRtuCompleteDecomposition()

CMR_ERROR CMRtuCompleteDecomposition ( CMR cmr,
CMR_MATROID_DEC dec,
CMR_TU_PARAMS params,
CMR_TU_STATS stats,
double  timeLimit 
)

Completes a subtree of an existing decomposition tree.

Replace the node's subtree by a new one even if it exists. Note that different parameters may yield a different subtree.

Note
Requires params.algorithm to be CMR_TU_ALGORITHM_DECOMPOSITION.
Parameters
cmrCMR environment.
decPointer to the decomposition node that is the root of the new subtree.
paramsParameters for the computation.
statsStatistics for the computation (may be NULL).
timeLimitTime limit to impose.

◆ CMRtuParamsInit()

CMR_ERROR CMRtuParamsInit ( CMR_TU_PARAMS params)

Initializes the default parameters for recognition of totally unimodular matrices.

These are selected for minimum running time.

Parameters
paramsPointer to parameters.

◆ CMRtuStatsInit()

CMR_ERROR CMRtuStatsInit ( CMR_TU_STATS stats)

Initializes all statistics for recognition algorithm for totally unimodular matrices.

Parameters
statsPointer to statistics.

◆ CMRtuStatsPrint()

CMR_ERROR CMRtuStatsPrint ( FILE *  stream,
CMR_TU_STATS stats,
const char *  prefix 
)

Prints statistics for recognition algorithm for totally unimodular matrices.

Parameters
streamFile stream to print to.
statsPointer to statistics.
prefixPrefix string to prepend to each printed line (may be NULL).

◆ CMRtuTest()

CMR_ERROR CMRtuTest ( CMR cmr,
CMR_CHRMAT matrix,
bool *  pisTotallyUnimodular,
CMR_MATROID_DEC **  pdec,
CMR_SUBMAT **  psubmatrix,
CMR_TU_PARAMS params,
CMR_TU_STATS stats,
double  timeLimit 
)

Tests a matrix \( M \) for being totally unimodular.

Tests if matrix \( M \) is totally unimodular and sets *pisTotallyUnimodular accordingly.

If \( M \) is totally unimodular and pdec != NULL, then *pdec will contain a decomposition tree of the regular matroid. The caller must release it via CMRdecFree().

If \( M \) is not totally unimodular and psubmatrix != NULL, then *psubmatrix will indicate a submatrix of \( M \) with determinant \( -2 \) or \( 2 \).

Parameters
cmrCMR environment
matrixMatrix \( M \).
pisTotallyUnimodularPointer for storing whether \( M \) is totally unimodular.
pdecPointer for storing the decomposition tree (may be NULL).
psubmatrixPointer for storing a submatrix with non-ternary determinant (may be NULL).
paramsParameters for the computation (may be NULL for defaults).
statsStatistics for the computation (may be NULL).
timeLimitTime limit to impose.

◆ tuDecomposition()

static CMR_ERROR tuDecomposition ( CMR cmr,
CMR_CHRMAT matrix,
void *  data,
bool *  pisTotallyUnimodular,
CMR_SUBMAT **  psubmatrix,
double  timeLimit 
)
static
Parameters
cmrCMR environment.
matrixSome matrix to be tested for total unimodularity.
dataAdditional data (must be NULL).
pisTotallyUnimodularPointer for storing whether matrix is totally unimodular.
psubmatrixPointer for storing a proper non-totally unimodular submatrix of matrix.
timeLimitTime limit to impose.

◆ tuEulerian()

static CMR_ERROR tuEulerian ( CMR cmr,
CMR_CHRMAT matrix,
bool  isTransposed,
bool *  pisTotallyUnimodular,
CMR_SUBMAT **  psubmatrix,
CMR_TU_STATS stats,
double  timeLimit 
)
static

Submatrix test.

Parameters
cmrCMR environment
matrixMatrix \( M \).
isTransposedWhether we're dealing with the transpose.
pisTotallyUnimodularPointer for storing whether \( M \) is totally unimodular.
psubmatrixPointer for storing the submatrix.
statsStatistics.
timeLimitTime limit to impose.

◆ tuEulerianColumns()

static CMR_ERROR tuEulerianColumns ( CMR_TU_ENUMERATION enumeration,
size_t  numColumns 
)
static

Recursive enumeration of column subsets and subsequent testing of Eulerian submatrix.

Parameters
enumerationEnumeration information.
numColumnsNumber of already selected columns.

◆ tuEulerianRows()

static bool tuEulerianRows ( CMR_TU_ENUMERATION enumeration,
size_t  numRows 
)
static

Recursive enumeration of row subsets and subsequent testing of total unimodularity.

Returns
true if we can stop (due to time limit or a found violating submatrix).
Parameters
enumerationEnumeration information.
numRowsNumber of already selected rows.

◆ tuPartition()

static CMR_ERROR tuPartition ( CMR cmr,
CMR_CHRMAT matrix,
bool  transposed,
bool *  pisTotallyUnimodular,
CMR_TU_STATS stats,
double  timeLimit 
)
static

Partition test based on Ghouila-Houri.

Parameters
cmrCMR environment
matrixMatrix \( M \).
transposedWhether we're dealing with the transposed .
pisTotallyUnimodularPointer for storing whether \( M \) is totally unimodular.
statsStatistics.
timeLimitTime limit to impose.

◆ tuPartitionSearch()

static bool tuPartitionSearch ( CMR cmr,
CMR_CHRMAT matrix,
int8_t *  selection,
size_t  current,
int *  columnSum 
)
static

Recursively assigns +1 or -1 to each row that is part of the subset to test Ghouila-Houri.

Returns
whether a feasible assignment was found.
Parameters
cmrCMR environment
matrixMatrix \( M \).
selectionArray with selection.
currentIndex to decide for selection.
columnSumArray for computing column sums.

◆ tuPartitionSubset()

static int tuPartitionSubset ( CMR cmr,
CMR_CHRMAT matrix,
bool  transposed,
int8_t *  selection,
size_t  current,
int *  columnSum,
CMR_TU_STATS stats,
clock_t  startClock,
double  timeLimit 
)
static

Recursively selects a row subset and tests Ghouila-Houri for each.

Returns
1 if totally unimodular, 0 if not, and -1 if time limit was reached.
Parameters
cmrCMR environment
matrixMatrix \( M \).
transposedWhether we're dealing with the transpose.
selectionArray with selection.
currentIndex to decide for selection.
columnSumArray for computing column sums.
statsStatistics.
startClockClock for start for computation.
timeLimitTime limit for computation.