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-2018 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file sepa_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  aggrdata->aggrrows[aggrdata->naggrrows] = colrows[k];
415  aggrdata->aggrrowscoef[aggrdata->naggrrows] = colrowvals[k];
416  ++aggrdata->naggrrows;
417  }
418  }
419  }
420  }
421 
422  /* add sentinel entry at the end */
423  aggrdata->aggrrowsstart[aggrdata->nbounddistvars] = aggrdata->naggrrows;
424 
425  /* for each continous variable that is not at its bounds check if there is a
426  * row where it is the only such variable ("good" rows). In the array with the rows that are
427  * suitable for substituting this variable move the good rows to the beginning
428  * and store the number of good rows for each of the variables.
429  * If a variable has at least one good row, then it is a "better" variable and we make
430  * the value of the bounddistance for this variable negative, to mark it.
431  * Note that better variables are continous variables that are not at their bounds
432  * and can be projected out without introducing bad variables (by using a good row).
433  */
434  {
435  int beg;
436 
437  beg = aggrdata->aggrrowsstart[0];
438  for( i = 0; i < aggrdata->nbounddistvars; ++i )
439  {
440  int k;
441  int ngoodrows;
442  int end;
443 
444  end = aggrdata->aggrrowsstart[i + 1];
445  ngoodrows = 0;
446  for( k = beg; k < end; ++k )
447  {
448  int lppos = SCIProwGetLPPos(aggrdata->aggrrows[k]);
449 
450  if( aggrdata->nbadvarsinrow[lppos] == 1 &&
451  SCIPisEQ(scip, SCIProwGetLhs(aggrdata->aggrrows[k]), SCIProwGetRhs(aggrdata->aggrrows[k])) )
452  {
453  int nextgoodrowpos = beg + ngoodrows;
454  if( k > nextgoodrowpos )
455  {
456  SCIPswapPointers((void**) (&aggrdata->aggrrows[k]), (void**) (&aggrdata->aggrrows[nextgoodrowpos]));
457  SCIPswapReals(&aggrdata->aggrrowscoef[k], &aggrdata->aggrrowscoef[nextgoodrowpos]);
458  }
459  ++ngoodrows;
460  }
461  }
462  if( ngoodrows > 0 )
463  {
464  aggrdata->bounddist[i] = -aggrdata->bounddist[i];
465  }
466  aggrdata->ngoodaggrrows[i] = ngoodrows;
467  beg = end;
468  }
469  }
470 
471  return SCIP_OKAY;
472 }
473 
474 /** free resources held in aggregation data */
475 static
477  SCIP* scip, /**< SCIP datastructure */
478  AGGREGATIONDATA* aggrdata /**< pointer to ggregation data */
479  )
480 {
481  SCIPaggrRowFree(scip, &aggrdata->aggrrow);
483  SCIPfreeBufferArrayNull(scip, &aggrdata->aggrrows);
484  SCIPfreeBufferArray(scip, &aggrdata->nbadvarsinrow);
485  SCIPfreeBufferArray(scip, &aggrdata->aggrrowsstart);
486  SCIPfreeBufferArray(scip, &aggrdata->ngoodaggrrows);
487  SCIPfreeBufferArray(scip, &aggrdata->bounddistinds);
488  SCIPfreeBufferArray(scip, &aggrdata->bounddist);
489 }
490 
491 /** retrieves the candidate rows for canceling out the given variable, also returns the number of "good" rows which are the
492  * rows stored at the first ngoodrows positions. A row is good if its continuous variables are all at their bounds, except
493  * maybe the given continuous variable (in probvaridx)
494  */
495 static
497  AGGREGATIONDATA* aggrdata, /**< pointer to ggregation data */
498  int probvaridx, /**< problem index of variables to retrieve candidates for */
499  SCIP_ROW*** rows, /**< pointer to store array to candidate rows */
500  SCIP_Real** rowvarcoefs, /**< pointer to store array of coefficients of given variable in the corresponding rows */
501  int* nrows, /**< pointer to return number of rows in returned arrays */
502  int* ngoodrows /**< pointer to return number of "good" rows in the returned arrays */
503  )
504 {
505  int aggrdataidx;
506 
507  if( !SCIPsortedvecFindInt(aggrdata->bounddistinds, probvaridx, aggrdata->nbounddistvars, &aggrdataidx) )
508  return FALSE;
509 
510  *rows = aggrdata->aggrrows + aggrdata->aggrrowsstart[aggrdataidx];
511  *nrows = aggrdata->aggrrowsstart[aggrdataidx + 1] - aggrdata->aggrrowsstart[aggrdataidx];
512  *rowvarcoefs = aggrdata->aggrrowscoef + aggrdata->aggrrowsstart[aggrdataidx];
513  *ngoodrows = aggrdata->ngoodaggrrows[aggrdataidx];
514 
515  return TRUE;
516 }
517 
518 /** find the bound distance value in the aggregation data struct for the given variable problem index */
519 static
521  AGGREGATIONDATA* aggrdata, /**< SCIP datastructure */
522  int probvaridx /**< problem index of variables to retrieve candidates for */
523  )
524 {
525  int aggrdataidx;
527  if( !SCIPsortedvecFindInt(aggrdata->bounddistinds, probvaridx, aggrdata->nbounddistvars, &aggrdataidx) )
528  return 0.0;
529 
530  return aggrdata->bounddist[aggrdataidx];
531 }
532 
533 /** Aggregates the next row suitable for cancelling out an active continuous variable.
534  *
535  * Equality rows that contain no other active continuous variables are preffered and apart from that
536  * the scores for the rows are used to determine which row is aggregated next
537  */
538 static
540  SCIP* scip, /**< SCIP data structure */
541  SCIP_SEPADATA* sepadata, /**< separator data */
542  SCIP_Real* rowlhsscores, /**< aggregation scores for left hand sides of row */
543  SCIP_Real* rowrhsscores, /**< aggregation scores for right hand sides of row */
544  AGGREGATIONDATA* aggrdata, /**< aggregation data */
545  SCIP_AGGRROW* aggrrow, /**< current aggregation row */
546  int* naggrs, /**< pointer to increase counter if real aggregation took place */
547  SCIP_Bool* success /**< pointer to return whether another row was added to the aggregation row */
548  )
549 {
550  int i;
551  int firstcontvar;
552  int* badvarinds;
553  SCIP_Real* badvarbddist;
554  int nbadvars;
555  SCIP_Real minbddist;
556  SCIP_ROW* bestrow;
557  SCIP_Real bestrowscore;
558  SCIP_Real aggrfac;
559  int bestrowside;
560  int ncontvars;
561  int nnz = SCIPaggrRowGetNNz(aggrrow);
562  int* inds = SCIPaggrRowGetInds(aggrrow);
563 
564  assert( success != NULL );
565  *success = FALSE;
566 
567  firstcontvar = SCIPgetNBinVars(scip) + SCIPgetNIntVars(scip);
568  ncontvars = SCIPgetNImplVars(scip) + SCIPgetNContVars(scip);
569  assert( firstcontvar + ncontvars == SCIPgetNVars(scip) );
570 
571  SCIP_CALL( SCIPallocBufferArray(scip, &badvarinds, MIN(ncontvars, nnz)) );
572  SCIP_CALL( SCIPallocBufferArray(scip, &badvarbddist, MIN(ncontvars, nnz)) );
573 
574  nbadvars = 0;
575 
576  for( i = 0; i < nnz; ++i )
577  {
578  SCIP_Real bounddist;
579 
580  /* only consider continuous variables */
581  if( inds[i] < firstcontvar )
582  continue;
583 
584  bounddist = aggrdataGetBoundDist(aggrdata, inds[i]);
585 
586  if( bounddist == 0.0 )
587  continue;
588 
589  badvarinds[nbadvars] = inds[i];
590  badvarbddist[nbadvars] = bounddist;
591  ++nbadvars;
592  }
593 
594  if( nbadvars == 0 )
595  goto TERMINATE;
596 
597  SCIPsortDownRealInt(badvarbddist, badvarinds, nbadvars);
598 
599  aggrfac = 0.0;
600  bestrowscore = 0.0;
601  bestrowside = 0;
602  minbddist = 0.0;
603  bestrow = NULL;
604 
605  /* because the "good" bad variables have a negative bound distance, they are at the end */
606  for( i = nbadvars - 1; i >= 0; --i )
607  {
608  int probvaridx;
609  SCIP_ROW** candrows;
610  SCIP_Real* candrowcoefs;
611  int nrows;
612  int ngoodrows;
613  int k;
614 
615  /* if the bound distance is not negative, there are no more good variables so stop */
616  if( badvarbddist[i] > 0.0 )
617  break;
618 
619  /* if no best row was found yet, this variable has the currently best bound distance */
620  if( aggrfac == 0.0 )
621  minbddist = -badvarbddist[i] * (1.0 - sepadata->aggrtol);
622 
623  /* if the bound distance of the current variable is smaller than the minimum bound distance stop looping */
624  if( -badvarbddist[i] < minbddist )
625  break;
626 
627  probvaridx = badvarinds[i];
628 
629  if( !getRowAggregationCandidates(aggrdata, probvaridx, &candrows, &candrowcoefs, &nrows, &ngoodrows) )
630  {
631  SCIPABORT();
632  }
633  assert(ngoodrows > 0); /* bounddistance was negative for this variable, so it should have good rows */
634 
635  for( k = 0; k < ngoodrows; ++k )
636  {
637  SCIP_Real rowaggrfac;
638  SCIP_Real rowscore;
639  int lppos;
640 
641  /* do not add rows twice */
642  if( SCIPaggrRowHasRowBeenAdded(aggrrow, candrows[k]) )
643  continue;
644 
645  rowaggrfac = - SCIPaggrRowGetProbvarValue(aggrrow, probvaridx) / candrowcoefs[k];
646 
647  /* if factor is too extreme skip this row */
648  if( SCIPisFeasZero(scip, rowaggrfac) || REALABS(rowaggrfac) > sepadata->maxrowfac )
649  continue;
650 
651  lppos = SCIProwGetLPPos(candrows[k]);
652 
653  /* row could be used and good rows are equalities, so ignore sidetype */
654  rowscore = MAX(rowlhsscores[lppos], rowrhsscores[lppos]);
655 
656  /* if this rows score is better than the currently best score, remember it */
657  if( aggrfac == 0.0 || rowscore > bestrowscore )
658  {
659  bestrow = candrows[k];
660  aggrfac = rowaggrfac;
661  bestrowscore = rowscore;
662  bestrowside = 0;
663  }
664  }
665  }
666 
667  /* found a row among the good rows, so aggregate it and stop */
668  if( aggrfac != 0.0 )
669  {
670  ++(*naggrs);
671  SCIP_CALL( SCIPaggrRowAddRow(scip, aggrrow, bestrow, aggrfac, bestrowside) );
672  SCIPaggrRowRemoveZeros(scip, aggrrow, success);
673  goto TERMINATE;
674  }
675 
676  for( i = 0; i < nbadvars; ++i )
677  {
678  int probvaridx;
679  SCIP_ROW** candrows;
680  SCIP_Real* candrowcoefs;
681  int nrows;
682  int ngoodrows;
683  int k;
684 
685  /* if the bound distance is negative, there are no more variables to be tested, so stop */
686  if( badvarbddist[i] < 0.0 )
687  break;
688 
689  /* if no best row was found yet, this variable has the currently best bound distance */
690  if( aggrfac == 0.0 )
691  minbddist = badvarbddist[i] * (1.0 - sepadata->aggrtol);
692 
693  /* if the bound distance of the current variable is smaller than the minimum bound distance stop looping */
694  if( badvarbddist[i] < minbddist )
695  break;
696 
697  probvaridx = badvarinds[i];
698 
699  if( !getRowAggregationCandidates(aggrdata, probvaridx, &candrows, &candrowcoefs, &nrows, &ngoodrows) )
700  {
701  SCIPABORT();
702  }
703 
704  /* bounddistance was positive for this variable, so it should not have good rows */
705  assert(ngoodrows == 0);
706 
707  for( k = 0; k < nrows; ++k )
708  {
709  SCIP_Real rowaggrfac;
710  SCIP_Real rowscore;
711  int rowside;
712  int lppos;
713 
714  /* do not add rows twice */
715  if( SCIPaggrRowHasRowBeenAdded(aggrrow, candrows[k]) )
716  continue;
717 
718  rowaggrfac = - SCIPaggrRowGetProbvarValue(aggrrow, probvaridx) / candrowcoefs[k];
719 
720  /* if factor is too extreme skip this row */
721  if( SCIPisFeasZero(scip, rowaggrfac) || REALABS(rowaggrfac) > sepadata->maxrowfac )
722  continue;
723 
724  /* row could be used, decide which side */
725  lppos = SCIProwGetLPPos(candrows[k]);
726 
727  /* either both or none of the rowscores are 0.0 so use the one which gives a positive slack */
728  if( (rowaggrfac < 0.0 && !SCIPisInfinity(scip, -SCIProwGetLhs(candrows[k]))) || SCIPisInfinity(scip, SCIProwGetRhs(candrows[k])) )
729  {
730  rowscore = rowlhsscores[lppos];
731  rowside = -1;
732  }
733  else
734  {
735  rowscore = rowrhsscores[lppos];
736  rowside = 1;
737  }
738 
739  /* if this rows score is better than the currently best score, remember it */
740  if( aggrfac == 0.0 || SCIPisGT(scip, rowscore, bestrowscore) ||
741  (SCIPisEQ(scip, rowscore, bestrowscore) && aggrdata->nbadvarsinrow[lppos] < aggrdata->nbadvarsinrow[SCIProwGetLPPos(bestrow)]) )
742  {
743  bestrow = candrows[k];
744  aggrfac = rowaggrfac;
745  bestrowscore = rowscore;
746  bestrowside = rowside;
747  }
748  }
749  }
750 
751  /* found a row so aggregate it */
752  if( aggrfac != 0.0 )
753  {
754  ++(*naggrs);
755  SCIP_CALL( SCIPaggrRowAddRow(scip, aggrrow, bestrow, aggrfac, bestrowside) );
756  SCIPaggrRowRemoveZeros(scip, aggrrow, success);
757  }
758 
759 TERMINATE:
760  SCIPfreeBufferArray(scip, &badvarbddist);
761  SCIPfreeBufferArray(scip, &badvarinds);
762 
763  return SCIP_OKAY;
764 }
765 
766 /** aggregates different single mixed integer constraints by taking linear combinations of the rows of the LP */
767 static
769  SCIP* scip, /**< SCIP data structure */
770  AGGREGATIONDATA* aggrdata, /**< pointer to aggregation data */
771  SCIP_SEPA* sepa, /**< separator */
772  SCIP_SOL* sol, /**< the solution that should be separated, or NULL for LP solution */
773  SCIP_Bool allowlocal, /**< should local cuts be allowed */
774  SCIP_Real* rowlhsscores, /**< aggregation scores for left hand sides of row */
775  SCIP_Real* rowrhsscores, /**< aggregation scores for right hand sides of row */
776  int startrow, /**< index of row to start aggregation */
777  int maxaggrs, /**< maximal number of aggregations */
778  SCIP_Bool* wastried, /**< pointer to store whether the given startrow was actually tried */
779  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
780  int* cutinds, /**< buffer array to store temporarily cut */
781  SCIP_Real* cutcoefs, /**< buffer array to store temporarily cut */
782  SCIP_Bool negate, /**< should the start row be multiplied by -1 */
783  int* ncuts /**< pointer to count the number of generated cuts */
784  )
785 {
786  SCIP_SEPADATA* sepadata;
787  SCIP_ROW** rows;
788 
789  SCIP_Real startweight;
790  SCIP_Real startrowact;
791  int maxaggrnonzs;
792  int naggrs;
793  int nrows;
794  int maxtestdelta;
795 
796  SCIP_Real cutrhs;
797  SCIP_Real cutefficacy;
798 
799  assert(scip != NULL);
800  assert(sepa != NULL);
801  assert(rowlhsscores != NULL);
802  assert(rowrhsscores != NULL);
803  assert(wastried != NULL);
804  assert(cutoff != NULL);
805  assert(ncuts != NULL);
806 
807  sepadata = SCIPsepaGetData(sepa);
808  assert(sepadata != NULL);
809 
810  *cutoff = FALSE;
811  *wastried = FALSE;
812 
813  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
814  assert(nrows == 0 || rows != NULL);
815  assert(0 <= startrow && startrow < nrows);
816 
817  SCIPdebugMsg(scip, "start c-MIR aggregation with row <%s> (%d/%d)\n", SCIProwGetName(rows[startrow]), startrow, nrows);
818 
819  /* calculate maximal number of non-zeros in aggregated row */
820  maxaggrnonzs = (int)(sepadata->maxaggdensity * SCIPgetNLPCols(scip)) + sepadata->densityoffset;
821 
822  startrowact = SCIPgetRowSolActivity(scip, rows[startrow], sol);
823 
824  if( startrowact <= 0.5 * SCIProwGetLhs(rows[startrow]) + 0.5 * SCIProwGetRhs(rows[startrow]) )
825  startweight = -1.0;
826  else
827  startweight = 1.0;
828 
829  maxtestdelta = sepadata->maxtestdelta == -1 ? INT_MAX : sepadata->maxtestdelta;
830 
831  /* add start row to the initially empty aggregation row (aggrrow) */
832  SCIP_CALL( SCIPaggrRowAddRow(scip, aggrdata->aggrrow, rows[startrow], negate ? -startweight : startweight, 0) );
833 
834  /* try to generate cut from the current aggregated row; add cut if found, otherwise add another row to aggrrow
835  * in order to get rid of a continuous variable
836  */
837  naggrs = 0;
838  while( naggrs <= maxaggrs )
839  {
840  int cutrank;
841  int cutnnz;
842  SCIP_Bool aggrsuccess;
843  SCIP_Bool cmirsuccess;
844  SCIP_Bool cmircutislocal;
845  SCIP_Bool flowcoversuccess;
846  SCIP_Real flowcoverefficacy;
847  SCIP_Bool flowcovercutislocal;
848  SCIP_ROW* cut = NULL;
849 
850  *wastried = TRUE;
851 
852  /* Step 1:
853  * try to generate a MIR cut out of the current aggregated row
854  */
855 
856  flowcoverefficacy = -SCIPinfinity(scip);
857 
858  if( sepadata->sepflowcover )
859  {
860  SCIP_CALL( SCIPcalcFlowCover(scip, sol, POSTPROCESS, BOUNDSWITCH, allowlocal, aggrdata->aggrrow,
861  cutcoefs, &cutrhs, cutinds, &cutnnz, &flowcoverefficacy, &cutrank, &flowcovercutislocal, &flowcoversuccess) );
862  }
863  else
864  {
865  flowcoversuccess = FALSE;
866  }
867 
868  cutefficacy = flowcoverefficacy;
869 
870  if( sepadata->sepcmir )
871  {
872  SCIP_CALL( SCIPcutGenerationHeuristicCMIR(scip, sol, POSTPROCESS, BOUNDSWITCH, USEVBDS, allowlocal, maxtestdelta, NULL, NULL, MINFRAC, MAXFRAC,
873  aggrdata->aggrrow, cutcoefs, &cutrhs, cutinds, &cutnnz, &cutefficacy, &cutrank, &cmircutislocal, &cmirsuccess) );
874  }
875  else
876  {
877  cmirsuccess = FALSE;
878  }
879 
880  if( cmirsuccess )
881  {
882  SCIP_CALL( addCut(scip, sol, sepadata->cmir, FALSE, cutcoefs, cutinds, cutnnz, cutrhs, cutefficacy, cmircutislocal,
883  sepadata->dynamiccuts, cutrank, "cmir", cutoff, ncuts, &cut) ); /*lint !e644*/
884  }
885  else if ( flowcoversuccess )
886  {
887  /* cppcheck-suppress uninitvar */
888  SCIP_CALL( addCut(scip, sol, sepadata->flowcover, FALSE, cutcoefs, cutinds, cutnnz, cutrhs, cutefficacy, flowcovercutislocal,
889  sepadata->dynamiccuts, cutrank, "flowcover", cutoff, ncuts, &cut) ); /*lint !e644*/
890  }
891 
892  if ( *cutoff )
893  {
894  if( cut != NULL )
895  {
896  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
897  }
898  break;
899  }
900 
901  /* if the cut was successfully added, decrease the score of the rows used in the aggregation and clean the aggregation
902  * row (and call this function again with a different start row for aggregation)
903  */
904  if( cut != NULL )
905  {
906  int* rowinds;
907  int i;
908 
909  rowinds = SCIPaggrRowGetRowInds(aggrdata->aggrrow);
910  nrows = SCIPaggrRowGetNRows(aggrdata->aggrrow);
911 
912  /* decrease row score of used rows slightly */
913  for( i = 0; i < nrows; ++i )
914  {
915  SCIP_Real fac = 1.0 - 0.999 * SCIProwGetParallelism(rows[rowinds[i]], cut, 'e');
916 
917  rowlhsscores[rowinds[i]] *= fac;
918  rowrhsscores[rowinds[i]] *= fac;
919  }
920 
921  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
922 
923  SCIPdebugMsg(scip, " -> abort aggregation: cut found\n");
924  break;
925  }
926 
927  /* Step 2:
928  * aggregate an additional row in order to remove a continuous variable
929  */
930 
931  /* abort, if we reached the maximal number of aggregations */
932  if( naggrs == maxaggrs )
933  {
934  SCIPdebugMsg(scip, " -> abort aggregation: maximal number of aggregations reached\n");
935  break;
936  }
937 
938  SCIP_CALL( aggregateNextRow(scip, sepadata, rowlhsscores, rowrhsscores, aggrdata, aggrdata->aggrrow,
939  &naggrs, &aggrsuccess) );
940 
941  /* no suitable aggregation was found or number of non-zeros is now too large so abort */
942  if( ! aggrsuccess || SCIPaggrRowGetNNz(aggrdata->aggrrow) > maxaggrnonzs || SCIPaggrRowGetNNz(aggrdata->aggrrow) == 0 )
943  {
944  break;
945  }
946 
947  SCIPdebugMsg(scip, " -> current aggregation has %d/%d nonzeros and consists of %d/%d rows\n",
948  SCIPaggrRowGetNNz(aggrdata->aggrrow), maxaggrnonzs, naggrs, maxaggrs);
949  }
950 
951  SCIPaggrRowClear(aggrdata->aggrrow);
952 
953  return SCIP_OKAY;
954 }
955 
956 /** gives an estimate of how much the activity of this row is affected by fractionality in the current solution */
957 static
959  SCIP_ROW* row, /**< the LP row */
960  SCIP_Real* fractionalities /**< array of fractionalities for each variable */
961  )
962 {
963  int nlpnonz;
964  int i;
965  SCIP_COL** cols;
966  SCIP_Real* vals;
967  SCIP_Real fracsum = 0.0;
968 
969  cols = SCIProwGetCols(row);
970  vals = SCIProwGetVals(row);
971  nlpnonz = SCIProwGetNLPNonz(row);
972 
973  for( i = 0; i < nlpnonz; ++i )
974  {
975  SCIP_VAR* var = SCIPcolGetVar(cols[i]);
976  fracsum += REALABS(vals[i] * fractionalities[SCIPvarGetProbindex(var)]);
977  }
978 
979  return fracsum;
980 }
981 
982 /** searches and adds c-MIR cuts that separate the given primal solution */
983 static
985  SCIP* scip, /**< SCIP data structure */
986  SCIP_SEPA* sepa, /**< the c-MIR separator */
987  SCIP_SOL* sol, /**< the solution that should be separated, or NULL for LP solution */
988  SCIP_Bool allowlocal, /**< should local cuts be allowed */
989  SCIP_RESULT* result /**< pointer to store the result */
990  )
991 {
992  AGGREGATIONDATA aggrdata;
993  SCIP_SEPADATA* sepadata;
994  SCIP_VAR** vars;
995  SCIP_Real* varsolvals;
996  SCIP_Real* bestcontlbs;
997  SCIP_Real* bestcontubs;
998  SCIP_Real* fractionalities;
999  SCIP_ROW** rows;
1000  SCIP_Real* rowlhsscores;
1001  SCIP_Real* rowrhsscores;
1002  SCIP_Real* rowscores;
1003  int* roworder;
1004  SCIP_Real maxslack;
1005  SCIP_Bool cutoff = FALSE;
1006  int nvars;
1007  int nintvars;
1008  int ncontvars;
1009  int nrows;
1010  int nnonzrows;
1011  int zerorows;
1012  int ntries;
1013  int nfails;
1014  int depth;
1015  int ncalls;
1016  int maxtries;
1017  int maxfails;
1018  int maxaggrs;
1019  int maxsepacuts;
1020  int ncuts;
1021  int r;
1022  int v;
1023 
1024  int* cutinds;
1025  SCIP_Real* cutcoefs;
1026 
1027  assert(result != NULL);
1028  assert(*result == SCIP_DIDNOTRUN);
1029 
1030  sepadata = SCIPsepaGetData(sepa);
1031  assert(sepadata != NULL);
1032 
1033  depth = SCIPgetDepth(scip);
1034  ncalls = SCIPsepaGetNCallsAtNode(sepa);
1035 
1036  /* only call the cmir cut separator a given number of times at each node */
1037  if( (depth == 0 && sepadata->maxroundsroot >= 0 && ncalls >= sepadata->maxroundsroot)
1038  || (depth > 0 && sepadata->maxrounds >= 0 && ncalls >= sepadata->maxrounds) )
1039  return SCIP_OKAY;
1040 
1041  /* check which cuts should be separated */
1042  {
1043  int cmirfreq;
1044  int flowcoverfreq;
1045 
1046  cmirfreq = SCIPsepaGetFreq(sepadata->cmir);
1047  flowcoverfreq = SCIPsepaGetFreq(sepadata->flowcover);
1048 
1049  sepadata->sepcmir = cmirfreq > 0 ? (depth % cmirfreq) == 0 : cmirfreq == depth;
1050  sepadata->sepflowcover = flowcoverfreq > 0 ? (depth % flowcoverfreq) == 0 : flowcoverfreq == depth;
1051  }
1052 
1053  if( ! sepadata->sepcmir && ! sepadata->sepflowcover )
1054  return SCIP_OKAY;
1055 
1056  /* get all rows and number of columns */
1057  SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
1058  assert(nrows == 0 || rows != NULL);
1059 
1060  /* nothing to do, if LP is empty */
1061  if( nrows == 0 )
1062  return SCIP_OKAY;
1063 
1064  /* check whether SCIP was stopped in the meantime */
1065  if( SCIPisStopped(scip) )
1066  return SCIP_OKAY;
1067 
1068  /* get active problem variables */
1069  vars = SCIPgetVars(scip);
1070  nvars = SCIPgetNVars(scip);
1071  ncontvars = SCIPgetNContVars(scip);
1072 #ifdef IMPLINTSARECONT
1073  ncontvars += SCIPgetNImplVars(scip); /* also aggregate out implicit integers */
1074 #endif
1075  nintvars = nvars - ncontvars;
1076  assert(nvars == 0 || vars != NULL);
1077 
1078  /* nothing to do, if problem has no variables */
1079  if( nvars == 0 )
1080  return SCIP_OKAY;
1081 
1082  SCIPdebugMsg(scip, "separating c-MIR cuts\n");
1083 
1084  *result = SCIP_DIDNOTFIND;
1085 
1086  /* get data structure */
1087  SCIP_CALL( SCIPallocBufferArray(scip, &rowlhsscores, nrows) );
1088  SCIP_CALL( SCIPallocBufferArray(scip, &rowrhsscores, nrows) );
1089  SCIP_CALL( SCIPallocBufferArray(scip, &rowscores, 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 
1098  /* get the solution values for all active variables */
1099  SCIP_CALL( SCIPgetSolVals(scip, sol, nvars, vars, varsolvals) );
1100 
1101  /* calculate the fractionality of the integer variables in the current solution */
1102  for( v = 0; v < nintvars; ++v )
1103  {
1104  fractionalities[v] = SCIPfeasFrac(scip, varsolvals[v]);
1105  fractionalities[v] = MIN(fractionalities[v], 1.0 - fractionalities[v]);
1106  }
1107 
1108  /* calculate the fractionality of the continuous variables in the current solution;
1109  * The fractionality of a continuous variable x is defined to be a * f_y,
1110  * if there is a variable bound x <= a * y + c where f_y is the fractionality of y
1111  * and in the current solution the variable bound has no slack.
1112  */
1113  for( ; v < nvars; ++v )
1114  {
1115  SCIP_VAR** vlbvars;
1116  SCIP_VAR** vubvars;
1117  SCIP_Real* vlbcoefs;
1118  SCIP_Real* vubcoefs;
1119  SCIP_Real closestvlb;
1120  SCIP_Real closestvub;
1121  int closestvlbidx;
1122  int closestvubidx;
1123 
1124  SCIP_CALL( SCIPgetVarClosestVlb(scip, vars[v], sol, &closestvlb, &closestvlbidx) );
1125  SCIP_CALL( SCIPgetVarClosestVub(scip, vars[v], sol, &closestvub, &closestvubidx) );
1126 
1127  vlbvars = SCIPvarGetVlbVars(vars[v]);
1128  vubvars = SCIPvarGetVubVars(vars[v]);
1129  vlbcoefs = SCIPvarGetVlbCoefs(vars[v]);
1130  vubcoefs = SCIPvarGetVubCoefs(vars[v]);
1131 
1132  fractionalities[v] = 0.0;
1133  if( closestvlbidx != -1 && SCIPisEQ(scip, varsolvals[v], closestvlb) )
1134  {
1135  int vlbvarprobidx = SCIPvarGetProbindex(vlbvars[closestvlbidx]);
1136  SCIP_Real frac = SCIPfeasFrac(scip, varsolvals[vlbvarprobidx]);
1137 
1138  if( frac < 0.0 )
1139  frac = 0.0;
1140  assert(frac >= 0.0 && frac < 1.0);
1141  frac = MIN(frac, 1.0 - frac) * vlbcoefs[closestvlbidx];
1142  fractionalities[v] += frac;
1143  }
1144 
1145  if( closestvubidx != -1 && SCIPisEQ(scip, varsolvals[v], closestvub) )
1146  {
1147  int vubvarprobidx = SCIPvarGetProbindex(vubvars[closestvubidx]);
1148  SCIP_Real frac = SCIPfeasFrac(scip, varsolvals[vubvarprobidx]);
1149 
1150  if( frac < 0.0 )
1151  frac = 0.0;
1152  assert(frac >= 0.0 && frac < 1.0);
1153  frac = MIN(frac, 1.0 - frac) * vubcoefs[closestvubidx];
1154  fractionalities[v] += frac;
1155  }
1156  }
1157 
1158  /* get the maximal number of cuts allowed in a separation round */
1159  if( depth == 0 )
1160  {
1161  maxtries = sepadata->maxtriesroot;
1162  maxfails = sepadata->maxfailsroot;
1163  maxaggrs = sepadata->maxaggrsroot;
1164  maxsepacuts = sepadata->maxsepacutsroot;
1165  maxslack = sepadata->maxslackroot;
1166  }
1167  else
1168  {
1169  maxtries = sepadata->maxtries;
1170  maxfails = sepadata->maxfails;
1171  maxaggrs = sepadata->maxaggrs;
1172  maxsepacuts = sepadata->maxsepacuts;
1173  maxslack = sepadata->maxslack;
1174  }
1175 
1176  /* calculate aggregation scores for both sides of all rows, and sort rows by decreasing maximal score
1177  * TODO: document score definition */
1178 
1179  /* count the number of non-zero rows and zero rows. these values are used for the sorting of the rowscores.
1180  * only the non-zero rows need to be sorted. */
1181  nnonzrows = 0;
1182  zerorows = 0;
1183  for( r = 0; r < nrows; r++ )
1184  {
1185  int nnonz;
1186  int i;
1187 
1188  assert(SCIProwGetLPPos(rows[r]) == r);
1189 
1190  nnonz = SCIProwGetNLPNonz(rows[r]);
1191  if( nnonz == 0 )
1192  {
1193  /* ignore empty rows */
1194  rowlhsscores[r] = 0.0;
1195  rowrhsscores[r] = 0.0;
1196 
1197  /* add the row number to the back of roworder for zero rows */
1198  zerorows++;
1199  rowscores[r] = 0.0;
1200  roworder[nrows - zerorows] = r;
1201  }
1202  else
1203  {
1204  SCIP_Real activity;
1205  SCIP_Real lhs;
1206  SCIP_Real rhs;
1207  SCIP_Real dualsol;
1208  SCIP_Real dualscore;
1209  SCIP_Real rowdensity;
1210  SCIP_Real rownorm;
1211  SCIP_Real slack;
1212  SCIP_Real fracact;
1213  SCIP_Real fracscore;
1214  SCIP_Real objnorm;
1215 
1216  objnorm = SCIPgetObjNorm(scip);
1217  objnorm = MAX(objnorm, 1.0);
1218 
1219  fracact = getRowFracActivity(rows[r], fractionalities);
1220  dualsol = (sol == NULL ? SCIProwGetDualsol(rows[r]) : 1.0);
1221  activity = SCIPgetRowSolActivity(scip, rows[r], sol);
1222  lhs = SCIProwGetLhs(rows[r]);
1223  rhs = SCIProwGetRhs(rows[r]);
1224  rownorm = SCIProwGetNorm(rows[r]);
1225  rownorm = MAX(rownorm, 0.1);
1226  rowdensity = (SCIP_Real)(nnonz - sepadata->densityoffset)/(SCIP_Real)nvars;
1227  assert(SCIPisPositive(scip, rownorm));
1228  fracscore = fracact / rownorm;
1229 
1230  slack = (activity - lhs)/rownorm;
1231  dualscore = MAX(fracscore * dualsol/objnorm, 0.0001);
1232  if( !SCIPisInfinity(scip, -lhs) && SCIPisLE(scip, slack, maxslack)
1233  && (allowlocal || !SCIProwIsLocal(rows[r])) /*lint !e506 !e774*/
1234  && rowdensity <= sepadata->maxrowdensity
1235  && rowdensity <= sepadata->maxaggdensity ) /*lint !e774*/
1236  {
1237  rowlhsscores[r] = dualscore + sepadata->densityscore * (1.0-rowdensity) + sepadata->slackscore * MAX(1.0 - slack, 0.0);
1238  assert(rowlhsscores[r] > 0.0);
1239  }
1240  else
1241  rowlhsscores[r] = 0.0;
1242 
1243  slack = (rhs - activity)/rownorm;
1244  dualscore = MAX(-fracscore * dualsol/objnorm, 0.0001);
1245  if( !SCIPisInfinity(scip, rhs) && SCIPisLE(scip, slack, maxslack)
1246  && (allowlocal || !SCIProwIsLocal(rows[r])) /*lint !e506 !e774*/
1247  && rowdensity <= sepadata->maxrowdensity
1248  && rowdensity <= sepadata->maxaggdensity ) /*lint !e774*/
1249  {
1250  rowrhsscores[r] = dualscore + sepadata->densityscore * (1.0-rowdensity) + sepadata->slackscore * MAX(1.0 - slack, 0.0);
1251  assert(rowrhsscores[r] > 0.0);
1252  }
1253  else
1254  rowrhsscores[r] = 0.0;
1255 
1256  /* for the row order only use the fractionality score since it best indicates how likely it is to find a cut */
1257  rowscores[r] = fracscore;
1258  if( rowscores[r] == 0.0 )
1259  {
1260  /* add the row number to the back of roworder for zero rows */
1261  zerorows++;
1262  roworder[nrows - zerorows] = r;
1263  }
1264  else
1265  {
1266  /* insert the row number in the correct position of roworder */
1267  for( i = nnonzrows; i > 0 && rowscores[r] > rowscores[roworder[i - 1]]; --i )
1268  roworder[i] = roworder[i - 1];
1269  roworder[i] = r;
1270 
1271  nnonzrows++;
1272  }
1273  }
1274 
1275  SCIPdebugMsg(scip, " -> row %d <%s>: lhsscore=%g rhsscore=%g maxscore=%g\n", r, SCIProwGetName(rows[r]),
1276  rowlhsscores[r], rowrhsscores[r], rowscores[r]);
1277  }
1278  assert(nrows == nnonzrows + zerorows);
1279 
1280  /* calculate the data required for performing the row aggregation */
1281  SCIP_CALL( setupAggregationData(scip, sol, allowlocal, &aggrdata) );
1282 
1283  ncuts = 0;
1284  if( maxtries < 0 )
1285  maxtries = INT_MAX;
1286  if( maxfails < 0 )
1287  maxfails = INT_MAX;
1288  else if( depth == 0 && 2 * SCIPgetNSepaRounds(scip) < maxfails )
1289  maxfails += maxfails - 2 * SCIPgetNSepaRounds(scip); /* allow up to double as many fails in early separounds of root node */
1290 
1291  /* start aggregation heuristic for each row in the LP and generate resulting cuts */
1292  ntries = 0;
1293  nfails = 0;
1294  for( r = 0; r < nnonzrows && ntries < maxtries && ncuts < maxsepacuts && !SCIPisStopped(scip); r++ )
1295  {
1296  SCIP_Bool wastried;
1297  int oldncuts;
1298 
1299  oldncuts = ncuts;
1300  SCIP_CALL( aggregation(scip, &aggrdata, sepa, sol, allowlocal, rowlhsscores, rowrhsscores,
1301  roworder[r], maxaggrs, &wastried, &cutoff, cutinds, cutcoefs, FALSE, &ncuts) );
1302 
1303  /* if trynegscaling is true we start the aggregation heuristic again for this row, but multiply it by -1 first.
1304  * This is done by calling the aggregation function with the parameter negate equal to TRUE
1305  */
1306  if( sepadata->trynegscaling && !cutoff )
1307  {
1308  SCIP_CALL( aggregation(scip, &aggrdata, sepa, sol, allowlocal, rowlhsscores, rowrhsscores,
1309  roworder[r], maxaggrs, &wastried, &cutoff, cutinds, cutcoefs, TRUE, &ncuts) );
1310  }
1311 
1312  if ( cutoff )
1313  break;
1314 
1315  if( !wastried )
1316  {
1317  continue;
1318  }
1319  ntries++;
1320 
1321  if( ncuts == oldncuts )
1322  {
1323  nfails++;
1324  if( nfails >= maxfails )
1325  {
1326  break;
1327  }
1328  }
1329  else
1330  {
1331  nfails = 0;
1332  }
1333  }
1334 
1335  /* free data structure */
1336  destroyAggregationData(scip, &aggrdata);
1337  SCIPfreeBufferArray(scip, &cutcoefs);
1338  SCIPfreeBufferArray(scip, &cutinds);
1339  SCIPfreeBufferArray(scip, &fractionalities);
1340  SCIPfreeBufferArray(scip, &bestcontubs);
1341  SCIPfreeBufferArray(scip, &bestcontlbs);
1342  SCIPfreeBufferArray(scip, &varsolvals);
1343  SCIPfreeBufferArray(scip, &roworder);
1344  SCIPfreeBufferArray(scip, &rowscores);
1345  SCIPfreeBufferArray(scip, &rowrhsscores);
1346  SCIPfreeBufferArray(scip, &rowlhsscores);
1347 
1348  if ( cutoff )
1349  *result = SCIP_CUTOFF;
1350  else if ( ncuts > 0 )
1351  *result = SCIP_SEPARATED;
1352 
1353  return SCIP_OKAY;
1354 }
1355 
1356 /*
1357  * Callback methods of separator
1358  */
1359 
1360 /** copy method for separator plugins (called when SCIP copies plugins) */
1361 static
1362 SCIP_DECL_SEPACOPY(sepaCopyAggregation)
1363 { /*lint --e{715}*/
1364  assert(scip != NULL);
1365  assert(sepa != NULL);
1366  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
1367 
1368  /* call inclusion method of constraint handler */
1370 
1371  return SCIP_OKAY;
1372 }
1373 
1374 /** destructor of separator to free user data (called when SCIP is exiting) */
1375 static
1376 SCIP_DECL_SEPAFREE(sepaFreeAggregation)
1377 { /*lint --e{715}*/
1378  SCIP_SEPADATA* sepadata;
1379 
1380  /* free separator data */
1381  sepadata = SCIPsepaGetData(sepa);
1382  assert(sepadata != NULL);
1383 
1384  SCIPfreeBlockMemory(scip, &sepadata);
1385 
1386  SCIPsepaSetData(sepa, NULL);
1387 
1388  return SCIP_OKAY;
1389 }
1390 
1391 /** LP solution separation method of separator */
1392 static
1393 SCIP_DECL_SEPAEXECLP(sepaExeclpAggregation)
1394 { /*lint --e{715}*/
1395  assert( result != NULL );
1396 
1397  *result = SCIP_DIDNOTRUN;
1398 
1399  /* only call separator, if we are not close to terminating */
1400  if( SCIPisStopped(scip) )
1401  return SCIP_OKAY;
1402 
1403  /* only call separator, if an optimal LP solution is at hand */
1405  return SCIP_OKAY;
1406 
1407  /* only call separator, if there are fractional variables */
1408  if( SCIPgetNLPBranchCands(scip) == 0 )
1409  return SCIP_OKAY;
1410 
1411  SCIP_CALL( separateCuts(scip, sepa, NULL, allowlocal, result) );
1412 
1413  return SCIP_OKAY;
1414 }
1415 
1416 /** arbitrary primal solution separation method of separator */
1417 static
1418 SCIP_DECL_SEPAEXECSOL(sepaExecsolAggregation)
1419 { /*lint --e{715}*/
1420  assert( result != NULL );
1421 
1422  *result = SCIP_DIDNOTRUN;
1423 
1424  SCIP_CALL( separateCuts(scip, sepa, sol, allowlocal, result) );
1425 
1426  return SCIP_OKAY;
1427 }
1428 
1429 /** LP solution separation method of dummy separator */
1430 static
1431 SCIP_DECL_SEPAEXECLP(sepaExeclpDummy)
1432 { /*lint --e{715}*/
1433  assert( result != NULL );
1434 
1435  *result = SCIP_DIDNOTRUN;
1436 
1437  return SCIP_OKAY;
1438 }
1439 
1440 /** arbitrary primal solution separation method of dummy separator */
1441 static
1442 SCIP_DECL_SEPAEXECSOL(sepaExecsolDummy)
1443 { /*lint --e{715}*/
1444  assert( result != NULL );
1445 
1446  *result = SCIP_DIDNOTRUN;
1447 
1448  return SCIP_OKAY;
1449 }
1450 
1451 /*
1452  * separator specific interface methods
1453  */
1454 
1455 /** creates the cmir separator and includes it in SCIP */
1457  SCIP* scip /**< SCIP data structure */
1458  )
1459 {
1460  SCIP_SEPADATA* sepadata;
1461  SCIP_SEPA* sepa;
1463  /* create cmir separator data */
1464  SCIP_CALL( SCIPallocBlockMemory(scip, &sepadata) );
1465 
1466  /* include dummy separators */
1467  SCIP_CALL( SCIPincludeSepaBasic(scip, &sepadata->flowcover, "flowcover", "separator for flowcover cuts", -100000, SEPA_FREQ, 0.0,
1468  SEPA_USESSUBSCIP, FALSE, sepaExeclpDummy, sepaExecsolDummy, NULL) );
1469 
1470  assert(sepadata->flowcover != NULL);
1471 
1472  SCIP_CALL( SCIPincludeSepaBasic(scip, &sepadata->cmir, "cmir", "separator for cmir cuts", -100000, SEPA_FREQ, 0.0,
1473  SEPA_USESSUBSCIP, FALSE, sepaExeclpDummy, sepaExecsolDummy, NULL) );
1474 
1475  assert(sepadata->cmir != NULL);
1476 
1477  /* include separator */
1480  sepaExeclpAggregation, sepaExecsolAggregation,
1481  sepadata) );
1482 
1483  assert(sepa != NULL);
1484 
1485  /* set non-NULL pointers to callback methods */
1486  SCIP_CALL( SCIPsetSepaCopy(scip, sepa, sepaCopyAggregation) );
1487  SCIP_CALL( SCIPsetSepaFree(scip, sepa, sepaFreeAggregation) );
1488 
1489  /* add cmir separator parameters */
1490  SCIP_CALL( SCIPaddIntParam(scip,
1491  "separating/" SEPA_NAME "/maxrounds",
1492  "maximal number of cmir separation rounds per node (-1: unlimited)",
1493  &sepadata->maxrounds, FALSE, DEFAULT_MAXROUNDS, -1, INT_MAX, NULL, NULL) );
1494  SCIP_CALL( SCIPaddIntParam(scip,
1495  "separating/" SEPA_NAME "/maxroundsroot",
1496  "maximal number of cmir separation rounds in the root node (-1: unlimited)",
1497  &sepadata->maxroundsroot, FALSE, DEFAULT_MAXROUNDSROOT, -1, INT_MAX, NULL, NULL) );
1498  SCIP_CALL( SCIPaddIntParam(scip,
1499  "separating/" SEPA_NAME "/maxtries",
1500  "maximal number of rows to start aggregation with per separation round (-1: unlimited)",
1501  &sepadata->maxtries, TRUE, DEFAULT_MAXTRIES, -1, INT_MAX, NULL, NULL) );
1502  SCIP_CALL( SCIPaddIntParam(scip,
1503  "separating/" SEPA_NAME "/maxtriesroot",
1504  "maximal number of rows to start aggregation with per separation round in the root node (-1: unlimited)",
1505  &sepadata->maxtriesroot, TRUE, DEFAULT_MAXTRIESROOT, -1, INT_MAX, NULL, NULL) );
1506  SCIP_CALL( SCIPaddIntParam(scip,
1507  "separating/" SEPA_NAME "/maxfails",
1508  "maximal number of consecutive unsuccessful aggregation tries (-1: unlimited)",
1509  &sepadata->maxfails, TRUE, DEFAULT_MAXFAILS, -1, INT_MAX, NULL, NULL) );
1510  SCIP_CALL( SCIPaddIntParam(scip,
1511  "separating/" SEPA_NAME "/maxfailsroot",
1512  "maximal number of consecutive unsuccessful aggregation tries in the root node (-1: unlimited)",
1513  &sepadata->maxfailsroot, TRUE, DEFAULT_MAXFAILSROOT, -1, INT_MAX, NULL, NULL) );
1514  SCIP_CALL( SCIPaddIntParam(scip,
1515  "separating/" SEPA_NAME "/maxaggrs",
1516  "maximal number of aggregations for each row per separation round",
1517  &sepadata->maxaggrs, TRUE, DEFAULT_MAXAGGRS, 0, INT_MAX, NULL, NULL) );
1518  SCIP_CALL( SCIPaddIntParam(scip,
1519  "separating/" SEPA_NAME "/maxaggrsroot",
1520  "maximal number of aggregations for each row per separation round in the root node",
1521  &sepadata->maxaggrsroot, TRUE, DEFAULT_MAXAGGRSROOT, 0, INT_MAX, NULL, NULL) );
1522  SCIP_CALL( SCIPaddIntParam(scip,
1523  "separating/" SEPA_NAME "/maxsepacuts",
1524  "maximal number of cmir cuts separated per separation round",
1525  &sepadata->maxsepacuts, FALSE, DEFAULT_MAXSEPACUTS, 0, INT_MAX, NULL, NULL) );
1526  SCIP_CALL( SCIPaddIntParam(scip,
1527  "separating/" SEPA_NAME "/maxsepacutsroot",
1528  "maximal number of cmir cuts separated per separation round in the root node",
1529  &sepadata->maxsepacutsroot, FALSE, DEFAULT_MAXSEPACUTSROOT, 0, INT_MAX, NULL, NULL) );
1531  "separating/" SEPA_NAME "/maxslack",
1532  "maximal slack of rows to be used in aggregation",
1533  &sepadata->maxslack, TRUE, DEFAULT_MAXSLACK, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1535  "separating/" SEPA_NAME "/maxslackroot",
1536  "maximal slack of rows to be used in aggregation in the root node",
1537  &sepadata->maxslackroot, TRUE, DEFAULT_MAXSLACKROOT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1539  "separating/" SEPA_NAME "/densityscore",
1540  "weight of row density in the aggregation scoring of the rows",
1541  &sepadata->densityscore, TRUE, DEFAULT_DENSITYSCORE, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1543  "separating/" SEPA_NAME "/slackscore",
1544  "weight of slack in the aggregation scoring of the rows",
1545  &sepadata->slackscore, TRUE, DEFAULT_SLACKSCORE, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1547  "separating/" SEPA_NAME "/maxaggdensity",
1548  "maximal density of aggregated row",
1549  &sepadata->maxaggdensity, TRUE, DEFAULT_MAXAGGDENSITY, 0.0, 1.0, NULL, NULL) );
1551  "separating/" SEPA_NAME "/maxrowdensity",
1552  "maximal density of row to be used in aggregation",
1553  &sepadata->maxrowdensity, TRUE, DEFAULT_MAXROWDENSITY, 0.0, 1.0, NULL, NULL) );
1554  SCIP_CALL( SCIPaddIntParam(scip,
1555  "separating/" SEPA_NAME "/densityoffset",
1556  "additional number of variables allowed in row on top of density",
1557  &sepadata->densityoffset, TRUE, DEFAULT_DENSITYOFFSET, 0, INT_MAX, NULL, NULL) );
1559  "separating/" SEPA_NAME "/maxrowfac",
1560  "maximal row aggregation factor",
1561  &sepadata->maxrowfac, TRUE, DEFAULT_MAXROWFAC, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1562  SCIP_CALL( SCIPaddIntParam(scip,
1563  "separating/" SEPA_NAME "/maxtestdelta",
1564  "maximal number of different deltas to try (-1: unlimited)",
1565  &sepadata->maxtestdelta, TRUE, DEFAULT_MAXTESTDELTA, -1, INT_MAX, NULL, NULL) );
1567  "separating/" SEPA_NAME "/aggrtol",
1568  "tolerance for bound distances used to select continuous variable in current aggregated constraint to be eliminated",
1569  &sepadata->aggrtol, TRUE, DEFAULT_AGGRTOL, 0.0, SCIP_REAL_MAX, NULL, NULL) );
1571  "separating/" SEPA_NAME "/trynegscaling",
1572  "should negative values also be tested in scaling?",
1573  &sepadata->trynegscaling, TRUE, DEFAULT_TRYNEGSCALING, NULL, NULL) );
1575  "separating/" SEPA_NAME "/fixintegralrhs",
1576  "should an additional variable be complemented if f0 = 0?",
1577  &sepadata->fixintegralrhs, TRUE, DEFAULT_FIXINTEGRALRHS, NULL, NULL) );
1579  "separating/" SEPA_NAME "/dynamiccuts",
1580  "should generated cuts be removed from the LP if they are no longer tight?",
1581  &sepadata->dynamiccuts, FALSE, DEFAULT_DYNAMICCUTS, NULL, NULL) );
1582 
1583  return SCIP_OKAY;
1584 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
#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
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2134
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
#define MAKECONTINTEGRAL
#define DEFAULT_DENSITYSCORE
void SCIPaggrRowFree(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1581
int SCIPaggrRowGetNRows(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2295
#define DEFAULT_MAXFAILSROOT
SCIP_Real * SCIPvarGetVlbCoefs(SCIP_VAR *var)
Definition: var.c:17557
#define NULL
Definition: def.h:239
#define DEFAULT_MAXTESTDELTA
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1547
public methods for SCIP parameter handling
SCIP_RETCODE SCIPaggrRowAddRow(SCIP *scip, SCIP_AGGRROW *aggrrow, SCIP_ROW *row, SCIP_Real weight, int sidetype)
Definition: cuts.c:1684
#define BOUNDSWITCH
public methods for memory management
static SCIP_DECL_SEPACOPY(sepaCopyAggregation)
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1570
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17343
#define SCIP_MAXSTRLEN
Definition: def.h:260
#define DEFAULT_MAXROUNDSROOT
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
Definition: lp.c:16748
static SCIP_DECL_SEPAEXECSOL(sepaExecsolAggregation)
#define DEFAULT_MAXSLACKROOT
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1602
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:16790
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17399
#define DEFAULT_FIXINTEGRALRHS
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:16928
int SCIProwGetNLPNonz(SCIP_ROW *row)
Definition: lp.c:16804
void SCIPswapPointers(void **pointer1, void **pointer2)
Definition: misc.c:9645
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1918
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:16869
#define FALSE
Definition: def.h:65
methods for the aggregation rows
#define DEFAULT_SLACKSCORE
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10017
#define TRUE
Definition: def.h:64
#define SCIPdebug(x)
Definition: pub_message.h:74
const char * SCIPsepaGetName(SCIP_SEPA *sepa)
Definition: sepa.c:689
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
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:4222
SCIP_RETCODE SCIPincludeSepaAggregation(SCIP *scip)
SCIP_Real * bounddist
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17036
SCIP_ROW ** aggrrows
public methods for problem variables
static SCIP_Real negate(SCIP_Real x)
void SCIPswapReals(SCIP_Real *value1, SCIP_Real *value2)
Definition: misc.c:9632
int SCIPaggrRowGetNNz(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2360
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
SCIP_VAR ** SCIPvarGetVlbVars(SCIP_VAR *var)
Definition: var.c:17547
void SCIPsortDownRealInt(SCIP_Real *realarray, int *intarray, int len)
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:142
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
int SCIPgetNLPBranchCands(SCIP *scip)
Definition: scip_branch.c:417
public methods for SCIP variables
SCIP_RETCODE SCIPsetSepaCopy(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: scip_sepa.c:220
SCIP_Real SCIProwGetDualsol(SCIP_ROW *row)
Definition: lp.c:16889
flow cover and complemented mixed integer rounding cuts separator (Marchand&#39;s version) ...
#define SCIPdebugMsg
Definition: scip_message.h:88
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:155
public methods for separator plugins
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2224
SCIP_Real SCIPgetObjNorm(SCIP *scip)
Definition: scip_prob.c:1697
SCIP_Real SCIPepsilon(SCIP *scip)
SCIP_RETCODE SCIPgetVarClosestVlb(SCIP *scip, SCIP_VAR *var, SCIP_SOL *sol, SCIP_Real *closestvlb, int *closestvlbidx)
Definition: scip_var.c:6520
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1823
public methods for numerical tolerances
SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:600
SCIP_Bool SCIPaggrRowHasRowBeenAdded(SCIP_AGGRROW *aggrrow, SCIP_ROW *row)
Definition: cuts.c:2327
public methods for querying solving statistics
public methods for the branch-and-bound tree
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17353
int SCIPsepaGetFreq(SCIP_SEPA *sepa)
Definition: sepa.c:733
#define DEFAULT_MAXROWFAC
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:161
#define SEPA_FREQ
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_Real SCIPgetRowMinCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1805
#define MINFRAC
int * SCIPaggrRowGetRowInds(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2305
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_ROW ** SCIPcolGetRows(SCIP_COL *col)
Definition: lp.c:16738
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1447
#define DEFAULT_MAXAGGRSROOT
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:16978
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:143
int SCIPsepaGetNCallsAtNode(SCIP_SEPA *sepa)
Definition: sepa.c:816
SCIP_Bool SCIPisEfficacious(SCIP *scip, SCIP_Real efficacy)
Definition: scip_cut.c:179
#define DEFAULT_MAXROWDENSITY
#define DEFAULT_MAXFAILS
#define MAXFRAC
void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:610
int * SCIPaggrRowGetInds(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:2350
#define REALABS(x)
Definition: def.h:174
static SCIP_DECL_SEPAEXECLP(sepaExeclpAggregation)
void SCIPaggrRowRemoveZeros(SCIP *scip, SCIP_AGGRROW *aggrrow, SCIP_Bool *valid)
Definition: cuts.c:2282
#define SCIP_CALL(x)
Definition: def.h:351
SCIP_RETCODE SCIPgetVarClosestVub(SCIP *scip, SCIP_VAR *var, SCIP_SOL *sol, SCIP_Real *closestvub, int *closestvubidx)
Definition: scip_var.c:6543
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:16879
SCIP_Real * SCIPvarGetVubCoefs(SCIP_VAR *var)
Definition: var.c:17599
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:294
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:16988
SCIP_Bool SCIPsortedvecFindInt(int *intarray, int val, int len, int *pos)
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:16815
SCIP_RETCODE SCIPincludeSepaBasic(SCIP *scip, SCIP_SEPA **sepa, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: scip_sepa.c:178
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:130
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:16825
public data structures and miscellaneous methods
#define SEPA_USESSUBSCIP
#define SCIP_Bool
Definition: def.h:62
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:226
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2179
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_Bool SCIPvarIsInLP(SCIP_VAR *var)
Definition: var.c:17068
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:7409
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:715
int SCIPgetRowNumIntCols(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1787
#define DEFAULT_MAXTRIES
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:405
#define MIN(x, y)
Definition: def.h:209
public methods for LP management
SCIP_RETCODE SCIPcreateEmptyRowSepa(SCIP *scip, SCIP_ROW **row, SCIP_SEPA *sepa, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip_lp.c:1365
public methods for cuts and aggregation rows
#define SEPA_NAME
SCIP_AGGRROW * aggrrow
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17057
static void destroyAggregationData(SCIP *scip, AGGREGATIONDATA *aggrdata)
static SCIP_RETCODE setupAggregationData(SCIP *scip, SCIP_SOL *sol, SCIP_Bool allowlocal, AGGREGATIONDATA *aggrdata)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPgetRowSolActivity(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
Definition: scip_lp.c:2045
#define DEFAULT_TRYNEGSCALING
SCIP_Bool SCIPisCutNew(SCIP *scip, SCIP_ROW *row)
Definition: scip_cut.c:387
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2089
public methods for the LP relaxation, rows and columns
int SCIProwGetRank(SCIP_ROW *row)
Definition: lp.c:16958
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2044
#define SEPA_PRIORITY
#define SCIP_REAL_MAX
Definition: def.h:151
#define DEFAULT_MAXSEPACUTS
#define DEFAULT_MAXAGGDENSITY
SCIP_Real SCIProwGetParallelism(SCIP_ROW *row1, SCIP_ROW *row2, char orthofunc)
Definition: lp.c:7631
SCIP_Real * r
Definition: circlepacking.c:50
methods for sorting joint arrays of various types
public methods for branching rule plugins and branching
#define DEFAULT_MAXROUNDS
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1474
general public methods
#define MAX(x, y)
Definition: def.h:208
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip_sepa.c:236
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SEPA_DELAY
#define DEFAULT_DENSITYOFFSET
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16639
public methods for solutions
void SCIProwChgRank(SCIP_ROW *row, int rank)
Definition: lp.c:17091
static SCIP_DECL_SEPAFREE(sepaFreeAggregation)
public methods for message output
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1999
int SCIProwGetLPPos(SCIP_ROW *row)
Definition: lp.c:17058
#define SCIP_Real
Definition: def.h:150
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:739
public methods for message handling
SCIP_RETCODE SCIPaggrRowCreate(SCIP *scip, SCIP_AGGRROW **aggrrow)
Definition: cuts.c:1549
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2094
SCIP_VAR ** SCIPvarGetVubVars(SCIP_VAR *var)
Definition: var.c:17589
#define DEFAULT_DYNAMICCUTS
#define POSTPROCESS
static SCIP_Real getRowFracActivity(SCIP_ROW *row, SCIP_Real *fractionalities)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static INLINE SCIP_Real SCIPaggrRowGetProbvarValue(SCIP_AGGRROW *aggrrow, int probindex)
Definition: cuts.h:239
int SCIPgetNLPCols(SCIP *scip)
Definition: scip_lp.c:551
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17409
SCIP_Real SCIPsumepsilon(SCIP *scip)
public methods for separators
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:112
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
Definition: scip_lp.c:573
#define DEFAULT_MAXTRIESROOT
void SCIPaggrRowClear(SCIP_AGGRROW *aggrrow)
Definition: cuts.c:1949
#define DEFAULT_MAXSEPACUTSROOT
SCIP_Longint SCIPgetNLPs(SCIP *scip)
#define SCIPABORT()
Definition: def.h:323
public methods for global and local (sub)problems
int SCIPcolGetNLPNonz(SCIP_COL *col)
Definition: lp.c:16727
#define USEVBDS
SCIP_RETCODE SCIPmakeRowIntegral(SCIP *scip, SCIP_ROW *row, SCIP_Real mindelta, SCIP_Real maxdelta, SCIP_Longint maxdnom, SCIP_Real maxscale, SCIP_Bool usecontvars, SCIP_Bool *success)
Definition: scip_lp.c:1745
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1410
#define DEFAULT_AGGRTOL
SCIP_Real SCIProwGetNorm(SCIP_ROW *row)
Definition: lp.c:16845
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:211
#define DEFAULT_MAXSLACK
#define SEPA_DESC
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:38
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:129
int SCIPgetNSepaRounds(SCIP *scip)
SCIP_Real * aggrrowscoef
struct AggregationData AGGREGATIONDATA
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:134
memory allocation routines