Scippy

SCIP

Solving Constraint Integer Programs

heur_adaptivediving.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_adaptivediving.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief diving heuristic that selects adaptively between the existing, public dive sets
19  * @author Gregor Hendel
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include <assert.h>
25 #include <string.h>
26 
28 #include "scip/heuristics.h"
29 #include "scip/scipdefplugins.h"
30 
31 #define HEUR_NAME "adaptivediving"
32 #define HEUR_DESC "diving heuristic that selects adaptively between the existing, public divesets"
33 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_DIVING
34 #define HEUR_PRIORITY -70000
35 #define HEUR_FREQ 5
36 #define HEUR_FREQOFS 3
37 #define HEUR_MAXDEPTH -1
38 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPPLUNGE
39 #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
40 
41 #define DIVESETS_INITIALSIZE 10
42 #define DEFAULT_INITIALSEED 13
43 
44 /*
45  * Default parameter settings
46  */
47 #define DEFAULT_SELTYPE 'w'
48 #define DEFAULT_SCORETYPE 'c' /**< score parameter for selection: minimize either average 'n'odes, LP 'i'terations,
49  * backtrack/'c'onflict ratio, 'd'epth, 1 / 's'olutions, or
50  * 1 / solutions'u'ccess */
51 #define DEFAULT_USEADAPTIVECONTEXT FALSE
52 #define DEFAULT_SELCONFIDENCECOEFF 10.0 /**< coefficient c to decrease initial confidence (calls + 1.0) / (calls + c) in scores */
53 #define DEFAULT_EPSILON 1.0 /**< parameter that increases probability of exploration among divesets (only active if seltype is 'e') */
54 #define DEFAULT_MAXLPITERQUOT 0.1 /**< maximal fraction of diving LP iterations compared to node LP iterations */
55 #define DEFAULT_MAXLPITEROFS 1500L /**< additional number of allowed LP iterations */
56 #define DEFAULT_BESTSOLWEIGHT 10.0 /**< weight of incumbent solutions compared to other solutions in computation of LP iteration limit */
57 
58 /* locally defined heuristic data */
59 struct SCIP_HeurData
60 {
61  /* data structures used internally */
62  SCIP_SOL* sol; /**< working solution */
63  SCIP_RANDNUMGEN* randnumgen; /**< random number generator for selection */
64  SCIP_DIVESET** divesets; /**< publicly available divesets from diving heuristics */
65  int ndivesets; /**< number of publicly available divesets from diving heuristics */
66  int divesetssize; /**< array size for divesets array */
67  int lastselection; /**< stores the last selected diveset when the heuristics was run */
68  /* user parameters */
69  SCIP_Real epsilon; /**< parameter that increases probability of exploration among divesets (only active if seltype is 'e') */
70  SCIP_Real selconfidencecoeff; /**< coefficient c to decrease initial confidence (calls + 1.0) / (calls + c) in scores */
71  SCIP_Real maxlpiterquot; /**< maximal fraction of diving LP iterations compared to node LP iterations */
72  SCIP_Longint maxlpiterofs; /**< additional number of allowed LP iterations */
73  SCIP_Real bestsolweight; /**< weight of incumbent solutions compared to other solutions in computation of LP iteration limit */
74  char seltype; /**< selection strategy: (e)psilon-greedy, (w)eighted distribution, (n)ext diving */
75  char scoretype; /**< score parameter for selection: minimize either average 'n'odes, LP 'i'terations,
76  * backtrack/'c'onflict ratio, 'd'epth, 1 / 's'olutions, or
77  * 1 / solutions'u'ccess */
78  SCIP_Bool useadaptivecontext; /**< should the heuristic use its own statistics, or shared statistics? */
79 };
80 
81 /*
82  * local methods
83  */
84 
85 
86 /** get the selection score for this dive set */
87 static
89  SCIP_DIVESET* diveset, /**< diving settings data structure */
90  SCIP_HEURDATA* heurdata, /**< heuristic data */
91  SCIP_DIVECONTEXT divecontext, /**< context for diving statistics */
92  SCIP_Real* scoreptr /**< pointer to store the score */
93  )
94 {
95  SCIP_Real confidence;
96 
97  assert(scoreptr != NULL);
98 
99  /* compute confidence scalar (converges towards 1 with increasing number of calls) */
100  confidence = (SCIPdivesetGetNCalls(diveset, divecontext) + 1.0) /
101  (SCIPdivesetGetNCalls(diveset, divecontext) + heurdata->selconfidencecoeff);
102 
103  switch (heurdata->scoretype) {
104  case 'n': /* min average nodes */
105  *scoreptr = confidence * SCIPdivesetGetNProbingNodes(diveset, divecontext) / (SCIPdivesetGetNCalls(diveset, divecontext) + 1.0);
106  break;
107  case 'i': /* min avg LP iterations */
108  *scoreptr = confidence * SCIPdivesetGetNLPIterations(diveset, divecontext) / (SCIPdivesetGetNCalls(diveset, divecontext) + 1.0);
109  break;
110  case 'c': /* min backtrack / conflict ratio (the current default) */
111  *scoreptr = confidence * (SCIPdivesetGetNBacktracks(diveset, divecontext)) / (SCIPdivesetGetNConflicts(diveset, divecontext) + 10.0);
112  break;
113  case 'd': /* minimum average depth */
114  *scoreptr = SCIPdivesetGetAvgDepth(diveset, divecontext) * confidence;
115  break;
116  case 's': /* maximum number of solutions */
117  *scoreptr = confidence / (SCIPdivesetGetNSols(diveset, divecontext) + 1.0);
118  break;
119  case 'u': /* maximum solution success (which weighs best solutions higher) */
120  *scoreptr = confidence / (SCIPdivesetGetSolSuccess(diveset, divecontext) + 1.0);
121  break;
122  default:
123  SCIPerrorMessage("Unsupported scoring parameter '%c'\n", heurdata->scoretype);
124  SCIPABORT();
125  *scoreptr = SCIP_INVALID;
126  return SCIP_PARAMETERWRONGVAL;
127  }
128 
129  return SCIP_OKAY;
130 }
131 
132 /*
133  * Callback methods
134  */
135 
136 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
137 static
138 SCIP_DECL_HEURCOPY(heurCopyAdaptivediving)
139 { /*lint --e{715}*/
140  assert(scip != NULL);
141  assert(heur != NULL);
142  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
143 
144  /* call inclusion method of primal heuristic */
146 
147  return SCIP_OKAY;
148 }
149 
150 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
151 static
152 SCIP_DECL_HEURFREE(heurFreeAdaptivediving) /*lint --e{715}*/
153 { /*lint --e{715}*/
154  SCIP_HEURDATA* heurdata;
155 
156  assert(heur != NULL);
157  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
158  assert(scip != NULL);
159 
160  /* free heuristic data */
161  heurdata = SCIPheurGetData(heur);
162  assert(heurdata != NULL);
163 
164  if( heurdata->divesets != NULL )
165  {
166  SCIPfreeBlockMemoryArray(scip, &heurdata->divesets, heurdata->divesetssize);
167  }
168 
169  SCIPfreeRandom(scip, &heurdata->randnumgen);
170 
171  SCIPfreeMemory(scip, &heurdata);
172  SCIPheurSetData(heur, NULL);
173 
174  return SCIP_OKAY;
175 }
176 
177 /** find publicly available divesets and store them */
178 static
180  SCIP* scip, /**< SCIP data structure */
181  SCIP_HEUR* heur, /**< the heuristic */
182  SCIP_HEURDATA* heurdata /**< heuristic data */
183  )
184 {
185  int h;
186  SCIP_HEUR** heurs;
187 
188  assert(scip != NULL);
189  assert(heur != NULL);
190  assert(heurdata != NULL);
191 
192  heurs = SCIPgetHeurs(scip);
193 
194  heurdata->divesetssize = DIVESETS_INITIALSIZE;
195  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->divesets, heurdata->divesetssize) );
196  heurdata->ndivesets = 0;
197 
198  for( h = 0; h < SCIPgetNHeurs(scip); ++h )
199  {
200  int d;
201  assert(heurs[h] != NULL);
202 
203  /* loop over divesets of this heuristic and check whether they are public */
204  for( d = 0; d < SCIPheurGetNDivesets(heurs[h]); ++d )
205  {
206  SCIP_DIVESET* diveset = SCIPheurGetDivesets(heurs[h])[d];
207  if( SCIPdivesetIsPublic(diveset) )
208  {
209  SCIPdebugMsg(scip, "Found publicly available diveset %s\n", SCIPdivesetGetName(diveset));
210 
211  if( heurdata->ndivesets == heurdata->divesetssize )
212  {
213  int newsize = 2 * heurdata->divesetssize;
214  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &heurdata->divesets, heurdata->divesetssize, newsize) );
215  heurdata->divesetssize = newsize;
216  }
217  heurdata->divesets[heurdata->ndivesets++] = diveset;
218  }
219  else
220  {
221  SCIPdebugMsg(scip, "Skipping private diveset %s\n", SCIPdivesetGetName(diveset));
222  }
223  }
224  }
225  return SCIP_OKAY;
226 }
227 
228 
229 /** initialization method of primal heuristic (called after problem was transformed) */
230 static
231 SCIP_DECL_HEURINIT(heurInitAdaptivediving) /*lint --e{715}*/
232 { /*lint --e{715}*/
233  SCIP_HEURDATA* heurdata;
234 
235  assert(heur != NULL);
236  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
237 
238  /* get and reset heuristic data */
239  heurdata = SCIPheurGetData(heur);
240  heurdata->lastselection = -1;
241  if( heurdata->divesets != NULL )
242  {
243  /* we clear the list of collected divesets to ensure reproducability and consistent state across multiple runs
244  * within the same SCIP data structure */
245  SCIPfreeBlockMemoryArray(scip, &heurdata->divesets, heurdata->divesetssize);
246  assert(heurdata->divesets == NULL);
247  }
248 
249  assert(heurdata != NULL);
250 
251  /* create working solution */
252  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
253 
254  /* initialize random seed; use problem dimensions to vary initial order between different instances */
255  SCIPsetRandomSeed(scip, heurdata->randnumgen,
257 
258  return SCIP_OKAY;
259 }
260 
261 
262 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
263 static
264 SCIP_DECL_HEUREXIT(heurExitAdaptivediving) /*lint --e{715}*/
265 { /*lint --e{715}*/
266  SCIP_HEURDATA* heurdata;
267 
268  assert(heur != NULL);
269  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
270 
271  /* get heuristic data */
272  heurdata = SCIPheurGetData(heur);
273  assert(heurdata != NULL);
274 
275  /* free working solution */
276  SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
277 
278  return SCIP_OKAY;
279 }
280 
281 /*
282  * heuristic specific interface methods
283  */
284 
285 /** get LP iteration limit for diving */
286 static
288  SCIP* scip, /**< SCIP data structure */
289  SCIP_HEUR* heur, /**< the heuristic */
290  SCIP_HEURDATA* heurdata /**< heuristic data */
291  )
292 {
293  SCIP_Real nsolsfound = SCIPheurGetNSolsFound(heur) + heurdata->bestsolweight * SCIPheurGetNBestSolsFound(heur);
294  SCIP_Longint nlpiterations = SCIPgetNNodeLPIterations(scip);
295  SCIP_Longint ncalls = SCIPheurGetNCalls(heur);
296 
297  SCIP_Longint nlpiterationsdive = 0;
298  SCIP_Longint lpiterlimit;
299  int i;
300 
301  assert(scip != NULL);
302  assert(heur != NULL);
303  assert(heurdata != NULL);
304 
305  /* loop over the divesets and collect their individual iterations */
306  for( i = 0; i < heurdata->ndivesets; ++i )
307  {
308  nlpiterationsdive += SCIPdivesetGetNLPIterations(heurdata->divesets[i], SCIP_DIVECONTEXT_ADAPTIVE);
309  }
310 
311  /* compute the iteration limit */
312  lpiterlimit = (SCIP_Longint)(heurdata->maxlpiterquot * (nsolsfound+1.0)/(ncalls+1.0) * nlpiterations);
313  lpiterlimit += heurdata->maxlpiterofs;
314  lpiterlimit -= nlpiterationsdive;
315 
316  return lpiterlimit;
317 }
318 
319 #ifdef SCIP_DEBUG
320 /** print array for debug purpose */
321 static
322 char* printRealArray(
323  char* strbuf, /**< string buffer array */
324  SCIP_Real* elems, /**< array elements */
325  int nelems /**< number of elements */
326  )
327 {
328  int c;
329  char* pos = strbuf;
330 
331  for( c = 0; c < nelems; ++c )
332  {
333  pos += sprintf(pos, "%.4f ", elems[c]);
334  }
335 
336  return strbuf;
337 }
338 #endif
339 
340 /** sample from a distribution defined by weights */ /*lint -e715*/
341 static
342 int sampleWeighted(
343  SCIP* scip, /**< SCIP data structure */
344  SCIP_RANDNUMGEN* rng, /**< random number generator */
345  SCIP_Real* weights, /**< weights of a ground set that define the sampling distribution */
346  int nweights /**< number of elements in the ground set */
347  )
348 {
349  SCIP_Real weightsum;
350  SCIP_Real randomnr;
351  int w;
352 #ifdef SCIP_DEBUG
353  char strbuf[SCIP_MAXSTRLEN];
354  SCIPdebugMsg(scip, "Weights: %s\n", printRealArray(strbuf, weights, nweights));
355 #endif
356 
357  weightsum = 0.0;
358  /* collect sum of weights */
359  for( w = 0; w < nweights; ++w )
360  {
361  weightsum += weights[w];
362  }
363  assert(weightsum > 0);
364 
365  randomnr = SCIPrandomGetReal(rng, 0.0, weightsum);
366 
367  weightsum = 0.0;
368  /* choose first element i such that the weight sum exceeds the random number */
369  for( w = 0; w < nweights - 1; ++w )
370  {
371  weightsum += weights[w];
372 
373  if( weightsum >= randomnr )
374  break;
375  }
376  assert(w < nweights);
377  assert(weights[w] > 0.0);
378 
379  return w;
380 }
381 
382 /** select the diving method to apply */
383 static
385  SCIP* scip, /**< SCIP data structure */
386  SCIP_HEUR* heur, /**< the heuristic */
387  SCIP_HEURDATA* heurdata, /**< heuristic data */
388  int* selection /**< selection made */
389  )
390 {
391  SCIP_Bool* methodunavailable;
392  SCIP_DIVESET** divesets;
393  int ndivesets;
394  int d;
395  SCIP_RANDNUMGEN* rng;
396  SCIP_DIVECONTEXT divecontext;
397  SCIP_Real* weights;
398  SCIP_Real epsilon_t;
399 
400  divesets = heurdata->divesets;
401  ndivesets = heurdata->ndivesets;
402  assert(ndivesets > 0);
403  assert(divesets != NULL);
404 
405  SCIP_CALL( SCIPallocClearBufferArray(scip, &methodunavailable, ndivesets) );
406 
407  divecontext = heurdata->useadaptivecontext ? SCIP_DIVECONTEXT_ADAPTIVE : SCIP_DIVECONTEXT_TOTAL;
408 
409  /* check availability of divesets */
410  for( d = 0; d < heurdata->ndivesets; ++d )
411  {
412  SCIP_Bool available;
413  SCIP_CALL( SCIPisDivesetAvailable(scip, heurdata->divesets[d], &available) );
414  methodunavailable[d] = ! available;
415  }
416 
417  *selection = -1;
418 
419  rng = heurdata->randnumgen;
420  assert(rng != NULL);
421 
422  switch (heurdata->seltype) {
423  case 'e':
424  epsilon_t = heurdata->epsilon * sqrt(ndivesets / (SCIPheurGetNCalls(heur) + 1.0));
425  epsilon_t = MAX(epsilon_t, 0.05);
426 
427  /* select one of the available methods at random */
428  if( epsilon_t >= 1.0 || SCIPrandomGetReal(rng, 0.0, 1.0) < epsilon_t )
429  {
430  do
431  {
432  *selection = SCIPrandomGetInt(rng, 0, ndivesets - 1);
433  }
434  while( methodunavailable[*selection] );
435  }
436  else
437  {
438  SCIP_Real bestscore = SCIP_REAL_MAX;
439  for( d = 0; d < heurdata->ndivesets; ++d )
440  {
441  SCIP_Real score;
442 
443  if( methodunavailable[d] )
444  continue;
445 
446  SCIP_CALL( divesetGetSelectionScore(divesets[d], heurdata, divecontext, &score) );
447 
448  if( score < bestscore )
449  {
450  bestscore = score;
451  *selection = d;
452  }
453  }
454  }
455  break;
456  case 'w':
457  SCIP_CALL( SCIPallocBufferArray(scip, &weights, ndivesets) );
458 
459  /* initialize weights as inverse of the score + a small positive epsilon */
460  for( d = 0; d < ndivesets; ++d )
461  {
462  SCIP_Real score;
463 
464  SCIP_CALL( divesetGetSelectionScore(divesets[d], heurdata, divecontext, &score) );
465 
466  weights[d] = methodunavailable[d] ? 0.0 : 1 / (score + 1e-4);
467  }
468 
469  *selection = sampleWeighted(scip, rng, weights, ndivesets);
470 
471  SCIPfreeBufferArray(scip, &weights);
472  break;
473  case 'n':
474  /* continue from last selection and stop at the next available method */
475  *selection = heurdata->lastselection;
476 
477  do
478  {
479  *selection = (*selection + 1) % ndivesets;
480  }
481  while( methodunavailable[*selection] );
482  heurdata->lastselection = *selection;
483  break;
484  default:
485  SCIPerrorMessage("Error: Unknown selection method %c\n", heurdata->seltype);
486 
487  return SCIP_INVALIDDATA;
488  }
489 
490  assert(*selection >= 0 && *selection < ndivesets);
491  SCIPfreeBufferArray(scip, &methodunavailable);
492 
493  return SCIP_OKAY;
494 }
495 
496 /** execution method of primal heuristic */
497 static
498 SCIP_DECL_HEUREXEC(heurExecAdaptivediving) /*lint --e{715}*/
499 { /*lint --e{715}*/
500  SCIP_HEURDATA* heurdata;
501  SCIP_DIVESET* diveset;
502  SCIP_DIVESET** divesets;
503  SCIP_Longint lpiterlimit;
504  int selection;
505 
506  assert(heur != NULL);
507  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
508  assert(scip != NULL);
509  assert(result != NULL);
510  assert(SCIPhasCurrentNodeLP(scip));
511 
512  heurdata = SCIPheurGetData(heur);
513  if( heurdata->divesets == NULL )
514  {
515  SCIP_CALL( findAndStoreDivesets(scip, heur, heurdata) );
516  }
517 
518  divesets = heurdata->divesets;
519  assert(divesets != NULL);
520  assert(heurdata->ndivesets > 0);
521 
522  SCIPdebugMsg(scip, "heurExecAdaptivediving: depth %d sols %d inf %u node %lld (last dive at %lld)\n",
525  nodeinfeasible,
528  );
529 
530  *result = SCIP_DELAYED;
531 
532  /* do not call heuristic in node that was already detected to be infeasible */
533  if( nodeinfeasible )
534  return SCIP_OKAY;
535 
536  /* only call heuristic, if an optimal LP solution is at hand */
538  return SCIP_OKAY;
539 
540  /* only call heuristic, if the LP objective value is smaller than the cutoff bound */
542  return SCIP_OKAY;
543 
544  /* only call heuristic, if the LP solution is basic (which allows fast resolve in diving) */
545  if( !SCIPisLPSolBasic(scip) )
546  return SCIP_OKAY;
547 
548  /* don't dive two times at the same node */
550  {
551  SCIPdebugMsg(scip, "already dived at node here\n");
552 
553  return SCIP_OKAY;
554  }
555 
556  *result = SCIP_DIDNOTRUN;
557 
558  lpiterlimit = getLPIterlimit(scip, heur, heurdata);
559 
560  if( lpiterlimit <= 0 )
561  return SCIP_OKAY;
562 
563  /* select the next diving strategy based on previous success */
564  SCIP_CALL( selectDiving(scip, heur, heurdata, &selection) );
565  assert(selection >= 0 && selection < heurdata->ndivesets);
566 
567  diveset = divesets[selection];
568  assert(diveset != NULL);
569 
570  SCIPdebugMsg(scip, "Selected diveset %s\n", SCIPdivesetGetName(diveset));
571 
572  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible,
573  lpiterlimit, SCIP_DIVECONTEXT_ADAPTIVE) );
574 
575  if( *result == SCIP_FOUNDSOL )
576  {
577  SCIPdebugMsg(scip, "Solution found by diveset %s\n", SCIPdivesetGetName(diveset));
578  }
579 
580  return SCIP_OKAY;
581 }
582 
583 /** creates the adaptivediving heuristic and includes it in SCIP */
585  SCIP* scip /**< SCIP data structure */
586  )
587 {
588  SCIP_RETCODE retcode;
589  SCIP_HEURDATA* heurdata;
590  SCIP_HEUR* heur;
591 
592  /* create adaptivediving data */
593  heurdata = NULL;
594  SCIP_CALL( SCIPallocMemory(scip, &heurdata) );
595 
596  heurdata->divesets = NULL;
597  heurdata->ndivesets = 0;
598  heurdata->divesetssize = -1;
599 
600  SCIP_CALL_TERMINATE( retcode, SCIPcreateRandom(scip, &heurdata->randnumgen, DEFAULT_INITIALSEED, TRUE), TERMINATE );
601 
602  /* include adaptive diving primal heuristic */
605  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecAdaptivediving, heurdata) );
606 
607  assert(heur != NULL);
608 
609  /* set non-NULL pointers to callback methods */
610  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyAdaptivediving) );
611  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeAdaptivediving) );
612  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitAdaptivediving) );
613  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitAdaptivediving) );
614 
615  /* add parameters */
616  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/epsilon",
617  "parameter that increases probability of exploration among divesets (only active if seltype is 'e')",
618  &heurdata->epsilon, FALSE, DEFAULT_EPSILON, 0.0, SCIP_REAL_MAX, NULL, NULL) );
619 
620  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/" HEUR_NAME "/scoretype",
621  "score parameter for selection: minimize either average 'n'odes, LP 'i'terations,"
622  "backtrack/'c'onflict ratio, 'd'epth, 1 / 's'olutions, or 1 / solutions'u'ccess",
623  &heurdata->scoretype, FALSE, DEFAULT_SCORETYPE, "cdinsu", NULL, NULL) );
624 
625  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/" HEUR_NAME "/seltype",
626  "selection strategy: (e)psilon-greedy, (w)eighted distribution, (n)ext diving",
627  &heurdata->seltype, FALSE, DEFAULT_SELTYPE, "enw", NULL, NULL) );
628 
629  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useadaptivecontext",
630  "should the heuristic use its own statistics, or shared statistics?", &heurdata->useadaptivecontext, TRUE,
632 
633  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/selconfidencecoeff",
634  "coefficient c to decrease initial confidence (calls + 1.0) / (calls + c) in scores",
635  &heurdata->selconfidencecoeff, FALSE, DEFAULT_SELCONFIDENCECOEFF, 1.0, (SCIP_Real)INT_MAX, NULL, NULL) );
636 
637  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/maxlpiterquot",
638  "maximal fraction of diving LP iterations compared to node LP iterations",
639  &heurdata->maxlpiterquot, FALSE, DEFAULT_MAXLPITERQUOT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
640 
641  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxlpiterofs",
642  "additional number of allowed LP iterations",
643  &heurdata->maxlpiterofs, FALSE, DEFAULT_MAXLPITEROFS, 0L, (SCIP_Longint)INT_MAX, NULL, NULL) );
644 
645  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/bestsolweight",
646  "weight of incumbent solutions compared to other solutions in computation of LP iteration limit",
647  &heurdata->bestsolweight, FALSE, DEFAULT_BESTSOLWEIGHT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
648 
649 /* cppcheck-suppress unusedLabel */
650 TERMINATE:
651  if( retcode != SCIP_OKAY )
652  {
653  SCIPfreeMemory(scip, &heurdata);
654  return retcode;
655  }
656 
657  return SCIP_OKAY;
658 }
static SCIP_RETCODE selectDiving(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, int *selection)
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:101
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:90
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:84
SCIP_Longint SCIPdivesetGetNBacktracks(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:604
static SCIP_DECL_HEUREXEC(heurExecAdaptivediving)
static SCIP_DECL_HEURFREE(heurFreeAdaptivediving)
#define DEFAULT_BESTSOLWEIGHT
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
#define SCIPallocClearBufferArray(scip, ptr, num)
Definition: scip_mem.h:117
#define SCIP_MAXSTRLEN
Definition: def.h:293
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1587
void SCIPsetRandomSeed(SCIP *scip, SCIP_RANDNUMGEN *randnumgen, unsigned int seed)
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:201
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip_prob.c:2431
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Longint SCIPdivesetGetNLPIterations(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:578
int SCIPdivesetGetNCalls(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:474
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1639
#define FALSE
Definition: def.h:87
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:102
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
SCIP_HEUR ** SCIPgetHeurs(SCIP *scip)
Definition: scip_heur.c:262
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip_heur.c:108
int SCIPrandomGetInt(SCIP_RANDNUMGEN *randnumgen, int minrandval, int maxrandval)
Definition: misc.c:10003
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:127
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1362
static SCIP_DECL_HEUREXIT(heurExitAdaptivediving)
SCIP_Longint SCIPdivesetGetNProbingNodes(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:591
#define SCIPdebugMsg
Definition: scip_message.h:69
SCIP_Longint SCIPdivesetGetSolSuccess(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:460
SCIP_RETCODE SCIPperformGenericDivingAlgorithm(SCIP *scip, SCIP_DIVESET *diveset, SCIP_SOL *worksol, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Bool nodeinfeasible, SCIP_Longint iterlim, SCIP_DIVECONTEXT divecontext)
Definition: heuristics.c:209
SCIP_Bool SCIPdivesetIsPublic(SCIP_DIVESET *diveset)
Definition: heur.c:753
SCIP_Bool SCIPisLPSolBasic(SCIP *scip)
Definition: scip_lp.c:658
SCIP_VAR * w
Definition: circlepacking.c:58
#define HEUR_PRIORITY
#define DEFAULT_SCORETYPE
#define HEUR_DESC
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1441
#define DEFAULT_INITIALSEED
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
SCIP_Longint SCIPdivesetGetNSols(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:630
#define HEUR_TIMING
static SCIP_DECL_HEURCOPY(heurCopyAdaptivediving)
SCIP_RETCODE SCIPincludeHeurAdaptivediving(SCIP *scip)
SCIP_SOL * sol
Definition: struct_heur.h:62
static SCIP_DECL_HEURINIT(heurInitAdaptivediving)
#define NULL
Definition: lpi_spx1.cpp:155
#define SCIP_CALL(x)
Definition: def.h:384
int SCIPgetNOrigConss(SCIP *scip)
Definition: scip_prob.c:3133
SCIP_VAR * h
Definition: circlepacking.c:59
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1649
static SCIP_Longint getLPIterlimit(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1567
#define HEUR_MAXDEPTH
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:74
SCIP_Longint SCIPgetLastDivenode(SCIP *scip)
Definition: scip_lp.c:2730
SCIP_Longint SCIPgetNNodeLPIterations(SCIP *scip)
#define HEUR_FREQOFS
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
#define HEUR_USESSUBSCIP
#define SCIP_Bool
Definition: def.h:84
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:159
#define DIVESETS_INITIALSIZE
static SCIP_RETCODE findAndStoreDivesets(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:661
#define MAX(x, y)
Definition: tclique_def.h:83
SCIP_RETCODE SCIPisDivesetAvailable(SCIP *scip, SCIP_DIVESET *diveset, SCIP_Bool *available)
Definition: scip_heur.c:354
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:976
#define DEFAULT_EPSILON
#define HEUR_NAME
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2205
#define HEUR_DISPCHAR
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
Definition: misc.c:10025
#define SCIP_REAL_MAX
Definition: def.h:178
#define DEFAULT_SELCONFIDENCECOEFF
#define SCIPfreeMemory(scip, ptr)
Definition: scip_mem.h:69
#define DEFAULT_USEADAPTIVECONTEXT
int SCIPgetNHeurs(SCIP *scip)
Definition: scip_heur.c:273
enum SCIP_DiveContext SCIP_DIVECONTEXT
Definition: type_heur.h:63
SCIP_Real SCIPgetLPObjval(SCIP *scip)
Definition: scip_lp.c:238
SCIP_Longint SCIPdivesetGetNConflicts(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:617
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:158
static int sampleWeighted(SCIP *scip, SCIP_RANDNUMGEN *rng, SCIP_Real *weights, int nweights)
#define DEFAULT_SELTYPE
SCIP_Real SCIPdivesetGetAvgDepth(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:526
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
#define SCIP_Real
Definition: def.h:177
#define SCIP_CALL_TERMINATE(retcode, x, TERM)
Definition: def.h:405
#define SCIP_INVALID
Definition: def.h:197
static SCIP_RETCODE divesetGetSelectionScore(SCIP_DIVESET *diveset, SCIP_HEURDATA *heurdata, SCIP_DIVECONTEXT divecontext, SCIP_Real *scoreptr)
#define DEFAULT_MAXLPITERQUOT
#define SCIP_Longint
Definition: def.h:162
SCIP_Longint SCIPheurGetNSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1577
#define DEFAULT_MAXLPITEROFS
diving heuristic that selects adaptively between the existing, public dive sets
#define SCIPallocMemory(scip, ptr)
Definition: scip_mem.h:51
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1352
#define HEUR_FREQ
SCIP_Longint SCIPgetNNodes(SCIP *scip)
#define SCIPABORT()
Definition: def.h:356
default SCIP plugins
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:130
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:48
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:319
const char * SCIPdivesetGetName(SCIP_DIVESET *diveset)
Definition: heur.c:434