From d4b924cc637855953df16ea8d6bc79f9329f11d6 Mon Sep 17 00:00:00 2001 From: Dominik Kamp Date: Tue, 2 Apr 2024 15:29:18 +0200 Subject: [PATCH] Resolve "Assertion triggered by !3354" --- CHANGELOG | 2 ++ src/scip/cons_logicor.c | 2 +- src/scip/cons_setppc.c | 2 +- src/scip/cons_varbound.c | 2 +- src/scip/matrix.c | 39 +++++++++++++++++++++++++++++++++++---- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 32be2eb8c7..d89e59b983 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,8 @@ Fixed bugs - declare contradicting infinities in getMinActivity() and getMaxActivity() as non-tight - reject farkas solution with large values to bound magnification of errors in SCIPgetFarkasProof() - if all variables are fixed, apply relative feasibility tolerance to avoid invalid infeasibility in applyFixings() of cons_linear.c +- delete empty redundant knapsack and linear constraints after cleanup in SCIPmatrixCreate() +- cleanup first constraints in SCIPcleanupConssVarbound(), SCIPcleanupConssSetppc(), and SCIPcleanupConssLogicor() Miscellaneous ------------- diff --git a/src/scip/cons_logicor.c b/src/scip/cons_logicor.c index ebaed51f43..3cc0e3c1d1 100644 --- a/src/scip/cons_logicor.c +++ b/src/scip/cons_logicor.c @@ -5684,7 +5684,7 @@ SCIP_RETCODE SCIPcleanupConssLogicor( SCIP_CALL( SCIPallocBufferArray(scip, &entries, nentries) ); /* loop backwards since then deleted constraints do not interfere with the loop */ - for( i = nconss - 1; i > 0; --i ) + for( i = nconss - 1; i >= 0; --i ) { SCIP_CONS* cons; SCIP_Bool redundant; diff --git a/src/scip/cons_setppc.c b/src/scip/cons_setppc.c index c170719a5d..96a087bc20 100644 --- a/src/scip/cons_setppc.c +++ b/src/scip/cons_setppc.c @@ -9763,7 +9763,7 @@ SCIP_RETCODE SCIPcleanupConssSetppc( conss = onlychecked ? SCIPconshdlrGetCheckConss(conshdlr) : SCIPconshdlrGetConss(conshdlr); /* loop backwards since then deleted constraints do not interfere with the loop */ - for( i = nconss - 1; i > 0; --i ) + for( i = nconss - 1; i >= 0; --i ) { SCIP_CONS* cons = conss[i]; diff --git a/src/scip/cons_varbound.c b/src/scip/cons_varbound.c index ac462bb692..58576af316 100644 --- a/src/scip/cons_varbound.c +++ b/src/scip/cons_varbound.c @@ -5702,7 +5702,7 @@ SCIP_RETCODE SCIPcleanupConssVarbound( conss = onlychecked ? SCIPconshdlrGetCheckConss(conshdlr) : SCIPconshdlrGetConss(conshdlr); /* loop backwards since then deleted constraints do not interfere with the loop */ - for( i = nconss - 1; i > 0; --i ) + for( i = nconss - 1; i >= 0; --i ) { SCIP_CALL( applyFixings(scip, conss[i], eventhdlr, infeasible, nchgbds, ndelconss, naddconss) ); diff --git a/src/scip/matrix.c b/src/scip/matrix.c index 66d8127290..a9d1080e09 100644 --- a/src/scip/matrix.c +++ b/src/scip/matrix.c @@ -467,11 +467,14 @@ SCIP_RETCODE SCIPmatrixCreate( { SCIP_MATRIX* matrix; SCIP_CONSHDLR** conshdlrs; + SCIP_CONSHDLR* conshdlr; const char* conshdlrname; SCIP_Bool stopped; SCIP_VAR** vars; SCIP_VAR* var; + SCIP_CONS** conshdlrconss; SCIP_CONS* cons; + int nconshdlrconss; int nconshdlrs; int nconss; int nconssall; @@ -509,8 +512,6 @@ SCIP_RETCODE SCIPmatrixCreate( for( i = 0; i < nconshdlrs; ++i ) { - int nconshdlrconss; - nconshdlrconss = SCIPconshdlrGetNCheckConss(conshdlrs[i]); if( nconshdlrconss > 0 ) @@ -586,10 +587,42 @@ SCIP_RETCODE SCIPmatrixCreate( if( *infeasible ) return SCIP_OKAY; + /* delete empty redundant knapsack constraints */ + conshdlr = SCIPfindConshdlr(scip, "knapsack"); + if( conshdlr != NULL ) + { + nconshdlrconss = SCIPconshdlrGetNCheckConss(conshdlr); + conshdlrconss = SCIPconshdlrGetCheckConss(conshdlr); + for( i = nconshdlrconss - 1; i >= 0; --i ) + { + if( SCIPgetNVarsKnapsack(scip, conshdlrconss[i]) == 0 ) + { + SCIP_CALL( SCIPdelCons(scip, conshdlrconss[i]) ); + ++(*ndelconss); + } + } + } + SCIP_CALL( SCIPcleanupConssLinear(scip, TRUE, infeasible) ); if( *infeasible ) return SCIP_OKAY; + /* delete empty redundant linear constraints */ + conshdlr = SCIPfindConshdlr(scip, "linear"); + if( conshdlr != NULL ) + { + nconshdlrconss = SCIPconshdlrGetNCheckConss(conshdlr); + conshdlrconss = SCIPconshdlrGetCheckConss(conshdlr); + for( i = nconshdlrconss - 1; i >= 0; --i ) + { + if( SCIPgetNVarsLinear(scip, conshdlrconss[i]) == 0 ) + { + SCIP_CALL( SCIPdelCons(scip, conshdlrconss[i]) ); + ++(*ndelconss); + } + } + } + vars = SCIPgetVars(scip); nvars = SCIPgetNVars(scip); @@ -661,8 +694,6 @@ SCIP_RETCODE SCIPmatrixCreate( /* loop a second time over constraints handlers and add supported constraints to the matrix */ for( i = 0; i < nconshdlrs; ++i ) { - SCIP_CONS** conshdlrconss; - int nconshdlrconss; SCIP_Bool rowadded; if( SCIPisStopped(scip) || (onlyifcomplete && !(*complete)) )