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-2021 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 heuristic data */
239  heurdata = SCIPheurGetData(heur);
240  heurdata->lastselection = -1;
241 
242  assert(heurdata != NULL);
243 
244  /* create working solution */
245  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
246 
247  /* initialize random seed; use problem dimensions to vary initial order between different instances */
248  SCIPsetRandomSeed(scip, heurdata->randnumgen,
250 
251  return SCIP_OKAY;
252 }
253 
254 
255 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
256 static
257 SCIP_DECL_HEUREXIT(heurExitAdaptivediving) /*lint --e{715}*/
258 { /*lint --e{715}*/
259  SCIP_HEURDATA* heurdata;
260 
261  assert(heur != NULL);
262  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
263 
264  /* get heuristic data */
265  heurdata = SCIPheurGetData(heur);
266  assert(heurdata != NULL);
267 
268  /* free working solution */
269  SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
270 
271  return SCIP_OKAY;
272 }
273 
274 /*
275  * heuristic specific interface methods
276  */
277 
278 /** get LP iteration limit for diving */
279 static
281  SCIP* scip, /**< SCIP data structure */
282  SCIP_HEUR* heur, /**< the heuristic */
283  SCIP_HEURDATA* heurdata /**< heuristic data */
284  )
285 {
286  SCIP_Real nsolsfound = SCIPheurGetNSolsFound(heur) + heurdata->bestsolweight * SCIPheurGetNBestSolsFound(heur);
287  SCIP_Longint nlpiterations = SCIPgetNNodeLPIterations(scip);
288  SCIP_Longint ncalls = SCIPheurGetNCalls(heur);
289 
290  SCIP_Longint nlpiterationsdive = 0;
291  SCIP_Longint lpiterlimit;
292  int i;
293 
294  assert(scip != NULL);
295  assert(heur != NULL);
296  assert(heurdata != NULL);
297 
298  /* loop over the divesets and collect their individual iterations */
299  for( i = 0; i < heurdata->ndivesets; ++i )
300  {
301  nlpiterationsdive += SCIPdivesetGetNLPIterations(heurdata->divesets[i], SCIP_DIVECONTEXT_ADAPTIVE);
302  }
303 
304  /* compute the iteration limit */
305  lpiterlimit = (SCIP_Longint)(heurdata->maxlpiterquot * (nsolsfound+1.0)/(ncalls+1.0) * nlpiterations);
306  lpiterlimit += heurdata->maxlpiterofs;
307  lpiterlimit -= nlpiterationsdive;
308 
309  return lpiterlimit;
310 }
311 
312 #ifdef SCIP_DEBUG
313 /** print array for debug purpose */
314 static
315 char* printRealArray(
316  char* strbuf, /**< string buffer array */
317  SCIP_Real* elems, /**< array elements */
318  int nelems /**< number of elements */
319  )
320 {
321  int c;
322  char* pos = strbuf;
323 
324  for( c = 0; c < nelems; ++c )
325  {
326  pos += sprintf(pos, "%.4f ", elems[c]);
327  }
328 
329  return strbuf;
330 }
331 #endif
332 
333 /** sample from a distribution defined by weights */ /*lint -e715*/
334 static
335 int sampleWeighted(
336  SCIP* scip, /**< SCIP data structure */
337  SCIP_RANDNUMGEN* rng, /**< random number generator */
338  SCIP_Real* weights, /**< weights of a ground set that define the sampling distribution */
339  int nweights /**< number of elements in the ground set */
340  )
341 {
342  SCIP_Real weightsum;
343  SCIP_Real randomnr;
344  int w;
345 #ifdef SCIP_DEBUG
346  char strbuf[SCIP_MAXSTRLEN];
347  SCIPdebugMsg(scip, "Weights: %s\n", printRealArray(strbuf, weights, nweights));
348 #endif
349 
350  weightsum = 0.0;
351  /* collect sum of weights */
352  for( w = 0; w < nweights; ++w )
353  {
354  weightsum += weights[w];
355  }
356  assert(weightsum > 0);
357 
358  randomnr = SCIPrandomGetReal(rng, 0.0, weightsum);
359 
360  weightsum = 0.0;
361  /* choose first element i such that the weight sum exceeds the random number */
362  for( w = 0; w < nweights - 1; ++w )
363  {
364  weightsum += weights[w];
365 
366  if( weightsum >= randomnr )
367  break;
368  }
369  assert(w < nweights);
370  assert(weights[w] > 0.0);
371 
372  return w;
373 }
374 
375 /** select the diving method to apply */
376 static
378  SCIP* scip, /**< SCIP data structure */
379  SCIP_HEUR* heur, /**< the heuristic */
380  SCIP_HEURDATA* heurdata, /**< heuristic data */
381  int* selection /**< selection made */
382  )
383 {
384  SCIP_Bool* methodunavailable;
385  SCIP_DIVESET** divesets;
386  int ndivesets;
387  int d;
388  SCIP_RANDNUMGEN* rng;
389  SCIP_DIVECONTEXT divecontext;
390  SCIP_Real* weights;
391  SCIP_Real epsilon_t;
392 
393  divesets = heurdata->divesets;
394  ndivesets = heurdata->ndivesets;
395  assert(ndivesets > 0);
396  assert(divesets != NULL);
397 
398  SCIP_CALL( SCIPallocClearBufferArray(scip, &methodunavailable, ndivesets) );
399 
400  divecontext = heurdata->useadaptivecontext ? SCIP_DIVECONTEXT_ADAPTIVE : SCIP_DIVECONTEXT_TOTAL;
401 
402  /* check availability of divesets */
403  for( d = 0; d < heurdata->ndivesets; ++d )
404  {
405  SCIP_Bool available;
406  SCIP_CALL( SCIPisDivesetAvailable(scip, heurdata->divesets[d], &available) );
407  methodunavailable[d] = ! available;
408  }
409 
410  *selection = -1;
411 
412  rng = heurdata->randnumgen;
413  assert(rng != NULL);
414 
415  switch (heurdata->seltype) {
416  case 'e':
417  epsilon_t = heurdata->epsilon * sqrt(ndivesets / (SCIPheurGetNCalls(heur) + 1.0));
418  epsilon_t = MAX(epsilon_t, 0.05);
419 
420  /* select one of the available methods at random */
421  if( epsilon_t >= 1.0 || SCIPrandomGetReal(rng, 0.0, 1.0) < epsilon_t )
422  {
423  do
424  {
425  *selection = SCIPrandomGetInt(rng, 0, ndivesets - 1);
426  }
427  while( methodunavailable[*selection] );
428  }
429  else
430  {
431  SCIP_Real bestscore = SCIP_REAL_MAX;
432  for( d = 0; d < heurdata->ndivesets; ++d )
433  {
434  SCIP_Real score;
435 
436  if( methodunavailable[d] )
437  continue;
438 
439  SCIP_CALL( divesetGetSelectionScore(divesets[d], heurdata, divecontext, &score) );
440 
441  if( score < bestscore )
442  {
443  bestscore = score;
444  *selection = d;
445  }
446  }
447  }
448  break;
449  case 'w':
450  SCIP_CALL( SCIPallocBufferArray(scip, &weights, ndivesets) );
451 
452  /* initialize weights as inverse of the score + a small positive epsilon */
453  for( d = 0; d < ndivesets; ++d )
454  {
455  SCIP_Real score;
456 
457  SCIP_CALL( divesetGetSelectionScore(divesets[d], heurdata, divecontext, &score) );
458 
459  weights[d] = methodunavailable[d] ? 0.0 : 1 / (score + 1e-4);
460  }
461 
462  *selection = sampleWeighted(scip, rng, weights, ndivesets);
463 
464  SCIPfreeBufferArray(scip, &weights);
465  break;
466  case 'n':
467  /* continue from last selection and stop at the next available method */
468  *selection = heurdata->lastselection;
469 
470  do
471  {
472  *selection = (*selection + 1) % ndivesets;
473  }
474  while( methodunavailable[*selection] );
475  heurdata->lastselection = *selection;
476  break;
477  default:
478  SCIPerrorMessage("Error: Unknown selection method %c\n", heurdata->seltype);
479 
480  return SCIP_INVALIDDATA;
481  }
482 
483  assert(*selection >= 0 && *selection < ndivesets);
484  SCIPfreeBufferArray(scip, &methodunavailable);
485 
486  return SCIP_OKAY;
487 }
488 
489 /** execution method of primal heuristic */
490 static
491 SCIP_DECL_HEUREXEC(heurExecAdaptivediving) /*lint --e{715}*/
492 { /*lint --e{715}*/
493  SCIP_HEURDATA* heurdata;
494  SCIP_DIVESET* diveset;
495  SCIP_DIVESET** divesets;
496  SCIP_Longint lpiterlimit;
497  int selection;
498 
499  assert(heur != NULL);
500  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
501  assert(scip != NULL);
502  assert(result != NULL);
503  assert(SCIPhasCurrentNodeLP(scip));
504 
505  heurdata = SCIPheurGetData(heur);
506  if( heurdata->divesets == NULL )
507  {
508  SCIP_CALL( findAndStoreDivesets(scip, heur, heurdata) );
509  }
510 
511  divesets = heurdata->divesets;
512  assert(divesets != NULL);
513  assert(heurdata->ndivesets > 0);
514 
515  SCIPdebugMsg(scip, "heurExecAdaptivediving: depth %d sols %d inf %u node %lld (last dive at %lld)\n",
518  nodeinfeasible,
521  );
522 
523  *result = SCIP_DELAYED;
524 
525  /* do not call heuristic in node that was already detected to be infeasible */
526  if( nodeinfeasible )
527  return SCIP_OKAY;
528 
529  /* only call heuristic, if an optimal LP solution is at hand */
531  return SCIP_OKAY;
532 
533  /* only call heuristic, if the LP objective value is smaller than the cutoff bound */
535  return SCIP_OKAY;
536 
537  /* only call heuristic, if the LP solution is basic (which allows fast resolve in diving) */
538  if( !SCIPisLPSolBasic(scip) )
539  return SCIP_OKAY;
540 
541  /* don't dive two times at the same node */
543  {
544  SCIPdebugMsg(scip, "already dived at node here\n");
545 
546  return SCIP_OKAY;
547  }
548 
549  *result = SCIP_DIDNOTRUN;
550 
551  lpiterlimit = getLPIterlimit(scip, heur, heurdata);
552 
553  if( lpiterlimit <= 0 )
554  return SCIP_OKAY;
555 
556  /* select the next diving strategy based on previous success */
557  SCIP_CALL( selectDiving(scip, heur, heurdata, &selection) );
558  assert(selection >= 0 && selection < heurdata->ndivesets);
559 
560  diveset = divesets[selection];
561  assert(diveset != NULL);
562 
563  SCIPdebugMsg(scip, "Selected diveset %s\n", SCIPdivesetGetName(diveset));
564 
565  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible,
566  lpiterlimit, SCIP_DIVECONTEXT_ADAPTIVE) );
567 
568  if( *result == SCIP_FOUNDSOL )
569  {
570  SCIPdebugMsg(scip, "Solution found by diveset %s\n", SCIPdivesetGetName(diveset));
571  }
572 
573  return SCIP_OKAY;
574 }
575 
576 /** creates the adaptivediving heuristic and includes it in SCIP */
578  SCIP* scip /**< SCIP data structure */
579  )
580 {
581  SCIP_RETCODE retcode;
582  SCIP_HEURDATA* heurdata;
583  SCIP_HEUR* heur;
584 
585  /* create adaptivediving data */
586  heurdata = NULL;
587  SCIP_CALL( SCIPallocMemory(scip, &heurdata) );
588 
589  heurdata->divesets = NULL;
590  heurdata->ndivesets = 0;
591  heurdata->divesetssize = -1;
592 
593  SCIP_CALL_TERMINATE( retcode, SCIPcreateRandom(scip, &heurdata->randnumgen, DEFAULT_INITIALSEED, TRUE), TERMINATE );
594 
595  /* include adaptive diving primal heuristic */
598  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecAdaptivediving, heurdata) );
599 
600  assert(heur != NULL);
601 
602  /* set non-NULL pointers to callback methods */
603  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyAdaptivediving) );
604  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeAdaptivediving) );
605  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitAdaptivediving) );
606  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitAdaptivediving) );
607 
608  /* add parameters */
609  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/epsilon",
610  "parameter that increases probability of exploration among divesets (only active if seltype is 'e')",
611  &heurdata->epsilon, FALSE, DEFAULT_EPSILON, 0.0, SCIP_REAL_MAX, NULL, NULL) );
612 
613  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/" HEUR_NAME "/scoretype",
614  "score parameter for selection: minimize either average 'n'odes, LP 'i'terations,"
615  "backtrack/'c'onflict ratio, 'd'epth, 1 / 's'olutions, or 1 / solutions'u'ccess",
616  &heurdata->scoretype, FALSE, DEFAULT_SCORETYPE, "cdinsu", NULL, NULL) );
617 
618  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/" HEUR_NAME "/seltype",
619  "selection strategy: (e)psilon-greedy, (w)eighted distribution, (n)ext diving",
620  &heurdata->seltype, FALSE, DEFAULT_SELTYPE, "enw", NULL, NULL) );
621 
622  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useadaptivecontext",
623  "should the heuristic use its own statistics, or shared statistics?", &heurdata->useadaptivecontext, TRUE,
625 
626  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/selconfidencecoeff",
627  "coefficient c to decrease initial confidence (calls + 1.0) / (calls + c) in scores",
628  &heurdata->selconfidencecoeff, FALSE, DEFAULT_SELCONFIDENCECOEFF, 1.0, (SCIP_Real)INT_MAX, NULL, NULL) );
629 
630  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/maxlpiterquot",
631  "maximal fraction of diving LP iterations compared to node LP iterations",
632  &heurdata->maxlpiterquot, FALSE, DEFAULT_MAXLPITERQUOT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
633 
634  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxlpiterofs",
635  "additional number of allowed LP iterations",
636  &heurdata->maxlpiterofs, FALSE, DEFAULT_MAXLPITEROFS, 0L, (SCIP_Longint)INT_MAX, NULL, NULL) );
637 
638  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/bestsolweight",
639  "weight of incumbent solutions compared to other solutions in computation of LP iteration limit",
640  &heurdata->bestsolweight, FALSE, DEFAULT_BESTSOLWEIGHT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
641 
642 /* cppcheck-suppress unusedLabel */
643 TERMINATE:
644  if( retcode != SCIP_OKAY )
645  {
646  SCIPfreeMemory(scip, &heurdata);
647  return retcode;
648  }
649 
650  return SCIP_OKAY;
651 }
static SCIP_RETCODE selectDiving(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, int *selection)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:97
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1555
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:86
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:977
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:80
SCIP_Longint SCIPheurGetNSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1565
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_DECL_HEUREXEC(heurExecAdaptivediving)
static SCIP_DECL_HEURFREE(heurFreeAdaptivediving)
SCIP_RETCODE SCIPisDivesetAvailable(SCIP *scip, SCIP_DIVESET *diveset, SCIP_Bool *available)
Definition: scip_heur.c:356
#define DEFAULT_BESTSOLWEIGHT
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1340
#define SCIPallocClearBufferArray(scip, ptr, num)
Definition: scip_mem.h:113
#define SCIP_MAXSTRLEN
Definition: def.h:279
SCIP_HEUR ** SCIPgetHeurs(SCIP *scip)
Definition: scip_heur.c:262
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
#define FALSE
Definition: def.h:73
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
Definition: misc.c:9981
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
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_Longint SCIPgetNNodeLPIterations(SCIP *scip)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
static SCIP_DECL_HEUREXIT(heurExitAdaptivediving)
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
#define SCIPdebugMsg
Definition: scip_message.h:69
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:159
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1575
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:74
SCIP_Longint SCIPdivesetGetNConflicts(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:608
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:320
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2206
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
SCIP_Longint SCIPdivesetGetNSols(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:621
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_VAR * w
Definition: circlepacking.c:58
#define HEUR_PRIORITY
#define DEFAULT_SCORETYPE
#define HEUR_DESC
#define DEFAULT_INITIALSEED
SCIP_Longint SCIPdivesetGetNLPIterations(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:569
SCIP_Bool SCIPdivesetIsPublic(SCIP_DIVESET *diveset)
Definition: heur.c:744
#define SCIPerrorMessage
Definition: pub_message.h:55
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1637
#define HEUR_TIMING
SCIP_Longint SCIPdivesetGetNBacktracks(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:595
static SCIP_DECL_HEURCOPY(heurCopyAdaptivediving)
SCIP_RETCODE SCIPincludeHeurAdaptivediving(SCIP *scip)
SCIPInterval sqrt(const SCIPInterval &x)
SCIP_SOL * sol
Definition: struct_heur.h:62
static SCIP_DECL_HEURINIT(heurInitAdaptivediving)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1350
#define NULL
Definition: lpi_spx1.cpp:155
const char * SCIPdivesetGetName(SCIP_DIVESET *diveset)
Definition: heur.c:425
int SCIPgetNOrigConss(SCIP *scip)
Definition: scip_prob.c:3128
#define SCIP_CALL(x)
Definition: def.h:370
SCIP_VAR * h
Definition: circlepacking.c:59
SCIP_Bool SCIPisLPSolBasic(SCIP *scip)
Definition: scip_lp.c:637
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip_prob.c:2426
static SCIP_Longint getLPIterlimit(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
SCIP_Longint SCIPdivesetGetNProbingNodes(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:582
#define HEUR_MAXDEPTH
SCIP_Real SCIPgetLPObjval(SCIP *scip)
Definition: scip_lp.c:238
#define HEUR_FREQOFS
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
int SCIPrandomGetInt(SCIP_RANDNUMGEN *randnumgen, int minrandval, int maxrandval)
Definition: misc.c:9959
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1627
#define HEUR_USESSUBSCIP
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:638
#define SCIP_Bool
Definition: def.h:70
#define DIVESETS_INITIALSIZE
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:201
static SCIP_RETCODE findAndStoreDivesets(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
#define MAX(x, y)
Definition: tclique_def.h:83
#define DEFAULT_EPSILON
#define HEUR_NAME
#define HEUR_DISPCHAR
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_Real SCIPdivesetGetAvgDepth(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:517
#define SCIP_REAL_MAX
Definition: def.h:164
#define DEFAULT_SELCONFIDENCECOEFF
#define SCIPfreeMemory(scip, ptr)
Definition: scip_mem.h:67
#define DEFAULT_USEADAPTIVECONTEXT
int SCIPdivesetGetNCalls(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:465
enum SCIP_DiveContext SCIP_DIVECONTEXT
Definition: type_heur.h:63
void SCIPsetRandomSeed(SCIP *scip, SCIP_RANDNUMGEN *randnumgen, unsigned int seed)
static int sampleWeighted(SCIP *scip, SCIP_RANDNUMGEN *rng, SCIP_Real *weights, int nweights)
#define DEFAULT_SELTYPE
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
SCIP_Longint SCIPgetLastDivenode(SCIP *scip)
Definition: scip_lp.c:2685
#define SCIP_Real
Definition: def.h:163
#define SCIP_CALL_TERMINATE(retcode, x, TERM)
Definition: def.h:391
#define SCIP_INVALID
Definition: def.h:183
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:148
#define DEFAULT_MAXLPITEROFS
diving heuristic that selects adaptively between the existing, public dive sets
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
#define SCIPallocMemory(scip, ptr)
Definition: scip_mem.h:51
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 HEUR_FREQ
#define SCIPABORT()
Definition: def.h:342
default SCIP plugins
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
SCIP_Longint SCIPdivesetGetSolSuccess(SCIP_DIVESET *diveset, SCIP_DIVECONTEXT divecontext)
Definition: heur.c:451
int SCIPgetNHeurs(SCIP *scip)
Definition: scip_heur.c:275