From e863dfca8c37c8e9b69060829eb8286882026410 Mon Sep 17 00:00:00 2001 From: Marc Pfetsch Date: Sat, 30 Nov 2024 18:50:02 +0100 Subject: [PATCH 1/2] update requiredsize handling --- src/scip/var.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scip/var.c b/src/scip/var.c index 72258c65ca..546e56d628 100644 --- a/src/scip/var.c +++ b/src/scip/var.c @@ -4190,8 +4190,7 @@ SCIP_RETCODE SCIPvarGetActiveRepresentatives( * actual size, but this would need another loop through the active variables. We therefore take the upper bound. */ /* return results */ - *requiredsize = nactivevars; - if( varssize >= *requiredsize ) + if( varssize >= nactivevars ) { assert(vars != NULL); @@ -4232,6 +4231,8 @@ SCIP_RETCODE SCIPvarGetActiveRepresentatives( /* clean buffer again */ tmpscalars[var->index] = 0.0; } + /* set requiredsize to space actually needed */ + *requiredsize = *nvars; } else { @@ -4242,6 +4243,7 @@ SCIP_RETCODE SCIPvarGetActiveRepresentatives( assert( 0 <= var->index && var->index < ntotalvars ); tmpscalars[var->index] = 0.0; } + *requiredsize = nactivevars; } assert(SCIPsetIsInfinity(set, *constant) == ((*constant) == SCIPsetInfinity(set))); /*lint !e777*/ From 20c369ed259210cc98deb7fe3bcd9acaaad44359 Mon Sep 17 00:00:00 2001 From: Marc Pfetsch Date: Sat, 30 Nov 2024 19:32:51 +0100 Subject: [PATCH 2/2] revise assert wrt SCIPgetProbvarLinearSum() --- src/scip/cons_linear.c | 6 +++--- src/scip/cons_logicor.c | 4 ++-- src/scip/cons_pseudoboolean.c | 6 +++--- src/scip/cons_setppc.c | 6 +++--- src/scip/cons_sos1.c | 1 + src/scip/expr_var.c | 3 ++- src/scip/matrix.c | 2 +- src/scip/prop_genvbounds.c | 2 ++ src/scip/reader_ccg.c | 2 +- src/scip/reader_fzn.c | 2 +- src/scip/reader_gms.c | 1 + src/scip/reader_lp.c | 2 +- src/scip/reader_mps.c | 2 +- src/scip/reader_opb.c | 2 +- src/scip/reader_pbm.c | 2 +- src/scip/reader_pip.c | 2 +- src/scip/reader_ppm.c | 2 +- src/scip/symmetry_graph.c | 1 + 18 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/scip/cons_linear.c b/src/scip/cons_linear.c index c6807c0abb..fb1a630b6d 100644 --- a/src/scip/cons_linear.c +++ b/src/scip/cons_linear.c @@ -17947,8 +17947,8 @@ SCIP_RETCODE SCIPcreateConsLinear( SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize) ); - assert(requiredsize <= nconsvars); } + assert(requiredsize == nconsvars); /* adjust sides and check that we do not subtract infinity values */ if( SCIPisInfinity(scip, REALABS(constant)) ) @@ -18165,8 +18165,8 @@ SCIP_RETCODE SCIPcopyConsLinear( SCIP_CALL( SCIPreallocBufferArray(scip, &coefs, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(sourcescip, vars, coefs, &nvars, requiredsize, &constant, &requiredsize) ); - assert(requiredsize <= nvars); } + assert(requiredsize == nvars); } else { @@ -18263,8 +18263,8 @@ SCIP_RETCODE SCIPaddCoefLinear( SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize) ); - assert(requiredsize <= nconsvars); } + assert(requiredsize == nconsvars); consdata = SCIPconsGetData(cons); assert(consdata != NULL); diff --git a/src/scip/cons_logicor.c b/src/scip/cons_logicor.c index c3dac02a4c..dd1dc23da9 100644 --- a/src/scip/cons_logicor.c +++ b/src/scip/cons_logicor.c @@ -1014,9 +1014,9 @@ SCIP_RETCODE applyFixings( size = requiredsize; SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, size, &constant, &requiredsize) ); - assert(nconsvars <= size); assert(requiredsize <= size); } + assert(requiredsize == nconsvars); easycase = FALSE; @@ -1092,9 +1092,9 @@ SCIP_RETCODE applyFixings( size = requiredsize; SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, size, &constant, &requiredsize) ); - assert(nconsvars <= size); assert(requiredsize <= size); } + assert(requiredsize == nconsvars); lhs = 1.0 - constant; rhs = SCIPinfinity(scip); diff --git a/src/scip/cons_pseudoboolean.c b/src/scip/cons_pseudoboolean.c index 7d33f8ba34..d97ccda0e6 100644 --- a/src/scip/cons_pseudoboolean.c +++ b/src/scip/cons_pseudoboolean.c @@ -5102,9 +5102,8 @@ SCIP_RETCODE correctConshdlrdata( activescalars[0] = 1.0; activeconstant = 0.0; nactivevars = 1; - SCIP_CALL( SCIPgetProbvarLinearSum(scip, activevars, activescalars, &nactivevars, nvars, - &activeconstant, &requiredsize) ); - assert(requiredsize <= nvars); + SCIP_CALL( SCIPgetProbvarLinearSum(scip, activevars, activescalars, &nactivevars, nvars, &activeconstant, &requiredsize) ); + assert(requiredsize == nactivevars); for( i = 0; i < nactivevars && del; ++i ) { @@ -5619,6 +5618,7 @@ SCIP_RETCODE tryUpgradingXor( /* get linear active representation */ SCIP_CALL( SCIPgetProbvarLinearSum(scip, linvars, lincoefs, &nlinvars, MAXNVARS, &constant, &requiredsize) ); + assert(requiredsize == nlinvars); SCIP_CALL( SCIPduplicateBufferArray(scip, &activelinvars, linvars, nlinvars) ); if( requiredsize > MAXNVARS ) diff --git a/src/scip/cons_setppc.c b/src/scip/cons_setppc.c index 6b23ec1a67..ec21cef1d1 100644 --- a/src/scip/cons_setppc.c +++ b/src/scip/cons_setppc.c @@ -1852,7 +1852,7 @@ SCIP_RETCODE applyFixings( SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, consvarssize, &constant, &requiredsize) ); assert(requiredsize <= consvarssize); } - assert(nconsvars <= consvarssize); + assert(requiredsize == nconsvars); easycase = FALSE; @@ -1988,9 +1988,9 @@ SCIP_RETCODE applyFixings( SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, size) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, size, &constant, &requiredsize) ); - assert(requiredsize == size); + assert(requiredsize <= size); } - assert(nconsvars <= size); + assert(requiredsize == nconsvars); /* compute sides */ if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING ) diff --git a/src/scip/cons_sos1.c b/src/scip/cons_sos1.c index 2af5e476e1..aa432f7895 100644 --- a/src/scip/cons_sos1.c +++ b/src/scip/cons_sos1.c @@ -2813,6 +2813,7 @@ SCIP_RETCODE tightenVarsBoundsSOS1( SCIP_CALL( SCIPgetProbvarLinearSum(scip, trafolinvars, trafolinvals, &ntrafolinvars, requiredsize, &constant, &requiredsize) ); } + assert(requiredsize == ntrafolinvars); if( !SCIPisInfinity(scip, -trafolhs) ) trafolhs -= constant; if( !SCIPisInfinity(scip, traforhs) ) diff --git a/src/scip/expr_var.c b/src/scip/expr_var.c index 388121daea..cd1ab38f29 100644 --- a/src/scip/expr_var.c +++ b/src/scip/expr_var.c @@ -112,8 +112,9 @@ SCIP_DECL_EXPRSIMPLIFY(simplifyVar) SCIP_CALL( SCIPreallocBufferArray(scip, &coefs, requsize) ); varssize = requsize; SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, coefs, &nvars, varssize, &constant, &requsize) ); - assert(requsize <= nvars); + assert(requsize <= varssize); } + assert(requsize == nvars); } /* create expression for constant + sum coefs_i vars_i */ diff --git a/src/scip/matrix.c b/src/scip/matrix.c index 6b4e4cacf0..8b97da4c52 100644 --- a/src/scip/matrix.c +++ b/src/scip/matrix.c @@ -91,8 +91,8 @@ SCIP_RETCODE getActiveVariables( /* call function a second time with enough memory */ SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize) ); - assert(requiredsize <= *nvars); } + assert(requiredsize == *nvars); return SCIP_OKAY; } diff --git a/src/scip/prop_genvbounds.c b/src/scip/prop_genvbounds.c index 2e581fe865..5b36b75883 100644 --- a/src/scip/prop_genvbounds.c +++ b/src/scip/prop_genvbounds.c @@ -2494,7 +2494,9 @@ SCIP_DECL_PROPEXITPRE(propExitpreGenvbounds) } SCIP_CALL( SCIPgetProbvarLinearSum(scip, genvbound->vars, genvbound->coefs, &genvbound->ncoefs, requiredsize, &genvbound->constant, &requiredsize) ); + assert(requiredsize <= genvbound->coefssize); } + assert(requiredsize == genvbound->ncoefs); /* capture new and release old variables */ for( j = 0; j < genvbound->ncoefs; ++j ) diff --git a/src/scip/reader_ccg.c b/src/scip/reader_ccg.c index aa7c5813bd..2a68ef192a 100644 --- a/src/scip/reader_ccg.c +++ b/src/scip/reader_ccg.c @@ -192,8 +192,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize) ); - assert( requiredsize <= *nvars ); } + assert( requiredsize == *nvars ); } else { diff --git a/src/scip/reader_fzn.c b/src/scip/reader_fzn.c index ffd83fbb80..176d07309d 100644 --- a/src/scip/reader_fzn.c +++ b/src/scip/reader_fzn.c @@ -3891,8 +3891,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize) ); - assert( requiredsize <= *nvars ); } + assert( requiredsize == *nvars ); } else { diff --git a/src/scip/reader_gms.c b/src/scip/reader_gms.c index 72f358505e..2214be4cb2 100644 --- a/src/scip/reader_gms.c +++ b/src/scip/reader_gms.c @@ -118,6 +118,7 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, *varssize, constant, &requiredsize) ); assert(requiredsize <= *varssize); } + assert(requiredsize == *nvars); } else { diff --git a/src/scip/reader_lp.c b/src/scip/reader_lp.c index ec3885abbc..79c1a8daa5 100644 --- a/src/scip/reader_lp.c +++ b/src/scip/reader_lp.c @@ -2545,8 +2545,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize) ); - assert( requiredsize <= *nvars ); } + assert( requiredsize == *nvars ); } else { diff --git a/src/scip/reader_mps.c b/src/scip/reader_mps.c index 08d50af467..eedb4732c3 100644 --- a/src/scip/reader_mps.c +++ b/src/scip/reader_mps.c @@ -2969,8 +2969,8 @@ SCIP_RETCODE getLinearCoeffs( SCIP_CALL( SCIPreallocBufferArray(scip, &activevals, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, activevars, activevals, &nactivevars, requiredsize, &activeconstant, &requiredsize) ); - assert( requiredsize <= nactivevars ); } + assert( requiredsize == nactivevars ); } else { diff --git a/src/scip/reader_opb.c b/src/scip/reader_opb.c index cef946c61b..0c6208d00a 100644 --- a/src/scip/reader_opb.c +++ b/src/scip/reader_opb.c @@ -1795,8 +1795,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize) ); - assert( requiredsize <= *nvars ); } + assert( requiredsize == *nvars ); } else for( v = 0; v < *nvars; ++v ) diff --git a/src/scip/reader_pbm.c b/src/scip/reader_pbm.c index 2aa0d3b8cb..98f457b8a1 100644 --- a/src/scip/reader_pbm.c +++ b/src/scip/reader_pbm.c @@ -104,8 +104,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize) ); - assert(requiredsize <= *nvars); } + assert(requiredsize == *nvars); } else { diff --git a/src/scip/reader_pip.c b/src/scip/reader_pip.c index eea02e5c93..1c785013b9 100644 --- a/src/scip/reader_pip.c +++ b/src/scip/reader_pip.c @@ -1766,8 +1766,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize) ); - assert( requiredsize <= *nvars ); } + assert( requiredsize == *nvars ); } else { diff --git a/src/scip/reader_ppm.c b/src/scip/reader_ppm.c index f0890a5008..30122b47d8 100644 --- a/src/scip/reader_ppm.c +++ b/src/scip/reader_ppm.c @@ -123,8 +123,8 @@ SCIP_RETCODE getActiveVariables( SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) ); SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize) ); - assert( requiredsize <= *nvars ); } + assert( requiredsize == *nvars ); } else { diff --git a/src/scip/symmetry_graph.c b/src/scip/symmetry_graph.c index 4d9a3870bd..5503650cf7 100644 --- a/src/scip/symmetry_graph.c +++ b/src/scip/symmetry_graph.c @@ -1865,6 +1865,7 @@ SCIP_RETCODE SCIPgetSymActiveVariables( SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize) ); } + assert( requiredsize == *nvars ); } else {