Scippy

SCIP

Solving Constraint Integer Programs

conflict.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file conflict.c
17  * @brief methods and datastructures for conflict analysis
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Stefan Heinz
21  * @author Marc Pfetsch
22  * @author Michael Winkler
23  * @author Jakob Witzig
24  *
25  * This file implements a conflict analysis method like the one used in modern
26  * SAT solvers like zchaff. The algorithm works as follows:
27  *
28  * Given is a set of bound changes that are not allowed being applied simultaneously, because they
29  * render the current node infeasible (e.g. because a single constraint is infeasible in the these
30  * bounds, or because the LP relaxation is infeasible). The goal is to deduce a clause on variables
31  * -- a conflict clause -- representing the "reason" for this conflict, i.e., the branching decisions
32  * or the deductions (applied e.g. in domain propagation) that lead to the conflict. This clause can
33  * then be added to the constraint set to help cutting off similar parts of the branch and bound
34  * tree, that would lead to the same conflict. A conflict clause can also be generated, if the
35  * conflict was detected by a locally valid constraint. In this case, the resulting conflict clause
36  * is also locally valid in the same depth as the conflict detecting constraint. If all involved
37  * variables are binary, a linear (set covering) constraint can be generated, otherwise a bound
38  * disjunction constraint is generated. Details are given in
39  *
40  * Tobias Achterberg, Conflict Analysis in Mixed Integer Programming@n
41  * Discrete Optimization, 4, 4-20 (2007)
42  *
43  * See also @ref CONF. Here is an outline of the algorithm:
44  *
45  * -# Put all the given bound changes to a priority queue, which is ordered,
46  * such that the bound change that was applied last due to branching or deduction
47  * is at the top of the queue. The variables in the queue are always active
48  * problem variables. Because binary variables are preferred over general integer
49  * variables, integer variables are put on the priority queue prior to the binary
50  * variables. Create an empty conflict set.
51  * -# Remove the top bound change b from the priority queue.
52  * -# Perform the following case distinction:
53  * -# If the remaining queue is non-empty, and bound change b' (the one that is now
54  * on the top of the queue) was applied at the same depth level as b, and if
55  * b was a deduction with known inference reason, and if the inference constraint's
56  * valid depth is smaller or equal to the conflict detecting constraint's valid
57  * depth:
58  * - Resolve bound change b by asking the constraint that inferred the
59  * bound change to put all the bound changes on the priority queue, that
60  * lead to the deduction of b.
61  * Note that these bound changes have at most the same inference depth
62  * level as b, and were deduced earlier than b.
63  * -# Otherwise, the bound change b was a branching decision or a deduction with
64  * missing inference reason, or the inference constraint's validity is more local
65  * than the one of the conflict detecting constraint.
66  * - If a the bound changed corresponds to a binary variable, add it or its
67  * negation to the conflict set, depending on which of them is currently fixed to
68  * FALSE (i.e., the conflict set consists of literals that cannot be FALSE
69  * altogether at the same time).
70  * - Otherwise put the bound change into the conflict set.
71  * Note that if the bound change was a branching, all deduced bound changes
72  * remaining in the priority queue have smaller inference depth level than b,
73  * since deductions are always applied after the branching decisions. However,
74  * there is the possibility, that b was a deduction, where the inference
75  * reason was not given or the inference constraint was too local.
76  * With this lack of information, we must treat the deduced bound change like
77  * a branching, and there may exist other deduced bound changes of the same
78  * inference depth level in the priority queue.
79  * -# If priority queue is non-empty, goto step 2.
80  * -# The conflict set represents the conflict clause saying that at least one
81  * of the conflict variables must take a different value. The conflict set is then passed
82  * to the conflict handlers, that may create a corresponding constraint (e.g. a logicor
83  * constraint or bound disjunction constraint) out of these conflict variables and
84  * add it to the problem.
85  *
86  * If all deduced bound changes come with (global) inference information, depending on
87  * the conflict analyzing strategy, the resulting conflict set has the following property:
88  * - 1-FirstUIP: In the depth level where the conflict was found, at most one variable
89  * assigned at that level is member of the conflict set. This conflict variable is the
90  * first unique implication point of its depth level (FUIP).
91  * - All-FirstUIP: For each depth level, at most one variable assigned at that level is
92  * member of the conflict set. This conflict variable is the first unique implication
93  * point of its depth level (FUIP).
94  *
95  * The user has to do the following to get the conflict analysis running in its
96  * current implementation:
97  * - A constraint handler or propagator supporting the conflict analysis must implement
98  * the CONSRESPROP/PROPRESPROP call, that processes a bound change inference b and puts all
99  * the reason bounds leading to the application of b with calls to
100  * SCIPaddConflictBound() on the conflict queue (algorithm step 3.(a)).
101  * - If the current bounds lead to a deduction of a bound change (e.g. in domain
102  * propagation), a constraint handler should call SCIPinferVarLbCons() or
103  * SCIPinferVarUbCons(), thus providing the constraint that infered the bound change.
104  * A propagator should call SCIPinferVarLbProp() or SCIPinferVarUbProp() instead,
105  * thus providing a pointer to itself.
106  * - If (in the current bounds) an infeasibility is detected, the constraint handler or
107  * propagator should
108  * 1. call SCIPinitConflictAnalysis() to initialize the conflict queue,
109  * 2. call SCIPaddConflictBound() for each bound that lead to the conflict,
110  * 3. call SCIPanalyzeConflictCons() or SCIPanalyzeConflict() to analyze the conflict
111  * and add an appropriate conflict constraint.
112  */
113 
114 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
115 
116 #include <assert.h>
117 #include <string.h>
118 
119 #include "scip/def.h"
120 #include "scip/set.h"
121 #include "scip/stat.h"
122 #include "scip/clock.h"
123 #include "scip/visual.h"
124 #include "scip/history.h"
125 #include "scip/paramset.h"
126 #include "scip/lp.h"
127 #include "scip/var.h"
128 #include "scip/prob.h"
129 #include "scip/tree.h"
130 #include "scip/scip.h"
131 #include "scip/conflict.h"
132 #include "scip/cons.h"
133 #include "scip/prop.h"
134 #include "scip/presolve.h"
135 #include "scip/debug.h"
136 #include "scip/pub_message.h"
137 #include "scip/pub_misc.h"
138 #include "scip/cuts.h"
139 #include "lpi/lpi.h"
140 
141 #include "scip/struct_conflict.h"
142 #include "scip/cons_linear.h"
143 
144 #define BOUNDSWITCH 0.51 /**< threshold for bound switching - see SCIPcutsAppyMIR() */
145 #define USEVBDS FALSE /**< use variable bounds - see SCIPcutsAppyMIR() */
146 #define ALLOWLOCAL FALSE /**< allow to generate local cuts - see SCIPcutsAppyMIR() */
147 #define FIXINTEGRALRHS FALSE /**< try to generate an integral rhs - see SCIPcutsAppyMIR() */
148 #define MINFRAC 0.05 /**< minimal fractionality of floor(rhs) - see SCIPcutsApplyMIR() */
149 #define SCALE 1.0 /**< additional scaling factor - see SCIPcutsApplyMIR() */
150 
151 /*#define SCIP_CONFGRAPH*/
152 
153 
154 #ifdef SCIP_CONFGRAPH
155 /*
156  * Output of Conflict Graph
157  */
158 
159 #include <stdio.h>
160 
161 static FILE* confgraphfile = NULL; /**< output file for current conflict graph */
162 static SCIP_BDCHGINFO* confgraphcurrentbdchginfo = NULL; /**< currently resolved bound change */
163 static int confgraphnconflictsets = 0; /**< number of conflict sets marked in the graph */
164 
165 /** writes a node section to the conflict graph file */
166 static
167 void confgraphWriteNode(
168  void* idptr, /**< id of the node */
169  const char* label, /**< label of the node */
170  const char* nodetype, /**< type of the node */
171  const char* fillcolor, /**< color of the node's interior */
172  const char* bordercolor /**< color of the node's border */
173  )
174 {
175  assert(confgraphfile != NULL);
176 
177  SCIPgmlWriteNode(confgraphfile, (unsigned int)(size_t)idptr, label, nodetype, fillcolor, bordercolor);
178 }
179 
180 /** writes an edge section to the conflict graph file */
181 static
182 void confgraphWriteEdge(
183  void* source, /**< source node of the edge */
184  void* target, /**< target node of the edge */
185  const char* color /**< color of the edge */
186  )
187 {
188  assert(confgraphfile != NULL);
189 
190 #ifndef SCIP_CONFGRAPH_EDGE
191  SCIPgmlWriteArc(confgraphfile, (unsigned int)(size_t)source, (unsigned int)(size_t)target, NULL, color);
192 #else
193  SCIPgmlWriteEdge(confgraphfile, (unsigned int)(size_t)source, (unsigned int)(size_t)target, NULL, color);
194 #endif
195 }
196 
197 /** creates a file to output the current conflict graph into; adds the conflict vertex to the graph */
198 static
199 SCIP_RETCODE confgraphCreate(
200  SCIP_SET* set, /**< global SCIP settings */
201  SCIP_CONFLICT* conflict /**< conflict analysis data */
202  )
203 {
204  char fname[SCIP_MAXSTRLEN];
205 
206  assert(conflict != NULL);
207  assert(confgraphfile == NULL);
208 
209  (void) SCIPsnprintf(fname, SCIP_MAXSTRLEN, "conf%p%d.gml", conflict, conflict->count);
210  SCIPinfoMessage(set->scip, NULL, "storing conflict graph in file <%s>\n", fname);
211 
212  confgraphfile = fopen(fname, "w");
213 
214  if( confgraphfile == NULL )
215  {
216  SCIPerrorMessage("cannot open graph file <%s>\n", fname);
217  SCIPABORT(); /*lint !e527*/
218  return SCIP_WRITEERROR;
219  }
220 
221  SCIPgmlWriteOpening(confgraphfile, TRUE);
222 
223  confgraphWriteNode(NULL, "conflict", "ellipse", "#ff0000", "#000000");
224 
225  confgraphcurrentbdchginfo = NULL;
226 
227  return SCIP_OKAY;
228 }
229 
230 /** closes conflict graph file */
231 static
232 void confgraphFree(
233  void
234  )
235 {
236  if( confgraphfile != NULL )
237  {
238  SCIPgmlWriteClosing(confgraphfile);
239 
240  fclose(confgraphfile);
241 
242  confgraphfile = NULL;
243  confgraphnconflictsets = 0;
244  }
245 }
246 
247 /** adds a bound change node to the conflict graph and links it to the currently resolved bound change */
248 static
249 void confgraphAddBdchg(
250  SCIP_BDCHGINFO* bdchginfo /**< bound change to add to the conflict graph */
251  )
252 {
253  const char* colors[] = {
254  "#8888ff", /* blue for constraint resolving */
255  "#ffff00", /* yellow for propagator resolving */
256  "#55ff55" /* green branching decision */
257  };
258  char label[SCIP_MAXSTRLEN];
259  char depth[SCIP_MAXSTRLEN];
260  int col;
261 
262 
263  switch( SCIPbdchginfoGetChgtype(bdchginfo) )
264  {
266  col = 2;
267  break;
269  col = 0;
270  break;
272  col = (SCIPbdchginfoGetInferProp(bdchginfo) == NULL ? 1 : 0);
273  break;
274  default:
275  SCIPerrorMessage("invalid bound change type\n");
276  col = 0;
277  SCIPABORT();
278  break;
279  }
280 
281  if( SCIPbdchginfoGetDepth(bdchginfo) == INT_MAX )
282  (void) SCIPsnprintf(depth, SCIP_MAXSTRLEN, "dive");
283  else
284  (void) SCIPsnprintf(depth, SCIP_MAXSTRLEN, "%d", SCIPbdchginfoGetDepth(bdchginfo));
285  (void) SCIPsnprintf(label, SCIP_MAXSTRLEN, "%s %s %g\n[%s:%d]", SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)),
286  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
287  SCIPbdchginfoGetNewbound(bdchginfo), depth, SCIPbdchginfoGetPos(bdchginfo));
288  confgraphWriteNode(bdchginfo, label, "ellipse", colors[col], "#000000");
289  confgraphWriteEdge(bdchginfo, confgraphcurrentbdchginfo, "#000000");
290 }
291 
292 /** links the already existing bound change node to the currently resolved bound change */
293 static
294 void confgraphLinkBdchg(
295  SCIP_BDCHGINFO* bdchginfo /**< bound change to add to the conflict graph */
296  )
297 {
298  confgraphWriteEdge(bdchginfo, confgraphcurrentbdchginfo, "#000000");
299 }
300 
301 /** marks the given bound change to be the currently resolved bound change */
302 static
303 void confgraphSetCurrentBdchg(
304  SCIP_BDCHGINFO* bdchginfo /**< bound change to add to the conflict graph */
305  )
306 {
307  confgraphcurrentbdchginfo = bdchginfo;
308 }
309 
310 /** marks given conflict set in the conflict graph */
311 static
312 void confgraphMarkConflictset(
313  SCIP_CONFLICTSET* conflictset /**< conflict set */
314  )
315 {
316  char label[SCIP_MAXSTRLEN];
317  int i;
318 
319  assert(conflictset != NULL);
320 
321  confgraphnconflictsets++;
322  (void) SCIPsnprintf(label, SCIP_MAXSTRLEN, "conf %d (%d)", confgraphnconflictsets, conflictset->validdepth);
323  confgraphWriteNode((void*)(size_t)confgraphnconflictsets, label, "rectangle", "#ff00ff", "#000000");
324  for( i = 0; i < conflictset->nbdchginfos; ++i )
325  confgraphWriteEdge((void*)(size_t)confgraphnconflictsets, conflictset->bdchginfos[i], "#ff00ff");
326 }
327 
328 #endif
329 
330 
331 
332 /*
333  * Conflict Handler
334  */
335 
336 /** compares two conflict handlers w. r. to their priority */
337 SCIP_DECL_SORTPTRCOMP(SCIPconflicthdlrComp)
338 { /*lint --e{715}*/
339  return ((SCIP_CONFLICTHDLR*)elem2)->priority - ((SCIP_CONFLICTHDLR*)elem1)->priority;
340 }
341 
342 /** comparison method for sorting conflict handler w.r.t. to their name */
343 SCIP_DECL_SORTPTRCOMP(SCIPconflicthdlrCompName)
344 {
346 }
347 
348 /** method to call, when the priority of a conflict handler was changed */
349 static
350 SCIP_DECL_PARAMCHGD(paramChgdConflicthdlrPriority)
351 { /*lint --e{715}*/
352  SCIP_PARAMDATA* paramdata;
353 
354  paramdata = SCIPparamGetData(param);
355  assert(paramdata != NULL);
356 
357  /* use SCIPsetConflicthdlrPriority() to mark the conflicthdlrs unsorted */
358  SCIP_CALL( SCIPsetConflicthdlrPriority(scip, (SCIP_CONFLICTHDLR*)paramdata, SCIPparamGetInt(param)) ); /*lint !e740*/
359 
360  return SCIP_OKAY;
361 }
362 
363 /** copies the given conflict handler to a new scip */
365  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
366  SCIP_SET* set /**< SCIP_SET of SCIP to copy to */
367  )
368 {
369  assert(conflicthdlr != NULL);
370  assert(set != NULL);
371  assert(set->scip != NULL);
372 
373  if( conflicthdlr->conflictcopy != NULL )
374  {
375  SCIPsetDebugMsg(set, "including conflict handler %s in subscip %p\n", SCIPconflicthdlrGetName(conflicthdlr), (void*)set->scip);
376  SCIP_CALL( conflicthdlr->conflictcopy(set->scip, conflicthdlr) );
377  }
378 
379  return SCIP_OKAY;
380 }
381 
382 /** creates a conflict handler */
384  SCIP_CONFLICTHDLR** conflicthdlr, /**< pointer to conflict handler data structure */
385  SCIP_SET* set, /**< global SCIP settings */
386  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
387  BMS_BLKMEM* blkmem, /**< block memory for parameter settings */
388  const char* name, /**< name of conflict handler */
389  const char* desc, /**< description of conflict handler */
390  int priority, /**< priority of the conflict handler */
391  SCIP_DECL_CONFLICTCOPY((*conflictcopy)), /**< copy method of conflict handler or NULL if you don't want to copy your plugin into sub-SCIPs */
392  SCIP_DECL_CONFLICTFREE((*conflictfree)), /**< destructor of conflict handler */
393  SCIP_DECL_CONFLICTINIT((*conflictinit)), /**< initialize conflict handler */
394  SCIP_DECL_CONFLICTEXIT((*conflictexit)), /**< deinitialize conflict handler */
395  SCIP_DECL_CONFLICTINITSOL((*conflictinitsol)),/**< solving process initialization method of conflict handler */
396  SCIP_DECL_CONFLICTEXITSOL((*conflictexitsol)),/**< solving process deinitialization method of conflict handler */
397  SCIP_DECL_CONFLICTEXEC((*conflictexec)), /**< conflict processing method of conflict handler */
398  SCIP_CONFLICTHDLRDATA* conflicthdlrdata /**< conflict handler data */
399  )
400 {
402  char paramdesc[SCIP_MAXSTRLEN];
403 
404  assert(conflicthdlr != NULL);
405  assert(name != NULL);
406  assert(desc != NULL);
407 
408  SCIP_ALLOC( BMSallocMemory(conflicthdlr) );
409  SCIP_ALLOC( BMSduplicateMemoryArray(&(*conflicthdlr)->name, name, strlen(name)+1) );
410  SCIP_ALLOC( BMSduplicateMemoryArray(&(*conflicthdlr)->desc, desc, strlen(desc)+1) );
411  (*conflicthdlr)->priority = priority;
412  (*conflicthdlr)->conflictcopy = conflictcopy;
413  (*conflicthdlr)->conflictfree = conflictfree;
414  (*conflicthdlr)->conflictinit = conflictinit;
415  (*conflicthdlr)->conflictexit = conflictexit;
416  (*conflicthdlr)->conflictinitsol = conflictinitsol;
417  (*conflicthdlr)->conflictexitsol = conflictexitsol;
418  (*conflicthdlr)->conflictexec = conflictexec;
419  (*conflicthdlr)->conflicthdlrdata = conflicthdlrdata;
420  (*conflicthdlr)->initialized = FALSE;
421 
422  SCIP_CALL( SCIPclockCreate(&(*conflicthdlr)->setuptime, SCIP_CLOCKTYPE_DEFAULT) );
423  SCIP_CALL( SCIPclockCreate(&(*conflicthdlr)->conflicttime, SCIP_CLOCKTYPE_DEFAULT) );
424 
425  /* add parameters */
426  (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "conflict/%s/priority", name);
427  (void) SCIPsnprintf(paramdesc, SCIP_MAXSTRLEN, "priority of conflict handler <%s>", name);
428  SCIP_CALL( SCIPsetAddIntParam(set, messagehdlr, blkmem, paramname, paramdesc,
429  &(*conflicthdlr)->priority, TRUE, priority, INT_MIN, INT_MAX,
430  paramChgdConflicthdlrPriority, (SCIP_PARAMDATA*)(*conflicthdlr)) ); /*lint !e740*/
431 
432  return SCIP_OKAY;
433 }
434 
435 /** calls destructor and frees memory of conflict handler */
437  SCIP_CONFLICTHDLR** conflicthdlr, /**< pointer to conflict handler data structure */
438  SCIP_SET* set /**< global SCIP settings */
439  )
440 {
441  assert(conflicthdlr != NULL);
442  assert(*conflicthdlr != NULL);
443  assert(!(*conflicthdlr)->initialized);
444  assert(set != NULL);
445 
446  /* call destructor of conflict handler */
447  if( (*conflicthdlr)->conflictfree != NULL )
448  {
449  SCIP_CALL( (*conflicthdlr)->conflictfree(set->scip, *conflicthdlr) );
450  }
451 
452  SCIPclockFree(&(*conflicthdlr)->conflicttime);
453  SCIPclockFree(&(*conflicthdlr)->setuptime);
454 
455  BMSfreeMemoryArray(&(*conflicthdlr)->name);
456  BMSfreeMemoryArray(&(*conflicthdlr)->desc);
457  BMSfreeMemory(conflicthdlr);
458 
459  return SCIP_OKAY;
460 }
461 
462 /** calls initialization method of conflict handler */
464  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
465  SCIP_SET* set /**< global SCIP settings */
466  )
467 {
468  assert(conflicthdlr != NULL);
469  assert(set != NULL);
470 
471  if( conflicthdlr->initialized )
472  {
473  SCIPerrorMessage("conflict handler <%s> already initialized\n", conflicthdlr->name);
474  return SCIP_INVALIDCALL;
475  }
476 
477  if( set->misc_resetstat )
478  {
479  SCIPclockReset(conflicthdlr->setuptime);
480  SCIPclockReset(conflicthdlr->conflicttime);
481  }
482 
483  /* call initialization method of conflict handler */
484  if( conflicthdlr->conflictinit != NULL )
485  {
486  /* start timing */
487  SCIPclockStart(conflicthdlr->setuptime, set);
488 
489  SCIP_CALL( conflicthdlr->conflictinit(set->scip, conflicthdlr) );
490 
491  /* stop timing */
492  SCIPclockStop(conflicthdlr->setuptime, set);
493  }
494  conflicthdlr->initialized = TRUE;
495 
496  return SCIP_OKAY;
497 }
498 
499 /** calls exit method of conflict handler */
501  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
502  SCIP_SET* set /**< global SCIP settings */
503  )
504 {
505  assert(conflicthdlr != NULL);
506  assert(set != NULL);
507 
508  if( !conflicthdlr->initialized )
509  {
510  SCIPerrorMessage("conflict handler <%s> not initialized\n", conflicthdlr->name);
511  return SCIP_INVALIDCALL;
512  }
513 
514  /* call deinitialization method of conflict handler */
515  if( conflicthdlr->conflictexit != NULL )
516  {
517  /* start timing */
518  SCIPclockStart(conflicthdlr->setuptime, set);
519 
520  SCIP_CALL( conflicthdlr->conflictexit(set->scip, conflicthdlr) );
521 
522  /* stop timing */
523  SCIPclockStop(conflicthdlr->setuptime, set);
524  }
525  conflicthdlr->initialized = FALSE;
526 
527  return SCIP_OKAY;
528 }
529 
530 /** informs conflict handler that the branch and bound process is being started */
532  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
533  SCIP_SET* set /**< global SCIP settings */
534  )
535 {
536  assert(conflicthdlr != NULL);
537  assert(set != NULL);
538 
539  /* call solving process initialization method of conflict handler */
540  if( conflicthdlr->conflictinitsol != NULL )
541  {
542  /* start timing */
543  SCIPclockStart(conflicthdlr->setuptime, set);
544 
545  SCIP_CALL( conflicthdlr->conflictinitsol(set->scip, conflicthdlr) );
546 
547  /* stop timing */
548  SCIPclockStop(conflicthdlr->setuptime, set);
549  }
550 
551  return SCIP_OKAY;
552 }
553 
554 /** informs conflict handler that the branch and bound process data is being freed */
556  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
557  SCIP_SET* set /**< global SCIP settings */
558  )
559 {
560  assert(conflicthdlr != NULL);
561  assert(set != NULL);
562 
563  /* call solving process deinitialization method of conflict handler */
564  if( conflicthdlr->conflictexitsol != NULL )
565  {
566  /* start timing */
567  SCIPclockStart(conflicthdlr->setuptime, set);
568 
569  SCIP_CALL( conflicthdlr->conflictexitsol(set->scip, conflicthdlr) );
570 
571  /* stop timing */
572  SCIPclockStop(conflicthdlr->setuptime, set);
573  }
574 
575  return SCIP_OKAY;
576 }
577 
578 /** calls execution method of conflict handler */
580  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
581  SCIP_SET* set, /**< global SCIP settings */
582  SCIP_NODE* node, /**< node to add conflict constraint to */
583  SCIP_NODE* validnode, /**< node at which the constraint is valid */
584  SCIP_BDCHGINFO** bdchginfos, /**< bound change resembling the conflict set */
585  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict */
586  int nbdchginfos, /**< number of bound changes in the conflict set */
587  SCIP_CONFTYPE conftype, /**< type of the conflict */
588  SCIP_Bool usescutoffbound, /**< depends the conflict on the cutoff bound? */
589  SCIP_Bool resolved, /**< was the conflict set already used to create a constraint? */
590  SCIP_RESULT* result /**< pointer to store the result of the callback method */
591  )
592 {
593 
594  assert(conflicthdlr != NULL);
595  assert(set != NULL);
596  assert(bdchginfos != NULL || nbdchginfos == 0);
597  assert(result != NULL);
598 
599  /* call solution start method of conflict handler */
600  *result = SCIP_DIDNOTRUN;
601  if( conflicthdlr->conflictexec != NULL )
602  {
603  /* start timing */
604  SCIPclockStart(conflicthdlr->conflicttime, set);
605 
606  SCIP_CALL( conflicthdlr->conflictexec(set->scip, conflicthdlr, node, validnode, bdchginfos, relaxedbds, nbdchginfos,
607  conftype, usescutoffbound, set->conf_separate, (SCIPnodeGetDepth(validnode) > 0), set->conf_dynamic,
608  set->conf_removable, resolved, result) );
609 
610  /* stop timing */
611  SCIPclockStop(conflicthdlr->conflicttime, set);
612 
613  if( *result != SCIP_CONSADDED
614  && *result != SCIP_DIDNOTFIND
615  && *result != SCIP_DIDNOTRUN )
616  {
617  SCIPerrorMessage("execution method of conflict handler <%s> returned invalid result <%d>\n",
618  conflicthdlr->name, *result);
619  return SCIP_INVALIDRESULT;
620  }
621  }
622 
623  return SCIP_OKAY;
624 }
625 
626 /** gets user data of conflict handler */
628  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
629  )
630 {
631  assert(conflicthdlr != NULL);
632 
633  return conflicthdlr->conflicthdlrdata;
634 }
635 
636 /** sets user data of conflict handler; user has to free old data in advance! */
638  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
639  SCIP_CONFLICTHDLRDATA* conflicthdlrdata /**< new conflict handler user data */
640  )
641 {
642  assert(conflicthdlr != NULL);
643 
644  conflicthdlr->conflicthdlrdata = conflicthdlrdata;
645 }
646 
647 /** set copy method of conflict handler */
649  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
650  SCIP_DECL_CONFLICTCOPY((*conflictcopy)) /**< copy method of the conflict handler */
651  )
652 {
653  assert(conflicthdlr != NULL);
654 
655  conflicthdlr->conflictcopy = conflictcopy;
656 }
657 
658 /** set destructor of conflict handler */
660  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
661  SCIP_DECL_CONFLICTFREE((*conflictfree)) /**< destructor of conflict handler */
662  )
663 {
664  assert(conflicthdlr != NULL);
665 
666  conflicthdlr->conflictfree = conflictfree;
667 }
668 
669 /** set initialization method of conflict handler */
671  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
672  SCIP_DECL_CONFLICTINIT((*conflictinit)) /**< initialization method conflict handler */
673  )
674 {
675  assert(conflicthdlr != NULL);
676 
677  conflicthdlr->conflictinit = conflictinit;
678 }
679 
680 /** set deinitialization method of conflict handler */
682  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
683  SCIP_DECL_CONFLICTEXIT((*conflictexit)) /**< deinitialization method conflict handler */
684  )
685 {
686  assert(conflicthdlr != NULL);
687 
688  conflicthdlr->conflictexit = conflictexit;
689 }
690 
691 /** set solving process initialization method of conflict handler */
693  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
694  SCIP_DECL_CONFLICTINITSOL((*conflictinitsol))/**< solving process initialization method of conflict handler */
695  )
696 {
697  assert(conflicthdlr != NULL);
698 
699  conflicthdlr->conflictinitsol = conflictinitsol;
700 }
701 
702 /** set solving process deinitialization method of conflict handler */
704  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
705  SCIP_DECL_CONFLICTEXITSOL((*conflictexitsol))/**< solving process deinitialization method of conflict handler */
706  )
707 {
708  assert(conflicthdlr != NULL);
709 
710  conflicthdlr->conflictexitsol = conflictexitsol;
711 }
712 
713 /** gets name of conflict handler */
715  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
716  )
717 {
718  assert(conflicthdlr != NULL);
719 
720  return conflicthdlr->name;
721 }
722 
723 /** gets description of conflict handler */
725  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
726  )
727 {
728  assert(conflicthdlr != NULL);
729 
730  return conflicthdlr->desc;
731 }
732 
733 /** gets priority of conflict handler */
735  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
736  )
737 {
738  assert(conflicthdlr != NULL);
739 
740  return conflicthdlr->priority;
741 }
742 
743 /** sets priority of conflict handler */
745  SCIP_CONFLICTHDLR* conflicthdlr, /**< conflict handler */
746  SCIP_SET* set, /**< global SCIP settings */
747  int priority /**< new priority of the conflict handler */
748  )
749 {
750  assert(conflicthdlr != NULL);
751  assert(set != NULL);
752 
753  conflicthdlr->priority = priority;
754  set->conflicthdlrssorted = FALSE;
755 }
756 
757 /** is conflict handler initialized? */
759  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
760  )
761 {
762  assert(conflicthdlr != NULL);
763 
764  return conflicthdlr->initialized;
765 }
766 
767 /** enables or disables all clocks of \p conflicthdlr, depending on the value of the flag */
769  SCIP_CONFLICTHDLR* conflicthdlr, /**< the conflict handler for which all clocks should be enabled or disabled */
770  SCIP_Bool enable /**< should the clocks of the conflict handler be enabled? */
771  )
772 {
773  assert(conflicthdlr != NULL);
774 
775  SCIPclockEnableOrDisable(conflicthdlr->setuptime, enable);
776  SCIPclockEnableOrDisable(conflicthdlr->conflicttime, enable);
777 }
778 
779 /** gets time in seconds used in this conflict handler for setting up for next stages */
781  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
782  )
783 {
784  assert(conflicthdlr != NULL);
785 
786  return SCIPclockGetTime(conflicthdlr->setuptime);
787 }
788 
789 /** gets time in seconds used in this conflict handler */
791  SCIP_CONFLICTHDLR* conflicthdlr /**< conflict handler */
792  )
793 {
794  assert(conflicthdlr != NULL);
795 
796  return SCIPclockGetTime(conflicthdlr->conflicttime);
797 }
798 
799 /*
800  * Conflict LP Bound Changes
801  */
802 
803 
804 /** create conflict LP bound change data structure */
805 static
807  SCIP_LPBDCHGS** lpbdchgs, /**< pointer to store the conflict LP bound change data structure */
808  SCIP_SET* set, /**< global SCIP settings */
809  int ncols /**< number of columns */
810  )
811 {
812  SCIP_CALL( SCIPsetAllocBuffer(set, lpbdchgs) );
813 
814  SCIP_CALL( SCIPsetAllocBufferArray(set, &(*lpbdchgs)->bdchginds, ncols) );
815  SCIP_CALL( SCIPsetAllocBufferArray(set, &(*lpbdchgs)->bdchglbs, ncols) );
816  SCIP_CALL( SCIPsetAllocBufferArray(set, &(*lpbdchgs)->bdchgubs, ncols) );
817  SCIP_CALL( SCIPsetAllocBufferArray(set, &(*lpbdchgs)->bdchgcolinds, ncols) );
818  SCIP_CALL( SCIPsetAllocBufferArray(set, &(*lpbdchgs)->usedcols, ncols) );
819  BMSclearMemoryArray((*lpbdchgs)->usedcols, ncols);
820 
821  (*lpbdchgs)->nbdchgs = 0;
822 
823  return SCIP_OKAY;
824 }
825 
826 /** reset conflict LP bound change data structure */
827 static
829  SCIP_LPBDCHGS* lpbdchgs, /**< conflict LP bound change data structure */
830  int ncols /**< number of columns */
831  )
832 {
833  assert(lpbdchgs != NULL);
834 
835  BMSclearMemoryArray(lpbdchgs->usedcols, ncols);
836  lpbdchgs->nbdchgs = 0;
837 }
838 
839 /** free conflict LP bound change data structure */
840 static
842  SCIP_LPBDCHGS** lpbdchgs, /**< pointer to store the conflict LP bound change data structure */
843  SCIP_SET* set /**< global SCIP settings */
844  )
845 {
846  SCIPsetFreeBufferArray(set, &(*lpbdchgs)->usedcols);
847  SCIPsetFreeBufferArray(set, &(*lpbdchgs)->bdchgcolinds);
848  SCIPsetFreeBufferArray(set, &(*lpbdchgs)->bdchgubs);
849  SCIPsetFreeBufferArray(set, &(*lpbdchgs)->bdchglbs);
850  SCIPsetFreeBufferArray(set, &(*lpbdchgs)->bdchginds);
851 
852  SCIPsetFreeBuffer(set, lpbdchgs);
853 }
854 
855 /*
856  * Conflict Sets
857  */
858 
859 /** resizes the array of the temporary bound change informations to be able to store at least num bound change entries */
860 static
862  SCIP_CONFLICT* conflict, /**< conflict analysis data */
863  SCIP_SET* set, /**< global SCIP settings */
864  int num /**< minimal number of slots in arrays */
865  )
866 {
867  assert(conflict != NULL);
868  assert(set != NULL);
869 
870  if( num > conflict->tmpbdchginfossize )
871  {
872  int newsize;
873 
874  newsize = SCIPsetCalcMemGrowSize(set, num);
875  SCIP_ALLOC( BMSreallocMemoryArray(&conflict->tmpbdchginfos, newsize) );
876  conflict->tmpbdchginfossize = newsize;
877  }
878  assert(num <= conflict->tmpbdchginfossize);
879 
880  return SCIP_OKAY;
881 }
882 
883 /** creates a temporary bound change information object that is destroyed after the conflict sets are flushed */
884 static
886  SCIP_CONFLICT* conflict, /**< conflict analysis data */
887  BMS_BLKMEM* blkmem, /**< block memory */
888  SCIP_SET* set, /**< global SCIP settings */
889  SCIP_VAR* var, /**< active variable that changed the bounds */
890  SCIP_BOUNDTYPE boundtype, /**< type of bound for var: lower or upper bound */
891  SCIP_Real oldbound, /**< old value for bound */
892  SCIP_Real newbound, /**< new value for bound */
893  SCIP_BDCHGINFO** bdchginfo /**< pointer to store bound change information */
894  )
895 {
896  assert(conflict != NULL);
897 
898  SCIP_CALL( conflictEnsureTmpbdchginfosMem(conflict, set, conflict->ntmpbdchginfos+1) );
899  SCIP_CALL( SCIPbdchginfoCreate(&conflict->tmpbdchginfos[conflict->ntmpbdchginfos], blkmem,
900  var, boundtype, oldbound, newbound) );
901  *bdchginfo = conflict->tmpbdchginfos[conflict->ntmpbdchginfos];
902  conflict->ntmpbdchginfos++;
903 
904  return SCIP_OKAY;
905 }
906 
907 /** frees all temporarily created bound change information data */
908 static
910  SCIP_CONFLICT* conflict, /**< conflict analysis data */
911  BMS_BLKMEM* blkmem /**< block memory */
912  )
913 {
914  int i;
915 
916  assert(conflict != NULL);
917 
918  for( i = 0; i < conflict->ntmpbdchginfos; ++i )
919  SCIPbdchginfoFree(&conflict->tmpbdchginfos[i], blkmem);
920  conflict->ntmpbdchginfos = 0;
921 }
922 
923 /** clears the given conflict set */
924 static
926  SCIP_CONFLICTSET* conflictset /**< conflict set */
927  )
928 {
929  assert(conflictset != NULL);
930 
931  conflictset->nbdchginfos = 0;
932  conflictset->validdepth = 0;
933  conflictset->insertdepth = 0;
934  conflictset->conflictdepth = 0;
935  conflictset->repropdepth = 0;
936  conflictset->repropagate = TRUE;
937  conflictset->usescutoffbound = FALSE;
938  conflictset->conflicttype = SCIP_CONFTYPE_UNKNOWN;
939 }
940 
941 /** creates an empty conflict set */
942 static
944  SCIP_CONFLICTSET** conflictset, /**< pointer to store the conflict set */
945  BMS_BLKMEM* blkmem /**< block memory of transformed problem */
946  )
947 {
948  assert(conflictset != NULL);
949 
950  SCIP_ALLOC( BMSallocBlockMemory(blkmem, conflictset) );
951  (*conflictset)->bdchginfos = NULL;
952  (*conflictset)->relaxedbds = NULL;
953  (*conflictset)->sortvals = NULL;
954  (*conflictset)->bdchginfossize = 0;
955 
956  conflictsetClear(*conflictset);
957 
958  return SCIP_OKAY;
959 }
960 
961 /** creates a copy of the given conflict set, allocating an additional amount of memory */
962 static
964  SCIP_CONFLICTSET** targetconflictset, /**< pointer to store the conflict set */
965  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
966  SCIP_CONFLICTSET* sourceconflictset, /**< source conflict set */
967  int nadditionalelems /**< number of additional elements to allocate memory for */
968  )
969 {
970  int targetsize;
971 
972  assert(targetconflictset != NULL);
973  assert(sourceconflictset != NULL);
974 
975  targetsize = sourceconflictset->nbdchginfos + nadditionalelems;
976  SCIP_ALLOC( BMSallocBlockMemory(blkmem, targetconflictset) );
977  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*targetconflictset)->bdchginfos, targetsize) );
978  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*targetconflictset)->relaxedbds, targetsize) );
979  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*targetconflictset)->sortvals, targetsize) );
980  (*targetconflictset)->bdchginfossize = targetsize;
981 
982  BMScopyMemoryArray((*targetconflictset)->bdchginfos, sourceconflictset->bdchginfos, sourceconflictset->nbdchginfos);
983  BMScopyMemoryArray((*targetconflictset)->relaxedbds, sourceconflictset->relaxedbds, sourceconflictset->nbdchginfos);
984  BMScopyMemoryArray((*targetconflictset)->sortvals, sourceconflictset->sortvals, sourceconflictset->nbdchginfos);
985 
986  (*targetconflictset)->nbdchginfos = sourceconflictset->nbdchginfos;
987  (*targetconflictset)->validdepth = sourceconflictset->validdepth;
988  (*targetconflictset)->insertdepth = sourceconflictset->insertdepth;
989  (*targetconflictset)->conflictdepth = sourceconflictset->conflictdepth;
990  (*targetconflictset)->repropdepth = sourceconflictset->repropdepth;
991  (*targetconflictset)->usescutoffbound = sourceconflictset->usescutoffbound;
992  (*targetconflictset)->conflicttype = sourceconflictset->conflicttype;
993 
994  return SCIP_OKAY;
995 }
996 
997 /** frees a conflict set */
998 static
1000  SCIP_CONFLICTSET** conflictset, /**< pointer to the conflict set */
1001  BMS_BLKMEM* blkmem /**< block memory of transformed problem */
1002  )
1003 {
1004  assert(conflictset != NULL);
1005  assert(*conflictset != NULL);
1006 
1007  BMSfreeBlockMemoryArrayNull(blkmem, &(*conflictset)->bdchginfos, (*conflictset)->bdchginfossize);
1008  BMSfreeBlockMemoryArrayNull(blkmem, &(*conflictset)->relaxedbds, (*conflictset)->bdchginfossize);
1009  BMSfreeBlockMemoryArrayNull(blkmem, &(*conflictset)->sortvals, (*conflictset)->bdchginfossize);
1010  BMSfreeBlockMemory(blkmem, conflictset);
1011 }
1012 
1013 /** resizes the arrays of the conflict set to be able to store at least num bound change entries */
1014 static
1016  SCIP_CONFLICTSET* conflictset, /**< conflict set */
1017  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
1018  SCIP_SET* set, /**< global SCIP settings */
1019  int num /**< minimal number of slots in arrays */
1020  )
1021 {
1022  assert(conflictset != NULL);
1023  assert(set != NULL);
1024 
1025  if( num > conflictset->bdchginfossize )
1026  {
1027  int newsize;
1028 
1029  newsize = SCIPsetCalcMemGrowSize(set, num);
1030  SCIP_ALLOC( BMSreallocBlockMemoryArray(blkmem, &conflictset->bdchginfos, conflictset->bdchginfossize, newsize) );
1031  SCIP_ALLOC( BMSreallocBlockMemoryArray(blkmem, &conflictset->relaxedbds, conflictset->bdchginfossize, newsize) );
1032  SCIP_ALLOC( BMSreallocBlockMemoryArray(blkmem, &conflictset->sortvals, conflictset->bdchginfossize, newsize) );
1033  conflictset->bdchginfossize = newsize;
1034  }
1035  assert(num <= conflictset->bdchginfossize);
1036 
1037  return SCIP_OKAY;
1038 }
1039 
1040 /** calculates the score of the conflict set
1041  *
1042  * the score is weighted sum of number of bound changes, repropagation depth, and valid depth
1043  */
1044 static
1046  SCIP_CONFLICTSET* conflictset, /**< conflict set */
1047  SCIP_SET* set /**< global SCIP settings */
1048  )
1049 {
1050  assert(conflictset != NULL);
1051 
1052  return -(set->conf_weightsize * conflictset->nbdchginfos
1053  + set->conf_weightrepropdepth * conflictset->repropdepth
1054  + set->conf_weightvaliddepth * conflictset->validdepth);
1055 }
1056 
1057 /** calculates the score of a bound change within a conflict */
1058 static
1060  SCIP_Real prooflhs, /**< lhs of proof constraint */
1061  SCIP_Real proofact, /**< activity of the proof constraint */
1062  SCIP_Real proofactdelta, /**< activity change */
1063  SCIP_Real proofcoef, /**< coefficient in proof constraint */
1064  int depth, /**< bound change depth */
1065  int currentdepth, /**< current depth */
1066  SCIP_VAR* var, /**< variable corresponding to bound change */
1067  SCIP_SET* set /**< global SCIP settings */
1068  )
1069 {
1070  SCIP_COL* col;
1071  SCIP_Real score;
1072 
1073  score = set->conf_proofscorefac * (1.0 - proofactdelta/(prooflhs - proofact));
1074  score = MAX(score, 0.0);
1075  score += set->conf_depthscorefac * (SCIP_Real)(depth+1)/(SCIP_Real)(currentdepth+1);
1076 
1078  col = SCIPvarGetCol(var);
1079  else
1080  col = NULL;
1081 
1082  if( proofcoef > 0.0 )
1083  {
1084  if( col != NULL && SCIPcolGetNNonz(col) > 0 )
1085  score += set->conf_uplockscorefac * (SCIP_Real)(SCIPvarGetNLocksUp(var))/(SCIP_Real)(SCIPcolGetNNonz(col));
1086  else
1087  score += set->conf_uplockscorefac * SCIPvarGetNLocksUp(var);
1088  }
1089  else
1090  {
1091  if( col != NULL && SCIPcolGetNNonz(col) > 0 )
1092  score += set->conf_downlockscorefac * (SCIP_Real)(SCIPvarGetNLocksDown(var))/(SCIP_Real)(SCIPcolGetNNonz(col));
1093  else
1094  score += set->conf_downlockscorefac * SCIPvarGetNLocksDown(var);
1095  }
1096 
1097  return score;
1098 }
1099 
1100 /** check if the bound change info (which is the potential next candidate which is queued) is valid for the current
1101  * conflict analysis; a bound change info can get invalid if after this one was added to the queue, a weaker bound
1102  * change was added to the queue (due the bound widening idea) which immediately makes this bound change redundant; due
1103  * to the priority we did not removed that bound change info since that cost O(log(n)); hence we have to skip/ignore it
1104  * now
1105  *
1106  * The following situations can occur before for example the bound change info (x >= 3) is potentially popped from the
1107  * queue.
1108  *
1109  * Postcondition: the reason why (x >= 3) was queued is that at this time point no lower bound of x was involved yet in
1110  * the current conflict or the lower bound which was involved until then was stronger, e.g., (x >= 2).
1111  *
1112  * 1) during the time until (x >= 3) gets potentially popped no weaker lower bound was added to the queue, in that case
1113  * the conflictlbcount is valid and conflictlb is 3; that is (var->conflictlbcount == conflict->count &&
1114  * var->conflictlb == 3)
1115  *
1116  * 2) a weaker bound change info gets queued (e.g., x >= 4); this bound change is popped before (x >= 3) since it has
1117  * higher priority (which is the time stamp of the bound change info and (x >= 4) has to be done after (x >= 3)
1118  * during propagation or branching)
1119  *
1120  * a) if (x >= 4) is popped and added to the conflict set the conflictlbcount is still valid and conflictlb is at
1121  * most 4; that is (var->conflictlbcount == conflict->count && var->conflictlb >= 4); it follows that any bound
1122  * change info which is stronger than (x >= 4) gets ignored (for example x >= 2)
1123  *
1124  * b) if (x >= 4) is popped and resolved without introducing a new lower bound on x until (x >= 3) is a potentially
1125  * candidate the conflictlbcount indicates that bound change is currently not present; that is
1126  * (var->conflictlbcount != conflict->count)
1127  *
1128  * c) if (x >= 4) is popped and resolved and a new lower bound on x (e.g., x >= 2) is introduced until (x >= 3) is
1129  * pooped, the conflictlbcount indicates that bound change is currently present; that is (var->conflictlbcount ==
1130  * conflict->count); however the (x >= 3) only has be explained if conflictlb matches that one; that is
1131  * (var->conflictlb == bdchginfo->newbound); otherwise it redundant/invalid.
1132  */
1133 static
1135  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1136  SCIP_BDCHGINFO* bdchginfo /**< bound change information */
1137  )
1138 {
1139  SCIP_VAR* var;
1140 
1141  assert(bdchginfo != NULL);
1142 
1143  var = SCIPbdchginfoGetVar(bdchginfo);
1144  assert(var != NULL);
1145 
1146  /* the bound change info of a binary (domained) variable can never be invalid since the concepts of relaxed bounds
1147  * and bound widening do not make sense for these type of variables
1148  */
1149  if( SCIPvarIsBinary(var) )
1150  return FALSE;
1151 
1152  /* check if the bdchginfo is invaild since a tight/weaker bound change was already explained */
1154  {
1155  if( var->conflictlbcount != conflict->count || var->conflictlb != SCIPbdchginfoGetNewbound(bdchginfo) ) /*lint !e777*/
1156  {
1157  assert(!SCIPvarIsBinary(var));
1158  return TRUE;
1159  }
1160  }
1161  else
1162  {
1163  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_UPPER);
1164 
1165  if( var->conflictubcount != conflict->count || var->conflictub != SCIPbdchginfoGetNewbound(bdchginfo) ) /*lint !e777*/
1166  {
1167  assert(!SCIPvarIsBinary(var));
1168  return TRUE;
1169  }
1170  }
1171 
1172  return FALSE;
1173 }
1174 
1175 /** adds a bound change to a conflict set */
1176 static
1178  SCIP_CONFLICTSET* conflictset, /**< conflict set */
1179  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
1180  SCIP_SET* set, /**< global SCIP settings */
1181  SCIP_BDCHGINFO* bdchginfo, /**< bound change to add to the conflict set */
1182  SCIP_Real relaxedbd /**< relaxed bound */
1183  )
1184 {
1185  SCIP_BDCHGINFO** bdchginfos;
1186  SCIP_Real* relaxedbds;
1187  int* sortvals;
1188  SCIP_VAR* var;
1189  SCIP_BOUNDTYPE boundtype;
1190  int idx;
1191  int sortval;
1192  int pos;
1193 
1194  assert(conflictset != NULL);
1195  assert(bdchginfo != NULL);
1196 
1197  /* allocate memory for additional element */
1198  SCIP_CALL( conflictsetEnsureBdchginfosMem(conflictset, blkmem, set, conflictset->nbdchginfos+1) );
1199 
1200  /* insert the new bound change in the arrays sorted by increasing variable index and by bound type */
1201  bdchginfos = conflictset->bdchginfos;
1202  relaxedbds = conflictset->relaxedbds;
1203  sortvals = conflictset->sortvals;
1204  var = SCIPbdchginfoGetVar(bdchginfo);
1205  boundtype = SCIPbdchginfoGetBoundtype(bdchginfo);
1206  idx = SCIPvarGetIndex(var);
1207  assert(idx < INT_MAX/2);
1208  assert((int)boundtype == 0 || (int)boundtype == 1);
1209  sortval = 2*idx + (int)boundtype; /* first sorting criteria: variable index, second criteria: boundtype */
1210 
1211  /* insert new element into the sorted arrays; if an element exits with the same value insert the new element afterwards
1212  *
1213  * @todo check if it better (faster) to first search for the position O(log n) and compare the sort values and if
1214  * they are equal just replace the element and if not run the insert method O(n)
1215  */
1216 
1217  SCIPsortedvecInsertIntPtrReal(sortvals, (void**)bdchginfos, relaxedbds, sortval, (void*)bdchginfo, relaxedbd, &conflictset->nbdchginfos, &pos);
1218  assert(pos == conflictset->nbdchginfos - 1 || sortval < sortvals[pos+1]);
1219 
1220  /* merge multiple bound changes */
1221  if( pos > 0 && sortval == sortvals[pos-1] )
1222  {
1223  /* this is a multiple bound change */
1224  if( SCIPbdchginfoIsTighter(bdchginfo, bdchginfos[pos-1]) )
1225  {
1226  /* remove the "old" bound change since the "new" one in tighter */
1227  SCIPsortedvecDelPosIntPtrReal(sortvals, (void**)bdchginfos, relaxedbds, pos-1, &conflictset->nbdchginfos);
1228  }
1229  else if( SCIPbdchginfoIsTighter(bdchginfos[pos-1], bdchginfo) )
1230  {
1231  /* remove the "new" bound change since the "old" one is tighter */
1232  SCIPsortedvecDelPosIntPtrReal(sortvals, (void**)bdchginfos, relaxedbds, pos, &conflictset->nbdchginfos);
1233  }
1234  else
1235  {
1236  /* both bound change are equivalent; hence, keep the worse relaxed bound and remove one of them */
1237  relaxedbds[pos-1] = boundtype == SCIP_BOUNDTYPE_LOWER ? MAX(relaxedbds[pos-1], relaxedbd) : MIN(relaxedbds[pos-1], relaxedbd);
1238  SCIPsortedvecDelPosIntPtrReal(sortvals, (void**)bdchginfos, relaxedbds, pos, &conflictset->nbdchginfos);
1239  }
1240  }
1241 
1242  return SCIP_OKAY;
1243 }
1244 
1245 /** adds given bound changes to a conflict set */
1246 static
1248  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1249  SCIP_CONFLICTSET* conflictset, /**< conflict set */
1250  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
1251  SCIP_SET* set, /**< global SCIP settings */
1252  SCIP_BDCHGINFO** bdchginfos, /**< bound changes to add to the conflict set */
1253  int nbdchginfos /**< number of bound changes to add */
1254  )
1255 {
1256  SCIP_BDCHGINFO** confbdchginfos;
1257  SCIP_BDCHGINFO* bdchginfo;
1258  SCIP_Real* confrelaxedbds;
1259  int* confsortvals;
1260  int confnbdchginfos;
1261  int idx;
1262  int sortval;
1263  int i;
1264  SCIP_BOUNDTYPE boundtype;
1265 
1266  assert(conflict != NULL);
1267  assert(conflictset != NULL);
1268  assert(blkmem != NULL);
1269  assert(set != NULL);
1270  assert(bdchginfos != NULL || nbdchginfos == 0);
1271 
1272  /* nothing to add */
1273  if( nbdchginfos == 0 )
1274  return SCIP_OKAY;
1275 
1276  assert(bdchginfos != NULL);
1277 
1278  /* only one element to add, use the single insertion method */
1279  if( nbdchginfos == 1 )
1280  {
1281  bdchginfo = bdchginfos[0];
1282  assert(bdchginfo != NULL);
1283 
1284  if( !bdchginfoIsInvalid(conflict, bdchginfo) )
1285  {
1286  SCIP_CALL( conflictsetAddBound(conflictset, blkmem, set, bdchginfo, SCIPbdchginfoGetRelaxedBound(bdchginfo)) );
1287  }
1288  else
1289  {
1290  SCIPsetDebugMsg(set, "-> bound change info [%d:<%s> %s %g] is invaild -> ignore it\n", SCIPbdchginfoGetDepth(bdchginfo),
1291  SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)),
1292  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
1293  SCIPbdchginfoGetNewbound(bdchginfo));
1294  }
1295 
1296  return SCIP_OKAY;
1297  }
1298 
1299  confnbdchginfos = conflictset->nbdchginfos;
1300 
1301  /* allocate memory for additional element */
1302  SCIP_CALL( conflictsetEnsureBdchginfosMem(conflictset, blkmem, set, confnbdchginfos + nbdchginfos) );
1303 
1304  confbdchginfos = conflictset->bdchginfos;
1305  confrelaxedbds = conflictset->relaxedbds;
1306  confsortvals = conflictset->sortvals;
1307 
1308  assert(SCIP_BOUNDTYPE_LOWER == FALSE);/*lint !e641*/
1309  assert(SCIP_BOUNDTYPE_UPPER == TRUE);/*lint !e641*/
1310 
1311  for( i = 0; i < nbdchginfos; ++i )
1312  {
1313  bdchginfo = bdchginfos[i];
1314  assert(bdchginfo != NULL);
1315 
1316  /* add only valid bound change infos */
1317  if( !bdchginfoIsInvalid(conflict, bdchginfo) )
1318  {
1319  /* calculate sorting value */
1320  boundtype = SCIPbdchginfoGetBoundtype(bdchginfo);
1321  assert(SCIPbdchginfoGetVar(bdchginfo) != NULL);
1322 
1323  idx = SCIPvarGetIndex(SCIPbdchginfoGetVar(bdchginfo));
1324  assert(idx < INT_MAX/2);
1325 
1326  assert((int)boundtype == 0 || (int)boundtype == 1);
1327  sortval = 2*idx + (int)boundtype; /* first sorting criteria: variable index, second criteria: boundtype */
1328 
1329  /* add new element */
1330  confbdchginfos[confnbdchginfos] = bdchginfo;
1331  confrelaxedbds[confnbdchginfos] = SCIPbdchginfoGetRelaxedBound(bdchginfo);
1332  confsortvals[confnbdchginfos] = sortval;
1333  ++confnbdchginfos;
1334  }
1335  else
1336  {
1337  SCIPsetDebugMsg(set, "-> bound change info [%d:<%s> %s %g] is invaild -> ignore it\n", SCIPbdchginfoGetDepth(bdchginfo),
1338  SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)),
1339  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
1340  SCIPbdchginfoGetNewbound(bdchginfo));
1341  }
1342  }
1343  assert(confnbdchginfos <= conflictset->nbdchginfos + nbdchginfos);
1344 
1345  /* sort and merge the new conflict set */
1346  if( confnbdchginfos > conflictset->nbdchginfos )
1347  {
1348  int k = 0;
1349 
1350  /* sort array */
1351  SCIPsortIntPtrReal(confsortvals, (void**)confbdchginfos, confrelaxedbds, confnbdchginfos);
1352 
1353  i = 1;
1354  /* merge multiple bound changes */
1355  while( i < confnbdchginfos )
1356  {
1357  assert(i > k);
1358 
1359  /* is this a multiple bound change */
1360  if( confsortvals[k] == confsortvals[i] )
1361  {
1362  if( SCIPbdchginfoIsTighter(confbdchginfos[k], confbdchginfos[i]) )
1363  ++i;
1364  else if( SCIPbdchginfoIsTighter(confbdchginfos[i], confbdchginfos[k]) )
1365  {
1366  /* replace worse bound change info by tighter bound change info */
1367  confbdchginfos[k] = confbdchginfos[i];
1368  confrelaxedbds[k] = confrelaxedbds[i];
1369  confsortvals[k] = confsortvals[i];
1370  ++i;
1371  }
1372  else
1373  {
1374  assert(confsortvals[k] == confsortvals[i]);
1375 
1376  /* both bound change are equivalent; hence, keep the worse relaxed bound and remove one of them */
1377  confrelaxedbds[k] = (confsortvals[k] % 2 == 0) ? MAX(confrelaxedbds[k], confrelaxedbds[i]) : MIN(confrelaxedbds[k], confrelaxedbds[i]);
1378  ++i;
1379  }
1380  }
1381  else
1382  {
1383  /* all bound change infos must be valid */
1384  assert(!bdchginfoIsInvalid(conflict, confbdchginfos[k]));
1385 
1386  ++k;
1387  /* move next comparison element to the correct position */
1388  if( k != i )
1389  {
1390  confbdchginfos[k] = confbdchginfos[i];
1391  confrelaxedbds[k] = confrelaxedbds[i];
1392  confsortvals[k] = confsortvals[i];
1393  }
1394  ++i;
1395  }
1396  }
1397  /* last bound change infos must also be valid */
1398  assert(!bdchginfoIsInvalid(conflict, confbdchginfos[k]));
1399  /* the number of bound change infos cannot be decreased, it would mean that the conflict set was not merged
1400  * before
1401  */
1402  assert(conflictset->nbdchginfos <= k + 1 );
1403  assert(k + 1 <= confnbdchginfos);
1404 
1405  conflictset->nbdchginfos = k + 1;
1406  }
1407 
1408  return SCIP_OKAY;
1409 }
1410 
1411 /** calculates the conflict and the repropagation depths of the conflict set */
1412 static
1414  SCIP_CONFLICTSET* conflictset /**< conflict set */
1415  )
1416 {
1417  int maxdepth[2];
1418  int i;
1419 
1420  assert(conflictset != NULL);
1421  assert(conflictset->validdepth <= conflictset->insertdepth);
1422 
1423  /* get the depth of the last and last but one bound change */
1424  maxdepth[0] = conflictset->validdepth;
1425  maxdepth[1] = conflictset->validdepth;
1426  for( i = 0; i < conflictset->nbdchginfos; ++i )
1427  {
1428  int depth;
1429 
1430  depth = SCIPbdchginfoGetDepth(conflictset->bdchginfos[i]);
1431  assert(depth >= 0);
1432  if( depth > maxdepth[0] )
1433  {
1434  maxdepth[1] = maxdepth[0];
1435  maxdepth[0] = depth;
1436  }
1437  else if( depth > maxdepth[1] )
1438  maxdepth[1] = depth;
1439  }
1440  assert(maxdepth[0] >= maxdepth[1]);
1441 
1442  conflictset->conflictdepth = maxdepth[0];
1443  conflictset->repropdepth = maxdepth[1];
1444 }
1445 
1446 /** identifies the depth, at which the conflict set should be added:
1447  * - if the branching rule operates on variables only, and if all branching variables up to a certain
1448  * depth level are member of the conflict, the conflict constraint can only be violated in the subtree
1449  * of the node at that depth, because in all other nodes, at least one of these branching variables
1450  * violates its conflicting bound, such that the conflict constraint is feasible
1451  * - if there is at least one branching variable in a node, we assume, that this branching was performed
1452  * on variables, and that the siblings of this node are disjunct w.r.t. the branching variables' fixings
1453  * - we have to add the conflict set at least in the valid depth of the initial conflict set,
1454  * so we start searching at the first branching after this depth level, i.e. validdepth+1
1455  */
1456 static
1458  SCIP_CONFLICTSET* conflictset, /**< conflict set */
1459  SCIP_SET* set, /**< global SCIP settings */
1460  SCIP_TREE* tree /**< branch and bound tree */
1461  )
1462 {
1463  SCIP_Bool* branchingincluded;
1464  int currentdepth;
1465  int i;
1466 
1467  assert(conflictset != NULL);
1468  assert(set != NULL);
1469  assert(tree != NULL);
1470 
1471  /* the conflict set must not be inserted prior to its valid depth */
1472  conflictset->insertdepth = conflictset->validdepth;
1473  assert(conflictset->insertdepth >= 0);
1474 
1475  currentdepth = SCIPtreeGetCurrentDepth(tree);
1476  assert(currentdepth == tree->pathlen-1);
1477 
1478  /* mark the levels for which a branching variable is included in the conflict set */
1479  SCIP_CALL( SCIPsetAllocBufferArray(set, &branchingincluded, currentdepth+2) );
1480  BMSclearMemoryArray(branchingincluded, currentdepth+2);
1481  for( i = 0; i < conflictset->nbdchginfos; ++i )
1482  {
1483  int depth;
1484 
1485  depth = SCIPbdchginfoGetDepth(conflictset->bdchginfos[i]);
1486  depth = MIN(depth, currentdepth+1); /* put diving/probing/strong branching changes in this depth level */
1487  branchingincluded[depth] = TRUE;
1488  }
1489 
1490  /* skip additional depth levels where branching on the conflict variables was applied */
1491  while( conflictset->insertdepth < currentdepth && branchingincluded[conflictset->insertdepth+1] )
1492  conflictset->insertdepth++;
1493 
1494  /* free temporary memory */
1495  SCIPsetFreeBufferArray(set, &branchingincluded);
1496 
1497  assert(conflictset->validdepth <= conflictset->insertdepth && conflictset->insertdepth <= currentdepth);
1498 
1499  return SCIP_OKAY;
1500 }
1501 
1502 /** checks whether the first conflict set is redundant to the second one */
1503 static
1505  SCIP_CONFLICTSET* conflictset1, /**< first conflict conflict set */
1506  SCIP_CONFLICTSET* conflictset2 /**< second conflict conflict set */
1507  )
1508 {
1509  int i1;
1510  int i2;
1511 
1512  assert(conflictset1 != NULL);
1513  assert(conflictset2 != NULL);
1514 
1515  /* if conflictset1 has smaller validdepth, it is definitely not redundant to conflictset2 */
1516  if( conflictset1->validdepth < conflictset2->validdepth )
1517  return FALSE;
1518 
1519  /* check, if all bound changes in conflictset2 are also present at least as tight in conflictset1;
1520  * we can stop immediately, if more bound changes are remaining in conflictset2 than in conflictset1
1521  */
1522  for( i1 = 0, i2 = 0; i2 < conflictset2->nbdchginfos && conflictset1->nbdchginfos - i1 >= conflictset2->nbdchginfos - i2;
1523  ++i1, ++i2 )
1524  {
1525  int sortval;
1526 
1527  assert(i2 == 0 || conflictset2->sortvals[i2-1] < conflictset2->sortvals[i2]);
1528 
1529  sortval = conflictset2->sortvals[i2];
1530  for( ; i1 < conflictset1->nbdchginfos && conflictset1->sortvals[i1] < sortval; ++i1 )
1531  {
1532  /* while scanning conflictset1, check consistency */
1533  assert(i1 == 0 || conflictset1->sortvals[i1-1] < conflictset1->sortvals[i1]);
1534  }
1535  if( i1 >= conflictset1->nbdchginfos || conflictset1->sortvals[i1] > sortval
1536  || SCIPbdchginfoIsTighter(conflictset2->bdchginfos[i2], conflictset1->bdchginfos[i1]) )
1537  return FALSE;
1538  }
1539 
1540  return (i2 == conflictset2->nbdchginfos);
1541 }
1542 
1543 #ifdef SCIP_DEBUG
1544 /** prints a conflict set to the screen */
1545 static
1546 void conflictsetPrint(
1547  SCIP_CONFLICTSET* conflictset /**< conflict set */
1548  )
1549 {
1550  int i;
1551 
1552  assert(conflictset != NULL);
1553  for( i = 0; i < conflictset->nbdchginfos; ++i )
1554  {
1555  SCIPdebugPrintf(" [%d:<%s> %s %g(%g)]", SCIPbdchginfoGetDepth(conflictset->bdchginfos[i]),
1556  SCIPvarGetName(SCIPbdchginfoGetVar(conflictset->bdchginfos[i])),
1557  SCIPbdchginfoGetBoundtype(conflictset->bdchginfos[i]) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
1558  SCIPbdchginfoGetNewbound(conflictset->bdchginfos[i]), conflictset->relaxedbds[i]);
1559  }
1560  SCIPdebugPrintf("\n");
1561 }
1562 #endif
1563 
1564 /** resizes conflictsets array to be able to store at least num entries */
1565 static
1567  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1568  SCIP_SET* set, /**< global SCIP settings */
1569  int num /**< minimal number of slots in array */
1570  )
1571 {
1572  assert(conflict != NULL);
1573  assert(set != NULL);
1574 
1575  if( num > conflict->conflictsetssize )
1576  {
1577  int newsize;
1578 
1579  newsize = SCIPsetCalcMemGrowSize(set, num);
1580  SCIP_ALLOC( BMSreallocMemoryArray(&conflict->conflictsets, newsize) );
1581  SCIP_ALLOC( BMSreallocMemoryArray(&conflict->conflictsetscores, newsize) );
1582  conflict->conflictsetssize = newsize;
1583  }
1584  assert(num <= conflict->conflictsetssize);
1585 
1586  return SCIP_OKAY;
1587 }
1588 
1589 /** inserts conflict set into sorted conflictsets array and deletes the conflict set pointer */
1590 static
1592  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1593  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
1594  SCIP_SET* set, /**< global SCIP settings */
1595  SCIP_CONFLICTSET** conflictset /**< pointer to conflict set to insert */
1596  )
1597 {
1598  SCIP_Real score;
1599  int pos;
1600  int i;
1601  int j;
1602 
1603  assert(conflict != NULL);
1604  assert(set != NULL);
1605  assert(conflictset != NULL);
1606  assert(*conflictset != NULL);
1607  assert((*conflictset)->validdepth <= (*conflictset)->insertdepth);
1608  assert(set->conf_allowlocal || (*conflictset)->validdepth == 0);
1609 
1610  /* calculate conflict and repropagation depth */
1611  conflictsetCalcConflictDepth(*conflictset);
1612 
1613  /* if we apply repropagations, the conflict set should be inserted at most at its repropdepth */
1614  if( set->conf_repropagate )
1615  (*conflictset)->insertdepth = MIN((*conflictset)->insertdepth, (*conflictset)->repropdepth);
1616  else
1617  (*conflictset)->repropdepth = INT_MAX;
1618  assert((*conflictset)->insertdepth <= (*conflictset)->repropdepth);
1619 
1620  SCIPsetDebugMsg(set, "inserting conflict set (valid: %d, insert: %d, conf: %d, reprop: %d):\n",
1621  (*conflictset)->validdepth, (*conflictset)->insertdepth, (*conflictset)->conflictdepth, (*conflictset)->repropdepth);
1622  SCIPdebug(conflictsetPrint(*conflictset));
1623 
1624  /* get the score of the conflict set */
1625  score = conflictsetCalcScore(*conflictset, set);
1626 
1627  /* check, if conflict set is redundant to a better conflict set */
1628  for( pos = 0; pos < conflict->nconflictsets && score < conflict->conflictsetscores[pos]; ++pos )
1629  {
1630  /* check if conflict set is redundant with respect to conflictsets[pos] */
1631  if( conflictsetIsRedundant(*conflictset, conflict->conflictsets[pos]) )
1632  {
1633  SCIPsetDebugMsg(set, " -> conflict set is redundant to: ");
1634  SCIPdebug(conflictsetPrint(conflict->conflictsets[pos]));
1635  conflictsetFree(conflictset, blkmem);
1636  return SCIP_OKAY;
1637  }
1638 
1639  /**@todo like in sepastore.c: calculate overlap between conflictsets -> large overlap reduces score */
1640 
1641  }
1642 
1643  /* insert conflictset into the sorted conflictsets array */
1644  SCIP_CALL( conflictEnsureConflictsetsMem(conflict, set, conflict->nconflictsets + 1) );
1645  for( i = conflict->nconflictsets; i > pos; --i )
1646  {
1647  assert(score >= conflict->conflictsetscores[i-1]);
1648  conflict->conflictsets[i] = conflict->conflictsets[i-1];
1649  conflict->conflictsetscores[i] = conflict->conflictsetscores[i-1];
1650  }
1651  conflict->conflictsets[pos] = *conflictset;
1652  conflict->conflictsetscores[pos] = score;
1653  conflict->nconflictsets++;
1654 
1655  /* remove worse conflictsets that are redundant to the new conflictset */
1656  for( i = pos+1, j = pos+1; i < conflict->nconflictsets; ++i )
1657  {
1658  if( conflictsetIsRedundant(conflict->conflictsets[i], *conflictset) )
1659  {
1660  SCIPsetDebugMsg(set, " -> conflict set dominates: ");
1661  SCIPdebug(conflictsetPrint(conflict->conflictsets[i]));
1662  conflictsetFree(&conflict->conflictsets[i], blkmem);
1663  }
1664  else
1665  {
1666  assert(j <= i);
1667  conflict->conflictsets[j] = conflict->conflictsets[i];
1668  conflict->conflictsetscores[j] = conflict->conflictsetscores[i];
1669  j++;
1670  }
1671  }
1672  assert(j <= conflict->nconflictsets);
1673  conflict->nconflictsets = j;
1674 
1675 #ifdef SCIP_CONFGRAPH
1676  confgraphMarkConflictset(*conflictset);
1677 #endif
1678 
1679  *conflictset = NULL; /* ownership of pointer is now in the conflictsets array */
1680 
1681  return SCIP_OKAY;
1682 }
1683 
1684 /** calculates the maximal size of conflict sets to be used */
1685 static
1687  SCIP_SET* set, /**< global SCIP settings */
1688  SCIP_PROB* prob /**< problem data */
1689  )
1690 {
1691  int maxsize;
1692 
1693  assert(set != NULL);
1694  assert(prob != NULL);
1695 
1696  maxsize = (int)(set->conf_maxvarsfac * (prob->nvars - prob->ncontvars));
1697  maxsize = MAX(maxsize, set->conf_minmaxvars);
1698 
1699  return maxsize;
1700 }
1701 
1702 /** increases the conflict score of the variable in the given direction */
1703 static
1705  SCIP_VAR* var, /**< problem variable */
1706  BMS_BLKMEM* blkmem, /**< block memory */
1707  SCIP_SET* set, /**< global SCIP settings */
1708  SCIP_STAT* stat, /**< dynamic problem statistics */
1709  SCIP_BOUNDTYPE boundtype, /**< type of bound for which the score should be increased */
1710  SCIP_Real value, /**< value of the bound */
1711  SCIP_Real weight /**< weight of this VSIDS updates */
1712  )
1713 {
1714  SCIP_BRANCHDIR branchdir;
1715 
1716  assert(var != NULL);
1717  assert(stat != NULL);
1718 
1719  /* weight the VSIDS by the given weight */
1720  weight *= stat->vsidsweight;
1721 
1722  if( SCIPsetIsZero(set, weight) )
1723  return SCIP_OKAY;
1724 
1725  branchdir = (boundtype == SCIP_BOUNDTYPE_LOWER ? SCIP_BRANCHDIR_UPWARDS : SCIP_BRANCHDIR_DOWNWARDS); /*lint !e641*/
1726  SCIP_CALL( SCIPvarIncVSIDS(var, blkmem, set, stat, branchdir, value, weight) );
1727  SCIPhistoryIncVSIDS(stat->glbhistory, branchdir, weight);
1728  SCIPhistoryIncVSIDS(stat->glbhistorycrun, branchdir, weight);
1729 
1730  return SCIP_OKAY;
1731 }
1732 
1733 /** update conflict statistics */
1734 static
1736  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1737  BMS_BLKMEM* blkmem, /**< block memory */
1738  SCIP_SET* set, /**< global SCIP settings */
1739  SCIP_STAT* stat, /**< dynamic problem statistics */
1740  SCIP_CONFLICTSET* conflictset, /**< conflict set to add to the tree */
1741  int insertdepth /**< depth level at which the conflict set should be added */
1742  )
1743 {
1744  if( insertdepth > 0 )
1745  {
1746  conflict->nappliedlocconss++;
1747  conflict->nappliedlocliterals += conflictset->nbdchginfos;
1748  }
1749  else
1750  {
1751  int i;
1752  int conflictlength;
1753  conflictlength = conflictset->nbdchginfos;
1754 
1755  for( i = 0; i < conflictlength; i++ )
1756  {
1757  SCIP_VAR* var;
1758  SCIP_BRANCHDIR branchdir;
1759  SCIP_BOUNDTYPE boundtype;
1760  SCIP_Real bound;
1761 
1762  assert(stat != NULL);
1763 
1764  var = conflictset->bdchginfos[i]->var;
1765  boundtype = SCIPbdchginfoGetBoundtype(conflictset->bdchginfos[i]);
1766  bound = conflictset->relaxedbds[i];
1767 
1768  branchdir = (boundtype == SCIP_BOUNDTYPE_LOWER ? SCIP_BRANCHDIR_UPWARDS : SCIP_BRANCHDIR_DOWNWARDS); /*lint !e641*/
1769 
1770  SCIP_CALL( SCIPvarIncNActiveConflicts(var, blkmem, set, stat, branchdir, bound, (SCIP_Real)conflictlength) );
1771  SCIPhistoryIncNActiveConflicts(stat->glbhistory, branchdir, (SCIP_Real)conflictlength);
1772  SCIPhistoryIncNActiveConflicts(stat->glbhistorycrun, branchdir, (SCIP_Real)conflictlength);
1773 
1774  /* each variable which is part of the conflict gets an increase in the VSIDS */
1775  SCIP_CALL( incVSIDS(var, blkmem, set, stat, boundtype, bound, set->conf_conflictweight) );
1776  }
1777  conflict->nappliedglbconss++;
1778  conflict->nappliedglbliterals += conflictset->nbdchginfos;
1779  }
1780 
1781  return SCIP_OKAY;
1782 }
1783 
1784 
1785 /** check conflict set for redundancy, other conflicts in the same conflict analysis could have led to global reductions
1786  * an made this conflict set redundant
1787  */
1788 static
1790  SCIP_SET* set, /**< global SCIP settings */
1791  SCIP_CONFLICTSET* conflictset /**< conflict set */
1792  )
1793 {
1794  SCIP_BDCHGINFO** bdchginfos;
1795  SCIP_VAR* var;
1796  SCIP_Real* relaxedbds;
1797  SCIP_Real bound;
1798  int v;
1799 
1800  assert(set != NULL);
1801  assert(conflictset != NULL);
1802 
1803  bdchginfos = conflictset->bdchginfos;
1804  relaxedbds = conflictset->relaxedbds;
1805  assert(bdchginfos != NULL);
1806  assert(relaxedbds != NULL);
1807 
1808  /* check all boundtypes and bounds for redundancy */
1809  for( v = conflictset->nbdchginfos - 1; v >= 0; --v )
1810  {
1811  var = SCIPbdchginfoGetVar(bdchginfos[v]);
1812  assert(var != NULL);
1813  assert(SCIPvarGetProbindex(var) >= 0);
1814 
1815  /* check if the relaxed bound is really a relaxed bound */
1816  assert(SCIPbdchginfoGetBoundtype(bdchginfos[v]) == SCIP_BOUNDTYPE_LOWER || SCIPsetIsGE(set, relaxedbds[v], SCIPbdchginfoGetNewbound(bdchginfos[v])));
1817  assert(SCIPbdchginfoGetBoundtype(bdchginfos[v]) == SCIP_BOUNDTYPE_UPPER || SCIPsetIsLE(set, relaxedbds[v], SCIPbdchginfoGetNewbound(bdchginfos[v])));
1818 
1819  bound = relaxedbds[v];
1820 
1821  if( SCIPbdchginfoGetBoundtype(bdchginfos[v]) == SCIP_BOUNDTYPE_UPPER )
1822  {
1824  {
1825  assert(SCIPsetIsIntegral(set, bound));
1826  bound += 1.0;
1827  }
1828 
1829  /* check if the bound is already fulfilled globally */
1830  if( SCIPsetIsFeasGE(set, SCIPvarGetLbGlobal(var), bound) )
1831  return TRUE;
1832  }
1833  else
1834  {
1835  assert(SCIPbdchginfoGetBoundtype(bdchginfos[v]) == SCIP_BOUNDTYPE_LOWER);
1836 
1838  {
1839  assert(SCIPsetIsIntegral(set, bound));
1840  bound -= 1.0;
1841  }
1842 
1843  /* check if the bound is already fulfilled globally */
1844  if( SCIPsetIsFeasLE(set, SCIPvarGetUbGlobal(var), bound) )
1845  return TRUE;
1846  }
1847  }
1848 
1849  return FALSE;
1850 }
1851 
1852 /** find global fixings which can be derived from the new conflict set */
1853 static
1855  SCIP_SET* set, /**< global SCIP settings */
1856  SCIP_PROB* prob, /**< transformed problem after presolve */
1857  SCIP_CONFLICTSET* conflictset, /**< conflict set to add to the tree */
1858  int* nbdchgs, /**< number of global deducted bound changes due to the conflict set */
1859  int* nredvars, /**< number of redundant and removed variables from conflict set */
1860  SCIP_Bool* redundant /**< did we found a global reduction on a conflict set variable, which makes this conflict redundant */
1861  )
1862 {
1863  SCIP_BDCHGINFO** bdchginfos;
1864  SCIP_Real* relaxedbds;
1865  SCIP_VAR* var;
1866  SCIP_Bool* boundtypes;
1867  SCIP_Real* bounds;
1868  SCIP_Longint* nbinimpls;
1869  int* sortvals;
1870  SCIP_Real bound;
1871  SCIP_Bool isupper;
1872  int ntrivialredvars;
1873  int nbdchginfos;
1874  int nzeroimpls;
1875  int v;
1876 
1877  assert(set != NULL);
1878  assert(prob != NULL);
1879  assert(SCIPprobIsTransformed(prob));
1880  assert(conflictset != NULL);
1881  assert(nbdchgs != NULL);
1882  assert(nredvars != NULL);
1883  /* only check conflict sets with more than one variable */
1884  assert(conflictset->nbdchginfos > 1);
1885 
1886  *nbdchgs = 0;
1887  *nredvars = 0;
1888 
1889  /* due to other conflict in the same conflict analysis, this conflict set might have become redundant */
1890  *redundant = checkRedundancy(set, conflictset);
1891 
1892  if( *redundant )
1893  return SCIP_OKAY;
1894 
1895  bdchginfos = conflictset->bdchginfos;
1896  relaxedbds = conflictset->relaxedbds;
1897  nbdchginfos = conflictset->nbdchginfos;
1898  sortvals = conflictset->sortvals;
1899 
1900  assert(bdchginfos != NULL);
1901  assert(relaxedbds != NULL);
1902  assert(sortvals != NULL);
1903 
1904  /* check if the boolean representation of boundtypes matches the 'standard' definition */
1905  assert(SCIP_BOUNDTYPE_LOWER == FALSE); /*lint !e641*/
1906  assert(SCIP_BOUNDTYPE_UPPER == TRUE); /*lint !e641*/
1907 
1908  ntrivialredvars = 0;
1909 
1910  /* due to multiple conflict sets for one conflict, it can happen, that we already have redundant information in the
1911  * conflict set
1912  */
1913  for( v = nbdchginfos - 1; v >= 0; --v )
1914  {
1915  var = SCIPbdchginfoGetVar(bdchginfos[v]);
1916  bound = relaxedbds[v];
1917  isupper = (SCIP_Bool) SCIPboundtypeOpposite(SCIPbdchginfoGetBoundtype(bdchginfos[v]));
1918 
1919  /* for integral variable we can increase/decrease the conflicting bound */
1920  if( SCIPvarIsIntegral(var) )
1921  bound += (isupper ? -1.0 : +1.0);
1922 
1923  /* if conflict variable cannot fulfill the conflict we can remove it */
1924  if( (isupper && SCIPsetIsFeasLT(set, bound, SCIPvarGetLbGlobal(var))) ||
1925  (!isupper && SCIPsetIsFeasGT(set, bound, SCIPvarGetUbGlobal(var))) )
1926  {
1927  SCIPsetDebugMsg(set, "remove redundant variable <%s> from conflict set\n", SCIPvarGetName(var));
1928 
1929  bdchginfos[v] = bdchginfos[nbdchginfos - 1];
1930  relaxedbds[v] = relaxedbds[nbdchginfos - 1];
1931  sortvals[v] = sortvals[nbdchginfos - 1];
1932 
1933  --nbdchginfos;
1934  ++ntrivialredvars;
1935  }
1936  }
1937  assert(ntrivialredvars + nbdchginfos == conflictset->nbdchginfos);
1938 
1939  SCIPsetDebugMsg(set, "trivially removed %d redundant of %d variables from conflictset (%p)\n", ntrivialredvars, conflictset->nbdchginfos, (void*)conflictset);
1940  conflictset->nbdchginfos = nbdchginfos;
1941 
1942  /* all variables where removed, the conflict cannot be fulfilled, i.e., we have an infeasibility proof */
1943  if( conflictset->nbdchginfos == 0 )
1944  return SCIP_OKAY;
1945 
1946  /* do not check to big or trivial conflicts */
1947  if( conflictset->nbdchginfos > set->conf_maxvarsdetectimpliedbounds || conflictset->nbdchginfos == 1 )
1948  {
1949  *nredvars = ntrivialredvars;
1950  return SCIP_OKAY;
1951  }
1952 
1953  /* create array of boundtypes, and bound values in conflict set */
1954  SCIP_CALL( SCIPsetAllocBufferArray(set, &boundtypes, nbdchginfos) );
1955  SCIP_CALL( SCIPsetAllocBufferArray(set, &bounds, nbdchginfos) );
1956  /* memory for the estimates for binary implications used for sorting */
1957  SCIP_CALL( SCIPsetAllocBufferArray(set, &nbinimpls, nbdchginfos) );
1958 
1959  nzeroimpls = 0;
1960 
1961  /* collect estimates and initialize variables, boundtypes, and bounds array */
1962  for( v = 0; v < nbdchginfos; ++v )
1963  {
1964  var = SCIPbdchginfoGetVar(bdchginfos[v]);
1965  boundtypes[v] = (SCIP_Bool) SCIPboundtypeOpposite(SCIPbdchginfoGetBoundtype(bdchginfos[v]));
1966  bounds[v] = relaxedbds[v];
1967 
1968  assert(SCIPvarGetProbindex(var) >= 0);
1969 
1970  /* check if the relaxed bound is really a relaxed bound */
1971  assert(SCIPbdchginfoGetBoundtype(bdchginfos[v]) == SCIP_BOUNDTYPE_LOWER || SCIPsetIsGE(set, relaxedbds[v], SCIPbdchginfoGetNewbound(bdchginfos[v])));
1972  assert(SCIPbdchginfoGetBoundtype(bdchginfos[v]) == SCIP_BOUNDTYPE_UPPER || SCIPsetIsLE(set, relaxedbds[v], SCIPbdchginfoGetNewbound(bdchginfos[v])));
1973 
1974  /* for continuous variables, we can only use the relaxed version of the bounds negation: !(x <= u) -> x >= u */
1975  if( SCIPvarIsBinary(var) )
1976  {
1977  if( !boundtypes[v] )
1978  {
1979  assert(SCIPsetIsZero(set, bounds[v]));
1980  bounds[v] = 1.0;
1981  nbinimpls[v] = (SCIP_Longint)SCIPvarGetNCliques(var, TRUE) * 2;
1982  }
1983  else
1984  {
1985  assert(SCIPsetIsEQ(set, bounds[v], 1.0));
1986  bounds[v] = 0.0;
1987  nbinimpls[v] = (SCIP_Longint)SCIPvarGetNCliques(var, FALSE) * 2;
1988  }
1989  }
1990  else if( SCIPvarIsIntegral(var) )
1991  {
1992  assert(SCIPsetIsIntegral(set, bounds[v]));
1993 
1994  bounds[v] += ((!boundtypes[v]) ? +1.0 : -1.0);
1995  nbinimpls[v] = (boundtypes[v] ? SCIPvarGetNVlbs(var) : SCIPvarGetNVubs(var));
1996  }
1997  else if( ((!boundtypes[v]) && SCIPsetIsFeasEQ(set, SCIPvarGetLbGlobal(var), bounds[v]))
1998  || ((boundtypes[v]) && SCIPsetIsFeasEQ(set, SCIPvarGetUbGlobal(var), bounds[v])) )
1999  {
2000  /* the literal is satisfied in global bounds (may happen due to weak "negation" of continuous variables)
2001  * -> discard the conflict constraint
2002  */
2003  break;
2004  }
2005  else
2006  {
2007  nbinimpls[v] = (boundtypes[v] ? SCIPvarGetNVlbs(var) : SCIPvarGetNVubs(var));
2008  }
2009 
2010  if( nbinimpls[v] == 0 )
2011  ++nzeroimpls;
2012  }
2013 
2014  /* starting to derive global bound changes */
2015  if( v == nbdchginfos && ((!set->conf_fullshortenconflict && nzeroimpls < 2) || (set->conf_fullshortenconflict && nzeroimpls < nbdchginfos)) )
2016  {
2017  SCIP_VAR** vars;
2018  SCIP_Bool* redundants;
2019  SCIP_Bool glbinfeas;
2020 
2021  /* sort variables in increasing order of binary implications to gain speed later on */
2022  SCIPsortLongPtrRealRealBool(nbinimpls, (void**)bdchginfos, relaxedbds, bounds, boundtypes, v);
2023 
2024  SCIPsetDebugMsg(set, "checking for global reductions and redundant conflict variables(in %s) on conflict:\n", SCIPprobGetName(prob));
2025  SCIPsetDebugMsg(set, "[");
2026  for( v = 0; v < nbdchginfos; ++v )
2027  {
2028  SCIPsetDebugMsgPrint(set, "%s %s %g", SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfos[v])), (!boundtypes[v]) ? ">=" : "<=", bounds[v]);
2029  if( v < nbdchginfos - 1 )
2030  SCIPsetDebugMsgPrint(set, ", ");
2031  }
2032  SCIPsetDebugMsgPrint(set, "]\n");
2033 
2034  SCIP_CALL( SCIPsetAllocBufferArray(set, &vars, v) );
2035  SCIP_CALL( SCIPsetAllocCleanBufferArray(set, &redundants, v) );
2036 
2037  /* initialize conflict variable data */
2038  for( v = 0; v < nbdchginfos; ++v )
2039  vars[v] = SCIPbdchginfoGetVar(bdchginfos[v]);
2040 
2041  SCIP_CALL( SCIPshrinkDisjunctiveVarSet(set->scip, vars, bounds, boundtypes, redundants, nbdchginfos, nredvars,
2042  nbdchgs, redundant, &glbinfeas, set->conf_fullshortenconflict) );
2043 
2044  if( glbinfeas )
2045  {
2046  SCIPsetDebugMsg(set, "conflict set (%p) led to global infeasibility\n", (void*) conflictset);
2047  goto TERMINATE;
2048  }
2049 
2050 #ifdef SCIP_DEBUG
2051  if( *nbdchgs > 0 )
2052  {
2053  SCIPsetDebugMsg(set, "conflict set (%p) led to %d global bound reductions\n", (void*) conflictset, *nbdchgs);
2054  }
2055 #endif
2056 
2057  /* remove as redundant marked variables */
2058  if( *redundant )
2059  {
2060  SCIPsetDebugMsg(set, "conflict set (%p) is redundant because at least one global reduction, fulfills the conflict constraint\n", (void*)conflictset);
2061 
2062  BMSclearMemoryArray(redundants, nbdchginfos);
2063  }
2064  else if( *nredvars > 0 )
2065  {
2066  assert(bdchginfos == conflictset->bdchginfos);
2067  assert(relaxedbds == conflictset->relaxedbds);
2068  assert(sortvals == conflictset->sortvals);
2069 
2070  for( v = nbdchginfos - 1; v >= 0; --v )
2071  {
2072  /* if conflict variable was marked to be redundant remove it */
2073  if( redundants[v] )
2074  {
2075  SCIPsetDebugMsg(set, "remove redundant variable <%s> from conflict set\n", SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfos[v])));
2076 
2077  bdchginfos[v] = bdchginfos[nbdchginfos - 1];
2078  relaxedbds[v] = relaxedbds[nbdchginfos - 1];
2079  sortvals[v] = sortvals[nbdchginfos - 1];
2080 
2081  /* reset redundants[v] to 0 */
2082  redundants[v] = 0;
2083 
2084  --nbdchginfos;
2085  }
2086  }
2087  assert((*nredvars) + nbdchginfos == conflictset->nbdchginfos);
2088 
2089  SCIPsetDebugMsg(set, "removed %d redundant of %d variables from conflictset (%p)\n", (*nredvars), conflictset->nbdchginfos, (void*)conflictset);
2090  conflictset->nbdchginfos = nbdchginfos;
2091  }
2092 
2093  TERMINATE:
2094  SCIPsetFreeCleanBufferArray(set, &redundants);
2095  SCIPsetFreeBufferArray(set, &vars);
2096  }
2097 
2098  /* free temporary memory */
2099  SCIPsetFreeBufferArray(set, &nbinimpls);
2100  SCIPsetFreeBufferArray(set, &bounds);
2101  SCIPsetFreeBufferArray(set, &boundtypes);
2102 
2103  *nredvars += ntrivialredvars;
2104 
2105  return SCIP_OKAY;
2106 }
2107 
2108 /** adds the given conflict set as conflict constraint to the problem */
2109 static
2111  SCIP_CONFLICT* conflict, /**< conflict analysis data */
2112  BMS_BLKMEM* blkmem, /**< block memory */
2113  SCIP_SET* set, /**< global SCIP settings */
2114  SCIP_STAT* stat, /**< dynamic problem statistics */
2115  SCIP_PROB* transprob, /**< transformed problem after presolve */
2116  SCIP_PROB* origprob, /**< original problem */
2117  SCIP_TREE* tree, /**< branch and bound tree */
2118  SCIP_REOPT* reopt, /**< reoptimization data structure */
2119  SCIP_LP* lp, /**< current LP data */
2120  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
2121  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2122  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
2123  SCIP_CONFLICTSET* conflictset, /**< conflict set to add to the tree */
2124  int insertdepth, /**< depth level at which the conflict set should be added */
2125  SCIP_Bool* success /**< pointer to store whether the addition was successful */
2126  )
2127 {
2128  SCIP_Bool redundant;
2129  int h;
2130 
2131  assert(conflict != NULL);
2132  assert(tree != NULL);
2133  assert(tree->path != NULL);
2134  assert(conflictset != NULL);
2135  assert(conflictset->validdepth <= insertdepth);
2136  assert(success != NULL);
2137 
2138  *success = FALSE;
2139  redundant = FALSE;
2140 
2141  /* try to derive global bound changes and shorten the conflictset by using implication and clique and variable bound
2142  * information
2143  */
2144  if( conflictset->nbdchginfos > 1 && insertdepth == 0 )
2145  {
2146  int nbdchgs;
2147  int nredvars;
2148 #ifdef SCIP_DEBUG
2149  int oldnbdchginfos = conflictset->nbdchginfos;
2150 #endif
2151  assert(conflictset->validdepth == 0);
2152 
2153  SCIPclockStart(conflict->dIBclock, set);
2154 
2155  /* find global bound changes which can be derived from the new conflict set */
2156  SCIP_CALL( detectImpliedBounds(set, transprob, conflictset, &nbdchgs, &nredvars, &redundant) );
2157 
2158  /* all variables where removed, we have an infeasibility proof */
2159  if( conflictset->nbdchginfos == 0 )
2160  return SCIP_OKAY;
2161 
2162  /* debug check for reduced conflict set */
2163  if( nredvars > 0 )
2164  {
2165  /* check conflict set on debugging solution */
2166  SCIP_CALL( SCIPdebugCheckConflict(blkmem, set, tree->root, conflictset->bdchginfos, conflictset->relaxedbds, conflictset->nbdchginfos) ); /*lint !e506 !e774*/
2167  }
2168 
2169 #ifdef SCIP_DEBUG
2170  SCIPsetDebugMsg(set, " -> conflict set removed %d redundant variables (old nvars %d, new nvars = %d)\n", nredvars, oldnbdchginfos, conflictset->nbdchginfos);
2171  SCIPsetDebugMsg(set, " -> conflict set led to %d global bound changes %s(cdpt:%d, fdpt:%d, confdpt:%d, len:%d):\n",
2172  nbdchgs, redundant ? "(conflict became redundant) " : "", SCIPtreeGetCurrentDepth(tree), SCIPtreeGetFocusDepth(tree),
2173  conflictset->conflictdepth, conflictset->nbdchginfos);
2174  conflictsetPrint(conflictset);
2175 #endif
2176 
2177  SCIPclockStop(conflict->dIBclock, set);
2178 
2179  if( redundant )
2180  {
2181  if( nbdchgs > 0 )
2182  *success = TRUE;
2183 
2184  return SCIP_OKAY;
2185  }
2186  }
2187 
2188  /* in case the conflict set contains only one bound change which is globally valid we apply that bound change
2189  * directly (except if we are in strong branching or diving - in this case a bound change would yield an unflushed LP
2190  * and is not handled when restoring the information)
2191  *
2192  * @note A bound change can only be applied if it is are related to the active node or if is a global bound
2193  * change. Bound changes which are related to any other node cannot be handled at point due to the internal
2194  * data structure
2195  */
2196  if( conflictset->nbdchginfos == 1 && insertdepth == 0 && !lp->strongbranching && !lp->diving )
2197  {
2198  SCIP_VAR* var;
2199  SCIP_Real bound;
2200  SCIP_BOUNDTYPE boundtype;
2201 
2202  var = conflictset->bdchginfos[0]->var;
2203  assert(var != NULL);
2204 
2205  boundtype = SCIPboundtypeOpposite((SCIP_BOUNDTYPE) conflictset->bdchginfos[0]->boundtype);
2206  bound = conflictset->relaxedbds[0];
2207 
2208  /* for continuous variables, we can only use the relaxed version of the bounds negation: !(x <= u) -> x >= u */
2209  if( SCIPvarIsIntegral(var) )
2210  {
2211  assert(SCIPsetIsIntegral(set, bound));
2212  bound += (boundtype == SCIP_BOUNDTYPE_LOWER ? +1.0 : -1.0);
2213  }
2214 
2215  SCIPsetDebugMsg(set, " -> apply global bound change: <%s> %s %g\n",
2216  SCIPvarGetName(var), boundtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", bound);
2217 
2218  SCIP_CALL( SCIPnodeAddBoundchg(tree->path[conflictset->validdepth], blkmem, set, stat, transprob, origprob, tree,
2219  reopt, lp, branchcand, eventqueue, cliquetable, var, bound, boundtype, FALSE) );
2220 
2221  *success = TRUE;
2222  SCIP_CALL( updateStatistics(conflict, blkmem, set, stat, conflictset, insertdepth) );
2223  }
2224  else
2225  {
2226  /* sort conflict handlers by priority */
2228 
2229  /* call conflict handlers to create a conflict constraint */
2230  for( h = 0; h < set->nconflicthdlrs; ++h )
2231  {
2232  SCIP_RESULT result;
2233 
2234  assert(conflictset->conflicttype != SCIP_CONFTYPE_UNKNOWN);
2235 
2236  SCIP_CALL( SCIPconflicthdlrExec(set->conflicthdlrs[h], set, tree->path[insertdepth],
2237  tree->path[conflictset->validdepth], conflictset->bdchginfos, conflictset->relaxedbds,
2238  conflictset->nbdchginfos, conflictset->conflicttype, conflictset->usescutoffbound, *success, &result) );
2239  if( result == SCIP_CONSADDED )
2240  {
2241  *success = TRUE;
2242  SCIP_CALL( updateStatistics(conflict, blkmem, set, stat, conflictset, insertdepth) );
2243  }
2244 
2245  SCIPsetDebugMsg(set, " -> call conflict handler <%s> (prio=%d) to create conflict set with %d bounds returned result %d\n",
2246  SCIPconflicthdlrGetName(set->conflicthdlrs[h]), SCIPconflicthdlrGetPriority(set->conflicthdlrs[h]),
2247  conflictset->nbdchginfos, result);
2248  }
2249  }
2250 
2251  return SCIP_OKAY;
2252 }
2253 
2254 /** adds the collected conflict constraints to the corresponding nodes; the best set->conf_maxconss conflict constraints
2255  * are added to the node of their validdepth; additionally (if not yet added, and if repropagation is activated), the
2256  * conflict constraint that triggers the earliest repropagation is added to the node of its validdepth
2257  */
2259  SCIP_CONFLICT* conflict, /**< conflict analysis data */
2260  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
2261  SCIP_SET* set, /**< global SCIP settings */
2262  SCIP_STAT* stat, /**< dynamic problem statistics */
2263  SCIP_PROB* transprob, /**< transformed problem */
2264  SCIP_PROB* origprob, /**< original problem */
2265  SCIP_TREE* tree, /**< branch and bound tree */
2266  SCIP_REOPT* reopt, /**< reoptimization data structure */
2267  SCIP_LP* lp, /**< current LP data */
2268  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
2269  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2270  SCIP_CLIQUETABLE* cliquetable /**< clique table data structure */
2271  )
2272 {
2273  assert(conflict != NULL);
2274  assert(set != NULL);
2275  assert(stat != NULL);
2276  assert(transprob != NULL);
2277  assert(tree != NULL);
2278 
2279  /* is there anything to do? */
2280  if( conflict->nconflictsets > 0 )
2281  {
2282  SCIP_CONFLICTSET* repropconflictset;
2283  int nconflictsetsused;
2284  int focusdepth;
2285 #ifndef NDEBUG
2286  int currentdepth;
2287 #endif
2288  int cutoffdepth;
2289  int repropdepth;
2290  int maxconflictsets;
2291  int maxsize;
2292  int i;
2293 
2294  /* calculate the maximal number of conflict sets to accept, and the maximal size of each accepted conflict set */
2295  maxconflictsets = (set->conf_maxconss == -1 ? INT_MAX : set->conf_maxconss);
2296  maxsize = conflictCalcMaxsize(set, transprob);
2297 
2298  focusdepth = SCIPtreeGetFocusDepth(tree);
2299 #ifndef NDEBUG
2300  currentdepth = SCIPtreeGetCurrentDepth(tree);
2301  assert(focusdepth <= currentdepth);
2302  assert(currentdepth == tree->pathlen-1);
2303 #endif
2304 
2305  SCIPsetDebugMsg(set, "flushing %d conflict sets at focus depth %d (maxconflictsets: %d, maxsize: %d)\n",
2306  conflict->nconflictsets, focusdepth, maxconflictsets, maxsize);
2307 
2308  /* mark the focus node to have produced conflict sets in the visualization output */
2309  SCIPvisualFoundConflict(stat->visual, stat, tree->path[focusdepth]);
2310 
2311  /* insert the conflict sets at the corresponding nodes */
2312  nconflictsetsused = 0;
2313  cutoffdepth = INT_MAX;
2314  repropdepth = INT_MAX;
2315  repropconflictset = NULL;
2316  for( i = 0; i < conflict->nconflictsets && nconflictsetsused < maxconflictsets; ++i )
2317  {
2318  SCIP_CONFLICTSET* conflictset;
2319 
2320  conflictset = conflict->conflictsets[i];
2321  assert(conflictset != NULL);
2322  assert(0 <= conflictset->validdepth);
2323  assert(conflictset->validdepth <= conflictset->insertdepth);
2324  assert(conflictset->insertdepth <= focusdepth);
2325  assert(conflictset->insertdepth <= conflictset->repropdepth);
2326  assert(conflictset->repropdepth <= currentdepth || conflictset->repropdepth == INT_MAX); /* INT_MAX for dive/probing/strong */
2327  assert(conflictset->conflictdepth <= currentdepth || conflictset->conflictdepth == INT_MAX); /* INT_MAX for dive/probing/strong */
2328 
2329  /* ignore conflict sets that are only valid at a node that was already cut off */
2330  if( conflictset->insertdepth >= cutoffdepth )
2331  {
2332  SCIPsetDebugMsg(set, " -> ignoring conflict set with insertdepth %d >= cutoffdepth %d\n",
2333  conflictset->validdepth, cutoffdepth);
2334  continue;
2335  }
2336 
2337  /* if no conflict bounds exist, the node and its sub tree in the conflict set's valid depth can be
2338  * cut off completely
2339  */
2340  if( conflictset->nbdchginfos == 0 )
2341  {
2342  SCIPsetDebugMsg(set, " -> empty conflict set in depth %d cuts off sub tree at depth %d\n",
2343  focusdepth, conflictset->validdepth);
2344 
2345  SCIP_CALL( SCIPnodeCutoff(tree->path[conflictset->validdepth], set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
2346  cutoffdepth = conflictset->validdepth;
2347  continue;
2348  }
2349 
2350  /* if the conflict set is too long, use the conflict set only if it decreases the repropagation depth */
2351  if( conflictset->nbdchginfos > maxsize )
2352  {
2353  SCIPsetDebugMsg(set, " -> conflict set is too long: %d > %d literals\n", conflictset->nbdchginfos, maxsize);
2354  if( set->conf_keepreprop && conflictset->repropagate && conflictset->repropdepth < repropdepth )
2355  {
2356  repropdepth = conflictset->repropdepth;
2357  repropconflictset = conflictset;
2358  }
2359  }
2360  else
2361  {
2362  SCIP_Bool success;
2363 
2364  /* call conflict handlers to create a conflict constraint */
2365  SCIP_CALL( conflictAddConflictCons(conflict, blkmem, set, stat, transprob, origprob, tree, reopt, lp,
2366  branchcand, eventqueue, cliquetable, conflictset, conflictset->insertdepth, &success) );
2367 
2368  /* if no conflict bounds exist, the node and its sub tree in the conflict set's valid depth can be
2369  * cut off completely
2370  */
2371  if( conflictset->nbdchginfos == 0 )
2372  {
2373  assert(!success);
2374 
2375  SCIPsetDebugMsg(set, " -> empty conflict set in depth %d cuts off sub tree at depth %d\n",
2376  focusdepth, conflictset->validdepth);
2377 
2378  SCIP_CALL( SCIPnodeCutoff(tree->path[conflictset->validdepth], set, stat, tree, transprob, origprob,
2379  reopt, lp, blkmem) );
2380  cutoffdepth = conflictset->validdepth;
2381  continue;
2382  }
2383 
2384  if( success )
2385  {
2386  SCIPsetDebugMsg(set, " -> conflict set %d/%d added (cdpt:%d, fdpt:%d, insert:%d, valid:%d, conf:%d, reprop:%d, len:%d):\n",
2387  nconflictsetsused+1, maxconflictsets, SCIPtreeGetCurrentDepth(tree), SCIPtreeGetFocusDepth(tree),
2388  conflictset->insertdepth, conflictset->validdepth, conflictset->conflictdepth, conflictset->repropdepth,
2389  conflictset->nbdchginfos);
2390  SCIPdebug(conflictsetPrint(conflictset));
2391 
2392  if( conflictset->repropagate && conflictset->repropdepth <= repropdepth )
2393  {
2394  repropdepth = conflictset->repropdepth;
2395  repropconflictset = NULL;
2396  }
2397  nconflictsetsused++;
2398  }
2399  }
2400  }
2401 
2402  /* reactivate propagation on the first node where one of the new conflict sets trigger a deduction */
2403  if( set->conf_repropagate && repropdepth < cutoffdepth && repropdepth < tree->pathlen )
2404  {
2405  assert(0 <= repropdepth && repropdepth < tree->pathlen);
2406  assert((int) tree->path[repropdepth]->depth == repropdepth);
2407 
2408  /* if the conflict constraint of smallest repropagation depth was not yet added, insert it now */
2409  if( repropconflictset != NULL )
2410  {
2411  SCIP_Bool success;
2412 
2413  assert(repropconflictset->repropagate);
2414  assert(repropconflictset->repropdepth == repropdepth);
2415 
2416  SCIP_CALL( conflictAddConflictCons(conflict, blkmem, set, stat, transprob, origprob, tree, reopt, lp,
2417  branchcand, eventqueue, cliquetable, repropconflictset, repropdepth, &success) );
2418 
2419  /* if no conflict bounds exist, the node and its sub tree in the conflict set's valid depth can be
2420  * cut off completely
2421  */
2422  if( repropconflictset->nbdchginfos == 0 )
2423  {
2424  assert(!success);
2425 
2426  SCIPsetDebugMsg(set, " -> empty reprop conflict set in depth %d cuts off sub tree at depth %d\n",
2427  focusdepth, repropconflictset->validdepth);
2428 
2429  SCIP_CALL( SCIPnodeCutoff(tree->path[repropconflictset->validdepth], set, stat, tree, transprob, origprob,
2430  reopt, lp, blkmem) );
2431  }
2432 
2433 #ifdef SCIP_DEBUG
2434  if( success )
2435  {
2436  SCIPsetDebugMsg(set, " -> additional reprop conflict set added (cdpt:%d, fdpt:%d, insert:%d, valid:%d, conf:%d, reprop:%d, len:%d):\n",
2438  repropconflictset->insertdepth, repropconflictset->validdepth, repropconflictset->conflictdepth,
2439  repropconflictset->repropdepth, repropconflictset->nbdchginfos);
2440  SCIPdebug(conflictsetPrint(repropconflictset));
2441  }
2442 #endif
2443  }
2444 
2445  /* mark the node in the repropdepth to be propagated again */
2446  SCIPnodePropagateAgain(tree->path[repropdepth], set, stat, tree);
2447 
2448  SCIPsetDebugMsg(set, "marked node %p in depth %d to be repropagated due to conflicts found in depth %d\n",
2449  (void*)tree->path[repropdepth], repropdepth, focusdepth);
2450  }
2451 
2452  /* free the conflict store */
2453  for( i = 0; i < conflict->nconflictsets; ++i )
2454  {
2455  conflictsetFree(&conflict->conflictsets[i], blkmem);
2456  }
2457  conflict->nconflictsets = 0;
2458  }
2459 
2460  /* free all temporarily created bound change information data */
2461  conflictFreeTmpBdchginfos(conflict, blkmem);
2462 
2463  return SCIP_OKAY;
2464 }
2465 
2466 /** returns the current number of conflict sets in the conflict set storage */
2468  SCIP_CONFLICT* conflict /**< conflict analysis data */
2469  )
2470 {
2471  assert(conflict != NULL);
2472 
2473  return conflict->nconflictsets;
2474 }
2475 
2476 /** returns the total number of conflict constraints that were added to the problem */
2478  SCIP_CONFLICT* conflict /**< conflict analysis data */
2479  )
2480 {
2481  assert(conflict != NULL);
2482 
2483  return conflict->nappliedglbconss + conflict->nappliedlocconss;
2484 }
2485 
2486 /** returns the total number of literals in conflict constraints that were added to the problem */
2488  SCIP_CONFLICT* conflict /**< conflict analysis data */
2489  )
2490 {
2491  assert(conflict != NULL);
2492 
2493  return conflict->nappliedglbliterals + conflict->nappliedlocliterals;
2494 }
2495 
2496 /** returns the total number of global bound changes applied by the conflict analysis */
2498  SCIP_CONFLICT* conflict /**< conflict analysis data */
2499  )
2500 {
2501  assert(conflict != NULL);
2502 
2503  return conflict->nglbchgbds;
2504 }
2505 
2506 /** returns the total number of conflict constraints that were added globally to the problem */
2508  SCIP_CONFLICT* conflict /**< conflict analysis data */
2509  )
2510 {
2511  assert(conflict != NULL);
2512 
2513  return conflict->nappliedglbconss;
2514 }
2515 
2516 /** returns the total number of literals in conflict constraints that were added globally to the problem */
2518  SCIP_CONFLICT* conflict /**< conflict analysis data */
2519  )
2520 {
2521  assert(conflict != NULL);
2522 
2523  return conflict->nappliedglbliterals;
2524 }
2525 
2526 /** returns the total number of local bound changes applied by the conflict analysis */
2528  SCIP_CONFLICT* conflict /**< conflict analysis data */
2529  )
2530 {
2531  assert(conflict != NULL);
2532 
2533  return conflict->nlocchgbds;
2534 }
2535 
2536 /** returns the total number of conflict constraints that were added locally to the problem */
2538  SCIP_CONFLICT* conflict /**< conflict analysis data */
2539  )
2540 {
2541  assert(conflict != NULL);
2542 
2543  return conflict->nappliedlocconss;
2544 }
2545 
2546 /** returns the total number of literals in conflict constraints that were added locally to the problem */
2548  SCIP_CONFLICT* conflict /**< conflict analysis data */
2549  )
2550 {
2551  assert(conflict != NULL);
2552 
2553  return conflict->nappliedlocliterals;
2554 }
2555 
2556 
2557 
2558 
2559 /*
2560  * Propagation Conflict Analysis
2561  */
2562 
2563 /** returns whether bound change has a valid reason that can be resolved in conflict analysis */
2564 static
2566  SCIP_BDCHGINFO* bdchginfo /**< bound change information */
2567  )
2568 {
2569  assert(bdchginfo != NULL);
2570  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
2571 
2574  && SCIPbdchginfoGetInferProp(bdchginfo) != NULL));
2575 }
2576 
2577 /** compares two conflict set entries, such that bound changes infered later are
2578  * ordered prior to ones that were infered earlier
2579  */
2580 static
2581 SCIP_DECL_SORTPTRCOMP(conflictBdchginfoComp)
2582 { /*lint --e{715}*/
2583  SCIP_BDCHGINFO* bdchginfo1;
2584  SCIP_BDCHGINFO* bdchginfo2;
2585 
2586  bdchginfo1 = (SCIP_BDCHGINFO*)elem1;
2587  bdchginfo2 = (SCIP_BDCHGINFO*)elem2;
2588  assert(bdchginfo1 != NULL);
2589  assert(bdchginfo2 != NULL);
2590  assert(!SCIPbdchginfoIsRedundant(bdchginfo1));
2591  assert(!SCIPbdchginfoIsRedundant(bdchginfo2));
2592 
2594  return -1;
2595  else
2596  return +1;
2597 }
2598 
2599 /** return TRUE if conflict analysis is applicable; In case the function return FALSE there is no need to initialize the
2600  * conflict analysis since it will not be applied
2601  */
2603  SCIP_SET* set /**< global SCIP settings */
2604  )
2605 {
2606  /* check, if propagation conflict analysis is enabled */
2607  if( !set->conf_enable || !set->conf_useprop )
2608  return FALSE;
2609 
2610  /* check, if there are any conflict handlers to use a conflict set */
2611  if( set->nconflicthdlrs == 0 )
2612  return FALSE;
2613 
2614  return TRUE;
2615 }
2616 
2617 /** creates conflict analysis data for propagation conflicts */
2619  SCIP_CONFLICT** conflict, /**< pointer to conflict analysis data */
2620  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
2621  SCIP_SET* set /**< global SCIP settings */
2622  )
2623 {
2624  assert(conflict != NULL);
2625 
2626  SCIP_ALLOC( BMSallocMemory(conflict) );
2627 
2628  SCIP_CALL( SCIPclockCreate(&(*conflict)->dIBclock, SCIP_CLOCKTYPE_DEFAULT) );
2629  SCIP_CALL( SCIPclockCreate(&(*conflict)->propanalyzetime, SCIP_CLOCKTYPE_DEFAULT) );
2630  SCIP_CALL( SCIPclockCreate(&(*conflict)->inflpanalyzetime, SCIP_CLOCKTYPE_DEFAULT) );
2631  SCIP_CALL( SCIPclockCreate(&(*conflict)->boundlpanalyzetime, SCIP_CLOCKTYPE_DEFAULT) );
2632  SCIP_CALL( SCIPclockCreate(&(*conflict)->sbanalyzetime, SCIP_CLOCKTYPE_DEFAULT) );
2633  SCIP_CALL( SCIPclockCreate(&(*conflict)->pseudoanalyzetime, SCIP_CLOCKTYPE_DEFAULT) );
2634 
2635  /* enable or disable timing depending on the parameter statistic timing */
2636  SCIPconflictEnableOrDisableClocks((*conflict), set->time_statistictiming);
2637 
2638  SCIP_CALL( SCIPpqueueCreate(&(*conflict)->bdchgqueue, set->mem_arraygrowinit, set->mem_arraygrowfac,
2639  conflictBdchginfoComp) );
2640  SCIP_CALL( SCIPpqueueCreate(&(*conflict)->forcedbdchgqueue, set->mem_arraygrowinit, set->mem_arraygrowfac,
2641  conflictBdchginfoComp) );
2642  SCIP_CALL( conflictsetCreate(&(*conflict)->conflictset, blkmem) );
2643  (*conflict)->conflictsets = NULL;
2644  (*conflict)->conflictsetscores = NULL;
2645  (*conflict)->tmpbdchginfos = NULL;
2646  (*conflict)->conflictsetssize = 0;
2647  (*conflict)->nconflictsets = 0;
2648  (*conflict)->tmpbdchginfossize = 0;
2649  (*conflict)->ntmpbdchginfos = 0;
2650  (*conflict)->count = 0;
2651  (*conflict)->nglbchgbds = 0;
2652  (*conflict)->nappliedglbconss = 0;
2653  (*conflict)->nappliedglbliterals = 0;
2654  (*conflict)->nlocchgbds = 0;
2655  (*conflict)->nappliedlocconss = 0;
2656  (*conflict)->nappliedlocliterals = 0;
2657  (*conflict)->npropcalls = 0;
2658  (*conflict)->npropsuccess = 0;
2659  (*conflict)->npropconfconss = 0;
2660  (*conflict)->npropconfliterals = 0;
2661  (*conflict)->npropreconvconss = 0;
2662  (*conflict)->npropreconvliterals = 0;
2663  (*conflict)->ninflpcalls = 0;
2664  (*conflict)->ninflpsuccess = 0;
2665  (*conflict)->ninflpconfconss = 0;
2666  (*conflict)->ninflpconfliterals = 0;
2667  (*conflict)->ninflpreconvconss = 0;
2668  (*conflict)->ninflpreconvliterals = 0;
2669  (*conflict)->ninflpiterations = 0;
2670  (*conflict)->nboundlpcalls = 0;
2671  (*conflict)->nboundlpsuccess = 0;
2672  (*conflict)->nboundlpconfconss = 0;
2673  (*conflict)->nboundlpconfliterals = 0;
2674  (*conflict)->nboundlpreconvconss = 0;
2675  (*conflict)->nboundlpreconvliterals = 0;
2676  (*conflict)->nboundlpiterations = 0;
2677  (*conflict)->nsbcalls = 0;
2678  (*conflict)->nsbsuccess = 0;
2679  (*conflict)->nsbconfconss = 0;
2680  (*conflict)->nsbconfliterals = 0;
2681  (*conflict)->nsbreconvconss = 0;
2682  (*conflict)->nsbreconvliterals = 0;
2683  (*conflict)->nsbiterations = 0;
2684  (*conflict)->npseudocalls = 0;
2685  (*conflict)->npseudosuccess = 0;
2686  (*conflict)->npseudoconfconss = 0;
2687  (*conflict)->npseudoconfliterals = 0;
2688  (*conflict)->npseudoreconvconss = 0;
2689  (*conflict)->npseudoreconvliterals = 0;
2690  (*conflict)->ndualrayinfglobal = 0;
2691  (*conflict)->ndualrayinfsuccess = 0;
2692  (*conflict)->ndualrayinfseparoot = 0;
2693  (*conflict)->dualrayinfnnonzeros = 0;
2694 
2695  return SCIP_OKAY;
2696 }
2697 
2698 /** frees conflict analysis data for propagation conflicts */
2700  SCIP_CONFLICT** conflict, /**< pointer to conflict analysis data */
2701  BMS_BLKMEM* blkmem /**< block memory of transformed problem */
2702  )
2703 {
2704  assert(conflict != NULL);
2705  assert(*conflict != NULL);
2706  assert((*conflict)->nconflictsets == 0);
2707  assert((*conflict)->ntmpbdchginfos == 0);
2708 
2709 #ifdef SCIP_CONFGRAPH
2710  confgraphFree();
2711 #endif
2712 
2713  SCIPclockFree(&(*conflict)->dIBclock);
2714  SCIPclockFree(&(*conflict)->propanalyzetime);
2715  SCIPclockFree(&(*conflict)->inflpanalyzetime);
2716  SCIPclockFree(&(*conflict)->boundlpanalyzetime);
2717  SCIPclockFree(&(*conflict)->sbanalyzetime);
2718  SCIPclockFree(&(*conflict)->pseudoanalyzetime);
2719  SCIPpqueueFree(&(*conflict)->bdchgqueue);
2720  SCIPpqueueFree(&(*conflict)->forcedbdchgqueue);
2721  conflictsetFree(&(*conflict)->conflictset, blkmem);
2722  BMSfreeMemoryArrayNull(&(*conflict)->conflictsets);
2723  BMSfreeMemoryArrayNull(&(*conflict)->conflictsetscores);
2724  BMSfreeMemoryArrayNull(&(*conflict)->tmpbdchginfos);
2725  BMSfreeMemory(conflict);
2726 
2727  return SCIP_OKAY;
2728 }
2729 
2730 /** clears the conflict queue and the current conflict set */
2731 static
2733  SCIP_CONFLICT* conflict /**< conflict analysis data */
2734  )
2735 {
2736  assert(conflict != NULL);
2737 
2738  SCIPpqueueClear(conflict->bdchgqueue);
2739  SCIPpqueueClear(conflict->forcedbdchgqueue);
2740  conflictsetClear(conflict->conflictset);
2741 }
2742 
2743 /** initializes the propagation conflict analysis by clearing the conflict candidate queue */
2745  SCIP_CONFLICT* conflict, /**< conflict analysis data */
2746  SCIP_SET* set, /**< global SCIP settings */
2747  SCIP_STAT* stat, /**< problem statistics */
2748  SCIP_PROB* prob, /**< problem data */
2749  SCIP_CONFTYPE conftype, /**< type of the conflict */
2750  SCIP_Bool usescutoffbound /**< depends the conflict on a cutoff bound? */
2751  )
2752 {
2753  assert(conflict != NULL);
2754  assert(set != NULL);
2755  assert(stat != NULL);
2756  assert(prob != NULL);
2757 
2758  SCIPsetDebugMsg(set, "initializing conflict analysis\n");
2759 
2760  /* clear the conflict candidate queue and the conflict set */
2761  conflictClear(conflict);
2762 
2763  /* set conflict type */
2764  assert(conftype == SCIP_CONFTYPE_BNDEXCEEDING || conftype == SCIP_CONFTYPE_INFEASLP
2765  || conftype == SCIP_CONFTYPE_PROPAGATION);
2766  conflict->conflictset->conflicttype = conftype;
2767 
2768  /* set whether a cutoff bound is involved */
2769  conflict->conflictset->usescutoffbound = usescutoffbound;
2770 
2771  /* increase the conflict counter, such that binary variables of new conflict set and new conflict queue are labeled
2772  * with this new counter
2773  */
2774  conflict->count++;
2775  if( conflict->count == 0 ) /* make sure, 0 is not a valid conflict counter (may happen due to integer overflow) */
2776  conflict->count = 1;
2777 
2778  /* increase the conflict score weight for history updates of future conflict reasons */
2779  if( stat->nnodes > stat->lastconflictnode )
2780  {
2781  assert(0.0 < set->conf_scorefac && set->conf_scorefac <= 1.0);
2782  stat->vsidsweight /= set->conf_scorefac;
2783  assert(stat->vsidsweight > 0.0);
2784 
2785  /* if the conflict score for the next conflict exceeds 1000.0, rescale all history conflict scores */
2786  if( stat->vsidsweight >= 1000.0 )
2787  {
2788  int v;
2789 
2790  for( v = 0; v < prob->nvars; ++v )
2791  {
2792  SCIP_CALL( SCIPvarScaleVSIDS(prob->vars[v], 1.0/stat->vsidsweight) );
2793  }
2794  SCIPhistoryScaleVSIDS(stat->glbhistory, 1.0/stat->vsidsweight);
2796  stat->vsidsweight = 1.0;
2797  }
2798  stat->lastconflictnode = stat->nnodes;
2799  }
2800 
2801 #ifdef SCIP_CONFGRAPH
2802  confgraphFree();
2803  SCIP_CALL( confgraphCreate(set, conflict) );
2804 #endif
2805 
2806  return SCIP_OKAY;
2807 }
2808 
2809 /** marks bound to be present in the current conflict and returns whether a bound which is at least as tight was already
2810  * member of the current conflict (i.e., the given bound change does not need to be added)
2811  */
2812 static
2814  SCIP_CONFLICT* conflict, /**< conflict analysis data */
2815  SCIP_BDCHGINFO* bdchginfo, /**< bound change to add to the conflict set */
2816  SCIP_Real relaxedbd /**< relaxed bound */
2817  )
2818 {
2819  SCIP_VAR* var;
2820  SCIP_Real newbound;
2821 
2822  assert(conflict != NULL);
2823 
2824  var = SCIPbdchginfoGetVar(bdchginfo);
2825  newbound = SCIPbdchginfoGetNewbound(bdchginfo);
2826  assert(var != NULL);
2827 
2828  switch( SCIPbdchginfoGetBoundtype(bdchginfo) )
2829  {
2830  case SCIP_BOUNDTYPE_LOWER:
2831  /* check if the variables lower bound is already member of the conflict */
2832  if( var->conflictlbcount == conflict->count )
2833  {
2834  /* the variable is already member of the conflict; hence check if the new bound is redundant */
2835  if( var->conflictlb > newbound )
2836  {
2837  SCIPdebugMessage("ignoring redundant bound change <%s> >= %g since a stronger lower bound exist <%s> >= %g\n",
2838  SCIPvarGetName(var), newbound, SCIPvarGetName(var), var->conflictlb);
2839  return TRUE;
2840  }
2841  else if( var->conflictlb == newbound ) /*lint !e777*/
2842  {
2843  SCIPdebugMessage("ignoring redundant bound change <%s> >= %g since this lower bound is already present\n", SCIPvarGetName(var), newbound);
2844  SCIPdebugMessage("adjust relaxed lower bound <%g> -> <%g>\n", var->conflictlb, relaxedbd);
2845  var->conflictrelaxedlb = MAX(var->conflictrelaxedlb, relaxedbd);
2846  return TRUE;
2847  }
2848  }
2849 
2850  /* add the variable lower bound to the current conflict */
2851  var->conflictlbcount = conflict->count;
2852 
2853  /* remember the lower bound and relaxed bound to allow only better/tighter lower bounds for that variables
2854  * w.r.t. this conflict
2855  */
2856  var->conflictlb = newbound;
2857  var->conflictrelaxedlb = relaxedbd;
2858 
2859  return FALSE;
2860 
2861  case SCIP_BOUNDTYPE_UPPER:
2862  /* check if the variables upper bound is already member of the conflict */
2863  if( var->conflictubcount == conflict->count )
2864  {
2865  /* the variable is already member of the conflict; hence check if the new bound is redundant */
2866  if( var->conflictub < newbound )
2867  {
2868  SCIPdebugMessage("ignoring redundant bound change <%s> <= %g since a stronger upper bound exist <%s> <= %g\n",
2869  SCIPvarGetName(var), newbound, SCIPvarGetName(var), var->conflictub);
2870  return TRUE;
2871  }
2872  else if( var->conflictub == newbound ) /*lint !e777*/
2873  {
2874  SCIPdebugMessage("ignoring redundant bound change <%s> <= %g since this upper bound is already present\n", SCIPvarGetName(var), newbound);
2875  SCIPdebugMessage("adjust relaxed upper bound <%g> -> <%g>\n", var->conflictub, relaxedbd);
2876  var->conflictrelaxedub = MIN(var->conflictrelaxedub, relaxedbd);
2877  return TRUE;
2878  }
2879  }
2880 
2881  /* add the variable upper bound to the current conflict */
2882  var->conflictubcount = conflict->count;
2883 
2884  /* remember the upper bound and relaxed bound to allow only better/tighter upper bounds for that variables
2885  * w.r.t. this conflict
2886  */
2887  var->conflictub = newbound;
2888  var->conflictrelaxedub = relaxedbd;
2889 
2890  return FALSE;
2891 
2892  default:
2893  SCIPerrorMessage("invalid bound type %d\n", SCIPbdchginfoGetBoundtype(bdchginfo));
2894  SCIPABORT();
2895  return FALSE; /*lint !e527*/
2896  }
2897 }
2898 
2899 /** puts bound change into the current conflict set */
2900 static
2902  SCIP_CONFLICT* conflict, /**< conflict analysis data */
2903  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
2904  SCIP_SET* set, /**< global SCIP settings */
2905  SCIP_BDCHGINFO* bdchginfo, /**< bound change to add to the conflict set */
2906  SCIP_Real relaxedbd /**< relaxed bound */
2907  )
2908 {
2909  assert(conflict != NULL);
2910  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
2911 
2912  /* check if the relaxed bound is really a relaxed bound */
2913  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER || SCIPsetIsGE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
2914  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_UPPER || SCIPsetIsLE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
2915 
2916  SCIPsetDebugMsg(set, "putting bound change <%s> %s %g(%g) at depth %d to current conflict set\n",
2917  SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)),
2918  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", SCIPbdchginfoGetNewbound(bdchginfo),
2919  relaxedbd, SCIPbdchginfoGetDepth(bdchginfo));
2920 
2921  /* mark the bound to be member of the conflict and check if a bound which is at least as tight is already member of
2922  * the conflict
2923  */
2924  if( !conflictMarkBoundCheckPresence(conflict, bdchginfo, relaxedbd) )
2925  {
2926  /* add the bound change to the current conflict set */
2927  SCIP_CALL( conflictsetAddBound(conflict->conflictset, blkmem, set, bdchginfo, relaxedbd) );
2928 
2929 #ifdef SCIP_CONFGRAPH
2930  if( bdchginfo != confgraphcurrentbdchginfo )
2931  confgraphAddBdchg(bdchginfo);
2932 #endif
2933  }
2934 #ifdef SCIP_CONFGRAPH
2935  else
2936  confgraphLinkBdchg(bdchginfo);
2937 #endif
2938 
2939  return SCIP_OKAY;
2940 }
2941 
2942 /** returns whether the negation of the given bound change would lead to a globally valid literal */
2943 static
2945  SCIP_SET* set, /**< global SCIP settings */
2946  SCIP_BDCHGINFO* bdchginfo /**< bound change information */
2947  )
2948 {
2949  SCIP_VAR* var;
2950  SCIP_BOUNDTYPE boundtype;
2951  SCIP_Real bound;
2952 
2953  var = SCIPbdchginfoGetVar(bdchginfo);
2954  boundtype = SCIPbdchginfoGetBoundtype(bdchginfo);
2955  bound = SCIPbdchginfoGetNewbound(bdchginfo);
2956 
2957  return (SCIPvarGetType(var) == SCIP_VARTYPE_CONTINUOUS
2958  && ((boundtype == SCIP_BOUNDTYPE_LOWER && SCIPsetIsFeasGE(set, bound, SCIPvarGetUbGlobal(var)))
2959  || (boundtype == SCIP_BOUNDTYPE_UPPER && SCIPsetIsFeasLE(set, bound, SCIPvarGetLbGlobal(var)))));
2960 }
2961 
2962 /** adds given bound change information to the conflict candidate queue */
2963 static
2965  SCIP_CONFLICT* conflict, /**< conflict analysis data */
2966  SCIP_SET* set, /**< global SCIP settings */
2967  SCIP_BDCHGINFO* bdchginfo, /**< bound change information */
2968  SCIP_Real relaxedbd /**< relaxed bound */
2969  )
2970 {
2971  assert(conflict != NULL);
2972  assert(set != NULL);
2973  assert(bdchginfo != NULL);
2974  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
2975 
2976  /* check if the relaxed bound is really a relaxed bound */
2977  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER || SCIPsetIsGE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
2978  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_UPPER || SCIPsetIsLE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
2979 
2980  /* mark the bound to be member of the conflict and check if a bound which is at least as tight is already member of
2981  * the conflict
2982  */
2983  if( !conflictMarkBoundCheckPresence(conflict, bdchginfo, relaxedbd) )
2984  {
2985  /* insert the bound change into the conflict queue */
2986  if( (!set->conf_preferbinary || SCIPvarIsBinary(SCIPbdchginfoGetVar(bdchginfo)))
2987  && !isBoundchgUseless(set, bdchginfo) )
2988  {
2989  SCIP_CALL( SCIPpqueueInsert(conflict->bdchgqueue, (void*)bdchginfo) );
2990  }
2991  else
2992  {
2993  SCIP_CALL( SCIPpqueueInsert(conflict->forcedbdchgqueue, (void*)bdchginfo) );
2994  }
2995 
2996 #ifdef SCIP_CONFGRAPH
2997  confgraphAddBdchg(bdchginfo);
2998 #endif
2999  }
3000 #ifdef SCIP_CONFGRAPH
3001  else
3002  confgraphLinkBdchg(bdchginfo);
3003 #endif
3004 
3005  return SCIP_OKAY;
3006 }
3007 
3008 /** convert variable and bound change to active variable */
3009 static
3011  SCIP_VAR** var, /**< pointer to variable */
3012  SCIP_SET* set, /**< global SCIP settings */
3013  SCIP_BOUNDTYPE* boundtype, /**< pointer to type of bound that was changed: lower or upper bound */
3014  SCIP_Real* bound /**< pointer to bound to convert, or NULL */
3015  )
3016 {
3017  SCIP_Real scalar;
3018  SCIP_Real constant;
3019 
3020  scalar = 1.0;
3021  constant = 0.0;
3022 
3023  /* transform given varibale to active varibale */
3024  SCIP_CALL( SCIPvarGetProbvarSum(var, set, &scalar, &constant) );
3025  assert(SCIPvarGetStatus(*var) == SCIP_VARSTATUS_FIXED || scalar != 0.0); /*lint !e777*/
3026 
3027  if( SCIPvarGetStatus(*var) == SCIP_VARSTATUS_FIXED )
3028  return SCIP_OKAY;
3029 
3030  /* if the scalar of the aggregation is negative, we have to switch the bound type */
3031  if( scalar < 0.0 )
3032  (*boundtype) = SCIPboundtypeOpposite(*boundtype);
3033 
3034  if( bound != NULL )
3035  {
3036  (*bound) -= constant;
3037  (*bound) /= scalar;
3038  }
3039 
3040  return SCIP_OKAY;
3041 }
3042 
3043 /** adds variable's bound to conflict candidate queue */
3044 static
3046  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3047  BMS_BLKMEM* blkmem, /**< block memory */
3048  SCIP_SET* set, /**< global SCIP settings */
3049  SCIP_STAT* stat, /**< dynamic problem statistics */
3050  SCIP_VAR* var, /**< problem variable */
3051  SCIP_BOUNDTYPE boundtype, /**< type of bound that was changed: lower or upper bound */
3052  SCIP_BDCHGINFO* bdchginfo, /**< bound change info, or NULL */
3053  SCIP_Real relaxedbd /**< relaxed bound */
3054  )
3055 {
3056  assert(SCIPvarIsActive(var));
3057  assert(bdchginfo != NULL);
3058  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
3059 
3060  SCIPsetDebugMsg(set, " -> adding bound <%s> %s %.15g(%.15g) [status:%d, type:%d, depth:%d, pos:%d, reason:<%s>, info:%d] to candidates\n",
3061  SCIPvarGetName(var),
3062  boundtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3063  SCIPbdchginfoGetNewbound(bdchginfo), relaxedbd,
3064  SCIPvarGetStatus(var), SCIPvarGetType(var),
3065  SCIPbdchginfoGetDepth(bdchginfo), SCIPbdchginfoGetPos(bdchginfo),
3066  SCIPbdchginfoGetChgtype(bdchginfo) == SCIP_BOUNDCHGTYPE_BRANCHING ? "branch"
3070  : "none")),
3072 
3073  /* the local bound change may be resolved and has to be put on the candidate queue;
3074  * we even put bound changes without inference information on the queue in order to automatically
3075  * eliminate multiple insertions of the same bound change
3076  */
3077  assert(SCIPbdchginfoGetVar(bdchginfo) == var);
3078  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == boundtype);
3079  assert(SCIPbdchginfoGetDepth(bdchginfo) >= 0);
3080  assert(SCIPbdchginfoGetPos(bdchginfo) >= 0);
3081 
3082  /* the relaxed bound should be a relaxation */
3083  assert(boundtype == SCIP_BOUNDTYPE_LOWER ? SCIPsetIsLE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)) : SCIPsetIsGE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
3084 
3085  /* the relaxed bound should be worse then the old bound of the bound change info */
3086  assert(boundtype == SCIP_BOUNDTYPE_LOWER ? SCIPsetIsGT(set, relaxedbd, SCIPbdchginfoGetOldbound(bdchginfo)) : SCIPsetIsLT(set, relaxedbd, SCIPbdchginfoGetOldbound(bdchginfo)));
3087 
3088  /* put bound change information into priority queue */
3089  SCIP_CALL( conflictQueueBound(conflict, set, bdchginfo, relaxedbd) );
3090 
3091  /* each variable which is add to the conflict graph gets an increase in the VSIDS
3092  *
3093  * @note That is different to the VSIDS preseted in the literature
3094  */
3095  SCIP_CALL( incVSIDS(var, blkmem, set, stat, boundtype, relaxedbd, set->conf_conflictgraphweight) );
3096 
3097  return SCIP_OKAY;
3098 }
3099 
3100 /** adds variable's bound to conflict candidate queue */
3102  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3103  BMS_BLKMEM* blkmem, /**< block memory */
3104  SCIP_SET* set, /**< global SCIP settings */
3105  SCIP_STAT* stat, /**< dynamic problem statistics */
3106  SCIP_VAR* var, /**< problem variable */
3107  SCIP_BOUNDTYPE boundtype, /**< type of bound that was changed: lower or upper bound */
3108  SCIP_BDCHGIDX* bdchgidx /**< bound change index (time stamp of bound change), or NULL for current time */
3109  )
3110 {
3111  SCIP_BDCHGINFO* bdchginfo;
3112 
3113  assert(conflict != NULL);
3114  assert(stat != NULL);
3115  assert(var != NULL);
3116 
3117  /* convert bound to active problem variable */
3118  SCIP_CALL( convertToActiveVar(&var, set, &boundtype, NULL) );
3119 
3120  /* we can ignore fixed variables */
3122  return SCIP_OKAY;
3123 
3124  /* if the variable is multi-aggregated, add the bounds of all aggregation variables */
3126  {
3127  SCIP_VAR** vars;
3128  SCIP_Real* scalars;
3129  int nvars;
3130  int i;
3131 
3132  vars = SCIPvarGetMultaggrVars(var);
3133  scalars = SCIPvarGetMultaggrScalars(var);
3134  nvars = SCIPvarGetMultaggrNVars(var);
3135  for( i = 0; i < nvars; ++i )
3136  {
3137  SCIP_CALL( SCIPconflictAddBound(conflict, blkmem, set, stat, vars[i],
3138  (scalars[i] < 0.0 ? SCIPboundtypeOpposite(boundtype) : boundtype), bdchgidx) );
3139  }
3140 
3141  return SCIP_OKAY;
3142  }
3143  assert(SCIPvarIsActive(var));
3144 
3145  /* get bound change information */
3146  bdchginfo = SCIPvarGetBdchgInfo(var, boundtype, bdchgidx, FALSE);
3147 
3148  /* if bound of variable was not changed (this means it is still the global bound), we can ignore the conflicting
3149  * bound
3150  */
3151  if( bdchginfo == NULL )
3152  return SCIP_OKAY;
3153 
3154  assert(SCIPbdchgidxIsEarlier(SCIPbdchginfoGetIdx(bdchginfo), bdchgidx));
3155 
3156  SCIP_CALL( conflictAddBound(conflict, blkmem, set, stat, var, boundtype, bdchginfo, SCIPbdchginfoGetNewbound(bdchginfo)) );
3157 
3158  return SCIP_OKAY;
3159 }
3160 
3161 /** adds variable's bound to conflict candidate queue */
3163  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3164  BMS_BLKMEM* blkmem, /**< block memory */
3165  SCIP_SET* set, /**< global SCIP settings */
3166  SCIP_STAT* stat, /**< dynamic problem statistics */
3167  SCIP_VAR* var, /**< problem variable */
3168  SCIP_BOUNDTYPE boundtype, /**< type of bound that was changed: lower or upper bound */
3169  SCIP_BDCHGIDX* bdchgidx, /**< bound change index (time stamp of bound change), or NULL for current time */
3170  SCIP_Real relaxedbd /**< the relaxed bound */
3171  )
3172 {
3173  SCIP_BDCHGINFO* bdchginfo;
3174  int nbdchgs;
3175 
3176  assert(conflict != NULL);
3177  assert(stat != NULL);
3178  assert(var != NULL);
3179 
3180  if( !SCIPvarIsActive(var) )
3181  {
3182  /* convert bound to active problem variable */
3183  SCIP_CALL( convertToActiveVar(&var, set, &boundtype, &relaxedbd) );
3184 
3185  /* we can ignore fixed variables */
3187  return SCIP_OKAY;
3188 
3189  /* if the variable is multi-aggregated, add the bounds of all aggregation variables */
3191  {
3192  SCIPsetDebugMsg(set, "ignoring relaxed bound information since variable <%s> is multi-aggregated active\n", SCIPvarGetName(var));
3193 
3194  SCIP_CALL( SCIPconflictAddBound(conflict, blkmem, set, stat, var, boundtype, bdchgidx) );
3195 
3196  return SCIP_OKAY;
3197  }
3198  }
3199  assert(SCIPvarIsActive(var));
3200 
3201  /* get bound change information */
3202  bdchginfo = SCIPvarGetBdchgInfo(var, boundtype, bdchgidx, FALSE);
3203 
3204  /* if bound of variable was not changed (this means it is still the global bound), we can ignore the conflicting
3205  * bound
3206  */
3207  if( bdchginfo == NULL )
3208  return SCIP_OKAY;
3209 
3210  /* check that the bound change info is not a temporary one */
3211  assert(SCIPbdchgidxGetPos(&bdchginfo->bdchgidx) >= 0);
3212 
3213  /* get the position of the bound change information within the bound change array of the variable */
3214  nbdchgs = (int) bdchginfo->pos;
3215  assert(nbdchgs >= 0);
3216 
3217  /* if the relaxed bound should be ignored, set the relaxed bound to the bound given by the bdchgidx; that ensures
3218  * that the loop(s) below will be skipped
3219  */
3220  if( set->conf_ignorerelaxedbd )
3221  relaxedbd = SCIPbdchginfoGetNewbound(bdchginfo);
3222 
3223  /* search for the bound change information which includes the relaxed bound */
3224  if( boundtype == SCIP_BOUNDTYPE_LOWER )
3225  {
3226  SCIP_Real newbound;
3227 
3228  /* adjust relaxed lower bound w.r.t. variable type */
3229  SCIPvarAdjustLb(var, set, &relaxedbd);
3230 
3231  /* due to numericis we compare the relaxed lower bound to the one present at the particular time point and take
3232  * the better one
3233  */
3234  newbound = SCIPbdchginfoGetNewbound(bdchginfo);
3235  relaxedbd = MIN(relaxedbd, newbound);
3236 
3237  /* check if relaxed lower bound is smaller or equal to global lower bound; if so we can ignore the conflicting
3238  * bound
3239  */
3240  if( SCIPsetIsLE(set, relaxedbd, SCIPvarGetLbGlobal(var)) )
3241  return SCIP_OKAY;
3242 
3243  while( nbdchgs > 0 )
3244  {
3245  assert(SCIPsetIsLE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
3246 
3247  /* check if the old lower bound is greater than or equal to relaxed lower bound; if not we found the bound
3248  * change info which we need to report
3249  */
3250  if( SCIPsetIsGT(set, relaxedbd, SCIPbdchginfoGetOldbound(bdchginfo)) )
3251  break;
3252 
3253  bdchginfo = SCIPvarGetBdchgInfoLb(var, nbdchgs-1);
3254 
3255  SCIPsetDebugMsg(set, "lower bound change %d oldbd=%.15g, newbd=%.15g, depth=%d, pos=%d, redundant=%u\n",
3256  nbdchgs, SCIPbdchginfoGetOldbound(bdchginfo), SCIPbdchginfoGetNewbound(bdchginfo),
3257  SCIPbdchginfoGetDepth(bdchginfo), SCIPbdchginfoGetPos(bdchginfo),
3258  SCIPbdchginfoIsRedundant(bdchginfo));
3259 
3260  /* if bound change is redundant (this means it now a global bound), we can ignore the conflicting bound */
3261  if( SCIPbdchginfoIsRedundant(bdchginfo) )
3262  return SCIP_OKAY;
3263 
3264  nbdchgs--;
3265  }
3266  assert(SCIPsetIsGT(set, relaxedbd, SCIPbdchginfoGetOldbound(bdchginfo)));
3267  }
3268  else
3269  {
3270  SCIP_Real newbound;
3271 
3272  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
3273 
3274  /* adjust relaxed upper bound w.r.t. variable type */
3275  SCIPvarAdjustUb(var, set, &relaxedbd);
3276 
3277  /* due to numericis we compare the relaxed upper bound to the one present at the particular time point and take
3278  * the better one
3279  */
3280  newbound = SCIPbdchginfoGetNewbound(bdchginfo);
3281  relaxedbd = MAX(relaxedbd, newbound);
3282 
3283  /* check if relaxed upper bound is greater or equal to global upper bound; if so we can ignore the conflicting
3284  * bound
3285  */
3286  if( SCIPsetIsGE(set, relaxedbd, SCIPvarGetUbGlobal(var)) )
3287  return SCIP_OKAY;
3288 
3289  while( nbdchgs > 0 )
3290  {
3291  assert(SCIPsetIsGE(set, relaxedbd, SCIPbdchginfoGetNewbound(bdchginfo)));
3292 
3293  /* check if the old upper bound is smaller than or equal to the relaxed upper bound; if not we found the
3294  * bound change info which we need to report
3295  */
3296  if( SCIPsetIsLT(set, relaxedbd, SCIPbdchginfoGetOldbound(bdchginfo)) )
3297  break;
3298 
3299  bdchginfo = SCIPvarGetBdchgInfoUb(var, nbdchgs-1);
3300 
3301  SCIPsetDebugMsg(set, "upper bound change %d oldbd=%.15g, newbd=%.15g, depth=%d, pos=%d, redundant=%u\n",
3302  nbdchgs, SCIPbdchginfoGetOldbound(bdchginfo), SCIPbdchginfoGetNewbound(bdchginfo),
3303  SCIPbdchginfoGetDepth(bdchginfo), SCIPbdchginfoGetPos(bdchginfo),
3304  SCIPbdchginfoIsRedundant(bdchginfo));
3305 
3306  /* if bound change is redundant (this means it now a global bound), we can ignore the conflicting bound */
3307  if( SCIPbdchginfoIsRedundant(bdchginfo) )
3308  return SCIP_OKAY;
3309 
3310  nbdchgs--;
3311  }
3312  assert(SCIPsetIsLT(set, relaxedbd, SCIPbdchginfoGetOldbound(bdchginfo)));
3313  }
3314 
3315  assert(SCIPbdchgidxIsEarlier(SCIPbdchginfoGetIdx(bdchginfo), bdchgidx));
3316 
3317  /* put bound change information into priority queue */
3318  SCIP_CALL( conflictAddBound(conflict, blkmem, set, stat, var, boundtype, bdchginfo, relaxedbd) );
3319 
3320  return SCIP_OKAY;
3321 }
3322 
3323 /** checks if the given variable is already part of the current conflict set or queued for resolving with the same or
3324  * even stronger bound
3325  */
3327  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3328  SCIP_VAR* var, /**< problem variable */
3329  SCIP_SET* set, /**< global SCIP settings */
3330  SCIP_BOUNDTYPE boundtype, /**< type of bound for which the score should be increased */
3331  SCIP_BDCHGIDX* bdchgidx, /**< bound change index (time stamp of bound change), or NULL for current time */
3332  SCIP_Bool* used /**< pointer to store if the variable is already used */
3333  )
3334 {
3335  SCIP_Real newbound;
3336 
3337  /* convert bound to active problem variable */
3338  SCIP_CALL( convertToActiveVar(&var, set, &boundtype, NULL) );
3339 
3341  *used = FALSE;
3342  else
3343  {
3344  assert(SCIPvarIsActive(var));
3345  assert(var != NULL);
3346 
3347  switch( boundtype )
3348  {
3349  case SCIP_BOUNDTYPE_LOWER:
3350 
3351  newbound = SCIPgetVarLbAtIndex(set->scip, var, bdchgidx, FALSE);
3352 
3353  if( var->conflictlbcount == conflict->count && var->conflictlb >= newbound )
3354  {
3355  SCIPsetDebugMsg(set, "already queued bound change <%s> >= %g\n", SCIPvarGetName(var), newbound);
3356  *used = TRUE;
3357  }
3358  else
3359  *used = FALSE;
3360  break;
3361  case SCIP_BOUNDTYPE_UPPER:
3362 
3363  newbound = SCIPgetVarUbAtIndex(set->scip, var, bdchgidx, FALSE);
3364 
3365  if( var->conflictubcount == conflict->count && var->conflictub <= newbound )
3366  {
3367  SCIPsetDebugMsg(set, "already queued bound change <%s> <= %g\n", SCIPvarGetName(var), newbound);
3368  *used = TRUE;
3369  }
3370  else
3371  *used = FALSE;
3372  break;
3373  default:
3374  SCIPerrorMessage("invalid bound type %d\n", boundtype);
3375  SCIPABORT();
3376  *used = FALSE; /*lint !e527*/
3377  }
3378  }
3379 
3380  return SCIP_OKAY;
3381 }
3382 
3383 /** returns the conflict lower bound if the variable is present in the current conflict set; otherwise the global lower
3384  * bound
3385  */
3387  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3388  SCIP_VAR* var /**< problem variable */
3389  )
3390 {
3391  if( var->conflictlbcount == conflict->count )
3392  {
3393  assert(EPSGE(var->conflictlb, var->conflictrelaxedlb, 1e-09));
3394  return var->conflictrelaxedlb;
3395  }
3396 
3397  return SCIPvarGetLbGlobal(var);
3398 }
3399 
3400 /** returns the conflict upper bound if the variable is present in the current conflict set; otherwise the global upper
3401  * bound
3402  */
3404  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3405  SCIP_VAR* var /**< problem variable */
3406  )
3407 {
3408  if( var->conflictubcount == conflict->count )
3409  {
3410  assert(EPSLE(var->conflictub, var->conflictrelaxedub, 1e-09));
3411  return var->conflictrelaxedub;
3412  }
3413 
3414  return SCIPvarGetUbGlobal(var);
3415 }
3416 
3417 /** removes and returns next conflict analysis candidate from the candidate queue */
3418 static
3420  SCIP_CONFLICT* conflict /**< conflict analysis data */
3421  )
3422 {
3423  SCIP_BDCHGINFO* bdchginfo;
3424  SCIP_VAR* var;
3425 
3426  assert(conflict != NULL);
3427 
3428  if( SCIPpqueueNElems(conflict->forcedbdchgqueue) > 0 )
3429  bdchginfo = (SCIP_BDCHGINFO*)(SCIPpqueueRemove(conflict->forcedbdchgqueue));
3430  else
3431  bdchginfo = (SCIP_BDCHGINFO*)(SCIPpqueueRemove(conflict->bdchgqueue));
3432 
3433  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
3434 
3435  /* if we have a candidate this one should be valid for the current conflict analysis */
3436  assert(!bdchginfoIsInvalid(conflict, bdchginfo));
3437 
3438  /* mark the bound change to be no longer in the conflict (it will be either added again to the conflict set or
3439  * replaced by resolving, which might add a weaker change on the same bound to the queue)
3440  */
3441  var = SCIPbdchginfoGetVar(bdchginfo);
3443  {
3444  var->conflictlbcount = 0;
3446  }
3447  else
3448  {
3449  assert(SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_UPPER);
3450  var->conflictubcount = 0;
3452  }
3453 
3454 #ifdef SCIP_CONFGRAPH
3455  confgraphSetCurrentBdchg(bdchginfo);
3456 #endif
3457 
3458  return bdchginfo;
3459 }
3460 
3461 /** returns next conflict analysis candidate from the candidate queue without removing it */
3462 static
3464  SCIP_CONFLICT* conflict /**< conflict analysis data */
3465  )
3466 {
3467  SCIP_BDCHGINFO* bdchginfo;
3468 
3469  assert(conflict != NULL);
3470 
3471  if( SCIPpqueueNElems(conflict->forcedbdchgqueue) > 0 )
3472  {
3473  /* get next potetioal candidate */
3474  bdchginfo = (SCIP_BDCHGINFO*)(SCIPpqueueFirst(conflict->forcedbdchgqueue));
3475 
3476  /* check if this candidate is valid */
3477  if( bdchginfoIsInvalid(conflict, bdchginfo) )
3478  {
3479  SCIPdebugMessage("bound change info [%d:<%s> %s %g] is invaild -> pop it from the force queue\n", SCIPbdchginfoGetDepth(bdchginfo),
3480  SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)),
3481  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3482  SCIPbdchginfoGetNewbound(bdchginfo));
3483 
3484  /* pop the invalid bound change info from the queue */
3485  (void)(SCIPpqueueRemove(conflict->forcedbdchgqueue));
3486 
3487  /* call method recursively to get next conflict analysis candidate */
3488  bdchginfo = conflictFirstCand(conflict);
3489  }
3490  }
3491  else
3492  {
3493  bdchginfo = (SCIP_BDCHGINFO*)(SCIPpqueueFirst(conflict->bdchgqueue));
3494 
3495  /* check if this candidate is valid */
3496  if( bdchginfo != NULL && bdchginfoIsInvalid(conflict, bdchginfo) )
3497  {
3498  SCIPdebugMessage("bound change info [%d:<%s> %s %g] is invaild -> pop it from the queue\n", SCIPbdchginfoGetDepth(bdchginfo),
3499  SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)),
3500  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3501  SCIPbdchginfoGetNewbound(bdchginfo));
3502 
3503  /* pop the invalid bound change info from the queue */
3504  (void)(SCIPpqueueRemove(conflict->bdchgqueue));
3505 
3506  /* call method recursively to get next conflict analysis candidate */
3507  bdchginfo = conflictFirstCand(conflict);
3508  }
3509  }
3510  assert(bdchginfo == NULL || !SCIPbdchginfoIsRedundant(bdchginfo));
3511 
3512  return bdchginfo;
3513 }
3514 
3515 /** adds the current conflict set (extended by all remaining bound changes in the queue) to the pool of conflict sets */
3516 static
3518  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3519  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
3520  SCIP_SET* set, /**< global SCIP settings */
3521  SCIP_STAT* stat, /**< dynamic problem statistics */
3522  SCIP_TREE* tree, /**< branch and bound tree */
3523  int validdepth, /**< minimal depth level at which the conflict set is valid */
3524  SCIP_Bool diving, /**< are we in strong branching or diving mode? */
3525  SCIP_Bool repropagate, /**< should the constraint trigger a repropagation? */
3526  SCIP_Bool* success, /**< pointer to store whether the conflict set is valid */
3527  int* nliterals /**< pointer to store the number of literals in the generated conflictset */
3528  )
3529 {
3530  SCIP_CONFLICTSET* conflictset;
3531  SCIP_BDCHGINFO** bdchginfos;
3532  int nbdchginfos;
3533  int currentdepth;
3534  int focusdepth;
3535 
3536  assert(conflict != NULL);
3537  assert(conflict->conflictset != NULL);
3538  assert(set != NULL);
3539  assert(stat != NULL);
3540  assert(tree != NULL);
3541  assert(success != NULL);
3542  assert(nliterals != NULL);
3543  assert(SCIPpqueueNElems(conflict->forcedbdchgqueue) == 0);
3544 
3545  *success = FALSE;
3546  *nliterals = 0;
3547 
3548  /* check, whether local conflicts are allowed */
3549  validdepth = MAX(validdepth, conflict->conflictset->validdepth);
3550  if( !set->conf_allowlocal && validdepth > 0 )
3551  return SCIP_OKAY;
3552 
3553  focusdepth = SCIPtreeGetFocusDepth(tree);
3554  currentdepth = SCIPtreeGetCurrentDepth(tree);
3555  assert(currentdepth == tree->pathlen-1);
3556  assert(focusdepth <= currentdepth);
3557  assert(0 <= conflict->conflictset->validdepth && conflict->conflictset->validdepth <= currentdepth);
3558  assert(0 <= validdepth && validdepth <= currentdepth);
3559 
3560  /* get the elements of the bound change queue */
3561  bdchginfos = (SCIP_BDCHGINFO**)SCIPpqueueElems(conflict->bdchgqueue);
3562  nbdchginfos = SCIPpqueueNElems(conflict->bdchgqueue);
3563 
3564  /* create a copy of the current conflict set, allocating memory for the additional elements of the queue */
3565  SCIP_CALL( conflictsetCopy(&conflictset, blkmem, conflict->conflictset, nbdchginfos) );
3566  conflictset->validdepth = validdepth;
3567  conflictset->repropagate = repropagate;
3568 
3569  /* add the valid queue elements to the conflict set */
3570  SCIPsetDebugMsg(set, "adding %d variables from the queue as temporary conflict variables\n", nbdchginfos);
3571  SCIP_CALL( conflictsetAddBounds(conflict, conflictset, blkmem, set, bdchginfos, nbdchginfos) );
3572 
3573  /* calculate the depth, at which the conflictset should be inserted */
3574  SCIP_CALL( conflictsetCalcInsertDepth(conflictset, set, tree) );
3575  assert(conflictset->validdepth <= conflictset->insertdepth && conflictset->insertdepth <= currentdepth);
3576  SCIPsetDebugMsg(set, " -> conflict with %d literals found at depth %d is active in depth %d and valid in depth %d\n",
3577  conflictset->nbdchginfos, currentdepth, conflictset->insertdepth, conflictset->validdepth);
3578 
3579  /* if all branching variables are in the conflict set, the conflict set is of no use;
3580  * don't use conflict sets that are only valid in the probing path but not in the problem tree
3581  */
3582  if( (diving || conflictset->insertdepth < currentdepth) && conflictset->insertdepth <= focusdepth )
3583  {
3584  /* if the conflict should not be located only in the subtree where it is useful, put it to its valid depth level */
3585  if( !set->conf_settlelocal )
3586  conflictset->insertdepth = conflictset->validdepth;
3587 
3588  *nliterals = conflictset->nbdchginfos;
3589  SCIPsetDebugMsg(set, " -> final conflict set has %d literals\n", *nliterals);
3590 
3591  /* check conflict set on debugging solution */
3592  SCIP_CALL( SCIPdebugCheckConflict(blkmem, set, tree->path[validdepth],
3593  conflictset->bdchginfos, conflictset->relaxedbds, conflictset->nbdchginfos) ); /*lint !e506 !e774*/
3594 
3595  /* move conflictset to the conflictset storage */
3596  SCIP_CALL( conflictInsertConflictset(conflict, blkmem, set, &conflictset) );
3597  *success = TRUE;
3598  }
3599  else
3600  {
3601  /* free the temporary conflict set */
3602  conflictsetFree(&conflictset, blkmem);
3603  }
3604 
3605  return SCIP_OKAY;
3606 }
3607 
3608 /** tries to resolve given bound change
3609  * - resolutions on local constraints are only applied, if the constraint is valid at the
3610  * current minimal valid depth level, because this depth level is the topmost level to add the conflict
3611  * constraint to anyways
3612  *
3613  * @note it is sufficient to explain the relaxed bound change
3614  */
3615 static
3617  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3618  SCIP_SET* set, /**< global SCIP settings */
3619  SCIP_BDCHGINFO* bdchginfo, /**< bound change to resolve */
3620  SCIP_Real relaxedbd, /**< the relaxed bound */
3621  int validdepth, /**< minimal depth level at which the conflict is valid */
3622  SCIP_Bool* resolved /**< pointer to store whether the bound change was resolved */
3623  )
3624 {
3625  SCIP_VAR* actvar;
3626  SCIP_CONS* infercons;
3627  SCIP_PROP* inferprop;
3628  SCIP_RESULT result;
3629 
3630 #ifndef NDEBUG
3631  int nforcedbdchgqueue;
3632  int nbdchgqueue;
3633 
3634  /* store the current size of the conflict queues */
3635  assert(conflict != NULL);
3636  nforcedbdchgqueue = SCIPpqueueNElems(conflict->forcedbdchgqueue);
3637  nbdchgqueue = SCIPpqueueNElems(conflict->bdchgqueue);
3638 #else
3639  assert(conflict != NULL);
3640 #endif
3641 
3642  assert(resolved != NULL);
3643  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
3644 
3645  *resolved = FALSE;
3646 
3647  actvar = SCIPbdchginfoGetVar(bdchginfo);
3648  assert(actvar != NULL);
3649  assert(SCIPvarIsActive(actvar));
3650 
3651 #ifdef SCIP_DEBUG
3652  {
3653  int i;
3654  SCIPsetDebugMsg(set, "processing next conflicting bound (depth: %d, valid depth: %d, bdchgtype: %s [%s], vartype: %d): [<%s> %s %g(%g)]\n",
3655  SCIPbdchginfoGetDepth(bdchginfo), validdepth,
3656  SCIPbdchginfoGetChgtype(bdchginfo) == SCIP_BOUNDCHGTYPE_BRANCHING ? "branch"
3657  : SCIPbdchginfoGetChgtype(bdchginfo) == SCIP_BOUNDCHGTYPE_CONSINFER ? "cons" : "prop",
3661  : SCIPbdchginfoGetInferProp(bdchginfo) == NULL ? "-"
3663  SCIPvarGetType(actvar), SCIPvarGetName(actvar),
3664  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3665  SCIPbdchginfoGetNewbound(bdchginfo), relaxedbd);
3666  SCIPsetDebugMsg(set, " - conflict set :");
3667 
3668  for( i = 0; i < conflict->conflictset->nbdchginfos; ++i )
3669  {
3670  SCIPsetDebugMsgPrint(set, " [%d:<%s> %s %g(%g)]", SCIPbdchginfoGetDepth(conflict->conflictset->bdchginfos[i]),
3672  SCIPbdchginfoGetBoundtype(conflict->conflictset->bdchginfos[i]) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3673  SCIPbdchginfoGetNewbound(conflict->conflictset->bdchginfos[i]), conflict->conflictset->relaxedbds[i]);
3674  }
3675  SCIPsetDebugMsgPrint(set, "\n");
3676  SCIPsetDebugMsg(set, " - forced candidates :");
3677 
3678  for( i = 0; i < SCIPpqueueNElems(conflict->forcedbdchgqueue); ++i )
3679  {
3681  SCIPsetDebugMsgPrint(set, " [%d:<%s> %s %g(%g)]", SCIPbdchginfoGetDepth(info), SCIPvarGetName(SCIPbdchginfoGetVar(info)),
3682  bdchginfoIsInvalid(conflict, info) ? "<!>" : SCIPbdchginfoGetBoundtype(info) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3684  }
3685  SCIPsetDebugMsgPrint(set, "\n");
3686  SCIPsetDebugMsg(set, " - optional candidates:");
3687 
3688  for( i = 0; i < SCIPpqueueNElems(conflict->bdchgqueue); ++i )
3689  {
3690  SCIP_BDCHGINFO* info = (SCIP_BDCHGINFO*)(SCIPpqueueElems(conflict->bdchgqueue)[i]);
3691  SCIPsetDebugMsgPrint(set, " [%d:<%s> %s %g(%g)]", SCIPbdchginfoGetDepth(info), SCIPvarGetName(SCIPbdchginfoGetVar(info)),
3692  bdchginfoIsInvalid(conflict, info) ? "<!>" : SCIPbdchginfoGetBoundtype(info) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3694  }
3695  SCIPsetDebugMsgPrint(set, "\n");
3696  }
3697 #endif
3698 
3699  /* check, if the bound change can and should be resolved:
3700  * - resolutions on local constraints should only be applied, if the constraint is valid at the
3701  * current minimal valid depth level (which is initialized with the valid depth level of the initial
3702  * conflict set), because this depth level is the topmost level to add the conflict constraint to anyways
3703  */
3704  switch( SCIPbdchginfoGetChgtype(bdchginfo) )
3705  {
3707  infercons = SCIPbdchginfoGetInferCons(bdchginfo);
3708  assert(infercons != NULL);
3709 
3710  if( SCIPconsIsGlobal(infercons) || SCIPconsGetValidDepth(infercons) <= validdepth )
3711  {
3712  SCIP_VAR* infervar;
3713  int inferinfo;
3714  SCIP_BOUNDTYPE inferboundtype;
3715  SCIP_BDCHGIDX* bdchgidx;
3716 
3717  /* resolve bound change by asking the constraint that infered the bound to put all bounds that were
3718  * the reasons for the conflicting bound change on the priority queue
3719  */
3720  infervar = SCIPbdchginfoGetInferVar(bdchginfo);
3721  inferinfo = SCIPbdchginfoGetInferInfo(bdchginfo);
3722  inferboundtype = SCIPbdchginfoGetInferBoundtype(bdchginfo);
3723  bdchgidx = SCIPbdchginfoGetIdx(bdchginfo);
3724  assert(infervar != NULL);
3725 
3726  SCIPsetDebugMsg(set, "resolving bound <%s> %s %g(%g) [status:%d, type:%d, depth:%d, pos:%d]: <%s> %s %g [cons:<%s>(%s), info:%d]\n",
3727  SCIPvarGetName(actvar),
3728  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3729  SCIPbdchginfoGetNewbound(bdchginfo), relaxedbd,
3730  SCIPvarGetStatus(actvar), SCIPvarGetType(actvar),
3731  SCIPbdchginfoGetDepth(bdchginfo), SCIPbdchginfoGetPos(bdchginfo),
3732  SCIPvarGetName(infervar),
3733  inferboundtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3734  SCIPgetVarBdAtIndex(set->scip, infervar, inferboundtype, bdchgidx, TRUE),
3735  SCIPconsGetName(infercons),
3736  SCIPconsIsGlobal(infercons) ? "global" : "local",
3737  inferinfo);
3738 
3739  /* in case the inference variables is not an active variables, we need to transform the relaxed bound */
3740  if( actvar != infervar )
3741  {
3742  SCIP_VAR* var;
3743  SCIP_Real scalar;
3744  SCIP_Real constant;
3745 
3746  assert(SCIPvarGetStatus(infervar) == SCIP_VARSTATUS_AGGREGATED
3748  || (SCIPvarGetStatus(infervar) == SCIP_VARSTATUS_MULTAGGR && SCIPvarGetMultaggrNVars(infervar) == 1));
3749 
3750  scalar = 1.0;
3751  constant = 0.0;
3752 
3753  var = infervar;
3754 
3755  /* transform given varibale to active varibale */
3756  SCIP_CALL( SCIPvarGetProbvarSum(&var, set, &scalar, &constant) );
3757  assert(var == actvar);
3758 
3759  relaxedbd *= scalar;
3760  relaxedbd += constant;
3761  }
3762 
3763  SCIP_CALL( SCIPconsResolvePropagation(infercons, set, infervar, inferinfo, inferboundtype, bdchgidx, relaxedbd, &result) );
3764  *resolved = (result == SCIP_SUCCESS);
3765  }
3766  break;
3767 
3769  inferprop = SCIPbdchginfoGetInferProp(bdchginfo);
3770  if( inferprop != NULL )
3771  {
3772  SCIP_VAR* infervar;
3773  int inferinfo;
3774  SCIP_BOUNDTYPE inferboundtype;
3775  SCIP_BDCHGIDX* bdchgidx;
3776 
3777  /* resolve bound change by asking the propagator that infered the bound to put all bounds that were
3778  * the reasons for the conflicting bound change on the priority queue
3779  */
3780  infervar = SCIPbdchginfoGetInferVar(bdchginfo);
3781  inferinfo = SCIPbdchginfoGetInferInfo(bdchginfo);
3782  inferboundtype = SCIPbdchginfoGetInferBoundtype(bdchginfo);
3783  bdchgidx = SCIPbdchginfoGetIdx(bdchginfo);
3784  assert(infervar != NULL);
3785 
3786  SCIPsetDebugMsg(set, "resolving bound <%s> %s %g(%g) [status:%d, depth:%d, pos:%d]: <%s> %s %g [prop:<%s>, info:%d]\n",
3787  SCIPvarGetName(actvar),
3788  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3789  SCIPbdchginfoGetNewbound(bdchginfo), relaxedbd,
3790  SCIPvarGetStatus(actvar), SCIPbdchginfoGetDepth(bdchginfo), SCIPbdchginfoGetPos(bdchginfo),
3791  SCIPvarGetName(infervar),
3792  inferboundtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
3793  SCIPgetVarBdAtIndex(set->scip, infervar, inferboundtype, bdchgidx, TRUE),
3794  SCIPpropGetName(inferprop), inferinfo);
3795 
3796  SCIP_CALL( SCIPpropResolvePropagation(inferprop, set, infervar, inferinfo, inferboundtype, bdchgidx, relaxedbd, &result) );
3797  *resolved = (result == SCIP_SUCCESS);
3798  }
3799  break;
3800 
3802  assert(!(*resolved));
3803  break;
3804 
3805  default:
3806  SCIPerrorMessage("invalid bound change type <%d>\n", SCIPbdchginfoGetChgtype(bdchginfo));
3807  return SCIP_INVALIDDATA;
3808  }
3809 
3810  SCIPsetDebugMsg(set, "resolving status: %u\n", *resolved);
3811 
3812 #ifndef NDEBUG
3813  /* subtract the size of the conflicq queues */
3814  nforcedbdchgqueue -= SCIPpqueueNElems(conflict->forcedbdchgqueue);
3815  nbdchgqueue -= SCIPpqueueNElems(conflict->bdchgqueue);
3816 
3817  /* in case the bound change was not resolved, the conflict queues should have the same size (contents) */
3818  assert((*resolved) || (nforcedbdchgqueue == 0 && nbdchgqueue == 0));
3819 #endif
3820 
3821  return SCIP_OKAY;
3822 }
3823 
3824 /** if only one conflicting bound change of the last depth level was used, and if this can be resolved,
3825  * creates GRASP-like reconvergence conflict constraints in the conflict graph up to the branching variable of this
3826  * depth level
3827  */
3828 static
3830  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3831  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
3832  SCIP_SET* set, /**< global SCIP settings */
3833  SCIP_STAT* stat, /**< problem statistics */
3834  SCIP_PROB* prob, /**< problem data */
3835  SCIP_TREE* tree, /**< branch and bound tree */
3836  SCIP_Bool diving, /**< are we in strong branching or diving mode? */
3837  int validdepth, /**< minimal depth level at which the initial conflict set is valid */
3838  SCIP_BDCHGINFO* firstuip, /**< first UIP of conflict graph */
3839  int* nreconvconss, /**< pointer to store the number of generated reconvergence constraints */
3840  int* nreconvliterals /**< pointer to store the number of literals generated reconvergence constraints */
3841  )
3842 {
3843  SCIP_BDCHGINFO* uip;
3844  SCIP_CONFTYPE conftype;
3845  SCIP_Bool usescutoffbound;
3846  int firstuipdepth;
3847  int focusdepth;
3848  int currentdepth;
3849  int maxvaliddepth;
3850 
3851  assert(conflict != NULL);
3852  assert(firstuip != NULL);
3853  assert(nreconvconss != NULL);
3854  assert(nreconvliterals != NULL);
3855  assert(!SCIPbdchginfoIsRedundant(firstuip));
3856 
3857  focusdepth = SCIPtreeGetFocusDepth(tree);
3858  currentdepth = SCIPtreeGetCurrentDepth(tree);
3859  assert(currentdepth == tree->pathlen-1);
3860  assert(focusdepth <= currentdepth);
3861 
3862  /* check, whether local constraints are allowed; however, don't generate reconvergence constraints that are only valid
3863  * in the probing path and not in the problem tree (i.e. that exceed the focusdepth)
3864  */
3865  maxvaliddepth = (set->conf_allowlocal ? MIN(currentdepth-1, focusdepth) : 0);
3866  if( validdepth > maxvaliddepth )
3867  return SCIP_OKAY;
3868 
3869  firstuipdepth = SCIPbdchginfoGetDepth(firstuip);
3870 
3871  conftype = conflict->conflictset->conflicttype;
3872  usescutoffbound = conflict->conflictset->usescutoffbound;
3873 
3874  /* for each succeeding UIP pair of the last depth level, create one reconvergence constraint */
3875  uip = firstuip;
3876  while( uip != NULL && SCIPbdchginfoGetDepth(uip) == SCIPbdchginfoGetDepth(firstuip) && bdchginfoIsResolvable(uip) )
3877  {
3878  SCIP_BDCHGINFO* oppositeuip;
3879  SCIP_BDCHGINFO* bdchginfo;
3880  SCIP_BDCHGINFO* nextuip;
3881  SCIP_VAR* uipvar;
3882  SCIP_Real oppositeuipbound;
3883  SCIP_BOUNDTYPE oppositeuipboundtype;
3884  int nresolutions;
3885 
3886  assert(!SCIPbdchginfoIsRedundant(uip));
3887 
3888  SCIPsetDebugMsg(set, "creating reconvergence constraint for UIP <%s> %s %g in depth %d pos %d\n",
3891 
3892  /* initialize conflict data */
3893  SCIP_CALL( SCIPconflictInit(conflict, set, stat, prob, conftype, usescutoffbound) );
3894 
3895  conflict->conflictset->conflicttype = conftype;
3896  conflict->conflictset->usescutoffbound = usescutoffbound;
3897 
3898  /* create a temporary bound change information for the negation of the UIP's bound change;
3899  * this bound change information is freed in the SCIPconflictFlushConss() call;
3900  * for reconvergence constraints for continuous variables we can only use the "negation" !(x <= u) == (x >= u);
3901  * during conflict analysis, we treat a continuous bound "x >= u" in the conflict set as "x > u", and in the
3902  * generated constraint this is negated again to "x <= u" which is correct.
3903  */
3904  uipvar = SCIPbdchginfoGetVar(uip);
3905  oppositeuipboundtype = SCIPboundtypeOpposite(SCIPbdchginfoGetBoundtype(uip));
3906  oppositeuipbound = SCIPbdchginfoGetNewbound(uip);
3907  if( SCIPvarIsIntegral(uipvar) )
3908  {
3909  assert(SCIPsetIsIntegral(set, oppositeuipbound));
3910  oppositeuipbound += (oppositeuipboundtype == SCIP_BOUNDTYPE_LOWER ? +1.0 : -1.0);
3911  }
3912  SCIP_CALL( conflictCreateTmpBdchginfo(conflict, blkmem, set, uipvar,
3913  oppositeuipboundtype, oppositeuipboundtype == SCIP_BOUNDTYPE_LOWER ? SCIP_REAL_MIN : SCIP_REAL_MAX,
3914  oppositeuipbound, &oppositeuip) );
3915 
3916  /* put the negated UIP into the conflict set */
3917  SCIP_CALL( conflictAddConflictBound(conflict, blkmem, set, oppositeuip, oppositeuipbound) );
3918 
3919  /* put positive UIP into priority queue */
3920  SCIP_CALL( conflictQueueBound(conflict, set, uip, SCIPbdchginfoGetNewbound(uip) ) );
3921 
3922  /* resolve the queue until the next UIP is reached */
3923  bdchginfo = conflictFirstCand(conflict);
3924  nextuip = NULL;
3925  nresolutions = 0;
3926  while( bdchginfo != NULL && validdepth <= maxvaliddepth )
3927  {
3928  SCIP_BDCHGINFO* nextbdchginfo;
3929  SCIP_Real relaxedbd;
3930  SCIP_Bool forceresolve;
3931  int bdchgdepth;
3932 
3933  /* check if the next bound change must be resolved in every case */
3934  forceresolve = (SCIPpqueueNElems(conflict->forcedbdchgqueue) > 0);
3935 
3936  /* remove currently processed candidate and get next conflicting bound from the conflict candidate queue before
3937  * we remove the candidate we have to collect the relaxed bound since removing the candidate from the queue
3938  * invalidates the relaxed bound
3939  */
3940  assert(bdchginfo == conflictFirstCand(conflict));
3941  relaxedbd = SCIPbdchginfoGetRelaxedBound(bdchginfo);
3942  bdchginfo = conflictRemoveCand(conflict);
3943  nextbdchginfo = conflictFirstCand(conflict);
3944  bdchgdepth = SCIPbdchginfoGetDepth(bdchginfo);
3945  assert(bdchginfo != NULL);
3946  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
3947  assert(nextbdchginfo == NULL || SCIPbdchginfoGetDepth(bdchginfo) >= SCIPbdchginfoGetDepth(nextbdchginfo)
3948  || forceresolve);
3949  assert(bdchgdepth <= firstuipdepth);
3950 
3951  /* bound changes that are higher in the tree than the valid depth of the conflict can be ignored;
3952  * multiple insertions of the same bound change can be ignored
3953  */
3954  if( bdchgdepth > validdepth && bdchginfo != nextbdchginfo )
3955  {
3956  SCIP_VAR* actvar;
3957  SCIP_Bool resolved;
3958 
3959  actvar = SCIPbdchginfoGetVar(bdchginfo);
3960  assert(actvar != NULL);
3961  assert(SCIPvarIsActive(actvar));
3962 
3963  /* check if we have to resolve the bound change in this depth level
3964  * - the starting uip has to be resolved
3965  * - a bound change should be resolved, if it is in the fuip's depth level and not the
3966  * next uip (i.e., if it is not the last bound change in the fuip's depth level)
3967  * - a forced bound change must be resolved in any case
3968  */
3969  resolved = FALSE;
3970  if( bdchginfo == uip
3971  || (bdchgdepth == firstuipdepth
3972  && nextbdchginfo != NULL
3973  && SCIPbdchginfoGetDepth(nextbdchginfo) == bdchgdepth)
3974  || forceresolve )
3975  {
3976  SCIP_CALL( conflictResolveBound(conflict, set, bdchginfo, relaxedbd, validdepth, &resolved) );
3977  }
3978 
3979  if( resolved )
3980  nresolutions++;
3981  else if( forceresolve )
3982  {
3983  /* variable cannot enter the conflict clause: we have to make the conflict clause local, s.t.
3984  * the unresolved bound change is active in the whole sub tree of the conflict clause
3985  */
3986  assert(bdchgdepth >= validdepth);
3987  validdepth = bdchgdepth;
3988 
3989  SCIPsetDebugMsg(set, "couldn't resolve forced bound change on <%s> -> new valid depth: %d\n",
3990  SCIPvarGetName(actvar), validdepth);
3991  }
3992  else if( bdchginfo != uip )
3993  {
3994  assert(conflict->conflictset != NULL);
3995  assert(conflict->conflictset->nbdchginfos >= 1); /* starting UIP is already member of the conflict set */
3996 
3997  /* if this is the first variable of the conflict set besides the current starting UIP, it is the next
3998  * UIP (or the first unresolvable bound change)
3999  */
4000  if( bdchgdepth == firstuipdepth && conflict->conflictset->nbdchginfos == 1 )
4001  {
4002  assert(nextuip == NULL);
4003  nextuip = bdchginfo;
4004  }
4005 
4006  /* put bound change into the conflict set */
4007  SCIP_CALL( conflictAddConflictBound(conflict, blkmem, set, bdchginfo, relaxedbd) );
4008  assert(conflict->conflictset->nbdchginfos >= 2);
4009  }
4010  else
4011  assert(conflictFirstCand(conflict) == NULL); /* the starting UIP was not resolved */
4012  }
4013 
4014  /* get next conflicting bound from the conflict candidate queue (this does not need to be nextbdchginfo, because
4015  * due to resolving the bound changes, a variable could be added to the queue which must be
4016  * resolved before nextbdchginfo)
4017  */
4018  bdchginfo = conflictFirstCand(conflict);
4019  }
4020  assert(nextuip != uip);
4021 
4022  /* if only one propagation was resolved, the reconvergence constraint is already member of the constraint set
4023  * (it is exactly the constraint that produced the propagation)
4024  */
4025  if( nextuip != NULL && nresolutions >= 2 && bdchginfo == NULL && validdepth <= maxvaliddepth )
4026  {
4027  int nlits;
4028  SCIP_Bool success;
4029 
4030  assert(SCIPbdchginfoGetDepth(nextuip) == SCIPbdchginfoGetDepth(uip));
4031 
4032  /* check conflict graph frontier on debugging solution */
4033  SCIP_CALL( SCIPdebugCheckConflictFrontier(blkmem, set, tree->path[validdepth],
4034  bdchginfo, conflict->conflictset->bdchginfos, conflict->conflictset->relaxedbds,
4035  conflict->conflictset->nbdchginfos, conflict->bdchgqueue, conflict->forcedbdchgqueue) ); /*lint !e506 !e774*/
4036 
4037  SCIPsetDebugMsg(set, "creating reconvergence constraint from UIP <%s> to UIP <%s> in depth %d with %d literals after %d resolutions\n",
4039  SCIPbdchginfoGetDepth(uip), conflict->conflictset->nbdchginfos, nresolutions);
4040 
4041  /* call the conflict handlers to create a conflict set */
4042  SCIP_CALL( conflictAddConflictset(conflict, blkmem, set, stat, tree, validdepth, diving, FALSE,
4043  &success, &nlits) );
4044  if( success )
4045  {
4046  (*nreconvconss)++;
4047  (*nreconvliterals) += nlits;
4048  }
4049  }
4050 
4051  /* clear the conflict candidate queue and the conflict set (to make sure, oppositeuip is not referenced anymore) */
4052  conflictClear(conflict);
4053 
4054  uip = nextuip;
4055  }
4056 
4057  conflict->conflictset->conflicttype = conftype;
4058  conflict->conflictset->usescutoffbound = usescutoffbound;
4059 
4060 
4061  return SCIP_OKAY;
4062 }
4063 
4064 /** analyzes conflicting bound changes that were added with calls to SCIPconflictAddBound() and
4065  * SCIPconflictAddRelaxedBound(), and on success, calls the conflict handlers to create a conflict constraint out of
4066  * the resulting conflict set; afterwards the conflict queue and the conflict set is cleared
4067  */
4068 static
4070  SCIP_CONFLICT* conflict, /**< conflict analysis data */
4071  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
4072  SCIP_SET* set, /**< global SCIP settings */
4073  SCIP_STAT* stat, /**< problem statistics */
4074  SCIP_PROB* prob, /**< problem data */
4075  SCIP_TREE* tree, /**< branch and bound tree */
4076  SCIP_Bool diving, /**< are we in strong branching or diving mode? */
4077  int validdepth, /**< minimal depth level at which the initial conflict set is valid */
4078  SCIP_Bool mustresolve, /**< should the conflict set only be used, if a resolution was applied? */
4079  int* nconss, /**< pointer to store the number of generated conflict constraints */
4080  int* nliterals, /**< pointer to store the number of literals in generated conflict constraints */
4081  int* nreconvconss, /**< pointer to store the number of generated reconvergence constraints */
4082  int* nreconvliterals /**< pointer to store the number of literals generated reconvergence constraints */
4083  )
4084 {
4085  SCIP_BDCHGINFO* bdchginfo;
4086  SCIP_BDCHGINFO** firstuips;
4087  int nfirstuips;
4088  int focusdepth;
4089  int currentdepth;
4090  int maxvaliddepth;
4091  int resolvedepth;
4092  int nresolutions;
4093  int lastconsnresolutions;
4094  int lastconsresoldepth;
4095 
4096  assert(conflict != NULL);
4097  assert(conflict->conflictset != NULL);
4098  assert(conflict->conflictset->nbdchginfos >= 0);
4099  assert(set != NULL);
4100  assert(stat != NULL);
4101  assert(0 <= validdepth && validdepth <= SCIPtreeGetCurrentDepth(tree));
4102  assert(nconss != NULL);
4103  assert(nliterals != NULL);
4104  assert(nreconvconss != NULL);
4105  assert(nreconvliterals != NULL);
4106 
4107  focusdepth = SCIPtreeGetFocusDepth(tree);
4108  currentdepth = SCIPtreeGetCurrentDepth(tree);
4109  assert(currentdepth == tree->pathlen-1);
4110  assert(focusdepth <= currentdepth);
4111 
4112  resolvedepth = ((set->conf_fuiplevels >= 0 && set->conf_fuiplevels <= currentdepth)
4113  ? currentdepth - set->conf_fuiplevels + 1 : 0);
4114  assert(0 <= resolvedepth && resolvedepth <= currentdepth + 1);
4115 
4116  /* if we must resolve at least one bound change, find the first UIP at least in the last depth level */
4117  if( mustresolve )
4118  resolvedepth = MIN(resolvedepth, currentdepth);
4119 
4120  SCIPsetDebugMsg(set, "analyzing conflict with %d+%d conflict candidates and starting conflict set of size %d in depth %d (resolvedepth=%d)\n",
4122  conflict->conflictset->nbdchginfos, currentdepth, resolvedepth);
4123 
4124  *nconss = 0;
4125  *nliterals = 0;
4126  *nreconvconss = 0;
4127  *nreconvliterals = 0;
4128 
4129  /* check, whether local conflicts are allowed; however, don't generate conflict constraints that are only valid in the
4130  * probing path and not in the problem tree (i.e. that exceed the focusdepth)
4131  */
4132  maxvaliddepth = (set->conf_allowlocal ? MIN(currentdepth-1, focusdepth) : 0);
4133  if( validdepth > maxvaliddepth )
4134  return SCIP_OKAY;
4135 
4136  /* allocate temporary memory for storing first UIPs (in each depth level, at most two bound changes can be flagged
4137  * as UIP, namely a binary and a non-binary bound change)
4138  */
4139  SCIP_CALL( SCIPsetAllocBufferArray(set, &firstuips, 2*(currentdepth+1)) ); /*lint !e647*/
4140 
4141  /* process all bound changes in the conflict candidate queue */
4142  nresolutions = 0;
4143  lastconsnresolutions = (mustresolve ? 0 : -1);
4144  lastconsresoldepth = (mustresolve ? currentdepth : INT_MAX);
4145  bdchginfo = conflictFirstCand(conflict);
4146  nfirstuips = 0;
4147 
4148  /* check if the initial reason on debugging solution */
4149  SCIP_CALL( SCIPdebugCheckConflictFrontier(blkmem, set, tree->path[validdepth],
4150  NULL, conflict->conflictset->bdchginfos, conflict->conflictset->relaxedbds, conflict->conflictset->nbdchginfos,
4151  conflict->bdchgqueue, conflict->forcedbdchgqueue) ); /*lint !e506 !e774*/
4152 
4153  while( bdchginfo != NULL && validdepth <= maxvaliddepth )
4154  {
4155  SCIP_BDCHGINFO* nextbdchginfo;
4156  SCIP_Real relaxedbd;
4157  SCIP_Bool forceresolve;
4158  int bdchgdepth;
4159 
4160  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
4161 
4162  /* check if the next bound change must be resolved in every case */
4163  forceresolve = (SCIPpqueueNElems(conflict->forcedbdchgqueue) > 0);
4164 
4165  /* resolve next bound change in queue */
4166  bdchgdepth = SCIPbdchginfoGetDepth(bdchginfo);
4167  assert(0 <= bdchgdepth && bdchgdepth <= currentdepth);
4168  assert(SCIPvarIsActive(SCIPbdchginfoGetVar(bdchginfo)));
4169  assert(bdchgdepth < tree->pathlen);
4170  assert(tree->path[bdchgdepth] != NULL);
4171  assert(tree->path[bdchgdepth]->domchg != NULL);
4172  assert(SCIPbdchginfoGetPos(bdchginfo) < (int)tree->path[bdchgdepth]->domchg->domchgbound.nboundchgs);
4173  assert(tree->path[bdchgdepth]->domchg->domchgbound.boundchgs[SCIPbdchginfoGetPos(bdchginfo)].var
4174  == SCIPbdchginfoGetVar(bdchginfo));
4175  assert(tree->path[bdchgdepth]->domchg->domchgbound.boundchgs[SCIPbdchginfoGetPos(bdchginfo)].newbound
4176  == SCIPbdchginfoGetNewbound(bdchginfo)
4179  == SCIPbdchginfoGetNewbound(bdchginfo)); /*lint !e777*/
4180  assert((SCIP_BOUNDTYPE)tree->path[bdchgdepth]->domchg->domchgbound.boundchgs[SCIPbdchginfoGetPos(bdchginfo)].boundtype
4181  == SCIPbdchginfoGetBoundtype(bdchginfo));
4182 
4183  /* create intermediate conflict constraint */
4184  assert(nresolutions >= lastconsnresolutions);
4185  if( !forceresolve )
4186  {
4187  if( nresolutions == lastconsnresolutions )
4188  lastconsresoldepth = bdchgdepth; /* all intermediate depth levels consisted of only unresolved bound changes */
4189  else if( bdchgdepth < lastconsresoldepth && (set->conf_interconss == -1 || *nconss < set->conf_interconss) )
4190  {
4191  int nlits;
4192  SCIP_Bool success;
4193 
4194  /* call the conflict handlers to create a conflict set */
4195  SCIPsetDebugMsg(set, "creating intermediate conflictset after %d resolutions up to depth %d (valid at depth %d): %d conflict bounds, %d bounds in queue\n",
4196  nresolutions, bdchgdepth, validdepth, conflict->conflictset->nbdchginfos,
4197  SCIPpqueueNElems(conflict->bdchgqueue));
4198 
4199  SCIP_CALL( conflictAddConflictset(conflict, blkmem, set, stat, tree, validdepth, diving, TRUE,
4200  &success, &nlits) );
4201  lastconsnresolutions = nresolutions;
4202  lastconsresoldepth = bdchgdepth;
4203  if( success )
4204  {
4205  (*nconss)++;
4206  (*nliterals) += nlits;
4207  }
4208  }
4209  }
4210 
4211  /* remove currently processed candidate and get next conflicting bound from the conflict candidate queue before
4212  * we remove the candidate we have to collect the relaxed bound since removing the candidate from the queue
4213  * invalidates the relaxed bound
4214  */
4215  assert(bdchginfo == conflictFirstCand(conflict));
4216  relaxedbd = SCIPbdchginfoGetRelaxedBound(bdchginfo);
4217  bdchginfo = conflictRemoveCand(conflict);
4218  nextbdchginfo = conflictFirstCand(conflict);
4219  assert(bdchginfo != NULL);
4220  assert(!SCIPbdchginfoIsRedundant(bdchginfo));
4221  assert(nextbdchginfo == NULL || SCIPbdchginfoGetDepth(bdchginfo) >= SCIPbdchginfoGetDepth(nextbdchginfo)
4222  || forceresolve);
4223 
4224  /* we don't need to resolve bound changes that are already active in the valid depth of the current conflict set,
4225  * because the conflict set can only be added locally at the valid depth, and all bound changes applied in this
4226  * depth or earlier can be removed from the conflict constraint, since they are already applied in the constraint's
4227  * subtree;
4228  * if the next bound change on the remaining queue is equal to the current bound change,
4229  * this is a multiple insertion in the conflict candidate queue and we can ignore the current
4230  * bound change
4231  */
4232  if( bdchgdepth > validdepth && bdchginfo != nextbdchginfo )
4233  {
4234  SCIP_VAR* actvar;
4235  SCIP_Bool resolved;
4236 
4237  actvar = SCIPbdchginfoGetVar(bdchginfo);
4238  assert(actvar != NULL);
4239  assert(SCIPvarIsActive(actvar));
4240 
4241  /* check if we want to resolve the bound change in this depth level
4242  * - bound changes should be resolved, if
4243  * (i) we must apply at least one resolution and didn't resolve a bound change yet, or
4244  * (ii) their depth level is at least equal to the minimal resolving depth, and
4245  * they are not the last remaining conflicting bound change in their depth level
4246  * (iii) the bound change resolving is forced (i.e., the forced queue was non-empty)
4247  */
4248  resolved = FALSE;
4249  if( (mustresolve && nresolutions == 0)
4250  || (bdchgdepth >= resolvedepth
4251  && nextbdchginfo != NULL
4252  && SCIPbdchginfoGetDepth(nextbdchginfo) == bdchgdepth)
4253  || forceresolve )
4254  {
4255  SCIP_CALL( conflictResolveBound(conflict, set, bdchginfo, relaxedbd, validdepth, &resolved) );
4256  }
4257 
4258  if( resolved )
4259  nresolutions++;
4260  else if( forceresolve )
4261  {
4262  /* variable cannot enter the conflict clause: we have to make the conflict clause local, s.t.
4263  * the unresolved bound change is active in the whole sub tree of the conflict clause
4264  */
4265  assert(bdchgdepth >= validdepth);
4266  validdepth = bdchgdepth;
4267 
4268  SCIPsetDebugMsg(set, "couldn't resolve forced bound change on <%s> -> new valid depth: %d\n",
4269  SCIPvarGetName(actvar), validdepth);
4270  }
4271  else
4272  {
4273  /* if this is a UIP (the last bound change in its depth level), it can be used to generate a
4274  * UIP reconvergence constraint
4275  */
4276  if( nextbdchginfo == NULL || SCIPbdchginfoGetDepth(nextbdchginfo) != bdchgdepth )
4277  {
4278  assert(nfirstuips < 2*(currentdepth+1));
4279  firstuips[nfirstuips] = bdchginfo;
4280  nfirstuips++;
4281  }
4282 
4283  /* put variable into the conflict set, using the literal that is currently fixed to FALSE */
4284  SCIP_CALL( conflictAddConflictBound(conflict, blkmem, set, bdchginfo, relaxedbd) );
4285  }
4286  }
4287 
4288  /* check conflict graph frontier on debugging solution */
4289  SCIP_CALL( SCIPdebugCheckConflictFrontier(blkmem, set, tree->path[validdepth],
4290  bdchginfo, conflict->conflictset->bdchginfos, conflict->conflictset->relaxedbds, conflict->conflictset->nbdchginfos,
4291  conflict->bdchgqueue, conflict->forcedbdchgqueue) ); /*lint !e506 !e774*/
4292 
4293  /* get next conflicting bound from the conflict candidate queue (this needs not to be nextbdchginfo, because
4294  * due to resolving the bound changes, a bound change could be added to the queue which must be
4295  * resolved before nextbdchginfo)
4296  */
4297  bdchginfo = conflictFirstCand(conflict);
4298  }
4299 
4300  /* check, if a valid conflict set was found */
4301  if( bdchginfo == NULL
4302  && nresolutions > lastconsnresolutions
4303  && validdepth <= maxvaliddepth
4304  && (!mustresolve || nresolutions > 0 || conflict->conflictset->nbdchginfos == 0)
4305  && SCIPpqueueNElems(conflict->forcedbdchgqueue) == 0 )
4306  {
4307  int nlits;
4308  SCIP_Bool success;
4309 
4310  /* call the conflict handlers to create a conflict set */
4311  SCIP_CALL( conflictAddConflictset(conflict, blkmem, set, stat, tree, validdepth, diving, TRUE, &success, &nlits) );
4312  if( success )
4313  {
4314  (*nconss)++;
4315  (*nliterals) += nlits;
4316  }
4317  }
4318 
4319  /* produce reconvergence constraints defined by succeeding UIP's of the last depth level */
4320  if( set->conf_reconvlevels != 0 && validdepth <= maxvaliddepth )
4321  {
4322  int reconvlevels;
4323  int i;
4324 
4325  reconvlevels = (set->conf_reconvlevels == -1 ? INT_MAX : set->conf_reconvlevels);
4326  for( i = 0; i < nfirstuips; ++i )
4327  {
4328  if( SCIPbdchginfoHasInferenceReason(firstuips[i])
4329  && currentdepth - SCIPbdchginfoGetDepth(firstuips[i]) < reconvlevels )
4330  {
4331  SCIP_CALL( conflictCreateReconvergenceConss(conflict, blkmem, set, stat, prob, tree, diving,
4332  validdepth, firstuips[i], nreconvconss, nreconvliterals) );
4333  }
4334  }
4335  }
4336 
4337  /* free the temporary memory */
4338  SCIPsetFreeBufferArray(set, &firstuips);
4339 
4340  /* clear the conflict candidate queue and the conflict set */
4341  conflictClear(conflict);
4342 
4343  return SCIP_OKAY;
4344 }
4345 
4346 /** analyzes conflicting bound changes that were added with calls to SCIPconflictAddBound(), and on success, calls the
4347  * conflict handlers to create a conflict constraint out of the resulting conflict set;
4348  * updates statistics for propagation conflict analysis
4349  */
4351  SCIP_CONFLICT* conflict, /**< conflict analysis data */
4352  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
4353  SCIP_SET* set, /**< global SCIP settings */
4354  SCIP_STAT* stat, /**< problem statistics */
4355  SCIP_PROB* prob, /**< problem data */
4356  SCIP_TREE* tree, /**< branch and bound tree */
4357  int validdepth, /**< minimal depth level at which the initial conflict set is valid */
4358  SCIP_Bool* success /**< pointer to store whether a conflict constraint was created, or NULL */
4359  )
4360 {
4361  int nconss;
4362  int nliterals;
4363  int nreconvconss;
4364  int nreconvliterals;
4365 
4366  assert(conflict != NULL);
4367  assert(conflict->conflictset != NULL);
4368  assert(set != NULL);
4369  assert(prob != NULL);
4370 
4371  if( success != NULL )
4372  *success = FALSE;
4373 
4374  /* check if the conflict analysis is applicable */
4375  if( !SCIPconflictApplicable(set) )
4376  return SCIP_OKAY;
4377 
4378  /* check, if the conflict set will get too large with high probability */
4379  if( conflict->conflictset->nbdchginfos + SCIPpqueueNElems(conflict->bdchgqueue)
4380  + SCIPpqueueNElems(conflict->forcedbdchgqueue) >= 2*conflictCalcMaxsize(set, prob) )
4381  return SCIP_OKAY;
4382 
4383  SCIPsetDebugMsg(set, "analyzing conflict after infeasible propagation in depth %d\n", SCIPtreeGetCurrentDepth(tree));
4384 
4385  /* start timing */
4386  SCIPclockStart(conflict->propanalyzetime, set);
4387 
4388  conflict->npropcalls++;
4389 
4390  /* analyze the conflict set, and create a conflict constraint on success */
4391  SCIP_CALL( conflictAnalyze(conflict, blkmem, set, stat, prob, tree, FALSE, validdepth, TRUE,
4392  &nconss, &nliterals, &nreconvconss, &nreconvliterals) );
4393  conflict->npropsuccess += (nconss > 0 ? 1 : 0);
4394  conflict->npropconfconss += nconss;
4395  conflict->npropconfliterals += nliterals;
4396  conflict->npropreconvconss += nreconvconss;
4397  conflict->npropreconvliterals += nreconvliterals;
4398  if( success != NULL )
4399  *success = (nconss > 0);
4400 
4401  /* stop timing */
4402  SCIPclockStop(conflict->propanalyzetime, set);
4403 
4404  return SCIP_OKAY;
4405 }
4406 
4407 /** gets time in seconds used for preprocessing global conflict constraint before appliance */
4409  SCIP_CONFLICT* conflict /**< conflict analysis data */
4410  )
4411 {
4412  assert(conflict != NULL);
4413 
4414  return SCIPclockGetTime(conflict->dIBclock);
4415 }
4416 
4417 /** gets time in seconds used for analyzing propagation conflicts */
4419  SCIP_CONFLICT* conflict /**< conflict analysis data */
4420  )
4421 {
4422  assert(conflict != NULL);
4423 
4424  return SCIPclockGetTime(conflict->propanalyzetime);
4425 }
4426 
4427 /** gets number of calls to propagation conflict analysis */
4429  SCIP_CONFLICT* conflict /**< conflict analysis data */
4430  )
4431 {
4432  assert(conflict != NULL);
4433 
4434  return conflict->npropcalls;
4435 }
4436 
4437 /** gets number of calls to propagation conflict analysis that yield at least one conflict constraint */
4439  SCIP_CONFLICT* conflict /**< conflict analysis data */
4440  )
4441 {
4442  assert(conflict != NULL);
4443 
4444  return conflict->npropsuccess;
4445 }
4446 
4447 /** gets number of conflict constraints detected in propagation conflict analysis */
4449  SCIP_CONFLICT* conflict /**< conflict analysis data */
4450  )
4451 {
4452  assert(conflict != NULL);
4453 
4454  return conflict->npropconfconss;
4455 }
4456 
4457 /** gets total number of literals in conflict constraints created in propagation conflict analysis */
4459  SCIP_CONFLICT* conflict /**< conflict analysis data */
4460  )
4461 {
4462  assert(conflict != NULL);
4463 
4464  return conflict->npropconfliterals;
4465 }
4466 
4467 /** gets number of reconvergence constraints detected in propagation conflict analysis */
4469  SCIP_CONFLICT* conflict /**< conflict analysis data */
4470  )
4471 {
4472  assert(conflict != NULL);
4473 
4474  return conflict->npropreconvconss;
4475 }
4476 
4477 /** gets total number of literals in reconvergence constraints created in propagation conflict analysis */
4479  SCIP_CONFLICT* conflict /**< conflict analysis data */
4480  )
4481 {
4482  assert(conflict != NULL);
4483 
4484  return conflict->npropreconvliterals;
4485 }
4486 
4487 
4488 
4489 
4490 /*
4491  * Infeasible LP Conflict Analysis
4492  */
4493 
4494 /** ensures, that side change arrays can store at least num entries */
4495 static
4497  SCIP_SET* set, /**< global SCIP settings */
4498  int** sidechginds, /**< pointer to side change index array */
4499  SCIP_Real** sidechgoldlhss, /**< pointer to side change old left hand sides array */
4500  SCIP_Real** sidechgoldrhss, /**< pointer to side change old right hand sides array */
4501  SCIP_Real** sidechgnewlhss, /**< pointer to side change new left hand sides array */
4502  SCIP_Real** sidechgnewrhss, /**< pointer to side change new right hand sides array */
4503  int* sidechgssize, /**< pointer to size of side change arrays */
4504  int num /**< minimal number of entries to be able to store in side change arrays */
4505  )
4506 {
4507  assert(sidechginds != NULL);
4508  assert(sidechgoldlhss != NULL);
4509  assert(sidechgoldrhss != NULL);
4510  assert(sidechgnewlhss != NULL);
4511  assert(sidechgnewrhss != NULL);
4512  assert(sidechgssize != NULL);
4513 
4514  if( num > *sidechgssize )
4515  {
4516  int newsize;
4517 
4518  newsize = SCIPsetCalcMemGrowSize(set, num);
4519  SCIP_CALL( SCIPsetReallocBufferArray(set, sidechginds, newsize) );
4520  SCIP_CALL( SCIPsetReallocBufferArray(set, sidechgoldlhss, newsize) );
4521  SCIP_CALL( SCIPsetReallocBufferArray(set, sidechgoldrhss, newsize) );
4522  SCIP_CALL( SCIPsetReallocBufferArray(set, sidechgnewlhss, newsize) );
4523  SCIP_CALL( SCIPsetReallocBufferArray(set, sidechgnewrhss, newsize) );
4524  *sidechgssize = newsize;
4525  }
4526  assert(num <= *sidechgssize);
4527 
4528  return SCIP_OKAY;
4529 }
4530 
4531 /** adds removal of row's side to side change arrays; finite sides are only replaced by near infinite sides, such
4532  * that the row's sense in the LP solver is not changed
4533  */
4534 static
4536  SCIP_SET* set, /**< global SCIP settings */
4537  SCIP_ROW* row, /**< LP row to change the sides for */
4538  SCIP_Real lpiinfinity, /**< value treated as infinity in LP solver */
4539  int** sidechginds, /**< pointer to side change index array */
4540  SCIP_Real** sidechgoldlhss, /**< pointer to side change old left hand sides array */
4541  SCIP_Real** sidechgoldrhss, /**< pointer to side change old right hand sides array */
4542  SCIP_Real** sidechgnewlhss, /**< pointer to side change new left hand sides array */
4543  SCIP_Real** sidechgnewrhss, /**< pointer to side change new right hand sides array */
4544  int* sidechgssize, /**< pointer to size of side change arrays */
4545  int* nsidechgs /**< pointer to number of used slots in side change arrays */
4546  )
4547 {
4548  SCIP_Real lhs;
4549  SCIP_Real rhs;
4550  SCIP_Real constant;
4551 
4552  assert(sidechginds != NULL);
4553  assert(sidechgoldlhss != NULL);
4554  assert(sidechgoldrhss != NULL);
4555  assert(sidechgnewlhss != NULL);
4556  assert(sidechgnewrhss != NULL);
4557  assert(sidechgssize != NULL);
4558  assert(nsidechgs != NULL);
4559 
4560  lhs = SCIProwGetLhs(row);
4561  rhs = SCIProwGetRhs(row);
4562  constant = SCIProwGetConstant(row);
4563  assert(!SCIPsetIsInfinity(set, -lhs) || !SCIPsetIsInfinity(set, rhs));
4564 
4565  /* get memory to store additional side change */
4566  SCIP_CALL( ensureSidechgsSize(set, sidechginds, sidechgoldlhss, sidechgoldrhss, sidechgnewlhss, sidechgnewrhss,
4567  sidechgssize, (*nsidechgs)+1) );
4568  assert(*nsidechgs < *sidechgssize);
4569  assert(*sidechginds != NULL);
4570  assert(*sidechgoldlhss != NULL);
4571  assert(*sidechgoldrhss != NULL);
4572  assert(*sidechgnewlhss != NULL);
4573  assert(*sidechgnewrhss != NULL);
4574 
4575  /* store side change */
4576  (*sidechginds)[*nsidechgs] = SCIProwGetLPPos(row);
4577  if( SCIPsetIsInfinity(set, -lhs) )
4578  {
4579  (*sidechgoldlhss)[*nsidechgs] = -lpiinfinity;
4580  (*sidechgnewlhss)[*nsidechgs] = -lpiinfinity;
4581  }
4582  else
4583  {
4584  (*sidechgoldlhss)[*nsidechgs] = lhs - constant;
4585  (*sidechgnewlhss)[*nsidechgs] = -lpiinfinity;
4586  }
4587  if( SCIPsetIsInfinity(set, rhs) )
4588  {
4589  (*sidechgoldrhss)[*nsidechgs] = lpiinfinity;
4590  (*sidechgnewrhss)[*nsidechgs] = lpiinfinity;
4591  }
4592  else
4593  {
4594  (*sidechgoldrhss)[*nsidechgs] = rhs - constant;
4595  (*sidechgnewrhss)[*nsidechgs] = lpiinfinity;
4596  }
4597  (*nsidechgs)++;
4598 
4599  return SCIP_OKAY;
4600 }
4601 
4602 /** inserts variable's new bounds into bound change arrays */
4603 static
4605  SCIP_SET* set, /**< global SCIP settings */
4606  SCIP_VAR* var, /**< variable to change the LP bounds for */
4607  SCIP_Real newlb, /**< new lower bound */
4608  SCIP_Real newub, /**< new upper bound */
4609  SCIP_LPBDCHGS* oldlpbdchgs, /**< old LP bound changes used for reset the LP bound change */
4610  SCIP_LPBDCHGS* relaxedlpbdchgs, /**< relaxed LP bound changes used for reset the LP bound change */
4611  SCIP_LPI* lpi /**< pointer to LPi to access infinity of LP solver; necessary to set correct value */
4612  )
4613 {
4614  assert(newlb <= newub);
4615  assert(oldlpbdchgs != NULL);
4616  assert(relaxedlpbdchgs != NULL);
4617 
4619  {
4620  SCIP_COL* col;
4621  int idx;
4622  int c;
4623 
4624  col = SCIPvarGetCol(var);
4625  c = SCIPcolGetLPPos(col);
4626 
4627  if( c >= 0 )
4628  {
4629  /* store old bound change for resetting the LP later */
4630  if( !oldlpbdchgs->usedcols[c] )
4631  {
4632  idx = oldlpbdchgs->nbdchgs;
4633  oldlpbdchgs->usedcols[c] = TRUE;
4634  oldlpbdchgs->bdchgcolinds[c] = idx;
4635  oldlpbdchgs->nbdchgs++;
4636 
4637  oldlpbdchgs->bdchginds[idx] = c;
4638  oldlpbdchgs->bdchglbs[idx] = SCIPvarGetLbLP(var, set);
4639  oldlpbdchgs->bdchgubs[idx] = SCIPvarGetUbLP(var, set);
4640  }
4641  assert(oldlpbdchgs->bdchginds[oldlpbdchgs->bdchgcolinds[c]] == c);
4642  assert((SCIPlpiIsInfinity(lpi, -oldlpbdchgs->bdchglbs[oldlpbdchgs->bdchgcolinds[c]]) && SCIPsetIsInfinity(set, -SCIPvarGetLbLP(var, set))) ||
4643  SCIPsetIsEQ(set, oldlpbdchgs->bdchglbs[oldlpbdchgs->bdchgcolinds[c]], SCIPvarGetLbLP(var, set)));
4644  assert((SCIPlpiIsInfinity(lpi, oldlpbdchgs->bdchgubs[oldlpbdchgs->bdchgcolinds[c]]) && SCIPsetIsInfinity(set, SCIPvarGetUbLP(var, set))) ||
4645  SCIPsetIsEQ(set, oldlpbdchgs->bdchgubs[oldlpbdchgs->bdchgcolinds[c]], SCIPvarGetUbLP(var, set)));
4646 
4647  /* store bound change for conflict analysis */
4648  if( !relaxedlpbdchgs->usedcols[c] )
4649  {
4650  idx = relaxedlpbdchgs->nbdchgs;
4651  relaxedlpbdchgs->usedcols[c] = TRUE;
4652  relaxedlpbdchgs->bdchgcolinds[c] = idx;
4653  relaxedlpbdchgs->nbdchgs++;
4654 
4655  /* remember the positive for later further bound widenings */
4656  relaxedlpbdchgs->bdchginds[idx] = c;
4657  }
4658  else
4659  {
4660  idx = relaxedlpbdchgs->bdchgcolinds[c];
4661  assert(relaxedlpbdchgs->bdchginds[idx] == c);
4662 
4663  /* the new bound should be the same or more relaxed */
4664  assert(relaxedlpbdchgs->bdchglbs[idx] >= newlb ||
4665  (SCIPlpiIsInfinity(lpi, -relaxedlpbdchgs->bdchglbs[idx]) && SCIPsetIsInfinity(set, -newlb)));
4666  assert(relaxedlpbdchgs->bdchgubs[idx] <= newub ||
4667  (SCIPlpiIsInfinity(lpi, relaxedlpbdchgs->bdchgubs[idx]) && SCIPsetIsInfinity(set, newub)));
4668  }
4669 
4670  /* set the new bounds for the LP with the correct infinity value */
4671  relaxedlpbdchgs->bdchglbs[idx] = SCIPsetIsInfinity(set, -newlb) ? -SCIPlpiInfinity(lpi) : newlb;
4672  relaxedlpbdchgs->bdchgubs[idx] = SCIPsetIsInfinity(set, newub) ? SCIPlpiInfinity(lpi) : newub;
4673  if( SCIPsetIsInfinity(set, -oldlpbdchgs->bdchglbs[idx]) )
4674  oldlpbdchgs->bdchglbs[idx] = -SCIPlpiInfinity(lpi);
4675  if( SCIPsetIsInfinity(set, oldlpbdchgs->bdchgubs[idx]) )
4676  oldlpbdchgs->bdchgubs[idx] = SCIPlpiInfinity(lpi);
4677  }
4678  }
4679 
4680  return SCIP_OKAY;
4681 }
4682 
4683 /** ensures, that candidate array can store at least num entries */
4684 static
4686  SCIP_SET* set, /**< global SCIP settings */
4687  SCIP_VAR*** cands, /**< pointer to candidate array */
4688  SCIP_Real** candscores, /**< pointer to candidate score array */
4689  SCIP_Real** newbounds, /**< pointer to candidate new bounds array */
4690  SCIP_Real** proofactdeltas, /**< pointer to candidate proof delta array */
4691  int* candssize, /**< pointer to size of array */
4692  int num /**< minimal number of candidates to store in array */
4693  )
4694 {
4695  assert(cands != NULL);
4696  assert(candssize != NULL);
4697 
4698  if( num > *candssize )
4699  {
4700  int newsize;
4701 
4702  newsize = SCIPsetCalcMemGrowSize(set, num);
4703  SCIP_CALL( SCIPsetReallocBufferArray(set, cands, newsize) );
4704  SCIP_CALL( SCIPsetReallocBufferArray(set, candscores, newsize) );
4705  SCIP_CALL( SCIPsetReallocBufferArray(set, newbounds, newsize) );
4706  SCIP_CALL( SCIPsetReallocBufferArray(set, proofactdeltas, newsize) );
4707  *candssize = newsize;
4708  }
4709  assert(num <= *candssize);
4710 
4711  return SCIP_OKAY;
4712 }
4713 
4714 /** adds variable to candidate list, if the current best bound corresponding to the proof coefficient is local;
4715  * returns the array position in the candidate list, where the new candidate was inserted, or -1 if the
4716  * variable can relaxed to global bounds immediately without increasing the proof's activity;
4717  * the candidates are sorted with respect to the following two criteria:
4718  * - prefer bound changes that have been applied deeper in the tree, to get a more global conflict
4719  * - prefer variables with small Farkas coefficient to get rid of as many bound changes as possible
4720  */
4721 static
4723  SCIP_SET* set, /**< global SCIP settings */
4724  int currentdepth, /**< current depth in the tree */
4725  SCIP_VAR* var, /**< variable to add to candidate array */
4726  int lbchginfopos, /**< positions of currently active lower bound change information in variable's array */
4727  int ubchginfopos, /**< positions of currently active upper bound change information in variable's array */
4728  SCIP_Real proofcoef, /**< coefficient of variable in infeasibility/bound proof */
4729  SCIP_Real prooflhs, /**< left hand side of infeasibility/bound proof */
4730  SCIP_Real proofact, /**< activity of infeasibility/bound proof row */
4731  SCIP_VAR*** cands, /**< pointer to candidate array for undoing bound changes */
4732  SCIP_Real** candscores, /**< pointer to candidate score array for undoing bound changes */
4733  SCIP_Real** newbounds, /**< pointer to candidate new bounds array for undoing bound changes */
4734  SCIP_Real** proofactdeltas, /**< pointer to proof activity increase array for undoing bound changes */
4735  int* candssize, /**< pointer to size of cands arrays */
4736  int* ncands, /**< pointer to count number of candidates in bound change list */
4737  int firstcand /**< position of first unprocessed bound change candidate */
4738  )
4739 {
4740  SCIP_Real oldbound;
4741  SCIP_Real newbound;
4742  SCIP_Real proofactdelta;
4743  SCIP_Real score;
4744  int depth;
4745  int i;
4746  SCIP_Bool resolvable;
4747 
4748  assert(set != NULL);
4749  assert(var != NULL);
4750  assert(-1 <= lbchginfopos && lbchginfopos <= var->nlbchginfos);
4751  assert(-1 <= ubchginfopos && ubchginfopos <= var->nubchginfos);
4752  assert(!SCIPsetIsZero(set, proofcoef));
4753  assert(SCIPsetIsGT(set, prooflhs, proofact));
4754  assert(cands != NULL);
4755  assert(candscores != NULL);
4756  assert(newbounds != NULL);
4757  assert(proofactdeltas != NULL);
4758  assert(candssize != NULL);
4759  assert(ncands != NULL);
4760  assert(*ncands <= *candssize);
4761  assert(0 <= firstcand && firstcand <= *ncands);
4762 
4763  /* in the infeasibility or dual bound proof, the variable's bound is chosen to maximize the proof's activity */
4764  if( proofcoef > 0.0 )
4765  {
4766  assert(ubchginfopos >= 0); /* otherwise, undoBdchgsProof() should already have relaxed the local bound */
4767 
4768  /* calculate the difference of current bound to the previous bound the variable was set to */
4769  if( ubchginfopos == var->nubchginfos )
4770  {
4771  /* current bound is the strong branching or diving bound */
4772  oldbound = SCIPvarGetUbLP(var, set);
4773  newbound = SCIPvarGetUbLocal(var);
4774  depth = currentdepth+1;
4775  resolvable = FALSE;
4776  }
4777  else
4778  {
4779  /* current bound is the result of a local bound change */
4780  resolvable = bdchginfoIsResolvable(&var->ubchginfos[ubchginfopos]);
4781  depth = var->ubchginfos[ubchginfopos].bdchgidx.depth;
4782  oldbound = var->ubchginfos[ubchginfopos].newbound;
4783  newbound = var->ubchginfos[ubchginfopos].oldbound;
4784  }
4785  }
4786  else
4787  {
4788  assert(lbchginfopos >= 0); /* otherwise, undoBdchgsProof() should already have relaxed the local bound */
4789 
4790  /* calculate the difference of current bound to the previous bound the variable was set to */
4791  if( lbchginfopos == var->nlbchginfos )
4792  {
4793  /* current bound is the strong branching or diving bound */
4794  oldbound = SCIPvarGetLbLP(var, set);
4795  newbound = SCIPvarGetLbLocal(var);
4796  depth = currentdepth+1;
4797  resolvable = FALSE;
4798  }
4799  else
4800  {
4801  /* current bound is the result of a local bound change */
4802  resolvable = bdchginfoIsResolvable(&var->lbchginfos[lbchginfopos]);
4803  depth = var->lbchginfos[lbchginfopos].bdchgidx.depth;
4804  oldbound = var->lbchginfos[lbchginfopos].newbound;
4805  newbound = var->lbchginfos[lbchginfopos].oldbound;
4806  }
4807  }
4808 
4809  /* calculate the increase in the proof's activity */
4810  proofactdelta = (newbound - oldbound)*proofcoef;
4811  assert(proofactdelta > 0.0);
4812 
4813 
4814  /* calculate score for undoing the bound change */
4815  score = calcBdchgScore(prooflhs, proofact, proofactdelta, proofcoef, depth, currentdepth, var, set);
4816 
4817  if( !resolvable )
4818  {
4819  score += 10.0;
4820  if( !SCIPvarIsBinary(var) )
4821  score += 10.0;
4822  }
4823 
4824  /* get enough memory to store new candidate */
4825  SCIP_CALL( ensureCandsSize(set, cands, candscores, newbounds, proofactdeltas, candssize, (*ncands)+1) );
4826  assert(*cands != NULL);
4827  assert(*candscores != NULL);
4828  assert(*newbounds != NULL);
4829  assert(*proofactdeltas != NULL);
4830 
4831  SCIPsetDebugMsg(set, " -> local <%s> %s %g, relax <%s> %s %g, proofcoef=%g, dpt=%d, resolve=%u, delta=%g, score=%g\n",
4832  SCIPvarGetName(var), proofcoef > 0.0 ? "<=" : ">=", oldbound,
4833  SCIPvarGetName(var), proofcoef > 0.0 ? "<=" : ">=", newbound,
4834  proofcoef, depth, resolvable, proofactdelta, score);
4835 
4836  /* insert variable in candidate list without touching the already processed candidates */
4837  for( i = *ncands; i > firstcand && score > (*candscores)[i-1]; --i )
4838  {
4839  (*cands)[i] = (*cands)[i-1];
4840  (*candscores)[i] = (*candscores)[i-1];
4841  (*newbounds)[i] = (*newbounds)[i-1];
4842  (*proofactdeltas)[i] = (*proofactdeltas)[i-1];
4843  }
4844  (*cands)[i] = var;
4845  (*candscores)[i] = score;
4846  (*newbounds)[i] = newbound;
4847  (*proofactdeltas)[i] = proofactdelta;
4848  (*ncands)++;
4849 
4850  return SCIP_OKAY;
4851 }
4852 
4853 /** after changing the global bound of a variable, the bdchginfos that are now redundant are replaced with
4854  * oldbound = newbound = global bound; if the current bdchginfo is of such kind, the bound is equal to the
4855  * global bound and we can ignore it by installing a -1 as the corresponding bound change info position
4856  */
4857 static
4859  SCIP_VAR* var, /**< problem variable */
4860  int* lbchginfopos, /**< pointer to lower bound change information position */
4861  int* ubchginfopos /**< pointer to upper bound change information position */
4862  )
4863 {
4864  assert(var != NULL);
4865  assert(lbchginfopos != NULL);
4866  assert(ubchginfopos != NULL);
4867  assert(-1 <= *lbchginfopos && *lbchginfopos <= var->nlbchginfos);
4868  assert(-1 <= *ubchginfopos && *ubchginfopos <= var->nubchginfos);
4869  assert(*lbchginfopos == -1 || *lbchginfopos == var->nlbchginfos
4870  || var->lbchginfos[*lbchginfopos].redundant
4871  == (var->lbchginfos[*lbchginfopos].oldbound == var->lbchginfos[*lbchginfopos].newbound)); /*lint !e777*/
4872  assert(*ubchginfopos == -1 || *ubchginfopos == var->nubchginfos
4873  || var->ubchginfos[*ubchginfopos].redundant
4874  == (var->ubchginfos[*ubchginfopos].oldbound == var->ubchginfos[*ubchginfopos].newbound)); /*lint !e777*/
4875 
4876  if( *lbchginfopos >= 0 && *lbchginfopos < var->nlbchginfos && var->lbchginfos[*lbchginfopos].redundant )
4877  {
4878  assert(SCIPvarGetLbGlobal(var) == var->lbchginfos[*lbchginfopos].oldbound); /*lint !e777*/
4879  *lbchginfopos = -1;
4880  }
4881  if( *ubchginfopos >= 0 && *ubchginfopos < var->nubchginfos && var->ubchginfos[*ubchginfopos].redundant )
4882  {
4883  assert(SCIPvarGetUbGlobal(var) == var->ubchginfos[*ubchginfopos].oldbound); /*lint !e777*/
4884  *ubchginfopos = -1;
4885  }
4886 }
4887 
4888 /** undoes bound changes on variables, still leaving the given infeasibility proof valid */
4889 static
4891  SCIP_SET* set, /**< global SCIP settings */
4892  SCIP_PROB* prob, /**< problem data */
4893  int currentdepth, /**< current depth in the tree */
4894  SCIP_Real* proofcoefs, /**< coefficients in infeasibility proof */
4895  SCIP_Real prooflhs, /**< left hand side of proof */
4896  SCIP_Real* proofact, /**< current activity of proof */
4897  SCIP_Real* curvarlbs, /**< current lower bounds of active problem variables */
4898  SCIP_Real* curvarubs, /**< current upper bounds of active problem variables */
4899  int* lbchginfoposs, /**< positions of currently active lower bound change information in variables' arrays */
4900  int* ubchginfoposs, /**< positions of currently active upper bound change information in variables' arrays */
4901  SCIP_LPBDCHGS* oldlpbdchgs, /**< old LP bound changes used for reset the LP bound change, or NULL */
4902  SCIP_LPBDCHGS* relaxedlpbdchgs, /**< relaxed LP bound changes used for reset the LP bound change, or NULL */
4903  SCIP_Bool* resolve, /**< pointer to store whether the changed LP should be resolved again, or NULL */
4904  SCIP_LPI* lpi /**< pointer to LPi to access infinity of LP solver; necessary to set correct values */
4905  )
4906 {
4907  SCIP_VAR** vars;
4908  SCIP_VAR** cands;
4909  SCIP_Real* candscores;
4910  SCIP_Real* newbounds;
4911  SCIP_Real* proofactdeltas;
4912  int nvars;
4913  int ncands;
4914  int candssize;
4915  int v;
4916  int i;
4917 
4918  assert(prob != NULL);
4919  assert(proofcoefs != NULL);
4920  assert(SCIPsetIsFeasGT(set, prooflhs, (*proofact)));
4921  assert(curvarlbs != NULL);
4922  assert(curvarubs != NULL);
4923  assert(lbchginfoposs != NULL);
4924  assert(ubchginfoposs != NULL);
4925 
4926  if( resolve != NULL )
4927  *resolve = FALSE;
4928 
4929  vars = prob->vars;
4930  nvars = prob->nvars;
4931  assert(nvars == 0 || vars != NULL);
4932 
4933  /* calculate the order in which the bound changes are tried to be undone, and relax all bounds if this doesn't
4934  * increase the proof's activity
4935  */
4936  SCIP_CALL( SCIPsetAllocBufferArray(set, &cands, nvars) );
4937  SCIP_CALL( SCIPsetAllocBufferArray(set, &candscores, nvars) );
4938  SCIP_CALL( SCIPsetAllocBufferArray(set, &newbounds, nvars) );
4939  SCIP_CALL( SCIPsetAllocBufferArray(set, &proofactdeltas, nvars) );
4940  ncands = 0;
4941  candssize = nvars;
4942  for( v = 0; v < nvars; ++v )
4943  {
4944  SCIP_VAR* var;
4945  SCIP_Bool relaxed;
4946 
4947  var = vars[v];
4948 
4949  /* after changing the global bound of a variable, the bdchginfos that are now redundant are replaced with
4950  * oldbound = newbound = global bound; if the current bdchginfo is of such kind, the bound is equal to the
4951  * global bound and we can ignore it
4952  */
4953  skipRedundantBdchginfos(var, &lbchginfoposs[v], &ubchginfoposs[v]);
4954 
4955  /* ignore variables already relaxed to global bounds */
4956  if( (lbchginfoposs[v] == -1 && ubchginfoposs[v] == -1) )
4957  {
4958  proofcoefs[v] = 0.0;
4959  continue;
4960  }
4961 
4962  /* relax bounds that are not used in the proof to the global bounds */
4963  relaxed = FALSE;
4964  if( !SCIPsetIsNegative(set, proofcoefs[v]) )
4965  {
4966  /* the lower bound is not used */
4967  if( lbchginfoposs[v] >= 0 )
4968  {
4969  SCIPsetDebugMsg(set, " -> relaxing variable <%s>[%g,%g] to [%g,%g]: proofcoef=%g, %g <= %g\n",
4970  SCIPvarGetName(var), curvarlbs[v], curvarubs[v], SCIPvarGetLbGlobal(var), curvarubs[v],
4971  proofcoefs[v], prooflhs, (*proofact));
4972  curvarlbs[v] = SCIPvarGetLbGlobal(var);
4973  lbchginfoposs[v] = -1;
4974  relaxed = TRUE;
4975  }
4976  }
4977  if( !SCIPsetIsPositive(set, proofcoefs[v]) )
4978  {
4979  /* the upper bound is not used */
4980  if( ubchginfoposs[v] >= 0 )
4981  {
4982  SCIPsetDebugMsg(set, " -> relaxing variable <%s>[%g,%g] to [%g,%g]: proofcoef=%g, %g <= %g\n",
4983  SCIPvarGetName(var), curvarlbs[v], curvarubs[v], curvarlbs[v], SCIPvarGetUbGlobal(var),
4984  proofcoefs[v], prooflhs, (*proofact));
4985  curvarubs[v] = SCIPvarGetUbGlobal(var);
4986  ubchginfoposs[v] = -1;
4987  relaxed = TRUE;
4988  }
4989  }
4990  if( relaxed && oldlpbdchgs != NULL )
4991  {
4992  SCIP_CALL( addBdchg(set, var, curvarlbs[v], curvarubs[v], oldlpbdchgs, relaxedlpbdchgs, lpi) );
4993  }
4994 
4995  /* add bound to candidate list */
4996  if( lbchginfoposs[v] >= 0 || ubchginfoposs[v] >= 0 )
4997  {
4998  SCIP_CALL( addCand(set, currentdepth, var, lbchginfoposs[v], ubchginfoposs[v], proofcoefs[v],
4999  prooflhs, (*proofact), &cands, &candscores, &newbounds, &proofactdeltas, &candssize, &ncands, 0) );
5000  }
5001  /* we can set the proof coefficient to zero, because the variable is not needed */
5002  else
5003  proofcoefs[v] = 0.0;
5004  }
5005 
5006  /* try to undo remaining local bound changes while still keeping the proof row violated:
5007  * bound changes can be undone, if prooflhs > proofact + proofactdelta;
5008  * afterwards, the current proof activity has to be updated
5009  */
5010  for( i = 0; i < ncands; ++i )
5011  {
5012  assert(proofactdeltas[i] > 0.0);
5013  assert((lbchginfoposs[SCIPvarGetProbindex(cands[i])] >= 0) != (ubchginfoposs[SCIPvarGetProbindex(cands[i])] >= 0));
5014 
5015  /* when relaxing a constraint we still need to stay infeasible; therefore we need to do the comparison in
5016  * feasibility tolerance because if 'prooflhs' is (feas-))equal to 'proofact + proofactdeltas[i]' it would mean
5017  * that there is no violation
5018  */
5019  if( SCIPsetIsFeasGT(set, prooflhs, (*proofact) + proofactdeltas[i]) )
5020  {
5021  v = SCIPvarGetProbindex(cands[i]);
5022  assert(0 <= v && v < nvars);
5023  assert((lbchginfoposs[v] >= 0) != (ubchginfoposs[v] >= 0));
5024 
5025  SCIPsetDebugMsg(set, " -> relaxing variable <%s>[%g,%g] to [%g,%g]: proofcoef=%g, %g <= %g + %g\n",
5026  SCIPvarGetName(cands[i]), curvarlbs[v], curvarubs[v],
5027  proofcoefs[v] > 0.0 ? curvarlbs[v] : newbounds[i],
5028  proofcoefs[v] > 0.0 ? newbounds[i] : curvarubs[v],
5029  proofcoefs[v], prooflhs, (*proofact), proofactdeltas[i]);
5030 
5031  assert((SCIPsetIsPositive(set, proofcoefs[v]) && SCIPsetIsGT(set, newbounds[i], curvarubs[v]))
5032  || (SCIPsetIsNegative(set, proofcoefs[v]) && SCIPsetIsLT(set, newbounds[i], curvarlbs[v])));
5033  assert((SCIPsetIsPositive(set, proofcoefs[v])
5034  && SCIPsetIsEQ(set, proofactdeltas[i], (newbounds[i] - curvarubs[v])*proofcoefs[v]))
5035  || (SCIPsetIsNegative(set, proofcoefs[v])
5036  && SCIPsetIsEQ(set, proofactdeltas[i], (newbounds[i] - curvarlbs[v])*proofcoefs[v])));
5037  assert(!SCIPsetIsZero(set, proofcoefs[v]));
5038 
5039  if( proofcoefs[v] > 0.0 )
5040  {
5041  assert(ubchginfoposs[v] >= 0);
5042  assert(lbchginfoposs[v] == -1);
5043  curvarubs[v] = newbounds[i];
5044  ubchginfoposs[v]--;
5045  }
5046  else
5047  {
5048  assert(lbchginfoposs[v] >= 0);
5049  assert(ubchginfoposs[v] == -1);
5050  curvarlbs[v] = newbounds[i];
5051  lbchginfoposs[v]--;
5052  }
5053  if( oldlpbdchgs != NULL )
5054  {
5055  SCIP_CALL( addBdchg(set, cands[i], curvarlbs[v], curvarubs[v], oldlpbdchgs, relaxedlpbdchgs, lpi) );
5056  }
5057  (*proofact) += proofactdeltas[i];
5058  if( resolve != NULL && SCIPvarIsInLP(cands[i]) )
5059  *resolve = TRUE;
5060 
5061  /* after changing the global bound of a variable, the bdchginfos that are now redundant are replaced with
5062  * oldbound = newbound = global bound; if the current bdchginfo is of such kind, the bound is equal to the
5063  * global bound and we can ignore it
5064  */
5065  skipRedundantBdchginfos(cands[i], &lbchginfoposs[v], &ubchginfoposs[v]);
5066 
5067  /* insert the new local bound of the variable into the candidate list */
5068  if( lbchginfoposs[v] >= 0 || ubchginfoposs[v] >= 0 )
5069  {
5070  SCIP_CALL( addCand(set, currentdepth, cands[i], lbchginfoposs[v], ubchginfoposs[v], proofcoefs[v],
5071  prooflhs, (*proofact), &cands, &candscores, &newbounds, &proofactdeltas, &candssize, &ncands, i+1) );
5072  }
5073  else
5074  proofcoefs[v] = 0.0;
5075  }
5076  }
5077 
5078  /* free the buffer for the sorted bound change candidates */
5079  SCIPsetFreeBufferArray(set, &proofactdeltas);
5080  SCIPsetFreeBufferArray(set, &newbounds);
5081  SCIPsetFreeBufferArray(set, &candscores);
5082  SCIPsetFreeBufferArray(set, &cands);
5083 
5084  return SCIP_OKAY;
5085 }
5086 
5087 /* because calculations might cancel out some values, we stop the infeasibility analysis if a value is bigger than
5088  * 2^53 = 9007199254740992
5089  */
5090 #define NUMSTOP 9007199254740992.0
5091 
5092 /** analyzes an infeasible LP and undoes additional bound changes while staying infeasible */
5093 static
5095  SCIP_SET* set, /**< global SCIP settings */
5096  SCIP_PROB* prob, /**< problem data */
5097  SCIP_LP* lp, /**< LP data */
5098  int currentdepth, /**< current depth in the tree */
5099  SCIP_Real* curvarlbs, /**< current lower bounds of active problem variables */
5100  SCIP_Real* curvarubs, /**< current upper bounds of active problem variables */
5101  int* lbchginfoposs, /**< positions of currently active lower bound change information in variables' arrays */
5102  int* ubchginfoposs, /**< positions of currently active upper bound change information in variables' arrays */
5103  SCIP_LPBDCHGS* oldlpbdchgs, /**< old LP bound changes used for reset the LP bound change, or NULL */
5104  SCIP_LPBDCHGS* relaxedlpbdchgs, /**< relaxed LP bound changes used for reset the LP bound change, or NULL */
5105  SCIP_Bool* valid, /**< pointer to store whether the unfixings are valid */
5106  SCIP_Bool* resolve, /**< pointer to store whether the changed LP should be resolved again */
5107  SCIP_Real* farkascoefs, /**< coefficients in the proof constraint */
5108  SCIP_Real farkaslhs, /**< lhs of the proof constraint */
5109  SCIP_Real* farkasactivity /**< maximal activity of the proof constraint */
5110  )
5111 {
5112  SCIP_LPI* lpi;
5113 
5114  assert(prob != NULL);
5115  assert(lp != NULL);
5116  assert(lp->flushed);
5117  assert(lp->solved);
5118  assert(curvarlbs != NULL);
5119  assert(curvarubs != NULL);
5120  assert(lbchginfoposs != NULL);
5121  assert(ubchginfoposs != NULL);
5122  assert(valid != NULL);
5123  assert(resolve != NULL);
5124 
5125  SCIPsetDebugMsg(set, "undoing bound changes in infeasible LP: cutoff=%g\n", lp->cutoffbound);
5126 
5127  *valid = FALSE;
5128  *resolve = FALSE;
5129 
5130  lpi = SCIPlpGetLPI(lp);
5131 
5132  /* check, if the Farkas row is still violated (using current bounds and ignoring local rows) */
5133  if( SCIPsetIsFeasGT(set, farkaslhs, *farkasactivity) )
5134  {
5135  /* undo bound changes while keeping the infeasibility proof valid */
5136  SCIP_CALL( undoBdchgsProof(set, prob, currentdepth, farkascoefs, farkaslhs, farkasactivity,
5137  curvarlbs, curvarubs, lbchginfoposs, ubchginfoposs, oldlpbdchgs, relaxedlpbdchgs, resolve, lpi) );
5138 
5139  *valid = TRUE;
5140 
5141  /* resolving does not make sense: the old dual ray is still valid -> resolving will not change the solution */
5142  *resolve = FALSE;
5143  }
5144 
5145  return SCIP_OKAY;
5146 }
5147 
5148 /** analyzes an LP exceeding the objective limit and undoes additional bound changes while staying beyond the
5149  * objective limit
5150  */
5151 static
5153  SCIP_SET* set, /**< global SCIP settings */
5154  SCIP_PROB* prob, /**< problem data */
5155  SCIP_LP* lp, /**< LP data */
5156  int currentdepth, /**< current depth in the tree */
5157  SCIP_Real* curvarlbs, /**< current lower bounds of active problem variables */
5158  SCIP_Real* curvarubs, /**< current upper bounds of active problem variables */
5159  int* lbchginfoposs, /**< positions of currently active lower bound change information in variables' arrays */
5160  int* ubchginfoposs, /**< positions of currently active upper bound change information in variables' arrays */
5161  SCIP_LPBDCHGS* oldlpbdchgs, /**< old LP bound changes used for reset the LP bound change, or NULL */
5162  SCIP_LPBDCHGS* relaxedlpbdchgs, /**< relaxed LP bound changes used for reset the LP bound change, or NULL */
5163  SCIP_Bool* valid, /**< pointer to store whether the unfixings are valid */
5164  SCIP_Bool* resolve /**< pointer to store whether the changed LP should be resolved again */
5165  )
5166 {
5167  SCIP_RETCODE retcode;
5168  SCIP_LPI* lpi;
5169  SCIP_ROW** rows;
5170  SCIP_VAR** vars;
5171  SCIP_ROW* row;
5172  SCIP_VAR* var;
5173  SCIP_Real* primsols;
5174  SCIP_Real* dualsols;
5175  SCIP_Real* redcosts;
5176  SCIP_Real* dualcoefs;
5177  SCIP_Real* varredcosts;
5178  SCIP_Real duallhs;
5179  SCIP_Real dualact;
5180  int nrows;
5181  int ncols;
5182  int nvars;
5183  int r;
5184  int v;
5185  int i;
5186 
5187  assert(set != NULL);
5188  assert(prob != NULL);
5189  assert(lp != NULL);
5190  assert(lp->flushed);
5191  assert(lp->solved);
5192  assert(curvarlbs != NULL);
5193  assert(curvarubs != NULL);
5194  assert(lbchginfoposs != NULL);
5195  assert(ubchginfoposs != NULL);
5196  assert(valid != NULL);
5197  assert(resolve != NULL);
5198 
5199  *valid = FALSE;
5200  *resolve = FALSE;
5201 
5202  SCIPsetDebugMsg(set, "undoing bound changes in LP exceeding cutoff: cutoff=%g\n", lp->cutoffbound);
5203 
5204  /* get LP solver interface */
5205  lpi = SCIPlpGetLPI(lp);
5206 
5207  /* get LP rows and problem variables */
5208  rows = SCIPlpGetRows(lp);
5209  nrows = SCIPlpGetNRows(lp);
5210  ncols = SCIPlpGetNCols(lp);
5211  vars = prob->vars;
5212  nvars = prob->nvars;
5213  assert(nrows == 0 || rows != NULL);
5214  assert(nrows == lp->nlpirows);
5215 
5216  /* get temporary memory */
5217  SCIP_CALL( SCIPsetAllocBufferArray(set, &primsols, ncols) );
5218  SCIP_CALL( SCIPsetAllocBufferArray(set, &dualsols, nrows) );
5219  SCIP_CALL( SCIPsetAllocBufferArray(set, &redcosts, ncols) );
5220  SCIP_CALL( SCIPsetAllocBufferArray(set, &dualcoefs, nvars) );
5221  SCIP_CALL( SCIPsetAllocBufferArray(set, &varredcosts, nvars) );
5222 
5223  /* get solution from LPI */
5224  retcode = SCIPlpiGetSol(lpi, NULL, primsols, dualsols, NULL, redcosts);
5225  if( retcode == SCIP_LPERROR ) /* on an error in the LP solver, just abort the conflict analysis */
5226  goto TERMINATE;
5227  SCIP_CALL( retcode );
5228 #ifdef SCIP_DEBUG
5229  {
5230  SCIP_Real objval;
5231  SCIP_CALL( SCIPlpiGetObjval(lpi, &objval) );
5232  SCIPsetDebugMsg(set, " -> LP objval: %g\n", objval);
5233  }
5234 #endif
5235 
5236  /* Let y be the dual solution and r be the reduced cost vector. Let z be defined as
5237  * z_i := y_i if i is a global row,
5238  * z_i := 0 if i is a local row.
5239  * Define the set X := {x | lhs <= Ax <= rhs, lb <= x <= ub, c^Tx <= c*}, with c* being the current primal bound.
5240  * Then the following inequalities are valid for all x \in X:
5241  * - c* <= -c^Tx
5242  * <=> z^TAx - c* <= (z^TA - c^T) x
5243  * <=> z^TAx - c* <= (y^TA - c^T - (y-z)^TA) x
5244  * <=> z^TAx - c* <= (-r^T - (y-z)^TA) x (dual feasibility of (y,r): y^TA + r^T == c^T)
5245  * Because lhs <= Ax <= rhs and lb <= x <= ub, the inequality can be relaxed to give
5246  * min{z^Tq | lhs <= q <= rhs} - c* <= max{(-r^T - (y-z)^TA) x | lb <= x <= ub}, or X = {}.
5247  *
5248  * The resulting dual row is: z^T{lhs,rhs} - c* <= (-r^T - (y-z)^TA){lb,ub},
5249  * where lhs, rhs, lb, and ub are selected in order to maximize the feasibility of the row.
5250  */
5251 
5252  BMSclearMemoryArray(dualcoefs, nvars);
5253 
5254  /* use a slightly tighter cutoff bound, because solutions with equal objective value should also be declared
5255  * infeasible
5256  */
5257  duallhs = -(lp->cutoffbound - SCIPsetSumepsilon(set));
5258  dualact = 0.0;
5259 
5260  /* dual row: z^T{lhs,rhs} - c* <= (-r^T - (y-z)^TA){lb,ub}
5261  * process rows: add z^T{lhs,rhs} to the dual row's left hand side, and -(y-z)^TA to the dual row's coefficients
5262  */
5263  for( r = 0; r < nrows; ++r )
5264  {
5265  row = rows[r];
5266  assert(row != NULL);
5267  assert(row->len == 0 || row->cols != NULL);
5268  assert(row->len == 0 || row->vals != NULL);
5269  assert(row == lp->lpirows[r]);
5270 
5271  /* ignore dual solution values of 0.0 (in this case: y_i == z_i == 0) */
5272  if( SCIPsetIsZero(set, dualsols[r]) )
5273  continue;
5274 
5275  /* check dual feasibility */
5276  if( (SCIPsetIsInfinity(set, -row->lhs) && dualsols[r] > 0.0) || (SCIPsetIsInfinity(set, row->rhs) && dualsols[r] < 0.0) )
5277  {
5278  SCIPsetDebugMsg(set, " -> infeasible dual solution %g in row <%s>: lhs=%g, rhs=%g\n",
5279  dualsols[r], SCIProwGetName(row), row->lhs, row->rhs);
5280  goto TERMINATE;
5281  }
5282 
5283  /* local rows add up to the dual row's coefficients (because z_i == 0 => -(y_i - z_i) == -y_i),
5284  * global rows add up to the dual row's left hand side (because z_i == y_i != 0)
5285  */
5286  if( row->local )
5287  {
5288  /* add -y_i A_i to coefficients of dual row */
5289  for( i = 0; i < row->len; ++i )
5290  {
5291  v = SCIPvarGetProbindex(SCIPcolGetVar(row->cols[i]));
5292  assert(0 <= v && v < nvars);
5293  dualcoefs[v] -= dualsols[r] * row->vals[i];
5294  }
5295  SCIPsetDebugMsg(set, " -> local row <%s>: dual=%g\n", SCIProwGetName(row), dualsols[r]);
5296  }
5297  else
5298  {
5299  /* add minimal value to dual row's left hand side: z_i == y_i > 0 -> lhs, z_i == y_i < 0 -> rhs */
5300  if( dualsols[r] > 0.0 )
5301  {
5302  assert(!SCIPsetIsInfinity(set, -row->lhs));
5303  duallhs += dualsols[r] * (row->lhs - row->constant);
5304  }
5305  else
5306  {
5307  assert(!SCIPsetIsInfinity(set, row->rhs));
5308  duallhs += dualsols[r] * (row->rhs - row->constant);
5309  }
5310  SCIPsetDebugMsg(set, " -> global row <%s>[%g,%g]: dual=%g -> duallhs=%g\n",
5311  SCIProwGetName(row), row->lhs - row->constant, row->rhs - row->constant, dualsols[r], duallhs);
5312  }
5313  }
5314 
5315  /* dual row: z^T{lhs,rhs} - c* <= (-r^T - (y-z)^TA){lb,ub}
5316  * process variables: subtract reduced costs from dual row's coefficients, and calculate current maximal dual
5317  * activity by multiplying the resultant coefficient with lb or ub
5318  */
5319  for( v = 0; v < nvars; ++v )
5320  {
5321  var = vars[v];
5322  assert(SCIPvarGetProbindex(var) == v);
5323 
5325  {
5326  /* reduced costs for loose variables are equal to the objective value */
5327  varredcosts[v] = SCIPvarGetObj(var);
5328  }
5329  else
5330  {
5331  SCIP_Real capped_primsol; /* we're not primal feasible, primsol may exceed SCIP_INFINITY */
5332  SCIP_COL* col;
5333  int c;
5334 
5335  assert(SCIPvarGetStatus(var) == SCIP_VARSTATUS_COLUMN);
5336  col = SCIPvarGetCol(var);
5337  c = SCIPcolGetLPPos(col);
5338  assert(c == -1 || col == lp->cols[c]);
5339  assert(c == -1 || col == lp->lpicols[c]);
5340 
5341  /* get reduced costs from LPI, or calculate it manually if the column is not in current LP */
5342  varredcosts[v] = (c >= 0 ? redcosts[c] : SCIPcolCalcRedcost(col, dualsols));
5343 
5344  /* cap primal solution */
5345  capped_primsol = primsols[c];
5346  if( SCIPsetIsInfinity(set, primsols[c]) )
5347  capped_primsol = SCIPsetInfinity(set);
5348  else if( SCIPsetIsInfinity(set, -primsols[c]) )
5349  capped_primsol = -SCIPsetInfinity(set);
5350 
5351  /* check dual feasibility */
5352  if( (SCIPsetIsGT(set, capped_primsol, curvarlbs[v]) && SCIPsetIsDualfeasPositive(set, varredcosts[v]))
5353  || (SCIPsetIsLT(set, capped_primsol, curvarubs[v]) && SCIPsetIsDualfeasNegative(set, varredcosts[v])) )
5354  {
5355  SCIPsetDebugMsg(set, " -> infeasible reduced costs %g in var <%s>: lb=%g, ub=%g\n",
5356  varredcosts[v], SCIPvarGetName(var), curvarlbs[v], curvarubs[v]);
5357  goto TERMINATE;
5358  }
5359  }
5360 
5361  /* subtract reduced costs from dual row's coefficients */
5362  dualcoefs[v] -= varredcosts[v];
5363 
5364  /* add maximal value to dual row's activity: dualcoef > 0 -> ub, dualcoef < 0 -> lb */
5365  if( dualcoefs[v] > 0.0 )
5366  {
5367  if( SCIPsetIsInfinity(set, curvarubs[v]) )
5368  goto TERMINATE;
5369  dualact += dualcoefs[v] * curvarubs[v];
5370  }
5371  else
5372  {
5373  if( SCIPsetIsInfinity(set, -curvarlbs[v]) )
5374  goto TERMINATE;
5375  dualact += dualcoefs[v] * curvarlbs[v];
5376  }
5377  }
5378  SCIPsetDebugMsg(set, " -> final dual values: lhs=%g, act=%g\n", duallhs, dualact);
5379 
5380  /* check, if the dual row is still violated (using current bounds and ignoring local rows) */
5381  if( SCIPsetIsFeasGT(set, duallhs, dualact) )
5382  {
5383  /* undo bound changes while keeping the infeasibility proof valid */
5384  SCIP_CALL( undoBdchgsProof(set, prob, currentdepth, dualcoefs, duallhs, &dualact,
5385  curvarlbs, curvarubs, lbchginfoposs, ubchginfoposs, oldlpbdchgs, relaxedlpbdchgs, resolve, lpi) );
5386 
5387  *valid = TRUE;
5388  }
5389 
5390  TERMINATE:
5391 
5392  /* free temporary memory */
5393  SCIPsetFreeBufferArray(set, &varredcosts);
5394  SCIPsetFreeBufferArray(set, &dualcoefs);
5395  SCIPsetFreeBufferArray(set, &redcosts);
5396  SCIPsetFreeBufferArray(set, &dualsols);
5397  SCIPsetFreeBufferArray(set, &primsols);
5398 
5399  return SCIP_OKAY;
5400 }
5401 
5402 /** applies conflict analysis starting with given bound changes, that could not be undone during previous
5403  * infeasibility analysis
5404  */
5405 static
5407  SCIP_CONFLICT* conflict, /**< conflict analysis data */
5408  BMS_BLKMEM* blkmem, /**< block memory of transformed problem */
5409  SCIP_SET* set, /**< global SCIP settings */
5410  SCIP_STAT* stat, /**< problem statistics */
5411  SCIP_PROB* prob, /**< problem data */
5412  SCIP_TREE* tree, /**< branch and bound tree */
5413  SCIP_Bool diving, /**< are we in strong branching or diving mode? */
5414  int* lbchginfoposs, /**< positions of currently active lower bound change information in variables' arrays */
5415  int* ubchginfoposs, /**< positions of currently active upper bound change information in variables' arrays */
5416  int* nconss, /**< pointer to store the number of generated conflict constraints */
5417  int* nliterals, /**< pointer to store the number of literals in generated conflict constraints */
5418  int* nreconvconss, /**< pointer to store the number of generated reconvergence constraints */
5419  int* nreconvliterals /**< pointer to store the number of literals generated reconvergence constraints */
5420  )
5421 {
5422  SCIP_VAR** vars;
5423  SCIP_VAR* var;
5424  SCIP_CONFTYPE conftype;
5425  SCIP_Bool usescutoffbound;
5426  int nvars;
5427  int v;
5428  int nbdchgs;
5429  int maxsize;
5430 
5431  assert(prob != NULL);
5432  assert(lbchginfoposs != NULL);
5433  assert(ubchginfoposs != NULL);
5434  assert(nconss != NULL);
5435  assert(nliterals != NULL);
5436  assert(nreconvconss != NULL);
5437  assert(nreconvliterals != NULL);
5438 
5439  *nconss = 0;
5440  *nliterals = 0;
5441  *nreconvconss = 0;
5442  *nreconvliterals = 0;
5443 
5444  vars = prob->vars;
5445  nvars = prob->nvars;
5446  assert(nvars == 0 || vars != NULL);
5447 
5448  maxsize = 2*conflictCalcMaxsize(set, prob);
5449 
5450  /* initialize conflict data */
5451  conftype = conflict->conflictset->conflicttype;
5452  usescutoffbound = conflict->conflictset->usescutoffbound;
5453 
5454  SCIP_CALL( SCIPconflictInit(conflict, set, stat, prob, conftype, usescutoffbound) );
5455 
5456  conflict->conflictset->conflicttype = conftype;
5457  conflict->conflictset->usescutoffbound = usescutoffbound;
5458 
5459  /* add remaining bound changes to conflict queue */
5460  SCIPsetDebugMsg(set, "initial conflict set after undoing bound changes:\n");
5461 
5462  nbdchgs = 0;
5463  for( v = 0; v < nvars && nbdchgs < maxsize; ++v )
5464  {
5465  var = vars[v];
5466  assert(var != NULL);
5467  assert(var->nlbchginfos >= 0);
5468  assert(var->nubchginfos >= 0);
5469  assert(-1 <= lbchginfoposs[v] && lbchginfoposs[v] <= var->nlbchginfos);
5470  assert(-1 <= ubchginfoposs[v] && ubchginfoposs[v] <= var->nubchginfos);
5471 
5472  if( lbchginfoposs[v] == var->nlbchginfos || ubchginfoposs[v] == var->nubchginfos )
5473  {
5474  SCIP_BDCHGINFO* bdchginfo;
5475  SCIP_Real relaxedbd;
5476 
5477  /* the strong branching or diving bound stored in the column is responsible for the conflict:
5478  * it cannot be resolved and therefore has to be directly put into the conflict set
5479  */
5480  assert((lbchginfoposs[v] == var->nlbchginfos) != (ubchginfoposs[v] == var->nubchginfos)); /* only one can be tight in the dual! */
5481  assert(lbchginfoposs[v] < var->nlbchginfos || SCIPvarGetLbLP(var, set) > SCIPvarGetLbLocal(var));
5482  assert(ubchginfoposs[v] < var->nubchginfos || SCIPvarGetUbLP(var, set) < SCIPvarGetUbLocal(var));
5483 
5484  /* create an artificial bound change information for the diving/strong branching bound change;
5485  * they are freed in the SCIPconflictFlushConss() call
5486  */
5487  if( lbchginfoposs[v] == var->nlbchginfos )
5488  {
5489  SCIP_CALL( conflictCreateTmpBdchginfo(conflict, blkmem, set, var, SCIP_BOUNDTYPE_LOWER,
5490  SCIPvarGetLbLocal(var), SCIPvarGetLbLP(var, set), &bdchginfo) );
5491  relaxedbd = SCIPvarGetLbLP(var, set);
5492  }
5493  else
5494  {
5495  SCIP_CALL( conflictCreateTmpBdchginfo(conflict, blkmem, set, var, SCIP_BOUNDTYPE_UPPER,
5496  SCIPvarGetUbLocal(var), SCIPvarGetUbLP(var, set), &bdchginfo) );
5497  relaxedbd = SCIPvarGetUbLP(var, set);
5498  }
5499 
5500  /* put variable into the conflict set */
5501  SCIPsetDebugMsg(set, " force: <%s> %s %g [status: %d, type: %d, dive/strong]\n",
5502  SCIPvarGetName(var), lbchginfoposs[v] == var->nlbchginfos ? &