Scippy

SCIP

Solving Constraint Integer Programs

heur_dins.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-2016 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_dins.c
17  * @brief DINS primal heuristic (according to Ghosh)
18  * @author Timo Berthold
19  * @author Robert Waniek
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include <assert.h>
25 #include <string.h>
26 #include "scip/scip.h"
27 #include "scip/scipdefplugins.h"
28 #include "scip/cons_linear.h"
29 #include "scip/heur_dins.h"
30 
31 #define HEUR_NAME "dins"
32 #define HEUR_DESC "distance induced neighborhood search by Ghosh"
33 #define HEUR_DISPCHAR 'D'
34 #define HEUR_PRIORITY -1105000
35 #define HEUR_FREQ -1
36 #define HEUR_FREQOFS 0
37 #define HEUR_MAXDEPTH -1
38 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPNODE
39 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
40 
41 #define DEFAULT_NODESOFS 5000LL /* number of nodes added to the contingent of the total nodes */
42 #define DEFAULT_MAXNODES 5000LL /* maximum number of nodes to regard in the subproblem */
43 #define DEFAULT_MINNODES 50LL /* minimum number of nodes to regard in the subproblem */
44 #define DEFAULT_MINIMPROVE 0.01 /* factor by which DINS should at least improve the incumbent */
45 #define DEFAULT_NODESQUOT 0.05 /* subproblem nodes in relation to nodes of the original problem */
46 #define DEFAULT_LPLIMFAC 1.5 /* factor by which the limit on the number of LP depends on the node limit */
47 #define DEFAULT_MINFIXINGRATE 0.3 /* minimum percentage of integer variables that have to be fixed */
48 #define DEFAULT_NWAITINGNODES 200LL /* number of nodes without incumbent change that heuristic should wait */
49 #define DEFAULT_NEIGHBORHOODSIZE 18 /* radius of the incumbents neighborhood to be searched */
50 #define DEFAULT_SOLNUM 5 /* number of pool-solutions to be checked for flag array update */
51 #define DEFAULT_USELPROWS FALSE /* should subproblem be created out of the rows in the LP rows,
52  * otherwise, the copy constructors of the constraints handlers are used */
53 #define DEFAULT_COPYCUTS TRUE /* if DEFAULT_USELPROWS is FALSE, then should all active cuts from the cutpool
54  * of the original scip be copied to constraints of the subscip */
55 
56 /* event handler properties */
57 #define EVENTHDLR_NAME "Dins"
58 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic"
59 
60 /*
61  * Data structures
62  */
63 
64 /** DINS primal heuristic data */
65 struct SCIP_HeurData
66 {
67  SCIP_Longint nodesofs; /**< number of nodes added to the contingent of the total nodes */
68  SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
69  SCIP_Longint minnodes; /**< minimum number of nodes to regard in the subproblem */
70  SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
71  SCIP_Longint nwaitingnodes; /**< number of nodes without incumbent change that heuristic should wait */
72  SCIP_Real minimprove; /**< factor by which DINS should at least improve the incumbent */
73  SCIP_Longint usednodes; /**< nodes already used by DINS in earlier calls */
74  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
75  SCIP_Real nodelimit; /**< the nodelimit employed in the current sub-SCIP, for the event handler*/
76  SCIP_Real lplimfac; /**< factor by which the limit on the number of LP depends on the node limit */
77  int neighborhoodsize; /**< radius of the incumbent's neighborhood to be searched */
78  SCIP_Bool* delta; /**< stores whether a variable kept its value from root LP all the time */
79  int deltalength; /**< if there are no binary variables, we need no flag array */
80  SCIP_Longint lastnsolsfound; /**< solutions found until the last call of DINS */
81  int solnum; /**< number of pool-solutions to be checked for flag array update */
82  SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
83  SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
84  * to constraints in subproblem?
85  */
86 };
87 
88 
89 /*
90  * Local methods
91  */
92 
93 /** creates a subproblem for subscip by fixing a number of variables */
94 static
96  SCIP* scip, /**< SCIP data structure of the original problem */
97  SCIP* subscip, /**< SCIP data structure of the subproblem */
98  SCIP_VAR** vars, /**< variables of the original problem */
99  SCIP_VAR** subvars, /**< variables of the subproblem */
100  int nbinvars, /**< number of binary variables of problem and subproblem */
101  int nintvars, /**< number of general integer variables of problem and subproblem */
102  int* fixingcounter, /**< number of integer variables that get fixed */
103  SCIP_Bool uselprows /**< should subproblem be created out of the rows in the LP rows? */
104  )
105 {
106  SCIP_SOL* bestsol;
107  int i;
108 
109  assert(scip != NULL);
110  assert(subscip != NULL);
111  assert(vars != NULL);
112  assert(subvars != NULL);
113 
114  /* get the best MIP-solution known so far */
115  bestsol = SCIPgetBestSol(scip);
116  assert(bestsol != NULL);
117 
118  /* create the rebounded general integer variables of the subproblem */
119  for( i = nbinvars; i < nbinvars + nintvars; i++ )
120  {
121  SCIP_Real mipsol;
122  SCIP_Real lpsol;
123 
124  SCIP_Real lbglobal;
125  SCIP_Real ubglobal;
126 
127  /* get the bounds for each variable */
128  lbglobal = SCIPvarGetLbGlobal(vars[i]);
129  ubglobal = SCIPvarGetUbGlobal(vars[i]);
130 
131  assert(SCIPvarGetType(vars[i]) == SCIP_VARTYPE_INTEGER);
132  /* get the current LP solution for each variable */
133  lpsol = SCIPvarGetLPSol(vars[i]);
134  /* get the current MIP solution for each variable */
135  mipsol = SCIPgetSolVal(scip, bestsol, vars[i]);
136 
137  /* if the solution values differ by 0.5 or more, the variable is rebounded, otherwise it is just copied */
138  if( REALABS(lpsol-mipsol) >= 0.5 )
139  {
140  SCIP_Real lb;
141  SCIP_Real ub;
142  SCIP_Real range;
143 
144  lb = lbglobal;
145  ub = ubglobal;
146 
147  /* create a equally sized range around lpsol for general integers: bounds are lpsol +- (mipsol-lpsol) */
148  range = 2*lpsol-mipsol;
149 
150  if( mipsol >= lpsol )
151  {
152  range = SCIPfeasCeil(scip, range);
153  lb = MAX(lb, range);
154 
155  /* when the bound new upper bound is equal to the current MIP solution, we set both bounds to the integral bound (without eps) */
156  if( SCIPisFeasEQ(scip, mipsol, lb) )
157  ub = lb;
158  else
159  ub = mipsol;
160  }
161  else
162  {
163  range = SCIPfeasFloor(scip, range);
164  ub = MIN(ub, range);
165 
166  /* when the bound new upper bound is equal to the current MIP solution, we set both bounds to the integral bound (without eps) */
167  if( SCIPisFeasEQ(scip, mipsol, ub) )
168  lb = ub;
169  else
170  lb = mipsol;
171  }
172 
173  /* the global domain of variables might have been reduced since incumbent was found: adjust lb and ub accordingly */
174  lb = MAX(lb, lbglobal);
175  ub = MIN(ub, ubglobal);
176 
177  /* perform the bound change */
178  SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[i], lb) );
179  SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[i], ub) );
180 
181  if( ub-lb < 0.5 )
182  (*fixingcounter)++;
183  }
184  else
185  {
186  /* the global domain of variables might have been reduced since incumbent was found: adjust it accordingly */
187  mipsol = MAX(mipsol, lbglobal);
188  mipsol = MIN(mipsol, ubglobal);
189 
190  /* hard fixing for general integer variables with abs(mipsol-lpsol) < 0.5 */
191  SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[i], mipsol) );
192  SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[i], mipsol) );
193  (*fixingcounter)++;
194  }
195  }
196 
197  if( uselprows )
198  {
199  SCIP_ROW** rows; /* original scip rows */
200  int nrows;
201 
202  /* get the rows and their number */
203  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
204 
205  /* copy all rows to linear constraints */
206  for( i = 0; i < nrows; i++ )
207  {
208  SCIP_CONS* cons;
209  SCIP_VAR** consvars;
210  SCIP_COL** cols;
211  SCIP_Real constant;
212  SCIP_Real lhs;
213  SCIP_Real rhs;
214  SCIP_Real* vals;
215 
216  int nnonz;
217  int j;
218 
219  /* ignore rows that are only locally valid */
220  if( SCIProwIsLocal(rows[i]) )
221  continue;
222 
223  /* get the row's data */
224  constant = SCIProwGetConstant(rows[i]);
225  lhs = SCIProwGetLhs(rows[i]) - constant;
226  rhs = SCIProwGetRhs(rows[i]) - constant;
227  vals = SCIProwGetVals(rows[i]);
228  nnonz = SCIProwGetNNonz(rows[i]);
229  cols = SCIProwGetCols(rows[i]);
230 
231  assert(lhs <= rhs);
232 
233  /* allocate memory array to be filled with the corresponding subproblem variables */
234  SCIP_CALL( SCIPallocBufferArray(subscip, &consvars, nnonz) );
235  for( j = 0; j < nnonz; j++ )
236  consvars[j] = subvars [ SCIPvarGetProbindex(SCIPcolGetVar(cols[j])) ];
237 
238  /* create a new linear constraint and add it to the subproblem */
239  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, SCIProwGetName(rows[i]), nnonz, consvars, vals, lhs, rhs,
240  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE) );
241  SCIP_CALL( SCIPaddCons(subscip, cons) );
242  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
243 
244  /* free temporary memory */
245  SCIPfreeBufferArray(subscip, &consvars);
246  }
247  }
248 
249  return SCIP_OKAY;
250 }
251 
252 /** create the extra constraint of local branching and add it to subscip */
253 static
255  SCIP* scip, /**< SCIP data structure of the original problem */
256  SCIP* subscip, /**< SCIP data structure of the subproblem */
257  SCIP_VAR** subvars, /**< variables of the subproblem */
258  SCIP_HEURDATA* heurdata, /**< heuristic's data structure */
259  SCIP_Bool* fixed /**< TRUE --> include variable in LB constraint */
260  )
261 {
262  SCIP_CONS* cons; /* local branching constraint to create */
263  SCIP_VAR** consvars;
264  SCIP_VAR** vars;
265  SCIP_SOL* bestsol;
266 
267  SCIP_Real* consvals;
268  SCIP_Real solval;
269  SCIP_Real lhs;
270  SCIP_Real rhs;
271 
272  char consname[SCIP_MAXSTRLEN];
273 
274  int nbinvars;
275  int i;
276 
277  (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "%s_dinsLBcons", SCIPgetProbName(scip));
278 
279  /* get the data of the variables and the best solution */
280  SCIP_CALL( SCIPgetVarsData(scip, &vars, NULL, &nbinvars, NULL, NULL, NULL) );
281  bestsol = SCIPgetBestSol(scip);
282  assert(bestsol != NULL);
283 
284  /* memory allocation */
285  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nbinvars) );
286  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nbinvars) );
287 
288  /* set initial left and right hand sides of local branching constraint */
289  lhs = 0.0;
290  rhs = (SCIP_Real) heurdata->neighborhoodsize;
291 
292  /* create the distance function of the binary variables (to incumbent solution) */
293  for( i = 0; i < nbinvars; i++ )
294  {
295  consvars[i] = subvars[i];
296  assert(SCIPvarGetType(consvars[i]) == SCIP_VARTYPE_BINARY);
297  if( fixed[i] )
298  {
299  consvals[i]=0.0;
300  continue;
301  }
302 
303  solval = SCIPgetSolVal(scip, bestsol, vars[i]);
304  assert(SCIPisFeasIntegral(scip, solval));
305 
306  /* is variable i part of the binary support of the current solution? */
307  if( SCIPisFeasEQ(scip, solval, 1.0) )
308  {
309  consvals[i] = -1.0;
310  rhs -= 1.0;
311  lhs -= 1.0;
312  }
313  else
314  consvals[i] = 1.0;
315  }
316 
317  /* creates local branching constraint and adds it to subscip */
318  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, consname, nbinvars, consvars, consvals,
319  lhs, rhs, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE) );
320  SCIP_CALL( SCIPaddCons(subscip, cons) );
321  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
322 
323  /* free local memory */
324  SCIPfreeBufferArray(scip, &consvals);
325  SCIPfreeBufferArray(scip, &consvars);
326 
327  return SCIP_OKAY;
328 }
329 
330 /** creates a new solution for the original problem by copying the solution of the subproblem */
331 static
333  SCIP* scip, /**< original SCIP data structure */
334  SCIP* subscip, /**< SCIP structure of the subproblem */
335  SCIP_VAR** subvars, /**< the variables of the subproblem */
336  SCIP_HEUR* heur, /**< DINS heuristic structure */
337  SCIP_SOL* subsol, /**< solution of the subproblem */
338  SCIP_Bool* success /**< used to store whether new solution was found or not */
339  )
340 {
341  SCIP_VAR** vars; /* the original problem's variables */
342  int nvars;
343  SCIP_Real* subsolvals; /* solution values of the subproblem */
344  SCIP_SOL* newsol; /* solution to be created for the original problem */
345 
346  assert(scip != NULL);
347  assert(heur != NULL);
348  assert(subscip != NULL);
349  assert(subvars != NULL);
350  assert(subsol != NULL);
351 
352  /* get variables' data */
353  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
354  /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
355  * since constraint copying may have required the copy of variables that are fixed in the main SCIP
356  */
357  assert(nvars <= SCIPgetNOrigVars(subscip));
358 
359  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
360 
361  /* copy the solution */
362  SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
363 
364  /* create new solution for the original problem */
365  SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
366  SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
367 
368  /* try to add new solution to scip and free it immediately */
369  SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, success) );
370  if( *success )
371  {
372  SCIPdebugMessage("DINS successfully found new solution\n");
373  }
374 
375  SCIPfreeBufferArray(scip, &subsolvals);
376  return SCIP_OKAY;
377 }
378 
379 
380 /* ---------------- Callback methods of event handler ---------------- */
381 
382 /* exec the event handler
383  *
384  * we interrupt the solution process
385  */
386 static
387 SCIP_DECL_EVENTEXEC(eventExecDins)
388 {
389  SCIP_HEURDATA* heurdata;
390 
391  assert(eventhdlr != NULL);
392  assert(eventdata != NULL);
393  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
394  assert(event != NULL);
395  assert(SCIPeventGetType(event) & SCIP_EVENTTYPE_LPSOLVED);
396 
397  heurdata = (SCIP_HEURDATA*)eventdata;
398  assert(heurdata != NULL);
399 
400  /* interrupt solution process of sub-SCIP */
401  if( SCIPgetNLPs(scip) > heurdata->lplimfac * heurdata->nodelimit )
402  {
403  SCIPdebugMessage("interrupt after %" SCIP_LONGINT_FORMAT " LPs\n",SCIPgetNLPs(scip));
405  }
406 
407  return SCIP_OKAY;
408 }
409 
410 
411 /*
412  * Callback methods of primal heuristic
413  */
414 
415 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
416 static
417 SCIP_DECL_HEURCOPY(heurCopyDins)
418 { /*lint --e{715}*/
419  assert(scip != NULL);
420  assert(heur != NULL);
421  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
422 
423  /* call inclusion method of primal heuristic */
425 
426  return SCIP_OKAY;
427 }
428 
429 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
430 static
431 SCIP_DECL_HEURFREE(heurFreeDins)
432 { /*lint --e{715}*/
433  SCIP_HEURDATA* heurdata;
434 
435  assert(heur != NULL);
436  assert(scip != NULL);
437 
438  /* get heuristic data */
439  heurdata = SCIPheurGetData(heur);
440  assert(heurdata != NULL);
441 
442  /* free heuristic data */
443  SCIPfreeMemory(scip, &heurdata);
444  SCIPheurSetData(heur, NULL);
445 
446  return SCIP_OKAY;
447 }
448 
449 
450 /** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
451 static
452 SCIP_DECL_HEURINITSOL(heurInitsolDins)
453 {
454  SCIP_HEURDATA* heurdata;
455  int i;
456 
457  assert(heur != NULL);
458  assert(scip != NULL);
459 
460  /* get heuristic's data */
461  heurdata = SCIPheurGetData(heur);
462  assert(heurdata != NULL);
463 
464  /* initialize data */
465  heurdata->usednodes = 0;
466  heurdata->lastnsolsfound = 0;
467 
468  /* create flag array */
469  heurdata->deltalength = SCIPgetNBinVars(scip);
470 
471  /* no binvars => no flag array needed */
472  if( heurdata->deltalength > 0 )
473  {
474  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(heurdata->delta), heurdata->deltalength) );
475  for( i = 0; i < heurdata->deltalength; i++ )
476  heurdata->delta[i] = TRUE;
477  }
478  return SCIP_OKAY;
479 }
480 
481 /** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
482 static
483 SCIP_DECL_HEUREXITSOL(heurExitsolDins)
484 { /*lint --e{715}*/
485  SCIP_HEURDATA* heurdata;
486 
487  assert(heur != NULL);
488  assert(scip != NULL);
489 
490  /* get heuristic data */
491  heurdata = SCIPheurGetData(heur);
492  assert(heurdata != NULL);
493 
494  /* free flag array if exist */
495  if( heurdata->deltalength > 0 )
496  {
497  SCIPfreeBlockMemoryArray(scip, &(heurdata->delta), heurdata->deltalength);
498  }
499  return SCIP_OKAY;
500 }
501 
502 /** execution method of primal heuristic */
503 static
504 SCIP_DECL_HEUREXEC(heurExecDins)
505 { /*lint --e{715}*/
506  SCIP_HEURDATA* heurdata;
507  SCIP* subscip; /* the subproblem created by DINS */
508  SCIP_VAR** subvars; /* subproblem's variables */
509  SCIP_VAR** vars; /* variables of the original problem */
510  SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
511  SCIP_SOL* bestsol; /* best solution known so far */
512  SCIP_SOL** sols; /* list of known solutions */
513  SCIP_EVENTHDLR* eventhdlr; /* event handler for LP events */
514 
515  SCIP_Bool* fixed; /* fixing flag array */
516  SCIP_Bool* delta; /* flag array if variable value changed during solution process */
517 
518 
519  SCIP_Longint maxnnodes; /* maximum number of subnodes */
520  SCIP_Longint nsubnodes; /* nodelimit for subscip */
521  SCIP_Longint nsolsfound;
522 
523  SCIP_Real timelimit; /* timelimit for subscip (equals remaining time of scip) */
524  SCIP_Real cutoff; /* objective cutoff for the subproblem */
525  SCIP_Real upperbound;
526  SCIP_Real memorylimit; /* memory limit for solution process of subscip */
527  SCIP_Real lpsolval;
528  SCIP_Real rootlpsolval;
529  SCIP_Real mipsolval;
530  SCIP_Real solval;
531 
532  int ufcount; /* counts the number of true fixing flag entries */
533  int nvars; /* number of variables in original SCIP */
534  int nbinvars; /* number of binary variables in original SCIP */
535  int nintvars; /* number of general integer variables in original SCIP */
536  int nsols; /* number of known solutions */
537  int nsubsols;
538  int checklength;
539  int fixingcounter;
540  int i;
541  int j;
542 
543  SCIP_Bool success; /* used to store whether new solution was found or not */
544  SCIP_Bool infeasible; /* stores whether the hard fixing of a variables was feasible or not */
545 
546  SCIP_RETCODE retcode;
547 
548  assert(heur != NULL);
549  assert(scip != NULL);
550  assert(result != NULL);
551  assert(SCIPhasCurrentNodeLP(scip));
552 
553  *result = SCIP_DELAYED;
554 
555  /* do not call heuristic of node was already detected to be infeasible */
556  if( nodeinfeasible )
557  return SCIP_OKAY;
558 
559  /* only call heuristic, if a CIP solution is at hand */
560  if( SCIPgetNSols(scip) <= 0 )
561  return SCIP_OKAY;
562 
563  /* only call heuristic, if an optimal LP solution is at hand */
565  return SCIP_OKAY;
566 
567  /* only call heuristic, if the LP objective value is smaller than the cutoff bound */
569  return SCIP_OKAY;
570 
571  /* get heuristic's data */
572  heurdata = SCIPheurGetData(heur);
573  assert(heurdata != NULL);
574  delta = heurdata->delta;
575 
576  /* only call heuristic, if enough nodes were processed since last incumbent */
577  if( SCIPgetNNodes(scip) - SCIPgetSolNodenum(scip, SCIPgetBestSol(scip)) < heurdata->nwaitingnodes )
578  return SCIP_OKAY;
579 
580  *result = SCIP_DIDNOTRUN;
581 
582  /* determine the node limit for the current process */
583  maxnnodes = (SCIP_Longint) (heurdata->nodesquot * SCIPgetNNodes(scip));
584 
585  /* reward DINS if it succeeded often */
586  maxnnodes = (SCIP_Longint) (maxnnodes * (1.0 + 2.0 * (SCIPheurGetNBestSolsFound(heur)+1.0) / (SCIPheurGetNCalls(heur) + 1.0)));
587 
588  /* count the setup costs for the sub-MIP as 100 nodes */
589  maxnnodes -= 100 * SCIPheurGetNCalls(heur);
590  maxnnodes += heurdata->nodesofs;
591 
592  /* determine the node limit for the current process */
593  nsubnodes = maxnnodes - heurdata->usednodes;
594  nsubnodes = MIN(nsubnodes , heurdata->maxnodes);
595 
596  /* check whether we have enough nodes left to call sub problem solving */
597  if( nsubnodes < heurdata->minnodes )
598  return SCIP_OKAY;
599 
600  if( SCIPisStopped(scip) )
601  return SCIP_OKAY;
602 
603  /* get required data of the original problem */
604  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
605  assert(nbinvars <= nvars);
606 
607  /* do not run heuristic if only continuous variables are present */
608  if( nbinvars == 0 && nintvars == 0 )
609  return SCIP_OKAY;
610 
611  assert(vars != NULL);
612 
613  /* initialize the subproblem */
614  SCIP_CALL( SCIPcreate(&subscip) );
615 
616  /* create the variable mapping hash map */
617  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
618  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), SCIPcalcHashtableSize(5 * nvars)) );
619 
620  success = FALSE;
621  eventhdlr = NULL;
622 
623  if( heurdata->uselprows )
624  {
625  char probname[SCIP_MAXSTRLEN];
626 
627  /* copy all plugins */
629 
630  /* get name of the original problem and add the string "_dinssub" */
631  (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s_dinssub", SCIPgetProbName(scip));
632 
633  /* create the subproblem */
634  SCIP_CALL( SCIPcreateProb(subscip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
635 
636  /* copy all variables */
637  SCIP_CALL( SCIPcopyVars(scip, subscip, varmapfw, NULL, TRUE) );
638  }
639  else
640  {
641  SCIP_CALL( SCIPcopy(scip, subscip, varmapfw, NULL, "dins", TRUE, FALSE, TRUE, &success) );
642 
643  if( heurdata->copycuts )
644  {
645  /* copies all active cuts from cutpool of sourcescip to linear constraints in targetscip */
646  SCIP_CALL( SCIPcopyCuts(scip, subscip, varmapfw, NULL, TRUE, NULL) );
647  }
648 
649  /* create event handler for LP events */
650  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecDins, NULL) );
651  if( eventhdlr == NULL )
652  {
653  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
654  return SCIP_PLUGINNOTFOUND;
655  }
656 
657  SCIPdebugMessage("Copying the SCIP instance was %ssuccessful.\n", success ? "" : "not ");
658  }
659 
660  for( i = 0; i < nvars; i++ )
661  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
662 
663  /* free hash map */
664  SCIPhashmapFree(&varmapfw);
665 
666  /* create variables and rebound them if their bounds differ by more than 0.5 */
667  fixingcounter = 0;
668  SCIP_CALL( createSubproblem(scip, subscip, vars, subvars, nbinvars, nintvars, &fixingcounter, heurdata->uselprows) );
669  SCIPdebugMessage("DINS subproblem: %d vars (%d binvars & %d intvars), %d cons\n",
670  SCIPgetNVars(subscip), SCIPgetNBinVars(subscip) , SCIPgetNIntVars(subscip) , SCIPgetNConss(subscip));
671 
672  *result = SCIP_DIDNOTFIND;
673 
674  /* do not abort subproblem on CTRL-C */
675  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
676 
677  /* disable output to console */
678  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
679 
680 #ifdef SCIP_DEBUG
681  /* for debugging DINS, enable MIP output */
682  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
683  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
684 #endif
685 
686  /* check whether there is enough time and memory left */
687  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
688  if( !SCIPisInfinity(scip, timelimit) )
689  timelimit -= SCIPgetSolvingTime(scip);
690  SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
691 
692  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
693  if( !SCIPisInfinity(scip, memorylimit) )
694  {
695  memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
696  memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
697  }
698 
699  /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
700  if( timelimit <= 0.0 || memorylimit <= 2.0*SCIPgetMemExternEstim(scip)/1048576.0 )
701  goto TERMINATE;
702 
703  /* disable statistic timing inside sub SCIP unless we are in debug mode and print the statistic timing */
704 #ifdef SCIP_DEBUG
705  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", TRUE) );
706 #else
707  /* disable statistic timing inside sub SCIP */
708  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
709 #endif
710 
711  /* set limits for the subproblem */
712  heurdata->nodelimit = nsubnodes;
713  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nsubnodes) );
714  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/stallnodes", MAX(10, nsubnodes/10)) );
715  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", 3) );
716  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
717  SCIP_CALL( SCIPsetRealParam(subscip, "limits/memory", memorylimit) );
718 
719  /* forbid recursive call of heuristics and separators solving subMIPs */
720  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
721 
722  /* disable cutting plane separation */
724 
725  /* disable expensive presolving */
727 
728  /* use best estimate node selection */
729  if( SCIPfindNodesel(subscip, "estimate") != NULL && !SCIPisParamFixed(subscip, "nodeselection/estimate/stdpriority") )
730  {
731  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
732  }
733 
734  /* use inference branching */
735  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
736  {
737  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
738  }
739 
740  /* disable conflict analysis */
741  if( !SCIPisParamFixed(subscip, "conflict/useprop") )
742  {
743  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/useprop", FALSE) );
744  }
745  if( !SCIPisParamFixed(subscip, "conflict/useinflp") )
746  {
747  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/useinflp", FALSE) );
748  }
749  if( !SCIPisParamFixed(subscip, "conflict/useboundlp") )
750  {
751  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/useboundlp", FALSE) );
752  }
753  if( !SCIPisParamFixed(subscip, "conflict/usesb") )
754  {
755  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/usesb", FALSE) );
756  }
757  if( !SCIPisParamFixed(subscip, "conflict/usepseudo") )
758  {
759  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/usepseudo", FALSE) );
760  }
761 
762  /* employ a limit on the number of enforcement rounds in the quadratic constraint handler; this fixes the issue that
763  * sometimes the quadratic constraint handler needs hundreds or thousands of enforcement rounds to determine the
764  * feasibility status of a single node without fractional branching candidates by separation (namely for uflquad
765  * instances); however, the solution status of the sub-SCIP might get corrupted by this; hence no deductions shall be
766  * made for the original SCIP
767  */
768  if( SCIPfindConshdlr(subscip, "quadratic") != NULL && !SCIPisParamFixed(subscip, "constraints/quadratic/enfolplimit") )
769  {
770  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/quadratic/enfolplimit", 500) );
771  }
772 
773  /* get the best MIP-solution known so far */
774  bestsol = SCIPgetBestSol(scip);
775  assert(bestsol != NULL);
776 
777  /* get solution pool and number of solutions in pool */
778  sols = SCIPgetSols(scip);
779  nsols = SCIPgetNSols(scip);
780  nsolsfound = SCIPgetNSolsFound(scip);
781  checklength = MIN(nsols, heurdata->solnum);
782  assert(sols != NULL);
783  assert(nsols > 0);
784 
785  /* create fixing flag array */
786  SCIP_CALL( SCIPallocBufferArray(scip, &fixed, nbinvars) );
787 
788  /* if new binary variables have been created, e.g., due to column generation, reallocate the delta array */
789  if( heurdata->deltalength < nbinvars )
790  {
791  int newsize;
792 
793  newsize = SCIPcalcMemGrowSize(scip, nbinvars);
794  assert(newsize >= nbinvars);
795 
796  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &heurdata->delta, heurdata->deltalength, newsize) );
797  delta = heurdata->delta;
798 
799  /* initialize new part of delta array */
800  for( i = heurdata->deltalength; i < newsize; i++ )
801  delta[i] = TRUE;
802 
803  heurdata->deltalength = newsize;
804  }
805 
806  /* fixing for binary variables */
807  /* hard fixing for some with mipsol(s)=lpsolval=rootlpsolval and preparation for soft fixing for the remaining */
808  ufcount = 0;
809  for( i = 0; i < nbinvars; i++ )
810  {
811  /* soft fixing if the variable somewhen changed its value or the relaxations differ by adding a local branching constraint */
812  fixed[i] = FALSE;
813 
814  /* get the current LP solution for each variable */
815  lpsolval = SCIPvarGetLPSol(vars[i]);
816  /* get the current MIP solution for each variable */
817  mipsolval = SCIPgetSolVal(scip, bestsol, vars[i]);
818  /* get the root LP solution for each variable */
819  rootlpsolval = SCIPvarGetRootSol(vars[i]);
820 
821  if( SCIPisFeasEQ(scip, lpsolval, mipsolval) && SCIPisFeasEQ(scip, mipsolval, rootlpsolval) )
822  {
823  /* update delta */
824  if( nsols > 1 && heurdata->lastnsolsfound != nsolsfound && delta[i] ) /* no need to update delta[i] if already FALSE */
825  {
826  /* no need to update delta[i] if already FALSE or sols[i] already checked on previous run or worse than DINS-solution of last run */
827  for( j = 0; delta[i] && j < checklength && SCIPgetSolHeur(scip, sols[j]) != heur ; j++ )
828  {
829  solval = SCIPgetSolVal(scip, sols[j], vars[i]);
830  delta[i] = delta[i] && SCIPisFeasEQ(scip, mipsolval, solval);
831  }
832  }
833 
834  /* hard fixing if rootlpsolval=nodelpsolval=mipsolval(s) and delta (is TRUE) */
835  if( delta[i] && SCIPisFeasEQ(scip, mipsolval, lpsolval) && SCIPisFeasEQ(scip, mipsolval, rootlpsolval)
836  && SCIPisFeasEQ(scip, rootlpsolval, lpsolval)
837  && !SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(subvars[i]), SCIPvarGetUbGlobal(subvars[i])) )
838  {
839  SCIP_CALL( SCIPfixVar(subscip, subvars[i], mipsolval, &infeasible, &success) );
840  fixed[i] = !infeasible;
841 
842  if( success )
843  fixingcounter++;
844  else
845  {
846  SCIPdebugMessage("variable %d was already fixed\n", i);
847  }
848 
849  if( infeasible )
850  {
851  SCIPdebugMessage("fixing of variable %d to value %f was infeasible\n", i, mipsolval);
852  }
853  }
854  }
855  if( !fixed[i] )
856  ufcount++;
857  }
858 
859  /* store the number of found solutions for next run */
860  heurdata->lastnsolsfound = nsolsfound;
861 
862  /* perform prepared softfixing for all unfixed vars if the number of unfixed vars is larger than the neighborhoodsize (otherwise it will be useless) */
863  if( ufcount > heurdata->neighborhoodsize )
864  {
865  SCIP_CALL( addLocalBranchingConstraint(scip, subscip, subvars, heurdata, fixed) );
866  }
867 
868  /* free fixing flag array */
869  SCIPfreeBufferArray(scip, &fixed);
870 
871  /* abort, if all integer variables were fixed (which should not happen for MIP),
872  * but frequently happens for MINLPs using an LP relaxation
873  */
874  if( fixingcounter == nbinvars + nintvars )
875  goto TERMINATE;
876 
877  /* abort, if the amount of fixed variables is insufficient */
878  if( fixingcounter / (SCIP_Real)(MAX(nbinvars + nintvars, 1)) < heurdata->minfixingrate )
879  goto TERMINATE;
880 
881  /* add an objective cutoff */
882  cutoff = SCIPinfinity(scip);
884 
886  {
887  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip) + heurdata->minimprove * SCIPgetLowerbound(scip);
888  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
889  cutoff = MIN(upperbound, cutoff);
890  }
891  else
892  {
893  if( SCIPgetUpperbound(scip) >= 0 )
894  cutoff = (1 - heurdata->minimprove) * SCIPgetUpperbound(scip);
895  else
896  cutoff = (1 + heurdata->minimprove) * SCIPgetUpperbound(scip);
897  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
898  cutoff = MIN(upperbound, cutoff);
899  }
900  SCIP_CALL( SCIPsetObjlimit(subscip, cutoff) );
901 
902  /* catch LP events of sub-SCIP */
903  if( !heurdata->uselprows )
904  {
905  assert(eventhdlr != NULL);
906 
907  SCIP_CALL( SCIPtransformProb(subscip) );
908  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
909  }
910 
911  /* solve the subproblem */
912  SCIPdebugMessage("solving DINS sub-MIP with neighborhoodsize %d and maxnodes %" SCIP_LONGINT_FORMAT "\n", heurdata->neighborhoodsize, nsubnodes);
913  retcode = SCIPsolve(subscip);
914 
915  /* drop LP events of sub-SCIP */
916  if( !heurdata->uselprows )
917  {
918  assert(eventhdlr != NULL);
919 
920  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_LPSOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
921  }
922 
923  /* Errors in solving the subproblem should not kill the overall solving process
924  * Hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
925  */
926  if( retcode != SCIP_OKAY )
927  {
928 #ifndef NDEBUG
929  SCIP_CALL( retcode );
930 #endif
931  SCIPwarningMessage(scip, "Error while solving subproblem in DINS heuristic; sub-SCIP terminated with code <%d>\n", retcode);
932  }
933 
934  /* print solving statistics of subproblem if we are in SCIP's debug mode */
936 
937  heurdata->usednodes += SCIPgetNNodes(subscip);
938  nsubsols = SCIPgetNSols(subscip);
939  SCIPdebugMessage("DINS used %" SCIP_LONGINT_FORMAT "/%" SCIP_LONGINT_FORMAT " nodes and found %d solutions\n", SCIPgetNNodes(subscip), nsubnodes, nsubsols);
940 
941  /* check, whether a (new) solution was found */
942  if( nsubsols > 0 )
943  {
944  SCIP_SOL** subsols;
945 
946  /* check, whether a solution was found; due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted */
947  subsols = SCIPgetSols(subscip);
948  success = FALSE;
949  for( i = 0; i < nsubsols && !success; ++i )
950  {
951  SCIP_CALL( createNewSol(scip, subscip, subvars, heur, subsols[i], &success) );
952  }
953  if( success )
954  *result = SCIP_FOUNDSOL;
955  }
956 
957  TERMINATE:
958  /* free subproblem */
959  SCIPfreeBufferArray(scip, &subvars);
960  SCIP_CALL( SCIPfree(&subscip) );
961 
962  return SCIP_OKAY;
963 }
964 
965 
966 /*
967  * primal heuristic specific interface methods
968  */
969 
970 /** creates the DINS primal heuristic and includes it in SCIP */
972  SCIP* scip /**< SCIP data structure */
973  )
974 {
975  SCIP_HEURDATA* heurdata;
976  SCIP_HEUR* heur;
977 
978  /* create Dins primal heuristic data */
979  SCIP_CALL( SCIPallocMemory(scip, &heurdata) );
980 
981  /* include primal heuristic */
982  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
984  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecDins, heurdata) );
985 
986  assert(heur != NULL);
987 
988  /* set non-NULL pointers to callback methods */
989  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyDins) );
990  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeDins) );
991  SCIP_CALL( SCIPsetHeurInitsol(scip, heur, heurInitsolDins) );
992  SCIP_CALL( SCIPsetHeurExitsol(scip, heur, heurExitsolDins) );
993 
994  /* add DINS primal heuristic parameters */
995  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
996  "number of nodes added to the contingent of the total nodes",
997  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
998  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
999  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
1000  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
1001  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minnodes",
1002  "minimum number of nodes required to start the subproblem",
1003  &heurdata->minnodes, FALSE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1004  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/solnum",
1005  "number of pool-solutions to be checked for flag array update (for hard fixing of binary variables)",
1006  &heurdata->solnum, FALSE, DEFAULT_SOLNUM, 1, INT_MAX, NULL, NULL) );
1007  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/neighborhoodsize",
1008  "radius (using Manhattan metric) of the incumbent's neighborhood to be searched",
1009  &heurdata->neighborhoodsize, FALSE, DEFAULT_NEIGHBORHOODSIZE, 1, INT_MAX, NULL, NULL) );
1010  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
1011  "maximum number of nodes to regard in the subproblem",
1012  &heurdata->maxnodes,TRUE,DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1013  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
1014  "factor by which " HEUR_NAME " should at least improve the incumbent",
1015  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
1016  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nwaitingnodes",
1017  "number of nodes without incumbent change that heuristic should wait",
1018  &heurdata->nwaitingnodes, TRUE, DEFAULT_NWAITINGNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
1019 
1020  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/lplimfac",
1021  "factor by which the limit on the number of LP depends on the node limit",
1022  &heurdata->lplimfac, TRUE, DEFAULT_LPLIMFAC, 1.0, SCIP_REAL_MAX, NULL, NULL) );
1023 
1024  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minfixingrate",
1025  "minimum percentage of integer variables that have to be fixable",
1026  &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, 0.0, 1.0, NULL, NULL) );
1027 
1028  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/uselprows",
1029  "should subproblem be created out of the rows in the LP rows?",
1030  &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
1031 
1032  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/copycuts",
1033  "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
1034  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
1035 
1036  return SCIP_OKAY;
1037 }
SCIP_RETCODE SCIPsetHeurInitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINITSOL((*heurinitsol)))
Definition: scip.c:7361
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip.c:22777
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
Definition: scip.c:40329
int SCIPgetNVars(SCIP *scip)
Definition: scip.c:10698
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:5878
#define SCIPallocMemory(scip, ptr)
Definition: scip.h:20526
#define SCIP_EVENTTYPE_LPSOLVED
Definition: type_event.h:78
#define DEFAULT_LPLIMFAC
Definition: heur_dins.c:46
#define HEUR_FREQ
Definition: heur_dins.c:35
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:41648
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1147
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip.h:20573
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1273
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip.c:7297
#define EVENTHDLR_NAME
Definition: heur_dins.c:57
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1248
#define SCIP_MAXSTRLEN
Definition: def.h:201
#define DEFAULT_NODESOFS
Definition: heur_dins.c:41
#define NULL
Definition: lpi_spx.cpp:130
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1125
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:42032
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:18915
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:18861
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17067
#define EVENTHDLR_DESC
Definition: heur_dins.c:58
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, unsigned int timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip.c:7252
#define FALSE
Definition: def.h:56
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip.c:41009
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2057
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip.c:4046
#define DEFAULT_MAXNODES
Definition: heur_dins.c:42
int SCIPgetNBinVars(SCIP *scip)
Definition: scip.c:10743
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip.c:7778
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:8174
#define DEFAULT_MINFIXINGRATE
Definition: heur_dins.c:47
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
#define HEUR_DISPCHAR
Definition: heur_dins.c:33
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: scip.c:36299
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip.c:4109
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
static SCIP_DECL_HEURFREE(heurFreeDins)
Definition: heur_dins.c:431
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
Definition: scip.c:42008
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
Definition: scip.c:38561
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip.h:20556
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip.c:26439
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3601
#define SCIPdebugMessage
Definition: pub_message.h:77
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip.c:34983
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2116
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:18881
#define SCIP_LONGINT_MAX
Definition: def.h:113
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:24949
SCIP_HEUR * SCIPgetSolHeur(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:35306
SCIP_Real SCIPgetLPObjval(SCIP *scip)
Definition: scip.c:26482
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
Definition: scip.c:42044
static SCIP_DECL_HEURINITSOL(heurInitsolDins)
Definition: heur_dins.c:452
SCIP_Real SCIPgetLowerbound(SCIP *scip)
Definition: scip.c:38393
SCIP_RETCODE SCIPcopyCuts(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
Definition: scip.c:2883
int SCIPgetNSols(SCIP *scip)
Definition: scip.c:35668
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3547
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.c:3573
SCIP_Real SCIPvarGetRootSol(SCIP_VAR *var)
Definition: var.c:12607
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip.c:11138
SCIP_RETCODE SCIPincludeHeurDins(SCIP *scip)
Definition: heur_dins.c:971
#define SCIPfreeMemory(scip, ptr)
Definition: scip.h:20542
int SCIPgetNConss(SCIP *scip)
Definition: scip.c:11736
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip.c:15442
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip.c:3254
static SCIP_RETCODE createSubproblem(SCIP *scip, SCIP *subscip, SCIP_VAR **vars, SCIP_VAR **subvars, int nbinvars, int nintvars, int *fixingcounter, SCIP_Bool uselprows)
Definition: heur_dins.c:95
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:20049
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:18925
#define HEUR_NAME
Definition: heur_dins.c:31
#define DEFAULT_NEIGHBORHOODSIZE
Definition: heur_dins.c:49
int SCIPcalcHashtableSize(int minsize)
Definition: misc.c:1157
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:34002
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:41353
static SCIP_DECL_HEUREXITSOL(heurExitsolDins)
Definition: heur_dins.c:483
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41907
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:19024
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:146
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2075
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:4457
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip.h:20562
#define DEFAULT_NODESQUOT
Definition: heur_dins.c:45
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
Definition: scip.c:9019
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip.c:26750
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:35020
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:41637
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip.c:26354
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip.c:766
SCIP_SOL ** SCIPgetSols(SCIP *scip)
Definition: scip.c:35717
SCIP_Longint SCIPgetNLPs(SCIP *scip)
Definition: scip.c:37435
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:18974
#define HEUR_FREQOFS
Definition: heur_dins.c:36
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip.c:12623
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1068
SCIP_Real SCIPgetUpperbound(SCIP *scip)
Definition: scip.c:38534
static SCIP_DECL_HEURCOPY(heurCopyDins)
Definition: heur_dins.c:417
#define SCIP_Bool
Definition: def.h:53
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:35279
#define DEFAULT_MINNODES
Definition: heur_dins.c:43
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip.c:4001
#define DEFAULT_USELPROWS
Definition: heur_dins.c:51
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip.c:3709
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip.c:4382
SCIP_RETCODE SCIPcopyVars(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global)
Definition: scip.c:2179
#define MAX(x, y)
Definition: tclique_def.h:75
#define DEFAULT_COPYCUTS
Definition: heur_dins.c:53
#define HEUR_PRIORITY
Definition: heur_dins.c:34
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip.c:41396
SCIP_RETCODE SCIPsetHeurExitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXITSOL((*heurexitsol)))
Definition: scip.c:7377
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:4431
Constraint handler for linear constraints in their most general form, .
static SCIP_DECL_HEUREXEC(heurExecDins)
Definition: heur_dins.c:504
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41624
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
Definition: var.c:17431
#define SCIP_REAL_MAX
Definition: def.h:128
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:11477
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip.c:14503
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16608
DINS primal heuristic.
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1293
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:20585
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, SCIP_Bool *success)
Definition: heur_dins.c:332
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17057
#define DEFAULT_SOLNUM
Definition: heur_dins.c:50
#define HEUR_TIMING
Definition: heur_dins.c:38
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip.c:692
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip.c:36588
#define DEFAULT_MINIMPROVE
Definition: heur_dins.c:44
#define REALABS(x)
Definition: def.h:151
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
Definition: scip.c:38746
int SCIPgetNIntVars(SCIP *scip)
Definition: scip.c:10788
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)
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:18871
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:278
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip.c:7313
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:16750
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip.c:8436
#define SCIP_Real
Definition: def.h:127
#define MIN(x, y)
Definition: memory.c:67
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:19972
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip.c:10194
const char * SCIPgetProbName(SCIP *scip)
Definition: scip.c:9941
#define SCIP_Longint
Definition: def.h:112
#define HEUR_MAXDEPTH
Definition: heur_dins.c:37
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:917
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:34885
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip.c:3938
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:18836
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1058
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip.c:10572
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:20597
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip.c:3797
#define SCIPdebug(x)
Definition: pub_message.h:74
#define DEFAULT_NWAITINGNODES
Definition: heur_dins.c:48
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip.c:41422
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip.c:8124
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:18685
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip.c:35767
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3629
SCIP_Real SCIPsumepsilon(SCIP *scip)
Definition: scip.c:41132
default SCIP plugins
#define HEUR_DESC
Definition: heur_dins.c:32
static SCIP_RETCODE addLocalBranchingConstraint(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEURDATA *heurdata, SCIP_Bool *fixed)
Definition: heur_dins.c:254
static SCIP_DECL_EVENTEXEC(eventExecDins)
Definition: heur_dins.c:387
#define HEUR_USESSUBSCIP
Definition: heur_dins.c:39
SCIP_Longint SCIPgetNNodes(SCIP *scip)
Definition: scip.c:37372
SCIP callable library.
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip.c:36554
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip.c:41409