Scippy

SCIP

Solving Constraint Integer Programs

cons_setppc.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-2020 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 scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file cons_setppc.c
17  * @ingroup DEFPLUGINS_CONS
18  * @brief Constraint handler for the set partitioning / packing / covering constraints \f$1^T x\ \{=, \le, \ge\}\ 1\f$.
19  * @author Tobias Achterberg
20  * @author Michael Winkler
21  */
22 
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24 
25 #include "blockmemshell/memory.h"
26 #include "scip/cons_linear.h"
27 #include "scip/cons_quadratic.h"
28 #include "scip/cons_setppc.h"
29 #include "scip/pub_conflict.h"
30 #include "scip/pub_cons.h"
31 #include "scip/pub_event.h"
32 #include "scip/pub_lp.h"
33 #include "scip/pub_message.h"
34 #include "scip/pub_misc.h"
35 #include "scip/pub_misc_sort.h"
36 #include "scip/pub_var.h"
37 #include "scip/scip_conflict.h"
38 #include "scip/scip_cons.h"
39 #include "scip/scip_cut.h"
40 #include "scip/scip_event.h"
41 #include "scip/scip_general.h"
42 #include "scip/scip_lp.h"
43 #include "scip/scip_mem.h"
44 #include "scip/scip_message.h"
45 #include "scip/scip_numerics.h"
46 #include "scip/scip_param.h"
47 #include "scip/scip_prob.h"
48 #include "scip/scip_probing.h"
49 #include "scip/scip_randnumgen.h"
50 #include "scip/scip_sol.h"
51 #include "scip/scip_solvingstats.h"
52 #include "scip/scip_var.h"
53 #include <ctype.h>
54 #include <string.h>
55 
56 
57 #define CONSHDLR_NAME "setppc"
58 #define CONSHDLR_DESC "set partitioning / packing / covering constraints"
59 #define CONSHDLR_SEPAPRIORITY +700000 /**< priority of the constraint handler for separation */
60 #define CONSHDLR_ENFOPRIORITY -700000 /**< priority of the constraint handler for constraint enforcing */
61 #define CONSHDLR_CHECKPRIORITY -700000 /**< priority of the constraint handler for checking feasibility */
62 #define CONSHDLR_SEPAFREQ 0 /**< frequency for separating cuts; zero means to separate only in the root node */
63 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
64 #define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
65  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
66 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
67 #define CONSHDLR_DELAYSEPA FALSE /**< should separation method be delayed, if other separators found cuts? */
68 #define CONSHDLR_DELAYPROP FALSE /**< should propagation method be delayed, if other propagators found reductions? */
69 #define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
70 
71 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_ALWAYS
72 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP
73 
74 #define LINCONSUPGD_PRIORITY +700000 /**< priority of the constraint handler for upgrading of linear constraints */
75 #define QUADCONSUPGD_PRIORITY +700000 /**< priority of the constraint handler for upgrading of linear constraints */
76 
77 #define EVENTHDLR_NAME "setppc"
78 #define EVENTHDLR_DESC "bound change event handler for set partitioning / packing / covering constraints"
79 
80 #define CONFLICTHDLR_NAME "setppc"
81 #define CONFLICTHDLR_DESC "conflict handler creating set covering constraints"
82 #define CONFLICTHDLR_PRIORITY LINCONSUPGD_PRIORITY
83 
84 #define DEFAULT_PRESOLPAIRWISE TRUE /**< should pairwise constraint comparison be performed in presolving? */
85 
86 #define HASHSIZE_SETPPCCONS 500 /**< minimal size of hash table in setppc constraint tables */
87 #define DEFAULT_PRESOLUSEHASHING TRUE /**< should hash table be used for detecting redundant constraints in advance */
88 #define NMINCOMPARISONS 200000 /**< number for minimal pairwise presolving comparisons */
89 #define MINGAINPERNMINCOMPARISONS 1e-06 /**< minimal gain per minimal pairwise presolving comparisons to repeat pairwise comparison round */
90 
91 #define DEFAULT_RANDSEED 3
92 
93 /*#define VARUSES*/ /* activate variable usage counting, that is necessary for LP and pseudo branching */
94 /*#define BRANCHLP*/ /* BRANCHLP is only useful if the ENFOPRIORITY is set to a positive value */
95 #ifdef BRANCHLP
96 #define MINBRANCHWEIGHT 0.3 /**< minimum weight of both sets in binary set branching */
97 #define MAXBRANCHWEIGHT 0.7 /**< maximum weight of both sets in binary set branching */
98 #endif
99 #define DEFAULT_NPSEUDOBRANCHES 2 /**< number of children created in pseudo branching (0: disable branching) */
100 #define DEFAULT_DUALPRESOLVING TRUE /**< should dual presolving steps be performed? */
102 #define DEFAULT_CLIQUELIFTING FALSE /**< should we try to lift variables into other clique constraints, fix
103  * variables, aggregate them, and also shrink the amount of variables in
104  * clique constraints
105  */
106 #define DEFAULT_ADDVARIABLESASCLIQUES FALSE/**< should we try to generate extra clique constraint out of all binary
107  * variables to hopefully fasten the detection of redundant clique
108  * constraints */
109 #define DEFAULT_CLIQUESHRINKING TRUE /**< should we try to shrink the number of variables in a clique constraints, by
110  * replacing more than one variable by only one
111  */
112 
113 /* @todo maybe use event SCIP_EVENTTYPE_VARUNLOCKED to decide for another dual-presolving run on a constraint */
114 
115 /*
116  * Data structures
117  */
118 
119 /** constraint handler data */
120 struct SCIP_ConshdlrData
121 {
122  SCIP_EVENTHDLR* eventhdlr; /**< event handler for bound change events */
123  SCIP_CONSHDLR* conshdlrlinear; /**< pointer to linear constraint handler or NULL if not included */
124 #ifdef VARUSES
125  SCIP_INTARRAY* varuses; /**< number of times a var is used in the active setppc constraints */
126 #endif
127  SCIP_Longint nsetpart; /**< number of set partitioning constraints in transformed problem */
128  int npseudobranches; /**< number of children created in pseudo branching (0 to disable branching) */
129  int noldfixedvars; /**< number of fixed variables after last clique lifting run */
130  int noldimpls; /**< number of implication before last clique lifting run */
131  int noldcliques; /**< number of cliques before last clique lifting run */
132  int noldupgrs; /**< number of setppc constraints since the last clique lifting run */
133  int nclqpresolve; /**< number of setppc clique lifting runs */
134  SCIP_Bool updatedsetppctype; /**< remember whether we upgraded a constraint type */
135  SCIP_Bool cliquelifting; /**< should we perform the clique lifting procedure */
136  SCIP_Bool enablecliquelifting;/**< check whether we have enough changes to run the lifting procedure again */
137  SCIP_Bool cliqueshrinking; /**< should we try to shrink the number of variables in a clique
138  * constraints, by replacing more than one variable by only one
139  */
140  SCIP_Bool addvariablesascliques;/**< should we try to generate extra clique constraint out of all binary
141  * variables to hopefully fasten the detection of redundant clique
142  * constraints */
143  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
144  SCIP_Bool presolpairwise; /**< should pairwise constraint comparison be performed in presolving? */
145  SCIP_Bool presolusehashing; /**< should hash table be used for detecting redundant constraints in advance */
146  SCIP_Bool dualpresolving; /**< should dual presolving steps be performed? */
147 };
148 
149 /** constraint data for set partitioning / packing / covering constraints */
150 struct SCIP_ConsData
151 {
152  uint64_t signature; /**< bit signature of vars array */
153  SCIP_ROW* row; /**< LP row, if constraint is already stored in LP row format */
154  SCIP_VAR** vars; /**< variables of the constraint */
155  int varssize; /**< size of vars array */
156  int nvars; /**< number of variables in the constraint */
157  int nfixedzeros; /**< current number of variables fixed to zero in the constraint */
158  int nfixedones; /**< current number of variables fixed to one in the constraint */
159  unsigned int setppctype:2; /**< type of constraint: set partitioning, packing or covering */
160  unsigned int sorted:1; /**< are the constraint's variables sorted? */
161  unsigned int cliqueadded:1; /**< was the set partitioning / packing constraint already added as clique? */
162  unsigned int validsignature:1; /**< is the bit signature valid? */
163  unsigned int changed:1; /**< was constraint changed since last redundancy round in preprocessing? */
164  unsigned int varsdeleted:1; /**< were variables deleted after last cleanup? */
165  unsigned int merged:1; /**< are the constraint's equal/negated variables already merged? */
166  unsigned int presolpropagated:1; /**< was the constraint already propagated in presolving w.r.t. the current domains? */
167  unsigned int existmultaggr:1; /**< does this constraint contain aggregations */
168  unsigned int catchevents:1; /**< are events installed for this constraint? */
169 };
170 
171 
172 
173 
174 /*
175  * Local methods
176  */
177 
178 /** compares two active constraints of type set partitioning or set packing such that a "-1" is return if
179  * 1. the first constraint is a set partitioning constraint and the second is a set packing or
180  * 2. both constraints are set partitioning constraints and the second has more! variables than the first or
181  * 3. both constraints are set packing constraints and the second has less! variables than the first
182  * a "0" is return if
183  * 1. both constraint are of the same type and have the amount of variables or
184  * and a "1" is returned otherwise
185  */
186 static
187 int setppcCompare(
188  SCIP_CONS*const cons1, /**< first problem variable */
189  SCIP_CONS*const cons2 /**< second problem variable */
190  )
191 {
192  SCIP_CONSDATA* consdata1;
193  SCIP_CONSDATA* consdata2;
194 
195  assert(cons1 != NULL);
196  assert(cons2 != NULL);
197  assert(SCIPconsIsActive(cons1));
198  assert(SCIPconsIsActive(cons2));
199 
200  /* the partitioning type should be the smallest value and the packing the second smallest */
202 
203  consdata1 = SCIPconsGetData(cons1);
204  assert(consdata1 != NULL);
205  assert(consdata1->setppctype != SCIP_SETPPCTYPE_COVERING); /*lint !e641*/
206  consdata2 = SCIPconsGetData(cons2);
207  assert(consdata2 != NULL);
208  assert(consdata2->setppctype != SCIP_SETPPCTYPE_COVERING); /*lint !e641*/
209 
210  if( consdata1->setppctype < consdata2->setppctype ||
211  (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nvars < consdata2->nvars) || /*lint !e641*/
212  (consdata2->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->nvars > consdata2->nvars) ) /*lint !e641*/
213  return -1;
214  else if( (consdata1->setppctype == consdata2->setppctype && consdata1->nvars == consdata2->nvars) ) /*lint !e641*/
215  return 0;
216  else
217  {
218  assert(consdata1->setppctype > consdata2->setppctype || (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->setppctype == consdata2->setppctype && consdata1->nvars > consdata2->nvars) || (consdata1->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->setppctype == consdata2->setppctype && consdata1->nvars < consdata2->nvars)); /*lint !e641*/
219  return +1;
220  }
221 }
222 
223 /** sort constraints first after type (partitioning before packing before covering) and second after number of
224  * variables such that the partitioning constraints have increasing number of variables and the packing constraints
225  * have decreasing number of variables */
226 static
227 SCIP_DECL_SORTPTRCOMP(setppcConssSort)
228 {
229  return setppcCompare((SCIP_CONS*)elem1, (SCIP_CONS*)elem2);
230 }
231 
232 /** compares two setppc constraints such that a "-1" is return if the first constraint is active and
233  * 1. the second constraint is deleted
234  * 2. the first constraint is a set partitioning constraint and the second is a set packing or
235  * 3. both constraints are set partitioning constraints and the second has more! variables than the first or
236  * 4. both constraints are set packing constraints and the second has less! variables than the first
237  * a "0" is return if
238  * 1. both constraint are set-covering constraints
239  * 2. both constraint are of the same type and have the amount of variables or
240  * and a "1" is returned otherwise
241  */
242 static
243 int setppcCompare2(
244  SCIP_CONS*const cons1, /**< first problem variable */
245  SCIP_CONS*const cons2 /**< second problem variable */
246  )
247 {
248  SCIP_CONSDATA* consdata1;
249  SCIP_CONSDATA* consdata2;
250 
251  assert(cons1 != NULL);
252  assert(cons2 != NULL);
253 
254  if( SCIPconsIsDeleted(cons1) )
255  {
256  if( SCIPconsIsDeleted(cons2) )
257  return 0;
258  else
259  return +1;
260  }
261  else if( SCIPconsIsDeleted(cons2) )
262  return -1;
263 
264  consdata1 = SCIPconsGetData(cons1);
265  assert(consdata1 != NULL);
266  consdata2 = SCIPconsGetData(cons2);
267  assert(consdata2 != NULL);
268 
269  /* the partitioning type should be the smallest value and the packing the second smallest */
271 
272  if( consdata1->setppctype < consdata2->setppctype ||
273  ((SCIP_SETPPCTYPE)consdata1->setppctype != SCIP_SETPPCTYPE_COVERING &&
274  (((SCIP_SETPPCTYPE)consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nvars < consdata2->nvars) ||
275  ((SCIP_SETPPCTYPE)consdata2->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->nvars > consdata2->nvars))) )
276  return -1;
277  else if( ((SCIP_SETPPCTYPE)consdata2->setppctype == SCIP_SETPPCTYPE_COVERING || (consdata1->setppctype == consdata2->setppctype && consdata1->nvars == consdata2->nvars)) )
278  return 0;
279  else
280  {
281  assert(consdata1->setppctype > consdata2->setppctype || ((consdata1->setppctype == consdata2->setppctype) &&
282  ((consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nvars > consdata2->nvars)
283  || (consdata1->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->nvars < consdata2->nvars)))); /*lint !e641*/
284  return +1;
285  }
286 }
287 
288 /** sort constraints first after type (partitioning before packing before covering) and second after number of
289  * variables such that the partitioning constraints have increasing number of variables and the packing constraints
290  * have decreasing number of variables */
291 static
292 SCIP_DECL_SORTPTRCOMP(setppcConssSort2)
293 {
294  return setppcCompare2((SCIP_CONS*)elem1, (SCIP_CONS*)elem2);
295 }
296 
297 
298 /** installs rounding locks for the given variable in the given setppc constraint */
299 static
301  SCIP* scip, /**< SCIP data structure */
302  SCIP_CONS* cons, /**< setppc constraint */
303  SCIP_VAR* var /**< variable of constraint entry */
304  )
305 {
306  SCIP_CONSDATA* consdata;
307 
308  consdata = SCIPconsGetData(cons);
309  assert(consdata != NULL);
310 
311  switch( consdata->setppctype )
312  {
314  SCIP_CALL( SCIPlockVarCons(scip, var, cons, TRUE, TRUE) );
315  break;
317  SCIP_CALL( SCIPlockVarCons(scip, var, cons, FALSE, TRUE) );
318  break;
320  SCIP_CALL( SCIPlockVarCons(scip, var, cons, TRUE, FALSE) );
321  break;
322  default:
323  SCIPerrorMessage("unknown setppc type\n");
324  return SCIP_INVALIDDATA;
325  }
326 
327  return SCIP_OKAY;
328 }
329 
330 /** removes rounding locks for the given variable in the given setppc constraint */
331 static
333  SCIP* scip, /**< SCIP data structure */
334  SCIP_CONS* cons, /**< setppc constraint */
335  SCIP_VAR* var /**< variable of constraint entry */
336  )
337 {
338  SCIP_CONSDATA* consdata;
339 
340  consdata = SCIPconsGetData(cons);
341  assert(consdata != NULL);
342 
343  switch( consdata->setppctype )
344  {
346  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, TRUE, TRUE) );
347  break;
349  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, FALSE, TRUE) );
350  break;
352  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, TRUE, FALSE) );
353  break;
354  default:
355  SCIPerrorMessage("unknown setppc type\n");
356  return SCIP_INVALIDDATA;
357  }
358 
359  return SCIP_OKAY;
360 }
361 
362 /** creates constraint handler data for set partitioning / packing / covering constraint handler */
363 static
365  SCIP* scip, /**< SCIP data structure */
366  SCIP_CONSHDLRDATA** conshdlrdata, /**< pointer to store the constraint handler data */
367  SCIP_EVENTHDLR* eventhdlr /**< event handler */
368  )
369 {
370  assert(scip != NULL);
371  assert(conshdlrdata != NULL);
372  assert(eventhdlr != NULL);
373 
374  SCIP_CALL( SCIPallocBlockMemory(scip, conshdlrdata) );
375 #ifdef VARUSES
376  SCIP_CALL( SCIPcreateIntarray(scip, &(*conshdlrdata)->varuses) );
377 #endif
378  (*conshdlrdata)->npseudobranches = DEFAULT_NPSEUDOBRANCHES;
379 
380  /* set event handler for bound change events */
381  (*conshdlrdata)->eventhdlr = eventhdlr;
382  (*conshdlrdata)->nsetpart = 0;
383 
384  /* create a random number generator */
385  SCIP_CALL( SCIPcreateRandom(scip, &(*conshdlrdata)->randnumgen,
387 
388  return SCIP_OKAY;
389 }
390 
391 /** frees constraint handler data for set partitioning / packing / covering constraint handler */
392 static
394  SCIP* scip, /**< SCIP data structure */
395  SCIP_CONSHDLRDATA** conshdlrdata /**< pointer to the constraint handler data */
396  )
397 {
398  assert(conshdlrdata != NULL);
399  assert(*conshdlrdata != NULL);
400 
401 #ifdef VARUSES
402  SCIP_CALL( SCIPfreeIntarray(scip, &(*conshdlrdata)->varuses) );
403 #endif
404 
405  /* free random number generator */
406  SCIPfreeRandom(scip, &(*conshdlrdata)->randnumgen);
407 
408  SCIPfreeBlockMemory(scip, conshdlrdata);
409 
410  return SCIP_OKAY;
411 }
412 
413 #ifdef VARUSES
414 /** adds the given value to the usage counter of the given variable */
415 static
416 SCIP_RETCODE conshdlrdataAddVaruses(
417  SCIP* scip, /**< SCIP data structure */
418  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
419  SCIP_VAR* var, /**< variable to increase usage counter for */
420  int addval /**< value to add to the usage counter */
421  )
422 {
423  SCIP_INTARRAY* varuses;
424 
425  assert(conshdlrdata != NULL);
426  assert(var != NULL);
427 
428  varuses = conshdlrdata->varuses;
429  assert(varuses != NULL);
430 
431  /* if the variable is the negation of a problem variable, count the varuses in the problem variable */
432  if( SCIPvarIsNegated(var) )
433  {
434  SCIP_VAR* negvar;
435  int varindex;
436 
437  /* move the varuses value of the negated variable to the active problem variable */
438  varindex = SCIPvarGetIndex(var);
439  addval += SCIPgetIntarrayVal(scip, varuses, varindex);
440  SCIP_CALL( SCIPsetIntarrayVal(scip, varuses, varindex, 0) );
441  SCIP_CALL( SCIPgetNegatedVar(scip, var, &negvar) );
442  var = negvar;
443  }
444 
445  /* increase varuses counter */
446  SCIP_CALL( SCIPincIntarrayVal(scip, varuses, SCIPvarGetIndex(var), addval) );
447 
448  SCIPdebugMsg(scip, "added %d to varuses of <%s>: %d\n",
449  addval, SCIPvarGetName(var), SCIPgetIntarrayVal(scip, varuses, SCIPvarGetIndex(var)));
450 
451  return SCIP_OKAY;
452 }
453 
454 /** increases the usage counter of the given variable */
455 static
456 SCIP_RETCODE conshdlrdataIncVaruses(
457  SCIP* scip, /**< SCIP data structure */
458  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
459  SCIP_VAR* var /**< variable to increase usage counter for */
460  )
461 {
462  assert(conshdlrdata != NULL);
463 
464  SCIPdebugMsg(scip, "increasing varuses of <%s>: %d\n",
465  SCIPvarGetName(var), SCIPgetIntarrayVal(scip, conshdlrdata->varuses, SCIPvarGetIndex(var)));
466 
467  SCIP_CALL( conshdlrdataAddVaruses(scip, conshdlrdata, var, +1) );
468 
469  return SCIP_OKAY;
470 }
471 
472 /** decreases the usage counter of the given variable */
473 static
474 SCIP_RETCODE conshdlrdataDecVaruses(
475  SCIP* scip, /**< SCIP data structure */
476  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
477  SCIP_VAR* var /**< variable to increase usage counter for */
478  )
479 {
480  assert(conshdlrdata != NULL);
481 
482  SCIPdebugMsg(scip, "decreasing varuses of <%s>: %d\n",
483  SCIPvarGetName(var), SCIPgetIntarrayVal(scip, conshdlrdata->varuses, SCIPvarGetIndex(var)));
484 
485  SCIP_CALL( conshdlrdataAddVaruses(scip, conshdlrdata, var, -1) );
486 
487  return SCIP_OKAY;
488 }
489 
490 /** increases the usage counter of all variable in the constraint */
491 static
492 SCIP_RETCODE consdataIncVaruses(
493  SCIP* scip, /**< SCIP data structure */
494  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
495  SCIP_CONSDATA* consdata /**< setppc constraint data */
496  )
497 {
498  int v;
499 
500  assert(consdata != NULL);
501 
502  for( v = 0; v < consdata->nvars; ++v )
503  {
504  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, consdata->vars[v]) );
505  }
506 
507  return SCIP_OKAY;
508 }
509 
510 /** decreases the usage counter of all variable in the constraint */
511 static
512 SCIP_RETCODE consdataDecVaruses(
513  SCIP* scip, /**< SCIP data structure */
514  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
515  SCIP_CONSDATA* consdata /**< setppc constraint data */
516  )
517 {
518  int v;
519 
520  assert(consdata != NULL);
521 
522  for( v = 0; v < consdata->nvars; ++v )
523  {
524  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, consdata->vars[v]) );
525  }
526 
527  return SCIP_OKAY;
528 }
529 #endif
530 
531 /** ensures, that the vars array can store at least num entries */
532 static
534  SCIP* scip, /**< SCIP data structure */
535  SCIP_CONSDATA* consdata, /**< setppc constraint data */
536  int num /**< minimum number of entries to store */
537  )
538 {
539  assert(consdata != NULL);
540  assert(consdata->nvars <= consdata->varssize);
542  if( num > consdata->varssize )
543  {
544  int newsize;
545 
546  newsize = SCIPcalcMemGrowSize(scip, num);
547  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &consdata->vars, consdata->varssize, newsize) );
548  consdata->varssize = newsize;
549  }
550  assert(num <= consdata->varssize);
551 
552  return SCIP_OKAY;
553 }
554 
555 /** creates a set partitioning / packing / covering constraint data object */
556 static
558  SCIP* scip, /**< SCIP data structure */
559  SCIP_CONSDATA** consdata, /**< pointer to store the set partitioning / packing / covering constraint */
560  int nvars, /**< number of variables in the constraint */
561  SCIP_VAR** vars, /**< variables of the constraint */
562  SCIP_SETPPCTYPE setppctype /**< type of constraint: set partitioning, packing, or covering constraint */
563  )
564 {
565  assert(consdata != NULL);
566  assert(nvars == 0 || vars != NULL);
567 
568  SCIP_CALL( SCIPallocBlockMemory(scip, consdata) );
569 
570  (*consdata)->signature = 0;
571  (*consdata)->row = NULL;
572  (*consdata)->existmultaggr = FALSE;
573  (*consdata)->catchevents = FALSE;
574  (*consdata)->nfixedzeros = 0;
575  (*consdata)->nfixedones = 0;
576 
577  if( nvars > 0 )
578  {
579  int v;
580 
581  /* @todo the setppc constraint handler does not remove fixed variables from its var array; removing those
582  * variables is only possible if we consider the values of nfixedones and nfixedzeros in all propagation methods
583  */
584 #ifdef SCIP_DISABLED_CODE
585 
586  if( SCIPisConsCompressionEnabled(scip) )
587  {
588  SCIP_VAR** varsbuffer;
589  int k;
590 
591  /* allocate temporary buffer storage for active variables */
592  SCIP_CALL( SCIPallocBufferArray(scip, &varsbuffer, nvars) );
593 
594  k = 0;
595  /* collect fixed variables to compress the required memory */
596  for( v = 0; v < nvars; ++v )
597  {
598  assert(SCIPvarIsBinary(vars[v]));
599 
600  /* already fixed variables account as fixed ones or zero, only unfixed are appended */
601  if( SCIPvarGetLbGlobal(vars[v]) > 0.5 )
602  (*consdata)->nfixedones++;
603  else if( SCIPvarGetUbGlobal(vars[v]) < 0.5 )
604  (*consdata)->nfixedzeros++;
605  else
606  varsbuffer[k++] = vars[v];
607  }
608 
609  (*consdata)->varssize = k;
610  (*consdata)->nvars = k;
611  /* copy unfixed variables into constraint data */
612  if( k > 0 )
613  {
614  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->vars, varsbuffer, k) );
615  }
616 
617  /* free temporary storage */
618  SCIPfreeBufferArray(scip, &varsbuffer);
619  }
620  else
621 #endif
622  {
623  /* for uncompressed copies, simply duplicate the whole array */
624  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->vars, vars, nvars) );
625  (*consdata)->varssize = nvars;
626  (*consdata)->nvars = nvars;
627  }
628 
629  if( SCIPisTransformed(scip) )
630  {
631  /* get transformed variables */
632  SCIP_CALL( SCIPgetTransformedVars(scip, (*consdata)->nvars, (*consdata)->vars, (*consdata)->vars) );
633 
634  /* check for multi-aggregations and capture variables */
635  for( v = 0; v < (*consdata)->nvars; v++ )
636  {
637  SCIP_VAR* var = SCIPvarGetProbvar((*consdata)->vars[v]);
638  assert(var != NULL);
639  (*consdata)->existmultaggr = (*consdata)->existmultaggr || (SCIPvarGetStatus(var) == SCIP_VARSTATUS_MULTAGGR);
640  SCIP_CALL( SCIPcaptureVar(scip, (*consdata)->vars[v]) );
641  }
642  }
643  else
644  {
645  /* capture variables */
646  for( v = 0; v < (*consdata)->nvars; v++ )
647  {
648  assert((*consdata)->vars[v] != NULL);
649  SCIP_CALL( SCIPcaptureVar(scip, (*consdata)->vars[v]) );
650  }
651  }
652  }
653  else
654  {
655  (*consdata)->vars = NULL;
656  (*consdata)->varssize = 0;
657  (*consdata)->nvars = 0;
658  }
659  (*consdata)->setppctype = setppctype; /*lint !e641*/
660  (*consdata)->sorted = (nvars <= 1);
661  (*consdata)->cliqueadded = FALSE;
662  (*consdata)->validsignature = FALSE;
663  (*consdata)->changed = TRUE;
664  (*consdata)->varsdeleted = FALSE;
665  (*consdata)->merged = FALSE;
666  (*consdata)->presolpropagated = FALSE;
667 
668  return SCIP_OKAY;
669 }
670 
671 /** creates a transformed set partitioning / packing / covering constraint data object */
672 static
674  SCIP* scip, /**< SCIP data structure */
675  SCIP_CONSDATA** consdata, /**< pointer to store the set partitioning / packing / covering constraint */
676  int nvars, /**< number of variables in the constraint */
677  SCIP_VAR** vars, /**< variables of the constraint */
678  SCIP_SETPPCTYPE setppctype /**< type of constraint: set partitioning, packing, or covering constraint */
679  )
680 {
681  assert(consdata != NULL);
682  assert(nvars == 0 || vars != NULL);
683 
684  /* create constraint data */
685  SCIP_CALL( consdataCreate(scip, consdata, nvars, vars, setppctype) );
686 
687  /* transform the variables */
688  SCIP_CALL( SCIPgetTransformedVars(scip, (*consdata)->nvars, (*consdata)->vars, (*consdata)->vars) );
689 
690  return SCIP_OKAY;
691 }
692 
693 /** frees a set partitioning / packing / covering constraint data */
694 static
696  SCIP* scip, /**< SCIP data structure */
697  SCIP_CONSDATA** consdata /**< pointer to store the set partitioning / packing / covering constraint */
698  )
699 {
700  int v;
701 
702  assert(consdata != NULL);
703  assert(*consdata != NULL);
704 
705  /* release the row */
706  if( (*consdata)->row != NULL )
707  {
708  SCIP_CALL( SCIPreleaseRow(scip, &(*consdata)->row) );
709  }
710 
711  /* release variables */
712  for( v = 0; v < (*consdata)->nvars; v++ )
713  {
714  assert((*consdata)->vars[v] != NULL);
715  SCIP_CALL( SCIPreleaseVar(scip, &((*consdata)->vars[v])) );
716  }
717 
718  SCIPfreeBlockMemoryArrayNull(scip, &(*consdata)->vars, (*consdata)->varssize);
719  SCIPfreeBlockMemory(scip, consdata);
720 
721  return SCIP_OKAY;
722 }
723 
724 /** prints set partitioning / packing / covering constraint to file stream */
725 static
727  SCIP* scip, /**< SCIP data structure */
728  SCIP_CONSDATA* consdata, /**< set partitioning / packing / covering constraint data */
729  FILE* file /**< output file (or NULL for standard output) */
730  )
731 {
732  assert(consdata != NULL);
733 
734  /* print coefficients */
735  if( consdata->nvars == 0 )
736  SCIPinfoMessage(scip, file, "0 ");
737 
738  /* write linear sum */
739  SCIP_CALL( SCIPwriteVarsLinearsum(scip, file, consdata->vars, NULL, consdata->nvars, TRUE) );
740 
741  /* print right hand side */
742  switch( consdata->setppctype )
743  {
745  SCIPinfoMessage(scip, file, " == 1");
746  break;
748  SCIPinfoMessage(scip, file, " <= 1");
749  break;
751  SCIPinfoMessage(scip, file, " >= 1");
752  break;
753  default:
754  SCIPerrorMessage("unknown setppc type\n");
755  return SCIP_ERROR;
756  }
757 
758  return SCIP_OKAY;
759 }
760 
761 /** returns the bit signature of the given constraint data */
762 static
763 uint64_t consdataGetSignature(
764  SCIP_CONSDATA* consdata /**< set partitioning / packing / covering constraint data */
765  )
766 {
767  assert(consdata != NULL);
768 
769  if( !consdata->validsignature )
770  {
771  int i;
772 
773  consdata->signature = 0;
774  for( i = 0; i < consdata->nvars; ++i )
775  consdata->signature |= SCIPhashSignature64(SCIPvarGetIndex(consdata->vars[i]));
776  consdata->validsignature = TRUE;
777  }
778 
779  return consdata->signature;
780 }
781 
782 /** sorts setppc constraint's variables by non-decreasing variable index */
783 static
784 void consdataSort(
785  SCIP_CONSDATA* consdata /**< linear constraint data */
786  )
787 {
788  assert(consdata != NULL);
789 
790  if( !consdata->sorted )
791  {
792  if( consdata->nvars <= 1 )
793  consdata->sorted = TRUE;
794  else
795  {
796  SCIPsortPtr((void**)consdata->vars, SCIPvarComp, consdata->nvars);
797  consdata->sorted = TRUE;
798  }
799  }
800  assert(consdata->sorted);
801 #ifdef SCIP_DEBUG
802  /* check sorting */
803  {
804  int v;
805 
806  for( v = 0; v < consdata->nvars; ++v )
807  {
808  assert(v == consdata->nvars-1 || SCIPvarCompare(consdata->vars[v], consdata->vars[v+1]) <= 0);
809  }
810  }
811 #endif
812 }
813 
814 /** changes the type of a setppc constraint */
815 static
817  SCIP* scip, /**< SCIP data structure */
818  SCIP_CONS* cons, /**< setppc constraint */
819  SCIP_SETPPCTYPE setppctype /**< new type of constraint */
820  )
821 {
822  SCIP_CONSHDLR* conshdlr;
823  SCIP_CONSHDLRDATA* conshdlrdata;
824  SCIP_CONSDATA* consdata;
825  SCIP_Bool locked;
826  int i;
827 
828  consdata = SCIPconsGetData(cons);
829  assert(consdata != NULL);
830 
831  if( (SCIP_SETPPCTYPE)consdata->setppctype == setppctype )
832  return SCIP_OKAY;
833 
834  SCIPdebugMsg(scip, " -> converting <%s> into setppc type %d\n", SCIPconsGetName(cons), setppctype);
835 
836  /* remove rounding locks */
837  locked = FALSE;
838  for( i = 0; i < NLOCKTYPES && !locked; i++ )
839  locked = SCIPconsIsLockedType(cons, (SCIP_LOCKTYPE) i);
840 
841  if( locked )
842  {
843  for( i = 0; i < consdata->nvars; ++i )
844  {
845  SCIP_CALL( unlockRounding(scip, cons, consdata->vars[i]) );
846  }
847  }
848 
849  conshdlr = SCIPconsGetHdlr(cons);
850  assert(conshdlr != NULL);
851  conshdlrdata = SCIPconshdlrGetData(conshdlr);
852  assert(conshdlrdata != NULL);
853 
854  if( SCIPisTransformed(scip) )
855  {
856  if( setppctype == SCIP_SETPPCTYPE_PARTITIONING )
857  {
858  ++(conshdlrdata->nsetpart);
859  assert(conshdlrdata->nsetpart >= 0);
860  }
861  else if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
862  {
863  --(conshdlrdata->nsetpart);
864  assert(conshdlrdata->nsetpart >= 0);
865  }
866  }
867 
868  /* change the constraint type */
869  consdata->setppctype = setppctype; /*lint !e641*/
870 
871  /* reinstall rounding locks again */
872  if( locked )
873  {
874  for( i = 0; i < consdata->nvars; ++i )
875  {
876  SCIP_CALL( lockRounding(scip, cons, consdata->vars[i]) );
877  }
878  }
879 
880  /* remember that we changed a constraint type for clique lifting procedure */
881  if( setppctype != SCIP_SETPPCTYPE_COVERING )
882  conshdlrdata->updatedsetppctype = TRUE;
883 
884  return SCIP_OKAY;
885 }
886 
887 /** catches events for variable at given position */
888 static
890  SCIP* scip, /**< SCIP data structure */
891  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
892  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
893  int pos /**< array position of variable to catch bound change events for */
894  )
895 {
896  SCIP_CONSDATA* consdata;
897  SCIP_EVENTTYPE eventtype;
898  SCIP_VAR* var;
899 
900  consdata = SCIPconsGetData(cons);
901  assert(consdata != NULL);
902  assert(eventhdlr != NULL);
903  assert(0 <= pos && pos < consdata->nvars);
904  assert(consdata->vars != NULL);
905 
906  var = consdata->vars[pos];
907  assert(var != NULL);
908 
909  /* we are catching the following events:
910  *
911  * - SCIP_EVENTTYPE_BOUNDCHANGED: Is used to count the number of variable fixed locally to zero and one. That helps
912  * to speed up the propagation
913  *
914  * - SCIP_EVENTTYPE_VARDELETED: Is caught to remove a deleted variable from the constraint
915  *
916  * - SCIP_EVENTTYPE_VARFIXED: Is used to get informed if a variable of the constraint was aggregated which means was
917  * detected to be equal or a negated variable of on other variable. in case of a negation
918  * this could lead to a redundant constraint if the (other) active variable is also part
919  * of the constraint.
920  */
922 
923  /* catch bound change events on variable */
924  SCIP_CALL( SCIPcatchVarEvent(scip, var, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, NULL) );
925 
926  /* update the fixed variables counters for this variable */
927  if( SCIPisEQ(scip, SCIPvarGetUbLocal(var), 0.0) )
928  {
929  consdata->nfixedzeros++;
930 
931  /* during presolving, we may fix the last unfixed variable or do an aggregation if there are two unfixed variables */
932  if( SCIPconsIsActive(cons) && ((SCIPgetStage(scip) < SCIP_STAGE_INITSOLVE) && (consdata->nfixedzeros >= consdata->nvars - 2)) )
933  {
934  consdata->presolpropagated = FALSE;
935 
936  /* during solving, we only propagate again if there is only one unfixed variable left */
937  if( consdata->nfixedzeros >= consdata->nvars - 1 )
938  {
939  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
940  }
941  }
942  }
943  else if( SCIPisEQ(scip, SCIPvarGetLbLocal(var), 1.0) )
944  {
945  consdata->nfixedones++;
946 
947  if( SCIPconsIsActive(cons) )
948  {
949  consdata->presolpropagated = FALSE;
950  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
951  }
952  }
953 
954  return SCIP_OKAY;
955 }
956 
957 /** drops events for variable at given position */
958 static
960  SCIP* scip, /**< SCIP data structure */
961  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
962  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
963  int pos /**< array position of variable to catch bound change events for */
964  )
965 {
966  SCIP_CONSDATA* consdata;
967  SCIP_EVENTTYPE eventtype;
968  SCIP_VAR* var;
969 
970  consdata = SCIPconsGetData(cons);
971  assert(consdata != NULL);
972  assert(eventhdlr != NULL);
973  assert(0 <= pos && pos < consdata->nvars);
974  assert(consdata->vars != NULL);
975 
976  var = consdata->vars[pos];
977  assert(var != NULL);
978 
980 
981  /* drop events on variable */
982  SCIP_CALL( SCIPdropVarEvent(scip, var, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, -1) );
983 
984  /* update the fixed variables counters for this variable */
985  if( SCIPisEQ(scip, SCIPvarGetUbLocal(var), 0.0) )
986  consdata->nfixedzeros--;
987  else if( SCIPisEQ(scip, SCIPvarGetLbLocal(var), 1.0) )
988  consdata->nfixedones--;
989 
990  return SCIP_OKAY;
991 }
992 
993 /** catches bound change events for all variables in transformed setppc constraint */
994 static
996  SCIP* scip, /**< SCIP data structure */
997  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
998  SCIP_EVENTHDLR* eventhdlr /**< event handler to call for the event processing */
999  )
1000 {
1001  SCIP_CONSDATA* consdata;
1002  int i;
1004  consdata = SCIPconsGetData(cons);
1005  assert(consdata != NULL);
1006 
1007  if( consdata->catchevents == TRUE )
1008  return SCIP_OKAY;
1009 
1010  /* catch event for every single variable */
1011  for( i = 0; i < consdata->nvars; ++i )
1012  {
1013  SCIP_CALL( catchEvent(scip, cons, eventhdlr, i) );
1014  }
1015 
1016  consdata->catchevents = TRUE;
1017 
1018  return SCIP_OKAY;
1019 }
1020 
1021 /** drops bound change events for all variables in transformed setppc constraint */
1022 static
1024  SCIP* scip, /**< SCIP data structure */
1025  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
1026  SCIP_EVENTHDLR* eventhdlr /**< event handler to call for the event processing */
1027  )
1028 {
1029  SCIP_CONSDATA* consdata;
1030  int i;
1032  consdata = SCIPconsGetData(cons);
1033  assert(consdata != NULL);
1034 
1035  if( consdata->catchevents == FALSE )
1036  return SCIP_OKAY;
1037 
1038  /* drop event of every single variable */
1039  for( i = 0; i < consdata->nvars; ++i )
1040  {
1041  SCIP_CALL( dropEvent(scip, cons, eventhdlr, i) );
1042  }
1043 
1044  consdata->catchevents = FALSE;
1045 
1046  return SCIP_OKAY;
1047 }
1048 
1049 /** adds coefficient in setppc constraint */
1050 static
1052  SCIP* scip, /**< SCIP data structure */
1053  SCIP_CONS* cons, /**< setppc constraint */
1054  SCIP_VAR* var /**< variable to add to the constraint */
1055  )
1056 {
1057  SCIP_CONSDATA* consdata;
1058  SCIP_Bool transformed;
1060  assert(var != NULL);
1061 
1062  consdata = SCIPconsGetData(cons);
1063  assert(consdata != NULL);
1064 
1065  /* are we in the transformed problem? */
1066  transformed = SCIPconsIsTransformed(cons);
1067 
1068  /* always use transformed variables in transformed constraints */
1069  if( transformed )
1070  {
1071  SCIP_CALL( SCIPgetTransformedVar(scip, var, &var) );
1072  }
1073  assert(var != NULL);
1074  assert(transformed == SCIPvarIsTransformed(var));
1075 
1076  SCIP_CALL( consdataEnsureVarsSize(scip, consdata, consdata->nvars+1) );
1077  consdata->vars[consdata->nvars] = var;
1078  consdata->nvars++;
1079  if( consdata->validsignature )
1080  consdata->signature |= SCIPhashSignature64(SCIPvarGetIndex(var));
1081  consdata->sorted = (consdata->nvars == 1);
1082  consdata->changed = TRUE;
1083 
1084  /* capture the variable */
1085  SCIP_CALL( SCIPcaptureVar(scip, var) );
1086 
1087  /* if we are in transformed problem, catch the variable's events */
1088  if( transformed )
1089  {
1090  SCIP_CONSHDLR* conshdlr;
1091  SCIP_CONSHDLRDATA* conshdlrdata;
1092 
1093  /* get event handler */
1094  conshdlr = SCIPconsGetHdlr(cons);
1095  assert(conshdlr != NULL);
1096  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1097  assert(conshdlrdata != NULL);
1098  assert(conshdlrdata->eventhdlr != NULL);
1099 
1100  /* catch bound change events of variable */
1101  if( consdata->catchevents )
1102  {
1103  SCIP_CALL( catchEvent(scip, cons, conshdlrdata->eventhdlr, consdata->nvars-1) );
1104  }
1105 
1106  if( !consdata->existmultaggr && SCIPvarGetStatus(SCIPvarGetProbvar(var)) == SCIP_VARSTATUS_MULTAGGR )
1107  consdata->existmultaggr = TRUE;
1108 
1109 #ifdef VARUSES
1110  /* if the constraint is currently active, increase the variable usage counter */
1111  if( SCIPconsIsActive(cons) )
1112  {
1113  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var) );
1114  }
1115 #endif
1116  }
1117 
1118  /* install the rounding locks for the new variable */
1119  SCIP_CALL( lockRounding(scip, cons, var) );
1120 
1121  /* add the new coefficient to the LP row */
1122  if( consdata->row != NULL )
1123  {
1124  SCIP_CALL( SCIPaddVarToRow(scip, consdata->row, var, 1.0) );
1125  }
1126 
1127  consdata->merged = FALSE;
1128  consdata->cliqueadded = FALSE;
1129 
1130  return SCIP_OKAY;
1131 }
1132 
1133 /** deletes coefficient at given position from setppc constraint data */
1134 static
1136  SCIP* scip, /**< SCIP data structure */
1137  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
1138  int pos /**< position of coefficient to delete */
1139  )
1140 {
1141  SCIP_CONSDATA* consdata;
1142  SCIP_VAR* var;
1144  assert(scip != NULL);
1145  assert(cons != NULL);
1146 
1147  consdata = SCIPconsGetData(cons);
1148  assert(consdata != NULL);
1149  assert(0 <= pos && pos < consdata->nvars);
1150 
1151  var = consdata->vars[pos];
1152  assert(var != NULL);
1153  assert(SCIPconsIsTransformed(cons) == SCIPvarIsTransformed(var));
1154 
1155  /* remove the rounding locks for the deleted variable */
1156  SCIP_CALL( unlockRounding(scip, cons, var) );
1157 
1158  /* if we are in transformed problem, delete the event data of the variable */
1159  if( SCIPconsIsTransformed(cons) )
1160  {
1161  SCIP_CONSHDLR* conshdlr;
1162  SCIP_CONSHDLRDATA* conshdlrdata;
1163 
1164  /* get event handler */
1165  conshdlr = SCIPconsGetHdlr(cons);
1166  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1167  assert(conshdlrdata != NULL);
1168  assert(conshdlrdata->eventhdlr != NULL);
1169 
1170  /* drop bound change events of variable */
1171  if( consdata->catchevents )
1172  {
1173  SCIP_CALL( dropEvent(scip, cons, conshdlrdata->eventhdlr, pos) );
1174  }
1175 
1176  /* the last variable of the constraint was deleted; mark it for propagation (so that it can be deleted) */
1177  if( consdata->nvars == 1 )
1178  {
1179  consdata->presolpropagated = FALSE;
1180  }
1181  }
1182 
1183  /* delete coefficient from the LP row */
1184  if( consdata->row != NULL )
1185  {
1186  SCIP_CALL( SCIPaddVarToRow(scip, consdata->row, var, -1.0) );
1187  }
1188 
1189  /* move the last variable to the free slot */
1190  if( pos != consdata->nvars - 1 )
1191  {
1192  consdata->vars[pos] = consdata->vars[consdata->nvars-1];
1193  consdata->sorted = FALSE;
1194  }
1195  consdata->nvars--;
1196  consdata->validsignature = FALSE;
1197  consdata->changed = TRUE;
1198 
1199  /* release variable */
1200  SCIP_CALL( SCIPreleaseVar(scip, &var) );
1201 
1202  return SCIP_OKAY;
1203 }
1204 
1205 /** in case a part (more than one variable) in the setppc constraint is independent of every else (is locked only by
1206  * this constraint), we can perform dual reductions;
1207  *
1208  * (1) set covering
1209  *
1210  * - fix all independent variables with negative object coefficient to one
1211  * - fix all remaining independent variables to zero
1212  *
1213  * (i) all variables are independent and the constraint is not modifiable
1214  *
1215  * - fix the variable with the smallest object coefficient to one
1216  *
1217  * (ii) a variable x has exactly 0 uplocks and arbitrary downlocks and a variable y has exactly 1 downlock and
1218  * arbitrary uplocks and obj(x) <= obj(y) and obj(y) >= 0
1219  *
1220  * - fix y to 0, because it is dominated by x
1221  *
1222  * (2) set partitioning
1223  *
1224  * (i) all variables are independent and the constraint is not modifiable
1225  *
1226  * - fix the variable with the smallest object coefficient to one
1227  * - fix all remaining independent variables to zero
1228  *
1229  * (ii) a variable x has exactly 1 uplock and arbitrary downlocks and a variable y has exactly 1 downlock and
1230  * arbitrary uplocks and obj(x) <= obj(y)
1231  *
1232  * - fix y to 0, because it is dominated by x
1233  *
1234  * (3) set packing
1235  *
1236  * (i) all variables are independent and the constraint is not modifiable
1237  *
1238  * - fix the variable with the smallest object coefficient to one if the object coefficient is negative or zero
1239  * - fix all remaining independent variables to zero
1240  *
1241  * (ii) a variable x has exactly 1 uplock and arbitrary downlocks and a variable y has exactly 0 downlocks and
1242  * arbitrary uplocks and obj(x) <= obj(y)
1243  *
1244  * - fix y to 0, because it is dominated by x
1245  *
1246  *
1247  * Note: the following dual reduction for set covering and set packing constraints is already performed by the presolver
1248  * "dualfix"
1249  * (1) in case of a set covering constraint the following dual reduction can be performed:
1250  * - if a variable in a set covering constraint is only locked by that constraint and has negative or zero
1251  * objective coefficient than it can be fixed to one
1252  * (2) in case of a set packing constraint the following dual reduction can be performed:
1253  * - if a variable in a set packing constraint is only locked by that constraint and has positive or zero
1254  * objective coefficient than it can be fixed to zero
1255  *
1256  * Note: all dual reduction (ii) could also be performed by the "domcol" presolver, but cause the pairwise comparison of
1257  * columns is only done heuristically (and here it should be even cheaper) we perform them here (too)
1258  *
1259  */
1260 static
1262  SCIP* scip, /**< SCIP data structure */
1263  SCIP_CONS* cons, /**< setppc constraint */
1264  int* nfixedvars, /**< pointer to count number of fixings */
1265  int* ndelconss, /**< pointer to count number of deleted constraints */
1266  SCIP_RESULT* result /**< pointer to store the result SCIP_SUCCESS, if presolving was performed */
1267  )
1268 {
1269  SCIP_CONSDATA* consdata;
1270  SCIP_SETPPCTYPE setppctype;
1271  SCIP_VAR** vars;
1272  SCIP_VAR* activevar;
1273  SCIP_VAR* var;
1274  SCIP_Real bestobjval;
1275  SCIP_Real objval;
1276  SCIP_Real fixval;
1277  SCIP_Bool infeasible;
1278  SCIP_Bool fixed;
1279  SCIP_Bool negated;
1280  int noldfixed;
1281  int nposfixings;
1282  int nlockdowns;
1283  int nlockups;
1284  int nvars;
1285  int idx;
1286  int v;
1287 
1288  assert(scip != NULL);
1289  assert(cons != NULL);
1290  assert(nfixedvars != NULL);
1291  assert(ndelconss != NULL);
1292  assert(result != NULL);
1293 
1294  /* constraints for which the check flag is set to FALSE, did not contribute to the lock numbers; therefore, we cannot
1295  * use the locks to decide for a dual reduction using this constraint; for example after a restart the cuts which are
1296  * added to the problems have the check flag set to FALSE
1297  */
1298  if( !SCIPconsIsChecked(cons) )
1299  return SCIP_OKAY;
1300 
1301  assert(SCIPconsIsActive(cons));
1302 
1303  consdata = SCIPconsGetData(cons);
1304  assert(consdata != NULL);
1305 
1306  /* modifiable non-covering constraints cannot be deleted if one variable is fixed to one, because the propagation for
1307  * newly inserted variables must be considered later
1308  */
1309  if( consdata->nfixedones == 1 && SCIPconsIsModifiable(cons) )
1310  return SCIP_OKAY;
1311 
1312  /* all fixed variables should be removed at that point */
1313  assert(consdata->nfixedones == 0);
1314  assert(consdata->nfixedzeros == 0);
1315 
1316  nvars = consdata->nvars;
1317 
1318  /* we don't want to consider small constraints (note that the constraints can be modifiable, so we can't delete this
1319  * constraint)
1320  */
1321  if( nvars < 2 )
1322  return SCIP_OKAY;
1323 
1324  setppctype = (SCIP_SETPPCTYPE)consdata->setppctype;
1325  vars = consdata->vars;
1326  idx = -1;
1327  bestobjval = SCIP_INVALID;
1328 
1329  /* collect the rounding locks depending on the setppc type */
1330  switch( setppctype )
1331  {
1333  nlockdowns = 1;
1334  nlockups = 1;
1335  break;
1337  nlockdowns = 0;
1338  nlockups = 1;
1339  break;
1341  nlockdowns = 1;
1342  nlockups = 0;
1343  break;
1344  default:
1345  SCIPerrorMessage("unknown setppc type\n");
1346  SCIPABORT();
1347  return SCIP_INVALIDDATA; /*lint !e527*/
1348  }
1349 
1350  nposfixings = 0;
1351 
1352  /* check if we can apply the dual reduction; therefore count the number of variables where the setppc has the only
1353  * locks on this constraint
1354  */
1355  for( v = 0; v < nvars; ++v )
1356  {
1357  var = vars[v];
1358  assert(var != NULL);
1359 
1360  /* the variable should not be (globally) fixed */
1361  assert(SCIPvarGetLbGlobal(var) < 0.5 && SCIPvarGetUbGlobal(var) > 0.5);
1362 
1363  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) >= nlockdowns
1364  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) == nlockups )
1365  {
1366  activevar = var;
1367  negated = FALSE;
1368 
1369  /* get the active variable */
1370  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
1371  assert(SCIPvarIsActive(activevar));
1372 
1373  if( negated )
1374  objval = -SCIPvarGetObj(activevar);
1375  else
1376  objval = SCIPvarGetObj(activevar);
1377 
1378  /* check if the current variable has a smaller objective coefficient */
1379  if( idx == -1 || objval < bestobjval )
1380  {
1381  idx = v;
1382  bestobjval = objval;
1383  }
1384  }
1385 
1386  /* in case another constraint has also downlocks on that variable we cannot perform a dual reduction on these
1387  * variables
1388  */
1389  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == nlockdowns
1390  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) >= nlockups )
1391  ++nposfixings;
1392  }
1393 
1394  if( idx == -1 || nposfixings == 0 )
1395  return SCIP_OKAY;
1396 
1397  SCIPdebugMsg(scip, "dual fixing constraint: \n");
1398  SCIPdebug( SCIP_CALL( SCIPprintCons(scip, cons, NULL) ) );
1399  SCIPdebug( SCIPinfoMessage(scip, NULL, "\n") );
1400 
1401  assert(idx >= 0 && idx < nvars);
1402  assert(bestobjval < SCIPinfinity(scip));
1403 
1404  noldfixed = *nfixedvars;
1405 
1406  /* in case of set packing and set partitioning we fix the dominated variables to zero */
1407  if( setppctype != SCIP_SETPPCTYPE_COVERING )
1408  {
1409  /* first part of all variables */
1410  for( v = nvars - 1; v >= 0; --v )
1411  {
1412  if( v == idx )
1413  continue;
1414 
1415  var = vars[v];
1416  assert(var != NULL);
1417 
1418  /* in case another constraint has also downlocks on that variable we cannot perform a dual reduction on these
1419  * variables
1420  */
1421  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == nlockdowns
1422  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) >= nlockups )
1423  {
1424  activevar = var;
1425  negated = FALSE;
1426 
1427  /* get the active variable */
1428  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
1429  assert(SCIPvarIsActive(activevar));
1430 
1431  if( negated )
1432  objval = -SCIPvarGetObj(activevar);
1433  else
1434  objval = SCIPvarGetObj(activevar);
1435 
1436  if( objval >= bestobjval )
1437  {
1438  SCIP_CALL( SCIPfixVar(scip, var, 0.0, &infeasible, &fixed) );
1439  assert(!infeasible);
1440  assert(fixed);
1441 
1442  SCIPdebugMsg(scip, " -> dual-fixed dominated variable <%s> == 0.0\n", SCIPvarGetName(var));
1443  ++(*nfixedvars);
1444  }
1445  }
1446  }
1447  }
1448  /* if we got a set covering constraint and not all variables are locked from this constraint it might not get
1449  * redundant (which is case if it is not possible to fix at least one variable to one), we fix all redundant
1450  * variables to their best bound
1451  */
1452  else
1453  {
1454  /* first part of all variables */
1455  for( v = nvars - 1; v >= 0; --v )
1456  {
1457  if( v == idx )
1458  continue;
1459 
1460  var = vars[v];
1461  assert(var != NULL);
1462 
1463  /* in case another constraint has also downlocks on that variable we cannot perform a dual reduction on these
1464  * variables
1465  */
1466  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == nlockdowns
1467  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) >= nlockups )
1468  {
1469  activevar = var;
1470  negated = FALSE;
1471 
1472  /* get the active variable */
1473  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
1474  assert(SCIPvarIsActive(activevar));
1475  assert(negated
1478  assert(!negated
1481 
1482  if( negated )
1483  objval = -SCIPvarGetObj(activevar);
1484  else
1485  objval = SCIPvarGetObj(activevar);
1486 
1487  if( objval > 0.0 )
1488  fixval = 0.0;
1489  else
1490  fixval = 1.0;
1491 
1492  /* if variables has a negative objective contribution, and is uplocked by another constraint we cannot fix
1493  * the variables to 1
1494  */
1495  if( (fixval == 1.0 && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) > nlockups) || objval < bestobjval )
1496  continue;
1497 
1498  SCIP_CALL( SCIPfixVar(scip, var, fixval, &infeasible, &fixed) );
1499  assert(!infeasible);
1500  assert(fixed);
1501 
1502  SCIPdebugMsg(scip, " -> dual-fixed dominated variable <%s> == %g\n", SCIPvarGetName(var), fixval);
1503  ++(*nfixedvars);
1504  }
1505  }
1506  }
1507 
1508  /* if all variables but the domination variable is fixed and the constraint is not modifiable or the constraint is a
1509  * covering constraint and the bestobjval is less than or equal to zero, we can fix the domination variable (with best
1510  * objective coefficient) and the constraint gets redundant
1511  */
1512  if( ((*nfixedvars - noldfixed == nvars - 1) && !SCIPconsIsModifiable(cons)) || (setppctype == SCIP_SETPPCTYPE_COVERING && bestobjval <= 0.0) )
1513  {
1514  /* in case of a set packing constraint with positive objective values, all variables can be fixed to zero; in all
1515  * other cases the variable with the smallest objective values is fixed to one
1516  */
1517  if( (setppctype == SCIP_SETPPCTYPE_PACKING && bestobjval > 0.0
1518  && SCIPvarGetNLocksDownType(vars[idx], SCIP_LOCKTYPE_MODEL) == 0)
1519  || setppctype != SCIP_SETPPCTYPE_PACKING || bestobjval <= 0.0 )
1520  {
1521  if( setppctype == SCIP_SETPPCTYPE_PACKING && bestobjval > 0.0 )
1522  fixval = 0.0;
1523  else
1524  fixval = 1.0;
1525 
1526  SCIP_CALL( SCIPfixVar(scip, vars[idx], fixval, &infeasible, &fixed) );
1527  assert(!infeasible);
1528  assert(fixed);
1529 
1530  SCIPdebugMsg(scip, " -> dual-fixed best variable <%s> == %g\n", SCIPvarGetName(vars[idx]), fixval);
1531  ++(*nfixedvars);
1532  }
1533 
1534  /* check that we really have a non-violated constraint in hand before deleting */
1535  assert((setppctype == SCIP_SETPPCTYPE_PACKING && consdata->nfixedones <= 1) ||
1536  (setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata->nfixedones == 1) ||
1537  (setppctype == SCIP_SETPPCTYPE_COVERING && consdata->nfixedones >= 1));
1538 
1539  /* remove constraint since it is redundant */
1540  SCIP_CALL( SCIPdelCons(scip, cons) );
1541  ++(*ndelconss);
1542  }
1543 
1544  assert(*nfixedvars >= noldfixed);
1545 
1546  /* set result pointer to SCIP_SUCCESS, if variables could be fixed */
1547  if( *nfixedvars != noldfixed )
1548  *result = SCIP_SUCCESS;
1549 
1550  return SCIP_OKAY;
1551 }
1552 
1553 /** find pairs of negated variables in constraint:
1554  * partitioning/packing: all other variables must be zero, constraint is redundant
1555  * covering: constraint is redundant
1556  *
1557  * find sets of equal variables in constraint:
1558  * partitioning/packing: variable must be zero
1559  * covering: multiple entries of variable can be replaced by single entry
1560  */
1561 static
1563  SCIP* scip, /**< SCIP data structure */
1564  SCIP_CONS* cons, /**< knapsack constraint */
1565  int* nfixedvars, /**< pointer to store number of fixed variables */
1566  int* ndelconss, /**< pointer to store number of deleted constraints */
1567  int* nchgcoefs, /**< pointer to store number of changed coefficients */
1568  SCIP_Bool* cutoff /**< pointer to store whether a fixing leads to a cutoff */
1569  )
1571  SCIP_CONSDATA* consdata;
1572  int v;
1573 
1574  assert(scip != NULL);
1575  assert(cons != NULL);
1576  assert(nfixedvars != NULL);
1577  assert(ndelconss != NULL);
1578  assert(nchgcoefs != NULL);
1579  assert(cutoff != NULL);
1580 
1581  consdata = SCIPconsGetData(cons);
1582  assert(consdata != NULL);
1583 
1584  if( consdata->merged || SCIPconsIsDeleted(cons) )
1585  return SCIP_OKAY;
1586 
1587  if( consdata->nvars <= 1 )
1588  {
1589  consdata->merged = TRUE;
1590  return SCIP_OKAY;
1591  }
1592 
1593  assert(consdata->vars != NULL || consdata->nvars == 0);
1594 
1595  /* sorting array after indices of variables, that's only for faster merging */
1596  SCIPsortPtr((void**)consdata->vars, SCIPvarCompActiveAndNegated, consdata->nvars);
1597  /* setppc sorting now lost */
1598  consdata->sorted = FALSE;
1599 
1600  /* loop backwards through the items: deletion only affects rear items */
1601  for( v = consdata->nvars - 1; v > 0; --v )
1602  {
1603  SCIP_VAR* var1;
1604  SCIP_VAR* var2;
1605  SCIP_Bool negated1;
1606  SCIP_Bool negated2;
1607 
1608  negated1 = FALSE;
1609  negated2 = FALSE;
1610 
1611  var1 = consdata->vars[v];
1612  assert(SCIPvarIsBinary(var1));
1615  {
1616  var1 = SCIPvarGetNegatedVar(var1);
1617  negated1 = TRUE;
1618  }
1619  assert(var1 != NULL);
1620 
1621  var2 = consdata->vars[v-1];
1622  assert(SCIPvarIsBinary(var2));
1625  {
1626  var2 = SCIPvarGetNegatedVar(var2);
1627  negated2 = TRUE;
1628  }
1629  assert(var2 != NULL);
1630 
1631  if( var1 == var2 )
1632  {
1633  SCIP_Bool infeasible;
1634  SCIP_Bool fixed;
1635 
1636  /* one variables is active and the other is the same negated variable */
1637  if( negated1 != negated2 )
1638  {
1639  /* all other variable have to be zero if it's a partitioning or packing constraint */
1640  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
1641  {
1642  int i;
1643 
1644  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
1645  || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
1646 
1647  for( i = consdata->nvars - 1; i >= 0; --i )
1648  if( i != v && i != (v-1) )
1649  {
1650  SCIP_CALL( SCIPfixVar(scip, consdata->vars[i], 0.0, &infeasible, &fixed) );
1651  if( infeasible )
1652  {
1653  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 0\n",
1654  SCIPconsGetName(cons), SCIPvarGetName(consdata->vars[i]));
1655  *cutoff = TRUE;
1656  return SCIP_OKAY;
1657  }
1658 
1659  if( fixed )
1660  ++(*nfixedvars);
1661  }
1662  }
1663  /* all setppc-type constraints are redundant */
1664  SCIP_CALL( SCIPdelCons(scip, cons) );
1665  ++(*ndelconss);
1666  return SCIP_OKAY;
1667  }
1668  /* both variables are either active or negated */
1669  else
1670  {
1671  /* this variable can be fixed to zero if it's a partitioning or packing constraint */
1672  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
1673  {
1674  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
1675  || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
1676 
1677  SCIP_CALL( SCIPfixVar(scip, var1, negated1 ? 1.0 : 0.0, &infeasible, &fixed) );
1678  if( infeasible )
1679  {
1680  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == %g\n",
1681  SCIPconsGetName(cons), SCIPvarGetName(var1), negated1 ? 1.0 : 0.0);
1682  *cutoff = TRUE;
1683  return SCIP_OKAY;
1684  }
1685 
1686  if( fixed )
1687  ++(*nfixedvars);
1688  }
1689  /* multiple entries of variable can be replaced by single entry */
1690  else
1691  {
1692  SCIP_CALL( delCoefPos(scip, cons, v) ); /* only some changed behind position v-1, so it's okay */
1693  ++(*nchgcoefs);
1694  }
1695  }
1696  consdata->changed = TRUE;
1697  }
1698  }
1699  consdata->merged = TRUE;
1700 
1701  return SCIP_OKAY;
1702 }
1703 
1704 /** deletes all zero-fixed variables and replace aggregated variables */
1705 static
1707  SCIP* scip, /**< SCIP data structure */
1708  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
1709  int* naddconss, /**< pointer to count number of added constraints, or NULL indicating we
1710  * can not resolve multi-aggregations
1711  */
1712  int* ndelconss, /**< pointer to count number of deleted constraints, or NULL indicating we
1713  * can not resolve multi-aggregations
1714  */
1715  int* nfixedvars, /**< pointer to store number of fixed variables, or NULL indicating we can
1716  * not resolve multi-aggregations
1717  */
1718  SCIP_Bool* cutoff /**< pointer to store whether a fixing leads to a cutoff, or NULL
1719  * indicating we can not resolve multi-aggregations
1720  */
1721  )
1722 {
1723  SCIP_CONSDATA* consdata;
1724  int v;
1725 
1726  assert(scip != NULL);
1727  assert(cons != NULL);
1728 
1729  consdata = SCIPconsGetData(cons);
1730  assert(consdata != NULL);
1731 
1732  /* all multi-aggregations should be resolved */
1733  consdata->existmultaggr = FALSE;
1734 
1735  v = 0;
1736  while( v < consdata->nvars )
1737  {
1738  SCIP_VAR* var;
1739 
1740  var = consdata->vars[v];
1741  assert(SCIPvarIsBinary(var));
1742 
1743  if( SCIPvarGetUbGlobal(var) < 0.5 )
1744  {
1745  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(var), 0.0));
1746  SCIP_CALL( delCoefPos(scip, cons, v) );
1747  }
1748  else
1749  {
1750  SCIP_VAR* repvar;
1751  SCIP_Bool negated;
1752 
1753  /* get binary representative of variable */
1754  SCIP_CALL( SCIPgetBinvarRepresentative(scip, var, &repvar, &negated) );
1755 
1756  /* resolve multi-aggregation */
1758  {
1759  SCIP_VAR** consvars;
1760  SCIP_Real* consvals;
1761  SCIP_Real constant = 0.0;
1762  SCIP_Bool easycase;
1763  int nconsvars;
1764  int requiredsize;
1765  int v2;
1766 
1767  nconsvars = 1;
1768  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 1) );
1769  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 1) );
1770  consvars[0] = repvar;
1771  consvals[0] = 1.0;
1772 
1773  /* get active variables for new constraint */
1774  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, nconsvars, &constant, &requiredsize, TRUE) );
1775  /* if space was not enough we need to resize the buffers */
1776  if( requiredsize > nconsvars )
1777  {
1778  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, requiredsize) );
1779  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) );
1780 
1781  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize, TRUE) );
1782  assert(requiredsize <= nconsvars);
1783  }
1784 
1785  easycase = FALSE;
1786 
1787  if( SCIPisZero(scip, constant) )
1788  {
1789  /* add active representation */
1790  for( v2 = nconsvars - 1; v2 >= 0; --v2 )
1791  {
1792  if( !SCIPvarIsBinary(consvars[v2]) )
1793  break;
1794 
1795  if( !SCIPisEQ(scip, consvals[v2], 1.0) )
1796  break;
1797  }
1798 
1799  if( v2 < 0 )
1800  easycase = TRUE;
1801  }
1802  else if( SCIPisFeasEQ(scip, constant, 1.0) )
1803  {
1804  /* check for another multi-aggregation */
1805  for( v2 = consdata->nvars - 1; v2 > v; --v2 )
1806  {
1807  if( SCIPvarGetStatus(SCIPvarGetProbvar(consdata->vars[v])) == SCIP_VARSTATUS_MULTAGGR )
1808  break;
1809  }
1810 
1811  /* constraint is redundant */
1812  if( v2 == v && nconsvars == 0 )
1813  {
1814  /* we can fix */
1815  if( consdata->nvars > 1 && (SCIP_SETPPCTYPE)consdata->setppctype != SCIP_SETPPCTYPE_COVERING )
1816  {
1817  if( nfixedvars != NULL )
1818  {
1819  SCIP_Bool fixed;
1820 
1821  assert(cutoff != NULL);
1822 
1823  for( v2 = consdata->nvars - 1; v2 >= 0; --v2 )
1824  {
1825  if( consdata->vars[v2] != var )
1826  {
1827  SCIPdebugMsg(scip, "trying to fix <%s> to 0 due to at least one variable is already fixed to 1\n", SCIPvarGetName(consdata->vars[v2]));
1828 
1829  /* fix all remaining variables to zero, constraint is already feasible or infeasible */
1830  SCIP_CALL( SCIPfixVar(scip, consdata->vars[v2], 0.0, cutoff, &fixed) );
1831  if( *cutoff )
1832  {
1833  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 0\n",
1834  SCIPconsGetName(cons), SCIPvarGetName(consdata->vars[v2]));
1835 
1836  SCIPfreeBufferArray(scip, &consvals);
1837  SCIPfreeBufferArray(scip, &consvars);
1838 
1839  goto TERMINATE;
1840  }
1841 
1842  if( fixed )
1843  ++(*nfixedvars);
1844  }
1845  }
1846  }
1847  }
1848 
1849  if( ndelconss != NULL && (nfixedvars != NULL || consdata->nvars == 1 || (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING) )
1850  {
1851  /* delete old constraint */
1852  SCIP_CALL( SCIPdelCons(scip, cons) );
1853  ++(*ndelconss);
1854  }
1855  SCIPfreeBufferArray(scip, &consvals);
1856  SCIPfreeBufferArray(scip, &consvars);
1857 
1858  goto TERMINATE;
1859  }
1860  }
1861 
1862  /* we can easily add the coefficients and still have a setppc constraint */
1863  if( easycase )
1864  {
1865  /* delete old (multi-aggregated) variable */
1866  SCIP_CALL( delCoefPos(scip, cons, v) );
1867 
1868  /* add active representation */
1869  for( v2 = nconsvars - 1; v2 >= 0; --v2 )
1870  {
1871  assert(SCIPvarIsBinary(consvars[v2]));
1872  assert(SCIPvarIsActive(consvars[v2]) || (SCIPvarGetStatus(consvars[v2]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(consvars[v2]))));
1873 
1874  SCIP_CALL( addCoef(scip, cons, consvars[v2]) );
1875  }
1876  }
1877  /* we need to degrade this setppc constraint to a linear constraint */
1878  else if( (ndelconss != NULL && naddconss != NULL) || SCIPconsIsAdded(cons) )
1879  {
1880  char name[SCIP_MAXSTRLEN];
1881  SCIP_CONS* newcons;
1882  SCIP_Real lhs;
1883  SCIP_Real rhs;
1884  int size;
1885  int k;
1886 
1887  /* it might happen that there are more than one multi-aggregated variable, so we need to get the whole
1888  * probvar sum over all variables
1889  */
1890 
1891  size = MAX(nconsvars, 1) + consdata->nvars - 1;
1892 
1893  /* memory needed is at least old number of variables - 1 + number of variables in first multi-aggregation */
1894  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, size) );
1895  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, size) );
1896 
1897  nconsvars = consdata->nvars;
1898 
1899  /* add constraint variables to new linear variables */
1900  for( k = consdata->nvars - 1; k >= 0; --k )
1901  {
1902  consvars[k] = consdata->vars[k];
1903  consvals[k] = 1.0;
1904  }
1905 
1906  constant = 0.0;
1907 
1908  /* get active variables for new constraint */
1909  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, size, &constant, &requiredsize, TRUE) );
1910 
1911  /* if space was not enough (we found another multi-aggregation), we need to resize the buffers */
1912  if( requiredsize > nconsvars )
1913  {
1914  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, requiredsize) );
1915  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) );
1916 
1917  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize, TRUE) );
1918  assert(requiredsize <= nconsvars);
1919  }
1920 
1921  /* compute sides */
1922  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
1923  {
1924  lhs = -SCIPinfinity(scip);
1925  rhs = 1.0 - constant;
1926  }
1927  else if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
1928  {
1929  lhs = 1.0 - constant;
1930  rhs = 1.0 - constant;
1931  }
1932  else
1933  {
1934  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING);
1935  lhs = 1.0 - constant;
1936  rhs = SCIPinfinity(scip);
1937  }
1938 
1939  /* create linear constraint */
1940  (void)SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", SCIPconsGetName(cons));
1941  SCIP_CALL( SCIPcreateConsLinear(scip, &newcons, name, nconsvars, consvars, consvals, lhs, rhs,
1942  SCIPconsIsInitial(cons),
1946  SCIP_CALL( SCIPaddCons(scip, newcons) );
1947 
1948  SCIPdebugMsg(scip, "added linear constraint: ");
1949  SCIPdebugPrintCons(scip, newcons, NULL);
1950  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
1951 
1952  SCIPfreeBufferArray(scip, &consvals);
1953  SCIPfreeBufferArray(scip, &consvars);
1954 
1955  /* delete old constraint */
1956  SCIP_CALL( SCIPdelCons(scip, cons) );
1957  if( ndelconss != NULL && naddconss != NULL )
1958  {
1959  ++(*ndelconss);
1960  ++(*naddconss);
1961  }
1962 
1963  goto TERMINATE;
1964  }
1965  /* we need to degrade this setppc constraint to a linear constraint*/
1966  else
1967  {
1968  /* check, if the variable should be replaced with the representative */
1969  if( repvar != var )
1970  {
1971  /* delete old (aggregated) variable */
1972  SCIP_CALL( delCoefPos(scip, cons, v) );
1973 
1974  /* add representative instead */
1975  SCIP_CALL( addCoef(scip, cons, repvar) );
1976  }
1977 
1978  SCIPwarningMessage(scip, "setppc constraint <%s> has a multi-aggregated variable, which was not resolved and therefore could lead to aborts\n", SCIPconsGetName(cons));
1979  ++v;
1980  }
1981 
1982  SCIPfreeBufferArray(scip, &consvals);
1983  SCIPfreeBufferArray(scip, &consvars);
1984  }
1985  else
1986  {
1987  /* check, if the variable should be replaced with the representative */
1988  if( repvar != var )
1989  {
1990  /* delete old (aggregated) variable */
1991  SCIP_CALL( delCoefPos(scip, cons, v) );
1992 
1993  /* add representative instead */
1994  SCIP_CALL( addCoef(scip, cons, repvar) );
1995  }
1996  else
1997  ++v;
1998  }
1999  }
2000  }
2001 
2002  TERMINATE:
2003  /* all multi-aggregations should be resolved */
2004  consdata->existmultaggr = FALSE;
2005 
2006  return SCIP_OKAY;
2007 }
2008 
2009 /** analyzes conflicting assignment on given constraint where all of the variables where assigned to zero,
2010  * and adds conflict constraint to problem
2011  */
2012 static
2014  SCIP* scip, /**< SCIP data structure */
2015  SCIP_CONS* cons /**< set partitioning / packing / covering constraint that detected the conflict */
2016  )
2017 {
2018  SCIP_CONSDATA* consdata;
2019  int v;
2020 
2021  /* conflict analysis can only be applied in solving stage and if it is applicable */
2023  return SCIP_OKAY;
2024 
2025  consdata = SCIPconsGetData(cons);
2026  assert(consdata != NULL);
2027  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
2028  || consdata->setppctype == SCIP_SETPPCTYPE_COVERING); /*lint !e641*/
2029 
2030  /* initialize conflict analysis, and add all variables of infeasible constraint to conflict candidate queue */
2032 
2033  for( v = 0; v < consdata->nvars; ++v )
2034  {
2035  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
2036  }
2037 
2038  /* analyze the conflict */
2039  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
2040 
2041  return SCIP_OKAY;
2042 }
2043 
2044 /** analyzes conflicting assignment on given constraint where two of the variables where assigned to one,
2045  * and adds conflict constraint to problem
2046  */
2047 static
2049  SCIP* scip, /**< SCIP data structure */
2050  SCIP_CONS* cons /**< set partitioning / packing / covering constraint that detected the conflict */
2051  )
2052 {
2053  SCIP_CONSDATA* consdata;
2054  int v;
2055  int n;
2057  /* conflict analysis can only be applied in solving stage and if it is applicable */
2059  return SCIP_OKAY;
2060 
2061  consdata = SCIPconsGetData(cons);
2062  assert(consdata != NULL);
2063  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
2064  || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
2065 
2066  /* initialize conflict analysis, and add the two variables assigned to one to conflict candidate queue */
2068 
2069  n = 0;
2070  for( v = 0; v < consdata->nvars && n < 2; ++v )
2071  {
2072  if( SCIPvarGetLbLocal(consdata->vars[v]) > 0.5 )
2073  {
2074  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
2075  n++;
2076  }
2077  }
2078  assert(n == 2);
2079 
2080  /* analyze the conflict */
2081  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
2082 
2083  return SCIP_OKAY;
2084 }
2085 
2086 /** checks constraint for violation only looking at the fixed variables, applies further fixings if possible */
2087 static
2089  SCIP* scip, /**< SCIP data structure */
2090  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint to be processed */
2091  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
2092  int* nfixedvars, /**< pointer to count number of deleted variables */
2093  SCIP_Bool* addcut, /**< pointer to store whether this constraint must be added as a cut */
2094  SCIP_Bool* mustcheck /**< pointer to store whether this constraint must be checked for feasibility */
2095  )
2097  SCIP_CONSDATA* consdata;
2098 #ifndef NDEBUG
2099  int oldnfixedvars;
2100 #endif
2101 
2102  assert(cons != NULL);
2103  assert(SCIPconsGetHdlr(cons) != NULL);
2104  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
2105  assert(cutoff != NULL);
2106  assert(nfixedvars != NULL);
2107  assert(addcut != NULL);
2108  assert(mustcheck != NULL);
2109 
2110 #ifndef NDEBUG
2111  oldnfixedvars = *nfixedvars;
2112 #endif
2113 
2114  consdata = SCIPconsGetData(cons);
2115  assert(consdata != NULL);
2116  assert(consdata->nvars == 0 || consdata->vars != NULL);
2117  assert(0 <= consdata->nfixedzeros && consdata->nfixedzeros <= consdata->nvars);
2118  assert(0 <= consdata->nfixedones && consdata->nfixedones <= consdata->nvars);
2119 
2120  *addcut = FALSE;
2121  *mustcheck = TRUE;
2122 
2123  /*SCIPdebugMsg(scip, "processing constraint <%s> with respect to fixed variables (%d fixed to 0.0, %d fixed to 1.0)\n",
2124  SCIPconsGetName(cons), consdata->nfixedzeros, consdata->nfixedones);*/
2125 
2126  if( consdata->nfixedones == 1 )
2127  {
2128  /* exactly one variable is fixed to 1:
2129  * - a set covering constraint is feasible anyway and can be disabled
2130  * - all other variables in a set partitioning or packing constraint must be zero
2131  */
2132  if( consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
2133  {
2134  SCIPdebugMsg(scip, " -> disabling set covering constraint <%s>\n", SCIPconsGetName(cons));
2135  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2136  }
2137  else
2138  {
2139  if( consdata->nfixedzeros < consdata->nvars - 1 )
2140  {
2141  SCIP_VAR** vars;
2142  SCIP_VAR* var;
2143 #ifndef NDEBUG
2144  SCIP_Bool fixedonefound;
2145 #endif
2146  SCIP_Bool infeasible;
2147  SCIP_Bool tightened;
2148  int nvars;
2149  int v;
2150  int oneidx = -1;
2151 
2152  SCIPdebugMsg(scip, " -> fixing all other variables to zero in set packing/partitioning constraint <%s>\n",
2153  SCIPconsGetName(cons));
2154 
2155  /* unfixed variables exist: fix them to zero;
2156  * this could result in additional variables fixed to one due to aggregations; in this case, the
2157  * constraint is infeasible in local bounds
2158  */
2159  vars = consdata->vars;
2160  nvars = consdata->nvars;
2161 #ifndef NDEBUG
2162  fixedonefound = FALSE;
2163 #endif
2164  for( v = 0; v < nvars && consdata->nfixedones == 1; ++v )
2165  {
2166  var = vars[v];
2167  assert(SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) || SCIPisFeasEQ(scip, SCIPvarGetUbLocal(var), 1.0));
2168  if( SCIPvarGetLbLocal(var) < 0.5 )
2169  {
2170  SCIP_CALL( SCIPinferBinvarCons(scip, var, FALSE, cons, oneidx, &infeasible, &tightened) );
2171  assert(!infeasible);
2172 
2173  if( tightened )
2174  ++(*nfixedvars);
2175 
2176  SCIPdebugMsg(scip, " -> fixed <%s> to zero (tightened=%u)\n", SCIPvarGetName(var), tightened);
2177  }
2178  else
2179  {
2180 #ifndef NDEBUG
2181  fixedonefound = TRUE;
2182 #endif
2183  oneidx = v;
2184  }
2185  }
2186  /* the fixed to one variable must have been found, and at least one variable must have been fixed */
2187  assert(consdata->nfixedones >= 2 || (fixedonefound && *nfixedvars > oldnfixedvars));
2188 
2189  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2190  }
2191 
2192  /* now all other variables are fixed to zero:
2193  * the constraint is feasible, and if it's not modifiable, it is redundant
2194  */
2195  if( !SCIPconsIsModifiable(cons) && consdata->nfixedones == 1 )
2196  {
2197  SCIPdebugMsg(scip, " -> disabling set packing/partitioning constraint <%s>\n", SCIPconsGetName(cons));
2198  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2199  }
2200  }
2201  *mustcheck = FALSE;
2202  }
2203 
2204  if( consdata->nfixedones >= 2 )
2205  {
2206  /* at least two variables are fixed to 1:
2207  * - a set covering constraint is feasible anyway and can be disabled
2208  * - a set partitioning or packing constraint is infeasible
2209  */
2210  if( consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
2211  {
2212  SCIPdebugMsg(scip, " -> disabling set covering constraint <%s>\n", SCIPconsGetName(cons));
2213  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2214  }
2215  else
2216  {
2217  SCIPdebugMsg(scip, " -> conflict on set packing/partitioning constraint <%s>\n", SCIPconsGetName(cons));
2218 
2219  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2220 
2221  /* use conflict analysis to get a conflict constraint out of the conflicting assignment */
2222  SCIP_CALL( analyzeConflictOne(scip, cons) );
2223 
2224  *cutoff = TRUE;
2225  }
2226  *mustcheck = FALSE;
2227  }
2228  else if( consdata->nfixedzeros == consdata->nvars )
2229  {
2230  /* all variables are fixed to zero:
2231  * - a set packing constraint is feasible anyway, and if it's unmodifiable, it can be disabled
2232  * - a set partitioning or covering constraint is infeasible, and if it's unmodifiable, the node
2233  * can be cut off -- otherwise, the constraint must be added as a cut and further pricing must
2234  * be performed
2235  */
2236  assert(consdata->nfixedones == 0);
2237 
2238  if( consdata->setppctype == SCIP_SETPPCTYPE_PACKING ) /*lint !e641*/
2239  {
2240  if( !SCIPconsIsModifiable(cons) )
2241  {
2242  SCIPdebugMsg(scip, " -> disabling set packing constraint <%s>\n", SCIPconsGetName(cons));
2243  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2244  }
2245  }
2246  else
2247  {
2248  SCIPdebugMsg(scip, " -> set covering/partitioning constraint <%s> is infeasible\n", SCIPconsGetName(cons));
2249 
2250  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2251  if( SCIPconsIsModifiable(cons) )
2252  *addcut = TRUE;
2253  else
2254  {
2255  /* use conflict analysis to get a conflict constraint out of the conflicting assignment */
2256  SCIP_CALL( analyzeConflictZero(scip, cons) );
2257 
2258  *cutoff = TRUE;
2259  }
2260  }
2261  *mustcheck = FALSE;
2262  }
2263  else if( consdata->nfixedzeros == consdata->nvars - 1 && consdata->nfixedones == 0 )
2264  {
2265  /* all variables except one are fixed to zero:
2266  * - a set packing constraint is feasible anyway, and if it's unmodifiable, it can be disabled
2267  * - an unmodifiable set partitioning or covering constraint is feasible and can be disabled after the
2268  * remaining variable is fixed to one
2269  * - a modifiable set partitioning or covering constraint must be checked manually
2270  */
2271  if( consdata->setppctype == SCIP_SETPPCTYPE_PACKING ) /*lint !e641*/
2272  {
2273  if( !SCIPconsIsModifiable(cons) )
2274  {
2275  SCIPdebugMsg(scip, " -> disabling set packing constraint <%s>\n", SCIPconsGetName(cons));
2276  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2277  }
2278  *mustcheck = FALSE;
2279  }
2280  else if( !SCIPconsIsModifiable(cons) )
2281  {
2282  SCIP_VAR** vars;
2283  SCIP_VAR* var;
2284  SCIP_Bool infeasible;
2285  SCIP_Bool tightened;
2286  int nvars;
2287  int v;
2288 
2289  /* search the single variable that can be fixed */
2290  vars = consdata->vars;
2291  nvars = consdata->nvars;
2292  for( v = 0; v < nvars; ++v )
2293  {
2294  var = vars[v];
2295  assert(SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)));
2296  assert(SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) || SCIPisFeasEQ(scip, SCIPvarGetUbLocal(var), 1.0));
2297  if( SCIPvarGetUbLocal(var) > 0.5 )
2298  {
2299  SCIPdebugMsg(scip, " -> fixing remaining variable <%s> to one in set covering/partitioning constraint <%s>\n",
2300  SCIPvarGetName(var), SCIPconsGetName(cons));
2301  SCIP_CALL( SCIPinferBinvarCons(scip, var, TRUE, cons, 0, &infeasible, &tightened) );
2302  assert(!infeasible);
2303  assert(tightened);
2304 
2305  ++(*nfixedvars);
2306  break;
2307  }
2308  }
2309  assert(v < nvars);
2310  assert(consdata->nfixedzeros == consdata->nvars - 1);
2311  assert(consdata->nfixedones == 1);
2312 
2313  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2314  *mustcheck = FALSE;
2315  }
2316  }
2317  assert(consdata->nfixedzeros + consdata->nfixedones <= consdata->nvars);
2318 
2319  return SCIP_OKAY;
2320 }
2321 
2322 /** checks constraint for violation, returns TRUE iff constraint is feasible */
2323 static
2325  SCIP* scip, /**< SCIP data structure */
2326  SCIP_CONSDATA* consdata, /**< set partitioning / packing / covering constraint to be checked */
2327  SCIP_SOL* sol /**< primal CIP solution */
2328  )
2329 {
2330  SCIP_VAR** vars;
2331  SCIP_Real solval;
2333  SCIP_Real sumbound;
2334  SCIP_Real absviol;
2335  SCIP_Real relviol;
2336  SCIP_Bool check;
2337  int nvars;
2338  int v;
2339 
2340  /* calculate the constraint's activity */
2341  vars = consdata->vars;
2342  nvars = consdata->nvars;
2343  sum = 0.0;
2344  sumbound = ((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING ? 1.0 : 1.0 + 2*SCIPfeastol(scip));
2345  for( v = 0; v < nvars && sum < sumbound; ++v ) /* if sum >= sumbound, the feasibility is clearly decided */
2346  {
2347  assert(SCIPvarIsBinary(vars[v]));
2348 
2349  solval = SCIPgetSolVal(scip, sol, vars[v]);
2350  assert(SCIPisFeasGE(scip, solval, 0.0) && SCIPisFeasLE(scip, solval, 1.0));
2351 
2352  sum += solval;
2353  }
2354 
2355  absviol = sum - 1.0;
2356  relviol = SCIPrelDiff(sum, 1.0);
2357  switch( consdata->setppctype )
2358  {
2360  /* in case of partitioning, the violation is equal to the absolute difference between sum and 1 */
2361  absviol = REALABS(absviol);
2362  relviol = REALABS(relviol);
2363  check = SCIPisFeasEQ(scip, sum, 1.0);
2364  break;
2366  /* in case of packing, the violation is equal to how much sum exceeds 1 */
2367  check = SCIPisFeasLE(scip, sum, 1.0);
2368  break;
2370  /* in case of covering, the violation is equal to how much 1 exceeds sum */
2371  absviol = -absviol;
2372  relviol = -relviol;
2373  check = SCIPisFeasGE(scip, sum, 1.0);
2374  break;
2375  default:
2376  SCIPerrorMessage("unknown setppc type\n");
2377  SCIPABORT();
2378  return FALSE; /*lint !e527*/
2379  }
2380 
2381  if( sol != NULL )
2382  SCIPupdateSolLPConsViolation(scip, sol, absviol, relviol);
2383 
2384  return check;
2385 }
2386 
2387 /** creates an LP row in a set partitioning / packing / covering constraint data object */
2388 static
2390  SCIP* scip, /**< SCIP data structure */
2391  SCIP_CONS* cons /**< set partitioning / packing / covering constraint */
2392  )
2393 {
2394  SCIP_CONSDATA* consdata;
2395  SCIP_Real lhs;
2396  SCIP_Real rhs;
2398  consdata = SCIPconsGetData(cons);
2399  assert(consdata != NULL);
2400  assert(consdata->row == NULL);
2401 
2402  switch( consdata->setppctype )
2403  {
2405  lhs = 1.0;
2406  rhs = 1.0;
2407  break;
2409  lhs = -SCIPinfinity(scip);
2410  rhs = 1.0;
2411  break;
2413  lhs = 1.0;
2414  rhs = SCIPinfinity(scip);
2415  break;
2416  default:
2417  SCIPerrorMessage("unknown setppc type\n");
2418  return SCIP_INVALIDDATA;
2419  }
2420 
2421  SCIP_CALL( SCIPcreateEmptyRowCons(scip, &consdata->row, cons, SCIPconsGetName(cons), lhs, rhs,
2423 
2424  SCIP_CALL( SCIPaddVarsToRowSameCoef(scip, consdata->row, consdata->nvars, consdata->vars, 1.0) );
2425 
2426  return SCIP_OKAY;
2427 }
2428 
2429 /** adds setppc constraint as cut to the LP */
2430 static
2432  SCIP* scip, /**< SCIP data structure */
2433  SCIP_CONS* cons, /**< setppc constraint */
2434  SCIP_Bool* cutoff /**< whether a cutoff has been detected */
2435  )
2436 {
2437  SCIP_CONSDATA* consdata;
2438 
2439  assert( cutoff != NULL );
2440  *cutoff = FALSE;
2441 
2442  consdata = SCIPconsGetData(cons);
2443  assert(consdata != NULL);
2444 
2445  if( consdata->row == NULL )
2446  {
2447  /* convert set partitioning constraint data into LP row */
2448  SCIP_CALL( createRow(scip, cons) );
2449  }
2450  assert(consdata->row != NULL);
2451 
2452  /* insert LP row as cut */
2453  if( !SCIProwIsInLP(consdata->row) )
2454  {
2455  SCIPdebugMsg(scip, "adding constraint <%s> as cut to the LP\n", SCIPconsGetName(cons));
2456  SCIP_CALL( SCIPaddRow(scip, consdata->row, FALSE, cutoff) );
2457  }
2458 
2459  return SCIP_OKAY;
2460 }
2461 
2462 /** checks constraint for violation, and adds it as a cut if possible */
2463 static
2465  SCIP* scip, /**< SCIP data structure */
2466  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint to be separated */
2467  SCIP_SOL* sol, /**< primal CIP solution, NULL for current LP solution */
2468  SCIP_Bool lpfeas, /**< is the given solution feasible for the current LP ? */
2469  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
2470  SCIP_Bool* separated, /**< pointer to store TRUE, if a cut was found */
2471  SCIP_Bool* reduceddom /**< pointer to store TRUE, if a domain reduction was found */
2472  )
2473 {
2474  SCIP_CONSDATA* consdata;
2475  SCIP_Bool addcut;
2476  SCIP_Bool mustcheck;
2477 
2478  assert(cons != NULL);
2479  assert(SCIPconsGetHdlr(cons) != NULL);
2480  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
2481  assert(cutoff != NULL);
2482  assert(separated != NULL);
2483  assert(reduceddom != NULL);
2484 
2485  *cutoff = FALSE;
2486 
2487  consdata = SCIPconsGetData(cons);
2488  assert(consdata != NULL);
2489  assert(consdata->nvars == 0 || consdata->vars != NULL);
2490  assert(0 <= consdata->nfixedzeros && consdata->nfixedzeros <= consdata->nvars);
2491  assert(0 <= consdata->nfixedones && consdata->nfixedones <= consdata->nvars);
2492 
2493  /* skip constraints already in the LP */
2494  if( lpfeas && consdata->row != NULL && SCIProwIsInLP(consdata->row) )
2495  return SCIP_OKAY;
2496 
2497  SCIPdebugMsg(scip, "separating constraint <%s>\n", SCIPconsGetName(cons));
2498 
2499  /* check constraint for violation only looking at the fixed variables, apply further fixings if possible */
2500  if( lpfeas )
2501  {
2502  int nfixedvars = 0;
2503 
2504  SCIP_CALL( processFixings(scip, cons, cutoff, &nfixedvars, &addcut, &mustcheck) );
2505 
2506  *reduceddom = (nfixedvars > 0);
2507  }
2508  else
2509  {
2510  mustcheck = TRUE;
2511  addcut = FALSE;
2512  }
2513 
2514  if( mustcheck )
2515  {
2516  assert(!addcut);
2517 
2518  /* variable's fixings didn't give us any information -> we have to check the constraint */
2519  if( lpfeas && consdata->row != NULL )
2520  {
2521  SCIP_Real feasibility;
2522 
2523  assert(!SCIProwIsInLP(consdata->row));
2524  feasibility = SCIPgetRowSolFeasibility(scip, consdata->row, sol);
2525  addcut = SCIPisFeasNegative(scip, feasibility);
2526  }
2527  else
2528  addcut = !checkCons(scip, consdata, sol);
2529 
2530  if( !addcut )
2531  {
2532  /* constraint was feasible -> increase age */
2533  SCIP_CALL( SCIPincConsAge(scip, cons) );
2534  }
2535  }
2536 
2537  if( addcut )
2538  {
2539  /* insert LP row as cut */
2540  SCIP_CALL( addCut(scip, cons, cutoff) );
2541  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2542  *separated = TRUE;
2543  }
2544 
2545  return SCIP_OKAY;
2546 }
2547 
2548 /** enforces the pseudo solution on the given constraint */
2549 static
2551  SCIP* scip, /**< SCIP data structure */
2552  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint to be separated */
2553  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
2554  SCIP_Bool* infeasible, /**< pointer to store TRUE, if the constraint was infeasible */
2555  SCIP_Bool* reduceddom, /**< pointer to store TRUE, if a domain reduction was found */
2556  SCIP_Bool* solvelp /**< pointer to store TRUE, if the LP has to be solved */
2557  )
2559  SCIP_Bool addcut;
2560  SCIP_Bool mustcheck;
2561  int nfixedvars = 0;
2562 
2563  assert(!SCIPhasCurrentNodeLP(scip));
2564  assert(cons != NULL);
2565  assert(SCIPconsGetHdlr(cons) != NULL);
2566  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
2567  assert(cutoff != NULL);
2568  assert(infeasible != NULL);
2569  assert(reduceddom != NULL);
2570  assert(solvelp != NULL);
2571 
2572  /* check constraint for violation only looking at the fixed variables, apply further fixings if possible */
2573  SCIP_CALL( processFixings(scip, cons, cutoff, &nfixedvars, &addcut, &mustcheck) );
2574 
2575  *reduceddom = (nfixedvars > 0);
2576 
2577  if( mustcheck )
2578  {
2579  SCIP_CONSDATA* consdata;
2580 
2581  assert(!addcut);
2582 
2583  consdata = SCIPconsGetData(cons);
2584  assert(consdata != NULL);
2585 
2586  if( checkCons(scip, consdata, NULL) )
2587  {
2588  /* constraint was feasible -> increase age */
2589  SCIP_CALL( SCIPincConsAge(scip, cons) );
2590  }
2591  else
2592  {
2593  /* constraint was infeasible -> reset age */
2594  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2595  *infeasible = TRUE;
2596  }
2597  }
2598 
2599  if( addcut )
2600  {
2601  /* a cut must be added to the LP -> we have to solve the LP immediately */
2602  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2603  *solvelp = TRUE;
2604  }
2605 
2606  return SCIP_OKAY;
2607 }
2608 
2609 /** gets the key of the given element */
2610 static
2611 SCIP_DECL_HASHGETKEY(hashGetKeySetppccons)
2612 { /*lint --e{715}*/
2613  /* the key is the element itself */
2614  return elem;
2615 }
2616 
2617 /** returns TRUE iff both keys are equal; two constraints are equal if they have the same variables */
2618 static
2619 SCIP_DECL_HASHKEYEQ(hashKeyEqSetppccons)
2620 {
2621 #ifndef NDEBUG
2622  SCIP* scip;
2623 #endif
2624  SCIP_CONSDATA* consdata1;
2625  SCIP_CONSDATA* consdata2;
2626  SCIP_Bool coefsequal;
2627  int i;
2628 
2629  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
2630  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
2631  assert(consdata1->sorted);
2632  assert(consdata2->sorted);
2633 #ifndef NDEBUG
2634  scip = (SCIP*)userptr;
2635  assert(scip != NULL);
2636 #endif
2637 
2638  /* checks trivial case */
2639  if( consdata1->nvars != consdata2->nvars )
2640  return FALSE;
2641 
2642  coefsequal = TRUE;
2643 
2644  for( i = 0; i < consdata1->nvars; ++i )
2645  {
2646  /* tests if variables are equal */
2647  if( consdata1->vars[i] != consdata2->vars[i] )
2648  {
2649  assert(SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == 1 ||
2650  SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == -1);
2651  coefsequal = FALSE;
2652  break;
2653  }
2654  assert(SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == 0);
2655  }
2656 
2657  return coefsequal;
2658 }
2659 
2660 /** returns the hash value of the key */
2661 static
2662 SCIP_DECL_HASHKEYVAL(hashKeyValSetppccons)
2663 {
2664  SCIP_CONSDATA* consdata;
2665  int minidx;
2666  int mididx;
2667  int maxidx;
2668 #ifndef NDEBUG
2669  SCIP* scip;
2671  scip = (SCIP*)userptr;
2672  assert(scip != NULL);
2673 #endif
2674 
2675  consdata = SCIPconsGetData((SCIP_CONS*)key);
2676  assert(consdata != NULL);
2677  assert(consdata->nvars > 0);
2678 
2679  /* sorts the constraints */
2680  consdataSort(consdata);
2681 
2682  minidx = SCIPvarGetIndex(consdata->vars[0]);
2683  mididx = SCIPvarGetIndex(consdata->vars[consdata->nvars / 2]);
2684  maxidx = SCIPvarGetIndex(consdata->vars[consdata->nvars - 1]);
2685  assert(minidx >= 0 && minidx <= maxidx);
2686 
2687  return SCIPhashFour(consdata->nvars, minidx, mididx, maxidx);
2688 }
2689 
2690 /** add extra clique-constraints resulting from a given cliquepartition to SCIP */
2691 static
2693  SCIP*const scip, /**< SCIP data structure */
2694  SCIP_VAR**const binvars, /**< binary variables to create clique constraints */
2695  int const nbinvars, /**< number of binary variables to create clique constraints */
2696  int*const cliquepartition, /**< clique partition of binary variables */
2697  int const ncliques, /**< number of cliques in cliquepartition */
2698  SCIP_CONS**const usefulconss, /**< storage for created constraints */
2699  int*const nusefulconss, /**< pointer to store number of useful created constraints */
2700  int const nrounds, /**< actual presolving round */
2701  int*const nfixedvars, /**< pointer to count number of deleted variables */
2702  int*const naddconss, /**< pointer to count number of added constraints */
2703  int*const ndelconss, /**< pointer to count number of deleted constraints */
2704  int*const nchgcoefs, /**< pointer to count number of deleted coefficients */
2705  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
2706  )
2707 {
2708  SCIP_CONS* cliquecons;
2709  char name[SCIP_MAXSTRLEN];
2710  int lastclqidx;
2711  int nadded;
2712  int c;
2713  int v;
2714 
2715  assert(scip != NULL);
2716  assert(binvars != NULL || nbinvars == 0);
2717  assert(cliquepartition != NULL || nbinvars == 0);
2718  assert(ncliques >= 0 && ncliques <= nbinvars);
2719  assert(usefulconss != NULL);
2720  assert(nusefulconss != NULL);
2721  assert(nfixedvars != NULL);
2722  assert(naddconss != NULL);
2723  assert(ndelconss != NULL);
2724  assert(nchgcoefs != NULL);
2725  assert(cutoff != NULL);
2726 
2727  /* no given binary variables */
2728  if( nbinvars == 0 || ncliques == 0 )
2729  return SCIP_OKAY;
2730 
2731  assert(binvars != NULL);
2732  assert(cliquepartition != NULL);
2733 
2734  /* no useful clique information */
2735  if( ncliques == nbinvars )
2736  return SCIP_OKAY;
2737 
2738  lastclqidx = 0;
2739 
2740  /* @todo: maybe sort cliques and accordingly the variables so it will be faster to add the constraints */
2741  for( c = 0; c < ncliques - 1; ++c )
2742  {
2743  if( lastclqidx >= cliquepartition[c] )
2744  continue;
2745 
2746  nadded = 0;
2747 
2748  /* name the clique constraint */
2749  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "extra_clq_%d_round_%d", cliquepartition[c], nrounds);
2750  SCIP_CALL( SCIPcreateConsSetpack(scip, &cliquecons, name, 0, NULL,
2752 
2753  /* add variables to clique constraint */
2754  for( v = c; v < nbinvars - 1; ++v )
2755  {
2756  if( cliquepartition[c] == cliquepartition[v] )
2757  {
2758  SCIP_CALL( addCoef(scip, cliquecons, binvars[v]) );
2759  ++nadded;
2760  }
2761  }
2762 
2763  /* @todo: try to find a good value for what are enough variables to create this constraint, maybe at least
2764  * (nmaxvars(over all conss)-nminvars(over all conss))/2 */
2765  if( nadded >= 2 )
2766  {
2767  SCIP_CONSDATA* cliqueconsdata;
2768 
2769  SCIPdebugMsg(scip, " -> adding clique constraint: ");
2770  SCIPdebugPrintCons(scip, cliquecons, NULL);
2771  SCIP_CALL( SCIPaddCons(scip, cliquecons) );
2772  ++(*naddconss);
2773 
2774  /* we only want to consider merged constraints */
2775  SCIP_CALL( mergeMultiples(scip, cliquecons, nfixedvars, ndelconss, nchgcoefs, cutoff) );
2776  if( *cutoff )
2777  {
2778  SCIP_CALL( SCIPreleaseCons(scip, &cliquecons) );
2779 
2780  return SCIP_OKAY;
2781  }
2782 
2783  cliqueconsdata = SCIPconsGetData(cliquecons);
2784  assert(cliqueconsdata != NULL);
2785 
2786  /* the artificial constraints could be deleted while merging */
2787  if( !SCIPconsIsDeleted(cliquecons) && nadded - cliqueconsdata->nfixedzeros >= 2 )
2788  {
2789  assert(cliqueconsdata->nfixedones == 0);
2790 
2791  /* save the type and constraint */
2792  usefulconss[*nusefulconss] = cliquecons;
2793  ++(*nusefulconss);
2794  }
2795  SCIP_CALL( SCIPreleaseCons(scip, &cliquecons) );
2796  }
2797  else
2798  {
2799  SCIP_CALL( SCIPreleaseCons(scip, &cliquecons) );
2800  }
2801  lastclqidx = cliquepartition[c];
2802  }
2803 
2804  return SCIP_OKAY;
2805 }
2806 
2807 
2808 /** start to collect setpartitioning and setpacking constraints, and try to remove fixed variables and merged these
2809  * constraints
2810  */
2811 static
2813  SCIP*const scip, /**< SCIP data structure */
2814  SCIP_CONS**const conss, /**< constraint set */
2815  int const nconss, /**< number of constraints in constraint set */
2816  SCIP_CONS**const usefulconss, /**< storage for created constraints */
2817  int*const nusefulconss, /**< pointer to store number of useful created constraints */
2818  int*const nfixedvars, /**< pointer to count number of deleted variables */
2819  int*const ndelconss, /**< pointer to count number of deleted constraints */
2820  int*const nchgcoefs, /**< pointer to count number of deleted coefficients */
2821  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
2822  )
2823 {
2824  SCIP_CONS* cons;
2825  SCIP_CONSDATA* consdata;
2826  SCIP_Bool addcut;
2827  SCIP_Bool mustcheck;
2828  int nlocaladdconss = 0;
2829  int c;
2830 
2831  assert(scip != NULL);
2832  assert(conss != NULL || nconss == 0);
2833  assert(usefulconss != NULL);
2834  assert(nusefulconss != NULL);
2835  assert(nfixedvars != NULL);
2836  assert(ndelconss != NULL);
2837  assert(nchgcoefs != NULL);
2838  assert(cutoff != NULL);
2839 
2840  if( nconss == 0 )
2841  return SCIP_OKAY;
2842 
2843  assert(conss != NULL);
2844 
2845  for( c = nconss - 1; c >= 0; --c )
2846  {
2847  cons = conss[c];
2848 
2849  /* we only want to consider constraints with either active or negated of active variables, applyfixings removes
2850  * aggregated and fixed variables to zero, processFixings removes fixings to one but no aggregation
2851  *
2852  * @todo: maybe write a new method for deleting aggregations and all fixings
2853  */
2854  SCIP_CALL( applyFixings(scip, cons, &nlocaladdconss, ndelconss, nfixedvars, cutoff) );
2855  if( *cutoff )
2856  return SCIP_OKAY;
2857 
2858  if( SCIPconsIsDeleted(cons) )
2859  {
2860  /* reset nlocaladdconss and continue */
2861  nlocaladdconss = 0;
2862  continue;
2863  }
2864  assert(nlocaladdconss == 0);
2865 
2866  SCIP_CALL( processFixings(scip, cons, cutoff, nfixedvars, &addcut, &mustcheck) );
2867  if( *cutoff )
2868  return SCIP_OKAY;
2869 
2870  consdata = SCIPconsGetData(cons);
2871  assert(consdata != NULL);
2872 
2873  /* we only want to consider merged constraints */
2874  SCIP_CALL( mergeMultiples(scip, cons, nfixedvars, ndelconss, nchgcoefs, cutoff) );
2875  if( *cutoff )
2876  return SCIP_OKAY;
2877 
2878  if( SCIPconsIsModifiable(cons) || !SCIPconsIsActive(cons) )
2879  continue;
2880 
2881  assert(consdata->nfixedones == 0);
2882 
2883  if( consdata->nvars == 0 )
2884  continue;
2885 
2886  /* @todo: check for covering constraints with only two variables which are equal to a packing constraint with
2887  * negated variables */
2888  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
2889  {
2890  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
2891 
2892  usefulconss[*nusefulconss] = cons;
2893  ++(*nusefulconss);
2894  }
2895  }
2896 
2897  return SCIP_OKAY; /*lint !e438*/
2898 }
2899 
2900 /** creating all necessary data in array structure, collect all clique constraint variables and occurrences,
2901  * @note works only with merged and active not set-covering constraints
2902  */
2903 static
2905  SCIP*const scip, /**< SCIP data structure */
2906  SCIP_CONS**const usefulconss, /**< clique constraints */
2907  int const nusefulconss, /**< number of clique constraints */
2908  SCIP_VAR**const usefulvars, /**< storage for all found variables */
2909  int*const nusefulvars, /**< pointer to store number of added variables */
2910  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
2911  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
2912  int*const maxnvarconsidx, /**< storage for the maximal number of occurrences of a variable */
2913  int**const varconsidxs, /**< storage for constraint indices in which the corresponding variable exists */
2914  int*const maxnvars /**< pointer to store maximal number of variables of a constraint */
2915  )
2916 {
2917  SCIP_CONS* cons;
2918  SCIP_CONSDATA* consdata;
2919  int varindex;
2920  int c;
2921  int v;
2922 
2923  assert(scip != NULL);
2924  assert(usefulconss != NULL || nusefulconss == 0);
2925  assert(usefulvars != NULL);
2926  assert(nusefulvars != NULL);
2927  assert(vartoindex != NULL);
2928  assert(varnconss != NULL);
2929  assert(maxnvarconsidx != NULL);
2930  assert(varconsidxs != NULL);
2931  assert(maxnvars != NULL);
2932 
2933  if( nusefulconss == 0 )
2934  return SCIP_OKAY;
2935 
2936  assert(usefulconss != NULL);
2937 
2938  for( c = nusefulconss - 1; c >= 0; --c )
2939  {
2940  cons = usefulconss[c];
2941 
2942  assert(SCIPconsIsActive(cons));
2943 
2944  consdata = SCIPconsGetData(cons);
2945  assert(consdata != NULL);
2946 
2947  /* here we should have no covering constraints anymore and the constraint data should be merged */
2948  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
2949  assert(consdata->merged);
2950 
2951  /* save maximal number of vars */
2952  if( consdata->nvars > *maxnvars )
2953  *maxnvars = consdata->nvars;
2954 
2955  /* adding variables and information about occurrences to local data structure */
2956  for( v = consdata->nvars - 1; v >= 0; --v )
2957  {
2958  SCIP_VAR* var;
2959 
2960  var = consdata->vars[v];
2961  assert(var != NULL);
2962 
2963  /* don't remember fixed vars */
2964  if( SCIPvarGetLbLocal(var) > 0.5 || SCIPvarGetUbLocal(var) < 0.5 )
2965  continue;
2966 
2967  /* only collect active or negated active variables */
2969 
2970  if( !SCIPhashmapExists(vartoindex, (void*) var) )
2971  {
2972  SCIP_VAR* tmpvar;
2973 
2974  usefulvars[*nusefulvars] = var;
2975  ++(*nusefulvars);
2976  varindex = *nusefulvars;
2977  SCIP_CALL( SCIPhashmapInsertInt(vartoindex, (void*) var, varindex) );
2978 
2979  /* get the maximal number of occurrences of this variable, if this variables */
2980  tmpvar = SCIPvarIsNegated(var) ? SCIPvarGetNegatedVar(var) : var;
2981  maxnvarconsidx[varindex] = SCIPvarGetNLocksDownType(tmpvar, SCIP_LOCKTYPE_MODEL)
2983  SCIP_CALL( SCIPallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
2984  }
2985  else
2986  {
2987  assert(SCIPhashmapExists(vartoindex, (void*) var));
2988  varindex = SCIPhashmapGetImageInt(vartoindex, (void*) var);
2989  }
2990 
2991  /* the number of occurrences of a variable is not limited by the locks (so maybe we have to increase memory),
2992  * because for examples converted cuts are not check and therefore they have no locks on their variables */
2993  if( varnconss[varindex] == maxnvarconsidx[varindex] )
2994  {
2995  maxnvarconsidx[varindex] = SCIPcalcMemGrowSize(scip, maxnvarconsidx[varindex] + 1);
2996  SCIP_CALL( SCIPreallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
2997  }
2998 
2999  assert(varnconss[varindex] < maxnvarconsidx[varindex]);
3000  /* add the constraint number to the variable list */
3001  varconsidxs[varindex][varnconss[varindex]] = c;
3002  /* increase number of occurrences for variables */
3003  ++(varnconss[varindex]);
3004  }
3005  } /* data structure created */
3006 
3007  return SCIP_OKAY;
3008 }
3009 
3010 /** correct clique data due to an aggregation */
3011 static
3013  SCIP_VAR*const var, /**< variable which appears less */
3014  int const considx, /**< constraint index which to remove */
3015  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
3016  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
3017  int**const varconsidxs /**< storage for constraint indices in which the corresponding variable exists */
3018  )
3019 {
3020  int varindex;
3021  int i;
3022 #ifndef NDEBUG
3023  SCIP_Bool found = FALSE;
3024 #endif
3025 
3026  assert(var != NULL);
3027  assert(SCIPvarGetLbLocal(var) < 0.5 && SCIPvarGetUbLocal(var) > 0.5);
3028  assert(considx >= 0);
3029  assert(vartoindex != NULL);
3030  assert(varnconss != NULL);
3031  assert(varconsidxs != NULL);
3032 
3033  assert(SCIPhashmapExists(vartoindex, (void*) var));
3034  varindex = SCIPhashmapGetImageInt(vartoindex, (void*) var);
3035 
3036  /* remove entry of variable at the given position */
3037  for( i = 0; i < varnconss[varindex]; ++i )
3038  {
3039  if( varconsidxs[varindex][i] == considx )
3040  {
3041  varconsidxs[varindex][i] = varconsidxs[varindex][varnconss[varindex] - 1];
3042 #ifndef NDEBUG
3043  found = TRUE;
3044 #endif
3045  --(varnconss[varindex]);
3046  break;
3047  }
3048  }
3049  assert(found);
3050 }
3051 
3052 /* correct local data structure, add constraint entry to variable data */
3053 static
3055  SCIP*const scip, /**< SCIP data structure */
3056  SCIP_VAR*const addvar, /**< variable which was added */
3057  int const considx, /**< constraint index which to add */
3058  SCIP_Bool const maybenew, /**< could be a new variables, a negated of an already existing */
3059  SCIP_VAR**const usefulvars, /**< storage for all found variables */
3060  int*const nusefulvars, /**< pointer to store number of added variables */
3061  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
3062  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
3063  int*const maxnvarconsidx, /**< storage for the maximal number of occurrences of a variable */
3064  int**const varconsidxs /**< storage for constraint indices in which the corresponding variable exists */
3065  )
3066 {
3067  int varindex;
3068 
3069  assert(scip != NULL);
3070  assert(addvar != NULL);
3071  assert(SCIPvarGetLbLocal(addvar) < 0.5 && SCIPvarGetUbLocal(addvar) > 0.5);
3072  assert(usefulvars != NULL);
3073  assert(nusefulvars != NULL);
3074  assert(vartoindex != NULL);
3075  assert(varnconss != NULL);
3076  assert(maxnvarconsidx != NULL);
3077  assert(varconsidxs != NULL);
3078 
3079  /* we add the variable to the hashmap if its new */
3080  if( maybenew && !SCIPhashmapExists(vartoindex, (void*) addvar) )
3081  {
3082  assert(SCIPvarIsActive(addvar) || SCIPvarIsNegated(addvar));
3083  assert(SCIPvarGetNegatedVar(addvar) != NULL && SCIPhashmapExists(vartoindex, (void*) SCIPvarGetNegatedVar(addvar)));
3084 
3085  /* @note because we can only have created a negated variable, and we already allocated enough memory for
3086  * all (even not existing) negated variables the usefulvars array should be big enough
3087  */
3088  SCIPsortedvecInsertDownPtr((void**)usefulvars, SCIPvarCompActiveAndNegated, addvar, nusefulvars, NULL);
3089  varindex = *nusefulvars;
3090  SCIP_CALL( SCIPhashmapInsertInt(vartoindex, (void*) addvar, varindex) );
3091 
3092  assert(varconsidxs[varindex] == NULL);
3093 
3094  maxnvarconsidx[varindex] = 1;
3095  SCIP_CALL( SCIPallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
3096  varnconss[varindex] = 0;
3097  }
3098  else
3099  {
3100  varindex = SCIPhashmapGetImageInt(vartoindex, (void*) addvar);
3101 
3102  /* grow the needed memory if we added a variable */
3103  if( varnconss[varindex] == maxnvarconsidx[varindex] )
3104  {
3105  maxnvarconsidx[varindex] = SCIPcalcMemGrowSize(scip, maxnvarconsidx[varindex] + 1);
3106  SCIP_CALL( SCIPreallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
3107  }
3108  }
3109  assert(varnconss[varindex] < maxnvarconsidx[varindex]);
3110  varconsidxs[varindex][varnconss[varindex]] = considx;
3111 
3112  /* increase number of occurrences for variables */
3113  ++(varnconss[varindex]);
3114 
3115  return SCIP_OKAY;
3116 }
3117 
3118 
3119 /** check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
3120  * possible
3121  */
3122 static
3124  SCIP*const scip, /**< SCIP data structure */
3125  SCIP_CONS*const cons, /**< constraint */
3126  SCIP_Bool const aggregate, /**< try to aggregate if possible */
3127  SCIP_VAR** undoneaggrvars, /**< array to store aggregation variables, if aggregation is not performed
3128  * yet; both variables are standing next to each other; or NULL if
3129  * aggregate == TRUE
3130  */
3131  SCIP_Bool* undoneaggrtypes, /**< array to store aggregation type, if aggregation is not performed yet;
3132  * type FALSE means the aggregation is of the form x + y = 1; type TRUE means
3133  * the aggregation is of the form x = y; or NULL if aggregate == TRUE
3134  */
3135  int*const naggregations, /**< pointer to store number of aggregations which are not yet performed;
3136  * or NULL if aggregate == TRUE
3137  */
3138  int*const saggregations, /**< pointer to store size of the array for aggregation type and two times
3139  * the value is the size of the array for the aggregation variables which
3140  * are not yet performed; or NULL if aggregate == TRUE
3141  */
3142  int*const nfixedvars, /**< pointer to count number of deleted variables */
3143  int*const naggrvars, /**< pointer to count number of aggregated variables */
3144  int*const ndelconss, /**< pointer to count number of deleted constraints */
3145  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
3146  )
3147 {
3148  SCIP_CONSDATA* consdata;
3149  SCIP_VAR** vars;
3150  int nvars;
3151  int v;
3152  SCIP_Bool fixed;
3153 
3154  assert(scip != NULL);
3155  assert(cons != NULL);
3156  assert(nfixedvars != NULL);
3157  assert(naggrvars != NULL);
3158  assert(ndelconss != NULL);
3159  assert(cutoff != NULL);
3160 
3161  if( !SCIPconsIsActive(cons) )
3162  return SCIP_OKAY;
3163 
3164  consdata = SCIPconsGetData(cons);
3165  assert(consdata != NULL);
3166 
3167  if( consdata->presolpropagated )
3168  return SCIP_OKAY;
3169 
3170  consdata->presolpropagated = TRUE;
3171 
3172  vars = consdata->vars;
3173  nvars = consdata->nvars;
3174 
3175  /* no variables left */
3176  if( nvars == 0 && !SCIPconsIsModifiable(cons) )
3177  {
3178  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3179  {
3180  SCIPdebugMsg(scip, "empty set-partition/-covering constraint <%s> found -> cutoff\n", SCIPconsGetName(cons));
3181  *cutoff = TRUE;
3182 
3183  return SCIP_OKAY;
3184  }
3185  else
3186  {
3187  assert(consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
3188 
3189  /* delete constraint */
3190  SCIPdebugMsg(scip, " -> deleting constraint <%s>, no variables left\n", SCIPconsGetName(cons));
3191  SCIP_CALL( SCIPdelCons(scip, cons) );
3192  ++(*ndelconss);
3193 
3194  return SCIP_OKAY;
3195  }
3196  }
3197 
3198  /* more then two variables are fixed */
3199  if( consdata->nfixedones > 1 )
3200  {
3201  /* at least two variables are fixed to 1:
3202  * - a set covering constraint is feasible anyway and can be deleted
3203  * - a set partitioning or packing constraint is infeasible
3204  */
3205  if( consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3206  {
3207  /* delete constraint */
3208  SCIPdebugMsg(scip, " -> deleting set-covering constraint <%s>, at least two variables are fixed to 1\n", SCIPconsGetName(cons));
3209  SCIP_CALL( SCIPdelCons(scip, cons) );
3210  ++(*ndelconss);
3211 
3212  return SCIP_OKAY;
3213  }
3214 
3215  SCIPdebugMsg(scip, "set partitioning / packing constraint <%s> is infeasible, %d variables fixed to one\n", SCIPconsGetName(cons), consdata->nfixedones);
3216  *cutoff = TRUE;
3217 
3218  return SCIP_OKAY;
3219  }
3220 
3221  if( consdata->nfixedones == 1 )
3222  {
3223  /* exactly one variable is fixed to 1:
3224  * - a set covering constraint is feasible anyway and can be disabled
3225  * - all other variables in a set partitioning or packing constraint must be zero
3226  */
3227  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING && consdata->nfixedzeros < nvars - 1 ) /*lint !e641*/
3228  {
3229  assert(vars != NULL);
3230 
3231  for( v = nvars - 1; v >= 0; --v )
3232  {
3233  if( SCIPvarGetLbLocal(vars[v]) + 0.5 < SCIPvarGetUbLocal(vars[v]) )
3234  {
3235  SCIPdebugMsg(scip, "trying to fix <%s> to 0 due to at least one variable is already fixed to 1\n", SCIPvarGetName(vars[v]));
3236 
3237  /* fix all remaining variables to zero, constraint is already feasible or infeasible */
3238  SCIP_CALL( SCIPfixVar(scip, vars[v], 0.0, cutoff, &fixed) );
3239  if( *cutoff )
3240  {
3241  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 0\n",
3242  SCIPconsGetName(cons), SCIPvarGetName(vars[v]));
3243 
3244  return SCIP_OKAY;
3245  }
3246 
3247  assert(fixed);
3248  ++(*nfixedvars);
3249  }
3250  }
3251  }
3252 
3253  if( !SCIPconsIsModifiable(cons) || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3254  {
3255  /* delete constraint */
3256  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all variables are fixed\n", SCIPconsGetName(cons));
3257  assert(SCIPconsIsActive(cons));
3258  SCIP_CALL( SCIPdelCons(scip, cons) );
3259  ++(*ndelconss);
3260  }
3261 
3262  return SCIP_OKAY;
3263  }
3264 
3265  /* other propagations can only be done on not modifiable constraints */
3266  if( SCIPconsIsModifiable(cons) )
3267  return SCIP_OKAY;
3268 
3269  assert(vars != NULL);
3270 
3271  /* all variables were fixed to zero then either delete the constraint or stop with infeasibility */
3272  if( consdata->nfixedzeros == nvars )
3273  {
3274  assert(consdata->nfixedones == 0);
3275 
3276  /* all variables are fixed to zero:
3277  * - a set packing constraint is feasible anyway and can be deleted
3278  * - a set partitioning or covering constraint is infeasible, and so is the whole problem
3279  */
3280  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3281  {
3282  SCIPdebugMsg(scip, "set partitioning / covering constraint <%s> is infeasible\n", SCIPconsGetName(cons));
3283  *cutoff = TRUE;
3284 
3285  return SCIP_OKAY;
3286  }
3287 
3288  /* delete constraint */
3289  SCIPdebugMsg(scip, " -> deleting set-packing constraint <%s>, all variables are fixed to zero\n", SCIPconsGetName(cons));
3290  assert(SCIPconsIsActive(cons));
3291  SCIP_CALL( SCIPdelCons(scip, cons) );
3292  ++(*ndelconss);
3293 
3294  return SCIP_OKAY;
3295  }
3296 
3297  /* all but one variable were fixed to zero then delete the constraint and for setpartition fix the remaining variable to 1 */
3298  if( consdata->nfixedzeros + 1 == nvars )
3299  {
3300  assert(consdata->nfixedones == 0);
3301 
3302  /* all variables except one are fixed to zero:
3303  * - a set packing constraint is feasible anyway, and can be deleted
3304  * - a set partitioning or covering constraint is feasible and can be deleted after the
3305  * remaining variable is fixed to one
3306  */
3307  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3308  {
3309  fixed = FALSE;
3310  for( v = nvars - 1; v >= 0; --v )
3311  {
3312  assert(SCIPvarGetLbLocal(vars[v]) < 0.5);
3313  if( SCIPvarGetUbLocal(vars[v]) > 0.5 )
3314  {
3315  SCIPdebugMsg(scip, "trying to fix <%s> to 1 due to it's the last unfixed variable is the set-partitioning/covering constraint\n", SCIPvarGetName(vars[v]));
3316 
3317  /* fix the remaining set partition variable */
3318  SCIP_CALL( SCIPfixVar(scip, vars[v], 1.0, cutoff, &fixed) );
3319  if( *cutoff )
3320  {
3321  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 1\n",
3322  SCIPconsGetName(cons), SCIPvarGetName(vars[v]));
3323 
3324  return SCIP_OKAY;
3325  }
3326 
3327  assert(fixed);
3328  ++(*nfixedvars);
3329  break;
3330  }
3331  }
3332  assert(fixed);
3333  }
3334 
3335  /* delete constraint */
3336  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all %svariables are fixed\n", SCIPconsGetName(cons), consdata->setppctype == (int) SCIP_SETPPCTYPE_PACKING ? "but one " : "");
3337  assert(SCIPconsIsActive(cons));
3338  SCIP_CALL( SCIPdelCons(scip, cons) );
3339  ++(*ndelconss);
3340 
3341  return SCIP_OKAY;
3342  }
3343 
3344  /* all but two variable were fixed to zero in a setpartitioning constraint then delete the constraint and
3345  * aggregate the remaining two variables
3346  */
3347  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata->nfixedzeros + 2 == nvars ) /*lint !e641*/
3348  {
3349  SCIP_VAR* var;
3350 
3351  var = NULL;
3352  for( v = nvars - 1; v >= 0; --v )
3353  {
3354  assert(SCIPvarGetLbLocal(vars[v]) < 0.5);
3355 
3356  if( SCIPvarGetUbLocal(vars[v]) > 0.5 )
3357  {
3358  if( var == NULL )
3359  var = vars[v];
3360  else
3361  {
3362  SCIP_Bool redundant;
3363  SCIP_Bool aggregated;
3364 #ifdef VARUSES
3365  SCIP_CONSHDLR* conshdlr;
3366  SCIP_CONSHDLRDATA* conshdlrdata;
3367 
3368  /* get event handler and event handler data */
3369  conshdlr = SCIPconsGetHdlr(cons);
3370  assert(conshdlr != NULL);
3371  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3372  assert(conshdlrdata != NULL);
3373 #endif
3374  if( aggregate )
3375  {
3376  SCIPdebugMsg(scip, "trying to aggregate <%s> and <%s> due to they are the last two unfixed variables in the set partitionning constraint <%s>\n", SCIPvarGetName(var), SCIPvarGetName(vars[v]), SCIPconsGetName(cons));
3377 
3378 #ifdef VARUSES
3379  /* in order to not mess up the variable usage counting, we have to decrease usage counting, aggregate,
3380  * and increase usage counting again
3381  */
3382  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, var) );
3383  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, vars[v]) );
3384 #endif
3385 
3386  /* aggregate last remaining variables in the set partitioning constraint */
3387  SCIP_CALL( SCIPaggregateVars(scip, var, vars[v], 1.0, 1.0, 1.0, cutoff, &redundant, &aggregated) );
3388  if( *cutoff )
3389  {
3390  SCIPdebugMsg(scip, "set partitioning constraint <%s>: aggregate <%s> + <%s> == 1\n",
3391  SCIPconsGetName(cons), SCIPvarGetName(var), SCIPvarGetName(vars[v]));
3392 
3393  return SCIP_OKAY;
3394  }
3395 
3396 #ifdef VARUSES
3397  /* increase variable usage counting again */
3398  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var) );
3399  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, vars[v]) );
3400 #endif
3401 
3402  if( aggregated )
3403  ++(*naggrvars);
3404 
3405  if( redundant )
3406  {
3407  /* delete constraint */
3408  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all variables are fixed\n", SCIPconsGetName(cons));
3409  assert(SCIPconsIsActive(cons));
3410  SCIP_CALL( SCIPdelCons(scip, cons) );
3411  ++(*ndelconss);
3412  }
3413  }
3414  else
3415  {
3416  assert(undoneaggrvars != NULL);
3417  assert(undoneaggrtypes != NULL);
3418  assert(naggregations != NULL);
3419  assert(saggregations != NULL);
3420 
3421  SCIPdebugMsg(scip, "memorize the aggregation of <%s> + <%s> = 1, because they are the last two unfixed variable in the set partitioning constraints <%s>\n", SCIPvarGetName(var), SCIPvarGetName(vars[v]), SCIPconsGetName(cons));
3422 
3423  /* resize the aggregation arrays if necessary */
3424  if( *saggregations == *naggregations )
3425  {
3426  *saggregations = SCIPcalcMemGrowSize(scip, *naggregations + 1);
3427  assert(*saggregations > *naggregations);
3428  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrtypes, *saggregations) );
3429  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrvars, 2 * (*saggregations)) );
3430 
3431  /* clear the aggregation type array to set the default to the aggregation of the form x + y = 1 */
3432  BMSclearMemoryArray(&(undoneaggrtypes[*naggregations]), *saggregations - *naggregations); /*lint !e866*/
3433  }
3434 
3435  /* memorize aggregation variables*/
3436  assert(undoneaggrtypes[*naggregations] == FALSE);
3437  undoneaggrvars[2 * (*naggregations)] = var;
3438  undoneaggrvars[2 * (*naggregations) + 1] = vars[v];
3439  ++(*naggregations);
3440 
3441  if( !SCIPdoNotAggr(scip) )
3442  {
3443  /* delete constraint */
3444  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all variables are fixed\n", SCIPconsGetName(cons));
3445  assert(SCIPconsIsActive(cons));
3446  SCIP_CALL( SCIPdelCons(scip, cons) );
3447  ++(*ndelconss);
3448  }
3449  }
3450 
3451  return SCIP_OKAY;
3452  }
3453  }
3454  }
3455  /* we should never be here, because the last to unfixed variables should have been either aggregated or a cutoff
3456  * should be applied
3457  */
3458  assert(FALSE);
3459  }
3460 
3461  return SCIP_OKAY;
3462 }
3463 
3464 /** check for overlapping constraint */
3465 static
3467  SCIP*const scip, /**< SCIP data structure */
3468  SCIP_CONS*const cons, /**< constraint which may overlap */
3469  int const considx, /**< constraint index to avoid checking against itself */
3470  int const endidx, /**< end index to check against given constraint */
3471  SCIP_CONS**const usefulconss, /**< clique constraints */
3472  int const nusefulconss, /**< number of clique constraints */
3473  SCIP_VAR**const usefulvars, /**< storage for all found variables */
3474  int*const nusefulvars, /**< pointer to store number of added variables */
3475  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
3476  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
3477  int*const maxnvarconsidx, /**< storage for the maximal number of occurrences of a variable */
3478  int**const varconsidxs, /**< storage for constraint indices in which the corresponding variable exists */
3479  int*const countofoverlapping, /**< the amount of variables of cons which overlap in all other constraint */
3480  SCIP_Bool const shrinking, /**< try to replace some variables with one variable */
3481  SCIP_Bool*const chgcons, /**< pointer to store if the given constraint was changed, due to
3482  * added/deleted variables
3483  */
3484  SCIP_VAR** undoneaggrvars, /**< array to store aggregation variables, if aggregation is not performed
3485  * yet; both variables are standing next to each other;
3486  */
3487  SCIP_Bool* undoneaggrtypes, /**< array to store aggregation type, if aggregation is not performed yet;
3488  * type FALSE means the aggregation is of the form x + y = 1; type TRUE means
3489  * the aggregation is of the form x = y;
3490  */
3491  int*const naggregations, /**< pointer to store number of aggregations which are not yet performed; */
3492  int*const saggregations, /**< pointer to store size of the array for aggregation type and two times
3493  * the value is the size of the array for the aggregation variables which
3494  * are not yet performed;
3495  */
3496  int*const nfixedvars, /**< pointer to count number of deleted variables */
3497  int*const naggrvars, /**< pointer to count number of aggregated variables */
3498  int*const nchgcoefs, /**< pointer to count number of changed coefficients */
3499  int*const ndelconss, /**< pointer to count number of deleted constraints */
3500  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
3501  )
3502 {
3503  SCIP_CONS* cons1;
3504  SCIP_CONSDATA* consdata1;
3505  SCIP_CONSDATA* consdata;
3506  SCIP_VAR** vars;
3507  SCIP_VAR** vars1;
3508  SCIP_VAR* var;
3509  SCIP_VAR* var1;
3510  SCIP_Bool fixed;
3511  SCIP_Bool overlapdestroyed;
3512  int nvars;
3513  int nvars1;
3514  int oldnfixedzeros;
3515  int c;
3516  int v;
3517  int v1;
3518 #ifndef NDEBUG
3519  int oldnaggrvars;
3520 #endif
3521 
3522  assert(scip != NULL);
3523  assert(cons != NULL);
3524  assert(usefulconss != NULL && nusefulconss > 0);
3525  assert(0 <= considx && considx < nusefulconss);
3526  assert(usefulconss[considx] == cons);
3527  assert(0 <= endidx && endidx <= nusefulconss);
3528  assert(countofoverlapping != NULL);
3529  assert(chgcons != NULL);
3530  assert(undoneaggrvars != NULL);
3531  assert(undoneaggrtypes != NULL);
3532  assert(naggregations != NULL);
3533  assert(saggregations != NULL);
3534  assert(nfixedvars != NULL);
3535  assert(naggrvars != NULL);
3536  assert(nchgcoefs != NULL);
3537  assert(ndelconss != NULL);
3538  assert(cutoff != NULL);
3539 
3540  if( !SCIPconsIsActive(cons) )
3541  return SCIP_OKAY;
3542 
3543  consdata = SCIPconsGetData(cons);
3544  assert(consdata != NULL);
3545 
3546  nvars = consdata->nvars;
3547 
3548  if( nvars == 0 )
3549  return SCIP_OKAY;
3550 
3551  vars = consdata->vars;
3552  assert(vars != NULL);
3553 
3554  oldnfixedzeros = consdata->nfixedzeros;
3555  overlapdestroyed = FALSE;
3556 
3557  /* first check for redundancy for all unprocessed constraints with cons */
3558  for( c = endidx - 1; c >= 0; --c )
3559  {
3560  cons1 = usefulconss[c];
3561 
3562  if( !SCIPconsIsActive(cons1) )
3563  continue;
3564 
3565  /* avoid checking constraint against itself */
3566  if( considx == c )
3567  continue;
3568 
3569  assert(usefulconss[c] != cons);
3570 
3571 #ifndef NDEBUG
3572  oldnaggrvars = *naggrvars;
3573 #endif
3574 
3575  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
3576  * possible
3577  */
3578  SCIP_CALL( presolvePropagateCons(scip, cons1, FALSE, undoneaggrvars, undoneaggrtypes, naggregations, saggregations, nfixedvars, naggrvars, ndelconss, cutoff) );
3579 
3580  if( *cutoff )
3581  return SCIP_OKAY;
3582 
3583  /* we can't handle aggregated variables later on so we should have saved them for later */
3584  assert(*naggrvars == oldnaggrvars);
3585 
3586  if( !SCIPconsIsActive(cons1) )
3587  continue;
3588 
3589  consdata1 = SCIPconsGetData(cons1);
3590  assert(consdata1 != NULL);
3591 
3592  nvars1 = consdata1->nvars;
3593 
3594  if( nvars1 == 0 )
3595  continue;
3596 
3597  /* no more variables from cons as nvars1 can overlap */
3598  assert(countofoverlapping[c] <= nvars1);
3599 
3600  /* constraint should not be redundant or infeasible */
3601  assert(consdata1->nfixedones == 0);
3602 
3603  SCIPdebugMsg(scip, "constraint <%s> overlaps with constraint <%s> by %d variables\n", SCIPconsGetName(cons), SCIPconsGetName(cons1), countofoverlapping[c]);
3604 
3605  /* cons1 includes cons */
3606  if( !overlapdestroyed && countofoverlapping[c] == nvars - consdata->nfixedzeros )
3607  {
3608  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
3609  {
3610  if( nvars - consdata->nfixedzeros < nvars1 )
3611  {
3612 #ifndef NDEBUG
3613  SCIP_Bool negated0;
3614  SCIP_Bool negated1;
3615 #endif
3616 
3617  /* both constraints should stay merged */
3618  assert(consdata->merged);
3619  assert(consdata1->merged);
3620 
3621  vars1 = consdata1->vars;
3622  assert(vars1 != NULL);
3623 
3624  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
3625  SCIPsortDownPtr((void**)vars1, SCIPvarCompActiveAndNegated, nvars1);
3626  /* standard setppc-sorting now lost */
3627  consdata1->sorted = FALSE;
3628 
3629  /* iterate over the both cliques variables the "same" time */
3630  for( v = nvars - 1, v1 = nvars1 - 1; v >= 0 && v1 >= 0; )
3631  {
3632  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3633  {
3634  --v1;
3635  continue;
3636  }
3637  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3638  {
3639  --v;
3640  continue;
3641  }
3642 
3643  /* all variables inside the second clique constraint should be either active or negated of an active one */
3644  assert(SCIPvarIsActive(vars1[v1]) || (SCIPvarGetStatus(vars1[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars1[v1]))));
3645 
3646  /* get not negated variable and clique value in cons */
3647  if( SCIPvarGetStatus(vars[v]) != SCIP_VARSTATUS_NEGATED )
3648  {
3649  var = vars[v];
3650 #ifndef NDEBUG
3651  negated0 = FALSE;
3652 #endif
3653  }
3654  else
3655  {
3656  var = SCIPvarGetNegationVar(vars[v]);
3657 #ifndef NDEBUG
3658  negated0 = TRUE;
3659 #endif
3660  }
3661 
3662  /* get active variable and clique value of next variable */
3663  if( SCIPvarIsActive(vars1[v1]) )
3664  {
3665  var1 = vars1[v1];
3666 #ifndef NDEBUG
3667  negated1 = FALSE;
3668 #endif
3669  }
3670  else
3671  {
3673  var1 = SCIPvarGetNegationVar(vars1[v1]);
3674 #ifndef NDEBUG
3675  negated1 = TRUE;
3676 #endif
3677  }
3678 
3679  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
3680  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
3681  --v;
3682  /* variable index in the constraint is greater than the other one, so fix this variable */
3683  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
3684  {
3685  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(vars1[v1]));
3686 
3687  /* fix all variables except the one which has the negated var in the clique to zero */
3688  SCIP_CALL( SCIPfixVar(scip, vars1[v1], 0.0, cutoff, &fixed) );
3689  if( *cutoff )
3690  {
3691  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3692 
3693  return SCIP_OKAY;
3694  }
3695 
3696  assert(fixed);
3697  ++(*nfixedvars);
3698  --v1;
3699  }
3700  else
3701  {
3702  /* because the constraint's are merged it is not possible that one constraint contains a negated
3703  * variable of another and because all variables in cons are in cons1 this should be really the
3704  * same variable here; so we can decrease v and v1
3705  */
3706  assert(negated0 == negated1);
3707 
3708  --v;
3709  --v1;
3710  }
3711  }
3712  /* maybe we ended because of cons(v reached -1) so try to add rest of cons1 to cons */
3713  for( ; v1 >= 0; --v1)
3714  {
3715  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3716  continue;
3717 
3718  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(vars1[v1]));
3719 
3720  /* fix all variables except the one which has the negated var in the clique to zero */
3721  SCIP_CALL( SCIPfixVar(scip, vars1[v1], 0.0, cutoff, &fixed) );
3722  if( *cutoff )
3723  {
3724  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3725 
3726  return SCIP_OKAY;
3727  }
3728 
3729  assert(fixed);
3730  ++(*nfixedvars);
3731  }
3732  }
3733 
3734  /* if caused by all fixings now this set partitioning constraint doesn't have any variable which was
3735  * fixed to one, it's infeasible */
3736  if( consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nfixedzeros == nvars1 && consdata1->nfixedones != 1 ) /*lint !e641*/
3737  {
3738  SCIPdebugMsg(scip, "all variables in the set-partitioning constraint <%s> are fixed to zero, this leads to a cutoff\n", SCIPconsGetName(cons1));
3739  *cutoff = TRUE;
3740 
3741  return SCIP_OKAY;
3742  }
3743 
3744  assert(SCIPconsIsActive(cons1));
3745  /* delete second constraint */
3746  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> because it includes the setpartitioning constraint <%s> number <%d>\n", SCIPconsGetName(cons1), c, SCIPconsGetName(cons), considx);
3747 
3748  SCIP_CALL( SCIPupdateConsFlags(scip, cons, cons1) );
3749  SCIP_CALL( SCIPdelCons(scip, cons1) );
3750  ++(*ndelconss);
3751  }
3752  /* could already be deleted because the constraint was included in another set partition constraint */
3753  else if( SCIPconsIsActive(cons) )
3754  {
3755  /* delete cons due to redundancy to cons1 */
3756  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> due to inclusion in constraint <%s> number <%d>\n", SCIPconsGetName(cons), considx, SCIPconsGetName(cons1), c);
3757 
3758  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons) );
3759  SCIP_CALL( SCIPdelCons(scip, cons) );
3760  ++(*ndelconss);
3761  }
3762  }
3763  /* cons includes cons1
3764  *
3765  * @note that zero fixations from above can only appear through a set-partitioning constraint, this means if
3766  * cons was the set-partitioning constraint only variables which are not in this constraint could be fixed
3767  * to zero, and this also means that the overlapping variables in this particular case are still active or
3768  * fixed to 1
3769  * later on it could be possible that even variables in cons are fixed to zero, which can lead to wrong
3770  * results when checking if countofoverlapping[c] + consdata1->nfixedzeros == nvars1, because a fixed
3771  * variable could be counted twice
3772  */
3773  else if( (!overlapdestroyed && countofoverlapping[c] + consdata1->nfixedzeros == nvars1) || countofoverlapping[c] == nvars1 )
3774  {
3775  /* even in deleted constraints we may fix unfixed variables */
3776  if( consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
3777  {
3778  const int oldnfixedvars = *nfixedvars;
3779 #ifndef NDEBUG
3780  SCIP_Bool negated0;
3781  SCIP_Bool negated1;
3782 #endif
3783  /* both constraints should stay merged */
3784  assert(consdata->merged);
3785  assert(consdata1->merged);
3786 
3787  vars1 = consdata1->vars;
3788 
3789  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
3790  SCIPsortDownPtr((void**)vars1, SCIPvarCompActiveAndNegated, nvars1);
3791  /* standard setppc-sorting now lost */
3792  consdata1->sorted = FALSE;
3793 
3794  /* iterate over the both cliques variables the "same" time */
3795  for( v = nvars - 1, v1 = nvars1 - 1; v >= 0 && v1 >= 0; )
3796  {
3797  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3798  {
3799  --v1;
3800  continue;
3801  }
3802  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3803  {
3804  --v;
3805  continue;
3806  }
3807 
3808  /* all variables inside the second clique constraint should be either active or negated of an active one */
3809  assert(SCIPvarIsActive(vars1[v1]) || (SCIPvarGetStatus(vars1[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars1[v1]))));
3810  /* all variables inside the first clique constraint should be either active or negated of an active one */
3811  assert(SCIPvarIsActive(vars[v]) || (SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[v]))));
3812 
3813  /* get not negated variable and clique value in cons */
3814  if( SCIPvarIsActive(vars[v]) )
3815  {
3816  var = vars[v];
3817 #ifndef NDEBUG
3818  negated0 = FALSE;
3819 #endif
3820  }
3821  else
3822  {
3824  var = SCIPvarGetNegationVar(vars[v]);
3825 #ifndef NDEBUG
3826  negated0 = TRUE;
3827 #endif
3828  }
3829 
3830  /* get active variable and clique value of next variable */
3831  if( SCIPvarIsActive(vars1[v1]) )
3832  {
3833  var1 = vars1[v1];
3834 #ifndef NDEBUG
3835  negated1 = FALSE;
3836 #endif
3837  }
3838  else
3839  {
3841  var1 = SCIPvarGetNegationVar(vars1[v1]);
3842 #ifndef NDEBUG
3843  negated1 = TRUE;
3844 #endif
3845  }
3846 
3847  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
3848  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
3849  {
3850  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(var));
3851 
3852  /* fix all variables except the one which has the negated var in the clique to zero */
3853  SCIP_CALL( SCIPfixVar(scip, vars[v], 0.0, cutoff, &fixed) );
3854  if( *cutoff )
3855  {
3856  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3857 
3858  return SCIP_OKAY;
3859  }
3860 
3861  assert(fixed);
3862  ++(*nfixedvars);
3863 
3864  --v;
3865  }
3866  /* variable index in the constraint is greater than the other one, so fix this variable */
3867  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
3868  --v1;
3869  else
3870  {
3871  /* because the constraint's are merged it is not possible that one constraint contains a negated
3872  * variable of another and because all variables in cons1 are in cons this should be really the same
3873  * variable here; so we can decrease v and v1
3874  */
3875  assert(negated0 == negated1);
3876 
3877  --v;
3878  --v1;
3879  }
3880  }
3881 
3882  /* maybe we ended because of cons1(v1 reached -1) so try to add rest of cons to cons1 */
3883  for( ; v >= 0; --v)
3884  {
3885  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3886  continue;
3887 
3888  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(vars[v]));
3889 
3890  /* fix all variables except the one which has the negated var in the clique to zero */
3891  SCIP_CALL( SCIPfixVar(scip, vars[v], 0.0, cutoff, &fixed) );
3892  if( *cutoff )
3893  {
3894  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3895 
3896  return SCIP_OKAY;
3897  }
3898 
3899  assert(fixed);
3900  ++(*nfixedvars);
3901  }
3902 
3903  /* if caused by all fixings now this set partitioning constraint doesn't have any variable which was
3904  * fixed to one, it's infeasible */
3905  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata->nfixedzeros == nvars && consdata->nfixedones != 1 ) /*lint !e641*/
3906  {
3907  SCIPdebugMsg(scip, "all variables in the set-partitioning constraint <%s> are fixed to zero, this leads to a cutoff\n", SCIPconsGetName(cons1));
3908  *cutoff = TRUE;
3909 
3910  return SCIP_OKAY;
3911  }
3912 
3913  /* could already be deleted because the constraint was included in another set partition constraint */
3914  if( SCIPconsIsActive(cons) )
3915  {
3916  /* delete cons because it include another set partitioning constraint */
3917  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> because it includes the setpartitioning constraint <%s> number <%d>\n", SCIPconsGetName(cons), considx, SCIPconsGetName(cons1), c);
3918  assert(SCIPconsIsActive(cons));
3919 
3920  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons) );
3921  SCIP_CALL( SCIPdelCons(scip, cons) );
3922  ++(*ndelconss);
3923  }
3924 
3925  /* due to fixings in cons0 mark overlapping invalid for checking with fixedzero variables together */
3926  if( oldnfixedvars < *nfixedvars )
3927  overlapdestroyed = TRUE;
3928  }
3929  else
3930  {
3931  assert(consdata1->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
3932 
3933  /* delete cons1 due to redundancy to cons */
3934  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> due to inclusion in constraint <%s> number <%d>\n", SCIPconsGetName(cons1), c, SCIPconsGetName(cons), considx);
3935  assert(SCIPconsIsActive(cons1));
3936 
3937  SCIP_CALL( SCIPupdateConsFlags(scip, cons, cons1) );
3938  SCIP_CALL( SCIPdelCons(scip, cons1) );
3939  ++(*ndelconss);
3940  }
3941  }
3942  /* if cons has only one unfixed variable which is not in cons1 and cons1 has one variable which does not appear in
3943  * cons and both constraints are setpartitioning constraints we might aggregate both not overlapping variables and
3944  * delete one constraint
3945  */
3946  else if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars - oldnfixedzeros - 1 && countofoverlapping[c] == nvars1 - 1 ) /*lint !e641*/
3947  {
3948  SCIP_VAR* aggvar1;
3949  SCIP_VAR* aggvar2;
3950  SCIP_Bool negated0;
3951  SCIP_Bool negated1;
3952 
3953  aggvar1 = NULL;
3954  aggvar2 = NULL;
3955 
3956  /* both constraints should stay merged */
3957  assert(consdata->merged);
3958  assert(consdata1->merged);
3959 
3960  vars1 = consdata1->vars;
3961 
3962  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
3963  SCIPsortDownPtr((void**)vars1, SCIPvarCompActiveAndNegated, nvars1);
3964  /* standard setppc-sorting now lost */
3965  consdata1->sorted = FALSE;
3966 
3967  /* iterate over the both cliques variables the "same" time */
3968  for( v = nvars - 1, v1 = nvars1 - 1; v >= 0 && v1 >= 0; )
3969  {
3970  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3971  {
3972  --v1;
3973  continue;
3974  }
3975  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3976  {
3977  --v;
3978  continue;
3979  }
3980 
3981  /* all variables inside the second clique constraint should be either active or negated of an active one */
3982  assert(SCIPvarIsActive(vars1[v1]) || (SCIPvarGetStatus(vars1[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars1[v1]))));
3983  /* all variables inside the first clique constraint should be either active or negated of an active one */
3984  assert(SCIPvarIsActive(vars[v]) || (SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[v]))));
3985 
3986  /* get not negated variable and clique value in cons */
3987  if( SCIPvarIsActive(vars[v]) )
3988  {
3989  var = vars[v];
3990  negated0 = FALSE;
3991  }
3992  else
3993  {
3995  var = SCIPvarGetNegationVar(vars[v]);
3996  negated0 = TRUE;
3997  }
3998 
3999  /* get active variable and clique value of next variable */
4000  if( SCIPvarIsActive(vars1[v1]) )
4001  {
4002  var1 = vars1[v1];
4003  negated1 = FALSE;
4004  }
4005  else
4006  {
4008  var1 = SCIPvarGetNegationVar(vars1[v1]);
4009  negated1 = TRUE;
4010  }
4011 
4012  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
4013  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
4014  {
4015  assert(aggvar1 == NULL);
4016  aggvar1 = vars[v];
4017 
4018  if( aggvar2 != NULL )
4019  break;
4020 
4021  --v;
4022  }
4023  /* variable index in the constraint is greater than the other one, so fix this variable */
4024  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
4025  {
4026  assert(aggvar2 == NULL);
4027  aggvar2 = vars1[v1];
4028 
4029  if( aggvar1 != NULL )
4030  break;
4031 
4032  --v1;
4033  }
4034  else
4035  {
4036  /* because the constraint's are merged it is not possible that one constraint contains a negated variable
4037  * of another, but both variables in both constraints still can be negated to each other
4038  */
4039  if( negated0 != negated1 )
4040  {
4041  /* cons is except for one variable equal to cons1 and the unequal variable in cons is negated
4042  * to the one in cons1, so the problem is infeasible
4043  */
4044  SCIPdebugMsg(scip, "two set-partitioning constraint <%s> and <%s> have only one variable not in common, but this variable <%s> appears in one constraint as the negated version as in the other constraint\n", SCIPconsGetName(cons), SCIPconsGetName(cons1), SCIPvarGetName(vars[v]));
4045  *cutoff = TRUE;
4046 
4047  return SCIP_OKAY;
4048  }
4049  --v;
4050  --v1;
4051  }
4052  }
4053 
4054  /* due to fixings, it is possible that there are no active variables left, we we did not recognize which variables we could aggregate */
4055  if( aggvar1 == NULL && aggvar2 == NULL )
4056  continue;
4057 
4058  /* determine second aggregation var, if not yet done */
4059  if( aggvar2 == NULL )
4060  {
4061  for( ; v1 >= 0; --v1)
4062  {
4063  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
4064  continue;
4065 
4066  aggvar2 = vars1[v1];
4067  break;
4068  }
4069  }
4070  /* determine first aggregation var, if not yet done */
4071  else if( aggvar1 == NULL )
4072  {
4073  /* maybe we ended because of cons1(v1 reached -1) so find the aggvar1 in cons */
4074  for( ; v >= 0; --v)
4075  {
4076  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
4077  continue;
4078 
4079  aggvar1 = vars[v];
4080  break;
4081  }
4082  }
4083 
4084  /* due to fixings, it is possible that there are no active variables left, we we did not recognize which variables we could aggregate */
4085  if( aggvar1 == NULL || aggvar2 == NULL )
4086  continue;
4087 
4088  SCIPdebugMsg(scip, "memorize the aggregation of <%s> == <%s>, because they are the last two variable which are different in these two set partitioning constraints <%s> <%s>\n", SCIPvarGetName(aggvar1), SCIPvarGetName(aggvar2), SCIPconsGetName(cons), SCIPconsGetName(cons1));
4089 
4090  /* resize the aggregation arrays if necessary */
4091  if( *saggregations == *naggregations )
4092  {
4093  *saggregations = SCIPcalcMemGrowSize(scip, *naggregations + 1);
4094  assert(*saggregations > *naggregations);
4095  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrtypes, *saggregations) );
4096  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrvars, 2 * (*saggregations)) );
4097 
4098  /* clear the aggregation type array to set the default to the aggregation of the form x + y = 1 */
4099  BMSclearMemoryArray(&(undoneaggrtypes[*naggregations]), *saggregations - *naggregations); /*lint !e866*/
4100  }
4101 
4102  /* memorize aggregation variables*/
4103  undoneaggrtypes[*naggregations] = TRUE;
4104  undoneaggrvars[2 * (*naggregations)] = aggvar1;
4105  undoneaggrvars[2 * (*naggregations) + 1] = aggvar2;
4106  ++(*naggregations);
4107 
4108  if( !SCIPdoNotAggr(scip) )
4109  {
4110  /* delete constraint */
4111  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> because it is dominated by constraint <%s>\n", SCIPconsGetName(cons1), c, SCIPconsGetName(cons));
4112  assert(SCIPconsIsActive(cons1));
4113 
4114  SCIP_CALL( SCIPupdateConsFlags(scip, cons, cons1) );
4115  SCIP_CALL( SCIPdelCons(scip, cons1) );
4116  ++(*ndelconss);
4117  }
4118  }
4119  /* w.l.o.g. cons is a setpartitioning constraint and countofoverlapping == nvars - oldnfixedzeros - 1 we can
4120  * delete all overlapping variables in cons1 and add the negated variable of the not overlapped variable to cons
4121  * 1; the result should be a shorter constraint with the same impact
4122  */
4123  else if( shrinking && !overlapdestroyed && countofoverlapping[c] > 1 && ((consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars - oldnfixedzeros - 1) || (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars1 - 1)) ) /*lint !e641*/
4124  {
4125  SCIP_CONSDATA* consdatachange;
4126  SCIP_VAR** varstostay;
4127  SCIP_VAR** varstochange;
4128  SCIP_CONS* constochange;
4129  SCIP_CONS* constostay;
4130  SCIP_VAR* addvar;
4131  SCIP_Bool negated0;
4132  SCIP_Bool negated1;
4133  int nvarstostay;
4134  int nvarstochange;
4135  int constochangeidx;
4136 #ifndef NDEBUG
4137  const int oldnchgcoefs = *nchgcoefs;
4138 #endif
4139 
4140  addvar = NULL;
4141 
4142  assert((consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING) != (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING) || countofoverlapping[c] != nvars - 1 || countofoverlapping[c] != nvars1 - 1); /*lint !e641*/
4143 
4144  /* both constraints should stay merged */
4145  assert(consdata->merged);
4146  assert(consdata1->merged);
4147 
4148  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
4149  SCIPsortDownPtr((void**)(consdata1->vars), SCIPvarCompActiveAndNegated, nvars1);
4150  /* standard setppc-sorting now lost */
4151  consdata1->sorted = FALSE;
4152 
4153  /* initialize variables */
4154  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars - oldnfixedzeros - 1) /*lint !e641*/
4155  {
4156  varstostay = vars;
4157  varstochange = consdata1->vars;
4158  nvarstostay = nvars;
4159  nvarstochange = nvars1;
4160  constostay = cons;
4161  constochange = cons1;
4162  consdatachange = consdata1;
4163  constochangeidx = c;
4164  }
4165  else
4166  {
4167  varstostay = consdata1->vars;
4168  varstochange = vars;
4169  nvarstostay = nvars1;
4170  nvarstochange = nvars;
4171  constostay = cons1;
4172  constochange = cons;
4173  consdatachange = consdata;
4174  constochangeidx = considx;
4175 
4176  *chgcons = TRUE;
4177  }
4178 
4179  /* iterate over the both cliques variables the "same" time, here we need the backward loop, because we
4180  * delete some variables and we don not want to loose order
4181  */
4182  for( v = nvarstostay - 1, v1 = nvarstochange - 1; v >= 0 && v1 >= 0; )
4183  {
4184  if( SCIPvarGetLbLocal(varstochange[v1]) > 0.5 || SCIPvarGetUbLocal(varstochange[v1]) < 0.5 )
4185  {
4186  --v1;
4187  continue;
4188  }
4189  if( SCIPvarGetLbLocal(varstostay[v]) > 0.5 || SCIPvarGetUbLocal(varstostay[v]) < 0.5 )
4190  {
4191  --v;
4192  continue;
4193  }
4194 
4195  /* all variables inside the second clique constraint should be either active or negated of an active one */
4196  assert(SCIPvarIsActive(varstochange[v1]) || (SCIPvarGetStatus(varstochange[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstochange[v1]))));
4197  /* all variables inside the first clique constraint should be either active or negated of an active one */
4198  assert(SCIPvarIsActive(varstostay[v]) || (SCIPvarGetStatus(varstostay[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstostay[v]))));
4199 
4200  /* get not negated variable and clique value in constostay */
4201  if( SCIPvarIsActive(varstostay[v]) )
4202  {
4203  var = varstostay[v];
4204  negated0 = FALSE;
4205  }
4206  else
4207  {
4208  assert(SCIPvarGetStatus(varstostay[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstostay[v])));
4209  var = SCIPvarGetNegationVar(varstostay[v]);
4210  negated0 = TRUE;
4211  }
4212 
4213  /* get active variable and clique value of in constochange*/
4214  if( SCIPvarIsActive(varstochange[v1]) )
4215  {
4216  var1 = varstochange[v1];
4217  negated1 = FALSE;
4218  }
4219  else
4220  {
4221  assert(SCIPvarGetStatus(varstochange[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstochange[v1])));
4222  var1 = SCIPvarGetNegationVar(varstochange[v1]);
4223  negated1 = TRUE;
4224  }
4225 
4226  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
4227  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
4228  {
4229  assert(addvar == NULL);
4230  addvar = varstostay[v];
4231  --v;
4232  }
4233  /* variable index in the constraint is greater than the other one, so fix this variable */
4234  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
4235  {
4236  --v1;
4237  }
4238  else
4239  {
4240  /* because the constraint's are merged it is not possible that one constraint contains a negated variable
4241  * of another, but both constraint might have a variable in negated form of the other
4242  */
4243  if( negated0 != negated1 )
4244  {
4245  assert(addvar == NULL);
4246 
4247  SCIPdebugMsg(scip, "-> trying to fix <%s> to 0 because it would exist twice in a constraint\n", SCIPvarGetName(varstochange[v1]));
4248 
4249  /* fix variable to zero */
4250  SCIP_CALL( SCIPfixVar(scip, varstochange[v1], 0.0, cutoff, &fixed) );
4251  if( *cutoff )
4252  {
4253  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4254 
4255  return SCIP_OKAY;
4256  }
4257 
4258  assert(fixed);
4259  ++(*nfixedvars);
4260 
4261  /* the above fixing is equal to the fixation of varstostay[v] to 1, so we can call presolvePropagateCons() for consstay */
4262  SCIP_CALL( presolvePropagateCons(scip, constostay, FALSE, NULL, NULL, NULL, NULL, nfixedvars, naggrvars, ndelconss, cutoff) );
4263 
4264  return SCIP_OKAY;
4265  }
4266  else
4267  {
4268  /* correct local data structure, remove variable from constraint entry where it will be removed */
4269  deleteCliqueDataEntry(varstochange[v1], constochangeidx, vartoindex, varnconss, varconsidxs);
4270 
4271  SCIPdebugMsg(scip, " -> deleting variable <%s> in constraint <%s> number %d, because it will be replaced\n", SCIPvarGetName(varstochange[v1]), SCIPconsGetName(constochange), constochangeidx);
4272  /* delete overlapping variables in constochange */
4273  SCIP_CALL( delCoefPos(scip, constochange, v1) );
4274  ++(*nchgcoefs);
4275  }
4276 
4277  --v;
4278  --v1;
4279  }
4280  }
4281  assert(addvar != NULL || v >= 0);
4282  /* we should have removed exactly countofoverlapping[c] variables from the constochange */
4283  assert(*nchgcoefs - oldnchgcoefs == countofoverlapping[c]);
4284 
4285  /* determine addvar if not yet found */
4286  if( addvar == NULL )
4287  {
4288  for( ; v >= 0; --v)
4289  {
4290  if( SCIPvarGetLbLocal(varstostay[v]) > 0.5 || SCIPvarGetUbLocal(varstostay[v]) < 0.5 )
4291  continue;
4292 
4293  /* all variables inside the first clique constraint should be either active or negated of an active one */
4294  assert(SCIPvarIsActive(varstostay[v]) || (SCIPvarGetStatus(varstostay[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstostay[v]))));
4295 
4296  addvar = varstostay[v];
4297  break;
4298  }
4299  }
4300  assert(addvar != NULL);
4301 
4302  /* get representative variable for all deleted variables */
4303  SCIP_CALL( SCIPgetNegatedVar(scip, addvar, &addvar) );
4304  assert(addvar != NULL);
4305 
4306  SCIPdebugMsg(scip, " -> adding variable <%s> to constraint <%s> number %d\n", SCIPvarGetName(addvar), SCIPconsGetName(constochange), constochangeidx);
4307  /* add representative for overlapping instead */
4308  SCIP_CALL( addCoef(scip, constochange, addvar) );
4309  ++(*nchgcoefs);
4310 
4311  /* constraint should be still merged because this added variable is new in this constraint */
4312  consdatachange->merged = TRUE;
4313  assert(constochangeidx == (cons == constochange ? considx : c));
4314 
4315  /* correct local data structure, add constraint entry to variable data */
4316  SCIP_CALL( addCliqueDataEntry(scip, addvar, constochangeidx, TRUE, usefulvars, nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs) );
4317 
4318  /* cons changed so much, that it cannot be used for more overlapping checks */
4319  if( *chgcons )
4320  return SCIP_OKAY;
4321  }
4322  }
4323 
4324  return SCIP_OKAY;
4325 }
4326 
4327 /** try to lift variables to given constraint */
4328 /** @todo try another variant by determine lifting variables as the intersection of all cliques variables of the
4329  * constraint variables, note that the intersection changes after one variable was added
4330  */
4331 static
4333  SCIP*const scip, /**< SCIP data structure */
4334  SCIP_CONS*const cons, /**< constraint which may overlap */
4335  int const arraypos, /**< position of constraint in global array */
4336  SCIP_VAR**const usefulvars, /**< possible variables to lift */
4337  int*const nusefulvars, /**< pointer to store number of added variables */
4338  int const endidx, /**< end index for possible lifting variables */
4339  SCIP_Bool** cliquevalues, /**< pointer to clique values of constraint-variables, either one if the
4340  * variable is active or zero if the variable is negated
4341  * @note this array can be resized in this method
4342  */
4343  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
4344  int*const varnconss, /**< array with number of constraints a variable occurs */
4345  int*const maxnvarconsidx, /**< array with the maximal number of occurrences of a variable */
4346  int**const varconsidxs, /**< array with constraint indices in which the corresponding variable
4347  * exists
4348  */
4349  int*const maxnvars, /**< pointer to store maximal number of variables of a constraint */
4350  int*const nadded, /**< pointer to store number of possible added variables */
4351  SCIP_Bool*const chgcons, /**< pointer to store if the constraint was changed, due to added
4352  * variables
4353  */
4354  int*const nfixedvars, /**< pointer to count number of deleted variables */
4355  int*const ndelconss, /**< pointer to count number of deleted constraints */
4356  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
4357  )
4358 {
4359  SCIP_CONSDATA* consdata;
4360  SCIP_VAR** vars;
4361  SCIP_VAR* var;
4362  SCIP_VAR* var1;
4363  SCIP_Bool fixed;
4364  SCIP_Bool value;
4365  int nvars;
4366  int nottocheck; /* will be the position for a variable in cons0 which is in negated form in the same clique */
4367  int v;
4368  int v1;
4369  int k;
4370 
4371  assert(scip != NULL);
4372  assert(cons != NULL);
4373  assert(usefulvars != NULL);
4374  assert(cliquevalues != NULL);
4375  assert(*cliquevalues != NULL);
4376  assert(vartoindex != NULL);
4377  assert(varnconss != NULL);
4378  assert(maxnvarconsidx != NULL);
4379  assert(varconsidxs != NULL);
4380  assert(maxnvars != NULL);
4381  assert(nadded != NULL);
4382  assert(chgcons != NULL);
4383  assert(nfixedvars != NULL);
4384  assert(ndelconss != NULL);
4385  assert(cutoff != NULL);
4386 
4387  if( !SCIPconsIsActive(cons) )
4388  return SCIP_OKAY;
4389 
4390  consdata = SCIPconsGetData(cons);
4391  assert(consdata != NULL);
4392 
4393  nvars = consdata->nvars;
4394 
4395  if( nvars == 0 )
4396  return SCIP_OKAY;
4397 
4398  assert(nvars <= *maxnvars);
4399 
4400  vars = consdata->vars;
4401  assert(vars != NULL);
4402 
4403  v1 = endidx;
4404 
4405  /* now we try to add variables with index prior to endidx to cons */
4406  for( v = nvars - 1; v >= 0 && v1 >= 0; )
4407  {
4408  if( SCIPvarGetLbLocal(usefulvars[v1]) > 0.5 || SCIPvarGetUbLocal(usefulvars[v1]) < 0.5 )
4409  {
4410  --v1;
4411  continue;
4412  }
4413  if( SCIPvarGetUbLocal(vars[v]) < 0.5 )
4414  {
4415  --v;
4416  continue;
4417  }
4418 
4419  /* check that constraint variables are still correctly sorted, indices of active variables should be decreasing */
4420  assert(v == 0 || SCIPvarCompareActiveAndNegated(vars[v], vars[v - 1]) <= 0);
4421 
4422  /* there should no variables fixed to one occur in our constraint */
4423  assert(SCIPvarGetLbLocal(vars[v]) < 0.5 && SCIPvarGetUbLocal(vars[v]) > 0.5);
4424  assert(SCIPvarGetLbLocal(usefulvars[v1]) < 0.5 && SCIPvarGetUbLocal(usefulvars[v1]) > 0.5);
4425 
4426  /* all variables which we have inside the clique constraint and which can possibly be added should be either active or negated */
4427  assert(SCIPvarIsActive(vars[v]) || (SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[v]))));
4428  assert(SCIPvarIsActive(usefulvars[v1]) || (SCIPvarGetStatus(usefulvars[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(usefulvars[v1]))));
4429 
4430  /* constraint should during adding of variables stay merged, because for each variable which is added holds that
4431  * the index of this corresponding active variable is pairwise different to all indices of all active
4432  * corresponding variables inside the constraint
4433  * @note it should not happen that we add one variable and the corresponding counterpart to the same constraint */
4434  assert(consdata->merged);
4435 
4436  /* get active variable and clique value in cons */
4437  if( (*cliquevalues)[v] )
4438  var = vars[v];
4439  else
4440  {
4442  var = SCIPvarGetNegationVar(vars[v]);
4443  }
4444 
4445  /* get active variable and clique value of next variable */
4446  if( SCIPvarIsActive(usefulvars[v1]) )
4447  {
4448  var1 = usefulvars[v1];
4449  value = TRUE;
4450  }
4451  else
4452  {
4453  assert(SCIPvarGetStatus(usefulvars[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(usefulvars[v1])));
4454  var1 = SCIPvarGetNegationVar(usefulvars[v1]);
4455  value = FALSE;
4456  }
4457 
4458  nottocheck = -1;
4459  k = 0;
4460 
4461  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
4462  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
4463  {
4464  --v;
4465  continue;
4466  }
4467  /* variable index in the constraint is greater than the other one, so check for possible inclusion of the variable */
4468  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
4469  {
4470  assert(consdata == SCIPconsGetData(cons));
4471 
4472  /* check if every variable in the actual clique is in clique with the new variable */
4473  for( k = nvars - 1; k >= 0; --k )
4474  {
4475  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4476  {
4477  /* there should no variables fixed to one occur in our constraint */
4478  assert(SCIPvarGetLbLocal(vars[k]) < 0.5);
4479  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4480 
4481  if( (*cliquevalues)[k] )
4482  {
4483  assert(SCIPvarIsActive(vars[k]));
4484  var = vars[k];
4485  }
4486  else
4487  {
4489  var = SCIPvarGetNegationVar(vars[k]);
4490  }
4491  if( !SCIPhaveVarsCommonClique(scip, var1, value, var, (*cliquevalues)[k], TRUE) )
4492  break;
4493  }
4494  }
4495  --v1;
4496  }
4497  /* variable index in the constraint is equal to the index of the other variable, check if these variables are
4498  * negated of each other so memorize the position and check for possible inclusion of the new variable and if
4499  * possible decrease indices
4500  */
4501  else
4502  {
4503  /* one clique contains the negated and the other clique the corresponding active var */
4504  if( value != (*cliquevalues)[v] )
4505  {
4506  nottocheck = v;
4507 
4508  assert(consdata == SCIPconsGetData(cons));
4509  assert(nvars <= consdata->nvars);
4510 
4511  /* check if every variable in the actual clique is in clique with the new variable */
4512  for( k = nvars - 1; k >= 0; --k )
4513  {
4514  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4515  {
4516  /* there should no variables fixed to one occur in our constraint */
4517  assert(SCIPvarGetLbLocal(vars[k]) < 0.5);
4518 
4519  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4520 
4521  if( k == nottocheck )
4522  continue;
4523 
4524  if( (*cliquevalues)[k] )
4525  {
4526  assert(SCIPvarIsActive(vars[k]));
4527  var = vars[k];
4528  }
4529  else
4530  {
4532  var = SCIPvarGetNegationVar(vars[k]);
4533  }
4534 
4535  if( !SCIPhaveVarsCommonClique(scip, var1, value, var, (*cliquevalues)[k], TRUE) )
4536  break;
4537  }
4538  }
4539  }
4540  /* don't decrease v because it might happen that the corresponding negated variable of var is next in
4541  * usefulvars
4542  */
4543  --v1;
4544  }
4545 
4546  /* if k is smaller than 0 than the possible new variables is in the same clique with all variables of cons,
4547  * so we add the new variable to clique constraint or fix some variables */
4548  if( k < 0 )
4549  {
4550  ++(*nadded);
4551 
4552  /* we found a variable which is the negated variable of another one in this clique so we can fix all
4553  * other variable to zero and if it's a partitioning constraint we can also fix the variable of the
4554  * negated to one and we can delete the constraint too */
4555  if( nottocheck >= 0 )
4556  {
4557  assert(consdata == SCIPconsGetData(cons));
4558  assert(nvars <= consdata->nvars);
4559  assert(consdata->merged);
4560 
4561  /* process all vars for possible fixing */
4562  for( k = consdata->nvars - 1; k >= 0; --k )
4563  {
4564  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4565  {
4566  /* there should no variables fixed to one occur in our constraint */
4567  assert(SCIPvarGetLbLocal(vars[v]) < 0.5);
4568 
4569  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4570 
4571  if( k != nottocheck )
4572  {
4573  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because we could lift a negated variable of another constraint variable\n", SCIPvarGetName(vars[k]));
4574  /* fix variable to zero */
4575  SCIP_CALL( SCIPfixVar(scip, vars[k], 0.0, cutoff, &fixed) );
4576 
4577  if( *cutoff )
4578  {
4579  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4580 
4581  return SCIP_OKAY;
4582  }
4583 
4584  assert(fixed);
4585 
4586  ++(*nfixedvars);
4587  }
4588  }
4589  }
4590  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
4591  {
4592  assert(SCIPvarIsActive(vars[nottocheck]) || (SCIPvarGetStatus(vars[nottocheck]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[nottocheck]))));
4593 
4594  SCIPdebugMsg(scip, "trying to fix <%s> to 1 due to this setpartitioning variable is with its negated in the same clique\n", SCIPvarGetName(vars[nottocheck]));
4595  /* fix the remaining variable to one, due to it's the only one left to satisfy the constraint */
4596  SCIP_CALL( SCIPfixVar(scip, vars[nottocheck], 1.0, cutoff, &fixed) );
4597  if( *cutoff )
4598  {
4599  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4600 
4601  return SCIP_OKAY;
4602  }
4603 
4604  assert(fixed);
4605  ++(*nfixedvars);
4606  }
4607 
4608  /* delete constraint */
4609  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> due to active and negated variable in the same clique constraint\n", SCIPconsGetName(cons), arraypos);
4610  assert(SCIPconsIsActive(cons));
4611  SCIP_CALL( SCIPdelCons(scip, cons) );
4612  ++(*ndelconss);
4613 
4614  break;
4615  }
4616  /* we found a variable which could be added to a partitioning constraint so we can fix it to zero */
4617  else if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
4618  {
4619  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because this variable is in the same clique with a set partition\n", SCIPvarGetName(usefulvars[v1 + 1]));
4620  /* fix variable to zero */
4621  SCIP_CALL( SCIPfixVar(scip, usefulvars[v1 + 1], 0.0, cutoff, &fixed) );
4622 
4623  if( *cutoff )
4624  {
4625  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4626 
4627  return SCIP_OKAY;
4628  }
4629 
4630  assert(fixed);
4631 
4632  ++(*nfixedvars);
4633  }
4634  /* we have found a new variable for a set packing constraint cons, so add the found variable to the first constraint */
4635  else
4636  {
4637  SCIP_VAR* addvar;
4638 
4639  assert(SCIPconsIsActive(cons));
4640 
4641  addvar = usefulvars[v1 + 1];
4642 
4643  assert(SCIPvarGetLbLocal(addvar) < 0.5 && SCIPvarGetUbLocal(addvar) > 0.5);
4644 
4645  /* add representative instead */
4646  SCIPdebugMsg(scip, " -> adding variable <%s> to constraint <%s> number %d\n", SCIPvarGetName(usefulvars[v1 + 1]), SCIPconsGetName(cons), arraypos);
4647  SCIP_CALL( addCoef(scip, cons, addvar) );
4648  assert(consdata == SCIPconsGetData(cons));
4649  /* we know that this constraint stays merged but later on we have to resort */
4650  consdata->merged = TRUE;
4651 
4652  /* second we add the constraint index to the list of indices where this variable occurs */
4653  assert(SCIPhashmapExists(vartoindex, (void*) addvar));
4654 
4655  /* correct local data structure, add constraint entry to variable data */
4656  SCIP_CALL( addCliqueDataEntry(scip, addvar, arraypos, FALSE, usefulvars, nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs) );
4657 
4658  /* we need the new pointer to the variables, because due to adding variables it is possible that we
4659  * did reallocate the variables array inside the constraint, the index v should stay the same because the
4660  * added variable was inserted at the end and we are decreasing v in our for loop
4661  */
4662  vars = consdata->vars;
4663  nvars = consdata->nvars;
4664 
4665  /* we need to update our data structure */
4666 
4667  /* resize clique array if necessary, due to adding variables */
4668  if( (*maxnvars) < nvars )
4669  {
4670  while( (*maxnvars) < nvars )
4671  (*maxnvars) *= 2 ;
4672  SCIP_CALL( SCIPreallocBufferArray(scip, cliquevalues, (*maxnvars)) );
4673  }
4674  (*cliquevalues)[nvars - 1] = SCIPvarIsActive(addvar) ? TRUE : FALSE;
4675 
4676  (*chgcons) = TRUE;
4677  }
4678  }
4679  }
4680 
4681  if( !SCIPconsIsActive(cons) )
4682  return SCIP_OKAY;
4683 
4684  /* maybe we stopped because of cons(v reached -1) so try to add rest in usefulvars */
4685  for( ; v1 >= 0; --v1)
4686  {
4687  if( SCIPvarGetLbLocal(usefulvars[v1]) > 0.5 || SCIPvarGetUbLocal(usefulvars[v1]) < 0.5 )
4688  continue;
4689 
4690  /* get active variable and clique value */
4691  if( SCIPvarIsActive(usefulvars[v1]) )
4692  {
4693  var1 = usefulvars[v1];
4694  value = TRUE;
4695  }
4696  else
4697  {
4698  assert(SCIPvarGetStatus(usefulvars[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(usefulvars[v1])));
4699  var1 = SCIPvarGetNegationVar(usefulvars[v1]);
4700  value = FALSE;
4701  }
4702 
4703  assert(consdata == SCIPconsGetData(cons));
4704  assert(nvars <= consdata->nvars);
4705 
4706  /* check if every variable in the actual clique is in clique with the new variable */
4707  for( k = nvars - 1; k >= 0; --k )
4708  {
4709  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4710  {
4711  /* there should no variables fixed to one occur in our constraint */
4712  assert(SCIPvarGetLbLocal(vars[k]) < 0.5);
4713 
4714  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4715 
4716  if( (*cliquevalues)[k] )
4717  {
4718  assert(SCIPvarIsActive(vars[k]));
4719  var = vars[k];
4720  }
4721  else
4722  {
4724  var = SCIPvarGetNegationVar(vars[k]);
4725  }
4726 
4727  if( !SCIPvarsHaveCommonClique(var1, value, var, (*cliquevalues)[k], TRUE) )
4728  break;
4729  }
4730  }
4731 
4732  /* add new variable to clique constraint or fix some variables */
4733  if( k < 0 )
4734  {
4735  /* we found a variable which could be added to a partitioning constraint so we can fix it to zero */
4736  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
4737  {
4738  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because this variable is in the same clique with a set partition\n", SCIPvarGetName(usefulvars[v1]));
4739 
4740  /* fix variable to zero */
4741  SCIP_CALL( SCIPfixVar(scip, usefulvars[v1], 0.0, cutoff, &fixed) );
4742  if( *cutoff )
4743  {
4744  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4745 
4746  return SCIP_OKAY;
4747  }
4748  assert(fixed);
4749 
4750  ++(*nfixedvars);
4751  ++(*nadded);
4752  }
4753  /* add the found variable to the first constraint */
4754  else
4755  {
4756  SCIP_VAR* addvar;
4757 
4758  assert(SCIPconsIsActive(cons));
4759 
4760  addvar = usefulvars[v1];
4761 
4762  assert(SCIPvarGetLbLocal(addvar) < 0.5 && SCIPvarGetUbLocal(addvar) > 0.5);
4763 
4764  /* add representative instead */
4765  SCIPdebugMsg(scip, " -> adding variable <%s> to constraint <%s> number %d\n", SCIPvarGetName(addvar), SCIPconsGetName(cons), arraypos);
4766  SCIP_CALL( addCoef(scip, cons, addvar) );
4767  assert(consdata == SCIPconsGetData(cons));
4768  /* we know that this constraint stays merged but later on we have to resort */
4769  consdata->merged = TRUE;
4770 
4771  /* second we add the constraint index to the list of indices where this variable occurs */
4772  assert(SCIPhashmapExists(vartoindex, (void*) addvar));
4773 
4774  /* correct local data structure, add constraint entry to variable data */
4775  SCIP_CALL( addCliqueDataEntry(scip, addvar, arraypos, FALSE, usefulvars, nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs) );
4776 
4777  /* we need the new pointer to the variables, because due to adding variables it is possible that we
4778  * did reallocate the variables array inside the constraint, the index v should stay the same because the
4779  * added variable was inserted at the end and we are decreasing v in our for loop
4780  */
4781  vars = consdata->vars;
4782  nvars = consdata->nvars;
4783 
4784  /* we need to update our data structure */
4785 
4786  /* resize clique array if necessary, due to adding variables */
4787  if( (*maxnvars) < nvars )
4788  {
4789  while( (*maxnvars) < nvars )
4790  (*maxnvars) *= 2 ;
4791  SCIP_CALL( SCIPreallocBufferArray(scip, cliquevalues, (*maxnvars)) );
4792  }
4793  (*cliquevalues)[nvars - 1] = SCIPvarIsActive(addvar) ? TRUE : FALSE;
4794 
4795  ++(*nadded);
4796  (*chgcons) = TRUE;
4797  }
4798  }
4799  }
4800 
4801  return SCIP_OKAY;
4802 }
4803 
4804 /** perform all collected aggregations */
4805 static
4807  SCIP*const scip, /**< SCIP data structure */
4808  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
4809  SCIP_VAR**const undoneaggrvars, /**< aggregation variables storage */
4810  SCIP_Bool*const undoneaggrtypes, /**< aggregation type storage, type FALSE means the aggregation is of the
4811  * form x + y = 1; type TRUE means the aggregation is of the form x = y;
4812  */
4813  int const naggregations, /**< number of aggregations to performed */
4814  int*const naggrvars, /**< pointer to count number of aggregated variables */
4815  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
4816  )
4817 { /*lint --e{715}*/
4818  SCIP_VAR* var1;
4819  SCIP_VAR* var2;
4820  SCIP_Bool aggregated;
4821  SCIP_Bool redundant;
4822  int a;
4823 
4824  assert(scip != NULL);
4825  assert(conshdlrdata != NULL);
4826  assert(undoneaggrvars != NULL);
4827  assert(undoneaggrtypes != NULL);
4828  assert(naggregations > 0);
4829  assert(naggrvars != NULL);
4830  assert(cutoff != NULL);
4831 
4832  /* loop over all open aggregations and try to aggregate them */
4833  for( a = 0; a < naggregations; ++a )
4834  {
4835  var1 = undoneaggrvars[2 * a];
4836  var2 = undoneaggrvars[2 * a + 1];
4837  assert(var1 != NULL);
4838  assert(var2 != NULL);
4839 
4840  SCIPdebugMsg(scip, "trying to aggregate <%s> %s <%s>%s\n", SCIPvarGetName(var1), undoneaggrtypes[a] ? "=" : "+", SCIPvarGetName(var2), undoneaggrtypes[a] ? "" : " = 1");
4841 
4842 #ifdef VARUSES
4843  /* in order to not mess up the variable usage counting, we have to decrease usage counting, aggregate,
4844  * and increase usage counting again
4845  */
4846  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, var1) );
4847  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, var2) );
4848 #endif
4849 
4850  /* aggregate last remaining variables in the set partitioning constraint */
4851  if( undoneaggrtypes[a] )
4852  {
4853  SCIP_CALL( SCIPaggregateVars(scip, var1, var2, 1.0, -1.0, 0.0, cutoff, &redundant, &aggregated) );
4854  }
4855  else
4856  {
4857  SCIP_CALL( SCIPaggregateVars(scip, var1, var2, 1.0, 1.0, 1.0, cutoff, &redundant, &aggregated) );
4858  }
4859 
4860  if( *cutoff )
4861  {
4862  SCIPdebugMsg(scip, "aggregation was infeasible\n");
4863 
4864  return SCIP_OKAY;
4865  }
4866  /* binary variables should always be aggregated, or due to fixation the aggregation is redundant */
4867  assert(redundant);
4868 
4869  if( aggregated )
4870  ++(*naggrvars);
4871 
4872 #ifdef VARUSES
4873  /* increase variable usage counting again */
4874  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var1) );
4875  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var2) );
4876 #endif
4877  }
4878 
4879  return SCIP_OKAY;
4880 }
4881 
4882 /** check whether we can combine or grow cliques so some constraints become redundant or we can fix variables */
4883 /** @todo try another variant, by building up the clique graph and delete unnecessary (transitive closure) edges and do
4884  * a bfs search to search for common ancestors to get all possible lifting variables
4885  */
4886 static
4888  SCIP*const scip, /**< SCIP data structure */
4889  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
4890  SCIP_CONS**const conss, /**< constraint set */
4891  int const nconss, /**< number of constraints in constraint set */
4892  int const nrounds, /**< actual presolving round */
4893  int*const firstchange, /**< pointer to store first changed constraint */
4894  int*const firstclique, /**< pointer to store first constraint to start adding clique again */
4895  int*const lastclique, /**< pointer to store last constraint to add cliques again */
4896  int*const nfixedvars, /**< pointer to count number of deleted variables */
4897  int*const naggrvars, /**< pointer to count number of aggregated variables */
4898  int*const ndelconss, /**< pointer to count number of deleted constraints */
4899  int*const nchgcoefs, /**< pointer to count number of deleted coefficients */
4900  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
4901  )
4902 {
4903  /* extend cliques/constraints by checking whether some variables are in the same clique, no pairwise clique lifting
4904  * which would be slower
4905  */
4906  SCIP_CONS** usefulconss; /* array with pointers of constraint of setpartitioning and setpacking type */
4907  SCIP_VAR** usefulvars; /* array with pointers of variables in setpartitioning and setpacking constraints */
4908  int** varconsidxs; /* array consisting of constraint indices in which the corresponding variable exists */
4909  int* varnconss; /* array consisting of number of constraints the variable occurs */
4910  int* maxnvarconsidx; /* maximal number of occurrences of a variable */
4911  int* countofoverlapping = NULL; /* the amount of variables which are in another constraint */
4912  SCIP_Bool* cliquevalues = NULL; /* values of clique-variables, either one if the variable is active or zero if the variable is negated */
4913 
4914  SCIP_HASHMAP* vartoindex; /* mapping of SCIP variables to indices */
4915  SCIP_CONSDATA* consdata;
4916 
4917  SCIP_Bool chgcons0;
4918  int nvars;
4919  int c;
4920  int v;
4921  int nusefulconss;
4922  int nusefulvars;
4923  int susefulvars;
4924  int maxnvars;
4925  int varindex;
4926 
4927  SCIP_VAR** undoneaggrvars; /* storage for not yet performed aggregations */
4928  SCIP_Bool* undoneaggrtypes; /* storage for not yet performed aggregation type (x = y or x + y = 1) */
4929  int saggregations;
4930  int naggregations;
4931 
4932  assert(scip != NULL);
4933  assert(conshdlrdata != NULL);
4934  assert(conss != NULL || nconss == 0);
4935  assert(firstchange != NULL);
4936  assert(firstclique != NULL);
4937  assert(lastclique != NULL);
4938  assert(nfixedvars != NULL);
4939  assert(naggrvars != NULL);
4940  assert(ndelconss != NULL);
4941  assert(nchgcoefs != NULL);
4942  assert(cutoff != NULL);
4943 
4944  *cutoff = FALSE;
4945 
4946  if( nconss == 0 )
4947  return SCIP_OKAY;
4948 
4949  nvars = SCIPgetNVars(scip);
4950 
4951  if( nvars == 0 )
4952  return SCIP_OKAY;
4953 
4954  susefulvars = 2 * nvars; /* two times because of negated vars, maybe due to deleted variables we need to increase this */
4955 
4956  /* a hashmap from varindex to postion in varconsidxs array, because above is still too small */
4957  SCIP_CALL( SCIPhashmapCreate(&vartoindex, SCIPblkmem(scip), nvars) );
4958 
4959  /* get temporary memory for the aggregation storage, to memorize aggregations which will be performed later, otherwise we would destroy our local data structures */
4960  saggregations = nvars;
4961  SCIP_CALL( SCIPallocBufferArray(scip, &undoneaggrvars, 2 * saggregations) );
4962  SCIP_CALL( SCIPallocBufferArray(scip, &undoneaggrtypes, saggregations) );
4963  BMSclearMemoryArray(undoneaggrtypes, saggregations);
4964  naggregations = 0;
4965 
4966  /* get temporary memory for all clique constraints, all appearing variables and the mapping from variables to constraints */
4967  SCIP_CALL( SCIPallocBufferArray(scip, &usefulconss, nconss) );
4968  SCIP_CALL( SCIPallocBufferArray(scip, &usefulvars, susefulvars) );
4969  BMSclearMemoryArray(usefulvars, susefulvars);
4970  SCIP_CALL( SCIPallocBufferArray(scip, &varnconss, susefulvars + 1) );
4971  BMSclearMemoryArray(varnconss, susefulvars + 1);
4972  SCIP_CALL( SCIPallocBufferArray(scip, &maxnvarconsidx, susefulvars + 1) );
4973  SCIP_CALL( SCIPallocBufferArray(scip, &varconsidxs, susefulvars + 1) );
4974  BMSclearMemoryArray(varconsidxs, susefulvars + 1);
4975  nusefulvars = 0;
4976  nusefulconss = 0;
4977  maxnvars = 0;
4978 
4979  /* @todo: check for round limit for adding extra clique constraints */
4980  /* adding clique constraints which arises from global clique information */
4981  if( conshdlrdata->nclqpresolve == 0 && conshdlrdata->addvariablesascliques )
4982  {
4983  SCIP_VAR** vars = SCIPgetVars(scip);
4984  SCIP_VAR** binvars;
4985  int* cliquepartition;
4986  int ncliques;
4987  int nbinvars;
4988  int naddconss;
4989 
4990  nbinvars = SCIPgetNBinVars(scip);
4991  SCIP_CALL( SCIPduplicateBufferArray(scip, &binvars, vars, nbinvars) );
4992  SCIP_CALL( SCIPallocBufferArray(scip, &cliquepartition, nbinvars) );
4993 
4994  /* @todo: check for better permutations/don't permute the first round
4995  * @todo: take binary variables which are not of vartype SCIP_VARTYPE_BINARY into account
4996  */
4997  SCIPrandomPermuteArray(conshdlrdata->randnumgen, (void**)binvars, 0, nbinvars);
4998 
4999  /* try to create a clique-partition over all binary variables and create these cliques as new setppc constraints
5000  * and add them to the usefulconss array and adjust all necessary data this will hopefully lead to faster
5001  * detection of redundant constraints
5002  */
5003  SCIP_CALL( SCIPcalcCliquePartition(scip, binvars, nbinvars, cliquepartition, &ncliques) );
5004 
5005  /* resize usefulconss array if necessary */
5006  SCIP_CALL( SCIPreallocBufferArray(scip, &usefulconss, nconss + ncliques) );
5007 
5008  naddconss = 0;
5009 
5010  /* add extra clique constraints resulting from the cliquepartition calculation to SCIP and to the local data structure */
5011  SCIP_CALL( addExtraCliques(scip, binvars, nbinvars, cliquepartition, ncliques, usefulconss, &nusefulconss,
5012  nrounds, nfixedvars, &naddconss, ndelconss, nchgcoefs, cutoff) );
5013 
5014  /* bad hack, we don't want to count these artificial created constraints if they got deleted, so ndelconss
5015  * can become negative which will be change to zero at the end of this method if it's still negative
5016  */
5017  *ndelconss -= naddconss;
5018 
5019  SCIPfreeBufferArray(scip, &cliquepartition);
5020  SCIPfreeBufferArray(scip, &binvars);
5021 
5022  if( *cutoff )
5023  goto TERMINATE;
5024  }
5025 
5026  /* start to collect setpartitioning and setpacking constraints, and try to remove fixed variables and merged these
5027  * constraints
5028  */
5029  SCIP_CALL( collectCliqueConss(scip, conss, nconss, usefulconss, &nusefulconss, nfixedvars, ndelconss, nchgcoefs, cutoff) );
5030  /* @Note: Even after the call above some constraints can have fixed variables, because it might happen that caused by
5031  * mergeMultiplies some variables were fixed which occurred already in previous constraints
5032  */
5033  if( *cutoff )
5034  goto TERMINATE;
5035 
5036  /* no usefulconss found */
5037  if( nusefulconss <= 1 )
5038  goto TERMINATE;
5039 
5040  /* @todo: maybe sort them after biggest indices too, or another variant would be to restore the order as they were
5041  * read in
5042  */
5043  /* sort constraints first after type (partitioning before packing) and second after number of variables such that the
5044  * partitioning constraints have increasing number of variables and the packing constraints have decreasing number of
5045  * variables, because we loop from back to front we sort them downwards, so they are the other way around
5046  */
5047  SCIPsortDownPtr((void**)usefulconss, setppcConssSort, nusefulconss);
5048 
5049  /* creating all necessary data in array structure, collect all clique constraint variables and occurrences */
5050  SCIP_CALL( collectCliqueData(scip, usefulconss, nusefulconss, usefulvars, &nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs, &maxnvars) );
5051  assert(maxnvars > 0);
5052 
5053  /* allocate temporary memory for actual clique */
5054  SCIP_CALL( SCIPallocBufferArray(scip, &cliquevalues, maxnvars) );
5055  /* allocate temporary memory for counting an overlap of variables */
5056  SCIP_CALL( SCIPallocBufferArray(scip, &countofoverlapping, nusefulconss) );
5057 
5058  /* sort usefulvars after indices of variables, negated and active counterparts will stand side by side */
5059  SCIPsortDownPtr((void**)usefulvars, SCIPvarCompActiveAndNegated, nusefulvars);
5060 
5061  /* extend cliques/constraints by checking whether some variables of a second constraint are in the same clique */
5062  for( c = nusefulconss - 1; c >= 0 && !SCIPisStopped(scip); --c )
5063  {
5064  SCIP_VAR** cons0vars; /* these are the clique variables */
5065  SCIP_CONS* cons0;
5066  int ncons0vars;
5067  SCIP_VAR* var0;
5068  int v1;
5069  int nadded; /* number of possible added variables to constraint */
5070  int cons0fixedzeros;
5071  int oldnchgcoefs;
5072 #ifndef NDEBUG
5073  const int oldnaggrvars = *naggrvars;
5074 #endif
5075  cons0 = usefulconss[c];
5076 
5077  if( !SCIPconsIsActive(cons0) )
5078  continue;
5079 
5080  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
5081  * possible
5082  */
5083  SCIP_CALL( presolvePropagateCons(scip, cons0, FALSE, undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations, nfixedvars, naggrvars, ndelconss, cutoff) );
5084 
5085  if( *cutoff )
5086  break;
5087 
5088  /* we can't handle aggregated variables later on so we should have saved them for later */
5089  assert(*naggrvars == oldnaggrvars);
5090 
5091  if( !SCIPconsIsActive(cons0) )
5092  continue;
5093 
5094  /* we need to determine the cliquedata in each iteration because we eventual will change it later */
5095  consdata = SCIPconsGetData(cons0);
5096  assert(consdata != NULL);
5097 
5098  cons0vars = consdata->vars;
5099  ncons0vars = consdata->nvars;
5100 
5101  /* sorting array after indices of variables, negated and active counterparts will stand side by side */
5102  SCIPsortDownPtr((void**)cons0vars, SCIPvarCompActiveAndNegated, ncons0vars);
5103  /* standard setppc-sorting now lost */
5104  consdata->sorted = FALSE;
5105 
5106  /* clique array should be long enough */
5107  assert(maxnvars >= ncons0vars);
5108 
5109  /* clear old entries in overlapping constraint */
5110  BMSclearMemoryArray(countofoverlapping, nusefulconss);
5111 
5112  /* calculate overlapping */
5113  for( v = ncons0vars - 1; v >= 0 ; --v )
5114  {
5115  var0 = cons0vars[v];
5116 
5117  /* fixed variables later to the count */
5118  if( SCIPvarGetLbLocal(var0) > 0.5 || SCIPvarGetUbLocal(var0) < 0.5 )
5119  continue;
5120 
5121  assert(SCIPhashmapExists(vartoindex, (void*) var0));
5122 
5123  varindex = SCIPhashmapGetImageInt(vartoindex, (void*) var0);
5124  for( v1 = varnconss[varindex] - 1; v1 >= 0 ; --v1 )
5125  ++(countofoverlapping[varconsidxs[varindex][v1]]);
5126  }
5127 
5128  oldnchgcoefs = *nchgcoefs;
5129  cons0fixedzeros = consdata->nfixedzeros;
5130 
5131  chgcons0 = FALSE;
5132 
5133  /* check for overlapping constraint before starting lifting */
5134  SCIP_CALL( checkForOverlapping(scip, cons0, c, c, usefulconss, nusefulconss, usefulvars, &nusefulvars, vartoindex,
5135  varnconss, maxnvarconsidx, varconsidxs, countofoverlapping, conshdlrdata->cliqueshrinking, &chgcons0,
5136  undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations,
5137  nfixedvars, naggrvars, nchgcoefs, ndelconss, cutoff) );
5138 
5139  if( *cutoff )
5140  break;
5141 
5142  /* we can't handle aggregated variables later on so we should have saved them for later */
5143  assert(*naggrvars == oldnaggrvars);
5144 
5145  /* if cons0 changed, we need to reorder the variables */
5146  if( chgcons0 && *nchgcoefs > oldnchgcoefs )
5147  {
5148  consdata = SCIPconsGetData(cons0);
5149  assert(consdata != NULL);
5150 
5151  cons0vars = consdata->vars;
5152  ncons0vars = consdata->nvars;
5153 
5154  /* sorting array after indices of variables, negated and active counterparts will stand side by side */
5155  SCIPsortDownPtr((void**)cons0vars, SCIPvarCompActiveAndNegated, ncons0vars);
5156  /* standard setppc-sorting now lost */
5157  consdata->sorted = FALSE;
5158  }
5159 
5160  /* check cons0 again for redundancy/fixings, because due to fixings in all other constraints it might happen that cons0 is redundant now */
5161  if( consdata->nfixedones > 0 || consdata->nfixedzeros > cons0fixedzeros )
5162  {
5163  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
5164  * possible
5165  */
5166  SCIP_CALL( presolvePropagateCons(scip, cons0, FALSE, undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations, nfixedvars, naggrvars, ndelconss, cutoff) );
5167 
5168  if( *cutoff )
5169  break;
5170 
5171  /* we can't handle aggregated variables later on so we should have saved them for later */
5172  assert(*naggrvars == oldnaggrvars);
5173 
5174  if( !SCIPconsIsActive(cons0) )
5175  continue;
5176  }
5177 
5178  nadded = 0;
5179 
5180  /* iterate over the cliques variables and all possible new clique variables at the "same" time, determine starting
5181  * index
5182  *
5183  * @note: it might be better to start the first round with our computed v1, but maybe it's better to switch to
5184  * trying to add all variables the second time for set packing constraints
5185  */
5186 
5187  /* we try to add all variables to the partitioning constraints, to try to fix as much as possible */
5188  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
5189  v1 = nusefulvars - 1;
5190  else
5191  {
5192  /* if we already ran a presolving round we want to try to add new variables */
5193  if( conshdlrdata->nclqpresolve > 0 )
5194  v1 = nusefulvars - 1;
5195  else
5196  {
5197  /* find start position of variable which we will try to add to our constraint, so we will get better clique constraints */
5198  (void) SCIPsortedvecFindDownPtr((void**)usefulvars, SCIPvarCompActiveAndNegated, (void*)cons0vars[ncons0vars - 1], nusefulvars, &v1);
5199  assert(v1 >= 0 && v1 < nusefulvars);
5200  /* if constraint is not merged and we found a variable which is negated the same as it's neighbour we have to
5201  * increase v1 to make sure that we don't loose this important variable */
5202  if( v1 + 1 < nusefulvars && ((SCIPvarIsNegated(usefulvars[v1 + 1]) && SCIPvarGetNegatedVar(usefulvars[v1 + 1]) == usefulvars[v1]) || (SCIPvarIsNegated(usefulvars[v1]) && SCIPvarGetNegatedVar(usefulvars[v1]) == usefulvars[v1 + 1])) )
5203  ++v1;
5204  }
5205  }
5206 
5207  assert(maxnvars >= ncons0vars);
5208  /* initialize the cliquevalues array */
5209  for( v = ncons0vars - 1; v >= 0; --v )
5210  {
5211  if( SCIPvarGetLbLocal(cons0vars[v]) < 0.5 && SCIPvarGetUbLocal(cons0vars[v]) > 0.5 )
5212  {
5213  /* variable has to be either active or a negated variable of an active one */
5214  assert(SCIPvarIsActive(cons0vars[v]) || (SCIPvarGetStatus(cons0vars[v]) == SCIP_VARSTATUS_NEGATED &&
5215  SCIPvarIsActive(SCIPvarGetNegationVar(cons0vars[v]))));
5216  cliquevalues[v] = SCIPvarIsActive(cons0vars[v]) ? TRUE : FALSE;
5217  }
5218  }
5219 
5220  chgcons0 = FALSE;
5221 
5222  /* try to lift variables to cons0 */
5223  SCIP_CALL( liftCliqueVariables(scip, cons0, c, usefulvars, &nusefulvars, v1, &cliquevalues, vartoindex, varnconss,
5224  maxnvarconsidx, varconsidxs, &maxnvars, &nadded, &chgcons0, nfixedvars, ndelconss, cutoff) );
5225 
5226  if( *cutoff )
5227  break;
5228 
5229  if( !SCIPconsIsActive(cons0) )
5230  continue;
5231 
5232  /* check for redundant constraints due to changing cons0 */
5233  if( chgcons0 )
5234  {
5235  int i;
5236 
5237  *firstchange = MIN(*firstchange, c);
5238  *firstclique = MIN(*firstclique, c);
5239  *lastclique = MAX(*lastclique, c);
5240 
5241  /* variables array has changed due to lifting variables, so get new values */
5242  assert(consdata == SCIPconsGetData(cons0));
5243  cons0vars = consdata->vars;
5244  ncons0vars = consdata->nvars;
5245 
5246  /* resorting array, because we added new variables, in order of indices of variables, negated
5247  * and active counterparts would stand side by side
5248  */
5249  SCIPsortDownPtr((void**)cons0vars, SCIPvarCompActiveAndNegated, ncons0vars);
5250  /* standard setppc-sorting now lost */
5251  consdata->sorted = FALSE;
5252 
5253  /* clear old entries in overlapping constraint */
5254  BMSclearMemoryArray(countofoverlapping, nusefulconss);
5255 
5256  for( v = ncons0vars - 1; v >= 0 ; --v )
5257  {
5258  var0 = cons0vars[v];
5259 
5260  /* fixed variables later to the count */
5261  if( SCIPvarGetLbLocal(var0) > 0.5 || SCIPvarGetUbLocal(var0) < 0.5 )
5262  continue;
5263 
5264  assert(SCIPhashmapExists(vartoindex, (void*) var0));
5265 
5266  varindex = SCIPhashmapGetImageInt(vartoindex, (void*) var0);
5267  for( i = varnconss[varindex] - 1; i >= 0 ; --i )
5268  ++(countofoverlapping[varconsidxs[varindex][i]]);
5269  }
5270 
5271  chgcons0 = FALSE;
5272 
5273  /* check for overlapping constraint after lifting, in the first round we will only check up front */
5274  SCIP_CALL( checkForOverlapping(scip, cons0, c, (conshdlrdata->nclqpresolve > 0) ? nusefulconss : c,
5275  usefulconss, nusefulconss, usefulvars, &nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs,
5276  countofoverlapping, conshdlrdata->cliqueshrinking, &chgcons0,
5277  undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations,
5278  nfixedvars, naggrvars, nchgcoefs, ndelconss, cutoff) );
5279 
5280  if( *cutoff )
5281  break;
5282 
5283  /* we can't handle aggregated variables later on so we should have saved them for later */
5284  assert(*naggrvars == oldnaggrvars);
5285  }
5286  }
5287 
5288  TERMINATE:
5289  SCIPfreeBufferArrayNull(scip, &countofoverlapping);
5290  SCIPfreeBufferArrayNull(scip, &cliquevalues);
5291 
5292  /* free temporary memory for constraints, variables and the mapping between them in reverse order as they were
5293  * allocated
5294  */
5295  for( c = nusefulvars; c > 0; --c )
5296  {
5297  if( varconsidxs[c] != NULL )
5298  {
5299  SCIPfreeBufferArrayNull(scip, &(varconsidxs[c]));
5300  }
5301  }
5302 
5303  SCIPfreeBufferArray(scip, &varconsidxs);
5304  SCIPfreeBufferArray(scip, &maxnvarconsidx);
5305  SCIPfreeBufferArray(scip, &varnconss);
5306  SCIPfreeBufferArray(scip, &usefulvars);
5307  SCIPfreeBufferArray(scip, &usefulconss);
5308 
5309  /* perform all collected aggregations */
5310  if( !*cutoff && naggregations > 0 && !SCIPdoNotAggr(scip) )
5311  {
5312  SCIP_CALL( performAggregations(scip, conshdlrdata, undoneaggrvars, undoneaggrtypes, naggregations, naggrvars, cutoff) );
5313  }
5314 
5315  /* free temporary memory for the aggregation storage */
5316  SCIPfreeBufferArray(scip, &undoneaggrtypes);
5317  SCIPfreeBufferArray(scip, &undoneaggrvars);
5318 
5319  /* free hashmap */
5320  SCIPhashmapFree(&vartoindex);
5321 
5322  if( *ndelconss < 0 )
5323  *ndelconss = 0;
5324 
5325  return SCIP_OKAY;
5326 }
5327 
5328 
5329 /** add cliques to SCIP */
5330 static
5332  SCIP* scip, /**< SCIP data structure */
5333  SCIP_CONS** conss, /**< constraint set */
5334  int nconss, /**< number of constraints in constraint set */
5335  int firstclique, /**< first constraint to start to add cliques */
5336  int lastclique, /**< last constraint to start to add cliques */
5337  int* naddconss, /**< pointer to count number of added constraints */
5338  int* ndelconss, /**< pointer to count number of deleted constraints */
5339  int* nchgbds, /**< pointer to count number of changed bounds */
5340  SCIP_Bool* cutoff /**< pointer to store if the problem is infeasible due to a fixing */
5341  )
5342 {
5343  SCIP_CONS* cons;
5344  SCIP_CONSDATA* consdata;
5345  SCIP_Bool infeasible;
5346  int nlocalbdchgs;
5347  int c;
5348 
5349  assert(scip != NULL);
5350  assert(firstclique >= 0);
5351  assert(lastclique <= nconss);
5352  assert(conss != NULL || ((nconss == 0) && (lastclique == 0)));
5353 
5354  /* add clique and implication information */
5355  for( c = firstclique; c < lastclique; ++c )
5356  {
5357  cons = conss[c]; /*lint !e613*/
5358  assert(cons != NULL);
5359 
5360  /* ignore deleted constraints */
5361  if( !SCIPconsIsActive(cons) )
5362  continue;
5363 
5364  nlocalbdchgs = 0;
5365  SCIP_CALL( applyFixings(scip, cons, naddconss, ndelconss, &nlocalbdchgs, cutoff) );
5366  *nchgbds += nlocalbdchgs;
5367 
5368  if( *cutoff )
5369  return SCIP_OKAY;
5370 
5371  consdata = SCIPconsGetData(cons);
5372  assert(consdata != NULL);
5373 
5374  if( SCIPconsIsDeleted(cons) )
5375  continue;
5376 
5377  if( !consdata->cliqueadded && consdata->nvars >= 2 )
5378  {
5379  /* add a set partitioning / packing constraint as clique */
5380  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
5381  {
5382  SCIP_CALL( SCIPaddClique(scip, consdata->vars, NULL, consdata->nvars,
5383  ((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING), &infeasible, &nlocalbdchgs) );
5384  *nchgbds += nlocalbdchgs;
5385 
5386  if( infeasible )
5387  {
5388  *cutoff = TRUE;
5389  return SCIP_OKAY;
5390  }
5391  }
5392  else if( consdata->nvars == 2 && !SCIPconsIsModifiable(cons) )
5393  {
5394  /* a two-variable set covering constraint x + y >= 1 yields the implication x == 0 -> y == 1 */
5395  SCIP_CALL( SCIPaddVarImplication(scip, consdata->vars[0], FALSE, consdata->vars[1],
5396  SCIP_BOUNDTYPE_LOWER, 1.0, &infeasible, &nlocalbdchgs) );
5397  *nchgbds += nlocalbdchgs;
5398 
5399  if( infeasible )
5400  {
5401  *cutoff = TRUE;
5402  return SCIP_OKAY;
5403  }
5404  }
5405  consdata->cliqueadded = TRUE;
5406  }
5407  }
5408 
5409  return SCIP_OKAY;
5410 }
5411 
5412 /** perform multi-aggregation on variables resulting from a set-partitioning/-packing constraint */
5413 static
5415  SCIP* scip, /**< SCIP data structure */
5416  SCIP_Bool linearconshdlrexist,/**< does the linear constraint handler exist, necessary for multi-aggregations */
5417  SCIP_VAR** vars, /**< all variables including the variable to which will be multi-aggregated */
5418  int nvars, /**< number of all variables */
5419  int pos, /**< position of variable for multi-aggregation */
5420  SCIP_Bool* infeasible, /**< pointer to store infeasibility status of aggregation */
5421  SCIP_Bool* aggregated /**< pointer to store aggregation status */
5422  )
5423 {
5424  SCIP_VAR** tmpvars;
5425  SCIP_Real* scalars;
5426  int v;
5427 
5428  assert(scip != NULL);
5429  assert(vars != NULL);
5430  assert(nvars > 1);
5431  assert(0 <= pos && pos < nvars);
5432  assert(infeasible != NULL);
5433  assert(aggregated != NULL);
5434 
5435  if( nvars == 2 )
5436  {
5437  SCIP_Bool redundant;
5438 
5439  SCIPdebugMsg(scip, "aggregating %s = 1 - %s\n", SCIPvarGetName(vars[pos]), SCIPvarGetName(vars[nvars - pos - 1]));
5440 
5441  /* perform aggregation on variables resulting from a set-packing constraint */
5442  SCIP_CALL( SCIPaggregateVars(scip, vars[pos], vars[nvars - pos - 1], 1.0, 1.0, 1.0, infeasible, &redundant, aggregated) );
5443  assert(*infeasible || *aggregated);
5444 
5445  return SCIP_OKAY;
5446  }
5447 
5448  if( !linearconshdlrexist )
5449  {
5450  *infeasible = FALSE;
5451  return SCIP_OKAY;
5452  }
5453 
5454  /* if the last variable will be multi-aggregated, we do not need to copy the variables */
5455  if( pos == nvars - 1 )
5456  tmpvars = vars;
5457  else
5458  {
5459  /* copy variables for aggregation */
5460  SCIP_CALL( SCIPduplicateBufferArray(scip, &tmpvars, vars, nvars) );
5461  tmpvars[pos] = tmpvars[nvars - 1];
5462  }
5463 
5464  SCIP_CALL( SCIPallocBufferArray(scip, &scalars, nvars - 1) );
5465  /* initialize scalars */
5466  for( v = nvars - 2; v >= 0; --v )
5467  scalars[v] = -1.0;
5468 
5469  SCIPdebugMsg(scip, "multi-aggregating binary variable <%s> (locks: [%d,%d]; to %d variables)\n",
5471  SCIPvarGetNLocksUpType(vars[pos], SCIP_LOCKTYPE_MODEL), nvars - 1);
5472 
5473  /* perform multi-aggregation */
5474  SCIP_CALL( SCIPmultiaggregateVar(scip, vars[pos], nvars - 1, tmpvars, scalars, 1.0, infeasible, aggregated) );
5475  assert(!(*infeasible));
5476 
5477  SCIPfreeBufferArray(scip, &scalars);
5478 
5479  if( pos < nvars - 1 )
5480  {
5481  assert(tmpvars != vars);
5482  SCIPfreeBufferArray(scip, &tmpvars);
5483  }
5484 
5485  return SCIP_OKAY;
5486 }
5487 
5488 /** determine singleton variables in set-partitioning/-packing constraints, or doubleton variables (active and negated)
5489  * in any combination of set-partitioning and set-packing constraints
5490  *
5491  * we can multi-aggregate the variable and either change the set-partitioning constraint to a set-packing constraint or
5492  * even delete it
5493  *
5494  * 1. c1: x + y + z = 1, uplocks(x) = 1, downlocks(x) = 1 => x = 1 - y - z and change c1 to y + z <= 1
5495  *
5496  * 2. c2: x + y + z <= 1, uplocks(x) = 1, downlocks(x) = 0, obj(x) < 0 => x = 1 - y - z and change c2 to y + z <= 1
5497  *
5498  * 3. d1: x + y + z <= 1 and d2: ~x + u + v <= 1, uplocks(x) = 1, downlocks(x) = 1
5499  * a) obj(x) <= 0 => x = 1 - y - z and delete d1
5500  * b) obj(x) > 0 => ~x = 1 - u - v and delete d2
5501  *
5502  * 4. e1: x + y + z == 1 and e2: ~x + u + v (<= or ==) 1, uplocks(x) = (1 or 2), downlocks(x) = 2
5503  * => x = 1 - y - z and delete e1
5504  *
5505  * we can also aggregate a variable in a set-packing constraint with only two variables when the uplocks are equal to
5506  * one and then delete this constraint
5507  *
5508  * 5. f1: x + y <= 1, uplocks(x) = 1, obj(x) <= 0 => x = 1 - y and delete f1
5509  *
5510  * @todo might want to multi-aggregate variables even with more locks, when the fill in is still smaller or equal to
5511  * the old number of non-zeros, e.g.
5512  *
5513  * x + y + z = 1
5514  * ~x + u + v <=/= 1
5515  * ~x + w <= 1
5516  */
5517 static
5519  SCIP* scip, /**< SCIP data structure */
5520  SCIP_CONS** conss, /**< constraint set */
5521  int nconss, /**< number of constraints in constraint set */
5522  SCIP_Bool dualpresolvingenabled,/**< is dual presolving enabled */
5523  SCIP_Bool linearconshdlrexist,/**< does the linear constraint handler exist, necessary for
5524  * multi-aggregations
5525  */
5526  int* nfixedvars, /**< pointer to count number of deleted variables */
5527  int* naggrvars, /**< pointer to count number of aggregated variables */
5528  int* ndelconss, /**< pointer to count number of deleted constraints */
5529  int* nchgcoefs, /**< pointer to count number of changed coefficients */
5530  int* nchgsides, /**< pointer to count number of changed left hand sides */
5531  SCIP_Bool* cutoff /**< pointer to store if a cut off was detected */
5532  )
5533 {
5534  SCIP_CONS** usefulconss;
5535  SCIP_VAR** binvars;
5536  SCIP_HASHMAP* vartoindex;
5537  SCIP_Bool* chgtype;
5538  int* considxs;
5539  int* posincons;
5540  SCIP_Bool infeasible;
5541  SCIP_Bool aggregated;
5542  SCIP_Bool donotaggr;
5543  SCIP_Bool donotmultaggr;
5544  SCIP_Bool mustcheck;
5545  SCIP_Bool addcut;
5546  int nposvars;
5547  int ndecs;
5548  int nbinvars;
5549  int nposbinvars;
5550  int nuplocks;
5551  int ndownlocks;
5552  int posreplacements;
5553  int nhashmapentries;
5554  int nlocaladdconss;
5555  int v;
5556  int c;
5557 
5558  assert(scip != NULL);
5559  assert(conss != NULL);
5560  assert(nconss > 0);
5561  assert(nfixedvars != NULL);
5562  assert(naggrvars != NULL);
5563  assert(ndelconss != NULL);
5564  assert(nchgcoefs != NULL);
5565  assert(nchgsides != NULL);
5566 
5567  nbinvars = SCIPgetNBinVars(scip);
5568  nposbinvars = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
5569  assert(nbinvars + SCIPgetNIntVars(scip) + SCIPgetNImplVars(scip) == nposbinvars);
5570 
5571  binvars = SCIPgetVars(scip);
5572 
5573  /* determine number for possible multi-aggregations */
5574  nposvars = 0;
5575  for( v = nposbinvars - 1; v >= 0; --v )
5576  {
5577  assert(SCIPvarGetType(binvars[v]) != SCIP_VARTYPE_CONTINUOUS);
5578 
5579  if( v < nbinvars || SCIPvarIsBinary(binvars[v]) )
5580  {
5581  nuplocks = SCIPvarGetNLocksUpType(binvars[v], SCIP_LOCKTYPE_MODEL);
5582  ndownlocks = SCIPvarGetNLocksDownType(binvars[v], SCIP_LOCKTYPE_MODEL);
5583 
5584  if( (nuplocks == 1 && ndownlocks <= 1) || (nuplocks <= 1 && ndownlocks == 1) || (nuplocks <= 2 && ndownlocks <= 2 && SCIPvarGetNegatedVar(binvars[v]) != NULL) )
5585  ++nposvars;
5586  }
5587  }
5588 
5589  SCIPdebugMsg(scip, "found %d binary variables for possible multi-aggregation\n", nposvars);
5590 
5591  if( nposvars == 0 )
5592  return SCIP_OKAY;
5593 
5594  /* a hashmap from var to index when found in a set-partitioning constraint */
5595  SCIP_CALL( SCIPhashmapCreate(&vartoindex, SCIPblkmem(scip), nposvars) );
5596 
5597  /* get temporary memory */
5598  SCIP_CALL( SCIPallocBufferArray(scip, &chgtype, nconss) );
5599  BMSclearMemoryArray(chgtype, nconss);
5600 
5601  SCIP_CALL( SCIPallocBufferArray(scip, &considxs, nposbinvars) );
5602  SCIP_CALL( SCIPallocBufferArray(scip, &posincons, nposbinvars) );
5603 
5604  SCIP_CALL( SCIPduplicateBufferArray(scip, &usefulconss, conss, nconss) );
5605  /* sort constraints */
5606  SCIPsortPtr((void**)usefulconss, setppcConssSort2, nconss);
5607 
5608  posreplacements = 0;
5609  nhashmapentries = 0;
5610  ndecs = 0;
5611  donotaggr = SCIPdoNotAggr(scip);
5612  donotmultaggr = SCIPdoNotMultaggr(scip);
5613  assert(!donotaggr || !donotmultaggr);
5614 
5615  /* determine singleton variables in set-partitioning/-packing constraints, or doubleton variables (active and
5616  * negated) in any combination of set-partitioning and set-packing constraints
5617  *
5618  * we can multi-aggregate the variable and either change the set-partitioning constraint to a set-packing constraint
5619  * or even delete it
5620  */
5621  for( c = 0; c < nconss; ++c )
5622  {
5623  SCIP_CONS* cons;
5624  SCIP_CONSDATA* consdata;
5625  int oldnfixedvars;
5626  nlocaladdconss = 0;
5627 
5628  cons = usefulconss[c];
5629  assert(cons != NULL);
5630 
5631  if( SCIPconsIsDeleted(cons) )
5632  continue;
5633 
5634  consdata = SCIPconsGetData(cons);
5635  assert(consdata != NULL);
5636 
5637  /* if we cannot find any constraint to perform a useful multi-aggregation, stop */
5638  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING )
5639  break;
5640 
5641  if( !SCIPconsIsChecked(cons) )
5642  continue;
5643 
5644  if( SCIPconsIsModifiable(cons) )
5645  continue;
5646 
5647  /* update the variables */
5648  SCIP_CALL( applyFixings(scip, cons, &nlocaladdconss, ndelconss, nfixedvars, cutoff) );
5649 
5650  if( *cutoff )
5651  break;
5652 
5653  /* due to resolving multi-aggregations a constraint can become deleted */
5654  if( SCIPconsIsDeleted(cons) )
5655  continue;
5656 
5657  SCIP_CALL( processFixings(scip, cons, cutoff, nfixedvars, &addcut, &mustcheck) );
5658  assert(!addcut);
5659 
5660  if( *cutoff )
5661  break;
5662 
5663  if( SCIPconsIsDeleted(cons) )
5664  continue;
5665 
5666  oldnfixedvars = *nfixedvars;
5667 
5668  /* merging unmerged constraints */
5669  SCIP_CALL( mergeMultiples(scip, cons, nfixedvars, ndelconss, nchgcoefs, cutoff) );
5670 
5671  if( *cutoff )
5672  break;
5673 
5674  if( SCIPconsIsDeleted(cons) )
5675  continue;
5676 
5677  if( oldnfixedvars < *nfixedvars )
5678  {
5679  /* update the variables */
5680  SCIP_CALL( applyFixings(scip, cons, &nlocaladdconss, ndelconss, nfixedvars, cutoff) );
5681  assert(!SCIPconsIsDeleted(cons));
5682  assert(nlocaladdconss == 0);
5683  assert(!*cutoff);
5684 
5685  if( SCIPconsIsDeleted(cons) )
5686  continue;
5687  }
5688 
5689  /* if the constraint was not merged and consists of a variable with its negation, the constraint is redundant */
5690  if( consdata->nvars < 2 )
5691  {
5692  /* deleting redundant set-packing constraint */
5693  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
5694  {
5695  SCIPdebugMsg(scip, "deleting redundant set-packing constraint <%s>\n", SCIPconsGetName(cons));
5696 
5697  SCIP_CALL( SCIPdelCons(scip, cons) );
5698  ++(*ndelconss);
5699 
5700  continue;
5701  }
5702  else
5703  {
5704  SCIP_Bool fixed;
5705 
5706  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING);
5707 
5708  if( consdata->nvars == 0 )
5709  {
5710  SCIPdebugMsg(scip, "empty set partition constraint <%s> led to infeasibility\n", SCIPconsGetName(cons));
5711 
5712  *cutoff = TRUE;
5713  break;
5714  }
5715 
5716  SCIPdebugMsg(scip, "fixing <%s> to 1 because this variable is the last variable in a set partition constraint <%s>\n", SCIPvarGetName(consdata->vars[0]), SCIPconsGetName(cons));
5717 
5718  SCIP_CALL( SCIPfixVar(scip, consdata->vars[0], 1.0, &infeasible, &fixed) );
5719  assert(!infeasible);
5720 
5721  if( fixed )
5722  ++(*nfixedvars);
5723 
5724  assert(SCIPvarGetLbGlobal(consdata->vars[0]) > 0.5);
5725 
5726  SCIPdebugMsg(scip, "deleting redundant set-partition constraint <%s>\n", SCIPconsGetName(cons));
5727 
5728  SCIP_CALL( SCIPdelCons(scip, cons) );
5729  ++(*ndelconss);
5730 
5731  continue;
5732  }
5733  }
5734 
5735  /* perform dualpresolve on set-packing constraints with exactly two variables */
5736  if( !donotaggr && consdata->nvars == 2 && dualpresolvingenabled && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
5737  {
5738  SCIP_VAR* var;
5739  SCIP_Real objval;
5740  SCIP_Bool redundant;
5741 
5742  var = consdata->vars[0];
5743  assert(var != NULL);
5745 
5746  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
5747 
5749 
5750  if( nuplocks == 1 && objval <= 0 )
5751  {
5752  SCIPdebugMsg(scip, "dualpresolve, aggregating %s + %s = 1, in set-packing constraint %s\n", SCIPvarGetName(var), SCIPvarGetName(consdata->vars[1]), SCIPconsGetName(cons));
5753 
5754  /* perform aggregation on variables resulting from a set-packing constraint */
5755  SCIP_CALL( SCIPaggregateVars(scip, var, consdata->vars[1], 1.0, 1.0, 1.0, &infeasible, &redundant, &aggregated) );
5756 
5757  if( infeasible )
5758  {
5759  *cutoff = TRUE;
5760  break;
5761  }
5762 
5763  assert(aggregated);
5764  ++(*naggrvars);
5765 
5766  SCIP_CALL( SCIPdelCons(scip, cons) );
5767  ++(*ndelconss);
5768 
5769  continue;
5770  }
5771  else
5772  {
5773  var = consdata->vars[1];
5774  assert(var != NULL);
5776 
5777  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
5778 
5780 
5781  if( nuplocks == 1 && objval <= 0 )
5782  {
5783  SCIPdebugMsg(scip, "dualpresolve, aggregating %s + %s = 1, in set-packing constraint %s\n", SCIPvarGetName(var), SCIPvarGetName(consdata->vars[0]), SCIPconsGetName(cons));
5784 
5785  /* perform aggregation on variables resulting from a set-packing constraint */
5786  SCIP_CALL( SCIPaggregateVars(scip, var, consdata->vars[0], 1.0, 1.0, 1.0, &infeasible, &redundant, &aggregated) );
5787 
5788  if( infeasible )
5789  {
5790  *cutoff = TRUE;
5791  break;
5792  }
5793  assert(aggregated);
5794  ++(*naggrvars);
5795 
5796  SCIP_CALL( SCIPdelCons(scip, cons) );
5797  ++(*ndelconss);
5798 
5799  continue;
5800  }
5801  }
5802  }
5803  else if( !donotaggr && consdata->nvars == 2 && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
5804  {
5805  SCIP_Bool redundant;
5806 
5807  SCIPdebugMsg(scip, "aggregating %s + %s = 1, in set-partition constraint %s\n", SCIPvarGetName(consdata->vars[0]), SCIPvarGetName(consdata->vars[1]), SCIPconsGetName(cons));
5808 
5809  /* perform aggregation on variables resulting from a set-partitioning constraint */
5810  SCIP_CALL( SCIPaggregateVars(scip, consdata->vars[0], consdata->vars[1], 1.0, 1.0, 1.0, &infeasible, &redundant, &aggregated) );
581