Scippy

SCIP

Solving Constraint Integer Programs

heur_shiftandpropagate.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-2018 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_shiftandpropagate.c
17  * @brief shiftandpropagate primal heuristic
18  * @author Timo Berthold
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"
26 #include "scip/pub_event.h"
27 #include "scip/pub_heur.h"
28 #include "scip/pub_lp.h"
29 #include "scip/pub_message.h"
30 #include "scip/pub_misc.h"
31 #include "scip/pub_misc_sort.h"
32 #include "scip/pub_sol.h"
33 #include "scip/pub_var.h"
34 #include "scip/scip_event.h"
35 #include "scip/scip_general.h"
36 #include "scip/scip_heur.h"
37 #include "scip/scip_lp.h"
38 #include "scip/scip_mem.h"
39 #include "scip/scip_message.h"
40 #include "scip/scip_numerics.h"
41 #include "scip/scip_param.h"
42 #include "scip/scip_prob.h"
43 #include "scip/scip_probing.h"
44 #include "scip/scip_randnumgen.h"
45 #include "scip/scip_sol.h"
46 #include "scip/scip_solvingstats.h"
47 #include "scip/scip_tree.h"
48 #include "scip/scip_var.h"
49 #include <string.h>
50 
51 #define HEUR_NAME "shiftandpropagate"
52 #define HEUR_DESC "Pre-root heuristic to expand an auxiliary branch-and-bound tree and apply propagation techniques"
53 #define HEUR_DISPCHAR 'T'
54 #define HEUR_PRIORITY 1000
55 #define HEUR_FREQ 0
56 #define HEUR_FREQOFS 0
57 #define HEUR_MAXDEPTH -1
58 #define HEUR_TIMING SCIP_HEURTIMING_BEFORENODE
59 #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
60 
61 #define DEFAULT_WEIGHT_INEQUALITY 1 /**< the heuristic row weight for inequalities */
62 #define DEFAULT_WEIGHT_EQUALITY 3 /**< the heuristic row weight for equations */
63 #define DEFAULT_RELAX TRUE /**< Should continuous variables be relaxed from the problem? */
64 #define DEFAULT_PROBING TRUE /**< Is propagation of solution values enabled? */
65 #define DEFAULT_ONLYWITHOUTSOL TRUE /**< Should heuristic only be executed if no primal solution was found, yet? */
66 #define DEFAULT_NPROPROUNDS 10 /**< The default number of propagation rounds for each propagation used */
67 #define DEFAULT_PROPBREAKER 65000 /**< fixed maximum number of propagations */
68 #define DEFAULT_CUTOFFBREAKER 15 /**< fixed maximum number of allowed cutoffs before the heuristic stops */
69 #define DEFAULT_RANDSEED 29 /**< the default random seed for random number generation */
70 #define DEFAULT_SORTKEY 'v' /**< the default key for variable sorting */
71 #define DEFAULT_SORTVARS TRUE /**< should variables be processed in sorted order? */
72 #define DEFAULT_COLLECTSTATS TRUE /**< should variable statistics be collected during probing? */
73 #define DEFAULT_STOPAFTERFEASIBLE TRUE /**< Should the heuristic stop calculating optimal shift values when no more rows are violated? */
74 #define DEFAULT_PREFERBINARIES TRUE /**< Should binary variables be shifted first? */
75 #define DEFAULT_SELECTBEST FALSE /**< should the heuristic choose the best candidate in every round? (set to FALSE for static order)? */
76 #define DEFAULT_MAXCUTOFFQUOT 0.0 /**< maximum percentage of allowed cutoffs before stopping the heuristic */
77 #define SORTKEYS "nrtuv"/**< options sorting key: (n)orms down, norms (u)p, (v)iolated rows decreasing,
78  * viola(t)ed rows increasing, or (r)andom */
79 #define DEFAULT_NOZEROFIXING FALSE /**< should variables with a zero shifting value be delayed instead of being fixed? */
80 #define DEFAULT_FIXBINLOCKS TRUE /**< should binary variables with no locks in one direction be fixed to that direction? */
81 #define DEFAULT_BINLOCKSFIRST FALSE /**< should binary variables with no locks be preferred in the ordering? */
82 #define DEFAULT_NORMALIZE TRUE /**< should coefficients and left/right hand sides be normalized by max row coeff? */
83 #define DEFAULT_UPDATEWEIGHTS FALSE /**< should row weight be increased every time the row is violated? */
84 #define DEFAULT_IMPLISCONTINUOUS TRUE /**< should implicit integer variables be treated as continuous variables? */
85 
86 #define EVENTHDLR_NAME "eventhdlrshiftandpropagate"
87 #define EVENTHDLR_DESC "event handler to catch bound changes"
88 #define EVENTTYPE_SHIFTANDPROPAGATE (SCIP_EVENTTYPE_BOUNDCHANGED | SCIP_EVENTTYPE_GBDCHANGED)
89 
90 
91 /*
92  * Data structures
93  */
94 
95 /** primal heuristic data */
96 struct SCIP_HeurData
97 {
98  SCIP_COL** lpcols; /**< stores lp columns with discrete variables before cont. variables */
99  SCIP_RANDNUMGEN* randnumgen; /**< random number generation */
100  int* rowweights; /**< row weight storage */
101  SCIP_Bool relax; /**< should continuous variables be relaxed from the problem */
102  SCIP_Bool probing; /**< should probing be executed? */
103  SCIP_Bool onlywithoutsol; /**< Should heuristic only be executed if no primal solution was found, yet? */
104  int nlpcols; /**< the number of lp columns */
105  int nproprounds; /**< The default number of propagation rounds for each propagation used */
106  int cutoffbreaker; /**< the number of cutoffs before heuristic execution is stopped, or -1 for no
107  * limit */
108  SCIP_EVENTHDLR* eventhdlr; /**< event handler to register and process variable bound changes */
109 
110  SCIP_Real maxcutoffquot; /**< maximum percentage of allowed cutoffs before stopping the heuristic */
111  char sortkey; /**< the key by which variables are sorted */
112  SCIP_Bool sortvars; /**< should variables be processed in sorted order? */
113  SCIP_Bool collectstats; /**< should variable statistics be collected during probing? */
114  SCIP_Bool stopafterfeasible; /**< Should the heuristic stop calculating optimal shift values when no
115  * more rows are violated? */
116  SCIP_Bool preferbinaries; /**< Should binary variables be shifted first? */
117  SCIP_Bool nozerofixing; /**< should variables with a zero shifting value be delayed instead of being fixed? */
118  SCIP_Bool fixbinlocks; /**< should binary variables with no locks in one direction be fixed to that direction? */
119  SCIP_Bool binlocksfirst; /**< should binary variables with no locks be preferred in the ordering? */
120  SCIP_Bool normalize; /**< should coefficients and left/right hand sides be normalized by max row coeff? */
121  SCIP_Bool updateweights; /**< should row weight be increased every time the row is violated? */
122  SCIP_Bool impliscontinuous; /**< should implicit integer variables be treated as continuous variables? */
123  SCIP_Bool selectbest; /**< should the heuristic choose the best candidate in every round? (set to FALSE for static order)? */
125  SCIP_LPSOLSTAT lpsolstat; /**< the probing status after probing */
126  SCIP_Longint ntotaldomredsfound; /**< the total number of domain reductions during heuristic */
127  SCIP_Longint nlpiters; /**< number of LP iterations which the heuristic needed */
128  int nremainingviols; /**< the number of remaining violations */
129  int nprobings; /**< how many probings has the heuristic executed? */
130  int ncutoffs; /**< has the probing node been cutoff? */
131  )
132 };
133 
134 /** status of a variable in heuristic transformation */
135 enum TransformStatus
136 {
137  TRANSFORMSTATUS_NONE = 0, /**< variable has not been transformed yet */
138  TRANSFORMSTATUS_LB = 1, /**< variable has been shifted by using lower bound (x-lb) */
139  TRANSFORMSTATUS_NEG = 2, /**< variable has been negated by using upper bound (ub-x) */
140  TRANSFORMSTATUS_FREE = 3 /**< variable does not have to be shifted */
141 };
142 typedef enum TransformStatus TRANSFORMSTATUS;
144 /** information about the matrix after its heuristic transformation */
145 struct ConstraintMatrix
146 {
147  SCIP_Real* rowmatvals; /**< matrix coefficients row by row */
148  int* rowmatind; /**< the indices of the corresponding variables */
149  int* rowmatbegin; /**< the starting indices of each row */
150  SCIP_Real* colmatvals; /**< matrix coefficients column by column */
151  int* colmatind; /**< the indices of the corresponding rows for each coefficient */
152  int* colmatbegin; /**< the starting indices of each column */
153  int* violrows; /**< the number of violated rows for every variable */
154  TRANSFORMSTATUS* transformstatus; /**< information about transform status of every discrete variable */
155  SCIP_Real* lhs; /**< left hand side vector after normalization */
156  SCIP_Real* rhs; /**< right hand side vector after normalization */
157  SCIP_Real* colnorms; /**< vector norms of all discrete problem variables after normalization */
158  SCIP_Real* upperbounds; /**< the upper bounds of every non-continuous variable after transformation*/
159  SCIP_Real* transformshiftvals; /**< values by which original discrete variable bounds were shifted */
160  int nnonzs; /**< number of nonzero column entries */
161  int nrows; /**< number of rows of matrix */
162  int ncols; /**< the number of columns in matrix (including continuous vars) */
163  int ndiscvars; /**< number of discrete problem variables */
164  SCIP_Bool normalized; /**< indicates if the matrix data has already been normalized */
165 };
166 typedef struct ConstraintMatrix CONSTRAINTMATRIX;
168 struct SCIP_EventhdlrData
169 {
170  CONSTRAINTMATRIX* matrix; /**< the constraint matrix of the heuristic */
171  SCIP_HEURDATA* heurdata; /**< heuristic data */
172  int* violatedrows; /**< all currently violated LP rows */
173  int* violatedrowpos; /**< position in violatedrows array for every row */
174  int* nviolatedrows; /**< pointer to the total number of currently violated rows */
175 };
176 
177 struct SCIP_EventData
178 {
179  int colpos; /**< column position of the event-related variable */
180 };
181 /*
182  * Local methods
183  */
184 
185 /** returns whether a given variable is counted as discrete, depending on the parameter impliscontinuous */
186 static
188  SCIP_VAR* var, /**< variable to check for discreteness */
189  SCIP_Bool impliscontinuous /**< should implicit integer variables be counted as continuous? */
190  )
191 {
192  return SCIPvarIsIntegral(var) && (SCIPvarGetType(var) != SCIP_VARTYPE_IMPLINT || !impliscontinuous);
193 }
194 
195 /** returns whether a given column is counted as discrete, depending on the parameter impliscontinuous */
196 static
198  SCIP_COL* col, /**< column to check for discreteness */
199  SCIP_Bool impliscontinuous /**< should implicit integer variables be counted as continuous? */
200  )
201 {
202  return SCIPcolIsIntegral(col) && (!impliscontinuous || SCIPvarGetType(SCIPcolGetVar(col)) != SCIP_VARTYPE_IMPLINT);
203 }
204 
205 /** returns nonzero values and corresponding columns of given row */
206 static
207 void getRowData(
208  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
209  int rowindex, /**< index of the desired row */
210  SCIP_Real** valpointer, /**< pointer to store the nonzero coefficients of the row */
211  SCIP_Real* lhs, /**< lhs of the row */
212  SCIP_Real* rhs, /**< rhs of the row */
213  int** indexpointer, /**< pointer to store column indices which belong to the nonzeros */
214  int* nrowvals /**< pointer to store number of nonzeros in the desired row (or NULL) */
215  )
216 {
217  int arrayposition;
218 
219  assert(matrix != NULL);
220  assert(0 <= rowindex && rowindex < matrix->nrows);
221 
222  arrayposition = matrix->rowmatbegin[rowindex];
223 
224  if ( nrowvals != NULL )
225  {
226  if( rowindex == matrix->nrows - 1 )
227  *nrowvals = matrix->nnonzs - arrayposition;
228  else
229  *nrowvals = matrix->rowmatbegin[rowindex + 1] - arrayposition; /*lint !e679*/
230  }
231 
232  if( valpointer != NULL )
233  *valpointer = &(matrix->rowmatvals[arrayposition]);
234  if( indexpointer != NULL )
235  *indexpointer = &(matrix->rowmatind[arrayposition]);
236 
237  if( lhs != NULL )
238  *lhs = matrix->lhs[rowindex];
239 
240  if( rhs != NULL )
241  *rhs = matrix->rhs[rowindex];
242 }
243 
244 /** returns nonzero values and corresponding rows of given column */
245 static
246 void getColumnData(
247  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
248  int colindex, /**< the index of the desired column */
249  SCIP_Real** valpointer, /**< pointer to store the nonzero coefficients of the column */
250  int** indexpointer, /**< pointer to store row indices which belong to the nonzeros */
251  int* ncolvals /**< pointer to store number of nonzeros in the desired column */
252  )
253 {
254  int arrayposition;
255 
256  assert(matrix != NULL);
257  assert(0 <= colindex && colindex < matrix->ncols);
258 
259  arrayposition = matrix->colmatbegin[colindex];
260 
261  if( ncolvals != NULL )
262  {
263  if( colindex == matrix->ncols - 1 )
264  *ncolvals = matrix->nnonzs - arrayposition;
265  else
266  *ncolvals = matrix->colmatbegin[colindex + 1] - arrayposition; /*lint !e679*/
267  }
268  if( valpointer != NULL )
269  *valpointer = &(matrix->colmatvals[arrayposition]);
270 
271  if( indexpointer != NULL )
272  *indexpointer = &(matrix->colmatind[arrayposition]);
273 }
274 
275 /** relaxes a continuous variable from all its rows, which has influence
276  * on both the left and right hand side of the constraint.
277  */
278 static
279 void relaxVar(
280  SCIP* scip, /**< current scip instance */
281  SCIP_VAR* var, /**< variable which is relaxed from the problem */
282  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
283  SCIP_Bool normalize /**< should coefficients and be normalized by rows maximum norms? */
284  )
285 {
286  SCIP_ROW** colrows;
287  SCIP_COL* varcol;
288  SCIP_Real* colvals;
289  SCIP_Real ub;
290  SCIP_Real lb;
291  int ncolvals;
292  int r;
293 
294  assert(var != NULL);
295  assert(SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN);
296 
297  varcol = SCIPvarGetCol(var);
298  assert(varcol != NULL);
299 
300  /* get nonzero values and corresponding rows of variable */
301  colvals = SCIPcolGetVals(varcol);
302  ncolvals = SCIPcolGetNLPNonz(varcol);
303  colrows = SCIPcolGetRows(varcol);
304 
305  ub = SCIPvarGetUbGlobal(var);
306  lb = SCIPvarGetLbGlobal(var);
307 
308  assert(colvals != NULL || ncolvals == 0);
309 
310  SCIPdebugMsg(scip, "Relaxing variable <%s> with lb <%g> and ub <%g>\n",
311  SCIPvarGetName(var), lb, ub);
312 
313  assert(matrix->normalized);
314  /* relax variable from all its constraints */
315  for( r = 0; r < ncolvals; ++r )
316  {
317  SCIP_ROW* colrow;
318  SCIP_Real lhs;
319  SCIP_Real rhs;
320  SCIP_Real lhsvarbound;
321  SCIP_Real rhsvarbound;
322  SCIP_Real rowabs;
323  SCIP_Real colval;
324  int rowindex;
325 
326  colrow = colrows[r];
327  rowindex = SCIProwGetLPPos(colrow);
328 
329  if( rowindex == -1 )
330  break;
331 
332  rowabs = SCIPgetRowMaxCoef(scip, colrow);
333  assert(colvals != NULL); /* to please flexelint */
334  colval = colvals[r];
335  if( normalize && SCIPisFeasGT(scip, rowabs, 0.0) )
336  colval /= rowabs;
337 
338  assert(0 <= rowindex && rowindex < matrix->nrows);
339  getRowData(matrix, rowindex, NULL, &lhs, &rhs, NULL, NULL);
340  /* variables bound influence the lhs and rhs of current row depending on the sign
341  * of the variables coefficient.
342  */
343  if( SCIPisFeasPositive(scip, colval) )
344  {
345  lhsvarbound = ub;
346  rhsvarbound = lb;
347  }
348  else if( SCIPisFeasNegative(scip, colval) )
349  {
350  lhsvarbound = lb;
351  rhsvarbound = ub;
352  }
353  else
354  continue;
355 
356  /* relax variable from the current row */
357  if( !SCIPisInfinity(scip, -matrix->lhs[rowindex]) && !SCIPisInfinity(scip, ABS(lhsvarbound)) )
358  matrix->lhs[rowindex] -= colval * lhsvarbound;
359  else
360  matrix->lhs[rowindex] = -SCIPinfinity(scip);
361 
362  if( !SCIPisInfinity(scip, matrix->rhs[rowindex]) && !SCIPisInfinity(scip, ABS(rhsvarbound)) )
363  matrix->rhs[rowindex] -= colval * rhsvarbound;
364  else
365  matrix->rhs[rowindex] = SCIPinfinity(scip);
366 
367  SCIPdebugMsg(scip, "Row <%s> changed:Coefficient <%g>, LHS <%g> --> <%g>, RHS <%g> --> <%g>\n",
368  SCIProwGetName(colrow), colval, lhs, matrix->lhs[rowindex], rhs, matrix->rhs[rowindex]);
369  }
370 }
371 
372 /** transforms bounds of a given variable s.t. its lower bound equals zero afterwards.
373  * If the variable already has lower bound zero, the variable is not transformed,
374  * if not, the variable's bounds are changed w.r.t. the smaller absolute value of its
375  * bounds in order to avoid numerical inaccuracies. If both lower and upper bound
376  * of the variable differ from infinity, there are two cases. If |lb| <= |ub|,
377  * the bounds are shifted by -lb, else a new variable ub - x replaces x.
378  * The transformation is memorized by the transform status of the variable s.t.
379  * retransformation is possible.
380  */
381 static
382 void transformVariable(
383  SCIP* scip, /**< current scip instance */
384  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
385  SCIP_HEURDATA* heurdata, /**< heuristic data */
386  int colpos /**< position of variable column in matrix */
387  )
388 {
389  SCIP_COL* col;
390  SCIP_VAR* var;
391  SCIP_Real lb;
392  SCIP_Real ub;
393 
394  SCIP_Bool negatecoeffs; /* do the row coefficients need to be negated? */
395  SCIP_Real deltashift; /* difference from previous transformation */
396 
397  assert(matrix != NULL);
398  assert(0 <= colpos && colpos < heurdata->nlpcols);
399  col = heurdata->lpcols[colpos];
400  assert(col != NULL);
401  assert(SCIPcolIsInLP(col));
402 
403  var = SCIPcolGetVar(col);
404  assert(var != NULL);
405  assert(SCIPvarIsIntegral(var));
406  lb = SCIPvarGetLbLocal(var);
407  ub = SCIPvarGetUbLocal(var);
408 
409  negatecoeffs = FALSE;
410  /* if both lower and upper bound are -infinity and infinity, resp., this is reflected by a free transform status.
411  * If the lower bound is already zero, this is reflected by identity transform status. In both cases, none of the
412  * corresponding rows needs to be modified.
413  */
414  if( SCIPisInfinity(scip, -lb) && SCIPisInfinity(scip, ub) )
415  {
416  if( matrix->transformstatus[colpos] == TRANSFORMSTATUS_NEG )
417  negatecoeffs = TRUE;
418 
419  deltashift = matrix->transformshiftvals[colpos];
420  matrix->transformshiftvals[colpos] = 0.0;
421  matrix->transformstatus[colpos] = TRANSFORMSTATUS_FREE;
422  }
423  else if( SCIPisFeasLE(scip, ABS(lb), ABS(ub)) )
424  {
425  assert(!SCIPisInfinity(scip, lb));
426  matrix->transformstatus[colpos] = TRANSFORMSTATUS_LB;
427  deltashift = lb;
428  matrix->transformshiftvals[colpos] = lb;
429  }
430  else
431  {
432  assert(!SCIPisInfinity(scip, ub));
433  if( matrix->transformstatus[colpos] != TRANSFORMSTATUS_NEG )
434  negatecoeffs = TRUE;
435  matrix->transformstatus[colpos] = TRANSFORMSTATUS_NEG;
436  deltashift = ub;
437  matrix->transformshiftvals[colpos] = ub;
438  }
439 
440  /* determine the upper bound for this variable in heuristic transformation (lower bound is implicit; always 0) */
441  if( !SCIPisInfinity(scip, ub) && !SCIPisInfinity(scip, lb) )
442  matrix->upperbounds[colpos] = ub - lb;
443  else
444  matrix->upperbounds[colpos] = SCIPinfinity(scip);
445 
446  /* a real transformation is necessary. The variable x is either shifted by -lb or
447  * replaced by ub - x, depending on the smaller absolute of lb and ub.
448  */
449  if( !SCIPisFeasZero(scip, deltashift) || negatecoeffs )
450  {
451  SCIP_Real* vals;
452  int* rows;
453  int nrows;
454  int i;
455 
456  assert(!SCIPisInfinity(scip, deltashift));
457 
458  /* get nonzero values and corresponding rows of column */
459  getColumnData(matrix, colpos, &vals, &rows, &nrows);
460  assert(nrows == 0 ||(vals != NULL && rows != NULL));
461 
462  /* go through rows and modify its lhs, rhs and the variable coefficient, if necessary */
463  for( i = 0; i < nrows; ++i )
464  {
465  int rowpos = rows[i];
466  assert(rowpos >= 0);
467  assert(rowpos < matrix->nrows);
468 
469  if( !SCIPisInfinity(scip, -(matrix->lhs[rowpos])) )
470  matrix->lhs[rowpos] -= (vals[i]) * deltashift;
471 
472  if( !SCIPisInfinity(scip, matrix->rhs[rowpos]) )
473  matrix->rhs[rowpos] -= (vals[i]) * deltashift;
474 
475  if( negatecoeffs )
476  (vals[i]) = -(vals[i]);
477 
478  assert(SCIPisFeasLE(scip, matrix->lhs[rowpos], matrix->rhs[rowpos]));
479  }
480  }
481  SCIPdebugMsg(scip, "Variable <%s> at colpos %d transformed. LB <%g> --> <%g>, UB <%g> --> <%g>\n",
482  SCIPvarGetName(var), colpos, lb, 0.0, ub, matrix->upperbounds[colpos]);
483 }
484 
485 /** initializes copy of the original coefficient matrix and applies heuristic specific adjustments: normalizing row
486  * vectors, transforming variable domains such that lower bound is zero, and relaxing continuous variables.
487  */
488 static
490  SCIP* scip, /**< current scip instance */
491  CONSTRAINTMATRIX* matrix, /**< constraint matrix object to be initialized */
492  SCIP_HEURDATA* heurdata, /**< heuristic data */
493  int* colposs, /**< position of columns according to variable type sorting */
494  SCIP_Bool normalize, /**< should coefficients and be normalized by rows maximum norms? */
495  int* nmaxrows, /**< maximum number of rows a variable appears in */
496  SCIP_Bool relax, /**< should continuous variables be relaxed from the problem? */
497  SCIP_Bool* initialized, /**< was the initialization successful? */
498  SCIP_Bool* infeasible /**< is the problem infeasible? */
499  )
500 {
501  SCIP_ROW** lprows;
502  SCIP_COL** lpcols;
503  SCIP_Bool impliscontinuous;
504  int i;
505  int j;
506  int currentpointer;
507 
508  int nrows;
509  int ncols;
510 
511  assert(scip != NULL);
512  assert(matrix != NULL);
513  assert(initialized!= NULL);
514  assert(infeasible != NULL);
515  assert(nmaxrows != NULL);
516 
517  SCIPdebugMsg(scip, "entering Matrix Initialization method of SHIFTANDPROPAGATE heuristic!\n");
518 
519  /* get LP row data; column data is already initialized in heurdata */
520  SCIP_CALL( SCIPgetLPRowsData(scip, &lprows, &nrows) );
521  lpcols = heurdata->lpcols;
522  ncols = heurdata->nlpcols;
523 
524  matrix->nrows = nrows;
525  matrix->nnonzs = 0;
526  matrix->normalized = FALSE;
527  matrix->ndiscvars = 0;
528  *nmaxrows = 0;
529  impliscontinuous = heurdata->impliscontinuous;
530 
531  /* count the number of nonzeros of the LP constraint matrix */
532  for( j = 0; j < ncols; ++j )
533  {
534  assert(lpcols[j] != NULL);
535  assert(SCIPcolGetLPPos(lpcols[j]) >= 0);
536 
537  if( colIsDiscrete(lpcols[j], impliscontinuous) )
538  {
539  matrix->nnonzs += SCIPcolGetNLPNonz(lpcols[j]);
540  ++matrix->ndiscvars;
541  }
542  }
543 
544  matrix->ncols = matrix->ndiscvars;
545 
546  if( matrix->nnonzs == 0 )
547  {
548  SCIPdebugMsg(scip, "No matrix entries - Terminating initialization of matrix.\n");
549 
550  *initialized = FALSE;
551 
552  return SCIP_OKAY;
553  }
554 
555  /* allocate memory for the members of heuristic matrix */
556  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatvals, matrix->nnonzs) );
557  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatind, matrix->nnonzs) );
558  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatvals, matrix->nnonzs) );
559  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatind, matrix->nnonzs) );
560  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatbegin, matrix->nrows) );
561  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatbegin, matrix->ncols) );
562  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->lhs, matrix->nrows) );
563  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rhs, matrix->nrows) );
564  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colnorms, matrix->ncols) );
565  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->violrows, matrix->ncols) );
566  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->transformstatus, matrix->ndiscvars) );
567  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->upperbounds, matrix->ndiscvars) );
568  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->transformshiftvals, matrix->ndiscvars) );
569 
570  /* set transform status of variables */
571  for( j = 0; j < matrix->ndiscvars; ++j )
572  matrix->transformstatus[j] = TRANSFORMSTATUS_NONE;
573 
574  currentpointer = 0;
575  *infeasible = FALSE;
576 
577  /* initialize the rows vector of the heuristic matrix together with its corresponding
578  * lhs, rhs.
579  */
580  for( i = 0; i < nrows; ++i )
581  {
582  SCIP_COL** cols;
583  SCIP_ROW* row;
584  SCIP_Real* rowvals;
585  SCIP_Real constant;
586  SCIP_Real maxval;
587  int nrowlpnonz;
588 
589  /* get LP row information */
590  row = lprows[i];
591  rowvals = SCIProwGetVals(row);
592  nrowlpnonz = SCIProwGetNLPNonz(row);
593  maxval = SCIPgetRowMaxCoef(scip, row);
594  cols = SCIProwGetCols(row);
595  constant = SCIProwGetConstant(row);
596 
597  SCIPdebugMsg(scip, " %s : lhs=%g, rhs=%g, maxval=%g \n", SCIProwGetName(row), matrix->lhs[i], matrix->rhs[i], maxval);
598  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, row, NULL) ) );
599  assert(!SCIPisInfinity(scip, constant));
600 
601  matrix->rowmatbegin[i] = currentpointer;
602 
603  /* modify the lhs and rhs w.r.t to the rows constant and normalize by 1-norm, i.e divide the lhs and rhs by the
604  * maximum absolute value of the row
605  */
606  if( !SCIPisInfinity(scip, -SCIProwGetLhs(row)) )
607  matrix->lhs[i] = SCIProwGetLhs(row) - constant;
608  else
609  matrix->lhs[i] = -SCIPinfinity(scip);
610 
611  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) )
612  matrix->rhs[i] = SCIProwGetRhs(row) - constant;
613  else
614  matrix->rhs[i] = SCIPinfinity(scip);
615 
616  /* make sure that maxval is larger than zero before normalization.
617  * Maxval may be zero if the constraint contains no variables but is modifiable, hence not redundant
618  */
619  if( normalize && !SCIPisFeasZero(scip, maxval) )
620  {
621  if( !SCIPisInfinity(scip, -matrix->lhs[i]) )
622  matrix->lhs[i] /= maxval;
623  if( !SCIPisInfinity(scip, matrix->rhs[i]) )
624  matrix->rhs[i] /= maxval;
625  }
626 
627  /* in case of empty rows with a 0 < lhs <= 0.0 or 0.0 <= rhs < 0 we deduce the infeasibility of the problem */
628  if( nrowlpnonz == 0 && (SCIPisFeasPositive(scip, matrix->lhs[i]) || SCIPisFeasNegative(scip, matrix->rhs[i])) )
629  {
630  *infeasible = TRUE;
631  SCIPdebugMsg(scip, " Matrix initialization stopped because of row infeasibility! \n");
632  break;
633  }
634 
635  /* row coefficients are normalized and copied to heuristic matrix */
636  for( j = 0; j < nrowlpnonz; ++j )
637  {
638  if( !colIsDiscrete(cols[j], impliscontinuous) )
639  continue;
640  assert(SCIPcolGetLPPos(cols[j]) >= 0);
641  assert(currentpointer < matrix->nnonzs);
642 
643  matrix->rowmatvals[currentpointer] = rowvals[j];
644  if( normalize && SCIPisFeasGT(scip, maxval, 0.0) )
645  matrix->rowmatvals[currentpointer] /= maxval;
646 
647  matrix->rowmatind[currentpointer] = colposs[SCIPcolGetLPPos(cols[j])];
648 
649  ++currentpointer;
650  }
651  }
652 
653  matrix->normalized = TRUE;
654 
655  if( *infeasible )
656  return SCIP_OKAY;
657 
658  assert(currentpointer == matrix->nnonzs);
659 
660  currentpointer = 0;
661 
662  /* copy the nonzero coefficient data column by column to heuristic matrix */
663  for( j = 0; j < matrix->ncols; ++j )
664  {
665  SCIP_COL* currentcol;
666  SCIP_ROW** rows;
667  SCIP_Real* colvals;
668  int ncolnonz;
669 
670  assert(SCIPcolGetLPPos(lpcols[j]) >= 0);
671 
672  currentcol = lpcols[j];
673  assert(colIsDiscrete(currentcol, impliscontinuous));
674 
675  colvals = SCIPcolGetVals(currentcol);
676  rows = SCIPcolGetRows(currentcol);
677  ncolnonz = SCIPcolGetNLPNonz(currentcol);
678  matrix->colnorms[j] = ncolnonz;
679 
680  *nmaxrows = MAX(*nmaxrows, ncolnonz);
681 
682  /* loop over all rows with nonzero coefficients in the column, transform them and add them to the heuristic matrix */
683  matrix->colmatbegin[j] = currentpointer;
684 
685  for( i = 0; i < ncolnonz; ++i )
686  {
687  SCIP_Real maxval;
688 
689  assert(rows[i] != NULL);
690  assert(0 <= SCIProwGetLPPos(rows[i]));
691  assert(SCIProwGetLPPos(rows[i]) < nrows);
692  assert(currentpointer < matrix->nnonzs);
693 
694  /* rows are normalized by maximum norm */
695  maxval = SCIPgetRowMaxCoef(scip, rows[i]);
696 
697  assert(maxval > 0);
698 
699  matrix->colmatvals[currentpointer] = colvals[i];
700  if( normalize && SCIPisFeasGT(scip, maxval, 0.0) )
701  matrix->colmatvals[currentpointer] /= maxval;
702 
703  matrix->colmatind[currentpointer] = SCIProwGetLPPos(rows[i]);
704 
705  /* update the column norm */
706  matrix->colnorms[j] += ABS(matrix->colmatvals[currentpointer]);
707  ++currentpointer;
708  }
709  }
710  assert(currentpointer == matrix->nnonzs);
711 
712  /* each variable is either transformed, if it supposed to be integral, or relaxed */
713  for( j = 0; j < (relax ? ncols : matrix->ndiscvars); ++j )
714  {
715  SCIP_COL* col;
716 
717  col = lpcols[j];
718  if( colIsDiscrete(col, impliscontinuous) )
719  {
720  matrix->transformshiftvals[j] = 0.0;
721  transformVariable(scip, matrix, heurdata, j);
722  }
723  else
724  {
725  SCIP_VAR* var;
726  var = SCIPcolGetVar(col);
727  assert(!varIsDiscrete(var, impliscontinuous));
728  relaxVar(scip, var, matrix, normalize);
729  }
730  }
731  *initialized = TRUE;
732 
733  SCIPdebugMsg(scip, "Matrix initialized for %d discrete variables with %d cols, %d rows and %d nonzero entries\n",
734  matrix->ndiscvars, matrix->ncols, matrix->nrows, matrix->nnonzs);
735  return SCIP_OKAY;
736 }
737 
738 /** frees all members of the heuristic matrix */
739 static
740 void freeMatrix(
741  SCIP* scip, /**< current SCIP instance */
742  CONSTRAINTMATRIX** matrix /**< constraint matrix object */
743  )
744 {
745  assert(scip != NULL);
746  assert(matrix != NULL);
747 
748  /* all fields are only allocated, if problem is not empty */
749  if( (*matrix)->nnonzs > 0 )
750  {
751  assert((*matrix) != NULL);
752  assert((*matrix)->rowmatbegin != NULL);
753  assert((*matrix)->rowmatvals != NULL);
754  assert((*matrix)->rowmatind != NULL);
755  assert((*matrix)->colmatbegin != NULL);
756  assert((*matrix)->colmatvals!= NULL);
757  assert((*matrix)->colmatind != NULL);
758  assert((*matrix)->lhs != NULL);
759  assert((*matrix)->rhs != NULL);
760  assert((*matrix)->transformstatus != NULL);
761  assert((*matrix)->transformshiftvals != NULL);
762 
763  /* free all fields */
764  SCIPfreeBufferArray(scip, &((*matrix)->transformshiftvals));
765  SCIPfreeBufferArray(scip, &((*matrix)->upperbounds));
766  SCIPfreeBufferArray(scip, &((*matrix)->transformstatus));
767  SCIPfreeBufferArray(scip, &((*matrix)->violrows));
768  SCIPfreeBufferArray(scip, &((*matrix)->colnorms));
769  SCIPfreeBufferArray(scip, &((*matrix)->rhs));
770  SCIPfreeBufferArray(scip, &((*matrix)->lhs));
771  SCIPfreeBufferArray(scip, &((*matrix)->colmatbegin));
772  SCIPfreeBufferArray(scip, &((*matrix)->colmatind));
773  SCIPfreeBufferArray(scip, &((*matrix)->colmatvals));
774  SCIPfreeBufferArray(scip, &((*matrix)->rowmatind));
775  SCIPfreeBufferArray(scip, &((*matrix)->rowmatvals));
776  SCIPfreeBufferArray(scip, &((*matrix)->rowmatbegin));
777 
778  (*matrix)->nrows = 0;
779  (*matrix)->ncols = 0;
780  }
781 
782  /* free matrix */
783  SCIPfreeBuffer(scip, matrix);
784 }
785 
786 /** updates the information about a row whenever violation status changes */
787 static
788 void checkRowViolation(
789  SCIP* scip, /**< current SCIP instance */
790  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
791  int rowindex, /**< index of the row */
792  int* violatedrows, /**< contains all violated rows */
793  int* violatedrowpos, /**< positions of rows in the violatedrows array */
794  int* nviolatedrows, /**< pointer to update total number of violated rows */
795  int* rowweights, /**< row weight storage */
796  SCIP_Bool updateweights /**< should row weight be increased every time the row is violated? */
797  )
798 {
799  int* cols;
800  int ncols;
801  int c;
802  int violadd;
803  assert(matrix != NULL);
804  assert(violatedrows != NULL);
805  assert(violatedrowpos != NULL);
806  assert(nviolatedrows != NULL);
807 
808  getRowData(matrix, rowindex, NULL, NULL, NULL, &cols, &ncols);
809  violadd = 0;
810 
811  /* row is now violated. Enqueue it in the set of violated rows. */
812  if( violatedrowpos[rowindex] == -1 && (SCIPisFeasGT(scip, matrix->lhs[rowindex], 0.0) || SCIPisFeasLT(scip, matrix->rhs[rowindex], 0.0)) )
813  {
814  assert(*nviolatedrows < matrix->nrows);
815 
816  violatedrows[*nviolatedrows] = rowindex;
817  violatedrowpos[rowindex] = *nviolatedrows;
818  ++(*nviolatedrows);
819  if( updateweights )
820  ++rowweights[rowindex];
821 
822  violadd = 1;
823  }
824  /* row is now feasible. Remove it from the set of violated rows. */
825  else if( violatedrowpos[rowindex] >= 0 && SCIPisFeasLE(scip, matrix->lhs[rowindex], 0.0) && SCIPisFeasGE(scip, matrix->rhs[rowindex], 0.0) )
826  {
827  /* swap the row with last violated row */
828  if( violatedrowpos[rowindex] != *nviolatedrows - 1 )
829  {
830  assert(*nviolatedrows - 1 >= 0);
831  violatedrows[violatedrowpos[rowindex]] = violatedrows[*nviolatedrows - 1];
832  violatedrowpos[violatedrows[*nviolatedrows - 1]] = violatedrowpos[rowindex];
833  }
834 
835  /* unlink the row from its position in the array and decrease number of violated rows */
836  violatedrowpos[rowindex] = -1;
837  --(*nviolatedrows);
838  violadd = -1;
839  }
840 
841  /* increase or decrease the column violation counter */
842  for( c = 0; c < ncols; ++c )
843  {
844  matrix->violrows[cols[c]] += violadd;
845  assert(matrix->violrows[cols[c]] >= 0);
846  }
847 }
848 
849 /** collects the necessary information about row violations for the zero-solution. That is,
850  * all solution values in heuristic transformation are zero.
851  */
852 static
853 void checkViolations(
854  SCIP* scip, /**< current scip instance */
855  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
856  int colidx, /**< column index for specific column, or -1 for all rows */
857  int* violatedrows, /**< violated rows */
858  int* violatedrowpos, /**< row positions of violated rows */
859  int* nviolatedrows, /**< pointer to store the number of violated rows */
860  int* rowweights, /**< weight array for every row */
861  SCIP_Bool updateweights /**< should row weight be increased every time the row is violated? */
862  )
863 {
864  int nrows;
865  int* rowindices;
866  int i;
867 
868  assert(matrix != NULL);
869  assert(violatedrows != NULL);
870  assert(violatedrowpos != NULL);
871  assert(nviolatedrows != NULL);
872  assert(-1 <= colidx && colidx < matrix->ncols);
873 
874  /* check if we requested an update for a single variable, or if we want to (re)-initialize the whole violation info */
875  if( colidx >= 0 )
876  getColumnData(matrix, colidx, NULL, &rowindices, &nrows);
877  else
878  {
879  nrows = matrix->nrows;
880  rowindices = NULL;
881  *nviolatedrows = 0;
882 
883  /* reinitialize the violated rows */
884  for( i = 0; i < nrows; ++i )
885  violatedrowpos[i] = -1;
886 
887  /* clear the violated row counters for all variables */
888  BMSclearMemoryArray(matrix->violrows, matrix->ndiscvars);
889  }
890 
891  assert(colidx < 0 || *nviolatedrows >= 0);
892  SCIPdebugMsg(scip, "Entering violation check for %d rows! \n", nrows);
893  /* loop over rows and check if it is violated */
894  for( i = 0; i < nrows; ++i )
895  {
896  int rowpos;
897  if( colidx >= 0 )
898  {
899  assert(rowindices != NULL);
900  rowpos = rowindices[i];
901  }
902  else
903  rowpos = i;
904  /* check, if zero solution violates this row */
905  checkRowViolation(scip, matrix, rowpos, violatedrows, violatedrowpos, nviolatedrows, rowweights, updateweights);
906 
907  assert((violatedrowpos[rowpos] == -1 && SCIPisFeasGE(scip, matrix->rhs[rowpos], 0.0) && SCIPisFeasLE(scip, matrix->lhs[rowpos], 0.0))
908  || (violatedrowpos[rowpos] >= 0 &&(SCIPisFeasLT(scip, matrix->rhs[rowpos], 0.0) || SCIPisFeasGT(scip, matrix->lhs[rowpos], 0.0))));
909  }
910 }
911 
912 /** retransforms solution values of variables according to their transformation status */
913 static
915  SCIP* scip, /**< current scip instance */
916  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
917  SCIP_VAR* var, /**< variable whose solution value has to be retransformed */
918  int varindex, /**< permutation of variable indices according to sorting */
919  SCIP_Real solvalue /**< solution value of the variable */
920  )
921 {
922  TRANSFORMSTATUS status;
923 
924  assert(matrix != NULL);
925  assert(var != NULL);
926 
927  status = matrix->transformstatus[varindex];
928  assert(status != TRANSFORMSTATUS_NONE);
929 
930  /* check if original variable has different bounds and transform solution value correspondingly */
931  if( status == TRANSFORMSTATUS_LB )
932  {
933  assert(!SCIPisInfinity(scip, -SCIPvarGetLbLocal(var)));
934 
935  return solvalue + matrix->transformshiftvals[varindex];
936  }
937  else if( status == TRANSFORMSTATUS_NEG )
938  {
939  assert(!SCIPisInfinity(scip, SCIPvarGetUbLocal(var)));
940  return matrix->transformshiftvals[varindex] - solvalue;
941  }
942  return solvalue;
943 }
944 
945 /** determines the best shifting value of a variable
946  * @todo if there is already an incumbent solution, try considering the objective cutoff as additional constraint */
947 static
949  SCIP* scip, /**< current scip instance */
950  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
951  int varindex, /**< index of variable which should be shifted */
952  int direction, /**< the direction for this variable */
953  int* rowweights, /**< weighting of rows for best shift calculation */
954  SCIP_Real* steps, /**< buffer array to store the individual steps for individual rows */
955  int* violationchange, /**< buffer array to store the individual change of feasibility of row */
956  SCIP_Real* beststep, /**< pointer to store optimal shifting step */
957  int* rowviolations /**< pointer to store new weighted sum of row violations, i.e, v - f */
958  )
959 {
960  SCIP_Real* vals;
961  int* rows;
962 
963  SCIP_Real slacksurplus;
964  SCIP_Real upperbound;
965 
966  int nrows;
967  int sum;
968  int i;
969 
970  SCIP_Bool allzero;
971 
972  assert(beststep != NULL);
973  assert(rowviolations != NULL);
974  assert(rowweights != NULL);
975  assert(steps != NULL);
976  assert(violationchange != NULL);
977  assert(direction == 1 || direction == -1);
978 
979  upperbound = matrix->upperbounds[varindex];
980 
981  /* get nonzero values and corresponding rows of variable */
982  getColumnData(matrix, varindex, &vals, &rows, &nrows);
983 
984  /* loop over rows and calculate, which is the minimum shift to make this row feasible
985  * or the minimum shift to violate this row
986  */
987  allzero = TRUE;
988  slacksurplus = 0.0;
989  for( i = 0; i < nrows; ++i )
990  {
991  SCIP_Real lhs;
992  SCIP_Real rhs;
993  SCIP_Real val;
994  int rowpos;
995  SCIP_Bool rowisviolated;
996  int rowweight;
997 
998  /* get the row data */
999  rowpos = rows[i];
1000  assert(rowpos >= 0);
1001  lhs = matrix->lhs[rowpos];
1002  rhs = matrix->rhs[rowpos];
1003  rowweight = rowweights[rowpos];
1004  val = direction * vals[i];
1005 
1006  /* determine if current row is violated or not */
1007  rowisviolated =(SCIPisFeasLT(scip, rhs, 0.0) || SCIPisFeasLT(scip, -lhs, 0.0));
1008 
1009  /* for a feasible row, determine the minimum integer value within the bounds of the variable by which it has to be
1010  * shifted to make row infeasible.
1011  */
1012  if( !rowisviolated )
1013  {
1014  SCIP_Real maxfeasshift;
1015 
1016  maxfeasshift = SCIPinfinity(scip);
1017 
1018  /* feasibility can only be violated if the variable has a lock in the corresponding direction,
1019  * i.e. a positive coefficient for a "<="-constraint, a negative coefficient for a ">="-constraint.
1020  */
1021  if( SCIPisFeasGT(scip, val, 0.0) && !SCIPisInfinity(scip, rhs) )
1022  maxfeasshift = SCIPfeasFloor(scip, rhs/val);
1023  else if( SCIPisFeasLT(scip, val, 0.0) && !SCIPisInfinity(scip, -lhs) )
1024  maxfeasshift = SCIPfeasFloor(scip, lhs/val);
1025 
1026  /* if the variable has no lock in the current row, it can still help to increase the slack of this row;
1027  * we measure slack increase for shifting by one
1028  */
1029  if( SCIPisFeasGT(scip, val, 0.0) && SCIPisInfinity(scip, rhs) )
1030  slacksurplus += val;
1031  if( SCIPisFeasLT(scip, val, 0.0) && SCIPisInfinity(scip, -lhs) )
1032  slacksurplus -= val;
1033 
1034  /* check if the least violating shift lies within variable bounds and set corresponding array values */
1035  if( !SCIPisInfinity(scip, maxfeasshift) && SCIPisFeasLE(scip, maxfeasshift + 1.0, upperbound) )
1036  {
1037  steps[i] = maxfeasshift + 1.0;
1038  violationchange[i] = rowweight;
1039  allzero = FALSE;
1040  }
1041  else
1042  {
1043  steps[i] = upperbound;
1044  violationchange[i] = 0;
1045  }
1046  }
1047  /* for a violated row, determine the minimum integral value within the bounds of the variable by which it has to be
1048  * shifted to make row feasible.
1049  */
1050  else
1051  {
1052  SCIP_Real minfeasshift;
1053 
1054  minfeasshift = SCIPinfinity(scip);
1055 
1056  /* if coefficient has the right sign to make row feasible, determine the minimum integer to shift variable
1057  * to obtain feasibility
1058  */
1059  if( SCIPisFeasLT(scip, -lhs, 0.0) && SCIPisFeasGT(scip, val, 0.0) )
1060  minfeasshift = SCIPfeasCeil(scip, lhs/val);
1061  else if( SCIPisFeasLT(scip, rhs,0.0) && SCIPisFeasLT(scip, val, 0.0) )
1062  minfeasshift = SCIPfeasCeil(scip, rhs/val);
1063 
1064  /* check if the minimum feasibility recovery shift lies within variable bounds and set corresponding array
1065  * values
1066  */
1067  if( !SCIPisInfinity(scip, minfeasshift) && SCIPisFeasLE(scip, minfeasshift, upperbound) )
1068  {
1069  steps[i] = minfeasshift;
1070  violationchange[i] = -rowweight;
1071  allzero = FALSE;
1072  }
1073  else
1074  {
1075  steps[i] = upperbound;
1076  violationchange[i] = 0;
1077  }
1078  }
1079  }
1080 
1081  /* in case that the variable cannot affect the feasibility of any row, in particular it cannot violate
1082  * a single row, but we can add slack to already feasible rows, we will do this
1083  */
1084  if( allzero )
1085  {
1086  if( ! SCIPisInfinity(scip, upperbound) && SCIPisGT(scip, slacksurplus, 0.0) )
1087  *beststep = direction * upperbound;
1088  else
1089  *beststep = 0.0;
1090 
1091  return SCIP_OKAY;
1092  }
1093 
1094  /* sorts rows by increasing value of steps */
1095  SCIPsortRealInt(steps, violationchange, nrows);
1096 
1097  *beststep = 0.0;
1098  *rowviolations = 0;
1099  sum = 0;
1100 
1101  /* best shifting step is calculated by summing up the violation changes for each relevant step and
1102  * taking the one which leads to the minimum sum. This sum measures the balance of feasibility recovering and
1103  * violating changes which will be obtained by shifting the variable by this step
1104  * note, the sums for smaller steps have to be taken into account for all bigger steps, i.e., the sums can be
1105  * computed iteratively
1106  */
1107  for( i = 0; i < nrows && !SCIPisInfinity(scip, steps[i]); ++i )
1108  {
1109  sum += violationchange[i];
1110 
1111  /* if we reached the last entry for the current step value, we have finished computing its sum and
1112  * update the step defining the minimum sum
1113  */
1114  if( (i == nrows-1 || steps[i+1] > steps[i]) && sum < *rowviolations ) /*lint !e679*/
1115  {
1116  *rowviolations = sum;
1117  *beststep = direction * steps[i];
1118  }
1119  }
1120  assert(*rowviolations <= 0);
1121  assert(!SCIPisInfinity(scip, *beststep));
1122 
1123  return SCIP_OKAY;
1124 }
1125 
1126 /** updates transformation of a given variable by taking into account current local bounds. if the bounds have changed
1127  * since last update, updating the heuristic specific upper bound of the variable, its current transformed solution value
1128  * and all affected rows is necessary.
1129  */
1130 static
1132  SCIP* scip, /**< current scip */
1133  CONSTRAINTMATRIX* matrix, /**< constraint matrix object */
1134  SCIP_HEURDATA* heurdata, /**< heuristic data */
1135  int varindex, /**< index of variable in matrix */
1136  SCIP_Real lb, /**< local lower bound of the variable */
1137  SCIP_Real ub, /**< local upper bound of the variable */
1138  int* violatedrows, /**< violated rows */
1139  int* violatedrowpos, /**< violated row positions */
1140  int* nviolatedrows /**< pointer to store number of violated rows */
1141  )
1142 {
1143  TRANSFORMSTATUS status;
1144  SCIP_Real deltashift;
1145  SCIP_Bool checkviolations;
1146 
1147  assert(scip != NULL);
1148  assert(matrix != NULL);
1149  assert(0 <= varindex && varindex < matrix->ndiscvars);
1150 
1151  /* deltashift is the difference between the old and new transformation value. */
1152  deltashift = 0.0;
1153  status = matrix->transformstatus[varindex];
1154 
1155  SCIPdebugMsg(scip, " Variable <%d> [%g,%g], status %d(%g), ub %g \n", varindex, lb, ub, status,
1156  matrix->transformshiftvals[varindex], matrix->upperbounds[varindex]);
1157 
1158  checkviolations = FALSE;
1159  /* depending on the variable status, deltashift is calculated differently. */
1160  switch( status )
1161  {
1162  case TRANSFORMSTATUS_LB:
1163  if( SCIPisInfinity(scip, -lb) )
1164  {
1165  transformVariable(scip, matrix, heurdata, varindex);
1166  checkviolations = TRUE;
1167  }
1168  else
1169  {
1170  deltashift = lb - (matrix->transformshiftvals[varindex]);
1171  matrix->transformshiftvals[varindex] = lb;
1172  if( !SCIPisInfinity(scip, ub) )
1173  matrix->upperbounds[varindex] = ub - lb;
1174  else
1175  matrix->upperbounds[varindex] = SCIPinfinity(scip);
1176  }
1177  break;
1178  case TRANSFORMSTATUS_NEG:
1179  if( SCIPisInfinity(scip, ub) )
1180  {
1181  transformVariable(scip, matrix, heurdata, varindex);
1182  checkviolations = TRUE;
1183  }
1184  else
1185  {
1186  deltashift = (matrix->transformshiftvals[varindex]) - ub;
1187  matrix->transformshiftvals[varindex] = ub;
1188 
1189  if( !SCIPisInfinity(scip, -lb) )
1190  matrix->upperbounds[varindex] = ub - lb;
1191  else
1192  matrix->upperbounds[varindex] = SCIPinfinity(scip);
1193  }
1194  break;
1195  case TRANSFORMSTATUS_FREE:
1196  /* in case of a free transform status, if one of the bounds has become finite, we want
1197  * to transform this variable to a variable with a lowerbound or a negated transform status */
1198  if( !SCIPisInfinity(scip, -lb) || !SCIPisInfinity(scip, ub) )
1199  {
1200  transformVariable(scip, matrix, heurdata, varindex);
1201 
1202  /* violations have to be rechecked for rows in which variable appears */
1203  checkviolations = TRUE;
1204 
1205  assert(matrix->transformstatus[varindex] == TRANSFORMSTATUS_LB || TRANSFORMSTATUS_NEG);
1206  assert(SCIPisFeasLE(scip, ABS(lb), ABS(ub)) || matrix->transformstatus[varindex] == TRANSFORMSTATUS_NEG);
1207  }
1208  break;
1209 
1210  case TRANSFORMSTATUS_NONE:
1211  default:
1212  SCIPerrorMessage("Error: Invalid variable status <%d> in shift and propagagate heuristic, aborting!\n");
1213  SCIPABORT();
1214  return SCIP_INVALIDDATA; /*lint !e527*/
1215  }
1216  /* if the bound, by which the variable was shifted, has changed, deltashift is different from zero, which requires
1217  * an update of all affected rows
1218  */
1219  if( !SCIPisFeasZero(scip, deltashift) )
1220  {
1221  int i;
1222  int* rows;
1223  SCIP_Real* vals;
1224  int nrows;
1225 
1226  /* get nonzero values and corresponding rows of variable */
1227  getColumnData(matrix, varindex, &vals, &rows, &nrows);
1228 
1229  /* go through rows, update the rows w.r.t. the influence of the changed transformation of the variable */
1230  for( i = 0; i < nrows; ++i )
1231  {
1232  SCIPdebugMsg(scip, " update slacks of row<%d>: coefficient <%g>, %g <= 0 <= %g \n",
1233  rows[i], vals[i], matrix->lhs[rows[i]], matrix->rhs[rows[i]]);
1234 
1235  if( !SCIPisInfinity(scip, -(matrix->lhs[rows[i]])) )
1236  matrix->lhs[rows[i]] -= (vals[i]) * deltashift;
1237 
1238  if( !SCIPisInfinity(scip, matrix->rhs[rows[i]]) )
1239  matrix->rhs[rows[i]] -= (vals[i]) * deltashift;
1240  }
1241  checkviolations = TRUE;
1242  }
1243 
1244  /* check and update information about violated rows, if necessary */
1245  if( checkviolations )
1246  checkViolations(scip, matrix, varindex, violatedrows, violatedrowpos, nviolatedrows, heurdata->rowweights, heurdata->updateweights);
1247 
1248  SCIPdebugMsg(scip, " Variable <%d> [%g,%g], status %d(%g), ub %g \n", varindex, lb, ub, status,
1249  matrix->transformshiftvals[varindex], matrix->upperbounds[varindex]);
1250 
1251  return SCIP_OKAY;
1252 }
1253 
1254 /** comparison method for columns; binary < integer < implicit < continuous variables */
1255 static
1256 SCIP_DECL_SORTPTRCOMP(heurSortColsShiftandpropagate)
1258  SCIP_COL* col1;
1259  SCIP_COL* col2;
1260  SCIP_VAR* var1;
1261  SCIP_VAR* var2;
1262  SCIP_VARTYPE vartype1;
1263  SCIP_VARTYPE vartype2;
1264  int key1;
1265  int key2;
1266 
1267  col1 = (SCIP_COL*)elem1;
1268  col2 = (SCIP_COL*)elem2;
1269  var1 = SCIPcolGetVar(col1);
1270  var2 = SCIPcolGetVar(col2);
1271  assert(var1 != NULL && var2 != NULL);
1272 
1273  vartype1 = SCIPvarGetType(var1);
1274  vartype2 = SCIPvarGetType(var2);
1275 
1276  switch (vartype1)
1277  {
1278  case SCIP_VARTYPE_BINARY:
1279  key1 = 1;
1280  break;
1281  case SCIP_VARTYPE_INTEGER:
1282  key1 = 2;
1283  break;
1284  case SCIP_VARTYPE_IMPLINT:
1285  key1 = 3;
1286  break;
1288  key1 = 4;
1289  break;
1290  default:
1291  key1 = -1;
1292  SCIPerrorMessage("unknown variable type\n");
1293  SCIPABORT();
1294  break;
1295  }
1296  switch (vartype2)
1297  {
1298  case SCIP_VARTYPE_BINARY:
1299  key2 = 1;
1300  break;
1301  case SCIP_VARTYPE_INTEGER:
1302  key2 = 2;
1303  break;
1304  case SCIP_VARTYPE_IMPLINT:
1305  key2 = 3;
1306  break;
1308  key2 = 4;
1309  break;
1310  default:
1311  key2 = -1;
1312  SCIPerrorMessage("unknown variable type\n");
1313  SCIPABORT();
1314  break;
1315  }
1316  return key1 - key2;
1317 }
1318 
1319 /*
1320  * Callback methods of primal heuristic
1321  */
1322 
1323 /** deinitialization method of primal heuristic(called before transformed problem is freed) */
1324 static
1325 SCIP_DECL_HEUREXIT(heurExitShiftandpropagate)
1326 { /*lint --e{715}*/
1327  SCIP_HEURDATA* heurdata;
1328 
1329  heurdata = SCIPheurGetData(heur);
1330  assert(heurdata != NULL);
1331 
1332  /* free random number generator */
1333  SCIPfreeRandom(scip, &heurdata->randnumgen);
1334 
1335  /* if statistic mode is enabled, statistics are printed to console */
1336  SCIPstatistic(
1338  " DETAILS : %d violations left, %d probing status\n",
1339  heurdata->nremainingviols,
1340  heurdata->lpsolstat
1341  );
1343  " SHIFTANDPROPAGATE PROBING : %d probings, %" SCIP_LONGINT_FORMAT " domain reductions, ncutoffs: %d , LP iterations: %" SCIP_LONGINT_FORMAT " \n ",
1344  heurdata->nprobings,
1345  heurdata->ntotaldomredsfound,
1346  heurdata->ncutoffs,
1347  heurdata->nlpiters);
1348  );
1349 
1350  return SCIP_OKAY;
1351 }
1352 
1353 /** initialization method of primal heuristic(called after problem was transformed). We only need this method for
1354  * statistic mode of heuristic.
1355  */
1356 static
1357 SCIP_DECL_HEURINIT(heurInitShiftandpropagate)
1358 { /*lint --e{715}*/
1359  SCIP_HEURDATA* heurdata;
1360 
1361  heurdata = SCIPheurGetData(heur);
1362 
1363  assert(heurdata != NULL);
1364 
1365  /* create random number generator */
1366  SCIP_CALL( SCIPcreateRandom(scip, &heurdata->randnumgen,
1367  DEFAULT_RANDSEED, TRUE) );
1368 
1369  SCIPstatistic(
1370  heurdata->lpsolstat = SCIP_LPSOLSTAT_NOTSOLVED;
1371  heurdata->nremainingviols = 0;
1372  heurdata->nprobings = 0;
1373  heurdata->ntotaldomredsfound = 0;
1374  heurdata->ncutoffs = 0;
1375  heurdata->nlpiters = 0;
1376  )
1377  return SCIP_OKAY;
1378 }
1379 
1380 /** destructor of primal heuristic to free user data(called when SCIP is exiting) */
1381 static
1382 SCIP_DECL_HEURFREE(heurFreeShiftandpropagate)
1383 { /*lint --e{715}*/
1384  SCIP_HEURDATA* heurdata;
1385  SCIP_EVENTHDLR* eventhdlr;
1386  SCIP_EVENTHDLRDATA* eventhdlrdata;
1387 
1388  heurdata = SCIPheurGetData(heur);
1389  assert(heurdata != NULL);
1390  eventhdlr = heurdata->eventhdlr;
1391  assert(eventhdlr != NULL);
1392  eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
1393 
1394  SCIPfreeBlockMemoryNull(scip, &eventhdlrdata);
1395 
1396  /* free heuristic data */
1397  SCIPfreeBlockMemory(scip, &heurdata);
1398 
1399  SCIPheurSetData(heur, NULL);
1400 
1401  return SCIP_OKAY;
1402 }
1403 
1404 
1405 /** copy method for primal heuristic plugins(called when SCIP copies plugins) */
1406 static
1407 SCIP_DECL_HEURCOPY(heurCopyShiftandpropagate)
1408 { /*lint --e{715}*/
1409  assert(scip != NULL);
1410  assert(heur != NULL);
1411  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
1412 
1413  /* call inclusion method of primal heuristic */
1415 
1416  return SCIP_OKAY;
1417 }
1418 
1419 /** execution method of primal heuristic */
1420 static
1421 SCIP_DECL_HEUREXEC(heurExecShiftandpropagate)
1422 { /*lint --e{715}*/
1423  SCIP_HEURDATA* heurdata; /* heuristic data */
1424  SCIP_EVENTHDLR* eventhdlr; /* shiftandpropagate event handler */
1425  SCIP_EVENTHDLRDATA* eventhdlrdata; /* event handler data */
1426  SCIP_EVENTDATA** eventdatas; /* event data for every variable */
1427 
1428  CONSTRAINTMATRIX* matrix; /* constraint matrix object */
1429  SCIP_COL** lpcols; /* lp columns */
1430  SCIP_SOL* sol; /* solution pointer */
1431  SCIP_Real* colnorms; /* contains Euclidean norms of column vectors */
1432 
1433  SCIP_Real* steps; /* buffer arrays for best shift selection in main loop */
1434  int* violationchange;
1435 
1436  int* violatedrows; /* the violated rows */
1437  int* violatedrowpos; /* the array position of a violated row, or -1 */
1438  int* permutation; /* reflects the position of the variables after sorting */
1439  int* violatedvarrows; /* number of violated rows for each variable */
1440  int* colposs; /* position of columns according to variable type sorting */
1441  int nlpcols; /* number of lp columns */
1442  int nviolatedrows; /* number of violated rows */
1443  int ndiscvars; /* number of non-continuous variables of the problem */
1444  int lastindexofsusp; /* last variable which has been swapped due to a cutoff */
1445  int nbinvars; /* number of binary variables */
1446  int nintvars; /* number of integer variables */
1447  int i;
1448  int r;
1449  int v;
1450  int c;
1451  int ncutoffs; /* counts the number of cutoffs for this execution */
1452  int nprobings; /* counts the number of probings */
1453  int nlprows; /* the number LP rows */
1454  int nmaxrows; /* maximum number of LP rows of a variable */
1455 
1456  SCIP_Bool initialized; /* has the matrix been initialized? */
1457  SCIP_Bool cutoff; /* has current probing node been cutoff? */
1458  SCIP_Bool probing; /* should probing be applied or not? */
1459  SCIP_Bool infeasible; /* FALSE as long as currently infeasible rows have variables left */
1460  SCIP_Bool impliscontinuous;
1461 
1462  heurdata = SCIPheurGetData(heur);
1463  assert(heurdata != NULL);
1464 
1465  eventhdlr = heurdata->eventhdlr;
1466  assert(eventhdlr != NULL);
1467 
1468  eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
1469  assert(eventhdlrdata != NULL);
1470 
1471  *result = SCIP_DIDNOTRUN;
1472  SCIPdebugMsg(scip, "entering execution method of shift and propagate heuristic\n");
1473 
1474  /* heuristic is obsolete if there are only continuous variables */
1475  if( SCIPgetNVars(scip) - SCIPgetNContVars(scip) == 0 )
1476  return SCIP_OKAY;
1477 
1478  /* stop execution method if there is already a primarily feasible solution at hand */
1479  if( SCIPgetBestSol(scip) != NULL && heurdata->onlywithoutsol )
1480  return SCIP_OKAY;
1481 
1482  /* stop if there is no LP available */
1483  if ( ! SCIPhasCurrentNodeLP(scip) )
1484  return SCIP_OKAY;
1485 
1486  if( !SCIPisLPConstructed(scip) )
1487  {
1488  /* @note this call can have the side effect that variables are created */
1489  SCIP_CALL( SCIPconstructLP(scip, &cutoff) );
1490 
1491  /* manually cut off the node if the LP construction detected infeasibility (heuristics cannot return such a result) */
1492  if( cutoff )
1493  {
1495  return SCIP_OKAY;
1496  }
1497 
1498  SCIP_CALL( SCIPflushLP(scip) );
1499  }
1500 
1501  SCIPstatistic( heurdata->nlpiters = SCIPgetNLPIterations(scip) );
1502 
1503  nlprows = SCIPgetNLPRows(scip);
1504 
1505  SCIP_CALL( SCIPgetLPColsData(scip, &lpcols, &nlpcols) );
1506  assert(nlpcols == 0 || lpcols != NULL);
1507 
1508  /* we need an LP */
1509  if( nlprows == 0 || nlpcols == 0 )
1510  return SCIP_OKAY;
1511 
1512  *result = SCIP_DIDNOTFIND;
1513  initialized = FALSE;
1514 
1515  /* allocate lp column array */
1516  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->lpcols, nlpcols) );
1517  heurdata->nlpcols = nlpcols;
1518 
1519  impliscontinuous = heurdata->impliscontinuous;
1520 
1521 #ifndef NDEBUG
1522  BMSclearMemoryArray(heurdata->lpcols, nlpcols);
1523 #endif
1524 
1525  /* copy and sort the columns by their variable types (binary before integer before implicit integer before continuous) */
1526  BMScopyMemoryArray(heurdata->lpcols, lpcols, nlpcols);
1527 
1528  SCIPsortPtr((void**)heurdata->lpcols, heurSortColsShiftandpropagate, nlpcols);
1529 
1530  SCIP_CALL( SCIPallocBufferArray(scip, &colposs, nlpcols) );
1531 
1532  /* we have to collect the number of different variable types before we start probing since during probing variable
1533  * can be created (e.g., cons_xor.c)
1534  */
1535  ndiscvars = 0;
1536  nbinvars = 0;
1537  nintvars = 0;
1538  for( c = 0; c < nlpcols; ++c )
1539  {
1540  SCIP_COL* col;
1541  SCIP_VAR* colvar;
1542 
1543  col = heurdata->lpcols[c];
1544  assert(col != NULL);
1545  colvar = SCIPcolGetVar(col);
1546  assert(colvar != NULL);
1547 
1548  if( varIsDiscrete(colvar, impliscontinuous) )
1549  ++ndiscvars;
1550  if( SCIPvarGetType(colvar) == SCIP_VARTYPE_BINARY )
1551  ++nbinvars;
1552  else if( SCIPvarGetType(colvar) == SCIP_VARTYPE_INTEGER )
1553  ++nintvars;
1554 
1555  /* save the position of this column in the array such that it can be accessed as the "true" column position */
1556  assert(SCIPcolGetLPPos(col) >= 0);
1557  colposs[SCIPcolGetLPPos(col)] = c;
1558  }
1559  assert(nbinvars + nintvars <= ndiscvars);
1560 
1561  /* start probing mode */
1562  SCIP_CALL( SCIPstartProbing(scip) );
1563 
1564  /* enables collection of variable statistics during probing */
1565  if( heurdata->collectstats )
1566  SCIPenableVarHistory(scip);
1567  else
1568  SCIPdisableVarHistory(scip);
1569 
1570  /* this should always be fulfilled becase we perform shift and propagate only at the root node */
1571  assert(SCIP_MAXTREEDEPTH > SCIPgetDepth(scip));
1572 
1573  /* @todo check if this node is necessary (I don't think so) */
1574  SCIP_CALL( SCIPnewProbingNode(scip) );
1575  ncutoffs = 0;
1576  nprobings = 0;
1577  nmaxrows = 0;
1578  infeasible = FALSE;
1579 
1580  /* initialize heuristic matrix and working solution */
1581  SCIP_CALL( SCIPallocBuffer(scip, &matrix) );
1582  SCIP_CALL( initMatrix(scip, matrix, heurdata, colposs, heurdata->normalize, &nmaxrows, heurdata->relax, &initialized, &infeasible) );
1583 
1584  /* the column positions are not needed anymore */
1585  SCIPfreeBufferArray(scip, &colposs);
1586 
1587  /* could not initialize matrix */
1588  if( !initialized || infeasible )
1589  {
1590  SCIPdebugMsg(scip, " MATRIX not initialized -> Execution of heuristic stopped! \n");
1591  goto TERMINATE;
1592  }
1593 
1594  /* the number of discrete LP column variables can be less than the actual number of variables, if, e.g., there
1595  * are nonlinearities in the problem. The heuristic execution can be terminated in that case.
1596  */
1597  if( matrix->ndiscvars < ndiscvars )
1598  {
1599  SCIPdebugMsg(scip, "Not all discrete variables are in the current LP. Shiftandpropagate execution terminated.\n");
1600  goto TERMINATE;
1601  }
1602 
1603  assert(nmaxrows > 0);
1604 
1605  eventhdlrdata->matrix = matrix;
1606  eventhdlrdata->heurdata = heurdata;
1607 
1608  SCIP_CALL( SCIPcreateSol(scip, &sol, heur) );
1609  SCIPsolSetHeur(sol, heur);
1610 
1611  /* allocate arrays for execution method */
1612  SCIP_CALL( SCIPallocBufferArray(scip, &permutation, ndiscvars) );
1613  SCIP_CALL( SCIPallocBufferArray(scip, &heurdata->rowweights, matrix->nrows) );
1614 
1615  /* allocate necessary memory for best shift search */
1616  SCIP_CALL( SCIPallocBufferArray(scip, &steps, nmaxrows) );
1617  SCIP_CALL( SCIPallocBufferArray(scip, &violationchange, nmaxrows) );
1618 
1619  /* allocate arrays to store information about infeasible rows */
1620  SCIP_CALL( SCIPallocBufferArray(scip, &violatedrows, matrix->nrows) );
1621  SCIP_CALL( SCIPallocBufferArray(scip, &violatedrowpos, matrix->nrows) );
1622 
1623  eventhdlrdata->violatedrows = violatedrows;
1624  eventhdlrdata->violatedrowpos = violatedrowpos;
1625  eventhdlrdata->nviolatedrows = &nviolatedrows;
1626 
1627  /* initialize arrays. Before sorting, permutation is the identity permutation */
1628  for( i = 0; i < ndiscvars; ++i )
1629  permutation[i] = i;
1630 
1631  /* initialize row weights */
1632  for( r = 0; r < matrix->nrows; ++r )
1633  {
1634  if( !SCIPisInfinity(scip, -(matrix->lhs[r])) && !SCIPisInfinity(scip, matrix->rhs[r]) )
1635  heurdata->rowweights[r] = DEFAULT_WEIGHT_EQUALITY;
1636  else
1637  heurdata->rowweights[r] = DEFAULT_WEIGHT_INEQUALITY;
1638  }
1639  colnorms = matrix->colnorms;
1640 
1641  assert(nbinvars >= 0);
1642  assert(nintvars >= 0);
1643 
1644  /* check rows for infeasibility */
1645  checkViolations(scip, matrix, -1, violatedrows, violatedrowpos, &nviolatedrows, heurdata->rowweights, heurdata->updateweights);
1646 
1647  /* allocate memory for violatedvarrows array only if variable ordering relies on it */
1648  if( heurdata->sortvars && (heurdata->sortkey == 't' || heurdata->sortkey == 'v') )
1649  {
1650  SCIP_CALL( SCIPallocBufferArray(scip, &violatedvarrows, ndiscvars) );
1651  BMScopyMemoryArray(violatedvarrows, matrix->violrows, ndiscvars);
1652  }
1653  else
1654  violatedvarrows = NULL;
1655 
1656  /* sort variables w.r.t. the sorting key parameter. Sorting is indirect, all matrix column data
1657  * stays in place, but permutation array gives access to the sorted order of variables
1658  */
1659  if( heurdata->sortvars )
1660  {
1661  switch (heurdata->sortkey)
1662  {
1663  case 'n':
1664  /* variable ordering w.r.t. column norms nonincreasing */
1665  if( heurdata->preferbinaries )
1666  {
1667  if( nbinvars > 0 )
1668  SCIPsortDownRealInt(colnorms, permutation, nbinvars);
1669  if( nbinvars < ndiscvars )
1670  SCIPsortDownRealInt(&colnorms[nbinvars], &permutation[nbinvars], ndiscvars - nbinvars);
1671  }
1672  else
1673  {
1674  SCIPsortDownRealInt(colnorms, permutation, ndiscvars);
1675  }
1676  SCIPdebugMsg(scip, "Variables sorted down w.r.t their normalized columns!\n");
1677  break;
1678  case 'u':
1679  /* variable ordering w.r.t. column norms nondecreasing */
1680  if( heurdata->preferbinaries )
1681  {
1682  if( nbinvars > 0 )
1683  SCIPsortRealInt(colnorms, permutation, nbinvars);
1684  if( nbinvars < ndiscvars )
1685  SCIPsortRealInt(&colnorms[nbinvars], &permutation[nbinvars], ndiscvars - nbinvars);
1686  }
1687  else
1688  {
1689  SCIPsortRealInt(colnorms, permutation, ndiscvars);
1690  }
1691  SCIPdebugMsg(scip, "Variables sorted w.r.t their normalized columns!\n");
1692  break;
1693  case 'v':
1694  /* variable ordering w.r.t. nonincreasing number of violated rows */
1695  assert(violatedvarrows != NULL);
1696  if( heurdata->preferbinaries )
1697  {
1698  if( nbinvars > 0 )
1699  SCIPsortDownIntInt(violatedvarrows, permutation, nbinvars);
1700  if( nbinvars < ndiscvars )
1701  SCIPsortDownIntInt(&violatedvarrows[nbinvars], &permutation[nbinvars], ndiscvars - nbinvars);
1702  }
1703  else
1704  {
1705  SCIPsortDownIntInt(violatedvarrows, permutation, ndiscvars);
1706  }
1707 
1708  SCIPdebugMsg(scip, "Variables sorted down w.r.t their number of currently infeasible rows!\n");
1709  break;
1710  case 't':
1711  /* variable ordering w.r.t. nondecreasing number of violated rows */
1712  assert(violatedvarrows != NULL);
1713  if( heurdata->preferbinaries )
1714  {
1715  if( nbinvars > 0 )
1716  SCIPsortIntInt(violatedvarrows, permutation, nbinvars);
1717  if( nbinvars < ndiscvars )
1718  SCIPsortIntInt(&violatedvarrows[nbinvars], &permutation[nbinvars], ndiscvars - nbinvars);
1719  }
1720  else
1721  {
1722  SCIPsortIntInt(violatedvarrows, permutation, ndiscvars);
1723  }
1724 
1725  SCIPdebugMsg(scip, "Variables sorted (upwards) w.r.t their number of currently infeasible rows!\n");
1726  break;
1727  case 'r':
1728  /* random sorting */
1729  if( heurdata->preferbinaries )
1730  {
1731  if( nbinvars > 0 )
1732  SCIPrandomPermuteIntArray(heurdata->randnumgen, permutation, 0, nbinvars - 1);
1733  if( nbinvars < ndiscvars )
1734  SCIPrandomPermuteIntArray(heurdata->randnumgen, &permutation[nbinvars], nbinvars - 1,
1735  ndiscvars - nbinvars - 1);
1736  }
1737  else
1738  {
1739  SCIPrandomPermuteIntArray(heurdata->randnumgen, permutation, 0, ndiscvars - 1);
1740  }
1741  SCIPdebugMsg(scip, "Variables permuted randomly!\n");
1742  break;
1743  default:
1744  SCIPdebugMsg(scip, "No variable permutation applied\n");
1745  break;
1746  }
1747  }
1748 
1749  /* should binary variables without locks be treated first? */
1750  if( heurdata->binlocksfirst )
1751  {
1752  SCIP_VAR* var;
1753  int nbinwithoutlocks = 0;
1754 
1755  /* count number of binaries without locks */
1756  if( heurdata->preferbinaries )
1757  {
1758  for( c = 0; c < nbinvars; ++c )
1759  {
1760  var = SCIPcolGetVar(heurdata->lpcols[permutation[c]]);
1763  ++nbinwithoutlocks;
1764  }
1765  }
1766  else
1767  {
1768  for( c = 0; c < ndiscvars; ++c )
1769  {
1770  var = SCIPcolGetVar(heurdata->lpcols[permutation[c]]);
1771  if( SCIPvarIsBinary(var) )
1772  {
1775  ++nbinwithoutlocks;
1776  }
1777  }
1778  }
1779 
1780  if( nbinwithoutlocks > 0 )
1781  {
1782  SCIP_VAR* binvar;
1783  int b = 1;
1784  int tmp;
1785  c = 0;
1786 
1787  /* if c reaches nbinwithoutlocks, then all binary variables without locks were sorted to the beginning of the array */
1788  while( c < nbinwithoutlocks && b < ndiscvars )
1789  {
1790  assert(c < b);
1791  assert(c < ndiscvars);
1792  assert(b < ndiscvars);
1793  var = SCIPcolGetVar(heurdata->lpcols[permutation[c]]);
1794  binvar = SCIPcolGetVar(heurdata->lpcols[permutation[b]]);
1795 
1796  /* search for next variable which is not a binary variable without locks */
1799  {
1800  ++c;
1801  if( c >= nbinwithoutlocks )
1802  break;
1803  var = SCIPcolGetVar(heurdata->lpcols[permutation[c]]);
1804  }
1805  if( c >= nbinwithoutlocks )
1806  break;
1807 
1808  /* search for next binary variable without locks (with position > c) */
1809  if( b <= c )
1810  {
1811  b = c + 1;
1812  binvar = SCIPcolGetVar(heurdata->lpcols[permutation[b]]);
1813  }
1814  while( !SCIPvarIsBinary(binvar) || (SCIPvarGetNLocksUpType(binvar, SCIP_LOCKTYPE_MODEL) > 0
1816  {
1817  ++b;
1818  assert(b < ndiscvars);
1819  binvar = SCIPcolGetVar(heurdata->lpcols[permutation[b]]);
1820  }
1821 
1822  /* swap the two variables */
1823  tmp = permutation[b];
1824  permutation[b] = permutation[c];
1825  permutation[c] = tmp;
1826 
1827  /* increase counters */
1828  ++c;
1829  ++b;
1830  }
1831  }
1832 
1833 #ifndef NDEBUG
1834  for( c = 0; c < ndiscvars; ++c )
1835  {
1836  assert((c < nbinwithoutlocks) == (SCIPvarIsBinary(SCIPcolGetVar(heurdata->lpcols[permutation[c]]))
1837  && (SCIPvarGetNLocksUpType(SCIPcolGetVar(heurdata->lpcols[permutation[c]]), SCIP_LOCKTYPE_MODEL) == 0
1838  || SCIPvarGetNLocksDownType(SCIPcolGetVar(heurdata->lpcols[permutation[c]]), SCIP_LOCKTYPE_MODEL) == 0)));
1839  }
1840 #endif
1841  }
1842 
1843  SCIP_CALL( SCIPallocBufferArray(scip, &eventdatas, matrix->ndiscvars) );
1844  BMSclearMemoryArray(eventdatas, matrix->ndiscvars);
1845 
1846  /* initialize variable events to catch bound changes during propagation */
1847  for( c = 0; c < matrix->ndiscvars; ++c )
1848  {
1849  SCIP_VAR* var;
1850 
1851  var = SCIPcolGetVar(heurdata->lpcols[c]);
1852  assert(var != NULL);
1853  assert(SCIPvarIsIntegral(var));
1854  assert(eventdatas[c] == NULL);
1855 
1856  SCIP_CALL( SCIPallocBuffer(scip, &(eventdatas[c])) ); /*lint !e866*/
1857 
1858  eventdatas[c]->colpos = c;
1859 
1860  SCIP_CALL( SCIPcatchVarEvent(scip, var, EVENTTYPE_SHIFTANDPROPAGATE, eventhdlr, eventdatas[c], NULL) );
1861  }
1862 
1863  cutoff = FALSE;
1864 
1865  lastindexofsusp = -1;
1866  probing = heurdata->probing;
1867  infeasible = FALSE;
1868 
1869  SCIPdebugMsg(scip, "SHIFT_AND_PROPAGATE heuristic starts main loop with %d violations and %d remaining variables!\n",
1870  nviolatedrows, ndiscvars);
1871 
1872  assert(matrix->ndiscvars == ndiscvars);
1873 
1874  /* loop over variables, shift them according to shifting criteria and try to reduce the global infeasibility */
1875  for( c = 0; c < ndiscvars; ++c )
1876  {
1877  SCIP_VAR* var;
1878  SCIP_Longint ndomredsfound;
1879  SCIP_Real optimalshiftvalue;
1880  SCIP_Real origsolval;
1881  SCIP_Real lb;
1882  SCIP_Real ub;
1883  int nviolations;
1884  int permutedvarindex;
1885  int j;
1886  SCIP_Bool marksuspicious;
1887 
1888  if( heurdata->selectbest )
1889  { /* search for best candidate */
1890  j = c + 1;
1891  while( j < ndiscvars )
1892  {
1893  /* run through remaining variables and search for best candidate */
1894  if( matrix->violrows[permutation[c]] < matrix->violrows[permutation[j]] )
1895  {
1896  int tmp;
1897  tmp = permutation[c];
1898  permutation[c] = permutation[j];
1899  permutation[j] = tmp;
1900  }
1901  ++j;
1902  }
1903  }
1904  permutedvarindex = permutation[c];
1905  optimalshiftvalue = 0.0;
1906  nviolations = 0;
1907  var = SCIPcolGetVar(heurdata->lpcols[permutedvarindex]);
1908  lb = SCIPvarGetLbLocal(var);
1909  ub = SCIPvarGetUbLocal(var);
1910  assert(SCIPcolGetLPPos(SCIPvarGetCol(var)) >= 0);
1911  assert(SCIPvarIsIntegral(var));
1912 
1913  /* check whether we hit some limit, e.g. the time limit, in between
1914  * since the check itself consumes some time, we only do it every tenth iteration
1915  */
1916  if( c % 10 == 0 && SCIPisStopped(scip) )
1917  goto TERMINATE2;
1918 
1919  /* if propagation is enabled, check if propagation has changed the variables bounds
1920  * and update the transformed upper bound correspondingly
1921  * @todo this should not be necessary
1922  */
1923  if( heurdata->probing )
1924  SCIP_CALL( updateTransformation(scip, matrix, heurdata, permutedvarindex,lb, ub, violatedrows, violatedrowpos,
1925  &nviolatedrows) );
1926 
1927  SCIPdebugMsg(scip, "Variable %s with local bounds [%g,%g], status <%d>, matrix bound <%g>\n",
1928  SCIPvarGetName(var), lb, ub, matrix->transformstatus[permutedvarindex], matrix->upperbounds[permutedvarindex]);
1929 
1930  /* ignore variable if propagation fixed it (lb and ub will be zero) */
1931  if( SCIPisFeasZero(scip, matrix->upperbounds[permutedvarindex]) )
1932  {
1933  assert(!SCIPisInfinity(scip, ub));
1934  assert(SCIPisFeasEQ(scip, lb, ub));
1935 
1936  SCIP_CALL( SCIPsetSolVal(scip, sol, var, ub) );
1937 
1938  continue;
1939  }
1940 
1941  marksuspicious = FALSE;
1942 
1943  /* check whether the variable is binary and has no locks in one direction, so that we want to fix it to the
1944  * respective bound (only enabled by parameter)
1945  */
1946  if( heurdata->fixbinlocks && SCIPvarIsBinary(var)
1949  {
1951  origsolval = SCIPvarGetUbLocal(var);
1952  else
1953  {
1954  assert(SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == 0);
1955  origsolval = SCIPvarGetLbLocal(var);
1956  }
1957  }
1958  else
1959  {
1960  /* only apply the computationally expensive best shift selection, if there is a violated row left */
1961  if( !heurdata->stopafterfeasible || nviolatedrows > 0 )
1962  {
1963  /* compute optimal shift value for variable */
1964  SCIP_CALL( getOptimalShiftingValue(scip, matrix, permutedvarindex, 1, heurdata->rowweights, steps, violationchange,
1965  &optimalshiftvalue, &nviolations) );
1966  assert(SCIPisFeasGE(scip, optimalshiftvalue, 0.0));
1967 
1968  /* Variables with FREE transform have to be dealt with twice */
1969  if( matrix->transformstatus[permutedvarindex] == TRANSFORMSTATUS_FREE )
1970  {
1971  SCIP_Real downshiftvalue;
1972  int ndownviolations;
1973 
1974  downshiftvalue = 0.0;
1975  ndownviolations = 0;
1976  SCIP_CALL( getOptimalShiftingValue(scip, matrix, permutedvarindex, -1, heurdata->rowweights, steps, violationchange,
1977  &downshiftvalue, &ndownviolations) );
1978 
1979  assert(SCIPisLE(scip, downshiftvalue, 0.0));
1980 
1981  /* compare to positive direction and select the direction which makes more rows feasible */
1982  if( ndownviolations < nviolations )
1983  {
1984  optimalshiftvalue = downshiftvalue;
1985  }
1986  }
1987  }
1988  else
1989  optimalshiftvalue = 0.0;
1990 
1991  /* if zero optimal shift values are forbidden by the user parameter, delay the variable by marking it suspicious */
1992  if( heurdata->nozerofixing && nviolations > 0 && SCIPisFeasZero(scip, optimalshiftvalue) )
1993  marksuspicious = TRUE;
1994 
1995  /* retransform the solution value from the heuristic transformation space */
1996  assert(varIsDiscrete(var, impliscontinuous));
1997  origsolval = retransformVariable(scip, matrix, var, permutedvarindex, optimalshiftvalue);
1998  }
1999  assert(SCIPisFeasGE(scip, origsolval, lb) && SCIPisFeasLE(scip, origsolval, ub));
2000 
2001  /* check if propagation should still be performed
2002  * @todo do we need the hard coded value? we could use SCIP_MAXTREEDEPTH
2003  */
2004  if( nprobings > DEFAULT_PROPBREAKER )
2005  probing = FALSE;
2006 
2007  /* if propagation is enabled, fix the variable to the new solution value and propagate the fixation
2008  * (to fix other variables and to find out early whether solution is already infeasible)
2009  */
2010  if( !marksuspicious && probing )
2011  {
2012  /* this assert should be always fulfilled because we run this heuristic at the root node only and do not
2013  * perform probing if nprobings is less than DEFAULT_PROPBREAKER (currently: 65000)
2014  */
2015  assert(SCIP_MAXTREEDEPTH > SCIPgetDepth(scip));
2016 
2017  SCIP_CALL( SCIPnewProbingNode(scip) );
2018  SCIP_CALL( SCIPfixVarProbing(scip, var, origsolval) );
2019  ndomredsfound = 0;
2020 
2021  SCIPdebugMsg(scip, " Shift %g(%g originally) is optimal, propagate solution\n", optimalshiftvalue, origsolval);
2022  SCIP_CALL( SCIPpropagateProbing(scip, heurdata->nproprounds, &cutoff, &ndomredsfound) );
2023 
2024  ++nprobings;
2025  SCIPstatistic( heurdata->ntotaldomredsfound += ndomredsfound );
2026  SCIPdebugMsg(scip, "Propagation finished! <%" SCIP_LONGINT_FORMAT "> domain reductions %s, <%d> probing depth\n", ndomredsfound, cutoff ? "CUTOFF" : "",
2027  SCIPgetProbingDepth(scip));
2028  }
2029  assert(!cutoff || probing);
2030 
2031  /* propagation led to an empty domain, hence we backtrack and postpone the variable */
2032  if( cutoff )
2033  {
2034  assert(probing);
2035 
2036  ++ncutoffs;
2037 
2038  /* only continue heuristic if number of cutoffs occured so far is reasonably small */
2039  if( heurdata->cutoffbreaker >= 0 && ncutoffs >= ((heurdata->maxcutoffquot * SCIPgetProbingDepth(scip)) + heurdata->cutoffbreaker) )
2040  break;
2041 
2042  cutoff = FALSE;
2043 
2044  /* backtrack to the parent of the current node */
2045  assert(SCIPgetProbingDepth(scip) >= 1);
2047 
2048  /* this assert should be always fulfilled because we run this heuristic at the root node only and do not
2049  * perform probing if nprobings is less than DEFAULT_PROPBREAKER (currently: 65000)
2050  */
2051  assert(SCIP_MAXTREEDEPTH > SCIPgetDepth(scip));
2052 
2053  /* if the variable upper and lower bound are equal to the solution value to which we tried to fix the variable,
2054  * we are trapped at an infeasible node and break; this can only happen due to an intermediate global bound change of the variable,
2055  * I guess
2056  */
2057  if( SCIPisFeasEQ(scip, SCIPvarGetUbLocal(var), origsolval) && SCIPisFeasEQ(scip, SCIPvarGetLbLocal(var), origsolval) )
2058  {
2059  cutoff = TRUE;
2060  break;
2061  }
2062  else if( SCIPisFeasEQ(scip, SCIPvarGetLbLocal(var), origsolval) )
2063  {
2064  /* if the variable were to be set to one of its bounds, repropagate by tightening this bound by 1.0
2065  * into the direction of the other bound, if possible */
2066  assert(SCIPisFeasGE(scip, SCIPvarGetUbLocal(var), origsolval + 1.0));
2067 
2068  ndomredsfound = 0;
2069  SCIP_CALL( SCIPnewProbingNode(scip) );
2070  SCIP_CALL( SCIPchgVarLbProbing(scip, var, origsolval + 1.0) );
2071  SCIP_CALL( SCIPpropagateProbing(scip, heurdata->nproprounds, &cutoff, &ndomredsfound) );
2072 
2073  SCIPstatistic( heurdata->ntotaldomredsfound += ndomredsfound );
2074  }
2075  else if( SCIPisFeasEQ(scip, SCIPvarGetUbLocal(var), origsolval) )
2076  {
2077  /* if the variable were to be set to one of its bounds, repropagate by tightening this bound by 1.0
2078  * into the direction of the other bound, if possible */
2079  assert(SCIPisFeasLE(scip, SCIPvarGetLbLocal(var), origsolval - 1.0));
2080 
2081  ndomredsfound = 0;
2082 
2083  SCIP_CALL( SCIPnewProbingNode(scip) );
2084  SCIP_CALL( SCIPchgVarUbProbing(scip, var, origsolval - 1.0) );
2085  SCIP_CALL( SCIPpropagateProbing(scip, heurdata->nproprounds, &cutoff, &ndomredsfound) );
2086 
2087  SCIPstatistic( heurdata->ntotaldomredsfound += ndomredsfound );
2088  }
2089 
2090  /* if the tightened bound again leads to a cutoff, both subproblems are proven infeasible and the heuristic
2091  * can be stopped */
2092  if( cutoff )
2093  {
2094  break;
2095  }
2096  else
2097  {
2098  /* since repropagation was successful, we indicate that this variable led to a cutoff in one direction */
2099  marksuspicious = TRUE;
2100  }
2101  }
2102 
2103  if( marksuspicious )
2104  {
2105  /* mark the variable as suspicious */
2106  assert(permutedvarindex == permutation[c]);
2107 
2108  ++lastindexofsusp;
2109  assert(lastindexofsusp >= 0 && lastindexofsusp <= c);
2110 
2111  permutation[c] = permutation[lastindexofsusp];
2112  permutation[lastindexofsusp] = permutedvarindex;
2113 
2114  SCIPdebugMsg(scip, " Suspicious variable! Postponed from pos <%d> to position <%d>\n", c, lastindexofsusp);
2115  }
2116  else
2117  {
2118  SCIPdebugMsg(scip, "Variable <%d><%s> successfully shifted by value <%g>!\n", permutedvarindex,
2119  SCIPvarGetName(var), optimalshiftvalue);
2120 
2121  /* update solution */
2122  SCIP_CALL( SCIPsetSolVal(scip, sol, var, origsolval) );
2123 
2124  /* only to ensure that some assertions can be made later on */
2125  if( !probing )
2126  {
2127  SCIP_CALL( SCIPfixVarProbing(scip, var, origsolval) );
2128  }
2129  }
2130  }
2131  SCIPdebugMsg(scip, "Heuristic finished with %d remaining violations and %d remaining variables!\n",
2132  nviolatedrows, lastindexofsusp + 1);
2133 
2134  /* if constructed solution might be feasible, go through the queue of suspicious variables and set the solution
2135  * values
2136  */
2137  if( nviolatedrows == 0 && !cutoff )
2138  {
2139  SCIP_Bool stored;
2140  SCIP_Bool trysol;
2141 
2142  for( v = 0; v <= lastindexofsusp; ++v )
2143  {
2144  SCIP_VAR* var;
2145  SCIP_Real origsolval;
2146  int permutedvarindex;
2147 
2148  /* get the column position of the variable */
2149  permutedvarindex = permutation[v];
2150  var = SCIPcolGetVar(heurdata->lpcols[permutedvarindex]);
2151  assert(varIsDiscrete(var, impliscontinuous));
2152 
2153  /* update the transformation of the variable, since the bound might have changed after the last update. */
2154  if( heurdata->probing )
2155  SCIP_CALL( updateTransformation(scip, matrix, heurdata, permutedvarindex, SCIPvarGetLbLocal(var),
2156  SCIPvarGetUbLocal(var), violatedrows, violatedrowpos, &nviolatedrows) );
2157 
2158  /* retransform the solution value from the heuristic transformed space, set the solution value accordingly */
2159  assert(varIsDiscrete(var, impliscontinuous));
2160  origsolval = retransformVariable(scip, matrix, var, permutedvarindex, 0.0);
2161  assert(SCIPisFeasGE(scip, origsolval, SCIPvarGetLbLocal(var))
2162  && SCIPisFeasLE(scip, origsolval, SCIPvarGetUbLocal(var)));
2163  SCIP_CALL( SCIPsetSolVal(scip, sol, var, origsolval) );
2164  SCIP_CALL( SCIPfixVarProbing(scip, var, origsolval) ); /* only to ensure that some assertions can be made later */
2165 
2166  SCIPdebugMsg(scip, " Remaining variable <%s> set to <%g>; %d Violations\n", SCIPvarGetName(var), origsolval,
2167  nviolatedrows);
2168  }
2169 
2170  /* Fixing of remaining variables led to infeasibility */
2171  if( nviolatedrows > 0 )
2172  goto TERMINATE2;
2173 
2174  trysol = TRUE;
2175 
2176  /* if the constructed solution might still be extendable to a feasible solution, try this by
2177  * solving the remaining LP
2178  */
2179  if( nlpcols != matrix->ndiscvars )
2180  {
2181  /* case that remaining LP has to be solved */
2182  SCIP_Bool lperror;
2183 
2184 #ifndef NDEBUG
2185  {
2186  SCIP_VAR** vars;
2187 
2188  vars = SCIPgetVars(scip);
2189  assert(vars != NULL);
2190  /* ensure that all discrete variables in the remaining LP are fixed */
2191  for( v = 0; v < ndiscvars; ++v )
2192  {
2193  if( SCIPvarIsInLP(vars[v]) )
2194  assert(SCIPisFeasEQ(scip, SCIPvarGetLbLocal(vars[v]), SCIPvarGetUbLocal(vars[v])));
2195  }
2196  }
2197 #endif
2198 
2199  SCIPdebugMsg(scip, " -> old LP iterations: %" SCIP_LONGINT_FORMAT "\n", SCIPgetNLPIterations(scip));
2200 
2201 #ifdef SCIP_DEBUG
2202  SCIP_CALL( SCIPwriteLP(scip, "shiftandpropagatelp.mps") );
2203 #endif
2204  /* solve LP;
2205  * errors in the LP solver should not kill the overall solving process, if the LP is just needed for a heuristic.
2206  * hence in optimized mode, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
2207  */
2208 #ifdef NDEBUG
2209  {
2210  SCIP_RETCODE retstat;
2211  retstat = SCIPsolveProbingLP(scip, -1, &lperror, NULL);
2212  if( retstat != SCIP_OKAY )
2213  {
2214  SCIPwarningMessage(scip, "Error while solving LP in SHIFTANDPROPAGATE heuristic; LP solve terminated with code <%d>\n",
2215  retstat);
2216  }
2217  }
2218 #else
2219  SCIP_CALL( SCIPsolveProbingLP(scip, -1, &lperror, NULL) );
2220 #endif
2221 
2222  SCIPdebugMsg(scip, " -> new LP iterations: %" SCIP_LONGINT_FORMAT "\n", SCIPgetNLPIterations(scip));
2223  SCIPdebugMsg(scip, " -> error=%u, status=%d\n", lperror, SCIPgetLPSolstat(scip));
2224 
2225  /* check if this is a feasible solution */
2226  if( !lperror && SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_OPTIMAL )
2227  {
2228  /* copy the current LP solution to the working solution */
2229  SCIP_CALL( SCIPlinkLPSol(scip, sol) );
2230  }
2231  else
2232  trysol = FALSE;
2233 
2234  SCIPstatistic( heurdata->lpsolstat = SCIPgetLPSolstat(scip) );
2235  }
2236 
2237  /* check solution for feasibility, and add it to solution store if possible.
2238  * None of integrality, feasibility of LP rows, variable bounds have to be checked, because they
2239  * are guaranteed by the heuristic at this stage.
2240  */
2241  if( trysol )
2242  {
2243  SCIP_Bool printreason;
2244  SCIP_Bool completely;
2245 #ifdef SCIP_DEBUG
2246  printreason = TRUE;
2247 #else
2248  printreason = FALSE;
2249 #endif
2250 #ifndef NDEBUG
2251  completely = TRUE; /*lint !e838*/
2252 #else
2253  completely = FALSE;
2254 #endif
2255 
2256  /* we once also checked the variable bounds which should not be necessary */
2257  SCIP_CALL( SCIPtrySol(scip, sol, printreason, completely, FALSE, FALSE, FALSE, &stored) );
2258 
2259  if( stored )
2260  {
2261  SCIPdebugMsg(scip, "found feasible shifted solution:\n");
2262  SCIPdebug( SCIP_CALL( SCIPprintSol(scip, sol, NULL, FALSE) ) );
2263  *result = SCIP_FOUNDSOL;
2264 
2265  SCIPstatisticMessage(" Shiftandpropagate solution value: %16.9g \n", SCIPgetSolOrigObj(scip, sol));
2266  }
2267  }
2268  }
2269  else
2270  {
2271  SCIPdebugMsg(scip, "Solution constructed by heuristic is already known to be infeasible\n");
2272  }
2273 
2274  SCIPstatistic( heurdata->nremainingviols = nviolatedrows; );
2275 
2276  TERMINATE2:
2277  /* free allocated memory in reverse order of allocation */
2278  for( c = matrix->ndiscvars - 1; c >= 0; --c )
2279  {
2280  SCIP_VAR* var;
2281 
2282  var = SCIPcolGetVar(heurdata->lpcols[c]);
2283  assert(var != NULL);
2284  assert(eventdatas[c] != NULL);
2285 
2286  SCIP_CALL( SCIPdropVarEvent(scip, var, EVENTTYPE_SHIFTANDPROPAGATE, eventhdlr, eventdatas[c], -1) );
2287  SCIPfreeBuffer(scip, &(eventdatas[c]));
2288  }
2289  SCIPfreeBufferArray(scip, &eventdatas);
2290 
2291  if( violatedvarrows != NULL )
2292  {
2293  assert(heurdata->sortkey == 'v' || heurdata->sortkey == 't');
2294  SCIPfreeBufferArray(scip, &violatedvarrows);
2295  }
2296  /* free all allocated memory */
2297  SCIPfreeBufferArray(scip, &violatedrowpos);
2298  SCIPfreeBufferArray(scip, &violatedrows);
2299  SCIPfreeBufferArray(scip, &violationchange);
2300  SCIPfreeBufferArray(scip, &steps);
2301  SCIPfreeBufferArray(scip, &heurdata->rowweights);
2302  SCIPfreeBufferArray(scip, &permutation);
2303  SCIP_CALL( SCIPfreeSol(scip, &sol) );
2304 
2305  eventhdlrdata->nviolatedrows = NULL;
2306  eventhdlrdata->violatedrowpos = NULL;
2307  eventhdlrdata->violatedrows = NULL;
2308 
2309  TERMINATE:
2310  /* terminate probing mode and free the remaining memory */
2311  SCIPstatistic(
2312  heurdata->ncutoffs += ncutoffs;
2313  heurdata->nprobings += nprobings;
2314  heurdata->nlpiters = SCIPgetNLPIterations(scip) - heurdata->nlpiters;
2315  );
2316 
2317  SCIP_CALL( SCIPendProbing(scip) );
2318  SCIPfreeBufferArray(scip, &heurdata->lpcols);
2319  freeMatrix(scip, &matrix);
2320  eventhdlrdata->matrix = NULL;
2321 
2322  return SCIP_OKAY;
2323 }
2324 
2325 /** event handler execution method for the heuristic which catches all
2326  * events in which a lower or upper bound were tightened */
2327 static
2328 SCIP_DECL_EVENTEXEC(eventExecShiftandpropagate)
2329 { /*lint --e{715}*/
2330  SCIP_EVENTHDLRDATA* eventhdlrdata;
2331  SCIP_VAR* var;
2332  SCIP_COL* col;
2333  SCIP_Real lb;
2334  SCIP_Real ub;
2335  int colpos;
2336  CONSTRAINTMATRIX* matrix;
2337  SCIP_HEURDATA* heurdata;
2338 
2339  assert(scip != NULL);
2340  assert(eventhdlr != NULL);
2341  assert(strcmp(EVENTHDLR_NAME, SCIPeventhdlrGetName(eventhdlr)) == 0);
2342 
2343  eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
2344  assert(eventhdlrdata != NULL);
2345 
2346  matrix = eventhdlrdata->matrix;
2347 
2348  heurdata = eventhdlrdata->heurdata;
2349  assert(heurdata != NULL && heurdata->lpcols != NULL);
2350 
2351  colpos = eventdata->colpos;
2352 
2353  assert(0 <= colpos && colpos < matrix->ndiscvars);
2354 
2355  col = heurdata->lpcols[colpos];
2356  var = SCIPcolGetVar(col);
2357 
2358  lb = SCIPvarGetLbLocal(var);
2359  ub = SCIPvarGetUbLocal(var);
2360 
2361  SCIP_CALL( updateTransformation(scip, matrix, eventhdlrdata->heurdata, colpos, lb, ub, eventhdlrdata->violatedrows,
2362  eventhdlrdata->violatedrowpos, eventhdlrdata->nviolatedrows) );
2363 
2364  return SCIP_OKAY;
2365 }
2366 
2367 /*
2368  * primal heuristic specific interface methods
2369  */
2370 
2371 /** creates the shiftandpropagate primal heuristic and includes it in SCIP */
2373  SCIP* scip /**< SCIP data structure */
2374  )
2375 {
2376  SCIP_HEURDATA* heurdata;
2377  SCIP_HEUR* heur;
2378  SCIP_EVENTHDLRDATA* eventhandlerdata;
2379  SCIP_EVENTHDLR* eventhdlr;
2380 
2381  SCIP_CALL( SCIPallocBlockMemory(scip, &eventhandlerdata) );
2382  eventhandlerdata->matrix = NULL;
2383 
2384  eventhdlr = NULL;
2386  eventExecShiftandpropagate, eventhandlerdata) );
2387  assert(eventhdlr != NULL);
2388 
2389  /* create Shiftandpropagate primal heuristic data */
2390  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
2391  heurdata->rowweights = NULL;
2392  heurdata->nlpcols = 0;
2393  heurdata->eventhdlr = eventhdlr;
2394 
2395  /* include primal heuristic */
2396  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
2398  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecShiftandpropagate, heurdata) );
2399 
2400  assert(heur != NULL);
2401 
2402  /* set non-NULL pointers to callback methods */
2403  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyShiftandpropagate) );
2404  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeShiftandpropagate) );
2405  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitShiftandpropagate) );
2406  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitShiftandpropagate) );
2407 
2408  /* add shiftandpropagate primal heuristic parameters */
2409  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nproprounds",
2410  "The number of propagation rounds used for each propagation",
2411  &heurdata->nproprounds, TRUE, DEFAULT_NPROPROUNDS, -1, 1000, NULL, NULL) );
2412  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/relax", "Should continuous variables be relaxed?",
2413  &heurdata->relax, TRUE, DEFAULT_RELAX, NULL, NULL) );
2414  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/probing", "Should domains be reduced by probing?",
2415  &heurdata->probing, TRUE, DEFAULT_PROBING, NULL, NULL) );
2416  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/onlywithoutsol",
2417  "Should heuristic only be executed if no primal solution was found, yet?",
2418  &heurdata->onlywithoutsol, TRUE, DEFAULT_ONLYWITHOUTSOL, NULL, NULL) );
2419  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/cutoffbreaker", "The number of cutoffs before heuristic stops",
2420  &heurdata->cutoffbreaker, TRUE, DEFAULT_CUTOFFBREAKER, -1, 1000000, NULL, NULL) );
2421  SCIP_CALL( SCIPaddCharParam(scip, "heuristics/" HEUR_NAME "/sortkey",
2422  "the key for variable sorting: (n)orms down, norms (u)p, (v)iolations down, viola(t)ions up, or (r)andom",
2423  &heurdata->sortkey, TRUE, DEFAULT_SORTKEY, SORTKEYS, NULL, NULL) );
2424  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/sortvars", "Should variables be sorted for the heuristic?",
2425  &heurdata->sortvars, TRUE, DEFAULT_SORTVARS, NULL, NULL));
2426  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/collectstats", "should variable statistics be collected during probing?",
2427  &heurdata->collectstats, TRUE, DEFAULT_COLLECTSTATS, NULL, NULL) );
2428  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/stopafterfeasible",
2429  "Should the heuristic stop calculating optimal shift values when no more rows are violated?",
2430  &heurdata->stopafterfeasible, TRUE, DEFAULT_STOPAFTERFEASIBLE, NULL, NULL) );
2431  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/preferbinaries",
2432  "Should binary variables be shifted first?",
2433  &heurdata->preferbinaries, TRUE, DEFAULT_PREFERBINARIES, NULL, NULL) );
2434  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/nozerofixing",
2435  "should variables with a zero shifting value be delayed instead of being fixed?",
2436  &heurdata->nozerofixing, TRUE, DEFAULT_NOZEROFIXING, NULL, NULL) );
2437  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/fixbinlocks",
2438  "should binary variables with no locks in one direction be fixed to that direction?",
2439  &heurdata->fixbinlocks, TRUE, DEFAULT_FIXBINLOCKS, NULL, NULL) );
2440  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/binlocksfirst",
2441  "should binary variables with no locks be preferred in the ordering?",
2442  &heurdata->binlocksfirst, TRUE, DEFAULT_BINLOCKSFIRST, NULL, NULL) );
2443  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/normalize",
2444  "should coefficients and left/right hand sides be normalized by max row coeff?",
2445  &heurdata->normalize, TRUE, DEFAULT_NORMALIZE, NULL, NULL) );
2446  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/updateweights",
2447  "should row weight be increased every time the row is violated?",
2448  &heurdata->updateweights, TRUE, DEFAULT_UPDATEWEIGHTS, NULL, NULL) );
2449  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/impliscontinuous",
2450  "should implicit integer variables be treated as continuous variables?",
2451  &heurdata->impliscontinuous, TRUE, DEFAULT_IMPLISCONTINUOUS, NULL, NULL) );
2452  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/shiftandpropagate/selectbest",
2453  "should the heuristic choose the best candidate in every round? (set to FALSE for static order)?",
2454  &heurdata->selectbest, TRUE, DEFAULT_SELECTBEST, NULL, NULL) );
2455  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/maxcutoffquot",
2456  "maximum percentage of allowed cutoffs before stopping the heuristic",
2457  &heurdata->maxcutoffquot, TRUE, DEFAULT_MAXCUTOFFQUOT, 0.0, 2.0, NULL, NULL) );
2458 
2459  return SCIP_OKAY;
2460 }
void SCIPsortRealInt(SCIP_Real *realarray, int *intarray, int len)
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1075
#define NULL
Definition: def.h:239
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for SCIP parameter handling
int SCIPvarGetNLocksDownType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3176
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip_tree.c:158
SCIP_RETCODE SCIPbacktrackProbing(SCIP *scip, int probingdepth)
Definition: scip_probing.c:280
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
#define DEFAULT_FIXBINLOCKS
preroot heuristic that alternatingly fixes variables and propagates domains
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static void relaxVar(SCIP *scip, SCIP_VAR *var, CONSTRAINTMATRIX *matrix, SCIP_Bool normalize)
#define HEUR_USESSUBSCIP
public methods for memory management
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:422
int SCIPgetProbingDepth(SCIP *scip)
Definition: scip_probing.c:253
SCIP_RETCODE SCIPwriteLP(SCIP *scip, const char *filename)
Definition: scip_lp.c:880
#define DEFAULT_SORTKEY
#define HEUR_DESC
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17343
int SCIPvarGetNLocksUpType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3233
static SCIP_DECL_HEUREXEC(heurExecShiftandpropagate)
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
Definition: lp.c:16748
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:280
#define HEUR_NAME
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17399
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:172
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:16928
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16909
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
Definition: type_event.h:138
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
int SCIProwGetNLPNonz(SCIP_ROW *row)
Definition: lp.c:16804
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:16869
#define FALSE
Definition: def.h:65
#define DEFAULT_CUTOFFBREAKER
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:314
static SCIP_DECL_EVENTEXEC(eventExecShiftandpropagate)
SCIP_Bool SCIPcolIsIntegral(SCIP_COL *col)
Definition: lp.c:16659
#define DEFAULT_RELAX
static void freeMatrix(SCIP *scip, CONSTRAINTMATRIX **matrix)
SCIP_RETCODE SCIPcutoffNode(SCIP *scip, SCIP_NODE *node)
Definition: scip_tree.c:501
SCIP_Real SCIPinfinity(SCIP *scip)
#define TRUE
Definition: def.h:64
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIPstatisticMessage
Definition: pub_message.h:104
#define HEUR_DISPCHAR
#define DEFAULT_SORTVARS
#define DEFAULT_UPDATEWEIGHTS
#define DEFAULT_BINLOCKSFIRST
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
void SCIPsortDownIntInt(int *intarray1, int *intarray2, int len)
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
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:187
SCIP_RETCODE SCIPchgVarLbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_probing.c:356
#define DEFAULT_WEIGHT_INEQUALITY
void SCIPsortDownRealInt(SCIP_Real *realarray, int *intarray, int len)
SCIP_RETCODE SCIPconstructLP(SCIP *scip, SCIP_Bool *cutoff)
Definition: scip_lp.c:182
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:142
enum SCIP_LPSolStat SCIP_LPSOLSTAT
Definition: type_lp.h:42
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1175
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
SCIP_RETCODE SCIPgetLPColsData(SCIP *scip, SCIP_COL ***cols, int *ncols)
Definition: scip_lp.c:495
public methods for SCIP variables
#define DEFAULT_RANDSEED
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:203
#define HEUR_TIMING
#define SCIPdebugMsg
Definition: scip_message.h:88
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:155
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2224
#define DEFAULT_ONLYWITHOUTSOL
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1823
#define HEUR_PRIORITY
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
public methods for numerical tolerances
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
public methods for querying solving statistics
public methods for the branch-and-bound tree
SCIP_Bool SCIPisLPConstructed(SCIP *scip)
Definition: scip_lp.c:159
static SCIP_DECL_HEUREXIT(heurExitShiftandpropagate)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17353
#define DEFAULT_NORMALIZE
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1254
static SCIP_Bool varIsDiscrete(SCIP_VAR *var, SCIP_Bool impliscontinuous)
#define DEFAULT_STOPAFTERFEASIBLE
#define SCIPerrorMessage
Definition: pub_message.h:45
#define DEFAULT_SELECTBEST
void SCIPsortIntInt(int *intarray1, int *intarray2, int len)
static void transformVariable(SCIP *scip, CONSTRAINTMATRIX *matrix, SCIP_HEURDATA *heurdata, int colpos)
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:248
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
Definition: lp.c:16738
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
Definition: scip_probing.c:630
static SCIP_Bool colIsDiscrete(SCIP_COL *col, SCIP_Bool impliscontinuous)
public methods for event handler plugins and event handlers
SCIP_RETCODE SCIPfixVarProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval)
Definition: scip_probing.c:473
#define SCIPallocBuffer(scip, ptr)
Definition: scip_mem.h:128
#define EVENTTYPE_SHIFTANDPROPAGATE
static SCIP_RETCODE initMatrix(SCIP *scip, CONSTRAINTMATRIX *matrix, SCIP_HEURDATA *heurdata, int *colposs, SCIP_Bool normalize, int *nmaxrows, SCIP_Bool relax, SCIP_Bool *initialized, SCIP_Bool *infeasible)
#define SORTKEYS
SCIP_RETCODE SCIPendProbing(SCIP *scip)
Definition: scip_probing.c:315
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:155
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16729
#define DEFAULT_PREFERBINARIES
int SCIPgetNLPRows(SCIP *scip)
Definition: scip_lp.c:629
public methods for primal CIP solutions
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
#define SCIP_CALL(x)
Definition: def.h:351
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPsolveProbingLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition: scip_probing.c:866
#define DEFAULT_NOZEROFIXING
#define SCIPfreeBlockMemoryNull(scip, ptr)
Definition: scip_mem.h:115
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_DECL_HEURINIT(heurInitShiftandpropagate)
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:16879
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:16815
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:141
public methods for primal heuristic plugins and divesets
#define EVENTHDLR_NAME
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:130
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1270
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:16825
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:62
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:226
#define HEUR_MAXDEPTH
#define HEUR_FREQOFS
SCIP_Bool SCIPvarIsInLP(SCIP_VAR *var)
Definition: var.c:17068
#define DEFAULT_NPROPROUNDS
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:715
void SCIPsolSetHeur(SCIP_SOL *sol, SCIP_HEUR *heur)
Definition: sol.c:2594
void SCIPrandomPermuteIntArray(SCIP_RANDNUMGEN *randnumgen, int *array, int begin, int end)
Definition: misc.c:9413
enum TransformStatus TRANSFORMSTATUS
public methods for LP management
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:1034
void SCIPenableVarHistory(SCIP *scip)
Definition: scip_var.c:8540
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:468
#define DEFAULT_MAXCUTOFFQUOT
#define DEFAULT_IMPLISCONTINUOUS
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:116
#define DEFAULT_WEIGHT_EQUALITY
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17057
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1493
SCIP_RETCODE SCIPflushLP(SCIP *scip)
Definition: scip_lp.c:206
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
#define HEUR_FREQ
static void getColumnData(CONSTRAINTMATRIX *matrix, int colindex, SCIP_Real **valpointer, int **indexpointer, int *ncolvals)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: scip_sol.c:3197
#define SCIP_MAXTREEDEPTH
Definition: def.h:287
static void checkRowViolation(SCIP *scip, CONSTRAINTMATRIX *matrix, int rowindex, int *violatedrows, int *violatedrowpos, int *nviolatedrows, int *rowweights, SCIP_Bool updateweights)
public methods for the LP relaxation, rows and columns
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2044
static void checkViolations(SCIP *scip, CONSTRAINTMATRIX *matrix, int colidx, int *violatedrows, int *violatedrowpos, int *nviolatedrows, int *rowweights, SCIP_Bool updateweights)
SCIP_Real * r
Definition: circlepacking.c:50
methods for sorting joint arrays of various types
#define SCIP_LONGINT_FORMAT
Definition: def.h:142
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:16835
SCIP_VAR ** b
Definition: circlepacking.c:56
public methods for managing events
general public methods
#define SCIPfreeBuffer(scip, ptr)
Definition: scip_mem.h:140
#define MAX(x, y)
Definition: def.h:208
static SCIP_DECL_HEURCOPY(heurCopyShiftandpropagate)
static SCIP_Real retransformVariable(SCIP *scip, CONSTRAINTMATRIX *matrix, SCIP_VAR *var, int varindex, SCIP_Real solvalue)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2379
SCIP_RETCODE SCIPincludeHeurShiftandpropagate(SCIP *scip)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE updateTransformation(SCIP *scip, CONSTRAINTMATRIX *matrix, SCIP_HEURDATA *heurdata, int varindex, SCIP_Real lb, SCIP_Real ub, int *violatedrows, int *violatedrowpos, int *nviolatedrows)
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:239
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16639
public methods for solutions
public methods for random numbers
public methods for the probing mode
static void getRowData(CONSTRAINTMATRIX *matrix, int rowindex, SCIP_Real **valpointer, SCIP_Real *lhs, SCIP_Real *rhs, int **indexpointer, int *nrowvals)
public methods for message output
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:264
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1999
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16848
int SCIProwGetLPPos(SCIP_ROW *row)
Definition: lp.c:17058
#define SCIPstatistic(x)
Definition: pub_message.h:101
#define SCIP_Real
Definition: def.h:150
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:739
static SCIP_DECL_SORTPTRCOMP(heurSortColsShiftandpropagate)
public methods for message handling
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2094
#define SCIP_Longint
Definition: def.h:135
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16894
#define EVENTHDLR_DESC
#define DEFAULT_PROBING
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_PROPBREAKER
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:60
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:232
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17409
SCIP_RETCODE SCIPnewProbingNode(SCIP *scip)
Definition: scip_probing.c:220
#define DEFAULT_COLLECTSTATS
SCIP_RETCODE SCIPstartProbing(SCIP *scip)
Definition: scip_probing.c:174
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:112
public methods for primal heuristics
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip_lp.c:573
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:324
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1165
#define SCIPABORT()
Definition: def.h:323
public methods for global and local (sub)problems
int SCIPcolGetNLPNonz(SCIP_COL *col)
Definition: lp.c:16727
int SCIPcolGetLPPos(SCIP_COL *col)
Definition: lp.c:16680
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:16920
SCIP_RETCODE SCIPchgVarUbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_probing.c:400
static SCIP_DECL_HEURFREE(heurFreeShiftandpropagate)
void SCIPdisableVarHistory(SCIP *scip)
Definition: scip_var.c:8559
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:211
SCIP_Bool SCIPcolIsInLP(SCIP_COL *col)
Definition: lp.c:16702
#define ABS(x)
Definition: def.h:204
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:129
static SCIP_RETCODE getOptimalShiftingValue(SCIP *scip, CONSTRAINTMATRIX *matrix, int varindex, int direction, int *rowweights, SCIP_Real *steps, int *violationchange, SCIP_Real *beststep, int *rowviolations)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:377
memory allocation routines
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
Definition: scip_sol.c:1824