Scippy

SCIP

Solving Constraint Integer Programs

cutpool.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-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file cutpool.c
17  * @brief methods for storing cuts in a cut pool
18  * @author Tobias Achterberg
19  * @author Stefan Heinz
20  * @author Gerald Gamrath
21  * @author Marc Pfetsch
22  * @author Kati Wolter
23  */
24 
25 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
26 
27 #include <assert.h>
28 
29 #include "scip/def.h"
30 #include "scip/set.h"
31 #include "scip/stat.h"
32 #include "scip/clock.h"
33 #include "scip/lp.h"
34 #include "scip/cons.h"
35 #include "scip/sepa.h"
36 #include "scip/sepastore.h"
37 #include "scip/cutpool.h"
38 #include "scip/pub_message.h"
39 #include "scip/pub_misc.h"
40 
41 #include "scip/struct_cutpool.h"
42 
43 
44 
45 /*
46  * Hash functions
47  */
48 
49 /** gets the hash key of a cut */
50 static
51 SCIP_DECL_HASHGETKEY(hashGetKeyCut)
52 { /*lint --e{715}*/
53  SCIP_CUT* cut;
54 
55  cut = (SCIP_CUT*)elem;
56  assert(cut != NULL);
57  assert(cut->row != NULL);
58 
59  /* the key of a cut is the row */
60  return cut->row;
61 }
62 
63 /** returns TRUE iff both cuts are identical */
64 static
65 SCIP_DECL_HASHKEYEQ(hashKeyEqCut)
66 { /*lint --e{715}*/
67  /* Warning: The comparison of real values is made against default epsilon.
68  * This is ugly, but we have no settings at hand.
69  */
70  SCIP_ROW* row1;
71  SCIP_ROW* row2;
72 
73  row1 = (SCIP_ROW*)key1;
74  row2 = (SCIP_ROW*)key2;
75  assert(row1 != NULL);
76  assert(row2 != NULL);
77 
78  /* Sort the column indices of both rows.
79  *
80  * The columns in a row are divided into two parts: LP columns, which are currently in the LP and non-LP columns;
81  * we sort the rows, but that only ensures that within these two parts, columns are sorted w.r.t. their index.
82  * Normally, this should be suficient, because a column contained in both rows should either be one of the LP columns
83  * for both or one of the non-LP columns for both.
84  * However, directly after a row was created, before it is added to the LP, the row is not linked to all its
85  * columns and all columns are treated as non-LP columns.
86  * Therefore, if exactly one of the rows has no LP columns, we cannot rely on the partition, because this row might
87  * just have been created and also columns that are in the LP might be in the non-LP columns part.
88  */
89  SCIProwSort(row1);
90  SCIProwSort(row2);
91  assert(row1->lpcolssorted);
92  assert(row1->nonlpcolssorted);
93  assert(row1->validminmaxidx);
94  assert(row2->lpcolssorted);
95  assert(row2->nonlpcolssorted);
96  assert(row2->validminmaxidx);
97 
98  /* currently we are only handling rows which are completely linked or not linked at all */
99  assert(row1->nunlinked == 0 || row1->nlpcols == 0);
100  assert(row2->nunlinked == 0 || row2->nlpcols == 0);
101 
102  /* compare the trivial characteristics of the rows */
103  if( row1->len != row2->len
104  || row1->minidx != row2->minidx
105  || row1->maxidx != row2->maxidx
106  || row1->nummaxval != row2->nummaxval
107  || row1->numminval != row2->numminval
108  || REALABS(row1->lhs - row2->lhs) > SCIP_DEFAULT_EPSILON
109  || REALABS(row1->rhs - row2->rhs) > SCIP_DEFAULT_EPSILON
110  || REALABS(row1->maxval - row2->maxval) > SCIP_DEFAULT_EPSILON
111  || REALABS(row1->minval - row2->minval) > SCIP_DEFAULT_EPSILON
112  )
113  return FALSE;
114 
115  /* both rows have LP columns, or none of them has, or one has only LP colums and the other only non-LP columns,
116  * so we can rely on the sorting of the columns
117  */
118  if( (row1->nlpcols == 0) == (row2->nlpcols == 0)
119  || (row1->nlpcols == 0 && row2->nlpcols == row2->len)
120  || (row1->nlpcols == row1->len && row2->nlpcols == 0) )
121  {
122  int i;
123 
124  if( (row1->nlpcols == 0) == (row2->nlpcols == 0) )
125  {
126 #ifndef NDEBUG
127  /* in debug mode, we check that we can rely on the partition into LP columns and non-LP columns */
128  int i2;
129 
130  i = 0;
131  i2 = row2->nlpcols;
132  while( i < row1->nlpcols && i2 < row2->len )
133  {
134  assert(row1->cols[i] != row2->cols[i2]);
135  if( row1->cols[i]->index < row2->cols[i2]->index )
136  ++i;
137  else
138  {
139  assert(row1->cols[i]->index > row2->cols[i2]->index);
140  ++i2;
141  }
142  }
143  assert(i == row1->nlpcols || i2 == row2->len);
144 
145  i = row1->nlpcols;
146  i2 = 0;
147  while( i < row1->len && i2 < row2->nlpcols )
148  {
149  assert(row1->cols[i] != row2->cols[i2]);
150  if( row1->cols[i]->index < row2->cols[i2]->index )
151  ++i;
152  else
153  {
154  assert(row1->cols[i]->index > row2->cols[i2]->index);
155  ++i2;
156  }
157  }
158  assert(i == row1->len || i2 == row2->nlpcols);
159 #endif
160 
161  /* both rows are linked and the number of lpcolumns is not equal so they cannot be equal */
162  if( row1->nlpcols != row2->nlpcols )
163  return FALSE;
164  }
165 
166  /* compare the columns of the rows */
167  for( i = 0; i < row1->len; ++i )
168  {
169  if( row1->cols[i] != row2->cols[i] )
170  return FALSE;
171  }
172 
173  /* compare the coefficients of the rows */
174  for( i = 0; i < row1->len; ++i )
175  {
176  if( REALABS(row1->vals[i] - row2->vals[i]) > SCIP_DEFAULT_EPSILON )
177  return FALSE;
178  }
179  }
180  /* one row has LP columns, but the other not, that could be because the one without was just created and isn't
181  * linked yet; in this case, one column could be an LP column in one row and a non-LP column in the other row, so we
182  * cannot rely on the partition; thus, we iteratively check whether the next column of row1 is either the next LP
183  * column of row2 or the next non-LP column of row2 and the coefficients are equal
184  */
185  else
186  {
187  int i1;
188  int ilp;
189  int inlp;
190 
191  /* ensure that row1 is the row without LP columns, switch the rows, if neccessary */
192  if( row2->nlpcols == 0 )
193  {
194  SCIP_ROW* tmprow;
195  tmprow = row2;
196  row2 = row1;
197  row1 = tmprow;
198  }
199  assert(row1->nlpcols == 0 && row2->nlpcols > 0);
200 
201  ilp = 0;
202  inlp = row2->nlpcols;
203 
204  /* compare the columns and coefficients of the rows */
205  for( i1 = 0; i1 < row1->len; ++i1 )
206  {
207  /* current column of row1 is the current LP column of row2, check the coefficient */
208  if( ilp < row2->nlpcols && row1->cols[i1] == row2->cols[ilp] )
209  {
210  if( REALABS(row1->vals[i1] - row2->vals[ilp]) > SCIP_DEFAULT_EPSILON )
211  return FALSE;
212  else
213  ++ilp;
214  }
215  /* current column of row1 is the current non-LP column of row2, check the coefficient */
216  else if( inlp < row2->len && row1->cols[i1] == row2->cols[inlp] )
217  {
218  if( REALABS(row1->vals[i1] - row2->vals[inlp]) > SCIP_DEFAULT_EPSILON )
219  return FALSE;
220  else
221  ++inlp;
222  }
223  /* current column of row1 is neither the current LP column of row2, nor the current non-LP column of row 2 */
224  else
225  return FALSE;
226  }
227  }
228 
229  return TRUE;
230 }
231 
232 static
233 SCIP_DECL_HASHKEYVAL(hashKeyValCut)
234 { /*lint --e{715}*/
235  SCIP_ROW* row;
236  SCIP_Real maxval;
237  SCIP_Real minval;
238  SCIP_SET* set;
239 
240  set = (SCIP_SET*) userptr;
241  row = (SCIP_ROW*)key;
242  assert(row != NULL);
243 
244  maxval = SCIProwGetMaxval(row, set);
245  minval = SCIProwGetMinval(row, set);
246  assert(row->nummaxval > 0);
247  assert(row->numminval > 0);
248  assert(row->validminmaxidx);
249 
251  SCIPcombineThreeInt(row->len, row->minidx, row->maxidx));
252 }
253 
254 
255 /*
256  * dynamic memory arrays
257  */
258 
259 /** resizes cuts array to be able to store at least num entries */
260 static
262  SCIP_CUTPOOL* cutpool, /**< cut pool */
263  SCIP_SET* set, /**< global SCIP settings */
264  int num /**< minimal number of slots in array */
265  )
266 {
267  assert(cutpool != NULL);
268  assert(set != NULL);
269 
270  if( num > cutpool->cutssize )
271  {
272  int newsize;
273 
274  newsize = SCIPsetCalcMemGrowSize(set, num);
275  SCIP_ALLOC( BMSreallocMemoryArray(&cutpool->cuts, newsize) );
276  cutpool->cutssize = newsize;
277  }
278  assert(num <= cutpool->cutssize);
279 
280  return SCIP_OKAY;
281 }
282 
283 
284 
285 /*
286  * Cut methods
287  */
288 
289 /** creates a cut and captures the row */
290 static
292  SCIP_CUT** cut, /**< pointer to store the cut */
293  BMS_BLKMEM* blkmem, /**< block memory */
294  SCIP_ROW* row /**< row this cut represents */
295  )
296 {
297  assert(cut != NULL);
298  assert(blkmem != NULL);
299  assert(row != NULL);
300 
301  /* allocate cut memory */
302  SCIP_ALLOC( BMSallocBlockMemory(blkmem, cut) );
303  (*cut)->row = row;
304  (*cut)->age = 0;
305  (*cut)->processedlp = -1;
306  (*cut)->processedlpsol = -1;
307  (*cut)->pos = -1;
308 
309  /* capture row */
310  SCIProwCapture(row);
311 
312  return SCIP_OKAY;
313 }
314 
315 /** frees a cut and releases the row */
316 static
318  SCIP_CUT** cut, /**< pointer to store the cut */
319  BMS_BLKMEM* blkmem, /**< block memory */
320  SCIP_SET* set, /**< global SCIP settings */
321  SCIP_LP* lp /**< current LP data */
322  )
323 {
324  assert(cut != NULL);
325  assert(*cut != NULL);
326  assert((*cut)->row != NULL);
327  assert(blkmem != NULL);
328 
329  /* release row */
330  SCIP_CALL( SCIProwRelease(&(*cut)->row, blkmem, set, lp) );
331 
332  /* free cut memory */
333  BMSfreeBlockMemory(blkmem, cut);
334 
335  return SCIP_OKAY;
336 }
337 
338 /** returns whether the cut's age exceeds the age limit */
339 static
341  SCIP_CUT* cut, /**< cut to check */
342  int agelimit /**< maximum age a cut can reach before it is deleted from the pool, or -1 */
343  )
344 {
345  assert(cut != NULL);
346 
347  return (agelimit >= 0 && cut->age > agelimit);
348 }
349 
350 /** gets the row of the cut */
352  SCIP_CUT* cut /**< cut */
353  )
354 {
355  assert(cut != NULL);
356 
357  return cut->row;
358 }
359 
360 /** gets the age of the cut: the number of consecutive cut pool separation rounds where the cut was neither in the LP nor violated */
362  SCIP_CUT* cut /**< cut */
363  )
364 {
365  assert(cut != NULL);
366 
367  return cut->age;
368 }
369 
370 /** returns the ratio of LPs where the row belonging to this cut was active in an LP solution, i.e.
371  * where the age of its row has not been increased
372  *
373  * @see SCIPcutGetAge() to get the age of a cut
374  */
376  SCIP_CUT* cut /**< cut */
377  )
378 {
379  SCIP_Longint nlpsaftercreation;
380  SCIP_Longint activeinlpcounter;
381 
382  assert(cut != NULL);
383  assert(cut->row != NULL);
384 
385  nlpsaftercreation = SCIProwGetNLPsAfterCreation(cut->row);
386  activeinlpcounter = SCIProwGetActiveLPCount(cut->row);
387 
388  return (nlpsaftercreation > 0 ? activeinlpcounter / (SCIP_Real)nlpsaftercreation : 0.0);
389 }
390 
391 /*
392  * Cutpool methods
393  */
394 
395 /** creates cut pool */
397  SCIP_CUTPOOL** cutpool, /**< pointer to store cut pool */
398  BMS_BLKMEM* blkmem, /**< block memory */
399  SCIP_SET* set, /**< global SCIP settings */
400  int agelimit, /**< maximum age a cut can reach before it is deleted from the pool */
401  SCIP_Bool globalcutpool /**< is this the global cut pool of SCIP? */
402  )
403 {
404  assert(cutpool != NULL);
405  assert(agelimit >= -1);
406 
407  SCIP_ALLOC( BMSallocMemory(cutpool) );
408 
409  SCIP_CALL( SCIPclockCreate(&(*cutpool)->poolclock, SCIP_CLOCKTYPE_DEFAULT) );
410 
411  SCIP_CALL( SCIPhashtableCreate(&(*cutpool)->hashtable, blkmem,
412  (set->misc_usesmalltables ? SCIP_HASHSIZE_CUTPOOLS_SMALL : SCIP_HASHSIZE_CUTPOOLS),
413  hashGetKeyCut, hashKeyEqCut, hashKeyValCut, (void*) set) );
414 
415  (*cutpool)->cuts = NULL;
416  (*cutpool)->cutssize = 0;
417  (*cutpool)->ncuts = 0;
418  (*cutpool)->nremovablecuts = 0;
419  (*cutpool)->agelimit = agelimit;
420  (*cutpool)->processedlp = -1;
421  (*cutpool)->processedlpsol = -1;
422  (*cutpool)->firstunprocessed = 0;
423  (*cutpool)->firstunprocessedsol = 0;
424  (*cutpool)->maxncuts = 0;
425  (*cutpool)->ncalls = 0;
426  (*cutpool)->ncutsfound = 0;
427  (*cutpool)->globalcutpool = globalcutpool;
428 
429  return SCIP_OKAY;
430 }
431 
432 /** frees cut pool */
434  SCIP_CUTPOOL** cutpool, /**< pointer to store cut pool */
435  BMS_BLKMEM* blkmem, /**< block memory */
436  SCIP_SET* set, /**< global SCIP settings */
437  SCIP_LP* lp /**< current LP data */
438  )
439 {
440  assert(cutpool != NULL);
441  assert(*cutpool != NULL);
442 
443  /* remove all cuts from the pool */
444  SCIP_CALL( SCIPcutpoolClear(*cutpool, blkmem, set, lp) );
445 
446  /* free clock */
447  SCIPclockFree(&(*cutpool)->poolclock);
448 
449  /* free hash table */
450  SCIPhashtableFree(&(*cutpool)->hashtable);
451 
452  BMSfreeMemoryArrayNull(&(*cutpool)->cuts);
453  BMSfreeMemory(cutpool);
454 
455  return SCIP_OKAY;
456 }
457 
458 /** removes all rows from the cut pool */
460  SCIP_CUTPOOL* cutpool, /**< cut pool */
461  BMS_BLKMEM* blkmem, /**< block memory */
462  SCIP_SET* set, /**< global SCIP settings */
463  SCIP_LP* lp /**< current LP data */
464  )
465 {
466  int i;
467 
468  assert(cutpool != NULL);
469 
470  /* free cuts */
471  for( i = 0; i < cutpool->ncuts; ++i )
472  {
473  if( cutpool->globalcutpool )
474  cutpool->cuts[i]->row->inglobalcutpool = FALSE;
475  SCIProwUnlock(cutpool->cuts[i]->row);
476  SCIP_CALL( cutFree(&cutpool->cuts[i], blkmem, set, lp) );
477  }
478  cutpool->ncuts = 0;
479  cutpool->nremovablecuts = 0;
480 
481  return SCIP_OKAY;
482 }
483 
484 /** if not already existing, adds row to cut pool and captures it */
486  SCIP_CUTPOOL* cutpool, /**< cut pool */
487  BMS_BLKMEM* blkmem, /**< block memory */
488  SCIP_SET* set, /**< global SCIP settings */
489  SCIP_ROW* row /**< cutting plane to add */
490  )
491 {
492  assert(cutpool != NULL);
493  assert(row != NULL);
494 
495  /* only called to ensure that minidx and maxidx are up-to-date */
496  (void) SCIProwGetMaxidx(row, set);
497  assert(row->validminmaxidx);
498 
499  /* check in hash table, if cut already exists in the pool */
500  if( SCIPhashtableRetrieve(cutpool->hashtable, (void*)row) == NULL )
501  {
502  SCIP_CALL( SCIPcutpoolAddNewRow(cutpool, blkmem, set, row) );
503  }
504 
505  return SCIP_OKAY;
506 }
507 
508 /** adds row to cut pool and captures it; doesn't check for multiple cuts */
510  SCIP_CUTPOOL* cutpool, /**< cut pool */
511  BMS_BLKMEM* blkmem, /**< block memory */
512  SCIP_SET* set, /**< global SCIP settings */
513  SCIP_ROW* row /**< cutting plane to add */
514  )
515 {
516  SCIP_CUT* cut;
517 
518  assert(cutpool != NULL);
519  assert(row != NULL);
520 
521  /* check, if row is modifiable or local */
522  if( SCIProwIsModifiable(row) )
523  {
524  SCIPerrorMessage("cannot store modifiable row <%s> in a cut pool\n", SCIProwGetName(row));
525  return SCIP_INVALIDDATA;
526  }
527  if( SCIProwIsLocal(row) )
528  {
529  SCIPerrorMessage("cannot store locally valid row <%s> in a cut pool\n", SCIProwGetName(row));
530  return SCIP_INVALIDDATA;
531  }
532 
533  /* only called to ensure that minidx and maxidx are up-to-date */
534  (void) SCIProwGetMaxidx(row, set);
535  assert(row->validminmaxidx);
536 
537  /* create the cut */
538  SCIP_CALL( cutCreate(&cut, blkmem, row) );
539  cut->pos = cutpool->ncuts;
540 
541  /* add cut to the pool */
542  SCIP_CALL( cutpoolEnsureCutsMem(cutpool, set, cutpool->ncuts+1) );
543  cutpool->cuts[cutpool->ncuts] = cut;
544  cutpool->ncuts++;
545  cutpool->maxncuts = MAX(cutpool->maxncuts, cutpool->ncuts);
546  if( SCIProwIsRemovable(row) )
547  cutpool->nremovablecuts++;
548 
549  /* insert cut in the hash table */
550  SCIP_CALL( SCIPhashtableInsert(cutpool->hashtable, (void*)cut) );
551 
552  /* if this is the global cut pool of SCIP, mark the row to be member of the pool */
553  if( cutpool->globalcutpool )
554  row->inglobalcutpool = TRUE;
555 
556  /* lock the row */
557  SCIProwLock(row);
558 
559  return SCIP_OKAY;
560 }
561 
562 /** removes the cut from the cut pool */
563 static
565  SCIP_CUTPOOL* cutpool, /**< cut pool */
566  BMS_BLKMEM* blkmem, /**< block memory */
567  SCIP_SET* set, /**< global SCIP settings */
568  SCIP_STAT* stat, /**< problem statistics data */
569  SCIP_LP* lp, /**< current LP data */
570  SCIP_CUT* cut /**< cut to remove */
571  )
572 {
573  int pos;
574 
575  assert(cutpool != NULL);
576  assert(cutpool->firstunprocessed <= cutpool->ncuts);
577  assert(cutpool->firstunprocessedsol <= cutpool->ncuts);
578  assert(blkmem != NULL);
579  assert(stat != NULL);
580  assert(cutpool->processedlp <= stat->lpcount);
581  assert(cutpool->processedlpsol <= stat->lpcount);
582  assert(cut != NULL);
583  assert(cut->row != NULL);
584 
585  pos = cut->pos;
586  assert(0 <= pos && pos < cutpool->ncuts);
587  assert(cutpool->cuts[pos] == cut);
588 
589  /* decrease the number of removable cuts counter (row might have changed its removable status -> counting might not
590  * be correct
591  */
592  if( SCIProwIsRemovable(cut->row) && cutpool->nremovablecuts > 0 )
593  cutpool->nremovablecuts--;
594 
595  /* if this is the global cut pool of SCIP, mark the row to not be member anymore */
596  if( cutpool->globalcutpool )
597  cut->row->inglobalcutpool = FALSE;
598 
599  /* unlock the row */
600  SCIProwUnlock(cut->row);
601 
602  /* remove the cut from the hash table */
603  assert(SCIPhashtableExists(cutpool->hashtable, (void*)cut));
604  SCIP_CALL( SCIPhashtableRemove(cutpool->hashtable, (void*)cut) );
605 
606  /* free the cut */
607  SCIP_CALL( cutFree(&cutpool->cuts[pos], blkmem, set, lp) );
608 
609  /* move the last cut of the pool to the free position */
610  if( pos < cutpool->ncuts-1 )
611  {
612  cutpool->cuts[pos] = cutpool->cuts[cutpool->ncuts-1];
613  cutpool->cuts[pos]->pos = pos;
614  assert(cutpool->cuts[pos]->processedlp <= stat->lpcount);
615  assert(cutpool->cuts[pos]->processedlpsol <= stat->lpcount);
616  if( cutpool->cuts[pos]->processedlp < stat->lpcount )
617  cutpool->firstunprocessed = MIN(cutpool->firstunprocessed, pos);
618  if( cutpool->cuts[pos]->processedlpsol < stat->lpcount )
619  cutpool->firstunprocessedsol = MIN(cutpool->firstunprocessedsol, pos);
620  }
621  else
622  {
623  cutpool->firstunprocessed = MIN(cutpool->firstunprocessed, cutpool->ncuts-1);
624  cutpool->firstunprocessedsol = MIN(cutpool->firstunprocessedsol, cutpool->ncuts-1);
625  }
626 
627  cutpool->ncuts--;
628 
629  return SCIP_OKAY;
630 }
631 
632 /** removes the LP row from the cut pool */
634  SCIP_CUTPOOL* cutpool, /**< cut pool */
635  BMS_BLKMEM* blkmem, /**< block memory */
636  SCIP_SET* set, /**< global SCIP settings */
637  SCIP_STAT* stat, /**< problem statistics data */
638  SCIP_LP* lp, /**< current LP data */
639  SCIP_ROW* row /**< row to remove */
640  )
641 {
642  SCIP_CUT* cut;
643 
644  assert(cutpool != NULL);
645  assert(row != NULL);
646 
647  /* find the cut in hash table */
648  cut = (SCIP_CUT*)SCIPhashtableRetrieve(cutpool->hashtable, (void*)row);
649  if( cut == NULL )
650  {
651  SCIPerrorMessage("row <%s> is not existing in cutpool %p\n", SCIProwGetName(row), cutpool);
652  return SCIP_INVALIDDATA;
653  }
654 
655  SCIP_CALL( cutpoolDelCut(cutpool, blkmem, set, stat, lp, cut) );
656 
657  return SCIP_OKAY;
658 }
659 
660 
661 /** separates cuts of the cut pool */
663  SCIP_CUTPOOL* cutpool, /**< cut pool */
664  BMS_BLKMEM* blkmem, /**< block memory */
665  SCIP_SET* set, /**< global SCIP settings */
666  SCIP_STAT* stat, /**< problem statistics data */
667  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
668  SCIP_EVENTFILTER* eventfilter, /**< event filter for global events */
669  SCIP_LP* lp, /**< current LP data */
670  SCIP_SEPASTORE* sepastore, /**< separation storage */
671  SCIP_SOL* sol, /**< solution to be separated (or NULL for LP-solution) */
672  SCIP_Bool cutpoolisdelayed, /**< is the cutpool delayed (count cuts found)? */
673  SCIP_Bool root, /**< are we at the root node? */
674  SCIP_RESULT* result /**< pointer to store the result of the separation call */
675  )
676 {
677  SCIP_CUT* cut;
678  SCIP_Bool found;
679  SCIP_Bool cutoff;
680  int firstunproc;
681  int oldncuts;
682  int c;
683 
684  assert(cutpool != NULL);
685  assert(stat != NULL);
686  assert(cutpool->processedlp <= stat->lpcount);
687  assert(cutpool->processedlpsol <= stat->lpcount);
688  assert(cutpool->firstunprocessed <= cutpool->ncuts);
689  assert(cutpool->firstunprocessedsol <= cutpool->ncuts);
690  assert(result != NULL);
691 
692  *result = SCIP_DIDNOTRUN;
693 
694  /* don't separate cut pool in the root node, if there are no removable cuts */
695  if( root && cutpool->nremovablecuts == 0 )
696  return SCIP_OKAY;
697 
698  if ( sol == NULL )
699  {
700  if( cutpool->processedlp < stat->lpcount )
701  cutpool->firstunprocessed = 0;
702  if( cutpool->firstunprocessed == cutpool->ncuts )
703  return SCIP_OKAY;
704  firstunproc = cutpool->firstunprocessed;
705  }
706  else
707  {
708  if( cutpool->processedlpsol < stat->lpcount )
709  cutpool->firstunprocessedsol = 0;
710  if( cutpool->firstunprocessedsol == cutpool->ncuts )
711  return SCIP_OKAY;
712  firstunproc = cutpool->firstunprocessedsol;
713  }
714 
715  *result = SCIP_DIDNOTFIND;
716  cutpool->ncalls++;
717  found = FALSE;
718 
719  SCIPsetDebugMsg(set, "separating%s cut pool %p with %d cuts, beginning with cut %d\n", ( sol == NULL ) ? "" : " solution from", (void*)cutpool, cutpool->ncuts, firstunproc);
720 
721  /* start timing */
722  SCIPclockStart(cutpool->poolclock, set);
723 
724  /* remember the current total number of found cuts */
725  oldncuts = SCIPsepastoreGetNCuts(sepastore);
726 
727  /* process all unprocessed cuts in the pool */
728  cutoff = FALSE;
729  for( c = firstunproc; c < cutpool->ncuts; ++c )
730  {
731  SCIP_Longint proclp;
732 
733  cut = cutpool->cuts[c];
734  assert(cut != NULL);
735  assert(cut->processedlp <= stat->lpcount);
736  assert(cut->processedlpsol <= stat->lpcount);
737  assert(cut->pos == c);
738 
739  proclp = ( sol == NULL ) ? cut->processedlp : cut->processedlpsol;
740 
741  if( proclp < stat->lpcount )
742  {
743  SCIP_ROW* row;
744 
745  if ( sol == NULL )
746  cut->processedlp = stat->lpcount;
747  else
748  cut->processedlpsol = stat->lpcount;
749 
750  row = cut->row;
751  if( !SCIProwIsInLP(row) )
752  {
753  /* if the cut is a bound change (i.e. a row with only one variable), add it as bound change instead of LP
754  * row; hence, we want to remove the bound change cut from the SCIP cut pool
755  */
756  if( !SCIProwIsModifiable(row) && SCIProwGetNNonz(row) == 1 )
757  {
758  /* insert bound change cut into separation store which will force that cut */
759  SCIP_CALL( SCIPsepastoreAddCut(sepastore, blkmem, set, stat, eventqueue, eventfilter, lp, sol, row, FALSE, root, &cutoff) );
760  SCIP_CALL( cutpoolDelCut(cutpool, blkmem, set, stat, lp, cut) );
761 
762  if ( cutoff )
763  break;
764  }
765  else if( (sol == NULL && SCIProwIsLPEfficacious(row, set, stat, lp, root)) || (sol != NULL && SCIProwIsSolEfficacious(row, set, stat, sol, root)) )
766  {
767  /* insert cut in separation storage */
768  SCIPsetDebugMsg(set, " -> separated cut <%s> from the cut pool (feasibility: %g)\n",
769  SCIProwGetName(row), ( sol == NULL ) ? SCIProwGetLPFeasibility(row, set, stat, lp) : SCIProwGetSolFeasibility(row, set, stat, sol) );
770  SCIP_CALL( SCIPsepastoreAddCut(sepastore, blkmem, set, stat, eventqueue, eventfilter, lp, sol, row, FALSE, root, &cutoff) );
771 
772  /* count cuts */
773  if ( cutpoolisdelayed )
774  {
775  if ( SCIProwGetOriginSepa(row) != NULL )
776  {
777  SCIP_SEPA* sepa;
778 
779  sepa = SCIProwGetOriginSepa(row);
780  SCIPsepaIncNCutsFound(sepa);
782  }
783  else if ( SCIProwGetOriginCons(row) != NULL )
784  {
785  SCIP_CONSHDLR* conshdlr;
786 
787  conshdlr = SCIProwGetOriginCons(row);
788  SCIPconshdlrIncNCutsFound(conshdlr);
789  }
790  }
791 
792  found = TRUE;
793  cut->age = 0;
794 
795  if ( cutoff )
796  break;
797  }
798  else
799  {
800  cut->age++;
801  if( cutIsAged(cut, cutpool->agelimit) )
802  {
803  SCIP_CALL( cutpoolDelCut(cutpool, blkmem, set, stat, lp, cut) );
804  }
805  }
806  }
807  }
808  }
809 
810  if ( sol == NULL )
811  {
812  cutpool->processedlp = stat->lpcount;
813  cutpool->firstunprocessed = cutpool->ncuts;
814  }
815  else
816  {
817  cutpool->processedlpsol = stat->lpcount;
818  cutpool->firstunprocessedsol = cutpool->ncuts;
819  }
820 
821  /* update the number of found cuts */
822  cutpool->ncutsfound += SCIPsepastoreGetNCuts(sepastore) - oldncuts; /*lint !e776*/
823 
824  /* stop timing */
825  SCIPclockStop(cutpool->poolclock, set);
826 
827  if ( cutoff )
828  *result = SCIP_CUTOFF;
829  else if( found )
830  *result = SCIP_SEPARATED;
831 
832  return SCIP_OKAY;
833 }
834 
835 /** gets array of cuts in the cut pool */
837  SCIP_CUTPOOL* cutpool /**< cut pool */
838  )
839 {
840  assert(cutpool != NULL);
841 
842  return cutpool->cuts;
843 }
844 
845 /** gets number of cuts in the cut pool */
847  SCIP_CUTPOOL* cutpool /**< cut pool */
848  )
849 {
850  assert(cutpool != NULL);
851 
852  return cutpool->ncuts;
853 }
854 
855 /** gets maximum number of cuts that were stored in the cut pool at the same time */
857  SCIP_CUTPOOL* cutpool /**< cut pool */
858  )
859 {
860  assert(cutpool != NULL);
861 
862  return cutpool->maxncuts;
863 }
864 
865 /** gets time in seconds used for separating cuts from the pool */
867  SCIP_CUTPOOL* cutpool /**< cut pool */
868  )
869 {
870  assert(cutpool != NULL);
871 
872  return SCIPclockGetTime(cutpool->poolclock);
873 }
874 
875 /** get number of times, the cut pool was separated */
877  SCIP_CUTPOOL* cutpool /**< cut pool */
878  )
879 {
880  assert(cutpool != NULL);
881 
882  return cutpool->ncalls;
883 }
884 
885 /** get total number of cuts that were separated from the cut pool */
887  SCIP_CUTPOOL* cutpool /**< cut pool */
888  )
889 {
890  assert(cutpool != NULL);
891 
892  return cutpool->ncutsfound;
893 }
894 
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
internal methods for separators
SCIP_Bool SCIProwIsRemovable(SCIP_ROW *row)
Definition: lp.c:16520
SCIP_ROW * row
int nunlinked
Definition: struct_lp.h:228
SCIP_Real SCIProwGetSolFeasibility(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_SOL *sol)
Definition: lp.c:6338
int SCIProwGetMaxidx(SCIP_ROW *row, SCIP_SET *set)
Definition: lp.c:6521
SCIP_HASHTABLE * hashtable
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:107
int nummaxval
Definition: struct_lp.h:235
#define SCIP_HASHSIZE_CUTPOOLS
Definition: def.h:236
SCIP_SEPA * SCIProwGetOriginSepa(SCIP_ROW *row)
Definition: lp.c:16555
SCIP_Longint processedlp
SCIP_Real SCIProwGetMinval(SCIP_ROW *row, SCIP_SET *set)
Definition: lp.c:6505
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2253
SCIP_CUT ** cuts
SCIP_Longint SCIPcutpoolGetNCutsFound(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:886
internal methods for clocks and timing issues
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:16312
void SCIProwCapture(SCIP_ROW *row)
Definition: lp.c:5169
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:16450
SCIP_Longint SCIProwGetActiveLPCount(SCIP_ROW *row)
Definition: lp.c:16624
void SCIPclockStop(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:350
#define FALSE
Definition: def.h:64
SCIP_Longint processedlpsol
void SCIPclockStart(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:280
#define TRUE
Definition: def.h:63
SCIP_Real SCIPcutGetLPActivityQuot(SCIP_CUT *cut)
Definition: cutpool.c:375
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Longint SCIPcutpoolGetNCalls(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:876
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:5091
void SCIPsepaIncNCutsFoundAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:819
int index
Definition: struct_lp.h:158
static SCIP_RETCODE cutpoolDelCut(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp, SCIP_CUT *cut)
Definition: cutpool.c:564
int SCIPcutpoolGetMaxNCuts(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:856
static SCIP_RETCODE cutFree(SCIP_CUT **cut, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: cutpool.c:317
#define BMSfreeMemory(ptr)
Definition: memory.h:104
SCIP_Longint processedlp
SCIP_RETCODE SCIPcutpoolFree(SCIP_CUTPOOL **cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: cutpool.c:433
int nlpcols
Definition: struct_lp.h:227
internal methods for LP management
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:2014
#define SCIP_DEFAULT_EPSILON
Definition: def.h:151
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
Definition: lp.c:16602
SCIP_Real * vals
Definition: struct_lp.h:220
SCIP_RETCODE SCIPcutpoolDelRow(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp, SCIP_ROW *row)
Definition: cutpool.c:633
void SCIProwSort(SCIP_ROW *row)
Definition: lp.c:5846
SCIP_RETCODE SCIPcutpoolAddNewRow(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_ROW *row)
Definition: cutpool.c:509
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_Longint lpcount
Definition: struct_stat.h:169
static SCIP_RETCODE cutCreate(SCIP_CUT **cut, BMS_BLKMEM *blkmem, SCIP_ROW *row)
Definition: cutpool.c:291
SCIP_COL ** cols
Definition: struct_lp.h:218
#define SCIPcombineThreeInt(a, b, c)
Definition: pub_misc.h:480
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:16500
SCIP_Real minval
Definition: struct_lp.h:203
static INLINE uint32_t SCIPrealHashCode(double x)
Definition: pub_misc.h:488
static SCIP_DECL_HASHKEYVAL(hashKeyValCut)
Definition: cutpool.c:233
SCIP_Real lhs
Definition: struct_lp.h:195
SCIP_Longint processedlpsol
int SCIPsepastoreGetNCuts(SCIP_SEPASTORE *sepastore)
Definition: sepastore.c:1328
SCIP_Real SCIPclockGetTime(SCIP_CLOCK *clck)
Definition: clock.c:428
datastructures for storing cuts in a cut pool
#define NULL
Definition: lpi_spx1.cpp:137
SCIP_CONSHDLR * SCIProwGetOriginCons(SCIP_ROW *row)
Definition: lp.c:16540
#define REALABS(x)
Definition: def.h:169
int maxidx
Definition: struct_lp.h:234
SCIP_ROW * SCIPcutGetRow(SCIP_CUT *cut)
Definition: cutpool.c:351
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:316
#define SCIPhashTwo(a, b)
Definition: pub_misc.h:472
SCIP_RETCODE SCIPcutpoolClear(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: cutpool.c:459
SCIP_RETCODE SCIPhashtableRemove(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2383
SCIP_CUT ** SCIPcutpoolGetCuts(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:836
int SCIPcutpoolGetNCuts(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:846
internal methods for storing separated cuts
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:16510
SCIP_Bool SCIProwIsSolEfficacious(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_SOL *sol, SCIP_Bool root)
Definition: lp.c:6653
SCIP_RETCODE SCIProwRelease(SCIP_ROW **row, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: lp.c:5182
SCIP_RETCODE SCIPclockCreate(SCIP_CLOCK **clck, SCIP_CLOCKTYPE clocktype)
Definition: clock.c:160
void SCIPconshdlrIncNCutsFound(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4799
SCIP_RETCODE SCIPcutpoolAddRow(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_ROW *row)
Definition: cutpool.c:485
#define BMSfreeBlockMemory(mem, ptr)
Definition: memory.h:423
public data structures and miscellaneous methods
SCIP_RETCODE SCIPsepastoreAddCut(SCIP_SEPASTORE *sepastore, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_LP *lp, SCIP_SOL *sol, SCIP_ROW *cut, SCIP_Bool forcecut, SCIP_Bool root, SCIP_Bool *infeasible)
Definition: sepastore.c:406
#define SCIP_Bool
Definition: def.h:61
int numminval
Definition: struct_lp.h:236
void SCIPclockFree(SCIP_CLOCK **clck)
Definition: clock.c:175
#define MAX(x, y)
Definition: tclique_def.h:75
#define SCIP_HASHSIZE_CUTPOOLS_SMALL
Definition: def.h:239
#define SCIPsetDebugMsg
Definition: set.h:1870
int minidx
Definition: struct_lp.h:233
SCIP_RETCODE SCIPcutpoolCreate(SCIP_CUTPOOL **cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, int agelimit, SCIP_Bool globalcutpool)
Definition: cutpool.c:396
unsigned int lpcolssorted
Definition: struct_lp.h:240
internal methods for storing cuts in a cut pool
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
Definition: misc.c:2314
int firstunprocessedsol
SCIP_CLOCK * poolclock
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:2064
void SCIProwLock(SCIP_ROW *row)
Definition: lp.c:5208
SCIP_Real maxval
Definition: struct_lp.h:202
SCIP_Real rhs
Definition: struct_lp.h:196
SCIP_Longint ncalls
SCIP_Bool SCIProwIsLPEfficacious(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp, SCIP_Bool root)
Definition: lp.c:6594
unsigned int inglobalcutpool
Definition: struct_lp.h:251
public methods for message output
SCIP_Longint ncutsfound
SCIP_Real SCIProwGetLPFeasibility(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp)
Definition: lp.c:6084
#define SCIP_Real
Definition: def.h:145
internal methods for problem statistics
#define MIN(x, y)
Definition: memory.c:75
#define BMSallocMemory(ptr)
Definition: memory.h:78
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:86
internal methods for constraints and constraint handlers
void SCIPsepaIncNCutsFound(SCIP_SEPA *sepa)
Definition: sepa.c:809
SCIP_RETCODE SCIPcutpoolSeparate(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_LP *lp, SCIP_SEPASTORE *sepastore, SCIP_SOL *sol, SCIP_Bool cutpoolisdelayed, SCIP_Bool root, SCIP_RESULT *result)
Definition: cutpool.c:662
#define SCIP_Longint
Definition: def.h:130
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2365
SCIP_Real SCIProwGetMaxval(SCIP_ROW *row, SCIP_SET *set)
Definition: lp.c:6489
#define BMSallocBlockMemory(mem, ptr)
Definition: memory.h:410
SCIP_Real SCIPcutpoolGetTime(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:866
SCIP_Bool globalcutpool
int SCIPcutGetAge(SCIP_CUT *cut)
Definition: cutpool.c:361
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:396
unsigned int validminmaxidx
Definition: struct_lp.h:243
#define SCIPcombineTwoInt(a, b)
Definition: pub_misc.h:478
#define SCIP_ALLOC(x)
Definition: def.h:327
unsigned int nonlpcolssorted
Definition: struct_lp.h:241
SCIP_Longint SCIProwGetNLPsAfterCreation(SCIP_ROW *row)
Definition: lp.c:16634
static SCIP_Bool cutIsAged(SCIP_CUT *cut, int agelimit)
Definition: cutpool.c:340
static SCIP_DECL_HASHGETKEY(hashGetKeyCut)
Definition: cutpool.c:51
static SCIP_DECL_HASHKEYEQ(hashKeyEqCut)
Definition: cutpool.c:65
static SCIP_RETCODE cutpoolEnsureCutsMem(SCIP_CUTPOOL *cutpool, SCIP_SET *set, int num)
Definition: cutpool.c:261
int len
Definition: struct_lp.h:226
int age
Definition: struct_lp.h:237
void SCIProwUnlock(SCIP_ROW *row)
Definition: lp.c:5223