Scippy

SCIP

Solving Constraint Integer Programs

sepa_gomory.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 sepa_gomory.c
17  * @brief Gomory MIR Cuts
18  * @author Tobias Achterberg
19  * @author Stefan Heinz
20  * @author Domenico Salvagnin
21  * @author Marc Pfetsch
22  */
23 
24 /**@todo try k-Gomory-cuts (s. Cornuejols: K-Cuts: A Variation of Gomory Mixed Integer Cuts from the LP Tableau)
25  *
26  * @todo Try cuts on the objective tableau row.
27  *
28  * @todo Also try negative basis inverse row?
29  *
30  * @todo It happens that the SCIPcalcMIR() function returns with the same cut for different calls. Check if this is a
31  * bug or do not use it for the MIP below and turn off presolving and all heuristics:
32  *
33  * Max y
34  * Subject to
35  * c1: -x + y <= 1
36  * c2: 2x + 3y <= 12
37  * c3: 3x + 2y <= 12
38  * Bounds
39  * 0 <= x
40  * 0 <= y
41  * General
42  * x
43  * y
44  * END
45  */
46 
47 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
48 
49 #include "blockmemshell/memory.h"
50 #include "scip/cuts.h"
51 #include "scip/pub_lp.h"
52 #include "scip/pub_message.h"
53 #include "scip/pub_misc.h"
54 #include "scip/pub_misc_sort.h"
55 #include "scip/pub_sepa.h"
56 #include "scip/pub_var.h"
57 #include "scip/scip_branch.h"
58 #include "scip/scip_cut.h"
59 #include "scip/scip_general.h"
60 #include "scip/scip_lp.h"
61 #include "scip/scip_mem.h"
62 #include "scip/scip_message.h"
63 #include "scip/scip_numerics.h"
64 #include "scip/scip_param.h"
65 #include "scip/scip_prob.h"
66 #include "scip/scip_randnumgen.h"
67 #include "scip/scip_sepa.h"
68 #include "scip/scip_solvingstats.h"
69 #include "scip/scip_tree.h"
70 #include "scip/sepa_gomory.h"
71 #include <string.h>
72 
73 #define SEPA_NAME "gomory"
74 #define SEPA_DESC "Gomory MIR cuts separator"
75 #define SEPA_PRIORITY -1000
76 #define SEPA_FREQ 10
77 #define SEPA_MAXBOUNDDIST 1.0
78 #define SEPA_USESSUBSCIP FALSE /**< does the separator use a secondary SCIP instance? */
79 #define SEPA_DELAY FALSE /**< should separation method be delayed, if other separators found cuts? */
80 
81 #define DEFAULT_MAXROUNDS 5 /**< maximal number of gomory separation rounds per node (-1: unlimited) */
82 #define DEFAULT_MAXROUNDSROOT 10 /**< maximal number of gomory separation rounds in the root node (-1: unlimited) */
83 #define DEFAULT_MAXSEPACUTS 50 /**< maximal number of gomory cuts separated per separation round */
84 #define DEFAULT_MAXSEPACUTSROOT 200 /**< maximal number of gomory cuts separated per separation round in root node */
85 #define DEFAULT_MAXRANK -1 /**< maximal rank of a gomory cut that could not be scaled to integral coefficients (-1: unlimited) */
86 #define DEFAULT_MAXRANKINTEGRAL -1 /**< maximal rank of a gomory cut that could be scaled to integral coefficients (-1: unlimited) */
87 #define DEFAULT_DYNAMICCUTS TRUE /**< should generated cuts be removed from the LP if they are no longer tight? */
88 #define DEFAULT_AWAY 0.01 /**< minimal integrality violation of a basis variable in order to try Gomory cut */
89 #define DEFAULT_MAKEINTEGRAL FALSE /**< try to scale all cuts to integral coefficients */
90 #define DEFAULT_FORCECUTS TRUE /**< if conversion to integral coefficients failed still consider the cut */
91 #define DEFAULT_SEPARATEROWS TRUE /**< separate rows with integral slack */
92 #define DEFAULT_DELAYEDCUTS FALSE /**< should cuts be added to the delayed cut pool? */
93 #define DEFAULT_SIDETYPEBASIS TRUE /**< choose side types of row (lhs/rhs) based on basis information? */
94 #define DEFAULT_RANDSEED 53 /**< initial random seed */
95 
96 #define BOUNDSWITCH 0.9999 /**< threshold for bound switching - see SCIPcalcMIR() */
97 #define POSTPROCESS TRUE /**< apply postprocessing after MIR calculation - see SCIPcalcMIR() */
98 #define USEVBDS TRUE /**< use variable bounds - see SCIPcalcMIR() */
99 #define FIXINTEGRALRHS FALSE /**< try to generate an integral rhs - see SCIPcalcMIR() */
100 #define MAKECONTINTEGRAL FALSE /**< convert continuous variable to integral variables in SCIPmakeRowIntegral() */
101 
102 #define MAXAGGRLEN(nvars) (0.1*(nvars)+1000) /**< maximal length of base inequality */
103 
104 
105 /** separator data */
106 struct SCIP_SepaData
107 {
108  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
109  SCIP_Real away; /**< minimal integrality violation of a basis variable in order to try Gomory cut */
110  int maxrounds; /**< maximal number of gomory separation rounds per node (-1: unlimited) */
111  int maxroundsroot; /**< maximal number of gomory separation rounds in the root node (-1: unlimited) */
112  int maxsepacuts; /**< maximal number of gomory cuts separated per separation round */
113  int maxsepacutsroot; /**< maximal number of gomory cuts separated per separation round in root node */
114  int maxrank; /**< maximal rank of a gomory cut that could not be scaled to integral coefficients (-1: unlimited) */
115  int maxrankintegral; /**< maximal rank of a gomory cut that could be scaled to integral coefficients (-1: unlimited) */
116  int lastncutsfound; /**< total number of cuts found after last call of separator */
117  SCIP_Bool dynamiccuts; /**< should generated cuts be removed from the LP if they are no longer tight? */
118  SCIP_Bool makeintegral; /**< try to scale all cuts to integral coefficients */
119  SCIP_Bool forcecuts; /**< if conversion to integral coefficients failed still consider the cut */
120  SCIP_Bool separaterows; /**< separate rows with integral slack */
121  SCIP_Bool delayedcuts; /**< should cuts be added to the delayed cut pool? */
122  SCIP_Bool sidetypebasis; /**< choose side types of row (lhs/rhs) based on basis information? */
123 };
124 
125 
126 /** returns TRUE if the cut can be taken, otherwise FALSE if there some numerical evidences */
127 static
129  SCIP* scip, /**< SCIP data structure */
130  SCIP_SEPADATA* sepadata, /**< data of the separator */
131  SCIP_ROW* cut, /**< cut to check */
132  SCIP_Longint maxdnom, /**< maximal denominator to use for scaling */
133  SCIP_Real maxscale, /**< maximal scaling factor */
134  SCIP_Bool* useful /**< pointer to store if the cut is useful */
135  )
136 {
137  SCIP_Bool madeintegral;
138 
139  madeintegral = FALSE;
140  (*useful) = FALSE;
141 
142  if( sepadata->makeintegral && SCIPgetRowNumIntCols(scip, cut) == SCIProwGetNNonz(cut) )
143  {
144  /* try to scale the cut to integral values */
145  SCIP_CALL( SCIPmakeRowIntegral(scip, cut, -SCIPepsilon(scip), SCIPsumepsilon(scip),
146  maxdnom, maxscale, MAKECONTINTEGRAL, &madeintegral) );
147 
148  if( !madeintegral && !sepadata->forcecuts )
149  return SCIP_OKAY;
150 
151  /* in case the right hand side is plus infinity (due to scaling) the cut is useless so we are not taking it at all
152  */
153  if( madeintegral && SCIPisInfinity(scip, SCIProwGetRhs(cut)) )
154  return SCIP_OKAY;
155  }
156 
157  /* discard integral cut if the rank is too high */
158  if( madeintegral && sepadata->maxrankintegral != -1 && (SCIProwGetRank(cut) > sepadata->maxrankintegral) )
159  return SCIP_OKAY;
160 
161  /* discard cut if the rank is too high */
162  if( !madeintegral && (sepadata->maxrank != -1) && (SCIProwGetRank(cut) > sepadata->maxrank) )
163  return SCIP_OKAY;
164 
165  (*useful) = TRUE;
166 
167  return SCIP_OKAY;
168 }
169 
170 
171 /*
172  * Callback methods
173  */
174 
175 /** copy method for separator plugins (called when SCIP copies plugins) */
176 static
177 SCIP_DECL_SEPACOPY(sepaCopyGomory)
178 { /*lint --e{715}*/
179  assert(scip != NULL);
180  assert(sepa != NULL);
181  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
182 
183  /* call inclusion method of separator */
185 
186  return SCIP_OKAY;
187 }
188 
189 /** destructor of separator to free user data (called when SCIP is exiting) */
190 /**! [SnippetSepaFreeGomory] */
191 static
192 SCIP_DECL_SEPAFREE(sepaFreeGomory)
193 { /*lint --e{715}*/
194  SCIP_SEPADATA* sepadata;
195 
196  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
197 
198  /* free separator data */
199  sepadata = SCIPsepaGetData(sepa);
200  assert(sepadata != NULL);
201 
202  SCIPfreeBlockMemory(scip, &sepadata);
203 
204  SCIPsepaSetData(sepa, NULL);
205 
206  return SCIP_OKAY;
207 }
208 /**! [SnippetSepaFreeGomory] */
209 
210 /** initialization method of separator (called after problem was transformed) */
211 static
212 SCIP_DECL_SEPAINIT(sepaInitGomory)
213 {
214  SCIP_SEPADATA* sepadata;
215 
216  sepadata = SCIPsepaGetData(sepa);
217  assert(sepadata != NULL);
218 
219  /* create and initialize random number generator */
220  SCIP_CALL( SCIPcreateRandom(scip, &sepadata->randnumgen, DEFAULT_RANDSEED, TRUE) );
221 
222  return SCIP_OKAY;
223 }
224 
225 /** deinitialization method of separator (called before transformed problem is freed) */
226 static
227 SCIP_DECL_SEPAEXIT(sepaExitGomory)
228 { /*lint --e{715}*/
229  SCIP_SEPADATA* sepadata;
230 
231  sepadata = SCIPsepaGetData(sepa);
232  assert(sepadata != NULL);
233 
234  SCIPfreeRandom(scip, &sepadata->randnumgen);
235 
236  return SCIP_OKAY;
237 }
238 
239 
240 /** LP solution separation method of separator */
241 static
242 SCIP_DECL_SEPAEXECLP(sepaExeclpGomory)
243 { /*lint --e{715}*/
244  SCIP_SEPADATA* sepadata;
245  SCIP_VAR** vars;
246  SCIP_COL** cols;
247  SCIP_ROW** rows;
248  SCIP_AGGRROW* aggrrow;
249  SCIP_Real* binvrow;
250  SCIP_Real* cutcoefs;
251  SCIP_Real* basisfrac;
252  int* basisind;
253  int* basisperm;
254  int* inds;
255  int* cutinds;
256  SCIP_Real maxscale;
257  SCIP_Real minfrac;
258  SCIP_Real maxfrac;
259  SCIP_Longint maxdnom;
260  SCIP_Bool cutoff;
261  int ninds;
262  int naddedcuts;
263  int nvars;
264  int ncols;
265  int nrows;
266  int ncalls;
267  int depth;
268  int maxdepth;
269  int maxsepacuts;
270  int c;
271  int i;
272 
273  assert(sepa != NULL);
274  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
275  assert(scip != NULL);
276  assert(result != NULL);
277 
278  *result = SCIP_DIDNOTRUN;
279 
280  sepadata = SCIPsepaGetData(sepa);
281  assert(sepadata != NULL);
282 
283  depth = SCIPgetDepth(scip);
284  ncalls = SCIPsepaGetNCallsAtNode(sepa);
285 
286  minfrac = sepadata->away;
287  maxfrac = 1.0 - sepadata->away;
288 
289  /* only call separator, if we are not close to terminating */
290  if( SCIPisStopped(scip) )
291  return SCIP_OKAY;
292 
293  /* only call the gomory cut separator a given number of times at each node */
294  if( (depth == 0 && sepadata->maxroundsroot >= 0 && ncalls >= sepadata->maxroundsroot)
295  || (depth > 0 && sepadata->maxrounds >= 0 && ncalls >= sepadata->maxrounds) )
296  return SCIP_OKAY;
297 
298  /* only call separator, if an optimal LP solution is at hand */
300  return SCIP_OKAY;
301 
302  /* only call separator, if the LP solution is basic */
303  if( !SCIPisLPSolBasic(scip) )
304  return SCIP_OKAY;
305 
306  /* only call separator, if there are fractional variables */
307  if( SCIPgetNLPBranchCands(scip) == 0 )
308  return SCIP_OKAY;
309 
310  /* get variables data */
311  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
312 
313  /* get LP data */
314  SCIP_CALL( SCIPgetLPColsData(scip, &cols, &ncols) );
315  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
316  if( ncols == 0 || nrows == 0 )
317  return SCIP_OKAY;
318 
319 #if 0 /* if too many columns, separator is usually very slow: delay it until no other cuts have been found */
320  if( ncols >= 50*nrows )
321  return SCIP_OKAY;
322 
323  if( ncols >= 5*nrows )
324  {
325  int ncutsfound;
326 
327  ncutsfound = SCIPgetNCutsFound(scip);
328  if( ncutsfound > sepadata->lastncutsfound || !SCIPsepaWasLPDelayed(sepa) )
329  {
330  sepadata->lastncutsfound = ncutsfound;
331  *result = SCIP_DELAYED;
332  return SCIP_OKAY;
333  }
334  }
335 #endif
336 
337  /* set the maximal denominator in rational representation of gomory cut and the maximal scale factor to
338  * scale resulting cut to integral values to avoid numerical instabilities
339  */
340  /**@todo find better but still stable gomory cut settings: look at dcmulti, gesa3, khb0525, misc06, p2756 */
341  maxdepth = SCIPgetMaxDepth(scip);
342  if( depth == 0 )
343  {
344  maxdnom = 1000;
345  maxscale = 1000.0;
346  }
347  else if( depth <= maxdepth/4 )
348  {
349  maxdnom = 1000;
350  maxscale = 1000.0;
351  }
352  else if( depth <= maxdepth/2 )
353  {
354  maxdnom = 100;
355  maxscale = 100.0;
356  }
357  else
358  {
359  maxdnom = 10;
360  maxscale = 10.0;
361  }
362 
363  /* allocate temporary memory */
364  SCIP_CALL( SCIPallocBufferArray(scip, &cutcoefs, nvars) );
365  SCIP_CALL( SCIPallocBufferArray(scip, &cutinds, nvars) );
366  SCIP_CALL( SCIPallocBufferArray(scip, &basisind, nrows) );
367  SCIP_CALL( SCIPallocBufferArray(scip, &basisperm, nrows) );
368  SCIP_CALL( SCIPallocBufferArray(scip, &basisfrac, nrows) );
369  SCIP_CALL( SCIPallocBufferArray(scip, &binvrow, nrows) );
370  SCIP_CALL( SCIPallocBufferArray(scip, &inds, nrows) );
371  SCIP_CALL( SCIPaggrRowCreate(scip, &aggrrow) );
372 
373  /* get basis indices */
374  SCIP_CALL( SCIPgetLPBasisInd(scip, basisind) );
375 
376  for( i = 0; i < nrows; ++i )
377  {
378  SCIP_Real frac = 0.0;
379 
380  c = basisind[i];
381 
382  basisperm[i] = i;
383 
384  if( c >= 0 )
385  {
386  SCIP_VAR* var;
387 
388  assert(c < ncols);
389  var = SCIPcolGetVar(cols[c]);
391  {
392  frac = SCIPfeasFrac(scip, SCIPcolGetPrimsol(cols[c]));
393  frac = MIN(frac, 1.0 - frac);
394  }
395  }
396  else if( sepadata->separaterows )
397  {
398  SCIP_ROW* row;
399 
400  assert(0 <= -c-1 && -c-1 < nrows);
401  row = rows[-c-1];
402  if( SCIProwIsIntegral(row) && !SCIProwIsModifiable(row) )
403  {
404  frac = SCIPfeasFrac(scip, SCIPgetRowActivity(scip, row));
405  frac = MIN(frac, 1.0 - frac);
406  }
407  }
408 
409  if( frac >= minfrac )
410  {
411  /* slightly change fractionality to have random order for equal fractions */
412  basisfrac[i] = frac + SCIPrandomGetReal(sepadata->randnumgen, -1e-6, 1e-6);
413  }
414  else
415  {
416  basisfrac[i] = 0.0;
417  }
418  }
419 
420  /* sort basis indices by fractionality */
421  SCIPsortDownRealInt(basisfrac, basisperm, nrows);
422 
423  /* get the maximal number of cuts allowed in a separation round */
424  if( depth == 0 )
425  maxsepacuts = sepadata->maxsepacutsroot;
426  else
427  maxsepacuts = sepadata->maxsepacuts;
428 
429  SCIPdebugMsg(scip, "searching gomory cuts: %d cols, %d rows, maxdnom=%" SCIP_LONGINT_FORMAT ", maxscale=%g, maxcuts=%d\n",
430  ncols, nrows, maxdnom, maxscale, maxsepacuts);
431 
432  cutoff = FALSE;
433  naddedcuts = 0;
434 
435  /* for all basic columns belonging to integer variables, try to generate a gomory cut */
436  for( i = 0; i < nrows && naddedcuts < maxsepacuts && !SCIPisStopped(scip) && !cutoff; ++i )
437  {
438  SCIP_Real cutrhs;
439  SCIP_Real cutefficacy;
440  SCIP_Bool success;
441  SCIP_Bool cutislocal;
442  int cutnnz;
443  int cutrank;
444  int j;
445 
446  if( basisfrac[i] == 0.0 )
447  break;
448 
449  j = basisperm[i];
450  c = basisind[j];
451 
452  /* get the row of B^-1 for this basic integer variable with fractional solution value */
453  ninds = -1;
454  SCIP_CALL( SCIPgetLPBInvRow(scip, j, binvrow, inds, &ninds) );
455 
456  SCIP_CALL( SCIPaggrRowSumRows(scip, aggrrow, binvrow, inds, ninds,
457  sepadata->sidetypebasis, allowlocal, 2, (int) MAXAGGRLEN(nvars), &success) );
458 
459  if( !success )
460  continue;
461 
462  SCIP_CALL( SCIPcalcMIR(scip, NULL, POSTPROCESS, BOUNDSWITCH, USEVBDS, allowlocal, FIXINTEGRALRHS, NULL, NULL, minfrac, maxfrac,
463  1.0, aggrrow, cutcoefs, &cutrhs, cutinds, &cutnnz, &cutefficacy, &cutrank, &cutislocal, &success) );
464 
465  assert(allowlocal || !cutislocal);
466 
467  /* @todo Currently we are using the SCIPcalcMIR() function to compute the coefficients of the Gomory
468  * cut. Alternatively, we could use the direct version (see thesis of Achterberg formula (8.4)) which
469  * leads to cut a of the form \sum a_i x_i \geq 1. Rumor has it that these cuts are better.
470  */
471 
472  SCIPdebugMsg(scip, " -> success=%u, rhs=%g, efficacy=%g\n", success, cutrhs, cutefficacy);
473 
474  /* if successful, convert dense cut into sparse row, and add the row as a cut */
475  if( success )
476  {
477  if( cutnnz == 0 && SCIPisFeasNegative(scip, cutrhs) )
478  {
479  SCIPdebugMsg(scip, " -> gomory cut detected infeasibility with cut 0 <= %f\n", cutrhs);
480  cutoff = TRUE;
481  }
482  else if( SCIPisEfficacious(scip, cutefficacy) )
483  {
484  /* Only take efficient cuts, except for cuts with one non-zero coefficients (= bound
485  * changes); the latter cuts will be handled internally in sepastore.
486  */
487  SCIP_ROW* cut;
488  char cutname[SCIP_MAXSTRLEN];
489  int v;
490 
491  /* construct cut name */
492  if( c >= 0 )
493  (void) SCIPsnprintf(cutname, SCIP_MAXSTRLEN, "gom%d_x%d", SCIPgetNLPs(scip), c);
494  else
495  (void) SCIPsnprintf(cutname, SCIP_MAXSTRLEN, "gom%d_s%d", SCIPgetNLPs(scip), -c-1);
496 
497  /* create empty cut */
498  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, &cut, sepa, cutname, -SCIPinfinity(scip), cutrhs,
499  cutislocal, FALSE, sepadata->dynamiccuts) );
500 
501  /* set cut rank */
502  SCIProwChgRank(cut, cutrank);
503 
504  /* cache the row extension and only flush them if the cut gets added */
506 
507  /* collect all non-zero coefficients */
508  for( v = 0; v < cutnnz; ++v )
509  {
510  SCIP_CALL( SCIPaddVarToRow(scip, cut, vars[cutinds[v]], cutcoefs[v]) );
511  }
512 
513  if( cutnnz == 1 )
514  {
515  /* add the bound change as cut to avoid that the LP gets modified. that would mean the LP is not flushed
516  * and the method SCIPgetLPBInvRow() fails; SCIP internally will apply that bound change automatically
517  */
518 
519  /* flush all changes before adding the cut */
521  SCIP_CALL( SCIPaddRow(scip, cut, TRUE, &cutoff) );
522  naddedcuts++;
523  }
524  else
525  {
526  SCIP_Bool useful;
527 
528  assert(success == TRUE);
529  assert(SCIPisInfinity(scip, -SCIProwGetLhs(cut)));
530  assert(!SCIPisInfinity(scip, SCIProwGetRhs(cut)));
531 
532  SCIPdebugMsg(scip, " -> gomory cut for <%s>: rhs=%f, eff=%f\n",
533  c >= 0 ? SCIPvarGetName(SCIPcolGetVar(cols[c])) : SCIProwGetName(rows[-c-1]),
534  cutrhs, cutefficacy);
535 
536  SCIP_CALL( evaluateCutNumerics(scip, sepadata, cut, maxdnom, maxscale, &useful) );
537 
538  if( useful )
539  {
540  SCIPdebugMsg(scip, " -> found gomory cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
541  cutname, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
545 
546  /* flush all changes before adding the cut */
548 
549  if( SCIPisCutNew(scip, cut) )
550  {
551  /* add global cuts which are not implicit bound changes to the cut pool */
552  if( !cutislocal )
553  {
554  if( sepadata->delayedcuts )
555  {
557  }
558  else
559  {
560  SCIP_CALL( SCIPaddPoolCut(scip, cut) );
561  }
562  }
563  else
564  {
565  /* local cuts we add to the sepastore */
566  SCIP_CALL( SCIPaddRow(scip, cut, FALSE, &cutoff) );
567  }
568 
569  naddedcuts++;
570  }
571  }
572  }
573  /* release the row */
574  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
575  }
576  }
577  }
578 
579  /* free temporary memory */
580  SCIPfreeBufferArray(scip, &inds);
581  SCIPfreeBufferArray(scip, &binvrow);
582  SCIPfreeBufferArray(scip, &basisfrac);
583  SCIPfreeBufferArray(scip, &basisperm);
584  SCIPfreeBufferArray(scip, &basisind);
585  SCIPfreeBufferArray(scip, &cutinds);
586  SCIPfreeBufferArray(scip, &cutcoefs);
587  SCIPaggrRowFree(scip, &aggrrow);
588 
589  SCIPdebugMsg(scip, "end searching gomory cuts: found %d cuts\n", naddedcuts);
590 
591  sepadata->lastncutsfound = SCIPgetNCutsFound(scip);
592 
593  /* evaluate the result of the separation */
594  if( cutoff )
595  *result = SCIP_CUTOFF;
596  else if ( naddedcuts > 0 )
597  *result = SCIP_SEPARATED;
598  else
599  *result = SCIP_DIDNOTFIND;
600 
601  return SCIP_OKAY;
602 }
603 
604 
605 /*
606  * separator specific interface methods
607  */
608 
609 /** creates the Gomory MIR cut separator and includes it in SCIP */
611  SCIP* scip /**< SCIP data structure */
612  )
613 {
614  SCIP_SEPADATA* sepadata;
615  SCIP_SEPA* sepa;
616 
617  /* create separator data */
618  SCIP_CALL( SCIPallocBlockMemory(scip, &sepadata) );
619  sepadata->lastncutsfound = 0;
620 
621  /* include separator */
624  sepaExeclpGomory, NULL,
625  sepadata) );
626 
627  assert(sepa != NULL);
628 
629  /* set non-NULL pointers to callback methods */
630  SCIP_CALL( SCIPsetSepaCopy(scip, sepa, sepaCopyGomory) );
631  SCIP_CALL( SCIPsetSepaFree(scip, sepa, sepaFreeGomory) );
632  SCIP_CALL( SCIPsetSepaInit(scip, sepa, sepaInitGomory) );
633  SCIP_CALL( SCIPsetSepaExit(scip, sepa, sepaExitGomory) );
634 
635  /* add separator parameters */
637  "separating/gomory/maxrounds",
638  "maximal number of gomory separation rounds per node (-1: unlimited)",
639  &sepadata->maxrounds, FALSE, DEFAULT_MAXROUNDS, -1, INT_MAX, NULL, NULL) );
641  "separating/gomory/maxroundsroot",
642  "maximal number of gomory separation rounds in the root node (-1: unlimited)",
643  &sepadata->maxroundsroot, FALSE, DEFAULT_MAXROUNDSROOT, -1, INT_MAX, NULL, NULL) );
645  "separating/gomory/maxsepacuts",
646  "maximal number of gomory cuts separated per separation round",
647  &sepadata->maxsepacuts, FALSE, DEFAULT_MAXSEPACUTS, 0, INT_MAX, NULL, NULL) );
649  "separating/gomory/maxsepacutsroot",
650  "maximal number of gomory cuts separated per separation round in the root node",
651  &sepadata->maxsepacutsroot, FALSE, DEFAULT_MAXSEPACUTSROOT, 0, INT_MAX, NULL, NULL) );
653  "separating/gomory/maxrank",
654  "maximal rank of a gomory cut that could not be scaled to integral coefficients (-1: unlimited)",
655  &sepadata->maxrank, FALSE, DEFAULT_MAXRANK, -1, INT_MAX, NULL, NULL) );
657  "separating/gomory/maxrankintegral",
658  "maximal rank of a gomory cut that could be scaled to integral coefficients (-1: unlimited)",
659  &sepadata->maxrankintegral, FALSE, DEFAULT_MAXRANKINTEGRAL, -1, INT_MAX, NULL, NULL) );
661  "separating/gomory/away",
662  "minimal integrality violation of a basis variable in order to try Gomory cut",
663  &sepadata->away, FALSE, DEFAULT_AWAY, 1e-4, 0.5, NULL, NULL) );
665  "separating/gomory/dynamiccuts",
666  "should generated cuts be removed from the LP if they are no longer tight?",
667  &sepadata->dynamiccuts, FALSE, DEFAULT_DYNAMICCUTS, NULL, NULL) );
669  "separating/gomory/makeintegral",
670  "try to scale cuts to integral coefficients",
671  &sepadata->makeintegral, TRUE, DEFAULT_MAKEINTEGRAL, NULL, NULL) );
673  "separating/gomory/forcecuts",
674  "if conversion to integral coefficients failed still consider the cut",
675  &sepadata->forcecuts, TRUE, DEFAULT_FORCECUTS, NULL, NULL) );
677  "separating/gomory/separaterows",
678  "separate rows with integral slack",
679  &sepadata->separaterows, TRUE, DEFAULT_SEPARATEROWS, NULL, NULL) );
681  "separating/gomory/delayedcuts",
682  "should cuts be added to the delayed cut pool?",
683  &sepadata->delayedcuts, TRUE, DEFAULT_DELAYEDCUTS, NULL, NULL) );
685  "separating/gomory/sidetypebasis",
686  "choose side types of row (lhs/rhs) based on basis information?",
687  &sepadata->sidetypebasis, TRUE, DEFAULT_SIDETYPEBASIS, NULL, NULL) );
688 
689  return SCIP_OKAY;
690 }
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
#define DEFAULT_MAXSEPACUTSROOT
Definition: sepa_gomory.c:84
void SCIPaggrRowFree(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1581
SCIP_RETCODE SCIPgetLPBInvRow(SCIP *scip, int r, SCIP_Real *coefs, int *inds, int *ninds)
Definition: scip_lp.c:717
SCIP_RETCODE SCIPincludeSepaGomory(SCIP *scip)
Definition: sepa_gomory.c:610
#define NULL
Definition: def.h:239
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1547
public methods for SCIP parameter handling
static SCIP_RETCODE evaluateCutNumerics(SCIP *scip, SCIP_SEPADATA *sepadata, SCIP_ROW *cut, SCIP_Longint maxdnom, SCIP_Real maxscale, SCIP_Bool *useful)
Definition: sepa_gomory.c:128
#define SEPA_PRIORITY
Definition: sepa_gomory.c:75
public methods for memory management
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1570
#define SCIP_MAXSTRLEN
Definition: def.h:260
#define SEPA_DESC
Definition: sepa_gomory.c:74
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1602
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:16790
#define DEFAULT_MAXROUNDSROOT
Definition: sepa_gomory.c:82
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:16928
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPaddDelayedPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:684
int SCIPgetMaxDepth(SCIP *scip)
#define DEFAULT_DELAYEDCUTS
Definition: sepa_gomory.c:92
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1918
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:16869
#define FALSE
Definition: def.h:65
methods for the aggregation rows
#define DEFAULT_MAXROUNDS
Definition: sepa_gomory.c:81
#define SEPA_MAXBOUNDDIST
Definition: sepa_gomory.c:77
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10017
#define TRUE
Definition: def.h:64
const char * SCIPsepaGetName(SCIP_SEPA *sepa)
Definition: sepa.c:689
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
static SCIP_DECL_SEPAEXIT(sepaExitGomory)
Definition: sepa_gomory.c:227
#define DEFAULT_MAKEINTEGRAL
Definition: sepa_gomory.c:89
#define FIXINTEGRALRHS
Definition: sepa_gomory.c:99
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
void SCIPsortDownRealInt(SCIP_Real *realarray, int *intarray, int len)
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:142
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
SCIP_RETCODE SCIPgetLPColsData(SCIP *scip, SCIP_COL ***cols, int *ncols)
Definition: scip_lp.c:495
int SCIPgetNLPBranchCands(SCIP *scip)
Definition: scip_branch.c:417
SCIP_RETCODE SCIPsetSepaCopy(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: scip_sepa.c:220
#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
public methods for separator plugins
SCIP_Real SCIPepsilon(SCIP *scip)
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1823
#define USEVBDS
Definition: sepa_gomory.c:98
public methods for numerical tolerances
SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:600
#define DEFAULT_MAXRANKINTEGRAL
Definition: sepa_gomory.c:86
public methods for querying solving statistics
public methods for the branch-and-bound tree
static SCIP_DECL_SEPAEXECLP(sepaExeclpGomory)
Definition: sepa_gomory.c:242
SCIP_Bool SCIPisLPSolBasic(SCIP *scip)
Definition: scip_lp.c:670
SCIP_Real SCIPcolGetPrimsol(SCIP_COL *col)
Definition: lp.c:16593
#define MAKECONTINTEGRAL
Definition: sepa_gomory.c:100
SCIP_Real SCIPgetRowMinCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1805
#define DEFAULT_MAXSEPACUTS
Definition: sepa_gomory.c:83
#define SEPA_USESSUBSCIP
Definition: sepa_gomory.c:78
int SCIPgetNCutsFound(SCIP *scip)
SCIP_RETCODE SCIPsetSepaExit(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAEXIT((*sepaexit)))
Definition: scip_sepa.c:268
int SCIPsepaGetNCallsAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:816
SCIP_Bool SCIPisEfficacious(SCIP *scip, SCIP_Real efficacy)
Definition: scip_cut.c:179
#define DEFAULT_MAXRANK
Definition: sepa_gomory.c:85
#define DEFAULT_FORCECUTS
Definition: sepa_gomory.c:90
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16729
SCIP_Bool SCIProwIsIntegral(SCIP_ROW *row)
Definition: lp.c:16968
void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:610
#define DEFAULT_SEPARATEROWS
Definition: sepa_gomory.c:91
#define DEFAULT_SIDETYPEBASIS
Definition: sepa_gomory.c:93
static SCIP_DECL_SEPAINIT(sepaInitGomory)
Definition: sepa_gomory.c:212
#define SEPA_DELAY
Definition: sepa_gomory.c:79
#define SCIP_CALL(x)
Definition: def.h:351
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:16879
SCIP_Real SCIPgetRowLPActivity(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1894
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:294
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:16988
#define DEFAULT_DYNAMICCUTS
Definition: sepa_gomory.c:87
SCIP_RETCODE SCIPincludeSepaBasic(SCIP *scip, SCIP_SEPA **sepa, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: scip_sepa.c:178
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
SCIP_Bool SCIPsepaWasLPDelayed(SCIP_SEPA *sepa)
Definition: sepa.c:926
SCIP_RETCODE SCIPcalcMIR(SCIP *scip, SCIP_SOL *sol, SCIP_Bool postprocess, SCIP_Real boundswitch, SCIP_Bool usevbds, SCIP_Bool allowlocal, SCIP_Bool fixintegralrhs, int *boundsfortrans, SCIP_BOUNDTYPE *boundtypesfortrans, SCIP_Real minfrac, SCIP_Real maxfrac, SCIP_Real scale, SCIP_AGGRROW *aggrrow, SCIP_Real *cutcoefs, SCIP_Real *cutrhs, int *cutinds, int *cutnnz, SCIP_Real *cutefficacy, int *cutrank, SCIP_Bool *cutislocal, SCIP_Bool *success)
Definition: cuts.c:3904
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:130
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:62
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:226
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:715
#define SEPA_NAME
Definition: sepa_gomory.c:73
int SCIPgetRowNumIntCols(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1787
#define SEPA_FREQ
Definition: sepa_gomory.c:76
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:405
#define MIN(x, y)
Definition: def.h:209
public methods for LP management
SCIP_RETCODE SCIPcreateEmptyRowSepa(SCIP *scip, SCIP_ROW **row, SCIP_SEPA *sepa, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip_lp.c:1365
SCIP_Real SCIPgetCutEfficacy(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:138
public methods for cuts and aggregation rows
SCIP_RETCODE SCIPgetLPBasisInd(SCIP *scip, int *basisind)
Definition: scip_lp.c:689
Gomory MIR Cuts.
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisCutNew(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:387
#define MAXAGGRLEN(nvars)
Definition: sepa_gomory.c:102
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
Definition: misc.c:9394
public methods for the LP relaxation, rows and columns
int SCIProwGetRank(SCIP_ROW *row)
Definition: lp.c:16958
methods for sorting joint arrays of various types
static SCIP_DECL_SEPACOPY(sepaCopyGomory)
Definition: sepa_gomory.c:177
#define SCIP_LONGINT_FORMAT
Definition: def.h:142
public methods for branching rule plugins and branching
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1474
general public methods
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip_sepa.c:236
SCIP_RETCODE SCIPsetSepaInit(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAINIT((*sepainit)))
Definition: scip_sepa.c:252
SCIP_RETCODE SCIPaggrRowSumRows(SCIP *scip, SCIP_AGGRROW *aggrrow, SCIP_Real *weights, int *rowinds, int nrowinds, SCIP_Bool sidetypebasis, SCIP_Bool allowlocal, int negslack, int maxaggrlen, SCIP_Bool *valid)
Definition: cuts.c:2093
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16639
public methods for random numbers
void SCIProwChgRank(SCIP_ROW *row, int rank)
Definition: lp.c:17091
public methods for message output
#define SCIP_Real
Definition: def.h:150
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:739
#define POSTPROCESS
Definition: sepa_gomory.c:97
public methods for message handling
SCIP_RETCODE SCIPaggrRowCreate(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1549
#define SCIP_Longint
Definition: def.h:135
#define DEFAULT_AWAY
Definition: sepa_gomory.c:88
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16894
#define BOUNDSWITCH
Definition: sepa_gomory.c:96
#define DEFAULT_RANDSEED
Definition: sepa_gomory.c:94
static SCIP_DECL_SEPAFREE(sepaFreeGomory)
Definition: sepa_gomory.c:192
SCIP_Real SCIPsumepsilon(SCIP *scip)
public methods for separators
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip_lp.c:573
SCIP_Longint SCIPgetNLPs(SCIP *scip)
public methods for global and local (sub)problems
SCIP_RETCODE SCIPmakeRowIntegral(SCIP *scip, SCIP_ROW *row, SCIP_Real mindelta, SCIP_Real maxdelta, SCIP_Longint maxdnom, SCIP_Real maxscale, SCIP_Bool usecontvars, SCIP_Bool *success)
Definition: scip_lp.c:1745
SCIP_Real SCIProwGetNorm(SCIP_ROW *row)
Definition: lp.c:16845
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
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:38
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
SCIP_Real SCIPgetRowActivity(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:2005
memory allocation routines