Scippy

SCIP

Solving Constraint Integer Programs

heur_zeroobj.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_zeroobj.c
17  * @brief heuristic that tries to solve the problem without objective. In Gurobi, this heuristic is known as "Hail Mary"
18  * @author Timo Berthold
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 
26 #include "scip/heur_zeroobj.h"
27 #include "scip/cons_linear.h"
28 
29 #define HEUR_NAME "zeroobj"
30 #define HEUR_DESC "heuristic trying to solve the problem without objective"
31 #define HEUR_DISPCHAR 'Z'
32 #define HEUR_PRIORITY 100
33 #define HEUR_FREQ -1
34 #define HEUR_FREQOFS 0
35 #define HEUR_MAXDEPTH 0
36 #define HEUR_TIMING SCIP_HEURTIMING_BEFORENODE | SCIP_HEURTIMING_BEFOREPRESOL
37 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
38 
39 /* event handler properties */
40 #define EVENTHDLR_NAME "Zeroobj"
41 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic"
42 
43 /* default values for zeroobj-specific plugins */
44 #define DEFAULT_MAXNODES 1000LL /* maximum number of nodes to regard in the subproblem */
45 #define DEFAULT_MINIMPROVE 0.01 /* factor by which zeroobj should at least improve the incumbent */
46 #define DEFAULT_MINNODES 100LL /* minimum number of nodes to regard in the subproblem */
47 #define DEFAULT_MAXLPITERS 5000LL /* maximum number of LP iterations to be performed in the subproblem */
48 #define DEFAULT_NODESOFS 100LL /* number of nodes added to the contingent of the total nodes */
49 #define DEFAULT_NODESQUOT 0.1 /* subproblem nodes in relation to nodes of the original problem */
50 #define DEFAULT_ADDALLSOLS FALSE /* should all subproblem solutions be added to the original SCIP? */
51 #define DEFAULT_ONLYWITHOUTSOL TRUE /**< should heuristic only be executed if no primal solution was found, yet? */
52 
53 /*
54  * Data structures
55  */
56 
57 /** primal heuristic data */
58 struct SCIP_HeurData
59 {
60  SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
61  SCIP_Longint minnodes; /**< minimum number of nodes to regard in the subproblem */
62  SCIP_Longint maxlpiters; /**< maximum number of LP iterations to be performed in the subproblem */
63  SCIP_Longint nodesofs; /**< number of nodes added to the contingent of the total nodes */
64  SCIP_Longint usednodes; /**< nodes already used by zeroobj in earlier calls */
65  SCIP_Real minimprove; /**< factor by which zeroobj should at least improve the incumbent */
66  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
67  SCIP_Bool addallsols; /**< should all subproblem solutions be added to the original SCIP? */
68  SCIP_Bool onlywithoutsol; /**< should heuristic only be executed if no primal solution was found, yet? */
69 };
70 
71 
72 /*
73  * Local methods
74  */
75 
76 /** creates a new solution for the original problem by copying the solution of the subproblem */
77 static
79  SCIP* scip, /**< original SCIP data structure */
80  SCIP* subscip, /**< SCIP structure of the subproblem */
81  SCIP_VAR** subvars, /**< the variables of the subproblem */
82  SCIP_HEUR* heur, /**< zeroobj heuristic structure */
83  SCIP_SOL* subsol, /**< solution of the subproblem */
84  SCIP_Bool* success /**< used to store whether new solution was found or not */
85  )
86 {
87  SCIP_VAR** vars; /* the original problem's variables */
88  int nvars; /* the original problem's number of variables */
89  SCIP_Real* subsolvals; /* solution values of the subproblem */
90  SCIP_SOL* newsol; /* solution to be created for the original problem */
91 
92  assert(scip != NULL);
93  assert(subscip != NULL);
94  assert(subvars != NULL);
95  assert(subsol != NULL);
96 
97  /* get variables' data */
98  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
99 
100  /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
101  * since constraint copying may have required the copy of variables that are fixed in the main SCIP
102  */
103  assert(nvars <= SCIPgetNOrigVars(subscip));
104 
105  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
106 
107  /* copy the solution */
108  SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
109 
110  /* create new solution for the original problem */
111  SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
112  SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
113 
114  /* try to add new solution to scip and free it immediately */
115  SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, success) );
116 
117  SCIPfreeBufferArray(scip, &subsolvals);
118 
119  return SCIP_OKAY;
120 }
121 
122 /* ---------------- Callback methods of event handler ---------------- */
123 
124 /* exec the event handler
125  *
126  * we interrupt the solution process
127  */
128 static
129 SCIP_DECL_EVENTEXEC(eventExecZeroobj)
130 {
131  SCIP_HEURDATA* heurdata;
132 
133  assert(eventhdlr != NULL);
134  assert(eventdata != NULL);
135  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
136  assert(event != NULL);
138 
139  heurdata = (SCIP_HEURDATA*)eventdata;
140  assert(heurdata != NULL);
141 
142  /* interrupt solution process of sub-SCIP */
143  if( SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_ITERLIMIT || SCIPgetNLPIterations(scip) >= heurdata->maxlpiters )
144  {
146  }
147 
148  return SCIP_OKAY;
149 }
150 /* ---------------- Callback methods of primal heuristic ---------------- */
151 
152 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
153 static
154 SCIP_DECL_HEURCOPY(heurCopyZeroobj)
155 { /*lint --e{715}*/
156  assert(scip != NULL);
157  assert(heur != NULL);
158  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
159 
160  /* call inclusion method of primal heuristic */
162 
163  return SCIP_OKAY;
164 }
165 
166 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
167 static
168 SCIP_DECL_HEURFREE(heurFreeZeroobj)
169 { /*lint --e{715}*/
170  SCIP_HEURDATA* heurdata;
171 
172  assert( heur != NULL );
173  assert( scip != NULL );
174 
175  /* get heuristic data */
176  heurdata = SCIPheurGetData(heur);
177  assert( heurdata != NULL );
178 
179  /* free heuristic data */
180  SCIPfreeMemory(scip, &heurdata);
181  SCIPheurSetData(heur, NULL);
182 
183  return SCIP_OKAY;
184 }
185 
186 
187 /** initialization method of primal heuristic (called after problem was transformed) */
188 static
189 SCIP_DECL_HEURINIT(heurInitZeroobj)
190 { /*lint --e{715}*/
191  SCIP_HEURDATA* heurdata;
192 
193  assert( heur != NULL );
194  assert( scip != NULL );
195 
196  /* get heuristic data */
197  heurdata = SCIPheurGetData(heur);
198  assert( heurdata != NULL );
199 
200  /* initialize data */
201  heurdata->usednodes = 0;
202 
203  return SCIP_OKAY;
204 }
205 
206 
207 /** execution method of primal heuristic */
208 static
209 SCIP_DECL_HEUREXEC(heurExecZeroobj)
210 { /*lint --e{715}*/
211 
212  SCIP_HEURDATA* heurdata; /* heuristic's data */
213  SCIP_Longint nnodes; /* number of stalling nodes for the subproblem */
214 
215  assert( heur != NULL );
216  assert( scip != NULL );
217  assert( result != NULL );
218 
219  /* get heuristic data */
220  heurdata = SCIPheurGetData(heur);
221  assert( heurdata != NULL );
222 
223  /* calculate the maximal number of branching nodes until heuristic is aborted */
224  nnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
225 
226  /* reward zeroobj if it succeeded often */
227  nnodes = (SCIP_Longint)(nnodes * 3.0 * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0));
228  nnodes -= 100 * SCIPheurGetNCalls(heur); /* count the setup costs for the sub-SCIP as 100 nodes */
229  nnodes += heurdata->nodesofs;
230 
231  /* determine the node limit for the current process */
232  nnodes -= heurdata->usednodes;
233  nnodes = MIN(nnodes, heurdata->maxnodes);
234 
235  /* check whether we have enough nodes left to call subproblem solving */
236  if( nnodes < heurdata->minnodes )
237  {
238  SCIPdebugMessage("skipping zeroobj: nnodes=%" SCIP_LONGINT_FORMAT ", minnodes=%" SCIP_LONGINT_FORMAT "\n", nnodes, heurdata->minnodes);
239  return SCIP_OKAY;
240  }
241 
242  /* do not run zeroobj, if the problem does not have an objective function anyway */
243  if( SCIPgetNObjVars(scip) == 0 )
244  {
245  SCIPdebugMessage("skipping zeroobj: pure feasibility problem anyway\n");
246  return SCIP_OKAY;
247  }
248 
249  if( SCIPisStopped(scip) )
250  return SCIP_OKAY;
251 
252  SCIP_CALL( SCIPapplyZeroobj(scip, heur, result, heurdata->minimprove, nnodes) );
253 
254  return SCIP_OKAY;
255 }
256 
257 
258 /*
259  * primal heuristic specific interface methods
260  */
261 
262 
263 /** main procedure of the zeroobj heuristic, creates and solves a sub-SCIP */
265  SCIP* scip, /**< original SCIP data structure */
266  SCIP_HEUR* heur, /**< heuristic data structure */
267  SCIP_RESULT* result, /**< result data structure */
268  SCIP_Real minimprove, /**< factor by which zeroobj should at least improve the incumbent */
269  SCIP_Longint nnodes /**< node limit for the subproblem */
270  )
271 {
272  SCIP* subscip; /* the subproblem created by zeroobj */
273  SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
274  SCIP_VAR** vars; /* original problem's variables */
275  SCIP_VAR** subvars; /* subproblem's variables */
276  SCIP_HEURDATA* heurdata; /* heuristic's private data structure */
277  SCIP_EVENTHDLR* eventhdlr; /* event handler for LP events */
278 
279  SCIP_Real cutoff; /* objective cutoff for the subproblem */
280  SCIP_Real timelimit; /* time limit for zeroobj subproblem */
281  SCIP_Real memorylimit; /* memory limit for zeroobj subproblem */
282  SCIP_Real large;
283 
284  int nvars; /* number of original problem's variables */
285  int i;
286 
287  SCIP_Bool success;
288  SCIP_Bool valid;
289  SCIP_RETCODE retcode;
290  SCIP_SOL** subsols;
291  int nsubsols;
292 
293  assert(scip != NULL);
294  assert(heur != NULL);
295  assert(result != NULL);
296 
297  assert(nnodes >= 0);
298  assert(0.0 <= minimprove && minimprove <= 1.0);
299 
300  *result = SCIP_DIDNOTRUN;
301 
302  /* only call heuristic once at the root */
303  if( SCIPgetDepth(scip) <= 0 && SCIPheurGetNCalls(heur) > 0 )
304  return SCIP_OKAY;
305 
306  /* get heuristic data */
307  heurdata = SCIPheurGetData(heur);
308  assert(heurdata != NULL);
309 
310  /* only call the heuristic if we do not have an incumbent */
311  if( SCIPgetNSolsFound(scip) > 0 && heurdata->onlywithoutsol )
312  return SCIP_OKAY;
313 
314  /* check whether there is enough time and memory left */
315  timelimit = 0.0;
316  memorylimit = 0.0;
317  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
318  if( !SCIPisInfinity(scip, timelimit) )
319  timelimit -= SCIPgetSolvingTime(scip);
320  SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
321 
322  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
323  if( !SCIPisInfinity(scip, memorylimit) )
324  {
325  memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
326  memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
327  }
328 
329  /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
330  if( timelimit <= 0.0 || memorylimit <= 2.0*SCIPgetMemExternEstim(scip)/1048576.0 )
331  return SCIP_OKAY;
332 
333  *result = SCIP_DIDNOTFIND;
334 
335  /* get variable data */
336  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
337 
338  /* initialize the subproblem */
339  SCIP_CALL( SCIPcreate(&subscip) );
340 
341  /* create the variable mapping hash map */
342  SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(subscip), SCIPcalcHashtableSize(5 * nvars)) );
343  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
344 
345  /* different methods to create sub-problem: either copy LP relaxation or the CIP with all constraints */
346  valid = FALSE;
347 
348  /* copy complete SCIP instance */
349  SCIP_CALL( SCIPcopy(scip, subscip, varmapfw, NULL, "zeroobj", TRUE, FALSE, TRUE, &valid) );
350  SCIPdebugMessage("Copying the SCIP instance was %s complete.\n", valid ? "" : "not ");
351 
352  /* create event handler for LP events */
353  eventhdlr = NULL;
354  SCIP_CALL( SCIPincludeEventhdlrBasic(subscip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecZeroobj, NULL) );
355  if( eventhdlr == NULL )
356  {
357  SCIPerrorMessage("event handler for " HEUR_NAME " heuristic not found.\n");
358  return SCIP_PLUGINNOTFOUND;
359  }
360 
361  /* determine large value to set variables to */
362  large = SCIPinfinity(scip);
363  if( !SCIPisInfinity(scip, 0.1 / SCIPfeastol(scip)) )
364  large = 0.1 / SCIPfeastol(scip);
365 
366  /* get variable image and change to 0.0 in sub-SCIP */
367  for( i = 0; i < nvars; i++ )
368  {
369  SCIP_Real adjustedbound;
370  SCIP_Real lb;
371  SCIP_Real ub;
372  SCIP_Real inf;
373 
374  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
375  SCIP_CALL( SCIPchgVarObj(subscip, subvars[i], 0.0) );
376 
377  lb = SCIPvarGetLbGlobal(subvars[i]);
378  ub = SCIPvarGetUbGlobal(subvars[i]);
379  inf = SCIPinfinity(subscip);
380 
381  /* adjust infinite bounds in order to avoid that variables with non-zero objective
382  * get fixed to infinite value in zeroobj subproblem
383  */
384  if( SCIPisInfinity(subscip, ub ) )
385  {
386  adjustedbound = MAX(large, lb+large);
387  adjustedbound = MIN(adjustedbound, inf);
388  SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[i], adjustedbound) );
389  }
390  if( SCIPisInfinity(subscip, -lb ) )
391  {
392  adjustedbound = MIN(-large, ub-large);
393  adjustedbound = MAX(adjustedbound, -inf);
394  SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[i], adjustedbound) );
395  }
396  }
397 
398  /* free hash map */
399  SCIPhashmapFree(&varmapfw);
400 
401  /* do not abort subproblem on CTRL-C */
402  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
403 
404  /* disable output to console */
405  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
406 
407  /* disable statistic timing inside sub SCIP */
408  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
409 
410  /* set limits for the subproblem */
411  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nnodes) );
412  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
413  SCIP_CALL( SCIPsetRealParam(subscip, "limits/memory", memorylimit) );
414  SCIP_CALL( SCIPsetIntParam(subscip, "limits/solutions", 1) );
415 
416  /* forbid recursive call of heuristics and separators solving sub-SCIPs */
417  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
418 
419  /* disable expensive techniques that merely work on the dual bound */
420 
421  /* disable cutting plane separation */
423 
424  /* disable expensive presolving */
426  if( !SCIPisParamFixed(subscip, "presolving/maxrounds") )
427  {
428  SCIP_CALL( SCIPsetIntParam(subscip, "presolving/maxrounds", 50) );
429  }
430 
431  /* use dfs node selection */
432  if( SCIPfindNodesel(subscip, "restartdfs") != NULL && !SCIPisParamFixed(subscip, "nodeselection/restartdfs/stdpriority") )
433  {
434  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/restartdfs/stdpriority", INT_MAX/4) );
435  }
436 
437  /* use least infeasible branching */
438  if( SCIPfindBranchrule(subscip, "leastinf") != NULL && !SCIPisParamFixed(subscip, "branching/leastinf/priority") )
439  {
440  SCIP_CALL( SCIPsetIntParam(subscip, "branching/leastinf/priority", INT_MAX/4) );
441  }
442 
443  /* employ a limit on the number of enforcement rounds in the quadratic constraint handler; this fixes the issue that
444  * sometimes the quadratic constraint handler needs hundreds or thousands of enforcement rounds to determine the
445  * feasibility status of a single node without fractional branching candidates by separation (namely for uflquad
446  * instances); however, the solution status of the sub-SCIP might get corrupted by this; hence no deductions shall be
447  * made for the original SCIP
448  */
449  if( SCIPfindConshdlr(subscip, "quadratic") != NULL && !SCIPisParamFixed(subscip, "constraints/quadratic/enfolplimit") )
450  {
451  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/quadratic/enfolplimit", 10) );
452  }
453 
454  /* disable feaspump and fracdiving */
455  if( !SCIPisParamFixed(subscip, "heuristics/feaspump/freq") )
456  {
457  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/feaspump/freq", -1) );
458  }
459  if( !SCIPisParamFixed(subscip, "heuristics/fracdiving/freq") )
460  {
461  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/fracdiving/freq", -1) );
462  }
463 
464  /* restrict LP iterations */
465  SCIP_CALL( SCIPsetLongintParam(subscip, "lp/iterlim", 2*heurdata->maxlpiters / MAX(1,nnodes)) );
466  SCIP_CALL( SCIPsetLongintParam(subscip, "lp/rootiterlim", heurdata->maxlpiters) );
467 
468 #ifdef SCIP_DEBUG
469  /* for debugging zeroobj, enable MIP output */
470  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
471  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
472 #endif
473 
474  /* if there is already a solution, add an objective cutoff */
475  if( SCIPgetNSols(scip) > 0 )
476  {
477  SCIP_Real upperbound;
478  SCIP_CONS* origobjcons;
479 #ifndef NDEBUG
480  int nobjvars;
481  nobjvars = 0;
482 #endif
483 
484  cutoff = SCIPinfinity(scip);
485  assert( !SCIPisInfinity(scip,SCIPgetUpperbound(scip)) );
486 
487  upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
488 
489  if( !SCIPisInfinity(scip,-1.0*SCIPgetLowerbound(scip)) )
490  {
491  cutoff = (1-minimprove)*SCIPgetUpperbound(scip) + minimprove*SCIPgetLowerbound(scip);
492  }
493  else
494  {
495  if( SCIPgetUpperbound(scip) >= 0 )
496  cutoff = ( 1 - minimprove ) * SCIPgetUpperbound ( scip );
497  else
498  cutoff = ( 1 + minimprove ) * SCIPgetUpperbound ( scip );
499  }
500  cutoff = MIN(upperbound, cutoff);
501 
502  SCIP_CALL( SCIPcreateConsLinear(subscip, &origobjcons, "objbound_of_origscip", 0, NULL, NULL, -SCIPinfinity(subscip), cutoff,
504  for( i = 0; i < nvars; ++i)
505  {
506  if( !SCIPisFeasZero(subscip, SCIPvarGetObj(vars[i])) )
507  {
508  SCIP_CALL( SCIPaddCoefLinear(subscip, origobjcons, subvars[i], SCIPvarGetObj(vars[i])) );
509 #ifndef NDEBUG
510  nobjvars++;
511 #endif
512  }
513  }
514  SCIP_CALL( SCIPaddCons(subscip, origobjcons) );
515  SCIP_CALL( SCIPreleaseCons(subscip, &origobjcons) );
516  assert(nobjvars == SCIPgetNObjVars(scip));
517  }
518 
519  /* catch LP events of sub-SCIP */
520  SCIP_CALL( SCIPtransformProb(subscip) );
521  SCIP_CALL( SCIPcatchEvent(subscip, SCIP_EVENTTYPE_NODESOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, NULL) );
522 
523  SCIPdebugMessage("solving subproblem: nnodes=%" SCIP_LONGINT_FORMAT "\n", nnodes);
524  retcode = SCIPsolve(subscip);
525 
526  /* drop LP events of sub-SCIP */
527  SCIP_CALL( SCIPdropEvent(subscip, SCIP_EVENTTYPE_NODESOLVED, eventhdlr, (SCIP_EVENTDATA*) heurdata, -1) );
528 
529  /* errors in solving the subproblem should not kill the overall solving process;
530  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
531  */
532  if( retcode != SCIP_OKAY )
533  {
534 #ifndef NDEBUG
535  SCIP_CALL( retcode );
536 #endif
537  SCIPwarningMessage(scip, "Error while solving subproblem in zeroobj heuristic; sub-SCIP terminated with code <%d>\n",retcode);
538  }
539 
540  /* check, whether a solution was found;
541  * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted
542  */
543  nsubsols = SCIPgetNSols(subscip);
544  subsols = SCIPgetSols(subscip);
545  success = FALSE;
546  for( i = 0; i < nsubsols && (!success || heurdata->addallsols); ++i )
547  {
548  SCIP_CALL( createNewSol(scip, subscip, subvars, heur, subsols[i], &success) );
549  if( success )
550  *result = SCIP_FOUNDSOL;
551  }
552 
553 #ifdef SCIP_DEBUG
554  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
555 #endif
556 
557  /* free subproblem */
558  SCIPfreeBufferArray(scip, &subvars);
559  SCIP_CALL( SCIPfree(&subscip) );
560 
561  return SCIP_OKAY;
562 }
563 
564 
565 /** creates the zeroobj primal heuristic and includes it in SCIP */
567  SCIP* scip /**< SCIP data structure */
568  )
569 {
570  SCIP_HEURDATA* heurdata;
571  SCIP_HEUR* heur;
572 
573  /* create heuristic data */
574  SCIP_CALL( SCIPallocMemory(scip, &heurdata) );
575 
576  /* include primal heuristic */
577  heur = NULL;
578  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
580  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecZeroobj, heurdata) );
581  assert(heur != NULL);
582 
583  /* set non-NULL pointers to callback methods */
584  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyZeroobj) );
585  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeZeroobj) );
586  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitZeroobj) );
587 
588  /* add zeroobj primal heuristic parameters */
589  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
590  "maximum number of nodes to regard in the subproblem",
591  &heurdata->maxnodes, TRUE,DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
592 
593  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
594  "number of nodes added to the contingent of the total nodes",
595  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
596 
597  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/minnodes",
598  "minimum number of nodes required to start the subproblem",
599  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
600 
601  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/" HEUR_NAME "/maxlpiters",
602  "maximum number of LP iterations to be performed in the subproblem",
603  &heurdata->maxlpiters, TRUE, DEFAULT_MAXLPITERS, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
604 
605  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
606  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
607  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
608 
609  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprove",
610  "factor by which zeroobj should at least improve the incumbent",
611  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
612 
613  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/addallsols",
614  "should all subproblem solutions be added to the original SCIP?",
615  &heurdata->addallsols, TRUE, DEFAULT_ADDALLSOLS, NULL, NULL) );
616 
617  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/onlywithoutsol",
618  "should heuristic only be executed if no primal solution was found, yet?",
619  &heurdata->onlywithoutsol, TRUE, DEFAULT_ONLYWITHOUTSOL, NULL, NULL) );
620 
621  return SCIP_OKAY;
622 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:51
#define HEUR_FREQ
Definition: heur_zeroobj.c:33
#define DEFAULT_MAXLPITERS
Definition: heur_zeroobj.c:47
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
Definition: scip.c:40329
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:5878
#define SCIPallocMemory(scip, ptr)
Definition: scip.h:20526
#define DEFAULT_NODESOFS
Definition: heur_zeroobj.c:48
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:41648
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1147
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
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1248
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
Definition: scip.c:37454
#define NULL
Definition: lpi_spx.cpp:130
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1125
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17067
static SCIP_DECL_HEURINIT(heurInitZeroobj)
Definition: heur_zeroobj.c:189
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 HEUR_FREQOFS
Definition: heur_zeroobj.c:34
#define DEFAULT_ADDALLSOLS
Definition: heur_zeroobj.c:50
#define FALSE
Definition: def.h:56
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2057
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip.c:41009
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip.c:4046
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
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
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_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:41972
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip.c:4109
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip.c:19590
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
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 SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:16905
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2116
#define SCIP_LONGINT_MAX
Definition: def.h:113
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:24949
SCIP_Real SCIPgetLowerbound(SCIP *scip)
Definition: scip.c:38393
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
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip.c:11138
#define DEFAULT_ONLYWITHOUTSOL
Definition: heur_zeroobj.c:51
#define SCIPfreeMemory(scip, ptr)
Definition: scip.h:20542
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
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:20049
#define SCIPerrorMessage
Definition: pub_message.h:45
static SCIP_DECL_HEURCOPY(heurCopyZeroobj)
Definition: heur_zeroobj.c:154
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
#define EVENTHDLR_NAME
Definition: heur_zeroobj.c:40
#define DEFAULT_MINIMPROVE
Definition: heur_zeroobj.c:45
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
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_RETCODE SCIPfree(SCIP **scip)
Definition: scip.c:766
SCIP_SOL ** SCIPgetSols(SCIP *scip)
Definition: scip.c:35717
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip.c:12623
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1068
SCIP_RETCODE SCIPincludeHeurZeroobj(SCIP *scip)
Definition: heur_zeroobj.c:566
SCIP_Real SCIPgetUpperbound(SCIP *scip)
Definition: scip.c:38534
#define SCIP_Bool
Definition: def.h:53
SCIP_RETCODE SCIPapplyZeroobj(SCIP *scip, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Real minimprove, SCIP_Longint nnodes)
Definition: heur_zeroobj.c:264
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip.c:4001
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip.c:3709
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, SCIP_Bool *success)
Definition: heur_zeroobj.c:78
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip.c:4382
#define DEFAULT_MAXNODES
Definition: heur_zeroobj.c:44
#define MAX(x, y)
Definition: tclique_def.h:75
#define HEUR_PRIORITY
Definition: heur_zeroobj.c:32
#define HEUR_TIMING
Definition: heur_zeroobj.c:36
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip.c:41396
static SCIP_DECL_EVENTEXEC(eventExecZeroobj)
Definition: heur_zeroobj.c:129
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, .
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:38140
#define SCIP_EVENTTYPE_NODESOLVED
Definition: type_event.h:110
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip.c:7329
#define DEFAULT_NODESQUOT
Definition: heur_zeroobj.c:49
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:11477
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip.c:14503
static SCIP_DECL_HEURFREE(heurFreeZeroobj)
Definition: heur_zeroobj.c:168
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1293
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:20585
static SCIP_DECL_HEUREXEC(heurExecZeroobj)
Definition: heur_zeroobj.c:209
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17057
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 HEUR_NAME
Definition: heur_zeroobj.c:29
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
Definition: scip.c:38746
heuristic that tries to solve the problem without objective. In Gurobi, this heuristic is known as "H...
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 HEUR_DISPCHAR
Definition: heur_zeroobj.c:31
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:278
#define HEUR_USESSUBSCIP
Definition: heur_zeroobj.c:37
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip.c:7313
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip.c:8436
#define SCIP_Real
Definition: def.h:127
#define HEUR_DESC
Definition: heur_zeroobj.c:30
#define MIN(x, y)
Definition: memory.c:67
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:19972
SCIP_Real SCIPfeastol(SCIP *scip)
Definition: scip.c:41146
#define HEUR_MAXDEPTH
Definition: heur_zeroobj.c:35
#define SCIP_Longint
Definition: def.h:112
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
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
int SCIPgetNObjVars(SCIP *scip)
Definition: scip.c:10926
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip.c:8124
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
#define DEFAULT_MINNODES
Definition: heur_zeroobj.c:46
SCIP_Longint SCIPgetNNodes(SCIP *scip)
Definition: scip.c:37372
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip.c:36554
#define EVENTHDLR_DESC
Definition: heur_zeroobj.c:41
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip.c:41409