Scippy

SCIP

Solving Constraint Integer Programs

heur_rins.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_rins.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief LNS heuristic that combines the incumbent with the LP optimum
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_rins.h"
27 #include "scip/pub_event.h"
28 #include "scip/pub_heur.h"
29 #include "scip/pub_message.h"
30 #include "scip/pub_misc.h"
31 #include "scip/pub_sol.h"
32 #include "scip/pub_var.h"
33 #include "scip/scip_branch.h"
34 #include "scip/scip_cons.h"
35 #include "scip/scip_copy.h"
36 #include "scip/scip_event.h"
37 #include "scip/scip_general.h"
38 #include "scip/scip_heur.h"
39 #include "scip/scip_lp.h"
40 #include "scip/scip_mem.h"
41 #include "scip/scip_message.h"
42 #include "scip/scip_nodesel.h"
43 #include "scip/scip_numerics.h"
44 #include "scip/scip_param.h"
45 #include "scip/scip_prob.h"
46 #include "scip/scip_sol.h"
47 #include "scip/scip_solve.h"
48 #include "scip/scip_solvingstats.h"
49 #include <string.h>
50 
51 #define HEUR_NAME "rins"
52 #define HEUR_DESC "relaxation induced neighborhood search by Danna, Rothberg, and Le Pape"
53 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_LNS
54 #define HEUR_PRIORITY -1101000
55 #define HEUR_FREQ 25
56 #define HEUR_FREQOFS 0
57 #define HEUR_MAXDEPTH -1
58 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPNODE
59 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
60 
61 #define DEFAULT_NODESOFS 500 /* number of nodes added to the contingent of the total nodes */
62 #define DEFAULT_MAXNODES 5000 /* maximum number of nodes to regard in the subproblem */
63 #define DEFAULT_MINNODES 50 /* minimum number of nodes to regard in the subproblem */
64 #define DEFAULT_MINIMPROVE 0.01 /* factor by which RINS should at least improve the incumbent */
65 #define DEFAULT_MINFIXINGRATE 0.3 /* minimum percentage of integer variables that have to be fixed */
66 #define DEFAULT_NODESQUOT 0.3 /* subproblem nodes in relation to nodes of the original problem */
67 #define DEFAULT_LPLIMFAC 2.0 /* factor by which the limit on the number of LP depends on the node limit */
68 #define DEFAULT_NWAITINGNODES 200 /* number of nodes without incumbent change that heuristic should wait */
69 #define DEFAULT_USELPROWS FALSE /* should subproblem be created out of the rows in the LP rows,
70  * otherwise, the copy constructors of the constraints handlers are used */
71 #define DEFAULT_COPYCUTS TRUE /* if DEFAULT_USELPROWS is FALSE, then should all active cuts from the cutpool
72  * of the original scip be copied to constraints of the subscip
73  */
74 #define DEFAULT_USEUCT FALSE /* should uct node selection be used at the beginning of the search? */
75 
76 /* event handler properties */
77 #define EVENTHDLR_NAME "Rins"
78 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic"
79 
80 /*
81  * Data structures
82  */
83 
84 /** primal heuristic data */
85 struct SCIP_HeurData
86 {
87  int nodesofs; /**< number of nodes added to the contingent of the total nodes */
88  int maxnodes; /**< maximum number of nodes to regard in the subproblem */
89  int minnodes; /**< minimum number of nodes to regard in the subproblem */
90  SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
91  int nwaitingnodes; /**< number of nodes without incumbent change that heuristic should wait */
92  SCIP_Real minimprove; /**< factor by which RINS should at least improve the incumbent */
93  SCIP_Real nodelimit; /**< the nodelimit employed in the current sub-SCIP, for the event handler*/
94  SCIP_Real lplimfac; /**< factor by which the limit on the number of LP depends on the node limit */
95  SCIP_Longint usednodes; /**< nodes already used by RINS in earlier calls */
96  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
97  SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
98  SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
99  * to constraints in subproblem?
100  */
101  SCIP_Bool useuct; /**< should uct node selection be used at the beginning of the search? */
102 };
103 
104 /*
105  * Local methods
106  */
107 
108 
109 
110 
111 /** determines variable fixings for RINS
112  *
113  * RINS fixes variables with matching solution values in the current LP and the
114  * incumbent solution
115  */
116 static
118  SCIP* scip, /**< original SCIP data structure */
119  SCIP_VAR** fixedvars, /**< array to store source SCIP variables that should be fixed in the copy */
120  SCIP_Real* fixedvals, /**< array to store fixing values for variables that should be fixed in the copy */
121  int* nfixedvars, /**< pointer to store the number of variables that RINS can fix */
122  int fixedvarssize, /**< size of the buffer arrays to store potential fixings */
123  SCIP_Real minfixingrate, /**< percentage of integer variables that have to be fixed */
124  SCIP_Bool* success /**< pointer to store whether sufficiently many variable fixings were found */
125  )
126 {
127  SCIP_SOL* bestsol; /* incumbent solution of the original problem */
128  SCIP_VAR** vars; /* original scip variables */
129  SCIP_Real fixingrate;
130 
131  int nvars;
132  int nbinvars;
133  int nintvars;
134  int i;
135  int fixingcounter;
136 
137  assert(fixedvals != NULL);
138  assert(fixedvars != NULL);
139  assert(nfixedvars != NULL);
140 
141  /* get required data of the original problem */
142  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
143  bestsol = SCIPgetBestSol(scip);
144  assert(bestsol != NULL);
145 
146  fixingcounter = 0;
147  assert(fixedvarssize >= nbinvars + nintvars);
148 
149  /* determine variables to fix in the subproblem */
150  for( i = 0; i < nbinvars + nintvars; i++ )
151  {
152  SCIP_Real lpsolval;
153  SCIP_Real solval;
154 
155  /* get the current LP solution and the incumbent solution for each variable */
156  lpsolval = SCIPvarGetLPSol(vars[i]);
157  solval = SCIPgetSolVal(scip, bestsol, vars[i]);
158 
159  /* iff both solutions are equal, variable is stored to be fixed */
160  if( SCIPisFeasEQ(scip, lpsolval, solval) )
161  {
162  /* store the fixing and increase the number of fixed variables */
163  fixedvars[fixingcounter] = vars[i];
164  fixedvals[fixingcounter] = solval;
165  fixingcounter++;
166  }
167  }
168 
169  /* store the number of fixings */
170  *nfixedvars = fixingcounter;
171 
172  /* abort, if all variables should be fixed */
173  if( fixingcounter == nbinvars + nintvars )
174  {
175  *success = FALSE;
176  return SCIP_OKAY;
177  }
178  else
179  fixingrate = (SCIP_Real)fixingcounter / (SCIP_Real)(MAX(nbinvars + nintvars, 1));
180 
181  /* abort, if the amount of fixed variables is insufficient */
182  if( fixingrate < minfixingrate )
183  {
184  *success = FALSE;
185  return SCIP_OKAY;
186  }
187 
188  *success = TRUE;
189  return SCIP_OKAY;
190 }
191 
192 static
193 SCIP_DECL_EVENTEXEC(eventExecRins);
194 
195 /** wrapper for the part of heuristic that runs a subscip. Wrapper is needed to avoid possible ressource leaks */
196 static
198  SCIP* scip, /**< original SCIP data structure */
199  SCIP* subscip, /**< SCIP structure of the subproblem */
200  SCIP_HEUR* heur, /**< Heuristic pointer */
201  SCIP_HEURDATA* heurdata, /**< Heuristic's data */
202  SCIP_VAR** vars, /**< original problem's variables */
203  SCIP_VAR** fixedvars, /**< Fixed variables of original SCIP */
204  SCIP_Real* fixedvals, /**< Fixed values of original SCIP */
205  SCIP_RESULT* result, /**< Result pointer */
206  int nvars, /**< Number of variables */
207  int nfixedvars, /**< Number of fixed variables */
208  SCIP_Longint nnodes /**< Number of nodes in the b&b tree */
209  )
210 {
211  SCIP_VAR** subvars; /* variables of the subscip */
212  SCIP_HASHMAP* varmapfw; /* hashmap for mapping between vars of scip and subscip */
213  SCIP_EVENTHDLR* eventhdlr; /* event handler for LP events */
214  SCIP_Real upperbound; /* upperbound of the original SCIP */
215  SCIP_Real cutoff; /* objective cutoff for the subproblem */
216 
217  SCIP_Bool success;
218 
219  int i;
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, "rins", fixedvars, fixedvals, nfixedvars,
226  heurdata->uselprows, heurdata->copycuts, &success, NULL) );
227 
228  eventhdlr = NULL;
229  /* create event handler for LP events */
230  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecRins, NULL) );
231  if( eventhdlr == NULL )
232  {
233  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
234  return SCIP_PLUGINNOTFOUND;
235  }
236 
237  /* copy subproblem variables from map to obtain the same order */
238  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
239  for( i = 0; i < nvars; i++ )
240  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
241 
242  /* free hash map */
243  SCIPhashmapFree(&varmapfw);
244 
245  /* do not abort subproblem on CTRL-C */
246  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
247 
248 #ifdef SCIP_DEBUG
249  /* for debugging, enable full output */
250  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", SCIP_VERBLEVEL_FULL) );
251  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
252 #else
253  /* disable statistic timing inside sub SCIP and output to console */
254  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", (int) SCIP_VERBLEVEL_NONE) );
255  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
256 #endif
257 
258  /* set limits for the subproblem */
259  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
260  heurdata->nodelimit = nnodes;
261  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nnodes) );
262  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/stallnodes", MAX(10, nnodes/10)) );
263  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", 3) );
264 
265  /* forbid recursive call of heuristics and separators solving subMIPs */
266  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
267 
268  /* disable cutting plane separation */
270 
271  /* disable expensive presolving */
273 
274  /* use best estimate node selection */
275  if( SCIPfindNodesel(subscip, "estimate") != NULL && !SCIPisParamFixed(subscip, "nodeselection/estimate/stdpriority") )
276  {
277  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
278  }
279 
280  /* activate uct node selection at the top of the tree */
281  if( heurdata->useuct && SCIPfindNodesel(subscip, "uct") != NULL && !SCIPisParamFixed(subscip, "nodeselection/uct/stdpriority") )
282  {
283  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/uct/stdpriority", INT_MAX/2) );
284  }
285 
286  /* use inference branching */
287  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
288  {
289  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
290  }
291 
292  /* enable conflict analysis, disable analysis of boundexceeding LPs, and restrict conflict pool */
293  if( !SCIPisParamFixed(subscip, "conflict/enable") )
294  {
295  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/enable", TRUE) );
296  }
297  if( !SCIPisParamFixed(subscip, "conflict/useboundlp") )
298  {
299  SCIP_CALL( SCIPsetCharParam(subscip, "conflict/useboundlp", 'o') );
300  }
301  if( !SCIPisParamFixed(subscip, "conflict/maxstoresize") )
302  {
303  SCIP_CALL( SCIPsetIntParam(subscip, "conflict/maxstoresize", 100) );
304  }
305 
306  /* speed up sub-SCIP by not checking dual LP feasibility */
307  SCIP_CALL( SCIPsetBoolParam(subscip, "lp/checkdualfeas", FALSE) );
308 
309  /* add an objective cutoff */
310  assert( !SCIPisInfinity(scip,SCIPgetUpperbound(scip)) );
311 
312  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
313  if( !SCIPisInfinity(scip, -1.0 * SCIPgetLowerbound(scip)) )
314  {
315  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip) + heurdata->minimprove * SCIPgetLowerbound(scip);
316  }
317  else
318  {
319  if( SCIPgetUpperbound(scip) >= 0 )
320  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip);
321  else
322  cutoff = (1 + heurdata->minimprove) * SCIPgetUpperbound(scip);
323  }
324  cutoff = MIN(upperbound, cutoff);
325  SCIP_CALL( SCIPsetObjlimit(subscip, cutoff) );
326 
327  /* catch LP events of sub-SCIP */
328  SCIP_CALL( SCIPtransformProb(subscip) );
329  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
330 
331  /* Errors in solving the subproblem should not kill the overall solving process
332  * Hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
333  */
334  /* solve the subproblem */
335  SCIP_CALL_ABORT( SCIPsolve(subscip) );
336 
337  /* drop LP events of sub-SCIP */
338  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
339 
340  /* we try to merge variable statistics with those of our main SCIP */
341  SCIP_CALL( SCIPmergeVariableStatistics(subscip, scip, subvars, vars, nvars) );
342 
343  /* print solving statistics of subproblem if we are in SCIP's debug mode */
345 
346  heurdata->usednodes += SCIPgetNNodes(subscip);
347 
348  SCIP_CALL( SCIPtranslateSubSols(scip, subscip, heur, subvars, &success, NULL) );
349  if( success )
350  *result = SCIP_FOUNDSOL;
351 
352  /* free subproblem */
353  SCIPfreeBufferArray(scip, &subvars);
354 
355  return SCIP_OKAY;
356 }
357 
358 /* ---------------- Callback methods of event handler ---------------- */
359 
360 /* exec the event handler
361  *
362  * we interrupt the solution process
363  */
364 static
365 SCIP_DECL_EVENTEXEC(eventExecRins)
366 {
367  SCIP_HEURDATA* heurdata;
368 
369  assert(eventhdlr != NULL);
370  assert(eventdata != NULL);
371  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
372  assert(event != NULL);
373  assert(SCIPeventGetType(event) & SCIP_EVENTTYPE_LPSOLVED);
374 
375  heurdata = (SCIP_HEURDATA*)eventdata;
376  assert(heurdata != NULL);
377 
378  /* interrupt solution process of sub-SCIP */
379  if( SCIPgetNLPs(scip) > heurdata->lplimfac * heurdata->nodelimit )
380  {
381  SCIPdebugMsg(scip, "interrupt after %" SCIP_LONGINT_FORMAT " LPs\n",SCIPgetNLPs(scip));
383  }
384 
385  return SCIP_OKAY;
386 }
387 
388 
389 /*
390  * Callback methods of primal heuristic
391  */
392 
393 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
394 static
395 SCIP_DECL_HEURCOPY(heurCopyRins)
396 { /*lint --e{715}*/
397  assert(scip != NULL);
398  assert(heur != NULL);
399  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
400 
401  /* call inclusion method of primal heuristic */
403 
404  return SCIP_OKAY;
405 }
406 
407 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
408 static
409 SCIP_DECL_HEURFREE(heurFreeRins)
410 { /*lint --e{715}*/
411  SCIP_HEURDATA* heurdata;
412 
413  assert( heur != NULL );
414  assert( scip != NULL );
415 
416  /* get heuristic data */
417  heurdata = SCIPheurGetData(heur);
418  assert( heurdata != NULL );
419 
420  /* free heuristic data */
421  SCIPfreeBlockMemory(scip, &heurdata);
422  SCIPheurSetData(heur, NULL);
423 
424  return SCIP_OKAY;
425 }
426 
427 
428 /** initialization method of primal heuristic (called after problem was transformed) */
429 static
430 SCIP_DECL_HEURINIT(heurInitRins)
431 { /*lint --e{715}*/
432  SCIP_HEURDATA* heurdata;
433 
434  assert( heur != NULL );
435  assert( scip != NULL );
436 
437  /* get heuristic's data */
438  heurdata = SCIPheurGetData(heur);
439  assert( heurdata != NULL );
440 
441  /* initialize data */
442  heurdata->usednodes = 0;
443 
444  return SCIP_OKAY;
445 }
446 
447 
448 /** execution method of primal heuristic */
449 static
450 SCIP_DECL_HEUREXEC(heurExecRins)
451 { /*lint --e{715}*/
453 
454  SCIP_HEURDATA* heurdata; /* heuristic's data */
455  SCIP* subscip; /* the subproblem created by RINS */
456  SCIP_VAR** vars; /* original problem's variables */
457  SCIP_VAR** fixedvars;
458  SCIP_Real* fixedvals;
459 
460  SCIP_RETCODE retcode; /* retcode needed for wrapper method */
461 
462  int nvars;
463  int nbinvars;
464  int nintvars;
465  int nfixedvars;
466 
467  SCIP_Bool success;
468 
469  assert( heur != NULL );
470  assert( scip != NULL );
471  assert( result != NULL );
472  assert( SCIPhasCurrentNodeLP(scip) );
473 
474  *result = SCIP_DELAYED;
475 
476  /* do not call heuristic of node was already detected to be infeasible */
477  if( nodeinfeasible )
478  return SCIP_OKAY;
479 
480  /* get heuristic's data */
481  heurdata = SCIPheurGetData(heur);
482  assert( heurdata != NULL );
483 
484  /* only call heuristic, if an optimal LP solution and a feasible solution are at hand */
486  return SCIP_OKAY;
487 
488  /* only call heuristic, if the LP objective value is smaller than the cutoff bound */
490  return SCIP_OKAY;
491 
492  /* only call heuristic, if the best solution comes from transformed problem */
493  assert( SCIPgetBestSol(scip) != NULL );
495  return SCIP_OKAY;
496 
497  /* only call heuristic, if enough nodes were processed since last incumbent */
498  if( SCIPgetNNodes(scip) - SCIPgetSolNodenum(scip,SCIPgetBestSol(scip)) < heurdata->nwaitingnodes)
499  return SCIP_OKAY;
500 
501  *result = SCIP_DIDNOTRUN;
502 
503  /* calculate the maximal number of branching nodes until heuristic is aborted */
504  nnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
505 
506  /* reward RINS if it succeeded often */
507  nnodes = (SCIP_Longint)(nnodes * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0));
508  nnodes -= (SCIP_Longint)(100.0 * SCIPheurGetNCalls(heur)); /* count the setup costs for the sub-MIP as 100 nodes */
509  nnodes += heurdata->nodesofs;
510 
511  /* determine the node limit for the current process */
512  nnodes -= heurdata->usednodes;
513  nnodes = MIN(nnodes, heurdata->maxnodes);
514 
515  /* check whether we have enough nodes left to call subproblem solving */
516  if( nnodes < heurdata->minnodes )
517  return SCIP_OKAY;
518 
519  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
520 
521  /* check whether discrete variables are available */
522  if( nbinvars == 0 && nintvars == 0 )
523  return SCIP_OKAY;
524 
525  if( SCIPisStopped(scip) )
526  return SCIP_OKAY;
527 
528  /* allocate buffer storage to hold the RINS fixings */
529  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvars, nbinvars + nintvars) );
530  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvals, nbinvars + nintvars) );
531 
532  success = FALSE;
533 
534  nfixedvars = 0;
535  /* determine possible fixings for RINS: variables with same value in bestsol and LP relaxation */
536  SCIP_CALL( determineFixings(scip, fixedvars, fixedvals, &nfixedvars, nbinvars + nintvars, heurdata->minfixingrate, &success) );
537 
538  /* too few variables could be fixed by the RINS scheme */
539  if( !success )
540  goto TERMINATE;
541 
542  /* check whether there is enough time and memory left */
543  SCIP_CALL( SCIPcheckCopyLimits(scip, &success) );
544 
545  /* abort if no time is left or not enough memory to create a copy of SCIP */
546  if( !success )
547  goto TERMINATE;
548 
549  assert(nfixedvars > 0 && nfixedvars < nbinvars + nintvars);
550 
551  *result = SCIP_DIDNOTFIND;
552 
553  SCIPdebugMsg(scip, "RINS heuristic fixes %d out of %d binary+integer variables\n", nfixedvars, nbinvars + nintvars);
554  SCIP_CALL( SCIPcreate(&subscip) );
555 
556  retcode = wrapperRins(scip, subscip, heur, heurdata, vars, fixedvars, fixedvals, result, nvars, nfixedvars, nnodes);
557 
558  SCIP_CALL( SCIPfree(&subscip) );
559 
560  SCIP_CALL( retcode );
561 
562 TERMINATE:
563  SCIPfreeBufferArray(scip, &fixedvals);
564  SCIPfreeBufferArray(scip, &fixedvars);
565 
566  return SCIP_OKAY;
567 }
568 
569 /*
570  * primal heuristic specific interface methods
571  */
572 
573 /** creates the RINS primal heuristic and includes it in SCIP */
575  SCIP* scip /**< SCIP data structure */
576  )
577 {
578  SCIP_HEURDATA* heurdata;
579  SCIP_HEUR* heur;
580 
581  /* create Rins primal heuristic data */
582  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
583 
584  /* include primal heuristic */
585  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
587  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecRins, heurdata) );
588 
589  assert(heur != NULL);
590 
591  /* set non-NULL pointers to callback methods */
592  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyRins) );
593  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeRins) );
594  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitRins) );
595 
596  /* add RINS primal heuristic parameters */
597  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
598  "number of nodes added to the contingent of the total nodes",
599  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0, INT_MAX, NULL, NULL) );
600 
601  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
602  "maximum number of nodes to regard in the subproblem",
603  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0, INT_MAX, NULL, NULL) );
604 
605  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minnodes",
606  "minimum number of nodes required to start the subproblem",
607  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0, INT_MAX, NULL, NULL) );
608 
609  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
610  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
611  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
612 
613  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nwaitingnodes",
614  "number of nodes without incumbent change that heuristic should wait",
615  &heurdata->nwaitingnodes, TRUE, DEFAULT_NWAITINGNODES, 0, INT_MAX, NULL, NULL) );
616 
617  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
618  "factor by which " HEUR_NAME " should at least improve the incumbent",
619  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
620 
621  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minfixingrate",
622  "minimum percentage of integer variables that have to be fixed",
623  &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, 0.0, 1.0, NULL, NULL) );
624 
625  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/lplimfac",
626  "factor by which the limit on the number of LP depends on the node limit",
627  &heurdata->lplimfac, TRUE, DEFAULT_LPLIMFAC, 1.0, SCIP_REAL_MAX, NULL, NULL) );
628 
629  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
630  "should subproblem be created out of the rows in the LP rows?",
631  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
632 
633  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/copycuts",
634  "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
635  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
636 
637  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useuct",
638  "should uct node selection be used at the beginning of the search?",
639  &heurdata->useuct, TRUE, DEFAULT_USEUCT, NULL, NULL) );
640 
641  return SCIP_OKAY;
642 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2521
#define SCIP_EVENTTYPE_LPSOLVED
Definition: type_event.h:92
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:949
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for SCIP parameter handling
static SCIP_DECL_HEUREXEC(heurExecRins)
Definition: heur_rins.c:450
public methods for node selector plugins
public methods for memory management
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
#define HEUR_PRIORITY
Definition: heur_rins.c:54
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1587
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_MINNODES
Definition: heur_rins.c:63
public solving methods
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:95
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1865
#define FALSE
Definition: def.h:87
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3014
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:315
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3278
#define TRUE
Definition: def.h:86
#define SCIPdebug(x)
Definition: pub_message.h:84
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
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
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
#define HEUR_FREQ
Definition: heur_rins.c:55
#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 EVENTHDLR_NAME
Definition: heur_rins.c:77
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
#define DEFAULT_MINIMPROVE
Definition: heur_rins.c:64
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2613
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1441
#define SCIPerrorMessage
Definition: pub_message.h:55
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
#define HEUR_USESSUBSCIP
Definition: heur_rins.c:59
#define DEFAULT_USELPROWS
Definition: heur_rins.c:69
public methods for event handler plugins and event handlers
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:420
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:164
#define DEFAULT_MAXNODES
Definition: heur_rins.c:62
SCIP_RETCODE SCIPincludeHeurRins(SCIP *scip)
Definition: heur_rins.c:574
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
#define DEFAULT_USEUCT
Definition: heur_rins.c:74
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
Definition: var.c:18284
public methods for problem copies
public methods for primal CIP solutions
#define DEFAULT_LPLIMFAC
Definition: heur_rins.c:67
#define SCIP_CALL(x)
Definition: def.h:384
SCIP_Real SCIPgetLowerbound(SCIP *scip)
static SCIP_DECL_HEURCOPY(heurCopyRins)
Definition: heur_rins.c:395
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1567
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:74
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
#define DEFAULT_MINFIXINGRATE
Definition: heur_rins.c:65
#define HEUR_TIMING
Definition: heur_rins.c:58
static SCIP_RETCODE determineFixings(SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, SCIP_Real minfixingrate, SCIP_Bool *success)
Definition: heur_rins.c:117
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
#define HEUR_MAXDEPTH
Definition: heur_rins.c:57
public data structures and miscellaneous methods
#define DEFAULT_NODESOFS
Definition: heur_rins.c:61
#define SCIP_Bool
Definition: def.h:84
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:277
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:159
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:1021
#define HEUR_DESC
Definition: heur_rins.c:52
#define HEUR_NAME
Definition: heur_rins.c:51
#define DEFAULT_NWAITINGNODES
Definition: heur_rins.c:68
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip_prob.c:1421
LNS heuristic that combines the incumbent with the LP optimum.
#define MAX(x, y)
Definition: tclique_def.h:83
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:478
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:311
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2205
static SCIP_DECL_EVENTEXEC(eventExecRins)
Definition: heur_rins.c:365
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
static SCIP_DECL_HEURINIT(heurInitRins)
Definition: heur_rins.c:430
public methods for the LP relaxation, rows and columns
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
Definition: scip_param.c:652
#define SCIP_REAL_MAX
Definition: def.h:178
public methods for branching rule plugins and branching
public methods for managing events
general public methods
SCIP_Real SCIPgetLPObjval(SCIP *scip)
Definition: scip_lp.c:238
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2304
#define HEUR_DISPCHAR
Definition: heur_rins.c:53
public methods for solutions
public methods for message output
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
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
#define SCIP_Real
Definition: def.h:177
#define HEUR_FREQOFS
Definition: heur_rins.c:56
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:694
public methods for message handling
#define SCIP_Longint
Definition: def.h:162
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3235
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip_solve.c:358
static SCIP_RETCODE wrapperRins(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, SCIP_VAR **vars, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, SCIP_RESULT *result, int nvars, int nfixedvars, SCIP_Longint nnodes)
Definition: heur_rins.c:197
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
#define nnodes
Definition: gastrans.c:65
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip_solve.c:3542
SCIP_Real SCIPgetUpperbound(SCIP *scip)
public methods for primal heuristics
SCIPallocBlockMemory(scip, subsol))
#define SCIP_CALL_ABORT(x)
Definition: def.h:363
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1352
#define DEFAULT_COPYCUTS
Definition: heur_rins.c:71
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Longint SCIPgetNLPs(SCIP *scip)
public methods for global and local (sub)problems
static SCIP_DECL_HEURFREE(heurFreeRins)
Definition: heur_rins.c:409
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1352
#define DEFAULT_NODESQUOT
Definition: heur_rins.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 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 EVENTHDLR_DESC
Definition: heur_rins.c:78
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