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