Scippy

SCIP

Solving Constraint Integer Programs

heur_trustregion.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2020 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_trustregion.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief Large neighborhood search heuristic for Benders' decomposition based on trust region methods
19  * @author Stephen J. Maher
20  *
21  * The Trust Region heuristic draws upon trust region methods for solving optimization problems, especially in the
22  * context of Benders' decomposition. This heuristic has been developed to improve the heuristic performance of the
23  * Benders' decomposition algorithm within SCIP.
24  *
25  * The Trust Region heuristic copies the original SCIP instance and adds a constraint to penalize changes from the
26  * incumbent solution. Consider a problem that includes a set of binary variables \f$\mathcal{B}\f$. Given a feasible
27  * solution \f$\hat{x}\f$ to the original problem, we define the set \f$\mathcal{B}^{+}\f$ as the index set for the
28  * binary variables that are 1 in the input solution and \f$\mathcal{B}^{-}\f$ as the index set for binary variables
29  * that are 0. The trust region constraint, which is added to the sub-SCIP, is given by
30  *
31  * \f[
32  * \sum_{i \in \mathcal{B}^{+}}(1 - x_{i}) + \sum_{i \in \mathcal{B}^{-}}x_{i} \le \theta
33  * \f]
34  *
35  * The variable \f$\theta\f$ measure the distance, in terms of the binary variables, of candidate solutions to the input
36  * solution.
37  *
38  * In addition, an upper bounding constraint is explicitly added to enforce a minimum improvement from the heuristic,
39  * given by \f$f(x) \le f(\hat{x}) - \epsilon\f$. The parameter \f$\epsilon \ge 0\f$ denotes the minimum improvement
40  * that must be achieved by the heuristic.
41  *
42  * The objective function is then modified to \f$f(x) + M\theta\f$, where \f$M\f$ is a parameter for penalizing the
43  * distance of solutions from the input solution \f$\hat{x}\f$.
44  *
45  * If a new incumbent solution is found by this heuristic, then the Trust Region heuristic is immediately
46  * re-executed with this new incumbent solution.
47  */
48 
49 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
50 
51 #include "blockmemshell/memory.h"
52 #include "scip/cons_linear.h"
53 #include "scip/heuristics.h"
54 #include "scip/heur_trustregion.h"
55 #include "scip/pub_event.h"
56 #include "scip/pub_heur.h"
57 #include "scip/pub_message.h"
58 #include "scip/pub_misc.h"
59 #include "scip/pub_sol.h"
60 #include "scip/pub_var.h"
61 #include "scip/scip_branch.h"
62 #include "scip/scip_cons.h"
63 #include "scip/scip_copy.h"
64 #include "scip/scip_event.h"
65 #include "scip/scip_general.h"
66 #include "scip/scip_heur.h"
67 #include "scip/scip_mem.h"
68 #include "scip/scip_message.h"
69 #include "scip/scip_nodesel.h"
70 #include "scip/scip_numerics.h"
71 #include "scip/scip_param.h"
72 #include "scip/scip_prob.h"
73 #include "scip/scip_sol.h"
74 #include "scip/scip_solve.h"
75 #include "scip/scip_solvingstats.h"
76 #include "scip/scip_var.h"
77 #include <string.h>
78 
79 #define HEUR_NAME "trustregion"
80 #define HEUR_DESC "LNS heuristic for Benders' decomposition based on trust region methods"
81 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_LNS
82 #define HEUR_PRIORITY -1102000
83 #define HEUR_FREQ -1
84 #define HEUR_FREQOFS 0
85 #define HEUR_MAXDEPTH -1
86 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
87 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
88 
89 #define DEFAULT_MINBINVARS 10 /**< the minimum number of binary variables necessary to run the heuristic */
90 #define DEFAULT_NODESOFS 1000 /**< number of nodes added to the contingent of the total nodes */
91 #define DEFAULT_MAXNODES 10000 /**< maximum number of nodes to regard in the subproblem */
92 #define DEFAULT_MINNODES 100 /**< minimum number of nodes required to start the subproblem */
93 #define DEFAULT_NODESQUOT 0.05 /**< contingent of sub problem nodes in relation to original nodes */
94 #define DEFAULT_LPLIMFAC 1.5 /**< factor by which the limit on the number of LP depends on the node limit */
95 #define DEFAULT_NWAITINGNODES 1 /**< number of nodes without incumbent change that heuristic should wait */
96 #define DEFAULT_USELPROWS FALSE /**< should subproblem be created out of the rows in the LP rows,
97  * otherwise, the copy constructors of the constraints handlers are used */
98 #define DEFAULT_COPYCUTS TRUE /**< if DEFAULT_USELPROWS is FALSE, then should all active cuts from the cutpool
99  * of the original scip be copied to constraints of the subscip */
100 #define DEFAULT_BESTSOLLIMIT 3 /**< limit on number of improving incumbent solutions in sub-CIP */
101 
102 #define DEFAULT_VIOLPENALTY 100.0 /**< the penalty for violating the trust region */
103 #define DEFAULT_OBJMINIMPROVE 1e-2 /**< the minimum absolute improvement in the objective function value */
105 /* event handler properties */
106 #define EVENTHDLR_NAME "Trustregion"
107 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic"
110 #define EXECUTE 0
111 #define WAITFORNEWSOL 1
114 /*
115  * Data structures
116  */
117 
118 /** primal heuristic data */
119 struct SCIP_HeurData
120 {
121  SCIP_SOL* lastsol; /**< the last incumbent trustregion used as reference point */
122  SCIP_Longint usednodes; /**< amount of nodes trust region used during all calls */
123  SCIP_Real nodesquot; /**< contingent of sub problem nodes in relation to original nodes */
124  SCIP_Real nodelimit; /**< the nodelimit employed in the current sub-SCIP, for the event handler*/
125  SCIP_Real lplimfac; /**< factor by which the limit on the number of LP depends on the node limit */
126  SCIP_Real violpenalty; /**< the penalty for violating the trust region */
127  SCIP_Real objminimprove; /**< the minimum absolute improvement in the objective function value */
128  int nwaitingnodes; /**< number of nodes without incumbent change that heuristic should wait */
129  int nodesofs; /**< number of nodes added to the contingent of the total nodes */
130  int minnodes; /**< minimum number of nodes required to start the subproblem */
131  int maxnodes; /**< maximum number of nodes to regard in the subproblem */
132  int minbinvars; /**< minimum number of binary variables necessary to run the heuristic */
133  int callstatus; /**< current status of trustregion heuristic */
134  int curminnodes; /**< current minimal number of nodes required to start the subproblem */
135  int bestsollimit; /**< limit on number of improving incumbent solutions in sub-CIP */
136  SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
137  SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
138  * to constraints in subproblem? */
139 };
140 
141 
142 /*
143  * Local methods
144  */
145 
146 /** create the extra constraint of trust region and add it to \p subscip */
147 static
149  SCIP* scip, /**< SCIP data structure of the original problem */
150  SCIP* subscip, /**< SCIP data structure of the subproblem */
151  SCIP_VAR** subvars, /**< variables of the subproblem */
152  SCIP_HEURDATA* heurdata /**< heuristic's data structure */
153  )
154 {
155  SCIP_CONS* cons; /* trust region constraint to create */
156  SCIP_VAR** consvars;
157  SCIP_VAR** vars;
158  SCIP_SOL* bestsol;
159 
160  int nvars;
161  int nbinvars;
162  int nconsvars;
163  int i;
164  SCIP_Real lhs;
165  SCIP_Real rhs;
166  SCIP_Real* consvals;
167  char name[SCIP_MAXSTRLEN];
168 
169  /* adding the neighborhood constraint for the trust region heuristic */
170  SCIP_CALL( SCIPaddTrustregionNeighborhoodConstraint(scip, subscip, subvars, heurdata->violpenalty) );
171 
172  /* get the data of the variables and the best solution */
173  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, NULL, NULL, NULL) );
174  bestsol = SCIPgetBestSol(scip);
175  assert( bestsol != NULL );
176 
177  /* memory allocation */
178  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nvars + 1) );
179  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nvars + 1) );
180  nconsvars = 0;
181 
182  /* create the upper bounding constraint. An absolute minimum improvement is used for this heuristic. This is
183  * different to other LNS heuristics, where a relative improvement is used. The absolute improvement tries to take
184  * into account problem specific information that is available to the user, such as a minimum step in the objective
185  * limit if the objective function is integer
186  */
187  lhs = -SCIPinfinity(subscip);
188  rhs = SCIPgetSolTransObj(scip, bestsol) - heurdata->objminimprove;
189 
190  /* if the objective function is integer, then the floor of the RHS is taken */
191  if( SCIPisObjIntegral(scip) )
192  rhs = SCIPfeasFloor(scip, rhs);
193 
194  /* adding the coefficients to the upper bounding constraint */
195  for( i = 0; i < nvars; i++ )
196  {
197  if( subvars[i] == NULL )
198  continue;
199  consvals[nconsvars] = SCIPvarGetObj(subvars[i]);
200  consvars[nconsvars] = subvars[i];
201  ++nconsvars;
202  }
203 
204  /* creates trustregion constraint and adds it to subscip */
205  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_upperboundcons", SCIPgetProbName(scip));
206 
207  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, name, nconsvars, consvars, consvals,
208  lhs, rhs, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE) );
209  SCIP_CALL( SCIPaddCons(subscip, cons) );
210  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
211 
212  /* free local memory */
213  SCIPfreeBufferArray(scip, &consvals);
214  SCIPfreeBufferArray(scip, &consvars);
215 
216  return SCIP_OKAY;
217 }
218 
219 
220 /* ---------------- Callback methods of event handler ---------------- */
221 
222 /** event handler execution callback to interrupt the solution process */
223 static
224 SCIP_DECL_EVENTEXEC(eventExecTrustregion)
225 {
226  SCIP_HEURDATA* heurdata;
227 
228  assert(eventhdlr != NULL);
229  assert(eventdata != NULL);
230  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
231  assert(event != NULL);
232  assert(SCIPeventGetType(event) & SCIP_EVENTTYPE_LPSOLVED);
233 
234  heurdata = (SCIP_HEURDATA*)eventdata;
235  assert(heurdata != NULL);
236 
237  /* interrupt solution process of sub-SCIP */
238  if( SCIPgetNLPs(scip) > heurdata->lplimfac * heurdata->nodelimit )
239  {
240  SCIPdebugMsg(scip, "interrupt after %" SCIP_LONGINT_FORMAT " LPs\n",SCIPgetNLPs(scip));
241  SCIP_CALL( SCIPinterruptSolve(scip) );
242  }
243 
244  return SCIP_OKAY;
245 }
246 
247 
248 /*
249  * Callback methods of primal heuristic
250  */
251 
252 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
253 static
254 SCIP_DECL_HEURCOPY(heurCopyTrustregion)
255 { /*lint --e{715}*/
256  assert(scip != NULL);
257  assert(heur != NULL);
258  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
259 
260  /* call inclusion method of primal heuristic */
262 
263  return SCIP_OKAY;
264 }
265 
266 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
267 static
268 SCIP_DECL_HEURFREE(heurFreeTrustregion)
269 { /*lint --e{715}*/
270  SCIP_HEURDATA* heurdata;
271 
272  assert( heur != NULL );
273  assert( scip != NULL );
274 
275  /* get heuristic data */
276  heurdata = SCIPheurGetData(heur);
277  assert( heurdata != NULL );
278 
279  /* free heuristic data */
280  SCIPfreeBlockMemory(scip, &heurdata);
281  SCIPheurSetData(heur, NULL);
282 
283  return SCIP_OKAY;
284 }
285 
286 
287 /** initialization method of primal heuristic (called after problem was transformed) */
288 static
289 SCIP_DECL_HEURINIT(heurInitTrustregion)
290 { /*lint --e{715}*/
291  SCIP_HEURDATA* heurdata;
292 
293  assert( heur != NULL );
294  assert( scip != NULL );
295 
296  /* get heuristic's data */
297  heurdata = SCIPheurGetData(heur);
298  assert( heurdata != NULL );
299 
300  /* with a little abuse we initialize the heurdata as if trustregion would have finished its last step regularly */
301  heurdata->callstatus = WAITFORNEWSOL;
302  heurdata->lastsol = NULL;
303  heurdata->usednodes = 0;
304  heurdata->curminnodes = heurdata->minnodes;
305 
306  return SCIP_OKAY;
307 }
308 
309 /** sets up and solves the sub SCIP for the Trust Region heuristic */
310 static
312  SCIP* scip, /**< SCIP data structure */
313  SCIP* subscip, /**< the subproblem created by trustregion */
314  SCIP_HEUR* heur, /**< trustregion heuristic */
315  SCIP_Longint nsubnodes, /**< nodelimit for subscip */
316  SCIP_RESULT* result /**< result pointer */
317  )
318 {
319  SCIP_VAR** subvars;
320  SCIP_EVENTHDLR* eventhdlr;
321  SCIP_HEURDATA* heurdata;
322  SCIP_HASHMAP* varmapfw;
323  SCIP_VAR** vars;
324 
325  int nvars;
326  int i;
327 
328  SCIP_Bool success;
329 
330  assert(scip != NULL);
331  assert(subscip != NULL);
332  assert(heur != NULL);
333 
334  heurdata = SCIPheurGetData(heur);
335  assert(heurdata != NULL);
336 
337  /* get the data of the variables and the best solution */
338  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
339 
340  /* create the variable mapping hash map */
341  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), nvars) );
342  success = FALSE;
343 
344  /* create a problem copy as sub SCIP */
345  SCIP_CALL( SCIPcopyLargeNeighborhoodSearch(scip, subscip, varmapfw, "trustregion", NULL, NULL, 0, heurdata->uselprows,
346  heurdata->copycuts, &success, NULL) );
347 
348  SCIPdebugMsg(scip, "Copying SCIP was %s successful.\n", success ? "" : "not ");
349 
350  /* if the subproblem could not be created, free memory and return */
351  if( !success )
352  {
353  *result = SCIP_DIDNOTRUN;
354  goto TERMINATE;
355  }
356 
357  /* create event handler for LP events */
358  eventhdlr = NULL;
359  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecTrustregion, NULL) );
360  if( eventhdlr == NULL )
361  {
362  /* free hash map */
363  SCIPhashmapFree(&varmapfw);
364 
365  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
366  return SCIP_PLUGINNOTFOUND;
367  }
368 
369  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
370  for (i = 0; i < nvars; ++i)
371  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
372 
373  /* free hash map */
374  SCIPhashmapFree(&varmapfw);
375 
376  heurdata->nodelimit = nsubnodes;
377  SCIP_CALL( SCIPsetCommonSubscipParams(scip, subscip, nsubnodes, MAX(10, nsubnodes/10), heurdata->bestsollimit) );
378 
379  SCIP_CALL( addTrustRegionConstraints(scip, subscip, subvars, heurdata) );
380 
381  /* catch LP events of sub-SCIP */
382  if( !heurdata->uselprows )
383  {
384  assert(eventhdlr != NULL);
385 
386  SCIP_CALL( SCIPtransformProb(subscip) );
387  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
388  }
389 
390  /* solve the subproblem */
391  SCIPdebugMsg(scip, "solving trust region subproblem with maxnodes %" SCIP_LONGINT_FORMAT "\n", nsubnodes);
392 
393  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/trysol/priority", 100000) );
394 
395  /* Errors in solving the subproblem should not kill the overall solving process
396  * Hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
397  */
398  SCIP_CALL_ABORT( SCIPsolve(subscip) );
399 
400  /* drop LP events of sub-SCIP */
401  if( !heurdata->uselprows )
402  {
403  assert(eventhdlr != NULL);
404 
405  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
406  }
407 
408  /* print solving statistics of subproblem if we are in SCIP's debug mode */
410 
411  heurdata->usednodes += SCIPgetNNodes(subscip);
412  SCIPdebugMsg(scip, "trust region used %" SCIP_LONGINT_FORMAT "/%" SCIP_LONGINT_FORMAT " nodes\n",
413  SCIPgetNNodes(subscip), nsubnodes);
414 
415  /* checks the solutions of the sub SCIP and adds them to the main SCIP if feasible */
416  SCIP_CALL( SCIPtranslateSubSols(scip, subscip, heur, subvars, &success, NULL) );
417 
418  if( success )
419  *result = SCIP_FOUNDSOL;
420 
421  /* checking the status of the subscip */
422  heurdata->callstatus = WAITFORNEWSOL;
425  {
426  heurdata->callstatus = EXECUTE;
427  heurdata->curminnodes *= 2;
428  }
429 
430  TERMINATE:
431  /* free subproblem */
432  SCIPfreeBufferArray(scip, &subvars);
433 
434  return SCIP_OKAY;
435 }
436 
437 
438 /** execution method of primal heuristic */
439 static
440 SCIP_DECL_HEUREXEC(heurExecTrustregion)
441 { /*lint --e{715}*/
442  SCIP_Longint maxnnodes;
443  SCIP_Longint nsubnodes;
444 
445  SCIP_HEURDATA* heurdata;
446  SCIP* subscip;
447 
448  SCIP_SOL* bestsol;
449 
450  SCIP_Bool success;
451  SCIP_RETCODE retcode;
452 
453  assert(heur != NULL);
454  assert(scip != NULL);
455  assert(result != NULL);
456 
457  *result = SCIP_DIDNOTRUN;
458 
459  /* get heuristic's data */
460  heurdata = SCIPheurGetData(heur);
461  assert( heurdata != NULL );
462 
463  /* there should be enough binary variables that a trust region constraint makes sense */
464  if( SCIPgetNBinVars(scip) < heurdata->minbinvars )
465  return SCIP_OKAY;
466 
467  *result = SCIP_DELAYED;
468 
469  /* only call heuristic, if an IP solution is at hand */
470  if( SCIPgetNSols(scip) <= 0 )
471  return SCIP_OKAY;
472 
473  bestsol = SCIPgetBestSol(scip);
474  assert(bestsol != NULL);
475 
476  /* only call heuristic, if the best solution comes from transformed problem */
477  if( SCIPsolIsOriginal(bestsol) )
478  return SCIP_OKAY;
479 
480  /* only call heuristic, if enough nodes were processed since last incumbent */
481  if( SCIPgetNNodes(scip) - SCIPgetSolNodenum(scip, bestsol) < heurdata->nwaitingnodes)
482  return SCIP_OKAY;
483 
484  /* only call heuristic, if the best solution does not come from trivial heuristic */
485  if( SCIPsolGetHeur(bestsol) != NULL && strcmp(SCIPheurGetName(SCIPsolGetHeur(bestsol)), "trivial") == 0 )
486  return SCIP_OKAY;
487 
488  /* calculate the maximal number of branching nodes until heuristic is aborted */
489  maxnnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
490 
491  /* reward trust region if it found solutions often.
492  * In this case, the trust region heuristic is designed for Benders' decomposition and solutions found may not be
493  * added by this heuristic but by trysol. So we don't reward finding best solutions, but finding any solution. */
494  maxnnodes = (SCIP_Longint)(maxnnodes * (1.0 + 2.0*(SCIPheurGetNSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur)+1.0)));
495  maxnnodes -= 100 * SCIPheurGetNCalls(heur); /* count the setup costs for the sub-MIP as 100 nodes */
496  maxnnodes += heurdata->nodesofs;
497 
498  *result = SCIP_DIDNOTRUN;
499 
500  /* we continue to execute the trust region heuristic until no new best solution is found */
501  do
502  {
503  SCIP_RESULT heurresult;
504 
505  /* storing the best solution again since it is needed for the execution loop */
506  bestsol = SCIPgetBestSol(scip);
507 
508  /* reset minnodes if new solution was found */
509  if( heurdata->lastsol != bestsol )
510  {
511  heurdata->curminnodes = heurdata->minnodes;
512  heurdata->callstatus = EXECUTE;
513  heurdata->lastsol = bestsol;
514  }
515 
516  /* if no new solution was found and trust region also seems to fail, just keep on waiting */
517  if( heurdata->callstatus == WAITFORNEWSOL )
518  return SCIP_OKAY;
519 
520  /* determine the node limit for the current process */
521  nsubnodes = maxnnodes - heurdata->usednodes;
522  nsubnodes = MIN(nsubnodes, heurdata->maxnodes);
523 
524  /* check whether we have enough nodes left to call sub problem solving */
525  if( nsubnodes < heurdata->curminnodes )
526  return SCIP_OKAY;
527 
528  if( SCIPisStopped(scip) )
529  return SCIP_OKAY;
530 
531  /* check whether there is enough time and memory left */
532  SCIP_CALL( SCIPcheckCopyLimits(scip, &success) );
533 
534  /* abort if no time is left or there is not enough memory to create a copy of SCIP */
535  if( !success )
536  return SCIP_OKAY;
537 
538  heurresult = SCIP_DIDNOTFIND;
539 
540  SCIPdebugMsg(scip, "running trust region heuristic ...\n");
541 
542  SCIP_CALL( SCIPcreate(&subscip) );
543 
544  retcode = setupAndSolveSubscipTrustregion(scip, subscip, heur, nsubnodes, &heurresult);
545 
546  SCIP_CALL( SCIPfree(&subscip) );
547 
548  /* if the result is FOUNDSOL, this means that a solution was found during a previous execution of the heuristic.
549  * So the heuristic result should only be updated if the result is not FOUNDSOL.
550  */
551  if( *result != SCIP_FOUNDSOL )
552  *result = heurresult;
553  }
554  while( bestsol != SCIPgetBestSol(scip) && retcode == SCIP_OKAY );
555 
556  return retcode;
557 }
558 
559 
560 /*
561  * primal heuristic specific interface methods
562  */
563 
564 /** creates the trustregion primal heuristic and includes it in SCIP */
566  SCIP* scip /**< SCIP data structure */
567  )
568 {
569  SCIP_HEURDATA* heurdata;
570  SCIP_HEUR* heur;
571 
572  /* create Trustregion primal heuristic data */
573  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
574 
575  /* include primal heuristic */
576  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
578  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecTrustregion, heurdata) );
579 
580  assert(heur != NULL);
581 
582  /* set non-NULL pointers to callback methods */
583  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyTrustregion) );
584  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeTrustregion) );
585  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitTrustregion) );
586 
587  /* add trustregion primal heuristic parameters */
588  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
589  "number of nodes added to the contingent of the total nodes",
590  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0, INT_MAX, NULL, NULL) );
591 
592  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minbinvars",
593  "the number of binary variables necessary to run the heuristic",
594  &heurdata->minbinvars, FALSE, DEFAULT_MINBINVARS, 1, INT_MAX, NULL, NULL) );
595 
596  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
597  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
598  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
599 
600  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/lplimfac",
601  "factor by which the limit on the number of LP depends on the node limit",
602  &heurdata->lplimfac, TRUE, DEFAULT_LPLIMFAC, 1.0, SCIP_REAL_MAX, NULL, NULL) );
603 
604  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minnodes",
605  "minimum number of nodes required to start the subproblem",
606  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0, INT_MAX, NULL, NULL) );
607 
608  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
609  "maximum number of nodes to regard in the subproblem",
610  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0, INT_MAX, NULL, NULL) );
611 
612  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nwaitingnodes",
613  "number of nodes without incumbent change that heuristic should wait",
614  &heurdata->nwaitingnodes, TRUE, DEFAULT_NWAITINGNODES, 0, INT_MAX, NULL, NULL) );
615 
616  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
617  "should subproblem be created out of the rows in the LP rows?",
618  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
619 
620  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/copycuts",
621  "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
622  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
623 
624  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/bestsollimit",
625  "limit on number of improving incumbent solutions in sub-CIP",
626  &heurdata->bestsollimit, FALSE, DEFAULT_BESTSOLLIMIT, -1, INT_MAX, NULL, NULL) );
627 
628  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/violpenalty",
629  "the penalty for each change in the binary variables from the candidate solution",
630  &heurdata->violpenalty, FALSE, DEFAULT_VIOLPENALTY, 0.0, SCIP_REAL_MAX, NULL, NULL) );
631 
632  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/objminimprove",
633  "the minimum absolute improvement in the objective function value",
634  &heurdata->objminimprove, FALSE, DEFAULT_OBJMINIMPROVE, 0.0, SCIP_REAL_MAX, NULL, NULL) );
635 
636  return SCIP_OKAY;
637 }
SCIP_RETCODE SCIPsetCommonSubscipParams(SCIP *sourcescip, SCIP *subscip, SCIP_Longint nsubnodes, SCIP_Longint nstallnodes, int bestsollimit)
Definition: scip_copy.c:3269
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
static SCIP_DECL_HEURINIT(heurInitTrustregion)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1555
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define SCIP_EVENTTYPE_LPSOLVED
Definition: type_event.h:92
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:687
#define DEFAULT_LPLIMFAC
Large neighborhood search heuristic for Benders&#39; decomposition based on trust region methods...
SCIP_Longint SCIPheurGetNSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1565
static SCIP_DECL_HEURCOPY(heurCopyTrustregion)
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
public methods for SCIP parameter handling
public methods for node selector plugins
public methods for memory management
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1340
SCIP_STATUS SCIPgetStatus(SCIP *scip)
Definition: scip_general.c:467
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip_solve.c:3407
static SCIP_DECL_EVENTEXEC(eventExecTrustregion)
#define SCIP_MAXSTRLEN
Definition: def.h:273
SCIP_EXPORT SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2521
public solving methods
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip_solve.c:357
SCIP_RETCODE SCIPtranslateSubSols(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_VAR **subvars, SCIP_Bool *success, int *solindex)
Definition: scip_copy.c:1396
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:315
#define FALSE
Definition: def.h:73
#define DEFAULT_VIOLPENALTY
SCIP_EXPORT SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17510
SCIP_EXPORT SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2604
#define TRUE
Definition: def.h:72
#define SCIPdebug(x)
Definition: pub_message.h:84
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2527
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3200
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:48
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
#define HEUR_NAME
#define DEFAULT_BESTSOLLIMIT
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
public methods for SCIP variables
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
#define SCIPdebugMsg
Definition: scip_message.h:69
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3192
#define HEUR_USESSUBSCIP
public methods for numerical tolerances
SCIP_Longint SCIPgetNLPs(SCIP *scip)
#define HEUR_DESC
SCIP_RETCODE SCIPcopyLargeNeighborhoodSearch(SCIP *sourcescip, SCIP *subscip, SCIP_HASHMAP *varmap, const char *suffix, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool uselprows, SCIP_Bool copycuts, SCIP_Bool *success, SCIP_Bool *valid)
Definition: heuristics.c:916
public methods for querying solving statistics
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2206
#define DEFAULT_OBJMINIMPROVE
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip_heur.c:108
SCIP_RETCODE SCIPincludeHeurTrustregion(SCIP *scip)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:283
SCIP_Bool SCIPisObjIntegral(SCIP *scip)
Definition: scip_prob.c:1560
#define SCIPerrorMessage
Definition: pub_message.h:55
public methods for event handler plugins and event handlers
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:277
static SCIP_DECL_HEUREXEC(heurExecTrustregion)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
#define DEFAULT_NODESOFS
#define DEFAULT_USELPROWS
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:164
#define EXECUTE
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1350
#define NULL
Definition: lpi_spx1.cpp:155
#define WAITFORNEWSOL
public methods for problem copies
public methods for primal CIP solutions
#define SCIP_CALL(x)
Definition: def.h:364
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:1021
#define HEUR_MAXDEPTH
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1649
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
SCIP_Real SCIPinfinity(SCIP *scip)
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:70
const char * SCIPgetProbName(SCIP *scip)
Definition: scip_prob.c:1065
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3013
#define DEFAULT_MINNODES
#define MAX(x, y)
Definition: tclique_def.h:83
#define HEUR_DISPCHAR
static SCIP_DECL_HEURFREE(heurFreeTrustregion)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
Constraint handler for linear constraints in their most general form, .
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:95
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:130
#define SCIP_REAL_MAX
Definition: def.h:164
public methods for branching rule plugins and branching
public methods for managing events
general public methods
public methods for solutions
#define DEFAULT_COPYCUTS
#define EVENTHDLR_NAME
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:311
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
#define HEUR_FREQ
public methods for message output
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1860
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1483
static SCIP_RETCODE setupAndSolveSubscipTrustregion(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_Longint nsubnodes, SCIP_RESULT *result)
#define DEFAULT_NODESQUOT
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10590
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:74
SCIP_RETCODE SCIPaddTrustregionNeighborhoodConstraint(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR **subvars, SCIP_Real violpenalty)
Definition: heuristics.c:990
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3047
static SCIP_RETCODE addTrustRegionConstraints(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEURDATA *heurdata)
#define SCIP_Real
Definition: def.h:163
#define DEFAULT_MINBINVARS
#define HEUR_FREQOFS
public methods for message handling
#define HEUR_PRIORITY
#define SCIP_Longint
Definition: def.h:148
#define DEFAULT_MAXNODES
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2031
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2764
public methods for primal heuristics
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:315
#define SCIP_CALL_ABORT(x)
Definition: def.h:343
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1110
public methods for global and local (sub)problems
#define EVENTHDLR_DESC
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2305
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:497
#define HEUR_TIMING
memory allocation routines
#define DEFAULT_NWAITINGNODES