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