Scippy

SCIP

Solving Constraint Integer Programs

heur_distributiondiving.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2020 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_distributiondiving.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief Diving heuristic that chooses fixings w.r.t. changes in the solution density after Pryor and Chinneck.
19  * @author Gregor Hendel
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "blockmemshell/memory.h"
27 #include "scip/heuristics.h"
28 #include "scip/pub_event.h"
29 #include "scip/pub_heur.h"
30 #include "scip/pub_lp.h"
31 #include "scip/pub_message.h"
32 #include "scip/pub_var.h"
33 #include "scip/scip_event.h"
34 #include "scip/scip_general.h"
35 #include "scip/scip_heur.h"
36 #include "scip/scip_lp.h"
37 #include "scip/scip_mem.h"
38 #include "scip/scip_message.h"
39 #include "scip/scip_numerics.h"
40 #include "scip/scip_param.h"
41 #include "scip/scip_prob.h"
42 #include "scip/scip_probing.h"
43 #include "scip/scip_sol.h"
44 #include <string.h>
45 
46 #define HEUR_NAME "distributiondiving"
47 #define HEUR_DESC "Diving heuristic that chooses fixings w.r.t. changes in the solution density"
48 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_DIVING
49 #define HEUR_PRIORITY -1003300
50 #define HEUR_FREQ 10
51 #define HEUR_FREQOFS 3
52 #define HEUR_MAXDEPTH -1
53 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPPLUNGE
54 #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
55 #define EVENT_DISTRIBUTION SCIP_EVENTTYPE_BOUNDCHANGED /**< the event type to be handled by this event handler */
56 #define EVENTHDLR_NAME "eventhdlr_distributiondiving"
57 #define DIVESET_DIVETYPES SCIP_DIVETYPE_INTEGRALITY /**< bit mask that represents all supported dive types */
58 #define DIVESET_ISPUBLIC FALSE /**< is this dive set publicly available (ie., can be used by other primal heuristics?) */
59 
60 #define SQUARED(x) ((x) * (x))
61 /*
62  * Default parameter settings
63  */
64 
65 #define DEFAULT_MINRELDEPTH 0.0 /**< minimal relative depth to start diving */
66 #define DEFAULT_MAXRELDEPTH 1.0 /**< maximal relative depth to start diving */
67 #define DEFAULT_MAXLPITERQUOT 0.05 /**< maximal fraction of diving LP iterations compared to node LP iterations */
68 #define DEFAULT_MAXLPITEROFS 1000 /**< additional number of allowed LP iterations */
69 #define DEFAULT_MAXDIVEUBQUOT 0.8 /**< maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound)
70  * where diving is performed (0.0: no limit) */
71 #define DEFAULT_MAXDIVEAVGQUOT 0.0 /**< maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound)
72  * where diving is performed (0.0: no limit) */
73 #define DEFAULT_MAXDIVEUBQUOTNOSOL 0.1 /**< maximal UBQUOT when no solution was found yet (0.0: no limit) */
74 #define DEFAULT_MAXDIVEAVGQUOTNOSOL 0.0 /**< maximal AVGQUOT when no solution was found yet (0.0: no limit) */
75 #define DEFAULT_BACKTRACK TRUE /**< use one level of backtracking if infeasibility is encountered? */
76 #define DEFAULT_LPRESOLVEDOMCHGQUOT 0.15 /**< percentage of immediate domain changes during probing to trigger LP resolve */
77 #define DEFAULT_LPSOLVEFREQ 0 /**< LP solve frequency for diving heuristics */
78 #define DEFAULT_ONLYLPBRANCHCANDS TRUE /**< should only LP branching candidates be considered instead of the slower but
79  * more general constraint handler diving variable selection? */
80 
81 #define SCOREPARAM_VALUES "lhwvd" /**< the score;largest 'd'ifference, 'l'owest cumulative probability,'h'ighest c.p.,
82  * 'v'otes lowest c.p., votes highest c.p.('w'), 'r'evolving */
83 #define SCOREPARAM_VALUESLEN 5
84 #define DEFAULT_SCOREPARAM 'r' /**< default scoring parameter to guide the diving */
85 #define DEFAULT_RANDSEED 117 /**< initial seed for random number generation */
86 
87 /* locally defined heuristic data */
88 struct SCIP_HeurData
89 {
90  SCIP_SOL* sol; /**< working solution */
91  SCIP_EVENTHDLR* eventhdlr; /**< event handler pointer */
92  SCIP_VAR** updatedvars; /**< variables to process bound change events for */
93  SCIP_Real* rowmeans; /**< row activity mean values for all rows */
94  SCIP_Real* rowvariances; /**< row activity variances for all rows */
95  SCIP_Real* currentubs; /**< variable upper bounds as currently saved in the row activities */
96  SCIP_Real* currentlbs; /**< variable lower bounds as currently saved in the row activities */
97  int* rowinfinitiesdown; /**< count the number of variables with infinite bounds which allow for always
98  * repairing the constraint right hand side */
99  int* rowinfinitiesup; /**< count the number of variables with infinite bounds which allow for always
100  * repairing the constraint left hand side */
101  int* varposs; /**< array of variable positions in the updated variables array */
102  int* varfilterposs; /**< array of event filter positions for variable events */
103  int nupdatedvars; /**< the current number of variables with pending bound changes */
104  int memsize; /**< memory size of current arrays, needed for dynamic reallocation */
105  int varpossmemsize; /**< memory size of updated vars and varposs array */
106 
107  char scoreparam; /**< score user parameter */
108  char score; /**< score to be used depending on user parameter to use fixed score or revolve */
109 };
110 
111 struct SCIP_EventhdlrData
112 {
113  SCIP_HEURDATA* heurdata; /**< the heuristic data to access distribution arrays */
114 };
115 /*
116  * local methods
117  */
118 
119 /** ensure that maxindex + 1 rows can be represented in data arrays; memory gets reallocated with 10% extra space
120  * to save some time for future allocations */
121 static
123  SCIP* scip, /**< SCIP data structure */
124  SCIP_HEURDATA* heurdata, /**< heuristic data */
125  int maxindex /**< row index at hand (size must be at least this large) */
126  )
127 {
128  int newsize;
129  int r;
130 
131  /* maxindex fits in current array -> nothing to do */
132  if( maxindex < heurdata->memsize )
133  return SCIP_OKAY;
134 
135  /* new memory size is the max index + 1 plus 10% additional space */
136  newsize = (int)SCIPfeasCeil(scip, (maxindex + 1) * 1.1);
137  assert(newsize > heurdata->memsize);
138  assert(heurdata->memsize >= 0);
139 
140  /* alloc memory arrays for row information */
141  if( heurdata->memsize == 0 )
142  {
143  SCIP_VAR** vars;
144  int v;
145  int nvars;
146 
147  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->rowinfinitiesdown, newsize) );
148  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->rowinfinitiesup, newsize) );
149  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->rowmeans, newsize) );
150  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->rowvariances, newsize) );
151 
152  assert(SCIPgetStage(scip) == SCIP_STAGE_SOLVING);
153 
154  vars = SCIPgetVars(scip);
155  nvars = SCIPgetNVars(scip);
156 
157  assert(nvars > 0);
158 
159  /* allocate variable update event processing array storage */
160  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->varfilterposs, nvars) );
161  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->varposs, nvars) );
162  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->updatedvars, nvars) );
163  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->currentubs, nvars) );
164  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->currentlbs, nvars) );
165 
166  heurdata->varpossmemsize = nvars;
167  heurdata->nupdatedvars = 0;
168 
169  /* init variable event processing data */
170  for( v = 0; v < nvars; ++v )
171  {
172  assert(SCIPvarIsActive(vars[v]));
173  assert(SCIPvarGetProbindex(vars[v]) == v);
174 
175  /* set up variable events to catch bound changes */
176  SCIP_CALL( SCIPcatchVarEvent(scip, vars[v], EVENT_DISTRIBUTION, heurdata->eventhdlr, NULL, &(heurdata->varfilterposs[v])) );
177  assert(heurdata->varfilterposs[v] >= 0);
178 
179  heurdata->varposs[v] = -1;
180  heurdata->updatedvars[v] = NULL;
181  heurdata->currentlbs[v] = SCIP_INVALID;
182  heurdata->currentubs[v] = SCIP_INVALID;
183  }
184  }
185  else
186  {
187  SCIP_CALL( SCIPreallocBufferArray(scip, &heurdata->rowinfinitiesdown, newsize) );
188  SCIP_CALL( SCIPreallocBufferArray(scip, &heurdata->rowinfinitiesup, newsize) );
189  SCIP_CALL( SCIPreallocBufferArray(scip, &heurdata->rowmeans, newsize) );
190  SCIP_CALL( SCIPreallocBufferArray(scip, &heurdata->rowvariances, newsize) );
191  }
192 
193  /* loop over extended arrays and invalidate data to trigger initialization of this row when necessary */
194  for( r = heurdata->memsize; r < newsize; ++r )
195  {
196  heurdata->rowmeans[r] = SCIP_INVALID;
197  heurdata->rowvariances[r] = SCIP_INVALID;
198  heurdata->rowinfinitiesdown[r] = 0;
199  heurdata->rowinfinitiesup[r] = 0;
200  }
201 
202  /* adjust memsize */
203  heurdata->memsize = newsize;
204 
205  return SCIP_OKAY;
206 }
207 
208 /** update the variables current lower and upper bound */
209 static
211  SCIP* scip, /**< SCIP data structure */
212  SCIP_HEURDATA* heurdata, /**< heuristic data */
213  SCIP_VAR* var /**< the variable to update current bounds */
214  )
215 {
216  int varindex;
217  SCIP_Real lblocal;
218  SCIP_Real ublocal;
219 
220  assert(var != NULL);
221 
222  varindex = SCIPvarGetProbindex(var);
223  assert(0 <= varindex && varindex < heurdata->varpossmemsize);
224  lblocal = SCIPvarGetLbLocal(var);
225  ublocal = SCIPvarGetUbLocal(var);
226 
227  assert(SCIPisFeasLE(scip, lblocal, ublocal));
228 
229  heurdata->currentlbs[varindex] = lblocal;
230  heurdata->currentubs[varindex] = ublocal;
231 }
232 
233 /** calculates the initial mean and variance of the row activity normal distribution.
234  *
235  * The mean value \f$ \mu \f$ is given by \f$ \mu = \sum_i=1^n c_i * (lb_i +ub_i) / 2 \f$ where
236  * \f$n \f$ is the number of variables, and \f$ c_i, lb_i, ub_i \f$ are the variable coefficient and
237  * bounds, respectively. With the same notation, the variance \f$ \sigma^2 \f$ is given by
238  * \f$ \sigma^2 = \sum_i=1^n c_i^2 * \sigma^2_i \f$, with the variance being
239  * \f$ \sigma^2_i = ((ub_i - lb_i + 1)^2 - 1) / 12 \f$ for integer variables and
240  * \f$ \sigma^2_i = (ub_i - lb_i)^2 / 12 \f$ for continuous variables.
241  */
242 static
243 void rowCalculateGauss(
244  SCIP* scip, /**< SCIP data structure */
245  SCIP_HEURDATA* heurdata, /**< the heuristic rule data */
246  SCIP_ROW* row, /**< the row for which the gaussian normal distribution has to be calculated */
247  SCIP_Real* mu, /**< pointer to store the mean value of the gaussian normal distribution */
248  SCIP_Real* sigma2, /**< pointer to store the variance value of the gaussian normal distribution */
249  int* rowinfinitiesdown, /**< pointer to store the number of variables with infinite bounds to DECREASE activity */
250  int* rowinfinitiesup /**< pointer to store the number of variables with infinite bounds to INCREASE activity */
251  )
252 {
253  SCIP_COL** rowcols;
254  SCIP_Real* rowvals;
255  int nrowvals;
256  int c;
257 
258  assert(scip != NULL);
259  assert(row != NULL);
260  assert(mu != NULL);
261  assert(sigma2 != NULL);
262  assert(rowinfinitiesup != NULL);
263  assert(rowinfinitiesdown != NULL);
264 
265  rowcols = SCIProwGetCols(row);
266  rowvals = SCIProwGetVals(row);
267  nrowvals = SCIProwGetNNonz(row);
268 
269  assert(nrowvals == 0 || rowcols != NULL);
270  assert(nrowvals == 0 || rowvals != NULL);
271 
272  *mu = SCIProwGetConstant(row);
273  *sigma2 = 0.0;
274  *rowinfinitiesdown = 0;
275  *rowinfinitiesup = 0;
276 
277  /* loop over nonzero row coefficients and sum up the variable contributions to mu and sigma2 */
278  for( c = 0; c < nrowvals; ++c )
279  {
280  SCIP_VAR* colvar;
281  SCIP_Real colval;
282  SCIP_Real colvarlb;
283  SCIP_Real colvarub;
284  SCIP_Real squarecoeff;
285  SCIP_Real varvariance;
286  SCIP_Real varmean;
287  int varindex;
288 
289  assert(rowcols[c] != NULL);
290  colvar = SCIPcolGetVar(rowcols[c]);
291  assert(colvar != NULL);
292 
293  colval = rowvals[c];
294  colvarlb = SCIPvarGetLbLocal(colvar);
295  colvarub = SCIPvarGetUbLocal(colvar);
296 
297  varmean = 0.0;
298  varvariance = 0.0;
299  varindex = SCIPvarGetProbindex(colvar);
300  assert((heurdata->currentlbs[varindex] == SCIP_INVALID) == (heurdata->currentubs[varindex] == SCIP_INVALID)); /*lint !e777 doesn't like comparing floats for equality */
301 
302  /* variable bounds need to be watched from now on */
303  if( heurdata->currentlbs[varindex] == SCIP_INVALID ) /*lint !e777 doesn't like comparing floats for equality */
304  heurdataUpdateCurrentBounds(scip, heurdata, colvar);
305 
306  assert(!SCIPisInfinity(scip, colvarlb));
307  assert(!SCIPisInfinity(scip, -colvarub));
308  assert(SCIPisFeasLE(scip, colvarlb, colvarub));
309 
310  /* variables with infinite bounds are skipped for the calculation of the variance; they need to
311  * be accounted for by the counters for infinite row activity decrease and increase and they
312  * are used to shift the row activity mean in case they have one nonzero, but finite bound */
313  if( SCIPisInfinity(scip, -colvarlb) || SCIPisInfinity(scip, colvarub) )
314  {
315  if( SCIPisInfinity(scip, colvarub) )
316  {
317  /* an infinite upper bound gives the row an infinite maximum activity or minimum activity, if the coefficient is
318  * positive or negative, resp.
319  */
320  if( colval < 0.0 )
321  ++(*rowinfinitiesdown);
322  else
323  ++(*rowinfinitiesup);
324  }
325 
326  /* an infinite lower bound gives the row an infinite maximum activity or minimum activity, if the coefficient is
327  * negative or positive, resp.
328  */
329  if( SCIPisInfinity(scip, -colvarlb) )
330  {
331  if( colval > 0.0 )
332  ++(*rowinfinitiesdown);
333  else
334  ++(*rowinfinitiesup);
335  }
336  }
337  SCIPvarCalcDistributionParameters(scip, colvarlb, colvarub, SCIPvarGetType(colvar), &varmean, &varvariance);
338 
339  /* actual values are updated; the contribution of the variable to mu is the arithmetic mean of its bounds */
340  *mu += colval * varmean;
341 
342  /* the variance contribution of a variable is c^2 * (u - l)^2 / 12.0 for continuous and c^2 * ((u - l + 1)^2 - 1) / 12.0 for integer */
343  squarecoeff = SQUARED(colval);
344  *sigma2 += squarecoeff * varvariance;
345 
346  assert(!SCIPisFeasNegative(scip, *sigma2));
347  }
348 
349  SCIPdebug( SCIPprintRow(scip, row, NULL) );
350  SCIPdebugMsg(scip, " Row %s has a mean value of %g at a sigma2 of %g \n", SCIProwGetName(row), *mu, *sigma2);
351 }
352 
353 /** calculate the branching score of a variable, depending on the chosen score parameter */
354 static
356  SCIP* scip, /**< current SCIP */
357  SCIP_HEURDATA* heurdata, /**< branch rule data */
358  SCIP_VAR* var, /**< candidate variable */
359  SCIP_Real lpsolval, /**< current fractional LP-relaxation solution value */
360  SCIP_Real* upscore, /**< pointer to store the variable score when branching on it in upward direction */
361  SCIP_Real* downscore, /**< pointer to store the variable score when branching on it in downward direction */
362  char scoreparam /**< the score parameter of this heuristic */
363  )
364 {
365  SCIP_COL* varcol;
366  SCIP_ROW** colrows;
367  SCIP_Real* rowvals;
368  SCIP_Real varlb;
369  SCIP_Real varub;
370  SCIP_Real squaredbounddiff; /* current squared difference of variable bounds (ub - lb)^2 */
371  SCIP_Real newub; /* new upper bound if branching downwards */
372  SCIP_Real newlb; /* new lower bound if branching upwards */
373  SCIP_Real squaredbounddiffup; /* squared difference after branching upwards (ub - lb')^2 */
374  SCIP_Real squaredbounddiffdown; /* squared difference after branching downwards (ub' - lb)^2 */
375  SCIP_Real currentmean; /* current mean value of variable uniform distribution */
376  SCIP_Real meanup; /* mean value of variable uniform distribution after branching up */
377  SCIP_Real meandown; /* mean value of variable uniform distribution after branching down*/
378  SCIP_VARTYPE vartype;
379  int ncolrows;
380  int i;
381 
382  SCIP_Bool onlyactiverows; /* should only rows which are active at the current node be considered? */
383 
384  assert(scip != NULL);
385  assert(var != NULL);
386  assert(upscore != NULL);
387  assert(downscore != NULL);
388  assert(!SCIPisIntegral(scip, lpsolval) || SCIPvarIsBinary(var));
389  assert(SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN);
390 
391  varcol = SCIPvarGetCol(var);
392  assert(varcol != NULL);
393 
394  colrows = SCIPcolGetRows(varcol);
395  rowvals = SCIPcolGetVals(varcol);
396  ncolrows = SCIPcolGetNNonz(varcol);
397  varlb = SCIPvarGetLbLocal(var);
398  varub = SCIPvarGetUbLocal(var);
399  assert(varub - varlb > 0.5);
400  vartype = SCIPvarGetType(var);
401 
402  /* calculate mean and variance of variable uniform distribution before and after branching */
403  currentmean = 0.0;
404  squaredbounddiff = 0.0;
405  SCIPvarCalcDistributionParameters(scip, varlb, varub, vartype, &currentmean, &squaredbounddiff);
406 
407  /* unfixed binary variables may have an integer solution value in the LP solution, eg, at the presence of indicator constraints */
408  if( !SCIPvarIsBinary(var) )
409  {
410  newlb = SCIPfeasCeil(scip, lpsolval);
411  newub = SCIPfeasFloor(scip, lpsolval);
412  }
413  else
414  {
415  newlb = 1.0;
416  newub = 0.0;
417  }
418 
419  /* calculate the variable's uniform distribution after branching up and down, respectively. */
420  squaredbounddiffup = 0.0;
421  meanup = 0.0;
422  SCIPvarCalcDistributionParameters(scip, newlb, varub, vartype, &meanup, &squaredbounddiffup);
423 
424  /* calculate the distribution mean and variance for a variable with finite lower bound */
425  squaredbounddiffdown = 0.0;
426  meandown = 0.0;
427  SCIPvarCalcDistributionParameters(scip, varlb, newub, vartype, &meandown, &squaredbounddiffdown);
428 
429  /* initialize the variable's up and down score */
430  *upscore = 0.0;
431  *downscore = 0.0;
432 
433  onlyactiverows = FALSE;
434 
435  /* loop over the variable rows and calculate the up and down score */
436  for( i = 0; i < ncolrows; ++i )
437  {
438  SCIP_ROW* row;
439  SCIP_Real changedrowmean;
440  SCIP_Real rowmean;
441  SCIP_Real rowvariance;
442  SCIP_Real changedrowvariance;
443  SCIP_Real currentrowprob;
444  SCIP_Real newrowprobup;
445  SCIP_Real newrowprobdown;
446  SCIP_Real squaredcoeff;
447  SCIP_Real rowval;
448  int rowinfinitiesdown;
449  int rowinfinitiesup;
450  int rowpos;
451 
452  row = colrows[i];
453  rowval = rowvals[i];
454  assert(row != NULL);
455 
456  /* we access the rows by their index */
457  rowpos = SCIProwGetIndex(row);
458 
459  /* skip non-active rows if the user parameter was set this way */
460  if( onlyactiverows && SCIPisSumPositive(scip, SCIPgetRowLPFeasibility(scip, row)) )
461  continue;
462 
463  /* call method to ensure sufficient data capacity */
464  SCIP_CALL( heurdataEnsureArraySize(scip, heurdata, rowpos) );
465 
466  /* calculate row activity distribution if this is the first candidate to appear in this row */
467  if( heurdata->rowmeans[rowpos] == SCIP_INVALID ) /*lint !e777 doesn't like comparing floats for equality */
468  {
469  rowCalculateGauss(scip, heurdata, row, &heurdata->rowmeans[rowpos], &heurdata->rowvariances[rowpos],
470  &heurdata->rowinfinitiesdown[rowpos], &heurdata->rowinfinitiesup[rowpos]);
471  }
472 
473  /* retrieve the row distribution parameters from the branch rule data */
474  rowmean = heurdata->rowmeans[rowpos];
475  rowvariance = heurdata->rowvariances[rowpos];
476  rowinfinitiesdown = heurdata->rowinfinitiesdown[rowpos];
477  rowinfinitiesup = heurdata->rowinfinitiesup[rowpos];
478  assert(!SCIPisNegative(scip, rowvariance));
479 
480  currentrowprob = SCIProwCalcProbability(scip, row, rowmean, rowvariance,
481  rowinfinitiesdown, rowinfinitiesup);
482 
483  /* get variable's current expected contribution to row activity */
484  squaredcoeff = SQUARED(rowval);
485 
486  /* first, get the probability change for the row if the variable is branched on upwards. The probability
487  * can only be affected if the variable upper bound is finite
488  */
489  if( !SCIPisInfinity(scip, varub) )
490  {
491  int rowinftiesdownafterbranch;
492  int rowinftiesupafterbranch;
493 
494  /* calculate how branching would affect the row parameters */
495  changedrowmean = rowmean + rowval * (meanup - currentmean);
496  changedrowvariance = rowvariance + squaredcoeff * (squaredbounddiffup - squaredbounddiff);
497  changedrowvariance = MAX(0.0, changedrowvariance);
498 
499  rowinftiesdownafterbranch = rowinfinitiesdown;
500  rowinftiesupafterbranch = rowinfinitiesup;
501 
502  /* account for changes of the row's infinite bound contributions */
503  if( SCIPisInfinity(scip, -varlb) && rowval < 0.0 )
504  rowinftiesupafterbranch--;
505  if( SCIPisInfinity(scip, -varlb) && rowval > 0.0 )
506  rowinftiesdownafterbranch--;
507 
508  assert(rowinftiesupafterbranch >= 0);
509  assert(rowinftiesdownafterbranch >= 0);
510  newrowprobup = SCIProwCalcProbability(scip, row, changedrowmean, changedrowvariance, rowinftiesdownafterbranch,
511  rowinftiesupafterbranch);
512  }
513  else
514  newrowprobup = currentrowprob;
515 
516  /* do the same for the other branching direction */
517  if( !SCIPisInfinity(scip, varlb) )
518  {
519  int rowinftiesdownafterbranch;
520  int rowinftiesupafterbranch;
521 
522  changedrowmean = rowmean + rowval * (meandown - currentmean);
523  changedrowvariance = rowvariance + squaredcoeff * (squaredbounddiffdown - squaredbounddiff);
524  changedrowvariance = MAX(0.0, changedrowvariance);
525 
526  rowinftiesdownafterbranch = rowinfinitiesdown;
527  rowinftiesupafterbranch = rowinfinitiesup;
528 
529  /* account for changes of the row's infinite bound contributions */
530  if( SCIPisInfinity(scip, varub) && rowval > 0.0 )
531  rowinftiesupafterbranch -= 1;
532  if( SCIPisInfinity(scip, varub) && rowval < 0.0 )
533  rowinftiesdownafterbranch -= 1;
534 
535  assert(rowinftiesdownafterbranch >= 0);
536  assert(rowinftiesupafterbranch >= 0);
537  newrowprobdown = SCIProwCalcProbability(scip, row, changedrowmean, changedrowvariance, rowinftiesdownafterbranch,
538  rowinftiesupafterbranch);
539  }
540  else
541  newrowprobdown = currentrowprob;
542 
543  /* update the up and down score depending on the chosen scoring parameter */
544  SCIP_CALL( SCIPupdateDistributionScore(scip, currentrowprob, newrowprobup, newrowprobdown, upscore, downscore, scoreparam) );
545 
546  SCIPdebugMsg(scip, " Variable %s changes probability of row %s from %g to %g (branch up) or %g;\n",
547  SCIPvarGetName(var), SCIProwGetName(row), currentrowprob, newrowprobup, newrowprobdown);
548  SCIPdebugMsg(scip, " --> new variable score: %g (for branching up), %g (for branching down)\n",
549  *upscore, *downscore);
550  }
551 
552  return SCIP_OKAY;
553 }
554 
555 /** free heuristic data */
556 static
558  SCIP* scip, /**< SCIP data structure */
559  SCIP_HEURDATA* heurdata /**< heuristic data */
560  )
561 {
562  assert(heurdata->memsize == 0 || heurdata->rowmeans != NULL);
563  assert(heurdata->memsize >= 0);
564 
565  if( heurdata->varpossmemsize > 0 )
566  {
567  SCIP_VAR** vars;
568  int v;
569 
570  assert(heurdata->varpossmemsize == SCIPgetNVars(scip));
571 
572  vars = SCIPgetVars(scip);
573  for( v = heurdata->varpossmemsize - 1; v >= 0; --v )
574  {
575  SCIP_VAR* var;
576 
577  var = vars[v];
578 
579  assert(var != NULL);
580  assert(v == SCIPvarGetProbindex(var));
581  SCIP_CALL( SCIPdropVarEvent(scip, var, EVENT_DISTRIBUTION, heurdata->eventhdlr, NULL, heurdata->varfilterposs[v]) );
582  }
583  SCIPfreeBufferArray(scip, &heurdata->currentlbs);
584  SCIPfreeBufferArray(scip, &heurdata->currentubs);
585  SCIPfreeBufferArray(scip, &heurdata->updatedvars);
586  SCIPfreeBufferArray(scip, &heurdata->varposs);
587  SCIPfreeBufferArray(scip, &heurdata->varfilterposs);
588  }
589 
590  if( heurdata->memsize > 0 )
591  {
592  SCIPfreeBufferArray(scip, &heurdata->rowvariances);
593  SCIPfreeBufferArray(scip, &heurdata->rowmeans);
594  SCIPfreeBufferArray(scip, &heurdata->rowinfinitiesup);
595  SCIPfreeBufferArray(scip, &heurdata->rowinfinitiesdown);
596 
597  heurdata->memsize = 0;
598  }
599 
600  heurdata->varpossmemsize = 0;
601  heurdata->nupdatedvars = 0;
602 
603  return SCIP_OKAY;
604 }
605 
606 /** add variable to the bound change event queue; skipped if variable is already in there, or if variable has
607  * no row currently watched
608  */
609 static
611  SCIP_HEURDATA* heurdata, /**< heuristic data */
612  SCIP_VAR* var /**< the variable whose bound changes need to be processed */
613  )
614 {
615  int varindex;
616  int varpos;
617 
618  assert(var != NULL);
619 
620  varindex = SCIPvarGetProbindex(var);
621  assert(-1 <= varindex && varindex < heurdata->varpossmemsize);
622 
623  /* if variable is not active, it should not be watched */
624  if( varindex == -1 )
625  return;
626  varpos = heurdata->varposs[varindex];
627  assert(varpos < heurdata->nupdatedvars);
628 
629  /* nothing to do if variable is already in the queue */
630  if( varpos >= 0 )
631  {
632  assert(heurdata->updatedvars[varpos] == var);
633 
634  return;
635  }
636 
637  /* if none of the variables rows was calculated yet, variable needs not to be watched */
638  assert((heurdata->currentlbs[varindex] == SCIP_INVALID) == (heurdata->currentubs[varindex] == SCIP_INVALID)); /*lint !e777 doesn't like comparing floats for equality */
639 
640  /* we don't need to enqueue the variable if it hasn't been watched so far */
641  if( heurdata->currentlbs[varindex] == SCIP_INVALID ) /*lint !e777 see above */
642  return;
643 
644  /* add the variable to the heuristic data of variables to process updates for */
645  assert(heurdata->varpossmemsize > heurdata->nupdatedvars);
646  varpos = heurdata->nupdatedvars;
647  heurdata->updatedvars[varpos] = var;
648  heurdata->varposs[varindex] = varpos;
649  ++heurdata->nupdatedvars;
650 }
651 
652 /** returns the next unprocessed variable (last in, first out) with pending bound changes, or NULL */
653 static
655  SCIP_HEURDATA* heurdata /**< heuristic data */
656  )
657 {
658  SCIP_VAR* var;
659  int varpos;
660  int varindex;
661 
662  assert(heurdata->nupdatedvars >= 0);
663 
664  /* return if no variable is currently pending */
665  if( heurdata->nupdatedvars == 0 )
666  return NULL;
667 
668  varpos = heurdata->nupdatedvars - 1;
669  var = heurdata->updatedvars[varpos];
670  assert(var != NULL);
671  varindex = SCIPvarGetProbindex(var);
672  assert(0 <= varindex && varindex < heurdata->varpossmemsize);
673  assert(varpos == heurdata->varposs[varindex]);
674 
675  heurdata->varposs[varindex] = -1;
676  heurdata->nupdatedvars--;
677 
678  return var;
679 }
680 
681 /** process a variable from the queue of changed variables */
682 static
684  SCIP* scip, /**< SCIP data structure */
685  SCIP_HEURDATA* heurdata, /**< heuristic data */
686  SCIP_VAR* var /**< the variable whose bound changes need to be processed */
687  )
688 {
689  SCIP_ROW** colrows;
690  SCIP_COL* varcol;
691  SCIP_Real* colvals;
692  SCIP_Real oldmean;
693  SCIP_Real newmean;
694  SCIP_Real oldvariance;
695  SCIP_Real newvariance;
696  SCIP_Real oldlb;
697  SCIP_Real newlb;
698  SCIP_Real oldub;
699  SCIP_Real newub;
700  SCIP_VARTYPE vartype;
701  int ncolrows;
702  int r;
703  int varindex;
704 
705  /* ensure that this is a probing bound change */
706  assert(SCIPinProbing(scip));
707 
708  assert(var != NULL);
709  varcol = SCIPvarGetCol(var);
710  assert(varcol != NULL);
711  colrows = SCIPcolGetRows(varcol);
712  colvals = SCIPcolGetVals(varcol);
713  ncolrows = SCIPcolGetNNonz(varcol);
714 
715  varindex = SCIPvarGetProbindex(var);
716 
717  oldlb = heurdata->currentlbs[varindex];
718  oldub = heurdata->currentubs[varindex];
719 
720  /* skip update if the variable has never been subject of previously calculated row activities */
721  assert((oldlb == SCIP_INVALID) == (oldub == SCIP_INVALID)); /*lint !e777 doesn't like comparing floats for equality */
722  if( oldlb == SCIP_INVALID ) /*lint !e777 */
723  return SCIP_OKAY;
724 
725  newlb = SCIPvarGetLbLocal(var);
726  newub = SCIPvarGetUbLocal(var);
727 
728  /* skip update if the bound change events have cancelled out */
729  if( SCIPisFeasEQ(scip, oldlb, newlb) && SCIPisFeasEQ(scip, oldub, newub) )
730  return SCIP_OKAY;
731 
732  /* calculate old and new variable distribution mean and variance */
733  oldvariance = 0.0;
734  newvariance = 0.0;
735  oldmean = 0.0;
736  newmean = 0.0;
737  vartype = SCIPvarGetType(var);
738  SCIPvarCalcDistributionParameters(scip, oldlb, oldub, vartype, &oldmean, &oldvariance);
739  SCIPvarCalcDistributionParameters(scip, newlb, newub, vartype, &newmean, &newvariance);
740 
741  /* loop over all rows of this variable and update activity distribution */
742  for( r = 0; r < ncolrows; ++r )
743  {
744  int rowpos;
745 
746  assert(colrows[r] != NULL);
747  rowpos = SCIProwGetIndex(colrows[r]);
748  assert(rowpos >= 0);
749 
750  SCIP_CALL( heurdataEnsureArraySize(scip, heurdata, rowpos) );
751 
752  /* only consider rows for which activity distribution was already calculated */
753  if( heurdata->rowmeans[rowpos] != SCIP_INVALID ) /*lint !e777 doesn't like comparing floats for equality */
754  {
755  SCIP_Real coeff;
756  SCIP_Real coeffsquared;
757  assert(heurdata->rowvariances[rowpos] != SCIP_INVALID && SCIPisFeasGE(scip, heurdata->rowvariances[rowpos], 0.0)); /*lint !e777 */
758 
759  coeff = colvals[r];
760  coeffsquared = SQUARED(coeff);
761 
762  /* update variable contribution to row activity distribution */
763  heurdata->rowmeans[rowpos] += coeff * (newmean - oldmean);
764  heurdata->rowvariances[rowpos] += coeffsquared * (newvariance - oldvariance);
765  heurdata->rowvariances[rowpos] = MAX(0.0, heurdata->rowvariances[rowpos]);
766 
767  /* account for changes of the infinite contributions to row activities */
768  if( coeff > 0.0 )
769  {
770  /* if the coefficient is positive, upper bounds affect activity up */
771  if( SCIPisInfinity(scip, newub) && !SCIPisInfinity(scip, oldub) )
772  ++heurdata->rowinfinitiesup[rowpos];
773  else if( !SCIPisInfinity(scip, newub) && SCIPisInfinity(scip, oldub) )
774  --heurdata->rowinfinitiesup[rowpos];
775 
776  if( SCIPisInfinity(scip, newlb) && !SCIPisInfinity(scip, oldlb) )
777  ++heurdata->rowinfinitiesdown[rowpos];
778  else if( !SCIPisInfinity(scip, newlb) && SCIPisInfinity(scip, oldlb) )
779  --heurdata->rowinfinitiesdown[rowpos];
780  }
781  else if( coeff < 0.0 )
782  {
783  if( SCIPisInfinity(scip, newub) && !SCIPisInfinity(scip, oldub) )
784  ++heurdata->rowinfinitiesdown[rowpos];
785  else if( !SCIPisInfinity(scip, newub) && SCIPisInfinity(scip, oldub) )
786  --heurdata->rowinfinitiesdown[rowpos];
787 
788  if( SCIPisInfinity(scip, newlb) && !SCIPisInfinity(scip, oldlb) )
789  ++heurdata->rowinfinitiesup[rowpos];
790  else if( !SCIPisInfinity(scip, newlb) && SCIPisInfinity(scip, oldlb) )
791  --heurdata->rowinfinitiesup[rowpos];
792  }
793  assert(heurdata->rowinfinitiesdown[rowpos] >= 0);
794  assert(heurdata->rowinfinitiesup[rowpos] >= 0);
795  }
796  }
797 
798  /* store the new local bounds in the data */
799  heurdataUpdateCurrentBounds(scip, heurdata, var);
800 
801  return SCIP_OKAY;
802 }
803 
804 /** destructor of event handler to free user data (called when SCIP is exiting) */
805 static
806 SCIP_DECL_EVENTFREE(eventFreeDistributiondiving)
807 {
808  SCIP_EVENTHDLRDATA* eventhdlrdata;
809 
810  eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
811  assert(eventhdlrdata != NULL);
812 
813  SCIPfreeBlockMemory(scip, &eventhdlrdata);
814  SCIPeventhdlrSetData(eventhdlr, NULL);
815 
816  return SCIP_OKAY;
817 }
818 
819 /*
820  * Callback methods
821  */
822 
823 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
824 static
825 SCIP_DECL_HEURCOPY(heurCopyDistributiondiving)
826 { /*lint --e{715}*/
827  assert(scip != NULL);
828  assert(heur != NULL);
829  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
830 
831  /* call inclusion method of primal heuristic */
833 
834  return SCIP_OKAY;
835 }
836 
837 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
838 static
839 SCIP_DECL_HEURFREE(heurFreeDistributiondiving) /*lint --e{715}*/
840 { /*lint --e{715}*/
841  SCIP_HEURDATA* heurdata;
842 
843  assert(heur != NULL);
844  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
845  assert(scip != NULL);
846 
847  /* free heuristic data */
848  heurdata = SCIPheurGetData(heur);
849  assert(heurdata != NULL);
850  SCIPfreeBlockMemory(scip, &heurdata);
851  SCIPheurSetData(heur, NULL);
852 
853  return SCIP_OKAY;
854 }
855 
856 
857 /** initialization method of primal heuristic (called after problem was transformed) */
858 static
859 SCIP_DECL_HEURINIT(heurInitDistributiondiving) /*lint --e{715}*/
860 { /*lint --e{715}*/
861  SCIP_HEURDATA* heurdata;
862 
863  assert(heur != NULL);
864  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
865 
866  /* get heuristic data */
867  heurdata = SCIPheurGetData(heur);
868  assert(heurdata != NULL);
869 
870  /* create working solution */
871  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
872 
873  return SCIP_OKAY;
874 }
875 
876 
877 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
878 static
879 SCIP_DECL_HEUREXIT(heurExitDistributiondiving) /*lint --e{715}*/
880 { /*lint --e{715}*/
881  SCIP_HEURDATA* heurdata;
882 
883  assert(heur != NULL);
884  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
885 
886  /* get heuristic data */
887  heurdata = SCIPheurGetData(heur);
888  assert(heurdata != NULL);
889 
890  /* free working solution */
891  SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
892 
893  return SCIP_OKAY;
894 }
895 
896 /** scoring callback for distribution diving. best candidate maximizes the distribution score */
897 static
898 SCIP_DECL_DIVESETGETSCORE(divesetGetScoreDistributiondiving)
899 { /*lint --e{715}*/
900  SCIP_HEURDATA* heurdata;
901  SCIP_Real upscore;
902  SCIP_Real downscore;
903  int varindex;
904 
905  heurdata = SCIPheurGetData(SCIPdivesetGetHeur(diveset));
906  assert(heurdata != NULL);
907 
908  /* process pending bound change events */
909  while( heurdata->nupdatedvars > 0 )
910  {
911  SCIP_VAR* nextvar;
912 
913  /* pop the next variable from the queue and process its bound changes */
914  nextvar = heurdataPopBoundChangeVar(heurdata);
915  assert(nextvar != NULL);
916  SCIP_CALL( varProcessBoundChanges(scip, heurdata, nextvar) );
917  }
918 
919  assert(cand != NULL);
920 
921  varindex = SCIPvarGetProbindex(cand);
922 
923  /* terminate with a penalty for inactive variables, which the plugin can currently not score
924  * this should never happen with default settings where only LP branching candidates are iterated, but might occur
925  * if other constraint handlers try to score an inactive variable that was (multi-)aggregated or negated
926  */
927  if( varindex == - 1 )
928  {
929  *score = -1.0;
930  *roundup = FALSE;
931 
932  return SCIP_OKAY;
933  }
934 
935  /* in debug mode, ensure that all bound process events which occurred in the mean time have been captured
936  * by the heuristic event system
937  */
938  assert(SCIPisFeasLE(scip, SCIPvarGetLbLocal(cand), SCIPvarGetUbLocal(cand)));
939  assert(0 <= varindex && varindex < heurdata->varpossmemsize);
940 
941  assert((heurdata->currentlbs[varindex] == SCIP_INVALID) == (heurdata->currentubs[varindex] == SCIP_INVALID));/*lint !e777 doesn't like comparing floats for equality */
942  assert((heurdata->currentlbs[varindex] == SCIP_INVALID) || SCIPisFeasEQ(scip, SCIPvarGetLbLocal(cand), heurdata->currentlbs[varindex])); /*lint !e777 */
943  assert((heurdata->currentubs[varindex] == SCIP_INVALID) || SCIPisFeasEQ(scip, SCIPvarGetUbLocal(cand), heurdata->currentubs[varindex])); /*lint !e777 */
944 
945  /* if the heuristic has not captured the variable bounds yet, this can be done now */
946  if( heurdata->currentlbs[varindex] == SCIP_INVALID ) /*lint !e777 */
947  heurdataUpdateCurrentBounds(scip, heurdata, cand);
948 
949  upscore = 0.0;
950  downscore = 0.0;
951 
952  /* loop over candidate rows and determine the candidate up- and down- branching score w.r.t. the score parameter */
953  SCIP_CALL( calcBranchScore(scip, heurdata, cand, candsol, &upscore, &downscore, heurdata->score) );
954 
955  /* score is simply the maximum of the two individual scores */
956  *roundup = (upscore > downscore);
957  *score = MAX(upscore, downscore);
958 
959  return SCIP_OKAY;
960 }
961 
962 
963 /** execution method of primal heuristic */
964 static
965 SCIP_DECL_HEUREXEC(heurExecDistributiondiving)
966 { /*lint --e{715}*/
967  SCIP_HEURDATA* heurdata;
968  SCIP_DIVESET* diveset;
969  int nlprows;
970 
971  assert(heur != NULL);
972  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
973  assert(scip != NULL);
974  assert(result != NULL);
975  assert(SCIPhasCurrentNodeLP(scip));
976 
977  *result = SCIP_DIDNOTRUN;
978 
979  /* get heuristic's data */
980  heurdata = SCIPheurGetData(heur);
981  assert(heurdata != NULL);
982  nlprows = SCIPgetNLPRows(scip);
983  if( nlprows == 0 )
984  return SCIP_OKAY;
985 
986  /* terminate if there are no integer variables (note that, e.g., SOS1 variables may be present) */
987  if( SCIPgetNBinVars(scip) + SCIPgetNIntVars(scip) == 0 )
988  return SCIP_OKAY;
989 
990  /* select and store the scoring parameter for this call of the heuristic */
991  if( heurdata->scoreparam == 'r' )
992  heurdata->score = SCOREPARAM_VALUES[SCIPheurGetNCalls(heur) % SCOREPARAM_VALUESLEN];
993  else
994  heurdata->score = heurdata->scoreparam;
995 
996  SCIP_CALL( heurdataEnsureArraySize(scip, heurdata, nlprows) );
997  assert(SCIPheurGetNDivesets(heur) > 0);
998  assert(SCIPheurGetDivesets(heur) != NULL);
999  diveset = SCIPheurGetDivesets(heur)[0];
1000  assert(diveset != NULL);
1001 
1002  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible, -1L, SCIP_DIVECONTEXT_SINGLE) );
1003 
1004  SCIP_CALL( heurdataFreeArrays(scip, heurdata) );
1005 
1006  return SCIP_OKAY;
1007 }
1008 
1009 /** event execution method of distribution branching which handles bound change events of variables */
1010 static
1011 SCIP_DECL_EVENTEXEC(eventExecDistribution)
1012 {
1013  SCIP_HEURDATA* heurdata;
1014  SCIP_EVENTHDLRDATA* eventhdlrdata;
1015  SCIP_VAR* var;
1016 
1017  assert(eventhdlr != NULL);
1018  eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
1019  assert(eventhdlrdata != NULL);
1020 
1021  heurdata = eventhdlrdata->heurdata;
1022  var = SCIPeventGetVar(event);
1023 
1024  /* add the variable to the queue of unprocessed variables; method itself ensures that every variable is added at most once */
1025  heurdataAddBoundChangeVar(heurdata, var);
1026 
1027  return SCIP_OKAY;
1028 }
1029 
1030 /*
1031  * heuristic specific interface methods
1032  */
1033 
1034 #define divesetAvailableDistributiondiving NULL
1035 
1036 /** creates the distributiondiving heuristic and includes it in SCIP */
1038  SCIP* scip /**< SCIP data structure */
1039  )
1040 {
1041  SCIP_HEURDATA* heurdata;
1042  SCIP_HEUR* heur;
1043  SCIP_EVENTHDLRDATA* eventhdlrdata;
1044 
1045  /* create distributiondiving data */
1046  heurdata = NULL;
1047  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
1048 
1049  heurdata->memsize = 0;
1050  heurdata->rowmeans = NULL;
1051  heurdata->rowvariances = NULL;
1052  heurdata->rowinfinitiesdown = NULL;
1053  heurdata->rowinfinitiesup = NULL;
1054  heurdata->varfilterposs = NULL;
1055  heurdata->currentlbs = NULL;
1056  heurdata->currentubs = NULL;
1057 
1058  /* create event handler first to finish heuristic data */
1059  eventhdlrdata = NULL;
1060  SCIP_CALL( SCIPallocBlockMemory(scip, &eventhdlrdata) );
1061  eventhdlrdata->heurdata = heurdata;
1062 
1063  heurdata->eventhdlr = NULL;
1064  SCIP_CALL( SCIPincludeEventhdlrBasic(scip, &heurdata->eventhdlr, EVENTHDLR_NAME,
1065  "event handler for dynamic acitivity distribution updating",
1066  eventExecDistribution, eventhdlrdata) );
1067  assert( heurdata->eventhdlr != NULL);
1068  SCIP_CALL( SCIPsetEventhdlrFree(scip, heurdata->eventhdlr, eventFreeDistributiondiving) );
1069 
1070  /* include primal heuristic */
1071  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
1073  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecDistributiondiving, heurdata) );
1074 
1075  assert(heur != NULL);
1076 
1077  /* set non-NULL pointers to callback methods */
1078  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyDistributiondiving) );
1079  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeDistributiondiving) );
1080  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitDistributiondiving) );
1081  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitDistributiondiving) );
1082 
1083  /* add diveset with the defined scoring function */
1089  divesetGetScoreDistributiondiving, divesetAvailableDistributiondiving) );
1090 
1091  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/" HEUR_NAME "/scoreparam",
1092  "the score;largest 'd'ifference, 'l'owest cumulative probability,'h'ighest c.p., 'v'otes lowest c.p., votes highest c.p.('w'), 'r'evolving",
1093  &heurdata->scoreparam, TRUE, DEFAULT_SCOREPARAM, "lvdhwr", NULL, NULL) );
1094 
1095  return SCIP_OKAY;
1096 }
void SCIPeventhdlrSetData(SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: event.c:335
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1555
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:977
#define DIVESET_DIVETYPES
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
probability based branching rule based on an article by J. Pryor and J.W. Chinneck ...
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
public methods for SCIP parameter handling
int SCIPgetNLPRows(SCIP *scip)
Definition: scip_lp.c:596
#define SQUARED(x)
SCIP_Bool SCIPisSumPositive(SCIP *scip, SCIP_Real val)
public methods for memory management
static SCIP_DECL_DIVESETGETSCORE(divesetGetScoreDistributiondiving)
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1340
#define SCOREPARAM_VALUESLEN
void SCIPvarCalcDistributionParameters(SCIP *scip, SCIP_Real varlb, SCIP_Real varub, SCIP_VARTYPE vartype, SCIP_Real *mean, SCIP_Real *variance)
static SCIP_RETCODE heurdataEnsureArraySize(SCIP *scip, SCIP_HEURDATA *heurdata, int maxindex)
#define DEFAULT_RANDSEED
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
Definition: lp.c:17010
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:17062
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2152
int SCIPcolGetNNonz(SCIP_COL *col)
Definition: lp.c:16975
#define SCOREPARAM_VALUES
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
Definition: type_event.h:146
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:17107
SCIP_EXPORT SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:17192
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1986
SCIP_RETCODE SCIPperformGenericDivingAlgorithm(SCIP *scip, SCIP_DIVESET *diveset, SCIP_SOL *worksol, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Bool nodeinfeasible, SCIP_Longint iterlim, SCIP_DIVECONTEXT divecontext)
Definition: heuristics.c:209
#define FALSE
Definition: def.h:73
#define HEUR_NAME
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
Definition: lp.c:17000
#define HEUR_PRIORITY
SCIP_EXPORT SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17177
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
#define TRUE
Definition: def.h:72
#define SCIPdebug(x)
Definition: pub_message.h:84
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
#define HEUR_FREQ
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
SCIP_EXPORT SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:17335
public methods for problem variables
#define HEUR_USESSUBSCIP
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
static SCIP_RETCODE calcBranchScore(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_VAR *var, SCIP_Real lpsolval, SCIP_Real *upscore, SCIP_Real *downscore, char scoreparam)
#define EVENT_DISTRIBUTION
SCIP_EXPORT SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17131
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
static SCIP_DECL_EVENTFREE(eventFreeDistributiondiving)
#define SCIPdebugMsg
Definition: scip_message.h:69
#define HEUR_FREQOFS
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:74
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2076
public methods for numerical tolerances
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:320
SCIP_RETCODE SCIPupdateDistributionScore(SCIP *scip, SCIP_Real currentprob, SCIP_Real newprobup, SCIP_Real newprobdown, SCIP_Real *upscore, SCIP_Real *downscore, char scoreparam)
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip_heur.c:108
SCIP_HEUR * SCIPdivesetGetHeur(SCIP_DIVESET *diveset)
Definition: heur.c:396
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:325
#define DEFAULT_MINRELDEPTH
#define EVENTHDLR_NAME
#define DEFAULT_MAXDIVEUBQUOTNOSOL
#define DIVESET_ISPUBLIC
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTFREE((*eventfree)))
Definition: scip_event.c:141
SCIP_EXPORT const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:17012
#define DEFAULT_SCOREPARAM
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:17087
#define DEFAULT_LPSOLVEFREQ
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1637
public methods for event handler plugins and event handlers
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1941
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:17097
int SCIProwGetIndex(SCIP_ROW *row)
Definition: lp.c:17210
SCIP_SOL * sol
Definition: struct_heur.h:62
static SCIP_DECL_HEURCOPY(heurCopyDistributiondiving)
static SCIP_DECL_EVENTEXEC(eventExecDistribution)
#define HEUR_TIMING
SCIP_Bool SCIPinProbing(SCIP *scip)
Definition: scip_probing.c:88
static void rowCalculateGauss(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_ROW *row, SCIP_Real *mu, SCIP_Real *sigma2, int *rowinfinitiesdown, int *rowinfinitiesup)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1350
#define NULL
Definition: lpi_spx1.cpp:155
#define DEFAULT_MAXLPITEROFS
#define DEFAULT_MAXLPITERQUOT
#define SCIP_CALL(x)
Definition: def.h:364
static SCIP_DECL_HEUREXIT(heurExitDistributiondiving)
static void heurdataAddBoundChangeVar(SCIP_HEURDATA *heurdata, SCIP_VAR *var)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
#define divesetAvailableDistributiondiving
public methods for primal heuristic plugins and divesets
SCIP_EXPORT SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17376
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1627
#define SCIP_Bool
Definition: def.h:70
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:391
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:201
SCIP_Real SCIProwCalcProbability(SCIP *scip, SCIP_ROW *row, SCIP_Real mu, SCIP_Real sigma2, int rowinfinitiesdown, int rowinfinitiesup)
#define MAX(x, y)
Definition: tclique_def.h:83
public methods for LP management
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
static SCIP_DECL_HEUREXEC(heurExecDistributiondiving)
#define HEUR_MAXDEPTH
SCIP_RETCODE SCIPincludeHeurDistributiondiving(SCIP *scip)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_EXPORT SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17718
static void heurdataUpdateCurrentBounds(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_VAR *var)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:95
static SCIP_RETCODE heurdataFreeArrays(SCIP *scip, SCIP_HEURDATA *heurdata)
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16901
public methods for the LP relaxation, rows and columns
SCIP_RETCODE SCIPcreateDiveset(SCIP *scip, SCIP_DIVESET **diveset, SCIP_HEUR *heur, const char *name, SCIP_Real minreldepth, SCIP_Real maxreldepth, SCIP_Real maxlpiterquot, SCIP_Real maxdiveubquot, SCIP_Real maxdiveavgquot, SCIP_Real maxdiveubquotnosol, SCIP_Real maxdiveavgquotnosol, SCIP_Real lpresolvedomchgquot, int lpsolvefreq, int maxlpiterofs, unsigned int initialseed, SCIP_Bool backtrack, SCIP_Bool onlylpbranchcands, SCIP_Bool ispublic, SCIP_Bool specificsos1score, SCIP_DECL_DIVESETGETSCORE((*divesetgetscore)), SCIP_DECL_DIVESETAVAILABLE((*divesetavailable)))
Definition: scip_heur.c:311
SCIP_Real * r
Definition: circlepacking.c:50
SCIP_EXPORT SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17728
Diving heuristic that chooses fixings w.r.t. changes in the solution density after Pryor and Chinneck...
public methods for managing events
general public methods
#define DEFAULT_BACKTRACK
public methods for solutions
#define DEFAULT_MAXDIVEAVGQUOTNOSOL
public methods for the probing mode
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
public methods for message output
#define SCIP_Real
Definition: def.h:163
#define DEFAULT_ONLYLPBRANCHCANDS
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17200
public methods for message handling
#define SCIP_INVALID
Definition: def.h:183
SCIP_Real SCIPgetRowLPFeasibility(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1950
static SCIP_DECL_HEURFREE(heurFreeDistributiondiving)
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2031
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:345
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
#define HEUR_DESC
SCIP_VAR * SCIPeventGetVar(SCIP_EVENT *event)
Definition: event.c:1044
#define HEUR_DISPCHAR
SCIP_EXPORT int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17355
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:60
#define DEFAULT_LPRESOLVEDOMCHGQUOT
#define DEFAULT_MAXDIVEUBQUOT
static SCIP_VAR * heurdataPopBoundChangeVar(SCIP_HEURDATA *heurdata)
static SCIP_DECL_HEURINIT(heurInitDistributiondiving)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
public methods for primal heuristics
static SCIP_RETCODE varProcessBoundChanges(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_VAR *var)
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:356
public methods for global and local (sub)problems
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_param.c:158
#define DEFAULT_MAXRELDEPTH
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
#define DEFAULT_MAXDIVEAVGQUOT
memory allocation routines