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