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-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 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 <assert.h>
50 #include <string.h>
51 
52 #include "scip/sepa_gomory.h"
53 #include "scip/pub_misc.h"
54 #include "scip/pub_lp.h"
55 
56 #define SEPA_NAME "gomory"
57 #define SEPA_DESC "Gomory MIR cuts separator"
58 #define SEPA_PRIORITY -1000
59 #define SEPA_FREQ 0
60 #define SEPA_MAXBOUNDDIST 0.0
61 #define SEPA_USESSUBSCIP FALSE /**< does the separator use a secondary SCIP instance? */
62 #define SEPA_DELAY FALSE /**< should separation method be delayed, if other separators found cuts? */
63 
64 #define DEFAULT_MAXROUNDS 5 /**< maximal number of gomory separation rounds per node (-1: unlimited) */
65 #define DEFAULT_MAXROUNDSROOT 10 /**< maximal number of gomory separation rounds in the root node (-1: unlimited) */
66 #define DEFAULT_MAXSEPACUTS 50 /**< maximal number of gomory cuts separated per separation round */
67 #define DEFAULT_MAXSEPACUTSROOT 200 /**< maximal number of gomory cuts separated per separation round in root node */
68 #define DEFAULT_MAXRANK 3 /**< maximal rank of a gomory cut that could not be scaled to integral coefficients (-1: unlimited) */
69 #define DEFAULT_MAXRANKINTEGRAL -1 /**< maximal rank of a gomory cut that could be scaled to integral coefficients (-1: unlimited) */
70 #define DEFAULT_DYNAMICCUTS TRUE /**< should generated cuts be removed from the LP if they are no longer tight? */
71 #define DEFAULT_MAXWEIGHTRANGE 1e+04 /**< maximal valid range max(|weights|)/min(|weights|) of row weights */
72 #define DEFAULT_AWAY 0.01 /**< minimal integrality violation of a basis variable in order to try Gomory cut */
73 #define DEFAULT_MAKEINTEGRAL TRUE /**< try to scale all cuts to integral coefficients */
74 #define DEFAULT_FORCECUTS TRUE /**< if conversion to integral coefficients failed still consider the cut */
75 #define DEFAULT_SEPARATEROWS TRUE /**< separate rows with integral slack */
76 #define DEFAULT_DELAYEDCUTS TRUE /**< should cuts be added to the delayed cut pool? */
77 #define DEFAULT_SIDETYPEBASIS FALSE /**< choose side types of row (lhs/rhs) based on basis information? */
78 
79 #define BOUNDSWITCH 0.9999 /**< threshold for bound switching - see SCIPcalcMIR() */
80 #define USEVBDS TRUE /**< use variable bounds - see SCIPcalcMIR() */
81 #define ALLOWLOCAL TRUE /**< allow to generate local cuts - see SCIPcalcMIR() */
82 #define FIXINTEGRALRHS FALSE /**< try to generate an integral rhs - see SCIPcalcMIR() */
83 #define MAKECONTINTEGRAL FALSE /**< convert continuous variable to integral variables in SCIPmakeRowIntegral() */
84 
85 #define MAXAGGRLEN(nvars) (0.1*(nvars)+1000) /**< maximal length of base inequality */
86 
87 
88 /** separator data */
89 struct SCIP_SepaData
90 {
91  SCIP_Real maxweightrange; /**< maximal valid range max(|weights|)/min(|weights|) of row weights */
92  SCIP_Real away; /**< minimal integrality violation of a basis variable in order to try Gomory cut */
93  int maxrounds; /**< maximal number of gomory separation rounds per node (-1: unlimited) */
94  int maxroundsroot; /**< maximal number of gomory separation rounds in the root node (-1: unlimited) */
95  int maxsepacuts; /**< maximal number of gomory cuts separated per separation round */
96  int maxsepacutsroot; /**< maximal number of gomory cuts separated per separation round in root node */
97  int maxrank; /**< maximal rank of a gomory cut that could not be scaled to integral coefficients (-1: unlimited) */
98  int maxrankintegral; /**< maximal rank of a gomory cut that could be scaled to integral coefficients (-1: unlimited) */
99  int lastncutsfound; /**< total number of cuts found after last call of separator */
100  SCIP_Bool dynamiccuts; /**< should generated cuts be removed from the LP if they are no longer tight? */
101  SCIP_Bool makeintegral; /**< try to scale all cuts to integral coefficients */
102  SCIP_Bool forcecuts; /**< if conversion to integral coefficients failed still consider the cut */
103  SCIP_Bool separaterows; /**< separate rows with integral slack */
104  SCIP_Bool delayedcuts; /**< should cuts be added to the delayed cut pool? */
105  SCIP_Bool sidetypebasis; /**< choose side types of row (lhs/rhs) based on basis information? */
106 };
107 
108 
109 /** returns TRUE if the cut can be taken, otherwise FALSE if there some numerical evidences */
110 static
112  SCIP* scip, /**< SCIP data structure */
113  SCIP_SEPADATA* sepadata, /**< data of the separator */
114  SCIP_ROW* cut, /**< cut to check */
115  SCIP_Longint maxdnom, /**< maximal denominator to use for scaling */
116  SCIP_Real maxscale, /**< maximal scaling factor */
117  SCIP_Bool* useful /**< pointer to store if the cut is useful */
118  )
119 {
120  SCIP_Bool madeintegral;
121 
122  madeintegral = FALSE;
123  (*useful) = FALSE;
124 
125  if( sepadata->makeintegral )
126  {
127  /* try to scale the cut to integral values */
128  SCIP_CALL( SCIPmakeRowIntegral(scip, cut, -SCIPepsilon(scip), SCIPsumepsilon(scip),
129  maxdnom, maxscale, MAKECONTINTEGRAL, &madeintegral) );
130 
131  if( !madeintegral && !sepadata->forcecuts )
132  return SCIP_OKAY;
133 
134  /* in case the right hand side is plus infinity (due to scaling) the cut is useless so we are not taking it at all
135  */
136  if( madeintegral && SCIPisInfinity(scip, SCIProwGetRhs(cut)) )
137  return SCIP_OKAY;
138  }
139 
140  /* discard integral cut if the rank is too high */
141  if( madeintegral && sepadata->maxrankintegral != -1 && (SCIProwGetRank(cut) > sepadata->maxrankintegral) )
142  return SCIP_OKAY;
143 
144  /* discard cut if the rank is too high */
145  if( !madeintegral && (sepadata->maxrank != -1) && (SCIProwGetRank(cut) > sepadata->maxrank) )
146  return SCIP_OKAY;
147 
148  (*useful) = TRUE;
149 
150  return SCIP_OKAY;
151 }
152 
153 
154 /*
155  * Callback methods
156  */
157 
158 /** copy method for separator plugins (called when SCIP copies plugins) */
159 static
160 SCIP_DECL_SEPACOPY(sepaCopyGomory)
161 { /*lint --e{715}*/
162  assert(scip != NULL);
163  assert(sepa != NULL);
164  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
165 
166  /* call inclusion method of constraint handler */
168 
169  return SCIP_OKAY;
170 }
171 
172 /** destructor of separator to free user data (called when SCIP is exiting) */
173 static
174 SCIP_DECL_SEPAFREE(sepaFreeGomory)
175 { /*lint --e{715}*/
176  SCIP_SEPADATA* sepadata;
177 
178  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
179 
180  /* free separator data */
181  sepadata = SCIPsepaGetData(sepa);
182  assert(sepadata != NULL);
183 
184  SCIPfreeMemory(scip, &sepadata);
185 
186  SCIPsepaSetData(sepa, NULL);
187 
188  return SCIP_OKAY;
189 }
190 
191 
192 /** LP solution separation method of separator */
193 static
194 SCIP_DECL_SEPAEXECLP(sepaExeclpGomory)
195 { /*lint --e{715}*/
196  SCIP_SEPADATA* sepadata;
197  SCIP_VAR** vars;
198  SCIP_COL** cols;
199  SCIP_ROW** rows;
200  SCIP_Real* binvrow;
201  SCIP_Real* cutcoefs;
202  SCIP_Real maxscale;
203  SCIP_Real minfrac;
204  SCIP_Real maxfrac;
205  SCIP_Longint maxdnom;
206  SCIP_Bool cutoff;
207  int* sidetypes = NULL;
208  int* basisind;
209  int* inds;
210  int ninds;
211  int naddedcuts;
212  int nvars;
213  int ncols;
214  int nrows;
215  int ncalls;
216  int depth;
217  int maxdepth;
218  int maxsepacuts;
219  int c;
220  int i;
221 
222  assert(sepa != NULL);
223  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
224  assert(scip != NULL);
225  assert(result != NULL);
226 
227  *result = SCIP_DIDNOTRUN;
228 
229  sepadata = SCIPsepaGetData(sepa);
230  assert(sepadata != NULL);
231 
232  depth = SCIPgetDepth(scip);
233  ncalls = SCIPsepaGetNCallsAtNode(sepa);
234 
235  minfrac = sepadata->away;
236  maxfrac = 1.0 - sepadata->away;
237 
238  /* only call separator, if we are not close to terminating */
239  if( SCIPisStopped(scip) )
240  return SCIP_OKAY;
241 
242  /* only call the gomory cut separator a given number of times at each node */
243  if( (depth == 0 && sepadata->maxroundsroot >= 0 && ncalls >= sepadata->maxroundsroot)
244  || (depth > 0 && sepadata->maxrounds >= 0 && ncalls >= sepadata->maxrounds) )
245  return SCIP_OKAY;
246 
247  /* only call separator, if an optimal LP solution is at hand */
249  return SCIP_OKAY;
250 
251  /* only call separator, if the LP solution is basic */
252  if( !SCIPisLPSolBasic(scip) )
253  return SCIP_OKAY;
254 
255  /* only call separator, if there are fractional variables */
256  if( SCIPgetNLPBranchCands(scip) == 0 )
257  return SCIP_OKAY;
258 
259  /* get variables data */
260  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
261 
262  /* get LP data */
263  SCIP_CALL( SCIPgetLPColsData(scip, &cols, &ncols) );
264  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
265  if( ncols == 0 || nrows == 0 )
266  return SCIP_OKAY;
267 
268 #if 0 /* if too many columns, separator is usually very slow: delay it until no other cuts have been found */
269  if( ncols >= 50*nrows )
270  return SCIP_OKAY;
271 
272  if( ncols >= 5*nrows )
273  {
274  int ncutsfound;
275 
276  ncutsfound = SCIPgetNCutsFound(scip);
277  if( ncutsfound > sepadata->lastncutsfound || !SCIPsepaWasLPDelayed(sepa) )
278  {
279  sepadata->lastncutsfound = ncutsfound;
280  *result = SCIP_DELAYED;
281  return SCIP_OKAY;
282  }
283  }
284 #endif
285 
286  /* set the maximal denominator in rational representation of gomory cut and the maximal scale factor to
287  * scale resulting cut to integral values to avoid numerical instabilities
288  */
289  /**@todo find better but still stable gomory cut settings: look at dcmulti, gesa3, khb0525, misc06, p2756 */
290  maxdepth = SCIPgetMaxDepth(scip);
291  if( depth == 0 )
292  {
293  maxdnom = 1000;
294  maxscale = 1000.0;
295  }
296  else if( depth <= maxdepth/4 )
297  {
298  maxdnom = 1000;
299  maxscale = 1000.0;
300  }
301  else if( depth <= maxdepth/2 )
302  {
303  maxdnom = 100;
304  maxscale = 100.0;
305  }
306  else
307  {
308  maxdnom = 10;
309  maxscale = 10.0;
310  }
311 
312  /* allocate temporary memory */
313  SCIP_CALL( SCIPallocBufferArray(scip, &cutcoefs, nvars) );
314  SCIP_CALL( SCIPallocBufferArray(scip, &basisind, nrows) );
315  SCIP_CALL( SCIPallocBufferArray(scip, &binvrow, nrows) );
316  SCIP_CALL( SCIPallocBufferArray(scip, &inds, nrows) );
317  if ( sepadata->sidetypebasis )
318  {
319  SCIP_CALL( SCIPallocBufferArray(scip, &sidetypes, nrows) );
320  }
321 
322  /* get basis indices */
323  SCIP_CALL( SCIPgetLPBasisInd(scip, basisind) );
324 
325  /* get the maximal number of cuts allowed in a separation round */
326  if( depth == 0 )
327  maxsepacuts = sepadata->maxsepacutsroot;
328  else
329  maxsepacuts = sepadata->maxsepacuts;
330 
331  SCIPdebugMessage("searching gomory cuts: %d cols, %d rows, maxdnom=%" SCIP_LONGINT_FORMAT ", maxscale=%g, maxcuts=%d\n",
332  ncols, nrows, maxdnom, maxscale, maxsepacuts);
333 
334  cutoff = FALSE;
335  naddedcuts = 0;
336 
337  /* for all basic columns belonging to integer variables, try to generate a gomory cut */
338  for( i = 0; i < nrows && naddedcuts < maxsepacuts && !SCIPisStopped(scip) && !cutoff; ++i )
339  {
340  SCIP_Bool tryrow;
341 
342  tryrow = FALSE;
343  c = basisind[i];
344  if( c >= 0 )
345  {
346  SCIP_VAR* var;
347 
348  assert(c < ncols);
349  var = SCIPcolGetVar(cols[c]);
351  {
352  SCIP_Real primsol;
353 
354  primsol = SCIPcolGetPrimsol(cols[c]);
355  assert(SCIPgetVarSol(scip, var) == primsol); /*lint !e777*/
356 
357  if( SCIPfeasFrac(scip, primsol) >= minfrac )
358  {
359  SCIPdebugMessage("trying gomory cut for col <%s> [%g]\n", SCIPvarGetName(var), primsol);
360  tryrow = TRUE;
361  }
362  }
363  }
364  else if( sepadata->separaterows )
365  {
366  SCIP_ROW* row;
367 
368  assert(0 <= -c-1 && -c-1 < nrows);
369  row = rows[-c-1];
370  if( SCIProwIsIntegral(row) && !SCIProwIsModifiable(row) )
371  {
372  SCIP_Real primsol;
373 
374  primsol = SCIPgetRowActivity(scip, row);
375  if( SCIPfeasFrac(scip, primsol) >= minfrac )
376  {
377  SCIPdebugMessage("trying gomory cut for row <%s> [%g]\n", SCIProwGetName(row), primsol);
378  tryrow = TRUE;
379  }
380  }
381  }
382 
383  if( tryrow )
384  {
385  SCIP_Real cutrhs;
386  SCIP_Real cutact;
387  SCIP_Bool success;
388  SCIP_Bool cutislocal;
389  int cutrank;
390 
391  /* get the row of B^-1 for this basic integer variable with fractional solution value */
392  ninds = -1;
393  SCIP_CALL( SCIPgetLPBInvRow(scip, i, binvrow, inds, &ninds) );
394 
395  if ( sepadata->sidetypebasis )
396  {
397  int k;
398 
399  assert( sidetypes != NULL );
400  for (k = 0; k < nrows; ++k)
401  {
402  SCIP_BASESTAT stat;
403  SCIP_ROW* row;
404 
405  row = rows[k];
406  assert( row != NULL );
407 
408  /* for equations take automatic choice */
409  if ( SCIPisEQ(scip, SCIProwGetLhs(row), SCIProwGetRhs(row)) )
410  sidetypes[k] = 0;
411  else
412  {
413  /* for ranged rows use basis status */
414  assert( SCIPisLPSolBasic(scip) );
415  stat = SCIProwGetBasisStatus(row);
416  if ( stat == SCIP_BASESTAT_LOWER )
417  {
418  assert( ! SCIPisInfinity(scip, -SCIProwGetLhs(row)) );
419  sidetypes[k] = -1;
420  }
421  else if ( stat == SCIP_BASESTAT_UPPER )
422  {
423  assert( ! SCIPisInfinity(scip, SCIProwGetRhs(row)) );
424  sidetypes[k] = 1;
425  }
426  else
427  sidetypes[k] = 0;
428  }
429  }
430  }
431 
432  cutact = 0.0;
433  cutrhs = SCIPinfinity(scip);
434 
435  /* need to ensure that is sparsity information is requested from SCIPgetLPBInvRow
436  * that it is used in SCIPcalcMIR */
437  if( inds != NULL && ninds > -1 )
438  {
439  /* create a MIR cut out of the weighted LP rows using the B^-1 row as weights */
441  (int) MAXAGGRLEN(nvars), sepadata->maxweightrange, minfrac, maxfrac, binvrow, -1.0, inds, ninds, -1,
442  sidetypes, 1.0, NULL, NULL, cutcoefs, &cutrhs, &cutact, &success, &cutislocal, &cutrank) );
443  }
444  else
445  {
446  /* create a MIR cut out of the weighted LP rows using the B^-1 row as weights */
448  (int) MAXAGGRLEN(nvars), sepadata->maxweightrange, minfrac, maxfrac, binvrow, -1.0, NULL, -1, -1,
449  sidetypes, 1.0, NULL, NULL, cutcoefs, &cutrhs, &cutact, &success, &cutislocal, &cutrank) );
450  }
451  assert(ALLOWLOCAL || !cutislocal);
452 
453  /* @todo Currently we are using the SCIPcalcMIR() function to compute the coefficients of the Gomory
454  * cut. Alternatively, we could use the direct version (see thesis of Achterberg formula (8.4)) which
455  * leads to cut a of the form \sum a_i x_i \geq 1. Rumor has it that these cuts are better.
456  */
457 
458  SCIPdebugMessage(" -> success=%u: %g <= %g\n", success, cutact, cutrhs);
459 
460  /* if successful, convert dense cut into sparse row, and add the row as a cut */
461  if( success && SCIPisFeasGT(scip, cutact, cutrhs) )
462  {
463  SCIP_ROW* cut;
464  char cutname[SCIP_MAXSTRLEN];
465  int v;
466 
467  /* construct cut name */
468  if( c >= 0 )
469  (void) SCIPsnprintf(cutname, SCIP_MAXSTRLEN, "gom%d_x%d", SCIPgetNLPs(scip), c);
470  else
471  (void) SCIPsnprintf(cutname, SCIP_MAXSTRLEN, "gom%d_s%d", SCIPgetNLPs(scip), -c-1);
472 
473  /* create empty cut */
474  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, &cut, sepa, cutname, -SCIPinfinity(scip), cutrhs,
475  cutislocal, FALSE, sepadata->dynamiccuts) );
476 
477  /* set cut rank */
478  SCIProwChgRank(cut, cutrank);
479 
480  /* cache the row extension and only flush them if the cut gets added */
482 
483  /* collect all non-zero coefficients */
484  for( v = 0; v < nvars; ++v )
485  {
486  if( !SCIPisZero(scip, cutcoefs[v]) )
487  {
488  SCIP_CALL( SCIPaddVarToRow(scip, cut, vars[v], cutcoefs[v]) );
489  }
490  }
491 
492  if( SCIProwGetNNonz(cut) == 0 )
493  {
494  assert(SCIPisFeasNegative(scip, cutrhs));
495  SCIPdebugMessage(" -> gomory cut detected infeasibility with cut 0 <= %f\n", cutrhs);
496  cutoff = TRUE;
497  }
498  else if( SCIProwGetNNonz(cut) == 1 )
499  {
500  /* add the bound change as cut to avoid that the LP gets modified. that would mean the LP is not flushed
501  * and the method SCIPgetLPBInvRow() fails; SCIP internally will apply that bound change automatically
502  */
503  SCIP_CALL( SCIPaddCut(scip, NULL, cut, TRUE, &cutoff) );
504  naddedcuts++;
505  }
506  else
507  {
508  /* Only take efficacious cuts, except for cuts with one non-zero coefficients (= bound
509  * changes); the latter cuts will be handeled internally in sepastore.
510  */
511  if( SCIPisCutEfficacious(scip, NULL, cut) )
512  {
513  SCIP_Bool useful;
514 
515  assert(success == TRUE);
516  assert(SCIPisInfinity(scip, -SCIProwGetLhs(cut)));
517  assert(!SCIPisInfinity(scip, SCIProwGetRhs(cut)));
518 
519  SCIPdebugMessage(" -> gomory cut for <%s>: act=%f, rhs=%f, eff=%f\n",
520  c >= 0 ? SCIPvarGetName(SCIPcolGetVar(cols[c])) : SCIProwGetName(rows[-c-1]),
521  cutact, cutrhs, SCIPgetCutEfficacy(scip, NULL, cut));
522 
523  SCIP_CALL( evaluateCutNumerics(scip, sepadata, cut, maxdnom, maxscale, &useful) );
524 
525  if( useful )
526  {
527  SCIPdebugMessage(" -> found gomory cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
528  cutname, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
532 
533  /* flush all changes before adding the cut */
535 
536  /* add global cuts which are not implicit bound changes to the cut pool */
537  if( !cutislocal )
538  {
539  if( sepadata->delayedcuts )
540  {
542  }
543  else
544  {
545  SCIP_CALL( SCIPaddPoolCut(scip, cut) );
546  }
547  }
548  else
549  {
550  /* local cuts we add to the sepastore */
551  SCIP_CALL( SCIPaddCut(scip, NULL, cut, FALSE, &cutoff) );
552  }
553 
554  naddedcuts++;
555  }
556  }
557  }
558 
559  /* release the row */
560  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
561  }
562  }
563  }
564 
565  /* free temporary memory */
566  if ( sepadata->sidetypebasis )
567  {
568  SCIPfreeBufferArray(scip, &sidetypes);
569  }
570  SCIPfreeBufferArray(scip, &inds);
571  SCIPfreeBufferArray(scip, &binvrow);
572  SCIPfreeBufferArray(scip, &basisind);
573  SCIPfreeBufferArray(scip, &cutcoefs);
574 
575  SCIPdebugMessage("end searching gomory cuts: found %d cuts\n", naddedcuts);
576 
577  sepadata->lastncutsfound = SCIPgetNCutsFound(scip);
578 
579  /* evalute the result of the separation */
580  if( cutoff )
581  *result = SCIP_CUTOFF;
582  else if ( naddedcuts > 0 )
583  *result = SCIP_SEPARATED;
584  else
585  *result = SCIP_DIDNOTFIND;
586 
587  return SCIP_OKAY;
588 }
589 
590 
591 /*
592  * separator specific interface methods
593  */
594 
595 /** creates the Gomory MIR cut separator and includes it in SCIP */
597  SCIP* scip /**< SCIP data structure */
598  )
599 {
600  SCIP_SEPADATA* sepadata;
601  SCIP_SEPA* sepa;
602 
603  /* create separator data */
604  SCIP_CALL( SCIPallocMemory(scip, &sepadata) );
605  sepadata->lastncutsfound = 0;
606 
607  /* include separator */
610  sepaExeclpGomory, NULL,
611  sepadata) );
612 
613  assert(sepa != NULL);
614 
615  /* set non-NULL pointers to callback methods */
616  SCIP_CALL( SCIPsetSepaCopy(scip, sepa, sepaCopyGomory) );
617  SCIP_CALL( SCIPsetSepaFree(scip, sepa, sepaFreeGomory) );
618 
619  /* add separator parameters */
621  "separating/gomory/maxrounds",
622  "maximal number of gomory separation rounds per node (-1: unlimited)",
623  &sepadata->maxrounds, FALSE, DEFAULT_MAXROUNDS, -1, INT_MAX, NULL, NULL) );
625  "separating/gomory/maxroundsroot",
626  "maximal number of gomory separation rounds in the root node (-1: unlimited)",
627  &sepadata->maxroundsroot, FALSE, DEFAULT_MAXROUNDSROOT, -1, INT_MAX, NULL, NULL) );
629  "separating/gomory/maxsepacuts",
630  "maximal number of gomory cuts separated per separation round",
631  &sepadata->maxsepacuts, FALSE, DEFAULT_MAXSEPACUTS, 0, INT_MAX, NULL, NULL) );
633  "separating/gomory/maxsepacutsroot",
634  "maximal number of gomory cuts separated per separation round in the root node",
635  &sepadata->maxsepacutsroot, FALSE, DEFAULT_MAXSEPACUTSROOT, 0, INT_MAX, NULL, NULL) );
637  "separating/gomory/maxrank",
638  "maximal rank of a gomory cut that could not be scaled to integral coefficients (-1: unlimited)",
639  &sepadata->maxrank, FALSE, DEFAULT_MAXRANK, -1, INT_MAX, NULL, NULL) );
641  "separating/gomory/maxrankintegral",
642  "maximal rank of a gomory cut that could be scaled to integral coefficients (-1: unlimited)",
643  &sepadata->maxrankintegral, FALSE, DEFAULT_MAXRANKINTEGRAL, -1, INT_MAX, NULL, NULL) );
645  "separating/gomory/away",
646  "minimal integrality violation of a basis variable in order to try Gomory cut",
647  &sepadata->away, FALSE, DEFAULT_AWAY, 1e-4, 0.5, NULL, NULL) );
649  "separating/gomory/maxweightrange",
650  "maximal valid range max(|weights|)/min(|weights|) of row weights",
651  &sepadata->maxweightrange, TRUE, DEFAULT_MAXWEIGHTRANGE, 1.0, SCIP_REAL_MAX, NULL, NULL) );
653  "separating/gomory/dynamiccuts",
654  "should generated cuts be removed from the LP if they are no longer tight?",
655  &sepadata->dynamiccuts, FALSE, DEFAULT_DYNAMICCUTS, NULL, NULL) );
657  "separating/gomory/makeintegral",
658  "try to scale cuts to integral coefficients",
659  &sepadata->makeintegral, TRUE, DEFAULT_MAKEINTEGRAL, NULL, NULL) );
661  "separating/gomory/forcecuts",
662  "if conversion to integral coefficients failed still consider the cut",
663  &sepadata->forcecuts, TRUE, DEFAULT_FORCECUTS, NULL, NULL) );
665  "separating/gomory/separaterows",
666  "separate rows with integral slack",
667  &sepadata->separaterows, TRUE, DEFAULT_SEPARATEROWS, NULL, NULL) );
669  "separating/gomory/delayedcuts",
670  "should cuts be added to the delayed cut pool?",
671  &sepadata->delayedcuts, TRUE, DEFAULT_DELAYEDCUTS, NULL, NULL) );
673  "separating/gomory/sidetypebasis",
674  "choose side types of row (lhs/rhs) based on basis information?",
675  &sepadata->sidetypebasis, TRUE, DEFAULT_SIDETYPEBASIS, NULL, NULL) );
676 
677  return SCIP_OKAY;
678 }
int SCIPgetNLPBranchCands(SCIP *scip)
Definition: scip.c:33158
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41572
#define DEFAULT_MAXSEPACUTSROOT
Definition: sepa_gomory.c:67
SCIP_RETCODE SCIPgetLPBInvRow(SCIP *scip, int r, SCIP_Real *coefs, int *inds, int *ninds)
Definition: scip.c:26894
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:41685
#define SCIPallocMemory(scip, ptr)
Definition: scip.h:20526
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16443
SCIP_RETCODE SCIPaddDelayedPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:31341
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:111
SCIP_RETCODE SCIPcalcMIR(SCIP *scip, SCIP_SOL *sol, SCIP_Real boundswitch, SCIP_Bool usevbds, SCIP_Bool allowlocal, SCIP_Bool fixintegralrhs, int *boundsfortrans, SCIP_BOUNDTYPE *boundtypesfortrans, int maxmksetcoefs, SCIP_Real maxweightrange, SCIP_Real minfrac, SCIP_Real maxfrac, SCIP_Real *weights, SCIP_Real maxweight, int *weightinds, int nweightinds, int rowlensum, int *sidetypes, SCIP_Real scale, SCIP_Real *mksetcoefs, SCIP_Bool *mksetcoefsvalid, SCIP_Real *mircoef, SCIP_Real *mirrhs, SCIP_Real *cutactivity, SCIP_Bool *success, SCIP_Bool *cutislocal, int *cutrank)
Definition: scip.c:27058
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:41648
#define SEPA_PRIORITY
Definition: sepa_gomory.c:58
SCIP_Real SCIPgetRowMinCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28045
enum SCIP_BaseStat SCIP_BASESTAT
Definition: type_lpi.h:84
SCIP_RETCODE SCIPincludeSepaGomory(SCIP *scip)
Definition: sepa_gomory.c:596
#define SCIP_MAXSTRLEN
Definition: def.h:201
#define SEPA_DESC
Definition: sepa_gomory.c:57
#define NULL
Definition: lpi_spx.cpp:130
#define DEFAULT_MAXROUNDSROOT
Definition: sepa_gomory.c:65
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1125
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:18915
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip.c:30859
#define DEFAULT_DELAYEDCUTS
Definition: sepa_gomory.c:76
#define FALSE
Definition: def.h:56
#define DEFAULT_MAXROUNDS
Definition: sepa_gomory.c:64
#define SEPA_MAXBOUNDDIST
Definition: sepa_gomory.c:60
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:8174
#define TRUE
Definition: def.h:55
SCIP_BASESTAT SCIProwGetBasisStatus(SCIP_ROW *row)
Definition: lp.c:18963
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
#define DEFAULT_MAKEINTEGRAL
Definition: sepa_gomory.c:73
#define FIXINTEGRALRHS
Definition: sepa_gomory.c:82
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip.c:26439
#define ALLOWLOCAL
Definition: sepa_gomory.c:81
#define SCIPdebugMessage
Definition: pub_message.h:77
SCIP_RETCODE SCIPaddCut(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip.c:30967
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip.c:6718
SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:544
const char * SCIPsepaGetName(SCIP_SEPA *sepa)
Definition: sepa.c:633
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28063
SCIP_RETCODE SCIPgetLPColsData(SCIP *scip, SCIP_COL ***cols, int *ncols)
Definition: scip.c:26672
#define USEVBDS
Definition: sepa_gomory.c:80
#define DEFAULT_MAXRANKINTEGRAL
Definition: sepa_gomory.c:69
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.c:3547
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.c:3573
static SCIP_DECL_SEPAEXECLP(sepaExeclpGomory)
Definition: sepa_gomory.c:194
#define SCIPfreeMemory(scip, ptr)
Definition: scip.h:20542
int SCIPgetNCutsFound(SCIP *scip)
Definition: scip.c:37997
#define MAKECONTINTEGRAL
Definition: sepa_gomory.c:83
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:19034
#define DEFAULT_MAXSEPACUTS
Definition: sepa_gomory.c:66
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:18925
SCIP_Real SCIPcolGetPrimsol(SCIP_COL *col)
Definition: lp.c:18639
#define SEPA_USESSUBSCIP
Definition: sepa_gomory.c:61
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:41996
int SCIProwGetRank(SCIP_ROW *row)
Definition: lp.c:19004
SCIP_Real SCIPepsilon(SCIP *scip)
Definition: scip.c:41118
int SCIPgetMaxDepth(SCIP *scip)
Definition: scip.c:38214
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:31062
#define DEFAULT_MAXRANK
Definition: sepa_gomory.c:68
#define DEFAULT_FORCECUTS
Definition: sepa_gomory.c:74
#define MAXAGGRLEN(nvars)
Definition: sepa_gomory.c:85
#define DEFAULT_SEPARATEROWS
Definition: sepa_gomory.c:75
#define DEFAULT_SIDETYPEBASIS
Definition: sepa_gomory.c:77
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip.c:26750
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:41637
#define SEPA_DELAY
Definition: sepa_gomory.c:62
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.c:28003
SCIP_Longint SCIPgetNLPs(SCIP *scip)
Definition: scip.c:37435
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:18974
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.c:27629
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41946
#define DEFAULT_DYNAMICCUTS
Definition: sepa_gomory.c:70
public data structures and miscellaneous methods
void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:554
void SCIProwChgRank(SCIP_ROW *row, int rank)
Definition: lp.c:19137
#define SCIP_Bool
Definition: def.h:53
SCIP_Real SCIProwGetNorm(SCIP_ROW *row)
Definition: lp.c:18891
SCIP_Bool SCIPsepaWasLPDelayed(SCIP_SEPA *sepa)
Definition: sepa.c:870
SCIP_RETCODE SCIPsetSepaCopy(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: scip.c:6702
#define SEPA_NAME
Definition: sepa_gomory.c:56
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:27811
#define SEPA_FREQ
Definition: sepa_gomory.c:59
public methods for LP management
Gomory MIR Cuts.
#define DEFAULT_MAXWEIGHTRANGE
Definition: sepa_gomory.c:71
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:38140
#define SCIP_REAL_MAX
Definition: def.h:128
SCIP_RETCODE SCIPgetLPBasisInd(SCIP *scip, int *basisind)
Definition: scip.c:26866
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16608
static SCIP_DECL_SEPACOPY(sepaCopyGomory)
Definition: sepa_gomory.c:160
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:20585
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:27834
SCIP_Bool SCIProwIsIntegral(SCIP_ROW *row)
Definition: lp.c:19014
#define SCIP_Real
Definition: def.h:127
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip.c:27738
#define SCIP_Longint
Definition: def.h:112
int SCIPsepaGetNCallsAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:760
#define DEFAULT_AWAY
Definition: sepa_gomory.c:72
SCIP_Real SCIPgetVarSol(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:17628
SCIP_Real SCIPgetRowLPActivity(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28134
#define BOUNDSWITCH
Definition: sepa_gomory.c:79
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
Definition: scip.c:42068
SCIP_Real SCIPgetRowActivity(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28245
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:18836
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip.c:10572
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:20597
static SCIP_DECL_SEPAFREE(sepaFreeGomory)
Definition: sepa_gomory.c:174
SCIP_Bool SCIPisLPSolBasic(SCIP *scip)
Definition: scip.c:26847
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.c:6660
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:18685
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.c:3629
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:27864
SCIP_Real SCIPsumepsilon(SCIP *scip)
Definition: scip.c:41132
SCIP_Real SCIPgetCutEfficacy(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip.c:30836
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:38