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-2018 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file cons_setppc.c
17  * @brief Constraint handler for the set partitioning / packing / covering constraints \f$1^T x\ \{=, \le, \ge\}\ 1\f$.
18  * @author Tobias Achterberg
19  * @author Michael Winkler
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "blockmemshell/memory.h"
25 #include "scip/cons_linear.h"
26 #include "scip/cons_quadratic.h"
27 #include "scip/cons_setppc.h"
28 #include "scip/pub_conflict.h"
29 #include "scip/pub_cons.h"
30 #include "scip/pub_event.h"
31 #include "scip/pub_lp.h"
32 #include "scip/pub_message.h"
33 #include "scip/pub_misc.h"
34 #include "scip/pub_misc_sort.h"
35 #include "scip/pub_var.h"
36 #include "scip/scip_conflict.h"
37 #include "scip/scip_cons.h"
38 #include "scip/scip_cut.h"
39 #include "scip/scip_event.h"
40 #include "scip/scip_general.h"
41 #include "scip/scip_lp.h"
42 #include "scip/scip_mem.h"
43 #include "scip/scip_message.h"
44 #include "scip/scip_numerics.h"
45 #include "scip/scip_param.h"
46 #include "scip/scip_prob.h"
47 #include "scip/scip_probing.h"
48 #include "scip/scip_randnumgen.h"
49 #include "scip/scip_sol.h"
50 #include "scip/scip_solvingstats.h"
51 #include "scip/scip_var.h"
52 #include <ctype.h>
53 #include <string.h>
54 
55 
56 #define CONSHDLR_NAME "setppc"
57 #define CONSHDLR_DESC "set partitioning / packing / covering constraints"
58 #define CONSHDLR_SEPAPRIORITY +700000 /**< priority of the constraint handler for separation */
59 #define CONSHDLR_ENFOPRIORITY -700000 /**< priority of the constraint handler for constraint enforcing */
60 #define CONSHDLR_CHECKPRIORITY -700000 /**< priority of the constraint handler for checking feasibility */
61 #define CONSHDLR_SEPAFREQ 0 /**< frequency for separating cuts; zero means to separate only in the root node */
62 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
63 #define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
64  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
65 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
66 #define CONSHDLR_DELAYSEPA FALSE /**< should separation method be delayed, if other separators found cuts? */
67 #define CONSHDLR_DELAYPROP FALSE /**< should propagation method be delayed, if other propagators found reductions? */
68 #define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
69 
70 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_ALWAYS
71 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP
72 
73 #define LINCONSUPGD_PRIORITY +700000 /**< priority of the constraint handler for upgrading of linear constraints */
74 #define QUADCONSUPGD_PRIORITY +700000 /**< priority of the constraint handler for upgrading of linear constraints */
75 
76 #define EVENTHDLR_NAME "setppc"
77 #define EVENTHDLR_DESC "bound change event handler for set partitioning / packing / covering constraints"
78 
79 #define CONFLICTHDLR_NAME "setppc"
80 #define CONFLICTHDLR_DESC "conflict handler creating set covering constraints"
81 #define CONFLICTHDLR_PRIORITY LINCONSUPGD_PRIORITY
82 
83 #define DEFAULT_PRESOLPAIRWISE TRUE /**< should pairwise constraint comparison be performed in presolving? */
84 
85 #define HASHSIZE_SETPPCCONS 500 /**< minimal size of hash table in setppc constraint tables */
86 #define DEFAULT_PRESOLUSEHASHING TRUE /**< should hash table be used for detecting redundant constraints in advance */
87 #define NMINCOMPARISONS 200000 /**< number for minimal pairwise presolving comparisons */
88 #define MINGAINPERNMINCOMPARISONS 1e-06 /**< minimal gain per minimal pairwise presolving comparisons to repeat pairwise comparison round */
89 
90 #define DEFAULT_RANDSEED 3
91 
92 /*#define VARUSES*/ /* activate variable usage counting, that is necessary for LP and pseudo branching */
93 /*#define BRANCHLP*/ /* BRANCHLP is only useful if the ENFOPRIORITY is set to a positive value */
94 #ifdef BRANCHLP
95 #define MINBRANCHWEIGHT 0.3 /**< minimum weight of both sets in binary set branching */
96 #define MAXBRANCHWEIGHT 0.7 /**< maximum weight of both sets in binary set branching */
97 #endif
98 #define DEFAULT_NPSEUDOBRANCHES 2 /**< number of children created in pseudo branching (0: disable branching) */
99 #define DEFAULT_DUALPRESOLVING TRUE /**< should dual presolving steps be performed? */
101 #define DEFAULT_CLIQUELIFTING FALSE /**< should we try to lift variables into other clique constraints, fix
102  * variables, aggregate them, and also shrink the amount of variables in
103  * clique constraints
104  */
105 #define DEFAULT_ADDVARIABLESASCLIQUES FALSE/**< should we try to generate extra clique constraint out of all binary
106  * variables to hopefully fasten the detection of redundant clique
107  * constraints */
108 #define DEFAULT_CLIQUESHRINKING TRUE /**< should we try to shrink the number of variables in a clique constraints, by
109  * replacing more than one variable by only one
110  */
111 
112 /* @todo maybe use event SCIP_EVENTTYPE_VARUNLOCKED to decide for another dual-presolving run on a constraint */
113 
114 /*
115  * Data structures
116  */
117 
118 /** constraint handler data */
119 struct SCIP_ConshdlrData
120 {
121  SCIP_EVENTHDLR* eventhdlr; /**< event handler for bound change events */
122  SCIP_CONSHDLR* conshdlrlinear; /**< pointer to linear constraint handler or NULL if not included */
123 #ifdef VARUSES
124  SCIP_INTARRAY* varuses; /**< number of times a var is used in the active setppc constraints */
125 #endif
126  SCIP_Longint nsetpart; /**< number of set partitioning constraints in transformed problem */
127  int npseudobranches; /**< number of children created in pseudo branching (0 to disable branching) */
128  int noldfixedvars; /**< number of fixed variables after last clique lifting run */
129  int noldimpls; /**< number of implication before last clique lifting run */
130  int noldcliques; /**< number of cliques before last clique lifting run */
131  int noldupgrs; /**< number of setppc constraints since the last clique lifting run */
132  int nclqpresolve; /**< number of setppc clique lifting runs */
133  SCIP_Bool updatedsetppctype; /**< remember whether we upgraded a constraint type */
134  SCIP_Bool cliquelifting; /**< should we perform the clique lifting procedure */
135  SCIP_Bool enablecliquelifting;/**< check whether we have enough changes to run the lifting procedure again */
136  SCIP_Bool cliqueshrinking; /**< should we try to shrink the number of variables in a clique
137  * constraints, by replacing more than one variable by only one
138  */
139  SCIP_Bool addvariablesascliques;/**< should we try to generate extra clique constraint out of all binary
140  * variables to hopefully fasten the detection of redundant clique
141  * constraints */
142  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
143  SCIP_Bool presolpairwise; /**< should pairwise constraint comparison be performed in presolving? */
144  SCIP_Bool presolusehashing; /**< should hash table be used for detecting redundant constraints in advance */
145  SCIP_Bool dualpresolving; /**< should dual presolving steps be performed? */
146 };
147 
148 /** constraint data for set partitioning / packing / covering constraints */
149 struct SCIP_ConsData
150 {
151  uint64_t signature; /**< bit signature of vars array */
152  SCIP_ROW* row; /**< LP row, if constraint is already stored in LP row format */
153  SCIP_VAR** vars; /**< variables of the constraint */
154  int varssize; /**< size of vars array */
155  int nvars; /**< number of variables in the constraint */
156  int nfixedzeros; /**< current number of variables fixed to zero in the constraint */
157  int nfixedones; /**< current number of variables fixed to one in the constraint */
158  unsigned int setppctype:2; /**< type of constraint: set partitioning, packing or covering */
159  unsigned int sorted:1; /**< are the constraint's variables sorted? */
160  unsigned int cliqueadded:1; /**< was the set partitioning / packing constraint already added as clique? */
161  unsigned int validsignature:1; /**< is the bit signature valid? */
162  unsigned int changed:1; /**< was constraint changed since last redundancy round in preprocessing? */
163  unsigned int varsdeleted:1; /**< were variables deleted after last cleanup? */
164  unsigned int merged:1; /**< are the constraint's equal/negated variables already merged? */
165  unsigned int presolpropagated:1; /**< was the constraint already propagated in presolving w.r.t. the current domains? */
166  unsigned int existmultaggr:1; /**< does this constraint contain aggregations */
167  unsigned int catchevents:1; /**< are events installed for this constraint? */
168 };
169 
170 
171 
172 
173 /*
174  * Local methods
175  */
176 
177 /** compares two active constraints of type set partitioning or set packing such that a "-1" is return if
178  * 1. the first constraint is a set partitioning constraint and the second is a set packing or
179  * 2. both constraints are set partitioning constraints and the second has more! variables than the first or
180  * 3. both constraints are set packing constraints and the second has less! variables than the first
181  * a "0" is return if
182  * 1. both constraint are of the same type and have the amount of variables or
183  * and a "1" is returned otherwise
184  */
185 static
186 int setppcCompare(
187  SCIP_CONS*const cons1, /**< first problem variable */
188  SCIP_CONS*const cons2 /**< second problem variable */
189  )
190 {
191  SCIP_CONSDATA* consdata1;
192  SCIP_CONSDATA* consdata2;
193 
194  assert(cons1 != NULL);
195  assert(cons2 != NULL);
196  assert(SCIPconsIsActive(cons1));
197  assert(SCIPconsIsActive(cons2));
198 
199  /* the partitioning type should be the smallest value and the packing the second smallest */
201 
202  consdata1 = SCIPconsGetData(cons1);
203  assert(consdata1 != NULL);
204  assert(consdata1->setppctype != SCIP_SETPPCTYPE_COVERING); /*lint !e641*/
205  consdata2 = SCIPconsGetData(cons2);
206  assert(consdata2 != NULL);
207  assert(consdata2->setppctype != SCIP_SETPPCTYPE_COVERING); /*lint !e641*/
208 
209  if( consdata1->setppctype < consdata2->setppctype ||
210  (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nvars < consdata2->nvars) || /*lint !e641*/
211  (consdata2->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->nvars > consdata2->nvars) ) /*lint !e641*/
212  return -1;
213  else if( (consdata1->setppctype == consdata2->setppctype && consdata1->nvars == consdata2->nvars) ) /*lint !e641*/
214  return 0;
215  else
216  {
217  assert(consdata1->setppctype > consdata2->setppctype || (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->setppctype == consdata2->setppctype && consdata1->nvars > consdata2->nvars) || (consdata1->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->setppctype == consdata2->setppctype && consdata1->nvars < consdata2->nvars)); /*lint !e641*/
218  return +1;
219  }
220 }
221 
222 /** sort constraints first after type (partitioning before packing before covering) and second after number of
223  * variables such that the partitioning constraints have increasing number of variables and the packing constraints
224  * have decreasing number of variables */
225 static
226 SCIP_DECL_SORTPTRCOMP(setppcConssSort)
227 {
228  return setppcCompare((SCIP_CONS*)elem1, (SCIP_CONS*)elem2);
229 }
230 
231 /** compares two setppc constraints such that a "-1" is return if the first constraint is active and
232  * 1. the second constraint is deleted
233  * 2. the first constraint is a set partitioning constraint and the second is a set packing or
234  * 3. both constraints are set partitioning constraints and the second has more! variables than the first or
235  * 4. both constraints are set packing constraints and the second has less! variables than the first
236  * a "0" is return if
237  * 1. both constraint are set-covering constraints
238  * 2. both constraint are of the same type and have the amount of variables or
239  * and a "1" is returned otherwise
240  */
241 static
242 int setppcCompare2(
243  SCIP_CONS*const cons1, /**< first problem variable */
244  SCIP_CONS*const cons2 /**< second problem variable */
245  )
246 {
247  SCIP_CONSDATA* consdata1;
248  SCIP_CONSDATA* consdata2;
249 
250  assert(cons1 != NULL);
251  assert(cons2 != NULL);
252 
253  if( SCIPconsIsDeleted(cons1) )
254  {
255  if( SCIPconsIsDeleted(cons2) )
256  return 0;
257  else
258  return +1;
259  }
260  else if( SCIPconsIsDeleted(cons2) )
261  return -1;
262 
263  consdata1 = SCIPconsGetData(cons1);
264  assert(consdata1 != NULL);
265  consdata2 = SCIPconsGetData(cons2);
266  assert(consdata2 != NULL);
267 
268  /* the partitioning type should be the smallest value and the packing the second smallest */
270 
271  if( consdata1->setppctype < consdata2->setppctype ||
272  ((SCIP_SETPPCTYPE)consdata1->setppctype != SCIP_SETPPCTYPE_COVERING &&
273  (((SCIP_SETPPCTYPE)consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nvars < consdata2->nvars) ||
274  ((SCIP_SETPPCTYPE)consdata2->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->nvars > consdata2->nvars))) )
275  return -1;
276  else if( ((SCIP_SETPPCTYPE)consdata2->setppctype == SCIP_SETPPCTYPE_COVERING || (consdata1->setppctype == consdata2->setppctype && consdata1->nvars == consdata2->nvars)) )
277  return 0;
278  else
279  {
280  assert(consdata1->setppctype > consdata2->setppctype || ((consdata1->setppctype == consdata2->setppctype) &&
281  ((consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nvars > consdata2->nvars)
282  || (consdata1->setppctype == SCIP_SETPPCTYPE_PACKING && consdata1->nvars < consdata2->nvars)))); /*lint !e641*/
283  return +1;
284  }
285 }
286 
287 /** sort constraints first after type (partitioning before packing before covering) and second after number of
288  * variables such that the partitioning constraints have increasing number of variables and the packing constraints
289  * have decreasing number of variables */
290 static
291 SCIP_DECL_SORTPTRCOMP(setppcConssSort2)
292 {
293  return setppcCompare2((SCIP_CONS*)elem1, (SCIP_CONS*)elem2);
294 }
295 
296 
297 /** installs rounding locks for the given variable in the given setppc constraint */
298 static
300  SCIP* scip, /**< SCIP data structure */
301  SCIP_CONS* cons, /**< setppc constraint */
302  SCIP_VAR* var /**< variable of constraint entry */
303  )
304 {
305  SCIP_CONSDATA* consdata;
306 
307  consdata = SCIPconsGetData(cons);
308  assert(consdata != NULL);
309 
310  switch( consdata->setppctype )
311  {
313  SCIP_CALL( SCIPlockVarCons(scip, var, cons, TRUE, TRUE) );
314  break;
316  SCIP_CALL( SCIPlockVarCons(scip, var, cons, FALSE, TRUE) );
317  break;
319  SCIP_CALL( SCIPlockVarCons(scip, var, cons, TRUE, FALSE) );
320  break;
321  default:
322  SCIPerrorMessage("unknown setppc type\n");
323  return SCIP_INVALIDDATA;
324  }
325 
326  return SCIP_OKAY;
327 }
328 
329 /** removes rounding locks for the given variable in the given setppc constraint */
330 static
332  SCIP* scip, /**< SCIP data structure */
333  SCIP_CONS* cons, /**< setppc constraint */
334  SCIP_VAR* var /**< variable of constraint entry */
335  )
336 {
337  SCIP_CONSDATA* consdata;
338 
339  consdata = SCIPconsGetData(cons);
340  assert(consdata != NULL);
341 
342  switch( consdata->setppctype )
343  {
345  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, TRUE, TRUE) );
346  break;
348  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, FALSE, TRUE) );
349  break;
351  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, TRUE, FALSE) );
352  break;
353  default:
354  SCIPerrorMessage("unknown setppc type\n");
355  return SCIP_INVALIDDATA;
356  }
357 
358  return SCIP_OKAY;
359 }
360 
361 /** creates constraint handler data for set partitioning / packing / covering constraint handler */
362 static
364  SCIP* scip, /**< SCIP data structure */
365  SCIP_CONSHDLRDATA** conshdlrdata, /**< pointer to store the constraint handler data */
366  SCIP_EVENTHDLR* eventhdlr /**< event handler */
367  )
368 {
369  assert(scip != NULL);
370  assert(conshdlrdata != NULL);
371  assert(eventhdlr != NULL);
372 
373  SCIP_CALL( SCIPallocBlockMemory(scip, conshdlrdata) );
374 #ifdef VARUSES
375  SCIP_CALL( SCIPcreateIntarray(scip, &(*conshdlrdata)->varuses) );
376 #endif
377  (*conshdlrdata)->npseudobranches = DEFAULT_NPSEUDOBRANCHES;
378 
379  /* set event handler for bound change events */
380  (*conshdlrdata)->eventhdlr = eventhdlr;
381  (*conshdlrdata)->nsetpart = 0;
382 
383  /* create a random number generator */
384  SCIP_CALL( SCIPcreateRandom(scip, &(*conshdlrdata)->randnumgen,
386 
387  return SCIP_OKAY;
388 }
389 
390 /** frees constraint handler data for set partitioning / packing / covering constraint handler */
391 static
393  SCIP* scip, /**< SCIP data structure */
394  SCIP_CONSHDLRDATA** conshdlrdata /**< pointer to the constraint handler data */
395  )
396 {
397  assert(conshdlrdata != NULL);
398  assert(*conshdlrdata != NULL);
399 
400 #ifdef VARUSES
401  SCIP_CALL( SCIPfreeIntarray(scip, &(*conshdlrdata)->varuses) );
402 #endif
403 
404  /* free random number generator */
405  SCIPfreeRandom(scip, &(*conshdlrdata)->randnumgen);
406 
407  SCIPfreeBlockMemory(scip, conshdlrdata);
408 
409  return SCIP_OKAY;
410 }
411 
412 #ifdef VARUSES
413 /** adds the given value to the usage counter of the given variable */
414 static
415 SCIP_RETCODE conshdlrdataAddVaruses(
416  SCIP* scip, /**< SCIP data structure */
417  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
418  SCIP_VAR* var, /**< variable to increase usage counter for */
419  int addval /**< value to add to the usage counter */
420  )
421 {
422  SCIP_INTARRAY* varuses;
423 
424  assert(conshdlrdata != NULL);
425  assert(var != NULL);
426 
427  varuses = conshdlrdata->varuses;
428  assert(varuses != NULL);
429 
430  /* if the variable is the negation of a problem variable, count the varuses in the problem variable */
431  if( SCIPvarIsNegated(var) )
432  {
433  SCIP_VAR* negvar;
434  int varindex;
435 
436  /* move the varuses value of the negated variable to the active problem variable */
437  varindex = SCIPvarGetIndex(var);
438  addval += SCIPgetIntarrayVal(scip, varuses, varindex);
439  SCIP_CALL( SCIPsetIntarrayVal(scip, varuses, varindex, 0) );
440  SCIP_CALL( SCIPgetNegatedVar(scip, var, &negvar) );
441  var = negvar;
442  }
443 
444  /* increase varuses counter */
445  SCIP_CALL( SCIPincIntarrayVal(scip, varuses, SCIPvarGetIndex(var), addval) );
446 
447  SCIPdebugMsg(scip, "added %d to varuses of <%s>: %d\n",
448  addval, SCIPvarGetName(var), SCIPgetIntarrayVal(scip, varuses, SCIPvarGetIndex(var)));
449 
450  return SCIP_OKAY;
451 }
452 
453 /** increases the usage counter of the given variable */
454 static
455 SCIP_RETCODE conshdlrdataIncVaruses(
456  SCIP* scip, /**< SCIP data structure */
457  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
458  SCIP_VAR* var /**< variable to increase usage counter for */
459  )
460 {
461  assert(conshdlrdata != NULL);
462 
463  SCIPdebugMsg(scip, "increasing varuses of <%s>: %d\n",
464  SCIPvarGetName(var), SCIPgetIntarrayVal(scip, conshdlrdata->varuses, SCIPvarGetIndex(var)));
465 
466  SCIP_CALL( conshdlrdataAddVaruses(scip, conshdlrdata, var, +1) );
467 
468  return SCIP_OKAY;
469 }
470 
471 /** decreases the usage counter of the given variable */
472 static
473 SCIP_RETCODE conshdlrdataDecVaruses(
474  SCIP* scip, /**< SCIP data structure */
475  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
476  SCIP_VAR* var /**< variable to increase usage counter for */
477  )
478 {
479  assert(conshdlrdata != NULL);
480 
481  SCIPdebugMsg(scip, "decreasing varuses of <%s>: %d\n",
482  SCIPvarGetName(var), SCIPgetIntarrayVal(scip, conshdlrdata->varuses, SCIPvarGetIndex(var)));
483 
484  SCIP_CALL( conshdlrdataAddVaruses(scip, conshdlrdata, var, -1) );
485 
486  return SCIP_OKAY;
487 }
488 
489 /** increases the usage counter of all variable in the constraint */
490 static
491 SCIP_RETCODE consdataIncVaruses(
492  SCIP* scip, /**< SCIP data structure */
493  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
494  SCIP_CONSDATA* consdata /**< setppc constraint data */
495  )
496 {
497  int v;
498 
499  assert(consdata != NULL);
500 
501  for( v = 0; v < consdata->nvars; ++v )
502  {
503  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, consdata->vars[v]) );
504  }
505 
506  return SCIP_OKAY;
507 }
508 
509 /** decreases the usage counter of all variable in the constraint */
510 static
511 SCIP_RETCODE consdataDecVaruses(
512  SCIP* scip, /**< SCIP data structure */
513  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
514  SCIP_CONSDATA* consdata /**< setppc constraint data */
515  )
516 {
517  int v;
518 
519  assert(consdata != NULL);
520 
521  for( v = 0; v < consdata->nvars; ++v )
522  {
523  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, consdata->vars[v]) );
524  }
525 
526  return SCIP_OKAY;
527 }
528 #endif
529 
530 /** ensures, that the vars array can store at least num entries */
531 static
533  SCIP* scip, /**< SCIP data structure */
534  SCIP_CONSDATA* consdata, /**< setppc constraint data */
535  int num /**< minimum number of entries to store */
536  )
537 {
538  assert(consdata != NULL);
539  assert(consdata->nvars <= consdata->varssize);
541  if( num > consdata->varssize )
542  {
543  int newsize;
544 
545  newsize = SCIPcalcMemGrowSize(scip, num);
546  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &consdata->vars, consdata->varssize, newsize) );
547  consdata->varssize = newsize;
548  }
549  assert(num <= consdata->varssize);
550 
551  return SCIP_OKAY;
552 }
553 
554 /** creates a set partitioning / packing / covering constraint data object */
555 static
557  SCIP* scip, /**< SCIP data structure */
558  SCIP_CONSDATA** consdata, /**< pointer to store the set partitioning / packing / covering constraint */
559  int nvars, /**< number of variables in the constraint */
560  SCIP_VAR** vars, /**< variables of the constraint */
561  SCIP_SETPPCTYPE setppctype /**< type of constraint: set partitioning, packing, or covering constraint */
562  )
563 {
564  assert(consdata != NULL);
565  assert(nvars == 0 || vars != NULL);
566 
567  SCIP_CALL( SCIPallocBlockMemory(scip, consdata) );
568 
569  (*consdata)->signature = 0;
570  (*consdata)->row = NULL;
571  (*consdata)->existmultaggr = FALSE;
572  (*consdata)->catchevents = FALSE;
573  (*consdata)->nfixedzeros = 0;
574  (*consdata)->nfixedones = 0;
575 
576  if( nvars > 0 )
577  {
578  int v;
579 
580  /* @todo the setppc constraint handler does not remove fixed variables from its var array; removing those
581  * variables is only possible if we consider the values of nfixedones and nfixedzeros in all propagation methods
582  */
583 #ifdef SCIP_DISABLED_CODE
584 
585  if( SCIPisConsCompressionEnabled(scip) )
586  {
587  SCIP_VAR** varsbuffer;
588  int k;
589 
590  /* allocate temporary buffer storage for active variables */
591  SCIP_CALL( SCIPallocBufferArray(scip, &varsbuffer, nvars) );
592 
593  k = 0;
594  /* collect fixed variables to compress the required memory */
595  for( v = 0; v < nvars; ++v )
596  {
597  assert(SCIPvarIsBinary(vars[v]));
598 
599  /* already fixed variables account as fixed ones or zero, only unfixed are appended */
600  if( SCIPvarGetLbGlobal(vars[v]) > 0.5 )
601  (*consdata)->nfixedones++;
602  else if( SCIPvarGetUbGlobal(vars[v]) < 0.5 )
603  (*consdata)->nfixedzeros++;
604  else
605  varsbuffer[k++] = vars[v];
606  }
607 
608  (*consdata)->varssize = k;
609  (*consdata)->nvars = k;
610  /* copy unfixed variables into constraint data */
611  if( k > 0 )
612  {
613  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->vars, varsbuffer, k) );
614  }
615 
616  /* free temporary storage */
617  SCIPfreeBufferArray(scip, &varsbuffer);
618  }
619  else
620 #endif
621  {
622  /* for uncompressed copies, simply duplicate the whole array */
623  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->vars, vars, nvars) );
624  (*consdata)->varssize = nvars;
625  (*consdata)->nvars = nvars;
626  }
627 
628  if( SCIPisTransformed(scip) )
629  {
630  /* get transformed variables */
631  SCIP_CALL( SCIPgetTransformedVars(scip, (*consdata)->nvars, (*consdata)->vars, (*consdata)->vars) );
632 
633  /* check for multi-aggregations and capture variables */
634  for( v = 0; v < (*consdata)->nvars; v++ )
635  {
636  SCIP_VAR* var = SCIPvarGetProbvar((*consdata)->vars[v]);
637  assert(var != NULL);
638  (*consdata)->existmultaggr = (*consdata)->existmultaggr || (SCIPvarGetStatus(var) == SCIP_VARSTATUS_MULTAGGR);
639  SCIP_CALL( SCIPcaptureVar(scip, (*consdata)->vars[v]) );
640  }
641  }
642  else
643  {
644  /* capture variables */
645  for( v = 0; v < (*consdata)->nvars; v++ )
646  {
647  assert((*consdata)->vars[v] != NULL);
648  SCIP_CALL( SCIPcaptureVar(scip, (*consdata)->vars[v]) );
649  }
650  }
651  }
652  else
653  {
654  (*consdata)->vars = NULL;
655  (*consdata)->varssize = 0;
656  (*consdata)->nvars = 0;
657  }
658  (*consdata)->setppctype = setppctype; /*lint !e641*/
659  (*consdata)->sorted = (nvars <= 1);
660  (*consdata)->cliqueadded = FALSE;
661  (*consdata)->validsignature = FALSE;
662  (*consdata)->changed = TRUE;
663  (*consdata)->varsdeleted = FALSE;
664  (*consdata)->merged = FALSE;
665  (*consdata)->presolpropagated = FALSE;
666 
667  return SCIP_OKAY;
668 }
669 
670 /** creates a transformed set partitioning / packing / covering constraint data object */
671 static
673  SCIP* scip, /**< SCIP data structure */
674  SCIP_CONSDATA** consdata, /**< pointer to store the set partitioning / packing / covering constraint */
675  int nvars, /**< number of variables in the constraint */
676  SCIP_VAR** vars, /**< variables of the constraint */
677  SCIP_SETPPCTYPE setppctype /**< type of constraint: set partitioning, packing, or covering constraint */
678  )
679 {
680  assert(consdata != NULL);
681  assert(nvars == 0 || vars != NULL);
682 
683  /* create constraint data */
684  SCIP_CALL( consdataCreate(scip, consdata, nvars, vars, setppctype) );
685 
686  /* transform the variables */
687  SCIP_CALL( SCIPgetTransformedVars(scip, (*consdata)->nvars, (*consdata)->vars, (*consdata)->vars) );
688 
689  return SCIP_OKAY;
690 }
691 
692 /** frees a set partitioning / packing / covering constraint data */
693 static
695  SCIP* scip, /**< SCIP data structure */
696  SCIP_CONSDATA** consdata /**< pointer to store the set partitioning / packing / covering constraint */
697  )
698 {
699  int v;
700 
701  assert(consdata != NULL);
702  assert(*consdata != NULL);
703 
704  /* release the row */
705  if( (*consdata)->row != NULL )
706  {
707  SCIP_CALL( SCIPreleaseRow(scip, &(*consdata)->row) );
708  }
709 
710  /* release variables */
711  for( v = 0; v < (*consdata)->nvars; v++ )
712  {
713  assert((*consdata)->vars[v] != NULL);
714  SCIP_CALL( SCIPreleaseVar(scip, &((*consdata)->vars[v])) );
715  }
716 
717  SCIPfreeBlockMemoryArrayNull(scip, &(*consdata)->vars, (*consdata)->varssize);
718  SCIPfreeBlockMemory(scip, consdata);
719 
720  return SCIP_OKAY;
721 }
722 
723 /** prints set partitioning / packing / covering constraint to file stream */
724 static
726  SCIP* scip, /**< SCIP data structure */
727  SCIP_CONSDATA* consdata, /**< set partitioning / packing / covering constraint data */
728  FILE* file /**< output file (or NULL for standard output) */
729  )
730 {
731  assert(consdata != NULL);
732 
733  /* print coefficients */
734  if( consdata->nvars == 0 )
735  SCIPinfoMessage(scip, file, "0 ");
736 
737  /* write linear sum */
738  SCIP_CALL( SCIPwriteVarsLinearsum(scip, file, consdata->vars, NULL, consdata->nvars, TRUE) );
739 
740  /* print right hand side */
741  switch( consdata->setppctype )
742  {
744  SCIPinfoMessage(scip, file, " == 1");
745  break;
747  SCIPinfoMessage(scip, file, " <= 1");
748  break;
750  SCIPinfoMessage(scip, file, " >= 1");
751  break;
752  default:
753  SCIPerrorMessage("unknown setppc type\n");
754  return SCIP_ERROR;
755  }
756 
757  return SCIP_OKAY;
758 }
759 
760 /** returns the bit signature of the given constraint data */
761 static
762 uint64_t consdataGetSignature(
763  SCIP_CONSDATA* consdata /**< set partitioning / packing / covering constraint data */
764  )
765 {
766  assert(consdata != NULL);
767 
768  if( !consdata->validsignature )
769  {
770  int i;
771 
772  consdata->signature = 0;
773  for( i = 0; i < consdata->nvars; ++i )
774  consdata->signature |= SCIPhashSignature64(SCIPvarGetIndex(consdata->vars[i]));
775  consdata->validsignature = TRUE;
776  }
777 
778  return consdata->signature;
779 }
780 
781 /** sorts setppc constraint's variables by non-decreasing variable index */
782 static
783 void consdataSort(
784  SCIP_CONSDATA* consdata /**< linear constraint data */
785  )
786 {
787  assert(consdata != NULL);
788 
789  if( !consdata->sorted )
790  {
791  if( consdata->nvars <= 1 )
792  consdata->sorted = TRUE;
793  else
794  {
795  SCIPsortPtr((void**)consdata->vars, SCIPvarComp, consdata->nvars);
796  consdata->sorted = TRUE;
797  }
798  }
799  assert(consdata->sorted);
800 #ifdef SCIP_DEBUG
801  /* check sorting */
802  {
803  int v;
804 
805  for( v = 0; v < consdata->nvars; ++v )
806  {
807  assert(v == consdata->nvars-1 || SCIPvarCompare(consdata->vars[v], consdata->vars[v+1]) <= 0);
808  }
809  }
810 #endif
811 }
812 
813 /** changes the type of a setppc constraint */
814 static
816  SCIP* scip, /**< SCIP data structure */
817  SCIP_CONS* cons, /**< setppc constraint */
818  SCIP_SETPPCTYPE setppctype /**< new type of constraint */
819  )
820 {
821  SCIP_CONSHDLR* conshdlr;
822  SCIP_CONSHDLRDATA* conshdlrdata;
823  SCIP_CONSDATA* consdata;
824  SCIP_Bool locked;
825  int i;
826 
827  consdata = SCIPconsGetData(cons);
828  assert(consdata != NULL);
829 
830  if( (SCIP_SETPPCTYPE)consdata->setppctype == setppctype )
831  return SCIP_OKAY;
832 
833  SCIPdebugMsg(scip, " -> converting <%s> into setppc type %d\n", SCIPconsGetName(cons), setppctype);
834 
835  /* remove rounding locks */
836  locked = FALSE;
837  for( i = 0; i < NLOCKTYPES && !locked; i++ )
838  locked = SCIPconsIsLockedType(cons, (SCIP_LOCKTYPE) i);
839 
840  if( locked )
841  {
842  for( i = 0; i < consdata->nvars; ++i )
843  {
844  SCIP_CALL( unlockRounding(scip, cons, consdata->vars[i]) );
845  }
846  }
847 
848  conshdlr = SCIPconsGetHdlr(cons);
849  assert(conshdlr != NULL);
850  conshdlrdata = SCIPconshdlrGetData(conshdlr);
851  assert(conshdlrdata != NULL);
852 
853  if( SCIPisTransformed(scip) )
854  {
855  if( setppctype == SCIP_SETPPCTYPE_PARTITIONING )
856  {
857  ++(conshdlrdata->nsetpart);
858  assert(conshdlrdata->nsetpart >= 0);
859  }
860  else if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
861  {
862  --(conshdlrdata->nsetpart);
863  assert(conshdlrdata->nsetpart >= 0);
864  }
865  }
866 
867  /* change the constraint type */
868  consdata->setppctype = setppctype; /*lint !e641*/
869 
870  /* reinstall rounding locks again */
871  if( locked )
872  {
873  for( i = 0; i < consdata->nvars; ++i )
874  {
875  SCIP_CALL( lockRounding(scip, cons, consdata->vars[i]) );
876  }
877  }
878 
879  /* remember that we changed a constraint type for clique lifting procedure */
880  if( setppctype != SCIP_SETPPCTYPE_COVERING )
881  conshdlrdata->updatedsetppctype = TRUE;
882 
883  return SCIP_OKAY;
884 }
885 
886 /** catches events for variable at given position */
887 static
889  SCIP* scip, /**< SCIP data structure */
890  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
891  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
892  int pos /**< array position of variable to catch bound change events for */
893  )
894 {
895  SCIP_CONSDATA* consdata;
896  SCIP_EVENTTYPE eventtype;
897  SCIP_VAR* var;
898 
899  consdata = SCIPconsGetData(cons);
900  assert(consdata != NULL);
901  assert(eventhdlr != NULL);
902  assert(0 <= pos && pos < consdata->nvars);
903  assert(consdata->vars != NULL);
904 
905  var = consdata->vars[pos];
906  assert(var != NULL);
907 
908  /* we are catching the following events:
909  *
910  * - SCIP_EVENTTYPE_BOUNDCHANGED: Is used to count the number of variable fixed locally to zero and one. That helps
911  * to speed up the propagation
912  *
913  * - SCIP_EVENTTYPE_VARDELETED: Is caught to remove a deleted variable from the constraint
914  *
915  * - SCIP_EVENTTYPE_VARFIXED: Is used to get informed if a variable of the constraint was aggregated which means was
916  * detected to be equal or a negated variable of on other variable. in case of a negation
917  * this could lead to a redundant constraint if the (other) active variable is also part
918  * of the constraint.
919  */
921 
922  /* catch bound change events on variable */
923  SCIP_CALL( SCIPcatchVarEvent(scip, var, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, NULL) );
924 
925  /* update the fixed variables counters for this variable */
926  if( SCIPisEQ(scip, SCIPvarGetUbLocal(var), 0.0) )
927  {
928  consdata->nfixedzeros++;
929 
930  /* during presolving, we may fix the last unfixed variable or do an aggregation if there are two unfixed variables */
931  if( SCIPconsIsActive(cons) && ((SCIPgetStage(scip) < SCIP_STAGE_INITSOLVE) && (consdata->nfixedzeros >= consdata->nvars - 2)) )
932  {
933  consdata->presolpropagated = FALSE;
934 
935  /* during solving, we only propagate again if there is only one unfixed variable left */
936  if( consdata->nfixedzeros >= consdata->nvars - 1 )
937  {
938  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
939  }
940  }
941  }
942  else if( SCIPisEQ(scip, SCIPvarGetLbLocal(var), 1.0) )
943  {
944  consdata->nfixedones++;
945 
946  if( SCIPconsIsActive(cons) )
947  {
948  consdata->presolpropagated = FALSE;
949  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
950  }
951  }
952 
953  return SCIP_OKAY;
954 }
955 
956 /** drops events for variable at given position */
957 static
959  SCIP* scip, /**< SCIP data structure */
960  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
961  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
962  int pos /**< array position of variable to catch bound change events for */
963  )
964 {
965  SCIP_CONSDATA* consdata;
966  SCIP_EVENTTYPE eventtype;
967  SCIP_VAR* var;
968 
969  consdata = SCIPconsGetData(cons);
970  assert(consdata != NULL);
971  assert(eventhdlr != NULL);
972  assert(0 <= pos && pos < consdata->nvars);
973  assert(consdata->vars != NULL);
974 
975  var = consdata->vars[pos];
976  assert(var != NULL);
977 
979 
980  /* drop events on variable */
981  SCIP_CALL( SCIPdropVarEvent(scip, var, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, -1) );
982 
983  /* update the fixed variables counters for this variable */
984  if( SCIPisEQ(scip, SCIPvarGetUbLocal(var), 0.0) )
985  consdata->nfixedzeros--;
986  else if( SCIPisEQ(scip, SCIPvarGetLbLocal(var), 1.0) )
987  consdata->nfixedones--;
988 
989  return SCIP_OKAY;
990 }
991 
992 /** catches bound change events for all variables in transformed setppc constraint */
993 static
995  SCIP* scip, /**< SCIP data structure */
996  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
997  SCIP_EVENTHDLR* eventhdlr /**< event handler to call for the event processing */
998  )
999 {
1000  SCIP_CONSDATA* consdata;
1001  int i;
1003  consdata = SCIPconsGetData(cons);
1004  assert(consdata != NULL);
1005 
1006  if( consdata->catchevents == TRUE )
1007  return SCIP_OKAY;
1008 
1009  /* catch event for every single variable */
1010  for( i = 0; i < consdata->nvars; ++i )
1011  {
1012  SCIP_CALL( catchEvent(scip, cons, eventhdlr, i) );
1013  }
1014 
1015  consdata->catchevents = TRUE;
1016 
1017  return SCIP_OKAY;
1018 }
1019 
1020 /** drops bound change events for all variables in transformed setppc constraint */
1021 static
1023  SCIP* scip, /**< SCIP data structure */
1024  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
1025  SCIP_EVENTHDLR* eventhdlr /**< event handler to call for the event processing */
1026  )
1027 {
1028  SCIP_CONSDATA* consdata;
1029  int i;
1031  consdata = SCIPconsGetData(cons);
1032  assert(consdata != NULL);
1033 
1034  if( consdata->catchevents == FALSE )
1035  return SCIP_OKAY;
1036 
1037  /* drop event of every single variable */
1038  for( i = 0; i < consdata->nvars; ++i )
1039  {
1040  SCIP_CALL( dropEvent(scip, cons, eventhdlr, i) );
1041  }
1042 
1043  consdata->catchevents = FALSE;
1044 
1045  return SCIP_OKAY;
1046 }
1047 
1048 /** adds coefficient in setppc constraint */
1049 static
1051  SCIP* scip, /**< SCIP data structure */
1052  SCIP_CONS* cons, /**< setppc constraint */
1053  SCIP_VAR* var /**< variable to add to the constraint */
1054  )
1055 {
1056  SCIP_CONSDATA* consdata;
1057  SCIP_Bool transformed;
1059  assert(var != NULL);
1060 
1061  consdata = SCIPconsGetData(cons);
1062  assert(consdata != NULL);
1063 
1064  /* are we in the transformed problem? */
1065  transformed = SCIPconsIsTransformed(cons);
1066 
1067  /* always use transformed variables in transformed constraints */
1068  if( transformed )
1069  {
1070  SCIP_CALL( SCIPgetTransformedVar(scip, var, &var) );
1071  }
1072  assert(var != NULL);
1073  assert(transformed == SCIPvarIsTransformed(var));
1074 
1075  SCIP_CALL( consdataEnsureVarsSize(scip, consdata, consdata->nvars+1) );
1076  consdata->vars[consdata->nvars] = var;
1077  consdata->nvars++;
1078  if( consdata->validsignature )
1079  consdata->signature |= SCIPhashSignature64(SCIPvarGetIndex(var));
1080  consdata->sorted = (consdata->nvars == 1);
1081  consdata->changed = TRUE;
1082 
1083  /* capture the variable */
1084  SCIP_CALL( SCIPcaptureVar(scip, var) );
1085 
1086  /* if we are in transformed problem, catch the variable's events */
1087  if( transformed )
1088  {
1089  SCIP_CONSHDLR* conshdlr;
1090  SCIP_CONSHDLRDATA* conshdlrdata;
1091 
1092  /* get event handler */
1093  conshdlr = SCIPconsGetHdlr(cons);
1094  assert(conshdlr != NULL);
1095  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1096  assert(conshdlrdata != NULL);
1097  assert(conshdlrdata->eventhdlr != NULL);
1098 
1099  /* catch bound change events of variable */
1100  if( consdata->catchevents )
1101  {
1102  SCIP_CALL( catchEvent(scip, cons, conshdlrdata->eventhdlr, consdata->nvars-1) );
1103  }
1104 
1105  if( !consdata->existmultaggr && SCIPvarGetStatus(SCIPvarGetProbvar(var)) == SCIP_VARSTATUS_MULTAGGR )
1106  consdata->existmultaggr = TRUE;
1107 
1108 #ifdef VARUSES
1109  /* if the constraint is currently active, increase the variable usage counter */
1110  if( SCIPconsIsActive(cons) )
1111  {
1112  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var) );
1113  }
1114 #endif
1115  }
1116 
1117  /* install the rounding locks for the new variable */
1118  SCIP_CALL( lockRounding(scip, cons, var) );
1119 
1120  /* add the new coefficient to the LP row */
1121  if( consdata->row != NULL )
1122  {
1123  SCIP_CALL( SCIPaddVarToRow(scip, consdata->row, var, 1.0) );
1124  }
1125 
1126  consdata->merged = FALSE;
1127  consdata->cliqueadded = FALSE;
1128 
1129  return SCIP_OKAY;
1130 }
1131 
1132 /** deletes coefficient at given position from setppc constraint data */
1133 static
1135  SCIP* scip, /**< SCIP data structure */
1136  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
1137  int pos /**< position of coefficient to delete */
1138  )
1139 {
1140  SCIP_CONSDATA* consdata;
1141  SCIP_VAR* var;
1143  assert(scip != NULL);
1144  assert(cons != NULL);
1145 
1146  consdata = SCIPconsGetData(cons);
1147  assert(consdata != NULL);
1148  assert(0 <= pos && pos < consdata->nvars);
1149 
1150  var = consdata->vars[pos];
1151  assert(var != NULL);
1152  assert(SCIPconsIsTransformed(cons) == SCIPvarIsTransformed(var));
1153 
1154  /* remove the rounding locks for the deleted variable */
1155  SCIP_CALL( unlockRounding(scip, cons, var) );
1156 
1157  /* if we are in transformed problem, delete the event data of the variable */
1158  if( SCIPconsIsTransformed(cons) )
1159  {
1160  SCIP_CONSHDLR* conshdlr;
1161  SCIP_CONSHDLRDATA* conshdlrdata;
1162 
1163  /* get event handler */
1164  conshdlr = SCIPconsGetHdlr(cons);
1165  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1166  assert(conshdlrdata != NULL);
1167  assert(conshdlrdata->eventhdlr != NULL);
1168 
1169  /* drop bound change events of variable */
1170  if( consdata->catchevents )
1171  {
1172  SCIP_CALL( dropEvent(scip, cons, conshdlrdata->eventhdlr, pos) );
1173  }
1174 
1175  /* the last variable of the constraint was deleted; mark it for propagation (so that it can be deleted) */
1176  if( consdata->nvars == 1 )
1177  {
1178  consdata->presolpropagated = FALSE;
1179  }
1180  }
1181 
1182  /* delete coefficient from the LP row */
1183  if( consdata->row != NULL )
1184  {
1185  SCIP_CALL( SCIPaddVarToRow(scip, consdata->row, var, -1.0) );
1186  }
1187 
1188  /* move the last variable to the free slot */
1189  if( pos != consdata->nvars - 1 )
1190  {
1191  consdata->vars[pos] = consdata->vars[consdata->nvars-1];
1192  consdata->sorted = FALSE;
1193  }
1194  consdata->nvars--;
1195  consdata->validsignature = FALSE;
1196  consdata->changed = TRUE;
1197 
1198  /* release variable */
1199  SCIP_CALL( SCIPreleaseVar(scip, &var) );
1200 
1201  return SCIP_OKAY;
1202 }
1203 
1204 /** in case a part (more than one variable) in the setppc constraint is independent of every else (is locked only by
1205  * this constraint), we can perform dual reductions;
1206  *
1207  * (1) set covering
1208  *
1209  * - fix all independent variables with negative object coefficient to one
1210  * - fix all remaining independent variables to zero
1211  *
1212  * (i) all variables are independent and the constraint is not modifiable
1213  *
1214  * - fix the variable with the smallest object coefficient to one
1215  *
1216  * (ii) a variable x has exactly 0 uplocks and arbitrary downlocks and a variable y has exactly 1 downlock and
1217  * arbitrary uplocks and obj(x) <= obj(y) and obj(y) >= 0
1218  *
1219  * - fix y to 0, because it is dominated by x
1220  *
1221  * (2) set partitioning
1222  *
1223  * (i) all variables are independent and the constraint is not modifiable
1224  *
1225  * - fix the variable with the smallest object coefficient to one
1226  * - fix all remaining independent variables to zero
1227  *
1228  * (ii) a variable x has exactly 1 uplock and arbitrary downlocks and a variable y has exactly 1 downlock and
1229  * arbitrary uplocks and obj(x) <= obj(y)
1230  *
1231  * - fix y to 0, because it is dominated by x
1232  *
1233  * (3) set packing
1234  *
1235  * (i) all variables are independent and the constraint is not modifiable
1236  *
1237  * - fix the variable with the smallest object coefficient to one if the object coefficient is negative or zero
1238  * - fix all remaining independent variables to zero
1239  *
1240  * (ii) a variable x has exactly 1 uplock and arbitrary downlocks and a variable y has exactly 0 downlocks and
1241  * arbitrary uplocks and obj(x) <= obj(y)
1242  *
1243  * - fix y to 0, because it is dominated by x
1244  *
1245  *
1246  * Note: the following dual reduction for set covering and set packing constraints is already performed by the presolver
1247  * "dualfix"
1248  * (1) in case of a set covering constraint the following dual reduction can be performed:
1249  * - if a variable in a set covering constraint is only locked by that constraint and has negative or zero
1250  * objective coefficient than it can be fixed to one
1251  * (2) in case of a set packing constraint the following dual reduction can be performed:
1252  * - if a variable in a set packing constraint is only locked by that constraint and has positive or zero
1253  * objective coefficient than it can be fixed to zero
1254  *
1255  * Note: all dual reduction (ii) could also be performed by the "domcol" presolver, but cause the pairwise comparison of
1256  * columns is only done heuristically (and here it should be even cheaper) we perform them here (too)
1257  *
1258  */
1259 static
1261  SCIP* scip, /**< SCIP data structure */
1262  SCIP_CONS* cons, /**< setppc constraint */
1263  int* nfixedvars, /**< pointer to count number of fixings */
1264  int* ndelconss, /**< pointer to count number of deleted constraints */
1265  SCIP_RESULT* result /**< pointer to store the result SCIP_SUCCESS, if presolving was performed */
1266  )
1267 {
1268  SCIP_CONSDATA* consdata;
1269  SCIP_SETPPCTYPE setppctype;
1270  SCIP_VAR** vars;
1271  SCIP_VAR* activevar;
1272  SCIP_VAR* var;
1273  SCIP_Real bestobjval;
1274  SCIP_Real objval;
1275  SCIP_Real fixval;
1276  SCIP_Bool infeasible;
1277  SCIP_Bool fixed;
1278  SCIP_Bool negated;
1279  int noldfixed;
1280  int nposfixings;
1281  int nlockdowns;
1282  int nlockups;
1283  int nvars;
1284  int idx;
1285  int v;
1286 
1287  assert(scip != NULL);
1288  assert(cons != NULL);
1289  assert(nfixedvars != NULL);
1290  assert(ndelconss != NULL);
1291  assert(result != NULL);
1292 
1293  /* constraints for which the check flag is set to FALSE, did not contribute to the lock numbers; therefore, we cannot
1294  * use the locks to decide for a dual reduction using this constraint; for example after a restart the cuts which are
1295  * added to the problems have the check flag set to FALSE
1296  */
1297  if( !SCIPconsIsChecked(cons) )
1298  return SCIP_OKAY;
1299 
1300  assert(SCIPconsIsActive(cons));
1301 
1302  consdata = SCIPconsGetData(cons);
1303  assert(consdata != NULL);
1304 
1305  /* modifiable non-covering constraints cannot be deleted if one variable is fixed to one, because the propagation for
1306  * newly inserted variables must be considered later
1307  */
1308  if( consdata->nfixedones == 1 && SCIPconsIsModifiable(cons) )
1309  return SCIP_OKAY;
1310 
1311  /* all fixed variables should be removed at that point */
1312  assert(consdata->nfixedones == 0);
1313  assert(consdata->nfixedzeros == 0);
1314 
1315  nvars = consdata->nvars;
1316 
1317  /* we don't want to consider small constraints (note that the constraints can be modifiable, so we can't delete this
1318  * constraint)
1319  */
1320  if( nvars < 2 )
1321  return SCIP_OKAY;
1322 
1323  setppctype = (SCIP_SETPPCTYPE)consdata->setppctype;
1324  vars = consdata->vars;
1325  idx = -1;
1326  bestobjval = SCIP_INVALID;
1327 
1328  /* collect the rounding locks depending on the setppc type */
1329  switch( setppctype )
1330  {
1332  nlockdowns = 1;
1333  nlockups = 1;
1334  break;
1336  nlockdowns = 0;
1337  nlockups = 1;
1338  break;
1340  nlockdowns = 1;
1341  nlockups = 0;
1342  break;
1343  default:
1344  SCIPerrorMessage("unknown setppc type\n");
1345  SCIPABORT();
1346  return SCIP_INVALIDDATA; /*lint !e527*/
1347  }
1348 
1349  nposfixings = 0;
1350 
1351  /* check if we can apply the dual reduction; therefore count the number of variables where the setppc has the only
1352  * locks on this constraint
1353  */
1354  for( v = 0; v < nvars; ++v )
1355  {
1356  var = vars[v];
1357  assert(var != NULL);
1358 
1359  /* the variable should not be (globally) fixed */
1360  assert(SCIPvarGetLbGlobal(var) < 0.5 && SCIPvarGetUbGlobal(var) > 0.5);
1361 
1362  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) >= nlockdowns
1363  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) == nlockups )
1364  {
1365  activevar = var;
1366  negated = FALSE;
1367 
1368  /* get the active variable */
1369  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
1370  assert(SCIPvarIsActive(activevar));
1371 
1372  if( negated )
1373  objval = -SCIPvarGetObj(activevar);
1374  else
1375  objval = SCIPvarGetObj(activevar);
1376 
1377  /* check if the current variable has a smaller objective coefficient */
1378  if( idx == -1 || objval < bestobjval )
1379  {
1380  idx = v;
1381  bestobjval = objval;
1382  }
1383  }
1384 
1385  /* in case another constraint has also downlocks on that variable we cannot perform a dual reduction on these
1386  * variables
1387  */
1388  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == nlockdowns
1389  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) >= nlockups )
1390  ++nposfixings;
1391  }
1392 
1393  if( idx == -1 || nposfixings == 0 )
1394  return SCIP_OKAY;
1395 
1396  SCIPdebugMsg(scip, "dual fixing constraint: \n");
1397  SCIPdebug( SCIP_CALL( SCIPprintCons(scip, cons, NULL) ) );
1398  SCIPdebug( SCIPinfoMessage(scip, NULL, "\n") );
1399 
1400  assert(idx >= 0 && idx < nvars);
1401  assert(bestobjval < SCIPinfinity(scip));
1402 
1403  noldfixed = *nfixedvars;
1404 
1405  /* in case of set packing and set partitioning we fix the dominated variables to zero */
1406  if( setppctype != SCIP_SETPPCTYPE_COVERING )
1407  {
1408  /* first part of all variables */
1409  for( v = nvars - 1; v >= 0; --v )
1410  {
1411  if( v == idx )
1412  continue;
1413 
1414  var = vars[v];
1415  assert(var != NULL);
1416 
1417  /* in case another constraint has also downlocks on that variable we cannot perform a dual reduction on these
1418  * variables
1419  */
1420  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == nlockdowns
1421  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) >= nlockups )
1422  {
1423  activevar = var;
1424  negated = FALSE;
1425 
1426  /* get the active variable */
1427  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
1428  assert(SCIPvarIsActive(activevar));
1429 
1430  if( negated )
1431  objval = -SCIPvarGetObj(activevar);
1432  else
1433  objval = SCIPvarGetObj(activevar);
1434 
1435  if( objval >= bestobjval )
1436  {
1437  SCIP_CALL( SCIPfixVar(scip, var, 0.0, &infeasible, &fixed) );
1438  assert(!infeasible);
1439  assert(fixed);
1440 
1441  SCIPdebugMsg(scip, " -> dual-fixed dominated variable <%s> == 0.0\n", SCIPvarGetName(var));
1442  ++(*nfixedvars);
1443  }
1444  }
1445  }
1446  }
1447  /* if we got a set covering constraint and not all variables are locked from this constraint it might not get
1448  * redundant (which is case if it is not possible to fix at least one variable to one), we fix all redundant
1449  * variables to their best bound
1450  */
1451  else
1452  {
1453  /* first part of all variables */
1454  for( v = nvars - 1; v >= 0; --v )
1455  {
1456  if( v == idx )
1457  continue;
1458 
1459  var = vars[v];
1460  assert(var != NULL);
1461 
1462  /* in case another constraint has also downlocks on that variable we cannot perform a dual reduction on these
1463  * variables
1464  */
1465  if( SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) == nlockdowns
1466  && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) >= nlockups )
1467  {
1468  activevar = var;
1469  negated = FALSE;
1470 
1471  /* get the active variable */
1472  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
1473  assert(SCIPvarIsActive(activevar));
1474  assert(negated
1477  assert(!negated
1480 
1481  if( negated )
1482  objval = -SCIPvarGetObj(activevar);
1483  else
1484  objval = SCIPvarGetObj(activevar);
1485 
1486  if( objval > 0.0 )
1487  fixval = 0.0;
1488  else
1489  fixval = 1.0;
1490 
1491  /* if variables has a negative objective contribution, and is uplocked by another constraint we cannot fix
1492  * the variables to 1
1493  */
1494  if( (fixval == 1.0 && SCIPvarGetNLocksUpType(var, SCIP_LOCKTYPE_MODEL) > nlockups) || objval < bestobjval )
1495  continue;
1496 
1497  SCIP_CALL( SCIPfixVar(scip, var, fixval, &infeasible, &fixed) );
1498  assert(!infeasible);
1499  assert(fixed);
1500 
1501  SCIPdebugMsg(scip, " -> dual-fixed dominated variable <%s> == %g\n", SCIPvarGetName(var), fixval);
1502  ++(*nfixedvars);
1503  }
1504  }
1505  }
1506 
1507  /* if all variables but the domination variable is fixed and the constraint is not modifiables or the constraint is a
1508  * covering constraint and the bestobjval is less than or equal to zero, we can fix the domination variable (with best
1509  * objective coefficient) and the constraint gets redundant
1510  */
1511  if( ((*nfixedvars - noldfixed == nvars - 1) && !SCIPconsIsModifiable(cons)) || (setppctype == SCIP_SETPPCTYPE_COVERING && bestobjval <= 0.0) )
1512  {
1513  /* in case of a set packing constraint with positive objective values, all variables can be fixed to zero; in all
1514  * other cases the variable with the smallest objective values is fixed to one
1515  */
1516  if( (setppctype == SCIP_SETPPCTYPE_PACKING && bestobjval > 0.0
1517  && SCIPvarGetNLocksDownType(vars[idx], SCIP_LOCKTYPE_MODEL) == 0)
1518  || setppctype != SCIP_SETPPCTYPE_PACKING || bestobjval <= 0.0 )
1519  {
1520  if( setppctype == SCIP_SETPPCTYPE_PACKING && bestobjval > 0.0 )
1521  fixval = 0.0;
1522  else
1523  fixval = 1.0;
1524 
1525  SCIP_CALL( SCIPfixVar(scip, vars[idx], fixval, &infeasible, &fixed) );
1526  assert(!infeasible);
1527  assert(fixed);
1528 
1529  SCIPdebugMsg(scip, " -> dual-fixed best variable <%s> == %g\n", SCIPvarGetName(vars[idx]), fixval);
1530  ++(*nfixedvars);
1531  }
1532 
1533  /* check that we really have a non-violated constraint in hand before deleting */
1534  assert((setppctype == SCIP_SETPPCTYPE_PACKING && consdata->nfixedones <= 1) ||
1535  (setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata->nfixedones == 1) ||
1536  (setppctype == SCIP_SETPPCTYPE_COVERING && consdata->nfixedones >= 1));
1537 
1538  /* remove constraint since it is redundant */
1539  SCIP_CALL( SCIPdelCons(scip, cons) );
1540  ++(*ndelconss);
1541  }
1542 
1543  assert(*nfixedvars >= noldfixed);
1544 
1545  /* set result pointer to SCIP_SUCCESS, if variables could be fixed */
1546  if( *nfixedvars != noldfixed )
1547  *result = SCIP_SUCCESS;
1548 
1549  return SCIP_OKAY;
1550 }
1551 
1552 /** find pairs of negated variables in constraint:
1553  * partitioning/packing: all other variables must be zero, constraint is redundant
1554  * covering: constraint is redundant
1555  *
1556  * find sets of equal variables in constraint:
1557  * partitioning/packing: variable must be zero
1558  * covering: multiple entries of variable can be replaced by single entry
1559  */
1560 static
1562  SCIP* scip, /**< SCIP data structure */
1563  SCIP_CONS* cons, /**< knapsack constraint */
1564  int* nfixedvars, /**< pointer to store number of fixed variables */
1565  int* ndelconss, /**< pointer to store number of deleted constraints */
1566  int* nchgcoefs, /**< pointer to store number of changed coefficients */
1567  SCIP_Bool* cutoff /**< pointer to store whether a fixing leads to a cutoff */
1568  )
1570  SCIP_CONSDATA* consdata;
1571  int v;
1572 
1573  assert(scip != NULL);
1574  assert(cons != NULL);
1575  assert(nfixedvars != NULL);
1576  assert(ndelconss != NULL);
1577  assert(nchgcoefs != NULL);
1578  assert(cutoff != NULL);
1579 
1580  consdata = SCIPconsGetData(cons);
1581  assert(consdata != NULL);
1582 
1583  if( consdata->merged || SCIPconsIsDeleted(cons) )
1584  return SCIP_OKAY;
1585 
1586  if( consdata->nvars <= 1 )
1587  {
1588  consdata->merged = TRUE;
1589  return SCIP_OKAY;
1590  }
1591 
1592  assert(consdata->vars != NULL || consdata->nvars == 0);
1593 
1594  /* sorting array after indices of variables, that's only for faster merging */
1595  SCIPsortPtr((void**)consdata->vars, SCIPvarCompActiveAndNegated, consdata->nvars);
1596  /* setppc sorting now lost */
1597  consdata->sorted = FALSE;
1598 
1599  /* loop backwards through the items: deletion only affects rear items */
1600  for( v = consdata->nvars - 1; v > 0; --v )
1601  {
1602  SCIP_VAR* var1;
1603  SCIP_VAR* var2;
1604  SCIP_Bool negated1;
1605  SCIP_Bool negated2;
1606 
1607  negated1 = FALSE;
1608  negated2 = FALSE;
1609 
1610  var1 = consdata->vars[v];
1611  assert(SCIPvarIsBinary(var1));
1614  {
1615  var1 = SCIPvarGetNegatedVar(var1);
1616  negated1 = TRUE;
1617  }
1618  assert(var1 != NULL);
1619 
1620  var2 = consdata->vars[v-1];
1621  assert(SCIPvarIsBinary(var2));
1624  {
1625  var2 = SCIPvarGetNegatedVar(var2);
1626  negated2 = TRUE;
1627  }
1628  assert(var2 != NULL);
1629 
1630  if( var1 == var2 )
1631  {
1632  SCIP_Bool infeasible;
1633  SCIP_Bool fixed;
1634 
1635  /* one variables is active and the other is the same negated variable */
1636  if( negated1 != negated2 )
1637  {
1638  /* all other variable have to be zero if it's a partitioning or packing constraint */
1639  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
1640  {
1641  int i;
1642 
1643  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
1644  || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
1645 
1646  for( i = consdata->nvars - 1; i >= 0; --i )
1647  if( i != v && i != (v-1) )
1648  {
1649  SCIP_CALL( SCIPfixVar(scip, consdata->vars[i], 0.0, &infeasible, &fixed) );
1650  if( infeasible )
1651  {
1652  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 0\n",
1653  SCIPconsGetName(cons), SCIPvarGetName(consdata->vars[i]));
1654  *cutoff = TRUE;
1655  return SCIP_OKAY;
1656  }
1657 
1658  if( fixed )
1659  ++(*nfixedvars);
1660  }
1661  }
1662  /* all setppc-type constraints are redundant */
1663  SCIP_CALL( SCIPdelCons(scip, cons) );
1664  ++(*ndelconss);
1665  return SCIP_OKAY;
1666  }
1667  /* both variables are either active or negated */
1668  else
1669  {
1670  /* this variable can be fixed to zero if it's a partitioning or packing constraint */
1671  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
1672  {
1673  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
1674  || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
1675 
1676  SCIP_CALL( SCIPfixVar(scip, var1, negated1 ? 1.0 : 0.0, &infeasible, &fixed) );
1677  if( infeasible )
1678  {
1679  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == %g\n",
1680  SCIPconsGetName(cons), SCIPvarGetName(var1), negated1 ? 1.0 : 0.0);
1681  *cutoff = TRUE;
1682  return SCIP_OKAY;
1683  }
1684 
1685  if( fixed )
1686  ++(*nfixedvars);
1687  }
1688  /* multiple entries of variable can be replaced by single entry */
1689  else
1690  {
1691  SCIP_CALL( delCoefPos(scip, cons, v) ); /* only some changed behind position v-1, so it's okay */
1692  ++(*nchgcoefs);
1693  }
1694  }
1695  consdata->changed = TRUE;
1696  }
1697  }
1698  consdata->merged = TRUE;
1699 
1700  return SCIP_OKAY;
1701 }
1702 
1703 /** deletes all zero-fixed variables and replace aggregated variables */
1704 static
1706  SCIP* scip, /**< SCIP data structure */
1707  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint */
1708  int* naddconss, /**< pointer to count number of added constraints, or NULL indicating we
1709  * can not resolve multi-aggregations
1710  */
1711  int* ndelconss, /**< pointer to count number of deleted constraints, or NULL indicating we
1712  * can not resolve multi-aggregations
1713  */
1714  int* nfixedvars, /**< pointer to store number of fixed variables, or NULL indicating we can
1715  * not resolve multi-aggregations
1716  */
1717  SCIP_Bool* cutoff /**< pointer to store whether a fixing leads to a cutoff, or NULL
1718  * indicating we can not resolve multi-aggregations
1719  */
1720  )
1721 {
1722  SCIP_CONSDATA* consdata;
1723  int v;
1724 
1725  assert(scip != NULL);
1726  assert(cons != NULL);
1727 
1728  consdata = SCIPconsGetData(cons);
1729  assert(consdata != NULL);
1730 
1731  /* all multi-aggregations should be resolved */
1732  consdata->existmultaggr = FALSE;
1733 
1734  v = 0;
1735  while( v < consdata->nvars )
1736  {
1737  SCIP_VAR* var;
1738 
1739  var = consdata->vars[v];
1740  assert(SCIPvarIsBinary(var));
1741 
1742  if( SCIPvarGetUbGlobal(var) < 0.5 )
1743  {
1744  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(var), 0.0));
1745  SCIP_CALL( delCoefPos(scip, cons, v) );
1746  }
1747  else
1748  {
1749  SCIP_VAR* repvar;
1750  SCIP_Bool negated;
1751 
1752  /* get binary representative of variable */
1753  SCIP_CALL( SCIPgetBinvarRepresentative(scip, var, &repvar, &negated) );
1754 
1755  /* resolve multi-aggregation */
1757  {
1758  SCIP_VAR** consvars;
1759  SCIP_Real* consvals;
1760  SCIP_Real constant = 0.0;
1761  SCIP_Bool easycase;
1762  int nconsvars;
1763  int requiredsize;
1764  int v2;
1765 
1766  nconsvars = 1;
1767  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 1) );
1768  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 1) );
1769  consvars[0] = repvar;
1770  consvals[0] = 1.0;
1771 
1772  /* get active variables for new constraint */
1773  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, nconsvars, &constant, &requiredsize, TRUE) );
1774  /* if space was not enough we need to resize the buffers */
1775  if( requiredsize > nconsvars )
1776  {
1777  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, requiredsize) );
1778  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) );
1779 
1780  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize, TRUE) );
1781  assert(requiredsize <= nconsvars);
1782  }
1783 
1784  easycase = FALSE;
1785 
1786  if( SCIPisZero(scip, constant) )
1787  {
1788  /* add active representation */
1789  for( v2 = nconsvars - 1; v2 >= 0; --v2 )
1790  {
1791  if( !SCIPvarIsBinary(consvars[v2]) )
1792  {
1793  break;
1794 #if 0
1795  SCIPerrorMessage("try to resolve a multi-aggregation with a non-binary variable <%s>\n", consvars[v2]);
1796  return SCIP_ERROR;
1797 #endif
1798  }
1799 
1800  if( !SCIPisEQ(scip, consvals[v2], 1.0) )
1801  break;
1802  }
1803 
1804  if( v2 < 0 )
1805  easycase = TRUE;
1806  }
1807  else if( SCIPisFeasEQ(scip, constant, 1.0) )
1808  {
1809  /* check for another multi-aggregation */
1810  for( v2 = consdata->nvars - 1; v2 > v; --v2 )
1811  {
1812  if( SCIPvarGetStatus(SCIPvarGetProbvar(consdata->vars[v])) == SCIP_VARSTATUS_MULTAGGR )
1813  break;
1814  }
1815 
1816  /* constraint is redundant */
1817  if( v2 == v && nconsvars == 0 )
1818  {
1819  /* we can fix */
1820  if( consdata->nvars > 1 && (SCIP_SETPPCTYPE)consdata->setppctype != SCIP_SETPPCTYPE_COVERING )
1821  {
1822  if( nfixedvars != NULL )
1823  {
1824  SCIP_Bool fixed;
1825 
1826  assert(cutoff != NULL);
1827 
1828  for( v2 = consdata->nvars - 1; v2 >= 0; --v2 )
1829  {
1830  if( consdata->vars[v2] != var )
1831  {
1832  SCIPdebugMsg(scip, "trying to fix <%s> to 0 due to at least one variable is already fixed to 1\n", SCIPvarGetName(consdata->vars[v2]));
1833 
1834  /* fix all remaining variables to zero, constraint is already feasible or infeasible */
1835  SCIP_CALL( SCIPfixVar(scip, consdata->vars[v2], 0.0, cutoff, &fixed) );
1836  if( *cutoff )
1837  {
1838  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 0\n",
1839  SCIPconsGetName(cons), SCIPvarGetName(consdata->vars[v2]));
1840 
1841  SCIPfreeBufferArray(scip, &consvals);
1842  SCIPfreeBufferArray(scip, &consvars);
1843 
1844  goto TERMINATE;
1845  }
1846 
1847  if( fixed )
1848  ++(*nfixedvars);
1849  }
1850  }
1851  }
1852  }
1853 
1854  if( ndelconss != NULL && (nfixedvars != NULL || consdata->nvars == 1 || (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING) )
1855  {
1856  /* delete old constraint */
1857  SCIP_CALL( SCIPdelCons(scip, cons) );
1858  ++(*ndelconss);
1859  }
1860  SCIPfreeBufferArray(scip, &consvals);
1861  SCIPfreeBufferArray(scip, &consvars);
1862 
1863  goto TERMINATE;
1864  }
1865  }
1866 
1867  /* we can easily add the coefficients and still have a setppc constraint */
1868  if( easycase )
1869  {
1870  /* delete old (multi-aggregated) variable */
1871  SCIP_CALL( delCoefPos(scip, cons, v) );
1872 
1873  /* add active representation */
1874  for( v2 = nconsvars - 1; v2 >= 0; --v2 )
1875  {
1876  assert(SCIPvarIsBinary(consvars[v2]));
1877  assert(SCIPvarIsActive(consvars[v2]) || (SCIPvarGetStatus(consvars[v2]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(consvars[v2]))));
1878 
1879  SCIP_CALL( addCoef(scip, cons, consvars[v2]) );
1880  }
1881  }
1882  /* we need to degrade this setppc constraint to a linear constraint */
1883  else if( (ndelconss != NULL && naddconss != NULL) || SCIPconsIsAdded(cons) )
1884  {
1885  char name[SCIP_MAXSTRLEN];
1886  SCIP_CONS* newcons;
1887  SCIP_Real lhs;
1888  SCIP_Real rhs;
1889  int size;
1890  int k;
1891 
1892  /* it might happen that there are more than one multi-aggregated variable, so we need to get the whole
1893  * probvar sum over all variables
1894  */
1895 
1896  size = MAX(nconsvars, 1) + consdata->nvars - 1;
1897 
1898  /* memory needed is at least old number of variables - 1 + number of variables in first multi-aggregation */
1899  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, size) );
1900  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, size) );
1901 
1902  nconsvars = consdata->nvars;
1903 
1904  /* add constraint variables to new linear variables */
1905  for( k = consdata->nvars - 1; k >= 0; --k )
1906  {
1907  consvars[k] = consdata->vars[k];
1908  consvals[k] = 1.0;
1909  }
1910 
1911  constant = 0.0;
1912 
1913  /* get active variables for new constraint */
1914  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, size, &constant, &requiredsize, TRUE) );
1915 
1916  /* if space was not enough (we found another multi-aggregation), we need to resize the buffers */
1917  if( requiredsize > nconsvars )
1918  {
1919  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, requiredsize) );
1920  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) );
1921 
1922  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize, TRUE) );
1923  assert(requiredsize <= nconsvars);
1924  }
1925 
1926  /* compute sides */
1927  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
1928  {
1929  lhs = -SCIPinfinity(scip);
1930  rhs = 1.0 - constant;
1931  }
1932  else if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
1933  {
1934  lhs = 1.0 - constant;
1935  rhs = 1.0 - constant;
1936  }
1937  else
1938  {
1939  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING);
1940  lhs = 1.0 - constant;
1941  rhs = SCIPinfinity(scip);
1942  }
1943 
1944  /* create linear constraint */
1945  (void)SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", SCIPconsGetName(cons));
1946  SCIP_CALL( SCIPcreateConsLinear(scip, &newcons, name, nconsvars, consvars, consvals, lhs, rhs,
1947  SCIPconsIsInitial(cons),
1951  SCIP_CALL( SCIPaddCons(scip, newcons) );
1952 
1953  SCIPdebugMsg(scip, "added linear constraint: ");
1954  SCIPdebugPrintCons(scip, newcons, NULL);
1955  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
1956 
1957  SCIPfreeBufferArray(scip, &consvals);
1958  SCIPfreeBufferArray(scip, &consvars);
1959 
1960  /* delete old constraint */
1961  SCIP_CALL( SCIPdelCons(scip, cons) );
1962  if( ndelconss != NULL && naddconss != NULL )
1963  {
1964  ++(*ndelconss);
1965  ++(*naddconss);
1966  }
1967 
1968  goto TERMINATE;
1969  }
1970  /* we need to degrade this setppc constraint to a linear constraint*/
1971  else
1972  {
1973  /* check, if the variable should be replaced with the representative */
1974  if( repvar != var )
1975  {
1976  /* delete old (aggregated) variable */
1977  SCIP_CALL( delCoefPos(scip, cons, v) );
1978 
1979  /* add representative instead */
1980  SCIP_CALL( addCoef(scip, cons, repvar) );
1981  }
1982 
1983  SCIPwarningMessage(scip, "setppc constraint <%s> has a multi-aggregated variable, which was not resolved and therefore could lead to aborts\n", SCIPconsGetName(cons));
1984  ++v;
1985  }
1986 
1987  SCIPfreeBufferArray(scip, &consvals);
1988  SCIPfreeBufferArray(scip, &consvars);
1989  }
1990  else
1991  {
1992  /* check, if the variable should be replaced with the representative */
1993  if( repvar != var )
1994  {
1995  /* delete old (aggregated) variable */
1996  SCIP_CALL( delCoefPos(scip, cons, v) );
1997 
1998  /* add representative instead */
1999  SCIP_CALL( addCoef(scip, cons, repvar) );
2000  }
2001  else
2002  ++v;
2003  }
2004  }
2005  }
2006 
2007  TERMINATE:
2008  /* all multi-aggregations should be resolved */
2009  consdata->existmultaggr = FALSE;
2010 
2011  return SCIP_OKAY;
2012 }
2013 
2014 /** analyzes conflicting assignment on given constraint where all of the variables where assigned to zero,
2015  * and adds conflict constraint to problem
2016  */
2017 static
2019  SCIP* scip, /**< SCIP data structure */
2020  SCIP_CONS* cons /**< set partitioning / packing / covering constraint that detected the conflict */
2021  )
2022 {
2023  SCIP_CONSDATA* consdata;
2024  int v;
2025 
2026  /* conflict analysis can only be applied in solving stage and if it is applicable */
2028  return SCIP_OKAY;
2029 
2030  consdata = SCIPconsGetData(cons);
2031  assert(consdata != NULL);
2032  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
2033  || consdata->setppctype == SCIP_SETPPCTYPE_COVERING); /*lint !e641*/
2034 
2035  /* initialize conflict analysis, and add all variables of infeasible constraint to conflict candidate queue */
2037 
2038  for( v = 0; v < consdata->nvars; ++v )
2039  {
2040  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
2041  }
2042 
2043  /* analyze the conflict */
2044  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
2045 
2046  return SCIP_OKAY;
2047 }
2048 
2049 /** analyzes conflicting assignment on given constraint where two of the variables where assigned to one,
2050  * and adds conflict constraint to problem
2051  */
2052 static
2054  SCIP* scip, /**< SCIP data structure */
2055  SCIP_CONS* cons /**< set partitioning / packing / covering constraint that detected the conflict */
2056  )
2057 {
2058  SCIP_CONSDATA* consdata;
2059  int v;
2060  int n;
2062  /* conflict analysis can only be applied in solving stage and if it is applicable */
2064  return SCIP_OKAY;
2065 
2066  consdata = SCIPconsGetData(cons);
2067  assert(consdata != NULL);
2068  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
2069  || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
2070 
2071  /* initialize conflict analysis, and add the two variables assigned to one to conflict candidate queue */
2073 
2074  n = 0;
2075  for( v = 0; v < consdata->nvars && n < 2; ++v )
2076  {
2077  if( SCIPvarGetLbLocal(consdata->vars[v]) > 0.5 )
2078  {
2079  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
2080  n++;
2081  }
2082  }
2083  assert(n == 2);
2084 
2085  /* analyze the conflict */
2086  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
2087 
2088  return SCIP_OKAY;
2089 }
2090 
2091 /** checks constraint for violation only looking at the fixed variables, applies further fixings if possible */
2092 static
2094  SCIP* scip, /**< SCIP data structure */
2095  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint to be processed */
2096  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
2097  int* nfixedvars, /**< pointer to count number of deleted variables */
2098  SCIP_Bool* addcut, /**< pointer to store whether this constraint must be added as a cut */
2099  SCIP_Bool* mustcheck /**< pointer to store whether this constraint must be checked for feasibility */
2100  )
2102  SCIP_CONSDATA* consdata;
2103 #ifndef NDEBUG
2104  int oldnfixedvars;
2105 #endif
2106 
2107  assert(cons != NULL);
2108  assert(SCIPconsGetHdlr(cons) != NULL);
2109  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
2110  assert(cutoff != NULL);
2111  assert(nfixedvars != NULL);
2112  assert(addcut != NULL);
2113  assert(mustcheck != NULL);
2114 
2115 #ifndef NDEBUG
2116  oldnfixedvars = *nfixedvars;
2117 #endif
2118 
2119  consdata = SCIPconsGetData(cons);
2120  assert(consdata != NULL);
2121  assert(consdata->nvars == 0 || consdata->vars != NULL);
2122  assert(0 <= consdata->nfixedzeros && consdata->nfixedzeros <= consdata->nvars);
2123  assert(0 <= consdata->nfixedones && consdata->nfixedones <= consdata->nvars);
2124 
2125  *addcut = FALSE;
2126  *mustcheck = TRUE;
2127 
2128  /*SCIPdebugMsg(scip, "processing constraint <%s> with respect to fixed variables (%d fixed to 0.0, %d fixed to 1.0)\n",
2129  SCIPconsGetName(cons), consdata->nfixedzeros, consdata->nfixedones);*/
2130 
2131  if( consdata->nfixedones == 1 )
2132  {
2133  /* exactly one variable is fixed to 1:
2134  * - a set covering constraint is feasible anyway and can be disabled
2135  * - all other variables in a set partitioning or packing constraint must be zero
2136  */
2137  if( consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
2138  {
2139  SCIPdebugMsg(scip, " -> disabling set covering constraint <%s>\n", SCIPconsGetName(cons));
2140  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2141  }
2142  else
2143  {
2144  if( consdata->nfixedzeros < consdata->nvars - 1 )
2145  {
2146  SCIP_VAR** vars;
2147  SCIP_VAR* var;
2148 #ifndef NDEBUG
2149  SCIP_Bool fixedonefound;
2150 #endif
2151  SCIP_Bool infeasible;
2152  SCIP_Bool tightened;
2153  int nvars;
2154  int v;
2155  int oneidx = -1;
2156 
2157  SCIPdebugMsg(scip, " -> fixing all other variables to zero in set packing/partitioning constraint <%s>\n",
2158  SCIPconsGetName(cons));
2159 
2160  /* unfixed variables exist: fix them to zero;
2161  * this could result in additional variables fixed to one due to aggregations; in this case, the
2162  * constraint is infeasible in local bounds
2163  */
2164  vars = consdata->vars;
2165  nvars = consdata->nvars;
2166 #ifndef NDEBUG
2167  fixedonefound = FALSE;
2168 #endif
2169  for( v = 0; v < nvars && consdata->nfixedones == 1; ++v )
2170  {
2171  var = vars[v];
2172  assert(SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) || SCIPisFeasEQ(scip, SCIPvarGetUbLocal(var), 1.0));
2173  if( SCIPvarGetLbLocal(var) < 0.5 )
2174  {
2175  SCIP_CALL( SCIPinferBinvarCons(scip, var, FALSE, cons, oneidx, &infeasible, &tightened) );
2176  assert(!infeasible);
2177 
2178  if( tightened )
2179  ++(*nfixedvars);
2180 
2181  SCIPdebugMsg(scip, " -> fixed <%s> to zero (tightened=%u)\n", SCIPvarGetName(var), tightened);
2182  }
2183  else
2184  {
2185 #ifndef NDEBUG
2186  fixedonefound = TRUE;
2187 #endif
2188  oneidx = v;
2189  }
2190  }
2191  /* the fixed to one variable must have been found, and at least one variable must have been fixed */
2192  assert(consdata->nfixedones >= 2 || (fixedonefound && *nfixedvars > oldnfixedvars));
2193 
2194  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2195  }
2196 
2197  /* now all other variables are fixed to zero:
2198  * the constraint is feasible, and if it's not modifiable, it is redundant
2199  */
2200  if( !SCIPconsIsModifiable(cons) && consdata->nfixedones == 1 )
2201  {
2202  SCIPdebugMsg(scip, " -> disabling set packing/partitioning constraint <%s>\n", SCIPconsGetName(cons));
2203  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2204  }
2205  }
2206  *mustcheck = FALSE;
2207  }
2208 
2209  if( consdata->nfixedones >= 2 )
2210  {
2211  /* at least two variables are fixed to 1:
2212  * - a set covering constraint is feasible anyway and can be disabled
2213  * - a set partitioning or packing constraint is infeasible
2214  */
2215  if( consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
2216  {
2217  SCIPdebugMsg(scip, " -> disabling set covering constraint <%s>\n", SCIPconsGetName(cons));
2218  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2219  }
2220  else
2221  {
2222  SCIPdebugMsg(scip, " -> conflict on set packing/partitioning constraint <%s>\n", SCIPconsGetName(cons));
2223 
2224  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2225 
2226  /* use conflict analysis to get a conflict constraint out of the conflicting assignment */
2227  SCIP_CALL( analyzeConflictOne(scip, cons) );
2228 
2229  *cutoff = TRUE;
2230  }
2231  *mustcheck = FALSE;
2232  }
2233  else if( consdata->nfixedzeros == consdata->nvars )
2234  {
2235  /* all variables are fixed to zero:
2236  * - a set packing constraint is feasible anyway, and if it's unmodifiable, it can be disabled
2237  * - a set partitioning or covering constraint is infeasible, and if it's unmodifiable, the node
2238  * can be cut off -- otherwise, the constraint must be added as a cut and further pricing must
2239  * be performed
2240  */
2241  assert(consdata->nfixedones == 0);
2242 
2243  if( consdata->setppctype == SCIP_SETPPCTYPE_PACKING ) /*lint !e641*/
2244  {
2245  if( !SCIPconsIsModifiable(cons) )
2246  {
2247  SCIPdebugMsg(scip, " -> disabling set packing constraint <%s>\n", SCIPconsGetName(cons));
2248  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2249  }
2250  }
2251  else
2252  {
2253  SCIPdebugMsg(scip, " -> set covering/partitioning constraint <%s> is infeasible\n", SCIPconsGetName(cons));
2254 
2255  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2256  if( SCIPconsIsModifiable(cons) )
2257  *addcut = TRUE;
2258  else
2259  {
2260  /* use conflict analysis to get a conflict constraint out of the conflicting assignment */
2261  SCIP_CALL( analyzeConflictZero(scip, cons) );
2262 
2263  *cutoff = TRUE;
2264  }
2265  }
2266  *mustcheck = FALSE;
2267  }
2268  else if( consdata->nfixedzeros == consdata->nvars - 1 && consdata->nfixedones == 0 )
2269  {
2270  /* all variables except one are fixed to zero:
2271  * - a set packing constraint is feasible anyway, and if it's unmodifiable, it can be disabled
2272  * - an unmodifiable set partitioning or covering constraint is feasible and can be disabled after the
2273  * remaining variable is fixed to one
2274  * - a modifiable set partitioning or covering constraint must be checked manually
2275  */
2276  if( consdata->setppctype == SCIP_SETPPCTYPE_PACKING ) /*lint !e641*/
2277  {
2278  if( !SCIPconsIsModifiable(cons) )
2279  {
2280  SCIPdebugMsg(scip, " -> disabling set packing constraint <%s>\n", SCIPconsGetName(cons));
2281  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2282  }
2283  *mustcheck = FALSE;
2284  }
2285  else if( !SCIPconsIsModifiable(cons) )
2286  {
2287  SCIP_VAR** vars;
2288  SCIP_VAR* var;
2289  SCIP_Bool infeasible;
2290  SCIP_Bool tightened;
2291  int nvars;
2292  int v;
2293 
2294  /* search the single variable that can be fixed */
2295  vars = consdata->vars;
2296  nvars = consdata->nvars;
2297  for( v = 0; v < nvars; ++v )
2298  {
2299  var = vars[v];
2300  assert(SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)));
2301  assert(SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) || SCIPisFeasEQ(scip, SCIPvarGetUbLocal(var), 1.0));
2302  if( SCIPvarGetUbLocal(var) > 0.5 )
2303  {
2304  SCIPdebugMsg(scip, " -> fixing remaining variable <%s> to one in set covering/partitioning constraint <%s>\n",
2305  SCIPvarGetName(var), SCIPconsGetName(cons));
2306  SCIP_CALL( SCIPinferBinvarCons(scip, var, TRUE, cons, 0, &infeasible, &tightened) );
2307  assert(!infeasible);
2308  assert(tightened);
2309 
2310  ++(*nfixedvars);
2311  break;
2312  }
2313  }
2314  assert(v < nvars);
2315  assert(consdata->nfixedzeros == consdata->nvars - 1);
2316  assert(consdata->nfixedones == 1);
2317 
2318  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
2319  *mustcheck = FALSE;
2320  }
2321  }
2322  assert(consdata->nfixedzeros + consdata->nfixedones <= consdata->nvars);
2323 
2324  return SCIP_OKAY;
2325 }
2326 
2327 /** checks constraint for violation, returns TRUE iff constraint is feasible */
2328 static
2330  SCIP* scip, /**< SCIP data structure */
2331  SCIP_CONSDATA* consdata, /**< set partitioning / packing / covering constraint to be checked */
2332  SCIP_SOL* sol /**< primal CIP solution */
2333  )
2334 {
2335  SCIP_VAR** vars;
2336  SCIP_Real solval;
2338  SCIP_Real sumbound;
2339  SCIP_Real absviol;
2340  SCIP_Real relviol;
2341  SCIP_Bool check;
2342  int nvars;
2343  int v;
2344 
2345  /* calculate the constraint's activity */
2346  vars = consdata->vars;
2347  nvars = consdata->nvars;
2348  sum = 0.0;
2349  sumbound = ((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING ? 1.0 : 1.0 + 2*SCIPfeastol(scip));
2350  for( v = 0; v < nvars && sum < sumbound; ++v ) /* if sum >= sumbound, the feasibility is clearly decided */
2351  {
2352  assert(SCIPvarIsBinary(vars[v]));
2353 
2354  solval = SCIPgetSolVal(scip, sol, vars[v]);
2355  assert(SCIPisFeasGE(scip, solval, 0.0) && SCIPisFeasLE(scip, solval, 1.0));
2356 
2357  sum += solval;
2358  }
2359 
2360  absviol = sum - 1.0;
2361  relviol = SCIPrelDiff(sum, 1.0);
2362  switch( consdata->setppctype )
2363  {
2365  /* in case of partitioning, the violation is equal to the absolute difference between sum and 1 */
2366  absviol = REALABS(absviol);
2367  relviol = REALABS(relviol);
2368  check = SCIPisFeasEQ(scip, sum, 1.0);
2369  break;
2371  /* in case of packing, the violation is equal to how much sum exceeds 1 */
2372  check = SCIPisFeasLE(scip, sum, 1.0);
2373  break;
2375  /* in case of covering, the violation is equal to how much 1 exceeds sum */
2376  absviol = -absviol;
2377  relviol = -relviol;
2378  check = SCIPisFeasGE(scip, sum, 1.0);
2379  break;
2380  default:
2381  SCIPerrorMessage("unknown setppc type\n");
2382  SCIPABORT();
2383  return FALSE; /*lint !e527*/
2384  }
2385 
2386  if( sol != NULL )
2387  SCIPupdateSolLPConsViolation(scip, sol, absviol, relviol);
2388 
2389  return check;
2390 }
2391 
2392 /** creates an LP row in a set partitioning / packing / covering constraint data object */
2393 static
2395  SCIP* scip, /**< SCIP data structure */
2396  SCIP_CONS* cons /**< set partitioning / packing / covering constraint */
2397  )
2398 {
2399  SCIP_CONSDATA* consdata;
2400  SCIP_Real lhs;
2401  SCIP_Real rhs;
2403  consdata = SCIPconsGetData(cons);
2404  assert(consdata != NULL);
2405  assert(consdata->row == NULL);
2406 
2407  switch( consdata->setppctype )
2408  {
2410  lhs = 1.0;
2411  rhs = 1.0;
2412  break;
2414  lhs = -SCIPinfinity(scip);
2415  rhs = 1.0;
2416  break;
2418  lhs = 1.0;
2419  rhs = SCIPinfinity(scip);
2420  break;
2421  default:
2422  SCIPerrorMessage("unknown setppc type\n");
2423  return SCIP_INVALIDDATA;
2424  }
2425 
2426  SCIP_CALL( SCIPcreateEmptyRowCons(scip, &consdata->row, SCIPconsGetHdlr(cons), SCIPconsGetName(cons), lhs, rhs,
2428 
2429  SCIP_CALL( SCIPaddVarsToRowSameCoef(scip, consdata->row, consdata->nvars, consdata->vars, 1.0) );
2430 
2431  return SCIP_OKAY;
2432 }
2433 
2434 /** adds setppc constraint as cut to the LP */
2435 static
2437  SCIP* scip, /**< SCIP data structure */
2438  SCIP_CONS* cons, /**< setppc constraint */
2439  SCIP_Bool* cutoff /**< whether a cutoff has been detected */
2440  )
2441 {
2442  SCIP_CONSDATA* consdata;
2443 
2444  assert( cutoff != NULL );
2445  *cutoff = FALSE;
2446 
2447  consdata = SCIPconsGetData(cons);
2448  assert(consdata != NULL);
2449 
2450  if( consdata->row == NULL )
2451  {
2452  /* convert set partitioning constraint data into LP row */
2453  SCIP_CALL( createRow(scip, cons) );
2454  }
2455  assert(consdata->row != NULL);
2456 
2457  /* insert LP row as cut */
2458  if( !SCIProwIsInLP(consdata->row) )
2459  {
2460  SCIPdebugMsg(scip, "adding constraint <%s> as cut to the LP\n", SCIPconsGetName(cons));
2461  SCIP_CALL( SCIPaddRow(scip, consdata->row, FALSE, cutoff) );
2462  }
2463 
2464  return SCIP_OKAY;
2465 }
2466 
2467 /** checks constraint for violation, and adds it as a cut if possible */
2468 static
2470  SCIP* scip, /**< SCIP data structure */
2471  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint to be separated */
2472  SCIP_SOL* sol, /**< primal CIP solution, NULL for current LP solution */
2473  SCIP_Bool lpfeas, /**< is the given solution feasible for the current LP ? */
2474  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
2475  SCIP_Bool* separated, /**< pointer to store TRUE, if a cut was found */
2476  SCIP_Bool* reduceddom /**< pointer to store TRUE, if a domain reduction was found */
2477  )
2478 {
2479  SCIP_CONSDATA* consdata;
2480  SCIP_Bool addcut;
2481  SCIP_Bool mustcheck;
2482 
2483  assert(cons != NULL);
2484  assert(SCIPconsGetHdlr(cons) != NULL);
2485  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
2486  assert(cutoff != NULL);
2487  assert(separated != NULL);
2488  assert(reduceddom != NULL);
2489 
2490  *cutoff = FALSE;
2491 
2492  consdata = SCIPconsGetData(cons);
2493  assert(consdata != NULL);
2494  assert(consdata->nvars == 0 || consdata->vars != NULL);
2495  assert(0 <= consdata->nfixedzeros && consdata->nfixedzeros <= consdata->nvars);
2496  assert(0 <= consdata->nfixedones && consdata->nfixedones <= consdata->nvars);
2497 
2498  /* skip constraints already in the LP */
2499  if( lpfeas && consdata->row != NULL && SCIProwIsInLP(consdata->row) )
2500  return SCIP_OKAY;
2501 
2502  SCIPdebugMsg(scip, "separating constraint <%s>\n", SCIPconsGetName(cons));
2503 
2504  /* check constraint for violation only looking at the fixed variables, apply further fixings if possible */
2505  if( lpfeas )
2506  {
2507  int nfixedvars = 0;
2508 
2509  SCIP_CALL( processFixings(scip, cons, cutoff, &nfixedvars, &addcut, &mustcheck) );
2510 
2511  *reduceddom = (nfixedvars > 0);
2512  }
2513  else
2514  {
2515  mustcheck = TRUE;
2516  addcut = FALSE;
2517  }
2518 
2519  if( mustcheck )
2520  {
2521  assert(!addcut);
2522 
2523  /* variable's fixings didn't give us any information -> we have to check the constraint */
2524  if( lpfeas && consdata->row != NULL )
2525  {
2526  SCIP_Real feasibility;
2527 
2528  assert(!SCIProwIsInLP(consdata->row));
2529  feasibility = SCIPgetRowSolFeasibility(scip, consdata->row, sol);
2530  addcut = SCIPisFeasNegative(scip, feasibility);
2531  }
2532  else
2533  addcut = !checkCons(scip, consdata, sol);
2534 
2535  if( !addcut )
2536  {
2537  /* constraint was feasible -> increase age */
2538  SCIP_CALL( SCIPincConsAge(scip, cons) );
2539  }
2540  }
2541 
2542  if( addcut )
2543  {
2544  /* insert LP row as cut */
2545  SCIP_CALL( addCut(scip, cons, cutoff) );
2546  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2547  *separated = TRUE;
2548  }
2549 
2550  return SCIP_OKAY;
2551 }
2552 
2553 /** enforces the pseudo solution on the given constraint */
2554 static
2556  SCIP* scip, /**< SCIP data structure */
2557  SCIP_CONS* cons, /**< set partitioning / packing / covering constraint to be separated */
2558  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
2559  SCIP_Bool* infeasible, /**< pointer to store TRUE, if the constraint was infeasible */
2560  SCIP_Bool* reduceddom, /**< pointer to store TRUE, if a domain reduction was found */
2561  SCIP_Bool* solvelp /**< pointer to store TRUE, if the LP has to be solved */
2562  )
2564  SCIP_Bool addcut;
2565  SCIP_Bool mustcheck;
2566  int nfixedvars = 0;
2567 
2568  assert(!SCIPhasCurrentNodeLP(scip));
2569  assert(cons != NULL);
2570  assert(SCIPconsGetHdlr(cons) != NULL);
2571  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
2572  assert(cutoff != NULL);
2573  assert(infeasible != NULL);
2574  assert(reduceddom != NULL);
2575  assert(solvelp != NULL);
2576 
2577  /* check constraint for violation only looking at the fixed variables, apply further fixings if possible */
2578  SCIP_CALL( processFixings(scip, cons, cutoff, &nfixedvars, &addcut, &mustcheck) );
2579 
2580  *reduceddom = (nfixedvars > 0);
2581 
2582  if( mustcheck )
2583  {
2584  SCIP_CONSDATA* consdata;
2585 
2586  assert(!addcut);
2587 
2588  consdata = SCIPconsGetData(cons);
2589  assert(consdata != NULL);
2590 
2591  if( checkCons(scip, consdata, NULL) )
2592  {
2593  /* constraint was feasible -> increase age */
2594  SCIP_CALL( SCIPincConsAge(scip, cons) );
2595  }
2596  else
2597  {
2598  /* constraint was infeasible -> reset age */
2599  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2600  *infeasible = TRUE;
2601  }
2602  }
2603 
2604  if( addcut )
2605  {
2606  /* a cut must be added to the LP -> we have to solve the LP immediately */
2607  SCIP_CALL( SCIPresetConsAge(scip, cons) );
2608  *solvelp = TRUE;
2609  }
2610 
2611  return SCIP_OKAY;
2612 }
2613 
2614 /** gets the key of the given element */
2615 static
2616 SCIP_DECL_HASHGETKEY(hashGetKeySetppccons)
2617 { /*lint --e{715}*/
2618  /* the key is the element itself */
2619  return elem;
2620 }
2621 
2622 /** returns TRUE iff both keys are equal; two constraints are equal if they have the same variables */
2623 static
2624 SCIP_DECL_HASHKEYEQ(hashKeyEqSetppccons)
2625 {
2626 #ifndef NDEBUG
2627  SCIP* scip;
2628 #endif
2629  SCIP_CONSDATA* consdata1;
2630  SCIP_CONSDATA* consdata2;
2631  SCIP_Bool coefsequal;
2632  int i;
2633 
2634  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
2635  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
2636  assert(consdata1->sorted);
2637  assert(consdata2->sorted);
2638 #ifndef NDEBUG
2639  scip = (SCIP*)userptr;
2640  assert(scip != NULL);
2641 #endif
2642 
2643  /* checks trivial case */
2644  if( consdata1->nvars != consdata2->nvars )
2645  return FALSE;
2646 
2647  coefsequal = TRUE;
2648 
2649  for( i = 0; i < consdata1->nvars; ++i )
2650  {
2651  /* tests if variables are equal */
2652  if( consdata1->vars[i] != consdata2->vars[i] )
2653  {
2654  assert(SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == 1 ||
2655  SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == -1);
2656  coefsequal = FALSE;
2657  break;
2658  }
2659  assert(SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == 0);
2660  }
2661 
2662  return coefsequal;
2663 }
2664 
2665 /** returns the hash value of the key */
2666 static
2667 SCIP_DECL_HASHKEYVAL(hashKeyValSetppccons)
2668 {
2669  SCIP_CONSDATA* consdata;
2670  int minidx;
2671  int mididx;
2672  int maxidx;
2673 #ifndef NDEBUG
2674  SCIP* scip;
2676  scip = (SCIP*)userptr;
2677  assert(scip != NULL);
2678 #endif
2679 
2680  consdata = SCIPconsGetData((SCIP_CONS*)key);
2681  assert(consdata != NULL);
2682  assert(consdata->nvars > 0);
2683 
2684  /* sorts the constraints */
2685  consdataSort(consdata);
2686 
2687  minidx = SCIPvarGetIndex(consdata->vars[0]);
2688  mididx = SCIPvarGetIndex(consdata->vars[consdata->nvars / 2]);
2689  maxidx = SCIPvarGetIndex(consdata->vars[consdata->nvars - 1]);
2690  assert(minidx >= 0 && minidx <= maxidx);
2691 
2692  return SCIPhashTwo(SCIPcombineTwoInt(consdata->nvars, minidx),
2693  SCIPcombineTwoInt(mididx, maxidx));
2694 }
2695 
2696 /** add extra clique-constraints resulting from a given cliquepartition to SCIP */
2697 static
2699  SCIP*const scip, /**< SCIP data structure */
2700  SCIP_VAR**const binvars, /**< binary variables to create clique constraints */
2701  int const nbinvars, /**< number of binary variables to create clique constraints */
2702  int*const cliquepartition, /**< clique partition of binary variables */
2703  int const ncliques, /**< number of cliques in cliquepartition */
2704  SCIP_CONS**const usefulconss, /**< storage for created constraints */
2705  int*const nusefulconss, /**< pointer to store number of useful created constraints */
2706  int const nrounds, /**< actual presolving round */
2707  int*const nfixedvars, /**< pointer to count number of deleted variables */
2708  int*const naddconss, /**< pointer to count number of added constraints */
2709  int*const ndelconss, /**< pointer to count number of deleted constraints */
2710  int*const nchgcoefs, /**< pointer to count number of deleted coefficients */
2711  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
2712  )
2713 {
2714  SCIP_CONS* cliquecons;
2715  char name[SCIP_MAXSTRLEN];
2716  int lastclqidx;
2717  int nadded;
2718  int c;
2719  int v;
2720 
2721  assert(scip != NULL);
2722  assert(binvars != NULL || nbinvars == 0);
2723  assert(cliquepartition != NULL || nbinvars == 0);
2724  assert(ncliques >= 0 && ncliques <= nbinvars);
2725  assert(usefulconss != NULL);
2726  assert(nusefulconss != NULL);
2727  assert(nfixedvars != NULL);
2728  assert(naddconss != NULL);
2729  assert(ndelconss != NULL);
2730  assert(nchgcoefs != NULL);
2731  assert(cutoff != NULL);
2732 
2733  /* no given binary variables */
2734  if( nbinvars == 0 || ncliques == 0 )
2735  return SCIP_OKAY;
2736 
2737  assert(binvars != NULL);
2738  assert(cliquepartition != NULL);
2739 
2740  /* no useful clique information */
2741  if( ncliques == nbinvars )
2742  return SCIP_OKAY;
2743 
2744  lastclqidx = 0;
2745 
2746  /* @todo: maybe sort cliques and accordingly the variables so it will be faster to add the constraints */
2747  for( c = 0; c < ncliques - 1; ++c )
2748  {
2749  if( lastclqidx >= cliquepartition[c] )
2750  continue;
2751 
2752  nadded = 0;
2753 
2754  /* name the clique constraint */
2755  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "extra_clq_%d_round_%d", cliquepartition[c], nrounds);
2756  SCIP_CALL( SCIPcreateConsSetpack(scip, &cliquecons, name, 0, NULL,
2758 
2759  /* add variables to clique constraint */
2760  for( v = c; v < nbinvars - 1; ++v )
2761  {
2762  if( cliquepartition[c] == cliquepartition[v] )
2763  {
2764  SCIP_CALL( addCoef(scip, cliquecons, binvars[v]) );
2765  ++nadded;
2766  }
2767  }
2768 
2769  /* @todo: try to find a good value for what are enough variables to create this constraint, maybe at least
2770  * (nmaxvars(over all conss)-nminvars(over all conss))/2 */
2771  if( nadded >= 2 )
2772  {
2773  SCIP_CONSDATA* cliqueconsdata;
2774 
2775  SCIPdebugMsg(scip, " -> adding clique constraint: ");
2776  SCIPdebugPrintCons(scip, cliquecons, NULL);
2777  SCIP_CALL( SCIPaddCons(scip, cliquecons) );
2778  ++(*naddconss);
2779 
2780  /* we only want to consider merged constraints */
2781  SCIP_CALL( mergeMultiples(scip, cliquecons, nfixedvars, ndelconss, nchgcoefs, cutoff) );
2782  if( *cutoff )
2783  {
2784  SCIP_CALL( SCIPreleaseCons(scip, &cliquecons) );
2785 
2786  return SCIP_OKAY;
2787  }
2788 
2789  cliqueconsdata = SCIPconsGetData(cliquecons);
2790  assert(cliqueconsdata != NULL);
2791 
2792  /* the artificial constraints could be deleled while merging */
2793  if( !SCIPconsIsDeleted(cliquecons) && nadded - cliqueconsdata->nfixedzeros >= 2 )
2794  {
2795  assert(cliqueconsdata->nfixedones == 0);
2796 
2797  /* save the type and constraint */
2798  usefulconss[*nusefulconss] = cliquecons;
2799  ++(*nusefulconss);
2800  }
2801  SCIP_CALL( SCIPreleaseCons(scip, &cliquecons) );
2802  }
2803  else
2804  {
2805  SCIP_CALL( SCIPreleaseCons(scip, &cliquecons) );
2806  }
2807  lastclqidx = cliquepartition[c];
2808  }
2809 
2810  return SCIP_OKAY;
2811 }
2812 
2813 
2814 /** start to collect setpartitioning and setpacking constraints, and try to remove fixed variables and merged these
2815  * constraints
2816  */
2817 static
2819  SCIP*const scip, /**< SCIP data structure */
2820  SCIP_CONS**const conss, /**< constraint set */
2821  int const nconss, /**< number of constraints in constraint set */
2822  SCIP_CONS**const usefulconss, /**< storage for created constraints */
2823  int*const nusefulconss, /**< pointer to store number of useful created constraints */
2824  int*const nfixedvars, /**< pointer to count number of deleted variables */
2825  int*const ndelconss, /**< pointer to count number of deleted constraints */
2826  int*const nchgcoefs, /**< pointer to count number of deleted coefficients */
2827  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
2828  )
2829 {
2830  SCIP_CONS* cons;
2831  SCIP_CONSDATA* consdata;
2832  SCIP_Bool addcut;
2833  SCIP_Bool mustcheck;
2834  int nlocaladdconss = 0;
2835  int c;
2836 
2837  assert(scip != NULL);
2838  assert(conss != NULL || nconss == 0);
2839  assert(usefulconss != NULL);
2840  assert(nusefulconss != NULL);
2841  assert(nfixedvars != NULL);
2842  assert(ndelconss != NULL);
2843  assert(nchgcoefs != NULL);
2844  assert(cutoff != NULL);
2845 
2846  if( nconss == 0 )
2847  return SCIP_OKAY;
2848 
2849  assert(conss != NULL);
2850 
2851  for( c = nconss - 1; c >= 0; --c )
2852  {
2853  cons = conss[c];
2854 
2855  /* we only want to consider constraints with either active or negated of active variables, applyfixings removes
2856  * aggregated and fixed variables to zero, processFixings removes fixings to one but no aggregation
2857  *
2858  * @todo: maybe write a new method for deleting aggregations and all fixings
2859  */
2860  SCIP_CALL( applyFixings(scip, cons, &nlocaladdconss, ndelconss, nfixedvars, cutoff) );
2861  if( *cutoff )
2862  return SCIP_OKAY;
2863 
2864  if( SCIPconsIsDeleted(cons) )
2865  {
2866  /* reset nlocaladdconss and continue */
2867  nlocaladdconss = 0;
2868  continue;
2869  }
2870  assert(nlocaladdconss == 0);
2871 
2872  SCIP_CALL( processFixings(scip, cons, cutoff, nfixedvars, &addcut, &mustcheck) );
2873  if( *cutoff )
2874  return SCIP_OKAY;
2875 
2876  consdata = SCIPconsGetData(cons);
2877  assert(consdata != NULL);
2878 
2879  /* we only want to consider merged constraints */
2880  SCIP_CALL( mergeMultiples(scip, cons, nfixedvars, ndelconss, nchgcoefs, cutoff) );
2881  if( *cutoff )
2882  return SCIP_OKAY;
2883 
2884  if( SCIPconsIsModifiable(cons) || !SCIPconsIsActive(cons) )
2885  continue;
2886 
2887  assert(consdata->nfixedones == 0);
2888 
2889  if( consdata->nvars == 0 )
2890  continue;
2891 
2892  /* @todo: check for covering constraints with only two variables which are equal to a packing constraint with
2893  * negated variables */
2894  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
2895  {
2896  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
2897 
2898  usefulconss[*nusefulconss] = cons;
2899  ++(*nusefulconss);
2900  }
2901  }
2902 
2903  return SCIP_OKAY;
2904 }
2905 
2906 /** creating all necessary data in array structure, collect all clique constraint variables and occurances,
2907  * @note works only with merged and active not set-covering constraints
2908  */
2909 static
2911  SCIP*const scip, /**< SCIP data structure */
2912  SCIP_CONS**const usefulconss, /**< clique constraints */
2913  int const nusefulconss, /**< number of clique constraints */
2914  SCIP_VAR**const usefulvars, /**< storage for all found variables */
2915  int*const nusefulvars, /**< pointer to store number of added variables */
2916  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
2917  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
2918  int*const maxnvarconsidx, /**< storage for the maximal number of occurances of a variable */
2919  int**const varconsidxs, /**< storage for constraint indices in which the corresponding variable exists */
2920  int*const maxnvars /**< pointer to store maximal number of variables of a constraint */
2921  )
2922 {
2923  SCIP_CONS* cons;
2924  SCIP_CONSDATA* consdata;
2925  int varindex;
2926  int c;
2927  int v;
2928 
2929  assert(scip != NULL);
2930  assert(usefulconss != NULL || nusefulconss == 0);
2931  assert(usefulvars != NULL);
2932  assert(nusefulvars != NULL);
2933  assert(vartoindex != NULL);
2934  assert(varnconss != NULL);
2935  assert(maxnvarconsidx != NULL);
2936  assert(varconsidxs != NULL);
2937  assert(maxnvars != NULL);
2938 
2939  if( nusefulconss == 0 )
2940  return SCIP_OKAY;
2941 
2942  assert(usefulconss != NULL);
2943 
2944  for( c = nusefulconss - 1; c >= 0; --c )
2945  {
2946  cons = usefulconss[c];
2947 
2948  assert(SCIPconsIsActive(cons));
2949 
2950  consdata = SCIPconsGetData(cons);
2951  assert(consdata != NULL);
2952 
2953  /* here we should have no covering constraints anymore and the constraint data should be merged */
2954  assert(consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
2955  assert(consdata->merged);
2956 
2957  /* save maximal number of vars */
2958  if( consdata->nvars > *maxnvars )
2959  *maxnvars = consdata->nvars;
2960 
2961  /* adding variables and information about occurances to local data structure */
2962  for( v = consdata->nvars - 1; v >= 0; --v )
2963  {
2964  SCIP_VAR* var;
2965 
2966  var = consdata->vars[v];
2967  assert(var != NULL);
2968 
2969  /* don't remember fixed vars */
2970  if( SCIPvarGetLbLocal(var) > 0.5 || SCIPvarGetUbLocal(var) < 0.5 )
2971  continue;
2972 
2973  /* only collect active or negated active varibels */
2975 
2976  if( !SCIPhashmapExists(vartoindex, (void*) var) )
2977  {
2978  SCIP_VAR* tmpvar;
2979 
2980  usefulvars[*nusefulvars] = var;
2981  ++(*nusefulvars);
2982  varindex = *nusefulvars;
2983  SCIP_CALL( SCIPhashmapInsert(vartoindex, (void*) var, (void*) (size_t) varindex) );
2984 
2985  /* get the maximal number of occurances of this variable, if this variables */
2986  tmpvar = SCIPvarIsNegated(var) ? SCIPvarGetNegatedVar(var) : var;
2987  maxnvarconsidx[varindex] = SCIPvarGetNLocksDownType(tmpvar, SCIP_LOCKTYPE_MODEL)
2989  SCIP_CALL( SCIPallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
2990  }
2991  else
2992  {
2993  assert(SCIPhashmapGetImage(vartoindex, (void*) var) != NULL);
2994  varindex = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) var);
2995  }
2996 
2997  /* the number of occurances of a variable is not limited by the locks (so maybe we have to increase memory),
2998  * because for examples converted cuts are not check and therefore they have no locks on their variables */
2999  if( varnconss[varindex] == maxnvarconsidx[varindex] )
3000  {
3001  maxnvarconsidx[varindex] = SCIPcalcMemGrowSize(scip, maxnvarconsidx[varindex] + 1);
3002  SCIP_CALL( SCIPreallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
3003  }
3004 
3005  assert(varnconss[varindex] < maxnvarconsidx[varindex]);
3006  /* add the constraint number to the variable list */
3007  varconsidxs[varindex][varnconss[varindex]] = c;
3008  /* increase number of occurances for variables */
3009  ++(varnconss[varindex]);
3010  }
3011  } /* data structure created */
3012 
3013  return SCIP_OKAY;
3014 }
3015 
3016 /** correct clique data due to an aggregation */
3017 static
3019  SCIP_VAR*const var, /**< variable which appears less */
3020  int const considx, /**< constraint index which to remove */
3021  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
3022  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
3023  int**const varconsidxs /**< storage for constraint indices in which the corresponding variable exists */
3024  )
3025 {
3026  int varindex;
3027  int i;
3028 #ifndef NDEBUG
3029  SCIP_Bool found = FALSE;
3030 #endif
3031 
3032  assert(var != NULL);
3033  assert(SCIPvarGetLbLocal(var) < 0.5 && SCIPvarGetUbLocal(var) > 0.5);
3034  assert(considx >= 0);
3035  assert(vartoindex != NULL);
3036  assert(varnconss != NULL);
3037  assert(varconsidxs != NULL);
3038 
3039  assert(SCIPhashmapGetImage(vartoindex, (void*) var) != NULL);
3040  varindex = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) var);
3041 
3042  /* remove entry of variable at the given position */
3043  for( i = 0; i < varnconss[varindex]; ++i )
3044  {
3045  if( varconsidxs[varindex][i] == considx )
3046  {
3047  varconsidxs[varindex][i] = varconsidxs[varindex][varnconss[varindex] - 1];
3048 #ifndef NDEBUG
3049  found = TRUE;
3050 #endif
3051  --(varnconss[varindex]);
3052  break;
3053  }
3054  }
3055  assert(found);
3056 }
3057 
3058 /* correct local data structure, add constraint entry to variable data */
3059 static
3061  SCIP*const scip, /**< SCIP data structure */
3062  SCIP_VAR*const addvar, /**< variable which was added */
3063  int const considx, /**< constraint index which to add */
3064  SCIP_Bool const maybenew, /**< could be a new variables, a negated of an already existing */
3065  SCIP_VAR**const usefulvars, /**< storage for all found variables */
3066  int*const nusefulvars, /**< pointer to store number of added variables */
3067  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
3068  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
3069  int*const maxnvarconsidx, /**< storage for the maximal number of occurances of a variable */
3070  int**const varconsidxs /**< storage for constraint indices in which the corresponding variable exists */
3071  )
3072 {
3073  int varindex;
3074 
3075  assert(scip != NULL);
3076  assert(addvar != NULL);
3077  assert(SCIPvarGetLbLocal(addvar) < 0.5 && SCIPvarGetUbLocal(addvar) > 0.5);
3078  assert(usefulvars != NULL);
3079  assert(nusefulvars != NULL);
3080  assert(vartoindex != NULL);
3081  assert(varnconss != NULL);
3082  assert(maxnvarconsidx != NULL);
3083  assert(varconsidxs != NULL);
3084 
3085  /* we add the variable to the hashmap if its new */
3086  if( maybenew && !SCIPhashmapExists(vartoindex, (void*) addvar) )
3087  {
3088  assert(SCIPvarIsActive(addvar) || SCIPvarIsNegated(addvar));
3089  assert(SCIPvarGetNegatedVar(addvar) != NULL && SCIPhashmapExists(vartoindex, (void*) SCIPvarGetNegatedVar(addvar)));
3090 
3091  /* @note because we can only have created a negated variable, and we already alloacted enough memory for
3092  * all (even not existing) negated variables the usefulvars array should be big enough
3093  */
3094  SCIPsortedvecInsertDownPtr((void**)usefulvars, SCIPvarCompActiveAndNegated, addvar, nusefulvars, NULL);
3095  varindex = *nusefulvars;
3096  SCIP_CALL( SCIPhashmapInsert(vartoindex, (void*) addvar, (void*) (size_t) varindex) );
3097 
3098  assert(varconsidxs[varindex] == NULL);
3099 
3100  maxnvarconsidx[varindex] = 1;
3101  SCIP_CALL( SCIPallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
3102  varnconss[varindex] = 0;
3103  }
3104  else
3105  {
3106  varindex = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) addvar);
3107 
3108  /* grow the needed memory if we added a variable */
3109  if( varnconss[varindex] == maxnvarconsidx[varindex] )
3110  {
3111  maxnvarconsidx[varindex] = SCIPcalcMemGrowSize(scip, maxnvarconsidx[varindex] + 1);
3112  SCIP_CALL( SCIPreallocBufferArray(scip, &(varconsidxs[varindex]), maxnvarconsidx[varindex]) ); /*lint !e866*/
3113  }
3114  }
3115  assert(varnconss[varindex] < maxnvarconsidx[varindex]);
3116  varconsidxs[varindex][varnconss[varindex]] = considx;
3117 
3118  /* increase number of occurances for variables */
3119  ++(varnconss[varindex]);
3120 
3121  return SCIP_OKAY;
3122 }
3123 
3124 
3125 /** check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
3126  * possible
3127  */
3128 static
3130  SCIP*const scip, /**< SCIP data structure */
3131  SCIP_CONS*const cons, /**< constraint */
3132  SCIP_Bool const aggregate, /**< try to aggregate if possible */
3133  SCIP_VAR** undoneaggrvars, /**< array to store aggregation variables, if aggregation is not performed
3134  * yet; both variables are standing next to each other; or NULL if
3135  * aggregate == TRUE
3136  */
3137  SCIP_Bool* undoneaggrtypes, /**< array to store aggregation type, if aggregation is not performed yet;
3138  * type FALSE means the aggregation is of the form x + y = 1; type TRUE means
3139  * the aggregation is of the form x = y; or NULL if aggregate == TRUE
3140  */
3141  int*const naggregations, /**< pointer to store number of aggregations which are not yet performed;
3142  * or NULL if aggregate == TRUE
3143  */
3144  int*const saggregations, /**< pointer to store size of the array for aggregation type and two times
3145  * the value is the size of the array for the aggregation variables which
3146  * are not yet performed; or NULL if aggregate == TRUE
3147  */
3148  int*const nfixedvars, /**< pointer to count number of deleted variables */
3149  int*const naggrvars, /**< pointer to count number of aggregated variables */
3150  int*const ndelconss, /**< pointer to count number of deleted constraints */
3151  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
3152  )
3153 {
3154  SCIP_CONSDATA* consdata;
3155  SCIP_VAR** vars;
3156  int nvars;
3157  int v;
3158  SCIP_Bool fixed;
3159 
3160  assert(scip != NULL);
3161  assert(cons != NULL);
3162  assert(nfixedvars != NULL);
3163  assert(naggrvars != NULL);
3164  assert(ndelconss != NULL);
3165  assert(cutoff != NULL);
3166 
3167  if( !SCIPconsIsActive(cons) )
3168  return SCIP_OKAY;
3169 
3170  consdata = SCIPconsGetData(cons);
3171  assert(consdata != NULL);
3172 
3173  if( consdata->presolpropagated )
3174  return SCIP_OKAY;
3175 
3176  consdata->presolpropagated = TRUE;
3177 
3178  vars = consdata->vars;
3179  nvars = consdata->nvars;
3180 
3181  /* no variables left */
3182  if( nvars == 0 && !SCIPconsIsModifiable(cons) )
3183  {
3184  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3185  {
3186  SCIPdebugMsg(scip, "empty set-partition/-covering constraint <%s> found -> cutoff\n", SCIPconsGetName(cons));
3187  *cutoff = TRUE;
3188 
3189  return SCIP_OKAY;
3190  }
3191  else
3192  {
3193  assert(consdata->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
3194 
3195  /* delete constraint */
3196  SCIPdebugMsg(scip, " -> deleting constraint <%s>, no variables left\n", SCIPconsGetName(cons));
3197  SCIP_CALL( SCIPdelCons(scip, cons) );
3198  ++(*ndelconss);
3199 
3200  return SCIP_OKAY;
3201  }
3202  }
3203 
3204  /* more then two variables are fixed */
3205  if( consdata->nfixedones > 1 )
3206  {
3207  /* at least two variables are fixed to 1:
3208  * - a set covering constraint is feasible anyway and can be deleted
3209  * - a set partitioning or packing constraint is infeasible
3210  */
3211  if( consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3212  {
3213  /* delete constraint */
3214  SCIPdebugMsg(scip, " -> deleting set-covering constraint <%s>, at least two variables are fixed to 1\n", SCIPconsGetName(cons));
3215  SCIP_CALL( SCIPdelCons(scip, cons) );
3216  ++(*ndelconss);
3217 
3218  return SCIP_OKAY;
3219  }
3220 
3221  SCIPdebugMsg(scip, "set partitioning / packing constraint <%s> is infeasible, %d variables fixed to one\n", SCIPconsGetName(cons), consdata->nfixedones);
3222  *cutoff = TRUE;
3223 
3224  return SCIP_OKAY;
3225  }
3226 
3227  if( consdata->nfixedones == 1 )
3228  {
3229  /* exactly one variable is fixed to 1:
3230  * - a set covering constraint is feasible anyway and can be disabled
3231  * - all other variables in a set partitioning or packing constraint must be zero
3232  */
3233  if( consdata->setppctype != SCIP_SETPPCTYPE_COVERING && consdata->nfixedzeros < nvars - 1 ) /*lint !e641*/
3234  {
3235  assert(vars != NULL);
3236 
3237  for( v = nvars - 1; v >= 0; --v )
3238  {
3239  if( SCIPvarGetLbLocal(vars[v]) + 0.5 < SCIPvarGetUbLocal(vars[v]) )
3240  {
3241  SCIPdebugMsg(scip, "trying to fix <%s> to 0 due to at least one variable is already fixed to 1\n", SCIPvarGetName(vars[v]));
3242 
3243  /* fix all remaining variables to zero, constraint is already feasible or infeasible */
3244  SCIP_CALL( SCIPfixVar(scip, vars[v], 0.0, cutoff, &fixed) );
3245  if( *cutoff )
3246  {
3247  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 0\n",
3248  SCIPconsGetName(cons), SCIPvarGetName(vars[v]));
3249 
3250  return SCIP_OKAY;
3251  }
3252 
3253  assert(fixed);
3254  ++(*nfixedvars);
3255  }
3256  }
3257  }
3258 
3259  if( !SCIPconsIsModifiable(cons) || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3260  {
3261  /* delete constraint */
3262  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all variables are fixed\n", SCIPconsGetName(cons));
3263  assert(SCIPconsIsActive(cons));
3264  SCIP_CALL( SCIPdelCons(scip, cons) );
3265  ++(*ndelconss);
3266  }
3267 
3268  return SCIP_OKAY;
3269  }
3270 
3271  /* other propagations can only be done on not modifiable constraints */
3272  if( SCIPconsIsModifiable(cons) )
3273  return SCIP_OKAY;
3274 
3275  assert(vars != NULL);
3276 
3277  /* all variables were fixed to zero then either delete the constraint or stop with infeasibility */
3278  if( consdata->nfixedzeros == nvars )
3279  {
3280  assert(consdata->nfixedones == 0);
3281 
3282  /* all variables are fixed to zero:
3283  * - a set packing constraint is feasible anyway and can be deleted
3284  * - a set partitioning or covering constraint is infeasible, and so is the whole problem
3285  */
3286  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3287  {
3288  SCIPdebugMsg(scip, "set partitioning / covering constraint <%s> is infeasible\n", SCIPconsGetName(cons));
3289  *cutoff = TRUE;
3290 
3291  return SCIP_OKAY;
3292  }
3293 
3294  /* delete constraint */
3295  SCIPdebugMsg(scip, " -> deleting set-packing constraint <%s>, all variables are fixed to zero\n", SCIPconsGetName(cons));
3296  assert(SCIPconsIsActive(cons));
3297  SCIP_CALL( SCIPdelCons(scip, cons) );
3298  ++(*ndelconss);
3299 
3300  return SCIP_OKAY;
3301  }
3302 
3303  /* all but one variable were fixed to zero then delete the constraint and for setpartition fix the remaining variable to 1 */
3304  if( consdata->nfixedzeros + 1 == nvars )
3305  {
3306  assert(consdata->nfixedones == 0);
3307 
3308  /* all variables except one are fixed to zero:
3309  * - a set packing constraint is feasible anyway, and can be deleted
3310  * - a set partitioning or covering constraint is feasible and can be deleted after the
3311  * remaining variable is fixed to one
3312  */
3313  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || consdata->setppctype == SCIP_SETPPCTYPE_COVERING ) /*lint !e641*/
3314  {
3315  fixed = FALSE;
3316  for( v = nvars - 1; v >= 0; --v )
3317  {
3318  assert(SCIPvarGetLbLocal(vars[v]) < 0.5);
3319  if( SCIPvarGetUbLocal(vars[v]) > 0.5 )
3320  {
3321  SCIPdebugMsg(scip, "trying to fix <%s> to 1 due to it's the last unfixed variable is the set-partitioning/covering constraint\n", SCIPvarGetName(vars[v]));
3322 
3323  /* fix the remaining set partition variable */
3324  SCIP_CALL( SCIPfixVar(scip, vars[v], 1.0, cutoff, &fixed) );
3325  if( *cutoff )
3326  {
3327  SCIPdebugMsg(scip, "setppc constraint <%s>: infeasible fixing <%s> == 1\n",
3328  SCIPconsGetName(cons), SCIPvarGetName(vars[v]));
3329 
3330  return SCIP_OKAY;
3331  }
3332 
3333  assert(fixed);
3334  ++(*nfixedvars);
3335  break;
3336  }
3337  }
3338  assert(fixed);
3339  }
3340 
3341  /* delete constraint */
3342  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all %svariables are fixed\n", SCIPconsGetName(cons), consdata->setppctype == (int) SCIP_SETPPCTYPE_PACKING ? "but one " : "");
3343  assert(SCIPconsIsActive(cons));
3344  SCIP_CALL( SCIPdelCons(scip, cons) );
3345  ++(*ndelconss);
3346 
3347  return SCIP_OKAY;
3348  }
3349 
3350  /* all but two variable were fixed to zero in a setpartitioning constraint then delete the constraint and
3351  * aggregate the remaining two variables
3352  */
3353  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata->nfixedzeros + 2 == nvars ) /*lint !e641*/
3354  {
3355  SCIP_VAR* var;
3356 
3357  var = NULL;
3358  for( v = nvars - 1; v >= 0; --v )
3359  {
3360  assert(SCIPvarGetLbLocal(vars[v]) < 0.5);
3361 
3362  if( SCIPvarGetUbLocal(vars[v]) > 0.5 )
3363  {
3364  if( var == NULL )
3365  var = vars[v];
3366  else
3367  {
3368  SCIP_Bool redundant;
3369  SCIP_Bool aggregated;
3370 #ifdef VARUSES
3371  SCIP_CONSHDLR* conshdlr;
3372  SCIP_CONSHDLRDATA* conshdlrdata;
3373 
3374  /* get event handler and event handler data */
3375  conshdlr = SCIPconsGetHdlr(cons);
3376  assert(conshdlr != NULL);
3377  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3378  assert(conshdlrdata != NULL);
3379 #endif
3380  if( aggregate )
3381  {
3382  SCIPdebugMsg(scip, "trying to aggregate <%s> and <%s> due to they are the last two unfixed variables in the set partitionning constraint <%s>\n", SCIPvarGetName(var), SCIPvarGetName(vars[v]), SCIPconsGetName(cons));
3383 
3384 #ifdef VARUSES
3385  /* in order to not mess up the variable usage counting, we have to decrease usage counting, aggregate,
3386  * and increase usage counting again
3387  */
3388  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, var) );
3389  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, vars[v]) );
3390 #endif
3391 
3392  /* aggregate last remaining variables in the set partitioning constraint */
3393  SCIP_CALL( SCIPaggregateVars(scip, var, vars[v], 1.0, 1.0, 1.0, cutoff, &redundant, &aggregated) );
3394  if( *cutoff )
3395  {
3396  SCIPdebugMsg(scip, "set partitioning constraint <%s>: aggregate <%s> + <%s> == 1\n",
3397  SCIPconsGetName(cons), SCIPvarGetName(var), SCIPvarGetName(vars[v]));
3398 
3399  return SCIP_OKAY;
3400  }
3401 
3402 #ifdef VARUSES
3403  /* increase variable usage counting again */
3404  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var) );
3405  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, vars[v]) );
3406 #endif
3407 
3408  if( aggregated )
3409  ++(*naggrvars);
3410 
3411  if( redundant )
3412  {
3413  /* delete constraint */
3414  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all variables are fixed\n", SCIPconsGetName(cons));
3415  assert(SCIPconsIsActive(cons));
3416  SCIP_CALL( SCIPdelCons(scip, cons) );
3417  ++(*ndelconss);
3418  }
3419  }
3420  else
3421  {
3422  assert(undoneaggrvars != NULL);
3423  assert(undoneaggrtypes != NULL);
3424  assert(naggregations != NULL);
3425  assert(saggregations != NULL);
3426 
3427  SCIPdebugMsg(scip, "memorize the aggregation of <%s> + <%s> = 1, because they are the last two unfixed variable in the set partitioning constraints <%s>\n", SCIPvarGetName(var), SCIPvarGetName(vars[v]), SCIPconsGetName(cons));
3428 
3429  /* resize the aggregation arrays if necessary */
3430  if( *saggregations == *naggregations )
3431  {
3432  *saggregations = SCIPcalcMemGrowSize(scip, *naggregations + 1);
3433  assert(*saggregations > *naggregations);
3434  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrtypes, *saggregations) );
3435  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrvars, 2 * (*saggregations)) );
3436 
3437  /* clear the aggregation type array to set the default to the aggregation of the form x + y = 1 */
3438  BMSclearMemoryArray(&(undoneaggrtypes[*naggregations]), *saggregations - *naggregations); /*lint !e866*/
3439  }
3440 
3441  /* memorize aagregation variables*/
3442  assert(undoneaggrtypes[*naggregations] == FALSE);
3443  undoneaggrvars[2 * (*naggregations)] = var;
3444  undoneaggrvars[2 * (*naggregations) + 1] = vars[v];
3445  ++(*naggregations);
3446 
3447  if( !SCIPdoNotAggr(scip) )
3448  {
3449  /* delete constraint */
3450  SCIPdebugMsg(scip, " -> deleting constraint <%s>, all variables are fixed\n", SCIPconsGetName(cons));
3451  assert(SCIPconsIsActive(cons));
3452  SCIP_CALL( SCIPdelCons(scip, cons) );
3453  ++(*ndelconss);
3454  }
3455  }
3456 
3457  return SCIP_OKAY;
3458  }
3459  }
3460  }
3461  /* we should never be here, because the last to unfixed variables should have been either aggregated or a cutoff
3462  * should be applied
3463  */
3464  assert(FALSE);
3465  }
3466 
3467  return SCIP_OKAY;
3468 }
3469 
3470 /** check for overlapping constraint */
3471 static
3473  SCIP*const scip, /**< SCIP data structure */
3474  SCIP_CONS*const cons, /**< constraint which may overlap */
3475  int const considx, /**< constriant index to avoid checking against itself */
3476  int const endidx, /**< end index to check against given constraint */
3477  SCIP_CONS**const usefulconss, /**< clique constraints */
3478  int const nusefulconss, /**< number of clique constraints */
3479  SCIP_VAR**const usefulvars, /**< storage for all found variables */
3480  int*const nusefulvars, /**< pointer to store number of added variables */
3481  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
3482  int*const varnconss, /**< storage for remembering the number of constraints a variable occurs */
3483  int*const maxnvarconsidx, /**< storage for the maximal number of occurances of a variable */
3484  int**const varconsidxs, /**< storage for constraint indices in which the corresponding variable exists */
3485  int*const countofoverlapping, /**< the amount of variables of cons which overlap in all other constraint */
3486  SCIP_Bool const shrinking, /**< try to replace some variables with one variable */
3487  SCIP_Bool*const chgcons, /**< pointer to store if the given constraint was changed, due to
3488  * added/deleted variables
3489  */
3490  SCIP_VAR** undoneaggrvars, /**< array to store aggregation variables, if aggregation is not performed
3491  * yet; both variables are standing next to each other;
3492  */
3493  SCIP_Bool* undoneaggrtypes, /**< array to store aggregation type, if aggregation is not performed yet;
3494  * type FALSE means the aggregation is of the form x + y = 1; type TRUE means
3495  * the aggregation is of the form x = y;
3496  */
3497  int*const naggregations, /**< pointer to store number of aggregations which are not yet performed; */
3498  int*const saggregations, /**< pointer to store size of the array for aggregation type and two times
3499  * the value is the size of the array for the aggregation variables which
3500  * are not yet performed;
3501  */
3502  int*const nfixedvars, /**< pointer to count number of deleted variables */
3503  int*const naggrvars, /**< pointer to count number of aggregated variables */
3504  int*const nchgcoefs, /**< pointer to count number of changed coefficients */
3505  int*const ndelconss, /**< pointer to count number of deleted constraints */
3506  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
3507  )
3508 {
3509  SCIP_CONS* cons1;
3510  SCIP_CONSDATA* consdata1;
3511  SCIP_CONSDATA* consdata;
3512  SCIP_VAR** vars;
3513  SCIP_VAR** vars1;
3514  SCIP_VAR* var;
3515  SCIP_VAR* var1;
3516  SCIP_Bool fixed;
3517  SCIP_Bool overlapdestroyed;
3518  int nvars;
3519  int nvars1;
3520  int oldnfixedzeros;
3521  int c;
3522  int v;
3523  int v1;
3524 #ifndef NDEBUG
3525  int oldnaggrvars;
3526 #endif
3527 
3528  assert(scip != NULL);
3529  assert(cons != NULL);
3530  assert(usefulconss != NULL && nusefulconss > 0);
3531  assert(0 <= considx && considx < nusefulconss);
3532  assert(usefulconss[considx] == cons);
3533  assert(0 <= endidx && endidx <= nusefulconss);
3534  assert(countofoverlapping != NULL);
3535  assert(chgcons != NULL);
3536  assert(undoneaggrvars != NULL);
3537  assert(undoneaggrtypes != NULL);
3538  assert(naggregations != NULL);
3539  assert(saggregations != NULL);
3540  assert(nfixedvars != NULL);
3541  assert(naggrvars != NULL);
3542  assert(nchgcoefs != NULL);
3543  assert(ndelconss != NULL);
3544  assert(cutoff != NULL);
3545 
3546  if( !SCIPconsIsActive(cons) )
3547  return SCIP_OKAY;
3548 
3549  consdata = SCIPconsGetData(cons);
3550  assert(consdata != NULL);
3551 
3552  nvars = consdata->nvars;
3553 
3554  if( nvars == 0 )
3555  return SCIP_OKAY;
3556 
3557  vars = consdata->vars;
3558  assert(vars != NULL);
3559 
3560  oldnfixedzeros = consdata->nfixedzeros;
3561  overlapdestroyed = FALSE;
3562 
3563  /* first check for redundancy for all unprocessed constraints with cons */
3564  for( c = endidx - 1; c >= 0; --c )
3565  {
3566  cons1 = usefulconss[c];
3567 
3568  if( !SCIPconsIsActive(cons1) )
3569  continue;
3570 
3571  /* avoid checking constraint against itself */
3572  if( considx == c )
3573  continue;
3574 
3575  assert(usefulconss[c] != cons);
3576 
3577 #ifndef NDEBUG
3578  oldnaggrvars = *naggrvars;
3579 #endif
3580 
3581  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
3582  * possible
3583  */
3584  SCIP_CALL( presolvePropagateCons(scip, cons1, FALSE, undoneaggrvars, undoneaggrtypes, naggregations, saggregations, nfixedvars, naggrvars, ndelconss, cutoff) );
3585 
3586  if( *cutoff )
3587  return SCIP_OKAY;
3588 
3589  /* we can't handle aggregated variables later on so we should have saved them for later */
3590  assert(*naggrvars == oldnaggrvars);
3591 
3592  if( !SCIPconsIsActive(cons1) )
3593  continue;
3594 
3595  consdata1 = SCIPconsGetData(cons1);
3596  assert(consdata1 != NULL);
3597 
3598  nvars1 = consdata1->nvars;
3599 
3600  if( nvars1 == 0 )
3601  continue;
3602 
3603  /* no more variables from cons as nvars1 can overlap */
3604  assert(countofoverlapping[c] <= nvars1);
3605 
3606  /* constraint should not be redundant or infeasible */
3607  assert(consdata1->nfixedones == 0);
3608 
3609  SCIPdebugMsg(scip, "constraint <%s> overlaps with constraint <%s> by %d variables\n", SCIPconsGetName(cons), SCIPconsGetName(cons1), countofoverlapping[c]);
3610 
3611  /* cons1 includes cons */
3612  if( !overlapdestroyed && countofoverlapping[c] == nvars - consdata->nfixedzeros )
3613  {
3614  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
3615  {
3616  if( nvars - consdata->nfixedzeros < nvars1 )
3617  {
3618 #ifndef NDEBUG
3619  SCIP_Bool negated0;
3620  SCIP_Bool negated1;
3621 #endif
3622 
3623  /* both constraints should stay merged */
3624  assert(consdata->merged);
3625  assert(consdata1->merged);
3626 
3627  vars1 = consdata1->vars;
3628  assert(vars1 != NULL);
3629 
3630  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
3631  SCIPsortDownPtr((void**)vars1, SCIPvarCompActiveAndNegated, nvars1);
3632  /* standard setppc-sorting now lost */
3633  consdata1->sorted = FALSE;
3634 
3635  /* iterate over the both cliques variables the "same" time */
3636  for( v = nvars - 1, v1 = nvars1 - 1; v >= 0 && v1 >= 0; )
3637  {
3638  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3639  {
3640  --v1;
3641  continue;
3642  }
3643  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3644  {
3645  --v;
3646  continue;
3647  }
3648 
3649  /* all variables inside the second clique constraint should be either active or negated of an active one */
3650  assert(SCIPvarIsActive(vars1[v1]) || (SCIPvarGetStatus(vars1[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars1[v1]))));
3651 
3652  /* get not negated variable and clique value in cons */
3653  if( SCIPvarGetStatus(vars[v]) != SCIP_VARSTATUS_NEGATED )
3654  {
3655  var = vars[v];
3656 #ifndef NDEBUG
3657  negated0 = FALSE;
3658 #endif
3659  }
3660  else
3661  {
3662  var = SCIPvarGetNegationVar(vars[v]);
3663 #ifndef NDEBUG
3664  negated0 = TRUE;
3665 #endif
3666  }
3667 
3668  /* get active variable and clique value of next variable */
3669  if( SCIPvarIsActive(vars1[v1]) )
3670  {
3671  var1 = vars1[v1];
3672 #ifndef NDEBUG
3673  negated1 = FALSE;
3674 #endif
3675  }
3676  else
3677  {
3679  var1 = SCIPvarGetNegationVar(vars1[v1]);
3680 #ifndef NDEBUG
3681  negated1 = TRUE;
3682 #endif
3683  }
3684 
3685  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
3686  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
3687  --v;
3688  /* variable index in the constraint is greater than the other one, so fix this variable */
3689  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
3690  {
3691  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(vars1[v1]));
3692 
3693  /* fix all variables except the one which has the negated var in the clique to zero */
3694  SCIP_CALL( SCIPfixVar(scip, vars1[v1], 0.0, cutoff, &fixed) );
3695  if( *cutoff )
3696  {
3697  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3698 
3699  return SCIP_OKAY;
3700  }
3701 
3702  assert(fixed);
3703  ++(*nfixedvars);
3704  --v1;
3705  }
3706  else
3707  {
3708  /* because the constraint's are merged it is not possible that one constraint contains a negated
3709  * variable of another and because all variables in cons are in cons1 this should be really the
3710  * same variable here; so we can decrease v and v1
3711  */
3712  assert(negated0 == negated1);
3713 
3714  --v;
3715  --v1;
3716  }
3717  }
3718  /* maybe we ended because of cons(v reached -1) so try to add rest of cons1 to cons */
3719  for( ; v1 >= 0; --v1)
3720  {
3721  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3722  continue;
3723 
3724  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(vars1[v1]));
3725 
3726  /* fix all variables except the one which has the negated var in the clique to zero */
3727  SCIP_CALL( SCIPfixVar(scip, vars1[v1], 0.0, cutoff, &fixed) );
3728  if( *cutoff )
3729  {
3730  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3731 
3732  return SCIP_OKAY;
3733  }
3734 
3735  assert(fixed);
3736  ++(*nfixedvars);
3737  }
3738  }
3739 
3740  /* if caused by all fixings now this set partitioning constraint doesn't have any variable which was
3741  * fixed to one, it's infeasible */
3742  if( consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->nfixedzeros == nvars1 && consdata1->nfixedones != 1 ) /*lint !e641*/
3743  {
3744  SCIPdebugMsg(scip, "all variables in the set-partitioning constraint <%s> are fixed to zero, this leads to a cutoff\n", SCIPconsGetName(cons1));
3745  *cutoff = TRUE;
3746 
3747  return SCIP_OKAY;
3748  }
3749 
3750  assert(SCIPconsIsActive(cons1));
3751  /* delete second constraint */
3752  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> because it includes the setpartitioning constraint <%s> number <%d>\n", SCIPconsGetName(cons1), c, SCIPconsGetName(cons), considx);
3753 
3754  SCIP_CALL( SCIPupdateConsFlags(scip, cons, cons1) );
3755  SCIP_CALL( SCIPdelCons(scip, cons1) );
3756  ++(*ndelconss);
3757  }
3758  /* could already be deleted because the constraint was included in another set partition constraint */
3759  else if( SCIPconsIsActive(cons) )
3760  {
3761  /* delete cons due to redundancy to cons1 */
3762  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> due to inclusion in constraint <%s> number <%d>\n", SCIPconsGetName(cons), considx, SCIPconsGetName(cons1), c);
3763 
3764  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons) );
3765  SCIP_CALL( SCIPdelCons(scip, cons) );
3766  ++(*ndelconss);
3767  }
3768  }
3769  /* cons includes cons1
3770  *
3771  * @note that zero fixations from above can only appear through a set-partitioning constraint, this means if
3772  * cons was the set-partitioning constraint only variables which are not in this constraint could be fixed
3773  * to zero, and this also means that the overlapping variables in this particular case are still active or
3774  * fixed to 1
3775  * later on it could be possible that even variables in cons are fixed to zero, which can lead to wrong
3776  * results when checking if countofoverlapping[c] + consdata1->nfixedzeros == nvars1, because a fixed
3777  * variable could be counted twice
3778  */
3779  else if( (!overlapdestroyed && countofoverlapping[c] + consdata1->nfixedzeros == nvars1) || countofoverlapping[c] == nvars1 )
3780  {
3781  /* even in deleted constraints we may fix unfixed variables */
3782  if( consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
3783  {
3784  const int oldnfixedvars = *nfixedvars;
3785 #ifndef NDEBUG
3786  SCIP_Bool negated0;
3787  SCIP_Bool negated1;
3788 #endif
3789  /* both constraints should stay merged */
3790  assert(consdata->merged);
3791  assert(consdata1->merged);
3792 
3793  vars1 = consdata1->vars;
3794 
3795  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
3796  SCIPsortDownPtr((void**)vars1, SCIPvarCompActiveAndNegated, nvars1);
3797  /* standard setppc-sorting now lost */
3798  consdata1->sorted = FALSE;
3799 
3800  /* iterate over the both cliques variables the "same" time */
3801  for( v = nvars - 1, v1 = nvars1 - 1; v >= 0 && v1 >= 0; )
3802  {
3803  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3804  {
3805  --v1;
3806  continue;
3807  }
3808  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3809  {
3810  --v;
3811  continue;
3812  }
3813 
3814  /* all variables inside the second clique constraint should be either active or negated of an active one */
3815  assert(SCIPvarIsActive(vars1[v1]) || (SCIPvarGetStatus(vars1[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars1[v1]))));
3816  /* all variables inside the first clique constraint should be either active or negated of an active one */
3817  assert(SCIPvarIsActive(vars[v]) || (SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[v]))));
3818 
3819  /* get not negated variable and clique value in cons */
3820  if( SCIPvarIsActive(vars[v]) )
3821  {
3822  var = vars[v];
3823 #ifndef NDEBUG
3824  negated0 = FALSE;
3825 #endif
3826  }
3827  else
3828  {
3830  var = SCIPvarGetNegationVar(vars[v]);
3831 #ifndef NDEBUG
3832  negated0 = TRUE;
3833 #endif
3834  }
3835 
3836  /* get active variable and clique value of next variable */
3837  if( SCIPvarIsActive(vars1[v1]) )
3838  {
3839  var1 = vars1[v1];
3840 #ifndef NDEBUG
3841  negated1 = FALSE;
3842 #endif
3843  }
3844  else
3845  {
3847  var1 = SCIPvarGetNegationVar(vars1[v1]);
3848 #ifndef NDEBUG
3849  negated1 = TRUE;
3850 #endif
3851  }
3852 
3853  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
3854  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
3855  {
3856  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(var));
3857 
3858  /* fix all variables except the one which has the negated var in the clique to zero */
3859  SCIP_CALL( SCIPfixVar(scip, vars[v], 0.0, cutoff, &fixed) );
3860  if( *cutoff )
3861  {
3862  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3863 
3864  return SCIP_OKAY;
3865  }
3866 
3867  assert(fixed);
3868  ++(*nfixedvars);
3869 
3870  --v;
3871  }
3872  /* variable index in the constraint is greater than the other one, so fix this variable */
3873  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
3874  --v1;
3875  else
3876  {
3877  /* because the constraint's are merged it is not possible that one constraint contains a negated
3878  * variable of another and because all variables in cons1 are in cons this should be really the same
3879  * variable here; so we can decrease v and v1
3880  */
3881  assert(negated0 == negated1);
3882 
3883  --v;
3884  --v1;
3885  }
3886  }
3887 
3888  /* maybe we ended because of cons1(v1 reached -1) so try to add rest of cons to cons1 */
3889  for( ; v >= 0; --v)
3890  {
3891  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3892  continue;
3893 
3894  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because it is in the same clique with a complete set partitioning constraint\n", SCIPvarGetName(vars[v]));
3895 
3896  /* fix all variables except the one which has the negated var in the clique to zero */
3897  SCIP_CALL( SCIPfixVar(scip, vars[v], 0.0, cutoff, &fixed) );
3898  if( *cutoff )
3899  {
3900  SCIPdebugMsg(scip, "fixing led to cutoff\n");
3901 
3902  return SCIP_OKAY;
3903  }
3904 
3905  assert(fixed);
3906  ++(*nfixedvars);
3907  }
3908 
3909  /* if caused by all fixings now this set partitioning constraint doesn't have any variable which was
3910  * fixed to one, it's infeasible */
3911  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata->nfixedzeros == nvars && consdata->nfixedones != 1 ) /*lint !e641*/
3912  {
3913  SCIPdebugMsg(scip, "all variables in the set-partitioning constraint <%s> are fixed to zero, this leads to a cutoff\n", SCIPconsGetName(cons1));
3914  *cutoff = TRUE;
3915 
3916  return SCIP_OKAY;
3917  }
3918 
3919  /* could already be deleted because the constraint was included in another set partition constraint */
3920  if( SCIPconsIsActive(cons) )
3921  {
3922  /* delete cons because it include another set partitioning constraint */
3923  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> because it includes the setpartitioning constraint <%s> number <%d>\n", SCIPconsGetName(cons), considx, SCIPconsGetName(cons1), c);
3924  assert(SCIPconsIsActive(cons));
3925 
3926  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons) );
3927  SCIP_CALL( SCIPdelCons(scip, cons) );
3928  ++(*ndelconss);
3929  }
3930 
3931  /* due to fixings in cons0 mark overlapping invalid for checking with fixedzero variables together */
3932  if( oldnfixedvars < *nfixedvars )
3933  overlapdestroyed = TRUE;
3934  }
3935  else
3936  {
3937  assert(consdata1->setppctype == SCIP_SETPPCTYPE_PACKING); /*lint !e641*/
3938 
3939  /* delete cons1 due to redundancy to cons */
3940  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> due to inclusion in constraint <%s> number <%d>\n", SCIPconsGetName(cons1), c, SCIPconsGetName(cons), considx);
3941  assert(SCIPconsIsActive(cons1));
3942 
3943  SCIP_CALL( SCIPupdateConsFlags(scip, cons, cons1) );
3944  SCIP_CALL( SCIPdelCons(scip, cons1) );
3945  ++(*ndelconss);
3946  }
3947  }
3948  /* if cons has only one unfixed variable which is not in cons1 and cons1 has one variable which does not appaer in
3949  * cons and both constraints are setpartitioning constraints we might aggregate both not overlapping variables and
3950  * delete one constraint
3951  */
3952  else if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars - oldnfixedzeros - 1 && countofoverlapping[c] == nvars1 - 1 ) /*lint !e641*/
3953  {
3954  SCIP_VAR* aggvar1;
3955  SCIP_VAR* aggvar2;
3956  SCIP_Bool negated0;
3957  SCIP_Bool negated1;
3958 
3959  aggvar1 = NULL;
3960  aggvar2 = NULL;
3961 
3962  /* both constraints should stay merged */
3963  assert(consdata->merged);
3964  assert(consdata1->merged);
3965 
3966  vars1 = consdata1->vars;
3967 
3968  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
3969  SCIPsortDownPtr((void**)vars1, SCIPvarCompActiveAndNegated, nvars1);
3970  /* standard setppc-sorting now lost */
3971  consdata1->sorted = FALSE;
3972 
3973  /* iterate over the both cliques variables the "same" time */
3974  for( v = nvars - 1, v1 = nvars1 - 1; v >= 0 && v1 >= 0; )
3975  {
3976  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
3977  {
3978  --v1;
3979  continue;
3980  }
3981  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
3982  {
3983  --v;
3984  continue;
3985  }
3986 
3987  /* all variables inside the second clique constraint should be either active or negated of an active one */
3988  assert(SCIPvarIsActive(vars1[v1]) || (SCIPvarGetStatus(vars1[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars1[v1]))));
3989  /* all variables inside the first clique constraint should be either active or negated of an active one */
3990  assert(SCIPvarIsActive(vars[v]) || (SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[v]))));
3991 
3992  /* get not negated variable and clique value in cons */
3993  if( SCIPvarIsActive(vars[v]) )
3994  {
3995  var = vars[v];
3996  negated0 = FALSE;
3997  }
3998  else
3999  {
4001  var = SCIPvarGetNegationVar(vars[v]);
4002  negated0 = TRUE;
4003  }
4004 
4005  /* get active variable and clique value of next variable */
4006  if( SCIPvarIsActive(vars1[v1]) )
4007  {
4008  var1 = vars1[v1];
4009  negated1 = FALSE;
4010  }
4011  else
4012  {
4014  var1 = SCIPvarGetNegationVar(vars1[v1]);
4015  negated1 = TRUE;
4016  }
4017 
4018  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
4019  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
4020  {
4021  assert(aggvar1 == NULL);
4022  aggvar1 = vars[v];
4023 
4024  if( aggvar2 != NULL )
4025  break;
4026 
4027  --v;
4028  }
4029  /* variable index in the constraint is greater than the other one, so fix this variable */
4030  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
4031  {
4032  assert(aggvar2 == NULL);
4033  aggvar2 = vars1[v1];
4034 
4035  if( aggvar1 != NULL )
4036  break;
4037 
4038  --v1;
4039  }
4040  else
4041  {
4042  /* because the constraint's are merged it is not possible that one constraint contains a negated variable
4043  * of another, but both variables in both constraints still can be negated to each other
4044  */
4045  if( negated0 != negated1 )
4046  {
4047  /* cons is except for one variable equal to cons1 and the unequal variable in cons is negated
4048  * to the one in cons1, so the problem is infeasible
4049  */
4050  SCIPdebugMsg(scip, "two set-partitioning constraint <%s> and <%s> have only one variable not in common, but this variable <%s> appears in one constraint as the negated version as in the other constraint\n", SCIPconsGetName(cons), SCIPconsGetName(cons1), SCIPvarGetName(vars[v]));
4051  *cutoff = TRUE;
4052 
4053  return SCIP_OKAY;
4054  }
4055  --v;
4056  --v1;
4057  }
4058  }
4059 
4060  /* due to fixings, it is possible that there are no active variables left, we we did not recognize which variables we could aggregate */
4061  if( aggvar1 == NULL && aggvar2 == NULL )
4062  continue;
4063 
4064  /* determine second aggregation var, if not yet done */
4065  if( aggvar2 == NULL )
4066  {
4067  for( ; v1 >= 0; --v1)
4068  {
4069  if( SCIPvarGetLbLocal(vars1[v1]) > 0.5 || SCIPvarGetUbLocal(vars1[v1]) < 0.5 )
4070  continue;
4071 
4072  aggvar2 = vars1[v1];
4073  break;
4074  }
4075  }
4076  /* determine first aggregation var, if not yet done */
4077  else if( aggvar1 == NULL )
4078  {
4079  /* maybe we ended because of cons1(v1 reached -1) so find the aggvar1 in cons */
4080  for( ; v >= 0; --v)
4081  {
4082  if( SCIPvarGetLbLocal(vars[v]) > 0.5 || SCIPvarGetUbLocal(vars[v]) < 0.5 )
4083  continue;
4084 
4085  aggvar1 = vars[v];
4086  break;
4087  }
4088  }
4089 
4090  /* due to fixings, it is possible that there are no active variables left, we we did not recognize which variables we could aggregate */
4091  if( aggvar1 == NULL || aggvar2 == NULL )
4092  continue;
4093 
4094  SCIPdebugMsg(scip, "memorize the aggregation of <%s> == <%s>, because they are the last two variable which are different in these two set partitioning constraints <%s> <%s>\n", SCIPvarGetName(aggvar1), SCIPvarGetName(aggvar2), SCIPconsGetName(cons), SCIPconsGetName(cons1));
4095 
4096  /* resize the aggregation arrays if necessary */
4097  if( *saggregations == *naggregations )
4098  {
4099  *saggregations = SCIPcalcMemGrowSize(scip, *naggregations + 1);
4100  assert(*saggregations > *naggregations);
4101  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrtypes, *saggregations) );
4102  SCIP_CALL( SCIPreallocBufferArray(scip, &undoneaggrvars, 2 * (*saggregations)) );
4103 
4104  /* clear the aggregation type array to set the default to the aggregation of the form x + y = 1 */
4105  BMSclearMemoryArray(&(undoneaggrtypes[*naggregations]), *saggregations - *naggregations); /*lint !e866*/
4106  }
4107 
4108  /* memorize aagregation variables*/
4109  undoneaggrtypes[*naggregations] = TRUE;
4110  undoneaggrvars[2 * (*naggregations)] = aggvar1;
4111  undoneaggrvars[2 * (*naggregations) + 1] = aggvar2;
4112  ++(*naggregations);
4113 
4114  if( !SCIPdoNotAggr(scip) )
4115  {
4116  /* delete constraint */
4117  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> because it is dominated by constraint <%s>\n", SCIPconsGetName(cons1), c, SCIPconsGetName(cons));
4118  assert(SCIPconsIsActive(cons1));
4119 
4120  SCIP_CALL( SCIPupdateConsFlags(scip, cons, cons1) );
4121  SCIP_CALL( SCIPdelCons(scip, cons1) );
4122  ++(*ndelconss);
4123  }
4124  }
4125  /* w.l.o.g. cons is a setpartitioning constraint and countofoverlapping == nvars - oldnfixedzeros - 1 we can
4126  * delete all overlapping variables in cons1 and add the negated variable of the not overlapped variable to cons
4127  * 1; the result should be a shorter constraint with the same impact
4128  */
4129  else if( shrinking && !overlapdestroyed && countofoverlapping[c] > 1 && ((consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars - oldnfixedzeros - 1) || (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars1 - 1)) ) /*lint !e641*/
4130  {
4131  SCIP_CONSDATA* consdatachange;
4132  SCIP_VAR** varstostay;
4133  SCIP_VAR** varstochange;
4134  SCIP_CONS* constochange;
4135  SCIP_CONS* constostay;
4136  SCIP_VAR* addvar;
4137  SCIP_Bool negated0;
4138  SCIP_Bool negated1;
4139  int nvarstostay;
4140  int nvarstochange;
4141  int constochangeidx;
4142 #ifndef NDEBUG
4143  const int oldnchgcoefs = *nchgcoefs;
4144 #endif
4145 
4146  addvar = NULL;
4147 
4148  assert((consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING) != (consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING) || countofoverlapping[c] != nvars - 1 || countofoverlapping[c] != nvars1 - 1); /*lint !e641*/
4149 
4150  /* both constraints should stay merged */
4151  assert(consdata->merged);
4152  assert(consdata1->merged);
4153 
4154  /* sorting array after indices of variables, negated and active counterparts would stand side by side */
4155  SCIPsortDownPtr((void**)(consdata1->vars), SCIPvarCompActiveAndNegated, nvars1);
4156  /* standard setppc-sorting now lost */
4157  consdata1->sorted = FALSE;
4158 
4159  /* initialize variables */
4160  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && countofoverlapping[c] == nvars - oldnfixedzeros - 1) /*lint !e641*/
4161  {
4162  varstostay = vars;
4163  varstochange = consdata1->vars;
4164  nvarstostay = nvars;
4165  nvarstochange = nvars1;
4166  constostay = cons;
4167  constochange = cons1;
4168  consdatachange = consdata1;
4169  constochangeidx = c;
4170  }
4171  else
4172  {
4173  varstostay = consdata1->vars;
4174  varstochange = vars;
4175  nvarstostay = nvars1;
4176  nvarstochange = nvars;
4177  constostay = cons1;
4178  constochange = cons;
4179  consdatachange = consdata;
4180  constochangeidx = considx;
4181 
4182  *chgcons = TRUE;
4183  }
4184 
4185  /* iterate over the both cliques variables the "same" time, here we need the backward loop, because we
4186  * delete some variables and we don not want to loose order
4187  */
4188  for( v = nvarstostay - 1, v1 = nvarstochange - 1; v >= 0 && v1 >= 0; )
4189  {
4190  if( SCIPvarGetLbLocal(varstochange[v1]) > 0.5 || SCIPvarGetUbLocal(varstochange[v1]) < 0.5 )
4191  {
4192  --v1;
4193  continue;
4194  }
4195  if( SCIPvarGetLbLocal(varstostay[v]) > 0.5 || SCIPvarGetUbLocal(varstostay[v]) < 0.5 )
4196  {
4197  --v;
4198  continue;
4199  }
4200 
4201  /* all variables inside the second clique constraint should be either active or negated of an active one */
4202  assert(SCIPvarIsActive(varstochange[v1]) || (SCIPvarGetStatus(varstochange[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstochange[v1]))));
4203  /* all variables inside the first clique constraint should be either active or negated of an active one */
4204  assert(SCIPvarIsActive(varstostay[v]) || (SCIPvarGetStatus(varstostay[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstostay[v]))));
4205 
4206  /* get not negated variable and clique value in constostay */
4207  if( SCIPvarIsActive(varstostay[v]) )
4208  {
4209  var = varstostay[v];
4210  negated0 = FALSE;
4211  }
4212  else
4213  {
4214  assert(SCIPvarGetStatus(varstostay[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstostay[v])));
4215  var = SCIPvarGetNegationVar(varstostay[v]);
4216  negated0 = TRUE;
4217  }
4218 
4219  /* get active variable and clique value of in constochange*/
4220  if( SCIPvarIsActive(varstochange[v1]) )
4221  {
4222  var1 = varstochange[v1];
4223  negated1 = FALSE;
4224  }
4225  else
4226  {
4227  assert(SCIPvarGetStatus(varstochange[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstochange[v1])));
4228  var1 = SCIPvarGetNegationVar(varstochange[v1]);
4229  negated1 = TRUE;
4230  }
4231 
4232  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
4233  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
4234  {
4235  assert(addvar == NULL);
4236  addvar = varstostay[v];
4237  --v;
4238  }
4239  /* variable index in the constraint is greater than the other one, so fix this variable */
4240  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
4241  {
4242  --v1;
4243  }
4244  else
4245  {
4246  /* because the constraint's are merged it is not possible that one constraint contains a negated variable
4247  * of another, but both constraint might have a variable in neagted form of the other
4248  */
4249  if( negated0 != negated1 )
4250  {
4251  assert(addvar == NULL);
4252 
4253  SCIPdebugMsg(scip, "-> trying to fix <%s> to 0 because it would exist twice in a constraint\n", SCIPvarGetName(varstochange[v1]));
4254 
4255  /* fix variable to zero */
4256  SCIP_CALL( SCIPfixVar(scip, varstochange[v1], 0.0, cutoff, &fixed) );
4257  if( *cutoff )
4258  {
4259  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4260 
4261  return SCIP_OKAY;
4262  }
4263 
4264  assert(fixed);
4265  ++(*nfixedvars);
4266 
4267  /* the above fixing is equal to the fixation of varstostay[v] to 1, so we can call presolvePropagateCons() for consstay */
4268  SCIP_CALL( presolvePropagateCons(scip, constostay, FALSE, NULL, NULL, NULL, NULL, nfixedvars, naggrvars, ndelconss, cutoff) );
4269 
4270  return SCIP_OKAY;
4271  }
4272  else
4273  {
4274  /* correct local data structure, remove variable from constraint entry where it will be removed */
4275  deleteCliqueDataEntry(varstochange[v1], constochangeidx, vartoindex, varnconss, varconsidxs);
4276 
4277  SCIPdebugMsg(scip, " -> deleting variable <%s> in constraint <%s> number %d, because it will be replaced\n", SCIPvarGetName(varstochange[v1]), SCIPconsGetName(constochange), constochangeidx);
4278  /* delete overlapping variabes in constochange */
4279  SCIP_CALL( delCoefPos(scip, constochange, v1) );
4280  ++(*nchgcoefs);
4281  }
4282 
4283  --v;
4284  --v1;
4285  }
4286  }
4287  assert(addvar != NULL || v >= 0);
4288  /* we should have removed exactly countofoverlapping[c] variables from the constochange */
4289  assert(*nchgcoefs - oldnchgcoefs == countofoverlapping[c]);
4290 
4291  /* determine addvar if not yet found */
4292  if( addvar == NULL )
4293  {
4294  for( ; v >= 0; --v)
4295  {
4296  if( SCIPvarGetLbLocal(varstostay[v]) > 0.5 || SCIPvarGetUbLocal(varstostay[v]) < 0.5 )
4297  continue;
4298 
4299  /* all variables inside the first clique constraint should be either active or negated of an active one */
4300  assert(SCIPvarIsActive(varstostay[v]) || (SCIPvarGetStatus(varstostay[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(varstostay[v]))));
4301 
4302  addvar = varstostay[v];
4303  break;
4304  }
4305  }
4306  assert(addvar != NULL);
4307 
4308  /* get representative variable for all deleted variables */
4309  SCIP_CALL( SCIPgetNegatedVar(scip, addvar, &addvar) );
4310  assert(addvar != NULL);
4311 
4312  SCIPdebugMsg(scip, " -> adding variable <%s> to constraint <%s> number %d\n", SCIPvarGetName(addvar), SCIPconsGetName(constochange), constochangeidx);
4313  /* add representative for overlapping instead */
4314  SCIP_CALL( addCoef(scip, constochange, addvar) );
4315  ++(*nchgcoefs);
4316 
4317  /* constraint should be still merged because this added variable is new in this constraint */
4318  consdatachange->merged = TRUE;
4319  assert(constochangeidx == (cons == constochange ? considx : c));
4320 
4321  /* correct local data structure, add constraint entry to variable data */
4322  SCIP_CALL( addCliqueDataEntry(scip, addvar, constochangeidx, TRUE, usefulvars, nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs) );
4323 
4324  /* cons changed so much, that it cannot be used for more overlapping checks */
4325  if( *chgcons )
4326  return SCIP_OKAY;
4327  }
4328  }
4329 
4330  return SCIP_OKAY;
4331 }
4332 
4333 /** try to lift variables to given constraint */
4334 /** @todo try another variant by determine lifting variables as the intersection of all cliques variables of the
4335  * constraint variables, note that the insection changes after one variable was added
4336  */
4337 static
4339  SCIP*const scip, /**< SCIP data structure */
4340  SCIP_CONS*const cons, /**< constraint which may overlap */
4341  int const arraypos, /**< position of constraint in global array */
4342  SCIP_VAR**const usefulvars, /**< possible variables to lift */
4343  int*const nusefulvars, /**< pointer to store number of added variables */
4344  int const endidx, /**< end index for possible lifting variables */
4345  SCIP_Bool** cliquevalues, /**< pointer to clique values of constraint-variables, either one if the
4346  * varibale is active or zero if the variable is negated
4347  * @note this array can be resized in this method
4348  */
4349  SCIP_HASHMAP*const vartoindex, /**< hashmap mapping variables to indices */
4350  int*const varnconss, /**< array with number of constraints a variable occurs */
4351  int*const maxnvarconsidx, /**< array with the maximal number of occurances of a variable */
4352  int**const varconsidxs, /**< array with constraint indices in which the corresponding variable
4353  * exists
4354  */
4355  int*const maxnvars, /**< pointer to store maximal number of variables of a constraint */
4356  int*const nadded, /**< pointer to store number of possible added variables */
4357  SCIP_Bool*const chgcons, /**< pointer to store if the constraint was changed, due to added
4358  * variables
4359  */
4360  int*const nfixedvars, /**< pointer to count number of deleted variables */
4361  int*const ndelconss, /**< pointer to count number of deleted constraints */
4362  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
4363  )
4364 {
4365  SCIP_CONSDATA* consdata;
4366  SCIP_VAR** vars;
4367  SCIP_VAR* var;
4368  SCIP_VAR* var1;
4369  SCIP_Bool fixed;
4370  SCIP_Bool value;
4371  int nvars;
4372  int nottocheck; /* will be the position for a variable in cons0 which is in negated form in the same clique */
4373  int v;
4374  int v1;
4375  int k;
4376 
4377  assert(scip != NULL);
4378  assert(cons != NULL);
4379  assert(usefulvars != NULL);
4380  assert(cliquevalues != NULL);
4381  assert(*cliquevalues != NULL);
4382  assert(vartoindex != NULL);
4383  assert(varnconss != NULL);
4384  assert(maxnvarconsidx != NULL);
4385  assert(varconsidxs != NULL);
4386  assert(maxnvars != NULL);
4387  assert(nadded != NULL);
4388  assert(chgcons != NULL);
4389  assert(nfixedvars != NULL);
4390  assert(ndelconss != NULL);
4391  assert(cutoff != NULL);
4392 
4393  if( !SCIPconsIsActive(cons) )
4394  return SCIP_OKAY;
4395 
4396  consdata = SCIPconsGetData(cons);
4397  assert(consdata != NULL);
4398 
4399  nvars = consdata->nvars;
4400 
4401  if( nvars == 0 )
4402  return SCIP_OKAY;
4403 
4404  assert(nvars <= *maxnvars);
4405 
4406  vars = consdata->vars;
4407  assert(vars != NULL);
4408 
4409  v1 = endidx;
4410 
4411  /* now we try to add variables with index prior to endidx to cons */
4412  for( v = nvars - 1; v >= 0 && v1 >= 0; )
4413  {
4414  if( SCIPvarGetLbLocal(usefulvars[v1]) > 0.5 || SCIPvarGetUbLocal(usefulvars[v1]) < 0.5 )
4415  {
4416  --v1;
4417  continue;
4418  }
4419  if( SCIPvarGetUbLocal(vars[v]) < 0.5 )
4420  {
4421  --v;
4422  continue;
4423  }
4424 
4425  /* check that constraint variables are still correctly sorted, indices of active variables should be decreasing */
4426  assert(v == 0 || SCIPvarCompareActiveAndNegated(vars[v], vars[v - 1]) <= 0);
4427 
4428  /* there should no variables fixed to one occur in our constraint */
4429  assert(SCIPvarGetLbLocal(vars[v]) < 0.5 && SCIPvarGetUbLocal(vars[v]) > 0.5);
4430  assert(SCIPvarGetLbLocal(usefulvars[v1]) < 0.5 && SCIPvarGetUbLocal(usefulvars[v1]) > 0.5);
4431 
4432  /* all variables which we have inside the clique constraint and which can possibly be added should be either active or negated */
4433  assert(SCIPvarIsActive(vars[v]) || (SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[v]))));
4434  assert(SCIPvarIsActive(usefulvars[v1]) || (SCIPvarGetStatus(usefulvars[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(usefulvars[v1]))));
4435 
4436  /* constraint should during adding of variables stay merged, because for each variable which is added holds that
4437  * the index of this corresponding active variable is pairwise different to all indices of all active
4438  * corresponding variables inside the constraint
4439  * @note it should not happen that we add one variable and the corresponding counterpart to the same constraint */
4440  assert(consdata->merged);
4441 
4442  /* get active variable and clique value in cons */
4443  if( (*cliquevalues)[v] )
4444  var = vars[v];
4445  else
4446  {
4448  var = SCIPvarGetNegationVar(vars[v]);
4449  }
4450 
4451  /* get active variable and clique value of next variable */
4452  if( SCIPvarIsActive(usefulvars[v1]) )
4453  {
4454  var1 = usefulvars[v1];
4455  value = TRUE;
4456  }
4457  else
4458  {
4459  assert(SCIPvarGetStatus(usefulvars[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(usefulvars[v1])));
4460  var1 = SCIPvarGetNegationVar(usefulvars[v1]);
4461  value = FALSE;
4462  }
4463 
4464  nottocheck = -1;
4465  k = 0;
4466 
4467  /* variable index in the constraint smaller than the other one, so go to the next variable in cons */
4468  if( SCIPvarGetIndex(var) < SCIPvarGetIndex(var1) )
4469  {
4470  --v;
4471  continue;
4472  }
4473  /* variable index in the constraint is greater than the other one, so check for possible inclusion of the variable */
4474  else if( SCIPvarGetIndex(var) > SCIPvarGetIndex(var1) )
4475  {
4476  assert(consdata == SCIPconsGetData(cons));
4477 
4478  /* check if every variable in the actual clique is in clique with the new variable */
4479  for( k = nvars - 1; k >= 0; --k )
4480  {
4481  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4482  {
4483  /* there should no variables fixed to one occur in our constraint */
4484  assert(SCIPvarGetLbLocal(vars[k]) < 0.5);
4485  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4486 
4487  if( (*cliquevalues)[k] )
4488  {
4489  assert(SCIPvarIsActive(vars[k]));
4490  var = vars[k];
4491  }
4492  else
4493  {
4495  var = SCIPvarGetNegationVar(vars[k]);
4496  }
4497  if( !SCIPhaveVarsCommonClique(scip, var1, value, var, (*cliquevalues)[k], TRUE) )
4498  break;
4499  }
4500  }
4501  --v1;
4502  }
4503  /* variable index in the constraint is equal to the index of the other variable, check if these variables are
4504  * negated of each other so memorize the position and check for possible inclusion of the new variable and if
4505  * possible decrease indices
4506  */
4507  else
4508  {
4509  /* one clique contains the negated and the other clique the corresponding active var */
4510  if( value != (*cliquevalues)[v] )
4511  {
4512  nottocheck = v;
4513 
4514  assert(consdata == SCIPconsGetData(cons));
4515  assert(nvars <= consdata->nvars);
4516 
4517  /* check if every variable in the actual clique is in clique with the new variable */
4518  for( k = nvars - 1; k >= 0; --k )
4519  {
4520  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4521  {
4522  /* there should no variables fixed to one occur in our constraint */
4523  assert(SCIPvarGetLbLocal(vars[k]) < 0.5);
4524 
4525  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4526 
4527  if( k == nottocheck )
4528  continue;
4529 
4530  if( (*cliquevalues)[k] )
4531  {
4532  assert(SCIPvarIsActive(vars[k]));
4533  var = vars[k];
4534  }
4535  else
4536  {
4538  var = SCIPvarGetNegationVar(vars[k]);
4539  }
4540 
4541  if( !SCIPhaveVarsCommonClique(scip, var1, value, var, (*cliquevalues)[k], TRUE) )
4542  break;
4543  }
4544  }
4545  }
4546  /* don't decrease v because it might happen that the corresponding negated variable of var is next in
4547  * usefulvars
4548  */
4549  --v1;
4550  }
4551 
4552  /* if k is smaller than 0 than the possible new variables is in the same clique with all variables of cons,
4553  * so we add the new variable to clique constraint or fix some variables */
4554  if( k < 0 )
4555  {
4556  ++(*nadded);
4557 
4558  /* we found a variable which is the negated variable of another one in this clique so we can fix all
4559  * other variable to zero and if it's a partitioning constraint we can also fix the variable of the
4560  * negated to one and we can delete the constraint too */
4561  if( nottocheck >= 0 )
4562  {
4563  assert(consdata == SCIPconsGetData(cons));
4564  assert(nvars <= consdata->nvars);
4565  assert(consdata->merged);
4566 
4567  /* process all vars for possible fixing */
4568  for( k = consdata->nvars - 1; k >= 0; --k )
4569  {
4570  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4571  {
4572  /* there should no variables fixed to one occur in our constraint */
4573  assert(SCIPvarGetLbLocal(vars[v]) < 0.5);
4574 
4575  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4576 
4577  if( k != nottocheck )
4578  {
4579  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because we could lift a negated variable of another constraint variable\n", SCIPvarGetName(vars[k]));
4580  /* fix variable to zero */
4581  SCIP_CALL( SCIPfixVar(scip, vars[k], 0.0, cutoff, &fixed) );
4582 
4583  if( *cutoff )
4584  {
4585  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4586 
4587  return SCIP_OKAY;
4588  }
4589 
4590  assert(fixed);
4591 
4592  ++(*nfixedvars);
4593  }
4594  }
4595  }
4596  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
4597  {
4598  assert(SCIPvarIsActive(vars[nottocheck]) || (SCIPvarGetStatus(vars[nottocheck]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[nottocheck]))));
4599 
4600  SCIPdebugMsg(scip, "trying to fix <%s> to 1 due to this setpartitioning variable is with its negated in the same clique\n", SCIPvarGetName(vars[nottocheck]));
4601  /* fix the remaining variable to one, due to it's the only one left to satisfy the constraint */
4602  SCIP_CALL( SCIPfixVar(scip, vars[nottocheck], 1.0, cutoff, &fixed) );
4603  if( *cutoff )
4604  {
4605  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4606 
4607  return SCIP_OKAY;
4608  }
4609 
4610  assert(fixed);
4611  ++(*nfixedvars);
4612  }
4613 
4614  /* delete constraint */
4615  SCIPdebugMsg(scip, " -> deleting constraint <%s> number <%d> due to active and negated variable in the same clique constraint\n", SCIPconsGetName(cons), arraypos);
4616  assert(SCIPconsIsActive(cons));
4617  SCIP_CALL( SCIPdelCons(scip, cons) );
4618  ++(*ndelconss);
4619 
4620  break;
4621  }
4622  /* we found a variable which could be added to a partitioning constraint so we can fix it to zero */
4623  else if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
4624  {
4625  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because this variable is in the same clique with a set partition\n", SCIPvarGetName(usefulvars[v1 + 1]));
4626  /* fix variable to zero */
4627  SCIP_CALL( SCIPfixVar(scip, usefulvars[v1 + 1], 0.0, cutoff, &fixed) );
4628 
4629  if( *cutoff )
4630  {
4631  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4632 
4633  return SCIP_OKAY;
4634  }
4635 
4636  assert(fixed);
4637 
4638  ++(*nfixedvars);
4639  }
4640  /* we have found a new variable for a set packing constraint cons, so add the found variable to the first constraint */
4641  else
4642  {
4643  SCIP_VAR* addvar;
4644 
4645  assert(SCIPconsIsActive(cons));
4646 
4647  addvar = usefulvars[v1 + 1];
4648 
4649  assert(SCIPvarGetLbLocal(addvar) < 0.5 && SCIPvarGetUbLocal(addvar) > 0.5);
4650 
4651  /* add representative instead */
4652  SCIPdebugMsg(scip, " -> adding variable <%s> to constraint <%s> number %d\n", SCIPvarGetName(usefulvars[v1 + 1]), SCIPconsGetName(cons), arraypos);
4653  SCIP_CALL( addCoef(scip, cons, addvar) );
4654  assert(consdata == SCIPconsGetData(cons));
4655  /* we know that this constraint stays merged but later on we have to resort */
4656  consdata->merged = TRUE;
4657 
4658  /* second we add the constraint index to the list of indices where this variable occurs */
4659  assert(SCIPhashmapExists(vartoindex, (void*) addvar));
4660 
4661  /* correct local data structure, add constraint entry to variable data */
4662  SCIP_CALL( addCliqueDataEntry(scip, addvar, arraypos, FALSE, usefulvars, nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs) );
4663 
4664  /* we need the new pointer to the variables, because due to adding variables it is possible that we
4665  * did reallocate the variables array inside the constraint, the index v should stay the same because the
4666  * added variable was inserted at the end and we are decreasing v in our for loop
4667  */
4668  vars = consdata->vars;
4669  nvars = consdata->nvars;
4670 
4671  /* we need to update our data structure */
4672 
4673  /* resize clique array if necessary, due to adding variables */
4674  if( (*maxnvars) < nvars )
4675  {
4676  while( (*maxnvars) < nvars )
4677  (*maxnvars) *= 2 ;
4678  SCIP_CALL( SCIPreallocBufferArray(scip, cliquevalues, (*maxnvars)) );
4679  }
4680  (*cliquevalues)[nvars - 1] = SCIPvarIsActive(addvar) ? TRUE : FALSE;
4681 
4682  (*chgcons) = TRUE;
4683  }
4684  }
4685  }
4686 
4687  if( !SCIPconsIsActive(cons) )
4688  return SCIP_OKAY;
4689 
4690  /* maybe we stopped because of cons(v reached -1) so try to add rest in usefulvars */
4691  for( ; v1 >= 0; --v1)
4692  {
4693  if( SCIPvarGetLbLocal(usefulvars[v1]) > 0.5 || SCIPvarGetUbLocal(usefulvars[v1]) < 0.5 )
4694  continue;
4695 
4696  /* get active variable and clique value */
4697  if( SCIPvarIsActive(usefulvars[v1]) )
4698  {
4699  var1 = usefulvars[v1];
4700  value = TRUE;
4701  }
4702  else
4703  {
4704  assert(SCIPvarGetStatus(usefulvars[v1]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(usefulvars[v1])));
4705  var1 = SCIPvarGetNegationVar(usefulvars[v1]);
4706  value = FALSE;
4707  }
4708 
4709  assert(consdata == SCIPconsGetData(cons));
4710  assert(nvars <= consdata->nvars);
4711 
4712  /* check if every variable in the actual clique is in clique with the new variable */
4713  for( k = nvars - 1; k >= 0; --k )
4714  {
4715  if( SCIPvarGetUbLocal(vars[k]) > 0.5 )
4716  {
4717  /* there should no variables fixed to one occur in our constraint */
4718  assert(SCIPvarGetLbLocal(vars[k]) < 0.5);
4719 
4720  assert(SCIPvarIsActive(vars[k]) || (SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(vars[k]))));
4721 
4722  if( (*cliquevalues)[k] )
4723  {
4724  assert(SCIPvarIsActive(vars[k]));
4725  var = vars[k];
4726  }
4727  else
4728  {
4730  var = SCIPvarGetNegationVar(vars[k]);
4731  }
4732 
4733  if( !SCIPvarsHaveCommonClique(var1, value, var, (*cliquevalues)[k], TRUE) )
4734  break;
4735  }
4736  }
4737 
4738  /* add new variable to clique constraint or fix some variables */
4739  if( k < 0 )
4740  {
4741  /* we found a variable which could be added to a partitioning constraint so we can fix it to zero */
4742  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
4743  {
4744  SCIPdebugMsg(scip, "trying to fix <%s> to 0 because this variable is in the same clique with a set partition\n", SCIPvarGetName(usefulvars[v1]));
4745 
4746  /* fix variable to zero */
4747  SCIP_CALL( SCIPfixVar(scip, usefulvars[v1], 0.0, cutoff, &fixed) );
4748  if( *cutoff )
4749  {
4750  SCIPdebugMsg(scip, "fixing led to cutoff\n");
4751 
4752  return SCIP_OKAY;
4753  }
4754  assert(fixed);
4755 
4756  ++(*nfixedvars);
4757  ++(*nadded);
4758  }
4759  /* add the found variable to the first constraint */
4760  else
4761  {
4762  SCIP_VAR* addvar;
4763 
4764  assert(SCIPconsIsActive(cons));
4765 
4766  addvar = usefulvars[v1];
4767 
4768  assert(SCIPvarGetLbLocal(addvar) < 0.5 && SCIPvarGetUbLocal(addvar) > 0.5);
4769 
4770  /* add representative instead */
4771  SCIPdebugMsg(scip, " -> adding variable <%s> to constraint <%s> number %d\n", SCIPvarGetName(addvar), SCIPconsGetName(cons), arraypos);
4772  SCIP_CALL( addCoef(scip, cons, addvar) );
4773  assert(consdata == SCIPconsGetData(cons));
4774  /* we know that this constraint stays merged but later on we have to resort */
4775  consdata->merged = TRUE;
4776 
4777  /* second we add the constraint index to the list of indices where this variable occurs */
4778  assert(SCIPhashmapExists(vartoindex, (void*) addvar));
4779 
4780  /* correct local data structure, add constraint entry to variable data */
4781  SCIP_CALL( addCliqueDataEntry(scip, addvar, arraypos, FALSE, usefulvars, nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs) );
4782 
4783  /* we need the new pointer to the variables, because due to adding variables it is possible that we
4784  * did reallocate the variables array inside the constraint, the index v should stay the same because the
4785  * added variable was inserted at the end and we are decreasing v in our for loop
4786  */
4787  vars = consdata->vars;
4788  nvars = consdata->nvars;
4789 
4790  /* we need to update our data structure */
4791 
4792  /* resize clique array if necessary, due to adding variables */
4793  if( (*maxnvars) < nvars )
4794  {
4795  while( (*maxnvars) < nvars )
4796  (*maxnvars) *= 2 ;
4797  SCIP_CALL( SCIPreallocBufferArray(scip, cliquevalues, (*maxnvars)) );
4798  }
4799  (*cliquevalues)[nvars - 1] = SCIPvarIsActive(addvar) ? TRUE : FALSE;
4800 
4801  ++(*nadded);
4802  (*chgcons) = TRUE;
4803  }
4804  }
4805  }
4806 
4807  return SCIP_OKAY;
4808 }
4809 
4810 /** perform all collected aggregations */
4811 static
4813  SCIP*const scip, /**< SCIP data structure */
4814  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
4815  SCIP_VAR**const undoneaggrvars, /**< aggregation variables storage */
4816  SCIP_Bool*const undoneaggrtypes, /**< aggregation type storage, type FALSE means the aggregation is of the
4817  * form x + y = 1; type TRUE means the aggregation is of the form x = y;
4818  */
4819  int const naggregations, /**< number of aggregations to performed */
4820  int*const naggrvars, /**< pointer to count number of aggregated variables */
4821  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
4822  )
4823 { /*lint --e{715}*/
4824  SCIP_VAR* var1;
4825  SCIP_VAR* var2;
4826  SCIP_Bool aggregated;
4827  SCIP_Bool redundant;
4828  int a;
4829 
4830  assert(scip != NULL);
4831  assert(conshdlrdata != NULL);
4832  assert(undoneaggrvars != NULL);
4833  assert(undoneaggrtypes != NULL);
4834  assert(naggregations > 0);
4835  assert(naggrvars != NULL);
4836  assert(cutoff != NULL);
4837 
4838  /* loop over all open aggreagtions and try to aggregate them */
4839  for( a = 0; a < naggregations; ++a )
4840  {
4841  var1 = undoneaggrvars[2 * a];
4842  var2 = undoneaggrvars[2 * a + 1];
4843  assert(var1 != NULL);
4844  assert(var2 != NULL);
4845 
4846  SCIPdebugMsg(scip, "trying to aggregate <%s> %s <%s>%s\n", SCIPvarGetName(var1), undoneaggrtypes[a] ? "=" : "+", SCIPvarGetName(var2), undoneaggrtypes[a] ? "" : " = 1");
4847 
4848 #ifdef VARUSES
4849  /* in order to not mess up the variable usage counting, we have to decrease usage counting, aggregate,
4850  * and increase usage counting again
4851  */
4852  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, var1) );
4853  SCIP_CALL( conshdlrdataDecVaruses(scip, conshdlrdata, var2) );
4854 #endif
4855 
4856  /* aggregate last remaining variables in the set partitioning constraint */
4857  if( undoneaggrtypes[a] )
4858  {
4859  SCIP_CALL( SCIPaggregateVars(scip, var1, var2, 1.0, -1.0, 0.0, cutoff, &redundant, &aggregated) );
4860  }
4861  else
4862  {
4863  SCIP_CALL( SCIPaggregateVars(scip, var1, var2, 1.0, 1.0, 1.0, cutoff, &redundant, &aggregated) );
4864  }
4865 
4866  if( *cutoff )
4867  {
4868  SCIPdebugMsg(scip, "aggregation was infeasible\n");
4869 
4870  return SCIP_OKAY;
4871  }
4872  /* binary variables should always be aggregated, or due to fixation the aggregation is redundant */
4873  assert(redundant);
4874 
4875  if( aggregated )
4876  ++(*naggrvars);
4877 
4878 #ifdef VARUSES
4879  /* increase variable usage counting again */
4880  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var1) );
4881  SCIP_CALL( conshdlrdataIncVaruses(scip, conshdlrdata, var2) );
4882 #endif
4883  }
4884 
4885  return SCIP_OKAY;
4886 }
4887 
4888 /** check whether we can combine or grow cliques so some constraints become redundant or we can fix variables */
4889 /** @todo try another variant, by building up the clique graph and delete unnecessary (transitive closure) edges and do
4890  * a bfs search to search for common ancestors to get all possible lifting variables
4891  */
4892 static
4894  SCIP*const scip, /**< SCIP data structure */
4895  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
4896  SCIP_CONS**const conss, /**< constraint set */
4897  int const nconss, /**< number of constraints in constraint set */
4898  int const nrounds, /**< actual presolving round */
4899  int*const firstchange, /**< pointer to store first changed constraint */
4900  int*const firstclique, /**< pointer to store first constraint to start adding clique again */
4901  int*const lastclique, /**< pointer to store last constraint to add cliques again */
4902  int*const nfixedvars, /**< pointer to count number of deleted variables */
4903  int*const naggrvars, /**< pointer to count number of aggregated variables */
4904  int*const ndelconss, /**< pointer to count number of deleted constraints */
4905  int*const nchgcoefs, /**< pointer to count number of deleted coefficients */
4906  SCIP_Bool*const cutoff /**< pointer to store if the problem is infeasible due to a fixing */
4907  )
4908 {
4909  /* extend cliques/constraints by checking whether some variables are in the same clique, no pairwise clique lifting
4910  * which would be slower
4911  */
4912  SCIP_CONS** usefulconss; /* array with pointers of constraint of setpartitioning and setpacking type */
4913  SCIP_VAR** usefulvars; /* array with pointers of variables in setpartitioning and setpacking constraints */
4914  int** varconsidxs; /* array consisting of constraint indices in which the corresponding variable exists */
4915  int* varnconss; /* array consisting of number of constraints the variable occurs */
4916  int* maxnvarconsidx; /* maximal number of occurances of a variable */
4917  int* countofoverlapping = NULL; /* the amount of variables which are in another constraint */
4918  SCIP_Bool* cliquevalues = NULL; /* values of clique-variables, either one if the varibale is active or zero if the variable is negated */
4919 
4920  SCIP_HASHMAP* vartoindex; /* mapping of SCIP variables to indices */
4921  SCIP_CONSDATA* consdata;
4922 
4923  SCIP_Bool chgcons0;
4924  int nvars;
4925  int c;
4926  int v;
4927  int nusefulconss;
4928  int nusefulvars;
4929  int susefulvars;
4930  int maxnvars;
4931  int varindex;
4932 
4933  SCIP_VAR** undoneaggrvars; /* storage for not yet performed aggregations */
4934  SCIP_Bool* undoneaggrtypes; /* storage for not yet performed aggregation type (x = y or x + y = 1) */
4935  int saggregations;
4936  int naggregations;
4937 
4938  assert(scip != NULL);
4939  assert(conshdlrdata != NULL);
4940  assert(conss != NULL || nconss == 0);
4941  assert(firstchange != NULL);
4942  assert(firstclique != NULL);
4943  assert(lastclique != NULL);
4944  assert(nfixedvars != NULL);
4945  assert(naggrvars != NULL);
4946  assert(ndelconss != NULL);
4947  assert(nchgcoefs != NULL);
4948  assert(cutoff != NULL);
4949 
4950  *cutoff = FALSE;
4951 
4952  if( nconss == 0 )
4953  return SCIP_OKAY;
4954 
4955  nvars = SCIPgetNVars(scip);
4956 
4957  if( nvars == 0 )
4958  return SCIP_OKAY;
4959 
4960  susefulvars = 2 * nvars; /* two times because of negated vars, maybe due to deleted variables we need to increase this */
4961 
4962  /* a hashmap from varindex to postion in varconsidxs array, because above is still too small */
4963  SCIP_CALL( SCIPhashmapCreate(&vartoindex, SCIPblkmem(scip), nvars) );
4964 
4965  /* get temporary memory for the aggregation storage, to memorize aggregations which will be performed later, otherwise we would destroy our local data structures */
4966  saggregations = nvars;
4967  SCIP_CALL( SCIPallocBufferArray(scip, &undoneaggrvars, 2 * saggregations) );
4968  SCIP_CALL( SCIPallocBufferArray(scip, &undoneaggrtypes, saggregations) );
4969  BMSclearMemoryArray(undoneaggrtypes, saggregations);
4970  naggregations = 0;
4971 
4972  /* get temporary memory for all clique constraints, all appearing variables and the mapping from variables to constraints */
4973  SCIP_CALL( SCIPallocBufferArray(scip, &usefulconss, nconss) );
4974  SCIP_CALL( SCIPallocBufferArray(scip, &usefulvars, susefulvars) );
4975  BMSclearMemoryArray(usefulvars, susefulvars);
4976  SCIP_CALL( SCIPallocBufferArray(scip, &varnconss, susefulvars + 1) );
4977  BMSclearMemoryArray(varnconss, susefulvars + 1);
4978  SCIP_CALL( SCIPallocBufferArray(scip, &maxnvarconsidx, susefulvars + 1) );
4979  SCIP_CALL( SCIPallocBufferArray(scip, &varconsidxs, susefulvars + 1) );
4980  BMSclearMemoryArray(varconsidxs, susefulvars + 1);
4981  nusefulvars = 0;
4982  nusefulconss = 0;
4983  maxnvars = 0;
4984 
4985  /* @todo: check for round limit for adding extra clique constraints */
4986  /* adding clique constraints which arises from global clique information */
4987  if( conshdlrdata->nclqpresolve == 0 && conshdlrdata->addvariablesascliques )
4988  {
4989  SCIP_VAR** vars = SCIPgetVars(scip);
4990  SCIP_VAR** binvars;
4991  int* cliquepartition;
4992  int ncliques;
4993  int nbinvars;
4994  int naddconss;
4995 
4996  nbinvars = SCIPgetNBinVars(scip);
4997  SCIP_CALL( SCIPduplicateBufferArray(scip, &binvars, vars, nbinvars) );
4998  SCIP_CALL( SCIPallocBufferArray(scip, &cliquepartition, nbinvars) );
4999 
5000  /* @todo: check for better permutations/don't permutate the first round
5001  * @todo: take binary variables which are not of vartype SCIP_VARTYPE_BINARY into account
5002  */
5003  SCIPrandomPermuteArray(conshdlrdata->randnumgen, (void**)binvars, 0, nbinvars);
5004 
5005  /* try to create a clique-partition over all binary variables and create these cliques as new setppc constraints
5006  * and add them to the usefulconss array and adjust all necessary data this will hopefully lead to faster
5007  * detection of redundant constraints
5008  */
5009  SCIP_CALL( SCIPcalcCliquePartition(scip, binvars, nbinvars, cliquepartition, &ncliques) );
5010 
5011  /* resize usefulconss array if necessary */
5012  SCIP_CALL( SCIPreallocBufferArray(scip, &usefulconss, nconss + ncliques) );
5013 
5014  naddconss = 0;
5015 
5016  /* add extra clique constraints resulting from the cliquepartition calculation to SCIP and to the local data structure */
5017  SCIP_CALL( addExtraCliques(scip, binvars, nbinvars, cliquepartition, ncliques, usefulconss, &nusefulconss,
5018  nrounds, nfixedvars, &naddconss, ndelconss, nchgcoefs, cutoff) );
5019 
5020  /* bad hack, we don't want to count these artificial created constraints if they got deleted, so ndelconss
5021  * can become negative which will be change to zero at the end of this method if it's still negative
5022  */
5023  *ndelconss -= naddconss;
5024 
5025  SCIPfreeBufferArray(scip, &cliquepartition);
5026  SCIPfreeBufferArray(scip, &binvars);
5027 
5028  if( *cutoff )
5029  goto TERMINATE;
5030  }
5031 
5032  /* start to collect setpartitioning and setpacking constraints, and try to remove fixed variables and merged these
5033  * constraints
5034  */
5035  SCIP_CALL( collectCliqueConss(scip, conss, nconss, usefulconss, &nusefulconss, nfixedvars, ndelconss, nchgcoefs, cutoff) );
5036  /* @Note: Even after the call above some constraints can have fixed variables, because it might happen that caused by
5037  * mergeMultiplies some variables were fixed which occured already in previous constraints
5038  */
5039  if( *cutoff )
5040  goto TERMINATE;
5041 
5042  /* no usefulconss found */
5043  if( nusefulconss <= 1 )
5044  goto TERMINATE;
5045 
5046  /* @todo: maybe sort them after biggest indices too, or another variant would be to restore the order as they were
5047  * read in
5048  */
5049  /* sort constraints first after type (partitioning before packing) and second after number of variables such that the
5050  * partitioning constraints have increasing number of variables and the packing constraints have decreasing number of
5051  * variables, because we loop from back to front we sort them downwards, so they are the other way around
5052  */
5053  SCIPsortDownPtr((void**)usefulconss, setppcConssSort, nusefulconss);
5054 
5055  /* creating all necessary data in array structure, collect all clique constraint variables and occurances */
5056  SCIP_CALL( collectCliqueData(scip, usefulconss, nusefulconss, usefulvars, &nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs, &maxnvars) );
5057  assert(maxnvars > 0);
5058 
5059  /* allocate temporary memory for actual clique */
5060  SCIP_CALL( SCIPallocBufferArray(scip, &cliquevalues, maxnvars) );
5061  /* allocate temporary memory for counting an overlap of variables */
5062  SCIP_CALL( SCIPallocBufferArray(scip, &countofoverlapping, nusefulconss) );
5063 
5064  /* sort usefulvars after indices of variables, negated and active counterparts will stand side by side */
5065  SCIPsortDownPtr((void**)usefulvars, SCIPvarCompActiveAndNegated, nusefulvars);
5066 
5067  /* extend cliques/constraints by checking whether some variables of a second constraint are in the same clique */
5068  for( c = nusefulconss - 1; c >= 0 && !SCIPisStopped(scip); --c )
5069  {
5070  SCIP_VAR** cons0vars; /* these are the clique variables */
5071  SCIP_CONS* cons0;
5072  int ncons0vars;
5073  SCIP_VAR* var0;
5074  int v1;
5075  int nadded; /* number of possible added variables to constraint */
5076  int cons0fixedzeros;
5077  int oldnchgcoefs;
5078 #ifndef NDEBUG
5079  const int oldnaggrvars = *naggrvars;
5080 #endif
5081  cons0 = usefulconss[c];
5082 
5083  if( !SCIPconsIsActive(cons0) )
5084  continue;
5085 
5086  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
5087  * possible
5088  */
5089  SCIP_CALL( presolvePropagateCons(scip, cons0, FALSE, undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations, nfixedvars, naggrvars, ndelconss, cutoff) );
5090 
5091  if( *cutoff )
5092  break;
5093 
5094  /* we can't handle aggregated variables later on so we should have saved them for later */
5095  assert(*naggrvars == oldnaggrvars);
5096 
5097  if( !SCIPconsIsActive(cons0) )
5098  continue;
5099 
5100  /* we need to determine the cliquedata in each iteration because we eventual will change it later */
5101  consdata = SCIPconsGetData(cons0);
5102  assert(consdata != NULL);
5103 
5104  cons0vars = consdata->vars;
5105  ncons0vars = consdata->nvars;
5106 
5107  /* sorting array after indices of variables, negated and active counterparts will stand side by side */
5108  SCIPsortDownPtr((void**)cons0vars, SCIPvarCompActiveAndNegated, ncons0vars);
5109  /* standard setppc-sorting now lost */
5110  consdata->sorted = FALSE;
5111 
5112  /* clique array should be long enough */
5113  assert(maxnvars >= ncons0vars);
5114 
5115  /* clear old entries in overlapping constraint */
5116  BMSclearMemoryArray(countofoverlapping, nusefulconss);
5117 
5118  /* calculate overlapping */
5119  for( v = ncons0vars - 1; v >= 0 ; --v )
5120  {
5121  var0 = cons0vars[v];
5122 
5123  /* fixed variables later to the count */
5124  if( SCIPvarGetLbLocal(var0) > 0.5 || SCIPvarGetUbLocal(var0) < 0.5 )
5125  continue;
5126 
5127  assert(SCIPhashmapExists(vartoindex, (void*) var0));
5128 
5129  varindex = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) var0);
5130  for( v1 = varnconss[varindex] - 1; v1 >= 0 ; --v1 )
5131  ++(countofoverlapping[varconsidxs[varindex][v1]]);
5132  }
5133 
5134  oldnchgcoefs = *nchgcoefs;
5135  cons0fixedzeros = consdata->nfixedzeros;
5136 
5137  chgcons0 = FALSE;
5138 
5139  /* check for overlapping constraint before starting lifting */
5140  SCIP_CALL( checkForOverlapping(scip, cons0, c, c, usefulconss, nusefulconss, usefulvars, &nusefulvars, vartoindex,
5141  varnconss, maxnvarconsidx, varconsidxs, countofoverlapping, conshdlrdata->cliqueshrinking, &chgcons0,
5142  undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations,
5143  nfixedvars, naggrvars, nchgcoefs, ndelconss, cutoff) );
5144 
5145  if( *cutoff )
5146  break;
5147 
5148  /* we can't handle aggregated variables later on so we should have saved them for later */
5149  assert(*naggrvars == oldnaggrvars);
5150 
5151  /* if cons0 changed, we need to reorder the variables */
5152  if( chgcons0 && *nchgcoefs > oldnchgcoefs )
5153  {
5154  consdata = SCIPconsGetData(cons0);
5155  assert(consdata != NULL);
5156 
5157  cons0vars = consdata->vars;
5158  ncons0vars = consdata->nvars;
5159 
5160  /* sorting array after indices of variables, negated and active counterparts will stand side by side */
5161  SCIPsortDownPtr((void**)cons0vars, SCIPvarCompActiveAndNegated, ncons0vars);
5162  /* standard setppc-sorting now lost */
5163  consdata->sorted = FALSE;
5164  }
5165 
5166  /* check cons0 again for redundancy/fixings, because due to fixings in all other constraints it might happen that cons0 is redundant now */
5167  if( consdata->nfixedones > 0 || consdata->nfixedzeros > cons0fixedzeros )
5168  {
5169  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
5170  * possible
5171  */
5172  SCIP_CALL( presolvePropagateCons(scip, cons0, FALSE, undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations, nfixedvars, naggrvars, ndelconss, cutoff) );
5173 
5174  if( *cutoff )
5175  break;
5176 
5177  /* we can't handle aggregated variables later on so we should have saved them for later */
5178  assert(*naggrvars == oldnaggrvars);
5179 
5180  if( !SCIPconsIsActive(cons0) )
5181  continue;
5182  }
5183 
5184  nadded = 0;
5185 
5186  /* iterate over the cliques variables and all possible new clique variables at the "same" time, determine starting
5187  * index
5188  *
5189  * @note: it might be better to start the first round with our computed v1, but maybe it's better to switch to
5190  * trying to add all variables the second time for set packing constraints
5191  */
5192 
5193  /* we try to add all variables to the partitioning constraints, to try to fix as much as possible */
5194  if( consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
5195  v1 = nusefulvars - 1;
5196  else
5197  {
5198  /* if we already ran a presolving round we want to try to add new variables */
5199  if( conshdlrdata->nclqpresolve > 0 )
5200  v1 = nusefulvars - 1;
5201  else
5202  {
5203  /* find start position of variable which we will try to add to our constraint, so we will get better clique constraints */
5204  (void) SCIPsortedvecFindDownPtr((void**)usefulvars, SCIPvarCompActiveAndNegated, (void*)cons0vars[ncons0vars - 1], nusefulvars, &v1);
5205  assert(v1 >= 0 && v1 < nusefulvars);
5206  /* if constraint is not merged and we found a variable which is negated the same as it's neighbour we have to
5207  * increase v1 to make sure that we don't loose this important variable */
5208  if( v1 + 1 < nusefulvars && ((SCIPvarIsNegated(usefulvars[v1 + 1]) && SCIPvarGetNegatedVar(usefulvars[v1 + 1]) == usefulvars[v1]) || (SCIPvarIsNegated(usefulvars[v1]) && SCIPvarGetNegatedVar(usefulvars[v1]) == usefulvars[v1 + 1])) )
5209  ++v1;
5210  }
5211  }
5212 
5213  assert(maxnvars >= ncons0vars);
5214  /* initialize the cliquevalues array */
5215  for( v = ncons0vars - 1; v >= 0; --v )
5216  {
5217  if( SCIPvarGetLbLocal(cons0vars[v]) < 0.5 && SCIPvarGetUbLocal(cons0vars[v]) > 0.5 )
5218  {
5219  /* variable has to be either active or a negated variable of an active one */
5220  assert(SCIPvarIsActive(cons0vars[v]) || (SCIPvarGetStatus(cons0vars[v]) == SCIP_VARSTATUS_NEGATED &&
5221  SCIPvarIsActive(SCIPvarGetNegationVar(cons0vars[v]))));
5222  cliquevalues[v] = SCIPvarIsActive(cons0vars[v]) ? TRUE : FALSE;
5223  }
5224  }
5225 
5226  chgcons0 = FALSE;
5227 
5228  /* try to lift variables to cons0 */
5229  SCIP_CALL( liftCliqueVariables(scip, cons0, c, usefulvars, &nusefulvars, v1, &cliquevalues, vartoindex, varnconss,
5230  maxnvarconsidx, varconsidxs, &maxnvars, &nadded, &chgcons0, nfixedvars, ndelconss, cutoff) );
5231 
5232  if( *cutoff )
5233  break;
5234 
5235  if( !SCIPconsIsActive(cons0) )
5236  continue;
5237 
5238  /* check for redundant constraints due to changing cons0 */
5239  if( chgcons0 )
5240  {
5241  int i;
5242 
5243  *firstchange = MIN(*firstchange, c);
5244  *firstclique = MIN(*firstclique, c);
5245  *lastclique = MAX(*lastclique, c);
5246 
5247  /* variables array has changed due to lifting variables, so get new values */
5248  assert(consdata == SCIPconsGetData(cons0));
5249  cons0vars = consdata->vars;
5250  ncons0vars = consdata->nvars;
5251 
5252  /* resorting array, because we added new variables, in order of indices of variables, negated
5253  * and active counterparts would stand side by side
5254  */
5255  SCIPsortDownPtr((void**)cons0vars, SCIPvarCompActiveAndNegated, ncons0vars);
5256  /* standard setppc-sorting now lost */
5257  consdata->sorted = FALSE;
5258 
5259  /* clear old entries in overlapping constraint */
5260  BMSclearMemoryArray(countofoverlapping, nusefulconss);
5261 
5262  for( v = ncons0vars - 1; v >= 0 ; --v )
5263  {
5264  var0 = cons0vars[v];
5265 
5266  /* fixed variables later to the count */
5267  if( SCIPvarGetLbLocal(var0) > 0.5 || SCIPvarGetUbLocal(var0) < 0.5 )
5268  continue;
5269 
5270  assert(SCIPhashmapExists(vartoindex, (void*) var0));
5271 
5272  varindex = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) var0);
5273  for( i = varnconss[varindex] - 1; i >= 0 ; --i )
5274  ++(countofoverlapping[varconsidxs[varindex][i]]);
5275  }
5276 
5277  chgcons0 = FALSE;
5278 
5279  /* check for overlapping constraint after lifting, in the first round we will only check up front */
5280  SCIP_CALL( checkForOverlapping(scip, cons0, c, (conshdlrdata->nclqpresolve > 0) ? nusefulconss : c,
5281  usefulconss, nusefulconss, usefulvars, &nusefulvars, vartoindex, varnconss, maxnvarconsidx, varconsidxs,
5282  countofoverlapping, conshdlrdata->cliqueshrinking, &chgcons0,
5283  undoneaggrvars, undoneaggrtypes, &naggregations, &saggregations,
5284  nfixedvars, naggrvars, nchgcoefs, ndelconss, cutoff) );
5285 
5286  if( *cutoff )
5287  break;
5288 
5289  /* we can't handle aggregated variables later on so we should have saved them for later */
5290  assert(*naggrvars == oldnaggrvars);
5291  }
5292  }
5293 
5294  TERMINATE:
5295  SCIPfreeBufferArrayNull(scip, &countofoverlapping);
5296  SCIPfreeBufferArrayNull(scip, &cliquevalues);
5297 
5298  /* free temporary memory for constraints, variables and the mapping between them in reverse order as they were
5299  * allocated
5300  */
5301  for( c = nusefulvars; c > 0; --c )
5302  {
5303  if( varconsidxs[c] != NULL )
5304  {
5305  SCIPfreeBufferArrayNull(scip, &(varconsidxs[c]));
5306  }
5307  }
5308 
5309  SCIPfreeBufferArray(scip, &varconsidxs);
5310  SCIPfreeBufferArray(scip, &maxnvarconsidx);
5311  SCIPfreeBufferArray(scip, &varnconss);
5312  SCIPfreeBufferArray(scip, &usefulvars);
5313  SCIPfreeBufferArray(scip, &usefulconss);
5314 
5315  /* perform all collected aggregations */
5316  if( !*cutoff && naggregations > 0 && !SCIPdoNotAggr(scip) )
5317  {
5318  SCIP_CALL( performAggregations(scip, conshdlrdata, undoneaggrvars, undoneaggrtypes, naggregations, naggrvars, cutoff) );
5319  }
5320 
5321  /* free temporary memory for the aggregation storage */
5322  SCIPfreeBufferArray(scip, &undoneaggrtypes);
5323  SCIPfreeBufferArray(scip, &undoneaggrvars);
5324 
5325  /* free hashmap */
5326  SCIPhashmapFree(&vartoindex);
5327 
5328  if( *ndelconss < 0 )
5329  *ndelconss = 0;
5330 
5331  return SCIP_OKAY;
5332 }
5333 
5334 
5335 /** add cliques to SCIP */
5336 static
5338  SCIP* scip, /**< SCIP data structure */
5339  SCIP_CONS** conss, /**< constraint set */
5340  int nconss, /**< number of constraints in constraint set */
5341  int firstclique, /**< first constraint to start to add cliques */
5342  int lastclique, /**< last constraint to start to add cliques */
5343  int* naddconss, /**< pointer to count number of added constraints */
5344  int* ndelconss, /**< pointer to count number of deleted constraints */
5345  int* nchgbds, /**< pointer to count number of chnaged bounds */
5346  SCIP_Bool* cutoff /**< pointer to store if the problem is infeasible due to a fixing */
5347  )
5348 {
5349  SCIP_CONS* cons;
5350  SCIP_CONSDATA* consdata;
5351  SCIP_Bool infeasible;
5352  int nlocalbdchgs;
5353  int c;
5354 
5355  assert(scip != NULL);
5356  assert(firstclique >= 0);
5357  assert(lastclique <= nconss);
5358  assert(conss != NULL || ((nconss == 0) && (lastclique == 0)));
5359 
5360  /* add clique and implication information */
5361  for( c = firstclique; c < lastclique; ++c )
5362  {
5363  cons = conss[c]; /*lint !e613*/
5364  assert(cons != NULL);
5365 
5366  /* ignore deleted constraints */
5367  if( !SCIPconsIsActive(cons) )
5368  continue;
5369 
5370  nlocalbdchgs = 0;
5371  SCIP_CALL( applyFixings(scip, cons, naddconss, ndelconss, &nlocalbdchgs, cutoff) );
5372  *nchgbds += nlocalbdchgs;
5373 
5374  if( *cutoff )
5375  return SCIP_OKAY;
5376 
5377  consdata = SCIPconsGetData(cons);
5378  assert(consdata != NULL);
5379 
5380  if( SCIPconsIsDeleted(cons) )
5381  continue;
5382 
5383  if( !consdata->cliqueadded && consdata->nvars >= 2 )
5384  {
5385  /* add a set partitioning / packing constraint as clique */
5386  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING || (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
5387  {
5388  SCIP_CALL( SCIPaddClique(scip, consdata->vars, NULL, consdata->nvars,
5389  ((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING), &infeasible, &nlocalbdchgs) );
5390  *nchgbds += nlocalbdchgs;
5391 
5392  if( infeasible )
5393  {
5394  *cutoff = TRUE;
5395  return SCIP_OKAY;
5396  }
5397  }
5398  else if( consdata->nvars == 2 && !SCIPconsIsModifiable(cons) )
5399  {
5400  /* a two-variable set covering constraint x + y >= 1 yields the implication x == 0 -> y == 1 */
5401  SCIP_CALL( SCIPaddVarImplication(scip, consdata->vars[0], FALSE, consdata->vars[1],
5402  SCIP_BOUNDTYPE_LOWER, 1.0, &infeasible, &nlocalbdchgs) );
5403  *nchgbds += nlocalbdchgs;
5404 
5405  if( infeasible )
5406  {
5407  *cutoff = TRUE;
5408  return SCIP_OKAY;
5409  }
5410  }
5411  consdata->cliqueadded = TRUE;
5412  }
5413  }
5414 
5415  return SCIP_OKAY;
5416 }
5417 
5418 /** perform multi-aggregation on variables resulting from a set-partitioning/-packing constraint */
5419 static
5421  SCIP* scip, /**< SCIP data structure */
5422  SCIP_Bool linearconshdlrexist,/**< does the linear constraint handler exist, necessaray for multi-aggregations */
5423  SCIP_VAR** vars, /**< all variables including the variable to which will be multi-aggregated */
5424  int nvars, /**< number of all variables */
5425  int pos, /**< position of variable for multi-aggregation */
5426  SCIP_Bool* infeasible, /**< pointer to store infeasibility status of aggregation */
5427  SCIP_Bool* aggregated /**< pointer to store aggregation status */
5428  )
5429 {
5430  SCIP_VAR** tmpvars;
5431  SCIP_Real* scalars;
5432  int v;
5433 
5434  assert(scip != NULL);
5435  assert(vars != NULL);
5436  assert(nvars > 1);
5437  assert(0 <= pos && pos < nvars);
5438  assert(infeasible != NULL);
5439  assert(aggregated != NULL);
5440 
5441  if( nvars == 2 )
5442  {
5443  SCIP_Bool redundant;
5444 
5445  SCIPdebugMsg(scip, "aggregating %s = 1 - %s\n", SCIPvarGetName(vars[pos]), SCIPvarGetName(vars[nvars - pos - 1]));
5446 
5447  /* perform aggregation on variables resulting from a set-packing constraint */
5448  SCIP_CALL( SCIPaggregateVars(scip, vars[pos], vars[nvars - pos - 1], 1.0, 1.0, 1.0, infeasible, &redundant, aggregated) );
5449  assert(*infeasible || *aggregated);
5450 
5451  return SCIP_OKAY;
5452  }
5453 
5454  if( !linearconshdlrexist )
5455  return SCIP_OKAY;
5456 
5457  /* if the last variable will be multi-aggregated, we do not need to copy the variables */
5458  if( pos == nvars - 1 )
5459  tmpvars = vars;
5460  else
5461  {
5462  /* copy variables for aggregation */
5463  SCIP_CALL( SCIPduplicateBufferArray(scip, &tmpvars, vars, nvars) );
5464  tmpvars[pos] = tmpvars[nvars - 1];
5465  }
5466 
5467  SCIP_CALL( SCIPallocBufferArray(scip, &scalars, nvars - 1) );
5468  /* initialize scalars */
5469  for( v = nvars - 2; v >= 0; --v )
5470  scalars[v] = -1.0;
5471 
5472  SCIPdebugMsg(scip, "multi-aggregating binary variable <%s> (locks: [%d,%d]; to %d variables)\n",
5474  SCIPvarGetNLocksUpType(vars[pos], SCIP_LOCKTYPE_MODEL), nvars - 1);
5475 
5476  /* perform multi-aggregation */
5477  SCIP_CALL( SCIPmultiaggregateVar(scip, vars[pos], nvars - 1, tmpvars, scalars, 1.0, infeasible, aggregated) );
5478  assert(!(*infeasible));
5479 
5480  SCIPfreeBufferArray(scip, &scalars);
5481 
5482  if( pos < nvars - 1 )
5483  {
5484  assert(tmpvars != vars);
5485  SCIPfreeBufferArray(scip, &tmpvars);
5486  }
5487 
5488  return SCIP_OKAY;
5489 }
5490 
5491 /** determine singleton variables in set-partitioning/-packing constraints, or doubleton variables (active and negated)
5492  * in any combination of set-partitioning and set-packing constraints
5493  *
5494  * we can multi-aggregate the variable and either change the set-partitioning constraint to a set-packing constraint or
5495  * even delete it
5496  *
5497  * 1. c1: x + y + z = 1, uplocks(x) = 1, downlocks(x) = 1 => x = 1 - y - z and change c1 to y + z <= 1
5498  *
5499  * 2. c2: x + y + z <= 1, uplocks(x) = 1, downlocks(x) = 0, obj(x) < 0 => x = 1 - y - z and change c2 to y + z <= 1
5500  *
5501  * 3. d1: x + y + z <= 1 and d2: ~x + u + v <= 1, uplocks(x) = 1, downlocks(x) = 1
5502  * a) obj(x) <= 0 => x = 1 - y - z and delete d1
5503  * b) obj(x) > 0 => ~x = 1 - u - v and delete d2
5504  *
5505  * 4. e1: x + y + z == 1 and e2: ~x + u + v (<= or ==) 1, uplocks(x) = (1 or 2), downlocks(x) = 2
5506  * => x = 1 - y - z and delete e1
5507  *
5508  * we can also aggregate a variable in a set-packing constraint with only two variables when the uplocks are equal to
5509  * one and then delete this constraint
5510  *
5511  * 5. f1: x + y <= 1, uplocks(x) = 1, obj(x) <= 0 => x = 1 - y and delete f1
5512  *
5513  * @todo might want to multi-aggregate variables even with more locks, when the fill in is still smaller or equal to
5514  * the old number of non-zeros, e.g.
5515  *
5516  * x + y + z = 1
5517  * ~x + u + v <=/= 1
5518  * ~x + w <= 1
5519  */
5520 static
5522  SCIP* scip, /**< SCIP data structure */
5523  SCIP_CONS** conss, /**< constraint set */
5524  int nconss, /**< number of constraints in constraint set */
5525  SCIP_Bool dualpresolvingenabled,/**< is dual presolving enabled */
5526  SCIP_Bool linearconshdlrexist,/**< does the linear constraint handler exist, necessaray for
5527  * multi-aggregations
5528  */
5529  int* nfixedvars, /**< pointer to count number of deleted variables */
5530  int* naggrvars, /**< pointer to count number of aggregated variables */
5531  int* ndelconss, /**< pointer to count number of deleted constraints */
5532  int* nchgcoefs, /**< pointer to count number of changed coefficients */
5533  int* nchgsides, /**< pointer to count number of changed left hand sides */
5534  SCIP_Bool* cutoff /**< pointer to store if a cut off was detedcted */
5535  )
5536 {
5537  SCIP_CONS** usefulconss;
5538  SCIP_VAR** binvars;
5539  SCIP_HASHMAP* vartoindex;
5540  SCIP_Bool* chgtype;
5541  int* considxs;
5542  int* posincons;
5543  SCIP_Bool infeasible;
5544  SCIP_Bool aggregated;
5545  SCIP_Bool donotaggr;
5546  SCIP_Bool donotmultaggr;
5547  SCIP_Bool mustcheck;
5548  SCIP_Bool addcut;
5549  int nposvars;
5550  int ndecs;
5551  int nbinvars;
5552  int nposbinvars;
5553  int nuplocks;
5554  int ndownlocks;
5555  int posreplacements;
5556  int nhashmapentries;
5557  int nlocaladdconss;
5558  int v;
5559  int c;
5560 
5561  assert(scip != NULL);
5562  assert(conss != NULL);
5563  assert(nconss > 0);
5564  assert(nfixedvars != NULL);
5565  assert(naggrvars != NULL);
5566  assert(ndelconss != NULL);
5567  assert(nchgcoefs != NULL);
5568  assert(nchgsides != NULL);
5569 
5570  nbinvars = SCIPgetNBinVars(scip);
5571  nposbinvars = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
5572  assert(nbinvars + SCIPgetNIntVars(scip) + SCIPgetNImplVars(scip) == nposbinvars);
5573 
5574  binvars = SCIPgetVars(scip);
5575 
5576  /* determine number for possible multi-aggregations */
5577  nposvars = 0;
5578  for( v = nposbinvars - 1; v >= 0; --v )
5579  {
5580  assert(SCIPvarGetType(binvars[v]) != SCIP_VARTYPE_CONTINUOUS);
5581 
5582  if( v < nbinvars || SCIPvarIsBinary(binvars[v]) )
5583  {
5584  nuplocks = SCIPvarGetNLocksUpType(binvars[v], SCIP_LOCKTYPE_MODEL);
5585  ndownlocks = SCIPvarGetNLocksDownType(binvars[v], SCIP_LOCKTYPE_MODEL);
5586 
5587  if( (nuplocks == 1 && ndownlocks <= 1) || (nuplocks <= 1 && ndownlocks == 1) || (nuplocks <= 2 && ndownlocks <= 2 && SCIPvarGetNegatedVar(binvars[v]) != NULL) )
5588  ++nposvars;
5589  }
5590  }
5591 
5592  SCIPdebugMsg(scip, "found %d binary variables for possible multi-aggregation\n", nposvars);
5593 
5594  if( nposvars == 0 )
5595  return SCIP_OKAY;
5596 
5597  /* a hashmap from var to index when found in a set-partitioning constraint */
5598  SCIP_CALL( SCIPhashmapCreate(&vartoindex, SCIPblkmem(scip), nposvars) );
5599 
5600  /* get temporary memory */
5601  SCIP_CALL( SCIPallocBufferArray(scip, &chgtype, nconss) );
5602  BMSclearMemoryArray(chgtype, nconss);
5603 
5604  SCIP_CALL( SCIPallocBufferArray(scip, &considxs, nposbinvars) );
5605  SCIP_CALL( SCIPallocBufferArray(scip, &posincons, nposbinvars) );
5606 
5607  SCIP_CALL( SCIPduplicateBufferArray(scip, &usefulconss, conss, nconss) );
5608  /* sort constraints */
5609  SCIPsortPtr((void**)usefulconss, setppcConssSort2, nconss);
5610 
5611  posreplacements = 0;
5612  nhashmapentries = 0;
5613  ndecs = 0;
5614  donotaggr = SCIPdoNotAggr(scip);
5615  donotmultaggr = SCIPdoNotMultaggr(scip);
5616  assert(!donotaggr || !donotmultaggr);
5617 
5618  /* determine singleton variables in set-partitioning/-packing constraints, or doubleton variables (active and
5619  * negated) in any combination of set-partitioning and set-packing constraints
5620  *
5621  * we can multi-aggregate the variable and either change the set-partitioning constraint to a set-packing constraint
5622  * or even delete it
5623  */
5624  for( c = 0; c < nconss; ++c )
5625  {
5626  SCIP_CONS* cons;
5627  SCIP_CONSDATA* consdata;
5628  int oldnfixedvars;
5629  nlocaladdconss = 0;
5630 
5631  cons = usefulconss[c];
5632  assert(cons != NULL);
5633 
5634  if( SCIPconsIsDeleted(cons) )
5635  continue;
5636 
5637  consdata = SCIPconsGetData(cons);
5638  assert(consdata != NULL);
5639 
5640  /* if we cannot find any constraint to perform a useful multi-aggregation, stop */
5641  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING )
5642  break;
5643 
5644  if( !SCIPconsIsChecked(cons) )
5645  continue;
5646 
5647  if( SCIPconsIsModifiable(cons) )
5648  continue;
5649 
5650  /* update the variables */
5651  SCIP_CALL( applyFixings(scip, cons, &nlocaladdconss, ndelconss, nfixedvars, cutoff) );
5652 
5653  if( *cutoff )
5654  break;
5655 
5656  /* due to resolving multi-aggregations a constraint can become deleted */
5657  if( SCIPconsIsDeleted(cons) )
5658  continue;
5659 
5660  SCIP_CALL( processFixings(scip, cons, cutoff, nfixedvars, &addcut, &mustcheck) );
5661  assert(!addcut);
5662 
5663  if( *cutoff )
5664  break;
5665 
5666  if( SCIPconsIsDeleted(cons) )
5667  continue;
5668 
5669  oldnfixedvars = *nfixedvars;
5670 
5671  /* merging unmerged constraints */
5672  SCIP_CALL( mergeMultiples(scip, cons, nfixedvars, ndelconss, nchgcoefs, cutoff) );
5673 
5674  if( *cutoff )
5675  break;
5676 
5677  if( SCIPconsIsDeleted(cons) )
5678  continue;
5679 
5680  if( oldnfixedvars < *nfixedvars )
5681  {
5682  /* update the variables */
5683  SCIP_CALL( applyFixings(scip, cons, &nlocaladdconss, ndelconss, nfixedvars, cutoff) );
5684  assert(!SCIPconsIsDeleted(cons));
5685  assert(nlocaladdconss == 0);
5686  assert(!*cutoff);
5687 
5688  if( SCIPconsIsDeleted(cons) )
5689  continue;
5690  }
5691 
5692  /* if the constraint was not merged and consists of a variable with its negation, the constraint is redundant */
5693  if( consdata->nvars < 2 )
5694  {
5695  /* deleting redundant set-packing constraint */
5696  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
5697  {
5698  SCIPdebugMsg(scip, "deleting redundant set-packing constraint <%s>\n", SCIPconsGetName(cons));
5699 
5700  SCIP_CALL( SCIPdelCons(scip, cons) );
5701  ++(*ndelconss);
5702 
5703  continue;
5704  }
5705  else
5706  {
5707  SCIP_Bool fixed;
5708 
5709  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING);
5710 
5711  if( consdata->nvars == 0 )
5712  {
5713  SCIPdebugMsg(scip, "empty set partition constraint <%s> led to infeasibility\n", SCIPconsGetName(cons));
5714 
5715  *cutoff = TRUE;
5716  break;
5717  }
5718 
5719  SCIPdebugMsg(scip, "fixing <%s> to 1 because this variable is the last variable in a set partition constraint <%s>\n", SCIPvarGetName(consdata->vars[0]), SCIPconsGetName(cons));
5720 
5721  SCIP_CALL( SCIPfixVar(scip, consdata->vars[0], 1.0, &infeasible, &fixed) );
5722  assert(!infeasible);
5723 
5724  if( fixed )
5725  ++(*nfixedvars);
5726 
5727  assert(SCIPvarGetLbGlobal(consdata->vars[0]) > 0.5);
5728 
5729  SCIPdebugMsg(scip, "deleting redundant set-partition constraint <%s>\n", SCIPconsGetName(cons));
5730 
5731  SCIP_CALL( SCIPdelCons(scip, cons) );
5732  ++(*ndelconss);
5733 
5734  continue;
5735  }
5736  }
5737 
5738  /* perform dualpresolve on set-packing constraints with exactly two variables */
5739  if( !donotaggr && consdata->nvars == 2 && dualpresolvingenabled && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
5740  {
5741  SCIP_VAR* var;
5742  SCIP_Real objval;
5743  SCIP_Bool redundant;
5744 
5745  var = consdata->vars[0];
5746  assert(var != NULL);
5748 
5749  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
5750 
5752 
5753  if( nuplocks == 1 && objval <= 0 )
5754  {
5755  SCIPdebugMsg(scip, "dualpresolve, aggregating %s + %s = 1, in set-packing constraint %s\n", SCIPvarGetName(var), SCIPvarGetName(consdata->vars[1]), SCIPconsGetName(cons));
5756 
5757  /* perform aggregation on variables resulting from a set-packing constraint */
5758  SCIP_CALL( SCIPaggregateVars(scip, var, consdata->vars[1], 1.0, 1.0, 1.0, &infeasible, &redundant, &aggregated) );
5759 
5760  if( infeasible )
5761  {
5762  *cutoff = TRUE;
5763  break;
5764  }
5765 
5766  assert(aggregated);
5767  ++(*naggrvars);
5768 
5769  SCIP_CALL( SCIPdelCons(scip, cons) );
5770  ++(*ndelconss);
5771 
5772  continue;
5773  }
5774  else
5775  {
5776  var = consdata->vars[1];
5777  assert(var != NULL);
5779 
5780  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
5781 
5783 
5784  if( nuplocks == 1 && objval <= 0 )
5785  {
5786  SCIPdebugMsg(scip, "dualpresolve, aggregating %s + %s = 1, in set-packing constraint %s\n", SCIPvarGetName(var), SCIPvarGetName(consdata->vars[0]), SCIPconsGetName(cons));
5787 
5788  /* perform aggregation on variables resulting from a set-packing constraint */
5789  SCIP_CALL( SCIPaggregateVars(scip, var, consdata->vars[0], 1.0, 1.0, 1.0, &infeasible, &redundant, &aggregated) );
5790 
5791  if( infeasible )
5792  {
5793  *cutoff = TRUE;
5794  break;
5795  }
5796  assert(aggregated);
5797  ++(*naggrvars);
5798 
5799  SCIP_CALL( SCIPdelCons(scip, cons) );
5800  ++(*ndelconss);
5801 
5802  continue;
5803  }
5804  }
5805  }
5806  else if( !donotaggr && consdata->nvars == 2 && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
5807  {
5808  SCIP_Bool redundant;
5809 
5810  SCIPdebugMsg(scip, "aggregating %s + %s = 1, in set-partition constraint %s\n", SCIPvarGetName(consdata->vars[0]), SCIPvarGetName(consdata->vars[1]), SCIPconsGetName(cons));
5811 
5812  /* perform aggregation on variables resulting from a set-partitioning constraint */
5813  SCIP_CALL( SCIPaggregateVars(scip, consdata->vars[0], consdata->vars[1], 1.0, 1.0, 1.0, &infeasible, &redundant, &aggregated) );
5814 
5815  if( infeasible )
5816  {
5817  *cutoff = TRUE;
5818  break;
5819  }
5820 
5821  assert(aggregated);
5822  ++(*naggrvars);
5823 
5824  SCIP_CALL( SCIPdelCons(scip, cons) );
5825  ++(*ndelconss);
5826 
5827  continue;
5828  }
5829 
5830  /* we already found all possible variables for multi-aggregation */
5831  if( ndecs >= nposvars )
5832  continue;
5833 
5834  /* no multi aggregation is allowed, so we can continue */
5835  if( donotmultaggr )
5836  continue;
5837 
5838  /* if the following condition does not hold, we have an unmerged constraint, and we might need to merge it first */
5839  assert(nposbinvars >= consdata->nvars);
5840 
5841  /* search for possible variables for multi-aggregation */
5842  for( v = consdata->nvars - 1; v >= 0; --v )
5843  {
5844  SCIP_VAR* var;
5845  int deleteconsindex = -1;
5846 
5847  var = consdata->vars[v];
5848  assert(var != NULL);
5850 
5851  aggregated = FALSE;
5853  ndownlocks = SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL);
5854  assert(nuplocks >= 1 && ndownlocks >= 0); /* we are only treating set partitioning and set packing constraints, so every variable in there should have an uplock */
5855 
5856  if( dualpresolvingenabled && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING && nuplocks <= 1 && nuplocks + ndownlocks <= 2 )
5857  {
5858  assert(nuplocks == 1 && ndownlocks <= 1);
5859 
5860  /* we found a redundant variable in a set-partitioning constraint */
5861  if( ndownlocks == 0 )
5862  {
5863  SCIP_Real objval;
5864 
5865  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
5866 
5867  /* if the objective value is >= 0 the fixing is normally done by the dualfix presolver */
5868  if( !SCIPisNegative(scip, objval) )
5869  {
5870  SCIP_Bool fixed;
5871 
5872  SCIPdebugMsg(scip, "dual-fixing of variable <%s> to 0.0\n", SCIPvarGetName(var));
5873 
5874  SCIP_CALL( SCIPfixVar(scip, var, 0.0, &infeasible, &fixed) );
5875  assert(!infeasible);
5876  assert(fixed);
5877 
5878  ++(*nfixedvars);
5879  }
5880  else
5881  {
5882  SCIPdebugMsg(scip, "multi-aggregating in set-packing constraint\n");
5883 
5884  /* perform aggregation on variables resulting from a set-packing constraint */
5885  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, consdata->vars, consdata->nvars, v, &infeasible, &aggregated) );
5886 
5887  if( infeasible )
5888  {
5889  *cutoff = TRUE;
5890  break;
5891  }
5892  }
5893 
5894  ++ndecs;
5895  }
5896  else if( ndownlocks == 1 && SCIPvarGetNegatedVar(var) != NULL )
5897  {
5898  SCIP_CONSDATA* aggrconsdata;
5899  SCIP_VAR* negvar;
5900  SCIP_VAR* activevar;
5901  SCIP_Real objval;
5902  int multaggridx;
5903  int notmultaggridx;
5904  int image;
5905  int consindex;
5906  int varindex;
5907 
5908  assert(!SCIPhashmapExists(vartoindex, (void*) var));
5909 
5910  negvar = SCIPvarGetNegatedVar(var);
5911 
5912  /* if we found a new variable add it to the data */
5913  if( !SCIPhashmapExists(vartoindex, (void*) negvar) )
5914  {
5915  ++nhashmapentries;
5916  SCIP_CALL( SCIPhashmapInsert(vartoindex, (void*) var, (void*) (size_t) nhashmapentries) );
5917 
5918  considxs[nhashmapentries - 1] = c;
5919  posincons[nhashmapentries - 1] = v;
5920 
5921  ++posreplacements;
5922  continue;
5923  }
5924 
5925  assert(SCIPhashmapExists(vartoindex, (void*) negvar));
5926  image = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) negvar);
5927  assert(image > 0 && image <= nhashmapentries);
5928 
5929  consindex = considxs[image - 1];
5930  assert(0 <= consindex && consindex < nconss);
5931 
5932  /* if the following assert fails, the constraint was not merged, or something really strange happened */
5933  assert(consindex < c);
5934 
5935  ++ndecs;
5936  --posreplacements;
5937  assert(posreplacements >= 0);
5938 
5939  varindex = posincons[image - 1];
5940  considxs[image - 1] = -1;
5941  posincons[image - 1] = -1;
5942  SCIP_CALL( SCIPhashmapRemove(vartoindex, (void*) negvar) );
5943 
5944  /* if two variables in one constraint might be multi-aggregated, it might happen that this constraint was already removed */
5945  if( SCIPconsIsDeleted(usefulconss[consindex]) )
5946  continue;
5947 
5948  aggrconsdata = SCIPconsGetData(usefulconss[consindex]);
5949  assert(aggrconsdata != NULL);
5950  assert((SCIP_SETPPCTYPE)aggrconsdata->setppctype == SCIP_SETPPCTYPE_PACKING);
5951  assert(0 <= varindex);
5952 
5953  /* it might be that due to other multi-aggregations the constraint has fewer variables than when we
5954  * remembered the position, therefore we need to find the variable again
5955  */
5956  if( varindex >= aggrconsdata->nvars || aggrconsdata->vars[varindex] != negvar )
5957  {
5958  int v2;
5959 
5960  /* if the following assert is raised, then the constraint is redundant and we do not need to aggregate
5961  * anymore and can delete this constraint
5962  */
5963  assert(aggrconsdata->nvars >= 2);
5964 
5965  for( v2 = aggrconsdata->nvars - 1; v2 >= 0; --v2 )
5966  {
5967  if( aggrconsdata->vars[v2] == negvar )
5968  break;
5969  }
5970  assert(v2 >= 0);
5971 
5972  varindex = v2;
5973  }
5974  assert(0 <= varindex && varindex < aggrconsdata->nvars);
5975  assert(aggrconsdata->vars[varindex] == negvar);
5977 
5978  /* determine active variable and constraint that corresponds to */
5980  {
5981  activevar = negvar;
5982  multaggridx = consindex;
5983  notmultaggridx = c;
5984  }
5985  else
5986  {
5987  activevar = var;
5988  multaggridx = c;
5989  notmultaggridx = consindex;
5990  }
5991  objval = SCIPvarGetObj(activevar);
5992 
5993  SCIPdebugMsg(scip, "multi-aggregating in two set-packing constraint\n");
5994 
5995  if( objval <= 0.0 )
5996  {
5997  /* perform aggregation on variables resulting from a set-packing constraint */
5998  if( multaggridx == c )
5999  {
6000  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, consdata->vars, consdata->nvars, v, &infeasible, &aggregated) );
6001  }
6002  else
6003  {
6004  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, aggrconsdata->vars, aggrconsdata->nvars, varindex, &infeasible, &aggregated) );
6005  }
6006  deleteconsindex = multaggridx;
6007  }
6008  else
6009  {
6010  /* perform aggregation on variables resulting from a set-packing constraint */
6011  if( multaggridx == c )
6012  {
6013  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, aggrconsdata->vars, aggrconsdata->nvars, varindex, &infeasible, &aggregated) );
6014  }
6015  else
6016  {
6017  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, consdata->vars, consdata->nvars, v, &infeasible, &aggregated) );
6018  }
6019  deleteconsindex = notmultaggridx;
6020  }
6021 
6022  if( infeasible )
6023  {
6024  *cutoff = TRUE;
6025  break;
6026  }
6027 
6028  assert(deleteconsindex >= 0 && deleteconsindex <= c);
6029  }
6030  }
6031  /* we found a redundant variable in a set-partitioning constraint */
6032  else if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING && nuplocks == 1 && ndownlocks == 1 )
6033  {
6034  SCIPdebugMsg(scip, "multi-aggregating in set-partitioning constraint\n");
6035 
6036  /* perform aggregation on variables resulting from a set-partitioning constraint */
6037  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, consdata->vars, consdata->nvars, v, &infeasible, &aggregated) );
6038 
6039  if( infeasible )
6040  {
6041  *cutoff = TRUE;
6042  break;
6043  }
6044 
6045  ++ndecs;
6046  }
6047  /* we might have found a redundant variable */
6048  else if( ndownlocks <= 2 && nuplocks <= 2 && SCIPvarGetNegatedVar(var) != NULL )
6049  {
6050  SCIP_CONSDATA* aggrconsdata;
6051  int image;
6052  int consindex;
6053  int varindex;
6054 
6055  /* if we have two times the same variable in a set-partitioning constraint, we cannot aggregate this */
6056  if( SCIPhashmapExists(vartoindex, (void*) var) )
6057  {
6058  image = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) var);
6059  assert(image > 0 && image <= nhashmapentries);
6060 
6061  assert(0 <= considxs[image - 1] && considxs[image - 1] < nconss);
6062  assert(SCIPconsIsDeleted(usefulconss[considxs[image - 1]]) || chgtype[considxs[image - 1]] || (0 <= posincons[image - 1] && posincons[image - 1] < SCIPconsGetData(usefulconss[considxs[image - 1]])->nvars));
6063 
6064  considxs[image - 1] = -1;
6065  posincons[image - 1] = -1;
6066 
6067  SCIP_CALL( SCIPhashmapRemove(vartoindex, (void*) var) );
6068 
6069  --posreplacements;
6070  assert(posreplacements >= 0);
6071 
6072  continue;
6073  }
6074  else if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
6075  {
6076  /* if we found a new variable add it to the data */
6077  if( !SCIPhashmapExists(vartoindex, (void*) SCIPvarGetNegatedVar(var)) )
6078  {
6079  assert(!SCIPhashmapExists(vartoindex, (void*) var));
6080 
6081  ++nhashmapentries;
6082  SCIP_CALL( SCIPhashmapInsert(vartoindex, (void*) var, (void*) (size_t) nhashmapentries) );
6083 
6084  considxs[nhashmapentries - 1] = c;
6085  posincons[nhashmapentries - 1] = v;
6086 
6087  ++posreplacements;
6088  continue;
6089  }
6090  }
6091  else
6092  {
6093  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING);
6094 
6095  /* the negated variable did not occur in a set partitioning constraint (those will be iterated over
6096  * first), so we cannot aggregate this variable
6097  */
6098  if( !SCIPhashmapExists(vartoindex, (void*) SCIPvarGetNegatedVar(var)) )
6099  continue;
6100  }
6101 
6102  assert(!chgtype[c]);
6103  assert(SCIPhashmapExists(vartoindex, (void*) SCIPvarGetNegatedVar(var)));
6104  image = (int) (size_t) SCIPhashmapGetImage(vartoindex, (void*) SCIPvarGetNegatedVar(var));
6105  assert(image > 0 && image <= nhashmapentries);
6106 
6107  consindex = considxs[image - 1];
6108  assert(0 <= consindex && consindex < nconss);
6109 
6110  /* if the following assert fails, the constraint was not merged, or something really strange happened */
6111  assert(consindex < c);
6112 
6113  ++ndecs;
6114  --posreplacements;
6115  assert(posreplacements >= 0);
6116 
6117  varindex = posincons[image - 1];
6118  considxs[image - 1] = -1;
6119  posincons[image - 1] = -1;
6120  SCIP_CALL( SCIPhashmapRemove(vartoindex, (void*) SCIPvarGetNegatedVar(var)) );
6121 
6122  /* if two variables in one constraint might be multi-aggregated, it might happen that this constraint was
6123  * already removed
6124  */
6125  if( SCIPconsIsDeleted(usefulconss[consindex]) )
6126  continue;
6127 
6128  aggrconsdata = SCIPconsGetData(usefulconss[consindex]);
6129  assert(aggrconsdata != NULL);
6130 
6131  /* must not multi-aggregate variables that are locked more then twice by all setppc constraints */
6132  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING &&
6133  (SCIP_SETPPCTYPE)aggrconsdata->setppctype == SCIP_SETPPCTYPE_PACKING )
6134  {
6135  assert(!dualpresolvingenabled || nuplocks + ndownlocks > 2);
6136  continue;
6137  }
6138 
6139  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING ||
6140  (SCIP_SETPPCTYPE)aggrconsdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING);
6141 
6142  /* we already removed a variable before, so our positioning information might be wrong, so we need to walk
6143  * over all variables again
6144  */
6145  if( chgtype[consindex] )
6146  {
6147 #ifndef NDEBUG
6148  int v2;
6149 
6150  assert((SCIP_SETPPCTYPE)aggrconsdata->setppctype == SCIP_SETPPCTYPE_PACKING);
6151 
6152  /* negated variables needs to be still in the upgraded set-packing constraint */
6153  for( v2 = aggrconsdata->nvars - 1; v2 >= 0; --v2 )
6154  {
6155  if( aggrconsdata->vars[v2] == SCIPvarGetNegatedVar(var) )
6156  break;
6157  }
6158  assert(v2 >= 0);
6159 #endif
6160  assert((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING);
6161 
6162  SCIPdebugMsg(scip, "multi-aggregating in one set-partitioning or one set-packing constraint\n");
6163 
6164  /* perform aggregation on variables resulting from a set-partitioning constraint */
6165  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, consdata->vars, consdata->nvars, v, &infeasible, &aggregated) );
6166 
6167  if( infeasible )
6168  {
6169  *cutoff = TRUE;
6170  break;
6171  }
6172  assert(deleteconsindex == -1);
6173  }
6174  else
6175  {
6176  /* @note it might have happened that we have a variable at hand which exists actually in a set-packing
6177  * constraint and due to some other aggregation we increased the number of locks and reached this
6178  * part of the code, where we would expect only set-partitioning constraints in general, so in
6179  * such a strange case we cannot aggregate anything
6180  */
6181  if( (SCIP_SETPPCTYPE)aggrconsdata->setppctype != SCIP_SETPPCTYPE_PARTITIONING )
6182  continue;
6183 
6184  assert(0 <= varindex && varindex < aggrconsdata->nvars);
6185  assert(aggrconsdata->vars[varindex] == SCIPvarGetNegatedVar(var));
6186  assert((SCIP_SETPPCTYPE)aggrconsdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING);
6187 
6188  SCIPdebugMsg(scip, "multi-aggregating in two set-partitioning or one set-partitioning and -packing constraint\n");
6189 
6190  /* perform aggregation on variables resulting from a set-partitioning constraint */
6191  SCIP_CALL( multiAggregateBinvar(scip, linearconshdlrexist, aggrconsdata->vars, aggrconsdata->nvars, varindex, &infeasible, &aggregated) );
6192 
6193  if( infeasible )
6194  {
6195  *cutoff = TRUE;
6196  break;
6197  }
6198 
6199  /* change pointer for deletion */
6200  cons = usefulconss[consindex];
6201  assert(deleteconsindex == -1);
6202  }
6203  }
6204 
6205  if( aggregated )
6206  {
6207  assert(nuplocks >= 1 && ndownlocks >= 0); /* repeated from above */
6208  ++(*naggrvars);
6209 
6210  if( nuplocks == 1 && ndownlocks == 0 && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PACKING )
6211  {
6212  assert(deleteconsindex < 0);
6213 
6214  SCIP_CALL( delCoefPos(scip, cons, v) );
6215  ++(*nchgcoefs);
6216  }
6217  else if( nuplocks == 1 && ndownlocks == 1 && (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
6218  {
6219  assert(deleteconsindex < 0);
6220 
6221  SCIP_CALL( delCoefPos(scip, cons, v) );
6222  ++(*nchgcoefs);
6223 
6224  SCIPdebugMsg(scip, "changing constraint <%s> from set-partitioning to set-packing, due to multi-aggregation\n", SCIPconsGetName(cons));
6225 
6226  chgtype[c] = TRUE;
6227 
6229  ++(*nchgsides);
6230  }
6231  else
6232  {
6233  if( deleteconsindex >= 0 )
6234  {
6235  SCIPdebugMsg(scip, "1: deleting redundant constraint <%s>, due to multi-aggregation\n", SCIPconsGetName(usefulconss[deleteconsindex]));
6236  SCIPdebugPrintCons(scip, usefulconss[deleteconsindex], NULL);
6237 
6238  assert(!SCIPconsIsDeleted(usefulconss[deleteconsindex]));
6239  SCIP_CALL( SCIPdelCons(scip, usefulconss[deleteconsindex]) );
6240  }
6241  else
6242  {
6243  SCIPdebugMsg(scip, "2: deleting redundant constraint <%s>, due to multi-aggregation\n", SCIPconsGetName(cons));
6244  SCIPdebugPrintCons(scip, cons, NULL);
6245 
6246  assert(!SCIPconsIsDeleted(cons));
6247  SCIP_CALL( SCIPdelCons(scip, cons) );
6248  }
6249  ++(*ndelconss);
6250  }
6251 
6252  break;
6253  }
6254  }
6255  }
6256 
6257  /* free temporary memory */
6258  SCIPfreeBufferArray(scip, &usefulconss);
6259  SCIPfreeBufferArray(scip, &posincons);
6260  SCIPfreeBufferArray(scip, &considxs);
6261  SCIPfreeBufferArray(scip, &chgtype);
6262 
6263  /* free hashmap */
6264  SCIPhashmapFree(&vartoindex);
6265 
6266  return SCIP_OKAY;
6267 }
6268 
6269 
6270 /** compares each constraint with all other constraints for possible redundancy and removes or changes constraint
6271  * accordingly; in contrast to removeRedundantConstraints(), it uses a hash table
6272  */
6273 static
6275  SCIP* scip, /**< SCIP data structure */
6276  BMS_BLKMEM* blkmem, /**< block memory */
6277  SCIP_CONS** conss, /**< constraint set */
6278  int nconss, /**< number of constraints in constraint set */
6279  int* firstchange, /**< pointer to store first changed constraint */
6280  int* ndelconss, /**< pointer to count number of deleted constraints */
6281  int* nchgsides /**< pointer to count number of changed left/right hand sides */
6282  )
6283 {
6284  SCIP_HASHTABLE* hashtable;
6285  int hashtablesize;
6286  int c;
6287 
6288  assert(scip != NULL);
6289  assert(blkmem != NULL);
6290  assert(conss != NULL || nconss == 0);
6291  assert(firstchange != NULL);
6292  assert(ndelconss != NULL);
6293  assert(nchgsides != NULL);
6294 
6295  if( nconss == 0 )
6296  return SCIP_OKAY;
6297 
6298  assert(conss != NULL);
6299 
6300  /* create a hash table for the constraint set */
6301  hashtablesize = nconss;
6302  hashtablesize = MAX(hashtablesize, HASHSIZE_SETPPCCONS);
6303  SCIP_CALL( SCIPhashtableCreate(&hashtable, blkmem, hashtablesize,
6304  hashGetKeySetppccons, hashKeyEqSetppccons, hashKeyValSetppccons, (void*) scip) );
6305 
6306  /* check all constraints in the given set for redundancy */
6307  for( c = 0; c < nconss; ++c )
6308  {
6309  SCIP_CONS* cons0;
6310  SCIP_CONS* cons1;
6311 
6312  cons0 = conss[c];
6313 
6314  if( !SCIPconsIsActive(cons0) || SCIPconsIsModifiable(cons0) )
6315  continue;
6316 
6317  /* get constraint from current hash table with same variables as cons0 and with coefficients either equal or negated
6318  * to the ones of cons0 */
6319  cons1 = (SCIP_CONS*)(SCIPhashtableRetrieve(hashtable, (void*)cons0));
6320 
6321  if( cons1 != NULL )
6322  {
6323  SCIP_CONSDATA* consdata0;
6324  SCIP_CONSDATA* consdata1;
6325 
6326  assert(SCIPconsIsActive(cons1));
6327  assert(!SCIPconsIsModifiable(cons1));
6328 
6329  /* constraint found: create a new constraint with same coefficients and best left and right hand side;
6330  * delete old constraints afterwards
6331  */
6332  consdata0 = SCIPconsGetData(cons0);
6333  consdata1 = SCIPconsGetData(cons1);
6334 
6335  assert(consdata0 != NULL && consdata1 != NULL);
6336  assert(consdata0->nvars >= 1 && consdata0->nvars == consdata1->nvars);
6337 
6338  assert(consdata0->sorted && consdata1->sorted);
6339  assert(consdata0->vars[0] == consdata1->vars[0]);
6340 
6341  SCIPdebugMsg(scip, "setppc constraints <%s> and <%s> have identical variable sets\n",
6342  SCIPconsGetName(cons0), SCIPconsGetName(cons1));
6343  SCIPdebugPrintCons(scip, cons0, NULL);
6344  SCIPdebugPrintCons(scip, cons1, NULL);
6345 
6346  /* if necessary change type of setppc constraint */
6347  if( consdata1->setppctype != SCIP_SETPPCTYPE_PARTITIONING && consdata0->setppctype != consdata1->setppctype ) /*lint !e641*/
6348  {
6349  /* change the type of cons0 */
6351  (*nchgsides)++;
6352  }
6353 
6354  /* update flags of constraint which caused the redundancy s.t. nonredundant information doesn't get lost */
6355  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons0) );
6356 
6357  /* delete cons0 */
6358  SCIP_CALL( SCIPdelCons(scip, cons0) );
6359  (*ndelconss)++;
6360 
6361  /* update the first changed constraint to begin the next aggregation round with */
6362  if( consdata0->changed && SCIPconsGetPos(cons1) < *firstchange )
6363  *firstchange = SCIPconsGetPos(cons1);
6364 
6365  assert(SCIPconsIsActive(cons1));
6366  }
6367  else
6368  {
6369  /* no such constraint in current hash table: insert cons0 into hash table */
6370  SCIP_CALL( SCIPhashtableInsert(hashtable, (void*) cons0) );
6371  }
6372  }
6373 
6374  /* free hash table */
6375  SCIPhashtableFree(&hashtable);
6376 
6377  return SCIP_OKAY;
6378 }
6379 
6380 /** removes the redundant second constraint and updates the flags of the first one */
6381 static
6383  SCIP* scip, /**< SCIP data structure */
6384  SCIP_CONS* cons0, /**< constraint that should stay */
6385  SCIP_CONS* cons1, /**< constraint that should be deleted */
6386  int* ndelconss /**< pointer to count number of deleted constraints */
6387  )
6388 {
6389  assert(ndelconss != NULL);
6391  SCIPdebugMsg(scip, " -> removing setppc constraint <%s> which is redundant to <%s>\n",
6392  SCIPconsGetName(cons1), SCIPconsGetName(cons0));
6393  SCIPdebugPrintCons(scip, cons0, NULL);
6394  SCIPdebugPrintCons(scip, cons1, NULL);
6395 
6396  /* update flags of cons0 */
6397  SCIP_CALL( SCIPupdateConsFlags(scip, cons0, cons1) );
6398 
6399  /* delete cons1 */
6400  SCIP_CALL( SCIPdelCons(scip, cons1) );
6401  (*ndelconss)++;
6402 
6403  return SCIP_OKAY;
6404 }
6405 
6406 /** for cons0 contained in cons1, fixes variables of cons1 that are not in cons0 to zero */
6407 static
6409  SCIP* scip, /**< SCIP data structure */
6410  SCIP_CONS* cons0, /**< constraint that is contained in the other */
6411  SCIP_CONS* cons1, /**< constraint that is a superset of the other */
6412  SCIP_Bool* cutoff, /**< pointer to store whether a cutoff was found */
6413  int* nfixedvars /**< pointer to count number of fixed variables */
6414  )
6415 {
6416  SCIP_CONSDATA* consdata0;
6417  SCIP_CONSDATA* consdata1;
6418  int v0;
6419  int v1;
6420 
6421  assert(cutoff != NULL);
6422  assert(nfixedvars != NULL);
6423 
6424  *cutoff = FALSE;
6425 
6426  /* get constraint data */
6427  consdata0 = SCIPconsGetData(cons0);
6428  consdata1 = SCIPconsGetData(cons1);
6429  assert(consdata0 != NULL);
6430  assert(consdata1 != NULL);
6431  assert(consdata0->nvars < consdata1->nvars);
6432  assert(consdata0->sorted);
6433  assert(consdata1->sorted);
6434 
6435  /* fix variables in the range of cons0 */
6436  for( v0 = 0, v1 = 0; v0 < consdata0->nvars && !(*cutoff); ++v0, ++v1 )
6437  {
6438  int index0;
6439 
6440  assert(v1 < consdata1->nvars);
6441  index0 = SCIPvarGetIndex(consdata0->vars[v0]);
6442  for( ; SCIPvarGetIndex(consdata1->vars[v1]) < index0 && !(*cutoff); ++v1 )
6443  {
6444  SCIP_Bool fixed;
6445 
6446  /* fix variable to zero */
6447  SCIP_CALL( SCIPfixVar(scip, consdata1->vars[v1], 0.0, cutoff, &fixed) );
6448  if( fixed )
6449  {
6450  SCIPdebugMsg(scip, " -> fixed <%s> == 0\n", SCIPvarGetName(consdata1->vars[v1]));
6451  (*nfixedvars)++;
6452  }
6453  assert(v1 < consdata1->nvars-1);
6454  }
6455  assert(SCIPvarGetIndex(consdata1->vars[v1]) == index0 || *cutoff);
6456  }
6457 
6458  /* fix remaining variables of cons1 */
6459  for( ; v1 < consdata1->nvars && !(*cutoff); ++v1 )
6460  {
6461  SCIP_Bool fixed;
6462 
6463  assert(consdata0->nvars == 0
6464  || SCIPvarGetIndex(consdata1->vars[v1]) > SCIPvarGetIndex(consdata0->vars[consdata0->nvars-1]));
6465 
6466  /* fix variable to zero */
6467  SCIP_CALL( SCIPfixVar(scip, consdata1->vars[v1], 0.0, cutoff, &fixed) );
6468  if( fixed )
6469  {
6470  SCIPdebugMsg(scip, " -> fixed <%s> == 0\n", SCIPvarGetName(consdata1->vars[v1]));
6471  (*nfixedvars)++;
6472  }
6473  }
6474 
6475  return SCIP_OKAY;
6476 }
6477 
6478 /** applies reductions for cons0 being contained in cons1 */
6479 static
6481  SCIP* scip, /**< SCIP data structure */
6482  SCIP_CONS* cons0, /**< constraint that is contained in the other */
6483  SCIP_CONS* cons1, /**< constraint that is a superset of the other */
6484  SCIP_Bool* cutoff, /**< pointer to store whether a cutoff was found */
6485  int* nfixedvars, /**< pointer to count number of fixed variables */
6486  int* ndelconss, /**< pointer to count number of deleted constraints */
6487  int* nchgsides /**< pointer to count number of changed left/right hand sides */
6488  )
6489 {
6490  SCIP_CONSDATA* consdata0;
6491  SCIP_CONSDATA* consdata1;
6492 
6493  assert(cutoff != NULL);
6494  assert(nfixedvars != NULL);
6495  assert(ndelconss != NULL);
6496  assert(nchgsides != NULL);
6497 
6498  *cutoff = FALSE;
6499 
6500  /* get constraint data */
6501  consdata0 = SCIPconsGetData(cons0);
6502  consdata1 = SCIPconsGetData(cons1);
6503  assert(consdata0 != NULL);
6504  assert(consdata1 != NULL);
6505  assert(consdata0->nvars < consdata1->nvars);
6506  assert(consdata0->sorted);
6507  assert(consdata1->sorted);
6508 
6509  switch( consdata0->setppctype )
6510  {
6512  switch( consdata1->setppctype )
6513  {
6516  /* cons0: partitioning, cons1: partitioning or packing
6517  * -> fix additional variables in cons1 to zero, remove cons1
6518  */
6519  SCIP_CALL( fixAdditionalVars(scip, cons0, cons1, cutoff, nfixedvars) );
6520  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6521  break;
6522 
6524  /* cons0: partitioning, cons1: covering
6525  * -> remove cons1
6526  */
6527  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6528  break;
6529 
6530  default:
6531  SCIPerrorMessage("invalid setppc type <%d> of constraint <%s>\n", consdata1->setppctype, SCIPconsGetName(cons1));
6532  return SCIP_INVALIDDATA;
6533  }
6534  break;
6535 
6537  switch( consdata1->setppctype )
6538  {
6541  /* cons0: packing, cons1: partitioning or packing
6542  * -> remove cons0
6543  */
6544  SCIP_CALL( removeRedundantCons(scip, cons1, cons0, ndelconss) );
6545  break;
6546 
6548  /* cons0: packing, cons1: covering
6549  * -> nothing can be deduced
6550  */
6551  break;
6552 
6553  default:
6554  SCIPerrorMessage("invalid setppc type <%d> of constraint <%s>\n", consdata1->setppctype, SCIPconsGetName(cons1));
6555  return SCIP_INVALIDDATA;
6556  }
6557  break;
6558 
6560  switch( consdata1->setppctype )
6561  {
6564  /* cons0: covering, cons1: partitioning or packing
6565  * -> fix additional variables in cons1 to zero, remove cons1, convert cons0 into partitioning
6566  */
6567  SCIP_CALL( fixAdditionalVars(scip, cons0, cons1, cutoff, nfixedvars) );
6569  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6570  (*nchgsides)++;
6571  break;
6572 
6574  /* cons0: covering, cons1: covering
6575  * -> remove cons1
6576  */
6577  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6578  break;
6579 
6580  default:
6581  SCIPerrorMessage("invalid setppc type <%d> of constraint <%s>\n", consdata1->setppctype, SCIPconsGetName(cons1));
6582  return SCIP_INVALIDDATA;
6583  }
6584  break;
6585 
6586  default:
6587  SCIPerrorMessage("invalid setppc type <%d> of constraint <%s>\n", consdata0->setppctype, SCIPconsGetName(cons0));
6588  return SCIP_INVALIDDATA;
6589  }
6590 
6591  return SCIP_OKAY;
6592 }
6593 
6594 /** deletes redundant constraints */
6595 static
6597  SCIP* scip, /**< SCIP data structure */
6598  SCIP_CONS** conss, /**< constraint set */
6599  int firstchange, /**< first constraint that changed since last pair preprocessing round */
6600  int chkind, /**< index of constraint to check against all prior indices upto startind */
6601  SCIP_Bool* cutoff, /**< pointer to store whether a cutoff was found */
6602  int* nfixedvars, /**< pointer to count number of fixed variables */
6603  int* ndelconss, /**< pointer to count number of deleted constraints */
6604  int* nchgsides /**< pointer to count number of changed left/right hand sides */
6605  )
6606 {
6607  SCIP_CONS* cons0;
6608  SCIP_CONSDATA* consdata0;
6609  uint64_t signature0;
6610  SCIP_Bool cons0changed;
6611  int c;
6612 
6613  assert(scip != NULL);
6614  assert(conss != NULL);
6615  assert(cutoff != NULL);
6616  assert(nfixedvars != NULL);
6617  assert(ndelconss != NULL);
6618  assert(nchgsides != NULL);
6619 
6620  *cutoff = FALSE;
6621 
6622  /* get the constraint to be checked against all prior constraints */
6623  cons0 = conss[chkind];
6624  assert(SCIPconsIsActive(cons0));
6625  assert(!SCIPconsIsModifiable(cons0));
6626 
6627  consdata0 = SCIPconsGetData(cons0);
6628  assert(consdata0 != NULL);
6629  assert(consdata0->nvars >= 1);
6630 
6631  /* sort the constraint cons0 */
6632  consdataSort(consdata0);
6633 
6634  /* get the bit signature of the constraint */
6635  signature0 = consdataGetSignature(consdata0);
6636 
6637  /* check constraint against all prior constraints */
6638  cons0changed = consdata0->changed;
6639  consdata0->changed = FALSE;
6640  for( c = (cons0changed ? 0 : firstchange); c < chkind && !(*cutoff) && SCIPconsIsActive(cons0); ++c )
6641  {
6642  SCIP_CONS* cons1;
6643  SCIP_CONSDATA* consdata1;
6644  uint64_t signature1;
6645  uint64_t jointsignature;
6646  SCIP_Bool cons0iscontained;
6647  SCIP_Bool cons1iscontained;
6648  int v0;
6649  int v1;
6650 
6651  cons1 = conss[c];
6652 
6653  /* ignore inactive and modifiable constraints */
6654  if( !SCIPconsIsActive(cons1) || SCIPconsIsModifiable(cons1) )
6655  continue;
6656 
6657  consdata1 = SCIPconsGetData(cons1);
6658  assert(consdata1 != NULL);
6659 
6660  /* sort the constraint cons1 */
6661  consdataSort(consdata1);
6662 
6663  /* get the bit signature of cons1 */
6664  signature1 = consdataGetSignature(consdata1);
6665 
6666  /* check (based on signature) if the two constraints are not included in each other */
6667  jointsignature = (signature0 | signature1);
6668  if( jointsignature != signature0 && jointsignature != signature1 )
6669  continue;
6670 
6671  /* check whether one constraint is really a subset of the other */
6672  cons0iscontained = (consdata0->nvars <= consdata1->nvars);
6673  cons1iscontained = (consdata1->nvars <= consdata0->nvars);
6674  v0 = 0;
6675  v1 = 0;
6676  while( v0 < consdata0->nvars && v1 < consdata1->nvars )
6677  {
6678  int index0;
6679  int index1;
6680 
6681  index0 = SCIPvarGetIndex(consdata0->vars[v0]);
6682  index1 = SCIPvarGetIndex(consdata1->vars[v1]);
6683  if( index0 < index1 )
6684  {
6685  cons0iscontained = FALSE;
6686  if( !cons1iscontained )
6687  break;
6688  for( v0++; v0 < consdata0->nvars && SCIPvarGetIndex(consdata0->vars[v0]) < index1; v0++ )
6689  {}
6690  }
6691  else if( index1 < index0 )
6692  {
6693  cons1iscontained = FALSE;
6694  if( !cons0iscontained )
6695  break;
6696  for( v1++; v1 < consdata1->nvars && SCIPvarGetIndex(consdata1->vars[v1]) < index0; v1++ )
6697  {}
6698  }
6699  else
6700  {
6701  v0++;
6702  v1++;
6703  }
6704  }
6705  cons0iscontained = cons0iscontained && (v0 == consdata0->nvars);
6706  cons1iscontained = cons1iscontained && (v1 == consdata1->nvars);
6707 
6708  if( cons0iscontained && cons1iscontained )
6709  {
6710  SCIPdebugMsg(scip, "setppc constraints <%s> and <%s> have identical variable sets\n",
6711  SCIPconsGetName(cons0), SCIPconsGetName(cons1));
6712  SCIPdebugPrintCons(scip, cons0, NULL);
6713  SCIPdebugPrintCons(scip, cons1, NULL);
6714 
6715  /* both constraints consists of the same variables */
6716  if( consdata0->setppctype == consdata1->setppctype )
6717  {
6718  /* both constraints are equal: update flags in cons0 and delete cons1 */
6719  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6720  }
6721  else if( consdata0->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
6722  {
6723  /* the set partitioning constraint is stronger: remove the other one */
6724  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6725  }
6726  else if( consdata1->setppctype == SCIP_SETPPCTYPE_PARTITIONING ) /*lint !e641*/
6727  {
6728  /* the set partitioning constraint is stronger: remove the other one */
6729  SCIP_CALL( removeRedundantCons(scip, cons1, cons0, ndelconss) );
6730  }
6731  else
6732  {
6733  /* one is a covering, the other one a packing constraint: replace them by a single partitioning constraint */
6734  assert((consdata0->setppctype == SCIP_SETPPCTYPE_COVERING && consdata1->setppctype == SCIP_SETPPCTYPE_PACKING)
6735  || (consdata1->setppctype == SCIP_SETPPCTYPE_COVERING && consdata0->setppctype == SCIP_SETPPCTYPE_PACKING)); /*lint !e641*/
6736 
6737  /* change the type of cons0 */
6739  (*nchgsides)++;
6740 
6741  /* delete cons1 */
6742  SCIP_CALL( removeRedundantCons(scip, cons0, cons1, ndelconss) );
6743  }
6744  }
6745  else if( cons0iscontained )
6746  {
6747  /* cons0 is contained in cons1 */
6748  SCIPdebugMsg(scip, "setppc constraint <%s> is contained in <%s>\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
6749  SCIPdebugPrintCons(scip, cons0, NULL);
6750  SCIPdebugPrintCons(scip, cons1, NULL);
6751  SCIP_CALL( processContainedCons(scip, cons0, cons1, cutoff, nfixedvars, ndelconss, nchgsides) );
6752  }
6753  else if( cons1iscontained )
6754  {
6755  /* cons1 is contained in cons1 */
6756  SCIPdebugMsg(scip, "setppc constraint <%s> is contained in <%s>\n", SCIPconsGetName(cons1), SCIPconsGetName(cons0));
6757  SCIPdebugPrintCons(scip, cons0, NULL);
6758  SCIPdebugPrintCons(scip, cons1, NULL);
6759  SCIP_CALL( processContainedCons(scip, cons1, cons0, cutoff, nfixedvars, ndelconss, nchgsides) );
6760  }
6761  }
6762 
6763  return SCIP_OKAY;
6764 }
6765 
6766 /* perform deletion of variables in all constraints of the constraint handler */
6767 static
6769  SCIP* scip, /**< SCIP data structure */
6770  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6771  SCIP_CONS** conss, /**< array of constraints */
6772  int nconss /**< number of constraints */
6773  )
6774 {
6775  SCIP_CONSDATA* consdata;
6776  int i;
6777  int v;
6778 
6779  assert(scip != NULL);
6780  assert(conshdlr != NULL);
6781  assert(conss != NULL);
6782  assert(nconss >= 0);
6783  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
6784 
6785  /* iterate over all constraints */
6786  for( i = 0; i < nconss; i++ )
6787  {
6788  consdata = SCIPconsGetData(conss[i]);
6789 
6790  /* constraint is marked, that some of its variables were deleted */
6791  if( consdata->varsdeleted )
6792  {
6793  /* iterate over all variables of the constraint and delete marked variables */
6794  for( v = consdata->nvars - 1; v >= 0; v-- )
6795  {
6796  if( SCIPvarIsDeleted(consdata->vars[v]) )
6797  {
6798  SCIP_CALL( delCoefPos(scip, conss[i], v) );
6799  }
6800  }
6801  consdata->varsdeleted = FALSE;
6802  }
6803  }
6804 
6805  return SCIP_OKAY;
6806 }
6807 
6808 /** helper function to enforce constraints */
6809 static
6811  SCIP* scip, /**< SCIP data structure */
6812  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6813  SCIP_CONS** conss, /**< constraints to process */
6814  int nconss, /**< number of constraints */
6815  int nusefulconss, /**< number of useful (non-obsolete) constraints to process */
6816  SCIP_SOL* sol, /**< solution to enforce (NULL for the LP solution) */
6817  SCIP_RESULT* result /**< pointer to store the result of the enforcing call */
6818  )
6819 {
6820  SCIP_Bool cutoff;
6821  SCIP_Bool separated;
6822  SCIP_Bool reduceddom;
6823  int c;
6824 
6825  assert(conshdlr != NULL);
6826  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
6827  assert(nconss == 0 || conss != NULL);
6828  assert(result != NULL);
6829 
6830  SCIPdebugMsg(scip, "Enforcing %d set partitioning / packing / covering constraints for %s solution\n", nconss,
6831  sol == NULL ? "LP" : "relaxation");
6832 
6833  *result = SCIP_FEASIBLE;
6834 
6835  cutoff = FALSE;
6836  separated = FALSE;
6837  reduceddom = FALSE;
6838 
6839  /* check all useful set partitioning / packing / covering constraints for feasibility */
6840  for( c = 0; c < nusefulconss && !cutoff && !reduceddom; ++c )
6841  {
6842  SCIP_CALL( separateCons(scip, conss[c], sol, TRUE, &cutoff, &separated, &reduceddom) );
6843  }
6844 
6845  /* check all obsolete set partitioning / packing / covering constraints for feasibility */
6846  for( c = nusefulconss; c < nconss && !cutoff && !separated && !reduceddom; ++c )
6847  {
6848  SCIP_CALL( separateCons(scip, conss[c], sol, TRUE, &cutoff, &separated, &reduceddom) );
6849  }
6850 
6851 #ifdef VARUSES
6852 #ifdef BRANCHLP
6853  /* @todo also branch on relaxation solution */
6854  if( (sol == NULL) && !cutoff && !separated && !reduceddom )
6855  {
6856  /* if solution is not integral, choose a variable set to branch on */
6857  SCIP_CALL( branchLP(scip, conshdlr, result) );
6858  if( *result != SCIP_FEASIBLE )
6859  return SCIP_OKAY;
6860  }
6861 #endif
6862 #endif
6863 
6864  /* return the correct result */
6865  if( cutoff )
6866  *result = SCIP_CUTOFF;
6867  else if( separated )
6868  *result = SCIP_SEPARATED;
6869  else if( reduceddom )
6870  *result = SCIP_REDUCEDDOM;
6871 
6872  return SCIP_OKAY;
6873 }
6874 
6875 /*
6876  * upgrading of linear constraints
6877  */
6878 
6879 
6880 /** creates and captures a set partitioning / packing / covering constraint */
6881 static
6883  SCIP* scip, /**< SCIP data structure */
6884  SCIP_CONS** cons, /**< pointer to hold the created constraint */
6885  const char* name, /**< name of constraint */
6886  int nvars, /**< number of variables in the constraint */
6887  SCIP_VAR** vars, /**< array with variables of constraint entries */
6888  SCIP_SETPPCTYPE setppctype, /**< type of constraint: set partitioning, packing, or covering constraint */
6889  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
6890  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
6891  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
6892  * Usually set to TRUE. */
6893  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
6894  * TRUE for model constraints, FALSE for additional, redundant constraints. */
6895  SCIP_Bool check, /**< should the constraint be checked for feasibility?
6896  * TRUE for model constraints, FALSE for additional, redundant constraints. */
6897  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
6898  * Usually set to TRUE. */
6899  SCIP_Bool local, /**< is constraint only valid locally?
6900  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
6901  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
6902  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
6903  * adds coefficients to this constraint. */
6904  SCIP_Bool dynamic, /**< is constraint subject to aging?
6905  * Usually set to FALSE. Set to TRUE for own cuts which
6906  * are separated as constraints. */
6907  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
6908  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
6909  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
6910  * if it may be moved to a more global node?
6911  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
6912  )
6913 {
6914  SCIP_CONSHDLR* conshdlr;
6915  SCIP_CONSDATA* consdata;
6916  SCIP_CONSHDLRDATA* conshdlrdata;
6917 
6918  assert(scip != NULL);
6919 
6920  /* find the set partitioning constraint handler */
6921  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
6922  if( conshdlr == NULL )
6923  {
6924  SCIPerrorMessage("set partitioning / packing / covering constraint handler not found\n");
6925  return SCIP_INVALIDCALL;
6926  }
6927 
6928  /* create the constraint specific data */
6929  if( SCIPgetStage(scip) == SCIP_STAGE_PROBLEM )
6930  {
6931  /* create constraint in original problem */
6932  SCIP_CALL( consdataCreate(scip, &consdata, nvars, vars, setppctype) );
6933  }
6934  else
6935  {
6936  /* create constraint in transformed problem */
6937  SCIP_CALL( consdataCreateTransformed(scip, &consdata, nvars, vars, setppctype) );
6938  }
6939 
6940  /* create constraint */
6941  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, initial, separate, enforce, check, propagate,
6942  local, modifiable, dynamic, removable, stickingatnode) );
6943 
6944  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6945  assert(conshdlrdata != NULL);
6946 
6947  if( SCIPisTransformed(scip) && setppctype == SCIP_SETPPCTYPE_PARTITIONING )
6948  {
6949  ++(conshdlrdata->nsetpart);
6950  assert(conshdlrdata->nsetpart >= 0);
6951  }
6952 
6953  if( SCIPgetStage(scip) != SCIP_STAGE_PROBLEM )
6954  {
6955  /* get event handler */
6956  assert(conshdlrdata->eventhdlr != NULL);
6957 
6958  /* catch bound change events of variables */
6959  SCIP_CALL( catchAllEvents(scip, *cons, conshdlrdata->eventhdlr) );
6960  }
6961 
6962  return SCIP_OKAY;
6963 }
6964 
6965 /** creates and captures a normalized (with all coefficients +1) setppc constraint */
6966 static
6968  SCIP* scip, /**< SCIP data structure */
6969  SCIP_CONS** cons, /**< pointer to hold the created constraint */
6970  const char* name, /**< name of constraint */
6971  int nvars, /**< number of variables in the constraint */
6972  SCIP_VAR** vars, /**< array with variables of constraint entries */
6973  SCIP_Real* vals, /**< array with coefficients (+1.0 or -1.0) */
6974  int mult, /**< multiplier on the coefficients(+1 or -1) */
6975  SCIP_SETPPCTYPE setppctype, /**< type of constraint: set partitioning, packing, or covering constraint */
6976  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
6977  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
6978  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
6979  * Usually set to TRUE. */
6980  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
6981  * TRUE for model constraints, FALSE for additional, redundant constraints. */
6982  SCIP_Bool check, /**< should the constraint be checked for feasibility?
6983  * TRUE for model constraints, FALSE for additional, redundant constraints. */
6984  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
6985  * Usually set to TRUE. */
6986  SCIP_Bool local, /**< is constraint only valid locally?
6987  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
6988  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
6989  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
6990  * adds coefficients to this constraint. */
6991  SCIP_Bool dynamic, /**< is constraint subject to aging?
6992  * Usually set to FALSE. Set to TRUE for own cuts which
6993  * are separated as constraints. */
6994  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
6995  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
6996  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
6997  * if it may be moved to a more global node?
6998  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
6999  )
7000 {
7001  SCIP_VAR** transvars;
7002  int v;
7003 
7004  assert(nvars == 0 || vars != NULL);
7005  assert(nvars == 0 || vals != NULL);
7006  assert(mult == +1 || mult == -1);
7007 
7008  /* get temporary memory */
7009  SCIP_CALL( SCIPallocBufferArray(scip, &transvars, nvars) );
7010 
7011  /* negate positive or negative variables */
7012  for( v = 0; v < nvars; ++v )
7013  {
7014  if( mult * vals[v] > 0.0 )
7015  transvars[v] = vars[v];
7016  else
7017  {
7018  SCIP_CALL( SCIPgetNegatedVar(scip, vars[v], &transvars[v]) );
7019  }
7020  assert(transvars[v] != NULL);
7021  }
7022 
7023  /* create the constraint */
7024  SCIP_CALL( createConsSetppc(scip, cons, name, nvars, transvars, setppctype,
7025  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
7026 
7027  /* release temporary memory */
7028  SCIPfreeBufferArray(scip, &transvars);
7029 
7030  return SCIP_OKAY;
7031 }
7032 
7033 /** check, if linear constraint can be upgraded to set partitioning, packing, or covering constraint */
7034 static
7035 SCIP_DECL_LINCONSUPGD(linconsUpgdSetppc)
7036 { /*lint --e{715}*/
7037  assert(upgdcons != NULL);
7038  assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), "linear") == 0 );
7039 
7040  /* check, if linear constraint can be upgraded to set partitioning, packing, or covering constraint
7041  * - all set partitioning / packing / covering constraints consist only of binary variables with a
7042  * coefficient of +1.0 or -1.0 (variables with -1.0 coefficients can be negated):
7043  * lhs <= x1 + ... + xp - y1 - ... - yn <= rhs
7044  * - negating all variables y = (1-Y) with negative coefficients gives:
7045  * lhs + n <= x1 + ... + xp + Y1 + ... + Yn <= rhs + n
7046  * - negating all variables x = (1-X) with positive coefficients and multiplying with -1 gives:
7047  * p - rhs <= X1 + ... + Xp + y1 + ... + yn <= p - lhs
7048  * - a set partitioning constraint has left hand side of +1.0, and right hand side of +1.0 : x(S) == 1.0
7049  * -> without negations: lhs == rhs == 1 - n or lhs == rhs == p - 1
7050  * - a set packing constraint has left hand side of -infinity, and right hand side of +1.0 : x(S) <= 1.0
7051  * -> without negations: (lhs == -inf and rhs == 1 - n) or (lhs == p - 1 and rhs = +inf)
7052  * - a set covering constraint has left hand side of +1.0, and right hand side of +infinity: x(S) >= 1.0
7053  * -> without negations: (lhs == 1 - n and rhs == +inf) or (lhs == -inf and rhs = p - 1)
7054  */
7055  if( nposbin + nnegbin + nposimplbin + nnegimplbin == nvars && ncoeffspone + ncoeffsnone == nvars )
7056  {
7057  int mult;
7058 
7059  if( SCIPisEQ(scip, lhs, rhs) && (SCIPisEQ(scip, lhs, 1.0 - ncoeffsnone) || SCIPisEQ(scip, lhs, ncoeffspone - 1.0)) )
7060  {
7061  SCIPdebugMsg(scip, "upgrading constraint <%s> to set partitioning constraint\n", SCIPconsGetName(cons));
7062 
7063  /* check, if we have to multiply with -1 (negate the positive vars) or with +1 (negate the negative vars) */
7064  mult = SCIPisEQ(scip, lhs, 1.0 - ncoeffsnone) ? +1 : -1;
7065 
7066  /* create the set partitioning constraint (an automatically upgraded constraint is always unmodifiable) */
7067  assert(!SCIPconsIsModifiable(cons));
7068  SCIP_CALL( createNormalizedSetppc(scip, upgdcons, SCIPconsGetName(cons), nvars, vars, vals, mult,
7074  }
7075  else if( (SCIPisInfinity(scip, -lhs) && SCIPisEQ(scip, rhs, 1.0 - ncoeffsnone))
7076  || (SCIPisEQ(scip, lhs, ncoeffspone - 1.0) && SCIPisInfinity(scip, rhs)) )
7077  {
7078  SCIPdebugMsg(scip, "upgrading constraint <%s> to set packing constraint\n", SCIPconsGetName(cons));
7079 
7080  /* check, if we have to multiply with -1 (negate the positive vars) or with +1 (negate the negative vars) */
7081  mult = SCIPisInfinity(scip, -lhs) ? +1 : -1;
7082 
7083  /* create the set packing constraint (an automatically upgraded constraint is always unmodifiable) */
7084  assert(!SCIPconsIsModifiable(cons));
7085  SCIP_CALL( createNormalizedSetppc(scip, upgdcons, SCIPconsGetName(cons), nvars, vars, vals, mult,
7091  }
7092  else if( (SCIPisEQ(scip, lhs, 1.0 - ncoeffsnone) && SCIPisInfinity(scip, rhs))
7093  || (SCIPisInfinity(scip, -lhs) && SCIPisEQ(scip, rhs, ncoeffspone - 1.0)) )
7094  {
7095  SCIPdebugMsg(scip, "upgrading constraint <%s> to set covering constraint\n", SCIPconsGetName(cons));
7096 
7097  /* check, if we have to multiply with -1 (negate the positive vars) or with +1 (negate the negative vars) */
7098  mult = SCIPisInfinity(scip, rhs) ? +1 : -1;
7099 
7100  /* create the set covering constraint (an automatically upgraded constraint is always unmodifiable) */
7101  assert(!SCIPconsIsModifiable(cons));
7102  SCIP_CALL( createNormalizedSetppc(scip, upgdcons, SCIPconsGetName(cons), nvars, vars, vals, mult,
7108  }
7109  }
7110 
7111  return SCIP_OKAY;
7112 }
7113 
7114 /** tries to upgrade a quadratic constraint to a setpacking constraint */
7115 static
7116 SCIP_DECL_QUADCONSUPGD(quadraticUpgdSetppc)
7117 {
7118  SCIP_QUADVARTERM* quadvarterms;
7119  SCIP_BILINTERM* term;
7120  SCIP_VAR* vars[2];
7121  SCIP_Real coefx;
7122  SCIP_Real coefy;
7123  SCIP_Real rhs;
7125  assert( scip != NULL );
7126  assert( cons != NULL );
7127  assert( nupgdconss != NULL );
7128  assert( upgdconss != NULL );
7129  assert( ! SCIPconsIsModifiable(cons) );
7130  assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), "quadratic") == 0 );
7131 
7132  *nupgdconss = 0;
7133 
7134  SCIPdebugMsg(scip, "try to upgrade quadratic constraint <%s> to setpacking constraint ...\n", SCIPconsGetName(cons));
7135  SCIPdebugPrintCons(scip, cons, NULL);
7136 
7137  /* cannot currently handle linear part */
7138  if( SCIPgetNLinearVarsQuadratic(scip, cons) > 0 )
7139  return SCIP_OKAY;
7140 
7141  /* need only one bilinear term */
7142  if( SCIPgetNBilinTermsQuadratic(scip, cons) != 1 )
7143  return SCIP_OKAY;
7144 
7145  /* need exactly two quadratic variables */
7146  if( SCIPgetNQuadVarTermsQuadratic(scip, cons) != 2 )
7147  return SCIP_OKAY;
7148 
7149  /* get bilinear term */
7150  term = SCIPgetBilinTermsQuadratic(scip, cons);
7151  if( SCIPisZero(scip, term->coef) )
7152  return SCIP_OKAY;
7153 
7154  /* check types */
7156  return SCIP_OKAY;
7157 
7158  /* left and right hand side need to be equal
7159  * @todo we could also handle inequalities
7160  */
7161  rhs = SCIPgetRhsQuadratic(scip, cons);
7162  if( SCIPisInfinity(scip, rhs) || !SCIPisEQ(scip, SCIPgetLhsQuadratic(scip, cons), rhs) )
7163  return SCIP_OKAY;
7164 
7165  quadvarterms = SCIPgetQuadVarTermsQuadratic(scip, cons);
7166 
7167  coefx = quadvarterms[0].lincoef + quadvarterms[0].sqrcoef; /* for binary variables, we can treat sqr coef as lin coef */
7168  coefy = quadvarterms[1].lincoef + quadvarterms[0].sqrcoef; /* for binary variables, we can treat sqr coef as lin coef */
7169 
7170  /* divide constraint by coefficient of x*y */
7171  coefx /= term->coef;
7172  coefy /= term->coef;
7173  rhs /= term->coef;
7174 
7175  /* constraint is now of the form coefx * x + coefy * y + x * y == rhs
7176  * we can rewrite as (x + coefy) * (y + coefx) == rhs + coefx * coefy
7177  */
7178 
7179  /* we can only upgrade if coefx and coefy are 0 or -1 and rhs == -coefx * coefy */
7180  if( !SCIPisZero(scip, coefx) && !SCIPisEQ(scip, coefx, -1.0) )
7181  return SCIP_OKAY;
7182  if( !SCIPisZero(scip, coefy) && !SCIPisEQ(scip, coefy, -1.0) )
7183  return SCIP_OKAY;
7184  if( !SCIPisEQ(scip, rhs, -coefx * coefy) )
7185  return SCIP_OKAY;
7186 
7187  if( SCIPisZero(scip, coefy) )
7188  {
7189  vars[0] = quadvarterms[0].var;
7190  }
7191  else
7192  {
7193  assert(SCIPisEQ(scip, coefy, -1.0));
7194  /* x - 1 = -(1-x) = -(~x) */
7195  SCIP_CALL( SCIPgetNegatedVar(scip, quadvarterms[0].var, &vars[0]) );
7196  }
7197  if( SCIPisZero(scip, coefx) )
7198  {
7199  vars[1] = quadvarterms[1].var;
7200  }
7201  else
7202  {
7203  assert(SCIPisEQ(scip, coefx, -1.0));
7204  /* y - 1 = -(1 - y) = -(~y) */
7205  SCIP_CALL( SCIPgetNegatedVar(scip, quadvarterms[1].var, &vars[1]) );
7206  }
7207 
7208  /* constraint is now of the form vars[0] * vars[1] == 0 */
7209 
7210  SCIPdebugMsg(scip, "constraint <%s> can be upgraded ...\n", SCIPconsGetName(cons));
7211 
7212  /* vars[0] + vars[1] <= 1 */
7213  SCIP_CALL( SCIPcreateConsSetpack(scip, &upgdconss[0], SCIPconsGetName(cons), 2, vars,
7217  SCIPdebugPrintCons(scip, upgdconss[0], NULL);
7218 
7219  ++(*nupgdconss);
7220 
7221  return SCIP_OKAY;
7222 } /*lint !e715*/
7223 
7224 
7225 /*
7226  * Callback methods of constraint handler
7227  */
7228 
7229 /** copy method for constraint handler plugins (called when SCIP copies plugins) */
7230 static
7231 SCIP_DECL_CONSHDLRCOPY(conshdlrCopySetppc)
7232 { /*lint --e{715}*/
7233  assert(scip != NULL);
7234  assert(conshdlr != NULL);
7235  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7236 
7237  /* call inclusion method of constraint handler */
7240  *valid = TRUE;
7241 
7242  return SCIP_OKAY;
7243 }
7244 
7245 /** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
7246 static
7247 SCIP_DECL_CONSFREE(consFreeSetppc)
7248 { /*lint --e{715}*/
7249  SCIP_CONSHDLRDATA* conshdlrdata;
7250 
7251  assert(conshdlr != NULL);
7252  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7253  assert(scip != NULL);
7254 
7255  /* free constraint handler data */
7256  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7257  assert(conshdlrdata != NULL);
7258  SCIP_CALL( conshdlrdataFree(scip, &conshdlrdata) );
7259 
7260  SCIPconshdlrSetData(conshdlr, NULL);
7261 
7262  return SCIP_OKAY;
7263 }
7264 
7265 
7266 /** initialization method of constraint handler (called after problem was transformed) */
7267 static
7268 SCIP_DECL_CONSINIT(consInitSetppc)
7269 { /*lint --e{715}*/
7270  SCIP_CONSHDLRDATA* conshdlrdata;
7271 
7272  assert(conshdlr != NULL);
7273  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7274  assert(scip != NULL);
7275 
7276  /* free constraint handler data */
7277  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7278  assert(conshdlrdata != NULL);
7279 
7280  conshdlrdata->noldfixedvars = 0;
7281  conshdlrdata->noldimpls = 0;
7282  conshdlrdata->noldcliques = 0;
7283  conshdlrdata->noldupgrs = 0;
7284  conshdlrdata->nclqpresolve = 0;
7285  conshdlrdata->updatedsetppctype = FALSE;
7286  conshdlrdata->enablecliquelifting = TRUE;
7287 
7288  return SCIP_OKAY;
7289 }
7290 
7291 
7292 /** presolving deinitialization method of constraint handler (called after presolving has been finished) */
7293 static
7294 SCIP_DECL_CONSEXITPRE(consExitpreSetppc)
7295 { /*lint --e{715}*/
7296  int c;
7297 
7298  assert(scip != NULL);
7299  assert(conshdlr != NULL);
7300 
7301  for( c = 0; c < nconss; ++c )
7302  {
7303  if( !SCIPconsIsDeleted(conss[c]) )
7304  {
7305  /* we are not allowed to detect infeasibility in the exitpre stage */
7306  SCIP_CALL( applyFixings(scip, conss[c], NULL, NULL, NULL, NULL) );
7307  }
7308  }
7309 
7310  return SCIP_OKAY;
7311 }
7312 
7313 /** solving process deinitialization method of constraint handler (called before branch and bound process data is freed) */
7314 static
7315 SCIP_DECL_CONSEXITSOL(consExitsolSetppc)
7316 { /*lint --e{715}*/
7317  SCIP_CONSDATA* consdata;
7318  int c;
7319 
7320  /* release the rows of all constraints */
7321  for( c = 0; c < nconss; ++c )
7322  {
7323  consdata = SCIPconsGetData(conss[c]);
7324  assert(consdata != NULL);
7325 
7326  if( consdata->row != NULL )
7327  {
7328  SCIP_CALL( SCIPreleaseRow(scip, &consdata->row) );
7329  }
7330  }
7331 
7332  return SCIP_OKAY;
7333 }
7334 
7335 
7336 /** frees specific constraint data */
7337 static
7338 SCIP_DECL_CONSDELETE(consDeleteSetppc)
7339 { /*lint --e{715}*/
7340  SCIP_CONSHDLRDATA* conshdlrdata;
7341 
7342  assert(conshdlr != NULL);
7343  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7344 
7345  /* get event handler */
7346  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7347  assert(conshdlrdata != NULL);
7348  assert(conshdlrdata->eventhdlr != NULL);
7349 
7350  if( SCIPisTransformed(scip) )
7351  {
7352  if( (SCIP_SETPPCTYPE)((*consdata)->setppctype) == SCIP_SETPPCTYPE_PARTITIONING )
7353  {
7354  --(conshdlrdata->nsetpart);
7355  assert(conshdlrdata->nsetpart >= 0);
7356  }
7357  }
7358 
7359  /* if constraint belongs to transformed problem space, drop bound change events on variables */
7360  if( (*consdata)->nvars > 0 && SCIPvarIsTransformed((*consdata)->vars[0]) )
7361  {
7362  SCIP_CALL( dropAllEvents(scip, cons, conshdlrdata->eventhdlr) );
7363  }
7364 
7365  /* free setppc constraint data */
7366  SCIP_CALL( consdataFree(scip, consdata) );
7367 
7368  return SCIP_OKAY;
7369 }
7370 
7371 
7372 /** transforms constraint data into data belonging to the transformed problem */
7373 static
7374 SCIP_DECL_CONSTRANS(consTransSetppc)
7375 { /*lint --e{715}*/
7376  SCIP_CONSHDLRDATA* conshdlrdata;
7377  SCIP_CONSDATA* sourcedata;
7378  SCIP_CONSDATA* targetdata;
7379 
7380  /*debugMsg(scip, "Trans method of setppc constraints\n");*/
7381 
7382  assert(conshdlr != NULL);
7383  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7384  assert(SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMING);
7385  assert(sourcecons != NULL);
7386  assert(targetcons != NULL);
7387 
7388  /* get event handler */
7389  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7390  assert(conshdlrdata != NULL);
7391  assert(conshdlrdata->eventhdlr != NULL);
7392 
7393  sourcedata = SCIPconsGetData(sourcecons);
7394  assert(sourcedata != NULL);
7395  assert(sourcedata->row == NULL); /* in original problem, there cannot be LP rows */
7396 
7397  /* create constraint data for target constraint */
7398  SCIP_CALL( consdataCreateTransformed(scip, &targetdata, sourcedata->nvars, sourcedata->vars,
7399  (SCIP_SETPPCTYPE)sourcedata->setppctype) );
7400 
7401  /* create target constraint */
7402  SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata,
7403  SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons),
7404  SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons),
7405  SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons),
7406  SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) );
7407 
7408  if( (SCIP_SETPPCTYPE)sourcedata->setppctype == SCIP_SETPPCTYPE_PARTITIONING )
7409  {
7410  ++(conshdlrdata->nsetpart);
7411  assert(conshdlrdata->nsetpart >= 0);
7412  }
7413 
7414  /* catch bound change events of variables */
7415  SCIP_CALL( catchAllEvents(scip, *targetcons, conshdlrdata->eventhdlr) );
7416 
7417  return SCIP_OKAY;
7418 }
7419 
7420 
7421 /** LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved) */
7422 static
7423 SCIP_DECL_CONSINITLP(consInitlpSetppc)
7424 { /*lint --e{715}*/
7425  int c;
7426 
7427  *infeasible = FALSE;
7428 
7429  for( c = 0; c < nconss && !(*infeasible); ++c )
7430  {
7431  assert(SCIPconsIsInitial(conss[c]));
7432  SCIP_CALL( addCut(scip, conss[c], infeasible) );
7433  }
7434 
7435  return SCIP_OKAY;
7436 }
7437 
7438 
7439 /** separation method of constraint handler for LP solutions */
7440 static
7441 SCIP_DECL_CONSSEPALP(consSepalpSetppc)
7442 { /*lint --e{715}*/
7443  SCIP_Bool cutoff;
7444  SCIP_Bool separated;
7445  SCIP_Bool reduceddom;
7446  int c;
7447 
7448  assert(conshdlr != NULL);
7449  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7450  assert(nconss == 0 || conss != NULL);
7451  assert(result != NULL);
7452 
7453  SCIPdebugMsg(scip, "separating %d/%d set partitioning / packing / covering constraints\n", nusefulconss, nconss);
7454 
7455  *result = SCIP_DIDNOTFIND;
7456 
7457  cutoff = FALSE;
7458  separated = FALSE;
7459  reduceddom = FALSE;
7460 
7461  /* check all useful set partitioning / packing / covering constraints for feasibility */
7462  for( c = 0; c < nusefulconss && !cutoff; ++c )
7463  {
7464  SCIP_CALL( separateCons(scip, conss[c], NULL, TRUE, &cutoff, &separated, &reduceddom) );
7465  }
7466 
7467  /* combine set partitioning / packing / covering constraints to get more cuts */
7468  /**@todo further cuts of set partitioning / packing / covering constraints */
7469 
7470  /* return the correct result */
7471  if( cutoff )
7472  *result = SCIP_CUTOFF;
7473  else if( reduceddom )
7474  *result = SCIP_REDUCEDDOM;
7475  else if( separated )
7476  *result = SCIP_SEPARATED;
7477 
7478  return SCIP_OKAY;
7479 }
7480 
7481 
7482 /** separation method of constraint handler for arbitrary primal solutions */
7483 static
7484 SCIP_DECL_CONSSEPASOL(consSepasolSetppc)
7485 { /*lint --e{715}*/
7486  SCIP_Bool cutoff;
7487  SCIP_Bool separated;
7488  SCIP_Bool reduceddom;
7489  int c;
7490 
7491  assert(conshdlr != NULL);
7492  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7493  assert(nconss == 0 || conss != NULL);
7494  assert(result != NULL);
7495 
7496  SCIPdebugMsg(scip, "separating %d/%d set partitioning / packing / covering constraints\n", nusefulconss, nconss);
7497 
7498  *result = SCIP_DIDNOTFIND;
7499 
7500  cutoff = FALSE;
7501  separated = FALSE;
7502  reduceddom = FALSE;
7503 
7504  /* check all useful set partitioning / packing / covering constraints for feasibility */
7505  for( c = 0; c < nusefulconss && !cutoff; ++c )
7506  {
7507  SCIP_CALL( separateCons(scip, conss[c], sol, FALSE, &cutoff, &separated, &reduceddom) );
7508  }
7509 
7510  /* combine set partitioning / packing / covering constraints to get more cuts */
7511  /**@todo further cuts of set partitioning / packing / covering constraints */
7512 
7513  /* return the correct result */
7514  if( cutoff )
7515  *result = SCIP_CUTOFF;
7516  else if( reduceddom )
7517  *result = SCIP_REDUCEDDOM;
7518  else if( separated )
7519  *result = SCIP_SEPARATED;
7520 
7521  return SCIP_OKAY;
7522 }
7523 
7524 
7525 #ifdef VARUSES
7526 #ifdef BRANCHLP
7527 /** if fractional variables exist, chooses a set S of them and branches on (i) x(S) == 0, and (ii) x(S) >= 1 */
7528 static
7529 SCIP_RETCODE branchLP(
7530  SCIP* scip, /**< SCIP data structure */
7531  SCIP_CONSHDLR* conshdlr, /**< set partitioning / packing / covering constraint handler */
7532  SCIP_RESULT* result /**< pointer to store the result SCIP_BRANCHED, if branching was applied */
7533  )
7534 {
7535  SCIP_CONSHDLRDATA* conshdlrdata;
7536  SCIP_INTARRAY* varuses;
7537  SCIP_VAR** lpcands;
7538  SCIP_VAR** sortcands;
7539  SCIP_VAR* var;
7540  SCIP_Real branchweight;
7541  SCIP_Real solval;
7542  int* uses;
7543  int nlpcands;
7544  int nsortcands;
7545  int nselcands;
7546  int numuses;
7547  int i;
7548  int j;
7549 
7550  /**@todo use a better set partitioning / packing / covering branching on LP solution (use SOS branching) */
7551 
7552  assert(conshdlr != NULL);
7553  assert(result != NULL);
7554 
7555  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7556  assert(conshdlrdata != NULL);
7557 
7558  varuses = conshdlrdata->varuses;
7559  assert(varuses != NULL);
7560 
7561  /* get fractional variables */
7562  SCIP_CALL( SCIPgetLPBranchCands(scip, &lpcands, NULL, NULL, &nlpcands, NULL, NULL) );
7563  if( nlpcands == 0 )
7564  return SCIP_OKAY;
7565 
7566  assert(MINBRANCHWEIGHT <= MAXBRANCHWEIGHT);
7567 
7568  /* get temporary memory */
7569  SCIP_CALL( SCIPallocBufferArray(scip, &sortcands, nlpcands) );
7570  SCIP_CALL( SCIPallocBufferArray(scip, &uses, nlpcands) );
7571 
7572  /* sort fractional variables by number of uses in enabled set partitioning / packing / covering constraints */
7573  nsortcands = 0;
7574  for( i = 0; i < nlpcands; ++i )
7575  {
7576  var = lpcands[i];
7577  numuses = SCIPgetIntarrayVal(scip, varuses, SCIPvarGetIndex(var));
7578  if( numuses > 0 )
7579  {
7580  for( j = nsortcands; j > 0 && numuses > uses[j-1]; --j )
7581  {
7582  sortcands[j] = sortcands[j-1];
7583  uses[j] = uses[j-1];
7584  }
7585  assert(0 <= j && j <= nsortcands);
7586  sortcands[j] = var;
7587  uses[j] = numuses;
7588  nsortcands++;
7589  }
7590  }
7591  assert(nsortcands <= nlpcands);
7592 
7593  /* if none of the fractional variables is member of a set partitioning / packing / covering constraint,
7594  * we are not responsible for doing the branching
7595  */
7596  if( nsortcands > 0 )
7597  {
7598  SCIP_Real cumprio = 0.0;
7599  SCIP_Real minprio = SCIP_INVALID;
7600  SCIP_Real minestzero = SCIP_INVALID;
7601  SCIP_Real minestone = SCIP_INVALID;
7602  SCIP_Real tmp;
7603 
7604  /* select the first variables from the sorted candidate list, until MAXBRANCHWEIGHT is reached;
7605  * then choose one less
7606  */
7607  branchweight = 0.0;
7608  solval = 0.0;
7609  for( nselcands = 0; nselcands < nsortcands; ++nselcands )
7610  {
7611  solval = SCIPgetVarSol(scip, sortcands[nselcands]);
7612  assert(SCIPisFeasGE(scip, solval, 0.0) && SCIPisFeasLE(scip, solval, 1.0));
7613  branchweight += solval;
7614 
7615  /* did we exceed the maximal weight */
7616  if( branchweight > MAXBRANCHWEIGHT )
7617  break;
7618 
7619  /* @todo instead of taking the minimum into account try other variants like the maximum and the average */
7620  /* calculate priorities and estimates by adding up/taking the minimum of all single priorities/estimates */
7621  cumprio += SCIPcalcNodeselPriority(scip, sortcands[nselcands], SCIP_BRANCHDIR_DOWNWARDS, 0.0);
7622  tmp = SCIPcalcNodeselPriority(scip, sortcands[nselcands], SCIP_BRANCHDIR_UPWARDS, 1.0);
7623  minprio = MIN(minprio, tmp);
7624  tmp = SCIPcalcChildEstimate(scip, sortcands[nselcands], 0.0);;
7625  minestzero = MIN(minestzero, tmp);
7626  tmp = SCIPcalcChildEstimate(scip, sortcands[nselcands], 1.0);;
7627  minestone = MIN(minestone, tmp);
7628  }
7629  assert(minestzero != SCIP_INVALID); /*lint !e777*/
7630  assert(minestone != SCIP_INVALID); /*lint !e777*/
7631  assert(minprio != SCIP_INVALID); /*lint !e777*/
7632  assert(nselcands > 0);
7633  branchweight -= solval;
7634 
7635  /* check, if we accumulated at least MIN and at most MAXBRANCHWEIGHT weight */
7636  if( MINBRANCHWEIGHT <= branchweight && branchweight <= MAXBRANCHWEIGHT )
7637  {
7638  SCIP_NODE* node;
7639 
7640  /* perform the binary set branching on the selected variables */
7641  assert(1 <= nselcands && nselcands <= nlpcands);
7642 
7643  /* create left child, fix x_i = 0 for all i \in S */
7644  SCIP_CALL( SCIPcreateChild(scip, &node, cumprio, minestzero) );
7645  for( i = 0; i < nselcands; ++i )
7646  {
7647  SCIP_CALL( SCIPchgVarUbNode(scip, node, sortcands[i], 0.0) );
7648  }
7649 
7650  /* create right child: add constraint x(S) >= 1 */
7651  SCIP_CALL( SCIPcreateChild(scip, &node, minprio, minestone) );
7652  if( nselcands == 1 )
7653  {
7654  /* only one candidate selected: fix it to 1.0 */
7655  SCIPdebugMsg(scip, "fixing variable <%s> to 1.0 in right child node\n", SCIPvarGetName(sortcands[0]));
7656  SCIP_CALL( SCIPchgVarLbNode(scip, node, sortcands[0], 1.0) );
7657  }
7658  else
7659  {
7660  SCIP_CONS* newcons;
7661  char name[SCIP_MAXSTRLEN];
7662 
7663  /* add set covering constraint x(S) >= 1 */
7665 
7666  SCIP_CALL( SCIPcreateConsSetcover(scip, &newcons, name, nselcands, sortcands,
7667  FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE) );
7668  SCIP_CALL( SCIPaddConsNode(scip, node, newcons, NULL) );
7669  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
7670  }
7671 
7672  *result = SCIP_BRANCHED;
7673 
7674 #ifdef SCIP_DEBUG
7675  SCIPdebugMsg(scip, "binary set branching: nselcands=%d/%d, weight(S)=%g, A={", nselcands, nlpcands, branchweight);
7676  for( i = 0; i < nselcands; ++i )
7677  SCIPdebugMsgPrint(scip, " %s[%g]", SCIPvarGetName(sortcands[i]), SCIPgetSolVal(scip, NULL, sortcands[i]));
7678  SCIPdebugMsgPrint(scip, " }\n");
7679 #endif
7680  }
7681  }
7682 
7683  /* free temporary memory */
7684  SCIPfreeBufferArray(scip, &uses);
7685  SCIPfreeBufferArray(scip, &sortcands);
7686 
7687  return SCIP_OKAY;
7688 }
7689 #endif
7690 
7691 /** if unfixed variables exist, chooses a set S of them and creates |S|+1 child nodes:
7692  * - for each variable i from S, create child node with x_0 = ... = x_i-1 = 0, x_i = 1
7693  * - create an additional child node x_0 = ... = x_n-1 = 0
7694  */
7695 static
7696 SCIP_RETCODE branchPseudo(
7697  SCIP* scip, /**< SCIP data structure */
7698  SCIP_CONSHDLR* conshdlr, /**< set partitioning / packing / covering constraint handler */
7699  SCIP_RESULT* result /**< pointer to store the result SCIP_BRANCHED, if branching was applied */
7700  )
7701 {
7702  SCIP_CONSHDLRDATA* conshdlrdata;
7703  SCIP_INTARRAY* varuses;
7704  SCIP_VAR** pseudocands;
7705  SCIP_VAR** branchcands;
7706  SCIP_VAR* var;
7707  SCIP_NODE* node;
7708  int* canduses;
7709  int npseudocands;
7710  int maxnbranchcands;
7711  int nbranchcands;
7712  int uses;
7713  int i;
7714  int j;
7715 
7716  /**@todo use a better set partitioning / packing / covering branching on pseudo solution (use SOS branching) */
7717 
7718  assert(conshdlr != NULL);
7719  assert(result != NULL);
7720 
7721  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7722  assert(conshdlrdata != NULL);
7723 
7724  /* check, if pseudo branching is disabled */
7725  if( conshdlrdata->npseudobranches <= 1 )
7726  return SCIP_OKAY;
7727 
7728  /* get fractional variables */
7729  SCIP_CALL( SCIPgetPseudoBranchCands(scip, &pseudocands, NULL, &npseudocands) );
7730  if( npseudocands == 0 )
7731  return SCIP_OKAY;
7732 
7733  varuses = conshdlrdata->varuses;
7734  assert(varuses != NULL);
7735 
7736  /* choose the maximal number of branching variables */
7737  maxnbranchcands = conshdlrdata->npseudobranches-1;
7738  assert(maxnbranchcands >= 1);
7739 
7740  /* get temporary memory */
7741  SCIP_CALL( SCIPallocBufferArray(scip, &branchcands, maxnbranchcands) );
7742  SCIP_CALL( SCIPallocBufferArray(scip, &canduses, maxnbranchcands) );
7743 
7744  /* sort unfixed variables by number of uses in enabled set partitioning / packing / covering constraints */
7745  nbranchcands = 0;
7746  for( i = 0; i < npseudocands; ++i )
7747  {
7748  var = pseudocands[i];
7749  uses = SCIPgetIntarrayVal(scip, varuses, SCIPvarGetIndex(var));
7750  if( uses > 0 )
7751  {
7752  if( nbranchcands < maxnbranchcands || uses > canduses[nbranchcands-1] )
7753  {
7754  for( j = MIN(nbranchcands, maxnbranchcands-1); j > 0 && uses > canduses[j-1]; --j )
7755  {
7756  branchcands[j] = branchcands[j-1];
7757  canduses[j] = canduses[j-1];
7758  }
7759  assert(0 <= j && j <= nbranchcands && j < maxnbranchcands);
7760  branchcands[j] = var;
7761  canduses[j] = uses;
7762  if( nbranchcands < maxnbranchcands )
7763  nbranchcands++;
7764  }
7765  }
7766  }
7767  assert(nbranchcands <= maxnbranchcands);
7768 
7769  /* if none of the unfixed variables is member of a set partitioning / packing / covering constraint,
7770  * we are not responsible for doing the branching
7771  */
7772  if( nbranchcands > 0 )
7773  {
7774  SCIP_Real* estone;
7775  SCIP_Real minestzero = SCIP_INVALID;
7776  SCIP_Real tmp;
7777 
7778  SCIP_CALL( SCIPallocBufferArray(scip, &estone, nbranchcands) );
7779 
7780  /* @todo instead of taking the minimum into account try other variants like the maximum and the average */
7781  /* @todo calculate priorities instead of setting it to the number of branching candidates */
7782  /* calculate estimates by taking the minimum over all single estimates */
7783  for( i = 0; i < nbranchcands; ++i )
7784  {
7785  tmp = SCIPcalcChildEstimate(scip, branchcands[i], 0.0);;
7786  minestzero = MIN(minestzero, tmp);
7787  estone[i] = SCIPcalcChildEstimate(scip, branchcands[i], 1.0);
7788  }
7789  assert(minestzero != SCIP_INVALID); /*lint !e777*/
7790 
7791  /* branch on the first part of the sorted candidates:
7792  * - for each of these variables i, create a child node x_0 = ... = x_i-1 = 0, x_i = 1
7793  * - create an additional child node x_0 = ... = x_n-1 = 0
7794  */
7795  for( i = 0; i < nbranchcands; ++i )
7796  {
7797  /* create child with x_0 = ... = x_i-1 = 0, x_i = 1 */
7798  SCIP_CALL( SCIPcreateChild(scip, &node, (SCIP_Real)nbranchcands, MIN(minestzero, estone[i])) );
7799  for( j = 0; j < i; ++j )
7800  {
7801  SCIP_CALL( SCIPchgVarUbNode(scip, node, branchcands[j], 0.0) );
7802  }
7803  SCIP_CALL( SCIPchgVarLbNode(scip, node, branchcands[i], 1.0) );
7804  }
7805  /* create child with x_0 = ... = x_n = 0 */
7806  SCIP_CALL( SCIPcreateChild(scip, &node, (SCIP_Real)nbranchcands, minestzero) );
7807  for( i = 0; i < nbranchcands; ++i )
7808  {
7809  SCIP_CALL( SCIPchgVarUbNode(scip, node, branchcands[i], 0.0) );
7810  }
7811 
7812  *result = SCIP_BRANCHED;
7813 
7814  SCIPfreeBufferArray(scip, &estone);
7815 
7816 #ifdef SCIP_DEBUG
7817  {
7818  int nchildren;
7819  SCIP_CALL( SCIPgetChildren(scip, NULL, &nchildren) );
7820  SCIPdebugMsg(scip, "branched on pseudo solution: %d children\n", nchildren);
7821  }
7822 #endif
7823  }
7824 
7825  /* free temporary memory */
7826  SCIPfreeBufferArray(scip, &canduses);
7827  SCIPfreeBufferArray(scip, &branchcands);
7828 
7829  return SCIP_OKAY;
7830 }
7831 #endif
7832 
7833 
7834 /** constraint enforcing method of constraint handler for LP solutions */
7835 static
7836 SCIP_DECL_CONSENFOLP(consEnfolpSetppc)
7837 { /*lint --e{715}*/
7838  SCIP_CALL( enforceConstraint(scip, conshdlr, conss, nconss, nusefulconss, NULL, result) );
7839 
7840  return SCIP_OKAY;
7841 }
7842 
7843 
7844 /** constraint enforcing method of constraint handler for relaxation solutions */
7845 static
7846 SCIP_DECL_CONSENFORELAX(consEnforelaxSetppc)
7847 { /*lint --e{715}*/
7848  SCIP_CALL( enforceConstraint(scip, conshdlr, conss, nconss, nusefulconss, sol, result) );
7849 
7850  return SCIP_OKAY;
7851 }
7852 
7853 
7854 /** constraint enforcing method of constraint handler for pseudo solutions */
7855 static
7856 SCIP_DECL_CONSENFOPS(consEnfopsSetppc)
7857 { /*lint --e{715}*/
7858  SCIP_Bool cutoff;
7859  SCIP_Bool infeasible;
7860  SCIP_Bool reduceddom;
7861  SCIP_Bool solvelp;
7862  int c;
7863 
7864  assert(conshdlr != NULL);
7865  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7866  assert(nconss == 0 || conss != NULL);
7867  assert(result != NULL);
7868 
7869  /* if the solution is infeasible anyway due to objective value, skip the constraint processing and branch directly */
7870 #ifdef VARUSES
7871  if( objinfeasible )
7872  {
7873  *result = SCIP_DIDNOTRUN;
7874  SCIP_CALL( branchPseudo(scip, conshdlr, result) );
7875  return SCIP_OKAY;
7876  }
7877 #endif
7878 
7879  SCIPdebugMsg(scip, "pseudo enforcing %d set partitioning / packing / covering constraints\n", nconss);
7880 
7881  *result = SCIP_FEASIBLE;
7882 
7883  cutoff = FALSE;
7884  infeasible = FALSE;
7885  reduceddom = FALSE;
7886  solvelp = FALSE;
7887 
7888  /* check all set partitioning / packing / covering constraints for feasibility */
7889  for( c = 0; c < nconss && !cutoff && !reduceddom && !solvelp; ++c )
7890  {
7891  SCIP_CALL( enforcePseudo(scip, conss[c], &cutoff, &infeasible, &reduceddom, &solvelp) );
7892  }
7893 
7894  if( cutoff )
7895  *result = SCIP_CUTOFF;
7896  else if( reduceddom )
7897  *result = SCIP_REDUCEDDOM;
7898  else if( solvelp )
7899  *result = SCIP_SOLVELP;
7900  else if( infeasible )
7901  {
7902  *result = SCIP_INFEASIBLE;
7903 
7904 #ifdef VARUSES
7905  /* at least one constraint is violated by pseudo solution and we didn't find a better way to resolve this:
7906  * -> branch on pseudo solution
7907  */
7908  SCIP_CALL( branchPseudo(scip, conshdlr, result) );
7909 #endif
7910  }
7911 
7912  return SCIP_OKAY;
7913 }
7914 
7915 
7916 /** feasibility check method of constraint handler for integral solutions */
7917 static
7918 SCIP_DECL_CONSCHECK(consCheckSetppc)
7919 { /*lint --e{715}*/
7920  SCIP_CONS* cons;
7921  SCIP_CONSDATA* consdata;
7922  int c;
7923 
7924  assert(conshdlr != NULL);
7925  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7926  assert(nconss == 0 || conss != NULL);
7927  assert(result != NULL);
7928 
7929  *result = SCIP_FEASIBLE;
7930 
7931  /* check all set partitioning / packing / covering constraints for feasibility */
7932  for( c = 0; c < nconss && (*result == SCIP_FEASIBLE || completely); ++c )
7933  {
7934  cons = conss[c];
7935  consdata = SCIPconsGetData(cons);
7936  assert(consdata != NULL);
7937  if( checklprows || consdata->row == NULL || !SCIProwIsInLP(consdata->row) )
7938  {
7939  if( !checkCons(scip, consdata, sol) )
7940  {
7941  /* constraint is violated */
7942  *result = SCIP_INFEASIBLE;
7943 
7944  if( printreason )
7945  {
7946  SCIP_Real sum = 0.0;
7947  int v;
7948 
7949  SCIP_CALL( SCIPprintCons(scip, cons, NULL) );
7950 
7951  for( v = 0; v < consdata->nvars; ++v )
7952  {
7953  assert(SCIPvarIsBinary(consdata->vars[v]));
7954 
7955  sum += SCIPgetSolVal(scip, sol, consdata->vars[v]);
7956  }
7957  SCIPinfoMessage(scip, NULL, ";\n");
7958  SCIPinfoMessage(scip, NULL, "violation: the right hand side is violated by by %.15g\n", ABS(sum - 1));
7959  }
7960  }
7961  }
7962  }
7963 
7964  return SCIP_OKAY;
7965 }
7966 
7967 /** domain propagation method of constraint handler */
7968 static
7969 SCIP_DECL_CONSPROP(consPropSetppc)
7970 { /*lint --e{715}*/
7971  SCIP_Bool cutoff;
7972  SCIP_Bool addcut;
7973  SCIP_Bool mustcheck;
7974  SCIP_Bool inpresolve;
7975  int nfixedvars = 0;
7976  int c;
7978  assert(conshdlr != NULL);
7979  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
7980  assert(nconss == 0 || conss != NULL);
7981  assert(result != NULL);
7982 
7983  *result = SCIP_DIDNOTFIND;
7984 
7985  SCIPdebugMsg(scip, "propagating %d/%d set partitioning / packing / covering constraints\n", nmarkedconss, nconss);
7986 
7987  cutoff = FALSE;
7988  inpresolve = (SCIPgetStage(scip) < SCIP_STAGE_INITSOLVE);
7989 
7990  /* propagate all marked set partitioning / packing / covering constraints */
7991  for( c = nmarkedconss - 1; c >= 0 && !cutoff; --c )
7992  {
7993  assert(SCIPconsGetData(conss[c]) != NULL);
7994 
7995  /* during presolving, we do not want to propagate constraints with multiaggregated variables. After presolving,
7996  * we want to resolve the multiaggregation to have a clean data structure; All initial constraints should not
7997  * have multiaggregated variables, but this is not true for constraints that were introduced during solving
7998  */
7999  if( SCIPconsGetData(conss[c])->existmultaggr )
8000  {
8001  int naddconss, ndelconss;
8002 
8003  if( inpresolve )
8004  continue;
8005 
8006  naddconss = ndelconss = 0;
8007  SCIP_CALL( applyFixings(scip, conss[c], &naddconss, &ndelconss, &nfixedvars, &cutoff) );
8008 
8009  if( cutoff )
8010  break;
8011  }
8012 
8013  /* all multiaggregations should be resolved at here */
8014  assert(inpresolve || ! SCIPconsGetData(conss[c])->existmultaggr);
8015 
8016  SCIP_CALL( processFixings(scip, conss[c], &cutoff, &nfixedvars, &addcut, &mustcheck) );
8017 
8018  SCIP_CALL( SCIPunmarkConsPropagate(scip, conss[c]) );
8019  }
8020 
8021  /* return the correct result */
8022  if( cutoff )
8023  *result = SCIP_CUTOFF;
8024  else if( nfixedvars > 0 )
8025  *result = SCIP_REDUCEDDOM;
8026 
8027  return SCIP_OKAY;
8028 }
8029 
8030 
8031 /** presolving method of constraint handler */
8032 static
8033 SCIP_DECL_CONSPRESOL(consPresolSetppc)
8034 { /*lint --e{715}*/
8035  SCIP_CONSHDLRDATA* conshdlrdata;
8036  int oldnfixedvars;
8037  int oldnaggrvars;
8038  int oldndelconss;
8039  int oldnchgcoefs;
8040  int firstchange;
8041  int firstclique;
8042  int lastclique;
8043  int startdelconss;
8044  int c;
8045  SCIP_Bool cutoff;
8046 
8047  assert(conshdlr != NULL);
8048  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
8049  assert(scip != NULL);
8050  assert(result != NULL);
8051 
8052  *result = SCIP_DIDNOTFIND;
8053  oldnfixedvars = *nfixedvars;
8054  oldndelconss = *ndelconss;
8055  oldnaggrvars = *naggrvars;
8056  oldnchgcoefs = *nchgcoefs;
8057  cutoff = FALSE;
8058 
8059  conshdlrdata = SCIPconshdlrGetData(conshdlr);
8060  assert(conshdlrdata != NULL);
8061 
8062  /* determine whether we want to run the clique lifting procedure */
8063  conshdlrdata->enablecliquelifting = conshdlrdata->enablecliquelifting || conshdlrdata->updatedsetppctype
8064  || conshdlrdata->noldfixedvars != SCIPgetNFixedVars(scip) || conshdlrdata->noldimpls != SCIPgetNImplications(scip)
8065  || conshdlrdata->noldcliques != SCIPgetNCliques(scip) || conshdlrdata->noldupgrs != nconss;
8066 
8067  /* remember old values */
8068  startdelconss = *ndelconss;
8069  conshdlrdata->noldimpls = SCIPgetNImplications(scip);
8070  conshdlrdata->noldcliques = SCIPgetNCliques(scip);
8071  conshdlrdata->updatedsetppctype = FALSE;
8072 
8073  /* process constraints */
8074  firstchange = INT_MAX;
8075  firstclique = INT_MAX;
8076  lastclique = -1;
8077  for( c = 0; c < nconss && !SCIPisStopped(scip); ++c )
8078  {
8079  SCIP_CONS* cons;
8080  SCIP_CONSDATA* consdata;
8081 
8082  assert(*result != SCIP_CUTOFF);
8083 
8084  cons = conss[c];
8085  assert(cons != NULL);
8086  consdata = SCIPconsGetData(cons);
8087  assert(consdata != NULL);
8088 
8089  /*SCIPdebugMsg(scip, "presolving set partitioning / packing / covering constraint <%s>\n", SCIPconsGetName(cons));*/
8090 
8091  /* remove all variables that are fixed to zero and replace all aggregated variables */
8092  if( consdata->nfixedzeros > 0 || nnewaggrvars > 0 || nnewaddconss > 0 || nnewupgdconss > 0
8093  || *naggrvars > oldnaggrvars || (nrounds == 0 && SCIPgetNRuns(scip) > 1) )
8094  {
8095  SCIP_CALL( applyFixings(scip, cons, naddconss, ndelconss, nfixedvars, &cutoff) );
8096 
8097  if( cutoff )
8098  {
8099  *result = SCIP_CUTOFF;
8100  return SCIP_OKAY;
8101  }
8102 
8103  if( SCIPconsIsDeleted(cons) )
8104  continue;
8105  }
8106 
8107  /* find pairs of negated variables in constraint:
8108  * partitioning/packing: all other variables must be zero, constraint is redundant
8109  * covering: constraint is redundant
8110  *
8111  * find sets of equal variables in constraint:
8112  * partitioning/packing: variable must be zero
8113  * covering: multiple entries of variable can be replaced by single entry
8114  */
8115  SCIP_CALL( mergeMultiples(scip, cons, nfixedvars, ndelconss, nchgcoefs, &cutoff) );
8116 
8117  if( cutoff )
8118  {
8119  *result = SCIP_CUTOFF;
8120  return SCIP_OKAY;
8121  }
8122 
8123  /* if constraint was deleted while merging, go to the next constraint */
8124  if( !SCIPconsIsActive(cons) )
8125  continue;
8126 
8127  /* remove fixings found by merging */
8128  if( consdata->nfixedzeros > 0 )
8129  {
8130  SCIP_CALL( applyFixings(scip, cons, naddconss, ndelconss, nfixedvars, &cutoff) );
8131 
8132  if( cutoff )
8133  {
8134  *result = SCIP_CUTOFF;
8135  return SCIP_OKAY;
8136  }
8137 
8138  if( SCIPconsIsDeleted(cons) )
8139  continue;
8140  }
8141 
8142  /* check if constraint is already redundant or infeasible due to fixings, fix or aggregate left over variables if
8143  * possible
8144  */
8145  SCIP_CALL( presolvePropagateCons(scip, cons, TRUE, NULL, NULL, NULL, NULL, nfixedvars, naggrvars, ndelconss, &cutoff) );
8146 
8147  if( cutoff )
8148  {
8149  *result = SCIP_CUTOFF;
8150  return SCIP_OKAY;
8151  }
8152 
8153  /* if constraint was deleted while propagation, go to the next constraint */
8154  if( !SCIPconsIsActive(cons) )
8155  continue;
8156 
8157  /* remove fixings found by presolvePropagateCons() */
8158  if( consdata->nfixedzeros > 0 )
8159  {
8160  SCIP_CALL( applyFixings(scip, cons, naddconss, ndelconss, nfixedvars, &cutoff) );
8161 
8162  if( cutoff )
8163  {
8164  *result = SCIP_CUTOFF;
8165  return SCIP_OKAY;
8166  }
8167 
8168  if( SCIPconsIsDeleted(cons) )
8169  continue;
8170  }
8171 
8172  /* perform dual reductions */
8173  if( conshdlrdata->dualpresolving && SCIPallowDualReds(scip) )
8174  {
8175  SCIP_CALL( dualPresolving(scip, cons, nfixedvars, ndelconss, result) );
8176 
8177  /* if dual reduction deleted the constraint we take the next */
8178  if( !SCIPconsIsActive(cons) )
8179  continue;
8180  }
8181 
8182  /* remember the first changed constraint to begin the next redundancy round with */
8183  if( firstchange == INT_MAX && consdata->changed )
8184  firstchange = c;
8185 
8186  /* remember the first and last constraints for which we have to add the clique information */
8187  if( !consdata->cliqueadded && consdata->nvars >= 2 )
8188  {
8189  if( firstclique == INT_MAX )
8190  firstclique = c;
8191  lastclique = c;
8192  }
8193  }
8194 
8195  /* update result pointer */
8196  if( oldnfixedvars < *nfixedvars || oldnaggrvars < *naggrvars || oldndelconss < *ndelconss || oldnchgcoefs < *nchgcoefs )
8197  *result = SCIP_SUCCESS;
8198 
8199  if( firstchange < nconss && conshdlrdata->presolusehashing )
8200  {
8201  /* detect redundant constraints; fast version with hash table instead of pairwise comparison */
8202  SCIP_CALL( detectRedundantConstraints(scip, SCIPblkmem(scip), conss, nconss, &firstchange, ndelconss, nchgsides) );
8203  if( oldndelconss < *ndelconss )
8204  *result = SCIP_SUCCESS;
8205  }
8206 
8207  /* determine singleton variables in set-partitioning/-packing constraints, or doubleton variables (active and
8208  * negated) in any combination of set-partitioning and set-packing constraints
8209  */
8210  if( nconss > 1 && (presoltiming & SCIP_PRESOLTIMING_MEDIUM) != 0
8211  && ((conshdlrdata->nsetpart > 0 && !SCIPdoNotMultaggr(scip) && conshdlrdata->conshdlrlinear != NULL)
8212  || (conshdlrdata->dualpresolving && SCIPallowDualReds(scip)
8213  && conshdlrdata->nsetpart < nconss && !SCIPdoNotAggr(scip))) )
8214  {
8215  SCIP_CALL( removeDoubleAndSingletonsAndPerformDualpresolve(scip, conss, nconss, conshdlrdata->dualpresolving
8216  && SCIPallowDualReds(scip), conshdlrdata->conshdlrlinear != NULL, nfixedvars,
8217  naggrvars, ndelconss, nchgcoefs, nchgsides, &cutoff) );
8218 
8219  if( cutoff )
8220  {
8221  *result = SCIP_CUTOFF;
8222  return SCIP_OKAY;
8223  }
8224  else if( oldnfixedvars < *nfixedvars || oldnaggrvars < *naggrvars || oldndelconss < *ndelconss )
8225  *result = SCIP_SUCCESS;
8226  }
8227 
8228  /* clique lifting */
8229  if( conshdlrdata->cliquelifting && conshdlrdata->enablecliquelifting && (presoltiming & SCIP_PRESOLTIMING_EXHAUSTIVE) != 0 )
8230  {
8231  /* add cliques first before lifting variables */
8232  SCIP_CALL( addCliques(scip, conss, nconss, firstclique, lastclique, naddconss, ndelconss, nchgbds, &cutoff) );
8233 
8234  if( cutoff )
8235  {
8236  *result = SCIP_CUTOFF;
8237  return SCIP_OKAY;
8238  }
8239 
8240  firstclique = nconss;
8241  lastclique = -1;
8242 
8243  /* lift variables and check for fixings due to clique infomation */
8244  SCIP_CALL( preprocessCliques(scip, conshdlrdata, conss, nconss, nrounds, &firstchange, &firstclique,
8245  &lastclique, nfixedvars, naggrvars, ndelconss, nchgcoefs, &cutoff) );
8246  ++(conshdlrdata->nclqpresolve);
8247 
8248  if( cutoff )
8249  {
8250  *result = SCIP_CUTOFF;
8251  return SCIP_OKAY;
8252  }
8253  else if( oldnfixedvars < *nfixedvars || oldnaggrvars < *naggrvars || oldndelconss < *ndelconss || oldnchgcoefs < *nchgcoefs )
8254  *result = SCIP_SUCCESS;
8255 
8256  /* remember the number of fixings */
8257  conshdlrdata->noldfixedvars = *nfixedvars + *naggrvars;
8258  }
8259 
8260  if( oldndelconss == *ndelconss && (presoltiming & SCIP_PRESOLTIMING_EXHAUSTIVE) != 0 )
8261  {
8262  /* check constraints for redundancy */
8263  if( conshdlrdata->presolpairwise )
8264  {
8265  SCIP_Longint npaircomparisons = 0;
8266 
8267  oldndelconss = *ndelconss;
8268  oldnfixedvars = *nfixedvars;
8269 
8270  for( c = firstchange; c < nconss && !SCIPisStopped(scip); ++c )
8271  {
8272  assert(*result != SCIP_CUTOFF);
8273 
8274  if( SCIPconsIsActive(conss[c]) && !SCIPconsIsModifiable(conss[c]) )
8275  {
8276  npaircomparisons += (SCIPconsGetData(conss[c])->changed) ? (SCIP_Longint) c : ((SCIP_Longint) c - (SCIP_Longint) firstchange);
8277 
8278  SCIP_CALL( removeRedundantConstraints(scip, conss, firstchange, c, &cutoff, nfixedvars, ndelconss, nchgsides) );
8279  if( cutoff )
8280  {
8281  *result = SCIP_CUTOFF;
8282  return SCIP_OKAY;
8283  }
8284 
8285  if( npaircomparisons > NMINCOMPARISONS )
8286  {
8287  if( (*ndelconss - oldndelconss + *nfixedvars - oldnfixedvars) / ((SCIP_Real)npaircomparisons) < MINGAINPERNMINCOMPARISONS )
8288  break;
8289  oldndelconss = *ndelconss;
8290  oldnfixedvars = *nfixedvars;
8291  npaircomparisons = 0;
8292  *result = SCIP_SUCCESS;
8293  }
8294  }
8295  }
8296  }
8297  }
8298 
8299  /* add cliques after lifting variables */
8300  SCIP_CALL( addCliques(scip, conss, nconss, MIN(firstclique, nconss), MIN(lastclique, nconss), naddconss, ndelconss,
8301  nchgbds, &cutoff) );
8302 
8303  if( cutoff )
8304  *result = SCIP_CUTOFF;
8305 
8306  conshdlrdata->enablecliquelifting = FALSE;
8307  conshdlrdata->noldupgrs = nconss - (*ndelconss - startdelconss);
8308 
8309  return SCIP_OKAY;
8310 }
8311 
8312 
8313 /** propagation conflict resolving method of constraint handler */
8314 static
8315 SCIP_DECL_CONSRESPROP(consRespropSetppc)
8316 { /*lint --e{715}*/
8317  SCIP_CONSDATA* consdata;
8318  int v;
8319 
8320  assert(conshdlr != NULL);
8321  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
8322  assert(cons != NULL);
8323  assert(infervar != NULL);
8324  assert(result != NULL);
8325 
8326  consdata = SCIPconsGetData(cons);
8327  assert(consdata != NULL);
8328 
8329  SCIPdebugMsg(scip, "conflict resolving method of set partitioning / packing / covering constraint handler\n");
8330 
8331  if( (SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_COVERING
8332  || ((SCIP_SETPPCTYPE)consdata->setppctype == SCIP_SETPPCTYPE_PARTITIONING
8333  && SCIPgetVarLbAtIndex(scip, infervar, bdchgidx, TRUE) > 0.5) )
8334  {
8335 #ifndef NDEBUG
8336  SCIP_Bool confvarfound;
8337 #endif
8338 
8339  /* the inference constraint is a set partitioning or covering constraint with the inference variable infered to 1.0:
8340  * the reason for the deduction is the assignment of 0.0 to all other variables
8341  */
8342 #ifndef NDEBUG
8343  confvarfound = FALSE;
8344 #endif
8345  for( v = 0; v < consdata->nvars; ++v )
8346  {
8347  if( consdata->vars[v] != infervar )
8348  {
8349  /* the reason variable must be assigned to zero */
8350  assert(SCIPgetVarUbAtIndex(scip, consdata->vars[v], bdchgidx, FALSE) < 0.5);
8351  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
8352  }
8353 #ifndef NDEBUG
8354  else
8355  {
8356  assert(!confvarfound);
8357  confvarfound = TRUE;
8358  }
8359 #endif
8360  }
8361  assert(confvarfound);
8362  }
8363  else
8364  {
8365  /* the inference constraint is a set partitioning or packing constraint with the inference variable infered to 0.0:
8366  * the reason for the deduction is the assignment of 1.0 to a single variable
8367  */
8368  assert(SCIPgetVarUbAtIndex(scip, infervar, bdchgidx, TRUE) < 0.5);
8369 
8370  if( inferinfo >= 0 )
8371  {
8372  assert(SCIPgetVarLbAtIndex(scip, consdata->vars[inferinfo], bdchgidx, FALSE) > 0.5);
8373  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[inferinfo]) );
8374  }
8375  else
8376  {
8377  for( v = 0; v < consdata->nvars; ++v )
8378  {
8379  if( SCIPgetVarLbAtIndex(scip, consdata->vars[v], bdchgidx, FALSE) > 0.5 )
8380  {
8381  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
8382  break;
8383  }
8384  }
8385  assert(v < consdata->nvars);
8386  }
8387  }
8388 
8389  *result = SCIP_SUCCESS;
8390 
8391  return SCIP_OKAY;
8392 }
8393 
8394 
8395 /** variable rounding lock method of constraint handler */
8396 static
8397 SCIP_DECL_CONSLOCK(consLockSetppc)
8398 { /*lint --e{715}*/
8399  SCIP_CONSDATA* consdata;
8400  int nlocksdown;
8401  int nlocksup;
8402  int i;
8403 
8404  consdata = SCIPconsGetData(cons);
8405  assert(consdata != NULL);
8406 
8407  switch( consdata->setppctype )
8408  {
8410  nlocksdown = nlockspos + nlocksneg;
8411  nlocksup = nlockspos + nlocksneg;
8412  break;
8414  nlocksdown = nlocksneg;
8415  nlocksup = nlockspos;
8416  break;
8418  nlocksdown = nlockspos;
8419  nlocksup = nlocksneg;
8420  break;
8421  default:
8422  SCIPerrorMessage("unknown setppc type\n");
8423  return SCIP_INVALIDDATA;
8424  }
8425 
8426  for( i = 0; i < consdata->nvars; ++i )
8427  {
8428  SCIP_CALL( SCIPaddVarLocksType(scip, consdata->vars[i], locktype, nlocksdown, nlocksup) );
8429  }
8430 
8431  return SCIP_OKAY;
8432 }
8433 
8434 
8435 /** constraint activation notification method of constraint handler */
8436 static
8437 SCIP_DECL_CONSACTIVE(consActiveSetppc)
8438 { /*lint --e{715}*/
8439  assert(cons != NULL);
8440  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
8441  assert(SCIPconsIsTransformed(cons));
8442 
8443  SCIPdebugMsg(scip, "activation information for set partitioning / packing / covering constraint <%s>\n",
8444  SCIPconsGetName(cons));
8446  /* we only might add the constraint to the propagation list, when we are not activating it in probing mode */
8448  {
8449  SCIP_CONSDATA* consdata = SCIPconsGetData(cons);
8450  assert(consdata != NULL);
8451 
8452  if( consdata->nfixedones >= 1 || consdata->nfixedzeros >= consdata->nvars - 1 )
8453  {
8454  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
8455  }
8456  }
8457 
8458 #ifdef VARUSES
8459  /* increase the number of uses for each variable in the constraint */
8460  SCIP_CALL( consdataIncVaruses(scip, SCIPconshdlrGetData(conshdlr), SCIPconsGetData(cons)) );
8461 #endif
8462 
8463  return SCIP_OKAY;
8464 }
8465 
8466 
8467 /** constraint deactivation notification method of constraint handler */
8468 static
8469 SCIP_DECL_CONSDEACTIVE(consDeactiveSetppc)
8470 { /*lint --e{715}*/
8471  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
8472  assert(SCIPconsIsTransformed(cons));
8473 
8474  SCIPdebugMsg(scip, "deactivation information for set partitioning / packing / covering constraint <%s>\n",
8475  SCIPconsGetName(cons));
8476 
8477 #ifdef VARUSES
8478  /* decrease the number of uses for each variable in the constraint */
8479  SCIP_CALL( consdataDecVaruses(scip, SCIPconshdlrGetData(conshdlr), SCIPconsGetData(cons)) );
8480 #endif
8481 
8482  if( SCIPconsIsDeleted(cons) )
8483  {
8484  SCIP_CONSHDLRDATA* conshdlrdata;
8485  SCIP_CONSDATA* consdata;
8486 
8487  /* get constraint data */
8488  consdata = SCIPconsGetData(cons);
8489  assert(consdata != NULL);
8490 
8491  /* get event handler */
8492  conshdlrdata = SCIPconshdlrGetData(conshdlr);
8493  assert(conshdlrdata != NULL);
8494  assert(conshdlrdata->eventhdlr != NULL);
8495 
8496  /* if constraint belongs to transformed problem space, drop bound change events on variables */
8497  if( consdata->nvars > 0 && SCIPvarIsTransformed(consdata->vars[0]) )
8498  {
8499  SCIP_CALL( dropAllEvents(scip, cons, conshdlrdata->eventhdlr) );
8500  }
8501  }
8502 
8503  return SCIP_OKAY;
8504 }
8505 
8506 /** variable deletion method of constraint handler */
8507 static
8508 SCIP_DECL_CONSDELVARS(consDelvarsSetppc)
8509 {
8510  assert( scip != NULL );
8511  assert( conshdlr != NULL );
8512  assert( conss != NULL || nconss == 0 );
8513 
8514  if( nconss > 0 )
8515  {
8516  SCIP_CALL( performVarDeletions(scip, conshdlr, conss, nconss) );
8517  }
8518 
8519  return SCIP_OKAY;
8520 }
8521 
8522 
8523 
8524 /** constraint display method of constraint handler */
8525 static
8526 SCIP_DECL_CONSPRINT(consPrintSetppc)
8527 { /*lint --e{715}*/
8528  assert( scip != NULL );
8529  assert( conshdlr != NULL );
8530  assert( cons != NULL );
8531 
8532  SCIP_CALL( consdataPrint(scip, SCIPconsGetData(cons), file) );
8533 
8534  return SCIP_OKAY;
8535 }
8536 
8537 /** constraint copying method of constraint handler */
8538 static
8539 SCIP_DECL_CONSCOPY(consCopySetppc)
8540 { /*lint --e{715}*/
8541  SCIP_VAR** sourcevars;
8542  const char* consname;
8543  SCIP_Real lhs;
8544  SCIP_Real rhs;
8545  int nvars;
8546  SCIP_SETPPCTYPE type;
8548  /* get variables and coefficients of the source constraint */
8549  sourcevars = SCIPgetVarsSetppc(sourcescip, sourcecons);
8550  nvars = SCIPgetNVarsSetppc(sourcescip, sourcecons);
8551 
8552  /* get setppc type */
8553  type = SCIPgetTypeSetppc(sourcescip, sourcecons);
8554  lhs = -SCIPinfinity(scip);
8555  rhs = SCIPinfinity(scip);
8556 
8557  switch( type )
8558  {
8560  lhs = 1.0;
8561  rhs = 1.0;
8562  break;
8564  rhs = 1.0;
8565  break;
8567  lhs = 1.0;
8568  break;
8569  default:
8570  SCIPerrorMessage("unknown setppc type\n");
8571  return SCIP_INVALIDDATA;
8572  }
8573 
8574  if( name != NULL )
8575  consname = name;
8576  else
8577  consname = SCIPconsGetName(sourcecons);
8578 
8579  /* copy the logic using the linear constraint copy method */
8580  SCIP_CALL( SCIPcopyConsLinear(scip, cons, sourcescip, consname, nvars, sourcevars, NULL,
8581  lhs, rhs, varmap, consmap,
8582  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, global, valid) );
8583  assert(cons != NULL);
8584 
8585  return SCIP_OKAY;
8586 }
8587 
8588 /** constraint parsing method of constraint handler */
8589 static
8590 SCIP_DECL_CONSPARSE(consParseSetppc)
8591 { /*lint --e{715}*/
8592  SCIP_VAR** vars;
8593  int nvars;
8594 
8595  assert(scip != NULL);
8596  assert(success != NULL);
8597  assert(str != NULL);
8598  assert(name != NULL);
8599  assert(cons != NULL);
8600 
8601  *success = TRUE;
8602 
8603  nvars = 0;
8604  vars = NULL;
8605 
8606  /* check if lhs is just 0 */
8607  if( str[0] == '0' )
8608  {
8609  assert(str[1] == ' ');
8610  str += 2;
8611  }
8612  else
8613  {
8614  SCIP_Real* coefs;
8615  char* endptr;
8616  int coefssize;
8617  int requsize;
8618 
8619  /* initialize buffers for storing the coefficients */
8620  coefssize = 100;
8621  SCIP_CALL( SCIPallocBufferArray(scip, &vars, coefssize) );
8622  SCIP_CALL( SCIPallocBufferArray(scip, &coefs, coefssize) );
8623 
8624  /* parse linear sum to get variables and coefficients */
8625  SCIP_CALL( SCIPparseVarsLinearsum(scip, str, vars, coefs, &nvars, coefssize, &requsize, &endptr, success) );
8626 
8627  if( *success && requsize > coefssize )
8628  {
8629  /* realloc buffers and try again */
8630  coefssize = requsize;
8631  SCIP_CALL( SCIPreallocBufferArray(scip, &vars, coefssize) );
8632  SCIP_CALL( SCIPreallocBufferArray(scip, &coefs, coefssize) );
8633 
8634  SCIP_CALL( SCIPparseVarsLinearsum(scip, str, vars, coefs, &nvars, coefssize, &requsize, &endptr, success) );
8635  assert(!*success || requsize <= coefssize); /* if successful, then should have had enough space now */
8636  }
8637 
8638  if( !*success )
8639  {
8640  SCIPerrorMessage("no luck in parsing linear sum '%s'\n", str);
8641  }
8642  else
8643  str = endptr;
8644 
8645  /* free coefficient array */
8646  SCIPfreeBufferArray(scip, &coefs);
8647  }
8648 
8649  /* remove white spaces */
8650  while( isspace((unsigned char)*str) )
8651  str++;
8652 
8653  if( *success )
8654  {
8655  switch( *str )
8656  {
8657  case '=' :
8658  SCIP_CALL( SCIPcreateConsSetpart(scip, cons, name, nvars, vars,
8659  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
8660  break;
8661  case '<' :
8662  SCIP_CALL( SCIPcreateConsSetpack(scip, cons, name, nvars, vars,
8663  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
8664  break;
8665  case '>' :
8666  SCIP_CALL( SCIPcreateConsSetcover(scip, cons, name, nvars, vars,
8667  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
8668  break;
8669  default:
8670  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "error parsing setppc type\n");
8671  *success = FALSE;
8672  break;
8673  }
8674  }
8675 
8676  /* free variable array */
8677  SCIPfreeBufferArrayNull(scip, &vars);
8678 
8679  return SCIP_OKAY;
8680 }
8681 
8682 /** constraint method of constraint handler which returns the variables (if possible) */
8683 static
8684 SCIP_DECL_CONSGETVARS(consGetVarsSetppc)
8685 { /*lint --e{715}*/
8686  SCIP_CONSDATA* consdata;
8687 
8688  consdata = SCIPconsGetData(cons);
8689  assert(consdata != NULL);
8690 
8691  if( varssize < consdata->nvars )
8692  (*success) = FALSE;
8693  else
8694  {
8695  assert(vars != NULL);
8696 
8697  BMScopyMemoryArray(vars, consdata->vars, consdata->nvars);
8698  (*success) = TRUE;
8699  }
8700 
8701  return SCIP_OKAY;
8702 }
8703 
8704 /** constraint method of constraint handler which returns the number of variables (if possible) */
8705 static
8706 SCIP_DECL_CONSGETNVARS(consGetNVarsSetppc)
8707 { /*lint --e{715}*/
8708  SCIP_CONSDATA* consdata;
8709 
8710  consdata = SCIPconsGetData(cons);
8711  assert(consdata != NULL);
8712 
8713  (*nvars) = consdata->nvars;
8714  (*success) = TRUE;
8715 
8716  return SCIP_OKAY;
8717 }
8718 
8719 /*
8720  * Callback methods of event handler
8721  */
8722 
8723 static
8724 SCIP_DECL_EVENTEXEC(eventExecSetppc)
8725 { /*lint --e{715}*/
8726  SCIP_CONS* cons;
8727  SCIP_CONSDATA* consdata;
8728  SCIP_EVENTTYPE eventtype;
8729 
8730  assert(eventhdlr != NULL);
8731  assert(eventdata != NULL);
8732  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
8733  assert(event != NULL);
8734 
8735  /*debugMsg(scip, "Exec method of bound change event handler for set partitioning / packing / covering constraints\n");*/
8736 
8737  cons = (SCIP_CONS*)eventdata;
8738  assert(cons != NULL);
8739 
8740  consdata = SCIPconsGetData(cons);
8741  assert(consdata != NULL);
8742 
8743  eventtype = SCIPeventGetType(event);
8744 
8745  switch( eventtype )
8746  {
8748  consdata->nfixedones++;
8749  break;
8751  consdata->nfixedones--;
8752  break;
8754  consdata->nfixedzeros++;
8755  break;
8757  consdata->nfixedzeros--;
8758  break;
8760  consdata->varsdeleted = TRUE;
8761  break;
8763  if( consdata->merged )
8764  {
8765  SCIP_VAR* var = SCIPeventGetVar(event);
8766 
8767  /* this event should only arise during the presolving stage */
8768  assert(SCIPgetStage(scip) == SCIP_STAGE_PRESOLVING);
8769  assert(var != NULL);
8770 
8771  /* one variable was changed to a negated or aggregated variable, so maybe we can merge again */
8772  if( SCIPvarGetStatus(var) != SCIP_VARSTATUS_FIXED && SCIPvarGetLbGlobal(var) < 0.5 && SCIPvarGetUbGlobal(var) > 0.5 )
8773  consdata->merged = FALSE;
8774  }
8775 
8776  if( !consdata->existmultaggr )
8777  {
8778  SCIP_VAR* var = SCIPeventGetVar(event);
8779  assert(var != NULL);
8780 
8782  consdata->existmultaggr = TRUE;
8783  }
8784  break;
8785  default:
8786  SCIPerrorMessage("invalid event type\n");
8787  return SCIP_INVALIDDATA;
8788  }
8789  assert(0 <= consdata->nfixedzeros && consdata->nfixedzeros <= consdata->nvars);
8790  assert(0 <= consdata->nfixedones && consdata->nfixedones <= consdata->nvars);
8791 
8792  if( eventtype & SCIP_EVENTTYPE_BOUNDTIGHTENED )
8793  {
8794  if( consdata->nfixedones >= 1 || consdata->nfixedzeros >= consdata->nvars - 1 )
8795  {
8796  consdata->presolpropagated = FALSE;
8797  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
8798  }
8799  else if( (SCIPgetStage(scip) < SCIP_STAGE_INITSOLVE) && (consdata->nfixedzeros >= consdata->nvars - 2) )
8800  {
8801  consdata->presolpropagated = FALSE;
8802  }
8803  }
8804 
8805  /*debugMsg(scip, " -> constraint has %d zero-fixed and %d one-fixed of %d variables\n",
8806  consdata->nfixedzeros, consdata->nfixedones, consdata->nvars);*/
8807 
8808  return SCIP_OKAY;
8809 }
8810 
8811 
8812 
8813 
8814 /*
8815  * Callback methods of conflict handler
8816  */
8817 
8818 static
8819 SCIP_DECL_CONFLICTEXEC(conflictExecSetppc)
8820 { /*lint --e{715}*/
8821  SCIP_VAR** vars;
8822  int i;
8823 
8824  assert(conflicthdlr != NULL);
8825  assert(strcmp(SCIPconflicthdlrGetName(conflicthdlr), CONFLICTHDLR_NAME) == 0);
8826  assert(bdchginfos != NULL || nbdchginfos == 0);
8827  assert(result != NULL);
8828 
8829  /* don't process already resolved conflicts */
8830  if( resolved )
8831  {
8832  *result = SCIP_DIDNOTRUN;
8833  return SCIP_OKAY;
8834  }
8835 
8836  *result = SCIP_DIDNOTFIND;
8837 
8838  /* for two (binary) variables we will create a set packing constraint and add the clique information of the conflict is global */
8839  if( nbdchginfos == 2 )
8840  {
8841  SCIP_CONS* cons;
8842  char consname[SCIP_MAXSTRLEN];
8843  SCIP_VAR* twovars[2];
8844 
8845  assert(bdchginfos != NULL);
8846 
8847  twovars[0] = SCIPbdchginfoGetVar(bdchginfos[0]);
8848 
8849  /* we can only treat binary variables */
8850  if( !SCIPvarIsBinary(twovars[0]) )
8851  return SCIP_OKAY;
8852 
8853  /* if the variable is fixed to zero in the conflict set, we have to use its negation */
8854  if( SCIPbdchginfoGetNewbound(bdchginfos[0]) < 0.5 )
8855  {
8856  SCIP_CALL( SCIPgetNegatedVar(scip, twovars[0], &twovars[0]) );
8857  }
8858 
8859  twovars[1] = SCIPbdchginfoGetVar(bdchginfos[1]);
8860 
8861  /* we can only treat binary variables */
8862  if( !SCIPvarIsBinary(twovars[1]) )
8863  return SCIP_OKAY;
8864 
8865  /* if the variable is fixed to zero in the conflict set, we have to use its negation */
8866  if( SCIPbdchginfoGetNewbound(bdchginfos[1]) < 0.5 )
8867  {
8868  SCIP_CALL( SCIPgetNegatedVar(scip, twovars[1], &twovars[1]) );
8869  }
8870 
8871  /* create a constraint out of the conflict set */
8873  SCIP_CALL( SCIPcreateConsSetpack(scip, &cons, consname, 2, twovars,
8874  FALSE, separate, FALSE, FALSE, TRUE, local, FALSE, dynamic, removable, FALSE) );
8875 
8876  /* if the constraint gets globally added, we also add the clique information */
8877  if( !SCIPconsIsLocal(cons) )
8878  {
8879  SCIP_Bool infeasible;
8880  int ncliquebdchgs;
8881 
8882  SCIP_CALL( SCIPaddClique(scip, twovars, NULL, 2, FALSE, &infeasible, &ncliquebdchgs) );
8883 
8884  SCIPdebugMsg(scip, "new clique of conflict constraint %s led to %d fixings\n", consname, ncliquebdchgs);
8885 
8886  if( infeasible )
8887  {
8888  SCIPdebugMsg(scip, "new clique of conflict constraint %s led to infeasibility\n", consname);
8889  }
8890  }
8891 
8892  /* add conflict to SCIP */
8893  SCIP_CALL( SCIPaddConflict(scip, node, cons, validnode, conftype, cutoffinvolved) );
8894 
8895  *result = SCIP_CONSADDED;
8896 
8897  return SCIP_OKAY;
8898  }
8899 
8900  /* create array of variables in conflict constraint */
8901  SCIP_CALL( SCIPallocBufferArray(scip, &vars, nbdchginfos) );
8902  for( i = 0; i < nbdchginfos; ++i )
8903  {
8904  assert(bdchginfos != NULL);
8905 
8906  vars[i] = SCIPbdchginfoGetVar(bdchginfos[i]);
8907 
8908  /* we can only treat binary variables */
8909  if( !SCIPvarIsBinary(vars[i]) )
8910  break;
8911 
8912  /* if the variable is fixed to one in the conflict set, we have to use its negation */
8913  if( SCIPbdchginfoGetNewbound(bdchginfos[i]) > 0.5 )
8914  {
8915  SCIP_CALL( SCIPgetNegatedVar(scip, vars[i], &vars[i]) );
8916  }
8917  }
8918 
8919  if( i == nbdchginfos )
8920  {
8921  SCIP_CONS* cons;
8922  char consname[SCIP_MAXSTRLEN];
8923 
8924  /* create a constraint out of the conflict set */
8926  SCIP_CALL( SCIPcreateConsSetcover(scip, &cons, consname, nbdchginfos, vars,
8927  FALSE, separate, FALSE, FALSE, TRUE, local, FALSE, dynamic, removable, FALSE) );
8928  SCIP_CALL( SCIPaddConsNode(scip, node, cons, validnode) );
8929  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
8930 
8931  *result = SCIP_CONSADDED;
8932  }
8933 
8934  /* free temporary memory */
8935  SCIPfreeBufferArray(scip, &vars);
8936 
8937  return SCIP_OKAY;
8938 }
8939 
8940 
8941 
8942 
8943 /*
8944  * constraint specific interface methods
8945  */
8946 
8947 /** creates the handler for set partitioning / packing / covering constraints and includes it in SCIP */
8949  SCIP* scip /**< SCIP data structure */
8950  )
8951 {
8952  SCIP_CONSHDLRDATA* conshdlrdata;
8953  SCIP_CONSHDLR* conshdlr;
8954  SCIP_EVENTHDLR* eventhdlr;
8955 
8956  /* create event handler for bound change events */
8958  eventExecSetppc, NULL) );
8959 
8960  /* create conflict handler for setppc constraints */
8962  conflictExecSetppc, NULL) );
8963 
8964  /* create constraint handler data */
8965  SCIP_CALL( conshdlrdataCreate(scip, &conshdlrdata, eventhdlr) );
8966 
8967  /* include constraint handler */
8970  consEnfolpSetppc, consEnfopsSetppc, consCheckSetppc, consLockSetppc,
8971  conshdlrdata) );
8972  assert(conshdlr != NULL);
8973 
8974  /* set non-fundamental callbacks via specific setter functions */
8975  SCIP_CALL( SCIPsetConshdlrActive(scip, conshdlr, consActiveSetppc) );
8976  SCIP_CALL( SCIPsetConshdlrDeactive(scip, conshdlr, consDeactiveSetppc) );
8977  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopySetppc, consCopySetppc) );
8978  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteSetppc) );
8979  SCIP_CALL( SCIPsetConshdlrDelvars(scip, conshdlr, consDelvarsSetppc) );
8980  SCIP_CALL( SCIPsetConshdlrExitpre(scip, conshdlr, consExitpreSetppc) );
8981  SCIP_CALL( SCIPsetConshdlrExitsol(scip, conshdlr, consExitsolSetppc) );
8982  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, consFreeSetppc) );
8983  SCIP_CALL( SCIPsetConshdlrGetVars(scip, conshdlr, consGetVarsSetppc) );
8984  SCIP_CALL( SCIPsetConshdlrGetNVars(scip, conshdlr, consGetNVarsSetppc) );
8985  SCIP_CALL( SCIPsetConshdlrInit(scip, conshdlr, consInitSetppc) );
8986  SCIP_CALL( SCIPsetConshdlrInitlp(scip, conshdlr, consInitlpSetppc) );
8987  SCIP_CALL( SCIPsetConshdlrParse(scip, conshdlr, consParseSetppc) );
8988  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolSetppc, CONSHDLR_MAXPREROUNDS, CONSHDLR_PRESOLTIMING) );
8989  SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintSetppc) );
8990  SCIP_CALL( SCIPsetConshdlrProp(scip, conshdlr, consPropSetppc, CONSHDLR_PROPFREQ, CONSHDLR_DELAYPROP,
8992  SCIP_CALL( SCIPsetConshdlrResprop(scip, conshdlr, consRespropSetppc) );
8993  SCIP_CALL( SCIPsetConshdlrSepa(scip, conshdlr, consSepalpSetppc, consSepasolSetppc, CONSHDLR_SEPAFREQ,
8995  SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransSetppc) );
8996  SCIP_CALL( SCIPsetConshdlrEnforelax(scip, conshdlr, consEnforelaxSetppc) );
8997 
8998  conshdlrdata->conshdlrlinear = SCIPfindConshdlr(scip,"linear");
8999 
9000  if( conshdlrdata->conshdlrlinear != NULL )
9001  {
9002  /* include the linear constraint to setppc constraint upgrade in the linear constraint handler */
9004  }
9005  if( SCIPfindConshdlr(scip, "quadratic") != NULL )
9006  {
9007  /* notify function that upgrades quadratic constraint to setpacking */
9009  }
9010 
9011  /* set partitioning constraint handler parameters */
9012  SCIP_CALL( SCIPaddIntParam(scip,
9013  "constraints/" CONSHDLR_NAME "/npseudobranches",
9014  "number of children created in pseudo branching (0: disable pseudo branching)",
9015  &conshdlrdata->npseudobranches, TRUE, DEFAULT_NPSEUDOBRANCHES, 0, INT_MAX, NULL, NULL) );
9017  "constraints/" CONSHDLR_NAME "/presolpairwise",
9018  "should pairwise constraint comparison be performed in presolving?",
9019  &conshdlrdata->presolpairwise, TRUE, DEFAULT_PRESOLPAIRWISE, NULL, NULL) );
9021  "constraints/" CONSHDLR_NAME "/presolusehashing",
9022  "should hash table be used for detecting redundant constraints in advance",
9023  &conshdlrdata->presolusehashing, TRUE, DEFAULT_PRESOLUSEHASHING, NULL, NULL) );
9025  "constraints/" CONSHDLR_NAME "/dualpresolving",
9026  "should dual presolving steps be performed?",
9027  &conshdlrdata->dualpresolving, TRUE, DEFAULT_DUALPRESOLVING, NULL, NULL) );
9029  "constraints/" CONSHDLR_NAME "/cliquelifting",
9030  " should we try to lift variables into other clique constraints, fix variables, aggregate them, and also shrink the amount of variables in clique constraints",
9031  &conshdlrdata->cliquelifting, TRUE, DEFAULT_CLIQUELIFTING, NULL, NULL) );
9033  "constraints/" CONSHDLR_NAME "/addvariablesascliques",
9034  "should we try to generate extra cliques out of all binary variables to maybe fasten redundant constraint detection",
9035  &conshdlrdata->addvariablesascliques, TRUE, DEFAULT_ADDVARIABLESASCLIQUES, NULL, NULL) );
9037  "constraints/" CONSHDLR_NAME "/cliqueshrinking",
9038  "should we try to shrink the number of variables in a clique constraints, by replacing more than one variable by only one",
9039  &conshdlrdata->cliqueshrinking, TRUE, DEFAULT_CLIQUESHRINKING, NULL, NULL) );
9040 
9041  return SCIP_OKAY;
9042 }
9043 
9044 /** creates and captures a set partitioning constraint
9045  *
9046  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
9047  */
9049  SCIP* scip, /**< SCIP data structure */
9050  SCIP_CONS** cons, /**< pointer to hold the created constraint */
9051  const char* name, /**< name of constraint */
9052  int nvars, /**< number of variables in the constraint */
9053  SCIP_VAR** vars, /**< array with variables of constraint entries */
9054  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
9055  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
9056  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
9057  * Usually set to TRUE. */
9058  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
9059  * TRUE for model constraints, FALSE for additional, redundant constraints. */
9060  SCIP_Bool check, /**< should the constraint be checked for feasibility?
9061  * TRUE for model constraints, FALSE for additional, redundant constraints. */
9062  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
9063  * Usually set to TRUE. */
9064  SCIP_Bool local, /**< is constraint only valid locally?
9065  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
9066  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
9067  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
9068  * adds coefficients to this constraint. */
9069  SCIP_Bool dynamic, /**< is constraint subject to aging?
9070  * Usually set to FALSE. Set to TRUE for own cuts which
9071  * are separated as constraints. */
9072  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
9073  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
9074  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
9075  * if it may be moved to a more global node?
9076  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
9077  )
9078 {
9079  return createConsSetppc(scip, cons, name, nvars, vars, SCIP_SETPPCTYPE_PARTITIONING,
9080  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode);
9081 }
9082 
9083 /** creates and captures a set partitioning constraint with all constraint flags set
9084  * to their default values
9085  *
9086  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
9087  */
9089  SCIP* scip, /**< SCIP data structure */
9090  SCIP_CONS** cons, /**< pointer to hold the created constraint */
9091  const char* name, /**< name of constraint */
9092  int nvars, /**< number of variables in the constraint */
9093  SCIP_VAR** vars /**< array with variables of constraint entries */
9094  )
9095 {
9096  SCIP_CALL( SCIPcreateConsSetpart(scip, cons, name, nvars, vars,
9097  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
9098 
9099  return SCIP_OKAY;
9100 }
9101 
9102 /** creates and captures a set packing constraint
9103  *
9104  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
9105  */
9107  SCIP* scip, /**< SCIP data structure */
9108  SCIP_CONS** cons, /**< pointer to hold the created constraint */
9109  const char* name, /**< name of constraint */
9110  int nvars, /**< number of variables in the constraint */
9111  SCIP_VAR** vars, /**< array with variables of constraint entries */
9112  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
9113  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
9114  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
9115  * Usually set to TRUE. */
9116  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
9117  * TRUE for model constraints, FALSE for additional, redundant constraints. */
9118  SCIP_Bool check, /**< should the constraint be checked for feasibility?
9119  * TRUE for model constraints, FALSE for additional, redundant constraints. */
9120  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
9121  * Usually set to TRUE. */
9122  SCIP_Bool local, /**< is constraint only valid locally?
9123  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
9124  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
9125  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
9126  * adds coefficients to this constraint. */
9127  SCIP_Bool dynamic, /**< is constraint subject to aging?
9128  * Usually set to FALSE. Set to TRUE for own cuts which
9129  * are separated as constraints. */
9130  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
9131  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
9132  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
9133  * if it may be moved to a more global node?
9134  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
9135  )
9136 {
9137  return createConsSetppc(scip, cons, name, nvars, vars, SCIP_SETPPCTYPE_PACKING,
9138  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode);
9139 }
9140 
9141 /** creates and captures a set packing constraint with all constraint flags set
9142  * to their default values
9143  *
9144  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
9145  */
9147  SCIP* scip, /**< SCIP data structure */
9148  SCIP_CONS** cons, /**< pointer to hold the created constraint */
9149  const char* name, /**< name of constraint */
9150  int nvars, /**< number of variables in the constraint */
9151  SCIP_VAR** vars /**< array with variables of constraint entries */
9152  )
9153 {
9154  SCIP_CALL( SCIPcreateConsSetpack(scip, cons, name, nvars, vars,
9155  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
9156 
9157  return SCIP_OKAY;
9158 }
9159 
9160 /** creates and captures a set covering constraint
9161  *
9162  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
9163  */
9165  SCIP* scip, /**< SCIP data structure */
9166  SCIP_CONS** cons, /**< pointer to hold the created constraint */
9167  const char* name, /**< name of constraint */
9168  int nvars, /**< number of variables in the constraint */
9169  SCIP_VAR** vars, /**< array with variables of constraint entries */
9170  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
9171  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
9172  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
9173  * Usually set to TRUE. */
9174  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
9175  * TRUE for model constraints, FALSE for additional, redundant constraints. */
9176  SCIP_Bool check, /**< should the constraint be checked for feasibility?
9177  * TRUE for model constraints, FALSE for additional, redundant constraints. */
9178  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
9179  * Usually set to TRUE. */
9180  SCIP_Bool local, /**< is constraint only valid locally?
9181  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
9182  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
9183  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
9184  * adds coefficients to this constraint. */
9185  SCIP_Bool dynamic, /**< is constraint subject to aging?
9186  * Usually set to FALSE. Set to TRUE for own cuts which
9187  * are separated as constraints. */
9188  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
9189  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
9190  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
9191  * if it may be moved to a more global node?
9192  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
9193  )
9194 {
9195  return createConsSetppc(scip, cons, name, nvars, vars, SCIP_SETPPCTYPE_COVERING,
9196  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode);
9197 }
9198 
9199 /** creates and captures a set covering constraint with all constraint flags set
9200  * to their default values
9201  *
9202  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
9203  */
9205  SCIP* scip, /**< SCIP data structure */
9206  SCIP_CONS** cons, /**< pointer to hold the created constraint */
9207  const char* name, /**< name of constraint */
9208  int nvars, /**< number of variables in the constraint */
9209  SCIP_VAR** vars /**< array with variables of constraint entries */
9210  )
9211 {
9212  SCIP_CALL( SCIPcreateConsSetcover(scip, cons, name, nvars, vars,
9213  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
9214 
9215  return SCIP_OKAY;
9216 }
9217 
9218 /** adds coefficient in set partitioning / packing / covering constraint */
9220  SCIP* scip, /**< SCIP data structure */
9221  SCIP_CONS* cons, /**< constraint data */
9222  SCIP_VAR* var /**< variable to add to the constraint */
9223  )
9224 {
9225  assert(var != NULL);
9226 
9227  /*debugMsg(scip, "adding variable <%s> to setppc constraint <%s>\n",
9228  SCIPvarGetName(var), SCIPconsGetName(cons));*/
9229 
9230  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9231  {
9232  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9233  return SCIP_INVALIDDATA;
9234  }
9235 
9236  SCIP_CALL( addCoef(scip, cons, var) );
9237 
9238  return SCIP_OKAY;
9239 }
9240 
9241 /** gets number of variables in set partitioning / packing / covering constraint */
9242 int SCIPgetNVarsSetppc(
9243  SCIP* scip, /**< SCIP data structure */
9244  SCIP_CONS* cons /**< constraint data */
9245  )
9246 {
9247  SCIP_CONSDATA* consdata;
9248 
9249  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9250  {
9251  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9252  SCIPABORT();
9253  return -1; /*lint !e527*/
9254  }
9255 
9256  consdata = SCIPconsGetData(cons);
9257  assert(consdata != NULL);
9258 
9259  return consdata->nvars;
9260 }
9261 
9262 /** gets array of variables in set partitioning / packing / covering constraint */
9264  SCIP* scip, /**< SCIP data structure */
9265  SCIP_CONS* cons /**< constraint data */
9266  )
9267 {
9268  SCIP_CONSDATA* consdata;
9269 
9270  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9271  {
9272  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9273  SCIPABORT();
9274  return NULL; /*lint !e527*/
9275  }
9276 
9277  consdata = SCIPconsGetData(cons);
9278  assert(consdata != NULL);
9279 
9280  return consdata->vars;
9281 }
9282 
9283 /** gets type of set partitioning / packing / covering constraint */
9285  SCIP* scip, /**< SCIP data structure */
9286  SCIP_CONS* cons /**< constraint data */
9287  )
9288 {
9289  SCIP_CONSDATA* consdata;
9290 
9291  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9292  {
9293  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9294  SCIPABORT();
9295  }
9296 
9297  consdata = SCIPconsGetData(cons);
9298  assert(consdata != NULL);
9299 
9300  return (SCIP_SETPPCTYPE)(consdata->setppctype);
9301 }
9302 
9303 /** gets the dual solution of the set partitioning / packing / covering constraint in the current LP */
9305  SCIP* scip, /**< SCIP data structure */
9306  SCIP_CONS* cons /**< constraint data */
9307  )
9308 {
9309  SCIP_CONSDATA* consdata;
9310 
9311  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9312  {
9313  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9314  SCIPABORT();
9315  return SCIP_INVALID; /*lint !e527*/
9316  }
9317 
9318  consdata = SCIPconsGetData(cons);
9319  assert(consdata != NULL);
9320 
9321  if( consdata->row != NULL )
9322  return SCIProwGetDualsol(consdata->row);
9323  else
9324  return 0.0;
9325 }
9326 
9327 /** gets the dual Farkas value of the set partitioning / packing / covering constraint in the current infeasible LP */
9329  SCIP* scip, /**< SCIP data structure */
9330  SCIP_CONS* cons /**< constraint data */
9331  )
9332 {
9333  SCIP_CONSDATA* consdata;
9334 
9335  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9336  {
9337  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9338  SCIPABORT();
9339  return SCIP_INVALID; /*lint !e527*/
9340  }
9341 
9342  consdata = SCIPconsGetData(cons);
9343  assert(consdata != NULL);
9344 
9345  if( consdata->row != NULL )
9346  return SCIProwGetDualfarkas(consdata->row);
9347  else
9348  return 0.0;
9349 }
9350 
9351 /** returns the linear relaxation of the given set partitioning / packing / covering constraint; may return NULL if no
9352  * LP row was yet created; the user must not modify the row!
9353  */
9355  SCIP* scip, /**< SCIP data structure */
9356  SCIP_CONS* cons /**< constraint data */
9357  )
9358 {
9359  SCIP_CONSDATA* consdata;
9360 
9361  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9362  {
9363  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9364  SCIPABORT();
9365  return NULL; /*lint !e527*/
9366  }
9367 
9368  consdata = SCIPconsGetData(cons);
9369  assert(consdata != NULL);
9370 
9371  return consdata->row;
9372 }
9373 
9374 /** returns current number of variables fixed to one in the constraint */
9376  SCIP* scip, /**< SCIP data structure */
9377  SCIP_CONS* cons /**< constraint data */
9378  )
9379 {
9380  SCIP_CONSDATA* consdata;
9381 
9382  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9383  {
9384  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9385  SCIPABORT();
9386  return -1; /*lint !e527*/
9387  }
9388 
9389  consdata = SCIPconsGetData(cons);
9390  assert(consdata != NULL);
9391 
9392  return consdata->nfixedones;
9393 }
9394 
9395 
9396 /** returns current number of variables fixed to zero in the constraint */
9398  SCIP* scip, /**< SCIP data structure */
9399  SCIP_CONS* cons /**< constraint data */
9400  )
9401 {
9402  SCIP_CONSDATA* consdata;
9403 
9404  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
9405  {
9406  SCIPerrorMessage("constraint is not a set partitioning / packing / covering constraint\n");
9407  SCIPABORT();
9408  return -1; /*lint !e527*/
9409  }
9410 
9411  consdata = SCIPconsGetData(cons);
9412  assert(consdata != NULL);
9413 
9414  return consdata->nfixedzeros;
9415 }
9416 
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
#define LINCONSUPGD_PRIORITY
Definition: cons_setppc.c:74
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
Definition: scip_branch.c:384
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
SCIP_RETCODE SCIPaddVarsToRowSameCoef(SCIP *scip, SCIP_ROW *row, int nvars, SCIP_VAR **vars, SCIP_Real val)
Definition: scip_lp.c:1674
void SCIPconshdlrSetData(SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons.c:4221
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2134
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPincConsAge(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1798
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:105
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
Definition: scip_cons.c:640
static SCIP_RETCODE dualPresolving(SCIP *scip, SCIP_CONS *cons, int *nfixedvars, int *ndelconss, SCIP_RESULT *result)
Definition: cons_setppc.c:1268
SCIP_RETCODE SCIPincIntarrayVal(SCIP *scip, SCIP_INTARRAY *intarray, int idx, int incval)
#define NULL
Definition: def.h:239
static SCIP_RETCODE addCliques(SCIP *scip, SCIP_CONS **conss, int nconss, int firstclique, int lastclique, int *naddconss, int *ndelconss, int *nchgbds, SCIP_Bool *cutoff)
Definition: cons_setppc.c:5345
SCIP_Real SCIPfeastol(SCIP *scip)
static SCIP_RETCODE addExtraCliques(SCIP *const scip, SCIP_VAR **const binvars, int const nbinvars, int *const cliquepartition, int const ncliques, SCIP_CONS **const usefulconss, int *const nusefulconss, int const nrounds, int *const nfixedvars, int *const naddconss, int *const ndelconss, int *const nchgcoefs, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:2706
SCIP_Bool SCIPvarsHaveCommonClique(SCIP_VAR *var1, SCIP_Bool value1, SCIP_VAR *var2, SCIP_Bool value2, SCIP_Bool regardimplics)
Definition: var.c:10958
static SCIP_RETCODE analyzeConflictZero(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:2026
SCIP_VAR * var2
SCIP_Real SCIPgetVarUbAtIndex(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx, SCIP_Bool after)
Definition: scip_var.c:2130
int SCIPgetNFixedzerosSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9405
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for SCIP parameter handling
int SCIPvarGetNLocksDownType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3176
static SCIP_DECL_CONSENFORELAX(consEnforelaxSetppc)
Definition: cons_setppc.c:7854
SCIP_RETCODE SCIPaddCoefSetppc(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_setppc.c:9227
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:412
#define SCIP_EVENTTYPE_VARFIXED
Definition: type_event.h:58
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8335
SCIP_RETCODE SCIPsetConshdlrTrans(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSTRANS((*constrans)))
Definition: scip_cons.c:663
SCIP_RETCODE SCIPgetBinvarRepresentative(SCIP *scip, SCIP_VAR *var, SCIP_VAR **repvar, SCIP_Bool *negated)
Definition: scip_var.c:1600
static SCIP_RETCODE addCoef(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_setppc.c:1058
static SCIP_DECL_CONSLOCK(consLockSetppc)
Definition: cons_setppc.c:8405
static SCIP_DECL_CONSPARSE(consParseSetppc)
Definition: cons_setppc.c:8598
SCIP_Real SCIPgetVarLbAtIndex(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx, SCIP_Bool after)
Definition: scip_var.c:1994
SCIP_RETCODE SCIPincludeConshdlrSetppc(SCIP *scip)
Definition: cons_setppc.c:8956
int SCIPgetNFixedonesSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9383
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2265
static SCIP_RETCODE delCoefPos(SCIP *scip, SCIP_CONS *cons, int pos)
Definition: cons_setppc.c:1142
public methods for memory management
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:422
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:954
int SCIPgetNVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9250
SCIP_VAR * SCIPbdchginfoGetVar(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:17945
static SCIP_RETCODE analyzeConflictOne(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:2061
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17343
SCIP_RETCODE SCIPincludeQuadconsUpgrade(SCIP *scip, SCIP_DECL_QUADCONSUPGD((*quadconsupgd)), int priority, SCIP_Bool active, const char *conshdlrname)
SCIP_RETCODE SCIPsetConshdlrGetVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETVARS((*consgetvars)))
Definition: scip_cons.c:893
SCIP_RETCODE SCIPcopyConsLinear(SCIP *scip, SCIP_CONS **cons, SCIP *sourcescip, const char *name, int nvars, SCIP_VAR **sourcevars, SCIP_Real *sourcecoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode, SCIP_Bool global, SCIP_Bool *valid)
static SCIP_RETCODE detectRedundantConstraints(SCIP *scip, BMS_BLKMEM *blkmem, SCIP_CONS **conss, int nconss, int *firstchange, int *ndelconss, int *nchgsides)
Definition: cons_setppc.c:6282
SCIP_RETCODE SCIPvarGetProbvarBinary(SCIP_VAR **var, SCIP_Bool *negated)
Definition: var.c:11789
#define SCIP_MAXSTRLEN
Definition: def.h:260
int SCIPvarGetNLocksUpType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3233
SCIP_VAR * var1
static SCIP_RETCODE collectCliqueData(SCIP *const scip, SCIP_CONS **const usefulconss, int const nusefulconss, SCIP_VAR **const usefulvars, int *const nusefulvars, SCIP_HASHMAP *const vartoindex, int *const varnconss, int *const maxnvarconsidx, int **const varconsidxs, int *const maxnvars)
Definition: cons_setppc.c:2918
public methods for conflict handler plugins and conflict analysis
#define DEFAULT_PRESOLUSEHASHING
Definition: cons_setppc.c:87
static SCIP_DECL_CONSCOPY(consCopySetppc)
Definition: cons_setppc.c:8547
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
Definition: scip_cons.c:385
SCIP_RETCODE SCIPresetConsAge(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1826
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2895
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:210
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1602
#define CONSHDLR_EAGERFREQ
Definition: cons_setppc.c:63
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17399
SCIP_RETCODE SCIPaddConflictBinvar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPcreateConsSetcover(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_setppc.c:9172
SCIP_RETCODE SCIPsetConshdlrDeactive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDEACTIVE((*consdeactive)))
Definition: scip_cons.c:755
SCIP_RETCODE SCIPchgVarLbNode(SCIP *scip, SCIP_NODE *node, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_var.c:4783
SCIP_Bool SCIPconsIsAdded(SCIP_CONS *cons)
Definition: cons.c:8505
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:172
SCIP_RETCODE SCIPgetTransformedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **transvar)
Definition: scip_var.c:1442
SCIP_RETCODE SCIPupdateConsFlags(SCIP *scip, SCIP_CONS *cons0, SCIP_CONS *cons1)
Definition: scip_cons.c:1538
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip_var.c:1251
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16909
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
static SCIP_RETCODE createNormalizedSetppc(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, int mult, SCIP_SETPPCTYPE setppctype, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_setppc.c:6975
#define DEFAULT_ADDVARIABLESASCLIQUES
Definition: cons_setppc.c:109
#define CONSHDLR_PROP_TIMING
Definition: cons_setppc.c:72
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define NLOCKTYPES
Definition: type_var.h:81
static SCIP_DECL_CONSSEPASOL(consSepasolSetppc)
Definition: cons_setppc.c:7492
#define FALSE
Definition: def.h:65
int SCIPconsGetPos(SCIP_CONS *cons)
Definition: cons.c:8086
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2793
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:314
#define DEFAULT_NPSEUDOBRANCHES
Definition: cons_setppc.c:99
SCIP_Real SCIPrelDiff(SCIP_Real val1, SCIP_Real val2)
Definition: misc.c:10325
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
Definition: scip_cons.c:243
SCIP_Real SCIPinfinity(SCIP *scip)
static SCIP_DECL_HASHKEYVAL(hashKeyValSetppccons)
Definition: cons_setppc.c:2675
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10017
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
void SCIPrandomPermuteArray(SCIP_RANDNUMGEN *randnumgen, void **array, int begin, int end)
Definition: misc.c:9443
#define TRUE
Definition: def.h:64
#define SCIPdebug(x)
Definition: pub_message.h:74
SCIP_RETCODE SCIPunmarkConsPropagate(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:2056
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
Definition: cons.c:8355
SCIP_RETCODE SCIPcreateIntarray(SCIP *scip, SCIP_INTARRAY **intarray)
#define SCIP_PRESOLTIMING_EXHAUSTIVE
Definition: type_timing.h:45
static SCIP_DECL_CONSGETVARS(consGetVarsSetppc)
Definition: cons_setppc.c:8692
static SCIP_RETCODE preprocessCliques(SCIP *const scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_CONS **const conss, int const nconss, int const nrounds, int *const firstchange, int *const firstclique, int *const lastclique, int *const nfixedvars, int *const naggrvars, int *const ndelconss, int *const nchgcoefs, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:4901
SCIP_RETCODE SCIPfreeIntarray(SCIP *scip, SCIP_INTARRAY **intarray)
static SCIP_RETCODE enforcePseudo(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *cutoff, SCIP_Bool *infeasible, SCIP_Bool *reduceddom, SCIP_Bool *solvelp)
Definition: cons_setppc.c:2563
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
Definition: cons.c:8385
public methods for problem variables
SCIP_RETCODE SCIPinitConflictAnalysis(SCIP *scip, SCIP_CONFTYPE conftype, SCIP_Bool iscutoffinvolved)
static SCIP_DECL_QUADCONSUPGD(quadraticUpgdSetppc)
Definition: cons_setppc.c:7124
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
SCIP_RETCODE SCIPsetConshdlrSepa(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSSEPALP((*conssepalp)), SCIP_DECL_CONSSEPASOL((*conssepasol)), int sepafreq, int sepapriority, SCIP_Bool delaysepa)
Definition: scip_cons.c:297
SCIP_RETCODE SCIPchgVarUbNode(SCIP *scip, SCIP_NODE *node, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_var.c:4827
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip_mem.h:138
SCIP_Real SCIPgetDualfarkasSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9336
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2931
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:142
Constraint handler for the set partitioning / packing / covering constraints .
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
#define SCIPdebugPrintCons(x, y, z)
Definition: pub_message.h:83
SCIP_Bool SCIPisTransformed(SCIP *scip)
Definition: scip_general.c:611
public methods for SCIP variables
SCIP_RETCODE SCIPsetConshdlrDelvars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELVARS((*consdelvars)))
Definition: scip_cons.c:824
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:17169
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8345
#define SCIP_EVENTTYPE_BOUNDCHANGED
Definition: type_event.h:108
SCIP_RETCODE SCIPsetConshdlrInitlp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITLP((*consinitlp)))
Definition: scip_cons.c:686
SCIP_Real SCIProwGetDualsol(SCIP_ROW *row)
Definition: lp.c:16889
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:203
#define SCIPdebugMsgPrint
Definition: scip_message.h:89
#define SCIPdebugMsg
Definition: scip_message.h:88
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:155
SCIP_RETCODE SCIPgetTransformedVars(SCIP *scip, int nvars, SCIP_VAR **vars, SCIP_VAR **transvars)
Definition: scip_var.c:1483
static SCIP_RETCODE separateCons(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol, SCIP_Bool lpfeas, SCIP_Bool *cutoff, SCIP_Bool *separated, SCIP_Bool *reduceddom)
Definition: cons_setppc.c:2477
static SCIP_RETCODE removeRedundantCons(SCIP *scip, SCIP_CONS *cons0, SCIP_CONS *cons1, int *ndelconss)
Definition: cons_setppc.c:6390
SCIP_RETCODE SCIPsetConshdlrParse(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPARSE((*consparse)))
Definition: scip_cons.c:870
SCIP_Real SCIPgetLhsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE processContainedCons(SCIP *scip, SCIP_CONS *cons0, SCIP_CONS *cons1, SCIP_Bool *cutoff, int *nfixedvars, int *ndelconss, int *nchgsides)
Definition: cons_setppc.c:6488
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:8137
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:279
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2224
SCIP_RETCODE SCIPcreateCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONSHDLR *conshdlr, SCIP_CONSDATA *consdata, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: scip_cons.c:1011
SCIP_RETCODE SCIPparseVarsLinearsum(SCIP *scip, const char *str, SCIP_VAR **vars, SCIP_Real *vals, int *nvars, int varssize, int *requiredsize, char **endptr, SCIP_Bool *success)
Definition: scip_var.c:699
#define CONSHDLR_DELAYSEPA
Definition: cons_setppc.c:67
public methods for numerical tolerances
static SCIP_RETCODE checkForOverlapping(SCIP *const scip, SCIP_CONS *const cons, int const considx, int const endidx, SCIP_CONS **const usefulconss, int const nusefulconss, SCIP_VAR **const usefulvars, int *const nusefulvars, SCIP_HASHMAP *const vartoindex, int *const varnconss, int *const maxnvarconsidx, int **const varconsidxs, int *const countofoverlapping, SCIP_Bool const shrinking, SCIP_Bool *const chgcons, SCIP_VAR **undoneaggrvars, SCIP_Bool *undoneaggrtypes, int *const naggregations, int *const saggregations, int *const nfixedvars, int *const naggrvars, int *const nchgcoefs, int *const ndelconss, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:3480
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:2014
int SCIPgetNQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
#define DEFAULT_CLIQUELIFTING
Definition: cons_setppc.c:102
public methods for querying solving statistics
static SCIP_RETCODE consdataCreate(SCIP *scip, SCIP_CONSDATA **consdata, int nvars, SCIP_VAR **vars, SCIP_SETPPCTYPE setppctype)
Definition: cons_setppc.c:564
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
Definition: var.c:17159
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
Definition: lp.c:17080
#define CONSHDLR_DESC
Definition: cons_setppc.c:57
static SCIP_DECL_CONSEXITSOL(consExitsolSetppc)
Definition: cons_setppc.c:7323
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3025
SCIP_RETCODE SCIPaddVarLocksType(SCIP *scip, SCIP_VAR *var, SCIP_LOCKTYPE locktype, int nlocksdown, int nlocksup)
Definition: scip_var.c:4199
#define SCIP_EVENTTYPE_LBRELAXED
Definition: type_event.h:64
int SCIPgetNBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSPROP(consPropSetppc)
Definition: cons_setppc.c:7977
SCIP_Bool SCIPisConflictAnalysisApplicable(SCIP *scip)
int SCIPgetNFixedVars(SCIP *scip)
Definition: scip_prob.c:2361
static SCIP_DECL_CONSPRINT(consPrintSetppc)
Definition: cons_setppc.c:8534
static SCIP_DECL_CONSRESPROP(consRespropSetppc)
Definition: cons_setppc.c:8323
SCIP_RETCODE SCIPaddClique(SCIP *scip, SCIP_VAR **vars, SCIP_Bool *values, int nvars, SCIP_Bool isequation, SCIP_Bool *infeasible, int *nbdchgs)
Definition: scip_var.c:6819
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17353
static SCIP_RETCODE removeDoubleAndSingletonsAndPerformDualpresolve(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_Bool dualpresolvingenabled, SCIP_Bool linearconshdlrexist, int *nfixedvars, int *naggrvars, int *ndelconss, int *nchgcoefs, int *nchgsides, SCIP_Bool *cutoff)
Definition: cons_setppc.c:5529
SCIP_VAR * SCIPvarGetProbvar(SCIP_VAR *var)
Definition: var.c:11697
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:111
SCIP_RETCODE SCIPmultiaggregateVar(SCIP *scip, SCIP_VAR *var, int naggvars, SCIP_VAR **aggvars, SCIP_Real *scalars, SCIP_Real constant, SCIP_Bool *infeasible, SCIP_Bool *aggregated)
Definition: scip_var.c:8411
public methods for managing constraints
static SCIP_RETCODE fixAdditionalVars(SCIP *scip, SCIP_CONS *cons0, SCIP_CONS *cons1, SCIP_Bool *cutoff, int *nfixedvars)
Definition: cons_setppc.c:6416
#define CONFLICTHDLR_NAME
Definition: cons_setppc.c:80
#define SCIP_PRESOLTIMING_MEDIUM
Definition: type_timing.h:44
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip_cons.c:409
enum SCIP_LockType SCIP_LOCKTYPE
Definition: type_var.h:87
#define SCIPerrorMessage
Definition: pub_message.h:45
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4191
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2822
static SCIP_DECL_CONSPRESOL(consPresolSetppc)
Definition: cons_setppc.c:8041
int SCIPvarCompareActiveAndNegated(SCIP_VAR *var1, SCIP_VAR *var2)
Definition: var.c:11384
SCIP_Real SCIPgetDualsolSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9312
void SCIPsortDownPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
SCIP_RETCODE SCIPdelConsLocal(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:3527
#define DEFAULT_DUALPRESOLVING
Definition: cons_setppc.c:100
public methods for event handler plugins and event handlers
static SCIP_RETCODE addCliqueDataEntry(SCIP *const scip, SCIP_VAR *const addvar, int const considx, SCIP_Bool const maybenew, SCIP_VAR **const usefulvars, int *const nusefulvars, SCIP_HASHMAP *const vartoindex, int *const varnconss, int *const maxnvarconsidx, int **const varconsidxs)
Definition: cons_setppc.c:3068
static SCIP_DECL_HASHGETKEY(hashGetKeySetppccons)
Definition: cons_setppc.c:2624
#define EVENTHDLR_DESC
Definition: cons_setppc.c:78
SCIP_RETCODE SCIPgetChildren(SCIP *scip, SCIP_NODE ***children, int *nchildren)
Definition: scip_tree.c:231
#define MINGAINPERNMINCOMPARISONS
Definition: cons_setppc.c:89
SCIP_RETCODE SCIPaddVarImplication(SCIP *scip, SCIP_VAR *var, SCIP_Bool varfixing, SCIP_VAR *implvar, SCIP_BOUNDTYPE impltype, SCIP_Real implbound, SCIP_Bool *infeasible, int *nbdchgs)
Definition: scip_var.c:6691
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:143
static SCIP_DECL_CONSINIT(consInitSetppc)
Definition: cons_setppc.c:7276
#define CONFLICTHDLR_DESC
Definition: cons_setppc.c:81
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:128
static SCIP_DECL_CONSDELETE(consDeleteSetppc)
Definition: cons_setppc.c:7346
SCIP_RETCODE SCIPunlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip_var.c:4375
SCIP_RETCODE SCIPcreateConsBasicSetpack(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars)
Definition: cons_setppc.c:9154
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:8076
#define CONSHDLR_ENFOPRIORITY
Definition: cons_setppc.c:59
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:8295
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:155
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16729
SCIP_RETCODE SCIPcreateConsSetpart(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_setppc.c:9056
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip_cons.c:434
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2826
constraint handler for quadratic constraints
static int setppcCompare(SCIP_CONS *const cons1, SCIP_CONS *const cons2)
Definition: cons_setppc.c:194
static SCIP_RETCODE consdataCreateTransformed(SCIP *scip, SCIP_CONSDATA **consdata, int nvars, SCIP_VAR **vars, SCIP_SETPPCTYPE setppctype)
Definition: cons_setppc.c:680
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopySetppc)
Definition: cons_setppc.c:7239
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4211
static SCIP_DECL_EVENTEXEC(eventExecSetppc)
Definition: cons_setppc.c:8732
static SCIP_RETCODE multiAggregateBinvar(SCIP *scip, SCIP_Bool linearconshdlrexist, SCIP_VAR **vars, int nvars, int pos, SCIP_Bool *infeasible, SCIP_Bool *aggregated)
Definition: cons_setppc.c:5428
static SCIP_RETCODE dropAllEvents(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr)
Definition: cons_setppc.c:1030
SCIP_RETCODE SCIPmarkConsPropagate(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:2028
static void consdataSort(SCIP_CONSDATA *consdata)
Definition: cons_setppc.c:791
static SCIP_RETCODE consdataEnsureVarsSize(SCIP *scip, SCIP_CONSDATA *consdata, int num)
Definition: cons_setppc.c:540
static SCIP_RETCODE catchEvent(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, int pos)
Definition: cons_setppc.c:896
#define REALABS(x)
Definition: def.h:174
static SCIP_RETCODE dropEvent(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, int pos)
Definition: cons_setppc.c:966
#define CONSHDLR_NAME
Definition: cons_setppc.c:56
#define SCIP_EVENTTYPE_UBRELAXED
Definition: type_event.h:66
SCIP_RETCODE SCIPcreateChild(SCIP *scip, SCIP_NODE **node, SCIP_Real nodeselprio, SCIP_Real estimate)
Definition: scip_branch.c:959
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
SCIP_RETCODE SCIPvarGetAggregatedObj(SCIP_VAR *var, SCIP_Real *aggrobj)
Definition: var.c:17213
#define SCIP_CALL(x)
Definition: def.h:351
#define SCIPhashTwo(a, b)
Definition: pub_misc.h:474
#define SCIP_EVENTTYPE_LBTIGHTENED
Definition: type_event.h:63
static SCIP_RETCODE performVarDeletions(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss)
Definition: cons_setppc.c:6776
SCIP_Longint SCIPgetNTotalNodes(SCIP *scip)
#define SCIPhashSignature64(a)
Definition: pub_misc.h:473
SCIP_RETCODE SCIPgetProbvarLinearSum(SCIP *scip, SCIP_VAR **vars, SCIP_Real *scalars, int *nvars, int varssize, SCIP_Real *constant, int *requiredsize, SCIP_Bool mergemultiples)
Definition: scip_var.c:1740
SCIP_RETCODE SCIPcreateConsBasicSetcover(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars)
Definition: cons_setppc.c:9212
static SCIP_DECL_HASHKEYEQ(hashKeyEqSetppccons)
Definition: cons_setppc.c:2632
void SCIPupdateSolLPConsViolation(SCIP *scip, SCIP_SOL *sol, SCIP_Real absviol, SCIP_Real relviol)
Definition: scip_sol.c:334
int SCIPgetIntarrayVal(SCIP *scip, SCIP_INTARRAY *intarray, int idx)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define CONSHDLR_NEEDSCONS
Definition: cons_setppc.c:69
SCIP_RETCODE SCIPanalyzeConflictCons(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
static SCIP_DECL_CONFLICTEXEC(conflictExecSetppc)
Definition: cons_setppc.c:8827
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:296
Definition: grphload.c:88
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8315
static SCIP_DECL_CONSTRANS(consTransSetppc)
Definition: cons_setppc.c:7382
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:294
SCIP_RETCODE SCIPsetConshdlrResprop(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSRESPROP((*consresprop)))
Definition: scip_cons.c:709
static SCIP_DECL_SORTPTRCOMP(setppcConssSort)
Definition: cons_setppc.c:234
struct SCIP_ConsData SCIP_CONSDATA
Definition: type_cons.h:51
SCIP_BILINTERM * SCIPgetBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPgetPseudoBranchCands(SCIP *scip, SCIP_VAR ***pseudocands, int *npseudocands, int *npriopseudocands)
Definition: scip_branch.c:722
#define SCIP_EVENTTYPE_BOUNDTIGHTENED
Definition: type_event.h:106
#define CONSHDLR_CHECKPRIORITY
Definition: cons_setppc.c:60
static SCIP_RETCODE processFixings(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *cutoff, int *nfixedvars, SCIP_Bool *addcut, SCIP_Bool *mustcheck)
Definition: cons_setppc.c:2101
#define DEFAULT_CLIQUESHRINKING
Definition: cons_setppc.c:114
#define DEFAULT_PRESOLPAIRWISE
Definition: cons_setppc.c:84
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:141
static SCIP_RETCODE lockRounding(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_setppc.c:307
static SCIP_DECL_CONSDEACTIVE(consDeactiveSetppc)
Definition: cons_setppc.c:8477
public methods for constraint handler plugins and constraints
SCIP_RETCODE SCIPaddConsNode(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode)
Definition: scip_prob.c:3376
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
SCIP_Real SCIPgetRhsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_Bool checkCons(SCIP *scip, SCIP_CONSDATA *consdata, SCIP_SOL *sol)
Definition: cons_setppc.c:2337
SCIP_RETCODE SCIPcreateConsSetpack(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_setppc.c:9114
#define CONFLICTHDLR_PRIORITY
Definition: cons_setppc.c:82
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:130
static SCIP_RETCODE catchAllEvents(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr)
Definition: cons_setppc.c:1002
public data structures and miscellaneous methods
SCIP_VAR * SCIPeventGetVar(SCIP_EVENT *event)
Definition: event.c:1018
#define SCIP_Bool
Definition: def.h:62
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2179
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:995
#define CONSHDLR_PRESOLTIMING
Definition: cons_setppc.c:71
#define NMINCOMPARISONS
Definition: cons_setppc.c:88
SCIP_RETCODE SCIPcreateEmptyRowCons(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip_lp.c:1336
#define EVENTHDLR_NAME
Definition: cons_setppc.c:77
SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9292
static SCIP_DECL_CONSACTIVE(consActiveSetppc)
Definition: cons_setppc.c:8445
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip_cons.c:2550
#define CONSHDLR_MAXPREROUNDS
Definition: cons_setppc.c:66
static SCIP_RETCODE setSetppcType(SCIP *scip, SCIP_CONS *cons, SCIP_SETPPCTYPE setppctype)
Definition: cons_setppc.c:823
SCIP_RETCODE SCIPcalcCliquePartition(SCIP *const scip, SCIP_VAR **const vars, int const nvars, int *const cliquepartition, int *const ncliques)
Definition: scip_var.c:7154
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:8096
int SCIPvarCompare(SCIP_VAR *var1, SCIP_VAR *var2)
Definition: var.c:11422
#define MIN(x, y)
Definition: def.h:209
static SCIP_DECL_CONSFREE(consFreeSetppc)
Definition: cons_setppc.c:7255
public methods for LP management
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
Definition: cons.c:8205
public methods for cuts and aggregation rows
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8275
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8245
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17191
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:468
SCIP_Real SCIPbdchginfoGetNewbound(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:17935
SCIP_RETCODE SCIPsetIntarrayVal(SCIP *scip, SCIP_INTARRAY *intarray, int idx, int val)
SCIP_Real SCIPcalcNodeselPriority(SCIP *scip, SCIP_VAR *var, SCIP_BRANCHDIR branchdir, SCIP_Real targetvalue)
Definition: scip_branch.c:909
SCIP_ROW * SCIPgetRowSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9362
static SCIP_DECL_CONSENFOPS(consEnfopsSetppc)
Definition: cons_setppc.c:7864
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8168
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:116
int SCIPgetNRuns(SCIP *scip)
SCIP_Real SCIProwGetDualfarkas(SCIP_ROW *row)
Definition: lp.c:16902
SCIP_RETCODE SCIPlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip_var.c:4290
static SCIP_RETCODE removeRedundantConstraints(SCIP *scip, SCIP_CONS **conss, int firstchange, int chkind, SCIP_Bool *cutoff, int *nfixedvars, int *ndelconss, int *nchgsides)
Definition: cons_setppc.c:6604
static SCIP_RETCODE consdataPrint(SCIP *scip, SCIP_CONSDATA *consdata, FILE *file)
Definition: cons_setppc.c:733
SCIP_RETCODE SCIPsetConshdlrPrint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRINT((*consprint)))
Definition: scip_cons.c:847
#define SCIP_EVENTTYPE_UBTIGHTENED
Definition: type_event.h:65
Constraint handler for linear constraints in their most general form, .
SCIP_Longint SCIPgetNConflictConssApplied(SCIP *scip)
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
Definition: misc.c:2326
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
static SCIP_RETCODE collectCliqueConss(SCIP *const scip, SCIP_CONS **const conss, int const nconss, SCIP_CONS **const usefulconss, int *const nusefulconss, int *const nfixedvars, int *const ndelconss, int *const nchgcoefs, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:2826
static uint64_t consdataGetSignature(SCIP_CONSDATA *consdata)
Definition: cons_setppc.c:770
SCIP_Real SCIPcalcChildEstimate(SCIP *scip, SCIP_VAR *var, SCIP_Real targetvalue)
Definition: scip_branch.c:936
static SCIP_RETCODE conshdlrdataCreate(SCIP *scip, SCIP_CONSHDLRDATA **conshdlrdata, SCIP_EVENTHDLR *eventhdlr)
Definition: cons_setppc.c:371
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2089
SCIP_Bool SCIPinProbing(SCIP *scip)
Definition: scip_probing.c:152
public methods for the LP relaxation, rows and columns
SCIP_VAR ** SCIPgetVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9271
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:2064
SCIP_RETCODE SCIPincludeLinconsUpgrade(SCIP *scip, SCIP_DECL_LINCONSUPGD((*linconsupgd)), int priority, const char *conshdlrname)
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2044
static SCIP_RETCODE unlockRounding(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_setppc.c:339
SCIP_RETCODE SCIPwriteVarsLinearsum(SCIP *scip, FILE *file, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Bool type)
Definition: scip_var.c:333
static SCIP_RETCODE createConsSetppc(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_SETPPCTYPE setppctype, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_setppc.c:6890
methods for sorting joint arrays of various types
SCIP_Bool SCIPconsIsLockedType(SCIP_CONS *cons, SCIP_LOCKTYPE locktype)
Definition: cons.c:8469
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define SCIP_LONGINT_FORMAT
Definition: def.h:142
SCIP_RETCODE SCIPsetConshdlrExitpre(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITPRE((*consexitpre)))
Definition: scip_cons.c:578
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1474
int SCIPgetNLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
public methods for managing events
SCIP_RETCODE SCIPhashmapRemove(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3041
general public methods
#define HASHSIZE_SETPPCCONS
Definition: cons_setppc.c:86
#define MAX(x, y)
Definition: def.h:208
enum SCIP_SetppcType SCIP_SETPPCTYPE
Definition: cons_setppc.h:82
static SCIP_RETCODE mergeMultiples(SCIP *scip, SCIP_CONS *cons, int *nfixedvars, int *ndelconss, int *nchgcoefs, SCIP_Bool *cutoff)
Definition: cons_setppc.c:1569
static SCIP_DECL_LINCONSUPGD(linconsUpgdSetppc)
Definition: cons_setppc.c:7043
public methods for solutions
static const SCIP_Real scalars[]
Definition: lp.c:5650
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
Definition: cons.c:8106
public methods for random numbers
SCIP_RETCODE SCIPsetConshdlrInit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINIT((*consinit)))
Definition: scip_cons.c:458
static SCIP_DECL_CONSEXITPRE(consExitpreSetppc)
Definition: cons_setppc.c:7302
public methods for conflict analysis handlers
#define DEFAULT_RANDSEED
Definition: cons_setppc.c:91
SCIP_Bool SCIPisConsCompressionEnabled(SCIP *scip)
Definition: scip_copy.c:687
public methods for the probing mode
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1187
static SCIP_RETCODE presolvePropagateCons(SCIP *const scip, SCIP_CONS *const cons, SCIP_Bool const aggregate, SCIP_VAR **undoneaggrvars, SCIP_Bool *undoneaggrtypes, int *const naggregations, int *const saggregations, int *const nfixedvars, int *const naggrvars, int *const ndelconss, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:3137
static int setppcCompare2(SCIP_CONS *const cons1, SCIP_CONS *const cons2)
Definition: cons_setppc.c:250
SCIP_Bool SCIPallowDualReds(SCIP *scip)
Definition: scip_var.c:8478
SCIP_RETCODE SCIPincludeConflicthdlrBasic(SCIP *scip, SCIP_CONFLICTHDLR **conflicthdlrptr, const char *name, const char *desc, int priority, SCIP_DECL_CONFLICTEXEC((*conflictexec)), SCIP_CONFLICTHDLRDATA *conflicthdlrdata)
const char * SCIPconflicthdlrGetName(SCIP_CONFLICTHDLR *conflicthdlr)
Definition: conflict.c:761
SCIP_RETCODE SCIPsetConshdlrPresol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRESOL((*conspresol)), int maxprerounds, SCIP_PRESOLTIMING presoltiming)
Definition: scip_cons.c:602
public methods for message output
int SCIPgetNCliques(SCIP *scip)
Definition: scip_var.c:7473
SCIP_VAR * a
Definition: circlepacking.c:57
int SCIPgetNImplications(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1999
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16848
SCIP_RETCODE SCIPaggregateVars(SCIP *scip, SCIP_VAR *varx, SCIP_VAR *vary, SCIP_Real scalarx, SCIP_Real scalary, SCIP_Real rhs, SCIP_Bool *infeasible, SCIP_Bool *redundant, SCIP_Bool *aggregated)
Definition: scip_var.c:8277
SCIP_RETCODE SCIPcaptureVar(SCIP *scip, SCIP_VAR *var)
Definition: scip_var.c:1217
#define SCIP_Real
Definition: def.h:150
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8325
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:739
SCIP_RETCODE SCIPsetConshdlrGetNVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETNVARS((*consgetnvars)))
Definition: scip_cons.c:916
SCIP_Bool SCIPhaveVarsCommonClique(SCIP *scip, SCIP_VAR *var1, SCIP_Bool value1, SCIP_VAR *var2, SCIP_Bool value2, SCIP_Bool regardimplics)
Definition: scip_var.c:7557
static SCIP_RETCODE addCut(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *cutoff)
Definition: cons_setppc.c:2444
static SCIP_RETCODE conshdlrdataFree(SCIP *scip, SCIP_CONSHDLRDATA **conshdlrdata)
Definition: cons_setppc.c:400
static SCIP_DECL_CONSGETNVARS(consGetNVarsSetppc)
Definition: cons_setppc.c:8714
public methods for message handling
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8265
SCIP_Bool SCIPdoNotAggr(SCIP *scip)
Definition: scip_var.c:8441
#define SCIP_INVALID
Definition: def.h:170
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8255
#define SCIP_Longint
Definition: def.h:135
static SCIP_DECL_CONSSEPALP(consSepalpSetppc)
Definition: cons_setppc.c:7449
int SCIPvarGetIndex(SCIP_VAR *var)
Definition: var.c:17026
SCIP_Real SCIPgetRowSolFeasibility(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
Definition: scip_lp.c:2068
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16894
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPdoNotMultaggr(SCIP *scip)
Definition: scip_var.c:8451
static SCIP_DECL_CONSENFOLP(consEnfolpSetppc)
Definition: cons_setppc.c:7844
#define CONSHDLR_PROPFREQ
Definition: cons_setppc.c:62
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
Definition: type_cons.h:50
static void deleteCliqueDataEntry(SCIP_VAR *const var, int const considx, SCIP_HASHMAP *const vartoindex, int *const varnconss, int **const varconsidxs)
Definition: cons_setppc.c:3026
SCIP_Real SCIPgetVarSol(SCIP *scip, SCIP_VAR *var)
Definition: scip_var.c:2309
static SCIP_RETCODE performAggregations(SCIP *const scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR **const undoneaggrvars, SCIP_Bool *const undoneaggrtypes, int const naggregations, int *const naggrvars, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:4820
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17409
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
Definition: scip_mem.h:117
static SCIP_RETCODE liftCliqueVariables(SCIP *const scip, SCIP_CONS *const cons, int const arraypos, SCIP_VAR **const usefulvars, int *const nusefulvars, int const endidx, SCIP_Bool **cliquevalues, SCIP_HASHMAP *const vartoindex, int *const varnconss, int *const maxnvarconsidx, int **const varconsidxs, int *const maxnvars, int *const nadded, SCIP_Bool *const chgcons, int *const nfixedvars, int *const ndelconss, SCIP_Bool *const cutoff)
Definition: cons_setppc.c:4346
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
Definition: var.c:16871
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:2874
static SCIP_RETCODE consdataFree(SCIP *scip, SCIP_CONSDATA **consdata)
Definition: cons_setppc.c:702
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:112
static SCIP_RETCODE createRow(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:2402
#define CONSHDLR_DELAYPROP
Definition: cons_setppc.c:68
SCIP_RETCODE SCIPsetConshdlrActive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSACTIVE((*consactive)))
Definition: scip_cons.c:732
SCIP_QUADVARTERM * SCIPgetQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSDELVARS(consDelvarsSetppc)
Definition: cons_setppc.c:8516
SCIP_RETCODE SCIPcreateConsBasicSetpart(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars)
Definition: cons_setppc.c:9096
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:419
SCIP_RETCODE SCIPaddConflict(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode, SCIP_CONFTYPE conftype, SCIP_Bool iscutoffinvolved)
Definition: scip_prob.c:3280
SCIP_RETCODE SCIPsetConshdlrExitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITSOL((*consexitsol)))
Definition: scip_cons.c:530
#define SCIPcombineTwoInt(a, b)
Definition: pub_misc.h:480
#define SCIPABORT()
Definition: def.h:323
public methods for global and local (sub)problems
#define CONSHDLR_SEPAPRIORITY
Definition: cons_setppc.c:58
static SCIP_RETCODE enforceConstraint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, int nusefulconss, SCIP_SOL *sol, SCIP_RESULT *result)
Definition: cons_setppc.c:6818
#define QUADCONSUPGD_PRIORITY
Definition: cons_setppc.c:75
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1410
SCIP_Bool SCIPvarIsDeleted(SCIP_VAR *var)
Definition: var.c:16950
SCIP_RETCODE SCIPinferBinvarCons(SCIP *scip, SCIP_VAR *var, SCIP_Bool fixedval, SCIP_CONS *infercons, int inferinfo, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip_var.c:5636
void SCIPsortedvecInsertDownPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), void *keyval, int *len, int *pos)
static SCIP_DECL_CONSINITLP(consInitlpSetppc)
Definition: cons_setppc.c:7431
#define ABS(x)
Definition: def.h:204
SCIP_Bool SCIPsortedvecFindDownPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), void *val, int len, int *pos)
#define SCIP_EVENTTYPE_VARDELETED
Definition: type_event.h:57
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip_var.c:1530
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:129
static SCIP_RETCODE applyFixings(SCIP *scip, SCIP_CONS *cons, int *naddconss, int *ndelconss, int *nfixedvars, SCIP_Bool *cutoff)
Definition: cons_setppc.c:1713
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:17016
#define CONSHDLR_SEPAFREQ
Definition: cons_setppc.c:61
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:16884
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:134
uint64_t SCIP_EVENTTYPE
Definition: type_event.h:134
static SCIP_DECL_CONSCHECK(consCheckSetppc)
Definition: cons_setppc.c:7926
SCIP_RETCODE SCIPsetConshdlrProp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPROP((*consprop)), int propfreq, SCIP_Bool delayprop, SCIP_PROPTIMING proptiming)
Definition: scip_cons.c:343
memory allocation routines