Scippy

SCIP

Solving Constraint Integer Programs

heur_crossover.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-2017 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_crossover.c
17  * @brief crossover primal heuristic
18  * @author Timo Berthold
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include "scip/scip.h"
27 #include "scip/scipdefplugins.h"
28 #include "scip/cons_linear.h"
29 #include "scip/heur_crossover.h"
30 #include "scip/pub_misc.h"
31 
32 #define HEUR_NAME "crossover"
33 #define HEUR_DESC "LNS heuristic that fixes all variables that are identic in a couple of solutions"
34 #define HEUR_DISPCHAR 'C'
35 #define HEUR_PRIORITY -1104000
36 #define HEUR_FREQ 30
37 #define HEUR_FREQOFS 0
38 #define HEUR_MAXDEPTH -1
39 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
40 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
41 
42 #define DEFAULT_MAXNODES 5000LL /* maximum number of nodes to regard in the subproblem */
43 #define DEFAULT_MINIMPROVE 0.01 /* factor by which Crossover should at least improve the incumbent */
44 #define DEFAULT_MINNODES 50LL /* minimum number of nodes to regard in the subproblem */
45 #define DEFAULT_MINFIXINGRATE 0.666 /* minimum percentage of integer variables that have to be fixed */
46 #define DEFAULT_NODESOFS 500LL /* number of nodes added to the contingent of the total nodes */
47 #define DEFAULT_NODESQUOT 0.1 /* subproblem nodes in relation to nodes of the original problem */
48 #define DEFAULT_LPLIMFAC 2.0 /* factor by which the limit on the number of LP depends on the node limit */
49 #define DEFAULT_NUSEDSOLS 3 /* number of solutions that will be taken into account */
50 #define DEFAULT_NWAITINGNODES 200LL /* number of nodes without incumbent change heuristic should wait */
51 #define DEFAULT_RANDOMIZATION TRUE /* should the choice which sols to take be randomized? */
52 #define DEFAULT_DONTWAITATROOT FALSE /* should the nwaitingnodes parameter be ignored at the root node? */
53 #define DEFAULT_USELPROWS FALSE /* should subproblem be created out of the rows in the LP rows,
54  * otherwise, the copy constructors of the constraints handlers are used */
55 #define DEFAULT_COPYCUTS TRUE /* if DEFAULT_USELPROWS is FALSE, then should all active cuts from the
56  * cutpool of the original scip be copied to constraints of the subscip
57  */
58 #define DEFAULT_PERMUTE FALSE /* should the subproblem be permuted to increase diversification? */
59 #define HASHSIZE_SOLS 500 /* size of hash table for solution tuples in crossover heuristic */
60 #define DEFAULT_BESTSOLLIMIT -1 /* limit on number of improving incumbent solutions in sub-CIP */
61 #define DEFAULT_USEUCT FALSE /* should uct node selection be used at the beginning of the search? */
62 #define DEFAULT_RANDSEED 7 /* initial random seed */
63 
64 /* event handler properties */
65 #define EVENTHDLR_NAME "Crossover"
66 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic"
67 
68 /*
69  * Data structures
70  */
71 
72 typedef struct SolTuple SOLTUPLE;
73 
74 /** primal heuristic data */
75 struct SCIP_HeurData
76 {
77  SCIP_SOL* prevlastsol; /**< worst solution taken into account during the previous run */
78  SCIP_SOL* prevbestsol; /**< best solution during the previous run */
79  int prevnsols; /**< number of all solutions during the previous run */
80 
81  SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
82  SCIP_Longint minnodes; /**< minimum number of nodes to regard in the subproblem */
83  SCIP_Longint nodesofs; /**< number of nodes added to the contingent of the total nodes */
84  SCIP_Longint usednodes; /**< nodes already used by crossover in earlier calls */
85  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
86 
87  int nusedsols; /**< number of solutions that will be taken into account */
88  SCIP_Longint nwaitingnodes; /**< number of nodes without incumbent change heuristic should wait */
89  unsigned int nfailures; /**< number of failures since last successful call */
90  SCIP_Longint nextnodenumber; /**< number of nodes at which crossover should be called the next time */
91  SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
92  SCIP_Real minimprove; /**< factor by which Crossover should at least improve the incumbent */
93  SCIP_Real nodelimit; /**< the nodelimit employed in the current sub-SCIP, for the event handler*/
94  SCIP_Real lplimfac; /**< factor by which the limit on the number of LP depends on the node limit */
95  SCIP_Bool randomization; /**< should the choice which sols to take be randomized? */
96  SCIP_Bool dontwaitatroot; /**< should the nwaitingnodes parameter be ignored at the root node? */
97  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
98  SCIP_HASHTABLE* hashtable; /**< hashtable used to store the solution tuples already used */
99  SOLTUPLE* lasttuple; /**< last tuple of solutions created by crossover */
100  SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
101  SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
102  * to constraints in subproblem? */
103  SCIP_Bool permute; /**< should the subproblem be permuted to increase diversification? */
104  int bestsollimit; /**< limit on number of improving incumbent solutions in sub-CIP */
105  SCIP_Bool useuct; /**< should uct node selection be used at the beginning of the search? */
106 };
107 
108 /** n-tuple of solutions and their hashkey */
109 struct SolTuple
110 {
111  int* indices; /**< sorted array of solution indices */
112  int size; /**< size of the array (should be heurdata->nusedsols) */
113  unsigned int key; /**< hashkey of the tuple */
114  SOLTUPLE* prev; /**< previous solution tuple created */
115 };
116 
117 
118 /*
119  * Local methods
120  */
121 
122 /** gets the hash key of a solution tuple */
123 static
124 SCIP_DECL_HASHGETKEY(hashGetKeySols)
125 { /*lint --e{715}*/
126  return elem;
127 }
128 
129 
130 /** returns TRUE iff both solution tuples are identical */
131 static
132 SCIP_DECL_HASHKEYEQ(hashKeyEqSols)
133 { /*lint --e{715}*/
134  int i;
135  int size;
136 
137  int* indices1;
138  int* indices2;
139 
140  indices1 = ((SOLTUPLE*)key1)->indices;
141  indices2 = ((SOLTUPLE*)key2)->indices;
142 
143  /* there should be two nonempty arrays of the same size */
144  assert(indices1 != NULL);
145  assert(indices2 != NULL);
146  assert(((SOLTUPLE*)key1)->size == ((SOLTUPLE*)key2)->size);
147 
148  size = ((SOLTUPLE*)key1)->size;
149 
150  /* compare arrays by components, return TRUE, iff equal */
151  for( i = 0; i < size; i++ )
152  {
153  if( indices1[i] != indices2[i] )
154  return FALSE;
155  }
156 
157  return TRUE;
158 }
159 
160 
161 /** returns hashkey of a solution tuple */
162 static
163 SCIP_DECL_HASHKEYVAL(hashKeyValSols)
164 { /*lint --e{715}*/
165  return ((SOLTUPLE*)key)->key;
166 }
167 
168 
169 /** calculates a hash key for a given tuple of solution indices */
170 static
171 unsigned int calculateHashKey(
172  int* indices, /**< indices of solutions */
173  int size /**< number of solutions */
174  )
175 {
176  int i;
177  unsigned int hashkey;
178 
179  /* hashkey should be (x1+1) * (x2+1) * ... * (xn+1) + x1 + x2 + ... + xn */
180  hashkey = 1;
181  for( i = 0; i < size; i++ )
182  hashkey *= indices[i] + 1;
183  for( i = 0; i < size; i++ )
184  hashkey += indices[i];
185 
186  return hashkey;
187 }
188 
189 
190 /** insertion sort for a small int array */
191 static void sortArray(
192  int* a, /**< array to be sorted */
193  int size /**< size of array */
194  )
195 {
196  int i;
197  int j;
198  int tmp;
199 
200  /* simple insertion sort algorithm */
201  for( i = 1; i < size; i++ )
202  {
203  tmp = a[i];
204  j = i-1;
205  while( j >= 0 && a[j] > tmp )
206  {
207  a[j+1] = a[j]; /*lint !e679*/
208  j = j-1;
209  }
210  a[j+1] = tmp; /*lint !e679*/
211  }
212 }
213 
214 
215 /** creates a new tuple of solutions */
216 static
218  SCIP* scip, /**< original SCIP data structure */
219  SOLTUPLE** elem, /**< tuple of solutions which should be created */
220  int* indices, /**< indices of solutions */
221  int size, /**< number of solutions */
222  SCIP_HEURDATA* heurdata /**< primal heuristic data */
223  )
224 {
225  /* memory allocation */
226  SCIP_CALL( SCIPallocBlockMemory(scip, elem) );
227  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*elem)->indices, size) );
228  BMScopyMemoryArray((*elem)->indices, indices, size);
229 
230  /* data input */
231  sortArray(indices,size);
232  (*elem)->size = size;
233  (*elem)->key = calculateHashKey((*elem)->indices, (*elem)->size);
234  (*elem)->prev = heurdata->lasttuple;
235 
236  /* update heurdata */
237  heurdata->lasttuple = *elem;
238  return SCIP_OKAY;
239 }
240 
241 
242 /** checks whether the new solution was found at the same node by the same heuristic as an already selected one */
243 static
245  SCIP_SOL** sols, /**< feasible SCIP solutions */
246  int* selection, /**< pool of solutions crossover uses */
247  int selectionsize, /**< size of solution pool */
248  int newsol /**< candidate solution */
249  )
250 {
251  int i;
252 
253  for( i = 0; i < selectionsize; i++ )
254  {
255  if( SCIPsolGetHeur(sols[selection[i]]) == SCIPsolGetHeur(sols[newsol])
256  && SCIPsolGetNodenum(sols[selection[i]]) == SCIPsolGetNodenum(sols[newsol]) )
257  return FALSE;
258  }
259 
260  return TRUE;
261 }
262 
263 /** randomly selects the solutions crossover will use from the pool of all solutions found so far */
264 static
266  SCIP* scip, /**< original SCIP data structure */
267  int* selection, /**< pool of solutions crossover uses */
268  SCIP_HEURDATA* heurdata, /**< primal heuristic data */
269  SCIP_Bool* success /**< pointer to store whether the process was successful */
270  )
271 {
272  int i;
273  int j;
274  int lastsol; /* the worst solution possible to choose */
275  int nusedsols; /* number of solutions which will be chosen */
276 
277  SOLTUPLE* elem;
278  SCIP_SOL** sols;
279 
280  assert( success != NULL );
281 
282  /* initialization */
283  nusedsols = heurdata->nusedsols;
284  lastsol = SCIPgetNSols(scip);
285  sols = SCIPgetSols(scip);
286  assert(nusedsols < lastsol);
287 
288  i = 0;
289  *success = FALSE;
290 
291  /* perform at maximum 10 restarts and stop as soon as a new set of solutions is found */
292  while( !*success && i < 10 )
293  {
294  SCIP_Bool validtuple;
295 
296  validtuple = TRUE;
297  for( j = 0; j < nusedsols && validtuple; j++ )
298  {
299  int k;
300  k = SCIPrandomGetInt(heurdata->randnumgen, nusedsols-j-1, lastsol-1);
301 
302  /* ensure that the solution does not have a similar source as the others */
303  while( k >= nusedsols-j-1 && !solHasNewSource(sols, selection, j, k) )
304  k--;
305 
306  validtuple = (k >= nusedsols-j-1);
307  selection[j] = k;
308  lastsol = k;
309  }
310 
311  if( validtuple )
312  {
313  /* creates an object ready to be inserted into the hashtable */
314  SCIP_CALL( createSolTuple(scip, &elem, selection, nusedsols, heurdata) );
315 
316  /* check whether the randomized set is already in the hashtable, if not, insert it */
317  if( !SCIPhashtableExists(heurdata->hashtable, elem) )
318  {
319  SCIP_CALL( SCIPhashtableInsert(heurdata->hashtable, elem) );
320  *success = TRUE;
321  }
322  }
323  i++;
324  }
325 
326  return SCIP_OKAY;
327 }
328 
329 
330 /** determines the fixings for the CROSSOVER subproblem and checks whether enough fixings were found */
331 static
333  SCIP* scip, /**< original SCIP data structure */
334  SCIP_VAR** fixedvars, /**< array to store source SCIP variables whose copies should be fixed in the sub-SCIP */
335  SCIP_Real* fixedvals, /**< array to store solution values for variable fixing */
336  int* nfixedvars, /**< pointer to store the number of fixed variables */
337  int fixedvarssize, /**< size of the arrays to store fixing variables */
338  int* selection, /**< pool of solutions crossover will use */
339  SCIP_HEURDATA* heurdata, /**< primal heuristic data */
340  SCIP_Bool* success /**< pointer to store whether the problem was created successfully */
341  )
342 {
343  SCIP_VAR** vars; /* original scip variables */
344  SCIP_SOL** sols; /* pool of solutions */
345  SCIP_Real fixingrate; /* percentage of variables that are fixed */
346 
347  int nvars;
348  int nbinvars;
349  int nintvars;
350 
351  int i;
352  int j;
353 
354  sols = SCIPgetSols(scip);
355  assert(sols != NULL);
356  assert(fixedvars != NULL);
357  assert(fixedvals != NULL);
358 
359  /* get required data of the original problem */
360  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
361  assert(fixedvarssize >= nbinvars + nintvars);
362 
363  *nfixedvars = 0;
364 
365  /* go through discrete variables and collect potential fixings */
366  for( i = 0; i < nbinvars + nintvars; i++ )
367  {
368  SCIP_Real solval;
369  SCIP_Bool fixable;
370 
371  fixable = TRUE;
372  solval = SCIPgetSolVal(scip, sols[selection[0]], vars[i]);
373 
374  /* check, whether variable's value is identical for each selected solution */
375  for( j = 1; j < heurdata->nusedsols; j++ )
376  {
377  SCIP_Real varsolval;
378  varsolval = SCIPgetSolVal(scip, sols[selection[j]], vars[i]);
379  if( REALABS(solval - varsolval) > 0.5 )
380  {
381  fixable = FALSE;
382  break;
383  }
384  }
385 
386  /* original solval can be outside transformed global bounds */
387  fixable = fixable && SCIPvarGetLbGlobal(vars[i]) <= solval && solval <= SCIPvarGetUbGlobal(vars[i]);
388 
389  /* if solutions' values are equal, variable should be fixed in the subproblem */
390  if( fixable )
391  {
392  fixedvars[(*nfixedvars)] = vars[i];
393  fixedvals[(*nfixedvars)] = solval;
394  (*nfixedvars)++;
395  }
396  }
397 
398  fixingrate = (SCIP_Real)(*nfixedvars) / (SCIP_Real)(MAX(nbinvars + nintvars, 1));
399 
400  /* if all variables would be fixed or amount of fixed variables is insufficient,
401  * skip subproblem creation and abort immediately
402  */
403  *success = (*nfixedvars) < nbinvars + nintvars && fixingrate >= heurdata->minfixingrate;
404 
405  return SCIP_OKAY;
406 }
407 
408 /** creates a subproblem for subscip by fixing a number of variables */
409 static
411  SCIP* scip, /**< original SCIP data structure */
412  SCIP_VAR** fixedvars, /**< array to store source SCIP variables whose copies should be fixed in the sub-SCIP */
413  SCIP_Real* fixedvals, /**< array to store solution values for variable fixing */
414  int* nfixedvars, /**< pointer to store the number of fixed variables */
415  int fixedvarssize, /**< size of the arrays to store fixing variables */
416  int* selection, /**< pool of solutions crossover will use */
417  SCIP_HEURDATA* heurdata, /**< primal heuristic data */
418  SCIP_Bool* success /**< pointer to store whether the problem was created successfully */
419  )
420 {
421  SCIP_SOL** sols; /* array of all solutions found so far */
422  int nsols; /* number of all solutions found so far */
423  int nusedsols; /* number of solutions to use in crossover */
424  int i;
425 
426  /* get solutions' data */
427  nsols = SCIPgetNSols(scip);
428  sols = SCIPgetSols(scip);
429  nusedsols = heurdata->nusedsols;
430 
431  assert(nusedsols > 1);
432  assert(nsols >= nusedsols);
433 
434  /* use nusedsols best solutions if randomization is deactivated or there are only nusedsols solutions at hand
435  * or a good new solution was found since last call */
436  if( !heurdata->randomization || nsols == nusedsols || heurdata->prevlastsol != sols[nusedsols-1] )
437  {
438  SOLTUPLE* elem;
439  SCIP_HEUR* solheur;
440  SCIP_Longint solnodenum;
441  SCIP_Bool allsame;
442 
443  for( i = 0; i < nusedsols; i++ )
444  selection[i] = i;
445  SCIP_CALL( createSolTuple(scip, &elem, selection, nusedsols, heurdata) );
446 
447  solheur = SCIPsolGetHeur(sols[0]);
448  solnodenum = SCIPsolGetNodenum(sols[0]);
449  allsame = TRUE;
450 
451  /* check, whether all solutions have been found by the same heuristic at the same node; in this case we do not run
452  * crossover, since it would probably just optimize over the same space as the other heuristic
453  */
454  for( i = 1; i < nusedsols; i++ )
455  {
456  if( SCIPsolGetHeur(sols[i]) != solheur || SCIPsolGetNodenum(sols[i]) != solnodenum )
457  allsame = FALSE;
458  }
459  *success = !allsame && !SCIPhashtableExists(heurdata->hashtable, elem);
460 
461  /* check, whether solution tuple has already been tried */
462  if( !SCIPhashtableExists(heurdata->hashtable, elem) )
463  {
464  SCIP_CALL( SCIPhashtableInsert(heurdata->hashtable, elem) );
465  }
466 
467  /* if solution tuple has already been tried, randomization is allowed and enough solutions are at hand, try
468  * to randomize another tuple. E.g., this can happen if the last crossover solution was among the best ones */
469  if( !(*success) && heurdata->randomization && nsols > nusedsols )
470  {
471  SCIP_CALL( selectSolsRandomized(scip, selection, heurdata, success) );
472  }
473 
474  }
475  /* otherwise randomize the set of solutions */
476  else
477  {
478  SCIP_CALL( selectSolsRandomized(scip, selection, heurdata, success) );
479  }
480 
481  /* no acceptable solution tuple could be created */
482  if( !(*success) )
483  return SCIP_OKAY;
484 
485  /* set up the variables of the subproblem */
486  SCIP_CALL( fixVariables(scip, fixedvars, fixedvals, nfixedvars, fixedvarssize, selection, heurdata, success) );
487 
488  return SCIP_OKAY;
489 }
490 
491 
492 /** creates a new solution for the original problem by copying the solution of the subproblem */
493 static
495  SCIP* scip, /**< original SCIP data structure */
496  SCIP* subscip, /**< SCIP structure of the subproblem */
497  SCIP_VAR** subvars, /**< the variables of the subproblem */
498  SCIP_HEUR* heur, /**< crossover heuristic structure */
499  SCIP_SOL* subsol, /**< solution of the subproblem */
500  int* solindex, /**< index of the solution */
501  SCIP_Bool* success /**< used to store whether new solution was found or not */
502  )
503 {
504  SCIP_VAR** vars; /* the original problem's variables */
505  int nvars;
506  SCIP_SOL* newsol; /* solution to be created for the original problem */
507  SCIP_Real* subsolvals; /* solution values of the subproblem */
508 
509  assert(scip != NULL);
510  assert(subscip != NULL);
511  assert(subvars != NULL);
512  assert(subsol != NULL);
513 
514  /* get variables' data */
515  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
516  /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
517  * since constraint copying may have required the copy of variables that are fixed in the main SCIP */
518  assert(nvars <= SCIPgetNOrigVars(subscip));
519 
520  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
521 
522  /* copy the solution */
523  SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
524 
525  /* create new solution for the original problem */
526  SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
527  SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
528  *solindex = SCIPsolGetIndex(newsol);
529 
530  /* try to add new solution to scip and free it immediately */
531  SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, FALSE, TRUE, TRUE, TRUE, success) );
532 
533  SCIPfreeBufferArray(scip, &subsolvals);
534 
535  return SCIP_OKAY;
536 }
537 
538 /** updates heurdata after a run of crossover */
539 static
541  SCIP* scip, /**< original SCIP data structure */
542  SCIP_HEURDATA* heurdata /**< primal heuristic data */
543  )
544 {
545  /* increase number of failures, calculate next node at which crossover should be called and update actual solutions */
546  heurdata->nfailures++;
547  heurdata->nextnodenumber = (heurdata->nfailures <= 25
548  ? SCIPgetNNodes(scip) + 100*(2LL << heurdata->nfailures) /*lint !e703*/
549  : SCIP_LONGINT_MAX);
550 }
551 
552 /* ---------------- Callback methods of event handler ---------------- */
553 
554 /* exec the event handler
555  *
556  * we interrupt the solution process
557  */
558 static
559 SCIP_DECL_EVENTEXEC(eventExecCrossover)
560 {
561  SCIP_HEURDATA* heurdata;
562 
563  assert(eventhdlr != NULL);
564  assert(eventdata != NULL);
565  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
566  assert(event != NULL);
567  assert(SCIPeventGetType(event) & SCIP_EVENTTYPE_LPSOLVED);
568 
569  heurdata = (SCIP_HEURDATA*)eventdata;
570  assert(heurdata != NULL);
571 
572  /* interrupt solution process of sub-SCIP */
573  if( SCIPgetNLPs(scip) > heurdata->lplimfac * heurdata->nodelimit )
574  {
575  SCIPdebugMsg(scip, "interrupt after %" SCIP_LONGINT_FORMAT " LPs\n", SCIPgetNLPs(scip));
577  }
578 
579  return SCIP_OKAY;
580 }
581 
582 /*
583  * Callback methods of primal heuristic
584  */
585 
586 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
587 static
588 SCIP_DECL_HEURCOPY(heurCopyCrossover)
589 { /*lint --e{715}*/
590  assert(scip != NULL);
591  assert(heur != NULL);
592  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
593 
594  /* call inclusion method of primal heuristic */
596 
597  return SCIP_OKAY;
598 }
599 
600 /** setup and solve the subproblem and catch the return code */
601 static
603  SCIP* scip, /**< SCIP data structure */
604  SCIP* subscip, /**< sub-SCIP data structure */
605  SCIP_HEUR* heur, /**< mutation heuristic */
606  SCIP_HEURDATA* heurdata, /**< heuristics data */
607  SCIP_VAR** vars, /**< SCIP variables */
608  SCIP_VAR** fixedvars, /**< array to store the variables that should be fixed in the subproblem */
609  SCIP_Real* fixedvals, /**< array to store the fixing values to fix variables in the subproblem */
610  SCIP_Longint nstallnodes, /**< node limit for the subproblem */
611  SCIP_RESULT* result, /**< pointer to store the result */
612  int* selection, /**< pool of solutions crossover uses */
613  int nvars, /**< number of original problem's variables */
614  int nfixedvars, /**< the number of variables that should be fixed */
615  int nusedsols /**< number of solutions which will be chosen */
616  )
617 {
618  SCIP_EVENTHDLR* eventhdlr; /* event handler for LP events */
619  SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
620  SCIP_VAR** subvars; /* subproblem's variables */
621  SCIP_Real cutoff; /* objective cutoff for the subproblem */
622  SCIP_Real upperbound;
623  SCIP_Bool success;
624  int i;
625 
626  assert(scip != NULL);
627  assert(subscip != NULL);
628  assert(heur != NULL);
629  assert(heurdata != NULL);
630 
631  /* create the variable mapping hash map */
632  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), nvars) );
633  success = FALSE;
634 
635  /* create a copy of the transformed problem to be used by the heuristic */
636  SCIP_CALL( SCIPcopyLargeNeighborhoodSearch(scip, subscip, varmapfw, "crossover", fixedvars, fixedvals, nfixedvars,
637  heurdata->uselprows, heurdata->copycuts, &success, NULL) );
638 
639  eventhdlr = NULL;
640  /* create event handler for LP events */
641  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecCrossover, NULL) );
642  if( eventhdlr == NULL )
643  {
644  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
645  return SCIP_PLUGINNOTFOUND;
646  }
647 
648  /* store copied variables in the order in which they appear in the main SCIP */
649  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
650  for( i = 0; i < nvars; i++ )
651  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
652 
653  /* free hash map */
654  SCIPhashmapFree(&varmapfw);
655 
656  /* do not abort subproblem on CTRL-C */
657  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
658 
659 #ifdef SCIP_DEBUG
660  /* for debugging, enable full output */
661  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
662  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
663 #else
664  /* disable statistic timing inside sub SCIP and output to console */
665  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
666  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
667 #endif
668 
669  /* check whether there is enough time and memory left */
670  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", heurdata->bestsollimit) );
671 
672  /* set limits for the subproblem */
673  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
674  heurdata->nodelimit = nstallnodes;
675  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nstallnodes) );
676 
677  /* forbid recursive call of heuristics and separators solving subMIPs */
678  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
679 
680  /* disable cutting plane separation */
682 
683  /* disable expensive presolving */
685 
686  /* use best estimate node selection */
687  if( SCIPfindNodesel(subscip, "estimate") != NULL && !SCIPisParamFixed(subscip, "nodeselection/estimate/stdpriority") )
688  {
689  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
690  }
691 
692  /* activate uct node selection at the top of the tree */
693  if( heurdata->useuct && SCIPfindNodesel(subscip, "uct") != NULL && !SCIPisParamFixed(subscip, "nodeselection/uct/stdpriority") )
694  {
695  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/uct/stdpriority", INT_MAX/2) );
696  }
697 
698  /* use inference branching */
699  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
700  {
701  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
702  }
703 
704  /* enable conflict analysis, disable analysis of boundexceeding LPs, and restrict conflict pool */
705  if( !SCIPisParamFixed(subscip, "conflict/enable") )
706  {
707  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/enable", TRUE) );
708  }
709  if( !SCIPisParamFixed(subscip, "conflict/useboundlp") )
710  {
711  SCIP_CALL( SCIPsetCharParam(subscip, "conflict/useboundlp", 'o') );
712  }
713  if( !SCIPisParamFixed(subscip, "conflict/maxstoresize") )
714  {
715  SCIP_CALL( SCIPsetIntParam(subscip, "conflict/maxstoresize", 100) );
716  }
717 
718  /* speed up sub-SCIP by not checking dual LP feasibility */
719  SCIP_CALL( SCIPsetBoolParam(subscip, "lp/checkdualfeas", FALSE) );
720 
721  /* employ a limit on the number of enforcement rounds in the quadratic constraint handler; this fixes the issue that
722  * sometimes the quadratic constraint handler needs hundreds or thousands of enforcement rounds to determine the
723  * feasibility status of a single node without fractional branching candidates by separation (namely for uflquad
724  * instances); however, the solution status of the sub-SCIP might get corrupted by this; hence no deductions shall be
725  * made for the original SCIP
726  */
727  if( SCIPfindConshdlr(subscip, "quadratic") != NULL && !SCIPisParamFixed(subscip, "constraints/quadratic/enfolplimit") )
728  {
729  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/quadratic/enfolplimit", 500) );
730  }
731 
732  /* add an objective cutoff */
733  assert(!SCIPisInfinity(scip, SCIPgetUpperbound(scip)));
734 
735  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
736  if( !SCIPisInfinity(scip,-1.0*SCIPgetLowerbound(scip)) )
737  {
738  cutoff = (1-heurdata->minimprove)*SCIPgetUpperbound(scip) + heurdata->minimprove*SCIPgetLowerbound(scip);
739  }
740  else
741  {
742  if( SCIPgetUpperbound ( scip ) >= 0 )
743  cutoff = ( 1 - heurdata->minimprove ) * SCIPgetUpperbound ( scip );
744  else
745  cutoff = ( 1 + heurdata->minimprove ) * SCIPgetUpperbound ( scip );
746  }
747  cutoff = MIN(upperbound, cutoff );
748  SCIP_CALL( SCIPsetObjlimit(subscip, cutoff) );
749 
750  /* permute the subproblem to increase diversification */
751  if( heurdata->permute )
752  {
754  }
755 
756  /* catch LP events of sub-SCIP */
757  SCIP_CALL( SCIPtransformProb(subscip) );
758  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
759 
760  /* this code can be enabled whenever the subproblem should be written out */
761 #ifdef SCIP_DISABLED_CODE
762  SCIPdebug( SCIP_CALL( SCIPwriteOrigProblem(subscip, "crossoverprob.cip", "cip", FALSE) ) );
763 #endif
764  /* solve the subproblem */
765  SCIPdebugMsg(scip, "Solve Crossover subMIP\n");
766 
767  /* Errors in solving the subproblem should not kill the overall solving process.
768  * Hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop. */
769  SCIP_CALL_ABORT( SCIPsolve(subscip) );
770 
771  /* drop LP events of sub-SCIP */
772  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
773 
774  /* print solving statistics of subproblem if we are in SCIP's debug mode */
775  SCIPdebug( SCIP_CALL( SCIPprintStatistics(subscip, NULL) ) );
776 
777  heurdata->usednodes += SCIPgetNNodes(subscip);
778 
779  /* merge histories of the subscip-variables to the SCIP variables. */
780  SCIP_CALL( SCIPmergeVariableStatistics(subscip, scip, subvars, vars, nvars) );
781  SCIPdebugMsg(scip, "Transferring variable histories complete\n");
782 
783  /* check, whether a solution was found */
784  if( SCIPgetNSols(subscip) > 0 )
785  {
786  SCIP_SOL** subsols;
787  int nsubsols;
788  int solindex; /* index of the solution created by crossover */
789 
790  /* check, whether a solution was found;
791  * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted */
792  nsubsols = SCIPgetNSols(subscip);
793  subsols = SCIPgetSols(subscip);
794  success = FALSE;
795  solindex = -1;
796  for( i = 0; i < nsubsols && !success; ++i )
797  {
798  SCIP_CALL( createNewSol(scip, subscip, subvars, heur, subsols[i], &solindex, &success) );
799  }
800 
801  if( success )
802  {
803  int tmp;
804 
805  assert(solindex != -1);
806 
807  *result = SCIP_FOUNDSOL;
808 
809  /* insert all crossings of the new solution and (nusedsols-1) of its parents into the hashtable
810  * in order to avoid incest ;)
811  */
812  for( i = 0; i < nusedsols; i++ )
813  {
814  SOLTUPLE* elem;
815  tmp = selection[i];
816  selection[i] = solindex;
817 
818  SCIP_CALL( createSolTuple(scip, &elem, selection, nusedsols, heurdata) );
819  SCIP_CALL( SCIPhashtableInsert(heurdata->hashtable, elem) );
820  selection[i] = tmp;
821  }
822 
823  /* if solution was among the best ones, crossover should not be called until another good solution was found */
824  if( !heurdata->randomization )
825  {
826  heurdata->prevbestsol = SCIPgetBestSol(scip);
827  heurdata->prevlastsol = SCIPgetSols(scip)[heurdata->nusedsols-1];
828  }
829  }
830 
831  /* if solution is not better than incumbent or could not be added to problem => run is counted as a failure */
832  if( !success || solindex != SCIPsolGetIndex(SCIPgetBestSol(scip)) )
833  updateFailureStatistic(scip, heurdata);
834  }
835  else
836  {
837  /* if no new solution was found, run was a failure */
838  updateFailureStatistic(scip, heurdata);
839  }
840 
841  SCIPfreeBufferArray(scip, &subvars);
842 
843  return SCIP_OKAY;
844 }
845 
846 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
847 static
848 SCIP_DECL_HEURFREE(heurFreeCrossover)
849 { /*lint --e{715}*/
850  SCIP_HEURDATA* heurdata;
851 
852  assert(heur != NULL);
853  assert(scip != NULL);
854 
855  /* get heuristic data */
856  heurdata = SCIPheurGetData(heur);
857  assert(heurdata != NULL);
858 
859  /* free heuristic data */
860  SCIPfreeBlockMemory(scip, &heurdata);
861  SCIPheurSetData(heur, NULL);
862 
863  return SCIP_OKAY;
864 }
865 
866 /** initialization method of primal heuristic (called after problem was transformed) */
867 static
868 SCIP_DECL_HEURINIT(heurInitCrossover)
869 { /*lint --e{715}*/
870  SCIP_HEURDATA* heurdata;
871 
872  assert(heur != NULL);
873  assert(scip != NULL);
874 
875  /* get heuristic's data */
876  heurdata = SCIPheurGetData(heur);
877  assert(heurdata != NULL);
878 
879  /* initialize data */
880  heurdata->usednodes = 0;
881  heurdata->prevlastsol = NULL;
882  heurdata->prevbestsol = NULL;
883  heurdata->lasttuple = NULL;
884  heurdata->nfailures = 0;
885  heurdata->prevnsols = 0;
886  heurdata->nextnodenumber = 0;
887 
888  /* create random number generator */
889  SCIP_CALL( SCIPcreateRandom(scip, &heurdata->randnumgen, DEFAULT_RANDSEED) );
890 
891  /* initialize hash table */
892  SCIP_CALL( SCIPhashtableCreate(&heurdata->hashtable, SCIPblkmem(scip), HASHSIZE_SOLS,
893  hashGetKeySols, hashKeyEqSols, hashKeyValSols, NULL) );
894  assert(heurdata->hashtable != NULL);
895 
896  return SCIP_OKAY;
897 }
898 
899 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
900 static
901 SCIP_DECL_HEUREXIT(heurExitCrossover)
902 { /*lint --e{715}*/
903  SCIP_HEURDATA* heurdata;
904  SOLTUPLE* soltuple;
905 
906  assert(heur != NULL);
907  assert(scip != NULL);
908 
909  /* get heuristic data */
910  heurdata = SCIPheurGetData(heur);
911  assert(heurdata != NULL);
912  soltuple = heurdata->lasttuple;
913 
914  /* free all soltuples iteratively */
915  while( soltuple != NULL )
916  {
917  SOLTUPLE* tmp;
918  tmp = soltuple->prev;
919  SCIPfreeBlockMemoryArray(scip, &soltuple->indices, soltuple->size);
920  SCIPfreeBlockMemory(scip, &soltuple);
921  soltuple = tmp;
922  }
923 
924  /* free random number generator */
925  SCIPfreeRandom(scip, &heurdata->randnumgen);
926 
927  /* free hash table */
928  assert(heurdata->hashtable != NULL);
929  SCIPhashtableFree(&heurdata->hashtable);
930 
931  return SCIP_OKAY;
932 }
933 
934 /** execution method of primal heuristic */
935 static
936 SCIP_DECL_HEUREXEC(heurExecCrossover)
937 { /*lint --e{715}*/
938  SCIP* subscip; /* the subproblem created by crossover */
939  SCIP_HEURDATA* heurdata; /* primal heuristic data */
940  SCIP_VAR** vars; /* original problem's variables */
941  SCIP_VAR** fixedvars;
942  SCIP_SOL** sols;
943  SCIP_RETCODE retcode;
944  SCIP_Longint nstallnodes; /* node limit for the subproblem */
945  SCIP_Bool success;
946  SCIP_Real* fixedvals;
947  int* selection; /* pool of solutions crossover uses */
948  int nvars; /* number of original problem's variables */
949  int nbinvars;
950  int nintvars;
951  int nusedsols;
952  int nfixedvars;
953 
954  assert(heur != NULL);
955  assert(scip != NULL);
956  assert(result != NULL);
957 
958  /* get heuristic's data */
959  heurdata = SCIPheurGetData(heur);
960  assert(heurdata != NULL);
961  nusedsols = heurdata->nusedsols;
962 
963  *result = SCIP_DELAYED;
964 
965  /* only call heuristic, if enough solutions are at hand */
966  if( SCIPgetNSols(scip) < nusedsols )
967  return SCIP_OKAY;
968 
969  sols = SCIPgetSols(scip);
970  assert(sols != NULL);
971 
972  /* if one good solution was found, heuristic should not be delayed any longer */
973  if( sols[nusedsols-1] != heurdata->prevlastsol )
974  {
975  heurdata->nextnodenumber = SCIPgetNNodes(scip);
976  if( sols[0] != heurdata->prevbestsol )
977  heurdata->nfailures = 0;
978  }
979  /* in nonrandomized mode: only recall heuristic, if at least one new good solution was found in the meantime */
980  else if( !heurdata->randomization )
981  return SCIP_OKAY;
982 
983  /* if heuristic should be delayed, wait until certain number of nodes is reached */
984  if( SCIPgetNNodes(scip) < heurdata->nextnodenumber )
985  return SCIP_OKAY;
986 
987  /* only call heuristic, if enough nodes were processed since last incumbent */
988  if( SCIPgetNNodes(scip) - SCIPgetSolNodenum(scip, SCIPgetBestSol(scip)) < heurdata->nwaitingnodes
989  && (SCIPgetDepth(scip) > 0 || !heurdata->dontwaitatroot) )
990  return SCIP_OKAY;
991 
992  *result = SCIP_DIDNOTRUN;
993 
994  /* calculate the maximal number of branching nodes until heuristic is aborted */
995  nstallnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
996 
997  /* reward Crossover if it succeeded often */
998  nstallnodes = (SCIP_Longint)
999  (nstallnodes * (1.0 + 2.0*(SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur)+1.0)));
1000 
1001  /* count the setup costs for the sub-MIP as 100 nodes */
1002  nstallnodes -= 100 * SCIPheurGetNCalls(heur);
1003  nstallnodes += heurdata->nodesofs;
1004 
1005  /* determine the node limit for the current process */
1006  nstallnodes -= heurdata->usednodes;
1007  nstallnodes = MIN(nstallnodes, heurdata->maxnodes);
1008 
1009  /* check whether we have enough nodes left to call subproblem solving */
1010  if( nstallnodes < heurdata->minnodes )
1011  return SCIP_OKAY;
1012 
1013  /* consider time and memory limits of the main SCIP */
1014  SCIP_CALL( SCIPcheckCopyLimits(scip, &success) );
1015 
1016  if( !success )
1017  return SCIP_OKAY;
1018 
1019  if( SCIPisStopped(scip) )
1020  return SCIP_OKAY;
1021 
1022  /* get variable information */
1023  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
1024  assert(nvars > 0);
1025 
1026  /* check whether discrete variables are available */
1027  if( nbinvars == 0 && nintvars == 0 )
1028  return SCIP_OKAY;
1029 
1030  /* allocate necessary buffer storage for selection of variable fixings */
1031  SCIP_CALL( SCIPallocBufferArray(scip, &selection, nusedsols) );
1032  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvars, nbinvars + nintvars) );
1033  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvals, nbinvars + nintvars) );
1034 
1035  success = FALSE;
1036  nfixedvars = 0;
1037  /* determine fixings of variables with same value in a certain set of solutions */
1038  SCIP_CALL( determineVariableFixings(scip, fixedvars, fixedvals, &nfixedvars, nbinvars + nintvars, selection, heurdata, &success) );
1039 
1040  heurdata->prevbestsol = SCIPgetBestSol(scip);
1041  heurdata->prevlastsol = sols[heurdata->nusedsols-1];
1042 
1043  /* if creation of sub-SCIP was aborted (e.g. due to number of fixings), free sub-SCIP and abort */
1044  if( !success )
1045  {
1046  /* this run will be counted as a failure since no new solution tuple could be generated or the neighborhood of the
1047  * solution was not fruitful in the sense that it was too big
1048  */
1049  updateFailureStatistic(scip, heurdata);
1050 
1051  goto TERMINATE;
1052  }
1053 
1054  *result = SCIP_DIDNOTFIND;
1055  /* initializing the subproblem */
1056  SCIP_CALL( SCIPcreate(&subscip) );
1057 
1058  /* setup and solve the subproblem and catch the return code */
1059  retcode = setupAndSolveSubscipCrossover(scip, subscip, heur, heurdata, vars,
1060  fixedvars, fixedvals, nstallnodes, result, selection, nvars, nfixedvars, nusedsols);
1061 
1062  /* free the subscip in any case */
1063  SCIP_CALL( SCIPfree(&subscip) );
1064  SCIP_CALL( retcode );
1065 
1066 TERMINATE:
1067  /* free buffer storage for variable fixings */
1068  SCIPfreeBufferArray(scip, &fixedvals);
1069  SCIPfreeBufferArray(scip, &fixedvars);
1070  SCIPfreeBufferArray(scip, &selection);
1071 
1072  return SCIP_OKAY;
1073 }
1074 
1075 /*
1076  * primal heuristic specific interface methods
1077  */
1078 
1079 /** creates the crossover primal heuristic and includes it in SCIP */
1081  SCIP* scip /**< SCIP data structure */
1082  )
1083 {
1084  SCIP_HEURDATA* heurdata;
1085  SCIP_HEUR* heur;
1086 
1087  /* create Crossover primal heuristic data */
1088  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
1089 
1090  /* include primal heuristic */
1091  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
1093  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecCrossover, heurdata) );
1094 
1095  assert(heur != NULL);
1096 
1097  /* set non-NULL pointers to callback methods */
1098  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyCrossover) );
1099  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeCrossover) );
1100  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitCrossover) );
1101  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitCrossover) );
1102 
1103  /* add crossover primal heuristic parameters */
1104 
1105  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
1106  "number of nodes added to the contingent of the total nodes",
1107  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1108 
1109  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
1110  "maximum number of nodes to regard in the subproblem",
1111  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1112 
1113  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minnodes",
1114  "minimum number of nodes required to start the subproblem",
1115  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1116 
1117  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nusedsols",
1118  "number of solutions to be taken into account",
1119  &heurdata->nusedsols, FALSE, DEFAULT_NUSEDSOLS, 2, INT_MAX, NULL, NULL) );
1120 
1121  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nwaitingnodes",
1122  "number of nodes without incumbent change that heuristic should wait",
1123  &heurdata->nwaitingnodes, TRUE, DEFAULT_NWAITINGNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1124 
1125  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
1126  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
1127  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
1128 
1129  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minfixingrate",
1130  "minimum percentage of integer variables that have to be fixed",
1131  &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, 0.0, 1.0, NULL, NULL) );
1132 
1133  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
1134  "factor by which Crossover should at least improve the incumbent",
1135  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
1136 
1137  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/lplimfac",
1138  "factor by which the limit on the number of LP depends on the node limit",
1139  &heurdata->lplimfac, TRUE, DEFAULT_LPLIMFAC, 1.0, SCIP_REAL_MAX, NULL, NULL) );
1140 
1141  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/randomization",
1142  "should the choice which sols to take be randomized?",
1143  &heurdata->randomization, TRUE, DEFAULT_RANDOMIZATION, NULL, NULL) );
1144 
1145  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/dontwaitatroot",
1146  "should the nwaitingnodes parameter be ignored at the root node?",
1147  &heurdata->dontwaitatroot, TRUE, DEFAULT_DONTWAITATROOT, NULL, NULL) );
1148 
1149  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
1150  "should subproblem be created out of the rows in the LP rows?",
1151  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
1152 
1153  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/copycuts",
1154  "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
1155  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
1156 
1157  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/permute",
1158  "should the subproblem be permuted to increase diversification?",
1159  &heurdata->permute, TRUE, DEFAULT_PERMUTE, NULL, NULL) );
1160 
1161  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/bestsollimit",
1162  "limit on number of improving incumbent solutions in sub-CIP",
1163  &heurdata->bestsollimit, FALSE, DEFAULT_BESTSOLLIMIT, -1, INT_MAX, NULL, NULL) );
1164 
1165  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useuct",
1166  "should uct node selection be used at the beginning of the search?",
1167  &heurdata->useuct, TRUE, DEFAULT_USEUCT, NULL, NULL) );
1168  return SCIP_OKAY;
1169 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
Definition: scip.c:48620
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip.h:22604
#define SCIP_EVENTTYPE_LPSOLVED
Definition: type_event.h:84
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:5158
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip.h:22587
static SCIP_DECL_HASHKEYEQ(hashKeyEqSols)
#define HEUR_TIMING
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2265
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:6604
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17276
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1344
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed)
Definition: scip.c:48602
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip.c:8177
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip.c:12246
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip.c:8611
static SCIP_DECL_HEURCOPY(heurCopyCrossover)
#define DEFAULT_NODESOFS
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, int *solindex, SCIP_Bool *success)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip.c:11680
SCIP_SOL ** SCIPgetSols(SCIP *scip)
Definition: scip.c:39826
#define FALSE
Definition: def.h:64
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2793
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:278
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.c:4293
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip.c:4192
#define DEFAULT_RANDOMIZATION
#define DEFAULT_NUSEDSOLS
#define TRUE
Definition: def.h:63
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPwriteOrigProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
Definition: scip.c:10426
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:5132
static unsigned int calculateHashKey(int *indices, int size)
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip.c:9269
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip.h:22602
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.c:8084
#define HEUR_FREQOFS
int SCIPrandomGetInt(SCIP_RANDNUMGEN *randnumgen, int minrandval, int maxrandval)
Definition: misc.c:9366
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2931
#define DEFAULT_MAXNODES
#define SCIP_LONGINT_MAX
Definition: def.h:135
static SCIP_DECL_HASHGETKEY(hashGetKeySols)
static SCIP_DECL_EVENTEXEC(eventExecCrossover)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:22632
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip.c:748
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1119
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip.h:22585
#define SCIPdebugMsg
Definition: scip.h:455
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4265
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
Definition: scip.c:45645
static SCIP_DECL_HEURFREE(heurFreeCrossover)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:2014
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17286
#define HEUR_NAME
static SCIP_DECL_HEUREXEC(heurExecCrossover)
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip.c:16109
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1198
LNS heuristic that tries to combine several feasible solutions.
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip.c:4401
#define DEFAULT_NODESQUOT
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip.c:8145
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:38942
#define DEFAULT_USEUCT
#define DEFAULT_COPYCUTS
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip.c:4630
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:46725
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:155
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2826
SCIP_RETCODE SCIPmergeVariableStatistics(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR **sourcevars, SCIP_VAR **targetvars, int nvars)
Definition: scip.c:2428
SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2548
#define REALABS(x)
Definition: def.h:173
#define SCIP_CALL(x)
Definition: def.h:350
SCIP_Real SCIPgetLowerbound(SCIP *scip)
Definition: scip.c:43271
static SCIP_RETCODE setupAndSolveSubscipCrossover(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, SCIP_VAR **vars, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, SCIP_Longint nstallnodes, SCIP_RESULT *result, int *selection, int nvars, int nfixedvars, int nusedsols)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1324
static SCIP_DECL_HEUREXIT(heurExitCrossover)
static SCIP_RETCODE createSolTuple(SCIP *scip, SOLTUPLE **elem, int *indices, int size, SCIP_HEURDATA *heurdata)
#define EVENTHDLR_DESC
#define HEUR_DISPCHAR
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:22620
public data structures and miscellaneous methods
static SCIP_RETCODE selectSolsRandomized(SCIP *scip, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
SCIP_RETCODE SCIPpermuteProb(SCIP *scip, unsigned int randseed, SCIP_Bool permuteconss, SCIP_Bool permutebinvars, SCIP_Bool permuteintvars, SCIP_Bool permuteimplvars, SCIP_Bool permutecontvars)
Definition: scip.c:10599
#define SCIP_Bool
Definition: def.h:61
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip.c:41152
#define HEUR_FREQ
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:959
SCIP_Longint SCIPsolGetNodenum(SCIP_SOL *sol)
Definition: sol.c:2528
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip.c:11240
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:43039
#define HASHSIZE_SOLS
#define DEFAULT_DONTWAITATROOT
#define DEFAULT_BESTSOLLIMIT
struct SolTuple SOLTUPLE
#define MAX(x, y)
Definition: tclique_def.h:75
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: scip.c:40788
#define HEUR_MAXDEPTH
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip.c:4688
unsigned int SCIPinitializeRandomSeed(SCIP *scip, int initialseedvalue)
Definition: scip.c:25899
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip.c:41186
static SCIP_DECL_HEURINIT(heurInitCrossover)
int SCIPgetNSols(SCIP *scip)
Definition: scip.c:39777
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:116
SCIP_RETCODE SCIPincludeHeurCrossover(SCIP *scip)
#define DEFAULT_LPLIMFAC
static SCIP_RETCODE fixVariables(SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
Constraint handler for linear constraints in their most general form, .
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:47033
static SCIP_DECL_HASHKEYVAL(hashKeyValSols)
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
Definition: scip.c:4862
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:2064
#define SCIP_REAL_MAX
Definition: def.h:150
#define DEFAULT_USELPROWS
#define HEUR_PRIORITY
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip.c:39876
#define HEUR_USESSUBSCIP
#define DEFAULT_PERMUTE
#define HEUR_DESC
#define DEFAULT_MINNODES
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip.c:8161
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip.c:8957
SCIP_RETCODE SCIPcopyLargeNeighborhoodSearch(SCIP *sourcescip, SCIP *subscip, SCIP_HASHMAP *varmap, const char *suffix, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool uselprows, SCIP_Bool copycuts, SCIP_Bool *success, SCIP_Bool *valid)
Definition: heuristics.c:903
#define SCIP_Real
Definition: def.h:149
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1145
#define DEFAULT_NWAITINGNODES
static SCIP_Bool solHasNewSource(SCIP_SOL **sols, int *selection, int selectionsize, int newsol)
#define EVENTHDLR_NAME
#define SCIP_Longint
Definition: def.h:134
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip.c:4156
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2377
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:38807
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip.c:13929
#define DEFAULT_MINIMPROVE
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip.c:8129
SCIP_Real SCIPsumepsilon(SCIP *scip)
Definition: scip.c:46423
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip.c:17318
SCIP_Real SCIPgetUpperbound(SCIP *scip)
Definition: scip.c:43420
static void sortArray(int *a, int size)
#define SCIP_CALL_ABORT(x)
Definition: def.h:329
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1109
#define DEFAULT_RANDSEED
SCIP_Longint SCIPgetNNodes(SCIP *scip)
Definition: scip.c:42127
SCIP_Longint SCIPgetNLPs(SCIP *scip)
Definition: scip.c:42308
#define DEFAULT_MINFIXINGRATE
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip.c:38905
default SCIP plugins
static void updateFailureStatistic(SCIP *scip, SCIP_HEURDATA *heurdata)
int SCIPsolGetIndex(SCIP_SOL *sol)
Definition: sol.c:2579
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.c:4321
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip.c:5083
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip.c:4746
SCIP callable library.
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.c:4239
static SCIP_RETCODE determineVariableFixings(SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip.c:780
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:37872
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:39201