From 3f0b8ee6cb5c824ba8f40da17c37aeb33248ed79 Mon Sep 17 00:00:00 2001 From: Stefan Vigerske Date: Fri, 26 Jan 2024 11:25:42 +0700 Subject: [PATCH 1/4] reorganize asserts and add return to ensure fixconstant is init if OPT=opt - fixes heur_indicatordiving.c:1095:46: warning: 'fixconstant' may be used uninitialized --- src/scip/heur_indicatordiving.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/scip/heur_indicatordiving.c b/src/scip/heur_indicatordiving.c index 5690b72316..231fdba2e0 100644 --- a/src/scip/heur_indicatordiving.c +++ b/src/scip/heur_indicatordiving.c @@ -1037,11 +1037,13 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) fixconstant = TRUE; } /* Case: Variable is between constant and lb1 */ - else if( SCIPisGT(scip, lpsolsemicontinuous, scdata->vals0[idxbvars]) && SCIPisLT(scip, lpsolsemicontinuous, scdata->lbs1[idxbvars]) ) + else { SCIP_Real shiftedlpsolsemicontinuous = lpsolsemicontinuous; SCIP_Real shiftedlbs1 = scdata->lbs1[idxbvars]; + assert(SCIPisGT(scip, lpsolsemicontinuous, scdata->vals0[idxbvars]) && SCIPisLT(scip, lpsolsemicontinuous, scdata->lbs1[idxbvars])); + /* handle case if constant of semicont. var is not zero -> shift values */ if( !SCIPisZero(scip, scdata->vals0[idxbvars]) ) { @@ -1061,7 +1063,7 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) fixconstant = (*score <= (1 - heurdata->roundingfrac) * 100); break; default: - assert(FALSE); + return SCIP_INVALIDDATA; } switch( heurdata->semicontscoremode ) @@ -1082,16 +1084,11 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) } assert(*score>0); } - else - { - assert(FALSE); - } /* Set roundup depending on whether we have an indicator constraint or a varbound constraint: * - indicator constraint: roundup == fix to constant * - varbound constraint: roundup == push to range */ - /* coverity[uninit_use] */ *roundup = isindicatorvar ? fixconstant : !fixconstant; /*lint !e644*/ /* free memory */ From 75856eaaafd3d21594f7e0a41623b013ea277d42 Mon Sep 17 00:00:00 2001 From: Stefan Vigerske Date: Fri, 26 Jan 2024 11:29:36 +0700 Subject: [PATCH 2/4] remove unnecessary return value of checkAndGetVarbound - it was always SCIP_OKAY, so can also skip it --- src/scip/heur_indicatordiving.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/scip/heur_indicatordiving.c b/src/scip/heur_indicatordiving.c index 231fdba2e0..dc3c2a5dc2 100644 --- a/src/scip/heur_indicatordiving.c +++ b/src/scip/heur_indicatordiving.c @@ -267,7 +267,7 @@ SCIP_RETCODE checkAndGetIndicator( /** checks if variable is binary variable of varbound constraint and stores corresponding varbound constraint */ static -SCIP_RETCODE checkAndGetVarbound( +void checkAndGetVarbound( SCIP* scip, /**< SCIP data structure */ SCIP_VAR* cand, /**< candidate variable */ SCIP_HASHMAP* map, /**< pointer to hashmap containing varbound conss */ @@ -285,13 +285,11 @@ SCIP_RETCODE checkAndGetVarbound( *isvarbound = FALSE; if( SCIPvarGetType(cand) != SCIP_VARTYPE_BINARY ) - return SCIP_OKAY; + return; *cons = (SCIP_CONS*) SCIPhashmapGetImage(map, cand); if( *cons != NULL ) *isvarbound = TRUE; - - return SCIP_OKAY; } /** adds an indicator to the data of a semicontinuous variable */ @@ -909,7 +907,7 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) /* check if candidate variable is bounding variable */ if( heurdata->usevarbounds && !isindicatorvar ) { - SCIP_CALL( checkAndGetVarbound(scip, cand, heurdata->varboundmap, &varboundcons, &isvbdvar) ); + checkAndGetVarbound(scip, cand, heurdata->varboundmap, &varboundcons, &isvbdvar); } /* Return From 6d5298f3b409b839e39bd4d250a8c74a73070ca7 Mon Sep 17 00:00:00 2001 From: Stefan Vigerske Date: Fri, 26 Jan 2024 11:29:36 +0700 Subject: [PATCH 3/4] remove unnecessary return value of checkAndGetIndicator - it was always SCIP_OKAY, so can also skip it --- src/scip/heur_indicatordiving.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/scip/heur_indicatordiving.c b/src/scip/heur_indicatordiving.c index dc3c2a5dc2..461fda6fc3 100644 --- a/src/scip/heur_indicatordiving.c +++ b/src/scip/heur_indicatordiving.c @@ -216,7 +216,7 @@ SCIP_RETCODE releaseSCHashmap( * new probing node, it checks whether there are violated but not fixed indicator constraints */ static -SCIP_RETCODE checkAndGetIndicator( +void checkAndGetIndicator( SCIP* scip, /**< SCIP data structure */ SCIP_VAR* cand, /**< candidate variable */ SCIP_HASHMAP* map, /**< pointer to hashmap containing indicator conss */ @@ -261,8 +261,6 @@ SCIP_RETCODE checkAndGetIndicator( break; } } - - return SCIP_OKAY; } /** checks if variable is binary variable of varbound constraint and stores corresponding varbound constraint */ @@ -890,8 +888,8 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) heurdata->gotoindconss = FALSE; /* check if candidate variable is indicator variable */ - SCIP_CALL( checkAndGetIndicator(scip, cand, heurdata->indicatormap, &indicatorcons, &isindicatorvar, - &heurdata->containsviolindconss, heurdata->newnode, heurdata->sol, heurdata->indicatorconshdlr) ); + checkAndGetIndicator(scip, cand, heurdata->indicatormap, &indicatorcons, &isindicatorvar, + &heurdata->containsviolindconss, heurdata->newnode, heurdata->sol, heurdata->indicatorconshdlr); /* skip candidate in next calls since we have violated indicator constraints but current candidate is not determined * by the indicator constraint handler */ From e927244e43cd0c991ccddd7e609d25079555e9d9 Mon Sep 17 00:00:00 2001 From: Stefan Vigerske Date: Fri, 26 Jan 2024 11:42:22 +0700 Subject: [PATCH 4/4] change other if to assert as well to avoid uninit lincons if OPT=opt --- src/scip/heur_indicatordiving.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/scip/heur_indicatordiving.c b/src/scip/heur_indicatordiving.c index 461fda6fc3..3783e1ca18 100644 --- a/src/scip/heur_indicatordiving.c +++ b/src/scip/heur_indicatordiving.c @@ -938,11 +938,13 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) issemicont = SCIPisInfinity(scip, -SCIPconsGetLhs(scip, lincons, &success)); /* TODO: allow also indicators for lower bounds */ side = rhs; } - else if( isvbdvar ) + else { SCIP_Real rhs; SCIP_Real lhs; + assert(isvbdvar); + lincons = varboundcons; nonoptionvar = SCIPgetVbdvarVarbound(scip, varboundcons); rhs = SCIPconsGetRhs(scip, lincons, &success); @@ -950,10 +952,6 @@ SCIP_DECL_DIVESETGETSCORE(divesetGetScoreIndicatordiving) side = SCIPisInfinity(scip, rhs) ? lhs : rhs; assert(!SCIPisInfinity(scip, side)); } - else - { - assert(FALSE); - } SCIPdebugPrintCons(scip, lincons, NULL); SCIP_CALL( SCIPgetConsNVars(scip, lincons, &nconsvars, &success) );