Scippy

SCIP

Solving Constraint Integer Programs

sepa_cgmip.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-2023 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 /* #define SCIP_WRITEPROB */
25 /* #define SCIP_OUTPUT */
26 /**@file sepa_cgmip.c
27  * @ingroup DEFPLUGINS_SEPA
28  * @brief Chvatal-Gomory cuts computed via a sub-MIP
29  * @author Marc Pfetsch
30  *
31  * Separate Chvátal-Gomory cuts using a sub-MIP. The approach is based on the following papers.
32  *
33  * M. Fischetti and A. Lodi@n
34  * Optimizing over the first Chvátal closure,@n
35  * in: M. Jünger and V. Kaibel (eds.) Integer Programming and Combinatorial Optimization IPCO 2005,@n
36  * LNCS 3509, pp. 12-22. Springer, Berlin Heidelberg New York (2005)
37  *
38  * M. Fischetti and A. Lodi@n
39  * Optimizing over the first Chvátal closure,@n
40  * Mathematical Programming 110, 3-20 (2007)
41  *
42  * P. Bonami, G. Cornuéjols, S. Dash, M. Fischetti, and A. Lodi@n
43  * Projected Chvátal-Gomory cuts for mixed integer linear programs,@n
44  * Mathematical Programming 113, No. 2 (2008)
45  *
46  *
47  * There are several possibilities to generate the final cut:
48  *
49  * - The CMIR-routines of SCIP can be used (if @p usecmir is true). One can determine which bound is
50  * used in the rounding operation (if @p cmirownbounds is true) or let SCIP choose the best. This
51  * version is generally numerically the most stable.
52  * - If @p usestrongcg is true, we try to generate Strong-CG cuts (as done in sepa_strongcg.c).
53  * - One can directly generate the CG-cut as computed (if @p usecmir and @p usestrongcg are
54  * false). The cut is not taken from the solution of the MIP, but is recomputed, and some care (but
55  * not as much as in the first version) has been taken to create a valid cut.
56  *
57  * The computation time of the separation MIP is limited as follows:
58  * - There is a node limit (parameters @a minnodelimit and @a maxnodelimit).
59  * - There is a time limit (parameter @a timelimit).
60  * - If paramter @a earlyterm is true, the separation is run until the first cut that is violated is
61  * found. (Note that these cuts are not necessarily added to the LP, because here also the norm of
62  * the cuts are taken into account - which cannot easily be included into the separation subscip.)
63  * Then the solution process is continued for a certain number of nodes.
64  *
65  * @todo Check whether one can weaken the conditions on the continuous variables.
66  * @todo Use pointers to originating separators to sort out cuts that should not be used.
67  *
68  * @warning This separator should be used carefully - it may require a long separation time.
69  */
70 
71 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
72 
73 #include "blockmemshell/memory.h"
74 #include "scip/cons_linear.h"
75 #include "scip/cuts.h"
76 #include "scip/pub_cons.h"
77 #include "scip/pub_lp.h"
78 #include "scip/pub_message.h"
79 #include "scip/pub_misc.h"
80 #include "scip/pub_sepa.h"
81 #include "scip/pub_var.h"
82 #include "scip/scip_branch.h"
83 #include "scip/scip_cons.h"
84 #include "scip/scip_copy.h"
85 #include "scip/scip_cut.h"
86 #include "scip/scip_general.h"
87 #include "scip/scip_lp.h"
88 #include "scip/scip_mem.h"
89 #include "scip/scip_message.h"
90 #include "scip/scip_numerics.h"
91 #include "scip/scip_param.h"
92 #include "scip/scip_prob.h"
93 #include "scip/scip_randnumgen.h"
94 #include "scip/scip_sepa.h"
95 #include "scip/scip_sol.h"
96 #include "scip/scip_solve.h"
97 #include "scip/scip_solvingstats.h"
98 #include "scip/scip_timing.h"
99 #include "scip/scip_tree.h"
100 #include "scip/scip_var.h"
101 #include "scip/scipdefplugins.h"
102 #include "scip/sepa_cgmip.h"
103 #include <string.h>
104 
105 
106 #define SEPA_NAME "cgmip"
107 #define SEPA_DESC "Chvatal-Gomory cuts via MIPs separator"
108 #define SEPA_PRIORITY -1000
109 #define SEPA_FREQ -1
110 #define SEPA_MAXBOUNDDIST 0.0
111 #define SEPA_USESSUBSCIP TRUE /**< does the separator use a secondary SCIP instance? */
112 #define SEPA_DELAY FALSE /**< should separation method be delayed, if other separators found cuts? */
113 
114 #define DEFAULT_MAXROUNDS 5 /**< maximal number of separation rounds per node (-1: unlimited) */
115 #define DEFAULT_MAXROUNDSROOT 50 /**< maximal number of separation rounds in the root node (-1: unlimited) */
116 #define DEFAULT_MAXDEPTH -1 /**< maximal depth at which the separator is applied */
117 #define DEFAULT_DECISIONTREE FALSE /**< Use decision tree to turn separation on/off? */
118 #define DEFAULT_TIMELIMIT 1e20 /**< time limit for sub-MIP (set to infinity in order to be deterministic) */
119 #define DEFAULT_MEMORYLIMIT 1e20 /**< memory limit for sub-MIP */
120 #define DEFAULT_CUTCOEFBND 1000.0 /**< bounds on the values of the coefficients in the CG-cut */
121 #define DEFAULT_MINNODELIMIT 500LL /**< minimum number of nodes considered for sub-MIP (-1: unlimited) */
122 #define DEFAULT_MAXNODELIMIT 5000LL /**< maximum number of nodes considered for sub-MIP (-1: unlimited) */
123 #define DEFAULT_ONLYACTIVEROWS FALSE /**< Use only active rows to generate cuts? */
124 #define DEFAULT_MAXROWAGE -1 /**< maximal age of rows to consider if onlyactiverows is false */
125 #define DEFAULT_ONLYRANKONE FALSE /**< Separate rank 1 inequalities w.r.t. CG-MIP separator? */
126 #define DEFAULT_ONLYINTVARS FALSE /**< Generate cuts for problems with only integer variables? */
127 #define DEFAULT_CONTCONVERT FALSE /**< Convert some integral variables to be continuous to reduce the size of the sub-MIP? */
128 #define DEFAULT_CONTCONVFRAC 0.1 /**< fraction of integral variables converted to be continuous (if contconvert) */
129 #define DEFAULT_CONTCONVMIN 100 /**< minimum number of integral variables before some are converted to be continuous */
130 #define DEFAULT_INTCONVERT FALSE /**< Convert some integral variables attaining fractional values to have integral value? */
131 #define DEFAULT_INTCONVFRAC 0.1 /**< fraction of fractional integral variables converted to have integral value (if intconvert) */
132 #define DEFAULT_INTCONVMIN 100 /**< minimum number of integral variables before some are converted to have integral value */
133 #define DEFAULT_SKIPMULTBOUNDS TRUE /**< Skip the upper bounds on the multipliers in the sub-MIP? */
134 #define DEFAULT_OBJLONE FALSE /**< Should the objective of the sub-MIP only minimize the l1-norm of the multipliers? */
135 #define DEFAULT_OBJWEIGHT 1e-03 /**< objective weight for artificial variables */
136 #define DEFAULT_OBJWEIGHTSIZE TRUE /**< Weight each row by its size? */
137 #define DEFAULT_DYNAMICCUTS TRUE /**< Should generated cuts be removed from the LP if they are no longer tight? */
138 #define DEFAULT_USECMIR TRUE /**< Use CMIR-generator (otherwise add cut directly)? */
139 #define DEFAULT_USESTRONGCG FALSE /**< Use strong CG-function to strengthen cut? */
140 #define DEFAULT_CMIROWNBOUNDS FALSE /**< Tell CMIR-generator which bounds to used in rounding? */
141 #define DEFAULT_USECUTPOOL TRUE /**< Use cutpool to store CG-cuts even if the are not efficient? */
142 #define DEFAULT_PRIMALSEPARATION TRUE /**< Only separate cuts that are tight for the best feasible solution? */
143 #define DEFAULT_EARLYTERM TRUE /**< Terminate separation if a violated (but possibly sub-optimal) cut has been found? */
144 #define DEFAULT_ADDVIOLATIONCONS FALSE /**< Add constraint to subscip that only allows violated cuts (otherwise add obj. limit)?*/
145 #define DEFAULT_ADDVIOLCONSHDLR FALSE /**< Add constraint handler to filter out violated cuts? */
146 #define DEFAULT_CONSHDLRUSENORM TRUE /**< Should the violation constraint handler use the norm of a cut to check for feasibility? */
147 #define DEFAULT_USEOBJUB FALSE /**< Use upper bound on objective function (via primal solution)? */
148 #define DEFAULT_USEOBJLB FALSE /**< Use lower bound on objective function (via lower bound)? */
149 #define DEFAULT_SUBSCIPFAST TRUE /**< Should the settings for the sub-MIP be optimized for speed? */
150 #define DEFAULT_OUTPUT FALSE /**< Should information about the sub-MIP and cuts be displayed? */
151 #define DEFAULT_RANDSEED 101 /**< start random seed for random number generation */
152 #define DEFAULT_GENPRIMALSOLS FALSE /**< Try to generate primal solutions from Gomory cuts? */
153 
154 
155 #define NROWSTOOSMALL 5 /**< only separate if the number of rows is larger than this number */
156 #define NCOLSTOOSMALL 5 /**< only separate if the number of columns is larger than this number */
157 
158 #define EPSILONVALUE 1e-03 /**< epsilon value needed to model strict-inequalities */
159 #define BETAEPSILONVALUE 1e-02 /**< epsilon value for fracbeta - is larger than EPSILONVALUE for numerical stability */
160 #define STALLNODELIMIT 1000LL /**< number of stalling nodes if earlyterm is true */
161 #define CONSHDLRFULLNORM FALSE /**< compute real cut and compute norm for this (if addviolconshdlr and conshdlrusenorm are true) */
162 #define MINEFFICACY 0.05 /**< minimum efficacy of a cut - compare set.c */
163 #define MAXNSOLS 1000 /**< maximal number of solutions stored in sub-SCIP */
164 #define OBJWEIGHTRANGE 0.01 /**< maximal range of scaling of objective w.r.t. size of rows */
165 
166 /* parameters used for CMIR-generation (taken from sepa_gomory) */
167 #define BOUNDSWITCH 0.9999
168 #define USEVBDS TRUE
169 #define POSTPROCESS TRUE
170 #define MINFRAC 0.0009 /**< to allow a deviation of the same size as EPSILONVALUE */
171 #define MAXFRAC 0.9991 /**< to allow a deviation of the same size as EPSILONVALUE */
172 #define FIXINTEGRALRHS FALSE
173 #define MAKECONTINTEGRAL FALSE
174 #define MAXWEIGHTRANGE 1e+05 /**< maximal valid range max(|weights|)/min(|weights|) of row weights */
175 #define AWAY 0.005 /**< minimal fractionality of a basic variable in order to try GMI cut */
176 #define SEPARATEROWS TRUE /**< Separate rows with integral slack? */
177 
178 #define MAXAGGRLEN(nvars) nvars /**< currently very large to allow any generation; an alternative would be (0.1*(nvars)+1000) */
179 
180 /** separator data */
181 struct SCIP_SepaData
182 {
183  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
184  int maxrounds; /**< maximal number of separation rounds per node (-1: unlimited) */
185  int maxroundsroot; /**< maximal number of separation rounds in the root node (-1: unlimited) */
186  int maxdepth; /**< maximal depth at which the separator is applied */
187  SCIP_Bool decisiontree; /**< Use decision tree to turn separation on/off? */
188  SCIP_Real timelimit; /**< time limit for subscip */
189  SCIP_Real memorylimit; /**< memory limit for subscip */
190  SCIP_Longint minnodelimit; /**< minimum number of nodes considered for sub-MIP (-1: unlimited) */
191  SCIP_Longint maxnodelimit; /**< maximum number of nodes considered for sub-MIP (-1: unlimited) */
192  SCIP_Real cutcoefbnd; /**< bounds on the values of the coefficients in the CG-cut */
193  SCIP_Bool onlyactiverows; /**< Use only active rows to generate cuts? */
194  int maxrowage; /**< maximal age of rows to consider if onlyactiverows is false */
195  SCIP_Bool onlyrankone; /**< Separate only rank 1 inequalities w.r.t. CG-MIP separator? */
196  SCIP_Bool onlyintvars; /**< Generate cuts for problems with only integer variables? */
197  SCIP_Bool allowlocal; /**< Allow local cuts? */
198  SCIP_Bool contconvert; /**< Convert some integral variables to be continuous to reduce the size of the sub-MIP? */
199  SCIP_Real contconvfrac; /**< fraction of integral variables converted to be continuous (if contconvert) */
200  int contconvmin; /**< minimum number of integral variables before some are converted to be continuous */
201  SCIP_Bool intconvert; /**< Convert some integral variables attaining fractional values to have integral value? */
202  SCIP_Real intconvfrac; /**< fraction of frac. integral variables converted to have integral value (if intconvert) */
203  int intconvmin; /**< minimum number of integral variables before some are converted to have integral value */
204  SCIP_Bool skipmultbounds; /**< Skip the upper bounds on the multipliers in the sub-MIP? */
205  SCIP_Bool objlone; /**< Should the objective of the sub-MIP only minimize the l1-norm of the multipliers? */
206  SCIP_Real objweight; /**< objective weight for artificial variables */
207  SCIP_Bool objweightsize; /**< Weight each row by its size? */
208  SCIP_Bool dynamiccuts; /**< Should generated cuts be removed from the LP if they are no longer tight? */
209  SCIP_Bool usecmir; /**< Use CMIR-generator (otherwise add cut directly)? */
210  SCIP_Bool usestrongcg; /**< Use strong CG-function to strengthen cut? */
211  SCIP_Bool cmirownbounds; /**< Tell CMIR-generator which bounds to used in rounding? */
212  SCIP_Bool usecutpool; /**< Use cutpool to store CG-cuts even if the are not efficient? */
213  SCIP_Bool primalseparation; /**< Only separate cuts that are tight for the best feasible solution? */
214  SCIP_Bool earlyterm; /**< Terminate separation if a violated (but possibly sub-optimal) cut has been found? */
215  SCIP_Bool addviolationcons; /**< Add constraint to subscip that only allows violated cuts? */
216  SCIP_Bool addviolconshdlr; /**< Add constraint handler to filter out violated cuts? */
217  SCIP_Bool conshdlrusenorm; /**< Should the violation constraint handler use the cut-norm to check for feasibility? */
218  SCIP_Bool useobjub; /**< Use upper bound on objective function (via primal solution)? */
219  SCIP_Bool useobjlb; /**< Use lower bound on objective function (via lower bound)? */
220  SCIP_Bool subscipfast; /**< Should the settings for the sub-MIP be optimized for speed? */
221  SCIP_Bool output; /**< Should information about the sub-MIP and cuts be displayed? */
222  SCIP_Bool genprimalsols; /**< Try to generate primal solutions from Gomory cuts? */
223 };
224 
225 
226 /** what happens for columns in the LP */
228 {
229  colPresent = 0, /**< column is present in the separating MIP */
230  colContinuous = 1, /**< column corresponds to a continuous variable */
231  colConverted = 2, /**< column is converted to be continuous */
232  colAtUb = 3, /**< variable corresponding to column was at it's upper bound and was complemented */
233  colAtLb = 4 /**< variable corresponding to column was at it's lower bound (possibly complemented) */
234 };
236 
237 
238 /** data for the sub-MIP */
239 struct CGMIP_MIPData
240 {
241  SCIP* subscip; /**< pointer to (sub)SCIP data structure containing the auxiliary IP */
242  unsigned int m; /**< number of constraints of subscip */
243  unsigned int n; /**< number of variables of subscip */
244  unsigned int nrows; /**< number of rows of original LP */
245  unsigned int ncols; /**< number of columns of original LP */
246  unsigned int ntotalrows; /**< number of total rows used (possibly including objective rows) */
247 
248  SCIP_VAR** alpha; /**< cut coefficient variable (NULL if not in separating MIP) */
249  SCIP_VAR* beta; /**< rhs of cut */
250  SCIP_VAR** fracalpha; /**< fractional part of lhs of cut (NULL if not present) */
251  SCIP_VAR* fracbeta; /**< fractional part of rhs of cut */
252  CGMIP_COLTYPE* coltype; /**< type for the columns */
253  SCIP_Bool* iscomplemented; /**< whether the variable was complemented */
254  SCIP_Bool* isshifted; /**< whether the variable was shifted to have 0 lower bound */
255 
256  SCIP_VAR** ylhs; /**< auxiliary row variables for lhs (NULL if not present) */
257  SCIP_VAR** yrhs; /**< auxiliary row variables for rhs (NULL if not present) */
258 
259  SCIP_VAR** z; /**< auxiliary variables for upper bounds (NULL if not present) */
260 
261  SCIP_Real* lhs; /**< transformed left hand sides */
262  SCIP_Real* rhs; /**< transformed left hand sides */
263 
264  char normtype; /**< type of norm to use for efficacy norm calculation */
265 
266  /* additional redundant data */
267  SCIP_Bool conshdlrusenorm; /**< copy from sepadata */
268  SCIP_Bool conshdlrfullnorm; /**< compute real cut and compute norm for this (if addviolconshdlr and conshdlrusenorm are true) */
269  SCIP* scip; /**< original SCIP */
270  SCIP_SEPA* sepa; /**< CG-cut separator */
271  SCIP_SEPADATA* sepadata; /**< CG-cut separator data */
272 };
273 typedef struct CGMIP_MIPData CGMIP_MIPDATA;
274 
275 
276 /*
277  * constraint handler to filter out violated cuts
278  */
279 
280 /* constraint handler properties */
281 #define CONSHDLR_NAME "violatedCuts"
282 #define CONSHDLR_DESC "only allow solutions corresponding to violated cuts"
283 
284 /** constraint handler data */
285 struct SCIP_ConshdlrData
286 {
287  CGMIP_MIPDATA* mipdata; /**< data of separating sub-MIP */
288 };
289 
290 /* temporary forward declaration */
291 static
293  SCIP* scip, /**< original scip */
294  SCIP_SEPA* sepa, /**< separator */
295  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
296  SCIP_SEPADATA* sepadata, /**< separator data */
297  SCIP_SOL* sol, /**< current solution for sub-MIP */
298  SCIP_Bool usefrac, /**< use fractional value of multipliers */
299  SCIP_Real* cutcoefs, /**< coefficients of the cut */
300  SCIP_Real* cutrhs, /**< rhs of the cut */
301  SCIP_Bool* localrowsused, /**< pointer to store whether local rows were used in summation */
302  SCIP_Bool* localboundsused, /**< pointer to store whether local bounds were used in summation */
303  int * cutrank, /**< pointer to store the cut rank */
304  SCIP_Bool* success /**< whether we produced a valid cut */
305  );
306 
307 /** check whether cut corresponding to solution is violated */
308 static
310  SCIP* scip, /**< SCIP data structure */
311  CGMIP_MIPDATA* mipdata, /**< data of separating sub-MIP */
312  SCIP_SOL* sol, /**< solution to be checked */
313  SCIP_Bool* violated /**< pointer to store if the cut is violated */
314  )
315 {
316  SCIP_Real cutsqrnorm = 0.0;
317  SCIP* subscip;
318  SCIP_Real act;
319  SCIP_Real norm;
320  SCIP_Real val;
321  SCIP_VAR* var;
322  SCIP_Real rhs;
323  unsigned int j;
324  int len = 0;
325 
326  assert( mipdata != NULL );
327  subscip = mipdata->subscip;
328  assert( subscip != NULL );
329  assert( violated != NULL );
330 
331  /* initialize activity and norm */
332  act = 0.0;
333  norm = 1.0;
334  *violated = FALSE;
335 
336  /* compute activity and norm */
337  if ( mipdata->conshdlrusenorm )
338  {
339  /* check whether we should compute the full cut and then compute the norm */
340  if ( mipdata->conshdlrfullnorm )
341  {
342  SCIP_Real* cutcoefs;
343  SCIP_Bool localrowsused;
344  SCIP_Bool localboundsused;
345  SCIP_Bool success;
346  SCIP_VAR** vars;
347  int cutrank = 0;
348  int nvars;
349 
350  /* get data */
351  SCIP_CALL( SCIPgetVarsData(mipdata->scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
352  assert(nvars >= 0);
353  SCIP_CALL( SCIPallocBufferArray(scip, &cutcoefs, nvars) );
354 
355  /* compute coefficients */
356  SCIP_CALL( computeCut(mipdata->scip, mipdata->sepa, mipdata, mipdata->sepadata, sol, TRUE, cutcoefs, &rhs, &localrowsused, &localboundsused, &cutrank, &success) );
357 
358  /* try again if cut was not valid */
359  if ( ! success )
360  {
361  SCIP_CALL( computeCut(mipdata->scip, mipdata->sepa, mipdata, mipdata->sepadata, sol, FALSE,
362  cutcoefs, &rhs, &localrowsused, &localboundsused, &cutrank, &success) );
363 
364  if ( ! success )
365  return SCIP_OKAY;
366  }
367 
368 #ifdef SCIP_MORE_DEBUG
369  for (j = 0; j < (unsigned int) nvars; ++j)
370  {
371  if ( ! SCIPisZero(scip, cutcoefs[j]) )
372  SCIPinfoMessage(scip, NULL, "+ %f x%d", cutcoefs[j], j);
373  }
374  SCIPinfoMessage(scip, NULL, "\n");
375 #endif
376 
377  /* compute activity and Euclidean norm (todo: use arbitrary norm) */
378  cutsqrnorm = 0.0;
379  for (j = 0; j < (unsigned int) nvars; ++j)
380  {
381  if ( ! SCIPisZero(scip, cutcoefs[j]) )
382  {
383  act += cutcoefs[j] * SCIPvarGetLPSol(vars[j]);
384  cutsqrnorm += SQR(cutcoefs[j]);
385  }
386  }
387  norm = SQRT(cutsqrnorm);
388 
389  SCIPfreeBufferArray(scip, &cutcoefs);
390  } /*lint !e438*/
391  else
392  {
393  switch ( mipdata->normtype )
394  {
395  case 'e':
396  cutsqrnorm = 0.0;
397  for (j = 0; j < mipdata->ncols; ++j)
398  {
399  var = mipdata->alpha[j];
400  if ( var == NULL )
401  continue;
402 
403  val = SCIPgetSolVal(subscip, sol, var);
404  if ( !SCIPisZero(scip, val) )
405  {
406  act += val * SCIPvarGetObj(var);
407  cutsqrnorm += SQR(val);
408  }
409  }
410  norm = SQRT(cutsqrnorm);
411  break;
412  case 'm':
413  for (j = 0; j < mipdata->ncols; ++j)
414  {
415  var = mipdata->alpha[j];
416  if ( var == NULL )
417  continue;
418 
419  val = SCIPgetSolVal(subscip, sol, var);
420  if ( !SCIPisZero(scip, val) )
421  {
422  act += val * SCIPvarGetObj(var);
423  if ( REALABS(val) > norm )
424  norm = REALABS(val);
425  }
426  }
427  break;
428  case 's':
429  for (j = 0; j < mipdata->ncols; ++j)
430  {
431  var = mipdata->alpha[j];
432  if ( var == NULL )
433  continue;
434 
435  val = SCIPgetSolVal(subscip, sol, var);
436  if ( !SCIPisZero(scip, val) )
437  {
438  act += val * SCIPvarGetObj(var);
439  norm += REALABS(val);
440  }
441  }
442  break;
443  case 'd':
444  for (j = 0; j < mipdata->ncols; ++j)
445  {
446  var = mipdata->alpha[j];
447  if ( var == NULL )
448  continue;
449 
450  val = SCIPgetSolVal(subscip, sol, var);
451  if ( !SCIPisZero(scip, val) )
452  {
453  act += val * SCIPvarGetObj(var);
454  ++len;
455  }
456  }
457  if ( len > 0 )
458  norm = 1.0;
459  break;
460  default:
461  SCIPerrorMessage("invalid efficacy norm parameter '%c'\n", mipdata->normtype);
462  return SCIP_INVALIDDATA;
463  }
464  /* get rhs */
465  rhs = SCIPgetSolVal(subscip, sol, mipdata->beta);
466  }
467 
468  /* if norm is 0, the cut is trivial */
469  if ( SCIPisZero(subscip, norm) )
470  return SCIP_OKAY;
471  }
472  else
473  {
474  for (j = 0; j < mipdata->ncols; ++j)
475  {
476  var = mipdata->alpha[j];
477  if ( var == NULL )
478  continue;
479 
480  val = SCIPgetSolVal(subscip, sol, var);
481  if ( !SCIPisZero(subscip, val) )
482  act += SCIPvarGetObj(var) * val;
483  }
484 
485  /* get rhs */
486  rhs = SCIPgetSolVal(subscip, sol, mipdata->beta);
487  }
488 
489 #ifdef SCIP_DEBUG
490  if ( SCIPisEfficacious(subscip, (act - rhs)/norm) )
491  {
492  SCIPdebugMsg(scip, "Violated cut from solution - act: %f, rhs: %f, norm: %f, eff.: %f\n", act, rhs, norm, (act-rhs)/norm);
493  }
494  else
495  {
496  SCIPdebugMsg(scip, "Rejected cut from solution - act: %f, rhs: %f, norm: %f, eff.: %f\n", act, rhs, norm, (act-rhs)/norm);
497  }
498 #endif
499 
500  *violated = SCIPisEfficacious(subscip, (act - rhs)/norm);
501 
502  return SCIP_OKAY;
503 }
504 
505 
506 /** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
507 static
508 SCIP_DECL_CONSFREE(consFreeViolatedCuts)
509 { /*lint --e{715}*/
510  SCIP_CONSHDLRDATA* conshdlrdata;
511 
512  assert( scip != NULL );
513  assert( conshdlr != NULL );
514  conshdlrdata = SCIPconshdlrGetData(conshdlr);
515  assert( conshdlrdata != NULL );
516 
517  SCIPfreeBlockMemory(scip, &conshdlrdata);
518 
519  return SCIP_OKAY;
520 }
521 
522 
523 /** constraint enforcing method of constraint handler for LP solutions */
524 static
525 SCIP_DECL_CONSENFOLP(consEnfolpViolatedCuts)
526 { /*lint --e{715}*/
527  SCIP_CONSHDLRDATA* conshdlrdata;
528  SCIP_Bool violated;
529 
530  assert( scip != NULL );
531  assert( conshdlr != NULL );
532  assert( result != NULL );
533 
534  assert( SCIPgetNLPBranchCands(scip) == 0 );
535 
536  conshdlrdata = SCIPconshdlrGetData(conshdlr);
537  assert( conshdlrdata != NULL );
538 
539  SCIP_CALL( solCutIsViolated(scip, conshdlrdata->mipdata, NULL, &violated) );
540 
541  if ( violated )
542  *result = SCIP_FEASIBLE;
543  else
544  *result = SCIP_CUTOFF; /* cutoff, since all integer variables are integer, but the solution is not feasible */
545 
546  return SCIP_OKAY;
547 }
548 
549 
550 /** constraint enforcing method of constraint handler for pseudo solutions */
551 static
552 SCIP_DECL_CONSENFOPS(consEnfopsViolatedCuts)
553 { /*lint --e{715}*/
554  assert( result != NULL );
555 
556  /* this function should better not be called, since we need an LP solution for the sub-MIP to
557  * make sense, because of the multiplier variables. We therefore return SCIP_FEASIBLE. */
558  *result = SCIP_FEASIBLE;
559 
560  return SCIP_OKAY;
561 }
562 
563 
564 /** feasibility check method of constraint handler for integral solutions */
565 static
566 SCIP_DECL_CONSCHECK(consCheckViolatedCuts)
567 { /*lint --e{715}*/
568  SCIP_CONSHDLRDATA* conshdlrdata;
569  SCIP_Bool violated;
570 
571  assert( scip != NULL );
572  assert( conshdlr != NULL );
573  assert( sol != NULL );
574  assert( result != NULL );
575 
576  conshdlrdata = SCIPconshdlrGetData(conshdlr);
577  assert( conshdlrdata != NULL );
578 
579  SCIP_CALL( solCutIsViolated(scip, conshdlrdata->mipdata, sol, &violated) );
580 
581  if ( violated )
582  *result = SCIP_FEASIBLE;
583  else
584  *result = SCIP_INFEASIBLE;
585 
586  return SCIP_OKAY;
587 }
588 
589 
590 /** variable rounding lock method of constraint handler */
591 static
592 SCIP_DECL_CONSLOCK(consLockViolatedCuts)
593 { /*lint --e{715}*/
594  /* do not lock variables */
595  return SCIP_OKAY;
596 }
597 
598 
599 /** creates the violated CG-cut constraint handler and includes it in SCIP */
600 static
602  SCIP* scip, /**< SCIP data structure */
603  CGMIP_MIPDATA* mipdata /**< data of separating sub-MIP */
604  )
605 {
606  SCIP_CONSHDLRDATA* conshdlrdata;
607  SCIP_CONSHDLR* conshdlr;
608 
609  SCIP_CALL( SCIPallocBlockMemory(scip, &conshdlrdata) );
610  conshdlrdata->mipdata = mipdata;
611 
612  /* include constraint handler */
614  -1000000, -1000000, 100, FALSE,
615  consEnfolpViolatedCuts, consEnfopsViolatedCuts, consCheckViolatedCuts, consLockViolatedCuts,
616  conshdlrdata) );
617 
618  assert(conshdlr != NULL);
619 
620  /* set non-fundamental callbacks via specific setter functions */
621  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, consFreeViolatedCuts) );
622 
623  return SCIP_OKAY;
624 }
625 
626 
627 /*
628  * local methods
629  */
630 
631 
632 /** stores nonzero elements of dense coefficient vector as sparse vector and calculates activity and norm
633  *
634  * copied from sepa_gomory.c
635  */
636 static
638  SCIP* scip, /**< SCIP data structure */
639  int nvars, /**< number of problem variables */
640  SCIP_Real* cutcoefs, /**< dense coefficient vector */
641  SCIP_Real* varsolvals, /**< dense variable LP solution vector */
642  char normtype, /**< type of norm to use for efficacy norm calculation */
643  int* cutinds, /**< array to store variables of sparse cut vector */
644  SCIP_Real* cutvals, /**< array to store coefficients of sparse cut vector */
645  int* cutlen, /**< pointer to store number of nonzero entries in cut */
646  SCIP_Real* cutact, /**< pointer to store activity of cut */
647  SCIP_Real* cutnorm /**< pointer to store norm of cut vector */
648  )
649 {
650  SCIP_Real val;
651  SCIP_Real cutsqrnorm;
652  SCIP_Real act;
653  SCIP_Real norm;
654  int len;
655  int v;
656 
657  assert( nvars == 0 || cutcoefs != NULL );
658  assert( nvars == 0 || varsolvals != NULL );
659  assert( cutinds != NULL );
660  assert( cutvals != NULL );
661  assert( cutlen != NULL );
662  assert( cutact != NULL );
663  assert( cutnorm != NULL );
664 
665  len = 0;
666  act = 0.0;
667  norm = 0.0;
668  switch ( normtype )
669  {
670  case 'e':
671  cutsqrnorm = 0.0;
672  for (v = 0; v < nvars; ++v)
673  {
674  val = cutcoefs[v];
675  if ( !SCIPisZero(scip, val) )
676  {
677  act += val * varsolvals[v];
678  cutsqrnorm += SQR(val);
679  cutinds[len] = v;
680  cutvals[len++] = val;
681  }
682  }
683  norm = SQRT(cutsqrnorm);
684  break;
685  case 'm':
686  for (v = 0; v < nvars; ++v)
687  {
688  val = cutcoefs[v];
689  if ( !SCIPisZero(scip, val) )
690  {
691  act += val * varsolvals[v];
692  if ( REALABS(val) > norm )
693  norm = REALABS(val);
694  cutinds[len] = v;
695  cutvals[len++] = val;
696  }
697  }
698  break;
699  case 's':
700  for (v = 0; v < nvars; ++v)
701  {
702  val = cutcoefs[v];
703  if ( !SCIPisZero(scip, val) )
704  {
705  act += val * varsolvals[v];
706  norm += REALABS(val);
707  cutinds[len] = v;
708  cutvals[len++] = val;
709  }
710  }
711  break;
712  case 'd':
713  for (v = 0; v < nvars; ++v)
714  {
715  val = cutcoefs[v];
716  if ( !SCIPisZero(scip, val) )
717  {
718  act += val * varsolvals[v];
719  cutinds[len] = v;
720  cutvals[len++] = val;
721  }
722  }
723  if ( len > 0 )
724  norm = 1.0;
725  break;
726  default:
727  SCIPerrorMessage("invalid efficacy norm parameter '%c'\n", normtype);
728  return SCIP_INVALIDDATA;
729  }
730 
731  *cutlen = len;
732  *cutact = act;
733  *cutnorm = norm;
734 
735  return SCIP_OKAY;
736 }
737 
738 
739 /** Compute lhs/rhs for transformed column
740  *
741  * Consider a variable \f$x_j\f$ and some row of the original system:
742  * \f[
743  * \gamma \leq a^T x \leq \delta, \quad \ell_j \leq x_j \leq u_j.
744  * \f]
745  * We perform the transformation
746  * \f[
747  * x_i' = \left\{
748  * \begin{array}{ll}
749  * s + \frac{1}{\sigma}\, x_j & \mbox{if }i = j\\
750  * x_i & \mbox{otherwise},
751  * \end{array}
752  * \right.
753  * \f]
754  * where \f$s\f$ is the offset value and \f$\sigma\f$ is a scaling factor. The new system is
755  * \f[
756  * \gamma + \sigma\, a_j\,s \leq \sum_{i \neq j} a_i\, x_i' + \sigma a_j\, x_j' \leq \delta + \sigma\, a_j\, s
757  * \f]
758  * with bounds
759  * \f[
760  * \frac{1}{\sigma} \ell_j + s \leq x_j' \leq \frac{1}{\sigma} u_j + s, \qquad \mbox{ if }\sigma > 0
761  * \f]
762  * and
763  * \f[
764  * \frac{1}{\sigma} u_j + s \leq x_j' \leq \frac{1}{\sigma} \ell_j + s, \qquad \mbox{ if }\sigma < 0.
765  * \f]
766  *
767  * This can be used as follows:
768  *
769  * - If \f$x_j \geq \ell_j\f$ has a (nonzero) lower bound, one can use \f$s = -\ell_j\f$, \f$\sigma = 1\f$,
770  * and obtain \f$\gamma - a_j\,\ell_j \leq a^T x' \leq \delta - a_j\,\ell_j\f$, \f$0 \leq x_j' \leq u_j - \ell_j\f$.
771  *
772  * - If \f$x_j \leq u_j\f$ has a (nonzero) upper bound, one can use \f$s = u_j\f$, \f$\sigma = -1\f$,
773  * and obtain \f$\gamma - a_j\,u_j \leq \sum_{i \neq j} a_i\, x_i' - a_j\, x_j' \leq \delta - a_j\, u_j\f$,
774  * \f$0 \leq x_j' \leq u_j - \ell_j\f$.
775  */
776 static
778  SCIP* scip, /**< SCIP data structure */
779  SCIP_SEPADATA* sepadata, /**< separator data */
780  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
781  SCIP_COL* col, /**< column that should be complemented */
782  SCIP_Real offset, /**< offset by which column should be shifted */
783  SCIP_Real sigma, /**< scaling factor */
784  SCIP_Real* lhs, /**< array of lhs of rows */
785  SCIP_Real* rhs, /**< array rhs of rows */
786  SCIP_Real* lb, /**< pointer to lb of column */
787  SCIP_Real* ub, /**< pointer to ub of column */
788  SCIP_Real* primsol /**< pointer to solution value */
789  )
790 {
791  SCIP_ROW** colrows;
792  SCIP_Real* colvals;
793  int pos, i;
794 
795  assert( scip != NULL );
796  assert( lhs != NULL );
797  assert( rhs != NULL );
798  assert( col != NULL );
799 
800  colrows = SCIPcolGetRows(col);
801  colvals = SCIPcolGetVals(col);
802  assert( SCIPcolGetNLPNonz(col) == 0 || colrows != NULL );
803  assert( SCIPcolGetNLPNonz(col) == 0 || colvals != NULL );
804  assert( ! SCIPisZero(scip, sigma) );
805 
806  /* loop through rows that contain column */
807  for (i = 0; i < SCIPcolGetNLPNonz(col); ++i)
808  {
809  SCIP_ROW* row;
810 
811  row = colrows[i];
812  assert( row != NULL );
813 
814  /* skip modifiable rows and local rows, unless allowed */
815  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && !sepadata->allowlocal) )
816  continue;
817 
818  pos = SCIProwGetLPPos(row);
819  assert( 0 <= pos && pos < (int) mipdata->nrows );
820 
821  assert( ! SCIPisInfinity(scip, lhs[pos]) );
822  if ( ! SCIPisInfinity(scip, -lhs[pos]) )
823  lhs[pos] += sigma * colvals[i] * offset;
824 
825  assert( ! SCIPisInfinity(scip, -rhs[pos]) );
826  if ( ! SCIPisInfinity(scip, rhs[pos]) )
827  rhs[pos] += sigma * colvals[i] * offset;
828  }
829 
830  /* check objective function */
831  if ( sepadata->useobjub || sepadata->useobjlb )
832  {
833  assert( SCIPisEQ(scip, SCIPcolGetObj(col), SCIPvarGetObj(SCIPcolGetVar(col))) );
834  assert( mipdata->ntotalrows == mipdata->nrows + 1 );
835 
836  if ( ! SCIPisInfinity(scip, -lhs[mipdata->nrows]) )
837  lhs[mipdata->nrows] += sigma * SCIPcolGetObj(col) * offset;
838 
839  if ( ! SCIPisInfinity(scip, rhs[mipdata->nrows]) )
840  rhs[mipdata->nrows] += sigma * SCIPcolGetObj(col) * offset;
841  }
842 
843  /* correct lower and upper bounds and solution */
844  if ( SCIPisNegative(scip, sigma) )
845  {
846  SCIP_Real l;
847 
848  assert( ! SCIPisInfinity(scip, -*ub) );
849  if ( ! SCIPisInfinity(scip, *ub) )
850  l = *ub/sigma + offset;
851  else
852  l = -SCIPinfinity(scip);
853 
854  assert( ! SCIPisInfinity(scip, *lb) );
855  if ( ! SCIPisInfinity(scip, -*lb) )
856  *ub = *lb/sigma + offset;
857  else
858  *ub = SCIPinfinity(scip);
859  *lb = l;
860  }
861  else
862  {
863  assert( ! SCIPisInfinity(scip, *lb) );
864  if ( ! SCIPisInfinity(scip, -*lb) )
865  *lb = *lb/sigma + offset;
866  assert( ! SCIPisInfinity(scip, -*ub) );
867  if ( ! SCIPisInfinity(scip, *ub) )
868  *ub = *ub/sigma + offset;
869  }
870  *primsol = *primsol/sigma + offset;
871 
872  return SCIP_OKAY;
873 }
874 
875 
876 /** compute objective coefficient for rows that are weighted by size
877  *
878  * The objective is computed by multiplying a default value by
879  * \f[
880  * 1 - (r_{\mbox{max}} - r) \frac{1 - a}{r_{\mbox{max}} - r_{\mbox{min}}},
881  * \f]
882  * where \f$r\f$ is the size of the current row, \f$a \in [0,1]\f$ is a parameter, and \f$r_{\mbox{max}}\f$ and
883  * \f$r_{\mbox{min}}\f$ are the maximal and minimal size of a row, respectively.
884  *
885  * Thus, if \f$r = r_{\mbox{max}}\f$, we get 1 and if \f$r = r_{\mbox{min}}\f$, we get \f$a\f$.
886  */
887 static
889  int rowsize, /**< size of current row */
890  int minrowsize, /**< maximal size of rows */
891  int maxrowsize /**< minimal size of rows */
892  )
893 {
894  SCIP_Real a;
895 
896  assert( maxrowsize > 0 );
897  assert( minrowsize < INT_MAX );
898  assert( minrowsize <= maxrowsize );
899  assert( minrowsize <= rowsize && rowsize <= maxrowsize );
900 
901  if ( minrowsize == maxrowsize )
902  return 1.0;
903 
904  a = (1.0 - OBJWEIGHTRANGE)/((SCIP_Real) (maxrowsize - minrowsize));
905 
906  return 1.0 - a * ((SCIP_Real) (maxrowsize - rowsize));
907 }
908 
909 
910 /** Creates a subscip representing the separating MIP.
911  *
912  * Let the constraints of the original MIP be of the following form:
913  * \f[
914  * \begin{array}{l@{\;}ll}
915  * a \leq A x + & C r & \leq b\\
916  * \ell \leq x & & \leq u\\
917  * c \leq & r & \leq d\\
918  * x \in Z^n.
919  * \end{array}
920  * \f]
921  * Here, some of the bounds may have value \f$\infty\f$ or \f$-\infty\f$. Written in
922  * \f$\leq\f$-form this becomes:
923  * \f[
924  * \begin{array}{r@{\;}l}
925  * \tilde{A} x + \tilde{C} r & \leq \tilde{b}\\
926  * -x & \leq -\ell\\
927  * x & \leq u\\
928  * -r & \leq -c\\
929  * r & \leq d\\
930  * x \in Z^n,
931  * \end{array}
932  * \f]
933  * where we use
934  * \f[
935  * \tilde{A} =
936  * \left[
937  * \begin{array}{r}
938  * -A \\
939  * A
940  * \end{array}
941  * \right],
942  * \quad
943  * \tilde{C} =
944  * \left[
945  * \begin{array}{r}
946  * - C\\
947  * C
948  * \end{array}
949  * \right]
950  * \qquad\mbox{ and }\qquad
951  * \tilde{b} =
952  * \left[
953  * \begin{array}{r}
954  * -a\\
955  * b
956  * \end{array}
957  * \right].
958  * \f]
959  * For the moment we assume that \f$c = 0\f$, i.e., the lower bounds on the continuous variables
960  * are 0. To obtain a Chv&aacute;tal-Gomory cut we have to find nonnegative multipliers \f$y\f$,
961  * \f$\underline{z}\f$, and \f$\overline{z}\f$ such that
962  * \f[
963  * y^T \tilde{A} - \underline{z}^T + \overline{z}^T \in Z \qquad\mbox{ and }\qquad
964  * y^T \tilde{C} \geq 0.
965  * \f]
966  * Note that we use zero multipliers for the bounds on the continuous variables \f$r\f$. Moreover,
967  * if some bounds are infinity, the corresponding multipliers are assumed to be 0. From these
968  * conditions, we obtain
969  * \f[
970  * (y^T \tilde{A} - \underline{z}^T + \overline{z}^T)\, x +
971  * y^T \tilde{C} \, r \leq
972  * y^T \tilde{b} - \underline{z}^T \ell + \overline{z}^T u.
973  * \f]
974  * Because \f$r \geq 0\f$, we can ignore the term \f$y^T \tilde{C} \, r \geq 0\f$ and obtain the
975  * following cut:
976  * \f[
977  * (y^T \tilde{A} - \underline{z}^T + \overline{z}^T )\, x \leq
978  * \lfloor y^T \tilde{b} - \underline{z}^T \ell + \overline{z}^T u \rfloor.
979  * \f]
980  * Assume that \f$\ell = 0\f$ for the meantime. Then the cut can be written as:
981  * \f[
982  * \lfloor y^T \tilde{A} + \overline{z}^T \rfloor \, x \leq
983  * \lfloor y^T \tilde{b} + \overline{z}^T u \rfloor.
984  * \f]
985  *
986  * Following Fischetti and Lodi [2005], let \f$(x^*,r^*)\f$ be a fractional solution of the above
987  * original system. The separating MIP created below is
988  * \f[
989  * \begin{array}{rlr@{\;}l}
990  * \max & (x^*)^T \alpha - \beta - w^T y \\
991  * & f = \tilde{A}^T y + \overline{z} - \alpha \\
992  * & \tilde{f} = \tilde{b}^T y + u^T \overline{z} - \beta\\
993  * & \tilde{C}^T y \geq 0\\
994  * & 0 \leq f \leq 1 - \epsilon \\
995  * & 0 \leq \tilde{f} \leq 1 - \epsilon\\
996  * & 0 \leq y, \overline{z} \leq 1 - \epsilon.\\
997  * & \alpha \in Z^m, \beta \in Z.
998  * \end{array}
999  * \f]
1000  * Here, \f$w\f$ is a weight vector; it's idea is to make the sum over all components of \f$y\f$ as
1001  * small as possible, in order to generate sparse cuts.
1002  *
1003  * We perform the following additional computations:
1004  *
1005  * - If the lower bounds on \f$x_i\f$ or \f$r_j\f$ are finite, we shift the variable to have a zero
1006  * lower bound, i.e., we replace it by \f$x_i - \ell_i\f$ (or \f$r_j - u_j\f$). This is helpful in
1007  * several ways: As seen above, the resulting inequalities/formulations simplify. Moreover, it
1008  * allows to drop a variable if \f$x^*_i = 0\f$, see the next comment. If the lower bounds are not
1009  * finite, but the upper bounds are finite, we can complement the variable. If the variables are
1010  * free, the above formulation changes as follows: For free continuous variables, we require
1011  * \f$\tilde{C}^T y = 0\f$. For a free integer variable \f$x_j\f$ (which rarely occurs in
1012  * practice), we require \f$f_j = 0\f$, i.e., we force that \f$(\tilde{A}^T y + \overline{z})_j =
1013  * \alpha_j\f$.
1014  *
1015  * - If \f$x^*_j = 0 = \ell_j\f$ (after the above preprocessing), we drop variable \f$\alpha_j\f$
1016  * from the formulation. Let \f$(\alpha^*, \beta^*, y^*, \overline{z}^*)\f$ be an
1017  * optimal solution to the separating MIP. Then we can compute \f$\alpha_j =
1018  * \lfloor(\tilde{A}_j^T y^* + \overline{z}^*)\rfloor\f$.
1019  *
1020  * - If \f$x^*_i = u_i\f$, we complement the variable and drop it from the formulation, since the
1021  * lower bound is 0 afterwards.
1022  *
1023  * - If a variable has been shifted or complemented, we have to recompute \f$\beta\f$ with the
1024  * original lhs/rhs.
1025  *
1026  * - If a continuous variable \f$r_j\f$ is free, we have to force equality for the corresponding components in
1027  * \f$y^T \tilde{C} \, r \geq 0\f$.
1028  *
1029  * - If an integer variable \f$x_i\f$ is free, we are not allowed to round the cut down. In this
1030  * case, the combintation of rows and bounds has to be integral. We force this by requiring that
1031  * \f$f_i = 0\f$.
1032  *
1033  * - If @p contconvert is true, some integral variables are randomly treated as if they were
1034  * continuous. This has the effect that in the resulting cut the corresponding coefficient has
1035  * value 0. This makes the cuts more sparse. Moreover, the separation problems should become
1036  * easier.
1037  *
1038  * - If required, i.e., parameter @p primalseparation is true, we force a primal separation step. For
1039  * this we require that the cut is tight at the currently best solution. To get reliable solutions
1040  * we relax equality by EPSILONVALUE.
1041  *
1042  * - If required (via parameters @p useobjub or @p useobjlb), we add a row corresponding to the objective function with
1043  * respect to the current lower and upper bounds.
1044  */
1045 static
1047  SCIP* origscip, /**< SCIP data structure */
1048  SCIP_SEPA* sepa, /**< separator */
1049  SCIP_SEPADATA* sepadata, /**< separator data */
1050  CGMIP_MIPDATA* mipdata /**< data for sub-MIP */
1051  )
1052 {
1053  SCIP* subscip;
1054  SCIP_COL** cols;
1055  SCIP_ROW** rows;
1056  SCIP_Real* lhs;
1057  SCIP_Real* rhs;
1058  SCIP_Real* lb;
1059  SCIP_Real* ub;
1060  SCIP_Real* primsol;
1061  SCIP_Real multvarub;
1062 
1063  unsigned int cnt;
1064  unsigned int ucnt;
1065  unsigned int nshifted;
1066  unsigned int ncomplemented;
1067 #ifndef NDEBUG
1068  unsigned int ncontconverted = 0;
1069  unsigned int nintconverted = 0;
1070 #endif
1071  unsigned int nlbounds;
1072  unsigned int nubounds;
1073 
1074  SCIP_VAR** consvars;
1075  SCIP_Real* consvals;
1076  SCIP_CONS* cons;
1077  int nconsvars;
1078  char name[SCIP_MAXSTRLEN];
1079 
1080  int ncols;
1081  int nrows;
1082  int ntotalrows;
1083  int maxrowsize = 0;
1084  int minrowsize = INT_MAX;
1085  int i, j;
1086 
1087  assert( origscip != NULL );
1088  assert( sepadata != NULL );
1089 
1090  assert( mipdata->subscip == NULL );
1091 
1092  SCIP_CALL( SCIPgetLPColsData(origscip, &cols, &ncols) );
1093  SCIP_CALL( SCIPgetLPRowsData(origscip, &rows, &nrows) );
1094  assert( ncols > 0 && nrows > 0 );
1095 
1096  mipdata->m = 0;
1097  mipdata->n = 0;
1098  mipdata->nrows = (unsigned int) nrows;
1099  mipdata->ncols = (unsigned int) ncols;
1100  mipdata->ntotalrows = mipdata->nrows;
1101 
1102  if ( sepadata->useobjub || sepadata->useobjlb )
1103  mipdata->ntotalrows = mipdata->nrows + 1;
1104 
1105  assert(mipdata->ntotalrows <= INT_MAX);
1106  ntotalrows = (int) mipdata->ntotalrows;
1107 
1108  /* copy value */
1109  mipdata->conshdlrusenorm = sepadata->conshdlrusenorm;
1110 
1111  /* create subscip */
1112  SCIP_CALL( SCIPcreate( &(mipdata->subscip) ) );
1113  subscip = mipdata->subscip;
1115 
1116  /* add violation constraint handler if requested */
1117  if ( sepadata->addviolconshdlr )
1118  {
1119  SCIP_CALL( SCIPincludeConshdlrViolatedCut(subscip, mipdata) );
1120  }
1121 
1122  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "sepa_cgmip separating MIP (%s)", SCIPgetProbName(origscip));
1123  SCIP_CALL( SCIPcreateProb(subscip, name, NULL, NULL , NULL , NULL , NULL , NULL , NULL) );
1125 
1126  /* alloc memory for subscipdata elements */
1127  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->alpha), ncols) );
1128  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->fracalpha), ncols) );
1129  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->coltype), ncols) );
1130  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->iscomplemented), ncols) );
1131  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->isshifted), ncols) );
1132  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->ylhs), ntotalrows) );
1133  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->yrhs), ntotalrows) );
1134  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->z), 2*ncols) );
1135  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->lhs), ntotalrows) );
1136  SCIP_CALL( SCIPallocBlockMemoryArray(origscip, &(mipdata->rhs), ntotalrows) );
1137  lhs = mipdata->lhs;
1138  rhs = mipdata->rhs;
1139 
1140  /* get temporary storage */
1141  SCIP_CALL( SCIPallocBufferArray(origscip, &lb, ncols) );
1142  SCIP_CALL( SCIPallocBufferArray(origscip, &ub, ncols) );
1143  SCIP_CALL( SCIPallocBufferArray(origscip, &primsol, ncols) );
1144 
1145  /* store lhs/rhs for complementing (see below) and compute maximal nonzeros of candidate rows */
1146  for (i = 0; i < nrows; ++i)
1147  {
1148  SCIP_Real val;
1149  SCIP_ROW* row;
1150 
1151  row = rows[i];
1152  assert( row != NULL );
1153 
1154  val = SCIProwGetLhs(row) - SCIProwGetConstant(row);
1155  if ( SCIProwIsIntegral(row) )
1156  val = SCIPfeasCeil(origscip, val); /* row is integral: round left hand side up */
1157  lhs[i] = val;
1158 
1159  val = SCIProwGetRhs(row) - SCIProwGetConstant(row);
1160  if ( SCIProwIsIntegral(row) )
1161  val = SCIPfeasFloor(origscip, val); /* row is integral: round right hand side down */
1162  rhs[i] = val;
1163 
1164  /* skip modifiable rows and local rows, unless allowed */
1165  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && !sepadata->allowlocal) )
1166  continue;
1167 
1168  /* skip rows that not have been active for a longer time */
1169  if ( ! sepadata->onlyactiverows && sepadata->maxrowage > 0 && SCIProwGetAge(row) > sepadata->maxrowage )
1170  continue;
1171 
1172  /* check whether we want to skip cuts produced by the CGMIP separator */
1173  if ( sepadata->onlyrankone )
1174  {
1175  if ( SCIProwGetOriginSepa(row) == sepa )
1176  continue;
1177  }
1178 
1179  /* determine maximal row size: */
1180  val = SCIPgetRowLPActivity(origscip, row);
1181  if ( ! SCIPisInfinity(origscip, REALABS(lhs[i])) )
1182  {
1183  if ( ! sepadata->onlyactiverows || SCIPisFeasEQ(origscip, val, SCIProwGetLhs(row)) )
1184  {
1185  if ( SCIProwGetNLPNonz(row) > maxrowsize )
1186  maxrowsize = SCIProwGetNLPNonz(row);
1187  if ( SCIProwGetNLPNonz(row) < minrowsize )
1188  minrowsize = SCIProwGetNLPNonz(row);
1189  }
1190  }
1191  else
1192  {
1193  if ( ! SCIPisInfinity(origscip, rhs[i]) )
1194  {
1195  if ( ! sepadata->onlyactiverows || SCIPisFeasEQ(origscip, val, SCIProwGetRhs(row)) )
1196  {
1197  if ( SCIProwGetNLPNonz(row) > maxrowsize )
1198  maxrowsize = SCIProwGetNLPNonz(row);
1199  if ( SCIProwGetNLPNonz(row) < minrowsize )
1200  minrowsize = SCIProwGetNLPNonz(row);
1201  }
1202  }
1203  }
1204  }
1205  assert( maxrowsize > 0 );
1206  assert( minrowsize < INT_MAX );
1207 
1208  /* add cuts for objective function if required */
1209  if ( sepadata->useobjub )
1210  {
1211  assert( mipdata->ntotalrows == mipdata->nrows + 1 );
1212  rhs[mipdata->nrows] = SCIPgetUpperbound(origscip);
1213  assert( ! SCIPisObjIntegral(origscip) || SCIPisFeasIntegral(origscip, SCIPgetUpperbound(origscip)) );
1214 
1215  if ( ! SCIPisInfinity(origscip, SCIPgetUpperbound(origscip)) && SCIPgetNObjVars(origscip) > maxrowsize )
1216  maxrowsize = SCIPgetNObjVars(origscip);
1217  if ( ! SCIPisInfinity(origscip, SCIPgetUpperbound(origscip)) && SCIPgetNObjVars(origscip) < minrowsize )
1218  minrowsize = SCIPgetNObjVars(origscip);
1219  }
1220  if ( sepadata->useobjlb )
1221  {
1222  assert( mipdata->ntotalrows == mipdata->nrows + 1 );
1223 
1224  if ( SCIPisObjIntegral(origscip) )
1225  lhs[mipdata->nrows] = SCIPfeasCeil(origscip, SCIPgetLowerbound(origscip));
1226  else
1227  lhs[mipdata->nrows] = SCIPgetLowerbound(origscip);
1228 
1229  if ( ! SCIPisInfinity(origscip, -SCIPgetLowerbound(origscip)) && SCIPgetNObjVars(origscip) > maxrowsize )
1230  maxrowsize = SCIPgetNObjVars(origscip);
1231  if ( ! SCIPisInfinity(origscip, -SCIPgetLowerbound(origscip)) && SCIPgetNObjVars(origscip) < minrowsize )
1232  minrowsize = SCIPgetNObjVars(origscip);
1233  }
1234 
1235  /* store lb/ub for complementing and perform preprocessing */
1236  nshifted = 0;
1237  ncomplemented = 0;
1238  nlbounds = 0;
1239  nubounds = 0;
1240  for (j = 0; j < ncols; ++j)
1241  {
1242  SCIP_COL* col;
1243  SCIP_VAR* var;
1244 
1245  col = cols[j];
1246  assert( col != NULL );
1247  var = SCIPcolGetVar(col);
1248  assert( var != NULL );
1249 
1250  primsol[j] = SCIPcolGetPrimsol(col);
1251  assert( SCIPisEQ(origscip, SCIPgetVarSol(origscip, var), primsol[j]) );
1252 
1253  lb[j] = SCIPvarGetLbGlobal(var);
1254  assert( SCIPisEQ(origscip, SCIPvarGetLbLocal(var), SCIPcolGetLb(col)) );
1255 
1256  /* if allowed, try to use stronger local bound */
1257  if ( sepadata->allowlocal && SCIPisGT(origscip, SCIPvarGetLbLocal(var), lb[j]) )
1258  lb[j] = SCIPvarGetLbLocal(var);
1259 
1260  ub[j] = SCIPvarGetUbGlobal(var);
1261  assert( SCIPisEQ(origscip, SCIPvarGetUbLocal(var), SCIPcolGetUb(col)) );
1262 
1263  /* if allowed, try to use stronger local bound */
1264  if ( sepadata->allowlocal && SCIPisLT(origscip, SCIPvarGetUbLocal(var), ub[j]) )
1265  ub[j] = SCIPvarGetUbLocal(var);
1266 
1267  mipdata->coltype[j] = colPresent;
1268  mipdata->iscomplemented[j] = FALSE;
1269  mipdata->isshifted[j] = FALSE;
1270 
1271  /* check status of column/variable */
1272  if ( SCIPcolIsIntegral(col) )
1273  {
1274  /* integral variables taking integral values are not interesting - will be substituted out below */
1275  if ( ! SCIPisFeasIntegral(origscip, primsol[j]) )
1276  {
1277  /* possibly convert fractional integral variables to take integral values */
1278  if ( sepadata->intconvert && ncols >= sepadata->intconvmin )
1279  {
1280  /* randomly convert variables */
1281  if ( SCIPrandomGetReal(sepadata->randnumgen, 0.0, 1.0) <= sepadata->intconvfrac )
1282  {
1283  assert( ! SCIPisInfinity(origscip, ub[j]) || ! SCIPisInfinity(origscip, -lb[j]) );
1284 
1285  /* if both bounds are finite, take the closer one */
1286  if ( ! SCIPisInfinity(origscip, ub[j]) && ! SCIPisInfinity(origscip, -lb[j]) )
1287  {
1288  assert( SCIPisFeasIntegral(origscip, ub[j]) );
1289  assert( SCIPisFeasIntegral(origscip, lb[j]) );
1290  assert( SCIPisFeasLT(origscip, primsol[j], ub[j]) );
1291  assert( SCIPisFeasGT(origscip, primsol[j], lb[j]) );
1292  if ( ub[j] - primsol[j] < primsol[j] - lb[j] )
1293  primsol[j] = ub[j];
1294  else
1295  primsol[j] = lb[j];
1296 #ifndef NDEBUG
1297  ++nintconverted;
1298 #endif
1299  }
1300  else
1301  {
1302  /* if only lower bound is finite */
1303  if ( ! SCIPisInfinity(origscip, -lb[j]) )
1304  {
1305  assert( SCIPisFeasIntegral(origscip, lb[j]) );
1306  primsol[j] = lb[j];
1307 #ifndef NDEBUG
1308  ++nintconverted;
1309 #endif
1310  }
1311  else
1312  {
1313  assert( ! SCIPisInfinity(origscip, ub[j]) );
1314  assert( SCIPisFeasIntegral(origscip, ub[j]) );
1315  primsol[j] = ub[j];
1316 #ifndef NDEBUG
1317  ++nintconverted;
1318 #endif
1319  }
1320  }
1321  }
1322  }
1323  }
1324 
1325  /* integral variables taking integral values are not interesting - will be substituted out below */
1326  if ( ! SCIPisFeasIntegral(origscip, primsol[j]) )
1327  {
1328  /* possibly convert integral variables to be continuous */
1329  if ( sepadata->contconvert && ncols >= sepadata->contconvmin )
1330  {
1331  /* randomly convert variables */
1332  if ( SCIPrandomGetReal(sepadata->randnumgen, 0.0, 1.0) <= sepadata->contconvfrac )
1333  {
1334  /* preprocessing is also performed for converted columns */
1335  mipdata->coltype[j] = colConverted;
1336 #ifndef NDEBUG
1337  ++ncontconverted;
1338 #endif
1339  }
1340  }
1341  }
1342  }
1343  else
1344  {
1345  /* detect continuous variables, but perform preprocessing for them */
1346  mipdata->coltype[j] = colContinuous;
1347  }
1348 
1349  /* if integer variable is at its upper bound -> complementing (this also generates a 0 lower bound) */
1350  if ( mipdata->coltype[j] == colPresent && SCIPisFeasEQ(origscip, primsol[j], ub[j]) )
1351  {
1352  assert( ! SCIPisInfinity(origscip, ub[j]) );
1353  SCIP_CALL( transformColumn(origscip, sepadata, mipdata, col, ub[j], -1.0, lhs, rhs, &(lb[j]), &(ub[j]), &(primsol[j])) );
1354  mipdata->iscomplemented[j] = TRUE;
1355  mipdata->coltype[j] = colAtUb;
1356  ++nubounds;
1357  }
1358  else
1359  {
1360  /* if a variable has a finite nonzero lower bound -> shift */
1361  if ( ! SCIPisInfinity(origscip, -lb[j]) )
1362  {
1363  if ( ! SCIPisZero(origscip, lb[j]) )
1364  {
1365  SCIP_CALL( transformColumn(origscip, sepadata, mipdata, col, -lb[j], 1.0, lhs, rhs, &(lb[j]), &(ub[j]), &(primsol[j])) );
1366  assert( SCIPisZero(origscip, lb[j]) );
1367  mipdata->isshifted[j] = TRUE;
1368  ++nshifted;
1369  }
1370 
1371  /* if integer variable is at its lower bound */
1372  if ( mipdata->coltype[j] == colPresent && SCIPisZero(origscip, primsol[j]) )
1373  {
1374  mipdata->coltype[j] = colAtLb;
1375  ++nlbounds;
1376  }
1377  }
1378  else
1379  {
1380  /* lower bound is minus-infinity -> check whether upper bound is finite */
1381  if ( ! SCIPisInfinity(origscip, ub[j]) )
1382  {
1383  /* complement variable */
1384  SCIP_CALL( transformColumn(origscip, sepadata, mipdata, col, ub[j], -1.0, lhs, rhs, &(lb[j]), &(ub[j]), &(primsol[j])) );
1385  assert( SCIPisZero(origscip, lb[j]) );
1386  mipdata->iscomplemented[j] = TRUE;
1387  ++ncomplemented;
1388 
1389  /* if integer variable is at its lower bound */
1390  if ( mipdata->coltype[j] == colPresent && SCIPisZero(origscip, primsol[j]) )
1391  {
1392  mipdata->coltype[j] = colAtLb;
1393  ++nlbounds;
1394  }
1395  }
1396  }
1397  }
1398 
1399  assert( SCIPisFeasLE(origscip, lb[j], primsol[j]) );
1400  assert( SCIPisFeasLE(origscip, primsol[j], ub[j]) );
1401  }
1402 
1403 #ifndef NDEBUG
1404  if ( sepadata->intconvert && ncols >= sepadata->intconvmin )
1405  {
1406  SCIPdebugMsg(origscip, "Converted %u fractional integral variables to have integral value.\n", nintconverted);
1407  }
1408  if ( sepadata->contconvert && ncols >= sepadata->contconvmin )
1409  {
1410  SCIPdebugMsg(origscip, "Converted %u integral variables to be continuous.\n", ncontconverted);
1411  }
1412 #endif
1413  SCIPdebugMsg(origscip, "Original variables: %d integral, %d continuous, %u shifted, %u complemented, %u at lb, %u at ub\n",
1414  SCIPgetNBinVars(origscip) + SCIPgetNIntVars(origscip) + SCIPgetNImplVars(origscip), SCIPgetNContVars(origscip),
1415  nshifted, ncomplemented, nlbounds, nubounds);
1416 
1417  /* prepare upper bound on y-variables */
1418  if ( sepadata->skipmultbounds )
1419  multvarub = SCIPinfinity(origscip);
1420  else
1421  multvarub = 1.0 - EPSILONVALUE;
1422 
1423  /* create artificial variables for row combinations (y-variables) */
1424  cnt = 0;
1425  for (i = 0; i < nrows; ++i)
1426  {
1427  SCIP_ROW* row;
1428 
1429  row = rows[i];
1430  assert( row != NULL );
1431 
1432  mipdata->ylhs[i] = NULL;
1433  mipdata->yrhs[i] = NULL;
1434 
1435  /* skip modifiable rows and local rows, unless allowed */
1436  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && !sepadata->allowlocal) )
1437  continue;
1438 
1439  /* skip rows that not have been active for a longer time */
1440  if ( ! sepadata->onlyactiverows && sepadata->maxrowage > 0 && SCIProwGetAge(row) > sepadata->maxrowage )
1441  continue;
1442 
1443  /* check whether we want to skip cuts produced by the CGMIP separator */
1444  if ( sepadata->onlyrankone )
1445  {
1446  if ( SCIProwGetOriginSepa(row) == sepa )
1447  continue;
1448  }
1449 
1450  /* if we have an equation */
1451  if ( SCIPisEQ(origscip, lhs[i], rhs[i]) )
1452  {
1453  SCIP_Real weight = -sepadata->objweight;
1454 
1455  assert( ! SCIPisInfinity(origscip, rhs[i]) );
1456  assert( SCIPisFeasEQ(origscip, SCIPgetRowLPActivity(origscip, row), SCIProwGetLhs(row)) ); /* equations should always be active */
1457  assert( SCIPisFeasEQ(origscip, SCIPgetRowLPActivity(origscip, row), SCIProwGetRhs(row)) );
1458 
1459  if ( sepadata->objweightsize )
1460  weight = - sepadata->objweight * computeObjWeightSize(SCIProwGetNLPNonz(row), minrowsize, maxrowsize);
1461 
1462  /* create two variables for each equation */
1463  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "yeq1_%d", i);
1464  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->ylhs[i]), name, 0.0, multvarub,
1466  SCIP_CALL( SCIPaddVar(subscip, mipdata->ylhs[i]) );
1467  ++cnt;
1468 
1469 #ifdef SCIP_MORE_DEBUG
1470  SCIPdebugMsg(origscip, "Created variable <%s> for equation <%s>.\n", name, SCIProwGetName(row));
1471 #endif
1472 
1473  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "yeq2_%d", i);
1474  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->yrhs[i]), name, 0.0, multvarub,
1476  SCIP_CALL( SCIPaddVar(subscip, mipdata->yrhs[i]) );
1477  ++cnt;
1478 
1479 #ifdef SCIP_MORE_DEBUG
1480  SCIPdebugMsg(origscip, "Created variable <%s> for equation <%s>.\n", name, SCIProwGetName(row));
1481 #endif
1482  }
1483  else
1484  {
1485  /* create variable for lhs of row if necessary */
1486  if ( ! SCIPisInfinity(origscip, -lhs[i]) )
1487  {
1488  SCIP_Bool isactive = FALSE;
1489  SCIP_Real weight = 0.0;
1490 
1491  /* if the row is active, use objective weight equal to -sepadata->objweight */
1492  if ( SCIPisFeasEQ(origscip, SCIPgetRowLPActivity(origscip, row), SCIProwGetLhs(row)) )
1493  {
1494  isactive = TRUE;
1495  if ( sepadata->objweightsize )
1496  weight = -sepadata->objweight * computeObjWeightSize(SCIProwGetNLPNonz(row), minrowsize, maxrowsize);
1497  else
1498  weight = -sepadata->objweight;
1499  }
1500 
1501  if ( ! sepadata->onlyactiverows || isactive )
1502  {
1503  /* add variable */
1504  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "ylhs_%d", i);
1505  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->ylhs[i]), name, 0.0, multvarub,
1507  SCIP_CALL( SCIPaddVar(subscip, mipdata->ylhs[i]) );
1508  ++cnt;
1509 
1510 #ifdef SCIP_MORE_DEBUG
1511  SCIPdebugMsg(origscip, "Created variable <%s> for >= inequality <%s> (weight: %f).\n", name, SCIProwGetName(row), weight);
1512 #endif
1513  }
1514  }
1515 
1516  /* create variable for rhs of row if necessary */
1517  if ( ! SCIPisInfinity(origscip, rhs[i]) )
1518  {
1519  SCIP_Bool isactive = FALSE;
1520  SCIP_Real weight = 0.0;
1521 
1522  /* if the row is active, use objective weight equal to -sepadata->objweight */
1523  if ( SCIPisFeasEQ(origscip, SCIPgetRowLPActivity(origscip, row), SCIProwGetRhs(row)) )
1524  {
1525  isactive = TRUE;
1526  if ( sepadata->objweightsize )
1527  weight = -sepadata->objweight * computeObjWeightSize(SCIProwGetNLPNonz(row), minrowsize, maxrowsize);
1528  else
1529  weight = -sepadata->objweight;
1530  }
1531 
1532  if ( ! sepadata->onlyactiverows || isactive )
1533  {
1534  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "yrhs_%d", i);
1535  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->yrhs[i]), name, 0.0, multvarub,
1537  SCIP_CALL( SCIPaddVar(subscip, mipdata->yrhs[i]) );
1538  ++cnt;
1539 
1540 #ifdef SCIP_MORE_DEBUG
1541  SCIPdebugMsg(origscip, "Created variable <%s> for <= inequality <%s> (weight: %f).\n", name, SCIProwGetName(row), weight);
1542 #endif
1543  }
1544  }
1545  }
1546  }
1547  assert( (int) cnt <= 2 * nrows );
1548  mipdata->n += cnt;
1549 
1550  /* create artificial variables for objective function (if required) (y-variables) */
1551  if ( sepadata->useobjub || sepadata->useobjlb )
1552  {
1553  SCIP_Real weight = 0.0;
1554 
1555  assert( mipdata->ntotalrows == mipdata->nrows + 1 );
1556  mipdata->ylhs[mipdata->nrows] = NULL;
1557  mipdata->yrhs[mipdata->nrows] = NULL;
1558  cnt = 0;
1559 
1560  if ( sepadata->objweightsize )
1561  weight = -sepadata->objweight * computeObjWeightSize(SCIPgetNObjVars(origscip), minrowsize, maxrowsize);
1562  else
1563  weight = -sepadata->objweight;
1564 
1565  /* create variable for upper objective bound if necessary */
1566  if ( sepadata->useobjub && ! SCIPisInfinity(origscip, rhs[mipdata->nrows]) )
1567  {
1568  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "yobjub");
1569  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->yrhs[mipdata->nrows]), name, 0.0, multvarub,
1571  SCIP_CALL( SCIPaddVar(subscip, mipdata->yrhs[mipdata->nrows]) );
1572  ++cnt;
1573 
1574 #ifdef SCIP_MORE_DEBUG
1575  SCIPdebugMsg(origscip, "Created variable <%s> for upper bound on objective (weight: %f).\n", name, weight);
1576 #endif
1577  }
1578 
1579  /* create variable for lower bound objective if necessary */
1580  if ( sepadata->useobjlb && ! SCIPisInfinity(origscip, -lhs[mipdata->nrows]) )
1581  {
1582  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "yobjlb");
1583  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->ylhs[mipdata->nrows]), name, 0.0, multvarub,
1585  SCIP_CALL( SCIPaddVar(subscip, mipdata->ylhs[mipdata->nrows]) );
1586  ++cnt;
1587 
1588 #ifdef SCIP_MORE_DEBUG
1589  SCIPdebugMsg(origscip, "Created variable <%s> for lower bound on objective (weight: %f).\n", name, weight);
1590 #endif
1591  }
1592 
1593  assert( (int) cnt <= 2 * ntotalrows );
1594  mipdata->n += cnt;
1595  }
1596 
1597  /* create alpha, bound, and fractional variables */
1598  cnt = 0;
1599  ucnt = 0;
1600  for (j = 0; j < ncols; ++j)
1601  {
1602  mipdata->z[j] = NULL;
1603  mipdata->alpha[j] = NULL;
1604  mipdata->fracalpha[j] = NULL;
1605 
1606  if ( mipdata->coltype[j] == colPresent )
1607  {
1608  SCIP_Real obj;
1609 
1610  if ( sepadata->objlone )
1611  obj = 0.0;
1612  else
1613  obj = primsol[j];
1614 
1615  /* create alpha variables */
1616  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "alpha_%d", j);
1617  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->alpha[j]), name, -sepadata->cutcoefbnd, sepadata->cutcoefbnd, obj,
1619  SCIP_CALL( SCIPaddVar(subscip, mipdata->alpha[j]) );
1620  ++cnt;
1621 
1622  /* create fractional variables */
1623  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "f_%d", j);
1624  if ( SCIPisInfinity(origscip, -lb[j]) && SCIPisInfinity(origscip, ub[j]) )
1625  {
1626  /* fix fractional value to be zero for free original variables */
1627  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->fracalpha[j]), name, 0.0, 0.0, 0.0,
1629  }
1630  else
1631  {
1632  /* fractional value in [0, 1) for variables with finite bounds */
1633  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->fracalpha[j]), name, 0.0, 1.0-EPSILONVALUE, 0.0,
1635  }
1636  SCIP_CALL( SCIPaddVar(subscip, mipdata->fracalpha[j]) );
1637  ++cnt;
1638 
1639  /* create variables for upper bounds */
1640  if ( ! SCIPisInfinity(origscip, ub[j]) )
1641  {
1642  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "zub_%d", j);
1643  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->z[j]), name, 0.0, multvarub,
1645  SCIP_CALL( SCIPaddVar(subscip, mipdata->z[j]) );
1646  ++ucnt;
1647  }
1648  }
1649  }
1650  assert( (int) cnt <= 2 * ncols );
1651  assert( (int) ucnt <= ncols );
1652 
1653  /* create variable for the rhs of the cut */
1654  if ( sepadata->objlone )
1655  {
1656  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->beta), "beta", -sepadata->cutcoefbnd, sepadata->cutcoefbnd, 0.0,
1658  }
1659  else
1660  {
1661  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->beta), "beta", -sepadata->cutcoefbnd, sepadata->cutcoefbnd, -1.0,
1663  }
1664  SCIP_CALL( SCIPaddVar(subscip, mipdata->beta) );
1665 
1666  /* create fractional variable for the rhs */
1667  SCIP_CALL( SCIPcreateVar(subscip, &(mipdata->fracbeta), "fracbeta", 0.0, 1.0-BETAEPSILONVALUE, 0.0,
1669  SCIP_CALL( SCIPaddVar(subscip, mipdata->fracbeta) );
1670  mipdata->n += cnt + ucnt + 2;
1671 
1672  /* get temporary storage */
1673  SCIP_CALL( SCIPallocBufferArray(origscip, &consvals, (int) mipdata->n) );
1674  SCIP_CALL( SCIPallocBufferArray(origscip, &consvars, (int) mipdata->n) );
1675 
1676  /* create constraints for alpha variables of CG-cut */
1677  cnt = 0;
1678  for (j = 0; j < ncols; ++j)
1679  {
1680  SCIP_ROW** colrows;
1681  SCIP_Real* colvals;
1682 
1683  /* create ordinary part for all selected variables */
1684  if ( mipdata->coltype[j] == colPresent )
1685  {
1686  SCIP_Real sigma;
1687 
1688  assert( cols[j] != NULL );
1689  colrows = SCIPcolGetRows(cols[j]);
1690  colvals = SCIPcolGetVals(cols[j]);
1691  nconsvars = 0;
1692 
1693  if ( mipdata->iscomplemented[j] )
1694  sigma = -1.0;
1695  else
1696  sigma = 1.0;
1697 
1698  /* add part for columns */
1699  for (i = 0; i < SCIPcolGetNLPNonz(cols[j]); ++i)
1700  {
1701  SCIP_ROW* row;
1702  int pos;
1703 
1704  row = colrows[i];
1705  assert( row != NULL );
1706 
1707  /* skip modifiable rows and local rows, unless allowed */
1708  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && !sepadata->allowlocal) )
1709  continue;
1710 
1711  pos = SCIProwGetLPPos(row);
1712  assert( 0 <= pos && pos < nrows );
1713 
1714  if ( mipdata->ylhs[pos] != NULL )
1715  {
1716  consvars[nconsvars] = mipdata->ylhs[pos];
1717  consvals[nconsvars] = -sigma * colvals[i];
1718  ++nconsvars;
1719  }
1720  if ( mipdata->yrhs[pos] != NULL )
1721  {
1722  consvars[nconsvars] = mipdata->yrhs[pos];
1723  consvals[nconsvars] = sigma * colvals[i];
1724  ++nconsvars;
1725  }
1726  assert( nconsvars <= (int) mipdata->n );
1727  }
1728  /* add part for upper bounds */
1729  if ( mipdata->z[j] != NULL )
1730  {
1731  assert( ! SCIPisInfinity(origscip, ub[j]) );
1732  consvars[nconsvars] = mipdata->z[j];
1733  consvals[nconsvars] = 1.0;
1734  ++nconsvars;
1735  }
1736  assert( nconsvars <= (int) mipdata->n );
1737 
1738  /* add alpha variable */
1739  consvars[nconsvars] = mipdata->alpha[j];
1740  consvals[nconsvars] = -1.0;
1741  ++nconsvars;
1742  assert( nconsvars <= (int) mipdata->n );
1743 
1744  /* add fractional-alpha variable */
1745  consvars[nconsvars] = mipdata->fracalpha[j];
1746  consvals[nconsvars] = -1.0;
1747  ++nconsvars;
1748  assert( nconsvars <= (int) mipdata->n );
1749 
1750  /* check for lower and upper objective bounds */
1751  if ( (sepadata->useobjub || sepadata->useobjlb) && ! SCIPisZero(origscip, SCIPcolGetObj(cols[j])) )
1752  {
1753  /* add lower objective bound */
1754  if ( mipdata->ylhs[mipdata->nrows] != NULL )
1755  {
1756  assert( sepadata->useobjlb );
1757  consvars[nconsvars] = mipdata->ylhs[mipdata->nrows];
1758  consvals[nconsvars] = -sigma * SCIPcolGetObj(cols[j]);
1759  ++nconsvars;
1760  }
1761 
1762  /* add upper objective bound */
1763  if ( mipdata->yrhs[mipdata->nrows] != NULL )
1764  {
1765  assert( sepadata->useobjub );
1766  consvars[nconsvars] = mipdata->yrhs[mipdata->nrows];
1767  consvals[nconsvars] = sigma * SCIPcolGetObj(cols[j]);
1768  ++nconsvars;
1769  }
1770  }
1771 
1772  /* add linear constraint */
1773  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "alpha_%d", j);
1774  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, name, nconsvars, consvars, consvals, 0.0, 0.0,
1775  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1776  SCIP_CALL( SCIPaddCons(subscip, cons) );
1777  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
1778  ++cnt;
1779  }
1780  /* generate part that makes sure that cut is valid for continuous variables */
1781  else if ( mipdata->coltype[j] == colContinuous || mipdata->coltype[j] == colConverted )
1782  {
1783  SCIP_Real sigma;
1784  SCIP_Real r;
1785 
1786  assert( cols[j] != NULL );
1787  colrows = SCIPcolGetRows(cols[j]);
1788  colvals = SCIPcolGetVals(cols[j]);
1789  nconsvars = 0;
1790 
1791  if ( mipdata->iscomplemented[j] )
1792  sigma = -1.0;
1793  else
1794  sigma = 1.0;
1795 
1796  /* add part for columns */
1797  for (i = 0; i < SCIPcolGetNLPNonz(cols[j]); ++i)
1798  {
1799  SCIP_ROW* row;
1800  int pos;
1801 
1802  row = colrows[i];
1803  assert( row != NULL );
1804 
1805  /* skip modifiable rows and local rows, unless allowed */
1806  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && !sepadata->allowlocal) )
1807  continue;
1808 
1809  pos = SCIProwGetLPPos(row);
1810  assert( 0 <= pos && pos < nrows );
1811 
1812  if ( mipdata->ylhs[pos] != NULL )
1813  {
1814  consvars[nconsvars] = mipdata->ylhs[pos];
1815  consvals[nconsvars] = -sigma * colvals[i];
1816  ++nconsvars;
1817  }
1818  if ( mipdata->yrhs[pos] != NULL )
1819  {
1820  consvars[nconsvars] = mipdata->yrhs[pos];
1821  consvals[nconsvars] = sigma * colvals[i];
1822  ++nconsvars;
1823  }
1824  assert( nconsvars <= (int) mipdata->n );
1825  }
1826 
1827  /* check for lower and upper objective bounds */
1828  if ( (sepadata->useobjub || sepadata->useobjlb) && ! SCIPisZero(origscip, SCIPcolGetObj(cols[j])) )
1829  {
1830  /* add lower objective bound */
1831  if ( mipdata->ylhs[mipdata->nrows] )
1832  {
1833  assert( sepadata->useobjlb );
1834  consvars[nconsvars] = mipdata->ylhs[mipdata->nrows];
1835  consvals[nconsvars] = -sigma * SCIPcolGetObj(cols[j]);
1836  ++nconsvars;
1837  }
1838 
1839  /* add upper objective bound */
1840  if ( mipdata->yrhs[mipdata->nrows] )
1841  {
1842  assert( sepadata->useobjub );
1843  consvars[nconsvars] = mipdata->yrhs[mipdata->nrows];
1844  consvals[nconsvars] = sigma * SCIPcolGetObj(cols[j]);
1845  ++nconsvars;
1846  }
1847  }
1848 
1849  /* add linear constraint */
1850  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "cont_%d", j);
1851 
1852  /* for free continuous variables require equality */
1853  r = SCIPinfinity(subscip);
1854  if ( SCIPisInfinity(origscip, -lb[j]) && SCIPisInfinity(origscip, ub[j]) )
1855  r = 0.0;
1856  else
1857  assert( SCIPisZero(origscip, lb[j]) );
1858 
1859  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, name, nconsvars, consvars, consvals, 0.0, r,
1860  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1861  SCIP_CALL( SCIPaddCons(subscip, cons) );
1862  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
1863  ++cnt;
1864  }
1865  }
1866  assert( (int) cnt <= ncols );
1867  mipdata->m += cnt;
1868 
1869  /* create constraints for rhs of cut */
1870  nconsvars = 0;
1871 
1872  /* first for the rows */
1873  for (i = 0; i < nrows; ++i)
1874  {
1875  assert( rows[i] != NULL );
1876 
1877  /* skip modifiable rows and local rows, unless allowed */
1878  if ( SCIProwIsModifiable(rows[i]) || (SCIProwIsLocal(rows[i]) && !sepadata->allowlocal) )
1879  continue;
1880 
1881  /* if lhs is there */
1882  if ( mipdata->ylhs[i] != NULL && ! SCIPisZero(origscip, lhs[i]) )
1883  {
1884  assert( ! SCIPisInfinity(origscip, -lhs[i]) );
1885  consvars[nconsvars] = mipdata->ylhs[i];
1886  consvals[nconsvars] = -lhs[i];
1887  ++nconsvars;
1888  }
1889  /* if rhs is there */
1890  if ( mipdata->yrhs[i] != NULL && ! SCIPisZero(origscip, rhs[i]) )
1891  {
1892  assert( ! SCIPisInfinity(origscip, rhs[i]) );
1893  consvars[nconsvars] = mipdata->yrhs[i];
1894  consvals[nconsvars] = rhs[i];
1895  ++nconsvars;
1896  }
1897  assert( nconsvars <= (int) mipdata->n );
1898  }
1899 
1900  if ( sepadata->useobjub || sepadata->useobjlb )
1901  {
1902  /* add lower objective bound */
1903  if ( mipdata->ylhs[mipdata->nrows] != NULL && ! SCIPisZero(origscip, lhs[mipdata->nrows]) )
1904  {
1905  assert( sepadata->useobjlb );
1906  assert( ! SCIPisInfinity(origscip, -lhs[mipdata->nrows]) );
1907  consvars[nconsvars] = mipdata->ylhs[mipdata->nrows];
1908  consvals[nconsvars] = -lhs[mipdata->nrows];
1909  ++nconsvars;
1910  }
1911 
1912  /* add upper objective bound */
1913  if ( mipdata->yrhs[mipdata->nrows] != NULL && ! SCIPisZero(origscip, rhs[mipdata->nrows]) )
1914  {
1915  assert( sepadata->useobjub );
1916  assert( ! SCIPisInfinity(origscip, rhs[mipdata->nrows]) );
1917  consvars[nconsvars] = mipdata->yrhs[mipdata->nrows];
1918  consvals[nconsvars] = rhs[mipdata->nrows];
1919  ++nconsvars;
1920  }
1921  assert( nconsvars <= (int) mipdata->n );
1922  }
1923 
1924  /* next for the columns */
1925  for (j = 0; j < ncols; ++j)
1926  {
1927  /* if ub is there */
1928  if ( mipdata->z[j] != NULL && ! SCIPisZero(origscip, ub[j]) )
1929  {
1930  assert( mipdata->coltype[j] == colPresent );
1931  assert( ! SCIPisInfinity(origscip, ub[j]) );
1932  consvars[nconsvars] = mipdata->z[j];
1933  consvals[nconsvars] = ub[j];
1934  ++nconsvars;
1935  assert( nconsvars <= (int) mipdata->n );
1936  }
1937  }
1938  /* add beta variable */
1939  consvars[nconsvars] = mipdata->beta;
1940  consvals[nconsvars] = -1.0;
1941  ++nconsvars;
1942 
1943  /* add fractional-beta variable */
1944  consvars[nconsvars] = mipdata->fracbeta;
1945  consvals[nconsvars] = -1.0;
1946  ++nconsvars;
1947  assert( nconsvars <= (int) mipdata->n );
1948 
1949  /* add linear constraint */
1950  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, "beta", nconsvars, consvars, consvals, 0.0, 0.0,
1951  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1952  SCIP_CALL( SCIPaddCons(subscip, cons) );
1953  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
1954  ++mipdata->m;
1955 
1956  /* add primal separation constraint if required */
1957  if ( sepadata->primalseparation )
1958  {
1959  SCIP_SOL* bestsol;
1960  bestsol = SCIPgetBestSol(origscip);
1961  if ( bestsol != NULL )
1962  {
1963  nconsvars = 0;
1964  for (j = 0; j < ncols; ++j)
1965  {
1966  if ( mipdata->alpha[j] != NULL )
1967  {
1968  SCIP_Real val;
1969  assert( mipdata->coltype[j] == colPresent );
1970 
1971  val = SCIPgetSolVal(origscip, bestsol, SCIPcolGetVar(cols[j]));
1972  consvars[nconsvars] = mipdata->alpha[j];
1973  consvals[nconsvars] = val;
1974  ++nconsvars;
1975  assert( nconsvars <= (int) mipdata->n );
1976  }
1977  }
1978  consvars[nconsvars] = mipdata->beta;
1979  consvals[nconsvars] = -1.0;
1980  ++nconsvars;
1981 
1982  /* add linear constraint - allow slight deviation from equality */
1983  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, "primalseparation", nconsvars, consvars, consvals, -EPSILONVALUE, EPSILONVALUE,
1984  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1985  SCIP_CALL( SCIPaddCons(subscip, cons) );
1986  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
1987  ++mipdata->m;
1988  }
1989  }
1990 
1991  /* add constraint to force violated cuts if required */
1992  if ( sepadata->addviolationcons )
1993  {
1994  nconsvars = 0;
1995  for (j = 0; j < ncols; ++j)
1996  {
1997  if ( mipdata->alpha[j] != NULL )
1998  {
1999  consvars[nconsvars] = mipdata->alpha[j];
2000  consvals[nconsvars] = primsol[j];
2001  ++nconsvars;
2002  assert( nconsvars <= (int) mipdata->n );
2003  }
2004  }
2005  consvars[nconsvars] = mipdata->beta;
2006  consvals[nconsvars] = -1.0;
2007  ++nconsvars;
2008 
2009  /* add linear constraint - allow slight deviation from equality */
2010  SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, "violationConstraint", nconsvars, consvars, consvals, MINEFFICACY, SCIPinfinity(subscip),
2011  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2012  SCIP_CALL( SCIPaddCons(subscip, cons) );
2013  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
2014  ++mipdata->m;
2015  }
2016 
2017  SCIPdebugMsg(origscip, "Subscip has %u vars (%d integral, %d continuous), %u conss.\n",
2018  mipdata->n, SCIPgetNIntVars(subscip), SCIPgetNContVars(subscip), mipdata->m);
2019 
2020  /* free temporary memory */
2021  SCIPfreeBufferArray(origscip, &consvars);
2022  SCIPfreeBufferArray(origscip, &consvals);
2023 
2024  SCIPfreeBufferArray(origscip, &primsol);
2025  SCIPfreeBufferArray(origscip, &lb);
2026  SCIPfreeBufferArray(origscip, &ub);
2027 
2028  /* SCIPdebug( SCIP_CALL( SCIPprintOrigProblem(subscip, NULL, NULL, FALSE) ) ); */
2029 
2030 #ifdef SCIP_WRITEPROB
2031  {
2032  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "cgsepa%s%s%s%s_%s.lp",
2033  sepadata->objlone ? "_l1" : "",
2034  sepadata->addviolationcons ? "_vc" : "",
2035  sepadata->skipmultbounds ? "_ub" : "",
2036  sepadata->primalseparation ? "_ps" : "",
2037  SCIPgetProbName(origscip));
2038  SCIP_CALL( SCIPwriteOrigProblem(subscip, name, "lp", FALSE) );
2039  SCIPinfoMessage(origscip, NULL, "Wrote subscip to file <%s>.\n", name);
2040  }
2041 #endif
2042 
2043  return SCIP_OKAY;
2044 }
2045 
2046 
2047 /** sets parameters for subscip */
2048 static
2050  SCIP_SEPADATA* sepadata, /**< separator data */
2051  CGMIP_MIPDATA* mipdata /**< data for sub-MIP */
2052  )
2053 {
2054  SCIP* subscip;
2055 
2056  assert( sepadata != NULL );
2057  assert( mipdata != NULL );
2058 
2059  subscip = mipdata->subscip;
2060  assert( subscip != NULL );
2061 
2062  /* set objective limit, if no corresponding constraint has been added */
2063  if ( ! sepadata->addviolationcons && ! sepadata->addviolconshdlr )
2064  {
2065  SCIP_CALL( SCIPsetObjlimit(subscip, MINEFFICACY) );
2066  }
2067 
2068  /* do not abort subscip on CTRL-C */
2069  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
2070 
2071  /* disable memory saving mode: this is likely to result in the maximal depth being reached. This is because DFS
2072  * results in a repeated branching on the alpha-variables, which often have large bounds resulting in deep levels of
2073  * the tree. */
2074  SCIP_CALL( SCIPsetRealParam(subscip, "memory/savefac", 1.0) );
2075 
2076  /* set number of solutions stored */
2077  SCIP_CALL( SCIPsetIntParam(subscip, "limits/maxsol", MAXNSOLS) );
2078 
2079  /* determine output to console */
2080 #ifdef SCIP_OUTPUT
2081  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
2082  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 1000) );
2083  SCIP_CALL( SCIPsetIntParam(subscip, "display/nsols/active", 2) );
2084 #else
2085  if ( sepadata->output )
2086  {
2087  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
2088  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 1000) );
2089  SCIP_CALL( SCIPsetIntParam(subscip, "display/nsols/active", 2) );
2090  }
2091  else
2092  {
2093  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
2094  }
2095 #endif
2096 
2097  if ( sepadata->subscipfast )
2098  {
2099  /* forbid recursive call of plugins solving subMIPs (also disables CG-separation) */
2100 #ifdef SCIP_OUTPUT
2101  SCIP_CALL( SCIPsetSubscipsOff(subscip, FALSE) );
2102 #else
2103  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) ); /* quiet */
2104 #endif
2105  }
2106  else
2107  {
2108  /* avoid recursive call */
2109  if ( ! SCIPisParamFixed(subscip, "separating/cgmip/freq") )
2110  {
2111  SCIP_CALL( SCIPsetIntParam(subscip, "separating/cgmip/freq", -1) );
2112  }
2113  }
2114 
2115 #ifdef SCIP_DISABLED_CODE
2116  /* the following possibly helps to improve performance (untested) */
2118 #else
2119 
2120  /* zirounding is often successful, so allow it some more calls */
2121  if ( ! SCIPisParamFixed(subscip, "heuristics/zirounding/minstopncalls") )
2122  {
2123  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/zirounding/minstopncalls", 10000) );
2124  }
2125 
2126  if ( sepadata->subscipfast )
2127  {
2128  /* set other heuristics */
2129  if ( ! SCIPisParamFixed(subscip, "heuristics/shifting/freq") )
2130  {
2131  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/shifting/freq", 3) );
2132  }
2133  if ( ! SCIPisParamFixed(subscip, "heuristics/simplerounding/freq") )
2134  {
2135  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/simplerounding/freq", 1) );
2136  }
2137  if ( ! SCIPisParamFixed(subscip, "heuristics/rounding/freq") )
2138  {
2139  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/rounding/freq", 1) );
2140  }
2141  if ( ! SCIPisParamFixed(subscip, "heuristics/oneopt/freq") )
2142  {
2143  SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/oneopt/freq", 1) );
2144  }
2145 
2146  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/pscostdiving/freq", 1) ); */
2147  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/feaspump/freq", 3) ); */
2148 
2149  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/coefdiving/freq", -1) ); */
2150  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/fracdiving/freq", -1) ); */
2151  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/guideddiving/freq", -1) ); */
2152  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/linesearchdiving/freq", -1) ); */
2153  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/objpscostdiving/freq", -1) ); */
2154  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/rootsoldiving/freq", -1) ); */
2155  /* SCIP_CALL( SCIPsetIntParam(subscip, "heuristics/veclendiving/freq", -1) ); */
2156 
2157  /* use fast presolving */
2159 
2160  /* disable conflict analysis */
2161  /* SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/useprop", FALSE) ); */
2162  /* SCIP_CALL( SCIPsetCharParam(subscip, "conflict/useinflp", 'o') ); */
2163  /* SCIP_CALL( SCIPsetCharParam(subscip, "conflict/useboundlp", 'o') ); */
2164  /* SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/usesb", FALSE) ); */
2165  /* SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/usepseudo", FALSE) ); */
2166 
2167  /* use fast separation */
2169  }
2170 #endif
2171 
2172 #ifdef SCIP_WRITEPROB
2173  {
2174  char name[SCIP_MAXSTRLEN];
2175 
2176  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "cgsepa%s%s%s%s_%s.set",
2177  sepadata->objlone ? "_l1" : "",
2178  sepadata->addviolationcons ? "_vc" : "",
2179  sepadata->skipmultbounds ? "_ub" : "",
2180  sepadata->primalseparation ? "_ps" : "",
2181  SCIPgetProbName(mipdata->scip));
2182  SCIP_CALL( SCIPwriteParams(subscip, name, TRUE, FALSE) );
2183  SCIPinfoMessage(mipdata->scip, NULL, "Wrote settings to file <%s>.\n", name);
2184  }
2185 #endif
2186 
2187  return SCIP_OKAY;
2188 }
2189 
2190 
2191 /** try to convert fractional gomory cuts to primal solutions of CG-MIP */
2192 static
2194  SCIP* scip, /**< original SCIP data structure */
2195  SCIP_SEPADATA* sepadata, /**< separator data */
2196  CGMIP_MIPDATA* mipdata /**< data for sub-MIP */
2197  )
2198 {
2199  SCIP_VAR** vars;
2200  SCIP_ROW** rows;
2201  SCIP_COL** cols;
2202  SCIP_Real* binvrow;
2203  SCIP_Real* cutcoefs;
2204  int* basisind;
2205  int nvars;
2206  int nrows;
2207  int ncols;
2208  int ngen = 0;
2209  int ntried = 0;
2210  int i;
2211 
2212  assert( scip != NULL );
2213  assert( sepadata != NULL );
2214  assert( mipdata != NULL );
2215 
2216  /* get variables */
2217  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
2218 
2219  /* get rows and columns */
2220  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
2221  SCIP_CALL( SCIPgetLPColsData(scip, &cols, &ncols) );
2222  assert( ncols <= nvars );
2223 
2224  /* get storage */
2225  SCIP_CALL( SCIPallocBufferArray(scip, &basisind, nrows) );
2226  SCIP_CALL( SCIPallocBufferArray(scip, &binvrow, nrows) );
2227  SCIP_CALL( SCIPallocBufferArray(scip, &cutcoefs, ncols) );
2228 
2229  /* get basis indices */
2230  SCIP_CALL( SCIPgetLPBasisInd(scip, basisind) );
2231 
2232  /* loop through rows */
2233  for (i = 0; i < nrows; ++i)
2234  {
2235  SCIP_Bool tryrow = FALSE;
2236  SCIP_Real primsol = SCIP_INVALID;
2237  int c;
2238  int r;
2239 
2240  c = basisind[i];
2241  assert( c < ncols );
2242 
2243  if ( c >= 0 )
2244  {
2245  SCIP_VAR* var;
2246 
2247  var = SCIPcolGetVar(cols[c]);
2248 
2250  {
2251  primsol = SCIPcolGetPrimsol(cols[c]);
2252  assert( SCIPgetVarSol(scip, var) == primsol ); /*lint !e777*/
2253 
2254  if ( SCIPfeasFrac(scip, primsol) >= AWAY && SCIPfeasFrac(scip, primsol) <= 1 - AWAY )
2255  tryrow = TRUE;
2256  }
2257  }
2258 #if ( SEPARATEROWS == TRUE )
2259  else
2260  {
2261  SCIP_ROW* row;
2262 
2263  assert(0 <= -c-1 && -c-1 < nrows);
2264 
2265  row = rows[-c-1];
2266 
2267  if ( SCIProwIsIntegral(row) && ! SCIProwIsModifiable(row) )
2268  {
2269  /* Compute value of the slack variable (we only care about the correct fractionality) */
2270  if ( SCIPisInfinity(scip, SCIProwGetRhs(row)) )
2271  primsol = SCIProwGetLhs(row) - SCIPgetRowLPActivity(scip, row);
2272  else
2273  primsol = SCIProwGetRhs(row) - SCIPgetRowLPActivity(scip, row);
2274 
2275  if ( SCIPfeasFrac(scip, primsol) >= AWAY && SCIPfeasFrac(scip, primsol) <= 1 - AWAY )
2276  tryrow = TRUE;
2277  }
2278  }
2279 #endif
2280 
2281  if ( tryrow )
2282  {
2283  SCIP_Bool success;
2284  SCIP_SOL* sol;
2285  SCIP_Real cutrhs = 0.0;
2286  SCIP_ROW* row;
2287  SCIP_Real val;
2288  int j;
2289 
2290  assert( primsol != SCIP_INVALID ); /*lint !e777*/
2291 
2292  /* get the row of B^-1 for this basic integer variable with fractional solution value */
2293  SCIP_CALL( SCIPgetLPBInvRow(scip, i, binvrow, NULL, NULL) );
2294 
2295  /* clear cutcoefs */
2296  BMSclearMemoryArray(cutcoefs, ncols);
2297 
2298  /* create solution */
2299  SCIP_CALL( SCIPcreateSol(mipdata->subscip, &sol, NULL) );
2300 
2301  /* add values of multipliers to solution and compute coefficients */
2302  for (r = 0; r < nrows; ++r)
2303  {
2304  SCIP_COL** rowcols;
2305  SCIP_Real* rowvals;
2306  SCIP_Real binvval;
2307  SCIP_Real weight;
2308 
2309  row = rows[r];
2310  assert( row != NULL );
2311 
2312  binvval = binvrow[r];
2313  binvval = SCIPfrac(scip, binvval); /* can always take fractional value */
2314  if ( ! SCIPisFeasZero(scip, binvval) )
2315  {
2316  SCIP_Real lhs;
2317  SCIP_Real rhs;
2318  SCIP_Bool uselhs;
2319 
2320  lhs = SCIProwGetLhs(row);
2321  rhs = SCIProwGetRhs(row);
2322 
2323  if ( ! SCIPisEQ(scip, lhs, rhs) )
2324  {
2325  SCIP_BASESTAT stat;
2326 
2327  stat = SCIProwGetBasisStatus(row);
2328 
2329  if ( stat == SCIP_BASESTAT_LOWER )
2330  {
2331  assert( ! SCIPisInfinity(scip, -lhs) );
2332  uselhs = TRUE;
2333  }
2334  else if ( stat == SCIP_BASESTAT_UPPER )
2335  {
2336  assert( ! SCIPisInfinity(scip, rhs) );
2337  uselhs = FALSE;
2338  }
2339  else if ( SCIPisInfinity(scip, rhs) )
2340  uselhs = TRUE;
2341  else
2342  uselhs = FALSE;
2343  }
2344  else if ( binvval < 0.0 )
2345  uselhs = TRUE;
2346  else
2347  uselhs = FALSE;
2348 
2349  if ( uselhs )
2350  {
2351  assert( mipdata->ylhs[r] != NULL );
2352  SCIP_CALL( SCIPsetSolVal(mipdata->subscip, sol, mipdata->ylhs[r], fabs(binvval)) );
2353  weight = -fabs(binvval);
2354  }
2355  else
2356  {
2357  assert( mipdata->yrhs[r] != NULL );
2358  SCIP_CALL( SCIPsetSolVal(mipdata->subscip, sol, mipdata->yrhs[r], fabs(binvval)) );
2359  weight = fabs(binvval);
2360  }
2361 
2362  /* update cut coefficients */
2363  rowcols = SCIProwGetCols(row);
2364  rowvals = SCIProwGetVals(row);
2365 
2366  /* add the row coefficients to the sum */
2367  for (j = 0; j < SCIProwGetNLPNonz(row); ++j)
2368  {
2369  int idx;
2370 
2371  assert( rowcols[j] != NULL );
2372 
2373  idx = SCIPcolGetLPPos(rowcols[j]);
2374  assert( 0 <= idx && idx < ncols );
2375 
2376  cutcoefs[idx] += weight * rowvals[j];
2377  }
2378 
2379  /* compute rhs */
2380  if ( uselhs )
2381  {
2382  assert( ! SCIPisInfinity(scip, -SCIProwGetLhs(row)) );
2383  val = mipdata->lhs[r];
2384  }
2385  else
2386  {
2387  assert( ! SCIPisInfinity(scip, SCIProwGetRhs(row)) );
2388  val = mipdata->rhs[r];
2389  }
2390  cutrhs += weight * val;
2391  }
2392  }
2393 
2394  /* fill in values of cut */
2395  for (c = 0; c < ncols; ++c)
2396  {
2397  if ( mipdata->coltype[c] != colPresent )
2398  continue;
2399 
2400  val = SCIPfloor(scip, cutcoefs[c]);
2401  if ( mipdata->iscomplemented[c] )
2402  val = -val;
2403  if ( ! SCIPisFeasZero(scip, val) )
2404  {
2405  SCIP_CALL( SCIPsetSolVal(mipdata->subscip, sol, mipdata->alpha[c], val) );
2406  }
2407  val = SCIPfeasFrac(scip, cutcoefs[c]);
2408  if ( ! SCIPisFeasZero(scip, val) )
2409  {
2410  SCIP_CALL( SCIPsetSolVal(mipdata->subscip, sol, mipdata->fracalpha[c], val) );
2411  }
2412  }
2413 
2414  if ( ! SCIPisFeasZero(scip, SCIPfloor(scip, cutrhs)) )
2415  {
2416  SCIP_CALL( SCIPsetSolVal(mipdata->subscip, sol, mipdata->beta, SCIPfloor(scip, cutrhs)) );
2417  }
2418  if ( ! SCIPisFeasZero(scip, SCIPfeasFrac(scip, cutrhs)) )
2419  {
2420  SCIP_CALL( SCIPsetSolVal(mipdata->subscip, sol, mipdata->fracbeta, SCIPfeasFrac(scip, cutrhs)) );
2421  }
2422 
2423  SCIP_CALL( SCIPtrySolFree(mipdata->subscip, &sol, FALSE, FALSE, TRUE, TRUE, TRUE, &success) );
2424  ++ntried;
2425  if ( success )
2426  ++ngen;
2427  }
2428  }
2429 
2430  SCIPfreeBufferArray(scip, &cutcoefs);
2431  SCIPfreeBufferArray(scip, &binvrow);
2432  SCIPfreeBufferArray(scip, &basisind);
2433 
2434  SCIPdebugMsg(scip, "Created %d primal solutions for CG-MIP from tableau cuts (tried: %d).\n", ngen, ntried);
2435 
2436  return SCIP_OKAY;
2437 }
2438 
2439 
2440 /** solve subscip */
2441 static
2443  SCIP* origscip, /**< SCIP data structure */
2444  SCIP_SEPADATA* sepadata, /**< separator data */
2445  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
2446  SCIP_Bool* success /**< if setting was successful -> stop */
2447  )
2448 {
2449  SCIP* subscip;
2450  SCIP_RETCODE retcode;
2451  SCIP_STATUS status;
2452  SCIP_Real timelimit;
2453  SCIP_Real memorylimit;
2454  SCIP_Longint nodelimit;
2455 
2456  assert( origscip != NULL );
2457  assert( sepadata != NULL );
2458  assert( mipdata != NULL );
2459  assert( success != NULL );
2460 
2461  *success = TRUE;
2462 
2463  subscip = mipdata->subscip;
2464 
2465  SCIP_CALL( SCIPcheckCopyLimits(origscip, success) );
2466 
2467  if ( ! (*success) )
2468  return SCIP_OKAY;
2469 
2470  /* @todo Check whether copying the parameters is useful */
2471  /* SCIP_CALL( SCIPcopyLimits(origscip, subscip) ); */
2472 
2473  /* determine time limit */
2474  SCIP_CALL( SCIPgetRealParam(origscip, "limits/time", &timelimit) );
2475  if ( sepadata->timelimit < timelimit )
2476  timelimit = sepadata->timelimit;
2477 
2478  if ( ! SCIPisInfinity(origscip, timelimit) )
2479  {
2480  timelimit -= SCIPgetSolvingTime(origscip);
2481  if ( timelimit > 0.0 )
2482  {
2483  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
2484  }
2485  else
2486  {
2487  SCIPdebugMsg(origscip, "Reached timelimit.\n");
2488  *success = FALSE;
2489  return SCIP_OKAY;
2490  }
2491  }
2492 
2493  /* determine memory limit */
2494  SCIP_CALL( SCIPgetRealParam(origscip, "limits/memory", &memorylimit) );
2495  if ( sepadata->memorylimit < memorylimit )
2496  memorylimit = sepadata->memorylimit;
2497 
2498  if ( ! SCIPisInfinity(origscip, memorylimit) )
2499  {
2500  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
2501  memorylimit -= SCIPgetMemUsed(origscip)/1048576.0;
2502  memorylimit -= SCIPgetMemExternEstim(origscip)/1048576.0;
2503  if ( memorylimit > 0.0 )
2504  {
2505  SCIP_CALL( SCIPsetRealParam(subscip, "limits/memory", memorylimit) );
2506  }
2507  else
2508  {
2509  SCIPdebugMsg(origscip, "Reached memorylimit.\n");
2510  *success = TRUE;
2511  return SCIP_OKAY;
2512  }
2513  }
2514 
2515  /* set node limit for subproblem */
2516  if ( sepadata->minnodelimit < 0 || sepadata->maxnodelimit < 0 )
2517  nodelimit = SCIP_LONGINT_MAX;
2518  else
2519  {
2520  assert( sepadata->minnodelimit >= 0 && sepadata->maxnodelimit >= 0 );
2521  nodelimit = SCIPgetNLPIterations(origscip);
2522  nodelimit = MAX(sepadata->minnodelimit, nodelimit);
2523  nodelimit = MIN(sepadata->maxnodelimit, nodelimit);
2524  }
2525  assert( nodelimit >= 0 );
2526  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nodelimit) );
2527 
2528  /* try to create primal solutions of CG-MIP problem via tableau cuts */
2529  if ( sepadata->genprimalsols )
2530  {
2531  SCIP_CALL( SCIPtransformProb(subscip) );
2532  SCIP_CALL( createCGMIPprimalsols(origscip, sepadata, mipdata) );
2533  }
2534 
2535  SCIPdebugMsg(origscip, "Solving sub-SCIP (time limit: %f mem limit: %f node limit: %" SCIP_LONGINT_FORMAT ") ...\n", timelimit, memorylimit, nodelimit);
2536 
2537  /* disable statistic timing inside sub SCIP */
2538  if ( ! sepadata->output )
2539  {
2540  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
2541  }
2542 
2543  /* check whether we want a complete solve */
2544  if ( ! sepadata->earlyterm )
2545  {
2546  retcode = SCIPsolve(subscip);
2547  SCIPdebugMsg(origscip, "Finished solving CG-MIP (dualbound: %g, solving time: %.2f, nodes: %" SCIP_LONGINT_FORMAT ", nodelimit: %" SCIP_LONGINT_FORMAT").\n",
2548  SCIPgetDualbound(subscip), SCIPgetSolvingTime(subscip), SCIPgetNNodes(subscip), nodelimit);
2549 
2550  /* errors in solving the subproblem should not kill the overall solving process;
2551  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop. */
2552  if ( retcode != SCIP_OKAY )
2553  {
2554 #ifndef NDEBUG
2555  SCIP_CALL( retcode );
2556 #endif
2557  SCIPwarningMessage(origscip, "Error while solving subproblem in CGMIP separator; sub-SCIP terminated with code <%d>\n", retcode);
2558  *success = FALSE;
2559  return SCIP_OKAY;
2560  }
2561 
2562  status = SCIPgetStatus(subscip);
2563 
2564 #ifdef SCIP_OUTPUT
2565  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
2566 #else
2567  if ( sepadata->output )
2568  {
2569  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
2570  }
2571 #endif
2572 
2573  /* if the problem is infeasible (can happen because of violation constraint) */
2574  if ( status == SCIP_STATUS_INFEASIBLE || status == SCIP_STATUS_INFORUNBD )
2575  {
2576  SCIPdebugMsg(origscip, "CG-MIP separation problem infeasible.\n");
2577  *success = FALSE;
2578  return SCIP_OKAY;
2579  }
2580 
2581  /* if the solution ran into the time limit */
2582  if ( status == SCIP_STATUS_TIMELIMIT )
2583  {
2584  SCIPdebugMsg(origscip, "CG-MIP separation problem ran into time limit.\n");
2585  *success = FALSE;
2586  return SCIP_OKAY;
2587  }
2588 
2589  /* if the solution process was terminated */
2590  if ( status == SCIP_STATUS_USERINTERRUPT )
2591  {
2592  SCIPdebugMsg(origscip, "CG-MIP separation problem stopped by user interrupt.\n");
2593  *success = FALSE;
2594  return SCIP_OKAY;
2595  }
2596 
2597  /* all other statuses except optimal or node limit are invalid */
2598  if ( status != SCIP_STATUS_OPTIMAL && status != SCIP_STATUS_NODELIMIT )
2599  {
2600  SCIPerrorMessage("Solution of subscip for CG-separation returned with invalid status %d.\n", status);
2601  return SCIP_ERROR;
2602  }
2603  }
2604  else
2605  {
2606  /* otherwise we want a heuristic solve */
2607 
2608  /* -> solve until first solution is found */
2609  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", 1) );
2610  retcode = SCIPsolve(subscip);
2611  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", -1) );
2612 
2613  /* errors in solving the subproblem should not kill the overall solving process;
2614  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop. */
2615  if ( retcode != SCIP_OKAY )
2616  {
2617 #ifndef NDEBUG
2618  SCIP_CALL( retcode );
2619 #endif
2620  SCIPwarningMessage(origscip, "Error while solving subproblem in CGMIP separator; sub-SCIP terminated with code <%d>\n", retcode);
2621  *success = FALSE;
2622  return SCIP_OKAY;
2623  }
2624 
2625  status = SCIPgetStatus(subscip);
2626 
2627  /* if the solution process was terminated or the problem is infeasible (can happen because of violation constraint) */
2628  if ( status == SCIP_STATUS_TIMELIMIT || status == SCIP_STATUS_USERINTERRUPT || status == SCIP_STATUS_NODELIMIT ||
2629  status == SCIP_STATUS_INFEASIBLE || status == SCIP_STATUS_INFORUNBD || status == SCIP_STATUS_MEMLIMIT )
2630  {
2631  /* output statistics before stopping */
2632 #ifdef SCIP_OUTPUT
2633  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
2634 #else
2635  if ( sepadata->output )
2636  {
2637  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
2638  }
2639 #endif
2640  *success = FALSE;
2641  return SCIP_OKAY;
2642  }
2643 
2644  /* all other statuses except optimal or bestsollimit are invalid - (problem cannot be infeasible) */
2645  if ( status != SCIP_STATUS_OPTIMAL && status != SCIP_STATUS_BESTSOLLIMIT )
2646  {
2647  SCIPerrorMessage("Solution of subscip for CG-separation returned with invalid status %d.\n", status);
2648  return SCIP_ERROR;
2649  }
2650 
2651  /* solve some more, if a feasible solution was found */
2652  if ( status == SCIP_STATUS_BESTSOLLIMIT )
2653  {
2654  SCIPdebugMsg(origscip, "Continue solving separation problem (current time: %.2f, nodes: %" SCIP_LONGINT_FORMAT ") ...\n",
2655  SCIPgetSolvingTime(subscip), SCIPgetNNodes(subscip));
2656 
2657  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/stallnodes", STALLNODELIMIT) );
2658  retcode = SCIPsolve(subscip);
2659  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/stallnodes", -1LL) );
2660 
2661  SCIPdebugMsg(origscip, "Finished solving CG-MIP (dualbound: %g, solving time: %.2f, nodes: %" SCIP_LONGINT_FORMAT ", nodelimit: %" SCIP_LONGINT_FORMAT").\n",
2662  SCIPgetDualbound(subscip), SCIPgetSolvingTime(subscip), SCIPgetNNodes(subscip), nodelimit);
2663 
2664  /* errors in solving the subproblem should not kill the overall solving process;
2665  * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop. */
2666  if ( retcode != SCIP_OKAY )
2667  {
2668 #ifndef NDEBUG
2669  SCIP_CALL( retcode );
2670 #endif
2671  SCIPwarningMessage(origscip, "Error while solving subproblem in CGMIP separator; sub-SCIP terminated with code <%d>\n", retcode);
2672  *success = FALSE;
2673  return SCIP_OKAY;
2674  }
2675 
2676  status = SCIPgetStatus(subscip);
2677  assert( status != SCIP_STATUS_BESTSOLLIMIT );
2678 
2679 #ifdef SCIP_OUTPUT
2680  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
2681 #else
2682  if ( sepadata->output )
2683  {
2684  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
2685  }
2686 #endif
2687 
2688  /* if the solution process was terminated */
2689  if ( status == SCIP_STATUS_TIMELIMIT || status == SCIP_STATUS_USERINTERRUPT || status == SCIP_STATUS_MEMLIMIT )
2690  {
2691  *success = FALSE;
2692  return SCIP_OKAY;
2693  }
2694 
2695  /* all other statuses except optimal or bestsollimit are invalid */
2696  if ( status != SCIP_STATUS_OPTIMAL && status != SCIP_STATUS_STALLNODELIMIT && status != SCIP_STATUS_NODELIMIT )
2697  {
2698  SCIPerrorMessage("Solution of subscip for CG-separation returned with invalid status %d.\n", status);
2699  return SCIP_ERROR;
2700  }
2701  }
2702  }
2703 
2704  return SCIP_OKAY;
2705 }
2706 
2707 /** Computes cut from the given multipliers
2708  *
2709  * When computing the cut, we take the fractional part of the multipliers. This is known to produce stronger cuts in
2710  * the pure integer case, since the cut is the sum of the one using fractional parts and integer multiples of the
2711  * original constraints. However, if there are continuous variables, the resulting cut might not be valid. This is
2712  * checked and returned.
2713  *
2714  * Moreover, the cut computed here in general will not be the same as the one computed with the
2715  * sub-MIP, because of numerical differences. Here, we only combine rows whose corresponding
2716  * multiplier is positive w.r.t. the feasibility tolerance. In the sub-MIP, however, the rows are
2717  * combined in any case. This makes a difference, if the coefficients in the matrix are large and
2718  * hence yield a value that is larger than the tolerance.
2719  *
2720  * Because of the transformations we have the following:
2721  *
2722  * If variable \f$x_j\f$ was complemented, we have \f$x'_j = u_j - x_j\f$. If in the transformed
2723  * system the lower bound is used, its corresponding multiplier is \f$y^T A'_j - \lfloor y^T A'_j
2724  * \rfloor\f$, which corresponds to
2725  * \f[
2726  * y^T A'_j - \lfloor y^T A'_j \rfloor = - y^T A_j - \lfloor - y^T A_j \rfloor = - y^T A_j + \lceil y^T A_j \rceil
2727  * \f]
2728  * in the original system.
2729  *
2730  * If such a variable was at its upper bound before the transformation, it is at its lower bound
2731  * afterwards. Hence, its contribution to the cut is 0.
2732  *
2733  * Note that if the original LP-solution does not satisfy some of the rows with equality, the
2734  * violation of the cut might be smaller than what is computed with the reduced sub-MIP.
2735  *
2736  * Furthermore, note that if continuous variables have been shifted, the computed violation may be
2737  * different as well, because the necessary changes in the lhs/rhs are not used here anymore.
2738  *
2739  * @todo Check if cut is correct if continuous variables have been shifted.
2740  */
2741 static
2743  SCIP* scip, /**< original scip */
2744  SCIP_SEPA* sepa, /**< separator */
2745  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
2746  SCIP_SEPADATA* sepadata, /**< separator data */
2747  SCIP_SOL* sol, /**< current solution for sub-MIP */
2748  SCIP_Bool usefrac, /**< use fractional value of multipliers */
2749  SCIP_Real* cutcoefs, /**< coefficients of the cut */
2750  SCIP_Real* cutrhs, /**< rhs of the cut */
2751  SCIP_Bool* localrowsused, /**< pointer to store whether local rows were used in summation */
2752  SCIP_Bool* localboundsused, /**< pointer to store whether local bounds were used in summation */
2753  int* cutrank, /**< pointer to store the cut rank */
2754  SCIP_Bool* success /**< whether we produced a valid cut */
2755  )
2756 {
2757  SCIP* subscip;
2758  SCIP_VAR** vars;
2759  SCIP_ROW** rows;
2760  SCIP_COL** cols;
2761  SCIP_Real val;
2762  SCIP_Real maxabsweight;
2763  int nvars;
2764  int ncols;
2765  int nrows;
2766  int i;
2767  int j;
2768 
2769  assert( scip != NULL );
2770  assert( mipdata != NULL );
2771  assert( sepadata != NULL );
2772  assert( cutcoefs != NULL );
2773  assert( cutrhs != NULL );
2774  assert( localrowsused != NULL );
2775  assert( localboundsused != NULL );
2776  assert( cutrank != NULL );
2777  assert( success != NULL );
2778 
2779  /* initialize */
2780  *localrowsused = FALSE;
2781  *localboundsused = FALSE;
2782  *cutrank = 0;
2783  *success = TRUE;
2784 
2785  subscip = mipdata->subscip;
2786  assert( subscip != NULL );
2787 
2788  /* get data */
2789  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
2790  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
2791  SCIP_CALL( SCIPgetLPColsData(scip, &cols, &ncols) );
2792  assert( nrows == (int) mipdata->nrows );
2793  assert( ncols == (int) mipdata->ncols );
2794 
2795  BMSclearMemoryArray(cutcoefs, nvars);
2796  *cutrhs = 0.0;
2797 
2798  /* find maximal absolute weight */
2799  maxabsweight = 0.0;
2800  for (i = 0; i < nrows; ++i)
2801  {
2802  SCIP_ROW* row;
2803  SCIP_Real absweight = 0.0;
2804 
2805  row = rows[i];
2806  assert( row != NULL );
2807 
2808  /* skip modifiable rows and local rows, unless allowed */
2809  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && !sepadata->allowlocal) )
2810  {
2811  assert( mipdata->ylhs[i] == NULL && mipdata->yrhs[i] == NULL );
2812  continue;
2813  }
2814 
2815  /* get weight from solution (take larger of the values of lhs/rhs) */
2816  if ( mipdata->ylhs[i] != NULL )
2817  {
2818  val = SCIPgetSolVal(subscip, sol, mipdata->ylhs[i]);
2819 
2820  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
2821  if ( usefrac )
2822  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
2823 
2824  if ( SCIPisFeasPositive(scip, val) )
2825  absweight = val;
2826 
2827  assert( ! sepadata->onlyrankone || SCIProwGetOriginSepa(row) != sepa );
2828  }
2829  if ( mipdata->yrhs[i] != NULL )
2830  {
2831  val = SCIPgetSolVal(subscip, sol, mipdata->yrhs[i]);
2832 
2833  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
2834  if ( usefrac )
2835  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
2836 
2837  /* in a suboptimal solution both values may be positive - take the one with larger absolute value */
2838  if ( SCIPisFeasGT(scip, val, absweight) )
2839  absweight = val;
2840 
2841  assert( ! sepadata->onlyrankone || SCIProwGetOriginSepa(row) != sepa );
2842  }
2843  assert( ! SCIPisNegative(scip, absweight) );
2844 
2845  if ( absweight > maxabsweight )
2846  maxabsweight = absweight;
2847  }
2848 
2849  /* get weight from objective cuts */
2850  if ( sepadata->useobjub || sepadata->useobjlb )
2851  {
2852  SCIP_Real absweight = 0.0;
2853 
2854  assert( mipdata->ntotalrows == mipdata->nrows + 1 );
2855 
2856  if ( mipdata->ylhs[mipdata->nrows] != NULL )
2857  {
2858  val = SCIPgetSolVal(subscip, sol, mipdata->ylhs[mipdata->nrows]);
2859  if ( usefrac )
2860  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
2861 
2862  if ( SCIPisFeasPositive(scip, val) )
2863  absweight = val;
2864  }
2865  if ( mipdata->yrhs[mipdata->nrows] != NULL )
2866  {
2867  val = SCIPgetSolVal(subscip, sol, mipdata->yrhs[mipdata->nrows]);
2868  if ( usefrac )
2869  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
2870 
2871  /* in a suboptimal solution both values may be positive - take the one with larger absolute value */
2872  if ( SCIPisFeasGT(scip, val, absweight) )
2873  absweight = val;
2874  }
2875 
2876  if ( absweight > maxabsweight )
2877  maxabsweight = absweight;
2878  }
2879 
2880  /* calculate the row summation */
2881  for (i = 0; i < nrows; ++i)
2882  {
2883  SCIP_ROW* row;
2884  SCIP_Real weight;
2885  SCIP_Real absweight;
2886  SCIP_Bool uselhs;
2887 
2888  row = rows[i];
2889  assert( row != NULL );
2890 
2891  /* skip modifiable rows and local rows, unless allowed */
2892  if ( SCIProwIsModifiable(row) || (SCIProwIsLocal(row) && ! sepadata->allowlocal) )
2893  {
2894  assert( mipdata->ylhs[i] == NULL && mipdata->yrhs[i] == NULL );
2895  continue;
2896  }
2897 
2898  /* get weight from solution */
2899  weight = 0.0;
2900  uselhs = FALSE;
2901  if ( mipdata->ylhs[i] != NULL )
2902  {
2903  val = SCIPgetSolVal(subscip, sol, mipdata->ylhs[i]);
2904  assert( ! SCIPisFeasNegative(subscip, val) );
2905 
2906  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
2907  if ( usefrac )
2908  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
2909 
2910  if ( SCIPisFeasPositive(scip, val) )
2911  {
2912  uselhs = TRUE;
2913  weight = -val;
2914  }
2915  }
2916  if ( mipdata->yrhs[i] != NULL )
2917  {
2918  val = SCIPgetSolVal(subscip, sol, mipdata->yrhs[i]);
2919  assert( ! SCIPisFeasNegative(subscip, val) );
2920 
2921  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
2922  if ( usefrac )
2923  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
2924 
2925  /* in a suboptimal solution both values may be positive - take the one with larger absolute value */
2926  if ( SCIPisFeasGT(scip, val, REALABS(weight)) )
2927  weight = val;
2928  }
2929 
2930  /* add row if weight is nonzero and lies within range */
2931  absweight = REALABS(weight);
2932  if ( ! SCIPisSumZero(scip, weight) && absweight * MAXWEIGHTRANGE >= maxabsweight )
2933  {
2934  SCIP_COL** rowcols;
2935  SCIP_Real* rowvals;
2936 
2937  rowcols = SCIProwGetCols(row);
2938  rowvals = SCIProwGetVals(row);
2939 
2940  /* add the row coefficients to the sum */
2941  for (j = 0; j < SCIProwGetNLPNonz(row); ++j)
2942  {
2943  SCIP_VAR* var;
2944  int idx;
2945 
2946  assert( rowcols[j] != NULL );
2947  var = SCIPcolGetVar(rowcols[j]);
2948 
2949  assert( var != NULL );
2950  assert( SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN );
2951  assert( SCIPvarGetCol(var) == rowcols[j] );
2952 
2953  idx = SCIPvarGetProbindex(var);
2954  assert( 0 <= idx && idx < nvars );
2955 
2956  cutcoefs[idx] += weight * rowvals[j];
2957  }
2958 
2959  /* compute rhs */
2960  if ( uselhs )
2961  {
2962  assert( ! SCIPisInfinity(scip, -SCIProwGetLhs(row)) );
2963  val = SCIProwGetLhs(row) - SCIProwGetConstant(row);
2964  if ( SCIProwIsIntegral(row) )
2965  val = SCIPfeasCeil(scip, val); /* row is integral: round left hand side up */
2966  }
2967  else
2968  {
2969  assert( ! SCIPisInfinity(scip, SCIProwGetRhs(row)) );
2970  val = SCIProwGetRhs(row) - SCIProwGetConstant(row);
2971  if ( SCIProwIsIntegral(row) )
2972  val = SCIPfeasFloor(scip, val); /* row is integral: round right hand side down */
2973  }
2974  *cutrhs += weight * val;
2975 
2976  *localrowsused = *localrowsused || SCIProwIsLocal(row);
2977 
2978  if ( SCIProwGetRank(row) > *cutrank )
2979  *cutrank = SCIProwGetRank(row);
2980  }
2981  }
2982  /* add 1 to cutrank */
2983  ++(*cutrank);
2984 
2985  /* get weight from objective bounds */
2986  if ( sepadata->useobjub || sepadata->useobjlb )
2987  {
2988  SCIP_Real weight = 0.0;
2989  SCIP_Bool uselhs = FALSE;
2990  SCIP_Real absweight;
2991 
2992  assert( mipdata->ntotalrows == mipdata->nrows + 1 );
2993 
2994  if ( mipdata->ylhs[mipdata->nrows] != NULL )
2995  {
2996  val = SCIPgetSolVal(subscip, sol, mipdata->ylhs[mipdata->nrows]);
2997  assert( ! SCIPisFeasNegative(subscip, val) );
2998  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
2999  if ( usefrac )
3000  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3001 
3002  if ( SCIPisFeasPositive(scip, val) )
3003  {
3004  uselhs = TRUE;
3005  weight = -val;
3006  }
3007  }
3008  if ( mipdata->yrhs[mipdata->nrows] != NULL )
3009  {
3010  val = SCIPgetSolVal(subscip, sol, mipdata->yrhs[mipdata->nrows]);
3011  assert( ! SCIPisFeasNegative(subscip, val) );
3012  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
3013  if ( usefrac )
3014  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3015 
3016  /* in a suboptimal solution both values may be positive - take the one with larger absolute value */
3017  if ( SCIPisFeasGT(scip, val, REALABS(weight)) )
3018  weight = val;
3019  }
3020 
3021  /* add objective row if weight is nonzero and lies within range */
3022  absweight = REALABS(weight);
3023  if ( ! SCIPisSumZero(scip, weight) && absweight * MAXWEIGHTRANGE >= maxabsweight )
3024  {
3025  SCIP_Real obj = 0.0;
3026  int idx;
3027 
3028  /* add the objective row coefficients to the sum */
3029  for (j = 0; j < ncols; ++j)
3030  {
3031  assert( cols[j] != NULL );
3032 
3033  obj = SCIPcolGetObj(cols[j]);
3034  if ( ! SCIPisZero(scip, obj) )
3035  {
3036  idx = SCIPvarGetProbindex( SCIPcolGetVar(cols[j]) );
3037  assert( 0 <= idx && idx < nvars );
3038  cutcoefs[idx] += weight * obj;
3039  }
3040  }
3041 
3042  /* compute rhs */
3043  if ( uselhs )
3044  {
3045  val = SCIPgetLowerbound(scip);
3046  assert( ! SCIPisInfinity(scip, -val) );
3047  if ( SCIPisObjIntegral(scip) )
3048  val = SCIPfeasCeil(scip, val); /* objective is integral: round left hand side up */
3049  }
3050  else
3051  {
3052  val = SCIPgetUpperbound(scip);
3053  assert( ! SCIPisInfinity(scip, val) );
3054  if ( SCIPisObjIntegral(scip) )
3055  val = SCIPfeasFloor(scip, val); /* objective is integral: round right hand side down */
3056  }
3057  *cutrhs += weight * val;
3058  }
3059  }
3060 
3061  /* add upper bounds */
3062  for (j = 0; j < ncols; ++j)
3063  {
3064  assert( cols[j] != NULL );
3065  if ( mipdata->z[j] != NULL )
3066  {
3067  assert( mipdata->coltype[j] == colPresent );
3068 
3069  val = SCIPgetSolVal(subscip, sol, mipdata->z[j]);
3070  assert( ! SCIPisFeasNegative(subscip, val) );
3071 
3072  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
3073  if ( usefrac )
3074  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3075 
3076  /* if a bound has been used */
3077  if ( SCIPisSumPositive(subscip, val) )
3078  {
3079  SCIP_VAR* var;
3080  int idx;
3081 
3082  var = SCIPcolGetVar(cols[j]);
3083 
3084  assert( var != NULL );
3085  assert( SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN );
3086  assert( SCIPvarIsIntegral(var) );
3087  assert( SCIPvarGetCol(var) == cols[j] );
3088 
3089  idx = SCIPvarGetProbindex(var);
3090  assert( 0 <= idx && idx < nvars );
3091 
3092  /* check whether variable is complemented */
3093  if ( mipdata->iscomplemented[j] )
3094  {
3095  SCIP_Real lbnd;
3096  lbnd = SCIPvarGetLbGlobal(var);
3097  assert( ! SCIPisInfinity(scip, -lbnd) );
3098  assert( SCIPisIntegral(scip, lbnd) );
3099  assert( SCIPisEQ(scip, SCIPvarGetLbLocal(var), SCIPcolGetLb(cols[j])) );
3100 
3101  /* variable should not be free */
3102  assert( ! SCIPisInfinity(scip, -lbnd) || ! SCIPisInfinity(scip, SCIPvarGetUbGlobal(var)) );
3103 
3104  /* if allowed, try to use stronger local bound */
3105  if ( sepadata->allowlocal && SCIPvarGetLbLocal(var) - 0.5 > lbnd )
3106  {
3107  lbnd = SCIPvarGetLbLocal(var);
3108  assert( SCIPisIntegral(scip, lbnd) );
3109  *localboundsused = TRUE;
3110  }
3111 
3112  cutcoefs[idx] -= val;
3113  *cutrhs -= lbnd * val;
3114  }
3115  else
3116  {
3117  SCIP_Real ubnd;
3118  ubnd = SCIPvarGetUbGlobal(var);
3119  assert( ! SCIPisInfinity(scip, ubnd) );
3120  assert( SCIPisIntegral(scip, ubnd) );
3121  assert( SCIPisEQ(scip, SCIPvarGetUbLocal(var), SCIPcolGetUb(cols[j])) );
3122 
3123  /* if allowed, try to use stronger local bound */
3124  if ( sepadata->allowlocal && SCIPvarGetUbLocal(var) + 0.5 < ubnd )
3125  {
3126  ubnd = SCIPvarGetUbLocal(var);
3127  assert( SCIPisIntegral(scip, ubnd) );
3128  *localboundsused = TRUE;
3129  }
3130 
3131  cutcoefs[idx] += val;
3132  *cutrhs += ubnd * val;
3133  }
3134  }
3135  }
3136  }
3137 
3138  /* check lower bounds for integral variables */
3139  for (j = 0; j < nvars; ++j)
3140  {
3141  SCIP_VAR* var;
3142  int pos;
3143 
3144  var = vars[j];
3145  assert( var != NULL );
3146  pos = SCIPcolGetLPPos(SCIPvarGetCol(var));
3147 
3148  /* a variable may have status COLUMN, but the corresponding column may not (yet) be in the LP */
3149  if ( pos >= 0 && mipdata->coltype[pos] != colContinuous && mipdata->coltype[pos] != colConverted )
3150  {
3151  assert( pos < ncols );
3152  assert( SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN );
3153  assert( SCIPvarIsIntegral(var) );
3154 
3155  /* check whether variable is complemented */
3156  if ( mipdata->iscomplemented[pos] )
3157  {
3158  assert( ! mipdata->isshifted[pos] );
3159  /* if the variable is complemented, the multiplier for the upper bound arises from the
3160  lower bound multiplier for the transformed problem - because of the minus-sign in the
3161  transformation this yields a round-up operation. */
3162  val = SCIPfeasCeil(scip, cutcoefs[j]) - cutcoefs[j];
3163  assert( ! SCIPisFeasNegative(scip, val) );
3164 
3165  /* only if variable needs to be rounded */
3166  if ( SCIPisSumPositive(scip, val) )
3167  {
3168  SCIP_Real ubnd;
3169  ubnd = SCIPvarGetUbGlobal(var);
3170  assert( ! SCIPisInfinity(scip, ubnd) );
3171  assert( SCIPisIntegral(scip, ubnd) );
3172 
3173  /* variable should not be free */
3174  assert( ! SCIPisInfinity(scip, -SCIPvarGetLbGlobal(var)) || ! SCIPisInfinity(scip, ubnd) );
3175 
3176  /* if allowed, try to use stronger local bound */
3177  if ( sepadata->allowlocal && SCIPvarGetUbLocal(var) + 0.5 < ubnd )
3178  {
3179  ubnd = SCIPvarGetUbLocal(var);
3180  assert( SCIPisIntegral(scip, ubnd) );
3181  *localboundsused = TRUE;
3182  }
3183 
3184  /* round cut coefficients, i.e., add val to cutcoefs[j] */
3185  cutcoefs[j] = SCIPfeasCeil(scip, cutcoefs[j]);
3186 
3187  /* correct rhs */
3188  if ( ! SCIPisSumZero(scip, ubnd) )
3189  *cutrhs += ubnd * val;
3190  }
3191  }
3192  else
3193  {
3194  /* compute multiplier for lower bound: */
3195  val = cutcoefs[j] - SCIPfeasFloor(scip, cutcoefs[j]);
3196  assert( ! SCIPisFeasNegative(scip, val) );
3197 
3198  /* only if variable needs to be rounded */
3199  if ( SCIPisSumPositive(scip, val) )
3200  {
3201  SCIP_Real lbnd;
3202  lbnd = SCIPvarGetLbGlobal(var);
3203  assert( ! SCIPisInfinity(scip, -lbnd) );
3204  assert( SCIPisIntegral(scip, lbnd) );
3205 
3206  /* variable should not be free */
3207  assert( ! SCIPisInfinity(scip, -lbnd) || ! SCIPisInfinity(scip, SCIPvarGetUbGlobal(var)) );
3208 
3209  /* if allowed, try to use stronger local bound */
3210  if ( sepadata->allowlocal && SCIPvarGetLbLocal(var) - 0.5 > lbnd )
3211  {
3212  lbnd = SCIPvarGetLbLocal(var);
3213  assert( SCIPisIntegral(scip, lbnd) );
3214  *localboundsused = TRUE;
3215  }
3216 
3217  /* round cut coefficients, i.e., subtract val from cutcoefs[j] */
3218  cutcoefs[j] = SCIPfeasFloor(scip, cutcoefs[j]);
3219 
3220  /* correct rhs */
3221  if ( ! SCIPisSumZero(scip, lbnd) )
3222  *cutrhs -= lbnd * val;
3223  }
3224  }
3225  }
3226  else
3227  {
3228  /* force coefficients of all continuous variables or of variables not in the lp to zero */
3229  assert( pos == -1 || mipdata->coltype[pos] == colContinuous || mipdata->coltype[pos] == colConverted );
3230 
3231  /* check whether all coefficients for continuous or converted variables are nonnegative */
3232  if ( pos >= 0 )
3233  {
3234  if ( SCIPisFeasNegative(scip, cutcoefs[j]) )
3235  {
3236  *success = FALSE;
3237  break;
3238  }
3239  }
3240 
3241  cutcoefs[j] = 0.0;
3242  }
3243  }
3244 
3245  /* round rhs */
3246  *cutrhs = SCIPfeasFloor(scip, *cutrhs);
3247 
3248  return SCIP_OKAY;
3249 }
3250 
3251 /** Create CG-cut directly from solution of sub-MIP */
3252 static
3254  SCIP* scip, /**< SCIP data structure */
3255  SCIP_SEPA* sepa, /**< separator */
3256  SCIP_SEPADATA* sepadata, /**< separator data */
3257  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
3258  SCIP_SOL* sol, /**< solution of sub-MIP */
3259  SCIP_Real* cutcoefs, /**< cut coefficients */
3260  int* cutinds, /**< problem indices of variables appearing in cut */
3261  SCIP_Real* cutvals, /**< values of variables in cut */
3262  SCIP_Real* varsolvals, /**< solution value of variables */
3263  SCIP_Real* weights, /**< weights to compute cmir cut */
3264  int* nprevrows, /**< number of previously generated rows */
3265  SCIP_ROW** prevrows, /**< previously generated rows */
3266  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
3267  unsigned int* ngen /**< number of generated cuts */
3268  )
3269 {
3270  char name[SCIP_MAXSTRLEN];
3271  SCIP_Bool cutislocal;
3272  SCIP_Bool localrowsused;
3273  SCIP_Bool localboundsused;
3274  SCIP_Real cutrhs;
3275  SCIP_Real cutact;
3276  SCIP_Bool success;
3277  SCIP_VAR** vars;
3278  int cutrank = 0;
3279  int nvars;
3280  int k;
3281 
3282  assert( scip != NULL );
3283  assert( sepadata != NULL );
3284  assert( mipdata != NULL );
3285  assert( sol != NULL );
3286  assert( cutcoefs != NULL );
3287  assert( cutinds != NULL );
3288  assert( cutvals != NULL );
3289  assert( varsolvals != NULL );
3290  assert( weights != NULL );
3291  assert( nprevrows != NULL );
3292  assert( prevrows != NULL );
3293  assert( cutoff != NULL );
3294  assert( ngen != NULL );
3295 
3296  /* get variable data */
3297  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
3298 
3299  cutrhs = 0.0;
3300  localrowsused = FALSE;
3301  localboundsused = FALSE;
3302  *cutoff = FALSE;
3303  success = TRUE;
3304 
3305  /* compute coefficients */
3306  SCIP_CALL( computeCut(scip, sepa, mipdata, sepadata, sol, TRUE, cutcoefs, &cutrhs, &localrowsused, &localboundsused, &cutrank, &success) );
3307  cutislocal = localrowsused || localboundsused;
3308 
3309  /* Take next solution if cut was not valid - this can easily happen for mixed-integer problems, see function computeCut(). */
3310  if ( ! success )
3311  {
3312  /* try again without using fractional value */
3313  SCIP_CALL( computeCut(scip, sepa, mipdata, sepadata, sol, FALSE, cutcoefs, &cutrhs, &localrowsused, &localboundsused, &cutrank, &success) );
3314  cutislocal = localrowsused || localboundsused;
3315 
3316  if ( ! success )
3317  {
3318  SCIPdebugMsg(scip, "cut not valid - skipping ...\n");
3319  return SCIP_OKAY;
3320  }
3321  }
3322 
3323  /* compute activity */
3324  cutact = 0.0;
3325  for (k = 0; k < nvars; ++k)
3326  cutact += cutcoefs[k] * varsolvals[k];
3327 
3328 #ifdef SCIP_DISABLED_CODE
3329  /* the following test should be treated with care because of numerical differences - see computeCut() */
3330  {
3331  /* check for correctness of computed values */
3332  SCIP* subscip;
3333  SCIP_Real obj = 0.0;
3334  SCIP_Real val;
3335  SCIP_Bool contVarShifted = FALSE;
3336  unsigned int j;
3337  SCIP_COL** cols;
3338  int ncols;
3339 
3340  subscip = mipdata->subscip;
3341  assert( subscip != NULL );
3342 
3343  SCIP_CALL( SCIPprintSol(subscip, sol, NULL, FALSE) );
3344 
3345  SCIP_CALL( SCIPgetLPColsData(scip, &cols, &ncols) );
3346  for (j = 0; j < mipdata->ncols; ++j)
3347  {
3348  if ( mipdata->coltype[j] == colPresent )
3349  {
3350  int idx;
3351  assert( mipdata->alpha[j] != NULL );
3352  val = SCIPgetSolVal(subscip, sol, mipdata->alpha[j]);
3353  assert( SCIPisFeasIntegral(subscip, val) );
3354  idx = SCIPvarGetProbindex(SCIPcolGetVar(cols[j]));
3355  assert( SCIPisFeasEQ(scip, val, cutcoefs[idx]) );
3356  obj += val * SCIPvarGetObj(mipdata->alpha[j]);
3357  }
3358  else
3359  {
3360  if ( (mipdata->coltype[j] == colContinuous || mipdata->coltype[j] == colConverted) && mipdata->isshifted[j] )
3361  contVarShifted = TRUE;
3362  }
3363  }
3364  assert( mipdata->beta != NULL );
3365  val = SCIPgetSolVal(subscip, sol, mipdata->beta);
3366  assert( SCIPisFeasIntegral(subscip, val) );
3367  obj += val * SCIPvarGetObj(mipdata->beta);
3368  assert( contVarShifted || SCIPisFeasEQ(scip, obj, cutact - cutrhs) );
3369  }
3370 #endif
3371 
3372  /* if successful, convert dense cut into sparse row, and add the row as a cut */
3373  if ( SCIPisFeasGT(scip, cutact, cutrhs) )
3374  {
3375  SCIP_Real cutnorm;
3376  int cutlen;
3377 
3378  /* store the cut as sparse row, calculate activity and norm of cut */
3379  SCIP_CALL( storeCutInArrays(scip, nvars, cutcoefs, varsolvals, mipdata->normtype,
3380  cutinds, cutvals, &cutlen, &cutact, &cutnorm) );
3381 
3382  SCIPdebugMsg(scip, "act=%f, rhs=%f, norm=%f, eff=%f\n", cutact, cutrhs, cutnorm, (cutact - cutrhs)/cutnorm);
3383 
3384  /* if norm is 0, the cut is trivial */
3385  if ( SCIPisPositive(scip, cutnorm) )
3386  {
3387  SCIP_Bool violated = SCIPisEfficacious(scip, (cutact - cutrhs)/cutnorm);
3388 
3389  if ( violated || (sepadata->usecutpool && ! cutislocal ) )
3390  {
3391  SCIP_ROW* cut;
3392 
3393  /* create the cut */
3394  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "cgcut%" SCIP_LONGINT_FORMAT "_%u", SCIPgetNLPs(scip), *ngen);
3395  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, &cut, sepa, name, -SCIPinfinity(scip), cutrhs, cutislocal, FALSE, sepadata->dynamiccuts) );
3396  SCIP_CALL( SCIPcacheRowExtensions(scip, cut) );
3397 
3398  for (k = 0; k < cutlen; ++k)
3399  {
3400  SCIP_CALL( SCIPaddVarToRow(scip, cut, vars[cutinds[k]], cutvals[k]) );
3401  }
3402 
3403  /* set cut rank */
3404  SCIProwChgRank(cut, cutrank);
3405 
3406  SCIP_CALL( SCIPflushRowExtensions(scip, cut) );
3407 
3408  /*SCIPdebug( SCIP_CALL( SCIPprintRow(scip, cut, NULL) ) );*/
3409 
3410  /* add cut to pool */
3411  if ( ! cutislocal )
3412  {
3413  assert( violated || sepadata->usecutpool );
3414  SCIP_CALL( SCIPaddPoolCut(scip, cut) );
3415  }
3416 
3417  /* add cut if it is violated */
3418  if ( violated )
3419  {
3420  /* check whether cut has been found before - may happened due to projection */
3421  for (k = 0; k < *nprevrows; ++k)
3422  {
3423  SCIP_Real parval;
3424 
3425  assert( prevrows[k] != NULL );
3426  parval = SCIProwGetParallelism(cut, prevrows[k], 'e');
3427  /* exit if row is parallel to existing cut and rhs is not better */
3428  if ( SCIPisEQ(scip, parval, 1.0) && SCIPisGE(scip, cutrhs, SCIProwGetRhs(prevrows[k])) )
3429  break;
3430  }
3431 
3432  /* if cut is new */
3433  if ( k >= *nprevrows )
3434  {
3435  prevrows[*nprevrows] = cut;
3436  ++(*nprevrows);
3437 
3438  SCIPdebugMsg(scip, " -> CG-cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
3439  name, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
3440  SCIPgetCutEfficacy(scip, NULL, cut),
3441  SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
3442  SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut));
3443 #ifdef SCIP_DEBUG
3444  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3445 #else
3446  if ( sepadata->output )
3447  {
3448  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3449  }
3450 #endif
3451  SCIP_CALL( SCIPaddRow(scip, cut, FALSE, cutoff) );
3452  ++(*ngen);
3453  }
3454  else
3455  {
3456  SCIPdebugMsg(scip, "Cut already exists.\n");
3457  /* release the row */
3458  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3459  }
3460  }
3461  else
3462  {
3463  /* release the row */
3464  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3465  }
3466  }
3467  }
3468  }
3469 
3470  return SCIP_OKAY;
3471 }
3472 
3473 
3474 /** create CG-cut via CMIR-function */
3475 static
3477  SCIP* scip, /**< SCIP data structure */
3478  SCIP_SEPA* sepa, /**< separator */
3479  SCIP_SEPADATA* sepadata, /**< separator data */
3480  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
3481  SCIP_SOL* sol, /**< solution of sub-MIP */
3482  SCIP_AGGRROW* aggrrow, /**< aggregation row to use for creating MIR cut */
3483  SCIP_Real* cutcoefs, /**< cut coefficients */
3484  int* cutinds, /**< problem indices of variables appearing in cut */
3485  SCIP_Real* cutvals, /**< values of variables in cut */
3486  SCIP_Real* varsolvals, /**< solution value of variables */
3487  SCIP_Real* weights, /**< weights to compute cmir cut */
3488  int* boundsfortrans, /**< bounds for cmir function of NULL */
3489  SCIP_BOUNDTYPE* boundtypesfortrans, /**< type of bounds for cmir function or NULL */
3490  int* nprevrows, /**< number of previously generated rows */
3491  SCIP_ROW** prevrows, /**< previously generated rows */
3492  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
3493  unsigned int* ngen /**< number of generated cuts */
3494  )
3495 {
3496  char name[SCIP_MAXSTRLEN];
3497  SCIP_Longint maxdnom;
3498  SCIP_Bool cutislocal;
3499  SCIP_Real maxscale;
3500  SCIP_Real cutrhs;
3501  SCIP_Real cutefficacy;
3502  SCIP_Bool success;
3503  SCIP_ROW** rows;
3504  SCIP_VAR** vars;
3505  SCIP* subscip;
3506  int nrows;
3507  int nvars;
3508  int k;
3509  int cutrank;
3510  int cutnnz;
3511 
3512  assert( scip != NULL );
3513  assert( sepadata != NULL );
3514  assert( mipdata != NULL );
3515  assert( sol != NULL );
3516  assert( cutcoefs != NULL );
3517  assert( cutinds != NULL );
3518  assert( cutvals != NULL );
3519  assert( varsolvals != NULL );
3520  assert( weights != NULL );
3521  assert( nprevrows != NULL );
3522  assert( prevrows != NULL );
3523  assert( cutoff != NULL );
3524  assert( ngen != NULL );
3525 
3526  *cutoff = FALSE;
3527  subscip = mipdata->subscip;
3528  assert( subscip != NULL );
3529 
3530  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
3531  assert( nrows > 0 );
3532  assert( (int) mipdata->nrows == nrows );
3533 
3534  /* @todo more advanced settings - compare sepa_gomory.c */
3535  maxdnom = (SCIP_Longint) sepadata->cutcoefbnd+1;
3536  maxscale = 10000.0;
3537 
3538  /* get variable data */
3539  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
3540 
3541  /* generate weights */
3542  for (k = 0; k < nrows; ++k)
3543  {
3544  SCIP_Real val;
3545 
3546  weights[k] = 0;
3547  if ( mipdata->ylhs[k] != NULL )
3548  {
3549  assert( !SCIProwIsModifiable(rows[k]) && (!SCIProwIsLocal(rows[k]) || sepadata->allowlocal) );
3550 
3551  val = SCIPgetSolVal(subscip, sol, mipdata->ylhs[k]);
3552  assert( ! SCIPisFeasNegative(subscip, val) );
3553 
3554  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
3555  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3556 
3557  if ( SCIPisFeasPositive(subscip, val) )
3558  weights[k] = -val;
3559  }
3560 
3561  if ( mipdata->yrhs[k] != NULL )
3562  {
3563  assert( !SCIProwIsModifiable(rows[k]) && (!SCIProwIsLocal(rows[k]) || sepadata->allowlocal) );
3564 
3565  val = SCIPgetSolVal(subscip, sol, mipdata->yrhs[k]);
3566  assert( ! SCIPisFeasNegative(subscip, val) );
3567 
3568  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
3569  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3570 
3571  /* in a suboptimal solution both values may be positive - take the one with larger absolute value */
3572  if ( SCIPisFeasGT(scip, val, ABS(weights[k])) )
3573  weights[k] = val;
3574  }
3575  }
3576 
3577  /* set up data for bounds to use */
3578  if ( sepadata->cmirownbounds )
3579  {
3580  int typefortrans;
3581 
3582  assert( boundsfortrans != NULL );
3583  assert( boundtypesfortrans != NULL );
3584 
3585  if ( sepadata->allowlocal )
3586  typefortrans = -2;
3587  else
3588  typefortrans = -1;
3589 
3590  /* check all variables */
3591  for (k = 0; k < nvars; ++k)
3592  {
3593  int pos;
3594  SCIP_VAR* var;
3595 
3596  var = vars[k];
3597  assert( var != NULL );
3598  pos = SCIPcolGetLPPos(SCIPvarGetCol(var));
3599 
3600  if ( pos < 0 )
3601  continue;
3602 
3603  assert( pos < (int) mipdata->ncols );
3604  assert( SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN );
3605 
3606  boundsfortrans[k] = typefortrans;
3607  boundtypesfortrans[k] = SCIP_BOUNDTYPE_LOWER;
3608 
3609  if ( mipdata->coltype[pos] == colContinuous || mipdata->coltype[pos] == colConverted )
3610  {
3611  assert( SCIPvarIsIntegral(var) || mipdata->coltype[pos] != colContinuous );
3612  continue;
3613  }
3614 
3615  /* check upper bound */
3616  if ( mipdata->z[pos] != NULL && SCIPisSumPositive(subscip, SCIPgetSolVal(subscip, sol, mipdata->z[pos])) )
3617  {
3618  /* check whether variable is complemented */
3619  if ( ! mipdata->iscomplemented[pos] )
3620  boundtypesfortrans[k] = SCIP_BOUNDTYPE_UPPER;
3621  /* otherwise use lower bound */
3622  }
3623  else
3624  {
3625  /* check whether variable is complemented */
3626  if ( mipdata->iscomplemented[pos] )
3627  boundtypesfortrans[k] = SCIP_BOUNDTYPE_UPPER;
3628  /* otherwise use lower bound */
3629  }
3630  }
3631  }
3632 
3633  /* create a MIR cut using the above calculated weights */
3634  cutefficacy = -1.0;
3635  cutrhs = -1.0;
3636  SCIP_CALL( SCIPaggrRowSumRows(scip, aggrrow, weights, NULL, -1, FALSE,
3637  sepadata->allowlocal, 2, (int) MAXAGGRLEN(nvars), &success) );
3638 
3639  if ( ! success )
3640  return SCIP_OKAY;
3641 
3642  SCIP_CALL( SCIPcalcMIR(scip, NULL, POSTPROCESS, BOUNDSWITCH, USEVBDS, sepadata->allowlocal, FIXINTEGRALRHS, boundsfortrans,
3643  boundtypesfortrans, MINFRAC, MAXFRAC, 1.0, aggrrow, cutcoefs, &cutrhs, cutinds, &cutnnz, &cutefficacy,
3644  &cutrank, &cutislocal, &success) );
3645 
3646  assert( sepadata->allowlocal || !cutislocal );
3647  SCIPdebugMsg(scip, "CMIR: success = %u, cut is%sefficacious (cutefficacy: %g, cutrhs: %g)\n", success,
3648  SCIPisEfficacious(scip, cutefficacy) ? " " : " not ", cutefficacy, cutrhs);
3649 
3650  /* If successful, convert dense cut into sparse row, and add the row as a cut only if the cut if violated - if it is
3651  * not violated we might store non-local cuts in the pool. */
3652  if ( success && (SCIPisEfficacious(scip, cutefficacy) || (sepadata->usecutpool && ! cutislocal)) )
3653  {
3654  SCIP_ROW* cut;
3655 
3656  /* create the cut */
3657  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "cgcut%" SCIP_LONGINT_FORMAT "_%u", SCIPgetNLPs(scip), *ngen);
3658  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, &cut, sepa, name, -SCIPinfinity(scip), cutrhs, cutislocal, FALSE, sepadata->dynamiccuts) );
3659 
3660  SCIP_CALL( SCIPcacheRowExtensions(scip, cut) );
3661 
3662  for (k = 0; k < cutnnz; ++k)
3663  {
3664  SCIP_CALL( SCIPaddVarToRow(scip, cut, vars[cutinds[k]], cutcoefs[k]) );
3665  }
3666 
3667  assert( success );
3668 
3669  /* set cut rank */
3670  SCIProwChgRank(cut, cutrank);
3671 
3672 #ifdef SCIP_DEBUG
3673  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3674 #else
3675  if ( sepadata->output )
3676  {
3677  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3678  }
3679 #endif
3680 
3681  /* try to scale the cut to integral values */
3682  SCIP_CALL( SCIPmakeRowIntegral(scip, cut, -SCIPepsilon(scip), SCIPsumepsilon(scip),
3683  maxdnom, maxscale, MAKECONTINTEGRAL, &success) );
3684 
3685  /* if the cut could be made integral */
3686  if ( success )
3687  {
3688  SCIP_CALL( SCIPflushRowExtensions(scip, cut) );
3689 
3690  /* add cut to pool */
3691  if ( ! cutislocal )
3692  {
3693  assert( SCIPisEfficacious(scip, cutefficacy) || sepadata->usecutpool );
3694  SCIP_CALL( SCIPaddPoolCut(scip, cut) );
3695  }
3696 
3697  if ( ! SCIPisCutEfficacious(scip, NULL, cut) )
3698  {
3699  SCIPdebugMsg(scip, " -> CG-cut <%s> no longer efficacious: act=%f, rhs=%f, norm=%f, eff=%f\n",
3700  name, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
3701  SCIPgetCutEfficacy(scip, NULL, cut));
3702 
3703  /* release the row */
3704  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3705  }
3706  else
3707  {
3708  /* check whether cut has been found before - may happend due to projection */
3709  for (k = 0; k < *nprevrows; ++k)
3710  {
3711  SCIP_Real parval;
3712 
3713  assert( prevrows[k] != NULL );
3714  parval = SCIProwGetParallelism(cut, prevrows[k], 'e');
3715  /* exit if row is parallel to existing cut and rhs is not better */
3716  if ( SCIPisEQ(scip, parval, 1.0) && SCIPisGE(scip, cutrhs, SCIProwGetRhs(prevrows[k])) )
3717  break;
3718  }
3719 
3720  /* if cut is new */
3721  if ( k >= *nprevrows )
3722  {
3723  prevrows[*nprevrows] = cut;
3724  ++(*nprevrows);
3725 
3726  SCIPdebugMsg(scip, " -> CG-cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, rank=%d, min=%f, max=%f (range=%f)\n",
3727  name, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
3728  SCIPgetCutEfficacy(scip, NULL, cut), SCIProwGetRank(cut),
3729  SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
3730  SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut));
3731 #ifdef SCIP_OUTPUT
3732  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3733 #else
3734  if ( sepadata->output )
3735  {
3736  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3737  }
3738 #endif
3739  SCIP_CALL( SCIPaddRow(scip, cut, FALSE, cutoff) );
3740  ++(*ngen);
3741  }
3742  else
3743  {
3744  SCIPdebugMsg(scip, "Cut already exists.\n");
3745  /* release the row */
3746  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3747  }
3748  }
3749  }
3750  else
3751  {
3752  SCIPdebugMsg(scip, " -> CG-cut <%s> could not be scaled to integral coefficients: rhs=%f, eff=%f\n",
3753  name, cutefficacy, cutrhs);
3754 
3755  /* release the row */
3756  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3757  }
3758  }
3759 
3760  return SCIP_OKAY;
3761 }
3762 
3763 
3764 /** create CG-cut via strong-CG-function */
3765 static
3767  SCIP* scip, /**< SCIP data structure */
3768  SCIP_SEPA* sepa, /**< separator */
3769  SCIP_SEPADATA* sepadata, /**< separator data */
3770  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
3771  SCIP_SOL* sol, /**< solution of sub-MIP */
3772  SCIP_AGGRROW* aggrrow, /**< aggregation row to use for creating MIR cut */
3773  SCIP_Real* cutcoefs, /**< cut coefficients */
3774  int* cutinds, /**< problem indices of variables appearing in cut */
3775  SCIP_Real* cutvals, /**< values of variables in cut */
3776  SCIP_Real* varsolvals, /**< solution value of variables */
3777  SCIP_Real* weights, /**< weights to compute cmir cut */
3778  int* nprevrows, /**< number of previously generated rows */
3779  SCIP_ROW** prevrows, /**< previously generated rows */
3780  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
3781  unsigned int* ngen /**< number of generated cuts */
3782  )
3783 {
3784  char name[SCIP_MAXSTRLEN];
3785  SCIP_Longint maxdnom;
3786  SCIP_Bool cutislocal;
3787  SCIP_Real maxscale;
3788  SCIP_Real cutrhs;
3789  SCIP_Real cutefficacy;
3790  SCIP_Bool success;
3791  SCIP_ROW** rows;
3792  SCIP_VAR** vars;
3793  SCIP* subscip;
3794  int nrows;
3795  int nvars;
3796  int k;
3797  int cutrank;
3798  int cutnnz;
3799 
3800  assert( scip != NULL );
3801  assert( sepadata != NULL );
3802  assert( mipdata != NULL );
3803  assert( sol != NULL );
3804  assert( cutcoefs != NULL );
3805  assert( cutinds != NULL );
3806  assert( cutvals != NULL );
3807  assert( varsolvals != NULL );
3808  assert( weights != NULL );
3809  assert( nprevrows != NULL );
3810  assert( prevrows != NULL );
3811  assert( cutoff != NULL );
3812  assert( ngen != NULL );
3813 
3814  *cutoff = FALSE;
3815  subscip = mipdata->subscip;
3816  assert( subscip != NULL );
3817 
3818  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
3819  assert( nrows > 0 );
3820  assert( (int) mipdata->nrows == nrows );
3821 
3822  /* @todo more advanced settings - compare sepa_gomory.c */
3823  maxdnom = (SCIP_Longint) sepadata->cutcoefbnd + 1;
3824  maxscale = 10000.0;
3825 
3826  /* get variable data */
3827  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
3828 
3829  /* generate weights */
3830  for (k = 0; k < nrows; ++k)
3831  {
3832  SCIP_Real val;
3833 
3834  weights[k] = 0;
3835  if ( mipdata->ylhs[k] != NULL )
3836  {
3837  assert( !SCIProwIsModifiable(rows[k]) && (!SCIProwIsLocal(rows[k]) || sepadata->allowlocal) );
3838 
3839  val = SCIPgetSolVal(subscip, sol, mipdata->ylhs[k]);
3840  assert( ! SCIPisFeasNegative(subscip, val) );
3841 
3842  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
3843  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3844 
3845  if ( SCIPisFeasPositive(subscip, val) )
3846  weights[k] = -val;
3847  }
3848 
3849  if ( mipdata->yrhs[k] != NULL )
3850  {
3851  assert( !SCIProwIsModifiable(rows[k]) && (!SCIProwIsLocal(rows[k]) || sepadata->allowlocal) );
3852 
3853  val = SCIPgetSolVal(subscip, sol, mipdata->yrhs[k]);
3854  assert( ! SCIPisFeasNegative(subscip, val) );
3855 
3856  assert( sepadata->skipmultbounds || SCIPisFeasLT(subscip, val, 1.0) );
3857  val = SCIPfrac(scip, val); /* take fractional value if variable has no upper bounds */
3858 
3859  /* in a suboptimal solution both values may be positive - take the one with larger absolute value */
3860  if ( SCIPisFeasGT(scip, val, ABS(weights[k])) )
3861  weights[k] = val;
3862  }
3863  }
3864 
3865  /* create a strong CG cut out of the weighted LP rows using the B^-1 row as weights */
3866  cutefficacy = -1.0;
3867  cutrhs = -1.0;
3868  SCIP_CALL( SCIPaggrRowSumRows(scip, aggrrow, weights, NULL, -1, FALSE,
3869  sepadata->allowlocal, 1, (int) MAXAGGRLEN(nvars), &success) );
3870 
3871  if ( ! success )
3872  return SCIP_OKAY;
3873 
3874  SCIP_CALL( SCIPcalcStrongCG(scip, NULL, POSTPROCESS, BOUNDSWITCH, USEVBDS, sepadata->allowlocal, MINFRAC, MAXFRAC,
3875  1.0, aggrrow, cutcoefs, &cutrhs, cutinds, &cutnnz, &cutefficacy, &cutrank, &cutislocal, &success) );
3876 
3877  assert( sepadata->allowlocal || !cutislocal );
3878  SCIPdebugMsg(scip, "Strong-CG: success = %u, cut is%sefficacious (cutefficacy: %g, cutrhs: %g)\n", success,
3879  SCIPisEfficacious(scip, cutefficacy) ? " " : " not ", cutefficacy, cutrhs);
3880 
3881  /* If successful, convert dense cut into sparse row, and add the row as a cut only if the cut if violated - if it is
3882  * not violated we might store non-local cuts in the pool. */
3883  if ( success && (SCIPisEfficacious(scip, cutefficacy) || (sepadata->usecutpool && ! cutislocal)) )
3884  {
3885  SCIP_ROW* cut;
3886 
3887  /* create the cut */
3888  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "cgcut%" SCIP_LONGINT_FORMAT "_%u", SCIPgetNLPs(scip), *ngen);
3889  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, &cut, sepa, name, -SCIPinfinity(scip), cutrhs, cutislocal, FALSE, sepadata->dynamiccuts) );
3890 
3891  SCIP_CALL( SCIPcacheRowExtensions(scip, cut) );
3892 
3893  for (k = 0; k < cutnnz; ++k)
3894  {
3895  SCIP_CALL( SCIPaddVarToRow(scip, cut, vars[cutinds[k]], cutcoefs[k]) );
3896  }
3897 
3898  assert( success );
3899 
3900  /* set cut rank */
3901  SCIProwChgRank(cut, cutrank);
3902 
3903 #ifdef SCIP_DEBUG
3904  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3905 #else
3906  if ( sepadata->output )
3907  {
3908  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3909  }
3910 #endif
3911 
3912  /* try to scale the cut to integral values */
3913  SCIP_CALL( SCIPmakeRowIntegral(scip, cut, -SCIPepsilon(scip), SCIPsumepsilon(scip),
3914  maxdnom, maxscale, MAKECONTINTEGRAL, &success) );
3915 
3916  /* if the cut could be made integral */
3917  if ( success )
3918  {
3919  SCIP_CALL( SCIPflushRowExtensions(scip, cut) );
3920 
3921  /* add cut to pool */
3922  if ( ! cutislocal )
3923  {
3924  assert( SCIPisEfficacious(scip, cutefficacy) || sepadata->usecutpool );
3925  SCIP_CALL( SCIPaddPoolCut(scip, cut) );
3926  }
3927 
3928  if ( ! SCIPisCutEfficacious(scip, NULL, cut) )
3929  {
3930  SCIPdebugMsg(scip, " -> CG-cut <%s> no longer efficacious: act=%f, rhs=%f, norm=%f, eff=%f\n",
3931  name, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
3932  SCIPgetCutEfficacy(scip, NULL, cut));
3933 
3934  /* release the row */
3935  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3936  }
3937  else
3938  {
3939  /* check whether cut has been found before - may happend due to projection */
3940  for (k = 0; k < *nprevrows; ++k)
3941  {
3942  SCIP_Real parval;
3943 
3944  assert( prevrows[k] != NULL );
3945  parval = SCIProwGetParallelism(cut, prevrows[k], 'e');
3946  /* exit if row is parallel to existing cut and rhs is not better */
3947  if ( SCIPisEQ(scip, parval, 1.0) && SCIPisGE(scip, cutrhs, SCIProwGetRhs(prevrows[k])) )
3948  break;
3949  }
3950 
3951  /* if cut is new */
3952  if ( k >= *nprevrows )
3953  {
3954  prevrows[*nprevrows] = cut;
3955  ++(*nprevrows);
3956 
3957  SCIPdebugMsg(scip, " -> CG-cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, rank=%d, min=%f, max=%f (range=%f)\n",
3958  name, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
3959  SCIPgetCutEfficacy(scip, NULL, cut), SCIProwGetRank(cut),
3960  SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
3961  SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut));
3962 #ifdef SCIP_OUTPUT
3963  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3964 #else
3965  if ( sepadata->output )
3966  {
3967  SCIP_CALL( SCIPprintRow(scip, cut, NULL) );
3968  }
3969 #endif
3970  SCIP_CALL( SCIPaddRow(scip, cut, FALSE, cutoff) );
3971  ++(*ngen);
3972  }
3973  else
3974  {
3975  SCIPdebugMsg(scip, "Cut already exists.\n");
3976  /* release the row */
3977  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3978  }
3979  }
3980  }
3981  else
3982  {
3983  SCIPdebugMsg(scip, " -> CG-cut <%s> could not be scaled to integral coefficients: rhs=%f, eff=%f\n",
3984  name, cutefficacy, cutrhs);
3985 
3986  /* release the row */
3987  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
3988  }
3989  }
3990 
3991  return SCIP_OKAY;
3992 }
3993 
3994 
3995 /** Create CG-cuts from solutions of sub-MIP */
3996 static
3998  SCIP* scip, /**< SCIP data structure */
3999  SCIP_SEPA* sepa, /**< separator */
4000  SCIP_SEPADATA* sepadata, /**< separator data */
4001  CGMIP_MIPDATA* mipdata, /**< data for sub-MIP */
4002  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
4003  unsigned int* ngen /**< number of generated cuts */
4004  )
4005 {
4006  SCIP_BOUNDTYPE* boundtypesfortrans;
4007  SCIP_STAGE stage;
4008  SCIP_AGGRROW* aggrrow = NULL;
4009  SCIP_Real* varsolvals;
4010  SCIP_Real* weights;
4011  int* cutinds;
4012  SCIP_Real* cutvals;
4013  SCIP_Real* cutcoefs;
4014  SCIP_ROW** prevrows;
4015  SCIP_SOL** sols;
4016  SCIP_VAR** vars;
4017  SCIP* subscip;
4018  int* boundsfortrans;
4019  int nprevrows;
4020  int ntotalrows;
4021  int nsols;
4022  int nvars;
4023  int k;
4024  int s;
4025 
4026  assert( scip != NULL );
4027  assert( sepadata != NULL );
4028  assert( mipdata != NULL );
4029  assert( cutoff != NULL );
4030  assert( ngen != NULL );
4031 
4032  subscip = mipdata->subscip;
4033  assert( subscip != NULL );
4034 
4035  *cutoff = FALSE;
4036  *ngen = 0;
4037 
4038  /* check if solving was successful and get solutions */
4039  stage = SCIPgetStage(subscip);
4040  if ( stage == SCIP_STAGE_SOLVING || stage == SCIP_STAGE_SOLVED )
4041  nsols = SCIPgetNSols(subscip);
4042  else
4043  nsols = 0;
4044 
4045  /* only if solutions have been found */
4046  if ( nsols == 0 )
4047  return SCIP_OKAY;
4048 
4049  SCIPdebugMsg(scip, "Generating CG-cuts from %d sols (cmir: %u, strong-cg: %u) ...\n", nsols, sepadata->usecmir, sepadata->usestrongcg);
4050 
4051  sols = SCIPgetSols(subscip);
4052 
4053  /* get variable data */
4054  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
4055 
4056  /* allocate temporary memory */
4057  assert(mipdata->ntotalrows <= INT_MAX);
4058  ntotalrows = (int)mipdata->ntotalrows;
4059  assert( ntotalrows >= SCIPgetNLPRows(scip) && ntotalrows <= SCIPgetNLPRows(scip) + 1 );
4060  SCIP_CALL( SCIPallocBufferArray(scip, &cutcoefs, nvars) );
4061  SCIP_CALL( SCIPallocBufferArray(scip, &varsolvals, nvars) );
4062  SCIP_CALL( SCIPallocBufferArray(scip, &cutinds, nvars) );
4063  SCIP_CALL( SCIPallocBufferArray(scip, &cutvals, nvars) );
4064  SCIP_CALL( SCIPallocBufferArray(scip, &weights, ntotalrows) );
4065  SCIP_CALL( SCIPallocBufferArray(scip, &prevrows, 2 * nsols) );
4066 
4067  if ( sepadata->usecmir || sepadata->usestrongcg )
4068  {
4069  SCIP_CALL( SCIPaggrRowCreate(scip, &aggrrow) );
4070  }
4071 
4072  /* prepare arrays for bound information, if requested */
4073  if ( sepadata->usecmir && sepadata->cmirownbounds )
4074  {
4075  SCIP_CALL( SCIPallocBufferArray(scip, &boundsfortrans, nvars) );
4076  SCIP_CALL( SCIPallocBufferArray(scip, &boundtypesfortrans, nvars) );
4077  }
4078  else
4079  {
4080  boundsfortrans = NULL;
4081  boundtypesfortrans = NULL;
4082  }
4083 
4084  /* get solution values */
4085  for (k = 0; k < nvars; ++k)
4086  {
4087  if ( SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_COLUMN )
4088  varsolvals[k] = SCIPvarGetLPSol(vars[k]);
4089  else
4090  varsolvals[k] = 0.0;
4091  }
4092 
4093  /* loop through solutions found */
4094  nprevrows = 0;
4095  for (s = 0; s < nsols; ++s)
4096  {
4097  SCIP_SOL* sol;
4098  sol = sols[s];
4099 
4100  /* generate cuts by the C-MIR and/or Strong-CG functions */
4101  if ( sepadata->usecmir )
4102  {
4103  SCIP_CALL( createCGCutCMIR(scip, sepa, sepadata, mipdata, sol, aggrrow, cutcoefs, cutinds, cutvals, varsolvals, weights,
4104  boundsfortrans, boundtypesfortrans, &nprevrows, prevrows, cutoff, ngen) );
4105  }
4106 
4107  if ( sepadata->usestrongcg )
4108  {
4109  SCIP_CALL( createCGCutStrongCG(scip, sepa, sepadata, mipdata, sol, aggrrow, cutcoefs, cutinds, cutvals, varsolvals, weights,
4110  &nprevrows, prevrows, cutoff, ngen) );
4111  }
4112 
4113  if ( ! sepadata->usecmir && ! sepadata->usestrongcg )
4114  {
4115  SCIP_CALL( createCGCutDirect(scip, sepa, sepadata, mipdata, sol, cutcoefs, cutinds, cutvals, varsolvals, weights,
4116  &nprevrows, prevrows, cutoff, ngen) );
4117 
4118  assert(! sepadata->usecmir && ! sepadata->usestrongcg);
4119  }
4120  }
4121  assert( nprevrows <= 2 * nsols );
4122  assert( sepadata->usecmir || nprevrows <= nsols );
4123  assert( sepadata->usestrongcg || nprevrows <= nsols );
4124 
4125  /* release rows */
4126  for (k = 0; k < nprevrows; ++k)
4127  {
4128  SCIP_CALL( SCIPreleaseRow(scip, &(prevrows[k])) );
4129  }
4130 
4131  if ( sepadata->usecmir || sepadata->usestrongcg )
4132  SCIPaggrRowFree(scip, &aggrrow);
4133 
4134  /* free temporary memory */
4135  SCIPfreeBufferArrayNull(scip, &boundsfortrans);
4136  SCIPfreeBufferArrayNull(scip, &boundtypesfortrans);
4137 
4138  SCIPfreeBufferArray(scip, &prevrows);
4139  SCIPfreeBufferArray(scip, &weights);
4140  SCIPfreeBufferArray(scip, &cutvals);
4141  SCIPfreeBufferArray(scip, &cutinds);
4142  SCIPfreeBufferArray(scip, &varsolvals);
4143  SCIPfreeBufferArray(scip, &cutcoefs);
4144 
4145  return SCIP_OKAY;
4146 }
4147 
4148 
4149 /** frees "subscip" data */
4150 static
4152  SCIP* scip, /**< SCIP data structure */
4153  SCIP_SEPA* sepa, /**< separator data */
4154  CGMIP_MIPDATA* mipdata /**< data for sub-MIP */
4155  )
4156 {
4157  SCIP_SEPADATA* sepadata;
4158  unsigned int i, j;
4159  SCIP* subscip;
4160 
4161  assert( scip != NULL );
4162  assert( sepa != NULL );
4163  assert( mipdata != NULL );
4164 
4165  /* free separator data */
4166  sepadata = SCIPsepaGetData(sepa);
4167  assert( sepadata != NULL );
4168 
4169  SCIPdebugMsg(scip, "Freeing subscip ...\n");
4170 
4171  subscip = mipdata->subscip;
4172  assert( subscip != NULL );
4173 
4174  for (j = 0; j < mipdata->ncols; ++j)
4175  {
4176  if ( mipdata->coltype[j] == colPresent )
4177  {
4178  assert( mipdata->alpha[j] != NULL );
4179  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->alpha[j])) );
4180  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->fracalpha[j])) );
4181  }
4182  }
4183  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->beta)) );
4184  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->fracbeta)) );
4185 
4186  for (i = 0; i < mipdata->nrows; ++i)
4187  {
4188  if ( mipdata->ylhs[i] != NULL )
4189  {
4190  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->ylhs[i])) );
4191  }
4192  if ( mipdata->yrhs[i] != NULL )
4193  {
4194  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->yrhs[i])) );
4195  }
4196  }
4197 
4198  if ( sepadata->useobjub || sepadata->useobjlb )
4199  {
4200  if ( mipdata->yrhs[mipdata->nrows] )
4201  {
4202  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->yrhs[mipdata->nrows])) );
4203  }
4204  if ( mipdata->ylhs[mipdata->nrows] )
4205  {
4206  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->ylhs[mipdata->nrows])) );
4207  }
4208  }
4209 
4210  for (j = 0; j < mipdata->ncols; ++j)
4211  {
4212  if ( mipdata->z[j] != NULL )
4213  {
4214  SCIP_CALL( SCIPreleaseVar(subscip, &(mipdata->z[j])) );
4215  }
4216  }
4217 
4218  SCIP_CALL( SCIPfree(&(mipdata->subscip)) );
4219 
4220  SCIPfreeBlockMemoryArray(scip, &(mipdata->rhs), mipdata->ntotalrows);
4221  SCIPfreeBlockMemoryArray(scip, &(mipdata->lhs), mipdata->ntotalrows);
4222  SCIPfreeBlockMemoryArray(scip, &(mipdata->z), 2*mipdata->ncols); /*lint !e647*/
4223  SCIPfreeBlockMemoryArray(scip, &(mipdata->yrhs), mipdata->ntotalrows);
4224  SCIPfreeBlockMemoryArray(scip, &(mipdata->ylhs), mipdata->ntotalrows);
4225  SCIPfreeBlockMemoryArray(scip, &(mipdata->isshifted), mipdata->ncols);
4226  SCIPfreeBlockMemoryArray(scip, &(mipdata->iscomplemented), mipdata->ncols);
4227  SCIPfreeBlockMemoryArray(scip, &(mipdata->coltype), mipdata->ncols);
4228  SCIPfreeBlockMemoryArray(scip, &(mipdata->fracalpha), mipdata->ncols);
4229  SCIPfreeBlockMemoryArray(scip, &(mipdata->alpha), mipdata->ncols);
4230 
4231  return SCIP_OKAY;
4232 }
4233 
4234 
4235 /*
4236  * Callback methods
4237  */
4238 
4239 
4240 /** initialization method of separator (called after problem was transformed) */
4241 static
4242 SCIP_DECL_SEPAINIT(sepaInitCGMIP)
4243 {
4244  SCIP_SEPADATA* sepadata;
4245 
4246  sepadata = SCIPsepaGetData(sepa);
4247  assert(sepadata != NULL);
4248 
4249  /* create and initialize random number generator */
4250  SCIP_CALL( SCIPcreateRandom(scip, &sepadata->randnumgen, DEFAULT_RANDSEED, TRUE) );
4251 
4252  return SCIP_OKAY;
4253 }
4254 
4255 /** deinitialization method of separator (called before transformed problem is freed) */
4256 static
4257 SCIP_DECL_SEPAEXIT(sepaExitCGMIP)
4258 { /*lint --e{715}*/
4259  SCIP_SEPADATA* sepadata;
4260 
4261  sepadata = SCIPsepaGetData(sepa);
4262  assert(sepadata != NULL);
4263 
4264  SCIPfreeRandom(scip, &sepadata->randnumgen);
4265 
4266  return SCIP_OKAY;
4267 }
4268 
4269 /** copy method for separator plugins (called when SCIP copies plugins) */
4270 static
4271 SCIP_DECL_SEPACOPY(sepaCopyCGMIP)
4272 { /*lint --e{715}*/
4273  assert( scip != NULL );
4274  assert( sepa != NULL );
4275  assert( strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0 );
4276 
4277  /* call inclusion method of constraint handler */
4279 
4280  return SCIP_OKAY;
4281 }
4282 
4283 
4284 /** destructor of separator to free user data (called when SCIP is exiting) */
4285 static
4286 SCIP_DECL_SEPAFREE(sepaFreeCGMIP)
4287 { /*lint --e{715}*/
4288  SCIP_SEPADATA* sepadata;
4289 
4290  assert( scip != NULL );
4291  assert( sepa != NULL );
4292  assert( strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0 );
4293 
4294  /* free separator data */
4295  sepadata = SCIPsepaGetData(sepa);
4296  assert( sepadata != NULL );
4297 
4298  SCIPfreeBlockMemory(scip, &sepadata);
4299 
4300  SCIPsepaSetData(sepa, NULL);
4301 
4302  return SCIP_OKAY;
4303 }
4304 
4305 
4306 /** LP solution separation method of separator */
4307 static
4308 SCIP_DECL_SEPAEXECLP(sepaExeclpCGMIP)
4309 { /*lint --e{715}*/
4310  SCIP_SEPADATA* sepadata;
4311  CGMIP_MIPDATA* mipdata;
4312 
4313  int ncalls;
4314  int ncols;
4315  int nrows;
4316  unsigned int ngen = 0;
4317  SCIP_Bool success;
4318  SCIP_Bool cutoff = FALSE;
4319 
4320  assert( scip != NULL );
4321  assert( sepa != NULL );
4322  assert( strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0 );
4323  assert( result != NULL );
4324 
4325  *result = SCIP_DIDNOTRUN;
4326 
4327  sepadata = SCIPsepaGetData(sepa);
4328  assert(sepadata != NULL);
4329 
4330  /* only call separator, if we are not close to terminating */
4331  if ( SCIPisStopped(scip) )
4332  return SCIP_OKAY;
4333 
4334  /* only call separator up to a maximum depth */
4335  if ( sepadata->maxdepth >= 0 && depth > sepadata->maxdepth )
4336  return SCIP_OKAY;
4337 
4338  /* only call separator a given number of times at each node */
4339  ncalls = SCIPsepaGetNCallsAtNode(sepa);
4340  if ( (depth == 0 && sepadata->maxroundsroot >= 0 && ncalls >= sepadata->maxroundsroot)
4341  || (depth > 0 && sepadata->maxrounds >= 0 && ncalls >= sepadata->maxrounds) )
4342  return SCIP_OKAY;
4343 
4344  /* only call separator, if an optimal LP solution is at hand */
4346  return SCIP_OKAY;
4347 
4348  /* skip separation if there are continuous variables, but only integers required */
4349  if ( SCIPgetNContVars(scip) > 0 && sepadata->onlyintvars )
4350  return SCIP_OKAY;
4351 
4352  /* only call separator, if there are fractional variables */
4353  if ( SCIPgetNLPBranchCands(scip) == 0 )
4354  return SCIP_OKAY;
4355 
4356  /* check for parameters */
4357  if ( ( sepadata->useobjub || sepadata->useobjlb ) && ( sepadata->usecmir || sepadata->usestrongcg ) )
4358  {
4360  "WARNING - sepa_cgmip: Using objective function bounds and CMIR or Strong-CG functions is useless. Turning off usage of objective function bounds.\n");
4361  SCIP_CALL( SCIPsetBoolParam(scip, "separating/cgmip/useobjub", FALSE) );
4362  SCIP_CALL( SCIPsetBoolParam(scip, "separating/cgmip/useobjlb", FALSE) );
4363  }
4364  sepadata->allowlocal = allowlocal;
4365 
4366  /* get LP data */
4367  ncols = SCIPgetNLPCols(scip);
4368  nrows = SCIPgetNLPRows(scip);
4369  if ( ncols <= NCOLSTOOSMALL || nrows <= NROWSTOOSMALL )
4370  return SCIP_OKAY;
4371 
4372  /* determine whether we should run the separation based on a decision tree */
4373  if ( sepadata->decisiontree )
4374  {
4375  SCIP_Bool separate;
4376  SCIP_Real firstlptime;
4377 
4378  separate = FALSE;
4379  firstlptime = SCIPgetFirstLPTime(scip);
4380 
4381  if ( nrows <= 136 && firstlptime <= 0.05 && ncols <= 143 )
4382  separate = TRUE;
4383  else if ( nrows <= 136 && 0.05 < firstlptime && firstlptime <= 0.15 && ncols <= 143 )
4384  separate = TRUE;
4385  else if ( 136 < nrows && nrows <= 332 && ncols <= 143 )
4386  separate = TRUE;
4387  else if ( 136 < nrows && nrows <= 332 && 655 < ncols && ncols <= 1290 )
4388  separate = TRUE;
4389  else if ( 333 < nrows && nrows <= 874 && 0.15 < firstlptime && firstlptime <= 0.25 && 2614 < ncols && ncols <= 5141 )
4390  separate = TRUE;
4391  else if ( 875 < nrows && nrows <= 1676 && firstlptime <= 0.05 && 143 < ncols && ncols <= 265 )
4392  separate = TRUE;
4393  else if ( 875 < nrows && nrows <= 1676 && firstlptime <= 0.05 && 265 < ncols && ncols <= 654 )
4394  separate = TRUE;
4395  else if ( 875 < nrows && nrows <= 1676 && 0.05 < firstlptime && firstlptime <= 0.15 )
4396  separate = TRUE;
4397  else if ( 875 < nrows && nrows <= 1676 && 0.15 < firstlptime && firstlptime <= 0.25 && 1291 < ncols && ncols <= 2613 )
4398  separate = TRUE;
4399  else if ( nrows > 8146 && 0.75 < firstlptime && firstlptime <= 6.25 && 655 < ncols && ncols <= 1290 )
4400  separate = TRUE;
4401  else if ( nrows > 8146 && 0.75 < firstlptime && firstlptime <= 6.25 && 1291 < ncols && ncols <= 2613 )
4402  separate = TRUE;
4403  else if ( nrows > 8146 && firstlptime > 6.25 )
4404  separate = TRUE;
4405 
4406  if ( ! separate )
4407  {
4408  return SCIP_OKAY;
4409  }
4410  }
4411 
4412  /* preceed with separation */
4413  *result = SCIP_DIDNOTFIND;
4414 
4415  SCIPdebugMsg(scip, "separating CG-cuts via sub-MIPs: %d cols, %d rows\n", ncols, nrows);
4416 
4417  /* prepare data */
4418  SCIP_CALL( SCIPallocBlockMemory(scip, &mipdata) );
4419  mipdata->subscip = NULL;
4420  mipdata->alpha = NULL;
4421  mipdata->fracalpha = NULL;
4422  mipdata->beta = NULL;
4423  mipdata->fracbeta = NULL;
4424  mipdata->coltype = NULL;
4425  mipdata->iscomplemented = NULL;
4426  mipdata->isshifted = NULL;
4427  mipdata->ylhs = NULL;
4428  mipdata->yrhs = NULL;
4429  mipdata->z = NULL;
4430  mipdata->lhs = NULL;
4431  mipdata->rhs = NULL;
4432  mipdata->normtype = ' ';
4433 
4434  mipdata->conshdlrfullnorm = CONSHDLRFULLNORM;
4435  mipdata->scip = scip;
4436  mipdata->sepa = sepa;
4437  mipdata->sepadata = sepadata;
4438 
4439  /* get the type of norm to use for efficacy calculations */
4440  SCIP_CALL( SCIPgetCharParam(scip, "separating/efficacynorm", &mipdata->normtype) );
4441 
4442  /* create subscip */
4443  SCIP_CALL( createSubscip(scip, sepa, sepadata, mipdata) );
4444 
4445  /* set parameters */
4446  SCIP_CALL( subscipSetParams(sepadata, mipdata) );
4447 
4448  if ( ! SCIPisStopped(scip) )
4449  {
4450  /* solve subscip */
4451  SCIP_CALL( solveSubscip(scip, sepadata, mipdata, &success) );
4452 
4453  /* preceed if solution was successful */
4454  if ( success && ! SCIPisStopped(scip) )
4455  {
4456  SCIP_CALL( createCGCuts(scip, sepa, sepadata, mipdata, &cutoff, &ngen) );
4457  }
4458  }
4459 
4460  SCIP_CALL( freeSubscip(scip, sepa, mipdata) );
4461  SCIPfreeBlockMemory(scip, &mipdata);
4462 
4463  SCIPdebugMsg(scip, "Found %u CG-cuts.\n", ngen);
4464 
4465  if ( cutoff )
4466  *result = SCIP_CUTOFF;
4467  else if ( ngen > 0 )
4468  *result = SCIP_SEPARATED;
4469 
4470 #ifdef SCIP_OUTPUT
4471  /* SCIP_CALL( SCIPwriteLP(scip, "cuts.lp") ); */
4472  /* SCIP_CALL( SCIPwriteMIP(scip, "cuts.lp", FALSE, TRUE) ); */
4473 #endif
4474 
4475  return SCIP_OKAY;
4476 }
4477 
4478 /*
4479  * separator specific interface methods
4480  */
4481 
4482 /** creates the CGMIP MIR cut separator and includes it in SCIP */
4484  SCIP* scip /**< SCIP data structure */
4485  )
4486 {
4487  SCIP_SEPADATA* sepadata;
4488  SCIP_SEPA* sepa = NULL;
4489 
4490  /* create separator data */
4491  SCIP_CALL( SCIPallocBlockMemory(scip, &sepadata) );
4492 
4493  /* include separator */
4495  SEPA_USESSUBSCIP, SEPA_DELAY, sepaExeclpCGMIP, NULL, sepadata) );
4496  assert(sepa != NULL);
4497 
4498  SCIP_CALL( SCIPsetSepaCopy(scip, sepa, sepaCopyCGMIP) );
4499  SCIP_CALL( SCIPsetSepaFree(scip, sepa, sepaFreeCGMIP) );
4500  SCIP_CALL( SCIPsetSepaInit(scip, sepa, sepaInitCGMIP) );
4501  SCIP_CALL( SCIPsetSepaExit(scip, sepa, sepaExitCGMIP) );
4502 
4503  /* add separator parameters */
4504  SCIP_CALL( SCIPaddIntParam(scip,
4505  "separating/" SEPA_NAME "/maxrounds",
4506  "maximal number of cgmip separation rounds per node (-1: unlimited)",
4507  &sepadata->maxrounds, FALSE, DEFAULT_MAXROUNDS, -1, INT_MAX, NULL, NULL) );
4508 
4509  SCIP_CALL( SCIPaddIntParam(scip,
4510  "separating/" SEPA_NAME "/maxroundsroot",
4511  "maximal number of cgmip separation rounds in the root node (-1: unlimited)",
4512  &sepadata->maxroundsroot, FALSE, DEFAULT_MAXROUNDSROOT, -1, INT_MAX, NULL, NULL) );
4513 
4514  SCIP_CALL( SCIPaddIntParam(scip,
4515  "separating/" SEPA_NAME "/maxdepth",
4516  "maximal depth at which the separator is applied (-1: unlimited)",
4517  &sepadata->maxdepth, FALSE, DEFAULT_MAXDEPTH, -1, INT_MAX, NULL, NULL) );
4518 
4520  "separating/" SEPA_NAME "/decisiontree",
4521  "Use decision tree to turn separation on/off?",
4522  &sepadata->decisiontree, FALSE, DEFAULT_DECISIONTREE, NULL, NULL) );
4523 
4525  "separating/" SEPA_NAME "/timelimit",
4526  "time limit for sub-MIP",
4527  &sepadata->timelimit, TRUE, DEFAULT_TIMELIMIT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
4528 
4530  "separating/" SEPA_NAME "/memorylimit",
4531  "memory limit for sub-MIP",
4532  &sepadata->memorylimit, TRUE, DEFAULT_MEMORYLIMIT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
4533 
4535  "separating/" SEPA_NAME "/minnodelimit",
4536  "minimum number of nodes considered for sub-MIP (-1: unlimited)",
4537  &sepadata->minnodelimit, FALSE, DEFAULT_MINNODELIMIT, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
4538 
4540  "separating/" SEPA_NAME "/maxnodelimit",
4541  "maximum number of nodes considered for sub-MIP (-1: unlimited)",
4542  &sepadata->maxnodelimit, FALSE, DEFAULT_MAXNODELIMIT, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
4543 
4545  "separating/" SEPA_NAME "/cutcoefbnd",
4546  "bounds on the values of the coefficients in the CG-cut",
4547  &sepadata->cutcoefbnd, TRUE, DEFAULT_CUTCOEFBND, 0.0, SCIP_REAL_MAX, NULL, NULL) );
4548 
4550  "separating/" SEPA_NAME "/onlyactiverows",
4551  "Use only active rows to generate cuts?",
4552  &sepadata->onlyactiverows, FALSE, DEFAULT_ONLYACTIVEROWS, NULL, NULL) );
4553 
4554  SCIP_CALL( SCIPaddIntParam(scip,
4555  "separating/" SEPA_NAME "/maxrowage",
4556  "maximal age of rows to consider if onlyactiverows is false",
4557  &sepadata->maxrowage, FALSE, DEFAULT_MAXROWAGE, -1, INT_MAX, NULL, NULL) );
4558 
4560  "separating/" SEPA_NAME "/onlyrankone",
4561  "Separate only rank 1 inequalities w.r.t. CG-MIP separator?",
4562  &sepadata->onlyrankone, FALSE, DEFAULT_ONLYRANKONE, NULL, NULL) );
4563 
4565  "separating/" SEPA_NAME "/onlyintvars",
4566  "Generate cuts for problems with only integer variables?",
4567  &sepadata->onlyintvars, FALSE, DEFAULT_ONLYINTVARS, NULL, NULL) );
4568 
4570  "separating/" SEPA_NAME "/contconvert",
4571  "Convert some integral variables to be continuous to reduce the size of the sub-MIP?",
4572  &sepadata->contconvert, FALSE, DEFAULT_CONTCONVERT, NULL, NULL) );
4573 
4575  "separating/" SEPA_NAME "/contconvfrac",
4576  "fraction of integral variables converted to be continuous (if contconvert)",
4577  &sepadata->contconvfrac, FALSE, DEFAULT_CONTCONVFRAC, 0.0, 1.0, NULL, NULL) );
4578 
4579  SCIP_CALL( SCIPaddIntParam(scip,
4580  "separating/" SEPA_NAME "/contconvmin",
4581  "minimum number of integral variables before some are converted to be continuous",
4582  &sepadata->contconvmin, FALSE, DEFAULT_CONTCONVMIN, -1, INT_MAX, NULL, NULL) );
4583 
4585  "separating/" SEPA_NAME "/intconvert",
4586  "Convert some integral variables attaining fractional values to have integral value?",
4587  &sepadata->intconvert, FALSE, DEFAULT_INTCONVERT, NULL, NULL) );
4588 
4590  "separating/" SEPA_NAME "/intconvfrac",
4591  "fraction of frac. integral variables converted to have integral value (if intconvert)",
4592  &sepadata->intconvfrac, FALSE, DEFAULT_INTCONVFRAC, 0.0, 1.0, NULL, NULL) );
4593 
4594  SCIP_CALL( SCIPaddIntParam(scip,
4595  "separating/" SEPA_NAME "/intconvmin",
4596  "minimum number of integral variables before some are converted to have integral value",
4597  &sepadata->intconvmin, FALSE, DEFAULT_INTCONVMIN, -1, INT_MAX, NULL, NULL) );
4598 
4600  "separating/" SEPA_NAME "/skipmultbounds",
4601  "Skip the upper bounds on the multipliers in the sub-MIP?",
4602  &sepadata->skipmultbounds, FALSE, DEFAULT_SKIPMULTBOUNDS, NULL, NULL) );
4603 
4605  "separating/" SEPA_NAME "/objlone",
4606  "Should the objective of the sub-MIP minimize the l1-norm of the multipliers?",
4607  &sepadata->objlone, FALSE, DEFAULT_OBJLONE, NULL, NULL) );
4608 
4610  "separating/" SEPA_NAME "/objweight",
4611  "weight used for the row combination coefficient in the sub-MIP objective",
4612  &sepadata->objweight, TRUE, DEFAULT_OBJWEIGHT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
4613 
4615  "separating/" SEPA_NAME "/objweightsize",
4616  "Weight each row by its size?",
4617  &sepadata->objweightsize, FALSE, DEFAULT_OBJWEIGHTSIZE, NULL, NULL) );
4618 
4620  "separating/" SEPA_NAME "/dynamiccuts",
4621  "should generated cuts be removed from the LP if they are no longer tight?",
4622  &sepadata->dynamiccuts, FALSE, DEFAULT_DYNAMICCUTS, NULL, NULL) );
4623 
4625  "separating/" SEPA_NAME "/usecmir",
4626  "use CMIR-generator (otherwise add cut directly)?",
4627  &sepadata->usecmir, FALSE, DEFAULT_USECMIR, NULL, NULL) );
4628 
4630  "separating/" SEPA_NAME "/usestrongcg",
4631  "use strong CG-function to strengthen cut?",
4632  &sepadata->usestrongcg, FALSE, DEFAULT_USESTRONGCG, NULL, NULL) );
4633 
4635  "separating/" SEPA_NAME "/cmirownbounds",
4636  "tell CMIR-generator which bounds to used in rounding?",
4637  &sepadata->cmirownbounds, FALSE, DEFAULT_CMIROWNBOUNDS, NULL, NULL) );
4638 
4640  "separating/" SEPA_NAME "/usecutpool",
4641  "use cutpool to store CG-cuts even if the are not efficient?",
4642  &sepadata->usecutpool, FALSE, DEFAULT_USECUTPOOL, NULL, NULL) );
4643 
4645  "separating/" SEPA_NAME "/primalseparation",
4646  "only separate cuts that are tight for the best feasible solution?",
4647  &sepadata->primalseparation, FALSE, DEFAULT_PRIMALSEPARATION, NULL, NULL) );
4648 
4650  "separating/" SEPA_NAME "/earlyterm",
4651  "terminate separation if a violated (but possibly sub-optimal) cut has been found?",
4652  &sepadata->earlyterm, FALSE, DEFAULT_EARLYTERM, NULL, NULL) );
4653 
4655  "separating/" SEPA_NAME "/addviolationcons",
4656  "add constraint to subscip that only allows violated cuts (otherwise add obj. limit)?",
4657  &sepadata->addviolationcons, FALSE, DEFAULT_ADDVIOLATIONCONS, NULL, NULL) );
4658 
4660  "separating/" SEPA_NAME "/addviolconshdlr",
4661  "add constraint handler to filter out violated cuts?",
4662  &sepadata->addviolconshdlr, FALSE, DEFAULT_ADDVIOLCONSHDLR, NULL, NULL) );
4663 
4665  "separating/" SEPA_NAME "/conshdlrusenorm",
4666  "should the violation constraint handler use the norm of a cut to check for feasibility?",
4667  &sepadata->conshdlrusenorm, FALSE, DEFAULT_CONSHDLRUSENORM, NULL, NULL) );
4668 
4670  "separating/" SEPA_NAME "/useobjub",
4671  "Use upper bound on objective function (via primal solution)?",
4672  &sepadata->useobjub, FALSE, DEFAULT_USEOBJUB, NULL, NULL) );
4673 
4675  "separating/" SEPA_NAME "/useobjlb",
4676  "Use lower bound on objective function (via primal solution)?",
4677  &sepadata->useobjlb, FALSE, DEFAULT_USEOBJLB, NULL, NULL) );
4678 
4680  "separating/" SEPA_NAME "/subscipfast",
4681  "Should the settings for the sub-MIP be optimized for speed?",
4682  &sepadata->subscipfast, FALSE, DEFAULT_SUBSCIPFAST, NULL, NULL) );
4683 
4685  "separating/" SEPA_NAME "/output",
4686  "Should information about the sub-MIP and cuts be displayed?",
4687  &sepadata->output, FALSE, DEFAULT_OUTPUT, NULL, NULL) );
4688 
4690  "separating/" SEPA_NAME "/genprimalsols",
4691  "Try to generate primal solutions from Gomory cuts?",
4692  &sepadata->genprimalsols, FALSE, DEFAULT_GENPRIMALSOLS, NULL, NULL) );
4693 
4694  return SCIP_OKAY;
4695 }
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
static SCIP_RETCODE createCGMIPprimalsols(SCIP *scip, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata)
Definition: sepa_cgmip.c:2193
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:110
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:59
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2090
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPcalcStrongCG(SCIP *scip, SCIP_SOL *sol, SCIP_Bool postprocess, SCIP_Real boundswitch, SCIP_Bool usevbds, SCIP_Bool allowlocal, 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:8975
SCIP_RETCODE SCIPgetCharParam(SCIP *scip, const char *name, char *value)
Definition: scip_param.c:326
void SCIPaggrRowFree(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1763
SCIP_RETCODE SCIPgetLPBInvRow(SCIP *scip, int r, SCIP_Real *coefs, int *inds, int *ninds)
Definition: scip_lp.c:714
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:378
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:958
#define DEFAULT_INTCONVERT
Definition: sepa_cgmip.c:130
SCIP_SEPADATA * sepadata
Definition: struct_sepa.h:73
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:93
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1635
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_OUTPUT
Definition: sepa_cgmip.c:150
public methods for SCIP parameter handling
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:365
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIProwGetAge(SCIP_ROW *row)
Definition: lp.c:17374
SCIP_SEPA * SCIProwGetOriginSepa(SCIP_ROW *row)
Definition: lp.c:17479
static SCIP_RETCODE createCGCutCMIR(SCIP *scip, SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata, SCIP_SOL *sol, SCIP_AGGRROW *aggrrow, SCIP_Real *cutcoefs, int *cutinds, SCIP_Real *cutvals, SCIP_Real *varsolvals, SCIP_Real *weights, int *boundsfortrans, SCIP_BOUNDTYPE *boundtypesfortrans, int *nprevrows, SCIP_ROW **prevrows, SCIP_Bool *cutoff, unsigned int *ngen)
Definition: sepa_cgmip.c:3476
#define MAXNSOLS
Definition: sepa_cgmip.c:163
public methods for memory management
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1658
#define DEFAULT_OBJLONE
Definition: sepa_cgmip.c:134
#define MAXWEIGHTRANGE
Definition: sepa_cgmip.c:174
#define DEFAULT_CMIROWNBOUNDS
Definition: sepa_cgmip.c:140
enum CGMIP_ColType CGMIP_COLTYPE
Definition: sepa_cgmip.c:235
enum SCIP_BaseStat SCIP_BASESTAT
Definition: type_lpi.h:96
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17923
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip_param.c:307
#define SCIP_MAXSTRLEN
Definition: def.h:302
#define BETAEPSILONVALUE
Definition: sepa_cgmip.c:159
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
Definition: scip_prob.c:117
#define STALLNODELIMIT
Definition: sepa_cgmip.c:160
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
Definition: lp.c:17164
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1698
SCIP_Bool SCIPisSumPositive(SCIP *scip, SCIP_Real val)
static SCIP_DECL_CONSFREE(consFreeViolatedCuts)
Definition: sepa_cgmip.c:508
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17979
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public solving methods
public methods for timing
#define USEVBDS
Definition: sepa_cgmip.c:168
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17354
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip_var.c:1248
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
int SCIProwGetNLPNonz(SCIP_ROW *row)
Definition: lp.c:17230
#define FIXINTEGRALRHS
Definition: sepa_cgmip.c:172
static SCIP_DECL_SEPAINIT(sepaInitCGMIP)
Definition: sepa_cgmip.c:4242
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1874
#define DEFAULT_INTCONVMIN
Definition: sepa_cgmip.c:132
SCIP_SOL ** SCIPgetSols(SCIP *scip)
Definition: scip_sol.c:2263
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:17295
#define FALSE
Definition: def.h:96
#define CONSHDLR_NAME
Definition: sepa_cgmip.c:281
methods for the aggregation rows
#define DEFAULT_CUTCOEFBND
Definition: sepa_cgmip.c:120
SCIP_Bool SCIPcolIsIntegral(SCIP_COL *col)
Definition: lp.c:17075
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:111
SCIP_Real SCIPcolGetUb(SCIP_COL *col)
Definition: lp.c:16976
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
Definition: scip_cons.c:175
SCIP_BASESTAT SCIProwGetBasisStatus(SCIP_ROW *row)
Definition: lp.c:17343
SCIP_Real SCIPcolGetObj(SCIP_COL *col)
Definition: lp.c:16956
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10788
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
#define TRUE
Definition: def.h:95
const char * SCIPsepaGetName(SCIP_SEPA *sepa)
Definition: sepa.c:743
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_RETCODE SCIPwriteOrigProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
Definition: scip_prob.c:609
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:932
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17613
#define NROWSTOOSMALL
Definition: sepa_cgmip.c:155
public methods for problem variables
#define DEFAULT_USEOBJLB
Definition: sepa_cgmip.c:148
#define DEFAULT_CONTCONVMIN
Definition: sepa_cgmip.c:129
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:108
#define CONSHDLR_DESC
Definition: sepa_cgmip.c:282
#define SEPA_PRIORITY
Definition: sepa_cgmip.c:108
static SCIP_RETCODE SCIPincludeConshdlrViolatedCut(SCIP *scip, CGMIP_MIPDATA *mipdata)
Definition: sepa_cgmip.c:601
#define DEFAULT_EARLYTERM
Definition: sepa_cgmip.c:143
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIP_LONGINT_MAX
Definition: def.h:172
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:136
#define DEFAULT_MAXDEPTH
Definition: sepa_cgmip.c:116
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:292
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:89
SCIP_RETCODE SCIPgetLPColsData(SCIP *scip, SCIP_COL ***cols, int *ncols)
Definition: scip_lp.c:471
int SCIPgetNLPBranchCands(SCIP *scip)
Definition: scip_branch.c:428
public methods for SCIP variables
SCIP_RETCODE SCIPsetSepaCopy(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: scip_sepa.c:151
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip_param.c:603
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:120
#define SCIPdebugMsg
Definition: scip_message.h:78
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:83
SCIP_Bool SCIPisSumZero(SCIP *scip, SCIP_Real val)
public methods for separator plugins
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
#define SEPA_USESSUBSCIP
Definition: sepa_cgmip.c:111
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:208
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2180
static SCIP_RETCODE solCutIsViolated(SCIP *scip, CGMIP_MIPDATA *mipdata, SCIP_SOL *sol, SCIP_Bool *violated)
Definition: sepa_cgmip.c:309
SCIP_Real SCIPepsilon(SCIP *scip)
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1919
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
#define MAXAGGRLEN(nvars)
Definition: sepa_cgmip.c:178
public methods for numerical tolerances
SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:633
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
public methods for querying solving statistics
#define DEFAULT_TIMELIMIT
Definition: sepa_cgmip.c:118
const char * SCIPgetProbName(SCIP *scip)
Definition: scip_prob.c:1075
public methods for the branch-and-bound tree
#define DEFAULT_USEOBJUB
Definition: sepa_cgmip.c:147
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17933
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:117
public methods for managing constraints
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
Definition: scip_prob.c:1250
SCIP_Real SCIPcolGetPrimsol(SCIP_COL *col)
Definition: lp.c:16999
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2624
#define DEFAULT_ADDVIOLATIONCONS
Definition: sepa_cgmip.c:144
#define DEFAULT_DECISIONTREE
Definition: sepa_cgmip.c:117
#define DEFAULT_ONLYINTVARS
Definition: sepa_cgmip.c:126
SCIP_Real SCIPgetRowMinCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1901
#define DEFAULT_MAXROUNDSROOT
Definition: sepa_cgmip.c:115
#define SCIPerrorMessage
Definition: pub_message.h:64
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:219
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2778
#define MAKECONTINTEGRAL
Definition: sepa_cgmip.c:173
#define NCOLSTOOSMALL
Definition: sepa_cgmip.c:156
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
Definition: lp.c:17154
#define DEFAULT_MINNODELIMIT
Definition: sepa_cgmip.c:121
SCIP_RETCODE SCIPsetSepaExit(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAEXIT((*sepaexit)))
Definition: scip_sepa.c:199
#define DEFAULT_ONLYACTIVEROWS
Definition: sepa_cgmip.c:123
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:17404
SCIP_Real SCIPgetDualbound(SCIP *scip)
static SCIP_RETCODE createSubscip(SCIP *origscip, SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata)
Definition: sepa_cgmip.c:1046
struct CGMIP_MIPData CGMIP_MIPDATA
Definition: sepa_cgmip.c:273
#define DEFAULT_GENPRIMALSOLS
Definition: sepa_cgmip.c:152
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:137
int SCIPsepaGetNCallsAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:880
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:429
SCIP_STATUS SCIPgetStatus(SCIP *scip)
Definition: scip_general.c:483
#define BOUNDSWITCH
Definition: sepa_cgmip.c:167
SCIP_Bool SCIPisEfficacious(SCIP *scip, SCIP_Real efficacy)
Definition: scip_cut.c:135
static SCIP_DECL_CONSCHECK(consCheckViolatedCuts)
Definition: sepa_cgmip.c:566
static SCIP_DECL_CONSLOCK(consLockViolatedCuts)
Definition: sepa_cgmip.c:592
SCIP_Real SCIPcolGetLb(SCIP_COL *col)
Definition: lp.c:16966
#define DEFAULT_OBJWEIGHTSIZE
Definition: sepa_cgmip.c:136
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip_cons.c:366
SCIP_Bool SCIProwIsIntegral(SCIP_ROW *row)
Definition: lp.c:17394
void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:643
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4202
#define NULL
Definition: lpi_spx1.cpp:164
#define DEFAULT_MAXROWAGE
Definition: sepa_cgmip.c:124
static SCIP_DECL_SEPAEXECLP(sepaExeclpCGMIP)
Definition: sepa_cgmip.c:4308
#define DEFAULT_CONSHDLRUSENORM
Definition: sepa_cgmip.c:146
#define REALABS(x)
Definition: def.h:210
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
Definition: var.c:18297
#define MINEFFICACY
Definition: sepa_cgmip.c:162
int SCIPgetNLPRows(SCIP *scip)
Definition: scip_lp.c:626
public methods for problem copies
#define DEFAULT_ONLYRANKONE
Definition: sepa_cgmip.c:125
#define SCIP_CALL(x)
Definition: def.h:394
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPsetEmphasis(SCIP *scip, SCIP_PARAMEMPHASIS paramemphasis, SCIP_Bool quiet)
Definition: scip_param.c:861
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE subscipSetParams(SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata)
Definition: sepa_cgmip.c:2049
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:17305
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:225
#define DEFAULT_SUBSCIPFAST
Definition: sepa_cgmip.c:149
SCIP_Real SCIPgetRowLPActivity(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1990
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:250
#define DEFAULT_PRIMALSEPARATION
Definition: sepa_cgmip.c:142
static SCIP_Real computeObjWeightSize(int rowsize, int minrowsize, int maxrowsize)
Definition: sepa_cgmip.c:888
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:17414
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:17241
#define DEFAULT_SKIPMULTBOUNDS
Definition: sepa_cgmip.c:133
public methods for constraint handler plugins and constraints
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:109
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
SCIP_RETCODE SCIPincludeSepaCGMIP(SCIP *scip)
Definition: sepa_cgmip.c:4483
#define DEFAULT_RANDSEED
Definition: sepa_cgmip.c:151
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:3879
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:124
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1221
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:17251
#define DEFAULT_USECUTPOOL
Definition: sepa_cgmip.c:141
public data structures and miscellaneous methods
static SCIP_RETCODE createCGCutStrongCG(SCIP *scip, SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata, SCIP_SOL *sol, SCIP_AGGRROW *aggrrow, SCIP_Real *cutcoefs, int *cutinds, SCIP_Real *cutvals, SCIP_Real *varsolvals, SCIP_Real *weights, int *nprevrows, SCIP_ROW **prevrows, SCIP_Bool *cutoff, unsigned int *ngen)
Definition: sepa_cgmip.c:3766
#define SCIP_Bool
Definition: def.h:93
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:168
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2135
static SCIP_DECL_SEPAEXIT(sepaExitCGMIP)
Definition: sepa_cgmip.c:4257
#define MAXFRAC
Definition: sepa_cgmip.c:171
enum SCIP_Status SCIP_STATUS
Definition: type_stat.h:67
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip_prob.c:1430
#define MAX(x, y)
Definition: tclique_def.h:92
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: scip_sol.c:3241
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:361
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:487
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:1453
SCIP_Real SCIPgetCutEfficacy(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:94
public methods for cuts and aggregation rows
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17771
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
Definition: scip_var.c:114
#define MINFRAC
Definition: sepa_cgmip.c:170
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2214
static SCIP_DECL_SEPACOPY(sepaCopyCGMIP)
Definition: sepa_cgmip.c:4271
#define DEFAULT_OBJWEIGHT
Definition: sepa_cgmip.c:135
#define DEFAULT_DYNAMICCUTS
Definition: sepa_cgmip.c:137
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17634
SCIP_RETCODE SCIPgetLPBasisInd(SCIP *scip, int *basisind)
Definition: scip_lp.c:686
static SCIP_RETCODE solveSubscip(SCIP *origscip, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata, SCIP_Bool *success)
Definition: sepa_cgmip.c:2442
#define AWAY
Definition: sepa_cgmip.c:175
Constraint handler for linear constraints in their most general form, .
int SCIPgetNObjVars(SCIP *scip)
Definition: scip_prob.c:2228
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
static SCIP_RETCODE computeCut(SCIP *scip, SCIP_SEPA *sepa, CGMIP_MIPDATA *mipdata, SCIP_SEPADATA *sepadata, SCIP_SOL *sol, SCIP_Bool usefrac, SCIP_Real *cutcoefs, SCIP_Real *cutrhs, SCIP_Bool *localrowsused, SCIP_Bool *localboundsused, int *cutrank, SCIP_Bool *success)
Definition: sepa_cgmip.c:2742
static SCIP_DECL_SEPAFREE(sepaFreeCGMIP)
Definition: sepa_cgmip.c:4286
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2045
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
Definition: misc.c:10041
public methods for the LP relaxation, rows and columns
int SCIProwGetRank(SCIP_ROW *row)
Definition: lp.c:17384
#define DEFAULT_USESTRONGCG
Definition: sepa_cgmip.c:139
#define SCIP_REAL_MAX
Definition: def.h:187
SCIP_Real SCIProwGetParallelism(SCIP_ROW *row1, SCIP_ROW *row2, char orthofunc)
Definition: lp.c:7728
SCIP_Real * r
Definition: circlepacking.c:59
#define CONSHDLRFULLNORM
Definition: sepa_cgmip.c:161
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:17261
public methods for branching rule plugins and branching
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1562
SCIP_Bool SCIPisObjIntegral(SCIP *scip)
Definition: scip_prob.c:1570
static SCIP_RETCODE freeSubscip(SCIP *scip, SCIP_SEPA *sepa, CGMIP_MIPDATA *mipdata)
Definition: sepa_cgmip.c:4151
static SCIP_RETCODE storeCutInArrays(SCIP *scip, int nvars, SCIP_Real *cutcoefs, SCIP_Real *varsolvals, char normtype, int *cutinds, SCIP_Real *cutvals, int *cutlen, SCIP_Real *cutact, SCIP_Real *cutnorm)
Definition: sepa_cgmip.c:637
general public methods
#define DEFAULT_USECMIR
Definition: sepa_cgmip.c:138
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip_sepa.c:167
SCIP_RETCODE SCIPsetSepaInit(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAINIT((*sepainit)))
Definition: scip_sepa.c:183
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2313
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
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:2287
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:17045
public methods for solutions
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:100
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip_prob.c:1676
public methods for random numbers
void SCIProwChgRank(SCIP_ROW *row, int rank)
Definition: lp.c:17537
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1119
#define DEFAULT_MAXROUNDS
Definition: sepa_cgmip.c:114
public methods for message output
#define DEFAULT_CONTCONVERT
Definition: sepa_cgmip.c:127
#define DEFAULT_INTCONVFRAC
Definition: sepa_cgmip.c:131
SCIP_VAR * a
Definition: circlepacking.c:66
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
Chvatal-Gomory cuts computed via a sub-MIP.
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:126
#define DEFAULT_ADDVIOLCONSHDLR
Definition: sepa_cgmip.c:145
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17383
int SCIProwGetLPPos(SCIP_ROW *row)
Definition: lp.c:17504
#define SCIP_Real
Definition: def.h:186
enum SCIP_Stage SCIP_STAGE
Definition: type_set.h:59
static SCIP_DECL_CONSENFOLP(consEnfolpViolatedCuts)
Definition: sepa_cgmip.c:525
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:703
#define SEPA_DESC
Definition: sepa_cgmip.c:107
public methods for message handling
#define SCIP_INVALID
Definition: def.h:206
SCIP_RETCODE SCIPaggrRowCreate(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1731
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2209
#define SCIP_Longint
Definition: def.h:171
#define POSTPROCESS
Definition: sepa_cgmip.c:169
#define SEPA_DELAY
Definition: sepa_cgmip.c:112
SCIP_Real SCIPfrac(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3244
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17429
#define SEPA_FREQ
Definition: sepa_cgmip.c:109
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip_solve.c:367
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
Definition: type_cons.h:64
SCIP_Real SCIPgetVarSol(SCIP *scip, SCIP_VAR *var)
Definition: scip_var.c:2307
#define OBJWEIGHTRANGE
Definition: sepa_cgmip.c:164
int SCIPgetNLPCols(SCIP *scip)
Definition: scip_lp.c:527
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17989
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
static SCIP_RETCODE createCGCutDirect(SCIP *scip, SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata, SCIP_SOL *sol, SCIP_Real *cutcoefs, int *cutinds, SCIP_Real *cutvals, SCIP_Real *varsolvals, SCIP_Real *weights, int *nprevrows, SCIP_ROW **prevrows, SCIP_Bool *cutoff, unsigned int *ngen)
Definition: sepa_cgmip.c:3253
SCIP_RETCODE SCIPwriteParams(SCIP *scip, const char *filename, SCIP_Bool comments, SCIP_Bool onlychanged)
Definition: scip_param.c:792
static SCIP_RETCODE transformColumn(SCIP *scip, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata, SCIP_COL *col, SCIP_Real offset, SCIP_Real sigma, SCIP_Real *lhs, SCIP_Real *rhs, SCIP_Real *lb, SCIP_Real *ub, SCIP_Real *primsol)
Definition: sepa_cgmip.c:777
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
#define DEFAULT_MEMORYLIMIT
Definition: sepa_cgmip.c:119
static SCIP_RETCODE createCGCuts(SCIP *scip, SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata, CGMIP_MIPDATA *mipdata, SCIP_Bool *cutoff, unsigned int *ngen)
Definition: sepa_cgmip.c:3997
#define DEFAULT_MAXNODELIMIT
Definition: sepa_cgmip.c:122
public methods for separators
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:132
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip_lp.c:570
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Longint SCIPgetNLPs(SCIP *scip)
public methods for global and local (sub)problems
int SCIPcolGetNLPNonz(SCIP_COL *col)
Definition: lp.c:17143
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:17455
int SCIPcolGetLPPos(SCIP_COL *col)
Definition: lp.c:17096
static SCIP_DECL_CONSENFOPS(consEnfopsViolatedCuts)
Definition: sepa_cgmip.c:552
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:1841
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1361
default SCIP plugins
#define SEPA_NAME
Definition: sepa_cgmip.c:106
SCIP_Real SCIProwGetNorm(SCIP_ROW *row)
Definition: lp.c:17271
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:139
#define EPSILONVALUE
Definition: sepa_cgmip.c:158
SCIP_Real SCIPgetFirstLPTime(SCIP *scip)
Definition: scip_timing.c:468
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip_param.c:883
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
#define DEFAULT_CONTCONVFRAC
Definition: sepa_cgmip.c:128
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:545
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:52
#define SEPA_MAXBOUNDDIST
Definition: sepa_cgmip.c:110
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:57
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:324
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:328
CGMIP_ColType
Definition: sepa_cgmip.c:227
memory allocation routines
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
Definition: scip_sol.c:1775