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