Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
discopt committed Feb 20, 2024
1 parent f178052 commit c236ef0
Show file tree
Hide file tree
Showing 23 changed files with 524 additions and 1,207 deletions.
19 changes: 10 additions & 9 deletions include/cmr/matroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,16 @@ size_t* CMRmatroiddecPivotColumns(

CMR_EXPORT
CMR_ERROR CMRmatroiddecPrint(
CMR* cmr, /**< \ref CMR environment. */
CMR_MATROID_DEC* dec, /**< Decomposition node. */
FILE* stream, /**< Stream to write to. */
size_t indent, /**< Indentation of this node. */
bool printChildren, /**< Whether to recurse. */
bool printMatrices, /**< Whether to print matrices. */
bool printGraphs, /**< Whether to print graphs. */
bool printReductions, /**< Whether to print series-parallel reductions. */
bool printPivots /**< Whether to print pivots. */
CMR* cmr, /**< \ref CMR environment. */
CMR_MATROID_DEC* dec, /**< Decomposition node. */
FILE* stream, /**< Stream to write to. */
size_t indent, /**< Indentation of this node. */
bool printChildren, /**< Whether to recurse. */
bool printParentRowsColumns, /**< Whether to print mapping of rows/columns to parent rows/columns. */
bool printMatrices, /**< Whether to print matrices. */
bool printGraphs, /**< Whether to print graphs. */
bool printReductions, /**< Whether to print series-parallel reductions. */
bool printPivots /**< Whether to print pivots. */
);

/**
Expand Down
3 changes: 3 additions & 0 deletions src/cmr/camion.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@ CMR_ERROR CMRcamionCographicOrient(CMR* cmr, CMR_CHRMAT* matrix, CMR_GRAPH* cogr
{
if (arcsReversed[nodeData[v].edge] != shouldBeReversed)
{
CMRdbgMsg(6, "Found a contradiction in the orientation, i.e., the matrix is not a network matrix.\n");

*pisCamionSigned = false;
if (psubmatrix)
CMR_CALL( constructNonCamionSubmatrix(cmr, cograph, edgeData, rowEdge, nodeData[v].edge, psubmatrix) );

Expand Down
26 changes: 13 additions & 13 deletions src/cmr/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ void CMRassertStackConsistency(
}

#endif /* !NDEBUG */

size_t CMRgetStackUsage(CMR* cmr)
{
size_t result = 0;
for (size_t stack = 0; stack < cmr->currentStack; ++stack)
result += (FIRST_STACK_SIZE << stack);
result += (FIRST_STACK_SIZE << cmr->currentStack) - cmr->stacks[cmr->currentStack].top;

return result;
}

#endif /* else REPLACE_STACK_BY_MALLOC */


void CMRraiseErrorMessage(CMR* cmr, const char* format, ...)
{
Expand Down Expand Up @@ -395,19 +408,6 @@ void CMRclearErrorMessage(CMR* cmr)
cmr->errorMessage = NULL;
}
}

size_t CMRgetStackUsage(CMR* cmr)
{
size_t result = 0;
for (size_t stack = 0; stack < cmr->currentStack; ++stack)
result += (FIRST_STACK_SIZE << stack);
result += (FIRST_STACK_SIZE << cmr->currentStack) - cmr->stacks[cmr->currentStack].top;

return result;
}

#endif /* else REPLACE_STACK_BY_MALLOC */


