Scippy

SCIP

Solving Constraint Integer Programs

cons_logicor.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 2002-2022 Zuse Institute Berlin */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file cons_logicor.c
26  * @ingroup DEFPLUGINS_CONS
27  * @brief Constraint handler for logic or constraints \f$1^T x \ge 1\f$
28  * (equivalent to set covering, but algorithms are suited for depth first search).
29  * @author Tobias Achterberg
30  * @author Michael Winkler
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include "blockmemshell/memory.h"
36 #include "scip/cons_linear.h"
37 #include "scip/cons_logicor.h"
38 #include "scip/cons_setppc.h"
39 #include "scip/presolve.h"
40 #include "scip/pub_conflict.h"
41 #include "scip/pub_cons.h"
42 #include "scip/pub_event.h"
43 #include "scip/pub_lp.h"
44 #include "scip/pub_message.h"
45 #include "scip/pub_misc.h"
46 #include "scip/pub_misc_sort.h"
47 #include "scip/pub_var.h"
48 #include "scip/scip_conflict.h"
49 #include "scip/scip_cons.h"
50 #include "scip/scip_cut.h"
51 #include "scip/scip_event.h"
52 #include "scip/scip_general.h"
53 #include "scip/scip_lp.h"
54 #include "scip/scip_mem.h"
55 #include "scip/scip_message.h"
56 #include "scip/scip_nlp.h"
57 #include "scip/scip_numerics.h"
58 #include "scip/scip_param.h"
59 #include "scip/scip_prob.h"
60 #include "scip/scip_probing.h"
61 #include "scip/scip_sol.h"
62 #include "scip/scip_solvingstats.h"
63 #include "scip/scip_tree.h"
64 #include "scip/scip_var.h"
65 #include <string.h>
66 
67 
68 #define CONSHDLR_NAME "logicor"
69 #define CONSHDLR_DESC "logic or constraints"
70 #define CONSHDLR_SEPAPRIORITY +10000 /**< priority of the constraint handler for separation */
71 #define CONSHDLR_ENFOPRIORITY -2000000 /**< priority of the constraint handler for constraint enforcing */
72 #define CONSHDLR_CHECKPRIORITY -2000000 /**< priority of the constraint handler for checking feasibility */
73 #define CONSHDLR_SEPAFREQ 0 /**< frequency for separating cuts; zero means to separate only in the root node */
74 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
75 #define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
76  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
77 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
78 #define CONSHDLR_DELAYSEPA FALSE /**< should separation method be delayed, if other separators found cuts? */
79 #define CONSHDLR_DELAYPROP FALSE /**< should propagation method be delayed, if other propagators found reductions? */
80 #define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
81 
82 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_ALWAYS
83 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP
84 
85 #define LINCONSUPGD_PRIORITY +800000 /**< priority of the constraint handler for upgrading of linear constraints */
86 
87 #define EVENTHDLR_NAME "logicor"
88 #define EVENTHDLR_DESC "event handler for logic or constraints"
89 
90 #define CONFLICTHDLR_NAME "logicor"
91 #define CONFLICTHDLR_DESC "conflict handler creating logic or constraints"
92 #define CONFLICTHDLR_PRIORITY LINCONSUPGD_PRIORITY
93 
94 #define DEFAULT_PRESOLPAIRWISE TRUE /**< should pairwise constraint comparison be performed in presolving? */
95 #define DEFAULT_STRENGTHEN TRUE /**< should pairwise constraint comparison try to strengthen constraints by removing superflous non-zeros? */
96 
97 #define HASHSIZE_LOGICORCONS 500 /**< minimal size of hash table in logicor constraint tables */
98 #define DEFAULT_PRESOLUSEHASHING TRUE /**< should hash table be used for detecting redundant constraints in advance */
99 #define DEFAULT_DUALPRESOLVING TRUE /**< should dual presolving steps be performed? */
100 #define DEFAULT_NEGATEDCLIQUE TRUE /**< should negated clique information be used in presolving */
101 #define DEFAULT_IMPLICATIONS TRUE /**< should we try to shrink the variables and derive global boundchanges by
102  * using cliques and implications */
103 
104 /* @todo make this a parameter setting */
105 #if 1 /* @todo test which AGEINCREASE formula is better! */
106 #define AGEINCREASE(n) (1.0 + 0.2 * (n))
107 #else
108 #define AGEINCREASE(n) (0.1 * (n))
109 #endif
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 events on watched variables */
122  SCIP_CONSHDLR* conshdlrlinear; /**< pointer to linear constraint handler or NULL if not included */
123  SCIP_CONSHDLR* conshdlrsetppc; /**< pointer to setppc constraint handler or NULL if not included */
124  SCIP_Bool presolpairwise; /**< should pairwise constraint comparison be performed in presolving? */
125  SCIP_Bool presolusehashing; /**< should hash table be used for detecting redundant constraints in
126  * advance */
127  SCIP_Bool dualpresolving; /**< should dual presolving steps be performed? */
128  SCIP_Bool usenegatedclique; /**< should negated clique information be used in presolving */
129  SCIP_Bool useimplications; /**< should we try to shrink the variables and derive global boundchanges
130  * by using clique and implications */
131  SCIP_Bool usestrengthening; /**< should pairwise constraint comparison try to strengthen constraints by
132  * removing superflous non-zeros? */
133  int nlastcliquesneg; /**< number of cliques after last negated clique presolving round */
134  int nlastimplsneg; /**< number of implications after last negated clique presolving round */
135  int nlastcliquesshorten;/**< number of cliques after last shortening of constraints */
136  int nlastimplsshorten; /**< number of implications after last shortening of constraints */
137 };
138 
139 /* @todo it might speed up exit-presolve to remember all positions for variables when catching the varfixed event, or we
140  * change catching and dropping the events like it is done in cons_setppc, which probably makes the code more
141  * clear
142  */
143 
144 /** logic or constraint data */
145 struct SCIP_ConsData
146 {
147  SCIP_ROW* row; /**< LP row, if constraint is already stored in LP row format */
148  SCIP_NLROW* nlrow; /**< NLP row, if constraint has been added to NLP relaxation */
149  SCIP_VAR** vars; /**< variables of the constraint */
150  int varssize; /**< size of vars array */
151  int nvars; /**< number of variables in the constraint */
152  int watchedvar1; /**< position of the first watched variable */
153  int watchedvar2; /**< position of the second watched variable */
154  int filterpos1; /**< event filter position of first watched variable */
155  int filterpos2; /**< event filter position of second watched variable */
156  unsigned int signature; /**< constraint signature which is need for pairwise comparison */
157  unsigned int presolved:1; /**< flag indicates if we have some fixed, aggregated or multi-aggregated
158  * variables
159  */
160  unsigned int impladded:1; /**< was the 2-variable logic or constraint already added as implication? */
161  unsigned int sorted:1; /**< are the constraint's variables sorted? */
162  unsigned int changed:1; /**< was constraint changed since last redundancy round in preprocessing? */
163  unsigned int merged:1; /**< are the constraint's equal/negated variables already merged? */
164  unsigned int existmultaggr:1; /**< does this constraint contain aggregations */
165  unsigned int validsignature:1; /**< is the signature valid */
166 };
167 
168 
169 /*
170  * Local methods
171  */
172 
173 /** installs rounding locks for the given variable in the given logic or constraint */
174 static
176  SCIP* scip, /**< SCIP data structure */
177  SCIP_CONS* cons, /**< logic or constraint */
178  SCIP_VAR* var /**< variable of constraint entry */
179  )
180 {
181  SCIP_CALL( SCIPlockVarCons(scip, var, cons, TRUE, FALSE) );
182 
183  return SCIP_OKAY;
184 }
185 
186 /** removes rounding locks for the given variable in the given logic or constraint */
187 static
189  SCIP* scip, /**< SCIP data structure */
190  SCIP_CONS* cons, /**< logic or constraint */
191  SCIP_VAR* var /**< variable of constraint entry */
192  )
193 {
194  SCIP_CALL( SCIPunlockVarCons(scip, var, cons, TRUE, FALSE) );
195 
196  return SCIP_OKAY;
197 }
198 
199 /** creates constraint handler data for logic or constraint handler */
200 static
202  SCIP* scip, /**< SCIP data structure */
203  SCIP_CONSHDLRDATA** conshdlrdata, /**< pointer to store the constraint handler data */
204  SCIP_EVENTHDLR* eventhdlr /**< event handler */
205  )
206 {
207  assert(scip != NULL);
208  assert(conshdlrdata != NULL);
209  assert(eventhdlr != NULL);
210 
211  SCIP_CALL( SCIPallocBlockMemory(scip, conshdlrdata) );
212 
213  (*conshdlrdata)->nlastcliquesneg = 0;
214  (*conshdlrdata)->nlastimplsneg = 0;
215  (*conshdlrdata)->nlastcliquesshorten = 0;
216  (*conshdlrdata)->nlastimplsshorten = 0;
217 
218  /* set event handler for catching events on watched variables */
219  (*conshdlrdata)->eventhdlr = eventhdlr;
220 
221  return SCIP_OKAY;
222 }
223 
224 /** frees constraint handler data for logic or constraint handler */
225 static
226 void conshdlrdataFree(
227  SCIP* scip, /**< SCIP data structure */
228  SCIP_CONSHDLRDATA** conshdlrdata /**< pointer to the constraint handler data */
229  )
230 {
231  assert(conshdlrdata != NULL);
232  assert(*conshdlrdata != NULL);
233 
234  SCIPfreeBlockMemory(scip, conshdlrdata);
235 }
236 
237 /** ensures, that the vars array can store at least num entries */
238 static
240  SCIP* scip, /**< SCIP data structure */
241  SCIP_CONSDATA* consdata, /**< logicor constraint data */
242  int num /**< minimum number of entries to store */
243  )
244 {
245  assert(consdata != NULL);
246  assert(consdata->nvars <= consdata->varssize);
247 
248  if( num > consdata->varssize )
249  {
250  int newsize;
251 
252  newsize = SCIPcalcMemGrowSize(scip, num);
253  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &consdata->vars, consdata->varssize, newsize) );
254  consdata->varssize = newsize;
255  }
256  assert(num <= consdata->varssize);
257 
258  return SCIP_OKAY;
259 }
260 
261 /** creates a logic or constraint data object */
262 static
264  SCIP* scip, /**< SCIP data structure */
265  SCIP_CONSDATA** consdata, /**< pointer to store the logic or constraint data */
266  int nvars, /**< number of variables in the constraint */
267  SCIP_VAR** vars /**< variables of the constraint */
268  )
269 {
270  int v;
271 
272  assert(consdata != NULL);
273  assert(nvars == 0 || vars != NULL);
274 
275  SCIP_CALL( SCIPallocBlockMemory(scip, consdata) );
276 
277  (*consdata)->row = NULL;
278  (*consdata)->nlrow = NULL;
279  if( nvars > 0 )
280  {
281  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->vars, vars, nvars) );
282  (*consdata)->varssize = nvars;
283  (*consdata)->nvars = nvars;
284  }
285  else
286  {
287  (*consdata)->vars = NULL;
288  (*consdata)->varssize = 0;
289  (*consdata)->nvars = 0;
290  }
291  (*consdata)->watchedvar1 = -1;
292  (*consdata)->watchedvar2 = -1;
293  (*consdata)->filterpos1 = -1;
294  (*consdata)->filterpos2 = -1;
295  (*consdata)->presolved = FALSE;
296  (*consdata)->impladded = FALSE;
297  (*consdata)->changed = TRUE;
298  (*consdata)->sorted = (nvars <= 1);
299  (*consdata)->merged = (nvars <= 1);
300  (*consdata)->existmultaggr = FALSE;
301  (*consdata)->validsignature = FALSE;
302 
303  /* get transformed variables, if we are in the transformed problem */
304  if( SCIPisTransformed(scip) )
305  {
306  SCIP_CALL( SCIPgetTransformedVars(scip, (*consdata)->nvars, (*consdata)->vars, (*consdata)->vars) );
307 
308  /* check for multi-aggregations and capture variables */
309  for( v = 0; v < (*consdata)->nvars; v++ )
310  {
311  SCIP_VAR* var = SCIPvarGetProbvar((*consdata)->vars[v]);
312  assert(var != NULL);
313  (*consdata)->existmultaggr = (*consdata)->existmultaggr || (SCIPvarGetStatus(var) == SCIP_VARSTATUS_MULTAGGR);
314  SCIP_CALL( SCIPcaptureVar(scip, (*consdata)->vars[v]) );
315  }
316  }
317  else
318  {
319  /* capture variables */
320  for( v = 0; v < (*consdata)->nvars; v++ )
321  {
322  assert((*consdata)->vars[v] != NULL);
323  SCIP_CALL( SCIPcaptureVar(scip, (*consdata)->vars[v]) );
324  }
325  }
326 
327  return SCIP_OKAY;
328 }
329 
330 /** frees a logic or constraint data */
331 static
333  SCIP* scip, /**< SCIP data structure */
334  SCIP_CONSDATA** consdata /**< pointer to the logic or constraint */
335  )
336 {
337  int v;
338 
339  assert(consdata != NULL);
340  assert(*consdata != NULL);
341 
342  /* release the row */
343  if( (*consdata)->row != NULL )
344  {
345  SCIP_CALL( SCIPreleaseRow(scip, &(*consdata)->row) );
346  }
347 
348  /* release the nlrow */
349  if( (*consdata)->nlrow != NULL )
350  {
351  SCIP_CALL( SCIPreleaseNlRow(scip, &(*consdata)->nlrow) );
352  }
353 
354  /* release variables */
355  for( v = 0; v < (*consdata)->nvars; v++ )
356  {
357  assert((*consdata)->vars[v] != NULL);
358  SCIP_CALL( SCIPreleaseVar(scip, &((*consdata)->vars[v])) );
359  }
360 
361  SCIPfreeBlockMemoryArrayNull(scip, &(*consdata)->vars, (*consdata)->varssize);
362  SCIPfreeBlockMemory(scip, consdata);
363 
364  return SCIP_OKAY;
365 }
366 
367 /** prints logic or constraint to file stream */
368 static
370  SCIP* scip, /**< SCIP data structure */
371  SCIP_CONSDATA* consdata, /**< logic or constraint data */
372  FILE* file, /**< output file (or NULL for standard output) */
373  SCIP_Bool endline /**< should an endline be set? */
374  )
375 {
376  assert(consdata != NULL);
377 
378  /* print constraint type */
379  SCIPinfoMessage(scip, file, "logicor(");
380 
381  /* print variable list */
382  SCIP_CALL( SCIPwriteVarsList(scip, file, consdata->vars, consdata->nvars, TRUE, ',') );
383 
384  /* close bracket */
385  SCIPinfoMessage(scip, file, ")");
386 
387  if( endline )
388  SCIPinfoMessage(scip, file, "\n");
389 
390  return SCIP_OKAY;
391 }
392 
393 /** stores the given variable numbers as watched variables, and updates the event processing */
394 static
396  SCIP* scip, /**< SCIP data structure */
397  SCIP_CONS* cons, /**< logic or constraint */
398  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
399  int watchedvar1, /**< new first watched variable */
400  int watchedvar2 /**< new second watched variable */
401  )
402 {
403  SCIP_CONSDATA* consdata;
404 
405  consdata = SCIPconsGetData(cons);
406  assert(consdata != NULL);
407  assert(watchedvar1 == -1 || watchedvar1 != watchedvar2);
408  assert(watchedvar1 != -1 || watchedvar2 == -1);
409  assert(watchedvar1 == -1 || (0 <= watchedvar1 && watchedvar1 < consdata->nvars));
410  assert(watchedvar2 == -1 || (0 <= watchedvar2 && watchedvar2 < consdata->nvars));
411 
412  /* if one watched variable is equal to the old other watched variable, just switch positions */
413  if( watchedvar1 == consdata->watchedvar2 || watchedvar2 == consdata->watchedvar1 )
414  {
415  int tmp;
416 
417  tmp = consdata->watchedvar1;
418  consdata->watchedvar1 = consdata->watchedvar2;
419  consdata->watchedvar2 = tmp;
420  tmp = consdata->filterpos1;
421  consdata->filterpos1 = consdata->filterpos2;
422  consdata->filterpos2 = tmp;
423  }
424  assert(watchedvar1 == -1 || watchedvar1 != consdata->watchedvar2);
425  assert(watchedvar2 == -1 || watchedvar2 != consdata->watchedvar1);
426 
427  /* drop events on old watched variables */
428  if( consdata->watchedvar1 != -1 && consdata->watchedvar1 != watchedvar1 )
429  {
430  assert(consdata->filterpos1 != -1);
431  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[consdata->watchedvar1],
433  consdata->filterpos1) );
434  }
435  if( consdata->watchedvar2 != -1 && consdata->watchedvar2 != watchedvar2 )
436  {
437  assert(consdata->filterpos2 != -1);
438  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[consdata->watchedvar2],
440  consdata->filterpos2) );
441  }
442 
443  /* catch events on new watched variables */
444  if( watchedvar1 != -1 && watchedvar1 != consdata->watchedvar1 )
445  {
446  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[watchedvar1],
448  &consdata->filterpos1) );
449  }
450  if( watchedvar2 != -1 && watchedvar2 != consdata->watchedvar2 )
451  {
452  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[watchedvar2],
454  &consdata->filterpos2) );
455  }
456 
457  /* set the new watched variables */
458  consdata->watchedvar1 = watchedvar1;
459  consdata->watchedvar2 = watchedvar2;
460 
461  return SCIP_OKAY;
462 }
463 
464 /** adds coefficient in logicor constraint */
465 static
467  SCIP* scip, /**< SCIP data structure */
468  SCIP_CONS* cons, /**< logicor constraint */
469  SCIP_VAR* var /**< variable to add to the constraint */
470  )
471 {
472  SCIP_CONSDATA* consdata;
473  SCIP_Bool transformed;
474 
475  assert(var != NULL);
476 
477  consdata = SCIPconsGetData(cons);
478  assert(consdata != NULL);
479 
480  /* are we in the transformed problem? */
481  transformed = SCIPconsIsTransformed(cons);
482 
483  /* always use transformed variables in transformed constraints */
484  if( transformed )
485  {
486  SCIP_CALL( SCIPgetTransformedVar(scip, var, &var) );
487 
488  if( !consdata->existmultaggr && SCIPvarGetStatus(SCIPvarGetProbvar(var)) == SCIP_VARSTATUS_MULTAGGR )
489  consdata->existmultaggr = TRUE;
490 
491  consdata->presolved = FALSE;
492  }
493  assert(var != NULL);
494  assert(transformed == SCIPvarIsTransformed(var));
495 
496  SCIP_CALL( consdataEnsureVarsSize(scip, consdata, consdata->nvars + 1) );
497  consdata->vars[consdata->nvars] = var;
498  SCIP_CALL( SCIPcaptureVar(scip, consdata->vars[consdata->nvars]) );
499  consdata->nvars++;
500 
501  /* we only catch this event in presolving stage */
503  {
504  SCIP_CONSHDLRDATA* conshdlrdata;
505  SCIP_CONSHDLR* conshdlr;
506 
507  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
508  assert(conshdlr != NULL);
509  conshdlrdata = SCIPconshdlrGetData(conshdlr);
510  assert(conshdlrdata != NULL);
511 
512  SCIP_CALL( SCIPcatchVarEvent(scip, var, SCIP_EVENTTYPE_VARFIXED, conshdlrdata->eventhdlr,
513  (SCIP_EVENTDATA*)cons, NULL) );
514  }
515 
516  consdata->sorted = (consdata->nvars == 1);
517  consdata->changed = TRUE;
518  consdata->validsignature = FALSE;
519 
520  /* install the rounding locks for the new variable */
521  SCIP_CALL( lockRounding(scip, cons, var) );
522 
523  /* add the new coefficient to the LP row */
524  if( consdata->row != NULL )
525  {
526  SCIP_CALL( SCIPaddVarToRow(scip, consdata->row, var, 1.0) );
527  }
528 
529  consdata->merged = FALSE;
530 
531  return SCIP_OKAY;
532 }
533 
534 /** deletes coefficient at given position from logic or constraint data */
535 static
537  SCIP* scip, /**< SCIP data structure */
538  SCIP_CONS* cons, /**< logic or constraint */
539  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
540  int pos /**< position of coefficient to delete */
541  )
542 {
543  SCIP_CONSDATA* consdata;
544 
545  assert(eventhdlr != NULL);
546 
547  consdata = SCIPconsGetData(cons);
548  assert(consdata != NULL);
549  assert(0 <= pos && pos < consdata->nvars);
550  assert(SCIPconsIsTransformed(cons) == SCIPvarIsTransformed(consdata->vars[pos]));
551 
552  /* remove the rounding locks of variable */
553  SCIP_CALL( unlockRounding(scip, cons, consdata->vars[pos]) );
554 
555  /* we only catch this event in presolving stage, so we need to only drop it there */
557  {
558  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[pos], SCIP_EVENTTYPE_VARFIXED, eventhdlr,
559  (SCIP_EVENTDATA*)cons, -1) );
560  }
561 
562  if( SCIPconsIsTransformed(cons) )
563  {
564  /* if the position is watched, stop watching the position */
565  if( consdata->watchedvar1 == pos )
566  {
567  SCIP_CALL( switchWatchedvars(scip, cons, eventhdlr, consdata->watchedvar2, -1) );
568  }
569  if( consdata->watchedvar2 == pos )
570  {
571  SCIP_CALL( switchWatchedvars(scip, cons, eventhdlr, consdata->watchedvar1, -1) );
572  }
573  }
574  assert(pos != consdata->watchedvar1);
575  assert(pos != consdata->watchedvar2);
576 
577  /* release variable */
578  SCIP_CALL( SCIPreleaseVar(scip, &consdata->vars[pos]) );
579 
580  /* move the last variable to the free slot */
581  if( pos != consdata->nvars - 1 )
582  {
583  consdata->vars[pos] = consdata->vars[consdata->nvars-1];
584  consdata->sorted = FALSE;
585  }
586  consdata->nvars--;
587 
588  /* if the last variable (that moved) was watched, update the watched position */
589  if( consdata->watchedvar1 == consdata->nvars )
590  consdata->watchedvar1 = pos;
591  if( consdata->watchedvar2 == consdata->nvars )
592  consdata->watchedvar2 = pos;
593 
594  consdata->changed = TRUE;
595  consdata->validsignature = FALSE;
596 
597  SCIP_CALL( SCIPenableConsPropagation(scip, cons) );
598 
599  return SCIP_OKAY;
600 }
601 
602 /** in case a part (more than one variable) in the logic or constraint is independent of every else, we can perform dual
603  * reductions;
604  * - fix the variable with the smallest object coefficient to one if the constraint is not modifiable and all
605  * variable are independant
606  * - fix all independant variables with negative object coefficient to one
607  * - fix all remaining independant variables to zero
608  *
609  * also added the special case were exactly one variable is locked by this constraint and another variable without any
610  * uplocks has a better objective value than this single variable
611  * - here we fix the variable to 0.0 (if the objective contribution is non-negative)
612  *
613  * Note: the following dual reduction for logic or constraints is already performed by the presolver "dualfix"
614  * - if a variable in a set covering constraint is only locked by that constraint and has negative or zero
615  * objective coefficient than it can be fixed to one
616  */
617 static
619  SCIP* scip, /**< SCIP data structure */
620  SCIP_CONS* cons, /**< setppc constraint */
621  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
622  int* nfixedvars, /**< pointer to count number of fixings */
623  int* ndelconss, /**< pointer to count number of deleted constraints */
624  int* nchgcoefs, /**< pointer to count number of changed/deleted coefficients */
625  SCIP_RESULT* result /**< pointer to store the result SCIP_SUCCESS, if presolving was performed */
626  )
627 {
628  SCIP_CONSDATA* consdata;
629  SCIP_VAR** vars;
630  SCIP_VAR* var;
631  SCIP_VAR* activevar;
632  SCIP_Real bestobjval;
633  SCIP_Real bestobjvalnouplocks;
634  SCIP_Real objval;
635  SCIP_Real fixval;
636  SCIP_Bool infeasible;
637  SCIP_Bool fixed;
638  SCIP_Bool negated;
639  int nfixables;
640  int nvars;
641  int idx;
642  int idxnouplocks;
643  int v;
644 
645  assert(scip != NULL);
646  assert(cons != NULL);
647  assert(eventhdlr != NULL);
648  assert(nfixedvars != NULL);
649  assert(ndelconss != NULL);
650  assert(nchgcoefs != NULL);
651  assert(result != NULL);
652 
653  /* constraints for which the check flag is set to FALSE, did not contribute to the lock numbers; therefore, we cannot
654  * use the locks to decide for a dual reduction using this constraint; for example after a restart the cuts which are
655  * added to the problems have the check flag set to FALSE
656  */
657  if( !SCIPconsIsChecked(cons) )
658  return SCIP_OKAY;
659 
660  assert(SCIPconsIsActive(cons));
661 
662  consdata = SCIPconsGetData(cons);
663  assert(consdata != NULL);
664 
665  nvars = consdata->nvars;
666 
667  /* we don't want to consider small constraints (note that the constraints can be modifiable, so we can't delete this
668  * constraint)
669  */
670  if( nvars < 2 )
671  return SCIP_OKAY;
672 
673  vars = consdata->vars;
674  idx = -1;
675  idxnouplocks = -1;
676  bestobjval = SCIP_INVALID;
677  bestobjvalnouplocks = SCIP_INVALID;
678 
679  nfixables = 0;
680 
681  /* check if we can apply the dual reduction; therefore count the number of variables where the logic or has the only
682  * locks on
683  */
684  for( v = nvars - 1; v >= 0; --v )
685  {
686  var = vars[v];
687  assert(var != NULL);
688 
689  /* variables with varstatus not equal to SCIP_VARSTATUS_FIXED can also have fixed bounds, but were not removed yet */
690  if( SCIPvarGetUbGlobal(var) < 0.5 )
691  {
692 #ifndef NDEBUG
693  SCIP_VAR* bestvar = NULL;
694 #endif
695  if( idx == consdata->nvars - 1 )
696  {
697 #ifndef NDEBUG
698  bestvar = consdata->vars[idx];
699 #endif
700  idx = v;
701  }
702 
703  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
704  ++(*nchgcoefs);
705 
706  assert(bestvar == NULL || bestvar == consdata->vars[v]);
707 
708  continue;
709  }
710  if( SCIPvarGetLbGlobal(var) > 0.5 )
711  {
712  /* remove constraint since it is redundant */
713  SCIP_CALL( SCIPdelCons(scip, cons) );
714  ++(*ndelconss);
715 
716  return SCIP_OKAY;
717  }
718 
719  /* remember best variable with no uplocks, this variable dominates all other with exactly one downlock */
722  {
723  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
724 
725  /* check if the current variable has a smaller objective coefficient then the best one */
726  if( SCIPisLT(scip, objval, bestobjval) )
727  {
728  idxnouplocks = v;
729  bestobjvalnouplocks = objval;
730  }
731  }
732 
733  /* in case an other constraints has also locks on that variable we cannot perform a dual reduction on these
734  * variables
735  */
738  continue;
739 
740  ++nfixables;
741  negated = FALSE;
742 
743  /* get the active variable */
744  SCIP_CALL( SCIPvarGetProbvarBinary(&var, &negated) );
745  assert(SCIPvarIsActive(var));
746 
747  if( negated )
748  objval = -SCIPvarGetObj(var);
749  else
750  objval = SCIPvarGetObj(var);
751 
752  /* check if the current variable has a smaller objective coefficient */
753  if( SCIPisLT(scip, objval, bestobjval) )
754  {
755  idx = v;
756  bestobjval = objval;
757  }
758  }
759 
760  nvars = consdata->nvars;
761 
762  /* check if we have a single variable dominated by another */
763  if( nfixables == 1 && idxnouplocks >= 0 )
764  {
765  assert(bestobjvalnouplocks != SCIP_INVALID); /*lint !e777*/
766 
767  for( v = nvars - 1; v >= 0; --v )
768  {
769  var = vars[v];
770  assert(var != NULL);
771 
772  /* check if a variable only appearing in this constraint is dominated by another */
775  {
776  assert(idxnouplocks != v);
777 
778  SCIP_CALL( SCIPvarGetAggregatedObj(var, &objval) );
779 
780  if( SCIPisGE(scip, objval, bestobjvalnouplocks) && !SCIPisNegative(scip, objval) )
781  {
782  SCIP_CALL( SCIPfixVar(scip, var, 0.0, &infeasible, &fixed) );
783  assert(!infeasible);
784  assert(fixed);
785 
786  SCIPdebugMsg(scip, " -> dual fixing <%s> == 0.0\n", SCIPvarGetName(var));
787  ++(*nfixedvars);
788  }
789 
790  break;
791  }
792  }
793  }
794 
795  if( nfixables < 2 )
796  return SCIP_OKAY;
797 
798  nvars = consdata->nvars;
799 
800  assert(idx >= 0 && idx < nvars);
801  assert(bestobjval < SCIPinfinity(scip));
802 
803  *result = SCIP_SUCCESS;
804 
805  /* fix all redundant variables to their best bound */
806 
807  /* first part of all variables */
808  for( v = 0; v < nvars; ++v )
809  {
810  var = vars[v];
811  assert(var != NULL);
812 
813  /* in case an other constraints has also locks on that variable we cannot perform a dual reduction on these
814  * variables
815  */
818  continue;
819 
820  if( v == idx )
821  continue;
822 
823  activevar = var;
824  negated = FALSE;
825 
826  /* get the active variable */
827  SCIP_CALL( SCIPvarGetProbvarBinary(&activevar, &negated) );
828  assert(SCIPvarIsActive(activevar));
829 
830  if( negated )
831  objval = -SCIPvarGetObj(activevar);
832  else
833  objval = SCIPvarGetObj(activevar);
834 
835  if( objval > 0.0 )
836  fixval = 0.0;
837  else
838  fixval = 1.0;
839 
840  SCIP_CALL( SCIPfixVar(scip, var, fixval, &infeasible, &fixed) );
841  assert(!infeasible);
842  assert(fixed);
843 
844  SCIPdebugMsg(scip, " -> dual fixing <%s> == %g\n", SCIPvarGetName(var), fixval);
845  ++(*nfixedvars);
846  }
847 
848  /* if all variable have our appreciated number of locks and the constraint is not modifiable, or if the bestobjval is
849  * less than or equal to zero, we can fix the variable with the smallest objective coefficient to one and the
850  * constraint gets redundant
851  */
852  if( (nfixables == nvars && !SCIPconsIsModifiable(cons)) || bestobjval <= 0.0 )
853  {
854  SCIP_CALL( SCIPfixVar(scip, vars[idx], 1.0, &infeasible, &fixed) );
855  assert(!infeasible);
856  assert(fixed);
857 
858  SCIPdebugMsg(scip, " -> fixed <%s> == 1.0\n", SCIPvarGetName(vars[idx]));
859  ++(*nfixedvars);
860 
861  /* remove constraint since it is now redundant */
862  SCIP_CALL( SCIPdelCons(scip, cons) );
863  ++(*ndelconss);
864  }
865 
866  return SCIP_OKAY;
867 }
868 
869 /** deletes all zero-fixed variables, checks for variables fixed to one, replace all variables which are not active or
870  * not a negation of an active variable by there active or negation of an active counterpart
871  */
872 static
874  SCIP* scip, /**< SCIP data structure */
875  SCIP_CONS* cons, /**< logic or constraint */
876  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
877  SCIP_Bool* redundant, /**< returns whether a variable fixed to one exists in the constraint */
878  int* nchgcoefs, /**< pointer to count number of changed/deleted coefficients */
879  int* naddconss, /**< pointer to count number of added constraints, or NULL indicating we
880  * can not resolve multi-aggregations
881  */
882  int* ndelconss /**< pointer to count number of deleted constraints, or NULL indicating we
883  * can not resolve multi-aggregations
884  */
885  )
886 {
887  SCIP_CONSDATA* consdata;
888  SCIP_VAR* var;
889  int v;
890  SCIP_VAR** vars;
891  SCIP_Bool* negarray;
892  int nvars;
893 
894  assert(eventhdlr != NULL);
895  assert(redundant != NULL);
896 
897  consdata = SCIPconsGetData(cons);
898  assert(consdata != NULL);
899  assert(consdata->nvars == 0 || consdata->vars != NULL);
900 
901  *redundant = FALSE;
902  v = 0;
903 
904  /* all multi-aggregations should be resolved */
905  consdata->existmultaggr = FALSE;
906  consdata->presolved = TRUE;
907 
908  /* remove zeros and mark constraint redundant when found one variable fixed to one */
909  while( v < consdata->nvars )
910  {
911  var = consdata->vars[v];
912  assert(SCIPvarIsBinary(var));
913 
914  if( SCIPvarGetLbGlobal(var) > 0.5 )
915  {
916  assert(SCIPisFeasEQ(scip, SCIPvarGetUbGlobal(var), 1.0));
917  *redundant = TRUE;
918 
919  return SCIP_OKAY;
920  }
921  else if( SCIPvarGetUbGlobal(var) < 0.5 )
922  {
923  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(var), 0.0));
924  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
925  ++(*nchgcoefs);
926  }
927  else
928  ++v;
929  }
930 
931  if( consdata->nvars == 0 )
932  return SCIP_OKAY;
933 
934  nvars = consdata->nvars;
935 
936  /* allocate temporary memory */
937  SCIP_CALL( SCIPallocBufferArray(scip, &vars, nvars) );
938  SCIP_CALL( SCIPallocBufferArray(scip, &negarray, nvars) );
939 
940  /* get active or negation of active variables */
941  SCIP_CALL( SCIPgetBinvarRepresentatives(scip, nvars, consdata->vars, vars, negarray) );
942 
943  /* renew all variables, important that we do a backwards loop because deletion only affect rear items */
944  for( v = nvars - 1; v >= 0; --v )
945  {
946  var = vars[v];
947 
948  /* resolve multi-aggregation */
950  {
951  SCIP_VAR** consvars;
952  SCIP_Real* consvals;
953  SCIP_Real constant = 0.0;
954  SCIP_Bool easycase;
955  int nconsvars;
956  int requiredsize;
957  int v2;
958 
959  nconsvars = 1;
960  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 1) );
961  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 1) );
962  consvars[0] = var;
963  consvals[0] = 1.0;
964 
965  /* get active variables for new constraint */
966  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, nconsvars, &constant, &requiredsize, TRUE) );
967  /* if space was not enough we need to resize the buffers */
968  if( requiredsize > nconsvars )
969  {
970  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, requiredsize) );
971  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) );
972 
973  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize, TRUE) );
974  assert(requiredsize <= nconsvars);
975  }
976 
977  easycase = FALSE;
978 
979  if( SCIPisZero(scip, constant) )
980  {
981  /* add active representation */
982  for( v2 = nconsvars - 1; v2 >= 0; --v2 )
983  {
984  if( !SCIPvarIsBinary(consvars[v2]) )
985  break;
986 
987  if( !SCIPisEQ(scip, consvals[v2], 1.0) )
988  break;
989  }
990 
991  if( v2 < 0 )
992  easycase = TRUE;
993  }
994 
995  /* we can easily add the coefficients and still have a logicor constraint */
996  if( easycase )
997  {
998  /* delete old (multi-aggregated) variable */
999  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
1000  ++(*nchgcoefs);
1001 
1002  /* add active representation */
1003  for( v2 = nconsvars - 1; v2 >= 0; --v2 )
1004  {
1005  assert(SCIPvarIsBinary(consvars[v2]));
1006  assert(SCIPvarIsActive(consvars[v2]) || (SCIPvarGetStatus(consvars[v2]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(consvars[v2]))));
1007 
1008  SCIP_CALL( addCoef(scip, cons, consvars[v2]) );
1009  ++(*nchgcoefs);
1010  }
1011  }
1012  /* we need to degrade this logicor constraint to a linear constraint*/
1013  else if( (ndelconss != NULL && naddconss != NULL) || SCIPconsIsAdded(cons) )
1014  {
1015  char name[SCIP_MAXSTRLEN];
1016  SCIP_CONS* newcons;
1017  SCIP_Real lhs;
1018  SCIP_Real rhs;
1019  int size;
1020  int k;
1021 
1022  /* it might happen that there are more than one multi-aggregated variable, so we need to get the whole probvar sum over all variables */
1023 
1024  size = MAX(nconsvars, 1) + nvars - 1;
1025 
1026  /* memory needed is at least old number of variables - 1 + number of variables in first multi-aggregation */
1027  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, size) );
1028  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, size) );
1029 
1030  nconsvars = nvars;
1031 
1032  /* add constraint variables to new linear variables */
1033  for( k = nvars - 1; k >= 0; --k )
1034  {
1035  consvars[k] = vars[k];
1036  consvals[k] = 1.0;
1037  }
1038 
1039  constant = 0.0;
1040 
1041  /* get active variables for new constraint */
1042  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, size, &constant, &requiredsize, TRUE) );
1043 
1044  /* if space was not enough(we found another multi-aggregation), we need to resize the buffers */
1045  if( requiredsize > nconsvars )
1046  {
1047  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, requiredsize) );
1048  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, requiredsize) );
1049 
1050  SCIP_CALL( SCIPgetProbvarLinearSum(scip, consvars, consvals, &nconsvars, requiredsize, &constant, &requiredsize, TRUE) );
1051  assert(requiredsize <= nconsvars);
1052  }
1053 
1054  lhs = 1.0 - constant;
1055  rhs = SCIPinfinity(scip);
1056 
1057  /* create linear constraint */
1058  (void)SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", SCIPconsGetName(cons));
1059  SCIP_CALL( SCIPcreateConsLinear(scip, &newcons, name, nconsvars, consvars, consvals, lhs, rhs,
1060  SCIPconsIsInitial(cons),
1064  SCIP_CALL( SCIPaddCons(scip, newcons) );
1065 
1066  SCIPdebugMsg(scip, "added linear constraint: ");
1067  SCIPdebugPrintCons(scip, newcons, NULL);
1068  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
1069 
1070  SCIPfreeBufferArray(scip, &consvals);
1071  SCIPfreeBufferArray(scip, &consvars);
1072 
1073  /* delete old constraint */
1074  SCIP_CALL( SCIPdelCons(scip, cons) );
1075  if( ndelconss != NULL && naddconss != NULL )
1076  {
1077  assert( naddconss != NULL ); /* for lint */
1078  ++(*ndelconss);
1079  ++(*naddconss);
1080  }
1081 
1082  goto TERMINATE;
1083  }
1084  /* we need to degrade this logicor constraint to a linear constraint*/
1085  else
1086  {
1087  if( var != consdata->vars[v] )
1088  {
1089  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
1090  SCIP_CALL( addCoef(scip, cons, var) );
1091  }
1092 
1093  SCIPwarningMessage(scip, "logicor constraint <%s> has a multi-aggregated variable, which was not resolved and therefore could lead to aborts\n", SCIPconsGetName(cons));
1094  }
1095 
1096  SCIPfreeBufferArray(scip, &consvals);
1097  SCIPfreeBufferArray(scip, &consvars);
1098  }
1099  else if( var != consdata->vars[v] )
1100  {
1101  assert(SCIPvarIsBinary(var));
1102 
1103  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
1104 
1105  /* the binvar representative might be fixed:
1106  * - if fixed to 1, the constraint is redundant
1107  * - if fixed to 0, the representative does not need to be added to the constraint
1108  * - if not fixed, we add the representative to the constraint
1109  */
1110  if( SCIPvarGetLbGlobal(var) > 0.5 )
1111  {
1112  assert(SCIPisFeasEQ(scip, SCIPvarGetUbGlobal(var), 1.0));
1113  *redundant = TRUE;
1114 
1115  goto TERMINATE;
1116  }
1117  else if( SCIPvarGetUbGlobal(var) < 0.5 )
1118  {
1119  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(var), 0.0));
1120  ++(*nchgcoefs);
1121  }
1122  else
1123  {
1124  SCIP_CALL( addCoef(scip, cons, var) );
1125  }
1126  }
1127  }
1128 
1129  SCIPdebugMsg(scip, "after fixings: ");
1130  SCIPdebug( SCIP_CALL(consdataPrint(scip, consdata, NULL, TRUE)) );
1131 
1132  TERMINATE:
1133  /* free temporary memory */
1134  SCIPfreeBufferArray(scip, &negarray);
1135  SCIPfreeBufferArray(scip, &vars);
1136 
1137  consdata->presolved = TRUE;
1138 
1139  return SCIP_OKAY;
1140 }
1141 
1142 /** analyzes conflicting assignment on given constraint, and adds conflict constraint to problem */
1143 static
1145  SCIP* scip, /**< SCIP data structure */
1146  SCIP_CONS* cons /**< logic or constraint that detected the conflict */
1147  )
1148 {
1149  SCIP_CONSDATA* consdata;
1150  int v;
1151 
1152  /* conflict analysis can only be applied in solving stage and if it is applicable */
1154  return SCIP_OKAY;
1155 
1156  consdata = SCIPconsGetData(cons);
1157  assert(consdata != NULL);
1158 
1159  /* initialize conflict analysis, and add all variables of infeasible constraint to conflict candidate queue */
1161 
1162  for( v = 0; v < consdata->nvars; ++v )
1163  {
1164  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
1165  }
1166 
1167  /* analyze the conflict */
1168  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
1169 
1170  return SCIP_OKAY;
1171 }
1172 
1173 /** disables or deletes the given constraint, depending on the current depth */
1174 static
1176  SCIP* scip, /**< SCIP data structure */
1177  SCIP_CONS* cons /**< bound disjunction constraint to be disabled */
1178  )
1179 {
1180  assert(SCIPconsGetValidDepth(cons) <= SCIPgetDepth(scip));
1181 
1182  /* in case the logic or constraint is satisfied in the depth where it is also valid, we can delete it */
1183  if( SCIPgetDepth(scip) == SCIPconsGetValidDepth(cons) )
1184  {
1185  SCIP_CALL( SCIPdelCons(scip, cons) );
1186  }
1187  else
1188  {
1189  SCIPdebugMsg(scip, "disabling constraint cons <%s> at depth %d\n", SCIPconsGetName(cons), SCIPgetDepth(scip));
1190  SCIP_CALL( SCIPdisableCons(scip, cons) );
1191  }
1192 
1193  return SCIP_OKAY;
1194 }
1195 
1196 /** find pairs of negated variables in constraint: constraint is redundant */
1197 /** find sets of equal variables in constraint: multiple entries of variable can be replaced by single entry */
1198 static
1200  SCIP* scip, /**< SCIP data structure */
1201  SCIP_CONS* cons, /**< logic or constraint */
1202  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
1203  unsigned char** entries, /**< array to store whether two positions in constraints represent the same variable */
1204  int* nentries, /**< pointer for array size, if array will be to small it's corrected */
1205  SCIP_Bool* redundant, /**< returns whether a variable fixed to one exists in the constraint */
1206  int* nchgcoefs /**< pointer to count number of changed/deleted coefficients */
1207  )
1208 {
1209  SCIP_CONSDATA* consdata;
1210  SCIP_VAR** vars;
1211  int nvars;
1212  SCIP_Bool* negarray;
1213  SCIP_VAR* var;
1214  int v;
1215  int pos;
1216 #ifndef NDEBUG
1217  int nbinvars;
1218  int nintvars;
1219  int nimplvars;
1220 #endif
1221 
1222  assert(scip != NULL);
1223  assert(cons != NULL);
1224  assert(eventhdlr != NULL);
1225  assert(*entries != NULL);
1226  assert(nentries != NULL);
1227  assert(redundant != NULL);
1228  assert(nchgcoefs != NULL);
1229 
1230  consdata = SCIPconsGetData(cons);
1231  assert(consdata != NULL);
1232 
1233  nvars = consdata->nvars;
1234 
1235  *redundant = FALSE;
1236 
1237  if( consdata->merged )
1238  return SCIP_OKAY;
1239 
1240  if( consdata->nvars <= 1 )
1241  {
1242  consdata->merged = TRUE;
1243  return SCIP_OKAY;
1244  }
1245 
1246  assert(consdata->vars != NULL && nvars > 0);
1247 
1248 #ifndef NDEBUG
1249  nbinvars = SCIPgetNBinVars(scip);
1250  nintvars = SCIPgetNIntVars(scip);
1251  nimplvars = SCIPgetNImplVars(scip);
1252  assert(*nentries >= nbinvars + nintvars + nimplvars);
1253 
1254  /* all variables should be active or negative active variables, otherwise something went wrong with applyFixings()
1255  * called before mergeMultiples()
1256  */
1257  assert(consdata->presolved);
1258 #endif
1259 
1260  /* allocate temporary memory */
1261  SCIP_CALL( SCIPallocBufferArray(scip, &negarray, nvars) );
1262 
1263  vars = consdata->vars;
1264 
1265  /* initialize entries array */
1266  for( v = nvars - 1; v >= 0; --v )
1267  {
1268  /* all variables should be active or negative active variables, otherwise something went wrong with applyFixings()
1269  * called before mergeMultiples()
1270  */
1271  assert(SCIPvarIsActive(vars[v]) ||
1273  negarray[v] = SCIPvarIsNegated(vars[v]);
1274  var = negarray[v] ? SCIPvarGetNegationVar(vars[v]) : vars[v];
1275  assert(SCIPvarIsActive(var));
1276 
1277  pos = SCIPvarGetProbindex(var);
1278 
1279  /* check variable type, either pure binary or an integer/implicit integer variable with 0/1 bounds */
1280  assert((pos < nbinvars && SCIPvarGetType(var) == SCIP_VARTYPE_BINARY)
1281  || (SCIPvarIsBinary(var) &&
1282  ((pos >= nbinvars && pos < nbinvars + nintvars && SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER) ||
1283  (pos >= nbinvars + nintvars && pos < nbinvars + nintvars + nimplvars &&
1285 
1286  /* var is not active yet */
1287  (*entries)[pos] = 0;
1288  }
1289 
1290  /* check all vars for multiple entries, do necessary backwards loop because deletion only affect rear items */
1291  for( v = nvars - 1; v >= 0; --v )
1292  {
1293  var = negarray[v] ? SCIPvarGetNegationVar(vars[v]) : vars[v];
1294  assert(SCIPvarIsActive(var));
1295 
1296  pos = SCIPvarGetProbindex(var);
1297 
1298  /* if var occurs first time in constraint init entries array */
1299  if( (*entries)[pos] == 0 )
1300  (*entries)[pos] = negarray[v] ? 2 : 1;
1301  /* if var occurs second time in constraint, first time it was not negated */
1302  else if( (*entries)[pos] == 1 )
1303  {
1304  if( negarray[v] )
1305  {
1306  SCIPdebugMsg(scip, "logicor constraint <%s> redundant: variable <%s> and its negation are present\n",
1307  SCIPconsGetName(cons), SCIPvarGetName(var));
1308 
1309  *redundant = TRUE;
1310  goto TERMINATE;
1311  }
1312  else
1313  {
1314  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
1315  ++(*nchgcoefs);
1316  }
1317  }
1318  /* if var occurs second time in constraint, first time it was negated */
1319  else
1320  {
1321  if( !negarray[v] )
1322  {
1323  SCIPdebugMsg(scip, "logicor constraint <%s> redundant: variable <%s> and its negation are present\n",
1324  SCIPconsGetName(cons), SCIPvarGetName(var));
1325 
1326  *redundant = TRUE;
1327  goto TERMINATE;
1328  }
1329  else
1330  {
1331  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
1332  ++(*nchgcoefs);
1333  }
1334  }
1335  }
1336 
1337  TERMINATE:
1338  /* free temporary memory */
1339  SCIPfreeBufferArray(scip, &negarray);
1340 
1341  consdata->merged = TRUE;
1342 
1343  return SCIP_OKAY;
1344 }
1345 
1346 /** checks constraint for violation only looking at the watched variables, applies fixings if possible */
1347 static
1349  SCIP* scip, /**< SCIP data structure */
1350  SCIP_CONS* cons, /**< logic or constraint to be processed */
1351  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
1352  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
1353  SCIP_Bool* reduceddom, /**< pointer to store TRUE, if a domain reduction was found */
1354  SCIP_Bool* addcut, /**< pointer to store whether this constraint must be added as a cut */
1355  SCIP_Bool* mustcheck /**< pointer to store whether this constraint must be checked for feasibility */
1356  )
1357 {
1358  SCIP_CONSDATA* consdata;
1359  SCIP_VAR** vars;
1360  SCIP_Longint nbranchings1;
1361  SCIP_Longint nbranchings2;
1362  int nvars;
1363  int watchedvar1;
1364  int watchedvar2;
1365 
1366  assert(cons != NULL);
1367  assert(SCIPconsGetHdlr(cons) != NULL);
1368  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
1369  assert(cutoff != NULL);
1370  assert(reduceddom != NULL);
1371  assert(addcut != NULL);
1372  assert(mustcheck != NULL);
1373 
1374  consdata = SCIPconsGetData(cons);
1375  assert(consdata != NULL);
1376  assert(consdata->watchedvar1 == -1 || consdata->watchedvar1 != consdata->watchedvar2);
1377 
1378  *addcut = FALSE;
1379  *mustcheck = FALSE;
1380 
1381  SCIPdebugMsg(scip, "processing watched variables of constraint <%s>\n", SCIPconsGetName(cons));
1382 
1383  vars = consdata->vars;
1384  nvars = consdata->nvars;
1385  assert(nvars == 0 || vars != NULL);
1386 
1387  /* check watched variables if they are fixed to one */
1388  if( consdata->watchedvar1 >= 0 && SCIPvarGetLbLocal(vars[consdata->watchedvar1]) > 0.5 )
1389  {
1390  /* the variable is fixed to one, making the constraint redundant -> disable the constraint */
1391  SCIPdebugMsg(scip, " -> disabling constraint <%s> (watchedvar1 fixed to 1.0)\n", SCIPconsGetName(cons));
1392  SCIP_CALL( disableCons(scip, cons) );
1393  return SCIP_OKAY;
1394  }
1395  if( consdata->watchedvar2 >= 0 && SCIPvarGetLbLocal(vars[consdata->watchedvar2]) > 0.5 )
1396  {
1397  /* the variable is fixed to one, making the constraint redundant -> disable the constraint */
1398  SCIPdebugMsg(scip, " -> disabling constraint <%s> (watchedvar2 fixed to 1.0)\n", SCIPconsGetName(cons));
1399  SCIP_CALL( disableCons(scip, cons) );
1400  return SCIP_OKAY;
1401  }
1402 
1403  /* check if watched variables are still unfixed */
1404  watchedvar1 = -1;
1405  watchedvar2 = -1;
1406  nbranchings1 = SCIP_LONGINT_MAX;
1407  nbranchings2 = SCIP_LONGINT_MAX;
1408  if( consdata->watchedvar1 >= 0 && SCIPvarGetUbLocal(vars[consdata->watchedvar1]) > 0.5 )
1409  {
1410  watchedvar1 = consdata->watchedvar1;
1411  nbranchings1 = -1; /* prefer keeping the watched variable */
1412  }
1413  if( consdata->watchedvar2 >= 0 && SCIPvarGetUbLocal(vars[consdata->watchedvar2]) > 0.5 )
1414  {
1415  if( watchedvar1 == -1 )
1416  {
1417  watchedvar1 = consdata->watchedvar2;
1418  nbranchings1 = -1; /* prefer keeping the watched variable */
1419  }
1420  else
1421  {
1422  watchedvar2 = consdata->watchedvar2;
1423  nbranchings2 = -1; /* prefer keeping the watched variable */
1424  }
1425  }
1426  assert(watchedvar1 >= 0 || watchedvar2 == -1);
1427  assert(nbranchings1 <= nbranchings2);
1428 
1429  /* search for new watched variables */
1430  if( watchedvar2 == -1 )
1431  {
1432  int v;
1433 
1434  for( v = 0; v < nvars; ++v )
1435  {
1436  SCIP_Longint nbranchings;
1437 
1438  /* don't process the watched variables again */
1439  if( v == consdata->watchedvar1 || v == consdata->watchedvar2 )
1440  continue;
1441 
1442  /* check, if the variable is fixed */
1443  if( SCIPvarGetUbLocal(vars[v]) < 0.5 )
1444  continue;
1445 
1446  /* check, if the literal is satisfied */
1447  if( SCIPvarGetLbLocal(vars[v]) > 0.5 )
1448  {
1449  assert(v != consdata->watchedvar1);
1450  assert(v != consdata->watchedvar2);
1451 
1452  /* the variable is fixed to one, making the constraint redundant;
1453  * make sure, the feasible variable is watched and disable the constraint
1454  */
1455  SCIPdebugMsg(scip, " -> disabling constraint <%s> (variable <%s> fixed to 1.0)\n",
1456  SCIPconsGetName(cons), SCIPvarGetName(vars[v]));
1457  if( consdata->watchedvar1 != -1 )
1458  {
1459  SCIP_CALL( switchWatchedvars(scip, cons, eventhdlr, consdata->watchedvar1, v) );
1460  }
1461  else
1462  {
1463  SCIP_CALL( switchWatchedvars(scip, cons, eventhdlr, v, consdata->watchedvar2) );
1464  }
1465  SCIP_CALL( disableCons(scip, cons) );
1466  return SCIP_OKAY;
1467  }
1468 
1469  /* the variable is unfixed and can be used as watched variable */
1471  assert(nbranchings >= 0);
1472  if( nbranchings < nbranchings2 )
1473  {
1474  if( nbranchings < nbranchings1 )
1475  {
1476  watchedvar2 = watchedvar1;
1477  nbranchings2 = nbranchings1;
1478  watchedvar1 = v;
1479  nbranchings1 = nbranchings;
1480  }
1481  else
1482  {
1483  watchedvar2 = v;
1484  nbranchings2 = nbranchings;
1485  }
1486  }
1487  }
1488  }
1489  assert(nbranchings1 <= nbranchings2);
1490  assert(watchedvar1 >= 0 || watchedvar2 == -1);
1491 
1492  if( watchedvar1 == -1 )
1493  {
1494  /* there is no unfixed variable left -> the constraint is infeasible
1495  * - a modifiable constraint must be added as a cut and further pricing must be performed in the LP solving loop
1496  * - an unmodifiable constraint is infeasible and the node can be cut off
1497  */
1498  assert(watchedvar2 == -1);
1499 
1500  SCIPdebugMsg(scip, " -> constraint <%s> is infeasible\n", SCIPconsGetName(cons));
1501 
1502  SCIP_CALL( SCIPresetConsAge(scip, cons) );
1503  if( SCIPconsIsModifiable(cons) )
1504  *addcut = TRUE;
1505  else
1506  {
1507  /* use conflict analysis to get a conflict constraint out of the conflicting assignment */
1508  SCIP_CALL( analyzeConflict(scip, cons) );
1509 
1510  /* mark the node to be cut off */
1511  *cutoff = TRUE;
1512  }
1513  }
1514  else if( watchedvar2 == -1 )
1515  {
1516  /* there is only one unfixed variable:
1517  * - a modifiable constraint must be checked manually
1518  * - an unmodifiable constraint is feasible and can be disabled after the remaining variable is fixed to one
1519  */
1520  assert(0 <= watchedvar1 && watchedvar1 < nvars);
1521  assert(SCIPisFeasEQ(scip, SCIPvarGetLbLocal(vars[watchedvar1]), 0.0));
1522  assert(SCIPisFeasEQ(scip, SCIPvarGetUbLocal(vars[watchedvar1]), 1.0));
1523  if( SCIPconsIsModifiable(cons) )
1524  *mustcheck = TRUE;
1525  else
1526  {
1527  SCIP_Bool infbdchg;
1528 
1529  /* fixed remaining variable to one and disable constraint; make sure, the fixed-to-one variable is watched */
1530  SCIPdebugMsg(scip, " -> single-literal constraint <%s> (fix <%s> to 1.0) at depth %d\n",
1531  SCIPconsGetName(cons), SCIPvarGetName(vars[watchedvar1]), SCIPgetDepth(scip));
1532  SCIP_CALL( SCIPinferBinvarCons(scip, vars[watchedvar1], TRUE, cons, 0, &infbdchg, NULL) );
1533  assert(!infbdchg);
1534  SCIP_CALL( SCIPresetConsAge(scip, cons) );
1535  if( watchedvar1 != consdata->watchedvar1 ) /* keep one of the watched variables */
1536  {
1537  SCIP_CALL( switchWatchedvars(scip, cons, eventhdlr, watchedvar1, consdata->watchedvar1) );
1538  }
1539  SCIP_CALL( disableCons(scip, cons) );
1540  *reduceddom = TRUE;
1541  }
1542  }
1543  else
1544  {
1545  SCIPdebugMsg(scip, " -> new watched variables <%s> and <%s> of constraint <%s> are still unfixed\n",
1546  SCIPvarGetName(vars[watchedvar1]), SCIPvarGetName(vars[watchedvar2]), SCIPconsGetName(cons));
1547 
1548  /* switch to the new watched variables */
1549  SCIP_CALL( switchWatchedvars(scip, cons, eventhdlr, watchedvar1, watchedvar2) );
1550 
1551  /* there are at least two unfixed variables -> the constraint must be checked manually */
1552  *mustcheck = TRUE;
1553 
1554  /* disable propagation of constraint until a watched variable gets fixed */
1555  SCIP_CALL( SCIPdisableConsPropagation(scip, cons) );
1556 
1557  /* increase aging counter */
1558  SCIP_CALL( SCIPaddConsAge(scip, cons, AGEINCREASE(consdata->nvars)) );
1559  }
1560 
1561  return SCIP_OKAY;
1562 }
1563 
1564 /** checks constraint for violation, returns TRUE iff constraint is feasible */
1565 static
1567  SCIP* scip, /**< SCIP data structure */
1568  SCIP_CONS* cons, /**< logic or constraint to be checked */
1569  SCIP_SOL* sol /**< primal CIP solution */
1570  )
1571 {
1572  SCIP_CONSDATA* consdata;
1573  SCIP_VAR** vars;
1574  SCIP_Real solval;
1575  SCIP_Real sum;
1576  int nvars;
1577  int v;
1578 
1579  consdata = SCIPconsGetData(cons);
1580  assert(consdata != NULL);
1581 
1582  vars = consdata->vars;
1583  nvars = consdata->nvars;
1584 
1585  /* calculate the constraint's activity */
1586  sum = 0.0;
1587  for( v = 0; v < nvars && sum < 1.0; ++v )
1588  {
1589  assert(SCIPvarIsBinary(vars[v]));
1590 
1591  solval = SCIPgetSolVal(scip, sol, vars[v]);
1592  assert(SCIPisFeasGE(scip, solval, 0.0) && SCIPisFeasLE(scip, solval, 1.0));
1593 
1594  sum += solval;
1595  }
1596 
1597  /* calculate constraint violation and update it in solution */
1598  if( sol != NULL ){
1599  SCIP_Real absviol = 1.0 - sum;
1600  SCIP_Real relviol = SCIPrelDiff(1.0, sum);
1601  SCIPupdateSolLPConsViolation(scip, sol, absviol, relviol);
1602  }
1603 
1604  return SCIPisFeasLT(scip, sum, 1.0);
1605 }
1606 
1607 /** creates an LP row in a logic or constraint data object */
1608 static
1610  SCIP* scip, /**< SCIP data structure */
1611  SCIP_CONS* cons /**< logic or constraint */
1612  )
1613 {
1614  SCIP_CONSDATA* consdata;
1615 
1616  consdata = SCIPconsGetData(cons);
1617  assert(consdata != NULL);
1618  assert(consdata->row == NULL);
1619 
1620  SCIP_CALL( SCIPcreateEmptyRowCons(scip, &consdata->row, cons, SCIPconsGetName(cons), 1.0, SCIPinfinity(scip),
1622 
1623  SCIP_CALL( SCIPaddVarsToRowSameCoef(scip, consdata->row, consdata->nvars, consdata->vars, 1.0) );
1624 
1625  return SCIP_OKAY;
1626 }
1627 
1628 /** adds logicor constraint as row to the NLP, if not added yet */
1629 static
1631  SCIP* scip, /**< SCIP data structure */
1632  SCIP_CONS* cons /**< logicor constraint */
1633  )
1634 {
1635  SCIP_CONSDATA* consdata;
1636 
1637  assert(SCIPisNLPConstructed(scip));
1638 
1639  /* skip deactivated, redundant, or local constraints (the NLP does not allow for local rows at the moment) */
1640  if( !SCIPconsIsActive(cons) || !SCIPconsIsChecked(cons) || SCIPconsIsLocal(cons) )
1641  return SCIP_OKAY;
1642 
1643  consdata = SCIPconsGetData(cons);
1644  assert(consdata != NULL);
1645 
1646  if( consdata->nlrow == NULL )
1647  {
1648  SCIP_Real* coefs;
1649  int i;
1650 
1651  SCIP_CALL( SCIPallocBufferArray(scip, &coefs, consdata->nvars) );
1652  for( i = 0; i < consdata->nvars; ++i )
1653  coefs[i] = 1.0;
1654 
1655  SCIP_CALL( SCIPcreateNlRow(scip, &consdata->nlrow, SCIPconsGetName(cons),
1656  0.0, consdata->nvars, consdata->vars, coefs, NULL, 1.0, SCIPinfinity(scip), SCIP_EXPRCURV_LINEAR) );
1657  assert(consdata->nlrow != NULL);
1658 
1659  SCIPfreeBufferArray(scip, &coefs);
1660  }
1661 
1662  if( !SCIPnlrowIsInNLP(consdata->nlrow) )
1663  {
1664  SCIP_CALL( SCIPaddNlRow(scip, consdata->nlrow) );
1665  }
1666 
1667  return SCIP_OKAY;
1668 }
1669 
1670 /** adds logic or constraint as cut to the LP */
1671 static
1673  SCIP* scip, /**< SCIP data structure */
1674  SCIP_CONS* cons, /**< logic or constraint */
1675  SCIP_Bool* cutoff /**< whether a cutoff has been detected */
1676  )
1677 {
1678  SCIP_CONSDATA* consdata;
1679 
1680  assert( cutoff != NULL );
1681  *cutoff = FALSE;
1682 
1683  consdata = SCIPconsGetData(cons);
1684  assert(consdata != NULL);
1685 
1686  if( consdata->row == NULL )
1687  {
1688  /* convert logic or constraint data into LP row */
1689  SCIP_CALL( createRow(scip, cons) );
1690  }
1691  assert(consdata->row != NULL);
1692 
1693  /* insert LP row as cut */
1694  if( !SCIProwIsInLP(consdata->row) )
1695  {
1696  SCIPdebugMsg(scip, "adding constraint <%s> as cut to the LP\n", SCIPconsGetName(cons));
1697  SCIP_CALL( SCIPaddRow(scip, consdata->row, FALSE, cutoff) );
1698  }
1699 
1700  return SCIP_OKAY;
1701 }
1702 
1703 /** checks constraint for violation, and adds it as a cut if possible */
1704 static
1706  SCIP* scip, /**< SCIP data structure */
1707  SCIP_CONS* cons, /**< logic or constraint to be separated */
1708  SCIP_SOL* sol, /**< primal CIP solution, NULL for current LP solution */
1709  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
1710  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
1711  SCIP_Bool* separated, /**< pointer to store TRUE, if a cut was found */
1712  SCIP_Bool* reduceddom /**< pointer to store TRUE, if a domain reduction was found */
1713  )
1714 {
1715  SCIP_Bool addcut;
1716  SCIP_Bool mustcheck;
1717 
1718  assert(cons != NULL);
1719  assert(SCIPconsGetHdlr(cons) != NULL);
1720  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
1721  assert(cutoff != NULL);
1722  assert(separated != NULL);
1723  assert(reduceddom != NULL);
1724 
1725  *cutoff = FALSE;
1726  SCIPdebugMsg(scip, "separating constraint <%s>\n", SCIPconsGetName(cons));
1727 
1728  /* update and check the watched variables, if they were changed since last processing */
1729  if( sol == NULL && SCIPconsIsPropagationEnabled(cons) )
1730  {
1731  SCIP_CALL( processWatchedVars(scip, cons, eventhdlr, cutoff, reduceddom, &addcut, &mustcheck) );
1732  }
1733  else
1734  {
1735  addcut = FALSE;
1736  mustcheck = TRUE;
1737  }
1738 
1739  if( mustcheck )
1740  {
1741  SCIP_CONSDATA* consdata;
1742 
1743  assert(!addcut);
1744 
1745  consdata = SCIPconsGetData(cons);
1746  assert(consdata != NULL);
1747 
1748  /* variable's fixings didn't give us any information -> we have to check the constraint */
1749  if( sol == NULL && consdata->row != NULL )
1750  {
1751  /* skip constraints already in the LP */
1752  if( SCIProwIsInLP(consdata->row) )
1753  return SCIP_OKAY;
1754  else
1755  {
1756  SCIP_Real feasibility;
1757 
1758  assert(!SCIProwIsInLP(consdata->row));
1759  feasibility = SCIPgetRowLPFeasibility(scip, consdata->row);
1760  addcut = SCIPisFeasNegative(scip, feasibility);
1761  }
1762  }
1763  else
1764  {
1765  addcut = isConsViolated(scip, cons, sol);
1766  }
1767  }
1768 
1769  if( addcut )
1770  {
1771  /* insert LP row as cut */
1772  SCIP_CALL( addCut(scip, cons, cutoff) );
1773  SCIP_CALL( SCIPresetConsAge(scip, cons) );
1774  *separated = TRUE;
1775  }
1776 
1777  return SCIP_OKAY;
1778 }
1779 
1780 /** enforces the pseudo solution on the given constraint */
1781 static
1783  SCIP* scip, /**< SCIP data structure */
1784  SCIP_CONS* cons, /**< logic or constraint to be separated */
1785  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
1786  SCIP_Bool* cutoff, /**< pointer to store TRUE, if the node can be cut off */
1787  SCIP_Bool* infeasible, /**< pointer to store TRUE, if the constraint was infeasible */
1788  SCIP_Bool* reduceddom, /**< pointer to store TRUE, if a domain reduction was found */
1789  SCIP_Bool* solvelp /**< pointer to store TRUE, if the LP has to be solved */
1790  )
1791 {
1792  SCIP_Bool addcut;
1793  SCIP_Bool mustcheck;
1794 
1795  assert(!SCIPhasCurrentNodeLP(scip));
1796  assert(cons != NULL);
1797  assert(SCIPconsGetHdlr(cons) != NULL);
1798  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
1799  assert(cutoff != NULL);
1800  assert(infeasible != NULL);
1801  assert(reduceddom != NULL);
1802  assert(solvelp != NULL);
1803 
1804  /* update and check the watched variables, if they were changed since last processing */
1805  if( SCIPconsIsPropagationEnabled(cons) )
1806  {
1807  SCIP_CALL( processWatchedVars(scip, cons, eventhdlr, cutoff, reduceddom, &addcut, &mustcheck) );
1808  }
1809  else
1810  {
1811  addcut = FALSE;
1812  mustcheck = TRUE;
1813  }
1814 
1815  if( mustcheck )
1816  {
1817  assert(!addcut);
1818 
1819  if( isConsViolated(scip, cons, NULL) )
1820  {
1821  /* constraint was infeasible -> reset age */
1822  SCIP_CALL( SCIPresetConsAge(scip, cons) );
1823  *infeasible = TRUE;
1824  }
1825  }
1826  else if( addcut )
1827  {
1828  /* a cut must be added to the LP -> we have to solve the LP immediately */
1829  SCIP_CALL( SCIPresetConsAge(scip, cons) );
1830  *solvelp = TRUE;
1831  }
1832 
1833  return SCIP_OKAY;
1834 }
1835 
1836 /** sorts logicor constraint's variables by non-decreasing variable index */
1837 static
1838 void consdataSort(
1839  SCIP_CONSDATA* consdata /**< linear constraint data */
1840  )
1841 {
1842  assert(consdata != NULL);
1843 
1844  if( !consdata->sorted )
1845  {
1846  if( consdata->nvars <= 1 )
1847  consdata->sorted = TRUE;
1848  else
1849  {
1850  SCIP_VAR* var1 = NULL;
1851  SCIP_VAR* var2 = NULL;
1852 
1853  /* remember watch variables */
1854  if( consdata->watchedvar1 != -1 )
1855  {
1856  var1 = consdata->vars[consdata->watchedvar1];
1857  assert(var1 != NULL);
1858  consdata->watchedvar1 = -1;
1859  if( consdata->watchedvar2 != -1 )
1860  {
1861  var2 = consdata->vars[consdata->watchedvar2];
1862  assert(var2 != NULL);
1863  consdata->watchedvar2 = -1;
1864  }
1865  }
1866  assert(consdata->watchedvar1 == -1);
1867  assert(consdata->watchedvar2 == -1);
1868  assert(var1 != NULL || var2 == NULL);
1869 
1870  /* sort variables after index */
1871  SCIPsortPtr((void**)consdata->vars, SCIPvarComp, consdata->nvars);
1872  consdata->sorted = TRUE;
1873 
1874  /* correct watched variables */
1875  if( var1 != NULL )
1876  {
1877  int pos;
1878 #ifndef NDEBUG
1879  SCIP_Bool found;
1880 
1881  found = SCIPsortedvecFindPtr((void**)consdata->vars, SCIPvarComp, (void*)var1, consdata->nvars, &pos);
1882  assert(found);
1883 #else
1884  (void) SCIPsortedvecFindPtr((void**)consdata->vars, SCIPvarComp, (void*)var1, consdata->nvars, &pos);
1885 #endif
1886  assert(pos >= 0 && pos < consdata->nvars);
1887  consdata->watchedvar1 = pos;
1888 
1889  if( var2 != NULL )
1890  {
1891 #ifndef NDEBUG
1892  found = SCIPsortedvecFindPtr((void**)consdata->vars, SCIPvarComp, (void*)var2, consdata->nvars, &pos);
1893  assert(found);
1894 #else
1895  (void) SCIPsortedvecFindPtr((void**)consdata->vars, SCIPvarComp, (void*)var2, consdata->nvars, &pos);
1896 #endif
1897  assert(pos >= 0 && pos < consdata->nvars);
1898  consdata->watchedvar2 = pos;
1899  }
1900  }
1901  }
1902  }
1903 
1904 #ifdef SCIP_DEBUG
1905  /* check sorting */
1906  {
1907  int v;
1908 
1909  for( v = consdata->nvars - 1; v > 0; --v )
1910  {
1911  assert(SCIPvarCompare(consdata->vars[v], consdata->vars[v - 1]) >= 0);
1912  }
1913  }
1914 #endif
1915 }
1916 
1917 /** gets the key of the given element */
1918 static
1919 SCIP_DECL_HASHGETKEY(hashGetKeyLogicorcons)
1920 { /*lint --e{715}*/
1921  /* the key is the element itself */
1922  return elem;
1923 }
1924 
1925 /** returns TRUE iff both keys are equal; two constraints are equal if they have the same variables */
1926 static
1927 SCIP_DECL_HASHKEYEQ(hashKeyEqLogicorcons)
1928 {
1929  SCIP_CONSDATA* consdata1;
1930  SCIP_CONSDATA* consdata2;
1931  SCIP_Bool coefsequal;
1932  int i;
1933 #ifndef NDEBUG
1934  SCIP* scip;
1935 
1936  scip = (SCIP*)userptr;
1937  assert(scip != NULL);
1938 #endif
1939 
1940  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
1941  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
1942 
1943  /* checks trivial case */
1944  if( consdata1->nvars != consdata2->nvars )
1945  return FALSE;
1946 
1947  /* sorts the constraints */
1948  consdataSort(consdata1);
1949  consdataSort(consdata2);
1950  assert(consdata1->sorted);
1951  assert(consdata2->sorted);
1952 
1953  coefsequal = TRUE;
1954 
1955  for( i = 0; i < consdata1->nvars ; ++i )
1956  {
1957  /* tests if variables are equal */
1958  if( consdata1->vars[i] != consdata2->vars[i] )
1959  {
1960  assert(SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == 1 ||
1961  SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == -1);
1962  coefsequal = FALSE;
1963  break;
1964  }
1965  assert(SCIPvarCompare(consdata1->vars[i], consdata2->vars[i]) == 0);
1966  }
1967 
1968  return coefsequal;
1969 }
1970 
1971 /** returns the hash value of the key */
1972 static
1973 SCIP_DECL_HASHKEYVAL(hashKeyValLogicorcons)
1974 { /*lint --e{715}*/
1975  SCIP_CONSDATA* consdata;
1976  int minidx;
1977  int mididx;
1978  int maxidx;
1979 
1980  consdata = SCIPconsGetData((SCIP_CONS*)key);
1981  assert(consdata != NULL);
1982  assert(consdata->sorted);
1983  assert(consdata->nvars > 0);
1984 
1985  minidx = SCIPvarGetIndex(consdata->vars[0]);
1986  mididx = SCIPvarGetIndex(consdata->vars[consdata->nvars / 2]);
1987  maxidx = SCIPvarGetIndex(consdata->vars[consdata->nvars - 1]);
1988  assert(minidx >= 0 && minidx <= maxidx);
1989 
1990  return SCIPhashFour(consdata->nvars, minidx, mididx, maxidx);
1991 }
1992 
1993 /** compares each constraint with all other constraints for a possible duplication and removes duplicates using a hash
1994  * table; also @see removeRedundantConssAndNonzeros()
1995  */
1996 static
1998  SCIP* scip, /**< SCIP data structure */
1999  BMS_BLKMEM* blkmem, /**< block memory */
2000  SCIP_CONS** conss, /**< constraint set */
2001  int nconss, /**< number of constraints in constraint set */
2002  int* firstchange, /**< pointer to store first changed constraint */
2003  int* ndelconss /**< pointer to count number of deleted constraints */
2004  )
2005 {
2006  SCIP_HASHTABLE* hashtable;
2007  int hashtablesize;
2008  int c;
2009 
2010  assert(conss != NULL);
2011  assert(ndelconss != NULL);
2012 
2013  /* create a hash table for the constraint set */
2014  hashtablesize = nconss;
2015  hashtablesize = MAX(hashtablesize, HASHSIZE_LOGICORCONS);
2016  SCIP_CALL( SCIPhashtableCreate(&hashtable, blkmem, hashtablesize,
2017  hashGetKeyLogicorcons, hashKeyEqLogicorcons, hashKeyValLogicorcons, (void*) scip) );
2018 
2019  /* check all constraints in the given set for redundancy */
2020  for( c = 0; c < nconss; ++c )
2021  {
2022  SCIP_CONS* cons0;
2023  SCIP_CONS* cons1;
2024  SCIP_CONSDATA* consdata0;
2025 
2026  cons0 = conss[c];
2027 
2028  if( !SCIPconsIsActive(cons0) || SCIPconsIsModifiable(cons0) )
2029  continue;
2030 
2031  consdata0 = SCIPconsGetData(cons0);
2032  /* sort the constraint */
2033  consdataSort(consdata0);
2034  assert(consdata0->sorted);
2035 
2036  /* get constraint from current hash table with same variables as cons0 */
2037  cons1 = (SCIP_CONS*)(SCIPhashtableRetrieve(hashtable, (void*)cons0));
2038 
2039  if( cons1 != NULL )
2040  {
2041 #ifndef NDEBUG
2042  SCIP_CONSDATA* consdata1;
2043 #endif
2044 
2045  assert(SCIPconsIsActive(cons1));
2046  assert(!SCIPconsIsModifiable(cons1));
2047 
2048 #ifndef NDEBUG
2049  consdata1 = SCIPconsGetData(cons1);
2050 #endif
2051  assert(consdata1 != NULL);
2052  assert(consdata0->nvars >= 1 && consdata0->nvars == consdata1->nvars);
2053 
2054  assert(consdata0->sorted && consdata1->sorted);
2055  assert(consdata0->vars[0] == consdata1->vars[0]);
2056 
2057  /* update flags of constraint which caused the redundancy s.t. nonredundant information doesn't get lost */
2058  /* coverity[swapped_arguments] */
2059  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons0) );
2060 
2061  /* delete consdel */
2062  SCIP_CALL( SCIPdelCons(scip, cons0) );
2063  (*ndelconss)++;
2064 
2065  /* update the first changed constraint to begin the next aggregation round with */
2066  if( consdata0->changed && SCIPconsGetPos(cons1) < *firstchange )
2067  *firstchange = SCIPconsGetPos(cons1);
2068 
2069  assert(SCIPconsIsActive(cons1));
2070  }
2071  else
2072  {
2073  /* no such constraint in current hash table: insert cons0 into hash table */
2074  SCIP_CALL( SCIPhashtableInsert(hashtable, (void*) cons0) );
2075  }
2076  }
2077 
2078  /* free hash table */
2079  SCIPhashtableFree(&hashtable);
2080 
2081  return SCIP_OKAY;
2082 }
2083 
2084 /** removes the redundant second constraint and updates the flags of the first one */
2085 static
2087  SCIP* scip, /**< SCIP data structure */
2088  SCIP_CONS* cons0, /**< constraint that should stay */
2089  SCIP_CONS* cons1, /**< constraint that should be deleted */
2090  int* ndelconss /**< pointer to count number of deleted constraints */
2091  )
2092 {
2093  assert(ndelconss != NULL);
2094 
2095  SCIPdebugMsg(scip, " -> removing logicor constraint <%s> which is redundant to <%s>\n",
2096  SCIPconsGetName(cons1), SCIPconsGetName(cons0));
2097  SCIPdebugPrintCons(scip, cons0, NULL);
2098  SCIPdebugPrintCons(scip, cons1, NULL);
2099 
2100  /* update flags of cons0 */
2101  SCIP_CALL( SCIPupdateConsFlags(scip, cons0, cons1) );
2102 
2103  /* delete cons1 */
2104  SCIP_CALL( SCIPdelCons(scip, cons1) );
2105  (*ndelconss)++;
2106 
2107  return SCIP_OKAY;
2108 }
2109 
2110 
2111 /** compute and return a signature for given variables */
2112 static
2113 unsigned int calcSignature(
2114  SCIP_VAR** vars, /**< variables to calculate the signature for */
2115  int nvars /**< number of variables to calculate the signature for */
2116  )
2117 {
2118  unsigned int signature = 0;
2119  int v;
2120 
2121  assert(vars != NULL);
2122  assert(nvars >= 1);
2123 
2124  for( v = nvars - 1; v >= 0; --v )
2125  {
2126  signature |= ((unsigned int)1 << ((unsigned int)SCIPvarGetIndex(vars[v]) % (sizeof(unsigned int) * 8)));
2127  }
2128 
2129  return signature;
2130 }
2131 
2132 /** compute the constraint signature which is used to detect constraints, that contain potentially the same set of
2133  * variables
2134  */
2135 static
2137  SCIP_CONSDATA* consdata /**< logicor constraint data */
2138  )
2139 {
2140  if( consdata->validsignature )
2141  return;
2142 
2143  consdata->signature = calcSignature(consdata->vars, consdata->nvars);
2144  consdata->validsignature = TRUE;
2145 }
2146 
2147 /** remove a constraint from the column representation */
2148 static
2150  SCIP_CONS* cons, /**< logicor constraint */
2151  SCIP_HASHMAP* varstopos, /**< map for mapping variables to positions in the occurlist */
2152  SCIP_CONS*** occurlist, /**< column representation of logicor constraints */
2153  int* noccurlistentries, /**< arrray with number of constraints for each variable in the occurlist */
2154  int occurlistlength /**< number of columns in the occurlist */
2155  )
2156 {
2157  SCIP_VAR** vars;
2158  SCIP_VAR* var;
2159  SCIP_CONSDATA* consdata;
2160  int nvars;
2161  int pos;
2162  int v;
2163  int l;
2164 
2165  assert(cons != NULL);
2166  assert(SCIPconsIsActive(cons));
2167  assert(varstopos != NULL);
2168  assert(occurlist != NULL);
2169  assert(noccurlistentries != NULL);
2170 
2171  consdata = SCIPconsGetData(cons);
2172  assert(consdata != NULL);
2173 
2174  nvars = consdata->nvars;
2175  assert(nvars >= 1);
2176  vars = consdata->vars;
2177  assert(vars != NULL);
2178 
2179  /* remove constraint from list */
2180  for( v = nvars - 1; v >= 0; --v )
2181  {
2182  var = vars[v];
2183 
2184  assert(SCIPhashmapExists(varstopos, (void*) var));
2185 
2186  pos = SCIPhashmapGetImageInt(varstopos, (void*)var);
2187  assert(0 < pos && pos <= occurlistlength);
2188 
2189  --pos;
2190 
2191  /* remove for each variable one corresponding entry */
2192  for( l = noccurlistentries[pos] - 1; l >= 0; --l )
2193  {
2194  if( occurlist[pos][l] == cons )
2195  {
2196  --noccurlistentries[pos];
2197  assert(noccurlistentries[pos] >= 0);
2198 
2199  occurlist[pos][l] = occurlist[pos][noccurlistentries[pos]];
2200  break;
2201  }
2202  }
2203  assert(l >= 0);
2204  }
2205 }
2206 
2207 /** determine shortest constraint list in column representation */
2208 static
2210  SCIP_VAR** vars, /**< variables to find the shortestlist for */
2211  int nvars, /**< number of variables */
2212  SCIP_HASHMAP* varstopos, /**< map for mapping variables to positions in the occurlist */
2213  SCIP_CONS*** occurlist, /**< column representation of logicor constraints */
2214  int* noccurlistentries, /**< arrray with number of constraints for each variable in the occurlist */
2215  int occurlistlength, /**< number of columns in the occurlist */
2216  int* nentries, /**< pointer to store the number of entries in the shortest list */
2217  SCIP_CONS*** shortestlist /**< pointer to store smallest array with constraints */
2218  )
2219 {
2220  SCIP_VAR* var;
2221  int pos;
2222  int v;
2223 
2224  assert(vars != 0);
2225  assert(nvars >= 1);
2226  assert(varstopos != NULL);
2227  assert(occurlist != NULL);
2228  assert(noccurlistentries != NULL);
2229  assert(nentries != NULL);
2230  assert(shortestlist != NULL);
2231 
2232  *nentries = INT_MAX;
2233  *shortestlist = NULL;
2234 
2235  /* find the shortest list */
2236  for( v = nvars - 1; v >= 0; --v )
2237  {
2238  var = vars[v];
2239  assert(var != NULL);
2240 
2241  /* it might be that a variable is not yet put into the occurlist, then this constraint cannot cover another */
2242  if( !SCIPhashmapExists(varstopos, (void*) var) )
2243  {
2244  *nentries = 0;
2245  return;
2246  }
2247 
2248  pos = SCIPhashmapGetImageInt(varstopos, (void*)var);
2249  assert(0 < pos && pos <= occurlistlength);
2250 
2251  --pos;
2252 
2253  /* remember the shortest list */
2254  if( noccurlistentries[pos] < *nentries )
2255  {
2256  *nentries = noccurlistentries[pos];
2257  *shortestlist = occurlist[pos];
2258  }
2259  }
2260 }
2261 
2262 /** run a pairwise comparison for detecting subset-constraints of other constraint while using a signature */
2263 static
2265  SCIP* scip, /**< SCIP data structure */
2266  SCIP_CONS* cons, /**< logicor constraint to check if it covers another */
2267  SCIP_HASHMAP* varstopos, /**< map for mapping variables to positions in the occurlist */
2268  SCIP_CONS*** occurlist, /**< column representation of logicor constraints */
2269  int* noccurlistentries, /**< arrray with number of constraints for each variable in the occurlist */
2270  int occurlistlength, /**< number of columns in the occurlist */
2271  int* ndelconss /**< pointer to store the number of deleted constraints */
2272  )
2273 {
2274  SCIP_CONS** shortestlist;
2275  SCIP_VAR** vars;
2276  SCIP_CONS* cons1;
2277  SCIP_VAR* var;
2278  SCIP_CONSDATA* consdata;
2279  int nentries;
2280  int c;
2281  int v;
2282 
2283  assert(scip != NULL);
2284  assert(cons != NULL);
2285  assert(SCIPconsIsActive(cons));
2286  assert(!SCIPconsIsModifiable(cons));
2287  assert(varstopos != NULL);
2288  assert(occurlist != NULL);
2289  assert(noccurlistentries != NULL);
2290  assert(ndelconss != NULL);
2291 
2292  consdata = SCIPconsGetData(cons);
2293  assert(consdata != NULL);
2294  assert(consdata->nvars > 1);
2295  assert(consdata->validsignature);
2296  assert(consdata->sorted);
2297 
2298  vars = consdata->vars;
2299  assert(vars != NULL);
2300 
2301  /* determine shortest column */
2302  findShortestOccurlist(vars, consdata->nvars, varstopos, occurlist, noccurlistentries, occurlistlength, &nentries, &shortestlist);
2303 
2304  /* one variable which does not appear in the column representation anymore */
2305  if( nentries == 0 )
2306  return SCIP_OKAY;
2307 
2308  assert(shortestlist != NULL);
2309  assert(0 < nentries);
2310 
2311  /* check all constraints in the shortest list for coverage */
2312  for( c = nentries - 1; c >= 0; --c )
2313  {
2314  cons1 = shortestlist[c];
2315  assert(cons1 != NULL);
2316  assert(!SCIPconsIsModifiable(cons1));
2317  assert(SCIPconsIsActive(cons1));
2318 
2319  if( cons != cons1 )
2320  {
2321  SCIP_CONSDATA* consdata1 = SCIPconsGetData(cons1);
2322  assert(consdata1 != NULL);
2323  assert(consdata1->nvars >= consdata->nvars);
2324 
2325  /* constraints with the same length cannot be covered and same constraints are removed in
2326  * detectRedundantConstraints()
2327  */
2328  if( consdata1->nvars == consdata->nvars )
2329  continue;
2330 
2331  assert(consdata->validsignature);
2332  assert(consdata->sorted);
2333  assert(consdata1->validsignature);
2334  assert(consdata1->sorted);
2335 
2336  if( (consdata->signature & (~consdata1->signature)) == 0 )
2337  {
2338  SCIP_VAR* var1;
2339  int v1;
2340 
2341  v = 0;
2342  v1 = 0;
2343 
2344  while( v < consdata->nvars && v1 < consdata1->nvars )
2345  {
2346  int comp;
2347 
2348  var = vars[v];
2349  var1 = consdata1->vars[v1];
2350 
2351  comp = SCIPvarCompare(var, var1);
2352 
2353  if( comp == 0 )
2354  {
2355  ++v;
2356  ++v1;
2357  }
2358  else if( comp > 0 )
2359  ++v1;
2360  else
2361  break;
2362  }
2363 
2364  /* cons1 is covered by cons */
2365  if( v == consdata->nvars )
2366  {
2367  /* remove cons1 from columns representation */
2368  removeConsFromOccurList(cons1, varstopos, occurlist, noccurlistentries, occurlistlength);
2369 
2370  /* delete redundant constraint and update constraint flags if necessary */
2371  SCIP_CALL( removeRedundantCons(scip, cons, cons1, ndelconss) );
2372  }
2373  }
2374  }
2375  }
2376 
2377  return SCIP_OKAY;
2378 }
2379 
2380 /** compararer for sorting constraints after their number of variables */
2381 static
2382 SCIP_DECL_SORTPTRCOMP(conssLogicorComp)
2383 {
2384  SCIP_CONSDATA* consdata1;
2385  SCIP_CONSDATA* consdata2;
2386 
2387  assert(elem1 != NULL);
2388  assert(elem2 != NULL);
2389 
2390  consdata1 = SCIPconsGetData((SCIP_CONS*) elem1);
2391  consdata2 = SCIPconsGetData((SCIP_CONS*) elem2);
2392 
2393  assert(consdata1 != NULL);
2394  assert(consdata2 != NULL);
2395 
2396  return consdata1->nvars - consdata2->nvars;
2397 }
2398 
2399 /** add a constraint to the column representation */
2400 static
2402  SCIP* scip, /**< SCIP data structure */
2403  SCIP_CONS* cons, /**< logicor constraint */
2404  SCIP_HASHMAP* varstopos, /**< map for mapping variables to positions in the occurlist */
2405  SCIP_CONS*** occurlist, /**< column representation of logicor constraints */
2406  int* noccurlistentries, /**< arrray with number of constraints for each variable in the occurlist */
2407  int* occurlistsizes, /**< array of sizes for each variable in the occurlist */
2408  int* occurlistlength, /**< number of columns in the occurlist */
2409  int occurlistsize /**< size of occurlist */
2410  )
2411 {
2412  SCIP_VAR** vars;
2413  SCIP_VAR* var;
2414  SCIP_CONSDATA* consdata;
2415  int pos;
2416  int v;
2417 
2418  assert(scip != NULL);
2419  assert(cons != NULL);
2420  assert(SCIPconsIsActive(cons));
2421  assert(varstopos != NULL);
2422  assert(occurlist != NULL);
2423  assert(noccurlistentries != NULL);
2424  assert(occurlistsizes != NULL);
2425  assert(occurlistlength != NULL);
2426  assert(*occurlistlength <= occurlistsize);
2427 
2428  consdata = SCIPconsGetData(cons);
2429  assert(consdata != NULL);
2430  assert(consdata->nvars > 1);
2431 
2432  vars = consdata->vars;
2433  assert(vars != NULL);
2434 
2435  for( v = consdata->nvars - 1; v >= 0; --v )
2436  {
2437  var = vars[v];
2438  assert(var != NULL);
2440 
2441  /* check if the variable is not yet put into the occurlist */
2442  if( !SCIPhashmapExists(varstopos, (void*) var) )
2443  {
2444  pos = *occurlistlength;
2445  assert(pos <= occurlistsize);
2446 
2447  /* occurlist values need to be clear */
2448  assert(occurlist[pos] == NULL);
2449  assert(noccurlistentries[pos] == 0);
2450  assert(occurlistsizes[pos] == 0);
2451 
2452  /* allocate memory */
2454  occurlistsizes[pos] = SCIPvarGetNLocksDownType(var, SCIP_LOCKTYPE_MODEL) + 1;
2455  SCIP_CALL( SCIPallocBufferArray(scip, &(occurlist[pos]), occurlistsizes[pos]) ); /*lint !e866*/
2456 
2457  /* put constraint in list of current variable */
2458  occurlist[pos][noccurlistentries[pos]] = cons;
2459  ++(noccurlistentries[pos]);
2460 
2461  /* add new variable to map */
2462  SCIP_CALL( SCIPhashmapInsertInt(varstopos, var, pos + 1) );
2463 
2464  ++(*occurlistlength);
2465  }
2466  else
2467  {
2468  pos = SCIPhashmapGetImageInt(varstopos, (void*)var);
2469  assert(0 < pos && pos <= *occurlistlength);
2470 
2471  --pos;
2472 
2473  assert(occurlist[pos] != NULL);
2474  assert(occurlistsizes[pos] > 0);
2475 
2476  /* do we need to resize the array */
2477  if( noccurlistentries[pos] == occurlistsizes[pos] )
2478  {
2479  occurlistsizes[pos] = SCIPcalcMemGrowSize(scip, occurlistsizes[pos] + 1);
2480  assert(occurlistsizes[pos] > noccurlistentries[pos] && occurlistsizes[pos] < INT_MAX);
2481 
2482  /* resize occurlist for current variable */
2483  SCIP_CALL( SCIPreallocBufferArray(scip, &(occurlist[pos]), occurlistsizes[pos]) ); /*lint !e866*/
2484  }
2485  assert(noccurlistentries[pos] < occurlistsizes[pos]);
2486 
2487  /* put constraint in list of current variable */
2488  occurlist[pos][noccurlistentries[pos]] = cons;
2489  ++(noccurlistentries[pos]);
2490  }
2491  }
2492 
2493  return SCIP_OKAY;
2494 }
2495 
2496 /** run a pairwise comparison for the given variables against all constraits to detect redundant non-zeros in these
2497  * constraints
2498  */
2499 static
2501  SCIP* scip, /**< SCIP data structure */
2502  SCIP_CONS* cons, /**< logicor constraint to check if it covers another */
2503  SCIP_VAR* artvar, /**< artificial negated variable of constraint */
2504  int artpos, /**< position to replace constraint variable with artvar */
2505  SCIP_HASHMAP* varstopos, /**< map for mapping variables to positions in the occurlist */
2506  SCIP_CONS*** occurlist, /**< column representation of logicor constraints */
2507  int* noccurlistentries, /**< number of constraints for each variable in the occurlist */
2508  int occurlistlength, /**< number of columns in the occurlist */
2509  SCIP_EVENTHDLR* eventhdlr, /**< event handler */
2510  int* nchgcoefs, /**< pointer to store the number of deleted non-zeros */
2511  SCIP_Bool* deleted /**< pointer to store if cons will be deleted */
2512  )
2513 {
2514  SCIP_CONS** shortestlist;
2515  SCIP_VAR** vars;
2516  SCIP_CONS* cons1;
2517  SCIP_VAR* oldvar;
2518  SCIP_VAR* var;
2519  SCIP_CONSDATA* consdata;
2520  unsigned int signature;
2521  int nentries;
2522  int nvars;
2523  int c;
2524  int v;
2525  int pos;
2526 
2527  assert(scip != NULL);
2528  assert(cons != NULL);
2529  assert(artvar != NULL);
2530  assert(SCIPconsIsActive(cons));
2531  assert(!SCIPconsIsModifiable(cons));
2532  assert(varstopos != NULL);
2533  assert(SCIPhashmapExists(varstopos, (void*) artvar));
2534  assert(occurlist != NULL);
2535  assert(noccurlistentries != NULL);
2536  assert(nchgcoefs != NULL);
2537  assert(deleted != NULL);
2538 
2539  consdata = SCIPconsGetData(cons);
2540  assert(consdata != NULL);
2541  assert(consdata->sorted);
2542 
2543  nvars = consdata->nvars;
2544  assert(nvars > 1);
2545  assert(0 <= artpos && artpos < nvars);
2546 
2547  vars = consdata->vars;
2548  assert(vars != NULL);
2549 
2550  *deleted = FALSE;
2551 
2552  /* temporary exchange the variable for finding the shortest list */
2553  oldvar = vars[artpos];
2554  assert(oldvar == SCIPvarGetNegatedVar(artvar));
2555  vars[artpos] = artvar;
2556 
2557  /* determine shortest column */
2558  findShortestOccurlist(vars, nvars, varstopos, occurlist, noccurlistentries, occurlistlength, &nentries, &shortestlist);
2559 
2560  /* correct exchanged variable with constraint variables */
2561  vars[artpos] = oldvar;
2562 
2563  /* one variable which does not appear in the column representation anymore */
2564  if( nentries == 0 )
2565  return SCIP_OKAY;
2566 
2567  assert(shortestlist != NULL);
2568  assert(0 < nentries);
2569 
2570  /* temporary exchange the variable for calculating a valid signature */
2571  oldvar = vars[artpos];
2572  vars[artpos] = artvar;
2573  signature = calcSignature(vars, nvars);
2574 
2575  /* correct exchanged variable with constraint variables */
2576  vars[artpos] = oldvar;
2577 
2578  /* check all constraints in the shortest list for coverage */
2579  for( c = nentries - 1; c >= 0; --c )
2580  {
2581  cons1 = shortestlist[c];
2582  assert(cons1 != NULL);
2583  assert(!SCIPconsIsModifiable(cons1));
2584 
2585  if( !SCIPconsIsActive(cons1) )
2586  continue;
2587 
2588  if( cons != cons1 )
2589  {
2590  SCIP_CONSDATA* consdata1 = SCIPconsGetData(cons1);
2591  assert(consdata1 != NULL);
2592 
2593  /* constraints with the less variables cannot be covered */
2594  if( consdata1->nvars < nvars )
2595  continue;
2596 
2597  pos = -1;
2598 
2599  assert(consdata->sorted);
2600  assert(consdata->merged);
2601  assert(consdata1->validsignature);
2602  assert(consdata1->sorted);
2603  assert(consdata1->merged);
2604 
2605  if( (signature & (~consdata1->signature)) == 0 )
2606  {
2607  SCIP_VAR* var1;
2608  int v1;
2609 
2610  v = 0;
2611  v1 = 0;
2612 
2613  while( v < nvars && v1 < consdata1->nvars )
2614  {
2615  int comp;
2616 
2617  /* skip position of artificial variable */
2618  if( artpos == v )
2619  {
2620  ++v;
2621  continue;
2622  }
2623 
2624  var1 = consdata1->vars[v1];
2625 
2626  /* did we find the artificial variable in cons1 */
2627  if( artvar == var1 )
2628  {
2629  /* remember of possible redundant variable */
2630  assert(pos == -1);
2631  pos = v1;
2632 
2633  ++v1;
2634  continue;
2635  }
2636 
2637  var = vars[v];
2638  comp = SCIPvarCompare(var, var1);
2639 
2640  /* check if the cons1 can still be covered */
2641  if( comp == 0 )
2642  {
2643  ++v;
2644  ++v1;
2645  }
2646  else if( comp > 0 )
2647  ++v1;
2648  else
2649  break;
2650  }
2651 
2652  /* cons1 is might be covered by the changed constraints cons, meaning that we might remove the artvar from
2653  * cons1
2654  */
2655  if( v == nvars )
2656  {
2657  int l;
2658 
2659  /* if the artificial variable was not yet found, search over the rear variables in constraint cons1 */
2660  if( pos == -1 )
2661  {
2662  while( v1 < consdata1->nvars )
2663  {
2664  if( artvar == consdata1->vars[v1] )
2665  {
2666  /* remember of possible redundant variable */
2667  pos = v1;
2668  break;
2669  }
2670  ++v1;
2671  }
2672  }
2673 
2674  if( pos >= 0 )
2675  {
2676  int conspos;
2677 
2678  assert(pos < consdata1->nvars);
2679  assert(artvar == consdata1->vars[pos]);
2680 
2681  /* remove redudant entry in cons1 */
2682  SCIPdebugMsg(scip, "variable %s in logicor constraint <%s> is redundant and will be removed (used constraint %s)\n",
2683  SCIPvarGetName(artvar), SCIPconsGetName(cons1), SCIPconsGetName(cons));
2684  SCIPdebugPrintCons(scip, cons1, NULL);
2685  conspos = pos;
2686 
2687  if( consdata1->nvars > nvars )
2688  {
2689  pos = SCIPhashmapGetImageInt(varstopos, (void*)artvar);
2690  assert(0 < pos && pos <= occurlistlength);
2691 
2692  --pos;
2693 
2694  /* remove corresponding entry in column representation */
2695  for( l = noccurlistentries[pos] - 1; l >= 0; --l )
2696  {
2697  if( occurlist[pos][l] == cons1 )
2698  {
2699  --noccurlistentries[pos];
2700  assert(noccurlistentries[pos] >= 0);
2701 
2702  occurlist[pos][l] = occurlist[pos][noccurlistentries[pos]];
2703  break;
2704  }
2705  }
2706  assert(l >= 0);
2707  }
2708  else
2709  {
2710  assert(consdata1->nvars == nvars);
2711 
2712  /* delete cons */
2713  SCIPdebugMsg(scip, "logicor constraint <%s> is redundant due to constraint <%s> after removing variable <%s>\n",
2714  SCIPconsGetName(cons), SCIPconsGetName(cons1), SCIPvarGetName(artvar));
2715 
2716  /* remove cons from columns representation */
2717  removeConsFromOccurList(cons, varstopos, occurlist, noccurlistentries, occurlistlength);
2718 
2719  /* update flags of cons1 */
2720  SCIP_CALL( SCIPupdateConsFlags(scip, cons1, cons) );
2721 
2722  SCIP_CALL( SCIPdelCons(scip, cons) );
2723  *deleted = TRUE;
2724  }
2725 
2726  /* remove variable */
2727  SCIP_CALL( delCoefPos(scip, cons1, eventhdlr, conspos) );
2728  ++(*nchgcoefs);
2729  consdataSort(consdata1);
2730  consdataCalcSignature(consdata1);
2731 
2732  if( *deleted )
2733  return SCIP_OKAY;
2734  }
2735  }
2736  }
2737  }
2738  }
2739 
2740  return SCIP_OKAY;
2741 }
2742 
2743 /** find and remove redundant non-zero entries */
2744 static
2746  SCIP* scip, /**< SCIP data structure */
2747  SCIP_CONS** conss, /**< sorted array of logicor constraint */
2748  int nconss, /**< number of sorted constraints */
2749  SCIP_HASHMAP* varstopos, /**< map for mapping variables to positions in the occurlist */
2750  SCIP_CONS*** occurlist, /**< column representation of logicor constraints */
2751  int* noccurlistentries, /**< number of constraints for each variable in the occurlist */
2752  int occurlistlength, /**< number of columns in the occurlist */
2753  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
2754  int* ndelconss, /**< pointer to store the number of deleted constraints */
2755  int* nchgcoefs /**< pointer to store the number of remove coefficients */
2756  )
2757 {
2758  SCIP_VAR** vars;
2759  SCIP_CONSDATA* consdata;
2760  SCIP_CONS* cons;
2761  SCIP_VAR* artvar;
2762  int nvars;
2763  int c;
2764  int v;
2765 
2766  assert(scip != NULL);
2767  assert(conss != NULL || nconss == 0);
2768  assert(varstopos != NULL);
2769  assert(occurlist != NULL);
2770  assert(noccurlistentries != NULL);
2771  assert(eventhdlr != NULL);
2772  assert(ndelconss != NULL);
2773  assert(nchgcoefs != NULL);
2774 
2775  if( nconss == 0 )
2776  return SCIP_OKAY;
2777 
2778  assert(conss != NULL);
2779 
2780  for( c = 0; c < nconss; ++c )
2781  {
2782  cons = conss[c];
2783  assert(cons != NULL);
2784  assert(!SCIPconsIsModifiable(cons));
2785 
2786  if( !SCIPconsIsActive(cons) )
2787  continue;
2788 
2789  consdata = SCIPconsGetData(cons);
2790  assert(consdata != NULL);
2791 
2792  nvars = consdata->nvars;
2793  assert(nvars >= 1);
2794 
2795  if( nvars == 1 )
2796  continue;
2797 
2798  vars = consdata->vars;
2799  assert(vars != NULL);
2800 
2801  for( v = nvars - 1; v >= 0; --v )
2802  {
2803  artvar = SCIPvarGetNegatedVar(vars[v]);
2804 
2805  if( artvar != NULL && SCIPhashmapExists(varstopos, (void*) artvar) )
2806  {
2807  SCIP_Bool deleted;
2808 
2809  /* detect and remove redundant non-zero entries */
2810  /* @todo: improve this algorithm by using the information that a constraint variables does not appaer in any
2811  * other constraint, which means that only this variable needs to be negated to check for redundant
2812  * non-zeros, therefor change also findShortestOccurlist() to return the corresponding
2813  * variable/position
2814  */
2815  SCIP_CALL( removeRedundantNonZeros(scip, cons, artvar, v, varstopos, occurlist, noccurlistentries,
2816  occurlistlength, eventhdlr, nchgcoefs, &deleted) );
2817 
2818  if( deleted )
2819  {
2820  assert(SCIPconsIsDeleted(cons));
2821  ++(*ndelconss);
2822  break;
2823  }
2824  else
2825  assert(SCIPconsIsActive(cons));
2826  }
2827  }
2828  }
2829 
2830  return SCIP_OKAY;
2831 }
2832 
2833 
2834 /** prepares a constraint by removing fixings and merge it */
2835 static
2837  SCIP* scip, /**< SCIP data structure */
2838  SCIP_CONS* cons, /**< logic or constraint */
2839  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
2840  unsigned char** entries, /**< array to store whether two positions in constraints represent the same variable */
2841  int* nentries, /**< pointer for array size, if array will be to small it's corrected */
2842  SCIP_Bool* redundant, /**< returns whether a variable fixed to one exists in the constraint */
2843  int* nfixedvars, /**< pointer to count number of fixings */
2844  int* nchgcoefs, /**< pointer to count number of changed/deleted coefficients */
2845  int* ndelconss, /**< pointer to count number of deleted constraints */
2846  SCIP_Bool* cutoff /**< pointer to store, if cut off appeared */
2847  )
2848 {
2849  SCIP_CONSDATA* consdata;
2850 
2851  assert(scip != NULL);
2852  assert(cons != NULL);
2853  assert(!SCIPconsIsDeleted(cons));
2854  assert(eventhdlr != NULL);
2855  assert(*entries != NULL);
2856  assert(nentries != NULL);
2857  assert(redundant != NULL);
2858  assert(nfixedvars != NULL);
2859  assert(nchgcoefs != NULL);
2860  assert(ndelconss != NULL);
2861  assert(redundant != NULL);
2862 
2863  consdata = SCIPconsGetData(cons);
2864  assert(consdata != NULL);
2865  assert(consdata->nvars > 0);
2866 
2867  *redundant = FALSE;
2868 
2869  /* remove old fixings */
2870  if( !consdata->presolved )
2871  {
2872  /* remove all variables that are fixed to zero, check redundancy due to fixed-to-one variable */
2873  SCIP_CALL( applyFixings(scip, cons, eventhdlr, redundant, nchgcoefs, NULL, NULL) );
2874  }
2875 
2876  if( !*redundant )
2877  {
2878  /* merge constraint */
2879  SCIP_CALL( mergeMultiples(scip, cons, eventhdlr, entries, nentries, redundant, nchgcoefs) );
2880  }
2881 
2882  if( *redundant )
2883  {
2884  SCIP_CALL( SCIPdelCons(scip, cons) );
2885  ++(*ndelconss);
2886 
2887  return SCIP_OKAY;
2888  }
2889 
2890  if( consdata->nvars == 0 )
2891  {
2892  *cutoff = TRUE;
2893  }
2894  else if( consdata->nvars == 1 )
2895  {
2896  SCIP_Bool infeasible;
2897  SCIP_Bool fixed;
2898 
2899  SCIPdebugMsg(scip, " -> fix last remaining variable and delete constraint\n");
2900 
2901  SCIP_CALL( SCIPfixVar(scip, consdata->vars[0], 1.0, &infeasible, &fixed) );
2902  assert(!infeasible);
2903  assert(fixed);
2904  ++(*nfixedvars);
2905 
2906  SCIP_CALL( SCIPdelCons(scip, cons) );
2907  ++(*ndelconss);
2908 
2909  *redundant = TRUE;
2910  }
2911  consdata->presolved = TRUE;
2912 
2913  return SCIP_OKAY;
2914 }
2915 
2916 
2917 /** find covered/subsumed constraints and redundant non-zero entries
2918  *
2919  * covered:
2920  * e.g.: c1: x1 + x2 + x3 >= 1
2921  * c2: x1 + x2 + x3 + x4 >= 1
2922  *
2923  * strengthen:
2924  * e.g.: c1: x1 + x2 + x3 >= 1
2925  * c2: x1 + x2 + ~x3 + x4 >= 1
2926  *
2927  * => c2: x1 + x2 + x4 >= 1
2928  *
2929  * @see "Effective Preprocessing in SAT through Variable and Clause Elimination" by Niklas En and Armin Biere
2930  */
2931 static
2933  SCIP* scip, /**< SCIP data structure */
2934  SCIP_CONS** conss, /**< array of logicor constraints */
2935  int nconss, /**< number of logicor constraints */
2936  unsigned char** entries, /**< array to store whether two positions in constraints represent the same
2937  * variable */
2938  int* nentries, /**< pointer for array size, if array will be to small it's corrected */
2939  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
2940  SCIP_Bool usestrengthening, /**< should we try to strengthen constraints by removing superflous
2941  * non-zeros? */
2942  int* firstchange, /**< pointer to store first changed constraint */
2943  int* nfixedvars, /**< pointer to count number of fixings */
2944  int* ndelconss, /**< pointer to store the number of deleted constraints */
2945  int* nchgcoefs, /**< pointer to store the number of deleted coefficients */
2946  SCIP_Bool* cutoff /**< pointer to store, if cut off appeared */
2947  )
2948 {
2949  SCIP_CONS*** occurlist;
2950  SCIP_CONS** myconss;
2951  SCIP_HASHMAP* varstopos;
2952  SCIP_CONS* cons;
2953  SCIP_CONSDATA* consdata;
2954  int* noccurlistentries;
2955  int* occurlistsizes;
2956  SCIP_Bool redundant;
2957  SCIP_Bool conschanged;
2958  int lastnfixedvars;
2959  int nbinvars;
2960  int occurlistlength;
2961  int occurlistsize;
2962  int nmyconss;
2963  int nmaxvars;
2964  int c;
2965 
2966  assert(scip != NULL);
2967  assert(conss != NULL || nconss == 0);
2968  assert(entries != NULL);
2969  assert(*entries != NULL);
2970  assert(nentries != NULL);
2971  assert(eventhdlr != NULL);
2972  assert(firstchange != NULL);
2973  assert(0 <= *firstchange);
2974  assert(nfixedvars != NULL);
2975  assert(ndelconss != NULL);
2976  assert(nchgcoefs != NULL);
2977 
2978  if( *firstchange > nconss || nconss < 2 )
2979  return SCIP_OKAY;
2980 
2981  SCIPdebugMsg(scip, "starting removeRedundantConssAndNonzeros(), pairwise comparison to detect covered logicor constraints\n");
2982 
2983  /* copy constraints to re-order them */
2984  SCIP_CALL( SCIPduplicateBufferArray(scip, &myconss, conss, nconss) );
2985 
2986  nmyconss = nconss;
2987  lastnfixedvars = -1;
2988  while( *nfixedvars != lastnfixedvars )
2989  {
2990  lastnfixedvars = *nfixedvars;
2991  for( c = nconss - 1; c >= 0; --c )
2992  {
2993  cons = myconss[c];
2994  assert(cons != NULL);
2995 
2996  if( SCIPconsIsDeleted(cons) || SCIPconsIsModifiable(cons) )
2997  {
2998  myconss[c] = myconss[nmyconss - 1];
2999  --nmyconss;
3000 
3001  continue;
3002  }
3003 
3004  /* prepare constraint by removing fixings and merge it */
3005  SCIP_CALL( prepareCons(scip, cons, eventhdlr, entries, nentries, &redundant, nfixedvars, nchgcoefs, ndelconss, cutoff) );
3006 
3007  if( redundant )
3008  {
3009  assert(SCIPconsIsDeleted(cons));
3010  assert(!(*cutoff));
3011 
3012  myconss[c] = myconss[nmyconss - 1];
3013  --nmyconss;
3014 
3015  continue;
3016  }
3017 
3018  if( *cutoff )
3019  {
3020  SCIPfreeBufferArray(scip, &myconss);
3021 
3022  return SCIP_OKAY;
3023  }
3024 
3025  consdata = SCIPconsGetData(cons);
3026 
3027  /* sort the constraint */
3028  consdataSort(consdata);
3029 
3030  assert(consdata->nvars >= 2);
3031  }
3032  }
3033 
3034  SCIPsortPtr((void**)myconss, conssLogicorComp, nmyconss);
3035  assert(myconss[0] != NULL && myconss[nmyconss - 1] != NULL);
3036  assert(SCIPconsGetData(myconss[0]) != NULL && SCIPconsGetData(myconss[nmyconss - 1]) != NULL);
3037  assert(SCIPconsGetData(myconss[0])->nvars <= SCIPconsGetData(myconss[nmyconss - 1])->nvars);
3038 
3039  /* we can stop if strengthening is disabled and all constraints have the same amount of variables */
3040  if( !usestrengthening && SCIPconsGetData(myconss[0])->nvars == SCIPconsGetData(myconss[nmyconss - 1])->nvars )
3041  {
3042  SCIPfreeBufferArray(scip, &myconss);
3043 
3044  return SCIP_OKAY;
3045  }
3046 
3047  /* @note: in the following we have at least number of nonzeros in logicor constraints + three times two the number of
3048  * binary variables memory consumption + a map for variables to positions, we need this to get a column base
3049  * representation
3050  */
3051 
3052  /* get number of all possible(incl. implcit) binary variables and their negation */
3053  nbinvars = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
3054  occurlistsize = 2 * nbinvars;
3055 
3056  /* allocate memory for the column representation for each variable */
3057  SCIP_CALL( SCIPallocBufferArray(scip, &occurlist, occurlistsize) );
3058  BMSclearMemoryArray(occurlist, occurlistsize);
3059  SCIP_CALL( SCIPallocBufferArray(scip, &noccurlistentries, occurlistsize) );
3060  BMSclearMemoryArray(noccurlistentries, occurlistsize);
3061  SCIP_CALL( SCIPallocBufferArray(scip, &occurlistsizes, occurlistsize) );
3062  BMSclearMemoryArray(occurlistsizes, occurlistsize);
3063 
3064  /* create hashmap to map all occuring variables to a position in the list */
3065  SCIP_CALL( SCIPhashmapCreate(&varstopos, SCIPblkmem(scip), nmyconss) );
3066 
3067  /* get maximal number of variables over all logicor constraints */
3068  c = nmyconss - 1;
3069  cons = myconss[c];
3070  assert(cons != NULL);
3071  assert(SCIPconsIsActive(cons));
3072  consdata = SCIPconsGetData(cons);
3073  assert(consdata != NULL);
3074  nmaxvars = consdata->nvars;
3075 
3076  occurlistlength = 0;
3077  conschanged = FALSE;
3078 
3079  /* determine all constraints with the maximal number of variables and add them to the column representation */
3080  do
3081  {
3082  /* calculate hash-signature */
3083  consdataCalcSignature(consdata);
3084  assert(consdata->validsignature);
3085  conschanged = conschanged || consdata->changed;
3086  consdata->changed = FALSE;
3087 
3088  /* add constraint to column data structure */
3089  SCIP_CALL( addConsToOccurList(scip, cons, varstopos, occurlist, noccurlistentries, occurlistsizes, &occurlistlength, occurlistsize) );
3090 
3091  --c;
3092  if( c < 0 )
3093  break;
3094 
3095  cons = myconss[c];
3096  assert(cons != NULL);
3097  assert(SCIPconsIsActive(cons));
3098  consdata = SCIPconsGetData(cons);
3099  assert(consdata != NULL);
3100  }
3101  while( consdata->nvars == nmaxvars );
3102 
3103  /* remove covered constraints and left over constraints to the column representation */
3104  while( c >= 0 )
3105  {
3106  cons = myconss[c];
3107  assert(cons != NULL);
3108  assert(SCIPconsIsActive(cons));
3109  consdata = SCIPconsGetData(cons);
3110  assert(consdata != NULL);
3111 
3112  /* calculate hash-signature */
3113  consdataCalcSignature(consdata);
3114  assert(consdata->validsignature);
3115 
3116  /* search for covered constraints */
3117  if( conschanged || consdata->changed )
3118  {
3119  /* detect covered constraints
3120  *
3121  * e.g.: c1: x1 + x2 + x3 >= 1
3122  * c2: x1 + x2 + x3 + x4 >= 1
3123  *
3124  * => delete c2
3125  */
3126  SCIP_CALL( removeRedundantConss(scip, cons, varstopos, occurlist, noccurlistentries, occurlistlength, ndelconss) );
3127  assert(SCIPconsIsActive(cons));
3128 
3129  consdata->changed = FALSE;
3130  conschanged = TRUE;
3131  }
3132 
3133  /* add constraint to column data structure */
3134  SCIP_CALL( addConsToOccurList(scip, cons, varstopos, occurlist, noccurlistentries, occurlistsizes, &occurlistlength, occurlistsize) );
3135 
3136  --c;
3137  }
3138 
3139  /* strengthen constraint while removing non-zeros
3140  *
3141  * e.g.: c1: x1 + x2 + x3 >= 1
3142  * c2: x1 + x2 + ~x3 + x4 >= 1
3143  *
3144  * => c2: x1 + x2 + x4 >= 1
3145  *
3146  * special case:
3147  *
3148  * e.g.: c1: x1 + x2 + x3 >= 1
3149  * c2: x1 + x2 + ~x3 >= 1
3150  *
3151  * => delete c1; c2: x1 + x2 >= 1
3152  *
3153  */
3154  SCIP_CALL( strengthenConss(scip, myconss, nmyconss, varstopos, occurlist, noccurlistentries, occurlistlength, eventhdlr, ndelconss, nchgcoefs) );
3155 
3156  /* delete temporary memory in occurlist */
3157  for( --occurlistsize ; occurlistsize >= 0; --occurlistsize )
3158  {
3159  assert((occurlistsizes[occurlistsize] == 0) == (occurlist[occurlistsize] == NULL));
3160  SCIPfreeBufferArrayNull(scip, &(occurlist[occurlistsize]));
3161  }
3162 
3163  /* delete temporary memory */
3164  SCIPhashmapFree(&varstopos);
3165  SCIPfreeBufferArray(scip, &occurlistsizes);
3166  SCIPfreeBufferArray(scip, &noccurlistentries);
3167  SCIPfreeBufferArray(scip, &occurlist);
3168  SCIPfreeBufferArray(scip, &myconss);
3169 
3170  return SCIP_OKAY;
3171 }
3172 
3173 #define MAX_CONSLENGTH 200
3174 
3175 /** try to tighten constraints by reducing the number of variables in the constraints using implications and cliques,
3176  * also derive fixations through them, @see SCIPshrinkDisjunctiveVarSet()
3177  */
3178 static
3180  SCIP* scip, /**< SCIP data structure */
3181  SCIP_CONSHDLRDATA* conshdlrdata, /**< logic or constraint handler data */
3182  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
3183  SCIP_CONS** conss, /**< all constraints */
3184  int nconss, /**< number of constraints */
3185  unsigned char** entries, /**< array to store whether two positions in constraints represent the same
3186  * variable */
3187  int* nentries, /**< pointer for array size, if array will be to small it's corrected */
3188  int* nfixedvars, /**< pointer to count number of fixings */
3189  int* ndelconss, /**< pointer to count number of deleted constraints */
3190  int* nchgcoefs, /**< pointer to count number of changed/deleted coefficients */
3191  SCIP_Bool* cutoff /**< pointer to store, if cut off appeared */
3192  )
3193 {
3194  SCIP_VAR** probvars;
3195  SCIP_VAR* var;
3196  SCIP_Real* bounds;
3197  SCIP_Bool* boundtypes;
3198  SCIP_Bool* redundants;
3199  int nbinprobvars;
3200  int nredvars;
3201  int c;
3202  int v;
3203 
3204  assert(scip != NULL);
3205  assert(eventhdlr != NULL);
3206  assert(conss != NULL || nconss == 0);
3207  assert(entries != NULL);
3208  assert(*entries != NULL);
3209  assert(nentries != NULL);
3210  assert(nfixedvars != NULL);
3211  assert(ndelconss != NULL);
3212  assert(nchgcoefs != NULL);
3213 
3214  if( nconss == 0 )
3215  return SCIP_OKAY;
3216 
3217  assert(conss != NULL);
3218 
3219  if( SCIPgetNCliques(scip) == conshdlrdata->nlastcliquesshorten
3220  && SCIPgetNImplications(scip) == conshdlrdata->nlastimplsshorten )
3221  return SCIP_OKAY;
3222 
3223  conshdlrdata->nlastcliquesshorten = SCIPgetNCliques(scip);
3224  conshdlrdata->nlastimplsshorten = SCIPgetNImplications(scip);
3225 
3226  nbinprobvars = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
3227 
3228  /* allocate temporary memory */
3229  SCIP_CALL( SCIPallocBufferArray(scip, &probvars, nbinprobvars) );
3230  SCIP_CALL( SCIPallocBufferArray(scip, &bounds, nbinprobvars) );
3231  SCIP_CALL( SCIPallocBufferArray(scip, &boundtypes, nbinprobvars) );
3232  SCIP_CALL( SCIPallocCleanBufferArray(scip, &redundants, nbinprobvars) );
3233 
3234  for( c = nconss - 1; c >= 0; --c )
3235  {
3236  SCIP_Bool redundant = FALSE;
3237  SCIP_Bool glbinfeas = FALSE;
3238  SCIP_CONS* cons = conss[c];
3239  SCIP_CONSDATA* consdata;
3240 
3241  assert(cons != NULL);
3242 
3243  if( SCIPconsIsDeleted(cons) )
3244  continue;
3245 
3246  consdata = SCIPconsGetData(cons);
3247  assert(consdata != NULL);
3248 
3249  /* prepare constraint by removing fixings and merge it; we invalidate the presolved flag, because the calls to
3250  * SCIPcleanupCliques() in this loop may have lead to fixed variables that are not yet removed */
3251  consdata->presolved = FALSE;
3252  SCIP_CALL( prepareCons(scip, cons, eventhdlr, entries, nentries, &redundant, nfixedvars, nchgcoefs, ndelconss, cutoff) );
3253 
3254  if( redundant )
3255  {
3256  assert(SCIPconsIsDeleted(cons));
3257  continue;
3258  }
3259 
3260  if( *cutoff )
3261  goto TERMINATE;
3262 
3263  assert(consdata->nvars >= 2);
3264 
3265  /* do not try to shorten too long constraints */
3266  if( consdata->nvars > MAX_CONSLENGTH )
3267  continue;
3268 
3269  /* form necessary data */
3270  for( v = consdata->nvars - 1; v >= 0; --v)
3271  {
3272  var = consdata->vars[v];
3273  assert(var != NULL);
3275 
3276  if( SCIPvarIsActive(var) )
3277  {
3278  probvars[v] = var;
3279  bounds[v] = 1.0;
3280  boundtypes[v] = FALSE;
3281  }
3282  else
3283  {
3284  probvars[v] = SCIPvarGetNegationVar(var);
3285  bounds[v] = 0.0;
3286  boundtypes[v] = TRUE;
3287  }
3288  }
3289 
3290  SCIP_CALL( SCIPcleanupCliques(scip, cutoff) );
3291 
3292  if( *cutoff )
3293  goto TERMINATE;
3294 
3295  /* use implications and cliques to derive global fixings and to shrink the number of variables in this constraints */
3296  SCIP_CALL( SCIPshrinkDisjunctiveVarSet(scip, probvars, bounds, boundtypes, redundants, consdata->nvars, &nredvars,
3297  nfixedvars, &redundant, &glbinfeas, TRUE) );
3298 
3299  if( glbinfeas )
3300  {
3301  /* reset redundants array to FALSE */
3302  BMSclearMemoryArray(redundants, nbinprobvars);
3303  goto TERMINATE;
3304  }
3305 
3306  /* remove redundant constraint */
3307  if( redundant )
3308  {
3309  SCIP_CALL( SCIPdelCons(scip, cons) );
3310  ++(*ndelconss);
3311 
3312  /* reset redundants array to FALSE */
3313  BMSclearMemoryArray(redundants, consdata->nvars);
3314  continue;
3315  }
3316 
3317  /* remove redundant variables */
3318  if( nredvars > 0 )
3319  {
3320  for( v = consdata->nvars - 1; v >= 0; --v )
3321  {
3322  if( redundants[v] )
3323  {
3324  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
3325 
3326  /* reset entry to FALSE */
3327  redundants[v] = FALSE;
3328  }
3329  }
3330  *nchgcoefs += nredvars;
3331 
3332  /* if only one variable is left over fix it */
3333  if( consdata->nvars == 1 )
3334  {
3335  SCIP_Bool infeasible;
3336  SCIP_Bool fixed;
3337 
3338  SCIPdebugMsg(scip, " -> fix last remaining variable and delete constraint\n");
3339 
3340  SCIP_CALL( SCIPfixVar(scip, consdata->vars[0], 1.0, &infeasible, &fixed) );
3341  assert(!infeasible);
3342  assert(fixed);
3343  ++(*nfixedvars);
3344 
3345  SCIP_CALL( SCIPdelCons(scip, cons) );
3346  ++(*ndelconss);
3347  }
3348  /* @todo might also upgrade a two variable constraint to a set-packing constraint */
3349  }
3350  }
3351 
3352  /* invalidate the presolved flags, because the calls to SCIPcleanupCliques() may have lead to fixed variables that
3353  * are not yet removed */
3354  for( c = nconss - 1; c >= 0; --c )
3355  {
3356  SCIP_CONS* cons = conss[c];
3357  SCIP_CONSDATA* consdata;
3358 
3359  assert(cons != NULL);
3360 
3361  consdata = SCIPconsGetData(cons);
3362  assert(consdata != NULL);
3363 
3364  consdata->presolved = FALSE;
3365  }
3366 
3367  TERMINATE:
3368  /* free temporary memory */
3369  SCIPfreeCleanBufferArray(scip, &redundants);
3370  SCIPfreeBufferArray(scip, &boundtypes);
3371  SCIPfreeBufferArray(scip, &bounds);
3372  SCIPfreeBufferArray(scip, &probvars);
3373 
3374  return SCIP_OKAY;
3375 }
3376 
3377 #define MAXCOMPARISONS 1000000
3378 
3379 /** try to find a negated clique in a constraint which makes this constraint redundant but we need to keep the negated
3380  * clique information alive, so we create a corresponding set-packing constraint
3381  */
3382 static
3384  SCIP* scip, /**< SCIP data structure */
3385  SCIP_CONSHDLR* conshdlr, /**< logicor constraint handler */
3386  SCIP_CONSHDLR* conshdlrsetppc, /**< setppc constraint handler, or NULL */
3387  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
3388  SCIP_CONS** conss, /**< all constraints */
3389  int nconss, /**< number of constraints */
3390  unsigned char** entries, /**< array to store whether two positions in constraints represent the same
3391  * variable */
3392  int* nentries, /**< pointer for array size, if array will be to small it's corrected */
3393  int* nfixedvars, /**< pointer to count number of fixings */
3394  int* ndelconss, /**< pointer to count number of deleted constraints */
3395  int* nupgdconss, /**< pointer to count number of upgraded constraints */
3396  int* nchgcoefs, /**< pointer to count number of changed/deleted coefficients */
3397  SCIP_Bool* cutoff /**< pointer to store, if cut off appeared */
3398  )
3399 {
3400  SCIP_CONSHDLRDATA* conshdlrdata;
3401  SCIP_CONS* cons;
3402  SCIP_CONSDATA* consdata;
3403  SCIP_VAR** repvars;
3404  SCIP_Bool* negated;
3405  SCIP_VAR* var1;
3406  SCIP_Bool redundant;
3407  int c;
3408  int size;
3409  int maxcomppercons;
3410  int comppercons;
3411 
3412  assert(scip != NULL);
3413  assert(conshdlr != NULL);
3414  assert(eventhdlr != NULL);
3415  assert(conss != NULL || nconss == 0);
3416  assert(entries != NULL);
3417  assert(*entries != NULL);
3418  assert(nentries != NULL);
3419  assert(nfixedvars != NULL);
3420  assert(ndelconss != NULL);
3421  assert(nupgdconss != NULL);
3422  assert(nchgcoefs != NULL);
3423  assert(cutoff != NULL);
3424 
3425  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3426  assert(conshdlrdata != NULL);
3427 
3428  if( nconss == 0 )
3429  return SCIP_OKAY;
3430 
3431  if( SCIPgetNCliques(scip) == conshdlrdata->nlastcliquesneg && SCIPgetNImplications(scip) == conshdlrdata->nlastimplsneg )
3432  return SCIP_OKAY;
3433 
3434  conshdlrdata->nlastcliquesneg = SCIPgetNCliques(scip);
3435  conshdlrdata->nlastimplsneg = SCIPgetNImplications(scip);
3436 
3437  /* estimate the maximal number of variables in a logicor constraint */
3438  size = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
3439  if( size <= 0 )
3440  return SCIP_OKAY;
3441 
3442  /* temporary memory for active/negation of active variables */
3443  SCIP_CALL( SCIPallocBufferArray(scip, &repvars, size) );
3444  SCIP_CALL( SCIPallocBufferArray(scip, &negated, size) );
3445 
3446  /* iterate over all constraints and try to find negated cliques in logicors */
3447  for( c = nconss - 1; c >= 0; --c )
3448  {
3449  int v;
3450 
3451  assert(conss != NULL); /* for flexelint */
3452 
3453  cons = conss[c];
3454  assert(cons != NULL);
3455 
3456  if( !SCIPconsIsActive(cons) )
3457  continue;
3458 
3459  /* prepare constraint by removing fixings and merge it */
3460  SCIP_CALL( prepareCons(scip, cons, eventhdlr, entries, nentries, &redundant, nfixedvars, nchgcoefs, ndelconss, cutoff) );
3461 
3462  if( redundant )
3463  {
3464  assert(SCIPconsIsDeleted(cons));
3465  continue;
3466  }
3467 
3468  if( *cutoff )
3469  goto TERMINATE;
3470 
3471  consdata = SCIPconsGetData(cons);
3472  assert(consdata != NULL);
3473  assert(consdata->nvars >= 2);
3474  assert(consdata->nvars <= size);
3475  assert(consdata->presolved);
3476 
3477  if( SCIPconsIsModifiable(cons) && consdata->nvars == 2 )
3478  continue;
3479 
3480  if( c % 100 == 0 && SCIPisStopped(scip) )
3481  break;
3482 
3483  maxcomppercons = MAXCOMPARISONS / nconss;
3484  comppercons = 0;
3485 
3486  BMScopyMemoryArray(repvars, consdata->vars, consdata->nvars);
3487 
3488  /* all variables should be active or negative active variables, otherwise something went wrong with applyFixings()
3489  * called before mergeMultiples()
3490  */
3491  for( v = consdata->nvars - 1; v >= 0; --v )
3492  {
3493  assert(SCIPvarIsActive(repvars[v]) || (SCIPvarGetStatus(repvars[v]) == SCIP_VARSTATUS_NEGATED && SCIPvarIsActive(SCIPvarGetNegationVar(repvars[v]))));
3494  negated[v] = SCIPvarIsNegated(repvars[v]);
3495  }
3496 
3497  for( v = consdata->nvars - 1; v > 0; --v )
3498  {
3499  SCIP_Bool breakloop;
3500  SCIP_Bool neg1;
3501  int w;
3502 
3503  var1 = repvars[v];
3504 
3505  /* if there is no negated variable, there can't be a negated clique */
3506  if( SCIPvarGetNegatedVar(var1) == NULL )
3507  continue;
3508 
3509  /* get active counterpart to check for common cliques */
3511  {
3512  var1 = SCIPvarGetNegatedVar(var1);
3513  neg1 = TRUE;
3514  }
3515  else
3516  neg1 = FALSE;
3517 
3518  if( !SCIPvarIsActive(var1) )
3519  continue;
3520 
3521  /* no cliques available */
3522  if( SCIPvarGetNCliques(var1, neg1) == 0 && SCIPvarGetNImpls(var1, neg1) == 0 )
3523  continue;
3524 
3525  comppercons += (v - 1);
3526 
3527  breakloop = FALSE;
3528 
3529  for( w = v - 1; w >= 0; --w )
3530  {
3531  SCIP_VAR* var2;
3532  SCIP_Bool neg2;
3533 
3534  var2 = repvars[w];
3535 
3536  /* if there is no negated variable, there can't be a negated clique */
3537  if( SCIPvarGetNegatedVar(var2) == NULL )
3538  continue;
3539 
3541  {
3542  var2 = SCIPvarGetNegatedVar(var2);
3543  neg2 = TRUE;
3544  }
3545  else
3546  neg2 = FALSE;
3547 
3548  if( !SCIPvarIsActive(var2) )
3549  continue;
3550 
3551  /* no cliques available */
3552  if( SCIPvarGetNCliques(var2, neg2) == 0 && SCIPvarGetNImpls(var2, neg2) == 0 )
3553  continue;
3554 
3555  /* check if both active variable are the same */
3556  if( var1 == var2 )
3557  {
3558  if( neg1 != neg2 )
3559  {
3560  SCIPdebugMsg(scip, "logicor constraint <%s> is redundant, because variable <%s> and its negation <%s> exist\n",
3561  SCIPconsGetName(cons), SCIPvarGetName(var1), SCIPvarGetName(var2));
3562 
3563  SCIP_CALL( SCIPdelCons(scip, cons) );
3564 
3565  breakloop = TRUE;
3566  }
3567  else
3568  {
3569  #ifndef NDEBUG
3570  SCIP_VAR* lastvar = consdata->vars[consdata->nvars - 1];
3571  #endif
3572  SCIPdebugMsg(scip, "in logicor constraint <%s>, active variable of <%s> and active variable of <%s> are the same, removing the first\n",
3573  SCIPconsGetName(cons), SCIPvarGetName(consdata->vars[v]), SCIPvarGetName(consdata->vars[w]));
3574 
3575  SCIP_CALL( delCoefPos(scip, cons, eventhdlr, v) );
3576 
3577  if( v < consdata->nvars )
3578  {
3579  /* delCoefPos replaces the variable on position v with the last one, so w also need to correct the
3580  * negated array the same way, and because of deletion the number of variables is already decreased
3581  */
3582  assert(consdata->vars[v] == lastvar);
3583  negated[v] = negated[consdata->nvars];
3584  }
3585  ++(*nchgcoefs);
3586  }
3587  break;
3588  }
3589 
3590  if( SCIPvarsHaveCommonClique(var1, neg1, var2, neg2, TRUE) && conshdlrsetppc != NULL )
3591  {
3592  SCIP_CONS* newcons;
3593  SCIP_VAR* vars[2];
3594 
3595  /* this negated clique information could be created out of this logicor constraint even if there are more
3596  * than two variables left (, for example by probing), we need to keep this information by creating a
3597  * setppc constraint instead
3598  */
3599 
3600  /* get correct variables */
3601  if( !neg1 )
3602  vars[0] = SCIPvarGetNegatedVar(var1);
3603  else
3604  vars[0] = var1;
3605 
3606  if( !neg2 )
3607  vars[1] = SCIPvarGetNegatedVar(var2);
3608  else
3609  vars[1] = var2;
3610 
3611  SCIP_CALL( SCIPcreateConsSetpack(scip, &newcons, SCIPconsGetName(cons), 2, vars,
3614  SCIPconsIsLocal(cons), SCIPconsIsModifiable(cons),
3616 
3617  SCIP_CALL( SCIPaddCons(scip, newcons) );
3618  SCIPdebugPrintCons(scip, newcons, NULL);
3619 
3620  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
3621 
3622  SCIPdebugMsg(scip, "logicor constraint <%s> is redundant due to negated clique information and will be replaced by a setppc constraint \n",
3623  SCIPconsGetName(cons));
3624  SCIPdebugMsg(scip, "variable <%s> and variable <%s> are in a negated clique\n", SCIPvarGetName(consdata->vars[v]), SCIPvarGetName(consdata->vars[w]));
3625 
3626  SCIP_CALL( SCIPdelCons(scip, cons) );
3627  ++(*nupgdconss);
3628 
3629  breakloop = TRUE;
3630  break;
3631  }
3632  }
3633  if( breakloop )
3634  break;
3635 
3636  /* do not do to many comparisons */
3637  if( comppercons > maxcomppercons )
3638  break;
3639  }
3640  }
3641 
3642  TERMINATE:
3643  /* free temporary memory */
3644  SCIPfreeBufferArray(scip, &negated);
3645  SCIPfreeBufferArray(scip, &repvars);
3646 
3647  return SCIP_OKAY;
3648 }
3649 
3650 /** handle all cases with less than three variables in a logicor constraint
3651  *
3652  * in case a constraint has zero variables left, we detected infeasibility
3653  * in case a constraint has one variables left, we will fix it to one
3654  * in case a constraint has two variables left, we will add the implication and upgrade it to a set-packing constraint
3655  */
3656 static
3658  SCIP* scip, /**< SCIP data structure */
3659  SCIP_CONS* cons, /**< logic or constraint */
3660  SCIP_EVENTHDLR* eventhdlr, /**< event handler to call for the event processing */
3661  SCIP_CONSHDLR* conshdlrlinear, /**< linear constraint handler, or NULL */
3662  SCIP_CONSHDLR* conshdlrsetppc, /**< setppc constraint handler, or NULL */
3663  int* nfixedvars, /**< pointer to count number of fixings */
3664  int* nchgbds, /**< pointer to count number of tightened bounds */
3665  int* nchgcoefs, /**< pointer to count number of changed/deleted coefficients */
3666  int* ndelconss, /**< pointer to count number of deleted constraints */
3667  int* naddconss, /**< pointer to count number of added constraints */
3668  int* nupgdconss, /**< pointer to count number of upgraded constraints */
3669  SCIP_Bool* cutoff /**< pointer to store TRUE, if the node can be cut off */
3670  )
3671 {
3672  SCIP_CONSDATA* consdata;
3673  SCIP_Bool infeasible;
3674  SCIP_Bool fixed;
3675 
3676  assert(scip != NULL);
3677  assert(cons != NULL);
3678  assert(eventhdlr != NULL);
3679  assert(nfixedvars != NULL);
3680  assert(nchgbds != NULL);
3681  assert(nchgcoefs != NULL);
3682  assert(ndelconss != NULL);
3683  assert(naddconss != NULL);
3684  assert(nupgdconss != NULL);
3685  assert(cutoff != NULL);
3686 
3687  *cutoff = FALSE;
3688 
3689  if( SCIPconsIsModifiable(cons) )
3690  return SCIP_OKAY;
3691 
3692  consdata = SCIPconsGetData(cons);
3693  assert(consdata != NULL);
3694 
3695  /* if an unmodifiable logicor constraint has only two variables, we can add an implication and we will upgrade this
3696  * constraint to a set-packing constraint
3697  */
3698  if( consdata->nvars == 2 )
3699  {
3700  /* add implication if not yet done */
3701  if( !consdata->impladded )
3702  {
3703  SCIP_Bool implinfeasible;
3704  int nimplbdchgs;
3705  SCIP_Bool values[2];
3706 
3707  values[0] = FALSE;
3708  values[1] = FALSE;
3709  /* a two-variable logicor constraint x + y >= 1 yields the implication x == 0 -> y == 1, and is represented
3710  * by the clique inequality ~x + ~y <= 1
3711  */
3712  SCIP_CALL( SCIPaddClique(scip, consdata->vars, values, consdata->nvars, FALSE, &implinfeasible, &nimplbdchgs) );
3713  *nchgbds += nimplbdchgs;
3714  if( implinfeasible )
3715  {
3716  *cutoff = TRUE;
3717  return SCIP_OKAY;
3718  }
3719 
3720  /* adding the above implication could lead to fixings, which render the constraint redundant */
3721  if ( nimplbdchgs > 0 )
3722  {
3723  SCIP_Bool redundant;
3724 
3725  /* remove all variables that are fixed to zero, check redundancy due to fixed-to-one variable */
3726  SCIP_CALL( applyFixings(scip, cons, eventhdlr, &redundant, nchgcoefs, naddconss, ndelconss) );
3727  assert(!SCIPconsIsDeleted(cons));
3728 
3729  if( redundant )
3730  {
3731  SCIPdebugMsg(scip, "logic or constraint <%s> is redundant\n", SCIPconsGetName(cons));
3732 
3733  SCIP_CALL( SCIPdelCons(scip, cons) );
3734  (*ndelconss)++;
3735 
3736  return SCIP_OKAY;
3737  }
3738  }
3739  consdata->impladded = TRUE;
3740  }
3741 
3742  /* still we have two variables left, we will upgrade this constraint */
3743  if( consdata->nvars == 2 && conshdlrsetppc != NULL )
3744  {
3745  SCIP_CONS* newcons;
3746  SCIP_VAR* vars[2];
3747 
3748  /* get correct variables */
3749  SCIP_CALL( SCIPgetNegatedVar(scip, consdata->vars[0], &vars[0]) );
3750  SCIP_CALL( SCIPgetNegatedVar(scip, consdata->vars[1], &vars[1]) );
3751 
3752  SCIP_CALL( SCIPcreateConsSetpack(scip, &newcons, SCIPconsGetName(cons), 2, vars,
3757 
3758  SCIP_CALL( SCIPaddCons(scip, newcons) );
3759  SCIPdebugPrintCons(scip, newcons, NULL);
3760 
3761  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
3762 
3763  SCIPdebugMsg(scip, "logicor constraint <%s> was upgraded to a set-packing constraint\n", SCIPconsGetName(cons));
3764 
3765  SCIP_CALL( SCIPdelCons(scip, cons) );
3766  ++(*nupgdconss);
3767  }
3768  }
3769 
3770  /* if unmodifiable constraint has no variables, it is infeasible,
3771  * if unmodifiable constraint has only one variable, this one can be fixed and the constraint deleted
3772  */
3773  if( consdata->nvars == 0 )
3774  {
3775  SCIPdebugMsg(scip, "logic or constraint <%s> is infeasible\n", SCIPconsGetName(cons));
3776 
3777  *cutoff = TRUE;
3778  }
3779  else if( consdata->nvars == 1 )
3780  {
3781  SCIPdebugMsg(scip, "logic or constraint <%s> has only one variable not fixed to 0.0\n",
3782  SCIPconsGetName(cons));
3783 
3784  assert(consdata->vars != NULL);
3785  assert(consdata->vars[0] != NULL);
3786 
3787  if( SCIPvarGetStatus(consdata->vars[0]) != SCIP_VARSTATUS_MULTAGGR )
3788  {
3789  SCIPdebugMsg(scip, " -> fix variable and delete constraint\n");
3790 
3791  SCIP_CALL( SCIPfixVar(scip, consdata->vars[0], 1.0, &infeasible, &fixed) );
3792  if( infeasible )
3793  {
3794  SCIPdebugMsg(scip, " -> infeasible fixing\n");
3795 
3796  *cutoff = TRUE;
3797  return SCIP_OKAY;
3798  }
3799  if( fixed )
3800  (*nfixedvars)++;
3801 
3802  SCIP_CALL( SCIPdelCons(scip, cons) );
3803  (*ndelconss)++;
3804  }
3805  else if( conshdlrlinear != NULL )
3806  {
3807  SCIP_Real coef;
3808  SCIP_CONS* conslinear;
3809  char consname[SCIP_MAXSTRLEN];
3810 
3811  SCIPdebugMsg(scip, " -> variable is multi-aggregated, upgrade to linear constraint <%s> == 1 \n",
3812  SCIPvarGetName(consdata->vars[0]));
3813 
3814  coef = 1.0;
3815  (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "fixmaggr_%s_%s", SCIPconsGetName(cons),SCIPvarGetName(consdata->vars[0]) );
3816  SCIP_CALL( SCIPcreateConsLinear(scip, &conslinear, consname, 1, consdata->vars, &coef, 1.0, 1.0,
3820  SCIPconsIsStickingAtNode(cons)) );
3821 
3822  /* add constraint */
3823  SCIP_CALL( SCIPaddCons(scip, conslinear) );
3824  SCIP_CALL( SCIPreleaseCons(scip, &conslinear) );
3825  SCIP_CALL( SCIPdelCons(scip, cons) );
3826 
3827  (*ndelconss)++;
3828  (*naddconss)++;
3829  }
3830  }
3831 
3832  return SCIP_OKAY;
3833 }
3834 
3835 
3836 /*
3837  * upgrading of linear constraints
3838  */
3839 
3840 /** creates and captures a normalized (with all coefficients +1) logic or constraint */
3841 static
3843  SCIP* scip, /**< SCIP data structure */
3844  SCIP_CONS** cons, /**< pointer to hold the created constraint */
3845  const char* name, /**< name of constraint */
3846  int nvars, /**< number of variables in the constraint */
3847  SCIP_VAR** vars, /**< array with variables of constraint entries */
3848  SCIP_Real* vals, /**< array with coefficients (+1.0 or -1.0) */
3849  int mult, /**< multiplier on the coefficients(+1 or -1) */
3850  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
3851  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
3852  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
3853  * Usually set to TRUE. */
3854  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
3855  * TRUE for model constraints, FALSE for additional, redundant constraints. */
3856  SCIP_Bool check, /**< should the constraint be checked for feasibility?
3857  * TRUE for model constraints, FALSE for additional, redundant constraints. */
3858  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
3859  * Usually set to TRUE. */
3860  SCIP_Bool local, /**< is constraint only valid locally?
3861  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
3862  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
3863  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
3864  * adds coefficients to this constraint. */
3865  SCIP_Bool dynamic, /**< is constraint subject to aging?
3866  * Usually set to FALSE. Set to TRUE for own cuts which
3867  * are separated as constraints. */
3868  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
3869  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
3870  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
3871  * if it may be moved to a more global node?
3872  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
3873  )
3874 {
3875  SCIP_VAR** transvars;
3876  int v;
3877 
3878  assert(nvars == 0 || vars != NULL);
3879  assert(nvars == 0 || vals != NULL);
3880  assert(mult == +1 || mult == -1);
3881 
3882  /* get temporary memory */
3883  SCIP_CALL( SCIPallocBufferArray(scip, &transvars, nvars) );
3884 
3885  /* negate positive or negative variables */
3886  for( v = 0; v < nvars; ++v )
3887  {
3888  if( mult * vals[v] > 0.0 )
3889  transvars[v] = vars[v];
3890  else
3891  {
3892  SCIP_CALL( SCIPgetNegatedVar(scip, vars[v], &transvars[v]) );
3893  }
3894  assert(transvars[v] != NULL);
3895  }
3896 
3897  /* create the constraint */
3898  SCIP_CALL( SCIPcreateConsLogicor(scip, cons, name, nvars, transvars,
3899  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
3900 
3901  /* free temporary memory */
3902  SCIPfreeBufferArray(scip, &transvars);
3903 
3904  return SCIP_OKAY;
3905 }
3906 
3907 static
3908 SCIP_DECL_LINCONSUPGD(linconsUpgdLogicor)
3909 { /*lint --e{715}*/
3910  assert(upgdcons != NULL);
3911 
3912  /* check, if linear constraint can be upgraded to logic or constraint
3913  * - logic or constraints consist only of binary variables with a
3914  * coefficient of +1.0 or -1.0 (variables with -1.0 coefficients can be negated):
3915  * lhs <= x1 + ... + xp - y1 - ... - yn <= rhs
3916  * - negating all variables y = (1-Y) with negative coefficients gives:
3917  * lhs + n <= x1 + ... + xp + Y1 + ... + Yn <= rhs + n
3918  * - negating all variables x = (1-X) with positive coefficients and multiplying with -1 gives:
3919  * p - rhs <= X1 + ... + Xp + y1 + ... + yn <= p - lhs
3920  * - logic or constraints have left hand side of +1.0, and right hand side of +infinity: x(S) >= 1.0
3921  * -> without negations: (lhs == 1 - n and rhs == +inf) or (lhs == -inf and rhs = p - 1)
3922  */
3923  if( nvars > 2 && nposbin + nnegbin + nposimplbin + nnegimplbin == nvars && ncoeffspone + ncoeffsnone == nvars
3924  && ((SCIPisEQ(scip, lhs, 1.0 - ncoeffsnone) && SCIPisInfinity(scip, rhs))
3925  || (SCIPisInfinity(scip, -lhs) && SCIPisEQ(scip, rhs, ncoeffspone - 1.0))) )
3926  {
3927  int mult;
3928 
3929  SCIPdebugMsg(scip, "upgrading constraint <%s> to logic or constraint\n", SCIPconsGetName(cons));
3930 
3931  /* check, if we have to multiply with -1 (negate the positive vars) or with +1 (negate the negative vars) */
3932  mult = SCIPisInfinity(scip, rhs) ? +1 : -1;
3933 
3934  /* create the logic or constraint (an automatically upgraded constraint is always unmodifiable) */
3935  assert(!SCIPconsIsModifiable(cons));
3936  SCIP_CALL( createNormalizedLogicor(scip, upgdcons, SCIPconsGetName(cons), nvars, vars, vals, mult,
3941  }
3942 
3943  return SCIP_OKAY;
3944 }
3945 
3946 /** helper function to enforce constraints */
3947 static
3949  SCIP* scip, /**< SCIP data structure */
3950  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3951  SCIP_CONS** conss, /**< constraints to process */
3952  int nconss, /**< number of constraints */
3953  int nusefulconss, /**< number of useful (non-obsolete) constraints to process */
3954  SCIP_SOL* sol, /**< solution to enforce (NULL for the LP solution) */
3955  SCIP_RESULT* result /**< pointer to store the result of the enforcing call */
3956  )
3957 {
3958  SCIP_CONSHDLRDATA* conshdlrdata;
3959  SCIP_Bool cutoff;
3960  SCIP_Bool separated;
3961  SCIP_Bool reduceddom;
3962  int c;
3963 
3964  assert(conshdlr != NULL);
3965  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
3966  assert(nconss == 0 || conss != NULL);
3967  assert(result != NULL);
3968 
3969  SCIPdebugMsg(scip, "Enforcing %d logic or constraints for %s solution\n", nconss, sol == NULL ? "LP" : "relaxation");
3970 
3971  *result = SCIP_FEASIBLE;
3972 
3973  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3974  assert(conshdlrdata != NULL);
3975 
3976  cutoff = FALSE;
3977  separated = FALSE;
3978  reduceddom = FALSE;
3979 
3980  /* check all useful logic or constraints for feasibility */
3981  for( c = 0; c < nusefulconss && !cutoff && !reduceddom; ++c )
3982  {
3983  SCIP_CALL( separateCons(scip, conss[c], sol, conshdlrdata->eventhdlr, &cutoff, &separated, &reduceddom) );
3984  }
3985 
3986  /* check all obsolete logic or constraints for feasibility */
3987  for( c = nusefulconss; c < nconss && !cutoff && !separated && !reduceddom; ++c )
3988  {
3989  SCIP_CALL( separateCons(scip, conss[c], sol, conshdlrdata->eventhdlr, &cutoff, &separated, &reduceddom) );
3990  }
3991 
3992  /* return the correct result */
3993  if( cutoff )
3994  *result = SCIP_CUTOFF;
3995  else if( separated )
3996  *result = SCIP_SEPARATED;
3997  else if( reduceddom )
3998  *result = SCIP_REDUCEDDOM;
3999 
4000  return SCIP_OKAY;
4001 }
4002 
4003 
4004 /*
4005  * Callback methods of constraint handler
4006  */
4007 
4008 /** copy method for constraint handler plugins (called when SCIP copies plugins) */
4009 static
4010 SCIP_DECL_CONSHDLRCOPY(conshdlrCopyLogicor)
4011 { /*lint --e{715}*/
4012  assert(scip != NULL);
4013  assert(conshdlr != NULL);
4014  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4015 
4016  /* call inclusion method of constraint handler */
4018 
4019  *valid = TRUE;
4020 
4021  return SCIP_OKAY;
4022 }
4023 
4024 /** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
4025 static
4026 SCIP_DECL_CONSFREE(consFreeLogicor)
4027 { /*lint --e{715}*/
4028  SCIP_CONSHDLRDATA* conshdlrdata;
4029 
4030  assert(conshdlr != NULL);
4031  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4032  assert(scip != NULL);
4033 
4034  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4035  assert(conshdlrdata != NULL);
4036 
4037  /* free constraint handler data */
4038  conshdlrdataFree(scip, &conshdlrdata);
4039 
4040  SCIPconshdlrSetData(conshdlr, NULL);
4041 
4042  return SCIP_OKAY;
4043 }
4044 
4045 
4046 /** presolving initialization method of constraint handler (called when presolving is about to begin) */
4047 static
4048 SCIP_DECL_CONSINITPRE(consInitpreLogicor)
4049 { /*lint --e{715}*/
4050  SCIP_CONSHDLRDATA* conshdlrdata;
4051  SCIP_CONSDATA* consdata;
4052  int c;
4053  int v;
4054 
4055  assert(conshdlr != NULL);
4056  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4057  assert(conshdlrdata != NULL);
4058 
4059  conshdlrdata->nlastcliquesneg = 0;
4060  conshdlrdata->nlastimplsneg = 0;
4061  conshdlrdata->nlastcliquesshorten = 0;
4062  conshdlrdata->nlastimplsshorten = 0;
4063 
4064  /* catch all variable event for deleted variables, which is only used in presolving */
4065  for( c = nconss - 1; c >= 0; --c )
4066  {
4067  consdata = SCIPconsGetData(conss[c]);
4068  assert(consdata != NULL);
4069 
4070  for( v = consdata->nvars - 1; v >= 0; --v )
4071  {
4072  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[v], SCIP_EVENTTYPE_VARFIXED, conshdlrdata->eventhdlr,
4073  (SCIP_EVENTDATA*)conss[c], NULL) );
4074  }
4075  }
4076 
4077  return SCIP_OKAY;
4078 }
4079 /** presolving deinitialization method of constraint handler (called after presolving has been finished) */
4080 static
4081 SCIP_DECL_CONSEXITPRE(consExitpreLogicor)
4082 { /*lint --e{715}*/
4083  SCIP_CONSHDLRDATA* conshdlrdata;
4084  SCIP_CONSDATA* consdata;
4085  int nchgcoefs = 0;
4086  int c;
4087  int v;
4088 
4089  assert(conshdlr != NULL);
4090  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4091  assert(conshdlrdata != NULL);
4092 
4093  /* drop all variable event for deleted variables, which was only used in presolving */
4094  for( c = 0; c < nconss; ++c )
4095  {
4096  consdata = SCIPconsGetData(conss[c]);
4097  assert(consdata != NULL);
4098 
4099  for( v = 0; v < consdata->nvars; ++v )
4100  {
4101  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[v], SCIP_EVENTTYPE_VARFIXED, conshdlrdata->eventhdlr,
4102  (SCIP_EVENTDATA*)conss[c], -1) );
4103  }
4104 
4105  if( !SCIPconsIsDeleted(conss[c]) && !consdata->presolved )
4106  {
4107  SCIP_Bool redundant;
4108 
4109  /* we are not allowed to detect infeasibility in the exitpre stage */
4110  SCIP_CALL( applyFixings(scip, conss[c], conshdlrdata->eventhdlr, &redundant, &nchgcoefs, NULL, NULL) );
4111 
4112  /* it may happen that a constraint still contains variables that are fixed to one; for example, this happens
4113  * when variable fixings have been detected in the last presolving round by some other plugins (see #2941)
4114  */
4115  if( redundant )
4116  {
4117  SCIPdebugMsg(scip, "logic or constraint <%s> is redundant (detected during EXITPRE)\n", SCIPconsGetName(conss[c]));
4118 
4119  if( SCIPconsIsAdded(conss[c]) )
4120  {
4121  SCIP_CALL( SCIPdelCons(scip, conss[c]) );
4122  }
4123  else
4124  {
4125  /* we set the presolved flag to FALSE since not all fixing are removed if redundancy is detected */
4126  consdata->presolved = FALSE;
4127  }
4128  }
4129  }
4130  }
4131 
4132  return SCIP_OKAY;
4133 }
4134 
4135 /** solving process initialization method of constraint handler */
4136 static
4137 SCIP_DECL_CONSINITSOL(consInitsolLogicor)
4138 { /*lint --e{715}*/
4140  /* add nlrow representation to NLP, if NLP had been constructed */
4141  if( SCIPisNLPConstructed(scip) )
4142  {
4143  int c;
4144  for( c = 0; c < nconss; ++c )
4145  {
4146  SCIP_CALL( addNlrow(scip, conss[c]) );
4147  }
4148  }
4149 
4150  return SCIP_OKAY;
4151 }
4152 
4153 /** solving process deinitialization method of constraint handler (called before branch and bound process data is freed) */
4154 static
4155 SCIP_DECL_CONSEXITSOL(consExitsolLogicor)
4156 { /*lint --e{715}*/
4157  SCIP_CONSDATA* consdata;
4158  int c;
4159 
4160  /* release the rows and nlrows of all constraints */
4161  for( c = 0; c < nconss; ++c )
4162  {
4163  consdata = SCIPconsGetData(conss[c]);
4164  assert(consdata != NULL);
4165 
4166  if( consdata->row != NULL )
4167  {
4168  SCIP_CALL( SCIPreleaseRow(scip, &consdata->row) );
4169  }
4170 
4171  if( consdata->nlrow != NULL )
4172  {
4173  SCIP_CALL( SCIPreleaseNlRow(scip, &consdata->nlrow) );
4174  }
4175  }
4176 
4177  return SCIP_OKAY;
4178 }
4179 
4180 
4181 /** frees specific constraint data */
4182 static
4183 SCIP_DECL_CONSDELETE(consDeleteLogicor)
4184 { /*lint --e{715}*/
4185  assert(conshdlr != NULL);
4186  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4187  assert(consdata != NULL);
4188  assert(*consdata != NULL);
4189 
4191  {
4192  SCIP_CONSHDLRDATA* conshdlrdata;
4193  int v;
4194 
4195  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4196  assert(conshdlrdata != NULL);
4197 
4198  for( v = (*consdata)->nvars - 1; v >= 0; --v )
4199  {
4200  SCIP_CALL( SCIPdropVarEvent(scip, (*consdata)->vars[v], SCIP_EVENTTYPE_VARFIXED, conshdlrdata->eventhdlr,
4201  (SCIP_EVENTDATA*)cons, -1) );
4202  }
4203  }
4204 
4205  /* free LP row and logic or constraint */
4206  SCIP_CALL( consdataFree(scip, consdata) );
4207 
4208  return SCIP_OKAY;
4209 }
4210 
4211 
4212 /** transforms constraint data into data belonging to the transformed problem */
4213 static
4214 SCIP_DECL_CONSTRANS(consTransLogicor)
4215 { /*lint --e{715}*/
4216  SCIP_CONSDATA* sourcedata;
4217  SCIP_CONSDATA* targetdata;
4218 
4219  /*debugMsg(scip, "Trans method of logic or constraints\n");*/
4220 
4221  assert(conshdlr != NULL);
4222  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4223  assert(SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMING);
4224  assert(sourcecons != NULL);
4225  assert(targetcons != NULL);
4226 
4227  sourcedata = SCIPconsGetData(sourcecons);
4228  assert(sourcedata != NULL);
4229  assert(sourcedata->row == NULL); /* in original problem, there cannot be LP rows */
4230 
4231  /* create constraint data for target constraint */
4232  SCIP_CALL( consdataCreate(scip, &targetdata, sourcedata->nvars, sourcedata->vars) );
4233 
4234  /* create target constraint */
4235  SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata,
4236  SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons),
4237  SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons),
4238  SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons),
4239  SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) );
4240 
4241  return SCIP_OKAY;
4242 }
4243 
4244 
4245 /** LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved) */
4246 static
4247 SCIP_DECL_CONSINITLP(consInitlpLogicor)
4248 { /*lint --e{715}*/
4249  int c;
4250 
4251  *infeasible = FALSE;
4252 
4253  for( c = 0; c < nconss && !(*infeasible); ++c )
4254  {
4255  assert(SCIPconsIsInitial(conss[c]));
4256  SCIP_CALL( addCut(scip, conss[c], infeasible) );
4257  }
4258 
4259  return SCIP_OKAY;
4260 }
4261 
4262 
4263 /** separation method of constraint handler for LP solutions */
4264 static
4265 SCIP_DECL_CONSSEPALP(consSepalpLogicor)
4266 { /*lint --e{715}*/
4267  SCIP_CONSHDLRDATA* conshdlrdata;
4268  SCIP_Bool cutoff;
4269  SCIP_Bool separated;
4270  SCIP_Bool reduceddom;
4271  int c;
4272 
4273  assert(conshdlr != NULL);
4274  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4275  assert(nconss == 0 || conss != NULL);
4276  assert(result != NULL);
4277 
4278  SCIPdebugMsg(scip, "separating %d/%d logic or constraints\n", nusefulconss, nconss);
4279 
4280  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4281  assert(conshdlrdata != NULL);
4282 
4283  cutoff = FALSE;
4284  separated = FALSE;
4285  reduceddom = FALSE;
4286 
4287  /* check all useful logic or constraints for feasibility */
4288  for( c = 0; c < nusefulconss && !cutoff; ++c )
4289  {
4290  SCIP_CALL( separateCons(scip, conss[c], NULL, conshdlrdata->eventhdlr, &cutoff, &separated, &reduceddom) );
4291  }
4292 
4293  /* combine logic or constraints to get more cuts */
4294  /**@todo further cuts of logic or constraints */
4295 
4296  /* return the correct result */
4297  if( cutoff )
4298  *result = SCIP_CUTOFF;
4299  else if( reduceddom )
4300  *result = SCIP_REDUCEDDOM;
4301  else if( separated )
4302  *result = SCIP_SEPARATED;
4303  else
4304  *result = SCIP_DIDNOTFIND;
4305 
4306  return SCIP_OKAY;
4307 }
4308 
4309 
4310 /** separation method of constraint handler for arbitrary primal solutions */
4311 static
4312 SCIP_DECL_CONSSEPASOL(consSepasolLogicor)
4313 { /*lint --e{715}*/
4314  SCIP_CONSHDLRDATA* conshdlrdata;
4315  SCIP_Bool cutoff;
4316  SCIP_Bool separated;
4317  SCIP_Bool reduceddom;
4318  int c;
4319 
4320  assert(conshdlr != NULL);
4321  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4322  assert(nconss == 0 || conss != NULL);
4323  assert(result != NULL);
4324 
4325  SCIPdebugMsg(scip, "separating %d/%d logic or constraints\n", nusefulconss, nconss);
4326 
4327  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4328  assert(conshdlrdata != NULL);
4329 
4330  cutoff = FALSE;
4331  separated = FALSE;
4332  reduceddom = FALSE;
4333 
4334  /* check all useful logic or constraints for feasibility */
4335  for( c = 0; c < nusefulconss && !cutoff; ++c )
4336  {
4337  SCIP_CALL( separateCons(scip, conss[c], sol, conshdlrdata->eventhdlr, &cutoff, &separated, &reduceddom) );
4338  }
4339 
4340  /* combine logic or constraints to get more cuts */
4341  /**@todo further cuts of logic or constraints */
4342 
4343  /* return the correct result */
4344  if( cutoff )
4345  *result = SCIP_CUTOFF;
4346  else if( reduceddom )
4347  *result = SCIP_REDUCEDDOM;
4348  else if( separated )
4349  *result = SCIP_SEPARATED;
4350  else
4351  *result = SCIP_DIDNOTFIND;
4352 
4353  return SCIP_OKAY;
4354 }
4355 
4356 
4357 /** constraint enforcing method of constraint handler for LP solutions */
4358 static
4359 SCIP_DECL_CONSENFOLP(consEnfolpLogicor)
4360 { /*lint --e{715}*/
4361  SCIP_CALL( enforceConstraint(scip, conshdlr, conss, nconss, nusefulconss, NULL, result) );
4362 
4363  return SCIP_OKAY;
4364 }
4365 
4366 
4367 /** constraint enforcing method of constraint handler for relaxation solutions */
4368 static
4369 SCIP_DECL_CONSENFORELAX(consEnforelaxLogicor)
4370 { /*lint --e{715}*/
4371  SCIP_CALL( enforceConstraint(scip, conshdlr, conss, nconss, nusefulconss, sol, result) );
4372 
4373  return SCIP_OKAY;
4374 }
4375 
4376 
4377 /** constraint enforcing method of constraint handler for pseudo solutions */
4378 static
4379 SCIP_DECL_CONSENFOPS(consEnfopsLogicor)
4380 { /*lint --e{715}*/
4381  SCIP_CONSHDLRDATA* conshdlrdata;
4382  SCIP_Bool cutoff;
4383  SCIP_Bool infeasible;
4384  SCIP_Bool reduceddom;
4385  SCIP_Bool solvelp;
4386  int c;
4387 
4388  assert(conshdlr != NULL);
4389  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4390  assert(nconss == 0 || conss != NULL);
4391  assert(result != NULL);
4392 
4393  SCIPdebugMsg(scip, "pseudo enforcing %d logic or constraints\n", nconss);
4394 
4395  *result = SCIP_FEASIBLE;
4396 
4397  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4398  assert(conshdlrdata != NULL);
4399 
4400  cutoff = FALSE;
4401  infeasible = FALSE;
4402  reduceddom = FALSE;
4403  solvelp = FALSE;
4404 
4405  /* check all logic or constraints for feasibility */
4406  for( c = 0; c < nconss && !cutoff && !reduceddom && !solvelp; ++c )
4407  {
4408  SCIP_CALL( enforcePseudo(scip, conss[c], conshdlrdata->eventhdlr, &cutoff, &infeasible, &reduceddom, &solvelp) );
4409  }
4410 
4411  if( cutoff )
4412  *result = SCIP_CUTOFF;
4413  else if( reduceddom )
4414  *result = SCIP_REDUCEDDOM;
4415  else if( solvelp )
4416  *result = SCIP_SOLVELP;
4417  else if( infeasible )
4418  *result = SCIP_INFEASIBLE;
4419 
4420  return SCIP_OKAY;
4421 }
4422 
4423 
4424 /** feasibility check method of constraint handler for integral solutions */
4425 static
4426 SCIP_DECL_CONSCHECK(consCheckLogicor)
4427 { /*lint --e{715}*/
4428  SCIP_CONS* cons;
4429  SCIP_CONSDATA* consdata;
4430  int c;
4431 
4432  assert(conshdlr != NULL);
4433  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4434  assert(nconss == 0 || conss != NULL);
4435  assert(result != NULL);
4436 
4437  *result = SCIP_FEASIBLE;
4438 
4439  /* check all logic or constraints for feasibility */
4440  for( c = 0; c < nconss && (*result == SCIP_FEASIBLE || completely); ++c )
4441  {
4442  cons = conss[c];
4443  consdata = SCIPconsGetData(cons);
4444  assert(consdata != NULL);
4445  if( checklprows || consdata->row == NULL || !SCIProwIsInLP(consdata->row) )
4446  {
4447  if( isConsViolated(scip, cons, sol) )
4448  {
4449  /* constraint is violated */
4450  *result = SCIP_INFEASIBLE;
4451 
4452  if( printreason )
4453  {
4454 #ifndef NDEBUG
4455  int v;
4456  for( v = 0; v < consdata->nvars; ++v )
4457  {
4458  assert( consdata->vars[v] != NULL);
4459  assert( SCIPvarIsBinary(consdata->vars[v]) );
4460  assert( SCIPisFeasLT(scip, SCIPgetSolVal(scip, sol, consdata->vars[v]), 1.0) );
4461  }
4462 #endif
4463  SCIP_CALL( SCIPprintCons(scip, cons, NULL) );
4464  SCIPinfoMessage(scip, NULL, ";\n");
4465  SCIPinfoMessage(scip, NULL, "violation: all variables are set to zero\n");
4466  }
4467  }
4468  }
4469  }
4470 
4471  return SCIP_OKAY;
4472 }
4473 
4474 
4475 /** domain propagation method of constraint handler */
4476 static
4477 SCIP_DECL_CONSPROP(consPropLogicor)
4478 { /*lint --e{715}*/
4479  SCIP_CONSHDLRDATA* conshdlrdata;
4480  SCIP_Bool cutoff;
4481  SCIP_Bool reduceddom;
4482  SCIP_Bool addcut;
4483  SCIP_Bool mustcheck;
4484  int c;
4485 #ifndef NDEBUG
4486  SCIP_Bool inpresolve = (SCIPgetStage(scip) < SCIP_STAGE_INITSOLVE);
4487 #endif
4488 
4489  assert(conshdlr != NULL);
4490  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4491  assert(nconss == 0 || conss != NULL);
4492  assert(result != NULL);
4493 
4494  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4495  assert(conshdlrdata != NULL);
4496 
4497  cutoff = FALSE;
4498  reduceddom = FALSE;
4499 
4500  /* propagate all useful logic or constraints */
4501  for( c = 0; c < nusefulconss && !cutoff; ++c )
4502  {
4503  assert(inpresolve || !(SCIPconsGetData(conss[c])->existmultaggr));
4504 
4505  SCIPdebugMsg(scip, " propagate constraint %s\n", SCIPconsGetName(conss[c]));
4506  SCIP_CALL( processWatchedVars(scip, conss[c], conshdlrdata->eventhdlr, &cutoff, &reduceddom, &addcut, &mustcheck) );
4507  }
4508 
4509  /* return the correct result */
4510  if( cutoff )
4511  *result = SCIP_CUTOFF;
4512  else if( reduceddom )
4513  *result = SCIP_REDUCEDDOM;
4514  else
4515  *result = SCIP_DIDNOTFIND;
4516 
4517  return SCIP_OKAY; /*lint !e438*/
4518 }
4519 
4520 /** presolving method of constraint handler */
4521 static
4522 SCIP_DECL_CONSPRESOL(consPresolLogicor)
4523 { /*lint --e{715}*/
4524  SCIP_CONSHDLRDATA* conshdlrdata;
4525  SCIP_CONS* cons;
4526  SCIP_CONSDATA* consdata;
4527  unsigned char* entries;
4528  SCIP_Bool redundant;
4529  int c;
4530  int firstchange;
4531  int nentries;
4532  int oldnfixedvars;
4533  int oldnchgbds;
4534  int oldndelconss;
4535  int oldnupgdconss;
4536  int oldnchgcoefs;
4537 
4538  assert(conshdlr != NULL);
4539  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4540  assert(scip != NULL);
4541  assert(result != NULL);
4542 
4543  *result = SCIP_DIDNOTFIND;
4544 
4545  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4546  assert(conshdlrdata != NULL);
4547 
4548  nentries = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
4549 
4550  oldnfixedvars = *nfixedvars;
4551  oldnchgbds = *nchgbds;
4552  oldndelconss = *ndelconss;
4553  oldnupgdconss = *nupgdconss;
4554  oldnchgcoefs = *nchgcoefs;
4555 
4556  firstchange = INT_MAX;
4557 
4558  SCIP_CALL( SCIPallocBufferArray(scip, &entries, nentries) );
4559 
4560  /* process constraints */
4561  for( c = 0; c < nconss && *result != SCIP_CUTOFF && !SCIPisStopped(scip); ++c )
4562  {
4563  cons = conss[c];
4564  assert(cons != NULL);
4565  consdata = SCIPconsGetData(cons);
4566  assert(consdata != NULL);
4567 
4568  SCIPdebugMsg(scip, "presolving logic or constraint <%s>\n", SCIPconsGetName(cons));
4569 
4570  /* force presolving the constraint in the initial round */
4571  if( nrounds == 0 )
4572  {
4573  SCIP_CALL( SCIPenableConsPropagation(scip, cons) );
4574  }
4575 
4576  redundant = FALSE;
4577  if( !consdata->presolved )
4578  {
4579  /* remove all variables that are fixed to zero, check redundancy due to fixed-to-one variable */
4580  SCIP_CALL( applyFixings(scip, cons, conshdlrdata->eventhdlr, &redundant, nchgcoefs, naddconss, ndelconss) );
4581  }
4582 
4583  if( SCIPconsIsDeleted(cons) )
4584  continue;
4585 
4586  /* find pairs of negated variables in constraint: constraint is redundant */
4587  /* find sets of equal variables in constraint: multiple entries of variable can be replaced by single entry */
4588  if( !redundant )
4589  {
4590  SCIP_CALL( mergeMultiples(scip, cons, conshdlrdata->eventhdlr, &entries, &nentries, &redundant, nchgcoefs) );
4591  }
4592 
4593  if( redundant )
4594  {
4595  SCIPdebugMsg(scip, "logic or constraint <%s> is redundant\n", SCIPconsGetName(cons));
4596  SCIP_CALL( SCIPdelCons(scip, cons) );
4597  (*ndelconss)++;
4598  *result = SCIP_SUCCESS;
4599  continue;
4600  }
4601  else if( !SCIPconsIsModifiable(cons) )
4602  {
4603  if( consdata->nvars <= 2 )
4604  {
4605  SCIP_Bool cutoff;
4606 
4607  /* handle all cases with less than three variables in a logicor constraint */
4608  SCIP_CALL( fixDeleteOrUpgradeCons(scip, cons, conshdlrdata->eventhdlr, conshdlrdata->conshdlrlinear,
4609  conshdlrdata->conshdlrsetppc, nfixedvars, nchgbds, nchgcoefs, ndelconss, naddconss, nupgdconss, &cutoff) );
4610 
4611  if( cutoff )
4612  {
4613  *result = SCIP_CUTOFF;
4614  goto TERMINATE;
4615  }
4616  else if( *nfixedvars > oldnfixedvars || *nchgbds > oldnchgbds || *nchgcoefs > oldnchgcoefs
4617  || *ndelconss > oldndelconss || *nupgdconss > oldnupgdconss )
4618  *result = SCIP_SUCCESS;
4619 
4620  if( SCIPconsIsDeleted(cons) )
4621  continue;
4622  }
4623  }
4624 
4625  /* perform dual reductions */
4626  if( conshdlrdata->dualpresolving && SCIPallowStrongDualReds(scip) )
4627  {
4628  SCIP_CALL( dualPresolving(scip, cons, conshdlrdata->eventhdlr, nfixedvars, ndelconss, nchgcoefs, result) );
4629 
4630  /* if dual reduction deleted the constraint we take the next */
4631  if( !SCIPconsIsActive(cons) )
4632  continue;
4633 
4634  /* in dualpresolving we may have removed variables, so we need to take care of special cases */
4635  if( consdata->nvars <= 2 )
4636  {
4637  SCIP_Bool cutoff;
4638 
4639  /* handle all cases with less than three variables in a logicor constraint */
4640  SCIP_CALL( fixDeleteOrUpgradeCons(scip, cons, conshdlrdata->eventhdlr, conshdlrdata->conshdlrlinear,
4641  conshdlrdata->conshdlrsetppc, nfixedvars, nchgbds, nchgcoefs, ndelconss, naddconss, nupgdconss, &cutoff) );
4642 
4643  if( cutoff )
4644  {
4645  *result = SCIP_CUTOFF;
4646  goto TERMINATE;
4647  }
4648  else if( *nfixedvars > oldnfixedvars || *nchgbds > oldnchgbds || *nchgcoefs > oldnchgcoefs
4649  || *ndelconss > oldndelconss || *nupgdconss > oldnupgdconss )
4650  *result = SCIP_SUCCESS;
4651 
4652  if( SCIPconsIsDeleted(cons) )
4653  continue;
4654  }
4655  }
4656 
4657  /* remember the first changed constraint to begin the next redundancy round with */
4658  if( firstchange == INT_MAX && consdata->changed )
4659  firstchange = c;
4660 
4661  assert(consdata->nvars >= 2 || SCIPconsIsModifiable(cons));
4662  }
4663 
4664  assert(*result != SCIP_CUTOFF);
4665 
4666  /* fast preprocessing of pairs of logic or constraints, used for equal constraints */
4667  if( firstchange < nconss && conshdlrdata->presolusehashing )
4668  {
4669  /* detect redundant constraints; fast version with hash table instead of pairwise comparison */
4670  SCIP_CALL( detectRedundantConstraints(scip, SCIPblkmem(scip), conss, nconss, &firstchange, ndelconss) );
4671  }
4672 
4673  /* preprocess pairs of logic or constraints and apply negated clique presolving */
4674  if( SCIPisPresolveFinished(scip) )
4675  {
4676  SCIP_Bool cutoff = FALSE;
4677 
4678  /* check constraints for redundancy */
4679  if( conshdlrdata->presolpairwise && (presoltiming & SCIP_PRESOLTIMING_EXHAUSTIVE) != 0 )
4680  {
4681  SCIP_CALL( removeRedundantConssAndNonzeros(scip, conss, nconss, &entries, &nentries, conshdlrdata->eventhdlr,
4682  conshdlrdata->usestrengthening, &firstchange, nfixedvars, ndelconss, nchgcoefs, &cutoff) );
4683 
4684  if( cutoff )
4685  {
4686  *result = SCIP_CUTOFF;
4687  goto TERMINATE;
4688  }
4689  }
4690 
4691  if( SCIPisPresolveFinished(scip) )
4692  {
4693  /* try to tighten constraints by reducing the number of variables in the constraints using implications and
4694  * cliques, also derive fixations through them, @see SCIPshrinkDisjunctiveVarSet()
4695  */
4696  if( conshdlrdata->useimplications && (presoltiming & SCIP_PRESOLTIMING_EXHAUSTIVE) != 0 )
4697  {
4698  SCIP_CALL( shortenConss(scip, conshdlrdata, conshdlrdata->eventhdlr, conss, nconss,
4699  &entries, &nentries, nfixedvars, ndelconss, nchgcoefs, &cutoff) );
4700 
4701  if( cutoff )
4702  {
4703  *result = SCIP_CUTOFF;
4704  goto TERMINATE;
4705  }
4706  }
4707 
4708  /* check for redundant constraints due to negated clique information */
4709  if( conshdlrdata->usenegatedclique && (presoltiming & SCIP_PRESOLTIMING_MEDIUM) != 0 )
4710  {
4711  SCIP_CALL( removeConstraintsDueToNegCliques(scip, conshdlr, conshdlrdata->conshdlrsetppc,
4712  conshdlrdata->eventhdlr, conss, nconss, &entries, &nentries, nfixedvars, ndelconss,
4713  nupgdconss, nchgcoefs, &cutoff) );
4714 
4715  if( cutoff )
4716  {
4717  *result = SCIP_CUTOFF;
4718  goto TERMINATE;
4719  }
4720  }
4721  }
4722  }
4723 
4724  TERMINATE:
4725 
4726  SCIPfreeBufferArray(scip, &entries);
4727 
4728  return SCIP_OKAY;
4729 }
4730 
4731 
4732 /** propagation conflict resolving method of constraint handler */
4733 static
4734 SCIP_DECL_CONSRESPROP(consRespropLogicor)
4735 { /*lint --e{715}*/
4736  SCIP_CONSDATA* consdata;
4737 #ifndef NDEBUG
4738  SCIP_Bool infervarfound;
4739 #endif
4740  int v;
4741 
4742  assert(conshdlr != NULL);
4743  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4744  assert(cons != NULL);
4745  assert(infervar != NULL);
4746  assert(result != NULL);
4747 
4748  consdata = SCIPconsGetData(cons);
4749  assert(consdata != NULL);
4750 
4751  SCIPdebugMsg(scip, "conflict resolving method of logic or constraint handler\n");
4752 
4753  /* the only deductions are variables infered to 1.0 on logic or constraints where all other variables
4754  * are assigned to zero
4755  */
4756  assert(SCIPgetVarLbAtIndex(scip, infervar, bdchgidx, TRUE) > 0.5); /* the inference variable must be assigned to one */
4757 
4758 #ifndef NDEBUG
4759  infervarfound = FALSE;
4760 #endif
4761  for( v = 0; v < consdata->nvars; ++v )
4762  {
4763  if( consdata->vars[v] != infervar )
4764  {
4765  /* the reason variable must have been assigned to zero */
4766  assert(SCIPgetVarUbAtIndex(scip, consdata->vars[v], bdchgidx, FALSE) < 0.5);
4767  SCIP_CALL( SCIPaddConflictBinvar(scip, consdata->vars[v]) );
4768  }
4769 #ifndef NDEBUG
4770  else
4771  {
4772  assert(!infervarfound);
4773  infervarfound = TRUE;
4774  }
4775 #endif
4776  }
4777  assert(infervarfound);
4778 
4779  *result = SCIP_SUCCESS;
4780 
4781  return SCIP_OKAY;
4782 }
4783 
4784 
4785 /** variable rounding lock method of constraint handler */
4786 static
4787 SCIP_DECL_CONSLOCK(consLockLogicor)
4788 { /*lint --e{715}*/
4789  SCIP_CONSDATA* consdata;
4790  int i;
4791 
4792  consdata = SCIPconsGetData(cons);
4793  assert(consdata != NULL);
4794 
4795  /* lock every single coefficient */
4796  for( i = 0; i < consdata->nvars; ++i )
4797  {
4798  SCIP_CALL( SCIPaddVarLocksType(scip, consdata->vars[i], locktype, nlockspos, nlocksneg) );
4799  }
4800 
4801  return SCIP_OKAY;
4802 }
4803 
4804 
4805 /** constraint activation notification method of constraint handler */
4806 static
4807 SCIP_DECL_CONSACTIVE(consActiveLogicor)
4808 { /*lint --e{715}*/
4809  SCIP_CONSHDLRDATA* conshdlrdata;
4810  SCIP_CONSDATA* consdata;
4811 
4812  assert(conshdlr != NULL);
4813  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4814  assert(cons != NULL);
4815  assert(SCIPconsIsTransformed(cons));
4816 
4817  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4818  assert(conshdlrdata != NULL);
4819  consdata = SCIPconsGetData(cons);
4820  assert(consdata != NULL);
4821  assert(consdata->watchedvar1 == -1 || consdata->watchedvar1 != consdata->watchedvar2);
4822 
4823  SCIPdebugMsg(scip, "activating information for logic or constraint <%s>\n", SCIPconsGetName(cons));
4824  SCIPdebug( SCIP_CALL(consdataPrint(scip, consdata, NULL, TRUE)) );
4825 
4826  /* catch events on watched variables */
4827  if( consdata->watchedvar1 != -1 )
4828  {
4829  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[consdata->watchedvar1],
4830  SCIP_EVENTTYPE_UBTIGHTENED | SCIP_EVENTTYPE_LBRELAXED, conshdlrdata->eventhdlr, (SCIP_EVENTDATA*)cons,
4831  &consdata->filterpos1) );
4832  }
4833  if( consdata->watchedvar2 != -1 )
4834  {
4835  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[consdata->watchedvar2],
4836  SCIP_EVENTTYPE_UBTIGHTENED | SCIP_EVENTTYPE_LBRELAXED, conshdlrdata->eventhdlr, (SCIP_EVENTDATA*)cons,
4837  &consdata->filterpos2) );
4838  }
4839 
4840  if( SCIPgetStage(scip) == SCIP_STAGE_SOLVING && SCIPisNLPConstructed(scip) )
4841  {
4842  SCIP_CALL( addNlrow(scip, cons) );
4843  }
4844 
4845  return SCIP_OKAY;
4846 }
4847 
4848 
4849 /** constraint deactivation notification method of constraint handler */
4850 static
4851 SCIP_DECL_CONSDEACTIVE(consDeactiveLogicor)
4852 { /*lint --e{715}*/
4853  SCIP_CONSHDLRDATA* conshdlrdata;
4854  SCIP_CONSDATA* consdata;
4855 
4856  assert(conshdlr != NULL);
4857  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
4858  assert(cons != NULL);
4859  assert(SCIPconsIsTransformed(cons));
4860 
4861  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4862  assert(conshdlrdata != NULL);
4863  consdata = SCIPconsGetData(cons);
4864  assert(consdata != NULL);
4865  assert(consdata->watchedvar1 == -1 || consdata->watchedvar1 != consdata->watchedvar2);
4866 
4867  SCIPdebugMsg(scip, "deactivating information for logic or constraint <%s>\n", SCIPconsGetName(cons));
4868  SCIPdebug( SCIP_CALL(consdataPrint(scip, consdata, NULL, TRUE)) );
4869 
4870  /* drop events on watched variables */
4871  if( consdata->watchedvar1 != -1 )
4872  {
4873  assert(consdata->filterpos1 != -1);
4874  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[consdata->watchedvar1],
4875  SCIP_EVENTTYPE_UBTIGHTENED | SCIP_EVENTTYPE_LBRELAXED, conshdlrdata->eventhdlr, (SCIP_EVENTDATA*)cons,
4876  consdata->filterpos1) );
4877  consdata->watchedvar1 = -1;
4878  consdata->filterpos1 = -1;
4879  }
4880  if( consdata->watchedvar2 != -1 )
4881  {
4882  assert(consdata->filterpos2 != -1);
4883  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[consdata->watchedvar2],
4884  SCIP_EVENTTYPE_UBTIGHTENED | SCIP_EVENTTYPE_LBRELAXED, conshdlrdata->eventhdlr, (SCIP_EVENTDATA*)cons,
4885  consdata->filterpos2) );
4886  consdata->watchedvar2 = -1;
4887  consdata->filterpos2 = -1;
4888  }
4889 
4890  /* remove row from NLP, if still in solving
4891  * if we are in exitsolve, the whole NLP will be freed anyway
4892  */
4893  if( SCIPgetStage(scip) == SCIP_STAGE_SOLVING && consdata->nlrow != NULL )
4894  {
4895  SCIP_CALL( SCIPdelNlRow(scip, consdata->nlrow) );
4896  }
4897 
4898  return SCIP_OKAY;
4899 }
4900 
4901 
4902 /** constraint display method of constraint handler */
4903 static
4904 SCIP_DECL_CONSPRINT(consPrintLogicor)
4905 { /*lint --e{715}*/
4906  assert( scip != NULL );
4907  assert( conshdlr != NULL );
4908  assert( cons != NULL );
4909 
4910  SCIP_CALL( consdataPrint(scip, SCIPconsGetData(cons), file, FALSE) );
4911 
4912  return SCIP_OKAY;
4913 }
4914 
4915 /** constraint copying method of constraint handler */
4916 static
4917 SCIP_DECL_CONSCOPY(consCopyLogicor)
4918 { /*lint --e{715}*/
4919  SCIP_VAR** sourcevars;
4920  const char* consname;
4921  int nvars;
4922 
4923  /* get variables and coefficients of the source constraint */
4924  sourcevars = SCIPgetVarsLogicor(sourcescip, sourcecons);
4925  nvars = SCIPgetNVarsLogicor(sourcescip, sourcecons);
4926 
4927  if( name != NULL )
4928  consname = name;
4929  else
4930  consname = SCIPconsGetName(sourcecons);
4931 
4932  /* copy the logic using the linear constraint copy method */
4933  SCIP_CALL( SCIPcopyConsLinear(scip, cons, sourcescip, consname, nvars, sourcevars, NULL,
4934  1.0, SCIPinfinity(scip), varmap, consmap,
4935  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, global, valid) );
4936  assert(cons != NULL);
4937 
4938  return SCIP_OKAY;
4939 }
4940 
4941 /** constraint parsing method of constraint handler */
4942 static
4943 SCIP_DECL_CONSPARSE(consParseLogicor)
4944 { /*lint --e{715}*/
4945  SCIP_VAR** vars;
4946  char* strcopy;
4947  char* endptr;
4948  char* startptr;
4949  int requiredsize;
4950  int varssize;
4951  int nvars;
4952 
4953  SCIPdebugMsg(scip, "parse <%s> as logicor constraint\n", str);
4954 
4955  *success = FALSE;
4956 
4957  /* cutoff "logicor" from the constraint string */
4958  startptr = strchr((char*)str, '(');
4959 
4960  if( startptr == NULL )
4961  {
4962  SCIPerrorMessage("missing starting character '(' parsing logicor\n");
4963  return SCIP_OKAY;
4964  }
4965 
4966  /* skip '(' */
4967  ++startptr;
4968 
4969  /* find end character ')' */
4970  endptr = strrchr(startptr, ')');
4971 
4972  if( endptr == NULL )
4973  {
4974  SCIPerrorMessage("missing ending character ')' parsing logicor\n");
4975  return SCIP_OKAY;
4976  }
4977  assert(endptr >= startptr);
4978 
4979  if( endptr > startptr )
4980  {
4981  /* copy string for parsing; note that isspace() in SCIPparseVarsList() requires that strcopy ends with '\0' */
4982  SCIP_CALL( SCIPduplicateBufferArray(scip, &strcopy, startptr, (int)(endptr-startptr+1)) );
4983  strcopy[endptr-startptr] = '\0';
4984  varssize = 100;
4985  nvars = 0;
4986 
4987  /* allocate buffer array for variables */
4988  SCIP_CALL( SCIPallocBufferArray(scip, &vars, varssize) );
4989 
4990  /* parse string */
4991  SCIP_CALL( SCIPparseVarsList(scip, strcopy, vars, &nvars, varssize, &requiredsize, &endptr, ',', success) );
4992 
4993  if( *success )
4994  {
4995  /* check if the size of the variable array was great enough */
4996  if( varssize < requiredsize )
4997  {
4998  /* reallocate memory */
4999  varssize = requiredsize;
5000  SCIP_CALL( SCIPreallocBufferArray(scip, &vars, varssize) );
5001 
5002  /* parse string again with the correct size of the variable array */
5003  SCIP_CALL( SCIPparseVarsList(scip, strcopy, vars, &nvars, varssize, &requiredsize, &endptr, ',', success) );
5004  }
5005 
5006  assert(*success);
5007  assert(varssize >= requiredsize);
5008 
5009  /* create logicor constraint */
5010  SCIP_CALL( SCIPcreateConsLogicor(scip, cons, name, nvars, vars,
5011  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
5012  }
5013 
5014  /* free buffers */
5015  SCIPfreeBufferArray(scip, &vars);
5016  SCIPfreeBufferArray(scip, &strcopy);
5017  }
5018  else
5019  {
5020  if( !modifiable )
5021  {
5022  SCIPerrorMessage("cannot create empty logicor constraint\n");
5023  return SCIP_OKAY;
5024  }
5025 
5026  /* create empty logicor constraint */
5027  SCIP_CALL( SCIPcreateConsLogicor(scip, cons, name, 0, NULL,
5028  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
5029 
5030  *success = TRUE;
5031  }
5032 
5033  return SCIP_OKAY;
5034 }
5035 
5036 /** constraint method of constraint handler which returns the variables (if possible) */
5037 static
5038 SCIP_DECL_CONSGETVARS(consGetVarsLogicor)
5039 { /*lint --e{715}*/
5040  SCIP_CONSDATA* consdata;
5041 
5042  consdata = SCIPconsGetData(cons);
5043  assert(consdata != NULL);
5044 
5045  if( varssize < consdata->nvars )
5046  (*success) = FALSE;
5047  else
5048  {
5049  assert(vars != NULL);
5050 
5051  BMScopyMemoryArray(vars, consdata->vars, consdata->nvars);
5052  (*success) = TRUE;
5053  }
5054 
5055  return SCIP_OKAY;
5056 }
5057 
5058 /** constraint method of constraint handler which returns the number of variables (if possible) */
5059 static
5060 SCIP_DECL_CONSGETNVARS(consGetNVarsLogicor)
5061 { /*lint --e{715}*/
5062  SCIP_CONSDATA* consdata;
5063 
5064  consdata = SCIPconsGetData(cons);
5065  assert(consdata != NULL);
5066 
5067  (*nvars) = consdata->nvars;
5068  (*success) = TRUE;
5069 
5070  return SCIP_OKAY;
5071 }
5072 
5073 /*
5074  * Callback methods of event handler
5075  */
5076 
5077 static
5078 SCIP_DECL_EVENTEXEC(eventExecLogicor)
5079 { /*lint --e{715}*/
5080  assert(eventhdlr != NULL);
5081  assert(eventdata != NULL);
5082  assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
5083  assert(event != NULL);
5084 
5085  SCIPdebugMsg(scip, "exec method of event handler for logic or constraints\n");
5086 
5088  {
5089  SCIPdebugMsg(scip, "enabling constraint cons <%s> at depth %d\n", SCIPconsGetName((SCIP_CONS*)eventdata), SCIPgetDepth(scip));
5090 
5091  SCIP_CALL( SCIPenableCons(scip, (SCIP_CONS*)eventdata) );
5092  SCIP_CALL( SCIPenableConsPropagation(scip, (SCIP_CONS*)eventdata) );
5093  }
5094  else if( SCIPeventGetType(event) == SCIP_EVENTTYPE_UBTIGHTENED )
5095  {
5096  SCIP_CALL( SCIPenableConsPropagation(scip, (SCIP_CONS*)eventdata) );
5097  }
5098 
5100  {
5101  SCIP_VAR* var = SCIPeventGetVar(event);
5102  SCIP_CONS* cons = (SCIP_CONS*)eventdata;
5103  SCIP_CONSDATA* consdata;
5104 
5105  assert(cons != NULL);
5106  consdata = SCIPconsGetData(cons);
5107  assert(consdata != NULL);
5108 
5109  /* we only catch this event in presolving stage */
5110  assert(SCIPgetStage(scip) == SCIP_STAGE_PRESOLVING);
5111  assert(var != NULL);
5112 
5113  consdata->presolved = FALSE;
5114 
5116  {
5117  if( SCIPconsIsActive(cons) )
5118  {
5119  if( SCIPvarGetLbGlobal(var) < 0.5 && SCIPvarGetUbGlobal(var) > 0.5 )
5120  consdata->merged = FALSE;
5121 
5122  if( !consdata->existmultaggr )
5123  {
5125  consdata->existmultaggr = TRUE;
5126  }
5127  }
5128  }
5129  }
5130 
5131  return SCIP_OKAY;
5132 }
5133 
5134 
5135 /*
5136  * Callback methods of conflict handler
5137  */
5138 
5139 /** conflict processing method of conflict handler (called when conflict was found) */
5140 static
5141 SCIP_DECL_CONFLICTEXEC(conflictExecLogicor)
5142 { /*lint --e{715}*/
5143  SCIP_VAR** vars;
5144  int i;
5145 
5146  assert(conflicthdlr != NULL);
5147  assert(strcmp(SCIPconflicthdlrGetName(conflicthdlr), CONFLICTHDLR_NAME) == 0);
5148  assert(bdchginfos != NULL || nbdchginfos == 0);
5149  assert(result != NULL);
5150 
5151  *result = SCIP_DIDNOTRUN;
5152 
5153  /* don't process already resolved conflicts */
5154  if( resolved )
5155  return SCIP_OKAY;
5156 
5157  /* if the conflict consists of only two (binary) variables, it will be handled by the setppc conflict handler */
5158  if( nbdchginfos == 2 )
5159  return SCIP_OKAY;
5160 
5161  *result = SCIP_DIDNOTFIND;
5162 
5163  /* create array of variables in conflict constraint */
5164  SCIP_CALL( SCIPallocBufferArray(scip, &vars, nbdchginfos) );
5165  for( i = 0; i < nbdchginfos; ++i )
5166  {
5167  assert(bdchginfos != NULL); /* for flexelint */
5168  assert(bdchginfos[i] != NULL);
5169 
5170  vars[i] = SCIPbdchginfoGetVar(bdchginfos[i]);
5171 
5172  /* we can only treat binary variables */
5173  if( !SCIPvarIsBinary(vars[i]) )
5174  break;
5175 
5176  /* if the variable is fixed to one in the conflict set, we have to use its negation */
5177  if( SCIPbdchginfoGetNewbound(bdchginfos[i]) > 0.5 )
5178  {
5179  SCIP_CALL( SCIPgetNegatedVar(scip, vars[i], &vars[i]) );
5180  }
5181  }
5182 
5183  if( i == nbdchginfos )
5184  {
5185  SCIP_CONS* cons;
5186  char consname[SCIP_MAXSTRLEN];
5187 
5188  /* create a constraint out of the conflict set */
5189  (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "cf%d_%" SCIP_LONGINT_FORMAT, SCIPgetNRuns(scip), SCIPgetNConflictConssApplied(scip));
5190  SCIP_CALL( SCIPcreateConsLogicor(scip, &cons, consname, nbdchginfos, vars,
5191  FALSE, separate, FALSE, FALSE, TRUE, local, FALSE, dynamic, removable, FALSE) );
5192 
5193  /* add conflict to SCIP */
5194  SCIP_CALL( SCIPaddConflict(scip, node, cons, validnode, conftype, cutoffinvolved) );
5195 
5196  *result = SCIP_CONSADDED;
5197  }
5198 
5199  /* free temporary memory */
5200  SCIPfreeBufferArray(scip, &vars);
5201 
5202  return SCIP_OKAY;
5203 }
5204 
5205 
5206 /*
5207  * constraint specific interface methods
5208  */
5209 
5210 /** creates the handler for logic or constraints and includes it in SCIP */
5212  SCIP* scip /**< SCIP data structure */
5213  )
5214 {
5215  SCIP_CONSHDLRDATA* conshdlrdata;
5216  SCIP_CONSHDLR* conshdlr;
5217  SCIP_CONFLICTHDLR* conflicthdlr;
5218  SCIP_EVENTHDLR* eventhdlr;
5219 
5220  /* create event handler for events on watched variables */
5222  eventExecLogicor, NULL) );
5223 
5224  /* create conflict handler for logic or constraints */
5226  conflictExecLogicor, NULL) );
5227 
5228  /* create constraint handler data */
5229  SCIP_CALL( conshdlrdataCreate(scip, &conshdlrdata, eventhdlr) );
5230 
5231  /* include constraint handler */
5234  consEnfolpLogicor, consEnfopsLogicor, consCheckLogicor, consLockLogicor,
5235  conshdlrdata) );
5236  assert(conshdlr != NULL);
5237 
5238  /* set non-fundamental callbacks via specific setter functions */
5239  SCIP_CALL( SCIPsetConshdlrActive(scip, conshdlr, consActiveLogicor) );
5240  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopyLogicor, consCopyLogicor) );
5241  SCIP_CALL( SCIPsetConshdlrDeactive(scip, conshdlr, consDeactiveLogicor) );
5242  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteLogicor) );
5243  SCIP_CALL( SCIPsetConshdlrExitpre(scip, conshdlr, consExitpreLogicor) );
5244  SCIP_CALL( SCIPsetConshdlrInitsol(scip, conshdlr, consInitsolLogicor) );
5245  SCIP_CALL( SCIPsetConshdlrExitsol(scip, conshdlr, consExitsolLogicor) );
5246  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, consFreeLogicor) );
5247  SCIP_CALL( SCIPsetConshdlrGetVars(scip, conshdlr, consGetVarsLogicor) );
5248  SCIP_CALL( SCIPsetConshdlrGetNVars(scip, conshdlr, consGetNVarsLogicor) );
5249  SCIP_CALL( SCIPsetConshdlrInitpre(scip, conshdlr, consInitpreLogicor) );
5250  SCIP_CALL( SCIPsetConshdlrInitlp(scip, conshdlr, consInitlpLogicor) );
5251  SCIP_CALL( SCIPsetConshdlrParse(scip, conshdlr, consParseLogicor) );
5252  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolLogicor,CONSHDLR_MAXPREROUNDS, CONSHDLR_PRESOLTIMING) );
5253  SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintLogicor) );
5254  SCIP_CALL( SCIPsetConshdlrProp(scip, conshdlr, consPropLogicor, CONSHDLR_PROPFREQ, CONSHDLR_DELAYPROP,
5256  SCIP_CALL( SCIPsetConshdlrResprop(scip, conshdlr, consRespropLogicor) );
5257  SCIP_CALL( SCIPsetConshdlrSepa(scip, conshdlr, consSepalpLogicor, consSepasolLogicor, CONSHDLR_SEPAFREQ,
5259  SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransLogicor) );
5260  SCIP_CALL( SCIPsetConshdlrEnforelax(scip, conshdlr, consEnforelaxLogicor) );
5261 
5262  conshdlrdata->conshdlrlinear = SCIPfindConshdlr(scip, "linear");
5263  conshdlrdata->conshdlrsetppc = SCIPfindConshdlr(scip, "setppc");
5264 
5265  if( conshdlrdata->conshdlrlinear != NULL )
5266  {
5267  /* include the linear constraint to logicor constraint upgrade in the linear constraint handler */
5269  }
5270 
5271  /* logic or constraint handler parameters */
5273  "constraints/logicor/presolpairwise",
5274  "should pairwise constraint comparison be performed in presolving?",
5275  &conshdlrdata->presolpairwise, TRUE, DEFAULT_PRESOLPAIRWISE, NULL, NULL) );
5277  "constraints/logicor/presolusehashing",
5278  "should hash table be used for detecting redundant constraints in advance",
5279  &conshdlrdata->presolusehashing, TRUE, DEFAULT_PRESOLUSEHASHING, NULL, NULL) );
5281  "constraints/logicor/dualpresolving",
5282  "should dual presolving steps be performed?",
5283  &conshdlrdata->dualpresolving, TRUE, DEFAULT_DUALPRESOLVING, NULL, NULL) );
5285  "constraints/logicor/negatedclique",
5286  "should negated clique information be used in presolving",
5287  &conshdlrdata->usenegatedclique, TRUE, DEFAULT_NEGATEDCLIQUE, NULL, NULL) );
5289  "constraints/logicor/implications",
5290  "should implications/cliques be used in presolving",
5291  &conshdlrdata->useimplications, TRUE, DEFAULT_IMPLICATIONS, NULL, NULL) );
5293  "constraints/logicor/strengthen",
5294  "should pairwise constraint comparison try to strengthen constraints by removing superflous non-zeros?",
5295  &conshdlrdata->usestrengthening, TRUE, DEFAULT_STRENGTHEN, NULL, NULL) );
5296 
5297  return SCIP_OKAY;
5298 }
5299 
5300 
5301 /** creates and captures a logic or constraint
5302  *
5303  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
5304  */
5306  SCIP* scip, /**< SCIP data structure */
5307  SCIP_CONS** cons, /**< pointer to hold the created constraint */
5308  const char* name, /**< name of constraint */
5309  int nvars, /**< number of variables in the constraint */
5310  SCIP_VAR** vars, /**< array with variables of constraint entries */
5311  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
5312  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
5313  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
5314  * Usually set to TRUE. */
5315  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
5316  * TRUE for model constraints, FALSE for additional, redundant constraints. */
5317  SCIP_Bool check, /**< should the constraint be checked for feasibility?
5318  * TRUE for model constraints, FALSE for additional, redundant constraints. */
5319  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
5320  * Usually set to TRUE. */
5321  SCIP_Bool local, /**< is constraint only valid locally?
5322  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
5323  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
5324  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
5325  * adds coefficients to this constraint. */
5326  SCIP_Bool dynamic, /**< is constraint subject to aging?
5327  * Usually set to FALSE. Set to TRUE for own cuts which
5328  * are separated as constraints. */
5329  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
5330  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
5331  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
5332  * if it may be moved to a more global node?
5333  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
5334  )
5335 {
5336  SCIP_CONSHDLR* conshdlr;
5337  SCIP_CONSDATA* consdata;
5338 
5339  assert(scip != NULL);
5340 
5341  /* find the logicor constraint handler */
5342  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
5343  if( conshdlr == NULL )
5344  {
5345  SCIPerrorMessage("logic or constraint handler not found\n");
5346  return SCIP_INVALIDCALL;
5347  }
5348 
5349  /* create the constraint specific data */
5350  SCIP_CALL( consdataCreate(scip, &consdata, nvars, vars) );
5351 
5352  /* create constraint */
5353  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, initial, separate, enforce, check, propagate,
5354  local, modifiable, dynamic, removable, stickingatnode) );
5355 
5356  if( SCIPisTransformed(scip) && SCIPgetStage(scip) == SCIP_STAGE_PRESOLVING )
5357  {
5358  SCIP_CONSHDLRDATA* conshdlrdata;
5359  int v;
5360 
5361  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5362  assert(conshdlrdata != NULL);
5363 
5364  for( v = consdata->nvars - 1; v >= 0; --v )
5365  {
5366  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[v], SCIP_EVENTTYPE_VARFIXED, conshdlrdata->eventhdlr,
5367  (SCIP_EVENTDATA*)(*cons), NULL) );
5368  }
5369  }
5370 
5371  return SCIP_OKAY;
5372 }
5373 
5374 /** creates and captures a logicor constraint
5375  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
5376  * method SCIPcreateConsLogicor(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
5377  *
5378  * @see SCIPcreateConsLogicor() for information about the basic constraint flag configuration
5379  *
5380  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
5381  */
5383  SCIP* scip, /**< SCIP data structure */
5384  SCIP_CONS** cons, /**< pointer to hold the created constraint */
5385  const char* name, /**< name of constraint */
5386  int nvars, /**< number of variables in the constraint */
5387  SCIP_VAR** vars /**< array with variables of constraint entries */
5388  )
5389 {
5390  assert(scip != NULL);
5391 
5392  SCIP_CALL( SCIPcreateConsLogicor(scip, cons, name, nvars, vars,
5393  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5394 
5395  return SCIP_OKAY;
5396 }
5397 
5398 /** adds coefficient in logic or constraint */
5400  SCIP* scip, /**< SCIP data structure */
5401  SCIP_CONS* cons, /**< logicor constraint */
5402  SCIP_VAR* var /**< variable to add to the constraint */
5403  )
5404 {
5405  assert(var != NULL);
5406 
5407  /*debugMsg(scip, "adding variable <%s> to logicor constraint <%s>\n",
5408  SCIPvarGetName(var), SCIPconsGetName(cons));*/
5409 
5410  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
5411  {
5412  SCIPerrorMessage("constraint is not a logic or constraint\n");
5413  return SCIP_INVALIDDATA;
5414  }
5415 
5416  SCIP_CALL( addCoef(scip, cons, var) );
5417 
5418  return SCIP_OKAY;
5419 }
5420 
5421 /** gets number of variables in logic or constraint */
5423  SCIP* scip, /**< SCIP data structure */
5424  SCIP_CONS* cons /**< constraint data */
5425  )
5426 {
5427  SCIP_CONSDATA* consdata;
5428 
5429  assert(scip != NULL);
5430 
5431  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
5432  {
5433  SCIPerrorMessage("constraint is not a logic or constraint\n");
5434  SCIPABORT();
5435  return -1; /*lint !e527*/
5436  }
5437 
5438  consdata = SCIPconsGetData(cons);
5439  assert(consdata != NULL);
5440 
5441  return consdata->nvars;
5442 }
5443 
5444 /** gets array of variables in logic or constraint */
5446  SCIP* scip, /**< SCIP data structure */
5447  SCIP_CONS* cons /**< constraint data */
5448  )
5449 {
5450  SCIP_CONSDATA* consdata;
5451 
5452  assert(scip != NULL);
5453 
5454  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
5455  {
5456  SCIPerrorMessage("constraint is not a logic or constraint\n");
5457  SCIPABORT();
5458  return NULL; /*lint !e527*/
5459  }
5460 
5461  consdata = SCIPconsGetData(cons);
5462  assert(consdata != NULL);
5463 
5464  return consdata->vars;
5465 }
5466 
5467 /** gets the dual solution of the logic or constraint in the current LP */
5469  SCIP* scip, /**< SCIP data structure */
5470  SCIP_CONS* cons /**< constraint data */
5471  )
5472 {
5473  SCIP_CONSDATA* consdata;
5474 
5475  assert(scip != NULL);
5476 
5477  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
5478  {
5479  SCIPerrorMessage("constraint is not a logic or constraint\n");
5480  SCIPABORT();
5481  return SCIP_INVALID; /*lint !e527*/
5482  }
5483 
5484  consdata = SCIPconsGetData(cons);
5485  assert(consdata != NULL);
5486 
5487  if( consdata->row != NULL )
5488  return SCIProwGetDualsol(consdata->row);
5489  else
5490  return 0.0;
5491 }
5492 
5493 /** gets the dual Farkas value of the logic or constraint in the current infeasible LP */
5495  SCIP* scip, /**< SCIP data structure */
5496  SCIP_CONS* cons /**< constraint data */
5497  )
5498 {
5499  SCIP_CONSDATA* consdata;
5500 
5501  assert(scip != NULL);
5502 
5503  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
5504  {
5505  SCIPerrorMessage("constraint is not a logic or constraint\n");
5506  SCIPABORT();
5507  return SCIP_INVALID; /*lint !e527*/
5508  }
5509 
5510  consdata = SCIPconsGetData(cons);
5511  assert(consdata != NULL);
5512 
5513  if( consdata->row != NULL )
5514  return SCIProwGetDualfarkas(consdata->row);
5515  else
5516  return 0.0;
5517 }
5518 
5519 /** returns the linear relaxation of the given logic or constraint; may return NULL if no LP row was yet created;
5520  * the user must not modify the row!
5521  */
5523  SCIP* scip, /**< SCIP data structure */
5524  SCIP_CONS* cons /**< constraint data */
5525  )
5526 {
5527  SCIP_CONSDATA* consdata;
5528 
5529  assert(scip != NULL);
5530 
5531  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
5532  {
5533  SCIPerrorMessage("constraint is not a logic or constraint\n");
5534  SCIPABORT();
5535  return NULL; /*lint !e527*/
5536  }
5537 
5538  consdata = SCIPconsGetData(cons);
5539  assert(consdata != NULL);
5540 
5541  return consdata->row;
5542 }
5543 
5544 /** cleans up (multi-)aggregations and fixings from logicor constraints */
5546  SCIP* scip, /**< SCIP data structure */
5547  SCIP_Bool onlychecked, /**< should only checked constraints be cleaned up? */
5548  int* naddconss, /**< pointer to count number of added (linear) constraints */
5549  int* ndelconss, /**< pointer to count number of deleted (logicor) constraints */
5550  int* nchgcoefs /**< pointer to count number of changed coefficients */
5551  )
5552 {
5553  SCIP_CONSHDLR* conshdlr;
5554  SCIP_EVENTHDLR* eventhdlr;
5555  SCIP_CONS** conss;
5556  unsigned char* entries;
5557  int nconss;
5558  int nentries;
5559  int i;
5560 
5561  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
5562  if( conshdlr == NULL )
5563  return SCIP_OKAY;
5564 
5565  assert(naddconss != NULL);
5566  assert(ndelconss != NULL);
5567  assert(nchgcoefs != NULL);
5568 
5569  eventhdlr = SCIPconshdlrGetData(conshdlr)->eventhdlr;
5570  nconss = onlychecked ? SCIPconshdlrGetNCheckConss(conshdlr) : SCIPconshdlrGetNActiveConss(conshdlr);
5571  conss = onlychecked ? SCIPconshdlrGetCheckConss(conshdlr) : SCIPconshdlrGetConss(conshdlr);
5572 
5573  nentries = SCIPgetNVars(scip) - SCIPgetNContVars(scip);
5574  SCIP_CALL( SCIPallocBufferArray(scip, &entries, nentries) );
5575 
5576  /* loop backwards since then deleted constraints do not interfere with the loop */
5577  for( i = nconss - 1; i > 0; --i )
5578  {
5579  SCIP_CONS* cons;
5580  SCIP_Bool redundant;
5581 
5582  cons = conss[i];
5583  redundant = FALSE;
5584 
5585  SCIP_CALL( applyFixings(scip, cons, eventhdlr, &redundant, nchgcoefs, naddconss, ndelconss) );
5586 
5587  if( SCIPconsIsDeleted(cons) )
5588  continue;
5589 
5590  /* merge constraint */
5591  if( !redundant )
5592  {
5593  SCIP_CALL( mergeMultiples(scip, cons, eventhdlr, &entries, &nentries, &redundant, nchgcoefs) );
5594  }
5595 
5596  if( redundant )
5597  {
5598  SCIP_CALL( SCIPdelCons(scip, cons) );
5599  ++(*ndelconss);
5600  }
5601  }
5602 
5603  SCIPfreeBufferArray(scip, &entries);
5604 
5605  return SCIP_OKAY;
5606 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:61
SCIP_RETCODE SCIPaddVarsToRowSameCoef(SCIP *scip, SCIP_ROW *row, int nvars, SCIP_VAR **vars, SCIP_Real val)
Definition: scip_lp.c:1767
SCIP_RETCODE SCIPaddCoefLogicor(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
void SCIPconshdlrSetData(SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons.c:4214
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2090
static SCIP_DECL_CONSCHECK(consCheckLogicor)
SCIP_RETCODE SCIPcreateEmptyRowCons(SCIP *scip, SCIP_ROW **row, SCIP_CONS *cons, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip_lp.c:1422
SCIP_RETCODE SCIPaddConsAge(SCIP *scip, SCIP_CONS *cons, SCIP_Real deltaage)
Definition: scip_cons.c:1701
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:99
static SCIP_DECL_CONSPRESOL(consPresolLogicor)
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
Definition: scip_cons.c:572
#define DEFAULT_PRESOLUSEHASHING
Definition: cons_logicor.c:99
static SCIP_RETCODE removeRedundantCons(SCIP *scip, SCIP_CONS *cons0, SCIP_CONS *cons1, int *ndelconss)
SCIP_Bool SCIPvarsHaveCommonClique(SCIP_VAR *var1, SCIP_Bool value1, SCIP_VAR *var2, SCIP_Bool value2, SCIP_Bool regardimplics)
Definition: var.c:11483
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip_nlp.c:110
#define DEFAULT_PRESOLPAIRWISE
Definition: cons_logicor.c:95
SCIP_Real SCIPgetVarUbAtIndex(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx, SCIP_Bool after)
Definition: scip_var.c:2134
#define CONSHDLR_DELAYSEPA
Definition: cons_logicor.c:79
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:3298
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:365
#define SCIP_EVENTTYPE_VARFIXED
Definition: type_event.h:72
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8353
static SCIP_DECL_CONSINITLP(consInitlpLogicor)
SCIP_RETCODE SCIPsetConshdlrTrans(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSTRANS((*constrans)))
Definition: scip_cons.c:595
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE enforcePseudo(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *cutoff, SCIP_Bool *infeasible, SCIP_Bool *reduceddom, SCIP_Bool *solvelp)
#define CONSHDLR_NEEDSCONS
Definition: cons_logicor.c:81
SCIP_Real SCIPgetVarLbAtIndex(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx, SCIP_Bool after)
Definition: scip_var.c:1998
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2496
int SCIPconsGetValidDepth(SCIP_CONS *cons)
Definition: cons.c:8177
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:354
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:886
SCIP_VAR * SCIPbdchginfoGetVar(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:18521
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17919
SCIP_RETCODE SCIPsetConshdlrGetVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETVARS((*consgetvars)))
Definition: scip_cons.c:825
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)
int SCIPgetNVarsLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPvarGetProbvarBinary(SCIP_VAR **var, SCIP_Bool *negated)
Definition: var.c:12318
#define SCIP_MAXSTRLEN
Definition: def.h:302
int SCIPvarGetNLocksUpType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3356
public methods for conflict handler plugins and conflict analysis
static SCIP_DECL_CONSEXITPRE(consExitpreLogicor)
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
Definition: scip_cons.c:317
SCIP_RETCODE SCIPresetConsAge(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1758
static SCIP_DECL_CONSPRINT(consPrintLogicor)
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2851
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:139
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1695
static SCIP_RETCODE consdataFree(SCIP *scip, SCIP_CONSDATA **consdata)
Definition: cons_logicor.c:334
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17975
SCIP_RETCODE SCIPaddConflictBinvar(SCIP *scip, SCIP_VAR *var)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_DECL_CONFLICTEXEC(conflictExecLogicor)
SCIP_RETCODE SCIPdisableConsPropagation(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1927
SCIP_RETCODE SCIPsetConshdlrDeactive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDEACTIVE((*consdeactive)))
Definition: scip_cons.c:687
SCIP_Bool SCIPconsIsAdded(SCIP_CONS *cons)
Definition: cons.c:8523
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:104
static SCIP_RETCODE removeConstraintsDueToNegCliques(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLR *conshdlrsetppc, SCIP_EVENTHDLR *eventhdlr, SCIP_CONS **conss, int nconss, unsigned char **entries, int *nentries, int *nfixedvars, int *ndelconss, int *nupgdconss, int *nchgcoefs, SCIP_Bool *cutoff)
static SCIP_DECL_SORTPTRCOMP(conssLogicorComp)
SCIP_RETCODE SCIPgetTransformedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **transvar)
Definition: scip_var.c:1445
SCIP_RETCODE SCIPupdateConsFlags(SCIP *scip, SCIP_CONS *cons0, SCIP_CONS *cons1)
Definition: scip_cons.c:1470
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip_var.c:1254
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:17440
SCIP_RETCODE SCIPsetConshdlrInitpre(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITPRE((*consinitpre)))
Definition: scip_cons.c:486
static SCIP_RETCODE disableCons(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
static SCIP_DECL_CONSDEACTIVE(consDeactiveLogicor)
static SCIP_DECL_EVENTEXEC(eventExecLogicor)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE delCoefPos(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, int pos)
Definition: cons_logicor.c:538
#define CONSHDLR_DELAYPROP
Definition: cons_logicor.c:80
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4556
#define FALSE
Definition: def.h:96
int SCIPconsGetPos(SCIP_CONS *cons)
Definition: cons.c:8104
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3023
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:324
SCIP_Real SCIPrelDiff(SCIP_Real val1, SCIP_Real val2)
Definition: misc.c:11072
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:175
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10764
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
#define TRUE
Definition: def.h:95
#define SCIPdebug(x)
Definition: pub_message.h:93
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
Definition: cons.c:8373
#define SCIP_PRESOLTIMING_EXHAUSTIVE
Definition: type_timing.h:54
SCIP_RETCODE SCIPhashmapInsertInt(SCIP_HASHMAP *hashmap, void *origin, int image)
Definition: misc.c:3141
#define LINCONSUPGD_PRIORITY
Definition: cons_logicor.c:86
static unsigned int calcSignature(SCIP_VAR **vars, int nvars)
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17609
static SCIP_DECL_CONSEXITSOL(consExitsolLogicor)
static SCIP_DECL_CONSSEPALP(consSepalpLogicor)
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
Definition: cons.c:8403
public methods for problem variables
#define CONSHDLR_SEPAFREQ
Definition: cons_logicor.c:73
SCIP_RETCODE SCIPinitConflictAnalysis(SCIP *scip, SCIP_CONFTYPE conftype, SCIP_Bool iscutoffinvolved)
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:108
SCIP_RETCODE SCIPenableConsPropagation(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1897
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:229
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip_mem.h:132
#define CONSHDLR_NAME
Definition: cons_logicor.c:68
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE detectRedundantConstraints(SCIP *scip, BMS_BLKMEM *blkmem, SCIP_CONS **conss, int nconss, int *firstchange, int *ndelconss)
#define SCIP_LONGINT_MAX
Definition: def.h:172
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:136
SCIP_Longint SCIPvarGetNBranchingsCurrentRun(SCIP_VAR *var, SCIP_BRANCHDIR dir)
Definition: var.c:15752
Constraint handler for the set partitioning / packing / covering constraints .
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:89
#define SCIPdebugPrintCons(x, y, z)
Definition: pub_message.h:102
SCIP_Bool SCIPisTransformed(SCIP *scip)
Definition: scip_general.c:575
public methods for SCIP variables
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:17745
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8363
SCIP_RETCODE SCIPsetConshdlrInitlp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITLP((*consinitlp)))
Definition: scip_cons.c:618
SCIP_Real SCIProwGetDualsol(SCIP_ROW *row)
Definition: lp.c:17304
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:120
#define SCIPdebugMsg
Definition: scip_message.h:78
SCIP_RETCODE SCIPgetTransformedVars(SCIP *scip, int nvars, SCIP_VAR **vars, SCIP_VAR **transvars)
Definition: scip_var.c:1486
SCIP_RETCODE SCIPsetConshdlrParse(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPARSE((*consparse)))
Definition: scip_cons.c:802
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:8155
int SCIPvarGetNCliques(SCIP_VAR *var, SCIP_Bool varfixing)
Definition: var.c:18271
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:208
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2180
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:943
static SCIP_DECL_HASHGETKEY(hashGetKeyLogicorcons)
static SCIP_RETCODE switchWatchedvars(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, int watchedvar1, int watchedvar2)
Definition: cons_logicor.c:397
static SCIP_RETCODE addCut(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *cutoff)
static void consdataCalcSignature(SCIP_CONSDATA *consdata)
#define AGEINCREASE(n)
Definition: cons_logicor.c:108
public methods for numerical tolerances
static SCIP_RETCODE addNlrow(SCIP *scip, SCIP_CONS *cons)
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:2245
public methods for querying solving statistics
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
Definition: var.c:17735
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
Definition: lp.c:17515
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3372
SCIP_RETCODE SCIPaddVarLocksType(SCIP *scip, SCIP_VAR *var, SCIP_LOCKTYPE locktype, int nlocksdown, int nlocksup)
Definition: scip_var.c:4265
#define SCIP_EVENTTYPE_LBRELAXED
Definition: type_event.h:78
static SCIP_RETCODE shortenConss(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_EVENTHDLR *eventhdlr, SCIP_CONS **conss, int nconss, unsigned char **entries, int *nentries, int *nfixedvars, int *ndelconss, int *nchgcoefs, SCIP_Bool *cutoff)
SCIP_Bool SCIPisConflictAnalysisApplicable(SCIP *scip)
static SCIP_RETCODE analyzeConflict(SCIP *scip, SCIP_CONS *cons)
public methods for the branch-and-bound tree
#define SCIPallocCleanBufferArray(scip, ptr, num)
Definition: scip_mem.h:142
SCIP_RETCODE SCIPenableCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1783
SCIP_Real SCIPgetDualsolLogicor(SCIP *scip, SCIP_CONS *cons)
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:6927
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17929
SCIP_VAR * SCIPvarGetProbvar(SCIP_VAR *var)
Definition: var.c:12226
static void removeConsFromOccurList(SCIP_CONS *cons, SCIP_HASHMAP *varstopos, SCIP_CONS ***occurlist, int *noccurlistentries, int occurlistlength)
SCIP_RETCODE SCIPsetConshdlrInitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITSOL((*consinitsol)))
Definition: scip_cons.c:438
SCIP_VAR * w
Definition: circlepacking.c:67
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:105
static SCIP_DECL_HASHKEYVAL(hashKeyValLogicorcons)
public methods for managing constraints
SCIP_RETCODE SCIPparseVarsList(SCIP *scip, const char *str, SCIP_VAR **vars, int *nvars, int varssize, int *requiredsize, char **endptr, char delimiter, SCIP_Bool *success)
Definition: scip_var.c:610
SCIP_Bool SCIPisPresolveFinished(SCIP *scip)
Definition: scip_general.c:612
#define DEFAULT_DUALPRESOLVING
Definition: cons_logicor.c:100
SCIP_Bool SCIPnlrowIsInNLP(SCIP_NLROW *nlrow)
Definition: nlp.c:1872
static SCIP_DECL_CONSACTIVE(consActiveLogicor)
#define SCIP_PRESOLTIMING_MEDIUM
Definition: type_timing.h:53
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip_cons.c:341
static SCIP_DECL_CONSDELETE(consDeleteLogicor)
#define EVENTHDLR_DESC
Definition: cons_logicor.c:89
static SCIP_RETCODE prepareCons(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, unsigned char **entries, int *nentries, SCIP_Bool *redundant, int *nfixedvars, int *nchgcoefs, int *ndelconss, SCIP_Bool *cutoff)
static SCIP_DECL_CONSLOCK(consLockLogicor)
static SCIP_DECL_LINCONSUPGD(linconsUpgdLogicor)
#define SCIPhashFour(a, b, c, d)
Definition: pub_misc.h:524
SCIP_RETCODE SCIPgetBinvarRepresentatives(SCIP *scip, int nvars, SCIP_VAR **vars, SCIP_VAR **repvars, SCIP_Bool *negated)
Definition: scip_var.c:1650
#define SCIPerrorMessage
Definition: pub_message.h:64
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4184
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2778
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define CONSHDLR_ENFOPRIORITY
Definition: cons_logicor.c:71
static SCIP_DECL_CONSTRANS(consTransLogicor)
SCIP_RETCODE SCIPaddNlRow(SCIP *scip, SCIP_NLROW *nlrow)
Definition: scip_nlp.c:363
public methods for event handler plugins and event handlers
SCIP_RETCODE SCIPcleanupConssLogicor(SCIP *scip, SCIP_Bool onlychecked, int *naddconss, int *ndelconss, int *nchgcoefs)
Constraint handler for logicor constraints (equivalent to set covering, but algorithms are suited fo...
SCIP_RETCODE SCIPreleaseNlRow(SCIP *scip, SCIP_NLROW **nlrow)
Definition: scip_nlp.c:1025
static SCIP_DECL_CONSRESPROP(consRespropLogicor)
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:137
static SCIP_DECL_HASHKEYEQ(hashKeyEqLogicorcons)
static SCIP_RETCODE fixDeleteOrUpgradeCons(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, SCIP_CONSHDLR *conshdlrlinear, SCIP_CONSHDLR *conshdlrsetppc, int *nfixedvars, int *nchgbds, int *nchgcoefs, int *ndelconss, int *naddconss, int *nupgdconss, SCIP_Bool *cutoff)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:57
SCIP_Bool SCIPsortedvecFindPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), void *val, int len, int *pos)
SCIP_RETCODE SCIPunlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip_var.c:4443
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:8094
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:8313
SCIP_VAR ** SCIPgetVarsLogicor(SCIP *scip, SCIP_CONS *cons)
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:173
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:17260
static SCIP_RETCODE removeRedundantConssAndNonzeros(SCIP *scip, SCIP_CONS **conss, int nconss, unsigned char **entries, int *nentries, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool usestrengthening, int *firstchange, int *nfixedvars, int *ndelconss, int *nchgcoefs, SCIP_Bool *cutoff)
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip_cons.c:366
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3057
#define EVENTHDLR_NAME
Definition: cons_logicor.c:88
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4204
static SCIP_RETCODE unlockRounding(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_logicor.c:190
static SCIP_RETCODE addConsToOccurList(SCIP *scip, SCIP_CONS *cons, SCIP_HASHMAP *varstopos, SCIP_CONS ***occurlist, int *noccurlistentries, int *occurlistsizes, int *occurlistlength, int occurlistsize)
#define NULL
Definition: lpi_spx1.cpp:164
SCIP_RETCODE SCIPcreateConsBasicLogicor(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars)
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
SCIP_RETCODE SCIPvarGetAggregatedObj(SCIP_VAR *var, SCIP_Real *aggrobj)
Definition: var.c:17789
#define SCIP_CALL(x)
Definition: def.h:393
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:1744
#define CONFLICTHDLR_NAME
Definition: cons_logicor.c:91
void SCIPupdateSolLPConsViolation(SCIP *scip, SCIP_SOL *sol, SCIP_Real absviol, SCIP_Real relviol)
Definition: scip_sol.c:285
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPanalyzeConflictCons(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
SCIP_ROW * SCIPgetRowLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8333
static SCIP_RETCODE consdataEnsureVarsSize(SCIP *scip, SCIP_CONSDATA *consdata, int num)
Definition: cons_logicor.c:241
static SCIP_RETCODE applyFixings(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *redundant, int *nchgcoefs, int *naddconss, int *ndelconss)
Definition: cons_logicor.c:875
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:250
SCIP_RETCODE SCIPsetConshdlrResprop(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSRESPROP((*consresprop)))
Definition: scip_cons.c:641
struct SCIP_ConsData SCIP_CONSDATA
Definition: type_cons.h:65
SCIP_RETCODE SCIPdisableCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1817
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:83
public methods for constraint handler plugins and constraints
methods commonly used for presolving
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:9272
static SCIP_RETCODE consdataPrint(SCIP *scip, SCIP_CONSDATA *consdata, FILE *file, SCIP_Bool endline)
Definition: cons_logicor.c:371
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:124
public data structures and miscellaneous methods
static SCIP_DECL_CONSGETVARS(consGetVarsLogicor)
SCIP_VAR * SCIPeventGetVar(SCIP_EVENT *event)
Definition: event.c:1053
#define CONFLICTHDLR_DESC
Definition: cons_logicor.c:92
#define SCIP_Bool
Definition: def.h:93
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2135
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:1030
static SCIP_DECL_CONSENFOLP(consEnfolpLogicor)
static SCIP_RETCODE createNormalizedLogicor(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, int mult, 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)
static SCIP_DECL_CONSENFOPS(consEnfopsLogicor)
SCIP_Bool SCIPconsIsPropagationEnabled(SCIP_CONS *cons)
Definition: cons.c:8212
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:670
static void consdataSort(SCIP_CONSDATA *consdata)
int SCIPvarGetNImpls(SCIP_VAR *var, SCIP_Bool varfixing)
Definition: var.c:18197
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip_cons.c:2482
#define MAX(x, y)
Definition: tclique_def.h:92
#define CONSHDLR_MAXPREROUNDS
Definition: cons_logicor.c:78
#define MAX_CONSLENGTH
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:8114
int SCIPvarCompare(SCIP_VAR *var1, SCIP_VAR *var2)
Definition: var.c:11950
public methods for LP management
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
Definition: cons.c:8223
public methods for cuts and aggregation rows
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8293
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8263
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17767
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:400
SCIP_Real SCIPbdchginfoGetNewbound(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:18511
#define MAXCOMPARISONS
SCIP_RETCODE SCIPcreateNlRow(SCIP *scip, SCIP_NLROW **nlrow, const char *name, SCIP_Real constant, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, SCIP_EXPR *expr, SCIP_Real lhs, SCIP_Real rhs, SCIP_EXPRCURV curvature)
Definition: scip_nlp.c:921
static SCIP_DECL_CONSCOPY(consCopyLogicor)
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8282
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:136
int SCIPgetNRuns(SCIP *scip)
SCIP_Real SCIProwGetDualfarkas(SCIP_ROW *row)
Definition: lp.c:17317
SCIP_RETCODE SCIPlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip_var.c:4357
SCIP_Real SCIPgetDualfarkasLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPsetConshdlrPrint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRINT((*consprint)))
Definition: scip_cons.c:779
#define SCIP_EVENTTYPE_UBTIGHTENED
Definition: type_event.h:79
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:2557
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsLogicor(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)
static SCIP_RETCODE strengthenConss(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_HASHMAP *varstopos, SCIP_CONS ***occurlist, int *noccurlistentries, int occurlistlength, SCIP_EVENTHDLR *eventhdlr, int *ndelconss, int *nchgcoefs)
static SCIP_RETCODE conshdlrdataCreate(SCIP *scip, SCIP_CONSHDLRDATA **conshdlrdata, SCIP_EVENTHDLR *eventhdlr)
Definition: cons_logicor.c:203
static SCIP_DECL_CONSFREE(consFreeLogicor)
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2045
int SCIPconshdlrGetNActiveConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4633
SCIP_Bool SCIPinProbing(SCIP *scip)
Definition: scip_probing.c:97
public methods for the LP relaxation, rows and columns
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:2295
SCIP_RETCODE SCIPincludeLinconsUpgrade(SCIP *scip, SCIP_DECL_LINCONSUPGD((*linconsupgd)), int priority, const char *conshdlrname)
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2000
static SCIP_RETCODE createRow(SCIP *scip, SCIP_CONS *cons)
#define DEFAULT_NEGATEDCLIQUE
Definition: cons_logicor.c:101
SCIP_RETCODE SCIPdelNlRow(SCIP *scip, SCIP_NLROW *nlrow)
Definition: scip_nlp.c:391
public methods for nonlinear relaxation
#define HASHSIZE_LOGICORCONS
Definition: cons_logicor.c:98
static SCIP_RETCODE consdataCreate(SCIP *scip, SCIP_CONSDATA **consdata, int nvars, SCIP_VAR **vars)
Definition: cons_logicor.c:265
methods for sorting joint arrays of various types
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)
SCIP_RETCODE SCIPsetConshdlrExitpre(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITPRE((*consexitpre)))
Definition: scip_cons.c:510
static SCIP_DECL_CONSENFORELAX(consEnforelaxLogicor)
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1562
static SCIP_RETCODE processWatchedVars(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *cutoff, SCIP_Bool *reduceddom, SCIP_Bool *addcut, SCIP_Bool *mustcheck)
#define CONSHDLR_PRESOLTIMING
Definition: cons_logicor.c:83
SCIP_RETCODE SCIPwriteVarsList(SCIP *scip, FILE *file, SCIP_VAR **vars, int nvars, SCIP_Bool type, char delimiter)
Definition: scip_var.c:292
public methods for managing events
general public methods
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopyLogicor)
#define CONSHDLR_DESC
Definition: cons_logicor.c:69
#define CONSHDLR_PROPFREQ
Definition: cons_logicor.c:74
static SCIP_DECL_CONSPARSE(consParseLogicor)
#define CONSHDLR_EAGERFREQ
Definition: cons_logicor.c:75
public methods for solutions
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
Definition: cons.c:8124
SCIP_CONS ** SCIPconshdlrGetCheckConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4576
public methods for conflict analysis handlers
public methods for the probing mode
static SCIP_RETCODE lockRounding(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_logicor.c:177
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1119
SCIP_RETCODE SCIPincludeConflicthdlrBasic(SCIP *scip, SCIP_CONFLICTHDLR **conflicthdlrptr, const char *name, const char *desc, int priority, SCIP_DECL_CONFLICTEXEC((*conflictexec)), SCIP_CONFLICTHDLRDATA *conflicthdlrdata)
static SCIP_DECL_CONSINITPRE(consInitpreLogicor)
const char * SCIPconflicthdlrGetName(SCIP_CONFLICTHDLR *conflicthdlr)
Definition: conflict.c:772
SCIP_RETCODE SCIPsetConshdlrPresol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRESOL((*conspresol)), int maxprerounds, SCIP_PRESOLTIMING presoltiming)
Definition: scip_cons.c:534
static SCIP_RETCODE removeRedundantConss(SCIP *scip, SCIP_CONS *cons, SCIP_HASHMAP *varstopos, SCIP_CONS ***occurlist, int *noccurlistentries, int occurlistlength, int *ndelconss)
public methods for message output
int SCIPgetNCliques(SCIP *scip)
Definition: scip_var.c:7581
SCIP_Real SCIPgetRowLPFeasibility(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:2004
int SCIPgetNImplications(SCIP *scip)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17379
SCIP_RETCODE SCIPincludeConshdlrLogicor(SCIP *scip)
static SCIP_DECL_CONSPROP(consPropLogicor)
static void conshdlrdataFree(SCIP *scip, SCIP_CONSHDLRDATA **conshdlrdata)
Definition: cons_logicor.c:228
SCIP_RETCODE SCIPcaptureVar(SCIP *scip, SCIP_VAR *var)
Definition: scip_var.c:1220
#define SCIP_Real
Definition: def.h:186
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8343
#define SCIPfreeCleanBufferArray(scip, ptr)
Definition: scip_mem.h:146
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:703
SCIP_RETCODE SCIPsetConshdlrGetNVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETNVARS((*consgetnvars)))
Definition: scip_cons.c:848
int SCIPconshdlrGetNCheckConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4619
static SCIP_DECL_CONSGETNVARS(consGetNVarsLogicor)
public methods for message handling
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8283
#define CONSHDLR_SEPAPRIORITY
Definition: cons_logicor.c:70
#define SCIP_INVALID
Definition: def.h:206
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8273
static SCIP_RETCODE enforceConstraint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, int nusefulconss, SCIP_SOL *sol, SCIP_RESULT *result)
#define SCIP_Longint
Definition: def.h:171
int SCIPvarGetIndex(SCIP_VAR *var)
Definition: var.c:17599
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17425
SCIP_RETCODE SCIPshrinkDisjunctiveVarSet(SCIP *scip, SCIP_VAR **vars, SCIP_Real *bounds, SCIP_Bool *boundtypes, SCIP_Bool *redundants, int nvars, int *nredvars, int *nglobalred, SCIP_Bool *setredundant, SCIP_Bool *glbinfeas, SCIP_Bool fullshortening)
Definition: presolve.c:995
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
static SCIP_Bool isConsViolated(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
Definition: type_cons.h:64
static SCIP_DECL_CONSINITSOL(consInitsolLogicor)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17985
#define CONSHDLR_PROP_TIMING
Definition: cons_logicor.c:84
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
Definition: scip_mem.h:111
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
Definition: var.c:17402
static SCIP_RETCODE dualPresolving(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, int *nfixedvars, int *ndelconss, int *nchgcoefs, SCIP_RESULT *result)
Definition: cons_logicor.c:620
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:132
SCIP_RETCODE SCIPsetConshdlrActive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSACTIVE((*consactive)))
Definition: scip_cons.c:664
#define CONSHDLR_CHECKPRIORITY
Definition: cons_logicor.c:72
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:439
SCIP_RETCODE SCIPaddConflict(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode, SCIP_CONFTYPE conftype, SCIP_Bool iscutoffinvolved)
Definition: scip_prob.c:3236
int SCIPhashmapGetImageInt(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3230
static SCIP_RETCODE addCoef(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_logicor.c:468
static SCIP_DECL_CONSSEPASOL(consSepasolLogicor)
SCIP_RETCODE SCIPcleanupCliques(SCIP *scip, SCIP_Bool *infeasible)
Definition: scip_var.c:7538
SCIP_RETCODE SCIPsetConshdlrExitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITSOL((*consexitsol)))
Definition: scip_cons.c:462
#define SCIPABORT()
Definition: def.h:365
public methods for global and local (sub)problems
#define CONFLICTHDLR_PRIORITY
Definition: cons_logicor.c:93
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1361
SCIP_Bool SCIPallowStrongDualReds(SCIP *scip)
Definition: scip_var.c:8635
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:5729
static SCIP_RETCODE separateCons(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *cutoff, SCIP_Bool *separated, SCIP_Bool *reduceddom)
static void findShortestOccurlist(SCIP_VAR **vars, int nvars, SCIP_HASHMAP *varstopos, SCIP_CONS ***occurlist, int *noccurlistentries, int occurlistlength, int *nentries, SCIP_CONS ***shortestlist)
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip_var.c:1533
static SCIP_RETCODE removeRedundantNonZeros(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *artvar, int artpos, SCIP_HASHMAP *varstopos, SCIP_CONS ***occurlist, int *noccurlistentries, int occurlistlength, SCIP_EVENTHDLR *eventhdlr, int *nchgcoefs, SCIP_Bool *deleted)
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:57
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:17589
#define DEFAULT_STRENGTHEN
Definition: cons_logicor.c:96
#define DEFAULT_IMPLICATIONS
Definition: cons_logicor.c:102
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:17415
static SCIP_RETCODE mergeMultiples(SCIP *scip, SCIP_CONS *cons, SCIP_EVENTHDLR *eventhdlr, unsigned char **entries, int *nentries, SCIP_Bool *redundant, int *nchgcoefs)
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:128
SCIP_RETCODE SCIPsetConshdlrProp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPROP((*consprop)), int propfreq, SCIP_Bool delayprop, SCIP_PROPTIMING proptiming)
Definition: scip_cons.c:275
memory allocation routines