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