char* CMRconsistencyMessage(const char* format, ...)
{
Expand Down
4 changes: 4 additions & 0 deletions src/cmr/hereditary_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ CMR_ERROR CMRtestHereditaryPropertySimple(CMR* cmr, CMR_CHRMAT* matrix, Heredita
CMR_CALL( CMRfreeStackArray(cmr, &essentialRows) );
return CMR_ERROR_TIMEOUT;
}

CMRdbgMsg(2, "\n!!! Hereditary property test queries the test oracle!!!\n\n");
CMR_CALL( testFunction(cmr, candidateMatrix, testData, &hasProperty, &submatrix, remainingTime) );

CMRdbgMsg(2, "\n!!! Property %s present.\n\n", hasProperty ? "IS" : "is NOT");

assert(!submatrix); // TODO: we cannot deal with this, yet.

if (hasProperty)
Expand Down
18 changes: 18 additions & 0 deletions src/cmr/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,13 @@ CMR_ERROR CMRchrmatPrintDense(CMR* cmr, CMR_CHRMAT* matrix, FILE* stream, char z
if (header)
{
fputs(" ", stream);
#if defined(CMR_DEBUG)
for (size_t column = 0; column < matrix->numColumns; ++column)
fprintf(stream, "%2zu ", (column+1) % 10);
#else /* !CMR_DEBUG */
for (size_t column = 0; column < matrix->numColumns; ++column)
fprintf(stream, "%zu ", (column+1) % 10);
#endif /* CMR_DEBUG */
fputs("\n ", stream);
for (size_t column = 0; column < matrix->numColumns; ++column)
fputs("--", stream);
Expand All @@ -988,6 +993,18 @@ CMR_ERROR CMRchrmatPrintDense(CMR* cmr, CMR_CHRMAT* matrix, FILE* stream, char z
size_t first = matrix->rowSlice[row];
size_t beyond = matrix->rowSlice[row + 1];
size_t column = 0;
#if defined(CMR_DEBUG)
for (size_t entry = first; entry < beyond; ++entry)
{
size_t entryColumn = matrix->entryColumns[entry];
for (; column < entryColumn; ++column)
fprintf(stream, " %c ", zeroChar);
fprintf(stream, "%2d ", matrix->entryValues[entry]);
++column;
}
for (; column < matrix->numColumns; ++column)
fprintf(stream, " %c ", zeroChar);
#else /* !CMR_DEBUG */
for (size_t entry = first; entry < beyond; ++entry)
{
size_t entryColumn = matrix->entryColumns[entry];
Expand All @@ -998,6 +1015,7 @@ CMR_ERROR CMRchrmatPrintDense(CMR* cmr, CMR_CHRMAT* matrix, FILE* stream, char z
}
for (; column < matrix->numColumns; ++column)
fprintf(stream, "%c ", zeroChar);
#endif /* CMR_DEBUG */
fputc('\n', stream);
}
fflush(stream);
Expand Down
55 changes: 50 additions & 5 deletions src/cmr/matroid.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ size_t * CMRmatroiddecPivotColumns(CMR_MATROID_DEC* dec)
}

CMR_ERROR CMRmatroiddecPrint(CMR* cmr, CMR_MATROID_DEC* dec, FILE* stream, size_t indent, bool printChildren,
bool printMatrices, bool printGraphs, bool printReductions, bool printPivots)
bool printParentRowsColumns, bool printMatrices, bool printGraphs, bool printReductions, bool printPivots)
{
assert(cmr);
assert(stream);
Expand Down Expand Up @@ -708,8 +708,10 @@ CMR_ERROR CMRmatroiddecPrint(CMR* cmr, CMR_MATROID_DEC* dec, FILE* stream, size_
for (size_t i = 0; i < indent; ++i)
fputc(' ', stream);
fprintf(stream, "with series-parallel reductions:\n");
for (size_t i = 0; i < indent; ++i)
fputc(' ', stream);
for (size_t i = 0; i < dec->numSeriesParallelReductions; ++i)
fprintf(stream, " %s", CMRspReductionString(dec->seriesParallelReductions[i], NULL) );
fprintf(stream, "%s%s", (i == 0) ? " " : ", ", CMRspReductionString(dec->seriesParallelReductions[i], NULL) );
fputc('\n', stream);
}

Expand All @@ -723,13 +725,45 @@ CMR_ERROR CMRmatroiddecPrint(CMR* cmr, CMR_MATROID_DEC* dec, FILE* stream, size_
fputc('\n', stream);
}

if (printParentRowsColumns)
{
if (dec->rowsParent)
{
for (size_t i = 0; i < indent; ++i)
fputc(' ', stream);
fprintf(stream, "with mapping of rows to parent's rows:");
for (size_t row = 0; row < dec->numRows; ++row)
{
if (dec->rowsParent[row] == SIZE_MAX)
fprintf(stream, " N/A");
else
fprintf(stream, " r%zu", dec->rowsParent[row]+1);
}
fprintf(stream, "\n");
}
if (dec->columnsParent)
{
for (size_t i = 0; i < indent; ++i)
fputc(' ', stream);
fprintf(stream, "with mapping of columns to parent's columns:");
for (size_t column = 0; column < dec->numColumns; ++column)
{
if (dec->columnsParent[column] == SIZE_MAX)
fprintf(stream, " N/A");
else
fprintf(stream, " c%zu", dec->columnsParent[column]+1);
}
fprintf(stream, "\n");
}
}

if (printMatrices)
{
if (dec->matrix || dec->transpose)
{
for (size_t i = 0; i < indent; ++i)
fputc(' ', stream);
fprintf(stream, "with matrix:\n\n");
fprintf(stream, "with matrix:\n");
}
if (dec->matrix)
CMR_CALL( CMRchrmatPrintDense(cmr, dec->matrix, stream, '0', false) );
Expand Down Expand Up @@ -776,8 +810,8 @@ CMR_ERROR CMRmatroiddecPrint(CMR* cmr, CMR_MATROID_DEC* dec, FILE* stream, size_
fprintf(stream, "Unique child:\n");
else
fprintf(stream, "Child #%zu:\n", c+1);
CMR_CALL( CMRmatroiddecPrint(cmr, dec->children[c], stream, indent + 2, printChildren, printMatrices, printGraphs,
printReductions, printPivots) );
CMR_CALL( CMRmatroiddecPrint(cmr, dec->children[c], stream, indent + 2, printChildren, printParentRowsColumns,
printMatrices, printGraphs, printReductions, printPivots) );
}
}

Expand Down Expand Up @@ -1181,6 +1215,7 @@ CMR_ERROR CMRmatroiddecUpdateTwoSum(CMR* cmr, CMR_MATROID_DEC* dec, CMR_SEPA* se

dec->type = CMR_MATROID_DEC_TYPE_TWO_SUM;
dec->numChildren = 2;
dec->children = NULL;
CMR_CALL( CMRallocBlockArray(cmr, &dec->children, 2) );
for (size_t childIndex = 0; childIndex < 2; ++childIndex)
{
Expand Down Expand Up @@ -1279,6 +1314,16 @@ CMR_ERROR CMRmatroiddecUpdatePivots(CMR* cmr, CMR_MATROID_DEC* dec, size_t numPi
CMR_CALL( CMRduplicateBlockArray(cmr, &dec->pivotRows, numPivots, pivotRows) );
CMR_CALL( CMRduplicateBlockArray(cmr, &dec->pivotColumns, numPivots, pivotColumns) );

for (size_t row = 0; row < dec->numRows; ++row)
dec->children[0]->rowsParent[row] = row;
for (size_t column = 0; column < dec->numColumns; ++column)
dec->children[0]->columnsParent[column] = column;
for (size_t pivot = 0; pivot < numPivots; ++pivot)
{
dec->children[0]->rowsParent[pivotRows[pivot]] = SIZE_MAX;
dec->children[0]->columnsParent[pivotColumns[pivot]] = SIZE_MAX;
}

return CMR_OKAY;
}

Expand Down
6 changes: 3 additions & 3 deletions src/cmr/matroid_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ struct _CMR_MATROID_DEC
size_t numRows; /**< \brief Length of \ref rowsParent. */
size_t* rowsChild; /**< \brief Array for mapping each row to a row of the child (if
** applicable). */
size_t* rowsParent; /**< \brief Array for mapping rows to rows of parent. */
size_t* rowsParent; /**< \brief Array for mapping rows to rows of parent (or \c SIZE_MAX). */
CMR_ELEMENT* rowsRootElement; /**< \brief Array for mapping rows to elements of the root matrix. */

size_t numColumns; /**< \brief Length of \ref columnsParent. */
size_t* columnsChild; /**< \brief Array for mapping each column to a column of the child (if
** applicable). */
size_t* columnsParent; /**< \brief Array for mapping columns to columns of parent. */
** applicable). */
size_t* columnsParent; /**< \brief Array for mapping columns to columns of parent (or \c SIZE_MAX). */
CMR_ELEMENT* columnsRootElement; /**< \brief Array for mapping rows to elements of the root matrix. */

CMR_GRAPH* graph; /**< \brief Graph represented by this matrix. */
Expand Down
14 changes: 7 additions & 7 deletions src/cmr/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ typedef struct

typedef struct
{
DIJKSTRA_STAGE stage; /* Stage in BFS. */
int predecessor; /* Predecessor node. */
CMR_GRAPH_EDGE edge; /* Edge connecting to predecessor node. */
int distance; /* Combinatorial distance to the BFS root. */
char sign; /* Sign of this tree edge with respect to current column. */
bool fixed; /* Whether the orientation of this edge is already fixed. */
DIJKSTRA_STAGE stage; /**< Stage in BFS. */
int predecessor; /**< Predecessor node. */
CMR_GRAPH_EDGE edge; /**< Edge connecting to predecessor node. */
int distance; /**< Combinatorial distance to the BFS root. */
char sign; /**< Sign of this tree edge with respect to current column. */
bool fixed; /**< Whether the orientation of this edge is already fixed. */
} NetworkNodeData;

CMR_ERROR CMRnetworkTestTranspose(CMR* cmr, CMR_CHRMAT* matrix, bool* pisConetwork, CMR_GRAPH** pdigraph,
Expand Down Expand Up @@ -143,7 +143,7 @@ CMR_ERROR CMRnetworkTestTranspose(CMR* cmr, CMR_CHRMAT* matrix, bool* pisConetwo
if (isConetwork)
{
/* We have to find out which edges are reversed. */
CMRdbgMsg(0, "Matrix is graphic. Trying to compute reversed edges.");
CMRdbgMsg(0, "Matrix is graphic. Trying to compute reversed edges.\n");
CMR_CALL( CMRallocBlockArray(cmr, &arcsReversed, CMRgraphMemEdges(graph)) );

#if defined(CMR_DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion src/cmr/regularity.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ CMR_ERROR CMRregularityTaskRun(
}
else if (task->dec->nestedMinorsMatrix && (task->dec->nestedMinorsLastCographic == SIZE_MAX))
{
CMRdbgMsg(4, "Testing for %s along the sequence.\n", task->dec->isTernary ? "being conetwork" : "cographicness");
CMRdbgMsg(4, "Testing along the sequence for %s.\n", task->dec->isTernary ? "being conetwork" : "cographicness");
CMR_CALL( CMRregularityNestedMinorSequenceCographicness(cmr, task, punprocessed) );
}
else
Expand Down
18 changes: 9 additions & 9 deletions src/cmr/regularity_graphic.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

static
int dfsArticulationPoint(
CMR_GRAPH* graph, /**< Graph. */
bool* edgesEnabled, /**< Edge array indicating whether an edge is enabled. */
CMR_GRAPH_NODE node, /**< Current node. */
bool* nodesVisited, /**< Node array indicating whether a node was already visited. */
int* nodesDiscoveryTime, /**< Node array indicating at which time a node was visited. */
int* ptime, /**< Pointer to current time. */
CMR_GRAPH_NODE parentNode, /**< Parent node in DFS arborescence. */
CMR_GRAPH* graph, /**< Graph. */
bool* edgesEnabled, /**< Edge array indicating whether an edge is enabled. */
CMR_GRAPH_NODE node, /**< Current node. */
bool* nodesVisited, /**< Node array indicating whether a node was already visited. */
int* nodesDiscoveryTime, /**< Node array indicating at which time a node was visited. */
int* ptime, /**< Pointer to current time. */
CMR_GRAPH_NODE parentNode, /**< Parent node in DFS arborescence. */
size_t* nodesArticulationPoint /**< Node array indicating whether a node is an articulation point. */
)
{
Expand Down Expand Up @@ -521,7 +521,7 @@ CMR_ERROR addToGraph1Row(
CMRdbgMsg(12, "Candidate node is %ld.\n", splitNode);

#if defined(CMR_DEBUG)
CMRgraphPrint(stdout, graph);
CMRgraphPrint(graph, stdout);
fflush(stdout);
#endif /* CMR_DEBUG */

Expand Down Expand Up @@ -563,7 +563,7 @@ CMR_ERROR addToGraph1Row(

#if defined(CMR_DEBUG)
CMRdbgMsg(14, "Constructed auxiliary graph.\n");
CMRgraphPrint(stdout, auxiliaryGraph);
CMRgraphPrint(auxiliaryGraph, stdout);
fflush(stdout);
#endif /* CMR_DEBUG */

Expand Down
Loading

0 comments on commit c236ef0

Please sign in to comment.