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-2016 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file 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  || REALABS(row1->lhs - row2->lhs) > SCIP_DEFAULT_EPSILON
108  || REALABS(row1->rhs - row2->rhs) > SCIP_DEFAULT_EPSILON
109  || REALABS(row1->sqrnorm - row2->sqrnorm) > SCIP_DEFAULT_SUMEPSILON
110  || REALABS(row1->sumnorm - row2->sumnorm) > SCIP_DEFAULT_SUMEPSILON
111  || REALABS(row1->maxval - row2->maxval) > 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  unsigned int keyval;
237  int maxabsval;
238  SCIP_Real maxval;
239  SCIP_SET* set;
240 
241  set = (SCIP_SET*) userptr;
242  row = (SCIP_ROW*)key;
243  assert(row != NULL);
244 
245  maxval = SCIProwGetMaxval(row, set);
246  assert(row->nummaxval > 0);
247  assert(row->validminmaxidx);
248 
249  if( maxval > (SCIP_Real) INT_MAX )
250  maxabsval = 0;
251  else if( maxval < 1.0 )
252  maxabsval = (int) (10000*maxval);
253  else
254  maxabsval = (int) maxval;
255 
256  keyval = (row->maxidx << 29) + (row->len << 22) + (row->minidx << 11) + maxabsval; /*lint !e701*/
257 
258  return keyval;
259 }
260 
261 
262 
263 /*
264  * dynamic memory arrays
265  */
266 
267 /** resizes cuts array to be able to store at least num entries */
268 static
270  SCIP_CUTPOOL* cutpool, /**< cut pool */
271  SCIP_SET* set, /**< global SCIP settings */
272  int num /**< minimal number of slots in array */
273  )
274 {
275  assert(cutpool != NULL);
276  assert(set != NULL);
277 
278  if( num > cutpool->cutssize )
279  {
280  int newsize;
281 
282  newsize = SCIPsetCalcMemGrowSize(set, num);
283  SCIP_ALLOC( BMSreallocMemoryArray(&cutpool->cuts, newsize) );
284  cutpool->cutssize = newsize;
285  }
286  assert(num <= cutpool->cutssize);
287 
288  return SCIP_OKAY;
289 }
290 
291 
292 
293 /*
294  * Cut methods
295  */
296 
297 /** creates a cut and captures the row */
298 static
300  SCIP_CUT** cut, /**< pointer to store the cut */
301  BMS_BLKMEM* blkmem, /**< block memory */
302  SCIP_ROW* row /**< row this cut represents */
303  )
304 {
305  assert(cut != NULL);
306  assert(blkmem != NULL);
307  assert(row != NULL);
308 
309  /* allocate cut memory */
310  SCIP_ALLOC( BMSallocBlockMemory(blkmem, cut) );
311  (*cut)->row = row;
312  (*cut)->age = 0;
313  (*cut)->processedlp = -1;
314  (*cut)->processedlpsol = -1;
315  (*cut)->pos = -1;
316 
317  /* capture row */
318  SCIProwCapture(row);
319 
320  return SCIP_OKAY;
321 }
322 
323 /** frees a cut and releases the row */
324 static
326  SCIP_CUT** cut, /**< pointer to store the cut */
327  BMS_BLKMEM* blkmem, /**< block memory */
328  SCIP_SET* set, /**< global SCIP settings */
329  SCIP_LP* lp /**< current LP data */
330  )
331 {
332  assert(cut != NULL);
333  assert(*cut != NULL);
334  assert((*cut)->row != NULL);
335  assert(blkmem != NULL);
336 
337  /* release row */
338  SCIP_CALL( SCIProwRelease(&(*cut)->row, blkmem, set, lp) );
339 
340  /* free cut memory */
341  BMSfreeBlockMemory(blkmem, cut);
342 
343  return SCIP_OKAY;
344 }
345 
346 /** returns whether the cut's age exceeds the age limit */
347 static
349  SCIP_CUT* cut, /**< cut to check */
350  int agelimit /**< maximum age a cut can reach before it is deleted from the pool, or -1 */
351  )
352 {
353  assert(cut != NULL);
354 
355  return (agelimit >= 0 && cut->age > agelimit);
356 }
357 
358 /** gets the row of the cut */
360  SCIP_CUT* cut /**< cut */
361  )
362 {
363  assert(cut != NULL);
364 
365  return cut->row;
366 }
367 
368 /** gets the age of the cut: the number of consecutive cut pool separation rounds where the cut was neither in the LP nor violated */
370  SCIP_CUT* cut /**< cut */
371  )
372 {
373  assert(cut != NULL);
374 
375  return cut->age;
376 }
377 
378 /** returns the ratio of LPs where the row belonging to this cut was active in an LP solution, i.e.
379  * where the age of its row has not been increased
380  *
381  * @see SCIPcutGetAge() to get the age of a cut
382  */
384  SCIP_CUT* cut /**< cut */
385  )
386 {
387  SCIP_Longint nlpsaftercreation;
388  SCIP_Longint activeinlpcounter;
389 
390  assert(cut != NULL);
391  assert(cut->row != NULL);
392 
393  nlpsaftercreation = SCIProwGetNLPsAfterCreation(cut->row);
394  activeinlpcounter = SCIProwGetActiveLPCount(cut->row);
395 
396  return (nlpsaftercreation > 0 ? activeinlpcounter / (SCIP_Real)nlpsaftercreation : 0.0);
397 }
398 
399 /*
400  * Cutpool methods
401  */
402 
403 /** creates cut pool */
405  SCIP_CUTPOOL** cutpool, /**< pointer to store cut pool */
406  BMS_BLKMEM* blkmem, /**< block memory */
407  SCIP_SET* set, /**< global SCIP settings */
408  int agelimit, /**< maximum age a cut can reach before it is deleted from the pool */
409  SCIP_Bool globalcutpool /**< is this the global cut pool of SCIP? */
410  )
411 {
412  assert(cutpool != NULL);
413  assert(agelimit >= -1);
414 
415  SCIP_ALLOC( BMSallocMemory(cutpool) );
416 
417  SCIP_CALL( SCIPclockCreate(&(*cutpool)->poolclock, SCIP_CLOCKTYPE_DEFAULT) );
418 
419  SCIP_CALL( SCIPhashtableCreate(&(*cutpool)->hashtable, blkmem,
420  (set->misc_usesmalltables ? SCIP_HASHSIZE_CUTPOOLS_SMALL : SCIP_HASHSIZE_CUTPOOLS),
421  hashGetKeyCut, hashKeyEqCut, hashKeyValCut, (void*) set) );
422 
423  (*cutpool)->cuts = NULL;
424  (*cutpool)->cutssize = 0;
425  (*cutpool)->ncuts = 0;
426  (*cutpool)->nremovablecuts = 0;
427  (*cutpool)->agelimit = agelimit;
428  (*cutpool)->processedlp = -1;
429  (*cutpool)->processedlpsol = -1;
430  (*cutpool)->firstunprocessed = 0;
431  (*cutpool)->firstunprocessedsol = 0;
432  (*cutpool)->maxncuts = 0;
433  (*cutpool)->ncalls = 0;
434  (*cutpool)->ncutsfound = 0;
435  (*cutpool)->globalcutpool = globalcutpool;
436 
437  return SCIP_OKAY;
438 }
439 
440 /** frees cut pool */
442  SCIP_CUTPOOL** cutpool, /**< pointer to store cut pool */
443  BMS_BLKMEM* blkmem, /**< block memory */
444  SCIP_SET* set, /**< global SCIP settings */
445  SCIP_LP* lp /**< current LP data */
446  )
447 {
448  assert(cutpool != NULL);
449  assert(*cutpool != NULL);
450 
451  /* remove all cuts from the pool */
452  SCIP_CALL( SCIPcutpoolClear(*cutpool, blkmem, set, lp) );
453 
454  /* free clock */
455  SCIPclockFree(&(*cutpool)->poolclock);
456 
457  /* free hash table */
458  SCIPhashtableFree(&(*cutpool)->hashtable);
459 
460  BMSfreeMemoryArrayNull(&(*cutpool)->cuts);
461  BMSfreeMemory(cutpool);
462 
463  return SCIP_OKAY;
464 }
465 
466 /** removes all rows from the cut pool */
468  SCIP_CUTPOOL* cutpool, /**< cut pool */
469  BMS_BLKMEM* blkmem, /**< block memory */
470  SCIP_SET* set, /**< global SCIP settings */
471  SCIP_LP* lp /**< current LP data */
472  )
473 {
474  int i;
475 
476  assert(cutpool != NULL);
477 
478  /* free cuts */
479  for( i = 0; i < cutpool->ncuts; ++i )
480  {
481  if( cutpool->globalcutpool )
482  cutpool->cuts[i]->row->inglobalcutpool = FALSE;
483  SCIProwUnlock(cutpool->cuts[i]->row);
484  SCIP_CALL( cutFree(&cutpool->cuts[i], blkmem, set, lp) );
485  }
486  cutpool->ncuts = 0;
487  cutpool->nremovablecuts = 0;
488 
489  return SCIP_OKAY;
490 }
491 
492 /** if not already existing, adds row to cut pool and captures it */
494  SCIP_CUTPOOL* cutpool, /**< cut pool */
495  BMS_BLKMEM* blkmem, /**< block memory */
496  SCIP_SET* set, /**< global SCIP settings */
497  SCIP_ROW* row /**< cutting plane to add */
498  )
499 {
500  assert(cutpool != NULL);
501  assert(row != NULL);
502 
503  /* only called to ensure that minidx and maxidx are up-to-date */
504  (void) SCIProwGetMaxidx(row, set);
505  assert(row->validminmaxidx);
506 
507  /* check in hash table, if cut already exists in the pool */
508  if( SCIPhashtableRetrieve(cutpool->hashtable, (void*)row) == NULL )
509  {
510  SCIP_CALL( SCIPcutpoolAddNewRow(cutpool, blkmem, set, row) );
511  }
512 
513  return SCIP_OKAY;
514 }
515 
516 /** adds row to cut pool and captures it; doesn't check for multiple cuts */
518  SCIP_CUTPOOL* cutpool, /**< cut pool */
519  BMS_BLKMEM* blkmem, /**< block memory */
520  SCIP_SET* set, /**< global SCIP settings */
521  SCIP_ROW* row /**< cutting plane to add */
522  )
523 {
524  SCIP_CUT* cut;
525 
526  assert(cutpool != NULL);
527  assert(row != NULL);
528 
529  /* check, if row is modifiable or local */
530  if( SCIProwIsModifiable(row) )
531  {
532  SCIPerrorMessage("cannot store modifiable row <%s> in a cut pool\n", SCIProwGetName(row));
533  return SCIP_INVALIDDATA;
534  }
535  if( SCIProwIsLocal(row) )
536  {
537  SCIPerrorMessage("cannot store locally valid row <%s> in a cut pool\n", SCIProwGetName(row));
538  return SCIP_INVALIDDATA;
539  }
540 
541  /* only called to ensure that minidx and maxidx are up-to-date */
542  (void) SCIProwGetMaxidx(row, set);
543  assert(row->validminmaxidx);
544 
545  /* create the cut */
546  SCIP_CALL( cutCreate(&cut, blkmem, row) );
547  cut->pos = cutpool->ncuts;
548 
549  /* add cut to the pool */
550  SCIP_CALL( cutpoolEnsureCutsMem(cutpool, set, cutpool->ncuts+1) );
551  cutpool->cuts[cutpool->ncuts] = cut;
552  cutpool->ncuts++;
553  cutpool->maxncuts = MAX(cutpool->maxncuts, cutpool->ncuts);
554  if( SCIProwIsRemovable(row) )
555  cutpool->nremovablecuts++;
556 
557  /* insert cut in the hash table */
558  SCIP_CALL( SCIPhashtableInsert(cutpool->hashtable, (void*)cut) );
559 
560  /* if this is the global cut pool of SCIP, mark the row to be member of the pool */
561  if( cutpool->globalcutpool )
562  row->inglobalcutpool = TRUE;
563 
564  /* lock the row */
565  SCIProwLock(row);
566 
567  return SCIP_OKAY;
568 }
569 
570 /** removes the cut from the cut pool */
571 static
573  SCIP_CUTPOOL* cutpool, /**< cut pool */
574  BMS_BLKMEM* blkmem, /**< block memory */
575  SCIP_SET* set, /**< global SCIP settings */
576  SCIP_STAT* stat, /**< problem statistics data */
577  SCIP_LP* lp, /**< current LP data */
578  SCIP_CUT* cut /**< cut to remove */
579  )
580 {
581  int pos;
582 
583  assert(cutpool != NULL);
584  assert(cutpool->firstunprocessed <= cutpool->ncuts);
585  assert(cutpool->firstunprocessedsol <= cutpool->ncuts);
586  assert(blkmem != NULL);
587  assert(stat != NULL);
588  assert(cutpool->processedlp <= stat->lpcount);
589  assert(cutpool->processedlpsol <= stat->lpcount);
590  assert(cut != NULL);
591  assert(cut->row != NULL);
592 
593  pos = cut->pos;
594  assert(0 <= pos && pos < cutpool->ncuts);
595  assert(cutpool->cuts[pos] == cut);
596 
597  /* decrease the number of removable cuts counter (row might have changed its removable status -> counting might not
598  * be correct
599  */
600  if( SCIProwIsRemovable(cut->row) && cutpool->nremovablecuts > 0 )
601  cutpool->nremovablecuts--;
602 
603  /* if this is the global cut pool of SCIP, mark the row to not be member anymore */
604  if( cutpool->globalcutpool )
605  cut->row->inglobalcutpool = FALSE;
606 
607  /* unlock the row */
608  SCIProwUnlock(cut->row);
609 
610  /* remove the cut from the hash table */
611  assert(SCIPhashtableExists(cutpool->hashtable, (void*)cut));
612  SCIP_CALL( SCIPhashtableRemove(cutpool->hashtable, (void*)cut) );
613 
614  /* free the cut */
615  SCIP_CALL( cutFree(&cutpool->cuts[pos], blkmem, set, lp) );
616 
617  /* move the last cut of the pool to the free position */
618  if( pos < cutpool->ncuts-1 )
619  {
620  cutpool->cuts[pos] = cutpool->cuts[cutpool->ncuts-1];
621  cutpool->cuts[pos]->pos = pos;
622  assert(cutpool->cuts[pos]->processedlp <= stat->lpcount);
623  assert(cutpool->cuts[pos]->processedlpsol <= stat->lpcount);
624  if( cutpool->cuts[pos]->processedlp < stat->lpcount )
625  cutpool->firstunprocessed = MIN(cutpool->firstunprocessed, pos);
626  if( cutpool->cuts[pos]->processedlpsol < stat->lpcount )
627  cutpool->firstunprocessedsol = MIN(cutpool->firstunprocessedsol, pos);
628  }
629  else
630  {
631  cutpool->firstunprocessed = MIN(cutpool->firstunprocessed, cutpool->ncuts-1);
632  cutpool->firstunprocessedsol = MIN(cutpool->firstunprocessedsol, cutpool->ncuts-1);
633  }
634 
635  cutpool->ncuts--;
636 
637  return SCIP_OKAY;
638 }
639 
640 /** removes the LP row from the cut pool */
642  SCIP_CUTPOOL* cutpool, /**< cut pool */
643  BMS_BLKMEM* blkmem, /**< block memory */
644  SCIP_SET* set, /**< global SCIP settings */
645  SCIP_STAT* stat, /**< problem statistics data */
646  SCIP_LP* lp, /**< current LP data */
647  SCIP_ROW* row /**< row to remove */
648  )
649 {
650  SCIP_CUT* cut;
651 
652  assert(cutpool != NULL);
653  assert(row != NULL);
654 
655  /* find the cut in hash table */
656  cut = (SCIP_CUT*)SCIPhashtableRetrieve(cutpool->hashtable, (void*)row);
657  if( cut == NULL )
658  {
659  SCIPerrorMessage("row <%s> is not existing in cutpool %p\n", SCIProwGetName(row), cutpool);
660  return SCIP_INVALIDDATA;
661  }
662 
663  SCIP_CALL( cutpoolDelCut(cutpool, blkmem, set, stat, lp, cut) );
664 
665  return SCIP_OKAY;
666 }
667 
668 
669 /** separates cuts of the cut pool */
671  SCIP_CUTPOOL* cutpool, /**< cut pool */
672  BMS_BLKMEM* blkmem, /**< block memory */
673  SCIP_SET* set, /**< global SCIP settings */
674  SCIP_STAT* stat, /**< problem statistics data */
675  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
676  SCIP_EVENTFILTER* eventfilter, /**< event filter for global events */
677  SCIP_LP* lp, /**< current LP data */
678  SCIP_SEPASTORE* sepastore, /**< separation storage */
679  SCIP_SOL* sol, /**< solution to be separated (or NULL for LP-solution) */
680  SCIP_Bool cutpoolisdelayed, /**< is the cutpool delayed (count cuts found)? */
681  SCIP_Bool root, /**< are we at the root node? */
682  SCIP_RESULT* result /**< pointer to store the result of the separation call */
683  )
684 {
685  SCIP_CUT* cut;
686  SCIP_Bool found;
687  SCIP_Bool cutoff;
688  int firstunproc;
689  int oldncuts;
690  int c;
691 
692  assert(cutpool != NULL);
693  assert(stat != NULL);
694  assert(cutpool->processedlp <= stat->lpcount);
695  assert(cutpool->processedlpsol <= stat->lpcount);
696  assert(cutpool->firstunprocessed <= cutpool->ncuts);
697  assert(cutpool->firstunprocessedsol <= cutpool->ncuts);
698  assert(result != NULL);
699 
700  *result = SCIP_DIDNOTRUN;
701 
702  /* don't separate cut pool in the root node, if there are no removable cuts */
703  if( root && cutpool->nremovablecuts == 0 )
704  return SCIP_OKAY;
705 
706  if ( sol == NULL )
707  {
708  if( cutpool->processedlp < stat->lpcount )
709  cutpool->firstunprocessed = 0;
710  if( cutpool->firstunprocessed == cutpool->ncuts )
711  return SCIP_OKAY;
712  firstunproc = cutpool->firstunprocessed;
713  }
714  else
715  {
716  if( cutpool->processedlpsol < stat->lpcount )
717  cutpool->firstunprocessedsol = 0;
718  if( cutpool->firstunprocessedsol == cutpool->ncuts )
719  return SCIP_OKAY;
720  firstunproc = cutpool->firstunprocessedsol;
721  }
722 
723  *result = SCIP_DIDNOTFIND;
724  cutpool->ncalls++;
725  found = FALSE;
726 
727  SCIPdebugMessage("separating%s cut pool %p with %d cuts, beginning with cut %d\n", ( sol == NULL ) ? "" : " solution from", (void*)cutpool, cutpool->ncuts, firstunproc);
728 
729  /* start timing */
730  SCIPclockStart(cutpool->poolclock, set);
731 
732  /* remember the current total number of found cuts */
733  oldncuts = SCIPsepastoreGetNCuts(sepastore);
734 
735  /* process all unprocessed cuts in the pool */
736  cutoff = FALSE;
737  for( c = firstunproc; c < cutpool->ncuts; ++c )
738  {
739  SCIP_Longint proclp;
740 
741  cut = cutpool->cuts[c];
742  assert(cut != NULL);
743  assert(cut->processedlp <= stat->lpcount);
744  assert(cut->processedlpsol <= stat->lpcount);
745  assert(cut->pos == c);
746 
747  proclp = ( sol == NULL ) ? cut->processedlp : cut->processedlpsol;
748 
749  if( proclp < stat->lpcount )
750  {
751  SCIP_ROW* row;
752 
753  if ( sol == NULL )
754  cut->processedlp = stat->lpcount;
755  else
756  cut->processedlpsol = stat->lpcount;
757 
758  row = cut->row;
759  if( !SCIProwIsInLP(row) )
760  {
761  /* if the cut is a bound change (i.e. a row with only one variable), add it as bound change instead of LP
762  * row; hence, we want to remove the bound change cut from the SCIP cut pool
763  */
764  if( !SCIProwIsModifiable(row) && SCIProwGetNNonz(row) == 1 )
765  {
766  /* insert bound change cut into separation store which will force that cut */
767  SCIP_CALL( SCIPsepastoreAddCut(sepastore, blkmem, set, stat, eventqueue, eventfilter, lp, sol, row, FALSE, root, &cutoff) );
768  SCIP_CALL( cutpoolDelCut(cutpool, blkmem, set, stat, lp, cut) );
769 
770  if ( cutoff )
771  break;
772  }
773  else if( (sol == NULL && SCIProwIsLPEfficacious(row, set, stat, lp, root)) || (sol != NULL && SCIProwIsSolEfficacious(row, set, stat, sol, root)) )
774  {
775  /* insert cut in separation storage */
776  SCIPdebugMessage(" -> separated cut <%s> from the cut pool (feasibility: %g)\n",
777  SCIProwGetName(row), ( sol == NULL ) ? SCIProwGetLPFeasibility(row, set, stat, lp) : SCIProwGetSolFeasibility(row, set, stat, sol) );
778  SCIP_CALL( SCIPsepastoreAddCut(sepastore, blkmem, set, stat, eventqueue, eventfilter, lp, sol, row, FALSE, root, &cutoff) );
779 
780  /* count cuts */
781  if ( cutpoolisdelayed )
782  {
783  if ( SCIProwGetOriginSepa(row) != NULL )
784  {
785  SCIP_SEPA* sepa;
786 
787  sepa = SCIProwGetOriginSepa(row);
788  SCIPsepaIncNCutsFound(sepa);
790  }
791  else if ( SCIProwGetOriginCons(row) != NULL )
792  {
793  SCIP_CONSHDLR* conshdlr;
794 
795  conshdlr = SCIProwGetOriginCons(row);
796  SCIPconshdlrIncNCutsFound(conshdlr);
797  }
798  }
799 
800  found = TRUE;
801  cut->age = 0;
802 
803  if ( cutoff )
804  break;
805  }
806  else
807  {
808  cut->age++;
809  if( cutIsAged(cut, cutpool->agelimit) )
810  {
811  SCIP_CALL( cutpoolDelCut(cutpool, blkmem, set, stat, lp, cut) );
812  }
813  }
814  }
815  }
816  }
817 
818  if ( sol == NULL )
819  {
820  cutpool->processedlp = stat->lpcount;
821  cutpool->firstunprocessed = cutpool->ncuts;
822  }
823  else
824  {
825  cutpool->processedlpsol = stat->lpcount;
826  cutpool->firstunprocessedsol = cutpool->ncuts;
827  }
828 
829  /* update the number of found cuts */
830  cutpool->ncutsfound += SCIPsepastoreGetNCuts(sepastore) - oldncuts; /*lint !e776*/
831 
832  /* stop timing */
833  SCIPclockStop(cutpool->poolclock, set);
834 
835  if ( cutoff )
836  *result = SCIP_CUTOFF;
837  else if( found )
838  *result = SCIP_SEPARATED;
839 
840  return SCIP_OKAY;
841 }
842 
843 /** gets array of cuts in the cut pool */
845  SCIP_CUTPOOL* cutpool /**< cut pool */
846  )
847 {
848  assert(cutpool != NULL);
849 
850  return cutpool->cuts;
851 }
852 
853 /** gets number of cuts in the cut pool */
855  SCIP_CUTPOOL* cutpool /**< cut pool */
856  )
857 {
858  assert(cutpool != NULL);
859 
860  return cutpool->ncuts;
861 }
862 
863 /** gets maximum number of cuts that were stored in the cut pool at the same time */
865  SCIP_CUTPOOL* cutpool /**< cut pool */
866  )
867 {
868  assert(cutpool != NULL);
869 
870  return cutpool->maxncuts;
871 }
872 
873 /** gets time in seconds used for separating cuts from the pool */
875  SCIP_CUTPOOL* cutpool /**< cut pool */
876  )
877 {
878  assert(cutpool != NULL);
879 
880  return SCIPclockGetTime(cutpool->poolclock);
881 }
882 
883 /** get number of times, the cut pool was separated */
885  SCIP_CUTPOOL* cutpool /**< cut pool */
886  )
887 {
888  assert(cutpool != NULL);
889 
890  return cutpool->ncalls;
891 }
892 
893 /** get total number of cuts that were separated from the cut pool */
895  SCIP_CUTPOOL* cutpool /**< cut pool */
896  )
897 {
898  assert(cutpool != NULL);
899 
900  return cutpool->ncutsfound;
901 }
902 
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:51
internal methods for separators
SCIP_ROW * row
int nunlinked
Definition: struct_lp.h:225
SCIP_Real SCIProwGetSolFeasibility(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_SOL *sol)
Definition: lp.c:6272
SCIP_CONSHDLR * SCIProwGetOriginCons(SCIP_ROW *row)
Definition: lp.c:19064
int SCIProwGetMaxidx(SCIP_ROW *row, SCIP_SET *set)
Definition: lp.c:6455
#define BMSallocBlockMemory(mem, ptr)
Definition: memory.h:406
SCIP_HASHTABLE * hashtable
int nummaxval
Definition: struct_lp.h:232
#define SCIP_HASHSIZE_CUTPOOLS
Definition: def.h:212
SCIP_Longint processedlp
SCIP_Longint SCIProwGetNLPsAfterCreation(SCIP_ROW *row)
Definition: lp.c:19158
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:1567
SCIP_CUT ** cuts
internal methods for clocks and timing issues
#define NULL
Definition: lpi_spx.cpp:130
void SCIProwCapture(SCIP_ROW *row)
Definition: lp.c:5105
SCIP_SEPA * SCIProwGetOriginSepa(SCIP_ROW *row)
Definition: lp.c:19079
SCIP_Real SCIPcutGetLPActivityQuot(SCIP_CUT *cut)
Definition: cutpool.c:383
void SCIPclockStop(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:350
#define FALSE
Definition: def.h:56
SCIP_Longint processedlpsol
void SCIPclockStart(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:280
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:4766
SCIP_Real sumnorm
Definition: struct_lp.h:197
void SCIPsepaIncNCutsFoundAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:820
int index
Definition: struct_lp.h:155
#define SCIPdebugMessage
Definition: pub_message.h:77
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:572
static SCIP_RETCODE cutFree(SCIP_CUT **cut, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: cutpool.c:325
SCIP_Longint processedlp
SCIP_RETCODE SCIPcutpoolFree(SCIP_CUTPOOL **cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: cutpool.c:441
int nlpcols
Definition: struct_lp.h:224
internal methods for LP management
int SCIPcutpoolGetMaxNCuts(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:864
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:1480
SCIP_CUT ** SCIPcutpoolGetCuts(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:844
#define SCIP_DEFAULT_EPSILON
Definition: def.h:133
SCIP_Real * vals
Definition: struct_lp.h:217
void SCIProwUnlock(SCIP_ROW *row)
Definition: lp.c:5159
SCIP_RETCODE SCIPcutpoolDelRow(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp, SCIP_ROW *row)
Definition: cutpool.c:641
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:19034
SCIP_RETCODE SCIPcutpoolAddNewRow(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_ROW *row)
Definition: cutpool.c:517
#define SCIPerrorMessage
Definition: pub_message.h:45
int SCIPcutpoolGetNCuts(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:854
SCIP_Real sqrnorm
Definition: struct_lp.h:196
SCIP_Longint lpcount
Definition: struct_stat.h:141
static SCIP_RETCODE cutCreate(SCIP_CUT **cut, BMS_BLKMEM *blkmem, SCIP_ROW *row)
Definition: cutpool.c:299
SCIP_COL ** cols
Definition: struct_lp.h:215
static SCIP_DECL_HASHKEYVAL(hashKeyValCut)
Definition: cutpool.c:233
SCIP_Real lhs
Definition: struct_lp.h:192
SCIP_Longint processedlpsol
int SCIPsepastoreGetNCuts(SCIP_SEPASTORE *sepastore)
Definition: sepastore.c:1357
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
Definition: lp.c:19126
#define BMSallocMemory(ptr)
Definition: memory.h:74
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:19024
SCIP_Real SCIPclockGetTime(SCIP_CLOCK *clck)
Definition: clock.c:428
datastructures for storing cuts in a cut pool
int maxidx
Definition: struct_lp.h:231
SCIP_Longint SCIPcutpoolGetNCutsFound(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:894
SCIP_Real SCIPcutpoolGetTime(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:874
internal methods for global SCIP settings
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:82
#define BMSfreeMemory(ptr)
Definition: memory.h:100
SCIP_RETCODE SCIPcutpoolClear(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: cutpool.c:467
SCIP_RETCODE SCIPhashtableRemove(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:1719
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:18974
void SCIProwLock(SCIP_ROW *row)
Definition: lp.c:5144
SCIP_Longint SCIPcutpoolGetNCalls(SCIP_CUTPOOL *cutpool)
Definition: cutpool.c:884
internal methods for storing separated cuts
SCIP_Bool SCIProwIsSolEfficacious(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_SOL *sol, SCIP_Bool root)
Definition: lp.c:6587
SCIP_RETCODE SCIProwRelease(SCIP_ROW **row, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp)
Definition: lp.c:5118
SCIP_RETCODE SCIPclockCreate(SCIP_CLOCK **clck, SCIP_CLOCKTYPE clocktype)
Definition: clock.c:160
void SCIPconshdlrIncNCutsFound(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4551
SCIP_RETCODE SCIPcutpoolAddRow(SCIP_CUTPOOL *cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_ROW *row)
Definition: cutpool.c:493
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:103
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:554
#define SCIP_Bool
Definition: def.h:53
int SCIPcutGetAge(SCIP_CUT *cut)
Definition: cutpool.c:369
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:215
int minidx
Definition: struct_lp.h:230
#define BMSfreeBlockMemory(mem, ptr)
Definition: memory.h:419
SCIP_RETCODE SCIPcutpoolCreate(SCIP_CUTPOOL **cutpool, BMS_BLKMEM *blkmem, SCIP_SET *set, int agelimit, SCIP_Bool globalcutpool)
Definition: cutpool.c:404
unsigned int lpcolssorted
Definition: struct_lp.h:237
internal methods for storing cuts in a cut pool
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
Definition: misc.c:1627
int firstunprocessedsol
SCIP_CLOCK * poolclock
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:1510
SCIP_Real maxval
Definition: struct_lp.h:199
SCIP_Real rhs
Definition: struct_lp.h:193
SCIP_Longint ncalls
SCIP_Bool SCIProwIsLPEfficacious(SCIP_ROW *row, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp, SCIP_Bool root)
Definition: lp.c:6528
SCIP_Longint SCIProwGetActiveLPCount(SCIP_ROW *row)
Definition: lp.c:19148
#define REALABS(x)
Definition: def.h:151
unsigned int inglobalcutpool
Definition: struct_lp.h:248
#define SCIP_DEFAULT_SUMEPSILON
Definition: def.h:134
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:6018
#define SCIP_Real
Definition: def.h:127
internal methods for problem statistics
#define MIN(x, y)
Definition: memory.c:67
void SCIProwSort(SCIP_ROW *row)
Definition: lp.c:5780
internal methods for constraints and constraint handlers
void SCIPsepaIncNCutsFound(SCIP_SEPA *sepa)
Definition: sepa.c:810
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:670
#define SCIP_Longint
Definition: def.h:112
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:1692
SCIP_Real SCIProwGetMaxval(SCIP_ROW *row, SCIP_SET *set)
Definition: lp.c:6423
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:18836
SCIP_ROW * SCIPcutGetRow(SCIP_CUT *cut)
Definition: cutpool.c:359
SCIP_Bool globalcutpool
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:392
SCIP_Bool SCIProwIsRemovable(SCIP_ROW *row)
Definition: lp.c:19044
unsigned int validminmaxidx
Definition: struct_lp.h:240
#define SCIP_ALLOC(x)
Definition: def.h:277
unsigned int nonlpcolssorted
Definition: struct_lp.h:238
static SCIP_Bool cutIsAged(SCIP_CUT *cut, int agelimit)
Definition: cutpool.c:348
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:269
int len
Definition: struct_lp.h:223
int age
Definition: struct_lp.h:234