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