Scippy

SCIP

Solving Constraint Integer Programs

heur_mutation.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_mutation.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief LNS heuristic that tries to randomly mutate the incumbent solution
19  * @author Timo Berthold
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "blockmemshell/memory.h"
25 #include "scip/heuristics.h"
26 #include "scip/heur_mutation.h"
27 #include "scip/pub_heur.h"
28 #include "scip/pub_message.h"
29 #include "scip/pub_misc.h"
30 #include "scip/pub_sol.h"
31 #include "scip/pub_var.h"
32 #include "scip/scip_branch.h"
33 #include "scip/scip_cons.h"
34 #include "scip/scip_copy.h"
35 #include "scip/scip_general.h"
36 #include "scip/scip_heur.h"
37 #include "scip/scip_mem.h"
38 #include "scip/scip_message.h"
39 #include "scip/scip_nodesel.h"
40 #include "scip/scip_numerics.h"
41 #include "scip/scip_param.h"
42 #include "scip/scip_prob.h"
43 #include "scip/scip_randnumgen.h"
44 #include "scip/scip_sol.h"
45 #include "scip/scip_solve.h"
46 #include "scip/scip_solvingstats.h"
47 #include <string.h>
48 
49 #define HEUR_NAME "mutation"
50 #define HEUR_DESC "mutation heuristic randomly fixing variables"
51 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_LNS
52 #define HEUR_PRIORITY -1103000
53 #define HEUR_FREQ -1
54 #define HEUR_FREQOFS 8
55 #define HEUR_MAXDEPTH -1
56 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
57 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
58 
59 #define DEFAULT_NODESOFS 500 /**< number of nodes added to the contingent of the total nodes */
60 #define DEFAULT_MAXNODES 5000 /**< maximum number of nodes to regard in the subproblem */
61 #define DEFAULT_MINIMPROVE 0.01 /**< factor by which Mutation should at least improve the incumbent */
62 #define DEFAULT_MINNODES 500 /**< minimum number of nodes to regard in the subproblem */
63 #define DEFAULT_MINFIXINGRATE 0.8 /**< minimum percentage of integer variables that have to be fixed */
64 #define DEFAULT_NODESQUOT 0.1 /**< subproblem nodes in relation to nodes of the original problem */
65 #define DEFAULT_NWAITINGNODES 200 /**< number of nodes without incumbent change that heuristic should wait */
66 #define DEFAULT_USELPROWS FALSE /**< should subproblem be created out of the rows in the LP rows,
67  * otherwise, the copy constructors of the constraints handlers are used */
68 #define DEFAULT_COPYCUTS TRUE /**< if DEFAULT_USELPROWS is FALSE, then should all active cuts from the
69  * cutpool of the original scip be copied to constraints of the subscip */
70 #define DEFAULT_BESTSOLLIMIT -1 /**< limit on number of improving incumbent solutions in sub-CIP */
71 #define DEFAULT_USEUCT FALSE /**< should uct node selection be used at the beginning of the search? */
72 #define DEFAULT_RANDSEED 19 /**< initial random seed */
73 /*
74  * Data structures
75  */
76 
77 /** primal heuristic data */
78 struct SCIP_HeurData
79 {
80  int nodesofs; /**< number of nodes added to the contingent of the total nodes */
81  int maxnodes; /**< maximum number of nodes to regard in the subproblem */
82  int minnodes; /**< minimum number of nodes to regard in the subproblem */
83  SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
84  int nwaitingnodes; /**< number of nodes without incumbent change that heuristic should wait */
85  SCIP_Real minimprove; /**< factor by which Mutation should at least improve the incumbent */
86  SCIP_Longint usednodes; /**< nodes already used by Mutation in earlier calls */
87  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
88  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
89  SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
90  SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
91  * to constraints in subproblem?
92  */
93  int bestsollimit; /**< limit on number of improving incumbent solutions in sub-CIP */
94  SCIP_Bool useuct; /**< should uct node selection be used at the beginning of the search? */
95 };
96 
97 
98 /*
99  * Local methods
100  */
101 
102 /** determine variables and values which should be fixed in the mutation subproblem */
103 static
105  SCIP* scip, /**< original SCIP data structure */
106  SCIP_VAR** fixedvars, /**< array to store the variables that should be fixed in the subproblem */
107  SCIP_Real* fixedvals, /**< array to store the fixing values to fix variables in the subproblem */
108  int* nfixedvars, /**< pointer to store the number of variables that should be fixed */
109  SCIP_Real minfixingrate, /**< percentage of integer variables that have to be fixed */
110  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
111  SCIP_Bool* success /**< used to store whether the creation of the subproblem worked */
112  )
113 {
114  SCIP_VAR** vars; /* original scip variables */
115  SCIP_SOL* sol; /* pool of solutions */
116 
117  int nvars;
118  int nbinvars;
119  int nintvars;
120  int ndiscretevars;
121  int i;
122 
123  assert(fixedvars != NULL);
124  assert(fixedvals != NULL);
125 
126  /* get required data of the original problem */
127  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
128  sol = SCIPgetBestSol(scip);
129  assert(sol != NULL);
130 
131  /* compute the number of variables that should be fixed in the subproblem */
132  *nfixedvars = (int)(minfixingrate * (nbinvars + nintvars));
133 
134  /* avoid the two corner cases that no or all discrete variables should be fixed */
135  if( *nfixedvars == 0 || *nfixedvars == nbinvars + nintvars )
136  {
137  *success = FALSE;
138  return SCIP_OKAY;
139  }
140  assert(*nfixedvars < nbinvars + nintvars);
141 
142  ndiscretevars = nbinvars + nintvars;
143  /* copy the binary and integer variables into fixedvars */
144  BMScopyMemoryArray(fixedvars, vars, ndiscretevars);
145 
146  /* shuffle the array randomly */
147  SCIPrandomPermuteArray(randnumgen, (void **)fixedvars, 0, nbinvars + nintvars);
148 
149  *success = TRUE;
150  /* store the fixing values for the subset of variables that should be fixed */
151  for( i = 0; i < *nfixedvars; ++i )
152  {
153  /* fix all randomly marked variables */
154  SCIP_Real solval;
155  SCIP_Real lb;
156  SCIP_Real ub;
157 
158  solval = SCIPgetSolVal(scip, sol, fixedvars[i]);
159  lb = SCIPvarGetLbGlobal(fixedvars[i]);
160  ub = SCIPvarGetUbGlobal(fixedvars[i]);
161  assert(SCIPisLE(scip, lb, ub));
162 
163  /* due to dual reductions, it may happen that the solution value is not in
164  the variable's domain anymore */
165  if( SCIPisLT(scip, solval, lb) )
166  solval = lb;
167  else if( SCIPisGT(scip, solval, ub) )
168  solval = ub;
169 
170  /* we cannot fix to infinite solution values, better break in this case */
171  if( SCIPisInfinity(scip, REALABS(solval)) )
172  {
173  *success = FALSE;
174  break;
175  }
176 
177  /* store the possibly adjusted solution value as fixing value */
178  fixedvals[i] = solval;
179  }
180 
181  return SCIP_OKAY;
182 }
183 
184 /** setup and solve mutation sub-SCIP */
185 static
187  SCIP* scip, /**< SCIP data structure */
188  SCIP* subscip, /**< sub-SCIP data structure */
189  SCIP_HEUR* heur, /**< mutation heuristic */
190  SCIP_VAR** fixedvars, /**< array to store the variables that should be fixed in the subproblem */
191  SCIP_Real* fixedvals, /**< array to store the fixing values to fix variables in the subproblem */
192  int nfixedvars, /**< the number of variables that should be fixed */
193  SCIP_Longint nsubnodes, /**< node limit for the subproblem */
194  SCIP_RESULT* result /**< pointer to store the result */
195  )
196 {
197  SCIP_VAR** subvars; /* subproblem's variables */
198  SCIP_VAR** vars; /* original problem's variables */
199  SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
200  SCIP_HEURDATA* heurdata;
201  SCIP_Real cutoff; /* objective cutoff for the subproblem */
202  SCIP_Real upperbound;
203  int nvars; /* number of original problem's variables */
204  int i;
205  SCIP_Bool success;
206 
207  assert(scip != NULL);
208  assert(subscip != NULL);
209  assert(heur != NULL);
210  assert(fixedvars != NULL);
211  assert(fixedvals != NULL);
212 
213  heurdata = SCIPheurGetData(heur);
214  assert(heurdata != NULL);
215 
216  vars = SCIPgetVars(scip);
217  nvars = SCIPgetNVars(scip);
218 
219  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
220 
221  /* create the variable mapping hash map */
222  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), nvars) );
223 
224  /* create a problem copy as sub SCIP */
225  SCIP_CALL( SCIPcopyLargeNeighborhoodSearch(scip, subscip, varmapfw, "mutation", fixedvars, fixedvals, nfixedvars,
226  heurdata->uselprows, heurdata->copycuts, &success, NULL) );
227 
228  for( i = 0; i < nvars; i++ )
229  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
230 
231  /* free hash map */
232  SCIPhashmapFree(&varmapfw);
233 
234  /* do not abort subproblem on CTRL-C */
235  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
236 
237 #ifdef SCIP_DEBUG
238  /* for debugging, enable full output */
239  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
240  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
241 #else
242  /* disable statistic timing inside sub SCIP and output to console */
243  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
244  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
245 #endif
246 
247  /* set limits for the subproblem */
248  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
249  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nsubnodes) );
250  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", heurdata->bestsollimit) );
251 
252  /* forbid recursive call of heuristics and separators solving subMIPs */
253  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
254 
255  /* disable cutting plane separation */
257 
258  /* disable expensive presolving */
260 
261  /* use best estimate node selection */
262  if( SCIPfindNodesel(subscip, "estimate") != NULL && !SCIPisParamFixed(subscip, "nodeselection/estimate/stdpriority") )
263  {
264  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
265  }
266 
267  /* activate uct node selection at the top of the tree */
268  if( heurdata->useuct && SCIPfindNodesel(subscip, "uct") != NULL && !SCIPisParamFixed(subscip, "nodeselection/uct/stdpriority") )
269  {
270  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/uct/stdpriority", INT_MAX/2) );
271  }
272 
273  /* use inference branching */
274  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
275  {
276  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
277  }
278 
279  /* enable conflict analysis, disable analysis of boundexceeding LPs, and restrict conflict pool */
280  if( !SCIPisParamFixed(subscip, "conflict/enable") )
281  {
282  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/enable", TRUE) );
283  }
284  if( !SCIPisParamFixed(subscip, "conflict/useboundlp") )
285  {
286  SCIP_CALL( SCIPsetCharParam(subscip, "conflict/useboundlp", 'o') );
287  }
288  if( !SCIPisParamFixed(subscip, "conflict/maxstoresize") )
289  {
290  SCIP_CALL( SCIPsetIntParam(subscip, "conflict/maxstoresize", 100) );
291  }
292 
293  /* speed up sub-SCIP by not checking dual LP feasibility */
294  SCIP_CALL( SCIPsetBoolParam(subscip, "lp/checkdualfeas", FALSE) );
295 
296  /* employ a limit on the number of enforcement rounds in the quadratic constraint handlers; this fixes the issue that
297  * sometimes the quadratic constraint handler needs hundreds or thousands of enforcement rounds to determine the
298  * feasibility status of a single node without fractional branching candidates by separation (namely for uflquad
299  * instances); however, the solution status of the sub-SCIP might get corrupted by this; hence no decutions shall be
300  * made for the original SCIP
301  */
302  if( SCIPfindConshdlr(subscip, "quadratic") != NULL && !SCIPisParamFixed(subscip, "constraints/quadratic/enfolplimit") )
303  {
304  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/quadratic/enfolplimit", 10) );
305  }
306 
307  /* add an objective cutoff */
308  assert( !SCIPisInfinity(scip, SCIPgetUpperbound(scip)) );
309 
310  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
311  if( !SCIPisInfinity(scip, -1.0 * SCIPgetLowerbound(scip)) )
312  {
313  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip)
314  + heurdata->minimprove * SCIPgetLowerbound(scip);
315  }
316  else
317  {
318  if( SCIPgetUpperbound(scip) >= 0 )
319  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip);
320  else
321  cutoff = (1 + heurdata->minimprove) * SCIPgetUpperbound(scip);
322  }
323  cutoff = MIN(upperbound, cutoff);
324  SCIP_CALL(SCIPsetObjlimit(subscip, cutoff));
325 
326  /* solve the subproblem
327  *
328  * Errors in solving the subproblem should not kill the overall solving process
329  * Hence, the return code is caught but only in debug mode, SCIP will stop.
330  */
331  SCIPdebugMsg(scip, "Solve Mutation subMIP\n");
332  SCIP_CALL_ABORT( SCIPsolve(subscip) );
333 
334  /* transfer variable statistics from sub-SCIP */
335  SCIP_CALL( SCIPmergeVariableStatistics(subscip, scip, subvars, vars, nvars) );
336 
337  /* print solving statistics of subproblem if we are in SCIP's debug mode */
339 
340  heurdata->usednodes += SCIPgetNNodes(subscip);
341 
342  /* check, whether a solution was found;
343  * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted
344  */
345  SCIP_CALL( SCIPtranslateSubSols(scip, subscip, heur, subvars, &success, NULL) );
346  if( success )
347  *result = SCIP_FOUNDSOL;
348 
349  /* free subproblem */
350  SCIPfreeBufferArray(scip, &subvars);
351 
352  return SCIP_OKAY;
353 }
354 
355 
356 /*
357  * Callback methods of primal heuristic
358  */
359 
360 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
361 static
362 SCIP_DECL_HEURCOPY(heurCopyMutation)
363 { /*lint --e{715}*/
364  assert(scip != NULL);
365  assert(heur != NULL);
366  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
367 
368  /* call inclusion method of primal heuristic */
370 
371  return SCIP_OKAY;
372 }
373 
374 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
375 static
376 SCIP_DECL_HEURFREE(heurFreeMutation)
377 { /*lint --e{715}*/
378  SCIP_HEURDATA* heurdata;
379 
380  assert(heur != NULL);
381  assert(scip != NULL);
382 
383  /* get heuristic data */
384  heurdata = SCIPheurGetData(heur);
385  assert(heurdata != NULL);
386 
387  /* free heuristic data */
388  SCIPfreeBlockMemory(scip, &heurdata);
389  SCIPheurSetData(heur, NULL);
390 
391  return SCIP_OKAY;
392 }
393 
394 /** initialization method of primal heuristic (called after problem was transformed) */
395 static
396 SCIP_DECL_HEURINIT(heurInitMutation)
397 { /*lint --e{715}*/
398  SCIP_HEURDATA* heurdata;
399 
400  assert(heur != NULL);
401  assert(scip != NULL);
402 
403  /* get heuristic's data */
404  heurdata = SCIPheurGetData(heur);
405  assert(heurdata != NULL);
406 
407  /* initialize data */
408  heurdata->usednodes = 0;
409 
410  /* create random number generator */
411  SCIP_CALL( SCIPcreateRandom(scip, &heurdata->randnumgen,
413 
414  return SCIP_OKAY;
415 }
416 
417 /** deinitialization method of primal heuristic */
418 static
419 SCIP_DECL_HEUREXIT(heurExitMutation)
420 { /*lint --e{715}*/
421  SCIP_HEURDATA* heurdata;
422 
423  assert(heur != NULL);
424  assert(scip != NULL);
425 
426  /* get heuristic data */
427  heurdata = SCIPheurGetData(heur);
428  assert(heurdata != NULL);
429 
430  /* free random number generator */
431  SCIPfreeRandom(scip, &heurdata->randnumgen);
432 
433  return SCIP_OKAY;
434 }
435 
436 /** execution method of primal heuristic */
437 static
438 SCIP_DECL_HEUREXEC(heurExecMutation)
439 { /*lint --e{715}*/
440  SCIP_Longint maxnnodes;
441  SCIP_Longint nsubnodes; /* node limit for the subproblem */
442 
443  SCIP_HEURDATA* heurdata; /* heuristic's data */
444  SCIP* subscip; /* the subproblem created by mutation */
445  SCIP_VAR** fixedvars; /* array to store variables that should be fixed in the subproblem */
446  SCIP_Real* fixedvals; /* array to store fixing values for the variables */
447 
448  SCIP_Real maxnnodesr;
449 
450  int nfixedvars;
451  int nbinvars;
452  int nintvars;
453 
454  SCIP_Bool success;
455 
456  SCIP_RETCODE retcode;
457 
458  assert( heur != NULL );
459  assert( scip != NULL );
460  assert( result != NULL );
461 
462  /* get heuristic's data */
463  heurdata = SCIPheurGetData(heur);
464  assert(heurdata != NULL);
465 
466  *result = SCIP_DELAYED;
467 
468  /* only call heuristic, if feasible solution is available */
469  if( SCIPgetNSols(scip) <= 0 )
470  return SCIP_OKAY;
471 
472  /* only call heuristic, if the best solution comes from transformed problem */
473  assert(SCIPgetBestSol(scip) != NULL);
474  if( SCIPsolIsOriginal(SCIPgetBestSol(scip)) )
475  return SCIP_OKAY;
476 
477  /* only call heuristic, if enough nodes were processed since last incumbent */
478  if( SCIPgetNNodes(scip) - SCIPgetSolNodenum(scip,SCIPgetBestSol(scip)) < heurdata->nwaitingnodes)
479  return SCIP_OKAY;
480 
481  *result = SCIP_DIDNOTRUN;
482 
483  SCIP_CALL( SCIPgetVarsData(scip, NULL, NULL, &nbinvars, &nintvars, NULL, NULL) );
484 
485  /* only call heuristic, if discrete variables are present */
486  if( nbinvars + nintvars == 0 )
487  return SCIP_OKAY;
488 
489  /* calculate the maximal number of branching nodes until heuristic is aborted */
490  maxnnodesr = heurdata->nodesquot * SCIPgetNNodes(scip);
491 
492  /* reward mutation if it succeeded often, count the setup costs for the sub-MIP as 100 nodes */
493  maxnnodesr *= 1.0 + 2.0 * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0);
494  maxnnodes = (SCIP_Longint) maxnnodesr - 100 * SCIPheurGetNCalls(heur);
495  maxnnodes += heurdata->nodesofs;
496 
497  /* determine the node limit for the current process */
498  nsubnodes = maxnnodes - heurdata->usednodes;
499  nsubnodes = MIN(nsubnodes, heurdata->maxnodes);
500 
501  /* check whether we have enough nodes left to call subproblem solving */
502  if( nsubnodes < heurdata->minnodes )
503  return SCIP_OKAY;
504 
505  if( SCIPisStopped(scip) )
506  return SCIP_OKAY;
507 
508  /* check whether there is enough time and memory left */
509  SCIP_CALL( SCIPcheckCopyLimits(scip, &success) );
510 
511  if( !success )
512  return SCIP_OKAY;
513 
514  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvars, nbinvars + nintvars) );
515  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvals, nbinvars + nintvars) );
516 
517  /* determine variables that should be fixed in the mutation subproblem */
518  SCIP_CALL( determineVariableFixings(scip, fixedvars, fixedvals, &nfixedvars, heurdata->minfixingrate, heurdata->randnumgen, &success) );
519 
520  /* terminate if it is not possible to create the subproblem */
521  if( !success )
522  {
523  SCIPdebugMsg(scip, "Could not create the subproblem -> skip call\n");
524  goto TERMINATE;
525  }
526 
527  *result = SCIP_DIDNOTFIND;
528 
529  /* initializing the subproblem */
530  SCIP_CALL( SCIPcreate(&subscip) );
531 
532  /* setup and solve the subproblem and catch the return code */
533  retcode = setupAndSolveSubscipMutation(scip, subscip, heur, fixedvars, fixedvals, nfixedvars, nsubnodes, result);
534 
535  /* free the subscip in any case */
536  SCIP_CALL( SCIPfree(&subscip) );
537  SCIP_CALL( retcode );
538 
539  /* free storage for subproblem fixings */
540  TERMINATE:
541  SCIPfreeBufferArray(scip, &fixedvals);
542  SCIPfreeBufferArray(scip, &fixedvars);
543 
544  return SCIP_OKAY;
545 }
546 
547 /*
548  * primal heuristic specific interface methods
549  */
550 
551 /** creates the mutation primal heuristic and includes it in SCIP */
553  SCIP* scip /**< SCIP data structure */
554  )
555 {
556  SCIP_HEURDATA* heurdata;
557  SCIP_HEUR* heur;
558 
559  /* create Mutation primal heuristic data */
560  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
561 
562  /* include primal heuristic */
563  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
565  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecMutation, heurdata) );
566 
567  assert(heur != NULL);
568 
569  /* set non-NULL pointers to callback methods */
570  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyMutation) );
571  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeMutation) );
572  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitMutation) );
573  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitMutation) );
574 
575  /* add mutation primal heuristic parameters */
576  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
577  "number of nodes added to the contingent of the total nodes",
578  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0, INT_MAX, NULL, NULL) );
579 
580  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
581  "maximum number of nodes to regard in the subproblem",
582  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0, INT_MAX, NULL, NULL) );
583 
584  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minnodes",
585  "minimum number of nodes required to start the subproblem",
586  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0, INT_MAX, NULL, NULL) );
587 
588  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nwaitingnodes",
589  "number of nodes without incumbent change that heuristic should wait",
590  &heurdata->nwaitingnodes, TRUE, DEFAULT_NWAITINGNODES, 0, INT_MAX, NULL, NULL) );
591 
592  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
593  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
594  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
595 
596  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minfixingrate",
597  "percentage of integer variables that have to be fixed",
598  &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, SCIPsumepsilon(scip), 1.0-SCIPsumepsilon(scip), NULL, NULL) );
599 
600  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
601  "factor by which " HEUR_NAME " should at least improve the incumbent",
602  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
603 
604  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
605  "should subproblem be created out of the rows in the LP rows?",
606  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
607 
608  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/copycuts",
609  "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
610  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
611 
612  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/bestsollimit",
613  "limit on number of improving incumbent solutions in sub-CIP",
614  &heurdata->bestsollimit, FALSE, DEFAULT_BESTSOLLIMIT, -1, INT_MAX, NULL, NULL) );
615 
616  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useuct",
617  "should uct node selection be used at the beginning of the search?",
618  &heurdata->useuct, TRUE, DEFAULT_USEUCT, NULL, NULL) );
619 
620  return SCIP_OKAY;
621 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
#define DEFAULT_COPYCUTS
Definition: heur_mutation.c:69
static SCIP_DECL_HEURCOPY(heurCopyMutation)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1555
static SCIP_DECL_HEUREXIT(heurExitMutation)
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:687
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:877
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
static SCIP_DECL_HEURFREE(heurFreeMutation)
public methods for SCIP parameter handling
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
SCIP_RETCODE SCIPincludeHeurMutation(SCIP *scip)
public methods for node selector plugins
public methods for memory management
#define DEFAULT_NWAITINGNODES
Definition: heur_mutation.c:65
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1340
SCIP_EXPORT SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2521
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1353
public solving methods
#define DEFAULT_MINNODES
Definition: heur_mutation.c:62
#define DEFAULT_RANDSEED
Definition: heur_mutation.c:74
SCIP_RETCODE SCIPtranslateSubSols(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_VAR **subvars, SCIP_Bool *success, int *solindex)
Definition: scip_copy.c:1396
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1986
#define FALSE
Definition: def.h:73
#define HEUR_DISPCHAR
Definition: heur_mutation.c:51
#define TRUE
Definition: def.h:72
#define SCIPdebug(x)
Definition: pub_message.h:84
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
#define DEFAULT_MINFIXINGRATE
Definition: heur_mutation.c:63
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2555
static SCIP_RETCODE setupAndSolveSubscipMutation(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Longint nsubnodes, SCIP_RESULT *result)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3201
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
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
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
#define HEUR_NAME
Definition: heur_mutation.c:49
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip_param.c:899
SCIP_Real SCIPgetUpperbound(SCIP *scip)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
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_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3192
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1575
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
public methods for numerical tolerances
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
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:916
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip_prob.c:1420
public methods for querying solving statistics
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2206
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
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 SCIPgetNNodes(SCIP *scip)
static SCIP_DECL_HEUREXEC(heurExecMutation)
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:283
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip_branch.c:288
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1941
#define DEFAULT_NODESQUOT
Definition: heur_mutation.c:64
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
LNS heuristic that tries to randomly mutate the incumbent solution.
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1350
#define NULL
Definition: lpi_spx1.cpp:155
#define REALABS(x)
Definition: def.h:187
SCIP_RETCODE SCIPmergeVariableStatistics(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR **sourcevars, SCIP_VAR **targetvars, int nvars)
Definition: scip_copy.c:1251
public methods for problem copies
public methods for primal CIP solutions
#define DEFAULT_MAXNODES
Definition: heur_mutation.c:60
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip_nodesel.c:225
#define SCIP_CALL(x)
Definition: def.h:370
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:948
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
Definition: scip_param.c:677
#define DEFAULT_MINIMPROVE
Definition: heur_mutation.c:61
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
#define HEUR_MAXDEPTH
Definition: heur_mutation.c:55
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1649
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:70
#define HEUR_USESSUBSCIP
Definition: heur_mutation.c:57
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3014
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:201
#define HEUR_PRIORITY
Definition: heur_mutation.c:52
SCIP_EXPORT SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17677
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:210
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:126
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3228
#define DEFAULT_USELPROWS
Definition: heur_mutation.c:66
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 SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:561
#define HEUR_FREQOFS
Definition: heur_mutation.c:54
public methods for branching rule plugins and branching
general public methods
public methods for solutions
public methods for random numbers
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_EXPORT SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17667
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
public methods for message output
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1860
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_param.c:74
#define HEUR_DESC
Definition: heur_mutation.c:50
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3048
#define HEUR_TIMING
Definition: heur_mutation.c:56
#define SCIP_Real
Definition: def.h:163
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for message handling
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define HEUR_FREQ
Definition: heur_mutation.c:53
static SCIP_DECL_HEURINIT(heurInitMutation)
#define SCIP_Longint
Definition: def.h:148
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:445
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
#define DEFAULT_BESTSOLLIMIT
Definition: heur_mutation.c:72
public methods for primal heuristics
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:315
#define DEFAULT_USEUCT
Definition: heur_mutation.c:73
#define SCIP_CALL_ABORT(x)
Definition: def.h:349
public methods for global and local (sub)problems
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2305
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:503
void SCIPrandomPermuteArray(SCIP_RANDNUMGEN *randnumgen, void **array, int begin, int end)
Definition: misc.c:10030
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:974
#define DEFAULT_NODESOFS
Definition: heur_mutation.c:59
memory allocation routines
static SCIP_RETCODE determineVariableFixings(SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, SCIP_Real minfixingrate, SCIP_RANDNUMGEN *randnumgen, SCIP_Bool *success)