Scippy

SCIP

Solving Constraint Integer Programs

sepa_aggregation.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-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file sepa_aggregation.c
17  * @brief flow cover and complemented mixed integer rounding cuts separator (Marchand's version)
18  * @author Robert Lion Gottwald
19  * @author Kati Wolter
20  * @author Tobias Achterberg
21  *
22  * For an overview see:
23  *
24  * Marchand, H., & Wolsey, L. A. (2001).@n
25  * Aggregation and mixed integer rounding to solve MIPs.@n
26  * Operations research, 49(3), 363-371.
27  *
28  * Some remarks:
29  * - In general, continuous variables are less prefered than integer variables, since their cut
30  * coefficient is worse.
31  * - We seek for aggregations that project out continuous variables that are far away from their bound,
32  * since if it is at its bound then it doesn't contribute to the violation
33  * - These aggregations are also useful for the flowcover separation, so after building an aggregation
34  * we try to generate a MIR cut and a flowcover cut.
35  * - We only keep the best cut.
36  */
37 
38 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
39 
40 #include "blockmemshell/memory.h"
41 #include "scip/cuts.h"
42 #include "scip/pub_lp.h"
43 #include "scip/pub_message.h"
44 #include "scip/pub_misc.h"
45 #include "scip/pub_misc_sort.h"
46 #include "scip/pub_sepa.h"
47 #include "scip/pub_var.h"
48 #include "scip/scip_branch.h"
49 #include "scip/scip_cut.h"
50 #include "scip/scip_general.h"
51 #include "scip/scip_lp.h"
52 #include "scip/scip_mem.h"
53 #include "scip/scip_message.h"
54 #include "scip/scip_numerics.h"
55 #include "scip/scip_param.h"
56 #include "scip/scip_prob.h"
57 #include "scip/scip_sepa.h"
58 #include "scip/scip_sol.h"
59 #include "scip/scip_solvingstats.h"
60 #include "scip/scip_tree.h"
61 #include "scip/scip_var.h"
62 #include "scip/sepa_aggregation.h"
63 #include <string.h>
64 
65 
66 #define SEPA_NAME "aggregation"
67 #define SEPA_DESC "aggregation heuristic for complemented mixed integer rounding cuts and flowcover cuts"
68 #define SEPA_PRIORITY -3000
69 #define SEPA_FREQ 10
70 #define SEPA_MAXBOUNDDIST 1.0
71 #define SEPA_USESSUBSCIP FALSE /**< does the separator use a secondary SCIP instance? */
72 #define SEPA_DELAY FALSE /**< should separation method be delayed, if other separators found cuts? */
73 
74 #define DEFAULT_MAXROUNDS -1 /**< maximal number of cmir separation rounds per node (-1: unlimited) */
75 #define DEFAULT_MAXROUNDSROOT -1 /**< maximal number of cmir separation rounds in the root node (-1: unlimited) */
76 #define DEFAULT_MAXTRIES 200 /**< maximal number of rows to start aggregation with per separation round
77  * (-1: unlimited) */
78 #define DEFAULT_MAXTRIESROOT -1 /**< maximal number of rows to start aggregation with per round in the root node
79  * (-1: unlimited) */
80 #define DEFAULT_MAXFAILS 20 /**< maximal number of consecutive unsuccessful aggregation tries (-1: unlimited) */
81 #define DEFAULT_MAXFAILSROOT 100 /**< maximal number of consecutive unsuccessful aggregation tries in the root node
82  * (-1: unlimited) */
83 #define DEFAULT_MAXAGGRS 3 /**< maximal number of aggregations for each row per separation round */
84 #define DEFAULT_MAXAGGRSROOT 6 /**< maximal number of aggregations for each row per round in the root node */
85 #define DEFAULT_MAXSEPACUTS 100 /**< maximal number of cmir cuts separated per separation round */
86 #define DEFAULT_MAXSEPACUTSROOT 500 /**< maximal number of cmir cuts separated per separation round in root node */
87 #define DEFAULT_MAXSLACK 0.0 /**< maximal slack of rows to be used in aggregation */
88 #define DEFAULT_MAXSLACKROOT 0.1 /**< maximal slack of rows to be used in aggregation in the root node */
89 #define DEFAULT_DENSITYSCORE 1e-4 /**< weight of row density in the aggregation scoring of the rows */
90 #define DEFAULT_SLACKSCORE 1e-3 /**< weight of slack in the aggregation scoring of the rows */
91 #define DEFAULT_MAXAGGDENSITY 0.20 /**< maximal density of aggregated row */
92 #define DEFAULT_MAXROWDENSITY 0.05 /**< maximal density of row to be used in aggregation */
93 #define DEFAULT_DENSITYOFFSET 100 /**< additional number of variables allowed in row on top of density */
94 #define DEFAULT_MAXROWFAC 1e+4 /**< maximal row aggregation factor */
95 #define DEFAULT_MAXTESTDELTA -1 /**< maximal number of different deltas to try (-1: unlimited) */
96 #define DEFAULT_AGGRTOL 1e-2 /**< aggregation heuristic: we try to delete continuous variables from the current
97  * aggregation, whose distance to its tightest bound is >= L - DEFAULT_AGGRTOL,
98  * where L is the largest of the distances between a continuous variable's value
99  * and its tightest bound in the current aggregation */
100 #define DEFAULT_TRYNEGSCALING TRUE /**< should negative values also be tested in scaling? */
101 #define DEFAULT_FIXINTEGRALRHS TRUE /**< should an additional variable be complemented if f0 = 0? */
102 #define DEFAULT_DYNAMICCUTS TRUE /**< should generated cuts be removed from the LP if they are no longer tight? */
103 
104 #define BOUNDSWITCH 0.5
105 #define POSTPROCESS TRUE
106 #define USEVBDS TRUE
107 #define MINFRAC 0.05
108 #define MAXFRAC 0.999
109 #define MAKECONTINTEGRAL FALSE
110 #define IMPLINTSARECONT
113 /*
114  * Data structures
115  */
117 /** separator data */
118 struct SCIP_SepaData
119 {
120  SCIP_Real maxslack; /**< maximal slack of rows to be used in aggregation */
121  SCIP_Real maxslackroot; /**< maximal slack of rows to be used in aggregation in the root node */
122  SCIP_Real densityscore; /**< weight of row density in the aggregation scoring of the rows */
123  SCIP_Real slackscore; /**< weight of slack in the aggregation scoring of the rows */
124  SCIP_Real maxaggdensity; /**< maximal density of aggregated row */
125  SCIP_Real maxrowdensity; /**< maximal density of row to be used in aggregation */
126  SCIP_Real maxrowfac; /**< maximal row aggregation factor */
127  SCIP_Real aggrtol; /**< tolerance for bound distance used in aggregation heuristic */
128  int maxrounds; /**< maximal number of cmir separation rounds per node (-1: unlimited) */
129  int maxroundsroot; /**< maximal number of cmir separation rounds in the root node (-1: unlimited) */
130  int maxtries; /**< maximal number of rows to start aggregation with per separation round
131  * (-1: unlimited) */
132  int maxtriesroot; /**< maximal number of rows to start aggregation with per round in the root node
133  * (-1: unlimited) */
134  int maxfails; /**< maximal number of consecutive unsuccessful aggregation tries
135  * (-1: unlimited) */
136  int maxfailsroot; /**< maximal number of consecutive unsuccessful aggregation tries in the root
137  * node (-1: unlimited) */
138  int maxaggrs; /**< maximal number of aggregations for each row per separation round */
139  int maxaggrsroot; /**< maximal number of aggregations for each row per round in the root node */
140  int maxsepacuts; /**< maximal number of cmir cuts separated per separation round */
141  int maxsepacutsroot; /**< maximal number of cmir cuts separated per separation round in root node */
142  int densityoffset; /**< additional number of variables allowed in row on top of density */
143  int maxtestdelta; /**< maximal number of different deltas to try (-1: unlimited) */
144  SCIP_Bool trynegscaling; /**< should negative values also be tested in scaling? */
145  SCIP_Bool fixintegralrhs; /**< should an additional variable be complemented if f0 = 0? */
146  SCIP_Bool dynamiccuts; /**< should generated cuts be removed from the LP if they are no longer tight? */
147  SCIP_Bool sepflowcover; /**< whether flowcover cuts should be separated in the current call */
148  SCIP_Bool sepcmir; /**< whether cMIR cuts should be separated in the current call */
149  SCIP_SEPA* cmir; /**< separator for adding cmir cuts */
150  SCIP_SEPA* flowcover; /**< separator for adding flowcover cuts */
151 };
152 
153 /** data used for aggregation of row */
154 typedef
155 struct AggregationData {
156  SCIP_Real* bounddist; /**< bound distance of continuous variables */
157  int* bounddistinds; /**< problem indices of the continUous variables corresponding to the bounddistance value */
158  int nbounddistvars; /**< number of continuous variables that are not at their bounds */
159  SCIP_ROW** aggrrows; /**< array of rows suitable for substitution of continuous variable */
160  SCIP_Real* aggrrowscoef; /**< coefficient of continuous variable in row that is suitable for substitution of that variable */
161  int aggrrowssize; /**< size of aggrrows array */
162  int naggrrows; /**< occupied positions in aggrrows array */
163  int* aggrrowsstart; /**< array with start positions of suitable rows for substitution for each
164  * continuous variable with non-zero bound distance */
165  int* ngoodaggrrows; /**< array with number of rows suitable for substitution that only contain
166  * one continuous variable that is not at it's bound */
167  int* nbadvarsinrow; /**< number of continuous variables that are not at their bounds for each row */
168  SCIP_AGGRROW* aggrrow; /**< store aggregation row here so that it can be reused */
170 
171 /*
172  * Local methods
173  */
175 /** adds given cut to LP if violated */
176 static
178  SCIP* scip, /**< SCIP data structure */
179  SCIP_SOL* sol, /**< the solution that should be separated, or NULL for LP solution */
180  SCIP_SEPA* sepa, /**< separator */
181  SCIP_Bool makeintegral, /**< should cut be scaled to integral coefficients if possible? */
182  SCIP_Real* cutcoefs, /**< coefficients of active variables in cut */
183  int* cutinds, /**< problem indices of variables in cut */
184  int cutnnz, /**< number of non-zeros in cut */
185  SCIP_Real cutrhs, /**< right hand side of cut */
186  SCIP_Real cutefficacy, /**< efficacy of cut */
187  SCIP_Bool cutislocal, /**< is the cut only locally valid? */
188  SCIP_Bool cutremovable, /**< should the cut be removed from the LP due to aging or cleanup? */
189  int cutrank, /**< rank of the cut */
190  const char* cutclassname, /**< name of cut class to use for row names */
191  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
192  int* ncuts, /**< pointer to count the number of added cuts */
193  SCIP_ROW** thecut /**< pointer to return cut if it was added */
194  )
195 {
196  assert(scip != NULL);
197  assert(cutcoefs != NULL);
198  assert(cutoff != NULL);
199  assert(ncuts != NULL);
200 
201  *cutoff = FALSE;
202 
203  if( cutnnz > 0 && SCIPisEfficacious(scip, cutefficacy) )
204  {
205  SCIP_VAR** vars;
206  int i;
207  SCIP_ROW* cut;
208  char cutname[SCIP_MAXSTRLEN];
209  SCIP_Bool success;
210 
211  /* get active problem variables */
212  vars = SCIPgetVars(scip);
213 
214  /* create cut name */
215  (void) SCIPsnprintf(cutname, SCIP_MAXSTRLEN, "%s%d_%d", cutclassname, SCIPgetNLPs(scip), *ncuts);
216 
217 tryagain:
218  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, &cut, sepa, cutname, -SCIPinfinity(scip), cutrhs, cutislocal, FALSE, cutremovable) );
219 
220  SCIP_CALL( SCIPcacheRowExtensions(scip, cut) );
221 
222  for( i = 0; i < cutnnz; ++i )
223  {
224  SCIP_CALL( SCIPaddVarToRow(scip, cut, vars[cutinds[i]], cutcoefs[i]) );
225  }
226 
227  /* set cut rank */
228  SCIProwChgRank(cut, cutrank);
229 
230  SCIPdebugMsg(scip, " -> found potential %s cut <%s>: rhs=%f, eff=%f\n", cutclassname, cutname, cutrhs, cutefficacy);
231  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, cut, NULL) ) );
232 
233  /* if requested, try to scale the cut to integral values but only if the scaling is small; otherwise keep the fractional cut */
234  if( makeintegral && SCIPgetRowNumIntCols(scip, cut) == SCIProwGetNNonz(cut) )
235  {
236  SCIP_CALL( SCIPmakeRowIntegral(scip, cut, -SCIPepsilon(scip), SCIPsumepsilon(scip),
237  1000LL, 1000.0, MAKECONTINTEGRAL, &success) );
238 
239  if( SCIPisInfinity(scip, SCIProwGetRhs(cut)) )
240  {
241  /* release the row */
242  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
243 
244  /* the scaling destroyed the cut, so try to add it again, but this time do not scale it */
245  makeintegral = FALSE;
246  goto tryagain;
247  }
248  }
249  else
250  {
251  success = FALSE;
252  }
253 
254  if( success && !SCIPisCutEfficacious(scip, sol, cut) )
255  {
256  SCIPdebugMsg(scip, " -> %s cut <%s> no longer efficacious: rhs=%f, eff=%f\n", cutclassname, cutname, cutrhs, cutefficacy);
257  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, cut, NULL) ) );
258 
259  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
260 
261  /* the cut is not efficacious anymore due to the scaling, so do not add it */
262  return SCIP_OKAY;
263  }
264 
265  SCIPdebugMsg(scip, " -> found %s cut <%s>: rhs=%f, eff=%f, rank=%d, min=%f, max=%f (range=%g)\n",
266  cutclassname, cutname, cutrhs, cutefficacy, SCIProwGetRank(cut),
267  SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
268  SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut));
269  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, cut, NULL) ) );
270 
271  SCIP_CALL( SCIPflushRowExtensions(scip, cut) );
272 
273  if( SCIPisCutNew(scip, cut) )
274  {
275  (*ncuts)++;
276 
277  if( !cutislocal )
278  {
279  SCIP_CALL( SCIPaddPoolCut(scip, cut) );
280  }
281  else
282  {
283  SCIP_CALL( SCIPaddRow(scip, cut, FALSE, cutoff) );
284  }
285 
286  *thecut = cut;
287  }
288  else
289  {
290  /* release the row */
291  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
292  }
293  }
294 
295  return SCIP_OKAY;
296 }
297 
298 /** setup data for aggregating rows */
299 static
301  SCIP* scip, /**< SCIP data structure */
302  SCIP_SOL* sol, /**< solution to separate, NULL for LP solution */
303  SCIP_Bool allowlocal, /**< should local cuts be allowed */
304  AGGREGATIONDATA* aggrdata /**< pointer to aggregation data to setup */
305  )
306 {
307  SCIP_VAR** vars;
308  int nvars;
309  int nbinvars;
310  int nintvars;
311  int ncontvars;
312  int firstcontvar;
313  int nimplvars;
314  SCIP_ROW** rows;
315  int nrows;
316  int i;
317 
318  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, &nimplvars, &ncontvars) );
319  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
320 
321  SCIP_CALL( SCIPallocBufferArray(scip, &aggrdata->bounddist, ncontvars + nimplvars) );
322  SCIP_CALL( SCIPallocBufferArray(scip, &aggrdata->bounddistinds, ncontvars + nimplvars) );
323  SCIP_CALL( SCIPallocBufferArray(scip, &aggrdata->ngoodaggrrows, ncontvars + nimplvars) );
324  SCIP_CALL( SCIPallocBufferArray(scip, &aggrdata->aggrrowsstart, ncontvars + nimplvars + 1) );
325  SCIP_CALL( SCIPallocBufferArray(scip, &aggrdata->nbadvarsinrow, nrows) );
326  SCIP_CALL( SCIPaggrRowCreate(scip, &aggrdata->aggrrow) );
327  BMSclearMemoryArray(aggrdata->nbadvarsinrow, nrows);
328 
329  aggrdata->nbounddistvars = 0;
330  aggrdata->aggrrows = NULL;
331  aggrdata->aggrrowscoef = NULL;
332  aggrdata->aggrrowssize = 0;
333  aggrdata->naggrrows = 0;
334 
335  firstcontvar = nvars - ncontvars;
336 
337  for( i = nbinvars + nintvars; i < nvars; ++i )
338  {
339  SCIP_Real bounddist;
340  SCIP_Real primsol;
341  SCIP_Real distlb;
342  SCIP_Real distub;
343  SCIP_Real bestlb;
344  SCIP_Real bestub;
345  SCIP_Real bestvlb;
346  SCIP_Real bestvub;
347  int bestvlbidx;
348  int bestvubidx;
349 
350  /* compute the bound distance of the variable */
351  if( allowlocal )
352  {
353  bestlb = SCIPvarGetLbLocal(vars[i]);
354  bestub = SCIPvarGetUbLocal(vars[i]);
355  }
356  else
357  {
358  bestlb = SCIPvarGetLbGlobal(vars[i]);
359  bestub = SCIPvarGetUbGlobal(vars[i]);
360  }
361 
362  SCIP_CALL( SCIPgetVarClosestVlb(scip, vars[i], sol, &bestvlb, &bestvlbidx) );
363  SCIP_CALL( SCIPgetVarClosestVub(scip, vars[i], sol, &bestvub, &bestvubidx) );
364  if( bestvlbidx >= 0 )
365  bestlb = MAX(bestlb, bestvlb);
366  if( bestvubidx >= 0 )
367  bestub = MIN(bestub, bestvub);
368 
369  primsol = SCIPgetSolVal(scip, sol, vars[i]);
370  distlb = primsol - bestlb;
371  distub = bestub - primsol;
372 
373  bounddist = MIN(distlb, distub);
374  bounddist = MAX(bounddist, 0.0);
375 
376  /* prefer continuous variables over implicit integers to be aggregated out */
377  if( i < firstcontvar )
378  bounddist *= 0.1;
379 
380  /* when variable is not at its bound, we want to project it out, so add it to the aggregation data */
381  if( !SCIPisZero(scip, bounddist) )
382  {
383  int k = aggrdata->nbounddistvars++;
384 
385  aggrdata->bounddist[k] = bounddist;
386  aggrdata->bounddistinds[k] = i;
387  aggrdata->aggrrowsstart[k] = aggrdata->naggrrows;
388 
389  /* the current variable is a bad variable (continuous, not at its bound): increase the number of bad variable
390  * count on each row this variables appears in; also each of these rows can be used to project the variable out
391  * so store them.
392  */
393  if( SCIPvarIsInLP(vars[i]) )
394  {
395  SCIP_COL* col = SCIPvarGetCol(vars[i]);
396  SCIP_ROW** colrows = SCIPcolGetRows(col);
397  SCIP_Real* colrowvals = SCIPcolGetVals(col);
398  int ncolnonzeros = SCIPcolGetNLPNonz(col);
399  int aggrrowsminsize = aggrdata->naggrrows + ncolnonzeros;
400 
401  if( aggrrowsminsize > aggrdata->aggrrowssize )
402  {
403  SCIP_CALL( SCIPreallocBufferArray(scip, &aggrdata->aggrrows, aggrrowsminsize) );
404  SCIP_CALL( SCIPreallocBufferArray(scip, &aggrdata->aggrrowscoef, aggrrowsminsize) );
405  }
406 
407  for( k = 0; k < ncolnonzeros; ++k )
408  {
409  /* ignore modifiable rows */
410  if( SCIProwIsModifiable(colrows[k]) )
411  continue;
412 
413  ++aggrdata->nbadvarsinrow[SCIProwGetLPPos(colrows[k])];
414  /* coverity[var_deref_op] */
415  aggrdata->aggrrows[aggrdata->naggrrows] = colrows[k];
416  aggrdata->aggrrowscoef[aggrdata->naggrrows] = colrowvals[k];
417  ++aggrdata->naggrrows;
418  }
419  }
420  }
421  }
422 
423  /* add sentinel entry at the end */
424  aggrdata->aggrrowsstart[aggrdata->nbounddistvars] = aggrdata->naggrrows;
425 
426  /* for each continous variable that is not at its bounds check if there is a
427  * row where it is the only such variable ("good" rows). In the array with the rows that are
428  * suitable for substituting this variable move the good rows to the beginning
429  * and store the number of good rows for each of the variables.
430  * If a variable has at least one good row, then it is a "better" variable and we make
431  * the value of the bounddistance for this variable negative, to mark it.
432  * Note that better variables are continous variables that are not at their bounds
433  * and can be projected out without introducing bad variables (by using a good row).
434  */
435  {
436  int beg;
437 
438  beg = aggrdata->aggrrowsstart[0];
439  for( i = 0; i < aggrdata->nbounddistvars; ++i )
440  {
441  int k;
442  int ngoodrows;
443  int end;
444 
445  end = aggrdata->aggrrowsstart[i + 1];
446  ngoodrows = 0;
447  for( k = beg; k < end; ++k )
448  {
449  /* coverity[var_deref_op] */
450  int lppos = SCIProwGetLPPos(aggrdata->aggrrows[k]);
451 
452  if( aggrdata->nbadvarsinrow[lppos] == 1 &&
453  SCIPisEQ(scip, SCIProwGetLhs(aggrdata->aggrrows[k]), SCIProwGetRhs(aggrdata->aggrrows[k])) )
454  {
455  int nextgoodrowpos = beg + ngoodrows;
456  if( k > nextgoodrowpos )
457  {
458  SCIPswapPointers((void**) (&aggrdata->aggrrows[k]), (void**) (&aggrdata->aggrrows[nextgoodrowpos]));
459  SCIPswapReals(&aggrdata->aggrrowscoef[k], &aggrdata->aggrrowscoef[nextgoodrowpos]);
460  }
461  ++ngoodrows;
462  }
463  }
464  if( ngoodrows > 0 )
465  {
466  aggrdata->bounddist[i] = -aggrdata->bounddist[i];
467  }
468  aggrdata->ngoodaggrrows[i] = ngoodrows;
469  beg = end;
470  }
471  }
472 
473  return SCIP_OKAY;
474 }
475 
476 /** free resources held in aggregation data */
477 static
479  SCIP* scip, /**< SCIP datastructure */
480  AGGREGATIONDATA* aggrdata /**< pointer to ggregation data */
481  )
482 {
483  SCIPaggrRowFree(scip, &aggrdata->aggrrow);
485  SCIPfreeBufferArrayNull(scip, &aggrdata->aggrrows);
486  SCIPfreeBufferArray(scip, &aggrdata->nbadvarsinrow);
487  SCIPfreeBufferArray(scip, &aggrdata->aggrrowsstart);
488  SCIPfreeBufferArray(scip, &aggrdata->ngoodaggrrows);
489  SCIPfreeBufferArray(scip, &aggrdata->bounddistinds);
490  SCIPfreeBufferArray(scip, &aggrdata->bounddist);
491 }
492 
493 /** retrieves the candidate rows for canceling out the given variable, also returns the number of "good" rows which are the
494  * rows stored at the first ngoodrows positions. A row is good if its continuous variables are all at their bounds, except
495  * maybe the given continuous variable (in probvaridx)
496  */
497 static
499  AGGREGATIONDATA* aggrdata, /**< pointer to ggregation data */
500  int probvaridx, /**< problem index of variables to retrieve candidates for */
501  SCIP_ROW*** rows, /**< pointer to store array to candidate rows */
502  SCIP_Real** rowvarcoefs, /**< pointer to store array of coefficients of given variable in the corresponding rows */
503  int* nrows, /**< pointer to return number of rows in returned arrays */
504  int* ngoodrows /**< pointer to return number of "good" rows in the returned arrays */
505  )
506 {
507  int aggrdataidx;
508 
509  if( !SCIPsortedvecFindInt(aggrdata->bounddistinds, probvaridx, aggrdata->nbounddistvars, &aggrdataidx) )
510  return FALSE;
511 
512  *rows = aggrdata->aggrrows + aggrdata->aggrrowsstart[aggrdataidx];
513  *nrows = aggrdata->aggrrowsstart[aggrdataidx + 1] - aggrdata->aggrrowsstart[aggrdataidx];
514  *rowvarcoefs = aggrdata->aggrrowscoef + aggrdata->aggrrowsstart[aggrdataidx];
515  *ngoodrows = aggrdata->ngoodaggrrows[aggrdataidx];
516 
517  return TRUE;
518 }
519 
520 /** find the bound distance value in the aggregation data struct for the given variable problem index */
521 static
523  AGGREGATIONDATA* aggrdata, /**< SCIP datastructure */
524  int probvaridx /**< problem index of variables to retrieve candidates for */
525  )
526 {
527  int aggrdataidx;
529  if( !SCIPsortedvecFindInt(aggrdata->bounddistinds, probvaridx, aggrdata->nbounddistvars, &aggrdataidx) )
530  return 0.0;
531 
532  return aggrdata->bounddist[aggrdataidx];
533 }
534 
535 /** Aggregates the next row suitable for cancelling out an active continuous variable.
536  *
537  * Equality rows that contain no other active continuous variables are preffered and apart from that
538  * the scores for the rows are used to determine which row is aggregated next
539  */
540 static
542  SCIP* scip, /**< SCIP data structure */
543  SCIP_SEPADATA* sepadata, /**< separator data */
544  SCIP_Real* rowlhsscores, /**< aggregation scores for left hand sides of row */
545  SCIP_Real* rowrhsscores, /**< aggregation scores for right hand sides of row */
546  AGGREGATIONDATA* aggrdata, /**< aggregation data */
547  SCIP_AGGRROW* aggrrow, /**< current aggregation row */
548  int* naggrs, /**< pointer to increase counter if real aggregation took place */
549  SCIP_Bool* success /**< pointer to return whether another row was added to the aggregation row */
550  )
551 {
552  int i;
553  int firstcontvar;
554  int* badvarinds;
555  SCIP_Real* badvarbddist;
556  int nbadvars;
557  SCIP_Real minbddist;
558  SCIP_ROW* bestrow;
559  SCIP_Real bestrowscore;
560  SCIP_Real aggrfac;
561  int bestrowside;
562  int ncontvars;
563  int nnz = SCIPaggrRowGetNNz(aggrrow);
564  int* inds = SCIPaggrRowGetInds(aggrrow);
565 
566  assert( success != NULL );
567  *success = FALSE;
568 
569  firstcontvar = SCIPgetNBinVars(scip) + SCIPgetNIntVars(scip);
570  ncontvars = SCIPgetNImplVars(scip) + SCIPgetNContVars(scip);
571  assert( firstcontvar + ncontvars == SCIPgetNVars(scip) );
572 
573  SCIP_CALL( SCIPallocBufferArray(scip, &badvarinds, MIN(ncontvars, nnz)) );
574  SCIP_CALL( SCIPallocBufferArray(scip, &badvarbddist, MIN(ncontvars, nnz)) );
575 
576  nbadvars = 0;
577 
578  for( i = 0; i < nnz; ++i )
579  {
580  SCIP_Real bounddist;
581 
582  /* only consider continuous variables */
583  if( inds[i] < firstcontvar )
584  continue;
585 
586  bounddist = aggrdataGetBoundDist(aggrdata, inds[i]);
587 
588  if( bounddist == 0.0 )
589  continue;
590 
591  badvarinds[nbadvars] = inds[i];
592  badvarbddist[nbadvars] = bounddist;
593  ++nbadvars;
594  }
595 
596  if( nbadvars == 0 )
597  goto TERMINATE;
598 
599  SCIPsortDownRealInt(badvarbddist, badvarinds, nbadvars);
600 
601  aggrfac = 0.0;
602  bestrowscore = 0.0;
603  bestrowside = 0;
604  minbddist = 0.0;
605  bestrow = NULL;
606 
607  /* because the "good" bad variables have a negative bound distance, they are at the end */
608  for( i = nbadvars - 1; i >= 0; --i )
609  {
610  int probvaridx;
611  SCIP_ROW** candrows;
612  SCIP_Real* candrowcoefs;
613  int nrows;
614  int ngoodrows;
615  int k;
616 
617  /* if the bound distance is not negative, there are no more good variables so stop */
618  if( badvarbddist[i] > 0.0 )
619  break;
620 
621  /* if no best row was found yet, this variable has the currently best bound distance */
622  if( aggrfac == 0.0 )
623  minbddist = -badvarbddist[i] * (1.0 - sepadata->aggrtol);
624 
625  /* if the bound distance of the current variable is smaller than the minimum bound distance stop looping */
626  if( -badvarbddist[i] < minbddist )
627  break;
628 
629  probvaridx = badvarinds[i];
630 
631  if( !getRowAggregationCandidates(aggrdata, probvaridx, &candrows, &candrowcoefs, &nrows, &ngoodrows) )
632  {
633  SCIPABORT();
634  }
635  assert(ngoodrows > 0); /* bounddistance was negative for this variable, so it should have good rows */
636 
637  for( k = 0; k < ngoodrows; ++k )
638  {
639  SCIP_Real rowaggrfac;
640  SCIP_Real rowscore;
641  int lppos;
642 
643  /* do not add rows twice */
644  if( SCIPaggrRowHasRowBeenAdded(aggrrow, candrows[k]) )
645  continue;
646 
647  rowaggrfac = - SCIPaggrRowGetProbvarValue(aggrrow, probvaridx) / candrowcoefs[k];
648 
649  /* if factor is too extreme skip this row */
650  if( SCIPisFeasZero(scip, rowaggrfac) || REALABS(rowaggrfac) > sepadata->maxrowfac )
651  continue;
652 
653  lppos = SCIProwGetLPPos(candrows[k]);
654 
655  /* row could be used and good rows are equalities, so ignore sidetype */
656  rowscore = MAX(rowlhsscores[lppos], rowrhsscores[lppos]);
657 
658  /* if this rows score is better than the currently best score, remember it */
659  if( aggrfac == 0.0 || rowscore > bestrowscore )
660  {
661  bestrow = candrows[k];
662  aggrfac = rowaggrfac;
663  bestrowscore = rowscore;
664  bestrowside = 0;
665  }
666  }
667  }
668 
669  /* found a row among the good rows, so aggregate it and stop */
670  if( aggrfac != 0.0 )
671  {
672  ++(*naggrs);
673  SCIP_CALL( SCIPaggrRowAddRow(scip, aggrrow, bestrow, aggrfac, bestrowside) );
674  SCIPaggrRowRemoveZeros(scip, aggrrow, success);
675  goto TERMINATE;
676  }
677 
678  for( i = 0; i < nbadvars; ++i )
679  {
680  int probvaridx;
681  SCIP_ROW** candrows;
682  SCIP_Real* candrowcoefs;
683  int nrows;
684  int ngoodrows;
685  int k;
686 
687  /* if the bound distance is negative, there are no more variables to be tested, so stop */
688  if( badvarbddist[i] < 0.0 )
689  break;
690 
691  /* if no best row was found yet, this variable has the currently best bound distance */
692  if( aggrfac == 0.0 )
693  minbddist = badvarbddist[i] * (1.0 - sepadata->aggrtol);
694 
695  /* if the bound distance of the current variable is smaller than the minimum bound distance stop looping */
696  if( badvarbddist[i] < minbddist )
697  break;
698 
699  probvaridx = badvarinds[i];
700 
701  if( !getRowAggregationCandidates(aggrdata, probvaridx, &candrows, &candrowcoefs, &nrows, &ngoodrows) )
702  {
703  SCIPABORT();
704  }
705 
706  /* bounddistance was positive for this variable, so it should not have good rows */
707  assert(ngoodrows == 0);
708 
709  for( k = 0; k < nrows; ++k )
710  {
711  SCIP_Real rowaggrfac;
712  SCIP_Real rowscore;
713  int rowside;
714  int lppos;
715 
716  /* do not add rows twice */
717  if( SCIPaggrRowHasRowBeenAdded(aggrrow, candrows[k]) )
718  continue;
719 
720  rowaggrfac = - SCIPaggrRowGetProbvarValue(aggrrow, probvaridx) / candrowcoefs[k];
721 
722  /* if factor is too extreme skip this row */
723  if( SCIPisFeasZero(scip, rowaggrfac) || REALABS(rowaggrfac) > sepadata->maxrowfac )
724  continue;
725 
726  /* row could be used, decide which side */
727  lppos = SCIProwGetLPPos(candrows[k]);
728 
729  /* either both or none of the rowscores are 0.0 so use the one which gives a positive slack */
730  if( (rowaggrfac < 0.0 && !SCIPisInfinity(scip, -SCIProwGetLhs(candrows[k]))) || SCIPisInfinity(scip, SCIProwGetRhs(candrows[k])) )
731  {
732  rowscore = rowlhsscores[lppos];
733  rowside = -1;
734  }
735  else
736  {
737  rowscore = rowrhsscores[lppos];
738  rowside = 1;
739  }
740 
741  /* if this rows score is better than the currently best score, remember it */
742  if( aggrfac == 0.0 || SCIPisGT(scip, rowscore, bestrowscore) ||
743  (SCIPisEQ(scip, rowscore, bestrowscore) && aggrdata->nbadvarsinrow[lppos] < aggrdata->nbadvarsinrow[SCIProwGetLPPos(bestrow)]) )
744  {
745  bestrow = candrows[k];
746  aggrfac = rowaggrfac;
747  bestrowscore = rowscore;
748  bestrowside = rowside;
749  }
750  }
751  }
752 
753  /* found a row so aggregate it */
754  if( aggrfac != 0.0 )
755  {
756  ++(*naggrs);
757  SCIP_CALL( SCIPaggrRowAddRow(scip, aggrrow, bestrow, aggrfac, bestrowside) );
758  SCIPaggrRowRemoveZeros(scip, aggrrow, success);
759  }
760 
761 TERMINATE:
762  SCIPfreeBufferArray(scip, &badvarbddist);
763  SCIPfreeBufferArray(scip, &badvarinds);
764 
765  return SCIP_OKAY;
766 }
767 
768 /** aggregates different single mixed integer constraints by taking linear combinations of the rows of the LP */
769 static
771  SCIP* scip, /**< SCIP data structure */
772  AGGREGATIONDATA* aggrdata, /**< pointer to aggregation data */
773  SCIP_SEPA* sepa, /**< separator */
774  SCIP_SOL* sol, /**< the solution that should be separated, or NULL for LP solution */
775  SCIP_Bool allowlocal, /**< should local cuts be allowed */
776  SCIP_Real* rowlhsscores, /**< aggregation scores for left hand sides of row */
777  SCIP_Real* rowrhsscores, /**< aggregation scores for right hand sides of row */
778  int startrow, /**< index of row to start aggregation */
779  int maxaggrs, /**< maximal number of aggregations */
780  SCIP_Bool* wastried, /**< pointer to store whether the given startrow was actually tried */
781  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
782  int* cutinds, /**< buffer array to store temporarily cut */
783  SCIP_Real* cutcoefs, /**< buffer array to store temporarily cut */
784  SCIP_Bool negate, /**< should the start row be multiplied by -1 */
785  int* ncuts /**< pointer to count the number of generated cuts */
786  )
787 {
788  SCIP_SEPADATA* sepadata;
789  SCIP_ROW** rows;
790 
791  SCIP_Real startweight;
792  SCIP_Real startrowact;
793  int maxaggrnonzs;
794  int naggrs;
795  int nrows;
796  int maxtestdelta;
797 
798  SCIP_Real cutrhs;
799  SCIP_Real cutefficacy;
800 
801  assert(scip != NULL);
802  assert(sepa != NULL);
803  assert(rowlhsscores != NULL);
804  assert(rowrhsscores != NULL);
805  assert(wastried != NULL);
806  assert(cutoff != NULL);
807  assert(ncuts != NULL);
808 
809  sepadata = SCIPsepaGetData(sepa);
810  assert(sepadata != NULL);
811 
812  *cutoff = FALSE;
813  *wastried = FALSE;
814 
815  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
816  assert(nrows == 0 || rows != NULL);
817  assert(0 <= startrow && startrow < nrows);
818 
819  SCIPdebugMsg(scip, "start c-MIR aggregation with row <%s> (%d/%d)\n", SCIProwGetName(rows[startrow]), startrow, nrows);
820 
821  /* calculate maximal number of non-zeros in aggregated row */
822  maxaggrnonzs = (int)(sepadata->maxaggdensity * SCIPgetNLPCols(scip)) + sepadata->densityoffset;
823 
824  startrowact = SCIPgetRowSolActivity(scip, rows[startrow], sol);
825 
826  if( startrowact <= 0.5 * SCIProwGetLhs(rows[startrow]) + 0.5 * SCIProwGetRhs(rows[startrow]) )
827  startweight = -1.0;
828  else
829  startweight = 1.0;
830 
831  maxtestdelta = sepadata->maxtestdelta == -1 ? INT_MAX : sepadata->maxtestdelta;
832 
833  /* add start row to the initially empty aggregation row (aggrrow) */
834  SCIP_CALL( SCIPaggrRowAddRow(scip, aggrdata->aggrrow, rows[startrow], negate ? -startweight : startweight, 0) );
835 
836  /* try to generate cut from the current aggregated row; add cut if found, otherwise add another row to aggrrow
837  * in order to get rid of a continuous variable
838  */
839  naggrs = 0;
840  while( naggrs <= maxaggrs )
841  {
842  int cutrank;
843  int cutnnz;
844  SCIP_Bool aggrsuccess;
845  SCIP_Bool cmirsuccess;
846  SCIP_Bool cmircutislocal;
847  SCIP_Bool flowcoversuccess;
848  SCIP_Real flowcoverefficacy;
849  SCIP_Bool flowcovercutislocal;
850  SCIP_ROW* cut = NULL;
851 
852  *wastried = TRUE;
853 
854  /* Step 1:
855  * try to generate a MIR cut out of the current aggregated row
856  */
857 
858  flowcoverefficacy = -SCIPinfinity(scip);
859 
860  if( sepadata->sepflowcover )
861  {
862  SCIP_CALL( SCIPcalcFlowCover(scip, sol, POSTPROCESS, BOUNDSWITCH, allowlocal, aggrdata->aggrrow,
863  cutcoefs, &cutrhs, cutinds, &cutnnz, &flowcoverefficacy, &cutrank, &flowcovercutislocal, &flowcoversuccess) );
864  }
865  else
866  {
867  flowcoversuccess = FALSE;
868  }
869 
870  cutefficacy = flowcoverefficacy;
871 
872  if( sepadata->sepcmir )
873  {
874  SCIP_CALL( SCIPcutGenerationHeuristicCMIR(scip, sol, POSTPROCESS, BOUNDSWITCH, USEVBDS, allowlocal, maxtestdelta, NULL, NULL, MINFRAC, MAXFRAC,
875  aggrdata->aggrrow, cutcoefs, &cutrhs, cutinds, &cutnnz, &cutefficacy, &cutrank, &cmircutislocal, &cmirsuccess) );
876  }
877  else
878  {
879  cmirsuccess = FALSE;
880  }
881 
882  if( cmirsuccess )
883  {
884  SCIP_CALL( addCut(scip, sol, sepadata->cmir, FALSE, cutcoefs, cutinds, cutnnz, cutrhs, cutefficacy, cmircutislocal,
885  sepadata->dynamiccuts, cutrank, "cmir", cutoff, ncuts, &cut) ); /*lint !e644*/
886  }
887  else if ( flowcoversuccess )
888  {
889  /* cppcheck-suppress uninitvar */
890  SCIP_CALL( addCut(scip, sol, sepadata->flowcover, FALSE, cutcoefs, cutinds, cutnnz, cutrhs, cutefficacy, flowcovercutislocal,
891  sepadata->dynamiccuts, cutrank, "flowcover", cutoff, ncuts, &cut) ); /*lint !e644*/
892  }
893 
894  if ( *cutoff )
895  {
896  if( cut != NULL )
897  {
898  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
899  }
900  break;
901  }
902 
903  /* if the cut was successfully added, decrease the score of the rows used in the aggregation and clean the aggregation
904  * row (and call this function again with a different start row for aggregation)
905  */
906  if( cut != NULL )
907  {
908  int* rowinds;
909  int i;
910 
911  rowinds = SCIPaggrRowGetRowInds(aggrdata->aggrrow);
912  nrows = SCIPaggrRowGetNRows(aggrdata->aggrrow);
913 
914  /* decrease row score of used rows slightly */
915  for( i = 0; i < nrows; ++i )
916  {
917  SCIP_Real fac = 1.0 - 0.999 * SCIProwGetParallelism(rows[rowinds[i]], cut, 'e');
918 
919  rowlhsscores[rowinds[i]] *= fac;
920  rowrhsscores[rowinds[i]] *= fac;
921  }
922 
923  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
924 
925  SCIPdebugMsg(scip, " -> abort aggregation: cut found\n");
926  break;
927  }
928 
929  /* Step 2:
930  * aggregate an additional row in order to remove a continuous variable
931  */
932 
933  /* abort, if we reached the maximal number of aggregations */
934  if( naggrs == maxaggrs )
935  {
936  SCIPdebugMsg(scip, " -> abort aggregation: maximal number of aggregations reached\n");
937  break;
938  }
939 
940  SCIP_CALL( aggregateNextRow(scip, sepadata, rowlhsscores, rowrhsscores, aggrdata, aggrdata->aggrrow,
941  &naggrs, &aggrsuccess) );
942 
943  /* no suitable aggregation was found or number of non-zeros is now too large so abort */
944  if( ! aggrsuccess || SCIPaggrRowGetNNz(aggrdata->aggrrow) > maxaggrnonzs || SCIPaggrRowGetNNz(aggrdata->aggrrow) == 0 )
945  {
946  break;
947  }
948 
949  SCIPdebugMsg(scip, " -> current aggregation has %d/%d nonzeros and consists of %d/%d rows\n",
950  SCIPaggrRowGetNNz(aggrdata->aggrrow), maxaggrnonzs, naggrs, maxaggrs);
951  }
952 
953  SCIPaggrRowClear(aggrdata->aggrrow);
954 
955  return SCIP_OKAY;
956 }
957 
958 /** gives an estimate of how much the activity of this row is affected by fractionality in the current solution */
959 static
961  SCIP_ROW* row, /**< the LP row */
962  SCIP_Real* fractionalities /**< array of fractionalities for each variable */
963  )
964 {
965  int nlpnonz;
966  int i;
967  SCIP_COL** cols;
968  SCIP_Real* vals;
969  SCIP_Real fracsum = 0.0;
970 
971  cols = SCIProwGetCols(row);
972  vals = SCIProwGetVals(row);
973  nlpnonz = SCIProwGetNLPNonz(row);
974 
975  for( i = 0; i < nlpnonz; ++i )
976  {
977  SCIP_VAR* var = SCIPcolGetVar(cols[i]);
978  fracsum += REALABS(vals[i] * fractionalities[SCIPvarGetProbindex(var)]);
979  }
980 
981  return fracsum;
982 }
983 
984 /** searches and adds c-MIR cuts that separate the given primal solution */
985 static
987  SCIP* scip, /**< SCIP data structure */
988  SCIP_SEPA* sepa, /**< the c-MIR separator */
989  SCIP_SOL* sol, /**< the solution that should be separated, or NULL for LP solution */
990  SCIP_Bool allowlocal, /**< should local cuts be allowed */
991  SCIP_RESULT* result /**< pointer to store the result */
992  )
993 {
994  AGGREGATIONDATA aggrdata;
995  SCIP_SEPADATA* sepadata;
996  SCIP_VAR** vars;
997  SCIP_Real* varsolvals;
998  SCIP_Real* bestcontlbs;
999  SCIP_Real* bestcontubs;
1000  SCIP_Real* fractionalities;
1001  SCIP_ROW** rows;
1002  SCIP_Real* rowlhsscores;
1003  SCIP_Real* rowrhsscores;
1004  SCIP_Real* rowscores;
1005  int* roworder;
1006  SCIP_Real maxslack;
1007  SCIP_Bool cutoff = FALSE;
1008  int nvars;
1009  int nintvars;
1010  int ncontvars;
1011  int nrows;
1012  int nnonzrows;
1013  int ntries;
1014  int nfails;
1015  int depth;
1016  int ncalls;
1017  int maxtries;
1018  int maxfails;
1019  int maxaggrs;
1020  int maxsepacuts;
1021  int ncuts;
1022  int r;
1023  int v;
1024 
1025  int* cutinds;
1026  SCIP_Real* cutcoefs;
1027 
1028  assert(result != NULL);
1029  assert(*result == SCIP_DIDNOTRUN);
1030 
1031  sepadata = SCIPsepaGetData(sepa);
1032  assert(sepadata != NULL);
1033 
1034  depth = SCIPgetDepth(scip);
1035  ncalls = SCIPsepaGetNCallsAtNode(sepa);
1036 
1037  /* only call the cmir cut separator a given number of times at each node */
1038  if( (depth == 0 && sepadata->maxroundsroot >= 0 && ncalls >= sepadata->maxroundsroot)
1039  || (depth > 0 && sepadata->maxrounds >= 0 && ncalls >= sepadata->maxrounds) )
1040  return SCIP_OKAY;
1041 
1042  /* check which cuts should be separated */
1043  {
1044  int cmirfreq;
1045  int flowcoverfreq;
1046 
1047  cmirfreq = SCIPsepaGetFreq(sepadata->cmir);
1048  flowcoverfreq = SCIPsepaGetFreq(sepadata->flowcover);
1049 
1050  sepadata->sepcmir = cmirfreq > 0 ? (depth % cmirfreq) == 0 : cmirfreq == depth;
1051  sepadata->sepflowcover = flowcoverfreq > 0 ? (depth % flowcoverfreq) == 0 : flowcoverfreq == depth;
1052  }
1053 
1054  if( ! sepadata->sepcmir && ! sepadata->sepflowcover )
1055  return SCIP_OKAY;
1056 
1057  /* get all rows and number of columns */
1058  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
1059  assert(nrows == 0 || rows != NULL);
1060 
1061  /* nothing to do, if LP is empty */
1062  if( nrows == 0 )
1063  return SCIP_OKAY;
1064 
1065  /* check whether SCIP was stopped in the meantime */
1066  if( SCIPisStopped(scip) )
1067  return SCIP_OKAY;
1068 
1069  /* get active problem variables */
1070  vars = SCIPgetVars(scip);
1071  nvars = SCIPgetNVars(scip);
1072  ncontvars = SCIPgetNContVars(scip);
1073 #ifdef IMPLINTSARECONT
1074  ncontvars += SCIPgetNImplVars(scip); /* also aggregate out implicit integers */
1075 #endif
1076  nintvars = nvars - ncontvars;
1077  assert(nvars == 0 || vars != NULL);
1078 
1079  /* nothing to do, if problem has no variables */
1080  if( nvars == 0 )
1081  return SCIP_OKAY;
1082 
1083  SCIPdebugMsg(scip, "separating c-MIR cuts\n");
1084 
1085  *result = SCIP_DIDNOTFIND;
1086 
1087  /* get data structure */
1088  SCIP_CALL( SCIPallocBufferArray(scip, &rowlhsscores, nrows) );
1089  SCIP_CALL( SCIPallocBufferArray(scip, &rowrhsscores, nrows) );
1090  SCIP_CALL( SCIPallocBufferArray(scip, &roworder, nrows) );
1091  SCIP_CALL( SCIPallocBufferArray(scip, &varsolvals, nvars) );
1092  SCIP_CALL( SCIPallocBufferArray(scip, &bestcontlbs, ncontvars) );
1093  SCIP_CALL( SCIPallocBufferArray(scip, &bestcontubs, ncontvars) );
1094  SCIP_CALL( SCIPallocBufferArray(scip, &fractionalities, nvars) );
1095  SCIP_CALL( SCIPallocBufferArray(scip, &cutinds, nvars) );
1096  SCIP_CALL( SCIPallocBufferArray(scip, &cutcoefs, nvars) );
1097  SCIP_CALL( SCIPallocBufferArray(scip, &rowscores, nrows) );
1098 
1099  /* get the solution values for all active variables */
1100  SCIP_CALL( SCIPgetSolVals(scip, sol, nvars, vars, varsolvals) );
1101 
1102  /* calculate the fractionality of the integer variables in the current solution */
1103  for( v = 0; v < nintvars; ++v )
1104  {
1105  fractionalities[v] = SCIPfeasFrac(scip, varsolvals[v]);
1106  fractionalities[v] = MIN(fractionalities[v], 1.0 - fractionalities[v]);
1107  }
1108 
1109  /* calculate the fractionality of the continuous variables in the current solution;
1110  * The fractionality of a continuous variable x is defined to be a * f_y,
1111  * if there is a variable bound x <= a * y + c where f_y is the fractionality of y
1112  * and in the current solution the variable bound has no slack.
1113  */
1114  for( ; v < nvars; ++v )
1115  {
1116  SCIP_VAR** vlbvars;
1117  SCIP_VAR** vubvars;
1118  SCIP_Real* vlbcoefs;
1119  SCIP_Real* vubcoefs;
1120  SCIP_Real closestvlb;
1121  SCIP_Real closestvub;
1122  int closestvlbidx;
1123  int closestvubidx;
1124 
1125  SCIP_CALL( SCIPgetVarClosestVlb(scip, vars[v], sol, &closestvlb, &closestvlbidx) );
1126  SCIP_CALL( SCIPgetVarClosestVub(scip, vars[v], sol, &closestvub, &closestvubidx) );
1127 
1128  vlbvars = SCIPvarGetVlbVars(vars[v]);
1129  vubvars = SCIPvarGetVubVars(vars[v]);
1130  vlbcoefs = SCIPvarGetVlbCoefs(vars[v]);
1131  vubcoefs = SCIPvarGetVubCoefs(vars[v]);
1132 
1133  fractionalities[v] = 0.0;
1134  if( closestvlbidx != -1 && SCIPisEQ(scip, varsolvals[v], closestvlb) )
1135  {
1136  int vlbvarprobidx = SCIPvarGetProbindex(vlbvars[closestvlbidx]);
1137  SCIP_Real frac = SCIPfeasFrac(scip, varsolvals[vlbvarprobidx]);
1138 
1139  if( frac < 0.0 )
1140  frac = 0.0;
1141  assert(frac >= 0.0 && frac < 1.0);
1142  frac = MIN(frac, 1.0 - frac) * vlbcoefs[closestvlbidx];
1143  fractionalities[v] += frac;
1144  }
1145 
1146  if( closestvubidx != -1 && SCIPisEQ(scip, varsolvals[v], closestvub) )
1147  {
1148  int vubvarprobidx = SCIPvarGetProbindex(vubvars[closestvubidx]);
1149  SCIP_Real frac = SCIPfeasFrac(scip, varsolvals[vubvarprobidx]);
1150 
1151  if( frac < 0.0 )
1152  frac = 0.0;
1153  assert(frac >= 0.0 && frac < 1.0);
1154  frac = MIN(frac, 1.0 - frac) * vubcoefs[closestvubidx];
1155  fractionalities[v] += frac;
1156  }
1157  }
1158 
1159  /* get the maximal number of cuts allowed in a separation round */
1160  if( depth == 0 )
1161  {
1162  maxtries = sepadata->maxtriesroot;
1163  maxfails = sepadata->maxfailsroot;
1164  maxaggrs = sepadata->maxaggrsroot;
1165  maxsepacuts = sepadata->maxsepacutsroot;
1166  maxslack = sepadata->maxslackroot;
1167  }
1168  else
1169  {
1170  maxtries = sepadata->maxtries;
1171  maxfails = sepadata->maxfails;
1172  maxaggrs = sepadata->maxaggrs;
1173  maxsepacuts = sepadata->maxsepacuts;
1174  maxslack = sepadata->maxslack;
1175  }
1176 
1177  /* calculate aggregation scores for both sides of all rows, and sort rows by decreasing maximal score
1178  * TODO: document score definition */
1179 
1180  /* count the number of non-zero rows and zero rows. these values are used for the sorting of the rowscores.
1181  * only the non-zero rows need to be sorted. */
1182  nnonzrows = 0;
1183  for( r = 0; r < nrows; r++ )
1184  {
1185  int nnonz;
1186 
1187  assert(SCIProwGetLPPos(rows[r]) == r);
1188 
1189  nnonz = SCIProwGetNLPNonz(rows[r]);
1190  if( nnonz == 0 )
1191  {
1192  /* ignore empty rows */
1193  rowlhsscores[r] = 0.0;
1194  rowrhsscores[r] = 0.0;
1195  }
1196  else
1197  {
1198  SCIP_Real activity;
1199  SCIP_Real lhs;
1200  SCIP_Real rhs;
1201  SCIP_Real dualsol;
1202  SCIP_Real dualscore;
1203  SCIP_Real rowdensity;
1204  SCIP_Real rownorm;
1205  SCIP_Real slack;
1206  SCIP_Real fracact;
1207  SCIP_Real fracscore;
1208  SCIP_Real objnorm;
1209 
1210  objnorm = SCIPgetObjNorm(scip);
1211  objnorm = MAX(objnorm, 1.0);
1212 
1213  fracact = getRowFracActivity(rows[r], fractionalities);
1214  dualsol = (sol == NULL ? SCIProwGetDualsol(rows[r]) : 1.0);
1215  activity = SCIPgetRowSolActivity(scip, rows[r], sol);
1216  lhs = SCIProwGetLhs(rows[r]);
1217  rhs = SCIProwGetRhs(rows[r]);
1218  rownorm = SCIProwGetNorm(rows[r]);
1219  rownorm = MAX(rownorm, 0.1);
1220  rowdensity = (SCIP_Real)(nnonz - sepadata->densityoffset)/(SCIP_Real)nvars;
1221  assert(SCIPisPositive(scip, rownorm));
1222  fracscore = fracact / rownorm;
1223 
1224  slack = (activity - lhs)/rownorm;
1225  dualscore = MAX(fracscore * dualsol/objnorm, 0.0001);
1226  if( !SCIPisInfinity(scip, -lhs) && SCIPisLE(scip, slack, maxslack)
1227  && (allowlocal || !SCIProwIsLocal(rows[r])) /*lint !e506 !e774*/
1228  && rowdensity <= sepadata->maxrowdensity
1229  && rowdensity <= sepadata->maxaggdensity ) /*lint !e774*/
1230  {
1231  rowlhsscores[r] = dualscore + sepadata->densityscore * (1.0-rowdensity) + sepadata->slackscore * MAX(1.0 - slack, 0.0);
1232  assert(rowlhsscores[r] > 0.0);
1233  }
1234  else
1235  rowlhsscores[r] = 0.0;
1236 
1237  slack = (rhs - activity)/rownorm;
1238  dualscore = MAX(-fracscore * dualsol/objnorm, 0.0001);
1239  if( !SCIPisInfinity(scip, rhs) && SCIPisLE(scip, slack, maxslack)
1240  && (allowlocal || !SCIProwIsLocal(rows[r])) /*lint !e506 !e774*/
1241  && rowdensity <= sepadata->maxrowdensity
1242  && rowdensity <= sepadata->maxaggdensity ) /*lint !e774*/
1243  {
1244  rowrhsscores[r] = dualscore + sepadata->densityscore * (1.0-rowdensity) + sepadata->slackscore * MAX(1.0 - slack, 0.0);
1245  assert(rowrhsscores[r] > 0.0);
1246  }
1247  else
1248  rowrhsscores[r] = 0.0;
1249 
1250  /* for the row order only use the fractionality score since it best indicates how likely it is to find a cut */
1251  if( fracscore != 0.0 )
1252  {
1253  roworder[nnonzrows] = r;
1254  rowscores[nnonzrows] = fracscore;
1255  ++nnonzrows;
1256  }
1257  }
1258 
1259  SCIPdebugMsg(scip, " -> row %d <%s>: lhsscore=%g rhsscore=%g maxscore=%g\n", r, SCIProwGetName(rows[r]),
1260  rowlhsscores[r], rowrhsscores[r], rowscores[r]);
1261  }
1262  assert(nnonzrows <= nrows);
1263 
1264  SCIPsortDownRealInt(rowscores, roworder, nnonzrows);
1265  SCIPfreeBufferArray(scip, &rowscores);
1266 
1267  /* calculate the data required for performing the row aggregation */
1268  SCIP_CALL( setupAggregationData(scip, sol, allowlocal, &aggrdata) );
1269 
1270  ncuts = 0;
1271  if( maxtries < 0 )
1272  maxtries = INT_MAX;
1273  if( maxfails < 0 )
1274  maxfails = INT_MAX;
1275  else if( depth == 0 && 2 * SCIPgetNSepaRounds(scip) < maxfails )
1276  maxfails += maxfails - 2 * SCIPgetNSepaRounds(scip); /* allow up to double as many fails in early separounds of root node */
1277 
1278  /* start aggregation heuristic for each row in the LP and generate resulting cuts */
1279  ntries = 0;
1280  nfails = 0;
1281  for( r = 0; r < nnonzrows && ntries < maxtries && ncuts < maxsepacuts && !SCIPisStopped(scip); r++ )
1282  {
1283  SCIP_Bool wastried;
1284  int oldncuts;
1285 
1286  oldncuts = ncuts;
1287  SCIP_CALL( aggregation(scip, &aggrdata, sepa, sol, allowlocal, rowlhsscores, rowrhsscores,
1288  roworder[r], maxaggrs, &wastried, &cutoff, cutinds, cutcoefs, FALSE, &ncuts) );
1289 
1290  /* if trynegscaling is true we start the aggregation heuristic again for this row, but multiply it by -1 first.
1291  * This is done by calling the aggregation function with the parameter negate equal to TRUE
1292  */
1293  if( sepadata->trynegscaling && !cutoff )
1294  {
1295  SCIP_CALL( aggregation(scip, &aggrdata, sepa, sol, allowlocal, rowlhsscores, rowrhsscores,
1296  roworder[r], maxaggrs, &wastried, &cutoff, cutinds, cutcoefs, TRUE, &ncuts) );
1297  }
1298 
1299  if ( cutoff )
1300  break;
1301 
1302  if( !wastried )
1303  {
1304  continue;
1305  }
1306  ntries++;
1307 
1308  if( ncuts == oldncuts )
1309  {
1310  nfails++;
1311  if( nfails >= maxfails )
1312  {
1313  break;
1314  }
1315  }
1316  else
1317  {
1318  nfails = 0;
1319  }
1320  }
1321 
1322  /* free data structure */
1323  destroyAggregationData(scip, &aggrdata);
1324  SCIPfreeBufferArray(scip, &cutcoefs);
1325  SCIPfreeBufferArray(scip, &cutinds);
1326  SCIPfreeBufferArray(scip, &fractionalities);
1327  SCIPfreeBufferArray(scip, &bestcontubs);
1328  SCIPfreeBufferArray(scip, &bestcontlbs);
1329  SCIPfreeBufferArray(scip, &varsolvals);
1330  SCIPfreeBufferArray(scip, &roworder);
1331  SCIPfreeBufferArray(scip, &rowrhsscores);
1332  SCIPfreeBufferArray(scip, &rowlhsscores);
1333 
1334  if ( cutoff )
1335  *result = SCIP_CUTOFF;
1336  else if ( ncuts > 0 )
1337  *result = SCIP_SEPARATED;
1338 
1339  return SCIP_OKAY;
1340 }
1341 
1342 /*
1343  * Callback methods of separator
1344  */
1345 
1346 /** copy method for separator plugins (called when SCIP copies plugins) */
1347 static
1348 SCIP_DECL_SEPACOPY(sepaCopyAggregation)
1349 { /*lint --e{715}*/
1350  assert(scip != NULL);
1351  assert(sepa != NULL);
1352  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
1353 
1354  /* call inclusion method of constraint handler */
1356 
1357  return SCIP_OKAY;
1358 }
1359 
1360 /** destructor of separator to free user data (called when SCIP is exiting) */
1361 static
1362 SCIP_DECL_SEPAFREE(sepaFreeAggregation)
1363 { /*lint --e{715}*/
1364  SCIP_SEPADATA* sepadata;
1365 
1366  /* free separator data */
1367  sepadata = SCIPsepaGetData(sepa);
1368  assert(sepadata != NULL);
1369 
1370  SCIPfreeBlockMemory(scip, &sepadata);
1371 
1372  SCIPsepaSetData(sepa, NULL);
1373 
1374  return SCIP_OKAY;
1375 }
1376 
1377 /** LP solution separation method of separator */
1378 static
1379 SCIP_DECL_SEPAEXECLP(sepaExeclpAggregation)
1380 { /*lint --e{715}*/
1381  assert( result != NULL );
1382 
1383  *result = SCIP_DIDNOTRUN;
1384 
1385  /* only call separator, if we are not close to terminating */
1386  if( SCIPisStopped(scip) )
1387  return SCIP_OKAY;
1388 
1389  /* only call separator, if an optimal LP solution is at hand */
1391  return SCIP_OKAY;
1392 
1393  /* only call separator, if there are fractional variables */
1394  if( SCIPgetNLPBranchCands(scip) == 0 )
1395  return SCIP_OKAY;
1396 
1397  SCIP_CALL( separateCuts(scip, sepa, NULL, allowlocal, result) );
1398 
1399  return SCIP_OKAY;
1400 }
1401 
1402 /** arbitrary primal solution separation method of separator */
1403 static
1404 SCIP_DECL_SEPAEXECSOL(sepaExecsolAggregation)
1405 { /*lint --e{715}*/
1406  assert( result != NULL );
1407 
1408  *result = SCIP_DIDNOTRUN;
1409 
1410  SCIP_CALL( separateCuts(scip, sepa, sol, allowlocal, result) );
1411 
1412  return SCIP_OKAY;
1413 }
1414 
1415 /** LP solution separation method of dummy separator */
1416 static
1417 SCIP_DECL_SEPAEXECLP(sepaExeclpDummy)
1418 { /*lint --e{715}*/
1419  assert( result != NULL );
1420 
1421  *result = SCIP_DIDNOTRUN;
1422 
1423  return SCIP_OKAY;
1424 }
1425 
1426 /** arbitrary primal solution separation method of dummy separator */
1427 static
1428 SCIP_DECL_SEPAEXECSOL(sepaExecsolDummy)
1429 { /*lint --e{715}*/
1430  assert( result != NULL );
1431 
1432  *result = SCIP_DIDNOTRUN;
1433 
1434  return SCIP_OKAY;
1435 }
1436 
1437 /*
1438  * separator specific interface methods
1439  */
1440 
1441 /** creates the cmir separator and includes it in SCIP */
1443  SCIP* scip /**< SCIP data structure */
1444  )
1445 {
1446  SCIP_SEPADATA* sepadata;
1447  SCIP_SEPA* sepa;
1449  /* create cmir separator data */
1450  SCIP_CALL( SCIPallocBlockMemory(scip, &sepadata) );
1451 
1452  /* include dummy separators */
1453  SCIP_CALL( SCIPincludeSepaBasic(scip, &sepadata->flowcover, "flowcover", "separator for flowcover cuts", -100000, SEPA_FREQ, 0.0,
1454  SEPA_USESSUBSCIP, FALSE, sepaExeclpDummy, sepaExecsolDummy, NULL) );
1455 
1456  assert(sepadata->flowcover != NULL);
1457 
1458  SCIP_CALL( SCIPincludeSepaBasic(scip, &sepadata->cmir, "cmir", "separator for cmir cuts", -100000, SEPA_FREQ, 0.0,
1459  SEPA_USESSUBSCIP, FALSE, sepaExeclpDummy, sepaExecsolDummy, NULL) );
1460 
1461  assert(sepadata->cmir != NULL);
1462 
1463  /* include separator */
1466  sepaExeclpAggregation, sepaExecsolAggregation,
1467  sepadata) );
1468 
1469  assert(sepa != NULL);
1470 
1471  /* set non-NULL pointers to callback methods */
1472  SCIP_CALL( SCIPsetSepaCopy(scip, sepa, sepaCopyAggregation) );
1473  SCIP_CALL( SCIPsetSepaFree(scip, sepa, sepaFreeAggregation) );
1474 
1475  /* add cmir separator parameters */
1476  SCIP_CALL( SCIPaddIntParam(scip,
1477  "separating/" SEPA_NAME "/maxrounds",
1478  "maximal number of cmir separation rounds per node (-1: unlimited)",
1479  &sepadata->maxrounds, FALSE, DEFAULT_MAXROUNDS, -1, INT_MAX, NULL, NULL) );
1480  SCIP_CALL( SCIPaddIntParam(scip,
1481  "separating/" SEPA_NAME "/maxroundsroot",
1482  "maximal number of cmir separation rounds in the root node (-1: unlimited)",
1483  &sepadata->maxroundsroot, FALSE, DEFAULT_MAXROUNDSROOT, -1, INT_MAX, NULL, NULL) );
1484  SCIP_CALL( SCIPaddIntParam(scip,
1485  "separating/" SEPA_NAME "/maxtries",
1486  "maximal number of rows to start aggregation with per separation round (-1: unlimited)",
1487  &sepadata->maxtries, TRUE, DEFAULT_MAXTRIES, -1, INT_MAX, NULL, NULL) );
1488  SCIP_CALL( SCIPaddIntParam(scip,
1489  "separating/" SEPA_NAME "/maxtriesroot",
1490  "maximal number of rows to start aggregation with per separation round in the root node (-1: unlimited)",
1491  &sepadata->maxtriesroot, TRUE, DEFAULT_MAXTRIESROOT, -1, INT_MAX, NULL, NULL) );
1492  SCIP_CALL( SCIPaddIntParam(scip,
1493  "separating/" SEPA_NAME "/maxfails",
1494  "maximal number of consecutive unsuccessful aggregation tries (-1: unlimited)",
1495  &sepadata->maxfails, TRUE, DEFAULT_MAXFAILS, -1, INT_MAX, NULL, NULL) );
1496  SCIP_CALL( SCIPaddIntParam(scip,
1497  "separating/" SEPA_NAME "/maxfailsroot",
1498  "maximal number of consecutive unsuccessful aggregation tries in the root node (-1: unlimited)",
1499  &sepadata->maxfailsroot, TRUE, DEFAULT_MAXFAILSROOT, -1, INT_MAX, NULL, NULL) );
1500  SCIP_CALL( SCIPaddIntParam(scip,
1501  "separating/" SEPA_NAME "/maxaggrs",
1502  "maximal number of aggregations for each row per separation round",
1503  &sepadata->maxaggrs, TRUE, DEFAULT_MAXAGGRS, 0, INT_MAX, NULL, NULL) );
1504  SCIP_CALL( SCIPaddIntParam(scip,
1505  "separating/" SEPA_NAME "/maxaggrsroot",
1506  "maximal number of aggregations for each row per separation round in the root node",
1507  &sepadata->maxaggrsroot, TRUE, DEFAULT_MAXAGGRSROOT, 0, INT_MAX, NULL, NULL) );
1508  SCIP_CALL( SCIPaddIntParam(scip,
1509  "separating/" SEPA_NAME "/maxsepacuts",
1510  "maximal number of cmir cuts separated per separation round",
1511  &sepadata->maxsepacuts, FALSE, DEFAULT_MAXSEPACUTS, 0, INT_MAX, NULL, NULL) );
1512  SCIP_CALL( SCIPaddIntParam(scip,
1513  "separating/" SEPA_NAME "/maxsepacutsroot",
1514  "maximal number of cmir cuts separated per separation round in the root node",
1515  &sepadata->maxsepacutsroot, FALSE, DEFAULT_MAXSEPACUTSROOT, 0, INT_MAX, NULL, NULL) );
1517  "separating/" SEPA_NAME "/maxslack",
1518  "maximal slack of rows to be used in aggregation",
1519  &sepadata->maxslack, TRUE, DEFAULT_MAXSLACK, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1521  "separating/" SEPA_NAME "/maxslackroot",
1522  "maximal slack of rows to be used in aggregation in the root node",
1523  &sepadata->maxslackroot, TRUE, DEFAULT_MAXSLACKROOT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1525  "separating/" SEPA_NAME "/densityscore",
1526  "weight of row density in the aggregation scoring of the rows",
1527  &sepadata->densityscore, TRUE, DEFAULT_DENSITYSCORE, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1529  "separating/" SEPA_NAME "/slackscore",
1530  "weight of slack in the aggregation scoring of the rows",
1531  &sepadata->slackscore, TRUE, DEFAULT_SLACKSCORE, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1533  "separating/" SEPA_NAME "/maxaggdensity",
1534  "maximal density of aggregated row",
1535  &sepadata->maxaggdensity, TRUE, DEFAULT_MAXAGGDENSITY, 0.0, 1.0, NULL, NULL) );
1537  "separating/" SEPA_NAME "/maxrowdensity",
1538  "maximal density of row to be used in aggregation",
1539  &sepadata->maxrowdensity, TRUE, DEFAULT_MAXROWDENSITY, 0.0, 1.0, NULL, NULL) );
1540  SCIP_CALL( SCIPaddIntParam(scip,
1541  "separating/" SEPA_NAME "/densityoffset",
1542  "additional number of variables allowed in row on top of density",
1543  &sepadata->densityoffset, TRUE, DEFAULT_DENSITYOFFSET, 0, INT_MAX, NULL, NULL) );
1545  "separating/" SEPA_NAME "/maxrowfac",
1546  "maximal row aggregation factor",
1547  &sepadata->maxrowfac, TRUE, DEFAULT_MAXROWFAC, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1548  SCIP_CALL( SCIPaddIntParam(scip,
1549  "separating/" SEPA_NAME "/maxtestdelta",
1550  "maximal number of different deltas to try (-1: unlimited)",
1551  &sepadata->maxtestdelta, TRUE, DEFAULT_MAXTESTDELTA, -1, INT_MAX, NULL, NULL) );
1553  "separating/" SEPA_NAME "/aggrtol",
1554  "tolerance for bound distances used to select continuous variable in current aggregated constraint to be eliminated",
1555  &sepadata->aggrtol, TRUE, DEFAULT_AGGRTOL, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1557  "separating/" SEPA_NAME "/trynegscaling",
1558  "should negative values also be tested in scaling?",
1559  &sepadata->trynegscaling, TRUE, DEFAULT_TRYNEGSCALING, NULL, NULL) );
1561  "separating/" SEPA_NAME "/fixintegralrhs",
1562  "should an additional variable be complemented if f0 = 0?",
1563  &sepadata->fixintegralrhs, TRUE, DEFAULT_FIXINTEGRALRHS, NULL, NULL) );
1565  "separating/" SEPA_NAME "/dynamiccuts",
1566  "should generated cuts be removed from the LP if they are no longer tight?",
1567  &sepadata->dynamiccuts, FALSE, DEFAULT_DYNAMICCUTS, NULL, NULL) );
1568 
1569  return SCIP_OKAY;
1570 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_MAXAGGRS
static SCIP_RETCODE addCut(SCIP *scip, SCIP_SOL *sol, SCIP_SEPA *sepa, SCIP_Bool makeintegral, SCIP_Real *cutcoefs, int *cutinds, int cutnnz, SCIP_Real cutrhs, SCIP_Real cutefficacy, SCIP_Bool cutislocal, SCIP_Bool cutremovable, int cutrank, const char *cutclassname, SCIP_Bool *cutoff, int *ncuts, SCIP_ROW **thecut)
#define SEPA_MAXBOUNDDIST
#define MAKECONTINTEGRAL
#define DEFAULT_DENSITYSCORE
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2167
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:17075
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPaggrRowHasRowBeenAdded(SCIP_AGGRROW *aggrrow, SCIP_ROW *row)
Definition: cuts.c:2330
SCIP_Real SCIPepsilon(SCIP *scip)
#define DEFAULT_MAXFAILSROOT
#define NULL
Definition: def.h:253
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:686
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_EXPORT int SCIPsepaGetFreq(SCIP_SEPA *sepa)
Definition: sepa.c:740
#define DEFAULT_MAXTESTDELTA
SCIP_Real SCIProwGetDualsol(SCIP_ROW *row)
Definition: lp.c:16986
public methods for SCIP parameter handling
int SCIProwGetNLPNonz(SCIP_ROW *row)
Definition: lp.c:16901
SCIP_EXPORT SCIP_Bool SCIPvarIsInLP(SCIP_VAR *var)
Definition: var.c:17077
#define BOUNDSWITCH
public methods for memory management
static SCIP_DECL_SEPACOPY(sepaCopyAggregation)
#define SCIP_MAXSTRLEN
Definition: def.h:274
#define DEFAULT_MAXROUNDSROOT
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
Definition: lp.c:16845
static SCIP_DECL_SEPAEXECSOL(sepaExecsolAggregation)
#define DEFAULT_MAXSLACKROOT
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:16887
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1352
#define DEFAULT_FIXINTEGRALRHS
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2031
int SCIPgetNLPCols(SCIP *scip)
Definition: scip_lp.c:483
int SCIPgetNLPBranchCands(SCIP *scip)
Definition: scip_branch.c:417
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1987
#define FALSE
Definition: def.h:73
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
Definition: lp.c:16835
methods for the aggregation rows
int SCIPgetRowNumIntCols(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1724
SCIP_Real SCIPgetObjNorm(SCIP *scip)
Definition: scip_prob.c:1640
#define DEFAULT_SLACKSCORE
int SCIProwGetRank(SCIP_ROW *row)
Definition: lp.c:17055
#define TRUE
Definition: def.h:72
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Real * bounddist
void SCIPaggrRowFree(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1581
SCIP_ROW ** aggrrows
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2122
public methods for problem variables
static SCIP_Real negate(SCIP_Real x)
SCIP_RETCODE SCIPsetSepaCopy(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: scip_sepa.c:141
void SCIPswapReals(SCIP_Real *value1, SCIP_Real *value2)
Definition: misc.c:9878
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:47
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1502
int SCIProwGetLPPos(SCIP_ROW *row)
Definition: lp.c:17155
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
public methods for SCIP variables
flow cover and complemented mixed integer rounding cuts separator (Marchand&#39;s version) ...
#define SCIPdebugMsg
Definition: scip_message.h:69
public methods for separator plugins
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:17085
SCIP_RETCODE SCIPaggrRowCreate(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1549
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:158
SCIP_RETCODE SCIPgetVarClosestVub(SCIP *scip, SCIP_VAR *var, SCIP_SOL *sol, SCIP_Real *closestvub, int *closestvubidx)
Definition: scip_var.c:6544
SCIP_EXPORT SCIP_VAR ** SCIPvarGetVlbVars(SCIP_VAR *var)
Definition: var.c:17556
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
int * SCIPaggrRowGetRowInds(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2308
int * SCIPaggrRowGetInds(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2353
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2077
SCIP_Real SCIProwGetNorm(SCIP_ROW *row)
Definition: lp.c:16942
public methods for numerical tolerances
SCIP_Longint SCIPgetNLPs(SCIP *scip)
public methods for querying solving statistics
SCIP_Real SCIPgetRowMinCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1742
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPgetVarClosestVlb(SCIP *scip, SCIP_VAR *var, SCIP_SOL *sol, SCIP_Real *closestvlb, int *closestvlbidx)
Definition: scip_var.c:6521
public methods for the branch-and-bound tree
#define DEFAULT_MAXROWFAC
#define SEPA_FREQ
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1479
SCIP_EXPORT void SCIPsortDownRealInt(SCIP_Real *realarray, int *intarray, int len)
static SCIP_Real aggrdataGetBoundDist(AGGREGATIONDATA *aggrdata, int probvaridx)
static SCIP_RETCODE separateCuts(SCIP *scip, SCIP_SEPA *sepa, SCIP_SOL *sol, SCIP_Bool allowlocal, SCIP_RESULT *result)
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:16912
#define MINFRAC
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip_lp.c:505
static SCIP_RETCODE aggregation(SCIP *scip, AGGREGATIONDATA *aggrdata, SCIP_SEPA *sepa, SCIP_SOL *sol, SCIP_Bool allowlocal, SCIP_Real *rowlhsscores, SCIP_Real *rowrhsscores, int startrow, int maxaggrs, SCIP_Bool *wastried, SCIP_Bool *cutoff, int *cutinds, SCIP_Real *cutcoefs, SCIP_Bool negate, int *ncuts)
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1406
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1942
#define DEFAULT_MAXAGGRSROOT
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:124
#define DEFAULT_MAXROWDENSITY
SCIP_EXPORT SCIP_Real * SCIPvarGetVubCoefs(SCIP_VAR *var)
Definition: var.c:17608
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:16922
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
int SCIPcolGetNLPNonz(SCIP_COL *col)
Definition: lp.c:16824
#define DEFAULT_MAXFAILS
#define MAXFRAC
SCIP_EXPORT SCIP_Bool SCIPsortedvecFindInt(int *intarray, int val, int len, int *pos)
#define REALABS(x)
Definition: def.h:188
void SCIPaggrRowRemoveZeros(SCIP *scip, SCIP_AGGRROW *aggrrow, SCIP_Bool *valid)
Definition: cuts.c:2285
void SCIPaggrRowClear(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:1949
static SCIP_DECL_SEPAEXECLP(sepaExeclpAggregation)
#define SCIP_CALL(x)
Definition: def.h:365
SCIP_EXPORT SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:607
SCIP_EXPORT const char * SCIPsepaGetName(SCIP_SEPA *sepa)
Definition: sepa.c:696
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_EXPORT SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17066
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
SCIP_Real SCIPinfinity(SCIP *scip)
public data structures and miscellaneous methods
#define SEPA_USESSUBSCIP
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:637
#define SCIP_Bool
Definition: def.h:70
static SCIP_RETCODE aggregateNextRow(SCIP *scip, SCIP_SEPADATA *sepadata, SCIP_Real *rowlhsscores, SCIP_Real *rowrhsscores, AGGREGATIONDATA *aggrdata, SCIP_AGGRROW *aggrrow, int *naggrs, SCIP_Bool *success)
static SCIP_Bool getRowAggregationCandidates(AGGREGATIONDATA *aggrdata, int probvaridx, SCIP_ROW ***rows, SCIP_Real **rowvarcoefs, int *nrows, int *ngoodrows)
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:99
SCIP_EXPORT SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17362
#define DEFAULT_MAXTRIES
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:16966
#define MIN(x, y)
Definition: def.h:223
SCIP_RETCODE SCIPcutGenerationHeuristicCMIR(SCIP *scip, SCIP_SOL *sol, SCIP_Bool postprocess, SCIP_Real boundswitch, SCIP_Bool usevbds, SCIP_Bool allowlocal, int maxtestdelta, int *boundsfortrans, SCIP_BOUNDTYPE *boundtypesfortrans, SCIP_Real minfrac, SCIP_Real maxfrac, 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:4225
public methods for LP management
public methods for cuts and aggregation rows
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:87
#define SEPA_NAME
SCIP_AGGRROW * aggrrow
void SCIProwChgRank(SCIP_ROW *row, int rank)
Definition: lp.c:17188
int SCIPgetNSepaRounds(SCIP *scip)
static void destroyAggregationData(SCIP *scip, AGGREGATIONDATA *aggrdata)
static SCIP_RETCODE setupAggregationData(SCIP *scip, SCIP_SOL *sol, SCIP_Bool allowlocal, AGGREGATIONDATA *aggrdata)
#define DEFAULT_TRYNEGSCALING
SCIP_EXPORT SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17408
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:129
void SCIPswapPointers(void **pointer1, void **pointer2)
Definition: misc.c:9891
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16736
int SCIPaggrRowGetNRows(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2298
public methods for the LP relaxation, rows and columns
#define SEPA_PRIORITY
#define SCIP_REAL_MAX
Definition: def.h:165
#define DEFAULT_MAXSEPACUTS
SCIP_Real SCIProwGetParallelism(SCIP_ROW *row1, SCIP_ROW *row2, char orthofunc)
Definition: lp.c:7631
#define DEFAULT_MAXAGGDENSITY
SCIP_Real * r
Definition: circlepacking.c:50
SCIP_EXPORT SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17418
methods for sorting joint arrays of various types
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1389
public methods for branching rule plugins and branching
#define DEFAULT_MAXROUNDS
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:220
general public methods
#define MAX(x, y)
Definition: def.h:222
SCIP_RETCODE SCIPaggrRowAddRow(SCIP *scip, SCIP_AGGRROW *aggrrow, SCIP_ROW *row, SCIP_Real weight, int sidetype)
Definition: cuts.c:1684
#define SEPA_DELAY
#define DEFAULT_DENSITYOFFSET
public methods for solutions
SCIP_RETCODE SCIPcalcFlowCover(SCIP *scip, SCIP_SOL *sol, SCIP_Bool postprocess, SCIP_Real boundswitch, SCIP_Bool allowlocal, 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:7412
SCIP_EXPORT SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17352
SCIP_EXPORT SCIP_Real * SCIPvarGetVlbCoefs(SCIP_VAR *var)
Definition: var.c:17566
static SCIP_DECL_SEPAFREE(sepaFreeAggregation)
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1539
public methods for message output
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1861
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10263
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:73
#define SCIP_Real
Definition: def.h:164
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17025
public methods for message handling
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_DYNAMICCUTS
#define POSTPROCESS
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2032
static SCIP_Real getRowFracActivity(SCIP_ROW *row, SCIP_Real *fractionalities)
SCIP_RETCODE SCIPincludeSepaAggregation(SCIP *scip)
SCIP_EXPORT int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17045
SCIP_EXPORT void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:617
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:331
static INLINE SCIP_Real SCIPaggrRowGetProbvarValue(SCIP_AGGRROW *aggrrow, int probindex)
Definition: cuts.h:239
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:16976
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1760
public methods for separators
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:120
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip_sepa.c:157
#define DEFAULT_MAXTRIESROOT
#define DEFAULT_MAXSEPACUTSROOT
#define SCIPABORT()
Definition: def.h:337
public methods for global and local (sub)problems
SCIP_EXPORT int SCIPsepaGetNCallsAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:823
#define USEVBDS
#define DEFAULT_AGGRTOL
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:1682
SCIP_Bool SCIPisEfficacious(SCIP *scip, SCIP_Real efficacy)
Definition: scip_cut.c:105
SCIP_EXPORT SCIP_VAR ** SCIPvarGetVubVars(SCIP_VAR *var)
Definition: var.c:17598
#define DEFAULT_MAXSLACK
#define SEPA_DESC
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:38
int SCIPaggrRowGetNNz(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2363
SCIP_Real * aggrrowscoef
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:1297
struct AggregationData AGGREGATIONDATA
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
SCIP_Real SCIPgetRowSolActivity(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
Definition: scip_lp.c:1982
SCIP_Bool SCIPisCutNew(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:313
memory allocation routines