From 3fd83dab942efb4900ea69fc9a124644e4fe8143 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Thu, 14 Dec 2023 18:12:55 +0100 Subject: [PATCH 1/7] remove wrong assert --- src/scip/heur_scheduler.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index ee2e241e8b..1241c59dc7 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -2807,7 +2807,6 @@ SCIP_DECL_HEUREXEC(heurExecScheduler) assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0); assert(scip != NULL); assert(result != NULL); - assert(SCIPhasCurrentNodeLP(scip)); /* get heuristic data */ heurdata = SCIPheurGetData(heur); From fa7710e8c1a5a24a0468824daebda6fff5efa655 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Thu, 14 Dec 2023 18:21:47 +0100 Subject: [PATCH 2/7] resort heuristics if number of active heuristics changes --- src/scip/heur_scheduler.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index 1241c59dc7..9de5810bae 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -2372,6 +2372,7 @@ SCIP_RETCODE selectHeuristic( SCIP_CALL( SCIPbanditSelect(bandit, selection) ); } assert(*selection >= 0); + assert(*selection < heurdata->nactiveneighborhoods + heurdata->ndiving); return SCIP_OKAY; } @@ -2773,7 +2774,7 @@ SCIP_RETCODE initRest( * at the root node*/ if( heurdata->defaultroot ) { - SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->sortedindices, nheurs) ); + SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->sortedindices, heurdata->ndiving + heurdata->nneighborhoods) ); SCIP_CALL( SCIPallocBufferArray(scip, &priorities, nheurs) ); heurdata->counter = 0; @@ -4098,9 +4099,31 @@ SCIP_DECL_HEURINITSOL(heurInitsolScheduler) /* active neighborhoods might change between init calls, reset functionality must take this into account */ if( heurdata->bandit != NULL && SCIPbanditGetNActions(heurdata->bandit) != heurdata->ndiving + heurdata->nactiveneighborhoods ) { - SCIP_CALL( SCIPfreeBandit(scip, &heurdata->bandit) ); + SCIP_Real* initpriorities; + int nheurs; + SCIP_CALL( SCIPfreeBandit(scip, &heurdata->bandit) ); heurdata->bandit = NULL; + + /* since the number of active heursitics has changed, we have to update + * how heuristics are sorted by priority */ + nheurs = heurdata->nactiveneighborhoods + heurdata->ndiving; + SCIP_CALL( SCIPallocBufferArray(scip, &initpriorities, nheurs) ); + heurdata->counter = 0; + + for( i = 0; i < nheurs; ++i ) + { + heurdata->sortedindices[i] = i; + + if( i < heurdata->ndiving ) + initpriorities[i] = (SCIP_Real)-heurdata->divingheurs[i]->rootnodepriority; + else + initpriorities[i] = (SCIP_Real)-heurdata->neighborhoods[i - heurdata->ndiving]->rootnodepriority; + } + + SCIPsortRealInt(initpriorities, heurdata->sortedindices, nheurs); + + SCIPfreeBufferArray(scip, &initpriorities); } if( heurdata->nactiveneighborhoods + heurdata->ndiving > 0 ) @@ -4192,7 +4215,7 @@ SCIP_DECL_HEURFREE(heurFreeScheduler) SCIPfreeBlockMemoryArray(scip, &heurdata->divingheurs, heurdata->divingheurssize); if( heurdata->defaultroot ) - SCIPfreeBlockMemoryArray(scip, &heurdata->sortedindices, heurdata->ndiving + heurdata->nactiveneighborhoods); + SCIPfreeBlockMemoryArray(scip, &heurdata->sortedindices, heurdata->ndiving + heurdata->nneighborhoods); } /* free neighborhoods */ From b9c69bd927ce7f42c1b7365dabe9735aef8665f9 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Fri, 15 Dec 2023 12:58:47 +0100 Subject: [PATCH 3/7] resort indices only if struct is initialized --- src/scip/heur_scheduler.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index 9de5810bae..ce03fa4175 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -4099,31 +4099,34 @@ SCIP_DECL_HEURINITSOL(heurInitsolScheduler) /* active neighborhoods might change between init calls, reset functionality must take this into account */ if( heurdata->bandit != NULL && SCIPbanditGetNActions(heurdata->bandit) != heurdata->ndiving + heurdata->nactiveneighborhoods ) { - SCIP_Real* initpriorities; - int nheurs; - SCIP_CALL( SCIPfreeBandit(scip, &heurdata->bandit) ); heurdata->bandit = NULL; /* since the number of active heursitics has changed, we have to update - * how heuristics are sorted by priority */ - nheurs = heurdata->nactiveneighborhoods + heurdata->ndiving; - SCIP_CALL( SCIPallocBufferArray(scip, &initpriorities, nheurs) ); - heurdata->counter = 0; - - for( i = 0; i < nheurs; ++i ) + * how heuristics are sorted by priority, if we already initialized the data */ + if( heurdata->divingheurs != NULL ) { - heurdata->sortedindices[i] = i; + SCIP_Real* initpriorities; + int nheurs; - if( i < heurdata->ndiving ) - initpriorities[i] = (SCIP_Real)-heurdata->divingheurs[i]->rootnodepriority; - else - initpriorities[i] = (SCIP_Real)-heurdata->neighborhoods[i - heurdata->ndiving]->rootnodepriority; - } + nheurs = heurdata->nactiveneighborhoods + heurdata->ndiving; + SCIP_CALL( SCIPallocBufferArray(scip, &initpriorities, nheurs) ); + heurdata->counter = 0; + + for( i = 0; i < nheurs; ++i ) + { + heurdata->sortedindices[i] = i; - SCIPsortRealInt(initpriorities, heurdata->sortedindices, nheurs); + if( i < heurdata->ndiving ) + initpriorities[i] = (SCIP_Real)-heurdata->divingheurs[i]->rootnodepriority; + else + initpriorities[i] = (SCIP_Real)-heurdata->neighborhoods[i - heurdata->ndiving]->rootnodepriority; + } + + SCIPsortRealInt(initpriorities, heurdata->sortedindices, nheurs); - SCIPfreeBufferArray(scip, &initpriorities); + SCIPfreeBufferArray(scip, &initpriorities); + } } if( heurdata->nactiveneighborhoods + heurdata->ndiving > 0 ) From 4f684a884214012474855a5adb99374c3aba2b16 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Fri, 15 Dec 2023 15:20:25 +0100 Subject: [PATCH 4/7] fix memory leak --- src/scip/heur_scheduler.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index ce03fa4175..ccac87a028 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -4211,6 +4211,9 @@ SCIP_DECL_HEURFREE(heurFreeScheduler) for( j = 0; j < heurdata->ndiving; ++j ) { + SCIP_CALL( SCIPfreeClock(scip, &(heurdata->divingheurs[j]->stats->setupclock)) ); + SCIP_CALL( SCIPfreeClock(scip, &(heurdata->divingheurs[j]->stats->execclock)) ); + SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->solvefreqdata); SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->stats); } From d1149a19310018713bf2cdc7bc5c73a4a012afc3 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Fri, 15 Dec 2023 16:11:24 +0100 Subject: [PATCH 5/7] free diving heur struct --- src/scip/heur_scheduler.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index ccac87a028..9deb0f48fd 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -4216,6 +4216,7 @@ SCIP_DECL_HEURFREE(heurFreeScheduler) SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->solvefreqdata); SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->stats); + SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]); } SCIPfreeBlockMemoryArray(scip, &heurdata->divingheurs, heurdata->divingheurssize); From 514b2baa09de95c17c075dea7d1c5de12dc8f579 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Fri, 15 Dec 2023 16:38:16 +0100 Subject: [PATCH 6/7] try to fix lint error --- src/scip/heur_scheduler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index 9deb0f48fd..20d05432c2 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -4216,7 +4216,7 @@ SCIP_DECL_HEURFREE(heurFreeScheduler) SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->solvefreqdata); SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->stats); - SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]); + SCIPfreeBlockMemory(scip, &(heurdata->divingheurs[j])); } SCIPfreeBlockMemoryArray(scip, &heurdata->divingheurs, heurdata->divingheurssize); From 957b378d4d094b2bee0b198e202f348b2822bd70 Mon Sep 17 00:00:00 2001 From: Chmiela Date: Mon, 18 Dec 2023 12:05:38 +0100 Subject: [PATCH 7/7] refactor freeing of diving heuristics --- src/scip/heur_scheduler.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/scip/heur_scheduler.c b/src/scip/heur_scheduler.c index 20d05432c2..4462a1c9e1 100644 --- a/src/scip/heur_scheduler.c +++ b/src/scip/heur_scheduler.c @@ -887,6 +887,30 @@ SCIP_RETCODE transferSolution( return SCIP_OKAY; } +/** release all data and free diving heuristic */ +static +SCIP_RETCODE schedulerFreeDivingHeur( + SCIP* scip, /**< SCIP data structure */ + DIVING_HEUR** divingheur /**< pointer to diving heuristic that should be freed */ + ) +{ + DIVING_HEUR* divingheurptr; + assert(scip != NULL); + assert(divingheur != NULL); + + divingheurptr = *divingheur; + assert(divingheurptr != NULL); + + SCIP_CALL( SCIPfreeClock(scip, &divingheurptr->stats->setupclock) ); + SCIP_CALL( SCIPfreeClock(scip, &divingheurptr->stats->execclock) ); + + SCIPfreeBlockMemory(scip, &divingheurptr->solvefreqdata); + SCIPfreeBlockMemory(scip, &divingheurptr->stats); + SCIPfreeBlockMemory(scip, divingheur); + + return SCIP_OKAY; +} + /* ---------------- Callback methods of event handler ---------------- */ /** execution callback of the event handler @@ -4211,12 +4235,7 @@ SCIP_DECL_HEURFREE(heurFreeScheduler) for( j = 0; j < heurdata->ndiving; ++j ) { - SCIP_CALL( SCIPfreeClock(scip, &(heurdata->divingheurs[j]->stats->setupclock)) ); - SCIP_CALL( SCIPfreeClock(scip, &(heurdata->divingheurs[j]->stats->execclock)) ); - - SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->solvefreqdata); - SCIPfreeBlockMemory(scip, &heurdata->divingheurs[j]->stats); - SCIPfreeBlockMemory(scip, &(heurdata->divingheurs[j])); + SCIP_CALL( schedulerFreeDivingHeur(scip, &(heurdata->divingheurs[j])) ); } SCIPfreeBlockMemoryArray(scip, &heurdata->divingheurs, heurdata->divingheurssize);