Skip to content

Commit c25a29b

Browse files
committed
reorganize statistic update in twoopt
- move initialization and use of variables on dominiks suggestion
1 parent 0d5d6e2 commit c25a29b

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/scip/heur_twoopt.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ SCIP_RETCODE innerPresolve(
692692
*/
693693
startindex = 0;
694694
*nblocks = 0;
695+
*maxblocksize = 0;
695696
*nblockvars = 0;
696697

697698
SCIP_CALL( SCIPallocBlockMemoryArray(scip, blockstart, nvars/2) );
@@ -763,10 +764,10 @@ SCIP_RETCODE presolveTwoOpt(
763764
int nintvars;
764765
int nvars;
765766
SCIP_VAR** vars;
766-
int nbinblockvars = 0;
767+
int nbinblockvars;
767768
int nintblockvars;
768-
int maxbinblocksize = 0;
769-
int maxintblocksize = 0;
769+
int maxbinblocksize;
770+
int maxintblocksize;
770771

771772
assert(scip != NULL);
772773
assert(heurdata != NULL);
@@ -778,27 +779,31 @@ SCIP_RETCODE presolveTwoOpt(
778779
/* get necessary variable information, i.e. number of binary and integer variables */
779780
SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
780781

782+
#ifdef SCIP_STATISTIC
783+
/* update statistics */
784+
heurdata->ntotalbinvars += nbinvars;
785+
#endif
786+
781787
/* if number of binary problem variables exceeds 2, they are subject to 2-optimization algorithm, hence heuristic
782788
* calls innerPresolve method to detect necessary structures. */
783789
if( nbinvars >= 2 )
784790
{
785791
SCIP_CALL( innerPresolve(scip, vars, &(heurdata->binvars), nbinvars, &(heurdata->nbinblocks), &maxbinblocksize,
786792
&nbinblockvars, &(heurdata->binblockstart), &(heurdata->binblockend), heur, heurdata) );
787-
}
788-
789-
heurdata->nbinvars = nbinvars;
790-
heurdata->execute = nbinvars > 1 && heurdata->nbinblocks > 0;
791793

792794
#ifdef SCIP_STATISTIC
793-
/* update statistics */
794-
heurdata->binnblocks += (heurdata->nbinblocks);
795-
heurdata->binnblockvars += nbinblockvars;
796-
heurdata->ntotalbinvars += nbinvars;
797-
heurdata->maxbinblocksize = MAX(maxbinblocksize, heurdata->maxbinblocksize);
795+
/* update statistics */
796+
heurdata->binnblocks += heurdata->nbinblocks;
797+
heurdata->binnblockvars += nbinblockvars;
798+
heurdata->maxbinblocksize = MAX(maxbinblocksize, heurdata->maxbinblocksize);
798799

799-
SCIPstatisticMessage(" Twoopt BINARY presolving finished with <%d> blocks, <%d> block variables \n",
800-
heurdata->nbinblocks, nbinblockvars);
800+
SCIPstatisticMessage(" Twoopt BINARY presolving finished with <%d> blocks, <%d> block variables \n",
801+
heurdata->nbinblocks, nbinblockvars);
801802
#endif
803+
}
804+
805+
heurdata->nbinvars = nbinvars;
806+
heurdata->execute = nbinvars > 1 && heurdata->nbinblocks > 0;
802807

803808
if( heurdata->intopt && nintvars > 1 )
804809
{

0 commit comments

Comments
 (0)