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-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_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 -1103010
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  /* add an objective cutoff */
297  assert( !SCIPisInfinity(scip, SCIPgetUpperbound(scip)) );
298 
299  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
300  if( !SCIPisInfinity(scip, -1.0 * SCIPgetLowerbound(scip)) )
301  {
302  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip)
303  + heurdata->minimprove * SCIPgetLowerbound(scip);
304  }
305  else
306  {
307  if( SCIPgetUpperbound(scip) >= 0 )
308  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip);
309  else
310  cutoff = (1 + heurdata->minimprove) * SCIPgetUpperbound(scip);
311  }
312  cutoff = MIN(upperbound, cutoff);
313  SCIP_CALL(SCIPsetObjlimit(subscip, cutoff));
314 
315  /* solve the subproblem
316  *
317  * Errors in solving the subproblem should not kill the overall solving process
318  * Hence, the return code is caught but only in debug mode, SCIP will stop.
319  */
320  SCIPdebugMsg(scip, "Solve Mutation subMIP\n");
321  SCIP_CALL_ABORT( SCIPsolve(subscip) );
322 
323  /* transfer variable statistics from sub-SCIP */
324  SCIP_CALL( SCIPmergeVariableStatistics(subscip, scip, subvars, vars, nvars) );
325 
326  /* print solving statistics of subproblem if we are in SCIP's debug mode */
328 
329  heurdata->usednodes += SCIPgetNNodes(subscip);
330 
331  /* check, whether a solution was found;
332  * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted
333  */
334  SCIP_CALL( SCIPtranslateSubSols(scip, subscip, heur, subvars, &success, NULL) );
335  if( success )
336  *result = SCIP_FOUNDSOL;
337 
338  /* free subproblem */
339  SCIPfreeBufferArray(scip, &subvars);
340 
341  return SCIP_OKAY;
342 }
343 
344 
345 /*
346  * Callback methods of primal heuristic
347  */
348 
349 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
350 static
351 SCIP_DECL_HEURCOPY(heurCopyMutation)
352 { /*lint --e{715}*/
353  assert(scip != NULL);
354  assert(heur != NULL);
355  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
356 
357  /* call inclusion method of primal heuristic */
359 
360  return SCIP_OKAY;
361 }
362 
363 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
364 static
365 SCIP_DECL_HEURFREE(heurFreeMutation)
366 { /*lint --e{715}*/
367  SCIP_HEURDATA* heurdata;
368 
369  assert(heur != NULL);
370  assert(scip != NULL);
371 
372  /* get heuristic data */
373  heurdata = SCIPheurGetData(heur);
374  assert(heurdata != NULL);
375 
376  /* free heuristic data */
377  SCIPfreeBlockMemory(scip, &heurdata);
378  SCIPheurSetData(heur, NULL);
379 
380  return SCIP_OKAY;
381 }
382 
383 /** initialization method of primal heuristic (called after problem was transformed) */
384 static
385 SCIP_DECL_HEURINIT(heurInitMutation)
386 { /*lint --e{715}*/
387  SCIP_HEURDATA* heurdata;
388 
389  assert(heur != NULL);
390  assert(scip != NULL);
391 
392  /* get heuristic's data */
393  heurdata = SCIPheurGetData(heur);
394  assert(heurdata != NULL);
395 
396  /* initialize data */
397  heurdata->usednodes = 0;
398 
399  /* create random number generator */
400  SCIP_CALL( SCIPcreateRandom(scip, &heurdata->randnumgen,
402 
403  return SCIP_OKAY;
404 }
405 
406 /** deinitialization method of primal heuristic */
407 static
408 SCIP_DECL_HEUREXIT(heurExitMutation)
409 { /*lint --e{715}*/
410  SCIP_HEURDATA* heurdata;
411 
412  assert(heur != NULL);
413  assert(scip != NULL);
414 
415  /* get heuristic data */
416  heurdata = SCIPheurGetData(heur);
417  assert(heurdata != NULL);
418 
419  /* free random number generator */
420  SCIPfreeRandom(scip, &heurdata->randnumgen);
421 
422  return SCIP_OKAY;
423 }
424 
425 /** execution method of primal heuristic */
426 static
427 SCIP_DECL_HEUREXEC(heurExecMutation)
428 { /*lint --e{715}*/
429  SCIP_Longint maxnnodes;
430  SCIP_Longint nsubnodes; /* node limit for the subproblem */
431 
432  SCIP_HEURDATA* heurdata; /* heuristic's data */
433  SCIP* subscip; /* the subproblem created by mutation */
434  SCIP_VAR** fixedvars; /* array to store variables that should be fixed in the subproblem */
435  SCIP_Real* fixedvals; /* array to store fixing values for the variables */
436 
437  SCIP_Real maxnnodesr;
438 
439  int nfixedvars;
440  int nbinvars;
441  int nintvars;
442 
443  SCIP_Bool success;
444 
445  SCIP_RETCODE retcode;
446 
447  assert( heur != NULL );
448  assert( scip != NULL );
449  assert( result != NULL );
450 
451  /* get heuristic's data */
452  heurdata = SCIPheurGetData(heur);
453  assert(heurdata != NULL);
454 
455  *result = SCIP_DELAYED;
456 
457  /* only call heuristic, if feasible solution is available */
458  if( SCIPgetNSols(scip) <= 0 )
459  return SCIP_OKAY;
460 
461  /* only call heuristic, if the best solution comes from transformed problem */
462  assert(SCIPgetBestSol(scip) != NULL);
463  if( SCIPsolIsOriginal(SCIPgetBestSol(scip)) )
464  return SCIP_OKAY;
465 
466  /* only call heuristic, if enough nodes were processed since last incumbent */
467  if( SCIPgetNNodes(scip) - SCIPgetSolNodenum(scip,SCIPgetBestSol(scip)) < heurdata->nwaitingnodes)
468  return SCIP_OKAY;
469 
470  *result = SCIP_DIDNOTRUN;
471 
472  SCIP_CALL( SCIPgetVarsData(scip, NULL, NULL, &nbinvars, &nintvars, NULL, NULL) );
473 
474  /* only call heuristic, if discrete variables are present */
475  if( nbinvars + nintvars == 0 )
476  return SCIP_OKAY;
477 
478  /* calculate the maximal number of branching nodes until heuristic is aborted */
479  maxnnodesr = heurdata->nodesquot * SCIPgetNNodes(scip);
480 
481  /* reward mutation if it succeeded often, count the setup costs for the sub-MIP as 100 nodes */
482  maxnnodesr *= 1.0 + 2.0 * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0);
483  maxnnodes = (SCIP_Longint) maxnnodesr - 100 * SCIPheurGetNCalls(heur);
484  maxnnodes += heurdata->nodesofs;
485 
486  /* determine the node limit for the current process */
487  nsubnodes = maxnnodes - heurdata->usednodes;
488  nsubnodes = MIN(nsubnodes, heurdata->maxnodes);
489 
490  /* check whether we have enough nodes left to call subproblem solving */
491  if( nsubnodes < heurdata->minnodes )
492  return SCIP_OKAY;
493 
494  if( SCIPisStopped(scip) )
495  return SCIP_OKAY;
496 
497  /* check whether there is enough time and memory left */
498  SCIP_CALL( SCIPcheckCopyLimits(scip, &success) );
499 
500  if( !success )
501  return SCIP_OKAY;
502 
503  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvars, nbinvars + nintvars) );
504  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvals, nbinvars + nintvars) );
505 
506  /* determine variables that should be fixed in the mutation subproblem */
507  SCIP_CALL( determineVariableFixings(scip, fixedvars, fixedvals, &nfixedvars, heurdata->minfixingrate, heurdata->randnumgen, &success) );
508 
509  /* terminate if it is not possible to create the subproblem */
510  if( !success )
511  {
512  SCIPdebugMsg(scip, "Could not create the subproblem -> skip call\n");
513  goto TERMINATE;
514  }
515 
516  *result = SCIP_DIDNOTFIND;
517 
518  /* initializing the subproblem */
519  SCIP_CALL( SCIPcreate(&subscip) );
520 
521  /* setup and solve the subproblem and catch the return code */
522  retcode = setupAndSolveSubscipMutation(scip, subscip, heur, fixedvars, fixedvals, nfixedvars, nsubnodes, result);
523 
524  /* free the subscip in any case */
525  SCIP_CALL( SCIPfree(&subscip) );
526  SCIP_CALL( retcode );
527 
528  /* free storage for subproblem fixings */
529  TERMINATE:
530  SCIPfreeBufferArray(scip, &fixedvals);
531  SCIPfreeBufferArray(scip, &fixedvars);
532 
533  return SCIP_OKAY;
534 }
535 
536 /*
537  * primal heuristic specific interface methods
538  */
539 
540 /** creates the mutation primal heuristic and includes it in SCIP */
542  SCIP* scip /**< SCIP data structure */
543  )
544 {
545  SCIP_HEURDATA* heurdata;
546  SCIP_HEUR* heur;
547 
548  /* create Mutation primal heuristic data */
549  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
550 
551  /* include primal heuristic */
552  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
554  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecMutation, heurdata) );
555 
556  assert(heur != NULL);
557 
558  /* set non-NULL pointers to callback methods */
559  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyMutation) );
560  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeMutation) );
561  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitMutation) );
562  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitMutation) );
563 
564  /* add mutation primal heuristic parameters */
565  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
566  "number of nodes added to the contingent of the total nodes",
567  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0, INT_MAX, NULL, NULL) );
568 
569  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
570  "maximum number of nodes to regard in the subproblem",
571  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0, INT_MAX, NULL, NULL) );
572 
573  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minnodes",
574  "minimum number of nodes required to start the subproblem",
575  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0, INT_MAX, NULL, NULL) );
576 
577  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nwaitingnodes",
578  "number of nodes without incumbent change that heuristic should wait",
579  &heurdata->nwaitingnodes, TRUE, DEFAULT_NWAITINGNODES, 0, INT_MAX, NULL, NULL) );
580 
581  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
582  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
583  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
584 
585  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minfixingrate",
586  "percentage of integer variables that have to be fixed",
587  &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, SCIPsumepsilon(scip), 1.0-SCIPsumepsilon(scip), NULL, NULL) );
588 
589  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
590  "factor by which " HEUR_NAME " should at least improve the incumbent",
591  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
592 
593  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
594  "should subproblem be created out of the rows in the LP rows?",
595  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
596 
597  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/copycuts",
598  "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
599  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
600 
601  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/bestsollimit",
602  "limit on number of improving incumbent solutions in sub-CIP",
603  &heurdata->bestsollimit, FALSE, DEFAULT_BESTSOLLIMIT, -1, INT_MAX, NULL, NULL) );
604 
605  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useuct",
606  "should uct node selection be used at the beginning of the search?",
607  &heurdata->useuct, TRUE, DEFAULT_USEUCT, NULL, NULL) );
608 
609  return SCIP_OKAY;
610 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2521
#define DEFAULT_COPYCUTS
Definition: heur_mutation.c:69
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
static SCIP_DECL_HEURCOPY(heurCopyMutation)
static SCIP_DECL_HEUREXIT(heurExitMutation)
SCIP_RETCODE SCIPincludeHeurMutation(SCIP *scip)
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:949
static SCIP_DECL_HEURFREE(heurFreeMutation)
public methods for SCIP parameter handling
public methods for node selector plugins
public methods for memory management
#define DEFAULT_NWAITINGNODES
Definition: heur_mutation.c:65
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17910
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1587
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:201
public solving methods
#define DEFAULT_MINNODES
Definition: heur_mutation.c:62
#define DEFAULT_RANDSEED
Definition: heur_mutation.c:74
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1864
#define FALSE
Definition: def.h:87
#define HEUR_DISPCHAR
Definition: heur_mutation.c:51
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3014
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3278
#define TRUE
Definition: def.h:86
void SCIPrandomPermuteArray(SCIP_RANDNUMGEN *randnumgen, void **array, int begin, int end)
Definition: misc.c:10074
#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 SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:923
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip_branch.c:288
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)
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:99
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_RETCODE SCIPtranslateSubSols(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_VAR **subvars, SCIP_Bool *success, int *solindex)
Definition: scip_copy.c:1439
#define HEUR_NAME
Definition: heur_mutation.c:49
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3201
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:127
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:283
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1362
#define SCIPdebugMsg
Definition: scip_message.h:69
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
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
public methods for numerical tolerances
public methods for querying solving statistics
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17920
static SCIP_DECL_HEUREXEC(heurExecMutation)
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2613
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1441
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:210
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:420
#define DEFAULT_NODESQUOT
Definition: heur_mutation.c:64
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3048
SCIP_RETCODE SCIPmergeVariableStatistics(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR **sourcevars, SCIP_VAR **targetvars, int nvars)
Definition: scip_copy.c:1256
LNS heuristic that tries to randomly mutate the incumbent solution.
#define NULL
Definition: lpi_spx1.cpp:155
#define REALABS(x)
Definition: def.h:201
public methods for problem copies
public methods for primal CIP solutions
#define DEFAULT_MAXNODES
Definition: heur_mutation.c:60
#define SCIP_CALL(x)
Definition: def.h:384
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1567
#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_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:84
#define HEUR_USESSUBSCIP
Definition: heur_mutation.c:57
#define HEUR_PRIORITY
Definition: heur_mutation.c:52
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip_prob.c:1420
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:478
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2205
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:127
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
#define DEFAULT_USELPROWS
Definition: heur_mutation.c:66
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
Definition: scip_param.c:652
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1990
#define HEUR_FREQOFS
Definition: heur_mutation.c:54
public methods for branching rule plugins and branching
general public methods
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2304
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for solutions
public methods for random numbers
public methods for message output
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
#define HEUR_DESC
Definition: heur_mutation.c:50
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip_nodesel.c:225
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_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1945
#define HEUR_TIMING
Definition: heur_mutation.c:56
#define SCIP_Real
Definition: def.h:177
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:694
public methods for message handling
#define HEUR_FREQ
Definition: heur_mutation.c:53
static SCIP_DECL_HEURINIT(heurInitMutation)
#define SCIP_Longint
Definition: def.h:162
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3235
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_BESTSOLLIMIT
Definition: heur_mutation.c:72
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
public methods for primal heuristics
#define DEFAULT_USEUCT
Definition: heur_mutation.c:73
SCIPallocBlockMemory(scip, subsol))
#define SCIP_CALL_ABORT(x)
Definition: def.h:363
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1352
SCIP_Longint SCIPgetNNodes(SCIP *scip)
public methods for global and local (sub)problems
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1352
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 SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip_param.c:874
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:536
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 DEFAULT_NODESOFS
Definition: heur_mutation.c:59
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:315
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1648
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)