From ce5e0747a0268f4c3e2fed6142fd03bc5824750f Mon Sep 17 00:00:00 2001 From: Christopher Hojny Date: Wed, 7 Feb 2024 15:52:12 +0100 Subject: [PATCH 1/3] make sure entries are well-defined --- src/scip/symmetry.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/scip/symmetry.c b/src/scip/symmetry.c index c3d8158979..8331cb700b 100644 --- a/src/scip/symmetry.c +++ b/src/scip/symmetry.c @@ -1795,6 +1795,7 @@ SCIP_RETCODE detectOrbitopalSymmetries( static SCIP_RETCODE isDoublelLexSym( SCIP* scip, /**< SCIP pointer */ + int nsymvars, /**< number of variables on which symmetries act */ int*** matrices1, /**< first list of matrices associated with orbitopal symmetries */ int nrows1, /**< number of rows of first family of matrices */ int* ncols1, /**< for each matrix in the first family, its number of columns */ @@ -1831,6 +1832,7 @@ SCIP_RETCODE isDoublelLexSym( int j; assert( scip != NULL ); + assert( nsymvars >= 0 ); assert( matrices1 != NULL ); assert( nrows1 > 0 ); assert( ncols1 != NULL ); @@ -1877,6 +1879,19 @@ SCIP_RETCODE isDoublelLexSym( SCIP_CALL( SCIPallocBufferArray(scip, &idxtocol1, nidx) ); SCIP_CALL( SCIPallocBufferArray(scip, &idxtocol2, nidx) ); + for (i = 0; i < nsymvars; ++i) + idxtomatrix1[i] = -1; + for (i = 0; i < nsymvars; ++i) + idxtomatrix2[i] = -1; + for (i = 0; i < nsymvars; ++i) + idxtorow1[i] = -1; + for (i = 0; i < nsymvars; ++i) + idxtorow2[i] = -1; + for (i = 0; i < nsymvars; ++i) + idxtocol1[i] = -1; + for (i = 0; i < nsymvars; ++i) + idxtocol2[i] = -1; + for (c = 0; c < nmatrices1; ++c) { for (i = 0; i < nrows1; ++i) @@ -1902,6 +1917,16 @@ SCIP_RETCODE isDoublelLexSym( } } + /* check whether the variables of the two orbitopes coincide */ + for (i = 0; i < nsymvars; ++i) + { + if ( (idxtomatrix1[i] == -1) != (idxtomatrix2[i] == -1) ) + { + *success = FALSE; + goto FREEINITMEMORY; + } + } + /* Find a big matrix such that the columns of this matrix correspond to the columns of matrices in matrices1 * and the rows of this matrix correspond to the columns of matrices in matrices2. In total, this leads to * a matrix of block shape @@ -1991,13 +2016,6 @@ SCIP_RETCODE isDoublelLexSym( FREEMEMORY: SCIPfreeBufferArray(scip, &sortvals); - SCIPfreeBufferArray(scip, &idxtocol2); - SCIPfreeBufferArray(scip, &idxtocol1); - SCIPfreeBufferArray(scip, &idxtorow2); - SCIPfreeBufferArray(scip, &idxtorow1); - SCIPfreeBufferArray(scip, &idxtomatrix2); - SCIPfreeBufferArray(scip, &idxtomatrix1); - if ( !(*success) ) { for (i = *nrows - 1; i >= 0; --i) @@ -2012,6 +2030,14 @@ SCIP_RETCODE isDoublelLexSym( *colsbegin = NULL; } + FREEINITMEMORY: + SCIPfreeBufferArray(scip, &idxtocol2); + SCIPfreeBufferArray(scip, &idxtocol1); + SCIPfreeBufferArray(scip, &idxtorow2); + SCIPfreeBufferArray(scip, &idxtorow1); + SCIPfreeBufferArray(scip, &idxtomatrix2); + SCIPfreeBufferArray(scip, &idxtomatrix1); + return SCIP_OKAY; } @@ -2124,7 +2150,7 @@ SCIP_RETCODE SCIPdetectSingleOrDoubleLexMatrices( { assert( ncycs1 > 0 ); - SCIP_CALL( isDoublelLexSym(scip, matricestype1, ncycs1, ncolstype1, nmatricestype1, + SCIP_CALL( isDoublelLexSym(scip, permlen, matricestype1, ncycs1, ncolstype1, nmatricestype1, matricestype2, ncycs2, ncolstype2, nmatricestype2, lexmatrix, nrows, ncols, lexrowsbegin, lexcolsbegin, success) ); From 402615c9c7870ff916c9cdeefc2ba5bff29ec08b Mon Sep 17 00:00:00 2001 From: Christopher Hojny Date: Thu, 8 Feb 2024 10:37:34 +0100 Subject: [PATCH 2/3] updated CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 376935a1be..9a2bf109c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -272,6 +272,7 @@ Fixed bugs - fixed make install when SHARED=no and make uninstall - check absolute coefficients relative to extremal average to avoid invalid unifications in normalizeCons() - enforce and check symmetry-based constraints to take their locks (in dual reductions) into account +- fixed bug in detection of double lex matrices due to wrong memory allocation Miscellaneous ------------- From 325053ad63e57c208329b669299490e43cceef98 Mon Sep 17 00:00:00 2001 From: Christopher Hojny Date: Thu, 8 Feb 2024 12:09:45 +0100 Subject: [PATCH 3/3] added comment --- src/scip/symmetry.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scip/symmetry.c b/src/scip/symmetry.c index 8331cb700b..30d76296a6 100644 --- a/src/scip/symmetry.c +++ b/src/scip/symmetry.c @@ -1879,6 +1879,7 @@ SCIP_RETCODE isDoublelLexSym( SCIP_CALL( SCIPallocBufferArray(scip, &idxtocol1, nidx) ); SCIP_CALL( SCIPallocBufferArray(scip, &idxtocol2, nidx) ); + /* use separate loops for efficiency reasons */ for (i = 0; i < nsymvars; ++i) idxtomatrix1[i] = -1; for (i = 0; i < nsymvars; ++i)