Scippy

SCIP

Solving Constraint Integer Programs

heur_proximity.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 visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_proximity.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief improvement heuristic which uses an auxiliary objective instead of the original objective function which
19  * is itself added as a constraint to a sub-SCIP instance. The heuristic was presented by Matteo Fischetti
20  * and Michele Monaci.
21  * @author Gregor Hendel
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #include "blockmemshell/memory.h"
27 #include "scip/cons_linear.h"
28 #include "scip/heuristics.h"
29 #include "scip/heur_proximity.h"
30 #include "scip/pub_event.h"
31 #include "scip/pub_heur.h"
32 #include "scip/pub_message.h"
33 #include "scip/pub_misc.h"
34 #include "scip/pub_sol.h"
35 #include "scip/pub_var.h"
36 #include "scip/scip_branch.h"
37 #include "scip/scip_cons.h"
38 #include "scip/scip_copy.h"
39 #include "scip/scip_event.h"
40 #include "scip/scip_general.h"
41 #include "scip/scip_heur.h"
42 #include "scip/scip_lp.h"
43 #include "scip/scip_mem.h"
44 #include "scip/scip_message.h"
45 #include "scip/scip_nlp.h"
46 #include "scip/scip_nodesel.h"
47 #include "scip/scip_numerics.h"
48 #include "scip/scip_param.h"
49 #include "scip/scip_prob.h"
50 #include "scip/scip_sol.h"
51 #include "scip/scip_solve.h"
52 #include "scip/scip_solvingstats.h"
53 #include "scip/scip_timing.h"
54 #include "scip/scip_var.h"
55 #include <string.h>
56 
57 #define HEUR_NAME "proximity"
58 #define HEUR_DESC "heuristic trying to improve the incumbent by an auxiliary proximity objective function"
59 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_LNS
60 #define HEUR_PRIORITY -2000000
61 #define HEUR_FREQ -1
62 #define HEUR_FREQOFS 0
63 #define HEUR_MAXDEPTH -1
64 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
65 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
66 
67 /* event handler properties */
68 #define EVENTHDLR_NAME "Proximity"
69 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic"
70 
71 /* default values for proximity-specific parameters */
72 /* todo refine these values */
73 #define DEFAULT_MAXNODES 10000LL /**< maximum number of nodes to regard in the subproblem */
74 #define DEFAULT_MINIMPROVE 0.02 /**< factor by which proximity should at least improve the incumbent */
75 #define DEFAULT_MINGAP 0.01 /**< minimum primal-dual gap for which the heuristic is executed */
76 #define DEFAULT_MINNODES 1LL /**< minimum number of nodes to regard in the subproblem */
77 #define DEFAULT_MINLPITERS 200LL /**< minimum number of LP iterations to perform in one sub-mip */
78 #define DEFAULT_MAXLPITERS 100000LL /**< maximum number of LP iterations to be performed in the subproblem */
79 #define DEFAULT_NODESOFS 50LL /**< number of nodes added to the contingent of the total nodes */
80 #define DEFAULT_WAITINGNODES 100LL /**< default waiting nodes since last incumbent before heuristic is executed */
81 #define DEFAULT_NODESQUOT 0.1 /**< default quotient of sub-MIP nodes with respect to number of processed nodes*/
82 #define DEFAULT_USELPROWS FALSE /**< should subproblem be constructed based on LP row information? */
83 #define DEFAULT_BINVARQUOT 0.1 /**< default threshold for percentage of binary variables required to start */
84 #define DEFAULT_RESTART TRUE /**< should the heuristic immediately run again on its newly found solution? */
85 #define DEFAULT_USEFINALLP FALSE /**< should the heuristic solve a final LP in case of continuous objective variables? */
86 #define DEFAULT_LPITERSQUOT 0.2 /**< default quotient of sub-MIP LP iterations with respect to LP iterations so far */
87 #define DEFAULT_USEUCT FALSE /**< should uct node selection be used at the beginning of the search? */
88 
89 /*
90  * Data structures
91  */
92 
93 /** primal heuristic data */
94 struct SCIP_HeurData
95 {
96  SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
97  SCIP_Longint minnodes; /**< minimum number of nodes to regard in the subproblem */
98  SCIP_Longint maxlpiters; /**< maximum number of LP iterations to be performed in the subproblem */
99  SCIP_Longint nusedlpiters; /**< number of actually performed LP iterations */
100  SCIP_Longint minlpiters; /**< minimum number of LP iterations to perform in one sub-mip */
101  SCIP_Longint nodesofs; /**< number of nodes added to the contingent of the total nodes */
102  SCIP_Longint usednodes; /**< nodes already used by proximity in earlier calls */
103  SCIP_Longint waitingnodes; /**< waiting nodes since last incumbent before heuristic is executed */
104  SCIP_Real lpitersquot; /**< quotient of sub-MIP LP iterations with respect to LP iterations so far */
105  SCIP_Real minimprove; /**< factor by which proximity should at least improve the incumbent */
106  SCIP_Real mingap; /**< minimum primal-dual gap for which the heuristic is executed */
107  SCIP_Real nodesquot; /**< quotient of sub-MIP nodes with respect to number of processed nodes */
108  SCIP_Real binvarquot; /**< threshold for percantage of binary variables required to start */
109 
110  SCIP* subscip; /**< the subscip used by the heuristic */
111  SCIP_HASHMAP* varmapfw; /**< map between scip variables and subscip variables */
112  SCIP_VAR** subvars; /**< variables in subscip */
113  SCIP_CONS* objcons; /**< the objective cutoff constraint of the subproblem */
114 
115  int nsubvars; /**< the number of subvars */
116  int lastsolidx; /**< index of last solution on which the heuristic was processed */
117  int subprobidx; /**< counter for the subproblem index to be solved by proximity */
118 
119  SCIP_Bool uselprows; /**< should subproblem be constructed based on LP row information? */
120  SCIP_Bool restart; /**< should the heuristic immediately run again on its newly found solution? */
121  SCIP_Bool usefinallp; /**< should the heuristic solve a final LP in case of continuous objective variables? */
122  SCIP_Bool useuct; /**< should uct node selection be used at the beginning of the search? */
123 };
124 
125 
126 /*
127  * Local methods
128  */
129 
130 /** optimizes the continuous variables in an LP diving by fixing all integer variables to the given solution values */
131 static
133  SCIP* scip, /**< SCIP data structure */
134  SCIP_SOL* sol, /**< candidate solution for which continuous variables should be optimized */
135  SCIP_Bool* success /**< was the dive successful? */
136  )
137 {
138  SCIP_VAR** vars;
139  SCIP_RETCODE retstat;
140 
141  int v;
142  int nvars;
143  int ncontvars;
144  int nintvars;
145 
146  SCIP_Bool lperror;
147  SCIP_Bool requiresnlp;
148 
149  assert(success != NULL);
150 
151  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, &ncontvars) );
152 
153  nintvars = nvars - ncontvars;
154 
155  /**@todo in case of an MINLP, if SCIPisNLPConstructed() is TRUE rather solve the NLP instead of the LP */
156  requiresnlp = SCIPisNLPConstructed(scip);
157  if( requiresnlp || ncontvars == 0 )
158  return SCIP_OKAY;
159 
160  /* start diving to calculate the LP relaxation */
161  SCIP_CALL( SCIPstartDive(scip) );
162 
163  /* set the bounds of the variables: fixed for integers, global bounds for continuous */
164  for( v = 0; v < nvars; ++v )
165  {
166  if( SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_COLUMN )
167  {
168  SCIP_CALL( SCIPchgVarLbDive(scip, vars[v], SCIPvarGetLbGlobal(vars[v])) );
169  SCIP_CALL( SCIPchgVarUbDive(scip, vars[v], SCIPvarGetUbGlobal(vars[v])) );
170  }
171  }
172 
173  /* apply this after global bounds to not cause an error with intermediate empty domains */
174  for( v = 0; v < nintvars; ++v )
175  {
176  if( SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_COLUMN )
177  {
178  SCIP_Real solval;
179 
180  solval = SCIPgetSolVal(scip, sol, vars[v]);
181  SCIP_CALL( SCIPchgVarLbDive(scip, vars[v], solval) );
182  SCIP_CALL( SCIPchgVarUbDive(scip, vars[v], solval) );
183  }
184  }
185 
186  /* solve LP */
187  SCIPdebugMsg(scip, " -> old LP iterations: %" SCIP_LONGINT_FORMAT "\n", SCIPgetNLPIterations(scip));
188 
189  /* Errors in the LP solver should not kill the overall solving process, if the LP is just needed for a heuristic.
190  * Hence in optimized mode, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
191  */
192  retstat = SCIPsolveDiveLP(scip, -1, &lperror, NULL);
193  if( retstat != SCIP_OKAY )
194  {
195 #ifdef NDEBUG
196  SCIPwarningMessage(scip, "Error while solving LP in Proximity heuristic; LP solve terminated with code <%d>\n",retstat);
197 #else
198  SCIP_CALL( retstat );
199 #endif
200  }
201 
202  SCIPdebugMsg(scip, " -> new LP iterations: %" SCIP_LONGINT_FORMAT "\n", SCIPgetNLPIterations(scip));
203  SCIPdebugMsg(scip, " -> error=%u, status=%d\n", lperror, SCIPgetLPSolstat(scip));
204  if( !lperror && SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_OPTIMAL )
205  {
206  SCIP_CALL( SCIPlinkLPSol(scip, sol) );
207  SCIP_CALL( SCIPtrySol(scip, sol, FALSE, FALSE, TRUE, TRUE, TRUE, success) );
208  }
209 
210  /* terminate diving mode */
211  SCIP_CALL( SCIPendDive(scip) );
212 
213  return SCIP_OKAY;
214 }
215 
216 /** creates a new solution for the original problem by copying the solution of the subproblem */
217 static
219  SCIP* scip, /**< original SCIP data structure */
220  SCIP* subscip, /**< SCIP structure of the subproblem */
221  SCIP_VAR** subvars, /**< the variables of the subproblem */
222  SCIP_HEUR* heur, /**< proximity heuristic structure */
223  SCIP_SOL* subsol, /**< solution of the subproblem */
224  SCIP_Bool usefinallp, /**< should continuous variables be optimized by a final LP */
225  SCIP_Bool* success /**< used to store whether new solution was found or not */
226  )
227 {
228  SCIP_VAR** vars; /* the original problem's variables */
229  int nvars; /* the original problem's number of variables */
230  int ncontvars; /* the original problem's number of continuous variables */
231  SCIP_Real* subsolvals; /* solution values of the subproblem */
232  SCIP_SOL* newsol; /* solution to be created for the original problem */
233  int i;
234 
235  assert(scip != NULL);
236  assert(subscip != NULL);
237  assert(subvars != NULL);
238  assert(subsol != NULL);
239  assert(success != NULL);
240 
241  /* get variables' data */
242  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, &ncontvars) );
243 
244  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
245 
246  /* copy the solution */
247  for( i = 0; i < nvars; ++i )
248  {
249  if( subvars[i] == NULL )
250  subsolvals[i] = MIN(MAX(0.0, SCIPvarGetLbLocal(vars[i])), SCIPvarGetUbLocal(vars[i])); /*lint !e666*/
251  else
252  subsolvals[i] = SCIPgetSolVal(subscip, subsol, subvars[i]);
253  }
254 
255  /* create new solution for the original problem */
256  SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
257  SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
258 
259  *success = FALSE;
260 
261  /* solve an LP with all integer variables fixed to improve solution quality */
262  if( ncontvars > 0 && usefinallp && SCIPisLPConstructed(scip) )
263  {
264  int v;
265  int ncontobjvars = 0; /* does the problem instance have continuous variables with nonzero objective coefficients? */
266  SCIP_Real sumofobjsquares = 0.0;
267 
268  /* check if continuous variables with nonzero objective coefficient are present */
269  for( v = nvars - 1; v >= nvars - ncontvars; --v )
270  {
271  SCIP_VAR* var;
272 
273  var = vars[v];
274  assert(vars[v] != NULL);
275  assert(!SCIPvarIsIntegral(var));
276 
277  if( SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN && !SCIPisZero(scip, SCIPvarGetObj(var)) )
278  {
279  ++ncontobjvars;
280  sumofobjsquares += SCIPvarGetObj(var) * SCIPvarGetObj(var);
281  }
282  }
283 
284  SCIPstatisticMessage(" Continuous Objective variables: %d, Euclidean OBJ: %g total, %g continuous\n", ncontobjvars, SCIPgetObjNorm(scip), sumofobjsquares);
285 
286  /* solve a final LP to optimize solution values of continuous problem variables */
287  SCIPstatisticMessage("Solution Value before LP resolve: %g\n", SCIPgetSolOrigObj(scip, newsol));
288  SCIP_CALL( solveLp(scip, newsol, success) );
289 
290  /* if the LP solve was not successful, reset the solution */
291  if( !*success )
292  {
293  for( v = nvars - 1; v >= nvars - ncontvars; --v )
294  {
295  SCIP_CALL( SCIPsetSolVal(scip, newsol, vars[v], subsolvals[v]) );
296  }
297  }
298  }
299 
300  /* try to add new solution to SCIP and free it immediately */
301  if( !*success )
302  {
303  SCIP_CALL( SCIPtrySol(scip, newsol, FALSE, FALSE, TRUE, TRUE, TRUE, success) );
304  }
305  SCIP_CALL( SCIPfreeSol(scip, &newsol) );
306 
307  SCIPfreeBufferArray(scip, &subsolvals);
308 
309  return SCIP_OKAY;
310 }
311 
312 /** sets solving parameters for the subproblem created by the heuristic */
313 static
315  SCIP_HEURDATA* heurdata, /**< heuristic data structure */
316  SCIP* subscip /**< copied SCIP data structure */
317  )
318 {
319  assert(subscip != NULL);
320 
321  /* do not abort subproblem on CTRL-C */
322  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
323 
324 #ifdef SCIP_DEBUG
325  /* for debugging, enable full output */
326  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
327  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
328 #else
329  /* disable statistic timing inside sub SCIP and output to console */
330  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
331  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
332 #endif
333 
334  /* forbid recursive call of heuristics and separators solving sub-SCIPs */
335  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
336 
337  /* use restart dfs node selection */
338  if( SCIPfindNodesel(subscip, "restartdfs") != NULL && !SCIPisParamFixed(subscip, "nodeselection/restartdfs/stdpriority") )
339  {
340  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/restartdfs/stdpriority", INT_MAX/4) );
341  }
342 
343  /* activate uct node selection at the top of the tree */
344  if( heurdata->useuct && SCIPfindNodesel(subscip, "uct") != NULL && !SCIPisParamFixed(subscip, "nodeselection/uct/stdpriority") )
345  {
346  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/uct/stdpriority", INT_MAX/2) );
347  }
348 
349  /* disable expensive presolving
350  * todo maybe presolving can be entirely turned off here - parameter???
351  */
353 
354  /* SCIP_CALL( SCIPsetPresolving(scip, SCIP_PARAMSETTING_OFF, TRUE) ); */
355  if( !SCIPisParamFixed(subscip, "presolving/maxrounds") )
356  {
357  SCIP_CALL( SCIPsetIntParam(subscip, "presolving/maxrounds", 50) );
358  }
359 
360  /* disable cutting plane separation */
362 
363  /* todo: check branching rule in sub-SCIP */
364  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
365  {
366  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
367  }
368 
369  /* disable feasibility pump and fractional diving */
370  if( !SCIPisParamFixed(subscip, "heuristics/feaspump/freq") )
371  {
372  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/feaspump/freq", -1) );
373  }
374  if( !SCIPisParamFixed(subscip, "heuristics/fracdiving/freq") )
375  {
376  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/fracdiving/freq", -1) );
377  }
378 
379  /* todo check if
380  * SCIP_CALL( SCIPsetEmphasis(subscip, SCIP_PARAMEMPHASIS_FEASIBILITY, TRUE) );
381  * improves performance */
382 
383  return SCIP_OKAY;
384 }
385 
386 /** frees the subproblem */
387 static
389  SCIP* scip, /**< SCIP data structure */
390  SCIP_HEURDATA* heurdata /**< heuristic data */
391  )
392 {
393  /* free remaining memory from heuristic execution */
394  if( heurdata->subscip != NULL )
395  {
396  assert(heurdata->varmapfw != NULL);
397  assert(heurdata->subvars != NULL);
398  assert(heurdata->objcons != NULL);
399 
400  SCIPdebugMsg(scip, "Freeing subproblem of proximity heuristic\n");
401  SCIPfreeBlockMemoryArray(scip, &heurdata->subvars, heurdata->nsubvars);
402  SCIPhashmapFree(&heurdata->varmapfw);
403  SCIP_CALL( SCIPreleaseCons(heurdata->subscip, &heurdata->objcons) );
404  SCIP_CALL( SCIPfree(&heurdata->subscip) );
405 
406  heurdata->subscip = NULL;
407  heurdata->varmapfw = NULL;
408  heurdata->subvars = NULL;
409  heurdata->objcons = NULL;
410  }
411  return SCIP_OKAY;
412 }
413 
414 /* ---------------- Callback methods of event handler ---------------- */
415 
416 /** exec the event handler
417  *
418  * We interrupt the solution process.
419  */
420 static
421 SCIP_DECL_EVENTEXEC(eventExecProximity)
422 {
423  SCIP_HEURDATA* heurdata;
424 
425  assert(eventhdlr != NULL);
426  assert(eventdata != NULL);
427  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
428  assert(event != NULL);
430 
431  heurdata = (SCIP_HEURDATA*)eventdata;
432  assert(heurdata != NULL);
433 
434  /* interrupt solution process of sub-SCIP
435  * todo adjust interruption limit */
436  if( SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_ITERLIMIT || SCIPgetNLPIterations(scip) >= heurdata->maxlpiters )
437  {
439  }
440 
441  return SCIP_OKAY;
442 }
443 
444 
445 /* ---------------- Callback methods of primal heuristic ---------------- */
446 
447 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
448 static
449 SCIP_DECL_HEURCOPY(heurCopyProximity)
450 { /*lint --e{715}*/
451  assert(scip != NULL);
452  assert(heur != NULL);
453  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
454 
455  /* call inclusion method of primal heuristic */
457 
458  return SCIP_OKAY;
459 }
460 
461 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
462 static
463 SCIP_DECL_HEURFREE(heurFreeProximity)
464 { /*lint --e{715}*/
465  SCIP_HEURDATA* heurdata;
466 
467  assert( heur != NULL );
468  assert( scip != NULL );
469 
470  /* get heuristic data */
471  heurdata = SCIPheurGetData(heur);
472  assert( heurdata != NULL );
473 
474  /* free heuristic data */
475  SCIPfreeBlockMemory(scip, &heurdata);
476  SCIPheurSetData(heur, NULL);
477 
478  return SCIP_OKAY;
479 }
480 
481 
482 /** initialization method of primal heuristic (called after problem was transformed) */
483 static
484 SCIP_DECL_HEURINIT(heurInitProximity)
485 { /*lint --e{715}*/
486  SCIP_HEURDATA* heurdata;
487 
488  assert( heur != NULL );
489  assert( scip != NULL );
490 
491  /* get heuristic data */
492  heurdata = SCIPheurGetData(heur);
493  assert( heurdata != NULL );
494 
495  /* initialize data */
496  heurdata->usednodes = 0LL;
497  heurdata->lastsolidx = -1;
498  heurdata->nusedlpiters = 0LL;
499  heurdata->subprobidx = 0;
500 
501  heurdata->subscip = NULL;
502  heurdata->varmapfw = NULL;
503  heurdata->subvars = NULL;
504  heurdata->objcons = NULL;
505 
506  heurdata->nsubvars = 0;
507 
508  return SCIP_OKAY;
509 }
510 
511 /** solution process exiting method of proximity heuristic */
512 static
513 SCIP_DECL_HEUREXITSOL(heurExitsolProximity)
514 {
515  SCIP_HEURDATA* heurdata;
516 
517  assert( heur != NULL );
518  assert( scip != NULL );
519 
520  /* get heuristic data */
521  heurdata = SCIPheurGetData(heur);
522  assert( heurdata != NULL );
523 
524  SCIP_CALL( deleteSubproblem(scip, heurdata) );
525 
526  assert(heurdata->subscip == NULL && heurdata->varmapfw == NULL && heurdata->subvars == NULL && heurdata->objcons == NULL);
527 
528  return SCIP_OKAY;
529 }
530 
531 /** execution method of primal heuristic */
532 static
533 SCIP_DECL_HEUREXEC(heurExecProximity)
534 { /*lint --e{715}*/
535  SCIP_HEURDATA* heurdata; /* heuristic's data */
536  SCIP_Longint nnodes; /* number of stalling nodes for the subproblem */
537  SCIP_Longint nlpiters; /* lp iteration limit for the subproblem */
538  SCIP_Bool foundsol = FALSE;
539 
540  assert(heur != NULL);
541  assert(scip != NULL);
542  assert(result != NULL);
543 
544  *result = SCIP_DIDNOTRUN;
545 
546  /* get heuristic data */
547  heurdata = SCIPheurGetData(heur);
548  assert(heurdata != NULL);
549 
550  /* do not run heuristic when there are only few binary varables */
551  if( SCIPgetNBinVars(scip) < heurdata->binvarquot * SCIPgetNVars(scip) )
552  return SCIP_OKAY;
553 
554  /* calculate branching node limit for sub problem */
555  /* todo maybe treat root node differently */
556  nnodes = (SCIP_Longint) (heurdata->nodesquot * SCIPgetNNodes(scip));
557  nnodes += heurdata->nodesofs;
558 
559  /* determine the node and LP iteration limit for the solve of the sub-SCIP */
560  nnodes -= heurdata->usednodes;
561  nnodes = MIN(nnodes, heurdata->maxnodes);
562 
563  nlpiters = (SCIP_Longint) (heurdata->lpitersquot * SCIPgetNRootFirstLPIterations(scip));
564  nlpiters = MIN(nlpiters, heurdata->maxlpiters);
565 
566  /* check whether we have enough nodes left to call subproblem solving */
567  if( nnodes < heurdata->minnodes )
568  {
569  SCIPdebugMsg(scip, "skipping proximity: nnodes=%" SCIP_LONGINT_FORMAT ", minnodes=%" SCIP_LONGINT_FORMAT "\n", nnodes, heurdata->minnodes);
570  return SCIP_OKAY;
571  }
572 
573  /* do not run proximity, if the problem does not have an objective function anyway */
574  if( SCIPgetNObjVars(scip) == 0 )
575  {
576  SCIPdebugMsg(scip, "skipping proximity: pure feasibility problem anyway\n");
577  return SCIP_OKAY;
578  }
579 
580  do
581  {
582  /* main loop of proximity: in every iteration, a new subproblem is set up and solved until no improved solution
583  * is found or one of the heuristic limits on nodes or LP iterations is hit
584  * heuristic performs only one iteration if restart parameter is set to FALSE
585  */
586  SCIP_Longint nusednodes = 0LL;
587  SCIP_Longint nusedlpiters = 0LL;
588 
589  nlpiters = MAX(nlpiters, heurdata->minlpiters);
590 
591  /* define and solve the proximity subproblem */
592  SCIP_CALL( SCIPapplyProximity(scip, heur, result, heurdata->minimprove, nnodes, nlpiters, &nusednodes, &nusedlpiters, FALSE) );
593 
594  /* adjust node limit and LP iteration limit for future iterations */
595  assert(nusednodes <= nnodes);
596  heurdata->usednodes += nusednodes;
597  nnodes -= nusednodes;
598 
599  nlpiters -= nusedlpiters;
600  heurdata->nusedlpiters += nusedlpiters;
601 
602  /* memorize if a new solution has been found in at least one iteration */
603  if( *result == SCIP_FOUNDSOL )
604  foundsol = TRUE;
605  }
606  while( *result == SCIP_FOUNDSOL && heurdata->restart && !SCIPisStopped(scip) && nnodes > 0 );
607 
608  /* reset result pointer if solution has been found in previous iteration */
609  if( foundsol )
610  *result = SCIP_FOUNDSOL;
611 
612  /* free the occupied memory */
613  if( heurdata->subscip != NULL )
614  {
615  /* just for testing the library method, in debug mode, we call the wrapper method for the actual delete method */
616 #ifndef NDEBUG
618 #else
619  SCIP_CALL( deleteSubproblem(scip, heurdata) );
620 #endif
621  }
622  return SCIP_OKAY;
623 }
624 
625 
626 /*
627  * primal heuristic specific interface methods
628  */
629 
630 /** frees the sub-MIP created by proximity */
632  SCIP* scip /** SCIP data structure */
633  )
634 {
635  SCIP_HEUR* heur;
636  SCIP_HEURDATA* heurdata;
637 
638  assert(scip != NULL);
639 
640  heur = SCIPfindHeur(scip, HEUR_NAME);
641  assert(heur != NULL);
642 
643  heurdata = SCIPheurGetData(heur);
644  if( heurdata != NULL )
645  {
646  SCIP_CALL( deleteSubproblem(scip, heurdata) );
647  }
648 
649  return SCIP_OKAY;
650 }
651 
652 /** main procedure of the proximity heuristic, creates and solves a sub-SCIP
653  *
654  * @note The method can be applied in an iterative way, keeping the same subscip in between. If the @p freesubscip
655  * parameter is set to FALSE, the heuristic will keep the subscip data structures. Always set this parameter
656  * to TRUE, or call SCIPdeleteSubproblemProximity() afterwards.
657  */
659  SCIP* scip, /**< original SCIP data structure */
660  SCIP_HEUR* heur, /**< heuristic data structure */
661  SCIP_RESULT* result, /**< result data structure */
662  SCIP_Real minimprove, /**< factor by which proximity should at least improve the incumbent */
663  SCIP_Longint nnodes, /**< node limit for the subproblem */
664  SCIP_Longint nlpiters, /**< LP iteration limit for the subproblem */
665  SCIP_Longint* nusednodes, /**< pointer to store number of used nodes in subscip */
666  SCIP_Longint* nusedlpiters, /**< pointer to store number of used LP iterations in subscip */
667  SCIP_Bool freesubscip /**< should the created sub-MIP be freed at the end of the method? */
668  )
669 {
670  SCIP* subscip; /* the subproblem created by proximity */
671  SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
672  SCIP_VAR** vars; /* original problem's variables */
673  SCIP_VAR** subvars; /* subproblem's variables */
674  SCIP_HEURDATA* heurdata; /* heuristic's private data structure */
675  SCIP_EVENTHDLR* eventhdlr; /* event handler for LP events */
676 
677  SCIP_SOL* incumbent;
678  SCIP_CONS* objcons;
679  SCIP_Longint iterlim;
680 
681  SCIP_Real large;
682  SCIP_Real inf;
683 
684  SCIP_Real bestobj;
685  SCIP_Real objcutoff;
686  SCIP_Real lowerbound;
687 
688  int nvars; /* number of original problem's variables */
689  int nfixedvars;
690  int nsubsols;
691  int solidx;
692  int i;
693 
694  SCIP_Bool valid;
695  SCIP_Bool success;
696 
697  assert(scip != NULL);
698  assert(heur != NULL);
699  assert(result != NULL);
700 
701  assert(nnodes >= 0);
702  assert(0.0 <= minimprove && minimprove <= 1.0);
703 
704  *result = SCIP_DIDNOTRUN;
705 
706  /* get heuristic data */
707  heurdata = SCIPheurGetData(heur);
708  assert(heurdata != NULL);
709 
710  /* only call the heuristic if we have an incumbent */
711  if( SCIPgetNSolsFound(scip) == 0 )
712  return SCIP_OKAY;
713 
714  /* do not use heuristic on problems without binary variables */
715  if( SCIPgetNBinVars(scip) == 0 )
716  return SCIP_OKAY;
717 
718  incumbent = SCIPgetBestSol(scip);
719  assert(incumbent != NULL);
720 
721  /* make sure that the incumbent is valid for the transformed space, otherwise terminate */
722  if( SCIPsolIsOriginal(incumbent) )
723  return SCIP_OKAY;
724 
725  solidx = SCIPsolGetIndex(incumbent);
726 
727  if( heurdata->lastsolidx == solidx )
728  return SCIP_OKAY;
729 
730  /* only call heuristic, if the best solution does not come from trivial heuristic */
731  if( SCIPsolGetHeur(incumbent) != NULL && strcmp(SCIPheurGetName(SCIPsolGetHeur(incumbent)), "trivial") == 0 )
732  return SCIP_OKAY;
733 
734  /* waitingnodes parameter defines the minimum number of nodes to wait before a new incumbent is processed */
735  if( SCIPgetNNodes(scip) > 1 && SCIPgetNNodes(scip) - SCIPsolGetNodenum(incumbent) < heurdata->waitingnodes )
736  return SCIP_OKAY;
737 
738  bestobj = SCIPgetSolTransObj(scip, incumbent);
739  lowerbound = SCIPgetLowerbound(scip);
740 
741  /* use knowledge about integrality of objective to round up lower bound */
742  if( SCIPisObjIntegral(scip) )
743  {
744  SCIPdebugMsg(scip, " Rounding up lower bound: %f --> %f \n", lowerbound, SCIPfeasCeil(scip, lowerbound));
745  lowerbound = SCIPfeasCeil(scip, lowerbound);
746  }
747 
748  /* do not trigger heuristic if primal and dual bound are already close together */
749  if( SCIPisFeasLE(scip, bestobj, lowerbound) || SCIPgetGap(scip) <= heurdata->mingap )
750  return SCIP_OKAY;
751 
752  /* calculate the minimum improvement for a heuristic solution in terms of the distance between incumbent objective
753  * and the lower bound */
754  if( SCIPisInfinity(scip, REALABS(lowerbound)) )
755  {
756  if( SCIPisZero(scip, bestobj) )
757  objcutoff = bestobj - 1;
758  else
759  objcutoff = (1 - minimprove) * bestobj;
760  }
761  else
762  objcutoff = minimprove * lowerbound + (1 - minimprove) * (bestobj);
763 
764  /* use integrality of the objective function to round down (and thus strengthen) the objective cutoff */
765  if( SCIPisObjIntegral(scip) )
766  objcutoff = SCIPfeasFloor(scip, objcutoff);
767 
768  if( SCIPisFeasLT(scip, objcutoff, lowerbound) )
769  objcutoff = lowerbound;
770 
771  /* exit execution if the right hand side of the objective constraint does not change (suggests that the heuristic
772  * was not successful in a previous iteration) */
773  if( heurdata->objcons != NULL && SCIPisFeasEQ(scip, SCIPgetRhsLinear(heurdata->subscip, heurdata->objcons), objcutoff) )
774  return SCIP_OKAY;
775 
776  /* check whether there is enough time and memory left */
777  SCIP_CALL( SCIPcheckCopyLimits(scip, &valid) );
778 
779  if( ! valid )
780  return SCIP_OKAY;
781 
782  *result = SCIP_DIDNOTFIND;
783 
784  heurdata->lastsolidx = solidx;
785 
786  /* get variable data */
787  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
788 
789  /* create a subscip and copy the original scip instance into it */
790  if( heurdata->subscip == NULL )
791  {
792  assert(heurdata->varmapfw == NULL);
793  assert(heurdata->objcons == NULL);
794 
795  /* initialize the subproblem */
796  SCIP_CALL( SCIPcreate(&subscip) );
797 
798  /* create the variable mapping hash map */
799  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), nvars) );
800  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &subvars, nvars) );
801 
802  /* copy complete SCIP instance */
803  valid = FALSE;
804 
805  /* create a problem copy as sub SCIP */
806  SCIP_CALL( SCIPcopyLargeNeighborhoodSearch(scip, subscip, varmapfw, "proximity", NULL, NULL, 0, heurdata->uselprows, TRUE,
807  &success, &valid) );
808 
809  SCIPdebugMsg(scip, "Copying the SCIP instance was %s complete.\n", valid ? "" : "not ");
810 
811  /* create event handler for LP events */
812  eventhdlr = NULL;
813  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecProximity, NULL) );
814  if( eventhdlr == NULL )
815  {
816  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
817  return SCIP_PLUGINNOTFOUND;
818  }
819 
820  /* set up parameters for the copied instance */
821  SCIP_CALL( setupSubproblem(heurdata, subscip) );
822 
823  /* create the objective constraint in the sub scip, first without variables and values which will be added later */
824  SCIP_CALL( SCIPcreateConsBasicLinear(subscip, &objcons, "objbound_of_origscip", 0, NULL, NULL, -SCIPinfinity(subscip), SCIPinfinity(subscip)) );
825 
826  /* determine large value to set variable bounds to, safe-guard to avoid fixings to infinite values */
827  large = SCIPinfinity(scip);
828  if( !SCIPisInfinity(scip, 0.1 / SCIPfeastol(scip)) )
829  large = 0.1 / SCIPfeastol(scip);
830  inf = SCIPinfinity(subscip);
831 
832  /* get variable image and change objective to proximity function (Manhattan distance) in sub-SCIP */
833  for( i = 0; i < nvars; i++ )
834  {
835  SCIP_Real adjustedbound;
836  SCIP_Real lb;
837  SCIP_Real ub;
838 
839  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
840 
841  if( subvars[i] == NULL )
842  continue;
843 
844  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], 0.0) );
845 
846  lb = SCIPvarGetLbGlobal(subvars[i]);
847  ub = SCIPvarGetUbGlobal(subvars[i]);
848 
849  /* adjust infinite bounds in order to avoid that variables with non-zero objective
850  * get fixed to infinite value in proximity subproblem
851  */
852  if( SCIPisInfinity(subscip, ub) )
853  {
854  adjustedbound = MAX(large, lb + large);
855  adjustedbound = MIN(adjustedbound, inf);
856  SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[i], adjustedbound) );
857  }
858  if( SCIPisInfinity(subscip, -lb) )
859  {
860  adjustedbound = MIN(-large, ub - large);
861  adjustedbound = MAX(adjustedbound, -inf);
862  SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[i], adjustedbound) );
863  }
864 
865  /* add all nonzero objective coefficients to the objective constraint */
866  if( !SCIPisFeasZero(subscip, SCIPvarGetObj(vars[i])) )
867  {
868  SCIP_CALL( SCIPaddCoefLinear(subscip, objcons, subvars[i], SCIPvarGetObj(vars[i])) );
869  }
870  }
871 
872  /* add objective constraint to the subscip */
873  SCIP_CALL( SCIPaddCons(subscip, objcons) );
874  }
875  else
876  {
877  /* the instance, event handler, hash map and variable array were already copied in a previous iteration
878  * and stored in heuristic data
879  */
880  assert(heurdata->varmapfw != NULL);
881  assert(heurdata->subvars != NULL);
882  assert(heurdata->objcons != NULL);
883 
884  subscip = heurdata->subscip;
885  varmapfw = heurdata->varmapfw;
886  subvars = heurdata->subvars;
887  objcons = heurdata->objcons;
888 
889  eventhdlr = SCIPfindEventhdlr(subscip, EVENTHDLR_NAME);
890  assert(eventhdlr != NULL);
891  }
892 
893  SCIP_CALL( SCIPchgRhsLinear(subscip, objcons, objcutoff) );
894 
895  for( i = 0; i < SCIPgetNBinVars(scip); ++i )
896  {
897  SCIP_Real solval;
898 
899  if( subvars[i] == NULL )
900  continue;
901 
902  /* objective coefficients are only set for binary variables of the problem */
903  assert(SCIPvarIsBinary(subvars[i]));
904 
905  solval = SCIPgetSolVal(scip, incumbent, vars[i]);
906  assert(SCIPisFeasGE(scip, solval, 0.0));
907  assert(SCIPisFeasLE(scip, solval, 1.0));
908  assert(SCIPisFeasIntegral(scip, solval));
909 
910  if( solval < 0.5 )
911  {
912  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], 1.0) );
913  }
914  else
915  {
916  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], -1.0) );
917  }
918  }
919 
920  /* set limits for the subproblem */
921  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
922  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nnodes) );
923  SCIP_CALL( SCIPsetIntParam(subscip, "limits/solutions", 1) );
924 
925  /* restrict LP iterations */
926  /* todo set iterations limit depending on the number of iterations of the original problem root */
927  iterlim = nlpiters;
928  SCIP_CALL( SCIPsetLongintParam(subscip, "lp/iterlim", MAX(1, iterlim / MIN(10, nnodes))) );
929  SCIP_CALL( SCIPsetLongintParam(subscip, "lp/rootiterlim", iterlim) );
930 
931  /* catch LP events of sub-SCIP */
932  SCIP_CALL( SCIPtransformProb(subscip) );
933  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_NODESOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
934 
935  SCIPstatisticMessage("solving subproblem at Node: %" SCIP_LONGINT_FORMAT " "
936  "nnodes: %" SCIP_LONGINT_FORMAT " "
937  "iterlim: %" SCIP_LONGINT_FORMAT "\n", SCIPgetNNodes(scip), nnodes, iterlim);
938 
939  /* solve the subproblem with all previously adjusted parameters */
940  nfixedvars = SCIPgetNFixedVars(subscip);
941 
942  SCIP_CALL( SCIPpresolve(subscip) );
943 
944  nfixedvars = SCIPgetNFixedVars(subscip) - nfixedvars;
945  assert(nfixedvars >= 0);
946  SCIPstatisticMessage("presolve fixings %d: %d\n", ++(heurdata->subprobidx), nfixedvars);
947 
948  /* errors in solving the subproblem should not kill the overall solving process;
949  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
950  */
951  SCIP_CALL_ABORT( SCIPsolve(subscip) );
952 
953  /* print solving statistics of subproblem if we are in SCIP's debug mode */
955  SCIPstatisticMessage("solve of subscip %d:"
956  "usednodes: %" SCIP_LONGINT_FORMAT " "
957  "lp iters: %" SCIP_LONGINT_FORMAT " "
958  "root iters: %" SCIP_LONGINT_FORMAT " "
959  "Presolving Time: %.2f\n", heurdata->subprobidx,
961 
962  SCIPstatisticMessage("Solving Time %d: %.2f\n", heurdata->subprobidx, SCIPgetSolvingTime(subscip) );
963 
964  /* drop LP events of sub-SCIP */
965  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_NODESOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
966 
967  /* keep track of relevant information for future runs of heuristic */
968  if( nusednodes != NULL )
969  *nusednodes = SCIPgetNNodes(subscip);
970  if( nusedlpiters != NULL )
971  *nusedlpiters = SCIPgetNLPIterations(subscip);
972 
973  /* check whether a solution was found */
974  nsubsols = SCIPgetNSols(subscip);
975  incumbent = SCIPgetBestSol(subscip);
976  assert(nsubsols == 0 || incumbent != NULL);
977 
978  SCIPstatisticMessage("primal bound before subproblem %d: %g\n", heurdata->subprobidx, SCIPgetPrimalbound(scip));
979  if( nsubsols > 0 )
980  {
981  /* try to translate the sub problem solution to the original scip instance */
982  success = FALSE;
983  SCIP_CALL( createNewSol(scip, subscip, subvars, heur, incumbent, heurdata->usefinallp, &success) );
984 
985  if( success )
986  *result = SCIP_FOUNDSOL;
987  }
988  SCIPstatisticMessage("primal bound after subproblem %d: %g\n", heurdata->subprobidx, SCIPgetPrimalbound(scip));
989 
990  /* free the transformed subproblem data */
991  SCIP_CALL( SCIPfreeTransform(subscip) );
992 
993  /* save subproblem in heuristic data for subsequent runs if it has been successful, otherwise free subproblem */
994  heurdata->subscip = subscip;
995  heurdata->varmapfw = varmapfw;
996  heurdata->subvars = subvars;
997  heurdata->objcons = objcons;
998  heurdata->nsubvars = nvars;
999 
1000  /* delete the sub problem */
1001  if( freesubscip )
1002  {
1003  SCIP_CALL( deleteSubproblem(scip, heurdata) );
1004  }
1005 
1006  return SCIP_OKAY;
1007 }
1008 
1009 
1010 /** creates the proximity primal heuristic and includes it in SCIP */
1012  SCIP* scip /**< SCIP data structure */
1013  )
1014 {
1015  SCIP_HEURDATA* heurdata;
1016  SCIP_HEUR* heur = NULL;
1017 
1018  /* create heuristic data */
1019  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
1020 
1021  /* include primal heuristic */
1022  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
1024  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecProximity, heurdata) );
1025  assert(heur != NULL);
1026 
1027  /* set non-NULL pointers to callback methods */
1028  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyProximity) );
1029  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeProximity) );
1030  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitProximity) );
1031  SCIP_CALL( SCIPsetHeurExitsol(scip, heur, heurExitsolProximity) );
1032 
1033  /* add proximity primal heuristic parameters */
1034  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
1035  "should subproblem be constructed based on LP row information?",
1036  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
1037 
1038  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/restart",
1039  "should the heuristic immediately run again on its newly found solution?",
1040  &heurdata->restart, TRUE, DEFAULT_RESTART, NULL, NULL) );
1041 
1042  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/usefinallp",
1043  "should the heuristic solve a final LP in case of continuous objective variables?",
1044  &heurdata->usefinallp, TRUE, DEFAULT_USEFINALLP, NULL, NULL) );
1045 
1046  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
1047  "maximum number of nodes to regard in the subproblem",
1048  &heurdata->maxnodes, TRUE,DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1049 
1050  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
1051  "number of nodes added to the contingent of the total nodes",
1052  &heurdata->nodesofs, TRUE, DEFAULT_NODESOFS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1053 
1054  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minnodes",
1055  "minimum number of nodes required to start the subproblem",
1056  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1057 
1058  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxlpiters",
1059  "maximum number of LP iterations to be performed in the subproblem",
1060  &heurdata->maxlpiters, TRUE, DEFAULT_MAXLPITERS, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
1061 
1062  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minlpiters",
1063  "minimum number of LP iterations performed in subproblem",
1064  &heurdata->minlpiters, TRUE, DEFAULT_MINLPITERS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1065 
1066  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/waitingnodes",
1067  "waiting nodes since last incumbent before heuristic is executed",
1068  &heurdata->waitingnodes, TRUE, DEFAULT_WAITINGNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1069 
1070  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
1071  "factor by which proximity should at least improve the incumbent",
1072  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
1073 
1074  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
1075  "sub-MIP node limit w.r.t number of original nodes",
1076  &heurdata->nodesquot, TRUE, DEFAULT_NODESQUOT, 0.0, SCIPinfinity(scip), NULL, NULL) );
1077 
1078  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/binvarquot",
1079  "threshold for percentage of binary variables required to start",
1080  &heurdata->binvarquot, TRUE, DEFAULT_BINVARQUOT, 0.0, 1.0, NULL, NULL) );
1081 
1082  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/lpitersquot",
1083  "quotient of sub-MIP LP iterations with respect to LP iterations so far",
1084  &heurdata->lpitersquot, TRUE, DEFAULT_LPITERSQUOT, 0.0, 1.0, NULL, NULL) );
1085 
1086  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/mingap",
1087  "minimum primal-dual gap for which the heuristic is executed",
1088  &heurdata->mingap, TRUE, DEFAULT_MINGAP, 0.0, SCIPinfinity(scip), NULL, NULL) );
1089 
1090  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useuct",
1091  "should uct node selection be used at the beginning of the search?",
1092  &heurdata->useuct, TRUE, DEFAULT_USEUCT, NULL, NULL) );
1093 
1094  return SCIP_OKAY;
1095 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2521
SCIP_RETCODE SCIPsetHeurExitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXITSOL((*heurexitsol)))
Definition: scip_heur.c:233
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:101
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
#define DEFAULT_USELPROWS
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_var.c:4940
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1017
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:369
SCIP_Longint SCIPgetNRootLPIterations(SCIP *scip)
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:949
SCIP_Real SCIPfeastol(SCIP *scip)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:84
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip_nlp.c:101
#define DEFAULT_MINIMPROVE
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for SCIP parameter handling
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
SCIP_RETCODE SCIPcreateConsBasicLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for node selector plugins
public methods for memory management
SCIP_RETCODE SCIPincludeHeurProximity(SCIP *scip)
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17910
static SCIP_DECL_EVENTEXEC(eventExecProximity)
#define EVENTHDLR_DESC
static SCIP_DECL_HEURCOPY(heurCopyProximity)
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
static SCIP_RETCODE solveLp(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *success)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17966
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
public methods for timing
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:17431
static SCIP_DECL_HEURINIT(heurInitProximity)
#define DEFAULT_BINVARQUOT
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1865
static SCIP_RETCODE deleteSubproblem(SCIP *scip, SCIP_HEURDATA *heurdata)
#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
#define HEUR_MAXDEPTH
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:102
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3278
#define DEFAULT_USEFINALLP
SCIP_Real SCIPinfinity(SCIP *scip)
#define TRUE
Definition: def.h:86
#define SCIPdebug(x)
Definition: pub_message.h:84
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
#define SCIPstatisticMessage
Definition: pub_message.h:114
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
SCIP_RETCODE SCIPchgVarLbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_lp.c:2404
SCIP_Longint SCIPgetNRootFirstLPIterations(SCIP *scip)
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:99
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip_heur.c:108
SCIP_EVENTHDLR * SCIPfindEventhdlr(SCIP *scip, const char *name)
Definition: scip_event.c:225
#define HEUR_FREQ
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3201
#define SCIP_LONGINT_MAX
Definition: def.h:163
#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
public methods for SCIP variables
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:111
#define HEUR_PRIORITY
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_var.c:5029
#define SCIPdebugMsg
Definition: scip_message.h:69
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetPresolvingTime(SCIP *scip)
Definition: scip_timing.c:433
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_Real SCIPgetObjNorm(SCIP *scip)
Definition: scip_prob.c:1640
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
public methods for numerical tolerances
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
public methods for querying solving statistics
int SCIPgetNFixedVars(SCIP *scip)
Definition: scip_prob.c:2308
SCIP_Bool SCIPisLPConstructed(SCIP *scip)
Definition: scip_lp.c:92
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17920
#define HEUR_NAME
#define DEFAULT_MINLPITERS
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2613
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1441
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
Definition: scip_heur.c:249
#define DEFAULT_LPITERSQUOT
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:210
SCIP_RETCODE SCIPdeleteSubproblemProximity(SCIP *scip)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2769
#define HEUR_FREQOFS
SCIP_RETCODE SCIPsolveDiveLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition: scip_lp.c:2663
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
#define HEUR_TIMING
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
SCIP_RETCODE SCIPpresolve(SCIP *scip)
Definition: scip_solve.c:2443
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, SCIP_Bool usefinallp, SCIP_Bool *success)
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:164
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3048
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2604
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1482
#define DEFAULT_MAXNODES
#define REALABS(x)
Definition: def.h:201
public methods for problem copies
public methods for primal CIP solutions
#define EVENTHDLR_NAME
#define SCIP_CALL(x)
Definition: def.h:384
SCIP_Real SCIPgetLowerbound(SCIP *scip)
static SCIP_DECL_HEUREXEC(heurExecProximity)
#define DEFAULT_NODESOFS
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_NODESQUOT
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
#define DEFAULT_USEUCT
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip_var.c:4510
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1212
#define DEFAULT_MAXLPITERS
public data structures and miscellaneous methods
#define DEFAULT_MINGAP
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
Definition: scip_solve.c:3432
#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
SCIP_Longint SCIPsolGetNodenum(SCIP_SOL *sol)
Definition: sol.c:2584
SCIP_Real SCIPgetGap(SCIP *scip)
SCIP_RETCODE SCIPchgVarUbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_lp.c:2436
#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
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:976
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17758
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2205
#define DEFAULT_MINNODES
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1435
Constraint handler for linear constraints in their most general form, .
int SCIPgetNObjVars(SCIP *scip)
Definition: scip_prob.c:2219
SCIP_RETCODE SCIPchgRhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPtrySol(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:3125
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2036
public methods for the LP relaxation, rows and columns
#define SCIP_EVENTTYPE_NODESOLVED
Definition: type_event.h:127
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1991
public methods for nonlinear relaxation
public methods for branching rule plugins and branching
SCIP_Bool SCIPisObjIntegral(SCIP *scip)
Definition: scip_prob.c:1561
public methods for managing events
general public methods
#define HEUR_DESC
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2304
#define DEFAULT_WAITINGNODES
public methods for solutions
static SCIP_DECL_HEURFREE(heurFreeProximity)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1110
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
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17370
#define SCIP_Real
Definition: def.h:177
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:694
public methods for message handling
static SCIP_DECL_HEUREXITSOL(heurExitsolProximity)
#define SCIP_Longint
Definition: def.h:162
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3235
SCIP_RETCODE SCIPstartDive(SCIP *scip)
Definition: scip_lp.c:2227
static DPSUBSOL ** subsol
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1254
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip_solve.c:358
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
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 SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17976
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
#define HEUR_DISPCHAR
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip_solve.c:3516
public methods for primal heuristics
SCIPallocBlockMemory(scip, subsol))
SCIP_RETCODE SCIPapplyProximity(SCIP *scip, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Real minimprove, SCIP_Longint nnodes, SCIP_Longint nlpiters, SCIP_Longint *nusednodes, SCIP_Longint *nusedlpiters, SCIP_Bool freesubscip)
SCIP_RETCODE SCIPendDive(SCIP *scip)
Definition: scip_lp.c:2276
#define SCIP_CALL_ABORT(x)
Definition: def.h:363
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1352
SCIP_Longint SCIPgetNNodes(SCIP *scip)
#define HEUR_USESSUBSCIP
public methods for global and local (sub)problems
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:17442
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1352
#define DEFAULT_RESTART
int SCIPsolGetIndex(SCIP_SOL *sol)
Definition: sol.c:2635
improvement heuristic which uses an auxiliary objective instead of the original objective function wh...
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
static SCIP_RETCODE setupSubproblem(SCIP_HEURDATA *heurdata, SCIP *subscip)
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:315
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:319
memory allocation routines