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-2020 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  /* employ a limit on the number of enforcement rounds in the quadratic constraint handler; this fixes the issue that
380  * sometimes the quadratic constraint handler needs hundreds or thousands of enforcement rounds to determine the
381  * feasibility status of a single node without fractional branching candidates by separation (namely for uflquad
382  * instances); however, the solution status of the sub-SCIP might get corrupted by this; hence no deductions shall be
383  * made for the original SCIP
384  */
385  if( SCIPfindConshdlr(subscip, "quadratic") != NULL && !SCIPisParamFixed(subscip, "constraints/quadratic/enfolplimit") )
386  {
387  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/quadratic/enfolplimit", 500) );
388  }
389 
390  /* todo check if
391  * SCIP_CALL( SCIPsetEmphasis(subscip, SCIP_PARAMEMPHASIS_FEASIBILITY, TRUE) );
392  * improves performance */
393 
394  return SCIP_OKAY;
395 }
396 
397 /** frees the subproblem */
398 static
400  SCIP* scip, /**< SCIP data structure */
401  SCIP_HEURDATA* heurdata /**< heuristic data */
402  )
403 {
404  /* free remaining memory from heuristic execution */
405  if( heurdata->subscip != NULL )
406  {
407  assert(heurdata->varmapfw != NULL);
408  assert(heurdata->subvars != NULL);
409  assert(heurdata->objcons != NULL);
410 
411  SCIPdebugMsg(scip, "Freeing subproblem of proximity heuristic\n");
412  SCIPfreeBlockMemoryArray(scip, &heurdata->subvars, heurdata->nsubvars);
413  SCIPhashmapFree(&heurdata->varmapfw);
414  SCIP_CALL( SCIPreleaseCons(heurdata->subscip, &heurdata->objcons) );
415  SCIP_CALL( SCIPfree(&heurdata->subscip) );
416 
417  heurdata->subscip = NULL;
418  heurdata->varmapfw = NULL;
419  heurdata->subvars = NULL;
420  heurdata->objcons = NULL;
421  }
422  return SCIP_OKAY;
423 }
424 
425 /* ---------------- Callback methods of event handler ---------------- */
426 
427 /** exec the event handler
428  *
429  * We interrupt the solution process.
430  */
431 static
432 SCIP_DECL_EVENTEXEC(eventExecProximity)
433 {
434  SCIP_HEURDATA* heurdata;
435 
436  assert(eventhdlr != NULL);
437  assert(eventdata != NULL);
438  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
439  assert(event != NULL);
441 
442  heurdata = (SCIP_HEURDATA*)eventdata;
443  assert(heurdata != NULL);
444 
445  /* interrupt solution process of sub-SCIP
446  * todo adjust interruption limit */
447  if( SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_ITERLIMIT || SCIPgetNLPIterations(scip) >= heurdata->maxlpiters )
448  {
450  }
451 
452  return SCIP_OKAY;
453 }
454 
455 
456 /* ---------------- Callback methods of primal heuristic ---------------- */
457 
458 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
459 static
460 SCIP_DECL_HEURCOPY(heurCopyProximity)
461 { /*lint --e{715}*/
462  assert(scip != NULL);
463  assert(heur != NULL);
464  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
465 
466  /* call inclusion method of primal heuristic */
468 
469  return SCIP_OKAY;
470 }
471 
472 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
473 static
474 SCIP_DECL_HEURFREE(heurFreeProximity)
475 { /*lint --e{715}*/
476  SCIP_HEURDATA* heurdata;
477 
478  assert( heur != NULL );
479  assert( scip != NULL );
480 
481  /* get heuristic data */
482  heurdata = SCIPheurGetData(heur);
483  assert( heurdata != NULL );
484 
485  /* free heuristic data */
486  SCIPfreeBlockMemory(scip, &heurdata);
487  SCIPheurSetData(heur, NULL);
488 
489  return SCIP_OKAY;
490 }
491 
492 
493 /** initialization method of primal heuristic (called after problem was transformed) */
494 static
495 SCIP_DECL_HEURINIT(heurInitProximity)
496 { /*lint --e{715}*/
497  SCIP_HEURDATA* heurdata;
498 
499  assert( heur != NULL );
500  assert( scip != NULL );
501 
502  /* get heuristic data */
503  heurdata = SCIPheurGetData(heur);
504  assert( heurdata != NULL );
505 
506  /* initialize data */
507  heurdata->usednodes = 0LL;
508  heurdata->lastsolidx = -1;
509  heurdata->nusedlpiters = 0LL;
510  heurdata->subprobidx = 0;
511 
512  heurdata->subscip = NULL;
513  heurdata->varmapfw = NULL;
514  heurdata->subvars = NULL;
515  heurdata->objcons = NULL;
516 
517  heurdata->nsubvars = 0;
518 
519  return SCIP_OKAY;
520 }
521 
522 /** solution process exiting method of proximity heuristic */
523 static
524 SCIP_DECL_HEUREXITSOL(heurExitsolProximity)
525 {
526  SCIP_HEURDATA* heurdata;
527 
528  assert( heur != NULL );
529  assert( scip != NULL );
530 
531  /* get heuristic data */
532  heurdata = SCIPheurGetData(heur);
533  assert( heurdata != NULL );
534 
535  SCIP_CALL( deleteSubproblem(scip, heurdata) );
536 
537  assert(heurdata->subscip == NULL && heurdata->varmapfw == NULL && heurdata->subvars == NULL && heurdata->objcons == NULL);
538 
539  return SCIP_OKAY;
540 }
541 
542 /** execution method of primal heuristic */
543 static
544 SCIP_DECL_HEUREXEC(heurExecProximity)
545 { /*lint --e{715}*/
546  SCIP_HEURDATA* heurdata; /* heuristic's data */
547  SCIP_Longint nnodes; /* number of stalling nodes for the subproblem */
548  SCIP_Longint nlpiters; /* lp iteration limit for the subproblem */
549  SCIP_Bool foundsol = FALSE;
550 
551  assert(heur != NULL);
552  assert(scip != NULL);
553  assert(result != NULL);
554 
555  *result = SCIP_DIDNOTRUN;
556 
557  /* get heuristic data */
558  heurdata = SCIPheurGetData(heur);
559  assert(heurdata != NULL);
560 
561  /* do not run heuristic when there are only few binary varables */
562  if( SCIPgetNBinVars(scip) < heurdata->binvarquot * SCIPgetNVars(scip) )
563  return SCIP_OKAY;
564 
565  /* calculate branching node limit for sub problem */
566  /* todo maybe treat root node differently */
567  nnodes = (SCIP_Longint) (heurdata->nodesquot * SCIPgetNNodes(scip));
568  nnodes += heurdata->nodesofs;
569 
570  /* determine the node and LP iteration limit for the solve of the sub-SCIP */
571  nnodes -= heurdata->usednodes;
572  nnodes = MIN(nnodes, heurdata->maxnodes);
573 
574  nlpiters = (SCIP_Longint) (heurdata->lpitersquot * SCIPgetNRootFirstLPIterations(scip));
575  nlpiters = MIN(nlpiters, heurdata->maxlpiters);
576 
577  /* check whether we have enough nodes left to call subproblem solving */
578  if( nnodes < heurdata->minnodes )
579  {
580  SCIPdebugMsg(scip, "skipping proximity: nnodes=%" SCIP_LONGINT_FORMAT ", minnodes=%" SCIP_LONGINT_FORMAT "\n", nnodes, heurdata->minnodes);
581  return SCIP_OKAY;
582  }
583 
584  /* do not run proximity, if the problem does not have an objective function anyway */
585  if( SCIPgetNObjVars(scip) == 0 )
586  {
587  SCIPdebugMsg(scip, "skipping proximity: pure feasibility problem anyway\n");
588  return SCIP_OKAY;
589  }
590 
591  do
592  {
593  /* main loop of proximity: in every iteration, a new subproblem is set up and solved until no improved solution
594  * is found or one of the heuristic limits on nodes or LP iterations is hit
595  * heuristic performs only one iteration if restart parameter is set to FALSE
596  */
597  SCIP_Longint nusednodes = 0LL;
598  SCIP_Longint nusedlpiters = 0LL;
599 
600  nlpiters = MAX(nlpiters, heurdata->minlpiters);
601 
602  /* define and solve the proximity subproblem */
603  SCIP_CALL( SCIPapplyProximity(scip, heur, result, heurdata->minimprove, nnodes, nlpiters, &nusednodes, &nusedlpiters, FALSE) );
604 
605  /* adjust node limit and LP iteration limit for future iterations */
606  assert(nusednodes <= nnodes);
607  heurdata->usednodes += nusednodes;
608  nnodes -= nusednodes;
609 
610  nlpiters -= nusedlpiters;
611  heurdata->nusedlpiters += nusedlpiters;
612 
613  /* memorize if a new solution has been found in at least one iteration */
614  if( *result == SCIP_FOUNDSOL )
615  foundsol = TRUE;
616  }
617  while( *result == SCIP_FOUNDSOL && heurdata->restart && !SCIPisStopped(scip) && nnodes > 0 );
618 
619  /* reset result pointer if solution has been found in previous iteration */
620  if( foundsol )
621  *result = SCIP_FOUNDSOL;
622 
623  /* free the occupied memory */
624  if( heurdata->subscip != NULL )
625  {
626  /* just for testing the library method, in debug mode, we call the wrapper method for the actual delete method */
627 #ifndef NDEBUG
629 #else
630  SCIP_CALL( deleteSubproblem(scip, heurdata) );
631 #endif
632  }
633  return SCIP_OKAY;
634 }
635 
636 
637 /*
638  * primal heuristic specific interface methods
639  */
640 
641 /** frees the sub-MIP created by proximity */
643  SCIP* scip /** SCIP data structure */
644  )
645 {
646  SCIP_HEUR* heur;
647  SCIP_HEURDATA* heurdata;
648 
649  assert(scip != NULL);
650 
651  heur = SCIPfindHeur(scip, HEUR_NAME);
652  assert(heur != NULL);
653 
654  heurdata = SCIPheurGetData(heur);
655  if( heurdata != NULL )
656  {
657  SCIP_CALL( deleteSubproblem(scip, heurdata) );
658  }
659 
660  return SCIP_OKAY;
661 }
662 
663 /** main procedure of the proximity heuristic, creates and solves a sub-SCIP
664  *
665  * @note The method can be applied in an iterative way, keeping the same subscip in between. If the @p freesubscip
666  * parameter is set to FALSE, the heuristic will keep the subscip data structures. Always set this parameter
667  * to TRUE, or call SCIPdeleteSubproblemProximity() afterwards.
668  */
670  SCIP* scip, /**< original SCIP data structure */
671  SCIP_HEUR* heur, /**< heuristic data structure */
672  SCIP_RESULT* result, /**< result data structure */
673  SCIP_Real minimprove, /**< factor by which proximity should at least improve the incumbent */
674  SCIP_Longint nnodes, /**< node limit for the subproblem */
675  SCIP_Longint nlpiters, /**< LP iteration limit for the subproblem */
676  SCIP_Longint* nusednodes, /**< pointer to store number of used nodes in subscip */
677  SCIP_Longint* nusedlpiters, /**< pointer to store number of used LP iterations in subscip */
678  SCIP_Bool freesubscip /**< should the created sub-MIP be freed at the end of the method? */
679  )
680 {
681  SCIP* subscip; /* the subproblem created by proximity */
682  SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
683  SCIP_VAR** vars; /* original problem's variables */
684  SCIP_VAR** subvars; /* subproblem's variables */
685  SCIP_HEURDATA* heurdata; /* heuristic's private data structure */
686  SCIP_EVENTHDLR* eventhdlr; /* event handler for LP events */
687 
688  SCIP_SOL* incumbent;
689  SCIP_CONS* objcons;
690  SCIP_Longint iterlim;
691 
692  SCIP_Real large;
693  SCIP_Real inf;
694 
695  SCIP_Real bestobj;
696  SCIP_Real objcutoff;
697  SCIP_Real lowerbound;
698 
699  int nvars; /* number of original problem's variables */
700  int nfixedvars;
701  int nsubsols;
702  int solidx;
703  int i;
704 
705  SCIP_Bool valid;
706  SCIP_Bool success;
707 
708  assert(scip != NULL);
709  assert(heur != NULL);
710  assert(result != NULL);
711 
712  assert(nnodes >= 0);
713  assert(0.0 <= minimprove && minimprove <= 1.0);
714 
715  *result = SCIP_DIDNOTRUN;
716 
717  /* get heuristic data */
718  heurdata = SCIPheurGetData(heur);
719  assert(heurdata != NULL);
720 
721  /* only call the heuristic if we have an incumbent */
722  if( SCIPgetNSolsFound(scip) == 0 )
723  return SCIP_OKAY;
724 
725  /* do not use heuristic on problems without binary variables */
726  if( SCIPgetNBinVars(scip) == 0 )
727  return SCIP_OKAY;
728 
729  incumbent = SCIPgetBestSol(scip);
730  assert(incumbent != NULL);
731 
732  /* make sure that the incumbent is valid for the transformed space, otherwise terminate */
733  if( SCIPsolIsOriginal(incumbent) )
734  return SCIP_OKAY;
735 
736  solidx = SCIPsolGetIndex(incumbent);
737 
738  if( heurdata->lastsolidx == solidx )
739  return SCIP_OKAY;
740 
741  /* only call heuristic, if the best solution does not come from trivial heuristic */
742  if( SCIPsolGetHeur(incumbent) != NULL && strcmp(SCIPheurGetName(SCIPsolGetHeur(incumbent)), "trivial") == 0 )
743  return SCIP_OKAY;
744 
745  /* waitingnodes parameter defines the minimum number of nodes to wait before a new incumbent is processed */
746  if( SCIPgetNNodes(scip) > 1 && SCIPgetNNodes(scip) - SCIPsolGetNodenum(incumbent) < heurdata->waitingnodes )
747  return SCIP_OKAY;
748 
749  bestobj = SCIPgetSolTransObj(scip, incumbent);
750  lowerbound = SCIPgetLowerbound(scip);
751 
752  /* use knowledge about integrality of objective to round up lower bound */
753  if( SCIPisObjIntegral(scip) )
754  {
755  SCIPdebugMsg(scip, " Rounding up lower bound: %f --> %f \n", lowerbound, SCIPfeasCeil(scip, lowerbound));
756  lowerbound = SCIPfeasCeil(scip, lowerbound);
757  }
758 
759  /* do not trigger heuristic if primal and dual bound are already close together */
760  if( SCIPisFeasLE(scip, bestobj, lowerbound) || SCIPgetGap(scip) <= heurdata->mingap )
761  return SCIP_OKAY;
762 
763  /* calculate the minimum improvement for a heuristic solution in terms of the distance between incumbent objective
764  * and the lower bound */
765  if( SCIPisInfinity(scip, REALABS(lowerbound)) )
766  {
767  if( SCIPisZero(scip, bestobj) )
768  objcutoff = bestobj - 1;
769  else
770  objcutoff = (1 - minimprove) * bestobj;
771  }
772  else
773  objcutoff = minimprove * lowerbound + (1 - minimprove) * (bestobj);
774 
775  /* use integrality of the objective function to round down (and thus strengthen) the objective cutoff */
776  if( SCIPisObjIntegral(scip) )
777  objcutoff = SCIPfeasFloor(scip, objcutoff);
778 
779  if( SCIPisFeasLT(scip, objcutoff, lowerbound) )
780  objcutoff = lowerbound;
781 
782  /* exit execution if the right hand side of the objective constraint does not change (suggests that the heuristic
783  * was not successful in a previous iteration) */
784  if( heurdata->objcons != NULL && SCIPisFeasEQ(scip, SCIPgetRhsLinear(heurdata->subscip, heurdata->objcons), objcutoff) )
785  return SCIP_OKAY;
786 
787  /* check whether there is enough time and memory left */
788  SCIP_CALL( SCIPcheckCopyLimits(scip, &valid) );
789 
790  if( ! valid )
791  return SCIP_OKAY;
792 
793  *result = SCIP_DIDNOTFIND;
794 
795  heurdata->lastsolidx = solidx;
796 
797  /* get variable data */
798  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
799 
800  /* create a subscip and copy the original scip instance into it */
801  if( heurdata->subscip == NULL )
802  {
803  assert(heurdata->varmapfw == NULL);
804  assert(heurdata->objcons == NULL);
805 
806  /* initialize the subproblem */
807  SCIP_CALL( SCIPcreate(&subscip) );
808 
809  /* create the variable mapping hash map */
810  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), nvars) );
811  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &subvars, nvars) );
812 
813  /* copy complete SCIP instance */
814  valid = FALSE;
815 
816  /* create a problem copy as sub SCIP */
817  SCIP_CALL( SCIPcopyLargeNeighborhoodSearch(scip, subscip, varmapfw, "proximity", NULL, NULL, 0, heurdata->uselprows, TRUE,
818  &success, &valid) );
819 
820  SCIPdebugMsg(scip, "Copying the SCIP instance was %s complete.\n", valid ? "" : "not ");
821 
822  /* create event handler for LP events */
823  eventhdlr = NULL;
824  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecProximity, NULL) );
825  if( eventhdlr == NULL )
826  {
827  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
828  return SCIP_PLUGINNOTFOUND;
829  }
830 
831  /* set up parameters for the copied instance */
832  SCIP_CALL( setupSubproblem(heurdata, subscip) );
833 
834  /* create the objective constraint in the sub scip, first without variables and values which will be added later */
835  SCIP_CALL( SCIPcreateConsBasicLinear(subscip, &objcons, "objbound_of_origscip", 0, NULL, NULL, -SCIPinfinity(subscip), SCIPinfinity(subscip)) );
836 
837  /* determine large value to set variable bounds to, safe-guard to avoid fixings to infinite values */
838  large = SCIPinfinity(scip);
839  if( !SCIPisInfinity(scip, 0.1 / SCIPfeastol(scip)) )
840  large = 0.1 / SCIPfeastol(scip);
841  inf = SCIPinfinity(subscip);
842 
843  /* get variable image and change objective to proximity function (Manhattan distance) in sub-SCIP */
844  for( i = 0; i < nvars; i++ )
845  {
846  SCIP_Real adjustedbound;
847  SCIP_Real lb;
848  SCIP_Real ub;
849 
850  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
851 
852  if( subvars[i] == NULL )
853  continue;
854 
855  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], 0.0) );
856 
857  lb = SCIPvarGetLbGlobal(subvars[i]);
858  ub = SCIPvarGetUbGlobal(subvars[i]);
859 
860  /* adjust infinite bounds in order to avoid that variables with non-zero objective
861  * get fixed to infinite value in proximity subproblem
862  */
863  if( SCIPisInfinity(subscip, ub) )
864  {
865  adjustedbound = MAX(large, lb + large);
866  adjustedbound = MIN(adjustedbound, inf);
867  SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[i], adjustedbound) );
868  }
869  if( SCIPisInfinity(subscip, -lb) )
870  {
871  adjustedbound = MIN(-large, ub - large);
872  adjustedbound = MAX(adjustedbound, -inf);
873  SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[i], adjustedbound) );
874  }
875 
876  /* add all nonzero objective coefficients to the objective constraint */
877  if( !SCIPisFeasZero(subscip, SCIPvarGetObj(vars[i])) )
878  {
879  SCIP_CALL( SCIPaddCoefLinear(subscip, objcons, subvars[i], SCIPvarGetObj(vars[i])) );
880  }
881  }
882 
883  /* add objective constraint to the subscip */
884  SCIP_CALL( SCIPaddCons(subscip, objcons) );
885  }
886  else
887  {
888  /* the instance, event handler, hash map and variable array were already copied in a previous iteration
889  * and stored in heuristic data
890  */
891  assert(heurdata->varmapfw != NULL);
892  assert(heurdata->subvars != NULL);
893  assert(heurdata->objcons != NULL);
894 
895  subscip = heurdata->subscip;
896  varmapfw = heurdata->varmapfw;
897  subvars = heurdata->subvars;
898  objcons = heurdata->objcons;
899 
900  eventhdlr = SCIPfindEventhdlr(subscip, EVENTHDLR_NAME);
901  assert(eventhdlr != NULL);
902  }
903 
904  SCIP_CALL( SCIPchgRhsLinear(subscip, objcons, objcutoff) );
905 
906  for( i = 0; i < SCIPgetNBinVars(scip); ++i )
907  {
908  SCIP_Real solval;
909 
910  if( subvars[i] == NULL )
911  continue;
912 
913  /* objective coefficients are only set for binary variables of the problem */
914  assert(SCIPvarIsBinary(subvars[i]));
915 
916  solval = SCIPgetSolVal(scip, incumbent, vars[i]);
917  assert(SCIPisFeasGE(scip, solval, 0.0));
918  assert(SCIPisFeasLE(scip, solval, 1.0));
919  assert(SCIPisFeasIntegral(scip, solval));
920 
921  if( solval < 0.5 )
922  {
923  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], 1.0) );
924  }
925  else
926  {
927  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], -1.0) );
928  }
929  }
930 
931  /* set limits for the subproblem */
932  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
933  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nnodes) );
934  SCIP_CALL( SCIPsetIntParam(subscip, "limits/solutions", 1) );
935 
936  /* restrict LP iterations */
937  /* todo set iterations limit depending on the number of iterations of the original problem root */
938  iterlim = nlpiters;
939  SCIP_CALL( SCIPsetLongintParam(subscip, "lp/iterlim", MAX(1, iterlim / MIN(10, nnodes))) );
940  SCIP_CALL( SCIPsetLongintParam(subscip, "lp/rootiterlim", iterlim) );
941 
942  /* catch LP events of sub-SCIP */
943  SCIP_CALL( SCIPtransformProb(subscip) );
944  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_NODESOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
945 
946  SCIPstatisticMessage("solving subproblem at Node: %" SCIP_LONGINT_FORMAT " "
947  "nnodes: %" SCIP_LONGINT_FORMAT " "
948  "iterlim: %" SCIP_LONGINT_FORMAT "\n", SCIPgetNNodes(scip), nnodes, iterlim);
949 
950  /* solve the subproblem with all previously adjusted parameters */
951  nfixedvars = SCIPgetNFixedVars(subscip);
952 
953  SCIP_CALL( SCIPpresolve(subscip) );
954 
955  nfixedvars = SCIPgetNFixedVars(subscip) - nfixedvars;
956  assert(nfixedvars >= 0);
957  SCIPstatisticMessage("presolve fixings %d: %d\n", ++(heurdata->subprobidx), nfixedvars);
958 
959  /* errors in solving the subproblem should not kill the overall solving process;
960  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
961  */
962  SCIP_CALL_ABORT( SCIPsolve(subscip) );
963 
964  /* print solving statistics of subproblem if we are in SCIP's debug mode */
966  SCIPstatisticMessage("solve of subscip %d:"
967  "usednodes: %" SCIP_LONGINT_FORMAT " "
968  "lp iters: %" SCIP_LONGINT_FORMAT " "
969  "root iters: %" SCIP_LONGINT_FORMAT " "
970  "Presolving Time: %.2f\n", heurdata->subprobidx,
972 
973  SCIPstatisticMessage("Solving Time %d: %.2f\n", heurdata->subprobidx, SCIPgetSolvingTime(subscip) );
974 
975  /* drop LP events of sub-SCIP */
976  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_NODESOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
977 
978  /* keep track of relevant information for future runs of heuristic */
979  if( nusednodes != NULL )
980  *nusednodes = SCIPgetNNodes(subscip);
981  if( nusedlpiters != NULL )
982  *nusedlpiters = SCIPgetNLPIterations(subscip);
983 
984  /* check whether a solution was found */
985  nsubsols = SCIPgetNSols(subscip);
986  incumbent = SCIPgetBestSol(subscip);
987  assert(nsubsols == 0 || incumbent != NULL);
988 
989  SCIPstatisticMessage("primal bound before subproblem %d: %g\n", heurdata->subprobidx, SCIPgetPrimalbound(scip));
990  if( nsubsols > 0 )
991  {
992  /* try to translate the sub problem solution to the original scip instance */
993  success = FALSE;
994  SCIP_CALL( createNewSol(scip, subscip, subvars, heur, incumbent, heurdata->usefinallp, &success) );
995 
996  if( success )
997  *result = SCIP_FOUNDSOL;
998  }
999  SCIPstatisticMessage("primal bound after subproblem %d: %g\n", heurdata->subprobidx, SCIPgetPrimalbound(scip));
1000 
1001  /* free the transformed subproblem data */
1002  SCIP_CALL( SCIPfreeTransform(subscip) );
1003 
1004  /* save subproblem in heuristic data for subsequent runs if it has been successful, otherwise free subproblem */
1005  heurdata->subscip = subscip;
1006  heurdata->varmapfw = varmapfw;
1007  heurdata->subvars = subvars;
1008  heurdata->objcons = objcons;
1009  heurdata->nsubvars = nvars;
1010 
1011  /* delete the sub problem */
1012  if( freesubscip )
1013  {
1014  SCIP_CALL( deleteSubproblem(scip, heurdata) );
1015  }
1016 
1017  return SCIP_OKAY;
1018 }
1019 
1020 
1021 /** creates the proximity primal heuristic and includes it in SCIP */
1023  SCIP* scip /**< SCIP data structure */
1024  )
1025 {
1026  SCIP_HEURDATA* heurdata;
1027  SCIP_HEUR* heur = NULL;
1028 
1029  /* create heuristic data */
1030  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
1031 
1032  /* include primal heuristic */
1033  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
1035  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecProximity, heurdata) );
1036  assert(heur != NULL);
1037 
1038  /* set non-NULL pointers to callback methods */
1039  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyProximity) );
1040  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeProximity) );
1041  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitProximity) );
1042  SCIP_CALL( SCIPsetHeurExitsol(scip, heur, heurExitsolProximity) );
1043 
1044  /* add proximity primal heuristic parameters */
1045  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
1046  "should subproblem be constructed based on LP row information?",
1047  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
1048 
1049  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/restart",
1050  "should the heuristic immediately run again on its newly found solution?",
1051  &heurdata->restart, TRUE, DEFAULT_RESTART, NULL, NULL) );
1052 
1053  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/usefinallp",
1054  "should the heuristic solve a final LP in case of continuous objective variables?",
1055  &heurdata->usefinallp, TRUE, DEFAULT_USEFINALLP, NULL, NULL) );
1056 
1057  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
1058  "maximum number of nodes to regard in the subproblem",
1059  &heurdata->maxnodes, TRUE,DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1060 
1061  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
1062  "number of nodes added to the contingent of the total nodes",
1063  &heurdata->nodesofs, TRUE, DEFAULT_NODESOFS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1064 
1065  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minnodes",
1066  "minimum number of nodes required to start the subproblem",
1067  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1068 
1069  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxlpiters",
1070  "maximum number of LP iterations to be performed in the subproblem",
1071  &heurdata->maxlpiters, TRUE, DEFAULT_MAXLPITERS, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
1072 
1073  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minlpiters",
1074  "minimum number of LP iterations performed in subproblem",
1075  &heurdata->minlpiters, TRUE, DEFAULT_MINLPITERS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1076 
1077  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/waitingnodes",
1078  "waiting nodes since last incumbent before heuristic is executed",
1079  &heurdata->waitingnodes, TRUE, DEFAULT_WAITINGNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1080 
1081  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
1082  "factor by which proximity should at least improve the incumbent",
1083  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
1084 
1085  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
1086  "sub-MIP node limit w.r.t number of original nodes",
1087  &heurdata->nodesquot, TRUE, DEFAULT_NODESQUOT, 0.0, SCIPinfinity(scip), NULL, NULL) );
1088 
1089  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/binvarquot",
1090  "threshold for percentage of binary variables required to start",
1091  &heurdata->binvarquot, TRUE, DEFAULT_BINVARQUOT, 0.0, 1.0, NULL, NULL) );
1092 
1093  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/lpitersquot",
1094  "quotient of sub-MIP LP iterations with respect to LP iterations so far",
1095  &heurdata->lpitersquot, TRUE, DEFAULT_LPITERSQUOT, 0.0, 1.0, NULL, NULL) );
1096 
1097  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/mingap",
1098  "minimum primal-dual gap for which the heuristic is executed",
1099  &heurdata->mingap, TRUE, DEFAULT_MINGAP, 0.0, SCIPinfinity(scip), NULL, NULL) );
1100 
1101  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useuct",
1102  "should uct node selection be used at the beginning of the search?",
1103  &heurdata->useuct, TRUE, DEFAULT_USEUCT, NULL, NULL) );
1104 
1105  return SCIP_OKAY;
1106 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:97
SCIP_Real SCIPfeastol(SCIP *scip)
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
#define DEFAULT_USELPROWS
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:977
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:687
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:80
#define DEFAULT_MINIMPROVE
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:877
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1213
SCIP_RETCODE SCIPincludeHeurProximity(SCIP *scip)
public methods for SCIP parameter handling
public methods for node selector plugins
SCIP_RETCODE SCIPsetHeurExitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXITSOL((*heurexitsol)))
Definition: scip_heur.c:233
public methods for memory management
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1340
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip_solve.c:3407
static SCIP_DECL_EVENTEXEC(eventExecProximity)
SCIP_EXPORT SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2521
#define EVENTHDLR_DESC
static SCIP_DECL_HEURCOPY(heurCopyProximity)
SCIP_EVENTHDLR * SCIPfindEventhdlr(SCIP *scip, const char *name)
Definition: scip_event.c:225
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:123
static SCIP_RETCODE solveLp(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *success)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1353
public solving methods
SCIP_Real SCIPgetGap(SCIP *scip)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
public methods for timing
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip_solve.c:357
static SCIP_DECL_HEURINIT(heurInitProximity)
#define DEFAULT_BINVARQUOT
SCIP_EXPORT SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:17192
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:315
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1986
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:360
static SCIP_RETCODE deleteSubproblem(SCIP *scip, SCIP_HEURDATA *heurdata)
#define FALSE
Definition: def.h:73
#define HEUR_MAXDEPTH
SCIP_EXPORT SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17510
SCIP_Real SCIPgetObjNorm(SCIP *scip)
Definition: scip_prob.c:1639
SCIP_EXPORT SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2604
#define DEFAULT_USEFINALLP
SCIP_Real SCIPgetPresolvingTime(SCIP *scip)
Definition: scip_timing.c:424
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)
#define TRUE
Definition: def.h:72
#define SCIPdebug(x)
Definition: pub_message.h:84
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1018
#define SCIPstatisticMessage
Definition: pub_message.h:114
methods commonly used by primal heuristics
SCIP_Bool SCIPisLPConstructed(SCIP *scip)
Definition: scip_lp.c:92
SCIP_RETCODE SCIPchgVarLbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_lp.c:2359
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2527
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3200
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:48
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
SCIP_EXPORT SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17131
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip_param.c:893
#define HEUR_FREQ
#define SCIP_LONGINT_MAX
Definition: def.h:149
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
SCIP_RETCODE SCIPsolveDiveLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition: scip_lp.c:2618
public methods for SCIP variables
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
SCIP_RETCODE SCIPpresolve(SCIP *scip)
Definition: scip_solve.c:2366
#define HEUR_PRIORITY
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
#define SCIPdebugMsg
Definition: scip_message.h:69
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:159
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3192
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
public methods for numerical tolerances
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
Definition: scip_heur.c:249
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:320
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
public methods for querying solving statistics
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2206
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_Longint SCIPgetNNodes(SCIP *scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:283
#define HEUR_NAME
#define DEFAULT_MINLPITERS
SCIP_Bool SCIPisObjIntegral(SCIP *scip)
Definition: scip_prob.c:1560
#define DEFAULT_LPITERSQUOT
SCIP_EXPORT SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:17203
SCIP_Longint SCIPgetNRootFirstLPIterations(SCIP *scip)
#define SCIPerrorMessage
Definition: pub_message.h:55
#define HEUR_FREQOFS
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip_branch.c:288
#define HEUR_TIMING
public methods for event handler plugins and event handlers
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:277
int SCIPgetNObjVars(SCIP *scip)
Definition: scip_prob.c:2214
SCIP_RETCODE SCIPstartDive(SCIP *scip)
Definition: scip_lp.c:2182
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, SCIP_Bool usefinallp, SCIP_Bool *success)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:164
int SCIPgetNFixedVars(SCIP *scip)
Definition: scip_prob.c:2303
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1350
#define NULL
Definition: lpi_spx1.cpp:155
#define DEFAULT_MAXNODES
#define REALABS(x)
Definition: def.h:187
public methods for problem copies
public methods for primal CIP solutions
#define EVENTHDLR_NAME
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip_nodesel.c:225
#define SCIP_CALL(x)
Definition: def.h:364
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:942
static SCIP_DECL_HEUREXEC(heurExecProximity)
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:1021
#define DEFAULT_NODESOFS
#define DEFAULT_NODESQUOT
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
#define DEFAULT_USEUCT
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
SCIP_Real SCIPinfinity(SCIP *scip)
#define DEFAULT_MAXLPITERS
public data structures and miscellaneous methods
#define DEFAULT_MINGAP
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1255
SCIP_RETCODE SCIPendDive(SCIP *scip)
Definition: scip_lp.c:2231
#define SCIP_Bool
Definition: def.h:70
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3013
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip_nlp.c:210
SCIP_EXPORT SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17672
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:210
#define MAX(x, y)
Definition: tclique_def.h:83
SCIP_RETCODE SCIPchgVarUbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_lp.c:2391
SCIP_EXPORT int SCIPsolGetIndex(SCIP_SOL *sol)
Definition: sol.c:2635
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
#define DEFAULT_MINNODES
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_var.c:4943
Constraint handler for linear constraints in their most general form, .
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3228
SCIP_EXPORT SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17718
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:95
SCIP_RETCODE 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
public methods for the LP relaxation, rows and columns
#define SCIP_EVENTTYPE_NODESOLVED
Definition: type_event.h:127
public methods for nonlinear relaxations
SCIP_EXPORT SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17728
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:555
public methods for branching rule plugins and branching
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_var.c:5030
public methods for managing events
general public methods
#define HEUR_DESC
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
#define DEFAULT_WAITINGNODES
public methods for solutions
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip_var.c:4514
static SCIP_DECL_HEURFREE(heurFreeProximity)
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:311
SCIP_EXPORT SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17662
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_EXPORT SCIP_Longint SCIPsolGetNodenum(SCIP_SOL *sol)
Definition: sol.c:2584
public methods for message output
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1860
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1483
SCIP_Longint SCIPgetNRootLPIterations(SCIP *scip)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3047
#define SCIP_Real
Definition: def.h:163
public methods for message handling
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
static SCIP_DECL_HEUREXITSOL(heurExitsolProximity)
#define SCIP_Longint
Definition: def.h:148
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:439
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2031
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
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 SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2764
#define nnodes
Definition: gastrans.c:65
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
#define HEUR_DISPCHAR
public methods for primal heuristics
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:315
SCIP_RETCODE SCIPchgRhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
#define SCIP_CALL_ABORT(x)
Definition: def.h:343
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1110
SCIP_RETCODE SCIPdeleteSubproblemProximity(SCIP *scip)
#define HEUR_USESSUBSCIP
public methods for global and local (sub)problems
#define DEFAULT_RESTART
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2305
improvement heuristic which uses an auxiliary objective instead of the original objective function wh...
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:497
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:968
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)
static SCIP_RETCODE setupSubproblem(SCIP_HEURDATA *heurdata, SCIP *subscip)
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
Definition: scip_solve.c:3329
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1436
memory allocation routines