Scippy

SCIP

Solving Constraint Integer Programs

heur_undercover.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-2014 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_undercover.c
17  * @brief Undercover primal heuristic for MINLPs
18  * @author Timo Berthold
19  * @author Ambros Gleixner
20  *
21  * The undercover heuristic is designed for mixed-integer nonlinear programs and tries to fix a subset of variables such
22  * as to make each constraint linear or convex. For this purpose it solves a binary program to automatically determine
23  * the minimum number of variable fixings necessary. As fixing values, we use values from the LP relaxation, the NLP
24  * relaxation, or the incumbent solution.
25  *
26  * @todo use the conflict analysis to analyze the infeasibility which arise after the probing of the cover worked and
27  * solve returned infeasible, instead of adding the Nogood/Conflict by hand; that has the advantage that the SCIP
28  * takes care of creating the conflict and might shrink the initial reason
29  *
30  * @todo do not use LP and NLP fixing values in the same run, e.g., fixingalts = "lni", but start a second dive if LP
31  * values fail
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include <assert.h>
37 #include <string.h>
38 
39 #include "scip/scip.h"
40 #include "scip/scipdefplugins.h"
41 #include "scip/heur_undercover.h"
42 #include "nlpi/exprinterpret.h"
43 
44 #define HEUR_NAME "undercover"
45 #define HEUR_DESC "solves a sub-CIP determined by a set covering approach"
46 #define HEUR_DISPCHAR 'U'
47 #define HEUR_PRIORITY -1110000
48 #define HEUR_FREQ 0
49 #define HEUR_FREQOFS 0
50 #define HEUR_MAXDEPTH -1
51 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
52 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
53 
54 /* default values for user parameters, grouped by parameter type */
55 #define DEFAULT_FIXINGALTS "li" /**< sequence of fixing values used: 'l'p relaxation, 'n'lp relaxation, 'i'ncumbent solution */
56 
57 #define DEFAULT_MAXNODES (SCIP_Longint)500/**< maximum number of nodes to regard in the subproblem */
58 #define DEFAULT_MINNODES (SCIP_Longint)500/**< minimum number of nodes to regard in the subproblem */
59 #define DEFAULT_NODESOFS (SCIP_Longint)500/**< number of nodes added to the contingent of the total nodes */
60 
61 #define DEFAULT_CONFLICTWEIGHT 1000.0 /**< weight for conflict score in fixing order */
62 #define DEFAULT_CUTOFFWEIGHT 1.0 /**< weight for cutoff score in fixing order */
63 #define DEFAULT_INFERENCEWEIGHT 1.0 /**< weight for inference score in fixing order */
64 #define DEFAULT_MAXCOVERSIZEVARS 1.0 /**< maximum coversize (as fraction of total number of variables) */
65 #define DEFAULT_MAXCOVERSIZECONSS SCIP_REAL_MAX /**< maximum coversize (as ratio to the percentage of non-affected constraints) */
66 #define DEFAULT_MINCOVEREDREL 0.15 /**< minimum percentage of nonlinear constraints in the original problem */
67 #define DEFAULT_MINCOVEREDABS 5 /**< minimum number of nonlinear constraints in the original problem */
68 #define DEFAULT_MINIMPROVE 0.0 /**< factor by which heuristic should at least improve the incumbent */
69 #define DEFAULT_NODESQUOT 0.1 /**< subproblem nodes in relation to nodes of the original problem */
70 #define DEFAULT_RECOVERDIV 0.9 /**< fraction of covering variables in the last cover which need to change their value when recovering */
71 
72 #define DEFAULT_MAXBACKTRACKS 6 /**< maximum number of backtracks */
73 #define DEFAULT_MAXRECOVERS 0 /**< maximum number of recoverings */
74 #define DEFAULT_MAXREORDERS 1 /**< maximum number of reorderings of the fixing order */
75 
76 #define DEFAULT_COVERINGOBJ 'u' /**< objective function of the covering problem */
77 #define DEFAULT_FIXINGORDER 'v' /**< order in which variables should be fixed */
78 
79 #define DEFAULT_BEFORECUTS TRUE /**< should undercover called at root node before cut separation? */
80 #define DEFAULT_FIXINTFIRST FALSE /**< should integer variables in the cover be fixed first? */
81 #define DEFAULT_LOCKSROUNDING TRUE /**< shall LP values for integer vars be rounded according to locks? */
82 #define DEFAULT_ONLYCONVEXIFY FALSE /**< should we only fix/dom.red. variables creating nonconvexity? */
83 #define DEFAULT_POSTNLP TRUE /**< should the NLP heuristic be called to polish a feasible solution? */
84 #define DEFAULT_COVERBD FALSE /**< should bounddisjunction constraints be covered (or just copied)? */
85 #define DEFAULT_REUSECOVER FALSE /**< shall the cover be re-used if a conflict was added after an infeasible subproblem? */
86 #define DEFAULT_COPYCUTS TRUE /**< should all active cuts from the cutpool of the original scip be copied
87  * to constraints of the subscip
88  */
89 
90 /* local defines */
91 #define COVERINGOBJS "cdlmtu" /**< list of objective functions of the covering problem */
92 #define FIXINGORDERS "CcVv" /**< list of orders in which variables can be fixed */
93 #define MAXNLPFAILS 1 /**< maximum number of fails after which we give up solving the NLP relaxation */
94 #define MAXPOSTNLPFAILS 1 /**< maximum number of fails after which we give up calling NLP local search */
95 #define MINTIMELEFT 1.0 /**< don't start expensive parts of the heuristics if less than this amount of time left */
96 #define SUBMIPSETUPCOSTS 200 /**< number of nodes equivalent for the costs for setting up the sub-CIP */
97 
98 
99 /*
100  * Data structures
101  */
102 
103 /** primal heuristic data */
104 struct SCIP_HeurData
105 {
106  SCIP_CONSHDLR** nlconshdlrs; /**< array of nonlinear constraint handlers */
107  SCIP_HEUR* nlpheur; /**< pointer to NLP local search heuristics */
108  char* fixingalts; /**< sequence of fixing values used: 'l'p relaxation, 'n'lp relaxation, 'i'ncumbent solution */
109  SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
110  SCIP_Longint minnodes; /**< minimum number of nodes to regard in the subproblem */
111  SCIP_Longint nodesofs; /**< number of nodes added to the contingent of the total nodes */
112  SCIP_Longint nusednodes; /**< nodes already used by heuristic in earlier calls */
113  SCIP_Real conflictweight; /**< weight for conflict score in fixing order */
114  SCIP_Real cutoffweight; /**< weight for cutoff score in fixing order */
115  SCIP_Real inferenceweight; /**< weight for inference score in foxing order */
116  SCIP_Real maxcoversizevars; /**< maximum coversize (as fraction of total number of variables) */
117  SCIP_Real maxcoversizeconss; /**< maximum coversize maximum coversize (as ratio to the percentage of non-affected constraints) */
118  SCIP_Real mincoveredrel; /**< minimum percentage of nonlinear constraints in the original problem */
119  SCIP_Real minimprove; /**< factor by which heuristic should at least improve the incumbent */
120  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
121  SCIP_Real recoverdiv; /**< fraction of covering variables in the last cover which need to change their value when recovering */
122  int mincoveredabs; /**< minimum number of nonlinear constraints in the original problem */
123  int maxbacktracks; /**< maximum number of backtracks */
124  int maxrecovers; /**< maximum number of recoverings */
125  int maxreorders; /**< maximum number of reorderings of the fixing order */
126  int nfixingalts; /**< number of fixing alternatives */
127  int nnlpfails; /**< number of fails when solving the NLP relaxation after last success */
128  int npostnlpfails; /**< number of fails of the NLP local search after last success */
129  int nnlconshdlrs; /**< number of nonlinear constraint handlers */
130  char coveringobj; /**< objective function of the covering problem */
131  char fixingorder; /**< order in which variables should be fixed */
132  SCIP_Bool beforecuts; /**< should undercover be called at root node before cut separation? */
133  SCIP_Bool fixintfirst; /**< should integer variables in the cover be fixed first? */
134  SCIP_Bool globalbounds; /**< should global bounds on variables be used instead of local bounds at focus node? */
135  SCIP_Bool locksrounding; /**< shall LP values for integer vars be rounded according to locks? */
136  SCIP_Bool nlpsolved; /**< has current NLP relaxation already been solved successfully? */
137  SCIP_Bool nlpfailed; /**< has solving the NLP relaxation failed? */
138  SCIP_Bool onlyconvexify; /**< should we only fix/dom.red. variables creating nonconvexity? */
139  SCIP_Bool postnlp; /**< should the NLP heuristic be called to polish a feasible solution? */
140  SCIP_Bool coverbd; /**< should bounddisjunction constraints be covered (or just copied)? */
141  SCIP_Bool reusecover; /**< shall the cover be re-used if a conflict was added after an infeasible subproblem? */
142  SCIP_Bool copycuts; /**< should all active cuts from cutpool be copied to constraints in
143  * subproblem? */
144 };
145 
146 /** working memory for retrieving dense sparsity of Hessian matrices */
147 struct HessianData
148 {
149  SCIP_SOL* evalsol;
150  SCIP_Real* varvals;
151  SCIP_Bool* sparsity;
152  int nvars;
153 };
154 
155 /*
156  * Local methods
157  */
158 
159 
160 /** determines, whether a variable is fixed to the given value */
161 static
163  SCIP* scip, /**< SCIP data structure */
164  SCIP_VAR* var, /**< variable to check */
165  SCIP_Real val, /**< value to check */
166  SCIP_Bool global /**< should global bounds be used? */
167  )
168 {
169  SCIP_Bool isfixed;
170 
171  if( global )
172  isfixed = SCIPisFeasEQ(scip, val, SCIPvarGetLbGlobal(var)) && SCIPisFeasEQ(scip, val, SCIPvarGetUbGlobal(var));
173  else
174  isfixed = SCIPisFeasEQ(scip, val, SCIPvarGetLbLocal(var)) && SCIPisFeasEQ(scip, val, SCIPvarGetUbLocal(var));
175 
176  return isfixed;
177 }
178 
179 
180 /** determines, whether a term is already constant, because the variable is fixed or the coefficient is zero */
181 static
183  SCIP* scip, /**< SCIP data structure */
184  SCIP_VAR* var, /**< variable to check */
185  SCIP_Real coeff, /**< coefficient to check */
186  SCIP_Bool global /**< should global bounds be used? */
187  )
188 {
189  /* if the variable has zero coefficient in the original problem, the term is linear */
190  if( SCIPisZero(scip, coeff) )
191  return TRUE;
192 
193  /* if the variable is fixed in the original problem, the term is linear */
194  if( global )
195  return SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var));
196  else
197  return SCIPisFeasEQ(scip, SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var));
198 
199 }
200 
201 
202 /** determines, whether a term is convex */
203 static
205  SCIP* scip, /**< SCIP data structure */
206  SCIP_Real lhs, /**< left hand side of the constraint */
207  SCIP_Real rhs, /**< right hand side of the constraint */
208  SCIP_Bool sign /**< signature of the term */
209  )
210 {
211  return sign ? SCIPisInfinity(scip, -lhs) : SCIPisInfinity(scip, rhs);
212 }
213 
214 
215 /** increases counters */
216 static
217 void incCounters(
218  int* termcounter, /**< array to count in how many nonlinear terms a variable appears */
219  int* conscounter, /**< array to count in how many constraints a variable appears */
220  SCIP_Bool* consmarker, /**< was this variable already counted for this constraint? */
221  int idx /**< problem index of the variable */
222  )
223 {
224  termcounter[idx]++;
225  if( !consmarker[idx] )
226  {
227  conscounter[idx]++;
228  consmarker[idx] = TRUE;
229  }
230  return;
231 }
232 
233 
234 /** update time limit */
235 static
237  SCIP* scip, /**< SCIP data structure */
238  SCIP_CLOCK* clck, /**< clock timer */
239  SCIP_Real* timelimit /**< time limit */
240  )
241 {
242  *timelimit -= SCIPgetClockTime(scip, clck);
243  SCIP_CALL( SCIPresetClock(scip, clck) );
244  SCIP_CALL( SCIPstartClock(scip, clck) );
245 
246  return SCIP_OKAY;
247 }
248 
249 
250 /** analyzes a nonlinear row and adds constraints and fixings to the covering problem */
251 static
253  SCIP* scip, /**< original SCIP data structure */
254  SCIP_NLROW* nlrow, /**< nonlinear row representation of a nonlinear constraint */
255  SCIP_EXPRINT* exprint, /**< expression interpreter for computing sparsity pattern of the Hessian;
256  * if NULL, we will simply fix all variables in the expression tree */
257  struct HessianData* hessiandata, /**< working memory for retrieving dense sparsity of Hessian matrices */
258  SCIP* coveringscip, /**< SCIP data structure for the covering problem */
259  int nvars, /**< number of variables */
260  SCIP_VAR** coveringvars, /**< array to store the covering problem's variables */
261  int* termcounter, /**< counter array for number of nonlinear nonzeros per variable */
262  int* conscounter, /**< counter array for number of nonlinear constraints per variable */
263  SCIP_Bool* consmarker, /**< marker array if constraint has been counted in conscounter */
264  SCIP_Bool globalbounds, /**< should global bounds on variables be used instead of local bounds at focus node? */
265  SCIP_Bool onlyconvexify, /**< should we only fix/dom.red. variables creating nonconvexity? */
266  SCIP_Bool* success /**< pointer to store whether row was processed successfully */
267  )
268 {
269  SCIP_EXPRTREE* exprtree;
270  SCIP_Bool infeas;
271  SCIP_Bool fixed;
272  int t;
273  char name[SCIP_MAXSTRLEN];
274 
275  assert(scip != NULL);
276  assert(nlrow != NULL);
277  assert(exprint == NULL || hessiandata != NULL);
278  assert(coveringscip != NULL);
279  assert(nvars >= 1);
280  assert(coveringvars != NULL);
281  assert(termcounter != NULL);
282  assert(conscounter != NULL);
283  assert(consmarker != NULL);
284  assert(success != NULL);
285 
286  *success = FALSE;
287  BMSclearMemoryArray(consmarker, nvars);
288 
289  /* go through expression tree */
290  exprtree = SCIPnlrowGetExprtree(nlrow);
291  if( exprtree != NULL )
292  {
293  SCIP_VAR** exprtreevars;
294  int nexprtreevars;
295  int probidx1;
296  int probidx2;
297 
298  /* get variables in expression tree */
299  nexprtreevars = SCIPexprtreeGetNVars(exprtree);
300  exprtreevars = SCIPexprtreeGetVars(exprtree);
301 
302  if( exprtreevars != NULL && nexprtreevars > 0 )
303  {
304  SCIP_Bool usehessian;
305  int i;
306 
307  /* is an expression interpreter available which can return the sparsity pattern of the Hessian? */
308  usehessian = exprint != NULL && (SCIPexprintGetCapability() & SCIP_EXPRINTCAPABILITY_HESSIAN);
309  if( usehessian )
310  {
311  int idx1;
312  int idx2;
313 
314  assert(hessiandata != NULL);
315  assert(hessiandata->nvars == 0 || hessiandata->varvals != NULL);
316  assert(hessiandata->nvars == 0 || hessiandata->sparsity != NULL);
317 
318  /* compile expression tree */
319  SCIP_CALL( SCIPexprintCompile(exprint, exprtree) );
320 
321  /* ensure memory */
322  if( hessiandata->nvars < nexprtreevars )
323  {
324  SCIP_CALL( SCIPreallocBufferArray(scip, &hessiandata->varvals, nexprtreevars) );
325  SCIP_CALL( SCIPreallocBufferArray(scip, &hessiandata->sparsity, nexprtreevars*nexprtreevars) );
326  hessiandata->nvars = nexprtreevars;
327  }
328 
329  /* get point at which to evaluate the Hessian sparsity */
330  if( hessiandata->evalsol == NULL )
331  {
332  SCIP_CALL( SCIPcreateSol(scip, &hessiandata->evalsol, NULL) );
333  SCIP_CALL( SCIPlinkCurrentSol(scip, hessiandata->evalsol) );
334  }
335  SCIP_CALL( SCIPgetSolVals(scip, hessiandata->evalsol, nexprtreevars, exprtreevars, hessiandata->varvals) );
336 
337  /* get sparsity of the Hessian at current LP solution */
338  SCIP_CALL( SCIPexprintHessianSparsityDense(exprint, exprtree, hessiandata->varvals, hessiandata->sparsity) );
339 
340  for( idx1 = nexprtreevars-1; idx1 >= 0; idx1-- )
341  {
342  /* if constraints with inactive variables are present, we will have difficulties creating the sub-CIP later */
343  probidx1 = SCIPvarGetProbindex(exprtreevars[idx1]);
344  if( probidx1 == -1 )
345  {
346  SCIPdebugMessage("strange: inactive variables detected in nonlinear row <%s>\n", SCIPnlrowGetName(nlrow));
347  return SCIP_OKAY;
348  }
349 
350  /* nonzero diagonal element of the Hessian: fix */
351  if( hessiandata->sparsity[idx1*nexprtreevars + idx1]
352  && !termIsConstant(scip, exprtreevars[idx1], 1.0, globalbounds) )
353  {
354  SCIP_CALL( SCIPfixVar(coveringscip, coveringvars[probidx1], 1.0, &infeas, &fixed) );
355  assert(!infeas);
356  assert(fixed);
357 
358  /* update counters */
359  incCounters(termcounter, conscounter, consmarker, probidx1);
360 
361  SCIPdebugMessage("fixing var <%s> in covering problem to 1\n", SCIPvarGetName(coveringvars[probidx1]));
362 
363  /* if covering variable is fixed, then no need to still check non-diagonal elements */
364  continue;
365  }
366 
367  /* two different variables relate nonlinearly */
368  for( idx2 = nexprtreevars-1; idx2 > idx1; idx2-- )
369  {
370  SCIP_CONS* coveringcons;
371  SCIP_VAR* coveringconsvars[2];
372 
373  /* do not assume symmetry */
374  if( !hessiandata->sparsity[idx1*nexprtreevars + idx2] && !hessiandata->sparsity[idx2*nexprtreevars + idx1] )
375  continue;
376 
377  /* if diagonal has entry already, then covering constraint would always be satisfied, thus no need to add */
378  if( hessiandata->sparsity[idx2*nexprtreevars + idx2] && !termIsConstant(scip, exprtreevars[idx2], 1.0, globalbounds) )
379  continue;
380 
381  /* if constraints with inactive variables are present, we will have difficulties creating the sub-CIP later */
382  probidx2 = SCIPvarGetProbindex(exprtreevars[idx2]);
383  if( probidx2 == -1 )
384  {
385  SCIPdebugMessage("strange: inactive variables detected in nonlinear row <%s>\n", SCIPnlrowGetName(nlrow));
386  return SCIP_OKAY;
387  }
388 
389  /* if the term is linear because one of the variables is fixed, nothing to do */
390  if( termIsConstant(scip, exprtreevars[idx1], 1.0, globalbounds)
391  || termIsConstant(scip, exprtreevars[idx2], 1.0, globalbounds) )
392  continue;
393 
394  /* create covering constraint */
395  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering_%d_%d", SCIPnlrowGetName(nlrow), idx1, idx2);
396  coveringconsvars[0] = coveringvars[probidx1];
397  coveringconsvars[1] = coveringvars[probidx2];
398  SCIP_CALL( SCIPcreateConsSetcover(coveringscip, &coveringcons, name, 2, coveringconsvars,
399  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
400 
401  if( coveringcons == NULL )
402  {
403  SCIPdebugMessage("failed to create set covering constraint <%s>\n", name);
404  return SCIP_OKAY;
405  }
406 
407  /* add and release covering constraint */
408  SCIP_CALL( SCIPaddCons(coveringscip, coveringcons) );
409  SCIP_CALL( SCIPreleaseCons(coveringscip, &coveringcons) );
410 
411  SCIPdebugMessage("added covering constraint for vars <%s> and <%s> in covering problem\n", SCIPvarGetName(coveringvars[probidx1]), SCIPvarGetName(coveringvars[probidx2]));
412 
413  /* update counters for both variables */
414  incCounters(termcounter, conscounter, consmarker, probidx1);
415  incCounters(termcounter, conscounter, consmarker, probidx2);
416  }
417  }
418  }
419  /* fix all variables contained in the expression tree */
420  else
421  {
422  for( i = nexprtreevars-1; i >= 0; i-- )
423  {
424  assert(exprtreevars[i] != NULL);
425 
426  /* if constraints with inactive variables are present, we will have difficulties creating the sub-CIP later */
427  probidx1 = SCIPvarGetProbindex(exprtreevars[i]);
428  if( probidx1 == -1 )
429  {
430  SCIPdebugMessage("strange: inactive variable <%s> detected in nonlinear row <%s>\n",
431  SCIPvarGetName(exprtreevars[i]), SCIPnlrowGetName(nlrow));
432  return SCIP_OKAY;
433  }
434 
435  /* term is constant, nothing to do */
436  if( termIsConstant(scip, exprtreevars[i], 1.0, globalbounds) )
437  continue;
438 
439  /* otherwise fix variable */
440  SCIP_CALL( SCIPfixVar(coveringscip, coveringvars[probidx1], 1.0, &infeas, &fixed) );
441  assert(!infeas);
442  assert(fixed);
443 
444  /* update counters */
445  incCounters(termcounter, conscounter, consmarker, probidx1);
446 
447  SCIPdebugMessage("fixing var <%s> in covering problem to 1\n", SCIPvarGetName(coveringvars[probidx1]));
448  }
449  }
450  }
451  }
452 
453  /* go through all quadratic terms */
454  for( t = SCIPnlrowGetNQuadElems(nlrow)-1; t >= 0; t-- )
455  {
456  SCIP_QUADELEM* quadelem;
457  SCIP_VAR* bilinvar1;
458  SCIP_VAR* bilinvar2;
459  int probidx1;
460  int probidx2;
461 
462  /* get quadratic term */
463  quadelem = &SCIPnlrowGetQuadElems(nlrow)[t];
464 
465  /* get involved variables */
466  bilinvar1 = SCIPnlrowGetQuadVars(nlrow)[quadelem->idx1];
467  bilinvar2 = SCIPnlrowGetQuadVars(nlrow)[quadelem->idx2];
468  assert(bilinvar1 != NULL);
469  assert(bilinvar2 != NULL);
470 
471  /* if constraints with inactive variables are present, we will have difficulties creating the sub-CIP later */
472  probidx1 = SCIPvarGetProbindex(bilinvar1);
473  probidx2 = SCIPvarGetProbindex(bilinvar2);
474  if( probidx1 == -1 || probidx2 == -1 )
475  {
476  SCIPdebugMessage("inactive variables detected in nonlinear row <%s>\n", SCIPnlrowGetName(nlrow));
477  return SCIP_OKAY;
478  }
479 
480  /* we have a square term */
481  if( bilinvar1 == bilinvar2 )
482  {
483  /* term is constant, nothing to do */
484  if( termIsConstant(scip, bilinvar1, quadelem->coef, globalbounds) )
485  continue;
486 
487  /* if we only convexify and term is convex considering the bounds of the nlrow, nothing to do */
488  if( onlyconvexify && termIsConvex(scip, SCIPnlrowGetLhs(nlrow), SCIPnlrowGetRhs(nlrow), quadelem->coef >= 0) )
489  continue;
490 
491  /* otherwise variable has to be in the cover */
492  SCIP_CALL( SCIPfixVar(coveringscip, coveringvars[probidx1], 1.0, &infeas, &fixed) );
493  assert(!infeas);
494  assert(fixed);
495 
496  /* update counters */
497  incCounters(termcounter, conscounter, consmarker, probidx1);
498 
499  SCIPdebugMessage("fixing var <%s> in covering problem to 1\n", SCIPvarGetName(coveringvars[probidx1]));
500  }
501  /* we have a bilinear term */
502  else
503  {
504  SCIP_CONS* coveringcons;
505  SCIP_VAR* coveringconsvars[2];
506 
507  /* if the term is linear because one of the variables is fixed or the coefficient is zero, nothing to do */
508  if( termIsConstant(scip, bilinvar1, quadelem->coef, globalbounds)
509  || termIsConstant(scip, bilinvar2, quadelem->coef, globalbounds) )
510  continue;
511 
512  /* create covering constraint */
513  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering%d", SCIPnlrowGetName(nlrow), t);
514  coveringconsvars[0] = coveringvars[probidx1];
515  coveringconsvars[1] = coveringvars[probidx2];
516  SCIP_CALL( SCIPcreateConsSetcover(coveringscip, &coveringcons, name, 2, coveringconsvars,
517  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
518 
519  if( coveringcons == NULL )
520  {
521  SCIPdebugMessage("failed to create set covering constraint <%s>\n", name);
522  return SCIP_OKAY;
523  }
524 
525  /* add and release covering constraint */
526  SCIP_CALL( SCIPaddCons(coveringscip, coveringcons) );
527  SCIP_CALL( SCIPreleaseCons(coveringscip, &coveringcons) );
528 
529  /* update counters for both variables */
530  incCounters(termcounter, conscounter, consmarker, probidx1);
531  incCounters(termcounter, conscounter, consmarker, probidx2);
532  }
533  }
534 
535  *success = TRUE;
536 
537  return SCIP_OKAY;
538 }
539 
540 
541 /** creates the covering problem to determine a number of variables to be fixed */
542 static
544  SCIP* scip, /**< original SCIP data structure */
545  SCIP* coveringscip, /**< SCIP data structure for the covering problem */
546  SCIP_VAR** coveringvars, /**< array to store the covering problem's variables */
547  SCIP_Bool globalbounds, /**< should global bounds on variables be used instead of local bounds at focus node? */
548  SCIP_Bool onlyconvexify, /**< should we only fix/dom.red. variables creating nonconvexity? */
549  SCIP_Bool coverbd, /**< should bounddisjunction constraints be covered (or just copied)? */
550  char coveringobj, /**< objective function of the covering problem */
551  SCIP_Bool* success /**< pointer to store whether the problem was created successfully */
552  )
553 {
554  SCIP_VAR** vars;
555  SCIP_CONSHDLR* conshdlr;
556  SCIP_HASHMAP* nlrowmap;
557  SCIP_EXPRINT* exprint;
558  SCIP_Bool* consmarker;
559  int* conscounter;
560  int* termcounter;
561 
562  struct HessianData hessiandata;
563  int nlocksup;
564  int nlocksdown;
565  int nvars;
566  int i;
567  int probindex;
568  char name[SCIP_MAXSTRLEN];
569 
570  assert(scip != NULL);
571  assert(coveringscip != NULL);
572  assert(coveringvars != NULL);
573  assert(success != NULL);
574 
575  *success = FALSE;
576 
577  /* get required data of the original problem */
578  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
579 
580  /* create problem data structure */
581  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering", SCIPgetProbName(scip));
582  SCIP_CALL( SCIPcreateProb(coveringscip, name, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
583 
584  /* allocate and initialize to zero counter arrays for weighted objectives */
585  SCIP_CALL( SCIPallocBufferArray(scip, &consmarker, nvars) );
586  SCIP_CALL( SCIPallocBufferArray(scip, &conscounter, nvars) );
587  SCIP_CALL( SCIPallocBufferArray(scip, &termcounter, nvars) );
588  BMSclearMemoryArray(conscounter, nvars);
589  BMSclearMemoryArray(termcounter, nvars);
590 
591  /* create expression interpreter */
592  SCIP_CALL( SCIPexprintCreate(SCIPblkmem(scip), &exprint) );
593  assert(exprint != NULL);
594 
595  /* initialize empty hessiandata; memory will be allocated in method processNlRow() as required */
596  hessiandata.evalsol = NULL;
597  hessiandata.varvals = NULL;
598  hessiandata.sparsity = NULL;
599  hessiandata.nvars = 0;
600 
601  /* create covering variable for each variable in the original problem (fix it or not?) in the same order as in the
602  * original problem
603  */
604  for( i = 0; i < nvars; i++ )
605  {
606  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering", SCIPvarGetName(vars[i]));
607  SCIP_CALL( SCIPcreateVar(coveringscip, &coveringvars[i], name, 0.0, 1.0, 1.0, SCIP_VARTYPE_BINARY,
608  TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
609  assert(coveringvars[i] != NULL);
610  SCIP_CALL( SCIPaddVar(coveringscip, coveringvars[i]) );
611  }
612 
613  /* first, go through some special constraint handlers which we do not want to treat by looking at their nlrow
614  * representation; we store these in a hash map and afterwards process all nlrows which are not found in the hash map
615  */
616  nlrowmap = NULL;
617  if( SCIPisNLPConstructed(scip) )
618  {
619  int nnlprows;
620 
621  nnlprows = SCIPgetNNLPNlRows(scip);
622  if( nnlprows > 0 )
623  {
624  int mapsize;
625 
626  /* calculate size of hash map */
627  conshdlr = SCIPfindConshdlr(scip, "quadratic");
628  mapsize = SCIPconshdlrGetNActiveConss(conshdlr);
629  conshdlr = SCIPfindConshdlr(scip, "soc");
630  mapsize += SCIPconshdlrGetNActiveConss(conshdlr);
631  mapsize = MAX(mapsize, nnlprows);
632  mapsize = SCIPcalcHashtableSize(2*mapsize);
633  assert(mapsize > 0);
634 
635  /* create hash map */
636  SCIP_CALL( SCIPhashmapCreate(&nlrowmap, SCIPblkmem(scip), mapsize) );
637  assert(nlrowmap != NULL);
638  }
639  }
640 
641  /* go through all and constraints in the original problem */
642  conshdlr = SCIPfindConshdlr(scip, "and");
643  if( conshdlr != NULL )
644  {
645  int c;
646 
647  for( c = SCIPconshdlrGetNActiveConss(conshdlr)-1; c >= 0; c-- )
648  {
649  SCIP_CONS* andcons;
650  SCIP_CONS* coveringcons;
651  SCIP_VAR** andvars;
652  SCIP_VAR* andres;
653  SCIP_VAR** coveringconsvars;
654  SCIP_Real* coveringconsvals;
655  SCIP_Bool negated;
656 
657  int ntofix;
658  int v;
659 
660  /* get constraint and variables */
661  andcons = SCIPconshdlrGetConss(conshdlr)[c];
662  assert(andcons != NULL);
663  andvars = SCIPgetVarsAnd(scip, andcons);
664  assert(andvars != NULL);
665 
666  /* "and" constraints are not passed to the NLP, hence nothing to store in the hash map */
667 
668  /* allocate memory for covering constraint */
669  SCIP_CALL( SCIPallocBufferArray(coveringscip, &coveringconsvars, SCIPgetNVarsAnd(scip, andcons)+1) );
670  SCIP_CALL( SCIPallocBufferArray(coveringscip, &coveringconsvals, SCIPgetNVarsAnd(scip, andcons)+1) );
671 
672  /* collect unfixed variables */
673  BMSclearMemoryArray(consmarker, nvars);
674  ntofix = 0;
675  for( v = SCIPgetNVarsAnd(scip, andcons)-1; v >= 0; v-- )
676  {
677  assert(andvars[v] != NULL);
678  negated = FALSE;
679 
680  /* if variable is fixed to 0, entire constraint can be linearized */
681  if( varIsFixed(scip, andvars[v], 0.0, globalbounds) )
682  {
683  ntofix = 0;
684  break;
685  }
686 
687  /* if variable is fixed, nothing to do */
688  if( termIsConstant(scip, andvars[v], 1.0, globalbounds) )
689  {
690  continue;
691  }
692 
693  /* if constraints with inactive variables are present, we have to find the corresponding active variable */
694  probindex = SCIPvarGetProbindex(andvars[v]);
695  if( probindex == -1 )
696  {
697  SCIP_VAR* repvar;
698 
699  /* get binary representative of variable */
700  SCIP_CALL( SCIPgetBinvarRepresentative(scip, andvars[v], &repvar, &negated) );
701  assert(repvar != NULL);
702  assert(SCIPvarGetStatus(repvar) != SCIP_VARSTATUS_FIXED);
703 
705  {
706  SCIPdebugMessage("strange: multiaggregated variable found <%s>\n", SCIPvarGetName(andvars[v]));
707  SCIPdebugMessage("inactive variables detected in constraint <%s>\n", SCIPconsGetName(andcons));
708  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
709  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
710  goto TERMINATE;
711  }
712 
713  /* check for negation */
714  if( SCIPvarIsNegated(repvar) )
715  {
716  probindex = SCIPvarGetProbindex(SCIPvarGetNegationVar(repvar));
717  negated = TRUE;
718  }
719  else
720  {
721  assert(SCIPvarIsActive(repvar));
722  probindex = SCIPvarGetProbindex(repvar);
723  negated = FALSE;
724  }
725  }
726  assert(probindex >= 0);
727 
728  /* add covering variable for unfixed original variable */
729  if( negated )
730  {
731  SCIP_CALL( SCIPgetNegatedVar(coveringscip, coveringvars[probindex], &coveringconsvars[ntofix]) );
732  }
733  else
734  coveringconsvars[ntofix] = coveringvars[probindex];
735  coveringconsvals[ntofix] = 1.0;
736  ntofix++;
737  }
738  negated = FALSE;
739 
740  /* if constraints with inactive variables are present, we have to find the corresponding active variable */
741  andres = SCIPgetResultantAnd(scip, andcons);
742  assert(andres != NULL);
743  probindex = SCIPvarGetProbindex(andres);
744 
745  /* if resultant is fixed this constraint can be either linearized or is redundant because all operands can be fixed */
746  if( termIsConstant(scip, andres, 1.0, globalbounds) )
747  {
748  /* free memory for covering constraint */
749  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
750  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
751 
752  continue;
753  }
754 
755  if( probindex == -1 )
756  {
757  SCIP_VAR* repvar;
758 
759  /* get binary representative of variable */
760  SCIP_CALL( SCIPgetBinvarRepresentative(scip, SCIPgetResultantAnd(scip, andcons), &repvar, &negated) );
761  assert(repvar != NULL);
762  assert(SCIPvarGetStatus(repvar) != SCIP_VARSTATUS_FIXED);
763 
765  {
766  SCIPdebugMessage("strange: multiaggregated variable found <%s>\n", SCIPvarGetName(SCIPgetResultantAnd(scip, andcons)));
767  SCIPdebugMessage("inactive variables detected in constraint <%s>\n", SCIPconsGetName(andcons));
768  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
769  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
770  goto TERMINATE;
771  }
772 
773  /* check for negation */
774  if( SCIPvarIsNegated(repvar) )
775  {
776  probindex = SCIPvarGetProbindex(SCIPvarGetNegationVar(repvar));
777  negated = TRUE;
778  }
779  else
780  {
781  assert(SCIPvarIsActive(repvar));
782  probindex = SCIPvarGetProbindex(repvar);
783  negated = FALSE;
784  }
785  }
786  else if( SCIPvarGetLbGlobal(andres) > 0.5 || SCIPvarGetUbGlobal(andres) < 0.5 )
787  {
788  /* free memory for covering constraint */
789  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
790  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
791 
792  continue;
793  }
794  assert(probindex >= 0);
795  assert(!termIsConstant(scip, (negated ? SCIPvarGetNegatedVar(vars[probindex]) : vars[probindex]), 1.0, globalbounds));
796 
797  /* if less than two variables are unfixed or the resultant variable is fixed, the entire constraint can be
798  * linearized anyway
799  */
800  if( ntofix >= 2 )
801  {
802  assert(ntofix <= SCIPgetNVarsAnd(scip, andcons));
803 
804  /* add covering variable for unfixed resultant */
805  if( negated )
806  {
807  SCIP_CALL( SCIPgetNegatedVar(coveringscip, coveringvars[probindex], &coveringconsvars[ntofix]) );
808  }
809  else
810  coveringconsvars[ntofix] = coveringvars[probindex];
811  coveringconsvals[ntofix] = (SCIP_Real)(ntofix - 1);
812  ntofix++;
813 
814  /* create covering constraint */
815  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering", SCIPconsGetName(andcons));
816  SCIP_CALL( SCIPcreateConsLinear(coveringscip, &coveringcons, name, ntofix, coveringconsvars, coveringconsvals,
817  (SCIP_Real)(ntofix - 2), SCIPinfinity(coveringscip),
818  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
819 
820  if( coveringcons == NULL )
821  {
822  SCIPdebugMessage("failed to create linear constraint <%s>\n", name);
823  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
824  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
825  goto TERMINATE;
826  }
827 
828  /* add and release covering constraint */
829  SCIP_CALL( SCIPaddCons(coveringscip, coveringcons) );
830  SCIP_CALL( SCIPreleaseCons(coveringscip, &coveringcons) );
831 
832  /* update counters */
833  for( v = ntofix-1; v >= 0; v-- )
834  if( SCIPvarIsNegated(coveringconsvars[v]) )
835  incCounters(termcounter, conscounter, consmarker, SCIPvarGetProbindex(SCIPvarGetNegationVar(coveringconsvars[v])));
836  else
837  incCounters(termcounter, conscounter, consmarker, SCIPvarGetProbindex(coveringconsvars[v]));
838  }
839 
840  /* free memory for covering constraint */
841  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
842  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
843  }
844  }
845 
846  /* go through all bounddisjunction constraints in the original problem */
847  conshdlr = SCIPfindConshdlr(scip, "bounddisjunction");
848  if( conshdlr != NULL && coverbd )
849  {
850  int c;
851 
852  for( c = SCIPconshdlrGetNActiveConss(conshdlr)-1; c >= 0; c-- )
853  {
854  SCIP_CONS* bdcons;
855  SCIP_CONS* coveringcons;
856  SCIP_VAR** bdvars;
857  SCIP_VAR** coveringconsvars;
858  SCIP_Real* coveringconsvals;
859 
860  int nbdvars;
861  int ntofix;
862  int v;
863 
864  /* get constraint and variables */
865  bdcons = SCIPconshdlrGetConss(conshdlr)[c];
866  assert(bdcons != NULL);
867  bdvars = SCIPgetVarsBounddisjunction(scip, bdcons);
868  assert(bdvars != NULL);
869  nbdvars = SCIPgetNVarsBounddisjunction(scip, bdcons);
870 
871  /* bounddisjunction constraints are not passed to the NLP, hence nothing to store in the hash map */
872 
873  /* allocate memory for covering constraint */
874  SCIP_CALL( SCIPallocBufferArray(coveringscip, &coveringconsvars, nbdvars) );
875  SCIP_CALL( SCIPallocBufferArray(coveringscip, &coveringconsvals, nbdvars) );
876 
877  /* collect unfixed variables */
878  BMSclearMemoryArray(consmarker, nvars);
879  ntofix = 0;
880  for( v = nbdvars-1; v >= 0; v-- )
881  {
882  SCIP_Bool negated;
883 
884  assert(bdvars[v] != NULL);
885  negated = FALSE;
886 
887  /* if variable is fixed, nothing to do */
888  if( varIsFixed(scip, bdvars[v], globalbounds ? SCIPvarGetLbGlobal(bdvars[v]) : SCIPvarGetLbLocal(bdvars[v]),
889  globalbounds) )
890  {
891  continue;
892  }
893 
894  /* if constraints with inactive variables are present, we have to find the corresponding active variable */
895  probindex = SCIPvarGetProbindex(bdvars[v]);
896  if( probindex == -1 )
897  {
898  SCIP_VAR* repvar;
899 
900  /* get binary representative of variable */
901  SCIP_CALL( SCIPgetBinvarRepresentative(scip, bdvars[v], &repvar, &negated) );
902  assert(repvar != NULL);
903  assert(SCIPvarGetStatus(repvar) != SCIP_VARSTATUS_FIXED);
904 
906  {
907  SCIPdebugMessage("strange: multiaggregated variable found <%s>\n", SCIPvarGetName(bdvars[v]));
908  SCIPdebugMessage("inactive variables detected in constraint <%s>\n", SCIPconsGetName(bdcons));
909  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
910  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
911  goto TERMINATE;
912  }
913 
914  /* check for negation */
915  if( SCIPvarIsNegated(repvar) )
916  {
917  probindex = SCIPvarGetProbindex(SCIPvarGetNegationVar(repvar));
918  negated = TRUE;
919  }
920  else
921  {
922  assert(SCIPvarIsActive(repvar));
923  probindex = SCIPvarGetProbindex(repvar);
924  negated = FALSE;
925  }
926  }
927  assert(probindex >= 0);
928 
929  /* add covering variable for unfixed original variable */
930  if( negated )
931  {
932  SCIP_CALL( SCIPgetNegatedVar(coveringscip, coveringvars[probindex], &coveringconsvars[ntofix]) );
933  }
934  else
935  coveringconsvars[ntofix] = coveringvars[probindex];
936  coveringconsvals[ntofix] = 1.0;
937  ntofix++;
938  }
939 
940  /* if less than two variables are unfixed, the entire constraint can be linearized anyway */
941  if( ntofix >= 2 )
942  {
943  assert(ntofix <= nbdvars);
944 
945  /* create covering constraint */
946  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering", SCIPconsGetName(bdcons));
947  SCIP_CALL( SCIPcreateConsLinear(coveringscip, &coveringcons, name, ntofix, coveringconsvars, coveringconsvals,
948  (SCIP_Real)(ntofix - 1), SCIPinfinity(coveringscip),
949  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
950 
951  if( coveringcons == NULL )
952  {
953  SCIPdebugMessage("failed to create linear constraint <%s>\n", name);
954  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
955  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
956  goto TERMINATE;
957  }
958 
959  /* add and release covering constraint */
960  SCIP_CALL( SCIPaddCons(coveringscip, coveringcons) );
961  SCIP_CALL( SCIPreleaseCons(coveringscip, &coveringcons) );
962 
963  /* update counters */
964  for( v = ntofix-1; v >= 0; v-- )
965  if( SCIPvarIsNegated(coveringconsvars[v]) )
966  incCounters(termcounter, conscounter, consmarker, SCIPvarGetProbindex(SCIPvarGetNegationVar(coveringconsvars[v])));
967  else
968  incCounters(termcounter, conscounter, consmarker, SCIPvarGetProbindex(coveringconsvars[v]));
969  }
970 
971  /* free memory for covering constraint */
972  SCIPfreeBufferArray(coveringscip, &coveringconsvals);
973  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
974  }
975  }
976 
977  /* go through all indicator constraints in the original problem; fix the binary variable */
978  conshdlr = SCIPfindConshdlr(scip, "indicator");
979  if( conshdlr != NULL )
980  {
981  int c;
982 
983  for( c = SCIPconshdlrGetNActiveConss(conshdlr)-1; c >= 0; c-- )
984  {
985  SCIP_CONS* indcons;
986  SCIP_VAR* binvar;
987  SCIP_VAR* coveringvar;
988 
989  /* get constraint and variables */
990  indcons = SCIPconshdlrGetConss(conshdlr)[c];
991  assert(indcons != NULL);
992  binvar = SCIPgetBinaryVarIndicator(indcons);
993  assert(binvar != NULL);
994 
995  /* indicator constraints are not passed to the NLP, hence nothing to store in the hash map */
996 
997  /* if variable is fixed, nothing to do */
998  if( varIsFixed(scip, binvar, globalbounds ? SCIPvarGetLbGlobal(binvar) : SCIPvarGetLbLocal(binvar), globalbounds) )
999  {
1000  continue;
1001  }
1002 
1003  /* if constraints with inactive variables are present, we have to find the corresponding active variable */
1004  probindex = SCIPvarGetProbindex(binvar);
1005  if( probindex == -1 )
1006  {
1007  SCIP_VAR* repvar;
1008  SCIP_Bool negated;
1009 
1010  /* get binary representative of variable */
1011  negated = FALSE;
1012  SCIP_CALL( SCIPgetBinvarRepresentative(scip, binvar, &repvar, &negated) );
1013  assert(repvar != NULL);
1014  assert(SCIPvarGetStatus(repvar) != SCIP_VARSTATUS_FIXED);
1015 
1016  if( SCIPvarGetStatus(repvar) == SCIP_VARSTATUS_MULTAGGR )
1017  {
1018  SCIPdebugMessage("strange: multiaggregated variable found <%s>\n", SCIPvarGetName(binvar));
1019  SCIPdebugMessage("inactive variables detected in constraint <%s>\n", SCIPconsGetName(indcons));
1020  goto TERMINATE;
1021  }
1022 
1023  /* check for negation */
1024  if( SCIPvarIsNegated(repvar) )
1025  probindex = SCIPvarGetProbindex(SCIPvarGetNegationVar(repvar));
1026  else
1027  {
1028  assert(SCIPvarIsActive(repvar));
1029  probindex = SCIPvarGetProbindex(repvar);
1030  }
1031  }
1032  assert(probindex >= 0);
1033 
1034  /* get covering variable for unfixed binary variable in indicator constraint */
1035  coveringvar = coveringvars[probindex];
1036 
1037  /* require covering variable to be fixed such that indicator is linearized */
1038  SCIP_CALL( SCIPchgVarLb(coveringscip, coveringvar, 1.0) );
1039 
1040  /* update counters */
1041  BMSclearMemoryArray(consmarker, nvars);
1042  incCounters(termcounter, conscounter, consmarker, probindex);
1043  }
1044  }
1045 
1046  /* go through all quadratic constraints in the original problem */
1047  conshdlr = SCIPfindConshdlr(scip, "quadratic");
1048  if( conshdlr != NULL )
1049  {
1050  int c;
1051 
1052  for( c = SCIPconshdlrGetNActiveConss(conshdlr)-1; c >= 0; c-- )
1053  {
1054  SCIP_CONS* quadcons;
1055  SCIP_NLROW* nlrow;
1056 
1057  /* get constraint */
1058  quadcons = SCIPconshdlrGetConss(conshdlr)[c];
1059  assert(quadcons != NULL);
1060 
1061  /* get nlrow representation and store it in hash map */
1062  SCIP_CALL( SCIPgetNlRowQuadratic(scip, quadcons, &nlrow) );
1063  assert(nlrow != NULL);
1064  if( nlrowmap != NULL )
1065  {
1066  assert(!SCIPhashmapExists(nlrowmap, nlrow));
1067  SCIP_CALL( SCIPhashmapInsert(nlrowmap, nlrow, quadcons) );
1068  }
1069 
1070  /* if we only want to convexify and curvature and bounds prove already convexity, nothing to do */
1071  if( onlyconvexify
1072  && ((SCIPisInfinity(scip, -SCIPgetLhsQuadratic(scip, quadcons)) && SCIPisConvexQuadratic(scip, quadcons))
1073  || (SCIPisInfinity(scip, SCIPgetRhsQuadratic(scip, quadcons)) && SCIPisConcaveQuadratic(scip, quadcons))) )
1074  continue;
1075 
1076  /* process nlrow */
1077  *success = FALSE;
1078  SCIP_CALL( processNlRow(scip, nlrow, exprint, &hessiandata, coveringscip, nvars, coveringvars,
1079  termcounter, conscounter, consmarker, globalbounds, onlyconvexify, success) );
1080 
1081  if( *success == FALSE )
1082  goto TERMINATE;
1083  }
1084 
1085  *success = FALSE;
1086  }
1087 
1088  /* go through all "soc" constraints in the original problem */
1089  conshdlr = SCIPfindConshdlr(scip, "soc");
1090  if( conshdlr != NULL && !onlyconvexify )
1091  {
1092  int c;
1093 
1094  for( c = SCIPconshdlrGetNActiveConss(conshdlr)-1; c >= 0; c-- )
1095  {
1096  SCIP_CONS* soccons;
1097  SCIP_CONS* coveringcons;
1098  SCIP_VAR** soclhsvars;
1099  SCIP_VAR* socrhsvar;
1100  SCIP_VAR** coveringconsvars;
1101  SCIP_NLROW* nlrow;
1102 
1103  int ntofix;
1104  int v;
1105 
1106  /* get constraints and variables */
1107  soccons = SCIPconshdlrGetConss(conshdlr)[c];
1108  assert(soccons != NULL);
1109  socrhsvar = SCIPgetRhsVarSOC(scip, soccons);
1110  assert(socrhsvar != NULL);
1111  soclhsvars = SCIPgetLhsVarsSOC(scip, soccons);
1112  assert(soclhsvars != NULL);
1113 
1114  /* get nlrow representation and store it in hash map */
1115  SCIP_CALL( SCIPgetNlRowSOC(scip, soccons, &nlrow) );
1116  assert(nlrow != NULL);
1117  if( nlrowmap != NULL )
1118  {
1119  assert(!SCIPhashmapExists(nlrowmap, nlrow));
1120  SCIP_CALL( SCIPhashmapInsert(nlrowmap, nlrow, soccons) );
1121  }
1122 
1123  /* allocate memory for covering constraint */
1124  SCIP_CALL( SCIPallocBufferArray(coveringscip, &coveringconsvars, SCIPgetNLhsVarsSOC(scip, soccons)+1) );
1125 
1126  /* collect unfixed variables */
1127  BMSclearMemoryArray(consmarker, nvars);
1128  ntofix = 0;
1129 
1130  /* soc constraints should contain only active and multi-aggregated variables; the latter we do not handle */
1131  probindex = SCIPvarGetProbindex(socrhsvar);
1132  if( probindex == -1 )
1133  {
1134  SCIPdebugMessage("inactive variables detected in constraint <%s>\n", SCIPconsGetName(soccons));
1135  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
1136  goto TERMINATE;
1137  }
1138 
1139  /* add covering variable for unfixed rhs variable */
1140  if( !termIsConstant(scip, socrhsvar, SCIPgetRhsCoefSOC(scip, soccons), globalbounds) )
1141  {
1142  SCIP_CALL( SCIPgetNegatedVar(coveringscip, coveringvars[probindex], &coveringconsvars[ntofix]) );
1143  ntofix++;
1144  }
1145 
1146  /* go through lhs variables */
1147  for( v = SCIPgetNLhsVarsSOC(scip, soccons)-1; v >= 0; v-- )
1148  {
1149  assert(soclhsvars[v] != NULL);
1150 
1151  /* soc constraints should contain only active and multi-aggregated variables; the latter we do not handle */
1152  probindex = SCIPvarGetProbindex(soclhsvars[v]);
1153  if( probindex == -1 )
1154  {
1155  SCIPdebugMessage("inactive variables detected in constraint <%s>\n", SCIPconsGetName(soccons));
1156  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
1157  goto TERMINATE;
1158  }
1159 
1160  /* add covering variable for unfixed lhs variable */
1161  if( !termIsConstant(scip, soclhsvars[v], SCIPgetLhsCoefsSOC(scip, soccons)[v], globalbounds) )
1162  {
1163  SCIP_CALL( SCIPgetNegatedVar(coveringscip, coveringvars[probindex], &coveringconsvars[ntofix]) );
1164  ntofix++;
1165  }
1166  }
1167 
1168  if( ntofix >= 2 )
1169  {
1170  /* create covering constraint */
1171  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_covering", SCIPconsGetName(soccons));
1172  SCIP_CALL( SCIPcreateConsSetpack(coveringscip, &coveringcons, name, ntofix, coveringconsvars,
1173  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
1174 
1175  if( coveringcons == NULL )
1176  {
1177  SCIPdebugMessage("failed to create set packing constraint <%s>\n", name);
1178  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
1179  goto TERMINATE;
1180  }
1181 
1182  /* add and release covering constraint */
1183  SCIP_CALL( SCIPaddCons(coveringscip, coveringcons) );
1184  SCIP_CALL( SCIPreleaseCons(coveringscip, &coveringcons) );
1185 
1186  /* update counters */
1187  for( v = ntofix-1; v >= 0; v-- )
1188  incCounters(termcounter, conscounter, consmarker, SCIPvarGetProbindex(SCIPvarGetNegatedVar(coveringconsvars[v])));
1189  }
1190 
1191  /* free memory for covering constraint */
1192  SCIPfreeBufferArray(coveringscip, &coveringconsvars);
1193  }
1194  }
1195 
1196  /* go through all yet unprocessed nlrows */
1197  if( nlrowmap != NULL )
1198  {
1199  SCIP_NLROW** nlrows;
1200  int nnlrows;
1201 
1202  assert(SCIPisNLPConstructed(scip));
1203 
1204  /* get nlrows */
1205  nnlrows = SCIPgetNNLPNlRows(scip);
1206  nlrows = SCIPgetNLPNlRows(scip);
1207 
1208  for( i = nnlrows-1; i >= 0; i-- )
1209  {
1210  assert(nlrows[i] != NULL);
1211 
1212  /* nlrow or corresponding constraint already processed */
1213  if( SCIPhashmapExists(nlrowmap, nlrows[i]) )
1214  continue;
1215 
1216  /* process nlrow */
1217  *success = FALSE;
1218  SCIP_CALL( processNlRow(scip, nlrows[i], exprint, &hessiandata, coveringscip, nvars, coveringvars,
1219  termcounter, conscounter, consmarker, globalbounds, onlyconvexify, success) );
1220 
1221  if( *success == FALSE )
1222  goto TERMINATE;
1223  }
1224  }
1225 
1226  /* set objective function of covering problem */
1227  switch( coveringobj )
1228  {
1229  case 'c': /* number of influenced nonlinear constraints */
1230  for( i = nvars-1; i >= 0; i-- )
1231  {
1232  SCIP_CALL( SCIPchgVarObj(coveringscip, coveringvars[i], (SCIP_Real) conscounter[i]) );
1233  }
1234  break;
1235  case 'd': /* domain size */
1236  for( i = nvars-1; i >= 0; i-- )
1237  {
1238  SCIP_CALL( SCIPchgVarObj(coveringscip, coveringvars[i],
1239  (globalbounds ? SCIPvarGetUbGlobal(vars[i]) - SCIPvarGetLbGlobal(vars[i]) : SCIPvarGetUbLocal(vars[i]) - SCIPvarGetLbLocal(vars[i]))) );
1240  }
1241  break;
1242  case 'l': /* number of locks */
1243  for( i = nvars-1; i >= 0; i-- )
1244  {
1245  nlocksup = SCIPvarGetNLocksUp(vars[i]);
1246  nlocksdown = SCIPvarGetNLocksDown(vars[i]);
1247  SCIP_CALL( SCIPchgVarObj(coveringscip, coveringvars[i], (SCIP_Real) (nlocksup+nlocksdown+1)) );
1248  }
1249  break;
1250  case 'm': /* min(up locks, down locks)+1 */
1251  for( i = nvars-1; i >= 0; i-- )
1252  {
1253  nlocksup = SCIPvarGetNLocksUp(vars[i]);
1254  nlocksdown = SCIPvarGetNLocksDown(vars[i]);
1255  SCIP_CALL( SCIPchgVarObj(coveringscip, coveringvars[i], (SCIP_Real) (MIN(nlocksup, nlocksdown)+1)) );
1256  }
1257  break;
1258  case 't': /* number of influenced nonlinear terms */
1259  for( i = nvars-1; i >= 0; i-- )
1260  {
1261  SCIP_CALL( SCIPchgVarObj(coveringscip, coveringvars[i], (SCIP_Real) termcounter[i]) );
1262  }
1263  break;
1264  case 'u': /* unit penalties */
1265  for( i = nvars-1; i >= 0; i-- )
1266  {
1267  SCIP_CALL( SCIPchgVarObj(coveringscip, coveringvars[i], 1.0) );
1268  }
1269  break;
1270  default:
1271  SCIPerrorMessage("invalid choice <%c> for covering objective\n", coveringobj);
1272  goto TERMINATE;
1273  }
1274 
1275  /* covering problem successfully set up */
1276  *success = TRUE;
1277 
1278  TERMINATE:
1279  /* free nlrow hash map */
1280  if( nlrowmap != NULL )
1281  {
1282  SCIPhashmapFree(&nlrowmap);
1283  }
1284 
1285  /* free hessian data */
1286  if( hessiandata.nvars > 0 )
1287  {
1288  assert(hessiandata.evalsol != NULL);
1289  assert(hessiandata.varvals != NULL);
1290  assert(hessiandata.sparsity != NULL);
1291 
1292  SCIPfreeBufferArray(scip, &hessiandata.sparsity);
1293  SCIPfreeBufferArray(scip, &hessiandata.varvals);
1294 
1295  SCIP_CALL( SCIPfreeSol(scip, &hessiandata.evalsol) );
1296  }
1297  else
1298  {
1299  assert(hessiandata.evalsol == NULL);
1300  assert(hessiandata.varvals == NULL);
1301  assert(hessiandata.sparsity == NULL);
1302  }
1303 
1304  /* free expression interpreter */
1305  SCIP_CALL( SCIPexprintFree(&exprint) );
1306 
1307  SCIPstatistic(
1308  {
1309  int nnonzs;
1310  nnonzs = 0;
1311  for( i = 0; i < nvars; ++i)
1312  nnonzs += termcounter[i];
1313  SCIPstatisticPrintf("UCstats nnz/var: %9.6f\n", nnonzs/(SCIP_Real)nvars);
1314  nnonzs = 0;
1315  for( i = 0; i < nvars; ++i)
1316  if( conscounter[i] > 0 )
1317  nnonzs++;
1318  SCIPstatisticPrintf("UCstats nlvars: %6d\n", nnonzs);
1319  }
1320  );
1321 
1322  /* free counter arrays for weighted objectives */
1323  SCIPfreeBufferArray(scip, &termcounter);
1324  SCIPfreeBufferArray(scip, &conscounter);
1325  SCIPfreeBufferArray(scip, &consmarker);
1326 
1327  return SCIP_OKAY;
1328 }
1329 
1330 
1331 /** adds a constraint to the covering problem to forbid the given cover */
1332 static
1334  SCIP* scip, /**< SCIP data structure of the covering problem */
1335  int nvars, /**< number of variables */
1336  SCIP_VAR** vars, /**< variable array */
1337  int coversize, /**< size of the cover */
1338  int* cover, /**< problem indices of the variables in the cover */
1339  int diversification, /**< how many unfixed variables have to change their value? */
1340  SCIP_Bool* success, /**< pointer to store whether the cutoff constraint was created successfully */
1341  SCIP_Bool* infeas /**< pointer to store whether the cutoff proves (local or global) infeasibility */
1342  )
1343 {
1344  SCIP_CONS* cons;
1345  SCIP_VAR** consvars;
1346 
1347  char name[SCIP_MAXSTRLEN];
1348  int nconsvars;
1349  int i;
1350 
1351  assert(scip != NULL);
1352  assert(vars != NULL);
1353  assert(nvars >= 1);
1354  assert(cover != NULL);
1355  assert(coversize >= 1);
1356  assert(coversize <= nvars);
1357  assert(diversification >= 1);
1358  assert(success != NULL);
1359  assert(infeas != NULL);
1360 
1361  *success = FALSE;
1362  *infeas = FALSE;
1363 
1364  /* allocate memory for constraint variables */
1365  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, coversize) );
1366  nconsvars = 0;
1367  cons = NULL;
1368 
1369  /* create constraint name */
1370  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "forbid_cover_assignment");
1371 
1372  /* if all variables in the cover are binary and we require only one variable to change its value, then we create a
1373  * set covering constraint
1374  */
1375  if( diversification == 1 )
1376  {
1377  /* build up constraint */
1378  for( i = coversize-1; i >= 0; i-- )
1379  {
1380  if( !SCIPisFeasGE(scip, SCIPvarGetLbLocal(vars[cover[i]]), 1.0) )
1381  {
1382  SCIP_CALL( SCIPgetNegatedVar(scip, vars[cover[i]], &consvars[nconsvars]) );
1383  nconsvars++;
1384  }
1385  }
1386 
1387  /* if all covering variables are fixed to one, the constraint cannot be satisfied */
1388  if( nconsvars == 0 )
1389  {
1390  *infeas = TRUE;
1391  }
1392  else
1393  {
1394  /* create constraint */
1395  SCIP_CALL( SCIPcreateConsSetcover(scip, &cons, name, nconsvars, consvars,
1396  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
1397  }
1398  }
1399  /* if all variables in the cover are binary and we require more variables to change their value, then we create a
1400  * linear constraint
1401  */
1402  else
1403  {
1404  SCIP_Real* consvals;
1405  SCIP_Real rhs;
1406 
1407  /* build up constraint */
1408  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, coversize) );
1409  for( i = coversize-1; i >= 0; i-- )
1410  {
1411  if( !SCIPisFeasGE(scip, SCIPvarGetLbLocal(vars[cover[i]]), 1.0) )
1412  {
1413  consvars[nconsvars] = vars[cover[i]];
1414  consvals[nconsvars] = 1.0;
1415  nconsvars++;
1416  }
1417  }
1418  rhs = (SCIP_Real) (nconsvars-diversification);
1419 
1420  /* if too many covering variables are fixed to 1, the constraint cannot be satisfied */
1421  if( rhs < 0 )
1422  {
1423  *infeas = TRUE;
1424  }
1425  else
1426  {
1427  /* create constraint */
1428  SCIP_CALL( SCIPcreateConsLinear(scip, &cons, name,
1429  nconsvars, consvars, consvals, -SCIPinfinity(scip), rhs,
1430  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) );
1431  }
1432 
1433  /* free memory */
1434  SCIPfreeBufferArray(scip, &consvals);
1435  }
1436 
1437  /* free memory */
1438  SCIPfreeBufferArray(scip, &consvars);
1439 
1440  /* if proven infeasible, we do not even add the constraint; otherwise we add and release the constraint if created
1441  * successfully
1442  */
1443  if( !(*infeas) && cons != NULL )
1444  {
1445  SCIP_CALL( SCIPaddCons(scip, cons) );
1446  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1447  *success = TRUE;
1448  }
1449 
1450  return SCIP_OKAY;
1451 }
1452 
1453 
1454 /** adds a set covering or bound disjunction constraint to the original problem */
1455 static
1457  SCIP* scip, /**< SCIP data structure */
1458  int bdlen, /**< length of bound disjunction */
1459  SCIP_VAR** bdvars, /**< array of variables in bound disjunction */
1460  SCIP_BOUNDTYPE* bdtypes, /**< array of bound types in bound disjunction */
1461  SCIP_Real* bdbounds, /**< array of bounds in bound disjunction */
1462  SCIP_Bool local, /**< is constraint valid only locally? */
1463  SCIP_Bool dynamic, /**< is constraint subject to aging? */
1464  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup? */
1465  SCIP_Bool* success /**< pointer to store whether the cutoff constraint was created successfully */
1466  )
1467 {
1468  SCIP_CONS* cons;
1469  SCIP_VAR** consvars;
1470  SCIP_Bool isbinary;
1471  char name[SCIP_MAXSTRLEN];
1472  int i;
1473 
1474  assert(scip != NULL);
1475  assert(bdlen >= 1);
1476  assert(bdvars != NULL);
1477  assert(bdtypes != NULL);
1478  assert(bdbounds != NULL);
1479  assert(success != NULL);
1480 
1481  /* initialize */
1482  *success = FALSE;
1483  cons = NULL;
1484  consvars = NULL;
1485 
1486  /* create constraint name */
1487  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "undercover_cutoff");
1488 
1489  /* check if all variables in the cover are binary */
1490  isbinary = TRUE;
1491  for( i = bdlen-1; i >= 0 && isbinary; i-- )
1492  {
1493  isbinary = SCIPvarIsBinary(bdvars[i]);
1494  }
1495 
1496  /* if all variables in the cover are binary, then we create a logicor constraint */
1497  if( isbinary )
1498  {
1499  /* allocate memory for constraint variables */
1500  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, bdlen) );
1501 
1502  /* build up constraint */
1503  for( i = bdlen-1; i >= 0; i-- )
1504  {
1505  assert(bdtypes[i] == SCIP_BOUNDTYPE_LOWER || SCIPisFeasZero(scip, bdbounds[i]));
1506  assert(bdtypes[i] == SCIP_BOUNDTYPE_UPPER || SCIPisFeasEQ(scip, bdbounds[i], 1.0));
1507 
1508  if( bdtypes[i] == SCIP_BOUNDTYPE_LOWER )
1509  {
1510  consvars[i] = bdvars[i];
1511  }
1512  else
1513  {
1514  assert(bdtypes[i] == SCIP_BOUNDTYPE_UPPER);
1515  SCIP_CALL( SCIPgetNegatedVar(scip, bdvars[i], &consvars[i]) );
1516  }
1517  }
1518 
1519  /* create conflict constraint */
1520  SCIP_CALL( SCIPcreateConsLogicor(scip, &cons, name, bdlen, consvars,
1521  FALSE, TRUE, FALSE, FALSE, TRUE, local, FALSE, dynamic, removable, FALSE) );
1522  }
1523  /* otherwise we create a bound disjunction constraint as given */
1524  else
1525  {
1526  /* create conflict constraint */
1527  SCIP_CALL( SCIPcreateConsBounddisjunction(scip, &cons, name, bdlen, bdvars, bdtypes, bdbounds,
1528  FALSE, TRUE, FALSE, FALSE, TRUE, local, FALSE, dynamic, removable, FALSE) );
1529  }
1530 
1531  /* add and release constraint if created successfully */
1532  if( cons != NULL )
1533  {
1534  if( local )
1535  {
1536  SCIP_CALL( SCIPaddConsLocal(scip, cons, NULL) );
1537  }
1538  else
1539  {
1540  SCIP_CALL( SCIPaddCons(scip, cons) );
1541  }
1542 
1543  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1544  *success = TRUE;
1545  }
1546 
1547  /* free memory */
1548  SCIPfreeBufferArrayNull(scip, &consvars);
1549 
1550  return SCIP_OKAY;
1551 }
1552 
1553 
1554 /** solve covering problem */
1555 static
1557  SCIP* coveringscip, /**< SCIP data structure for the covering problem */
1558  int ncoveringvars, /**< number of the covering problem's variables */
1559  SCIP_VAR** coveringvars, /**< array of the covering problem's variables */
1560  int* coversize, /**< size of the computed cover */
1561  int* cover, /**< array to store indices of the variables in the computed cover
1562  * (should be ready to hold ncoveringvars entries) */
1563  SCIP_Real timelimit, /**< time limit */
1564  SCIP_Real memorylimit, /**< memory limit */
1565  SCIP_Real objlimit, /**< upper bound on the cover size */
1566  SCIP_Bool* success /**< feasible cover found? */
1567  )
1568 {
1569  SCIP_Real* solvals;
1570  SCIP_Real totalpenalty;
1571  SCIP_RETCODE retcode;
1572  int i;
1573 
1574  assert(coveringscip != NULL);
1575  assert(coveringvars != NULL);
1576  assert(cover != NULL);
1577  assert(coversize != NULL);
1578  assert(timelimit > 0.0);
1579  assert(memorylimit > 0.0);
1580  assert(success != NULL);
1581 
1582  *success = FALSE;
1583 
1584  /* forbid call of heuristics and separators solving sub-CIPs */
1585  SCIP_CALL( SCIPsetSubscipsOff(coveringscip, TRUE) );
1586 
1587  /* set presolving and separation to fast */
1590 
1591  /* use inference branching */
1592  if( SCIPfindBranchrule(coveringscip, "inference") != NULL && !SCIPisParamFixed(coveringscip, "branching/inference/priority") )
1593  {
1594  SCIP_CALL( SCIPsetIntParam(coveringscip, "branching/inference/priority", INT_MAX/4) );
1595  }
1596 
1597  /* only solve root */
1598  SCIP_CALL( SCIPsetLongintParam(coveringscip, "limits/nodes", 1LL) );
1599 
1600  SCIPdebugMessage("timelimit = %g, memlimit = %g\n", timelimit, memorylimit);
1601 
1602  /* set time, memory, and objective limit */
1603  SCIP_CALL( SCIPsetRealParam(coveringscip, "limits/time", timelimit) );
1604  SCIP_CALL( SCIPsetRealParam(coveringscip, "limits/memory", memorylimit) );
1605  SCIP_CALL( SCIPsetObjlimit(coveringscip, objlimit) );
1606 
1607  /* do not abort on CTRL-C */
1608  SCIP_CALL( SCIPsetBoolParam(coveringscip, "misc/catchctrlc", FALSE) );
1609 
1610  /* disable output to console in optimized mode, enable in SCIP's debug mode */
1611 #ifdef SCIP_DEBUG
1612  SCIP_CALL( SCIPsetIntParam(coveringscip, "display/verblevel", 5) );
1613  SCIP_CALL( SCIPsetIntParam(coveringscip, "display/freq", 100000) );
1614 #else
1615  SCIP_CALL( SCIPsetIntParam(coveringscip, "display/verblevel", 0) );
1616 #endif
1617 
1618 
1619  /* solve covering problem */
1620  retcode = SCIPsolve(coveringscip);
1621 
1622  /* errors in solving the covering problem should not kill the overall solving process;
1623  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
1624  */
1625  if( retcode != SCIP_OKAY )
1626  {
1627 #ifndef NDEBUG
1628  SCIP_CALL( retcode );
1629 #endif
1630  SCIPwarningMessage(coveringscip, "Error while solving covering problem in Undercover heuristic; sub-SCIP terminated with code <%d>\n",retcode);
1631  return SCIP_OKAY;
1632  }
1633 
1634  /* check, whether a feasible cover was found */
1635  if( SCIPgetNSols(coveringscip) == 0 )
1636  return SCIP_OKAY;
1637 
1638  /* store solution */
1639  SCIP_CALL( SCIPallocBufferArray(coveringscip, &solvals, ncoveringvars) );
1640  SCIP_CALL( SCIPgetSolVals(coveringscip, SCIPgetBestSol(coveringscip), ncoveringvars, coveringvars, solvals) );
1641 
1642  *coversize = 0;
1643  totalpenalty = 0.0;
1644  for( i = 0; i < ncoveringvars; i++ )
1645  {
1646  if( solvals[i] > 0.5 )
1647  {
1648  cover[*coversize] = i;
1649  (*coversize)++;
1650  }
1651  totalpenalty += SCIPvarGetObj(coveringvars[i]);
1652  }
1653 
1654  /* print solution if we are in SCIP's debug mode */
1655  assert(SCIPgetBestSol(coveringscip) != NULL);
1656  SCIPdebugMessage("found a feasible cover: %d/%d variables fixed, normalized penalty=%g\n\n",
1657  *coversize, SCIPgetNOrigVars(coveringscip), SCIPgetSolOrigObj(coveringscip, SCIPgetBestSol(coveringscip))/(totalpenalty+SCIPsumepsilon(coveringscip)));
1658  SCIPdebug( SCIP_CALL( SCIPprintSol(coveringscip, SCIPgetBestSol(coveringscip), NULL, FALSE) ) );
1659  SCIPdebugMessage("\r \n");
1660 
1661  *success = TRUE;
1662 
1663  /* free array of solution values */
1664  SCIPfreeBufferArray(coveringscip, &solvals);
1665 
1666  return SCIP_OKAY;
1667 }
1668 
1669 
1670 /** computes fixing order and returns whether order has really been changed */
1671 static
1673  SCIP* scip, /**< original SCIP data structure */
1674  SCIP_HEURDATA* heurdata, /**< heuristic data */
1675  int nvars, /**< number of variables in the original problem */
1676  SCIP_VAR** vars, /**< variables in the original problem */
1677  int coversize, /**< size of the cover */
1678  int* cover, /**< problem indices of the variables in the cover */
1679  int lastfailed, /**< position in cover array of the variable the fixing of which yielded
1680  * infeasibility in last dive (or >= coversize, in which case *success
1681  * is always TRUE) */
1682  SCIP_Bool* success /**< has order really been changed? */
1683  )
1684 {
1685  SCIP_Real* scores;
1686  SCIP_Real bestscore;
1687  SCIP_Bool sortdown;
1688  int i;
1689 
1690  assert(scip != NULL);
1691  assert(heurdata != NULL);
1692  assert(nvars >= 1);
1693  assert(vars != NULL);
1694  assert(coversize >= 1);
1695  assert(cover != NULL);
1696  assert(lastfailed >= 0);
1697 
1698  *success = FALSE;
1699 
1700  /* if fixing the first variable had failed, do not try with another order */
1701  if( lastfailed == 0 )
1702  return SCIP_OKAY;
1703 
1704  /* allocate buffer array for score values */
1705  SCIP_CALL( SCIPallocBufferArray(scip, &scores, coversize) );
1706 
1707  /* initialize best score to infinite value */
1708  sortdown = (heurdata->fixingorder == 'c' || heurdata->fixingorder == 'v' );
1709  bestscore = sortdown ? -SCIPinfinity(scip) : +SCIPinfinity(scip);
1710 
1711  /* compute score values */
1712  for( i = coversize-1; i >= 0; i-- )
1713  {
1714  SCIP_VAR* var;
1715 
1716  /* get variable in the cover */
1717  assert(cover[i] >= 0);
1718  assert(cover[i] < nvars);
1719  var = vars[cover[i]];
1720 
1721  if( heurdata->fixingorder == 'C' || heurdata->fixingorder == 'c' )
1722  scores[i] = heurdata->conflictweight * SCIPgetVarConflictScore(scip, var)
1723  + heurdata->inferenceweight * SCIPgetVarAvgInferenceCutoffScore(scip, var, heurdata->cutoffweight);
1724  else if( heurdata->fixingorder == 'V' || heurdata->fixingorder == 'v' )
1725  scores[i] = cover[i];
1726  else
1727  return SCIP_PARAMETERWRONGVAL;
1728 
1729  assert(scores[i] >= 0.0);
1730 
1731  /* update best score */
1732  if( sortdown )
1733  bestscore = MAX(bestscore, scores[i]);
1734  else
1735  bestscore = MIN(bestscore, scores[i]);
1736 
1737  }
1738 
1739  /* put integers to the front */
1740  if( heurdata->fixintfirst )
1741  {
1742  for( i = coversize-1; i >= 0; i-- )
1743  {
1744  if( SCIPvarIsIntegral(vars[cover[i]]) )
1745  {
1746  if( sortdown )
1747  scores[i] += bestscore+1.0;
1748  else
1749  scores[i] = bestscore - 1.0/(scores[i]+1.0);
1750  }
1751  }
1752  }
1753 
1754  /* put last failed variable to the front */
1755  if( lastfailed < coversize )
1756  {
1757  if( sortdown )
1758  scores[lastfailed] += bestscore+2.0;
1759  else
1760  scores[lastfailed] = bestscore - 2.0/(scores[lastfailed]+1.0);
1761  i = cover[lastfailed];
1762  }
1763 
1764  /* sort by non-decreasing (negative) score */
1765  if( sortdown )
1766  SCIPsortDownRealInt(scores, cover, coversize);
1767  else
1768  SCIPsortRealInt(scores, cover, coversize);
1769 
1770  assert(lastfailed >= coversize || cover[0] == i);
1771 
1772  /* free buffer memory */
1773  SCIPfreeBufferArray(scip, &scores);
1774 
1775  *success = TRUE;
1776 
1777  return SCIP_OKAY;
1778 }
1779 
1780 
1781 /** gets fixing value */
1782 static
1784  SCIP* scip, /**< original SCIP data structure */
1785  SCIP_HEURDATA* heurdata, /**< heuristic data */
1786  SCIP_VAR* var, /**< variable in the original problem */
1787  SCIP_Real* val, /**< buffer for returning fixing value */
1788  char fixalt, /**< source of the fixing value: 'l'p relaxation, 'n'lp relaxation, 'i'ncumbent solution */
1789  SCIP_Bool* success, /**< could value be retrieved successfully? */
1790  int bdlen, /**< current length of probing path */
1791  SCIP_VAR** bdvars, /**< array of variables with bound changes along probing path */
1792  SCIP_BOUNDTYPE* bdtypes, /**< array of bound types in bound disjunction */
1793  SCIP_Real* oldbounds /**< array of bounds before fixing */
1794  )
1795 {
1796  assert(scip != NULL);
1797  assert(heurdata != NULL);
1798  assert(var != NULL);
1799  assert(val != NULL);
1800  assert(success != NULL);
1801 
1802  *success = FALSE;
1803 
1804  switch( fixalt )
1805  {
1806  case 'l':
1807  /* get the last LP solution value */
1808  *val = SCIPvarGetLPSol(var);
1809  *success = TRUE;
1810  break;
1811  case 'n':
1812  /* only call this function if NLP relaxation is available */
1813  assert(SCIPisNLPConstructed(scip));
1814 
1815  /* the solution values are already available */
1816  if( heurdata->nlpsolved )
1817  {
1818  assert(!heurdata->nlpfailed);
1819 
1820  /* retrieve NLP solution value */
1821  *val = SCIPvarGetNLPSol(var);
1822  *success = TRUE;
1823  }
1824  /* solve NLP relaxation unless it has not failed too often before */
1825  else if( !heurdata->nlpfailed )
1826  { /*lint --e{850}*/
1827  SCIP_NLPSOLSTAT stat;
1828  int i;
1829 
1830  /* restore bounds at start of probing, since otherwise, if in backtrack mode, NLP solver becomes most likely
1831  * locally infeasible
1832  */
1833  SCIP_CALL( SCIPstartDiveNLP(scip) );
1834 
1835  for( i = bdlen-1; i >= 0; i-- )
1836  {
1837  SCIP_VAR* relaxvar;
1838  SCIP_Real lb;
1839  SCIP_Real ub;
1840 
1841  relaxvar = bdvars[i];
1842 
1843  /* both bounds were tightened */
1844  if( i > 0 && bdvars[i-1] == relaxvar )
1845  {
1846  assert(bdtypes[i] != bdtypes[i-1]);
1847 
1848  lb = bdtypes[i] == SCIP_BOUNDTYPE_UPPER ? oldbounds[i] : oldbounds[i-1];
1849  ub = bdtypes[i] == SCIP_BOUNDTYPE_UPPER ? oldbounds[i-1] : oldbounds[i];
1850  i--;
1851  }
1852  /* lower bound was tightened */
1853  else if( bdtypes[i] == SCIP_BOUNDTYPE_UPPER )
1854  {
1855  lb = oldbounds[i];
1856  ub = SCIPvarGetUbLocal(relaxvar);
1857  }
1858  /* upper bound was tightened */
1859  else
1860  {
1861  lb = SCIPvarGetLbLocal(relaxvar);
1862  ub = oldbounds[i];
1863  }
1864 
1865  assert(SCIPisLE(scip, lb, SCIPvarGetLbLocal(relaxvar)));
1866  assert(SCIPisGE(scip, ub, SCIPvarGetUbLocal(relaxvar)));
1867 
1868  /* relax bounds */
1869  SCIP_CALL( SCIPchgVarBoundsDiveNLP(scip, relaxvar, lb, ub) );
1870  }
1871 
1872  /* activate NLP solver output if we are in SCIP's debug mode */
1874 
1875  /* set starting point to lp solution */
1877 
1878  /* solve NLP relaxation */
1879  SCIP_CALL( SCIPsolveDiveNLP(scip) );
1880  stat = SCIPgetNLPSolstat(scip);
1881  *success = stat == SCIP_NLPSOLSTAT_GLOBOPT || stat == SCIP_NLPSOLSTAT_LOCOPT || stat == SCIP_NLPSOLSTAT_FEASIBLE;
1882 
1883  SCIPdebugMessage("solving NLP relaxation to obtain fixing values %s (stat=%d)\n", *success ? "successful" : "failed", stat);
1884 
1885  if( *success )
1886  {
1887  /* solving succeeded */
1888  heurdata->nnlpfails = 0;
1889  heurdata->nlpsolved = TRUE;
1890 
1891  /* retrieve NLP solution value */
1892  *val = SCIPvarGetNLPSol(var);
1893  }
1894  else
1895  {
1896  /* solving failed */
1897  heurdata->nnlpfails++;
1898  heurdata->nlpfailed = TRUE;
1899  heurdata->nlpsolved = FALSE;
1900 
1901  SCIPdebugMessage("solving NLP relaxation failed (%d time%s%s)\n",
1902  heurdata->nnlpfails, heurdata->nnlpfails > 1 ? "s" : "", heurdata->nnlpfails >= MAXNLPFAILS ? ", will not be called again" : "");
1903  }
1904  }
1905  break;
1906  case 'i':
1907  /* only call this function if a feasible solution is available */
1908  assert(SCIPgetBestSol(scip) != NULL);
1909 
1910  /* get value in the incumbent solution */
1911  *val = SCIPgetSolVal(scip, SCIPgetBestSol(scip), var);
1912  *success = TRUE;
1913  break;
1914  default:
1915  break;
1916  }
1917 
1918  return SCIP_OKAY;
1919 }
1920 
1921 
1922 /** calculates up to four alternative values for backtracking, if fixing the variable failed.
1923  * The alternatives are the two bounds of the variable, and the averages of the bounds and the fixing value.
1924  * For infinite bounds, fixval +/- abs(fixval) will be used instead.
1925  */
1926 static
1928  SCIP* scip, /**< original SCIP data structure */
1929  SCIP_VAR* var, /**< variable to calculate alternatives for */
1930  SCIP_Real fixval, /**< reference fixing value */
1931  int* nalternatives, /**< number of fixing values computed */
1932  SCIP_Real* alternatives /**< array to store the alternative fixing values */
1933  )
1934 {
1935  SCIP_Real lb;
1936  SCIP_Real ub;
1937 
1938  /* for binary variables, there is only two possible fixing values */
1939  if( SCIPvarIsBinary(var) )
1940  {
1941  if( SCIPisFeasEQ(scip, fixval, 0.0) || SCIPisFeasEQ(scip, fixval, 1.0) )
1942  {
1943  alternatives[0] = 1.0 - fixval;
1944  *nalternatives = 1;
1945  }
1946  else
1947  {
1948  alternatives[0] = 0.0;
1949  alternatives[1] = 1.0;
1950  *nalternatives = 2;
1951  }
1952  return;
1953  }
1954 
1955  /* get bounds */
1956  lb = SCIPvarGetLbLocal(var);
1957  ub = SCIPvarGetUbLocal(var);
1958 
1959  /* if lower bound is infinite, use x'-|x'|; if x' is zero, use -1.0 instead */
1960  if( SCIPisInfinity(scip, -lb) )
1961  lb = SCIPisFeasZero(scip, fixval) ? -1.0 : fixval - ABS(fixval);
1962 
1963  /* if upper bound is infinite, use x'+|x'|; if x' is zero, use 1.0 instead */
1964  if( SCIPisInfinity(scip, ub) )
1965  ub = SCIPisFeasZero(scip, fixval) ? 1.0 : fixval + ABS(fixval);
1966 
1967  assert(!SCIPisEQ(scip, lb, ub));
1968 
1969  /* collect alternatives */
1970  *nalternatives = 0;
1971 
1972  /* use lower bound if not equal to x' */
1973  if( !SCIPisFeasEQ(scip, lb, fixval) )
1974  {
1975  alternatives[*nalternatives] = lb;
1976  (*nalternatives)++;
1977  }
1978 
1979  /* use upper bound if not equal to x' */
1980  if( !SCIPisFeasEQ(scip, ub, fixval) )
1981  {
1982  alternatives[*nalternatives] = ub;
1983  (*nalternatives)++;
1984  }
1985 
1986  /* use the average of x' and lower bound as alternative value, if this is not equal to any of the other values */
1987  if( !SCIPisFeasEQ(scip, lb, fixval) && (!SCIPvarIsIntegral(var) || !SCIPisFeasEQ(scip, lb, fixval-1)) )
1988  {
1989  alternatives[*nalternatives] = (lb+fixval)/2.0;
1990  (*nalternatives)++;
1991  }
1992 
1993  /* use the average of x' and upper bound as alternative value, if this is not equal to any of the other values */
1994  if( !SCIPisFeasEQ(scip, ub, fixval) && (!SCIPvarIsIntegral(var) || !SCIPisFeasEQ(scip, ub, fixval+1)) )
1995  {
1996  alternatives[*nalternatives] = (ub+fixval)/2.0;
1997  (*nalternatives)++;
1998  }
1999 
2000  assert(*nalternatives <= 4);
2001 
2002  return;
2003 }
2004 
2005 
2006 /** rounds the given fixing value */
2007 static
2009  SCIP* scip, /**< original SCIP data structure */
2010  SCIP_Real* val, /**< fixing value to be rounded */
2011  SCIP_VAR* var, /**< corresponding variable */
2012  SCIP_Bool locksrounding /**< shall we round according to locks? (otherwise to nearest integer) */
2013  )
2014 {
2015  SCIP_Real x;
2016 
2017  x = *val;
2018 
2019  /* if integral within feasibility tolerance, only shift to nearest integer */
2020  if( SCIPisFeasIntegral(scip, x) )
2021  x = SCIPfeasFrac(scip, x) < 0.5 ? SCIPfeasFloor(scip, x) : SCIPfeasCeil(scip, x);
2022 
2023  /* round in the direction of least locks with fractionality as tie breaker */
2024  else if( locksrounding )
2025  {
2026  if( SCIPvarGetNLocksDown(var) < SCIPvarGetNLocksUp(var) )
2027  x = SCIPfeasFloor(scip, x);
2028  else if( SCIPvarGetNLocksDown(var) > SCIPvarGetNLocksUp(var) )
2029  x = SCIPfeasCeil(scip, x);
2030  else
2031  x = SCIPfeasFrac(scip, x) < 0.5 ? SCIPfeasFloor(scip, x) : SCIPfeasCeil(scip, x);
2032  }
2033  /* round in the direction of least fractionality with locks as tie breaker */
2034  else
2035  {
2036  if( SCIPfeasFrac(scip, x) < 0.5)
2037  x = SCIPfeasFloor(scip, x);
2038  else if( SCIPfeasFrac(scip, x) > 0.5 )
2039  x = SCIPfeasCeil(scip, x);
2040  else
2041  x = SCIPvarGetNLocksDown(var) < SCIPvarGetNLocksUp(var) ? SCIPfeasFloor(scip, x) : SCIPfeasCeil(scip, x);
2042  }
2043 
2044  /* return rounded fixing value */
2045  *val = x;
2046 
2047  return SCIP_OKAY;
2048 }
2049 
2050 
2051 /** copy the solution of the subproblem to newsol */
2052 static
2054  SCIP* scip, /**< original SCIP data structure */
2055  SCIP* subscip, /**< SCIP structure of the subproblem */
2056  SCIP_VAR** subvars, /**< the variables of the subproblem */
2057  SCIP_SOL* subsol, /**< solution of the subproblem */
2058  SCIP_SOL** newsol /**< solution to the original problem */
2059  )
2060 {
2061  SCIP_VAR** vars; /* the original problem's variables */
2062  SCIP_Real* subsolvals; /* solution values of the subproblem */
2063  int nvars;
2064 
2065  assert(scip != NULL);
2066  assert(subscip != NULL);
2067  assert(subvars != NULL);
2068  assert(subsol != NULL);
2069  assert(newsol != NULL);
2070  assert(*newsol != NULL);
2071 
2072  /* get variables' data */
2073  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
2074 
2075  /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
2076  * since constraint copying may have required the copy of variables that are fixed in the main SCIP
2077  */
2078  assert(nvars <= SCIPgetNOrigVars(subscip));
2079 
2080  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
2081 
2082  /* copy the solution */
2083  SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
2084  SCIP_CALL( SCIPsetSolVals(scip, *newsol, nvars, vars, subsolvals) );
2085 
2086  SCIPfreeBufferArray(scip, &subsolvals);
2087 
2088  return SCIP_OKAY;
2089 }
2090 
2091 
2092 /** solve subproblem and pass best feasible solution to original SCIP instance */
2093 static
2095  SCIP* scip, /**< SCIP data structure of the original problem */
2096  SCIP_HEUR* heur, /**< heuristic data structure */
2097  int coversize, /**< size of the cover */
2098  int* cover, /**< problem indices of the variables in the cover */
2099  SCIP_Real* fixingvals, /**< fixing values for the variables in the cover */
2100  SCIP_Real timelimit, /**< time limit */
2101  SCIP_Real memorylimit, /**< memory limit */
2102  SCIP_Longint nodelimit, /**< node limit */
2103  SCIP_Longint nstallnodes, /**< number of stalling nodes for the subproblem */
2104  SCIP_Bool* validsolved, /**< was problem constructed from a valid copy and solved (proven optimal or infeasible)? */
2105  SCIP_SOL** sol, /**< best solution found in subproblem (if feasible); *sol must be NULL, solution will be created */
2106  SCIP_Longint* nusednodes /**< number of nodes used for solving the subproblem */
2107  )
2108 {
2109  SCIP_HEURDATA* heurdata;
2110  SCIP* subscip;
2111  SCIP_VAR** subvars;
2112  SCIP_VAR** vars;
2113  SCIP_HASHMAP* varmap;
2114 
2115  SCIP_RETCODE retcode;
2116 
2117  int nvars;
2118  int i;
2119 
2120  assert(scip != NULL);
2121  assert(heur != NULL);
2122  assert(cover != NULL);
2123  assert(fixingvals != NULL);
2124  assert(coversize >= 1);
2125  assert(timelimit > 0.0);
2126  assert(memorylimit > 0.0);
2127  assert(nodelimit >= 1);
2128  assert(nstallnodes >= 1);
2129  assert(validsolved != NULL);
2130  assert(sol != NULL);
2131  assert(*sol == NULL);
2132  assert(nusednodes != NULL);
2133 
2134  *validsolved = FALSE;
2135  *nusednodes = 0;
2136 
2137  /* get heuristic data */
2138  heurdata = SCIPheurGetData(heur);
2139  assert(heurdata != NULL);
2140 
2141  /* get required data of the original problem */
2142  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
2143 
2144  /* create subproblem */
2145  SCIP_CALL( SCIPcreate(&subscip) );
2146  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
2147 
2148  /* create the variable mapping hash map */
2149  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(subscip), SCIPcalcHashtableSize(5 * nvars)) );
2150 
2151  /* copy original problem to subproblem; do not copy pricers */
2152  SCIP_CALL( SCIPcopy(scip, subscip, varmap, NULL, "undercoversub", heurdata->globalbounds, FALSE, TRUE, validsolved) );
2153 
2154  if( heurdata->copycuts )
2155  {
2156  /* copies all active cuts from cutpool of sourcescip to linear constraints in targetscip */
2157  SCIP_CALL( SCIPcopyCuts(scip, subscip, varmap, NULL, heurdata->globalbounds, NULL) );
2158  }
2159 
2160  SCIPdebugMessage("problem copied, copy %svalid\n", *validsolved ? "" : "in");
2161 
2162  /* store subproblem variables */
2163  for( i = nvars-1; i >= 0; i-- )
2164  {
2165  subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmap, vars[i]);
2166  assert(subvars[i] != NULL);
2167  }
2168 
2169  /* fix subproblem variables in the cover */
2170  SCIPdebugMessage("fixing variables\n");
2171  for( i = coversize-1; i >= 0; i-- )
2172  {
2173  assert(cover[i] >= 0);
2174  assert(cover[i] < nvars);
2175 
2176  SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[cover[i]], fixingvals[i]) );
2177  SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[cover[i]], fixingvals[i]) );
2178  }
2179 
2180  /* set the parameters such that good solutions are found fast */
2181  SCIPdebugMessage("setting subproblem parameters\n");
2185 
2186  /* deactivate expensive pre-root heuristics, since it may happen that the lp relaxation of the subproblem is already
2187  * infeasible; in this case, we do not want to waste time on heuristics before solving the root lp */
2188  if( !SCIPisParamFixed(subscip, "heuristics/shiftandpropagate/freq") )
2189  {
2190  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/shiftandpropagate/freq", -1) );
2191  }
2192 
2193  /* forbid recursive call of undercover heuristic */
2194  if( SCIPisParamFixed(subscip, "heuristics/"HEUR_NAME"/freq") )
2195  {
2196  SCIPwarningMessage(scip, "unfixing parameter heuristics/"HEUR_NAME"/freq in subscip of undercover heuristic to avoid recursive calls\n");
2197  SCIP_CALL( SCIPunfixParam(subscip, "heuristics/"HEUR_NAME"/freq") );
2198  }
2199  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/"HEUR_NAME"/freq", -1) );
2200 
2201  SCIPdebugMessage("timelimit = %g, memlimit = %g, nodelimit = %"SCIP_LONGINT_FORMAT", nstallnodes = %"SCIP_LONGINT_FORMAT"\n", timelimit, memorylimit, nodelimit, nstallnodes);
2202 
2203  SCIPdebugMessage("timelimit = %g, memlimit = %g, nodelimit = %"SCIP_LONGINT_FORMAT", nstallnodes = %"SCIP_LONGINT_FORMAT"\n", timelimit, memorylimit, nodelimit, nstallnodes);
2204 
2205  /* disable statistic timing inside sub SCIP */
2206  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
2207 
2208  /* set time, memory and node limits */
2209  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
2210  SCIP_CALL( SCIPsetRealParam(subscip, "limits/memory", memorylimit) );
2211  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nodelimit) );
2212  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/stallnodes", nstallnodes) );
2213 
2214  /* do not abort subproblem on CTRL-C */
2215  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
2216 
2217  /* disable output to console in optimized mode, enable in SCIP's debug mode */
2218 #ifdef SCIP_DEBUG
2219  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
2220  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000) );
2221 #else
2222  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
2223 #endif
2224 
2225  /* if there is already a solution, add an objective cutoff; note: this does not affect the validity of the subproblem
2226  * if we find solutions later, thus we do not set *validsolved to FALSE */
2227  if( SCIPgetNSols(scip) > 0 )
2228  {
2229  SCIP_Real cutoff;
2230  SCIP_Real upperbound;
2231 
2232  assert(!SCIPisInfinity(scip, SCIPgetUpperbound(scip)));
2233  upperbound = SCIPgetUpperbound(scip);
2234 
2235  if( SCIPisInfinity(scip, -SCIPgetLowerbound(scip)) )
2236  cutoff = (upperbound >= 0 ? 1.0 - heurdata->minimprove : 1.0 + heurdata->minimprove) * upperbound;
2237  else
2238  cutoff = (1.0 - heurdata->minimprove) * upperbound + heurdata->minimprove * SCIPgetLowerbound(scip);
2239 
2240  cutoff = MIN(upperbound, cutoff);
2241  SCIP_CALL( SCIPsetObjlimit(subscip, cutoff) );
2242 
2243  SCIPdebugMessage("adding objective cutoff=%g (minimprove=%g)\n", cutoff, heurdata->minimprove);
2244  }
2245 
2246  /* solve subproblem */
2247  SCIPdebugMessage("solving subproblem started\n");
2248  retcode = SCIPsolve(subscip);
2249 
2250  /* Errors in solving the subproblem should not kill the overall solving process
2251  * Hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
2252  */
2253  if( retcode != SCIP_OKAY )
2254  {
2255 #ifndef NDEBUG
2256  SCIP_CALL( retcode );
2257 #endif
2258  SCIPwarningMessage(scip, "Error while solving subproblem in Undercover heuristic; sub-SCIP terminated with code <%d>\n",retcode);
2259  return SCIP_OKAY;
2260  }
2261 
2262  /* print solving statistics of subproblem if we are in SCIP's debug mode */
2263  SCIPdebug( SCIP_CALL( SCIPprintStatistics(subscip, NULL) ) );
2264 
2265  /* store solving status; note: if we proved infeasibility in presence of an objective cutoff beyond the primal bound,
2266  * the subproblem was not a valid copy */
2267  *validsolved = *validsolved && (SCIPgetStatus(subscip) == SCIP_STATUS_OPTIMAL
2268  || (SCIPgetStatus(subscip) == SCIP_STATUS_INFEASIBLE && (SCIPgetNSols(scip) == 0 || heurdata->minimprove <= 0.0)));
2269  *nusednodes = SCIPgetNNodes(subscip);
2270 
2271  /* if a solution was found for the subproblem, create corresponding solution in the original problem */
2272  if( SCIPgetNSols(subscip) > 0 && (SCIPgetStatus(subscip) != SCIP_STATUS_INFEASIBLE || heurdata->minimprove > 0.0) )
2273  {
2274  SCIP_SOL** subsols;
2275  SCIP_Bool success;
2276  int nsubsols;
2277 
2278  /* create solution */
2279  SCIP_CALL( SCIPcreateSol(scip, sol, heur) );
2280 
2281  /* check, whether a solution was found;
2282  * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted */
2283  nsubsols = SCIPgetNSols(subscip);
2284  subsols = SCIPgetSols(subscip);
2285  assert(subsols != NULL);
2286 
2287  success = FALSE;
2288  for( i = 0; i < nsubsols && !success; i++ )
2289  {
2290  /* transform solution to original problem */
2291  SCIP_CALL( copySol(scip, subscip, subvars, subsols[i], sol) );
2292 
2293  /* try to add new solution to scip */
2294  SCIP_CALL( SCIPtrySol(scip, *sol, FALSE, TRUE, TRUE, TRUE, &success) );
2295  }
2296 
2297  if( success )
2298  {
2299  assert(i >= 1);
2300  SCIPdebugMessage("heuristic found %d solutions in subproblem; solution %d feasible in original problem\n", nsubsols, i);
2301  }
2302  else
2303  {
2304  /* free solution structure, since we found no feasible solution */
2305  SCIP_CALL( SCIPfreeSol(scip, sol) );
2306  *sol = NULL;
2307  }
2308 
2309  /* if the best subproblem solution was not accepted in the original problem, we do not trust the solving status */
2310  *validsolved = *validsolved && i == 1;
2311  }
2312 
2313  /* free variable mapping hash map, array of subproblem variables, and subproblem */
2314  SCIPhashmapFree(&varmap);
2315  SCIPfreeBufferArray(scip, &subvars);
2316  SCIP_CALL( SCIPfree(&subscip) );
2317 
2318  return SCIP_OKAY;
2319 }
2320 
2321 
2322 /** perform fixing of a variable and record bound disjunction information */
2323 static
2325  SCIP* scip, /**< SCIP data structure */
2326  SCIP_VAR* var, /**< variable to fix */
2327  SCIP_Real val, /**< fixing value */
2328  SCIP_Bool* infeas, /**< pointer to store whether the fixing lead to infeasibility */
2329  int* bdlen, /**< current length of bound disjunction */
2330  SCIP_VAR** bdvars, /**< array of variables in bound disjunction */
2331  SCIP_BOUNDTYPE* bdtypes, /**< array of bound types in bound disjunction */
2332  SCIP_Real* bdbounds, /**< array of bounds in bound disjunction */
2333  SCIP_Real* oldbounds /**< array of bounds before fixing */
2334  )
2335 {
2336  SCIP_Longint ndomredsfound;
2337  SCIP_Real oldlb;
2338  SCIP_Real oldub;
2339  int oldbdlen;
2340 
2341  assert(scip != NULL);
2342  assert(var != NULL);
2343  assert(val >= SCIPvarGetLbLocal(var));
2344  assert(val <= SCIPvarGetUbLocal(var));
2345  assert(infeas != NULL);
2346  assert(bdlen != NULL);
2347  assert(*bdlen >= 0);
2348  assert(*bdlen < 2*SCIPgetNVars(scip)-1);
2349  assert(bdvars != NULL);
2350  assert(bdtypes != NULL);
2351  assert(bdbounds != NULL);
2352 
2353  assert(!SCIPvarIsIntegral(var) || SCIPisFeasIntegral(scip, val));
2354 
2355  /* remember length of probing path */
2356  oldbdlen = *bdlen;
2357 
2358  /* get bounds of the variable to fix */
2359  oldlb = SCIPvarGetLbLocal(var);
2360  oldub = SCIPvarGetUbLocal(var);
2361 
2362  /* decrease upper bound to fixing value */
2363  *infeas = FALSE;
2364  if( SCIPisUbBetter(scip, val, oldlb, oldub) )
2365  {
2366  /* create next probing node */
2367  SCIP_CALL( SCIPnewProbingNode(scip) );
2368  SCIP_CALL( SCIPchgVarUbProbing(scip, var, val) );
2369 
2370  SCIPdebugMessage("tentatively decreasing upper bound of variable <%s> to %g for probing\n",
2371  SCIPvarGetName(var), val);
2372 
2373  /* store bound disjunction information */
2374  bdvars[*bdlen] = var;
2375  bdtypes[*bdlen] = SCIP_BOUNDTYPE_LOWER;
2376  bdbounds[*bdlen] = SCIPvarIsIntegral(var) ? SCIPfeasCeil(scip, val)+1.0 : val;
2377  oldbounds[*bdlen] = oldub;
2378  (*bdlen)++;
2379 
2380  /* propagate the bound change; conflict analysis is performed automatically */
2381  SCIP_CALL( SCIPpropagateProbing(scip, 0, infeas, &ndomredsfound) );
2382  SCIPdebugMessage(" --> propagation reduced %lld further domains\n", ndomredsfound);
2383 
2384  /* if propagation led to a cutoff, we backtrack immediately */
2385  if( *infeas )
2386  {
2387  *bdlen = oldbdlen;
2388  return SCIP_OKAY;
2389  }
2390 
2391  /* store bound before propagation */
2392  oldbounds[*bdlen] = oldlb;
2393 
2394  /* move fixing value into the new domain, since it may be outside due to numerical issues or previous propagation */
2395  oldlb = SCIPvarGetLbLocal(var);
2396  oldub = SCIPvarGetUbLocal(var);
2397  val = MIN(val, oldub);
2398  val = MAX(val, oldlb);
2399 
2400  assert(!SCIPvarIsIntegral(var) || SCIPisFeasIntegral(scip, val));
2401  }
2402 
2403  /* update lower bound to fixing value */
2404  *infeas = FALSE;
2405  if( SCIPisLbBetter(scip, val, oldlb, oldub) )
2406  {
2407  /* create next probing node */
2408  SCIP_CALL( SCIPnewProbingNode(scip) );
2409  SCIP_CALL( SCIPchgVarLbProbing(scip, var, val) );
2410 
2411  SCIPdebugMessage("tentatively increasing lower bound of variable <%s> to %g for probing\n",
2412  SCIPvarGetName(var), val);
2413 
2414  /* store bound disjunction information */
2415  bdvars[*bdlen] = var;
2416  bdtypes[*bdlen] = SCIP_BOUNDTYPE_UPPER;
2417  bdbounds[*bdlen] = SCIPvarIsIntegral(var) ? SCIPfeasCeil(scip, val)-1.0 : val;
2418  (*bdlen)++;
2419 
2420  /* propagate the bound change */
2421  SCIP_CALL( SCIPpropagateProbing(scip, 0, infeas, &ndomredsfound) );
2422  SCIPdebugMessage(" --> propagation reduced %lld further domains\n", ndomredsfound);
2423 
2424  /* if propagation led to a cutoff, we backtrack immediately */
2425  if( *infeas )
2426  {
2427  *bdlen = oldbdlen;
2428  return SCIP_OKAY;
2429  }
2430  }
2431 
2432  return SCIP_OKAY;
2433 }
2434 
2435 static
2437  SCIP* scip, /**< original SCIP data structure */
2438  SCIP_HEURDATA* heurdata, /**< heuristic data structure */
2439  int* cover, /**< array with indices of the variables in the computed cover */
2440  int coversize, /**< size of the cover */
2441  SCIP_Real* fixingvals, /**< fixing values for the variables in the cover */
2442  int* bdlen, /**< current length of bound disjunction along the probing path */
2443  SCIP_VAR** bdvars, /**< array of variables in bound disjunction */
2444  SCIP_BOUNDTYPE* bdtypes, /**< array of bound types in bound disjunction */
2445  SCIP_Real* bdbounds, /**< array of bounds in bound disjunction */
2446  SCIP_Real* oldbounds, /**< array of bounds before fixing */
2447  int* nfixedints, /**< pointer to store number of fixed integer variables */
2448  int* nfixedconts, /**< pointer to store number of fixed continuous variables */
2449  int* lastfailed, /**< position in cover array of the variable the fixing of which yielded
2450  * infeasibility */
2451  SCIP_Bool* infeas /**< pointer to store whether fix-and-propagate led to an infeasibility */
2452  )
2453 {
2454  SCIP_VAR** vars; /* original problem's variables */
2455 
2456  int i;
2457  SCIP_Bool lpsolved;
2458 
2459  /* start probing in original problem */
2460  lpsolved = SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_OPTIMAL;
2461  SCIP_CALL( SCIPstartProbing(scip) );
2462 
2463  /* initialize data */
2464  *nfixedints = 0;
2465  *nfixedconts = 0;
2466  *bdlen = 0;
2467  vars = SCIPgetVars(scip);
2468 
2469  /* round-fix-propagate-analyze-backtrack for each variable in the cover */
2470  for( i = 0; i < coversize && !(*infeas); i++ )
2471  {
2472  SCIP_Real* boundalts;
2473  SCIP_Real* usedvals;
2474  SCIP_Real val;
2475  int nbacktracks;
2476  int nboundalts;
2477  int nfailedvals;
2478  int nusedvals;
2479  int probingdepth;
2480  int idx;
2481 
2482  /* get probindex of next variable in the cover */
2483  idx = cover[i];
2484 
2485  /* nothing to do if the variable was already fixed, e.g., by propagation */
2486  if( SCIPisEQ(scip, SCIPvarGetLbLocal(vars[idx]), SCIPvarGetUbLocal(vars[idx])) )
2487  {
2488  fixingvals[i] = SCIPvarGetLbLocal(vars[idx]);
2489  continue;
2490  }
2491 
2492  /* we will store the fixing values already used to avoid try the same value twice */
2493  SCIP_CALL( SCIPallocBufferArray(scip, &usedvals, heurdata->maxbacktracks+1) );
2494  nusedvals = 0;
2495 
2496  /* backtracking loop */
2497  *infeas = TRUE;
2498  nfailedvals = 0;
2499  nboundalts = 0;
2500  boundalts = NULL;
2501  val = 0.0;
2502  for( nbacktracks = 0; nbacktracks <= heurdata->maxbacktracks+nfailedvals && *infeas; nbacktracks++ )
2503  {
2504  SCIP_Real oldlb;
2505  SCIP_Real oldub;
2506  SCIP_Bool usedbefore;
2507  int j;
2508 
2509  probingdepth = SCIPgetProbingDepth(scip);
2510 
2511  /* get fixing value */
2512  if( nbacktracks < heurdata->nfixingalts )
2513  {
2514  SCIP_Bool success;
2515 
2516  /* if the lp relaxation is not solved, we do not even try to retrieve the lp solution value;
2517  * if the NLP relaxation is not constructed, we do not even try to retrieve the NLP solution value;
2518  * if there is no feasible solution yet, we do not even try to obtain the value in the incumbent */
2519  success = FALSE;
2520  if( (heurdata->fixingalts[nbacktracks] != 'l' || lpsolved)
2521  && (heurdata->fixingalts[nbacktracks] != 'n' || !heurdata->nlpfailed)
2522  && (heurdata->fixingalts[nbacktracks] != 'i' || SCIPgetBestSol(scip) != NULL) )
2523  {
2524  SCIP_CALL( getFixingValue(scip, heurdata, vars[idx], &val, heurdata->fixingalts[nbacktracks], &success, *bdlen, bdvars, bdtypes, oldbounds) );
2525  }
2526 
2527  if( !success )
2528  {
2529  SCIPdebugMessage("retrieving fixing value '%c' for variable <%s> failed, trying next in the list\n",
2530  heurdata->fixingalts[nbacktracks], SCIPvarGetName(vars[idx]));
2531  nfailedvals++;
2532  continue;
2533  }
2534 
2535  /* for the first (successfully retrieved) fixing value, compute (at most 4) bound dependent
2536  * alternative fixing values */
2537  if( boundalts == NULL )
2538  {
2539  SCIP_CALL( SCIPallocBufferArray(scip, &boundalts, 4) );
2540  nboundalts = 0;
2541  calculateAlternatives(scip, vars[idx], val, &nboundalts, boundalts);
2542  assert(nboundalts >= 0);
2543  assert(nboundalts <= 4);
2544  }
2545  }
2546  /* get alternative fixing value */
2547  else if( boundalts != NULL && nbacktracks < heurdata->nfixingalts+nboundalts )
2548  {
2549  assert(nbacktracks-heurdata->nfixingalts >= 0);
2550  val = boundalts[nbacktracks-heurdata->nfixingalts];
2551  }
2552  else
2553  break;
2554 
2555  /* round fixing value */
2556  if( SCIPvarIsIntegral(vars[idx]) && !SCIPisIntegral(scip, val) )
2557  {
2558  SCIP_CALL( roundFixingValue(scip, &val, vars[idx], heurdata->locksrounding) );
2559  assert(SCIPisIntegral(scip, val));
2560  }
2561 
2562  /* move value into the domain, since it may be outside due to numerical issues or previous propagation */
2563  oldlb = SCIPvarGetLbLocal(vars[idx]);
2564  oldub = SCIPvarGetUbLocal(vars[idx]);
2565  val = MIN(val, oldub);
2566  val = MAX(val, oldlb);
2567 
2568  assert(!SCIPvarIsIntegral(vars[idx]) || SCIPisFeasIntegral(scip, val));
2569 
2570  /* check if this fixing value was already used */
2571  usedbefore = FALSE;
2572  for( j = nusedvals-1; j >= 0 && !usedbefore; j-- )
2573  usedbefore = SCIPisFeasEQ(scip, val, usedvals[j]);
2574 
2575  if( usedbefore )
2576  {
2577  nfailedvals++;
2578  continue;
2579  }
2580 
2581  /* store fixing value */
2582  assert(nusedvals < heurdata->maxbacktracks);
2583  usedvals[nusedvals] = val;
2584  nusedvals++;
2585 
2586  /* fix-propagate-analyze */
2587  SCIP_CALL( performFixing(scip, vars[idx], val, infeas, bdlen, bdvars, bdtypes, bdbounds, oldbounds) );
2588 
2589  /* if infeasible, backtrack and try alternative fixing value */
2590  if( *infeas )
2591  {
2592  SCIPdebugMessage(" --> cutoff detected - backtracking\n");
2593  SCIP_CALL( SCIPbacktrackProbing(scip, probingdepth) );
2594  }
2595  }
2596 
2597  /* free array of alternative backtracking values */
2598  if( boundalts != NULL)
2599  SCIPfreeBufferArray(scip, &boundalts);
2600  SCIPfreeBufferArray(scip, &usedvals);
2601 
2602  /* backtracking loop unsuccessful */
2603  if( *infeas )
2604  {
2605  SCIPdebugMessage("no feasible fixing value found for variable <%s> in fixing order\n",
2606  SCIPvarGetName(vars[idx]));
2607  break;
2608  }
2609  /* fixing successful */
2610  else
2611  {
2612  /* store successful fixing value */
2613  fixingvals[i] = val;
2614 
2615  /* statistics */
2616  if( SCIPvarGetType(vars[idx]) == SCIP_VARTYPE_CONTINUOUS )
2617  (*nfixedconts)++;
2618  else
2619  (*nfixedints)++;
2620  }
2621  }
2622  assert(*infeas || i == coversize);
2623  assert(!(*infeas) || i < coversize);
2624 
2625  /* end of dive */
2626  SCIP_CALL( SCIPendProbing(scip) );
2627 
2628  *lastfailed = i;
2629 
2630  return SCIP_OKAY;
2631 }
2632 
2633 /** main procedure of the undercover heuristic */
2634 static
2636  SCIP* scip, /**< original SCIP data structure */
2637  SCIP_HEUR* heur, /**< heuristic data structure */
2638  SCIP_RESULT* result, /**< result data structure */
2639  SCIP_Real timelimit, /**< time limit */
2640  SCIP_Real memorylimit, /**< memory limit */
2641  SCIP_Longint nstallnodes /**< number of stalling nodes for the subproblem */
2642  )
2643 {
2644  SCIP_HEURDATA* heurdata; /* heuristic data */
2645  SCIP_VAR** vars; /* original problem's variables */
2646  SCIP_CLOCK* clock; /* clock for updating time limit */
2647 
2648  SCIP* coveringscip; /* SCIP data structure for covering problem */
2649  SCIP_VAR** coveringvars; /* covering variables */
2650  SCIP_Real* fixingvals; /* array for storing fixing values used */
2651  int* cover; /* array to store problem indices of variables in the computed cover */
2652 
2653  SCIP_VAR** bdvars; /* array of variables in bound disjunction along the probing path */
2654  SCIP_BOUNDTYPE* bdtypes; /* array of bound types in bound disjunction along the probing path */
2655  SCIP_Real* bdbounds; /* array of bounds in bound disjunction along the probing path */
2656  SCIP_Real* oldbounds; /* array of bounds before fixing along the probing path */
2657 
2658  SCIP_Real maxcoversize;
2659 
2660  int coversize;
2661  int nvars;
2662  int ncovers;
2663  int nunfixeds;
2664  int nnlconss;
2665  int i;
2666 
2667  SCIP_Bool success;
2668  SCIP_Bool reusecover;
2669 
2670  assert(scip != NULL);
2671  assert(heur != NULL);
2672  assert(result != NULL);
2673  assert(*result == SCIP_DIDNOTFIND);
2674 
2675  /* create and start timing */
2676  SCIP_CALL( SCIPcreateClock(scip, &clock) );
2677  SCIP_CALL( SCIPstartClock(scip, clock) );
2678 
2679  /* initialize */
2680  fixingvals = NULL;
2681  cover = NULL;
2682  bdvars = NULL;
2683  bdtypes = NULL;
2684  bdbounds = NULL;
2685  oldbounds = NULL;
2686  coversize = 0;
2687 
2688  /* get heuristic data */
2689  heurdata = SCIPheurGetData(heur);
2690  assert(heurdata != NULL);
2691 
2692  /* NLP relaxation has not been solved yet (only solve once, not again for each cover or dive, because it is expensive) */
2693  heurdata->nlpsolved = FALSE;
2694 
2695  /* if solving the NLP relaxation has failed too often in previous runs, or NLP and NLP solver is not available, we do
2696  * not even try
2697  */
2698  heurdata->nlpfailed = heurdata->nnlpfails >= MAXNLPFAILS || !SCIPisNLPConstructed(scip) || SCIPgetNNlpis(scip) == 0;
2699 
2700  /* get variable data of original problem */
2701  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
2702 
2703  /* get number of nonlinear constraints */
2704  nnlconss = 0;
2705  for( i = 0; i < heurdata->nnlconshdlrs; ++i )
2706  nnlconss += SCIPconshdlrGetNActiveConss(heurdata->nlconshdlrs[i]);
2707  assert(nnlconss >= 0);
2708  assert(nnlconss <= SCIPgetNConss(scip));
2709 
2710  /* run only if problem is sufficiently nonlinear */
2711  if( nnlconss < (SCIP_Real) SCIPgetNConss(scip) * heurdata->mincoveredrel || nnlconss < heurdata->mincoveredabs )
2712  {
2713  SCIPdebugMessage("too few nonlinear constraints present, not running\n");
2714 
2715  /* free clock */
2716  SCIP_CALL( SCIPfreeClock(scip, &clock) );
2717 
2718  return SCIP_OKAY;
2719  }
2720 
2721  /* calculate upper bound for cover size */
2722  maxcoversize = nvars*heurdata->maxcoversizevars;
2723  if( heurdata->maxcoversizeconss < SCIP_REAL_MAX )
2724  {
2725  SCIP_Real maxcoversizeconss;
2726  maxcoversizeconss = heurdata->maxcoversizeconss * nnlconss / ((SCIP_Real) SCIPgetNConss(scip));
2727  maxcoversize = MIN(maxcoversize, maxcoversizeconss);
2728  }
2729 
2730  /* create covering problem */
2731  success = FALSE;
2732  SCIP_CALL( SCIPcreate(&coveringscip) );
2733  SCIP_CALL( SCIPincludeDefaultPlugins(coveringscip) );
2734  SCIP_CALL( SCIPallocBufferArray(scip, &coveringvars, nvars) );
2735  SCIP_CALL( createCoveringProblem(scip, coveringscip, coveringvars, heurdata->globalbounds, heurdata->onlyconvexify,
2736  heurdata->coverbd, heurdata->coveringobj, &success) );
2737 
2738  if( !success )
2739  {
2740  SCIPdebugMessage("creating covering problem failed, terminating\n");
2741  goto TERMINATE;
2742  }
2743  else
2744  {
2745  SCIPdebugMessage("covering problem created successfully\n");
2746  }
2747 
2748  /* count number of unfixed covering variables */
2749  nunfixeds = 0;
2750  for( i = nvars-1; i >= 0; i-- )
2751  {
2752  if( SCIPisFeasEQ(coveringscip, SCIPvarGetLbGlobal(coveringvars[i]), 1.0) )
2753  nunfixeds++;
2754  }
2755 
2756  /* update time limit */
2757  SCIP_CALL( updateTimelimit(scip, clock, &timelimit) );
2758 
2759  if( timelimit <= MINTIMELEFT )
2760  {
2761  SCIPdebugMessage("time limit hit, terminating\n");
2762  goto TERMINATE;
2763  }
2764 
2765  /* update memory left */
2766  memorylimit -= SCIPgetMemUsed(coveringscip)/1048576.0;
2767  memorylimit -= SCIPgetMemExternEstim(coveringscip)/1048576.0;
2768 
2769  /* allocate memory for storing bound disjunction information along probing path */
2770  SCIP_CALL( SCIPallocBufferArray(scip, &bdvars, 2*nvars) );
2771  SCIP_CALL( SCIPallocBufferArray(scip, &bdtypes, 2*nvars) );
2772  SCIP_CALL( SCIPallocBufferArray(scip, &bdbounds, 2*nvars) );
2773  SCIP_CALL( SCIPallocBufferArray(scip, &oldbounds, 2*nvars) );
2774 
2775  /* initialize data for recovering loop */
2776  SCIP_CALL( SCIPallocBufferArray(scip, &cover, nvars) );
2777  SCIP_CALL( SCIPallocBufferArray(scip, &fixingvals, nvars) );
2778  ncovers = 0;
2779  success = FALSE;
2780  reusecover = FALSE;
2781 
2782  heurdata->nfixingalts = (int) strlen(heurdata->fixingalts);
2783  assert(heurdata->nfixingalts >= 1);
2784 
2785  /* recovering loop */
2786  while( (ncovers <= heurdata->maxrecovers || reusecover) && !success )
2787  {
2788  int lastfailed;
2789  int ndives;
2790  int nfixedints;
2791  int nfixedconts;
2792  int bdlen; /* current length of bound disjunction along the probing path */
2793 
2794  SCIP_Bool conflictcreated;
2795 
2796  SCIPdebugMessage("solving covering problem\n\n");
2797  success = FALSE;
2798  bdlen = 0;
2799  conflictcreated = FALSE;
2800 
2801  /* solve covering problem */
2802  if( !reusecover )
2803  {
2804  SCIP_CALL( solveCoveringProblem(coveringscip, nvars, coveringvars, &coversize, cover,
2805  timelimit, memorylimit + (SCIPgetMemExternEstim(coveringscip)+SCIPgetMemUsed(coveringscip))/1048576.0, maxcoversize, &success) );
2806 
2807  SCIPstatistic(
2808  if( ncovers == 0 && success )
2809  SCIPstatisticPrintf("UCstats coversize abs: %6d rel: %9.6f\n", coversize, 100.0*coversize /(SCIP_Real)nvars);
2810  );
2811 
2812  assert(coversize >= 0);
2813  assert(coversize <= nvars);
2814  ncovers++;
2815 
2816  /* free transformed covering problem immediately */
2817  SCIP_CALL( SCIPfreeTransform(coveringscip) );
2818 
2819  /* terminate if no feasible cover was found */
2820  if( !success )
2821  {
2822  SCIPdebugMessage("no feasible cover found in covering problem %d, terminating\n", ncovers);
2823  goto TERMINATE;
2824  }
2825 
2826  /* terminate, if cover is empty or too large */
2827  if( coversize == 0 || coversize > maxcoversize )
2828  {
2829  SCIPdebugMessage("terminating due to coversize=%d\n", coversize);
2830  goto TERMINATE;
2831  }
2832 
2833  /* terminate, if cover too large for the ratio of nonlinear constraints */
2834  if( heurdata->maxcoversizeconss < SCIP_REAL_MAX && coversize > heurdata->maxcoversizeconss * nnlconss / (SCIP_Real) SCIPgetNConss(scip) )
2835  {
2836  SCIPdebugMessage("terminating due to coversize=%d\n", coversize);
2837  goto TERMINATE;
2838  }
2839  }
2840 
2841  /* data setup */
2842  ndives = 0;
2843  nfixedints = 0;
2844  nfixedconts = 0;
2845  success = FALSE;
2846  lastfailed = reusecover ? MAX(1, coversize-1) : coversize;
2847 
2848  /* round-fix-propagate-analyze-backtrack-reorder loop */
2849  while( ndives <= heurdata->maxreorders && !success )
2850  {
2851  SCIP_Bool reordered;
2852  SCIP_Bool infeas;
2853 
2854  /* compute fixing order */
2855  SCIP_CALL( computeFixingOrder(scip, heurdata, nvars, vars, coversize, cover, lastfailed, &reordered) );
2856  reordered = reordered || ndives == 0;
2857  SCIPdebugMessage("%sordering variables in cover %s\n", ndives == 0 ? "" : "re", reordered ? "" : "failed");
2858 
2859  /* stop if order has not changed */
2860  if( !reordered )
2861  break;
2862 
2863  infeas = FALSE;
2864  SCIP_CALL( fixAndPropagate(scip, heurdata, cover, coversize, fixingvals, &bdlen, bdvars, bdtypes, bdbounds, oldbounds,
2865  &nfixedints, &nfixedconts, &lastfailed, &infeas) );
2866  ndives++;
2867  success = !infeas;
2868  }
2869 
2870  /* update time limit */
2871  SCIPdebugMessage("%d dive%s of fix-and-propagate for cover %d took %.1f seconds\n", ndives, ndives > 1 ? "s" : "", ncovers, SCIPgetClockTime(scip, clock));
2872  SCIP_CALL( updateTimelimit(scip, clock, &timelimit) );
2873 
2874  if( timelimit <= MINTIMELEFT )
2875  {
2876  SCIPdebugMessage("time limit hit, terminating\n");
2877  goto TERMINATE;
2878  }
2879 
2880  /* no feasible fixing could be found for the current cover */
2881  if( !success )
2882  {
2883  SCIPdebugMessage("no feasible fixing values found for cover %d\n", ncovers);
2884  }
2885  else
2886  {
2887  SCIP_SOL* sol;
2888  SCIP_Longint nsubnodes;
2889  SCIP_Bool validsolved;
2890 
2891  SCIPdebugMessage("heuristic successfully fixed %d variables (%d integral, %d continuous) during probing\n",
2892  nfixedints+nfixedconts, nfixedints, nfixedconts); /*lint !e771*/
2893 
2894  /* solve sub-CIP and pass feasible solutions to original problem */
2895  success = FALSE;
2896  validsolved = FALSE;
2897  sol = NULL;
2898  nsubnodes = 0;
2899 
2900  SCIP_CALL( solveSubproblem(scip, heur, coversize, cover, fixingvals,
2901  timelimit, memorylimit, heurdata->maxnodes, nstallnodes, &validsolved, &sol, &nsubnodes) );
2902 
2903  /* update number of sub-CIP nodes used by heuristic so far */
2904  heurdata->nusednodes += nsubnodes;
2905 
2906  /* if the subproblem was constructed from a valid copy and solved, try to forbid the assignment of fixing
2907  * values to variables in the cover
2908  */
2909  if( validsolved )
2910  {
2911  SCIP_Real maxvarsfac;
2912  SCIP_Bool useconf;
2913  int minmaxvars;
2914 
2915  SCIP_CALL( SCIPgetIntParam(scip, "conflict/minmaxvars", &minmaxvars) );
2916  SCIP_CALL( SCIPgetRealParam(scip, "conflict/maxvarsfac", &maxvarsfac) );
2917 
2918  useconf = bdlen > 0 && (bdlen <= minmaxvars || bdlen < maxvarsfac*nvars);
2919 
2920  if( useconf )
2921  {
2922  /* even if we had reset the global bounds at start of probing, the constraint might be only locally valid due to local constraints/cuts */
2923  SCIP_CALL( createConflict(scip, bdlen, bdvars, bdtypes, bdbounds, SCIPgetDepth(scip) > 0, TRUE, TRUE, &success) );
2924  conflictcreated = success;
2925  }
2926 
2927  SCIPdebugMessage("subproblem solved (%s), forbidding assignment in original problem %s, %sconflict length=%d\n",
2928  sol == NULL ? "infeasible" : "optimal",
2929  success ? "successful" : "failed", useconf ? "" : "skipped due to ", bdlen);
2930  }
2931 
2932  /* heuristic succeeded */
2933  success = (sol != NULL);
2934  if( success )
2935  {
2936  *result = SCIP_FOUNDSOL;
2937  success = TRUE;
2938 
2939  /* update time limit */
2940  SCIP_CALL( updateTimelimit(scip, clock, &timelimit) );
2941 
2942  /* call NLP local search heuristic unless it has failed too often */
2943  if( heurdata->postnlp && heurdata->npostnlpfails < MAXPOSTNLPFAILS )
2944  {
2945  if( nfixedconts == 0 && validsolved )
2946  {
2947  SCIPdebugMessage("subproblem solved to optimality while all covering variables are integral, hence skipping NLP local search\n");
2948  }
2949  else if( timelimit <= MINTIMELEFT )
2950  {
2951  SCIPdebugMessage("time limit hit, skipping NLP local search\n");
2952  }
2953  else if( heurdata->nlpheur == NULL )
2954  {
2955  SCIPdebugMessage("NLP heuristic not found, skipping NLP local search\n");
2956  }
2957  else
2958  {
2959  SCIP_RESULT nlpresult;
2960 
2961  SCIP_CALL( SCIPapplyHeurSubNlp(scip, heurdata->nlpheur, &nlpresult, sol, -1LL, timelimit, heurdata->minimprove, NULL) );
2962  SCIPdebugMessage("NLP local search %s\n", nlpresult == SCIP_FOUNDSOL ? "successful" : "failed");
2963 
2964  if( nlpresult == SCIP_FOUNDSOL )
2965  heurdata->npostnlpfails = 0;
2966  else
2967  heurdata->npostnlpfails++;
2968  }
2969  }
2970 
2971  /* free solution */
2972  SCIP_CALL( SCIPfreeSol(scip, &sol) );
2973  }
2974  }
2975 
2976  /* heuristic failed but we have another recovering try, hence we forbid the current cover in the covering problem */
2977  if( !success && ncovers <= heurdata->maxrecovers )
2978  {
2979  SCIP_Bool infeas;
2980  int diversification;
2981 
2982  /* compute minimal number of unfixed covering variables (in the cover) which have to change their value */
2983  diversification = (int) SCIPfeasCeil(scip, (heurdata->recoverdiv) * (SCIP_Real) nunfixeds);
2984  diversification = MAX(diversification, 1);
2985 
2986  /* forbid unsuccessful cover globally in covering problem */
2987  SCIP_CALL( forbidCover(coveringscip, nvars, coveringvars, coversize, cover, diversification, &success, &infeas) );
2988 
2989  if( infeas )
2990  {
2991  SCIPdebugMessage("recovering problem infeasible (diversification=%d), terminating\n", diversification);
2992  goto TERMINATE;
2993  }
2994  else if( !success )
2995  {
2996  SCIPdebugMessage("failed to forbid current cover in the covering problem, terminating\n");
2997  goto TERMINATE;
2998  }
2999  else
3000  {
3001  SCIPdebugMessage("added constraint to the covering problem in order to forbid current cover\n");
3002  success = FALSE;
3003  }
3004  }
3005 
3006  /* try to re-use the same cover at most once */
3007  if( heurdata->reusecover && !reusecover && conflictcreated )
3008  reusecover = TRUE;
3009  else
3010  reusecover = FALSE;
3011  }
3012 
3013  TERMINATE:
3014  if( *result != SCIP_FOUNDSOL && *result != SCIP_DELAYED )
3015  {
3016  SCIPdebugMessage("heuristic terminating unsuccessfully\n");
3017  }
3018 
3019  /* we must remain in NLP diving mode until here to be able to retrieve NLP solution values easily */
3020  /* assert((SCIPisNLPConstructed(scip) == FALSE && heurdata->nlpsolved == FALSE) ||
3021  * (SCIPisNLPConstructed(scip) == TRUE && heurdata->nlpsolved == SCIPnlpIsDiving(SCIPgetNLP(scip))));
3022  */
3023  if( heurdata->nlpsolved )
3024  {
3025  SCIP_CALL( SCIPendDiveNLP(scip) );
3026  }
3027 
3028  /* free arrays for storing the cover */
3029  SCIPfreeBufferArrayNull(scip, &fixingvals);
3030  SCIPfreeBufferArrayNull(scip, &cover);
3031 
3032  /* free arrays for storing bound disjunction information along probing path */
3033  SCIPfreeBufferArrayNull(scip, &oldbounds);
3034  SCIPfreeBufferArrayNull(scip, &bdbounds);
3035  SCIPfreeBufferArrayNull(scip, &bdtypes);
3036  SCIPfreeBufferArrayNull(scip, &bdvars);
3037 
3038  /* free covering problem */
3039  for( i = nvars-1; i >= 0; i-- )
3040  {
3041  SCIP_CALL( SCIPreleaseVar(coveringscip, &coveringvars[i]) );
3042  }
3043  SCIPfreeBufferArray(scip, &coveringvars);
3044  SCIP_CALL( SCIPfree(&coveringscip) );
3045 
3046  /* free clock */
3047  SCIP_CALL( SCIPfreeClock(scip, &clock) );
3048 
3049  return SCIP_OKAY;
3050 }
3051 
3052 
3053 /*
3054  * Callback methods of primal heuristic
3055  */
3056 
3057 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
3058 static
3059 SCIP_DECL_HEURCOPY(heurCopyUndercover)
3060 { /*lint --e{715}*/
3061  assert(scip != NULL);
3062  assert(heur != NULL);
3063  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
3064 
3065  /* call inclusion method of primal heuristic */
3067 
3068  return SCIP_OKAY;
3069 }
3070 
3071 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
3072 static
3073 SCIP_DECL_HEURFREE(heurFreeUndercover)
3074 { /*lint --e{715}*/
3075  SCIP_HEURDATA* heurdata;
3076 
3077  assert(scip != NULL);
3078  assert(heur != NULL);
3079 
3080  /* get heuristic data */
3081  heurdata = SCIPheurGetData(heur);
3082  assert(heurdata != NULL);
3083 
3084  /* free heuristic data */
3085  SCIPfreeMemory(scip, &heurdata);
3086  SCIPheurSetData(heur, NULL);
3087 
3088  return SCIP_OKAY;
3089 }
3090 
3091 
3092 /** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
3093 static
3094 SCIP_DECL_HEURINITSOL(heurInitsolUndercover)
3095 { /*lint --e{715}*/
3096  SCIP_HEURDATA* heurdata;
3097  int h;
3098 
3099  assert(heur != NULL);
3100  assert(scip != NULL);
3101 
3102  /* get heuristic's data */
3103  heurdata = SCIPheurGetData(heur);
3104  assert(heurdata != NULL);
3105 
3106  /* initialize counters to zero */
3107  heurdata->nusednodes = 0;
3108  heurdata->npostnlpfails = 0;
3109  heurdata->nnlpfails = 0;
3110 
3111  /* if the heuristic is called at the root node, we may want to be called directly after the initial root LP solve */
3112  if( heurdata->beforecuts && SCIPheurGetFreqofs(heur) == 0 )
3114 
3115  /* find nonlinear constraint handlers */
3116  SCIP_CALL( SCIPallocMemoryArray(scip, &heurdata->nlconshdlrs, 7) );/*lint !e506*/
3117  h = 0;
3118 
3119  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "and");
3120  if( heurdata->nlconshdlrs[h] != NULL )
3121  h++;
3122 
3123  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "quadratic");
3124  if( heurdata->nlconshdlrs[h] != NULL )
3125  h++;
3126 
3127  if( heurdata->coverbd )
3128  {
3129  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "bounddisjunction");
3130  if( heurdata->nlconshdlrs[h] != NULL )
3131  h++;
3132  }
3133 
3134  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "indicator");
3135  if( heurdata->nlconshdlrs[h] != NULL )
3136  h++;
3137 
3138  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "soc");
3139  if( heurdata->nlconshdlrs[h] != NULL )
3140  h++;
3141 
3142  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "nonlinear");
3143  if( heurdata->nlconshdlrs[h] != NULL )
3144  h++;
3145 
3146  heurdata->nlconshdlrs[h] = SCIPfindConshdlr(scip, "abspower");
3147  if( heurdata->nlconshdlrs[h] != NULL )
3148  h++;
3149 
3150  heurdata->nnlconshdlrs = h;
3151 
3152  /* find NLP local search heuristic */
3153  heurdata->nlpheur = SCIPfindHeur(scip, "subnlp");
3154 
3155  /* add global linear constraints to NLP relaxation */
3156  if( SCIPisNLPConstructed(scip) && heurdata->nlpheur != NULL )
3157  {
3158  SCIP_CALL( SCIPaddLinearConsToNlpHeurSubNlp(scip, heurdata->nlpheur, TRUE, TRUE) );
3159  }
3160 
3161  return SCIP_OKAY;
3162 }
3163 
3164 /** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
3165 static
3166 SCIP_DECL_HEUREXITSOL(heurExitsolUndercover)
3167 {
3168  SCIP_HEURDATA* heurdata;
3169 
3170  assert(heur != NULL);
3171  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
3172 
3173  /* get heuristic's data */
3174  heurdata = SCIPheurGetData(heur);
3175  assert(heurdata != NULL);
3176 
3177  /* free array of nonlinear constraint handlers */
3178  SCIPfreeMemoryArray(scip, &heurdata->nlconshdlrs);
3179 
3180  /* reset timing, if it was changed temporary (at the root node) */
3182 
3183  return SCIP_OKAY;
3184 }
3185 
3186 /** execution method of primal heuristic */
3187 static
3188 SCIP_DECL_HEUREXEC(heurExecUndercover)
3189 { /*lint --e{715}*/
3190  SCIP_HEURDATA* heurdata; /* heuristic data */
3191  SCIP_Real timelimit; /* time limit for the subproblem */
3192  SCIP_Real memorylimit; /* memory limit for the subproblem */
3193  SCIP_Longint nstallnodes; /* number of stalling nodes for the subproblem */
3194  SCIP_Bool run;
3195 
3196  int h;
3197 
3198  assert(heur != NULL);
3199  assert(scip != NULL);
3200  assert(result != NULL);
3201 
3202  *result = SCIP_DIDNOTRUN;
3203 
3204  /* do not call heuristic of node was already detected to be infeasible */
3205  if( nodeinfeasible )
3206  return SCIP_OKAY;
3207 
3208  /* get heuristic's data */
3209  heurdata = SCIPheurGetData(heur);
3210  assert(heurdata != NULL);
3211 
3212  /* only call heuristic once at the root */
3213  if( SCIPgetDepth(scip) == 0 && SCIPheurGetNCalls(heur) > 0 )
3214  return SCIP_OKAY;
3215 
3216  /* if we want to use NLP fixing values exclusively and no NLP solver is available, we cannot run */
3217  if( strcmp(heurdata->fixingalts, "n") == 0 && SCIPgetNNlpis(scip) == 0 )
3218  {
3219  SCIPdebugMessage("skipping undercover heuristic: want to use NLP fixing values exclusively, but no NLP solver available\n");
3220  return SCIP_OKAY;
3221  }
3222 
3223  /* calculate stallnode limit */
3224  nstallnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
3225 
3226  /* reward heuristic if it succeeded often */
3227  nstallnodes = (SCIP_Longint)(nstallnodes * 3.0 * (SCIPheurGetNBestSolsFound(heur) + 1.0)/(SCIPheurGetNCalls(heur) + 1.0));
3228  nstallnodes -= SUBMIPSETUPCOSTS * SCIPheurGetNCalls(heur); /* account for the setup costs of the sub-CIP */
3229  nstallnodes += heurdata->nodesofs;
3230 
3231  /* determine the node limit for the current process */
3232  nstallnodes -= heurdata->nusednodes;
3233  nstallnodes = MIN(nstallnodes, heurdata->maxnodes);
3234  nstallnodes = MAX(nstallnodes, 1);
3235 
3236  /* only call heuristics if we have enough nodes left to call sub-CIP solving */
3237  if( nstallnodes < heurdata->minnodes )
3238  {
3239  SCIPdebugMessage("skipping undercover heuristic: nstallnodes=%"SCIP_LONGINT_FORMAT", minnodes=%"SCIP_LONGINT_FORMAT"\n", nstallnodes, heurdata->minnodes);
3240  return SCIP_OKAY;
3241  }
3242 
3243  /* only call heuristics if we have enough time left */
3244  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
3245  if( !SCIPisInfinity(scip, timelimit) )
3246  timelimit -= SCIPgetSolvingTime(scip);
3247  if( timelimit <= 2*MINTIMELEFT )
3248  {
3249  SCIPdebugMessage("skipping undercover heuristic: time left=%g\n", timelimit);
3250  return SCIP_OKAY;
3251  }
3252 
3253  /* only call heuristics if we have enough memory left */
3254  SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
3255  if( !SCIPisInfinity(scip, memorylimit) )
3256  {
3257  memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
3258  memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
3259  }
3260 
3261  if( memorylimit <= 2.0*SCIPgetMemExternEstim(scip)/1048576.0 )
3262  {
3263  SCIPdebugMessage("skipping undercover heuristic: too little memory\n");
3264  return SCIP_OKAY;
3265  }
3266 
3267  /* only call heuristic if nonlinear constraints are present */
3268  run = FALSE;
3269  for( h = heurdata->nnlconshdlrs-1; h >= 0 && !run; h-- )
3270  {
3271  run = (SCIPconshdlrGetNActiveConss(heurdata->nlconshdlrs[h]) > 0);
3272  }
3273 
3274  /* go through all nlrows and check for general nonlinearities */
3275  if( SCIPisNLPConstructed(scip) )
3276  {
3277  SCIP_NLROW** nlrows;
3278  int nnlrows;
3279  int i;
3280 
3281  /* get nlrows */
3282  nnlrows = SCIPgetNNLPNlRows(scip);
3283  nlrows = SCIPgetNLPNlRows(scip);
3284 
3285  /* check for an nlrow with nontrivial expression tree or quadratic terms; start from 0 since we expect the linear
3286  * nlrows at the end */
3287  for( i = nnlrows-1; i >= 0 && !run; i-- )
3288  {
3289  assert(nlrows[i] != NULL);
3290  run = SCIPnlrowGetExprtree(nlrows[i]) != NULL && SCIPexprtreeGetNVars(SCIPnlrowGetExprtree(nlrows[i])) > 0;
3291  run = run || SCIPnlrowGetNQuadVars(nlrows[i]) > 0;
3292  }
3293  }
3294 
3295  if( !run )
3296  {
3297  SCIPdebugMessage("skipping undercover heuristic: no nonlinear constraints found\n");
3298  return SCIP_OKAY;
3299  }
3300 
3301  /* only call heuristics if solving has not stopped yet */
3302  if( SCIPisStopped(scip) )
3303  return SCIP_OKAY;
3304 
3305  /* reset timing, if it was changed temporary (at the root node) */
3306  if( heurtiming != HEUR_TIMING )
3308 
3309  /* call heuristic */
3310  *result = SCIP_DIDNOTFIND;
3311  SCIPdebugMessage("calling undercover heuristic for <%s> at depth %d\n", SCIPgetProbName(scip), SCIPgetDepth(scip));
3312 
3313  SCIP_CALL( SCIPapplyUndercover(scip, heur, result, timelimit, memorylimit, nstallnodes) );
3314 
3315  return SCIP_OKAY;
3316 }
3317 
3318 
3319 /*
3320  * primal heuristic specific interface methods
3321  */
3322 
3323 /** creates the undercover primal heuristic and includes it in SCIP */
3325  SCIP* scip /**< SCIP data structure */
3326  )
3327 {
3328  SCIP_HEURDATA* heurdata;
3329  SCIP_HEUR* heur;
3330 
3331  /* create undercover primal heuristic data */
3332  SCIP_CALL( SCIPallocMemory(scip, &heurdata) );
3333 
3334  /* always use local bounds */
3335  heurdata->globalbounds = FALSE;
3336 
3337  /* include primal heuristic */
3338  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
3340  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecUndercover, heurdata) );
3341 
3342  assert(heur != NULL);
3343 
3344  /* set non-NULL pointers to callback methods */
3345  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyUndercover) );
3346  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeUndercover) );
3347  SCIP_CALL( SCIPsetHeurInitsol(scip, heur, heurInitsolUndercover) );
3348  SCIP_CALL( SCIPsetHeurExitsol(scip, heur, heurExitsolUndercover) );
3349 
3350  /* add string parameters */
3351  heurdata->fixingalts = NULL;
3352  SCIP_CALL( SCIPaddStringParam(scip, "heuristics/"HEUR_NAME"/fixingalts",
3353  "prioritized sequence of fixing values used ('l'p relaxation, 'n'lp relaxation, 'i'ncumbent solution)",
3354  &heurdata->fixingalts, FALSE, DEFAULT_FIXINGALTS, NULL, NULL) );
3355 
3356  /* add longint parameters */
3357  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/"HEUR_NAME"/maxnodes",
3358  "maximum number of nodes to regard in the subproblem",
3359  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
3360 
3361  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/"HEUR_NAME"/minnodes",
3362  "minimum number of nodes required to start the subproblem",
3363  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
3364 
3365  SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/"HEUR_NAME"/nodesofs",
3366  "number of nodes added to the contingent of the total nodes",
3367  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
3368 
3369  /* add real parameters */
3370  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/conflictweight",
3371  "weight for conflict score in fixing order",
3372  &heurdata->conflictweight, TRUE, DEFAULT_CONFLICTWEIGHT, SCIP_REAL_MIN, SCIP_REAL_MAX, NULL, NULL) );
3373 
3374  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/cutoffweight",
3375  "weight for cutoff score in fixing order",
3376  &heurdata->cutoffweight, TRUE, DEFAULT_CUTOFFWEIGHT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
3377 
3378  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/inferenceweight",
3379  "weight for inference score in fixing order",
3380  &heurdata->inferenceweight, TRUE, DEFAULT_INFERENCEWEIGHT, SCIP_REAL_MIN, SCIP_REAL_MAX, NULL, NULL) );
3381 
3382  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/maxcoversizevars",
3383  "maximum coversize (as fraction of total number of variables)",
3384  &heurdata->maxcoversizevars, TRUE, DEFAULT_MAXCOVERSIZEVARS, 0.0, 1.0, NULL, NULL) );
3385 
3386  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/maxcoversizeconss",
3387  "maximum coversize maximum coversize (as ratio to the percentage of non-affected constraints)",
3388  &heurdata->maxcoversizeconss, TRUE, DEFAULT_MAXCOVERSIZECONSS, 0.0, SCIP_REAL_MAX, NULL, NULL) );
3389 
3390  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/mincoveredrel",
3391  "minimum percentage of nonlinear constraints in the original problem",
3392  &heurdata->mincoveredrel, TRUE, DEFAULT_MINCOVEREDREL, 0.0, 1.0, NULL, NULL) );
3393 
3394  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/minimprove",
3395  "factor by which the heuristic should at least improve the incumbent",
3396  &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, -1.0, 1.0, NULL, NULL) );
3397 
3398  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/nodesquot",
3399  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
3400  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
3401 
3402  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/"HEUR_NAME"/recoverdiv",
3403  "fraction of covering variables in the last cover which need to change their value when recovering",
3404  &heurdata->recoverdiv, TRUE, DEFAULT_RECOVERDIV, 0.0, 1.0, NULL, NULL) );
3405 
3406  /* add int parameters */
3407  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/"HEUR_NAME"/mincoveredabs",
3408  "minimum number of nonlinear constraints in the original problem",
3409  &heurdata->mincoveredabs, TRUE, DEFAULT_MINCOVEREDABS, 0, INT_MAX, NULL, NULL) );
3410 
3411  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/"HEUR_NAME"/maxbacktracks",
3412  "maximum number of backtracks in fix-and-propagate",
3413  &heurdata->maxbacktracks, TRUE, DEFAULT_MAXBACKTRACKS, 0, INT_MAX, NULL, NULL) );
3414 
3415  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/"HEUR_NAME"/maxrecovers",
3416  "maximum number of recoverings",
3417  &heurdata->maxrecovers, TRUE, DEFAULT_MAXRECOVERS, 0, INT_MAX, NULL, NULL) );
3418 
3419  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/"HEUR_NAME"/maxreorders",
3420  "maximum number of reorderings of the fixing order",
3421  &heurdata->maxreorders, TRUE, DEFAULT_MAXREORDERS, 0, INT_MAX, NULL, NULL) );
3422 
3423  /* add char parameters */
3424  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/"HEUR_NAME"/coveringobj",
3425  "objective function of the covering problem (influenced nonlinear 'c'onstraints/'t'erms, 'd'omain size, 'l'ocks, 'm'in of up/down locks, 'u'nit penalties)",
3426  &heurdata->coveringobj, TRUE, DEFAULT_COVERINGOBJ, COVERINGOBJS, NULL, NULL) );
3427 
3428  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/"HEUR_NAME"/fixingorder",
3429  "order in which variables should be fixed (increasing 'C'onflict score, decreasing 'c'onflict score, increasing 'V'ariable index, decreasing 'v'ariable index",
3430  &heurdata->fixingorder, TRUE, DEFAULT_FIXINGORDER, FIXINGORDERS, NULL, NULL) );
3431 
3432  /* add bool parameters */
3433  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/beforecuts",
3434  "should the heuristic be called at root node before cut separation?",
3435  &heurdata->beforecuts, TRUE, DEFAULT_BEFORECUTS, NULL, NULL) );
3436 
3437  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/fixintfirst",
3438  "should integer variables in the cover be fixed first?",
3439  &heurdata->fixintfirst, TRUE, DEFAULT_FIXINTFIRST, NULL, NULL) );
3440 
3441  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/locksrounding",
3442  "shall LP values for integer vars be rounded according to locks?",
3443  &heurdata->locksrounding, TRUE, DEFAULT_LOCKSROUNDING, NULL, NULL) );
3444 
3445  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/onlyconvexify",
3446  "should we only fix variables in order to obtain a convex problem?",
3447  &heurdata->onlyconvexify, FALSE, DEFAULT_ONLYCONVEXIFY, NULL, NULL) );
3448 
3449  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/postnlp",
3450  "should the NLP heuristic be called to polish a feasible solution?",
3451  &heurdata->postnlp, FALSE, DEFAULT_POSTNLP, NULL, NULL) );
3452 
3453  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/coverbd",
3454  "should bounddisjunction constraints be covered (or just copied)?",
3455  &heurdata->coverbd, TRUE, DEFAULT_COVERBD, NULL, NULL) );
3456 
3457  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/copycuts",
3458  "should all active cuts from cutpool be copied to constraints in subproblem?",
3459  &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
3460 
3461  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/"HEUR_NAME"/reusecover",
3462  "shall the cover be reused if a conflict was added after an infeasible subproblem?",
3463  &heurdata->reusecover, TRUE, DEFAULT_REUSECOVER, NULL, NULL) );
3464 
3465  return SCIP_OKAY;
3466 }
3467 
3468 
3469 /** computes a minimal set of covering variables */
3471  SCIP* scip, /**< SCIP data structure */
3472  int* coversize, /**< buffer for the size of the computed cover */
3473  SCIP_VAR** cover, /**< pointer to store the variables (of the original SCIP) in the computed cover
3474  * (should be ready to hold SCIPgetNVars(scip) entries) */
3475  SCIP_Real timelimit, /**< time limit */
3476  SCIP_Real memorylimit, /**< memory limit */
3477  SCIP_Real objlimit, /**< objective limit: upper bound on coversize */
3478  SCIP_Bool globalbounds, /**< should global bounds on variables be used instead of local bounds at focus node? */
3479  SCIP_Bool onlyconvexify, /**< should we only fix/dom.red. variables creating nonconvexity? */
3480  SCIP_Bool coverbd, /**< should bounddisjunction constraints be covered (or just copied)? */
3481  char coveringobj, /**< objective function of the covering problem ('b'ranching status,
3482  * influenced nonlinear 'c'onstraints/'t'erms, 'd'omain size, 'l'ocks,
3483  * 'm'in of up/down locks, 'u'nit penalties, constraint 'v'iolation) */
3484  SCIP_Bool* success /**< feasible cover found? */
3485  )
3486 {
3487  SCIP* coveringscip; /* SCIP instance for covering problem */
3488  SCIP_VAR** coveringvars; /* covering variables */
3489  SCIP_VAR** vars; /* original variables */
3490  int* coverinds; /* indices of variables in the cover */
3491  int nvars; /* number of original variables */
3492  int i;
3493 
3494  assert(scip != NULL);
3495  assert(coversize != NULL);
3496  assert(success != NULL);
3497 
3498  *success = FALSE;
3499 
3500  /* allocate memory for variables of the covering problem */
3501  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL ) );
3502  SCIP_CALL( SCIPallocBufferArray(scip, &coveringvars, nvars) );
3503  SCIP_CALL( SCIPallocBufferArray(scip, &coverinds, nvars) );
3504 
3505  /* create covering problem */
3506  SCIP_CALL( SCIPcreate(&coveringscip) );
3507  SCIP_CALL( SCIPincludeDefaultPlugins(coveringscip) );
3508  SCIP_CALL( createCoveringProblem(scip, coveringscip, coveringvars, globalbounds, onlyconvexify, coverbd, coveringobj, success) );
3509 
3510  if( *success )
3511  {
3512  /* solve covering problem */
3513  SCIPdebugMessage("solving covering problem\n\n");
3514 
3515  SCIP_CALL( solveCoveringProblem(coveringscip, nvars, coveringvars, coversize, coverinds,
3516  timelimit, memorylimit + (SCIPgetMemExternEstim(coveringscip)+SCIPgetMemUsed(coveringscip))/1048576.0, objlimit, success) );
3517 
3518  if( *success )
3519  {
3520  assert(*coversize >= 0);
3521  assert(*coversize <= nvars);
3522 
3523  /* return original variables in the cover */
3524  for( i = *coversize-1; i >= 0; i-- )
3525  {
3526  assert(coverinds[i] >= 0);
3527  assert(coverinds[i] < nvars);
3528  cover[i] = vars[coverinds[i]];
3529  }
3530  }
3531  }
3532  else
3533  {
3534  SCIPdebugMessage("failure: covering problem could not be created\n");
3535  }
3536 
3537  /* free covering problem */
3538  for( i = nvars-1; i >= 0; i-- )
3539  {
3540  SCIP_CALL( SCIPreleaseVar(coveringscip, &coveringvars[i]) );
3541  }
3542  SCIP_CALL( SCIPfree(&coveringscip) );
3543  SCIPfreeBufferArray(scip, &coverinds);
3544  SCIPfreeBufferArray(scip, &coveringvars);
3545 
3546  return SCIP_OKAY;
3547 }
SCIP_RETCODE SCIPsetHeurInitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINITSOL((*heurinitsol)))
Definition: scip.c:7078
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:51
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip.c:20784
void SCIPsortRealInt(SCIP_Real *realarray, int *intarray, int len)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:38254
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:50
SCIP_RETCODE SCIPexprintCompile(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
#define SCIP_HEURTIMING_DURINGLPLOOP
Definition: type_timing.h:53
SCIP_RETCODE SCIPsetNLPIntPar(SCIP *scip, SCIP_NLPPARAM type, int ival)
Definition: scip.c:26645
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:16205
SCIP_RETCODE SCIPfreeClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip.c:37356
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:38397
static SCIP_RETCODE processNlRow(SCIP *scip, SCIP_NLROW *nlrow, SCIP_EXPRINT *exprint, struct HessianData *hessiandata, SCIP *coveringscip, int nvars, SCIP_VAR **coveringvars, int *termcounter, int *conscounter, SCIP_Bool *consmarker, SCIP_Bool globalbounds, SCIP_Bool onlyconvexify, SCIP_Bool *success)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
Definition: scip.c:36923
int SCIPgetNVars(SCIP *scip)
Definition: scip.c:10071
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:5600
#define HEUR_TIMING
int SCIPgetNVarsBounddisjunction(SCIP *scip, SCIP_CONS *cons)
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:15788
SCIP_RETCODE SCIPchgVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:17929
#define DEFAULT_FIXINGORDER
SCIP_STATUS SCIPgetStatus(SCIP *scip)
Definition: scip.c:897
static SCIP_Bool termIsConvex(SCIP *scip, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool sign)
methods to interpret (evaluate) an expression tree "fast"
#define HEUR_DISPCHAR
int SCIPnlrowGetNQuadElems(SCIP_NLROW *nlrow)
Definition: nlp.c:3312
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:38360
static SCIP_RETCODE getFixingValue(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_VAR *var, SCIP_Real *val, char fixalt, SCIP_Bool *success, int bdlen, SCIP_VAR **bdvars, SCIP_BOUNDTYPE *bdtypes, SCIP_Real *oldbounds)
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:591
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:717
static SCIP_RETCODE computeFixingOrder(SCIP *scip, SCIP_HEURDATA *heurdata, int nvars, SCIP_VAR **vars, int coversize, int *cover, int lastfailed, SCIP_Bool *success)
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip.c:7014
SCIP_RETCODE SCIPbacktrackProbing(SCIP *scip, int probingdepth)
Definition: scip.c:29573
#define DEFAULT_MAXRECOVERS
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:9751
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:15968
#define DEFAULT_MAXREORDERS
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1206
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
Definition: scip.c:13986
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip.c:10026
#define SCIP_MAXSTRLEN
Definition: def.h:196
#define DEFAULT_MINCOVEREDABS
#define NULL
Definition: lpi_spx.cpp:129
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:16426
#define DEFAULT_COPYCUTS
#define DEFAULT_RECOVERDIV
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4209
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1111
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:38803
SCIP_RETCODE SCIPstartClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip.c:37390
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:16380
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:6969
SCIP_Real SCIPgetClockTime(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip.c:37537
static SCIP_RETCODE solveCoveringProblem(SCIP *coveringscip, int ncoveringvars, SCIP_VAR **coveringvars, int *coversize, int *cover, SCIP_Real timelimit, SCIP_Real memorylimit, SCIP_Real objlimit, SCIP_Bool *success)
static SCIP_RETCODE roundFixingValue(SCIP *scip, SCIP_Real *val, SCIP_VAR *var, SCIP_Bool locksrounding)
SCIP_VAR * SCIPgetBinaryVarIndicator(SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateConsSetpack(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, 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)
Definition: cons_setppc.c:8952
int SCIPconshdlrGetNActiveConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4273
#define DEFAULT_MAXCOVERSIZECONSS
SCIP_RETCODE SCIPunfixParam(SCIP *scip, const char *name)
Definition: scip.c:3716
Undercover primal heuristic for MINLPs.
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
Definition: scip.c:29766
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
Definition: scip.c:7110
#define FALSE
Definition: def.h:52
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip.c:37596
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:1864
#define DEFAULT_MINIMPROVE
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip.c:3869
SCIP_EXPRINTCAPABILITY SCIPexprintGetCapability(void)
#define MAXPOSTNLPFAILS
static SCIP_DECL_HEUREXITSOL(heurExitsolUndercover)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:7579
#define TRUE
Definition: def.h:51
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_NLPSOLSTAT SCIPgetNLPSolstat(SCIP *scip)
Definition: scip.c:26466
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:38743
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip.c:3914
#define DEFAULT_INFERENCEWEIGHT
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip.c:17775
#define DEFAULT_MINCOVEREDREL
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:44
int SCIPgetNLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:4655
#define DEFAULT_NODESOFS
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
Definition: scip.c:38779
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip.c:24136
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
Definition: scip.c:13827
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:3442
#define SCIPdebugMessage
Definition: pub_message.h:77
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip.c:31775
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:19214
SCIP_RETCODE SCIPcomputeCoverUndercover(SCIP *scip, int *coversize, SCIP_VAR **cover, SCIP_Real timelimit, SCIP_Real memorylimit, SCIP_Real objlimit, SCIP_Bool globalbounds, SCIP_Bool onlyconvexify, SCIP_Bool coverbd, char coveringobj, SCIP_Bool *success)
SCIP_Real * SCIPgetLhsCoefsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:4681
#define DEFAULT_FIXINTFIRST
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:16227
#define COVERINGOBJS
void SCIPsortDownRealInt(SCIP_Real *realarray, int *intarray, int len)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:1923
#define SCIP_LONGINT_MAX
Definition: def.h:108
#define DEFAULT_BEFORECUTS
static SCIP_DECL_HEURCOPY(heurCopyUndercover)
#define DEFAULT_CONFLICTWEIGHT
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:22651
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:19215
static SCIP_RETCODE createConflict(SCIP *scip, int bdlen, SCIP_VAR **bdvars, SCIP_BOUNDTYPE *bdtypes, SCIP_Real *bdbounds, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool *success)
SCIP_RETCODE SCIPexprintCreate(BMS_BLKMEM *blkmem, SCIP_EXPRINT **exprint)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
Definition: scip.c:38815
SCIP_Bool SCIPisLbBetter(SCIP *scip, SCIP_Real newlb, SCIP_Real oldlb, SCIP_Real oldub)
Definition: scip.c:39054
SCIP_Real SCIPgetLowerbound(SCIP *scip)
Definition: scip.c:35061
SCIP_RETCODE SCIPresetClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip.c:37373
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:31855
SCIP_RETCODE SCIPcopyCuts(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
Definition: scip.c:2726
#define HEUR_NAME
SCIP_RETCODE SCIPendDiveNLP(SCIP *scip)
Definition: scip.c:26890
int SCIPgetNSols(SCIP *scip)
Definition: scip.c:32432
#define DEFAULT_MINNODES
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:3388
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:15907
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:1966
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:3414
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:15979
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip.c:10511
int SCIPgetNNLPNlRows(SCIP *scip)
Definition: scip.c:26312
#define DEFAULT_ONLYCONVEXIFY
#define DEFAULT_MAXNODES
SCIP_Real SCIPgetRhsCoefSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:4733
SCIP_Real coef
Definition: type_expr.h:101
SCIP_RETCODE SCIPgetBinvarRepresentative(SCIP *scip, SCIP_VAR *var, SCIP_VAR **repvar, SCIP_Bool *negated)
Definition: scip.c:15475
SCIP_VAR ** SCIPgetLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:4668
int SCIPgetNConss(SCIP *scip)
Definition: scip.c:11109
SCIP_VAR * SCIPgetRhsVarSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:4720
SCIP_VAR ** SCIPgetVarsAnd(SCIP *scip, SCIP_CONS *cons)
Definition: cons_and.c:5040
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:3095
#define SCIPallocMemory(scip, ptr)
Definition: scip.h:19159
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:18227
#define SCIPerrorMessage
Definition: pub_message.h:45
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:19221
#define HEUR_USESSUBSCIP
enum SCIP_NlpSolStat SCIP_NLPSOLSTAT
Definition: type_nlpi.h:69
static SCIP_DECL_HEUREXEC(heurExecUndercover)
#define FIXINGORDERS
int SCIPcalcHashtableSize(int minsize)
Definition: misc.c:964
int SCIPgetProbingDepth(SCIP *scip)
Definition: scip.c:29546
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip.c:26083
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:38292
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip.c:15406
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:30856
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:37940
SCIP_VAR ** SCIPgetVarsBounddisjunction(SCIP *scip, SCIP_CONS *cons)
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7557
SCIPInterval sign(const SCIPInterval &x)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:38648
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:15943
#define DEFAULT_NODESQUOT
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:1882
#define SUBMIPSETUPCOSTS
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:4199
#define DEFAULT_POSTNLP
SCIP_VAR * SCIPgetResultantAnd(SCIP *scip, SCIP_CONS *cons)
Definition: cons_and.c:5065
SCIP_Bool SCIPisConcaveQuadratic(SCIP *scip, SCIP_CONS *cons)
int SCIPexprtreeGetNVars(SCIP_EXPRTREE *tree)
Definition: expr.c:7974
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:8453
int SCIPvarGetNLocksUp(SCIP_VAR *var)
Definition: var.c:3214
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:31809
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:38349
void SCIPheurSetTimingmask(SCIP_HEUR *heur, SCIP_HEURTIMING timingmask)
Definition: heur.c:631
#define SCIP_CALL(x)
Definition: def.h:258
#define SCIPstatisticPrintf
Definition: pub_message.h:107
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip.c:755
SCIP_SOL ** SCIPgetSols(SCIP *scip)
Definition: scip.c:32481
SCIP_RETCODE SCIPaddLinearConsToNlpHeurSubNlp(SCIP *scip, SCIP_HEUR *heur, SCIP_Bool addcombconss, SCIP_Bool addcontconss)
Definition: heur_subnlp.c:2224
#define DEFAULT_CUTOFFWEIGHT
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:512
SCIP_RETCODE SCIPincludeHeurUndercover(SCIP *scip)
static SCIP_Bool varIsFixed(SCIP *scip, SCIP_VAR *var, SCIP_Real val, SCIP_Bool global)
SCIP_RETCODE SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3525
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip.c:15130
SCIP_RETCODE SCIPcreateConsBounddisjunction(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_BOUNDTYPE *boundtypes, SCIP_Real *bounds, 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 SCIPgetUpperbound(SCIP *scip)
Definition: scip.c:35202
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
Definition: var.c:16195
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:16436
SCIP_Real SCIPnlrowGetRhs(SCIP_NLROW *nlrow)
Definition: nlp.c:3373
SCIP_NLROW ** SCIPgetNLPNlRows(SCIP *scip)
Definition: scip.c:26290
#define SCIP_EXPRINTCAPABILITY_HESSIAN
SCIP_Real SCIPvarGetNLPSol(SCIP_VAR *var)
Definition: var.c:16773
#define SCIP_Bool
Definition: def.h:49
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
static void incCounters(int *termcounter, int *conscounter, SCIP_Bool *consmarker, int idx)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip.c:3824
#define DEFAULT_LOCKSROUNDING
SCIP_RETCODE SCIPlinkCurrentSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:31549
SCIP_Real SCIPgetVarConflictScore(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:21466
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip.c:3550
static void calculateAlternatives(SCIP *scip, SCIP_VAR *var, SCIP_Real fixval, int *nalternatives, SCIP_Real *alternatives)
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip.c:4124
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip.h:19222
#define HEUR_FREQ
static SCIP_RETCODE updateTimelimit(SCIP *scip, SCIP_CLOCK *clck, SCIP_Real *timelimit)
#define MAX(x, y)
Definition: tclique_def.h:75
int SCIPnlrowGetNQuadVars(SCIP_NLROW *nlrow)
Definition: nlp.c:3265
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip.c:37975
SCIP_RETCODE SCIPgetNlRowQuadratic(SCIP *scip, SCIP_CONS *cons, SCIP_NLROW **nlrow)
#define DEFAULT_COVERINGOBJ
SCIP_RETCODE SCIPapplyHeurSubNlp(SCIP *scip, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_SOL *refpoint, SCIP_Longint itercontingent, SCIP_Real timelimit, SCIP_Real minimprove, SCIP_Longint *iterused)
Definition: heur_subnlp.c:1517
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:19178
SCIP_RETCODE SCIPstartProbing(SCIP *scip)
Definition: scip.c:29476
SCIP_Real SCIPnlrowGetLhs(SCIP_NLROW *nlrow)
Definition: nlp.c:3363
SCIP_RETCODE SCIPsetHeurExitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXITSOL((*heurexitsol)))
Definition: scip.c:7094
SCIP_RETCODE SCIPendProbing(SCIP *scip)
Definition: scip.c:29607
#define SCIPallocMemoryArray(scip, ptr, num)
Definition: scip.h:19161
static SCIP_RETCODE performFixing(SCIP *scip, SCIP_VAR *var, SCIP_Real val, SCIP_Bool *infeas, int *bdlen, SCIP_VAR **bdvars, SCIP_BOUNDTYPE *bdtypes, SCIP_Real *bdbounds, SCIP_Real *oldbounds)
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:4173
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:34833
#define HEUR_DESC
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:38330
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
Definition: var.c:16760
#define SCIP_REAL_MAX
Definition: def.h:124
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:10850
#define SCIP_REAL_MIN
Definition: def.h:125
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip.c:13596
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:15953
SCIP_RETCODE SCIPsetHeuristics(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip.c:4147
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:737
#define SCIPfreeMemory(scip, ptr)
Definition: scip.h:19176
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:16370
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip.c:682
#define DEFAULT_MAXBACKTRACKS
#define DEFAULT_FIXINGALTS
SCIP_VAR ** SCIPnlrowGetQuadVars(SCIP_NLROW *nlrow)
Definition: nlp.c:3275
#define MAXNLPFAILS
SCIP_RETCODE SCIPstartDiveNLP(SCIP *scip)
Definition: scip.c:26863
#define MINTIMELEFT
SCIP_EXPRTREE * SCIPnlrowGetExprtree(SCIP_NLROW *nlrow)
Definition: nlp.c:3353
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
Definition: scip.c:38433
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_RETCODE SCIPchgVarUbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:29674
static SCIP_RETCODE fixAndPropagate(SCIP *scip, SCIP_HEURDATA *heurdata, int *cover, int coversize, SCIP_Real *fixingvals, int *bdlen, SCIP_VAR **bdvars, SCIP_BOUNDTYPE *bdtypes, SCIP_Real *bdbounds, SCIP_Real *oldbounds, int *nfixedints, int *nfixedconts, int *lastfailed, SCIP_Bool *infeas)
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip.c:7030
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:16072
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip.c:7867
static SCIP_Bool termIsConstant(SCIP *scip, SCIP_VAR *var, SCIP_Real coeff, SCIP_Bool global)
static SCIP_RETCODE solveSubproblem(SCIP *scip, SCIP_HEUR *heur, int coversize, int *cover, SCIP_Real *fixingvals, SCIP_Real timelimit, SCIP_Real memorylimit, SCIP_Longint nodelimit, SCIP_Longint nstallnodes, SCIP_Bool *validsolved, SCIP_SOL **sol, SCIP_Longint *nusednodes)
#define SCIPstatistic(x)
Definition: pub_message.h:101
const char * SCIPnlrowGetName(SCIP_NLROW *nlrow)
Definition: nlp.c:3383
#define SCIP_Real
Definition: def.h:123
SCIP_RETCODE SCIPnewProbingNode(SCIP *scip)
Definition: scip.c:29513
SCIP_RETCODE SCIPcreateConsSetcover(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, 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)
Definition: cons_setppc.c:9011
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3498
SCIP_RETCODE SCIPchgVarLbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:29640
#define MIN(x, y)
Definition: memory.c:59
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:38724
SCIP_RETCODE SCIPgetNlRowSOC(SCIP *scip, SCIP_CONS *cons, SCIP_NLROW **nlrow)
Definition: cons_soc.c:4629
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:18150
SCIP_RETCODE SCIPchgVarBoundsDiveNLP(SCIP *scip, SCIP_VAR *var, SCIP_Real lb, SCIP_Real ub)
Definition: scip.c:26944
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip.c:9567
const char * SCIPgetProbName(SCIP *scip)
Definition: scip.c:9314
SCIP_RETCODE SCIPsetNLPInitialGuessSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:26411
#define SCIP_Longint
Definition: def.h:107
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip.c:37305
static SCIP_RETCODE copySol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_SOL *subsol, SCIP_SOL **newsol)
SCIP_RETCODE SCIPgetIntParam(SCIP *scip, const char *name, int *value)
Definition: scip.c:3600
int SCIPgetNNlpis(SCIP *scip)
Definition: scip.c:8116
SCIP_RETCODE SCIPsetEmphasis(SCIP *scip, SCIP_PARAMEMPHASIS paramemphasis, SCIP_Bool quiet)
Definition: scip.c:4104
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:31679
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip.c:3779
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
Definition: scip.c:38839
#define HEUR_FREQOFS
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:502
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip.c:9945
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:16052
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip.c:3638
SCIP_RETCODE SCIPaddConsLocal(SCIP *scip, SCIP_CONS *cons, SCIP_NODE *validnode)
Definition: scip.c:11372
SCIP_RETCODE SCIPexprintHessianSparsityDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool *sparsity)
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:1901
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:98
static SCIP_RETCODE forbidCover(SCIP *scip, int nvars, SCIP_VAR **vars, int coversize, int *cover, int diversification, SCIP_Bool *success, SCIP_Bool *infeas)
SCIP_Real SCIPgetLhsQuadratic(SCIP *scip, SCIP_CONS *cons)
#define DEFAULT_REUSECOVER
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip.c:32531
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:3470
#define HEUR_PRIORITY
SCIP_RETCODE SCIPcreateConsLogicor(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, 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 SCIPsumepsilon(SCIP *scip)
Definition: scip.c:37719
static SCIP_RETCODE SCIPapplyUndercover(SCIP *scip, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Real timelimit, SCIP_Real memorylimit, SCIP_Longint nstallnodes)
static SCIP_DECL_HEURINITSOL(heurInitsolUndercover)
SCIP_RETCODE SCIPsolveDiveNLP(SCIP *scip)
Definition: scip.c:27003
SCIP_Real SCIPgetVarAvgInferenceCutoffScore(SCIP *scip, SCIP_VAR *var, SCIP_Real cutoffweight)
Definition: scip.c:21922
default SCIP plugins
#define DEFAULT_MAXCOVERSIZEVARS
int SCIPvarGetNLocksDown(SCIP_VAR *var)
Definition: var.c:3159
SCIP_Real SCIPgetRhsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: scip.c:32978
SCIP_RETCODE SCIPexprintFree(SCIP_EXPRINT **exprint)
SCIP_VAR ** SCIPexprtreeGetVars(SCIP_EXPRTREE *tree)
Definition: nlp.c:101
#define HEUR_MAXDEPTH
#define DEFAULT_COVERBD
SCIP_Longint SCIPgetNNodes(SCIP *scip)
Definition: scip.c:34065
static SCIP_RETCODE createCoveringProblem(SCIP *scip, SCIP *coveringscip, SCIP_VAR **coveringvars, SCIP_Bool globalbounds, SCIP_Bool onlyconvexify, SCIP_Bool coverbd, char coveringobj, SCIP_Bool *success)
SCIP_Bool SCIPisUbBetter(SCIP *scip, SCIP_Real newub, SCIP_Real oldlb, SCIP_Real oldub)
Definition: scip.c:39067
SCIP callable library.
SCIP_Bool SCIPisConvexQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_QUADELEM * SCIPnlrowGetQuadElems(SCIP_NLROW *nlrow)
Definition: nlp.c:3322
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
Definition: scip.c:32161
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip.c:31403
static SCIP_DECL_HEURFREE(heurFreeUndercover)
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip.c:37988
int SCIPheurGetFreqofs(SCIP_HEUR *heur)
Definition: heur.c:697
int SCIPgetNVarsAnd(SCIP *scip, SCIP_CONS *cons)
Definition: cons_and.c:5016