Scippy

SCIP

Solving Constraint Integer Programs

tree.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-2021 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file tree.c
17  * @ingroup OTHER_CFILES
18  * @brief methods for branch and bound tree
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #include <assert.h>
27 
28 #include "scip/def.h"
29 #include "scip/set.h"
30 #include "scip/stat.h"
31 #include "scip/clock.h"
32 #include "scip/visual.h"
33 #include "scip/event.h"
34 #include "scip/lp.h"
35 #include "scip/relax.h"
36 #include "scip/var.h"
37 #include "scip/implics.h"
38 #include "scip/primal.h"
39 #include "scip/tree.h"
40 #include "scip/reopt.h"
41 #include "scip/conflictstore.h"
42 #include "scip/solve.h"
43 #include "scip/cons.h"
44 #include "scip/nodesel.h"
45 #include "scip/prop.h"
46 #include "scip/debug.h"
47 #include "scip/prob.h"
48 #include "scip/scip.h"
49 #include "scip/struct_event.h"
50 #include "scip/pub_message.h"
51 #include "scip/struct_branch.h"
52 #include "lpi/lpi.h"
53 
54 
55 #define MAXREPROPMARK 511 /**< maximal subtree repropagation marker; must correspond to node data structure */
56 
57 
58 /*
59  * dynamic memory arrays
60  */
61 
62 /** resizes children arrays to be able to store at least num nodes */
63 static
65  SCIP_TREE* tree, /**< branch and bound tree */
66  SCIP_SET* set, /**< global SCIP settings */
67  int num /**< minimal number of node slots in array */
68  )
69 {
70  assert(tree != NULL);
71  assert(set != NULL);
72 
73  if( num > tree->childrensize )
74  {
75  int newsize;
76 
77  newsize = SCIPsetCalcMemGrowSize(set, num);
78  SCIP_ALLOC( BMSreallocMemoryArray(&tree->children, newsize) );
79  SCIP_ALLOC( BMSreallocMemoryArray(&tree->childrenprio, newsize) );
80  tree->childrensize = newsize;
81  }
82  assert(num <= tree->childrensize);
83 
84  return SCIP_OKAY;
85 }
86 
87 /** resizes path array to be able to store at least num nodes */
88 static
90  SCIP_TREE* tree, /**< branch and bound tree */
91  SCIP_SET* set, /**< global SCIP settings */
92  int num /**< minimal number of node slots in path */
93  )
94 {
95  assert(tree != NULL);
96  assert(set != NULL);
97 
98  if( num > tree->pathsize )
99  {
100  int newsize;
101 
102  newsize = SCIPsetCalcPathGrowSize(set, num);
103  SCIP_ALLOC( BMSreallocMemoryArray(&tree->path, newsize) );
104  SCIP_ALLOC( BMSreallocMemoryArray(&tree->pathnlpcols, newsize) );
105  SCIP_ALLOC( BMSreallocMemoryArray(&tree->pathnlprows, newsize) );
106  tree->pathsize = newsize;
107  }
108  assert(num <= tree->pathsize);
109 
110  return SCIP_OKAY;
111 }
112 
113 /** resizes pendingbdchgs array to be able to store at least num nodes */
114 static
116  SCIP_TREE* tree, /**< branch and bound tree */
117  SCIP_SET* set, /**< global SCIP settings */
118  int num /**< minimal number of node slots in path */
119  )
120 {
121  assert(tree != NULL);
122  assert(set != NULL);
123 
124  if( num > tree->pendingbdchgssize )
125  {
126  int newsize;
127 
128  newsize = SCIPsetCalcMemGrowSize(set, num);
129  SCIP_ALLOC( BMSreallocMemoryArray(&tree->pendingbdchgs, newsize) );
130  tree->pendingbdchgssize = newsize;
131  }
132  assert(num <= tree->pendingbdchgssize);
133 
134  return SCIP_OKAY;
135 }
136 
137 
138 
139 
140 /*
141  * Node methods
142  */
143 
144 /** node comparator for best lower bound */
145 SCIP_DECL_SORTPTRCOMP(SCIPnodeCompLowerbound)
146 { /*lint --e{715}*/
147  assert(elem1 != NULL);
148  assert(elem2 != NULL);
149 
150  if( ((SCIP_NODE*)elem1)->lowerbound < ((SCIP_NODE*)elem2)->lowerbound )
151  return -1;
152  else if( ((SCIP_NODE*)elem1)->lowerbound > ((SCIP_NODE*)elem2)->lowerbound )
153  return +1;
154  else
155  return 0;
156 }
157 
158 /** increases the reference counter of the LP state in the fork */
159 static
161  SCIP_FORK* fork, /**< fork data */
162  int nuses /**< number to add to the usage counter */
163  )
164 {
165  assert(fork != NULL);
166  assert(fork->nlpistateref >= 0);
167  assert(nuses > 0);
168 
169  fork->nlpistateref += nuses;
170  SCIPdebugMessage("captured LPI state of fork %p %d times -> new nlpistateref=%d\n", (void*)fork, nuses, fork->nlpistateref);
171 }
172 
173 /** decreases the reference counter of the LP state in the fork */
174 static
176  SCIP_FORK* fork, /**< fork data */
177  BMS_BLKMEM* blkmem, /**< block memory buffers */
178  SCIP_LP* lp /**< current LP data */
179  )
180 {
181  assert(fork != NULL);
182  assert(fork->nlpistateref > 0);
183  assert(blkmem != NULL);
184  assert(lp != NULL);
185 
186  fork->nlpistateref--;
187  if( fork->nlpistateref == 0 )
188  {
189  SCIP_CALL( SCIPlpFreeState(lp, blkmem, &(fork->lpistate)) );
190  }
191 
192  SCIPdebugMessage("released LPI state of fork %p -> new nlpistateref=%d\n", (void*)fork, fork->nlpistateref);
193 
194  return SCIP_OKAY;
195 }
196 
197 /** increases the reference counter of the LP state in the subroot */
198 static
200  SCIP_SUBROOT* subroot, /**< subroot data */
201  int nuses /**< number to add to the usage counter */
202  )
203 {
204  assert(subroot != NULL);
205  assert(subroot->nlpistateref >= 0);
206  assert(nuses > 0);
207 
208  subroot->nlpistateref += nuses;
209  SCIPdebugMessage("captured LPI state of subroot %p %d times -> new nlpistateref=%d\n",
210  (void*)subroot, nuses, subroot->nlpistateref);
211 }
212 
213 /** decreases the reference counter of the LP state in the subroot */
214 static
216  SCIP_SUBROOT* subroot, /**< subroot data */
217  BMS_BLKMEM* blkmem, /**< block memory buffers */
218  SCIP_LP* lp /**< current LP data */
219  )
220 {
221  assert(subroot != NULL);
222  assert(subroot->nlpistateref > 0);
223  assert(blkmem != NULL);
224  assert(lp != NULL);
225 
226  subroot->nlpistateref--;
227  if( subroot->nlpistateref == 0 )
228  {
229  SCIP_CALL( SCIPlpFreeState(lp, blkmem, &(subroot->lpistate)) );
230  }
231 
232  SCIPdebugMessage("released LPI state of subroot %p -> new nlpistateref=%d\n", (void*)subroot, subroot->nlpistateref);
233 
234  return SCIP_OKAY;
235 }
236 
237 /** increases the reference counter of the LP state in the fork or subroot node */
239  SCIP_NODE* node, /**< fork/subroot node */
240  int nuses /**< number to add to the usage counter */
241  )
242 {
243  assert(node != NULL);
244 
245  SCIPdebugMessage("capture %d times LPI state of node #%" SCIP_LONGINT_FORMAT " at depth %d (current: %d)\n",
246  nuses, SCIPnodeGetNumber(node), SCIPnodeGetDepth(node),
248 
249  switch( SCIPnodeGetType(node) )
250  {
251  case SCIP_NODETYPE_FORK:
252  forkCaptureLPIState(node->data.fork, nuses);
253  break;
255  subrootCaptureLPIState(node->data.subroot, nuses);
256  break;
257  default:
258  SCIPerrorMessage("node for capturing the LPI state is neither fork nor subroot\n");
259  SCIPABORT();
260  return SCIP_INVALIDDATA; /*lint !e527*/
261  } /*lint !e788*/
262  return SCIP_OKAY;
263 }
264 
265 /** decreases the reference counter of the LP state in the fork or subroot node */
267  SCIP_NODE* node, /**< fork/subroot node */
268  BMS_BLKMEM* blkmem, /**< block memory buffers */
269  SCIP_LP* lp /**< current LP data */
270  )
271 {
272  assert(node != NULL);
273 
274  SCIPdebugMessage("release LPI state of node #%" SCIP_LONGINT_FORMAT " at depth %d (current: %d)\n",
275  SCIPnodeGetNumber(node), SCIPnodeGetDepth(node),
277  switch( SCIPnodeGetType(node) )
278  {
279  case SCIP_NODETYPE_FORK:
280  return forkReleaseLPIState(node->data.fork, blkmem, lp);
282  return subrootReleaseLPIState(node->data.subroot, blkmem, lp);
283  default:
284  SCIPerrorMessage("node for releasing the LPI state is neither fork nor subroot\n");
285  return SCIP_INVALIDDATA;
286  } /*lint !e788*/
287 }
288 
289 /** creates probingnode data without LP information */
290 static
292  SCIP_PROBINGNODE** probingnode, /**< pointer to probingnode data */
293  BMS_BLKMEM* blkmem, /**< block memory */
294  SCIP_LP* lp /**< current LP data */
295  )
296 {
297  assert(probingnode != NULL);
298 
299  SCIP_ALLOC( BMSallocBlockMemory(blkmem, probingnode) );
300 
301  (*probingnode)->lpistate = NULL;
302  (*probingnode)->lpinorms = NULL;
303  (*probingnode)->ninitialcols = SCIPlpGetNCols(lp);
304  (*probingnode)->ninitialrows = SCIPlpGetNRows(lp);
305  (*probingnode)->ncols = (*probingnode)->ninitialcols;
306  (*probingnode)->nrows = (*probingnode)->ninitialrows;
307  (*probingnode)->origobjvars = NULL;
308  (*probingnode)->origobjvals = NULL;
309  (*probingnode)->nchgdobjs = 0;
310 
311  SCIPdebugMessage("created probingnode information (%d cols, %d rows)\n", (*probingnode)->ncols, (*probingnode)->nrows);
312 
313  return SCIP_OKAY;
314 }
315 
316 /** updates LP information in probingnode data */
317 static
319  SCIP_PROBINGNODE* probingnode, /**< probingnode data */
320  BMS_BLKMEM* blkmem, /**< block memory */
321  SCIP_TREE* tree, /**< branch and bound tree */
322  SCIP_LP* lp /**< current LP data */
323  )
324 {
325  SCIP_Bool storenorms = FALSE;
326 
327  assert(probingnode != NULL);
328  assert(SCIPtreeIsPathComplete(tree));
329  assert(lp != NULL);
330 
331  /* free old LP state */
332  if( probingnode->lpistate != NULL )
333  {
334  SCIP_CALL( SCIPlpFreeState(lp, blkmem, &probingnode->lpistate) );
335  }
336 
337  /* free old LP norms */
338  if( probingnode->lpinorms != NULL )
339  {
340  SCIP_CALL( SCIPlpFreeNorms(lp, blkmem, &probingnode->lpinorms) );
341  probingnode->lpinorms = NULL;
342  storenorms = TRUE;
343  }
344 
345  /* get current LP state */
346  if( lp->flushed && lp->solved )
347  {
348  SCIP_CALL( SCIPlpGetState(lp, blkmem, &probingnode->lpistate) );
349 
350  /* if LP norms were stored at this node before, store the new ones */
351  if( storenorms )
352  {
353  SCIP_CALL( SCIPlpGetNorms(lp, blkmem, &probingnode->lpinorms) );
354  }
355  probingnode->lpwasprimfeas = lp->primalfeasible;
356  probingnode->lpwasprimchecked = lp->primalchecked;
357  probingnode->lpwasdualfeas = lp->dualfeasible;
358  probingnode->lpwasdualchecked = lp->dualchecked;
359  }
360  else
361  probingnode->lpistate = NULL;
362 
363  probingnode->ncols = SCIPlpGetNCols(lp);
364  probingnode->nrows = SCIPlpGetNRows(lp);
365 
366  SCIPdebugMessage("updated probingnode information (%d cols, %d rows)\n", probingnode->ncols, probingnode->nrows);
367 
368  return SCIP_OKAY;
369 }
370 
371 /** frees probingnode data */
372 static
374  SCIP_PROBINGNODE** probingnode, /**< probingnode data */
375  BMS_BLKMEM* blkmem, /**< block memory */
376  SCIP_LP* lp /**< current LP data */
377  )
378 {
379  assert(probingnode != NULL);
380  assert(*probingnode != NULL);
381 
382  /* free the associated LP state */
383  if( (*probingnode)->lpistate != NULL )
384  {
385  SCIP_CALL( SCIPlpFreeState(lp, blkmem, &(*probingnode)->lpistate) );
386  }
387  /* free the associated LP norms */
388  if( (*probingnode)->lpinorms != NULL )
389  {
390  SCIP_CALL( SCIPlpFreeNorms(lp, blkmem, &(*probingnode)->lpinorms) );
391  }
392 
393  /* free objective information */
394  if( (*probingnode)->nchgdobjs > 0 )
395  {
396  assert((*probingnode)->origobjvars != NULL);
397  assert((*probingnode)->origobjvals != NULL);
398 
399  BMSfreeMemoryArray(&(*probingnode)->origobjvars);
400  BMSfreeMemoryArray(&(*probingnode)->origobjvals);
401  }
402 
403  BMSfreeBlockMemory(blkmem, probingnode);
404 
405  return SCIP_OKAY;
406 }
407 
408 /** initializes junction data */
409 static
411  SCIP_JUNCTION* junction, /**< pointer to junction data */
412  SCIP_TREE* tree /**< branch and bound tree */
413  )
414 {
415  assert(junction != NULL);
416  assert(tree != NULL);
417  assert(tree->nchildren > 0);
418  assert(SCIPtreeIsPathComplete(tree));
419  assert(tree->focusnode != NULL);
420 
421  junction->nchildren = tree->nchildren;
422 
423  /* increase the LPI state usage counter of the current LP fork */
424  if( tree->focuslpstatefork != NULL )
425  {
427  }
428 
429  return SCIP_OKAY;
430 }
431 
432 /** creates pseudofork data */
433 static
435  SCIP_PSEUDOFORK** pseudofork, /**< pointer to pseudofork data */
436  BMS_BLKMEM* blkmem, /**< block memory */
437  SCIP_TREE* tree, /**< branch and bound tree */
438  SCIP_LP* lp /**< current LP data */
439  )
440 {
441  assert(pseudofork != NULL);
442  assert(blkmem != NULL);
443  assert(tree != NULL);
444  assert(tree->nchildren > 0);
445  assert(SCIPtreeIsPathComplete(tree));
446  assert(tree->focusnode != NULL);
447 
448  SCIP_ALLOC( BMSallocBlockMemory(blkmem, pseudofork) );
449 
450  (*pseudofork)->addedcols = NULL;
451  (*pseudofork)->addedrows = NULL;
452  (*pseudofork)->naddedcols = SCIPlpGetNNewcols(lp);
453  (*pseudofork)->naddedrows = SCIPlpGetNNewrows(lp);
454  (*pseudofork)->nchildren = tree->nchildren;
455 
456  SCIPdebugMessage("creating pseudofork information with %d children (%d new cols, %d new rows)\n",
457  (*pseudofork)->nchildren, (*pseudofork)->naddedcols, (*pseudofork)->naddedrows);
458 
459  if( (*pseudofork)->naddedcols > 0 )
460  {
461  /* copy the newly created columns to the pseudofork's col array */
462  SCIP_ALLOC( BMSduplicateBlockMemoryArray(blkmem, &(*pseudofork)->addedcols, SCIPlpGetNewcols(lp), (*pseudofork)->naddedcols) ); /*lint !e666*/
463  }
464  if( (*pseudofork)->naddedrows > 0 )
465  {
466  int i;
467 
468  /* copy the newly created rows to the pseudofork's row array */
469  SCIP_ALLOC( BMSduplicateBlockMemoryArray(blkmem, &(*pseudofork)->addedrows, SCIPlpGetNewrows(lp), (*pseudofork)->naddedrows) ); /*lint !e666*/
470 
471  /* capture the added rows */
472  for( i = 0; i < (*pseudofork)->naddedrows; ++i )
473  SCIProwCapture((*pseudofork)->addedrows[i]);
474  }
475 
476  /* increase the LPI state usage counter of the current LP fork */
477  if( tree->focuslpstatefork != NULL )
478  {
480  }
481 
482  return SCIP_OKAY;
483 }
484 
485 /** frees pseudofork data */
486 static
488  SCIP_PSEUDOFORK** pseudofork, /**< pseudofork data */
489  BMS_BLKMEM* blkmem, /**< block memory */
490  SCIP_SET* set, /**< global SCIP settings */
491  SCIP_LP* lp /**< current LP data */
492  )
493 {
494  int i;
495 
496  assert(pseudofork != NULL);
497  assert(*pseudofork != NULL);
498  assert((*pseudofork)->nchildren == 0);
499  assert(blkmem != NULL);
500  assert(set != NULL);
501 
502  /* release the added rows */
503  for( i = 0; i < (*pseudofork)->naddedrows; ++i )
504  {
505  SCIP_CALL( SCIProwRelease(&(*pseudofork)->addedrows[i], blkmem, set, lp) );
506  }
507 
508  BMSfreeBlockMemoryArrayNull(blkmem, &(*pseudofork)->addedcols, (*pseudofork)->naddedcols);
509  BMSfreeBlockMemoryArrayNull(blkmem, &(*pseudofork)->addedrows, (*pseudofork)->naddedrows);
510  BMSfreeBlockMemory(blkmem, pseudofork);
511 
512  return SCIP_OKAY;
513 }
514 
515 /** creates fork data */
516 static
518  SCIP_FORK** fork, /**< pointer to fork data */
519  BMS_BLKMEM* blkmem, /**< block memory */
520  SCIP_SET* set, /**< global SCIP settings */
521  SCIP_PROB* prob, /**< transformed problem after presolve */
522  SCIP_TREE* tree, /**< branch and bound tree */
523  SCIP_LP* lp /**< current LP data */
524  )
525 {
526  assert(fork != NULL);
527  assert(blkmem != NULL);
528  assert(tree != NULL);
529  assert(tree->nchildren > 0);
530  assert(tree->nchildren < (1 << 30));
531  assert(SCIPtreeIsPathComplete(tree));
532  assert(tree->focusnode != NULL);
533  assert(lp != NULL);
534  assert(lp->flushed);
535  assert(lp->solved);
537 
538  SCIP_ALLOC( BMSallocBlockMemory(blkmem, fork) );
539 
540  SCIP_CALL( SCIPlpGetState(lp, blkmem, &((*fork)->lpistate)) );
541  (*fork)->lpwasprimfeas = lp->primalfeasible;
542  (*fork)->lpwasprimchecked = lp->primalchecked;
543  (*fork)->lpwasdualfeas = lp->dualfeasible;
544  (*fork)->lpwasdualchecked = lp->dualchecked;
545  (*fork)->lpobjval = SCIPlpGetObjval(lp, set, prob);
546  (*fork)->nlpistateref = 0;
547  (*fork)->addedcols = NULL;
548  (*fork)->addedrows = NULL;
549  (*fork)->naddedcols = SCIPlpGetNNewcols(lp);
550  (*fork)->naddedrows = SCIPlpGetNNewrows(lp);
551  (*fork)->nchildren = (unsigned int) tree->nchildren;
552 
553  SCIPsetDebugMsg(set, "creating fork information with %u children (%d new cols, %d new rows)\n", (*fork)->nchildren, (*fork)->naddedcols, (*fork)->naddedrows);
554 
555  if( (*fork)->naddedcols > 0 )
556  {
557  /* copy the newly created columns to the fork's col array */
558  SCIP_ALLOC( BMSduplicateBlockMemoryArray(blkmem, &(*fork)->addedcols, SCIPlpGetNewcols(lp), (*fork)->naddedcols) ); /*lint !e666*/
559  }
560  if( (*fork)->naddedrows > 0 )
561  {
562  int i;
563 
564  /* copy the newly created rows to the fork's row array */
565  SCIP_ALLOC( BMSduplicateBlockMemoryArray(blkmem, &(*fork)->addedrows, SCIPlpGetNewrows(lp), (*fork)->naddedrows) ); /*lint !e666*/
566 
567  /* capture the added rows */
568  for( i = 0; i < (*fork)->naddedrows; ++i )
569  SCIProwCapture((*fork)->addedrows[i]);
570  }
571 
572  /* capture the LPI state for the children */
573  forkCaptureLPIState(*fork, tree->nchildren);
574 
575  return SCIP_OKAY;
576 }
577 
578 /** frees fork data */
579 static
581  SCIP_FORK** fork, /**< fork data */
582  BMS_BLKMEM* blkmem, /**< block memory */
583  SCIP_SET* set, /**< global SCIP settings */
584  SCIP_LP* lp /**< current LP data */
585  )
586 {
587  int i;
588 
589  assert(fork != NULL);
590  assert(*fork != NULL);
591  assert((*fork)->nchildren == 0);
592  assert((*fork)->nlpistateref == 0);
593  assert((*fork)->lpistate == NULL);
594  assert(blkmem != NULL);
595  assert(set != NULL);
596  assert(lp != NULL);
597 
598  /* release the added rows */
599  for( i = (*fork)->naddedrows - 1; i >= 0; --i )
600  {
601  SCIP_CALL( SCIProwRelease(&(*fork)->addedrows[i], blkmem, set, lp) );
602  }
603 
604  BMSfreeBlockMemoryArrayNull(blkmem, &(*fork)->addedcols, (*fork)->naddedcols);
605  BMSfreeBlockMemoryArrayNull(blkmem, &(*fork)->addedrows, (*fork)->naddedrows);
606  BMSfreeBlockMemory(blkmem, fork);
607 
608  return SCIP_OKAY;
609 }
610 
611 #ifdef WITHSUBROOTS /** @todo test whether subroots should be created */
612 /** creates subroot data */
613 static
614 SCIP_RETCODE subrootCreate(
615  SCIP_SUBROOT** subroot, /**< pointer to subroot data */
616  BMS_BLKMEM* blkmem, /**< block memory */
617  SCIP_SET* set, /**< global SCIP settings */
618  SCIP_PROB* prob, /**< transformed problem after presolve */
619  SCIP_TREE* tree, /**< branch and bound tree */
620  SCIP_LP* lp /**< current LP data */
621  )
622 {
623  int i;
624 
625  assert(subroot != NULL);
626  assert(blkmem != NULL);
627  assert(tree != NULL);
628  assert(tree->nchildren > 0);
629  assert(SCIPtreeIsPathComplete(tree));
630  assert(tree->focusnode != NULL);
631  assert(lp != NULL);
632  assert(lp->flushed);
633  assert(lp->solved);
635 
636  SCIP_ALLOC( BMSallocBlockMemory(blkmem, subroot) );
637  (*subroot)->lpobjval = SCIPlpGetObjval(lp, set, prob);
638  (*subroot)->nlpistateref = 0;
639  (*subroot)->ncols = SCIPlpGetNCols(lp);
640  (*subroot)->nrows = SCIPlpGetNRows(lp);
641  (*subroot)->nchildren = (unsigned int) tree->nchildren;
642  SCIP_CALL( SCIPlpGetState(lp, blkmem, &((*subroot)->lpistate)) );
643  (*subroot)->lpwasprimfeas = lp->primalfeasible;
644  (*subroot)->lpwasprimchecked = lp->primalchecked;
645  (*subroot)->lpwasdualfeas = lp->dualfeasible;
646  (*subroot)->lpwasdualchecked = lp->dualchecked;
647 
648  if( (*subroot)->ncols != 0 )
649  {
650  SCIP_ALLOC( BMSduplicateBlockMemoryArray(blkmem, &(*subroot)->cols, SCIPlpGetCols(lp), (*subroot)->ncols) );
651  }
652  else
653  (*subroot)->cols = NULL;
654  if( (*subroot)->nrows != 0 )
655  {
656  SCIP_ALLOC( BMSduplicateBlockMemoryArray(blkmem, &(*subroot)->rows, SCIPlpGetRows(lp), (*subroot)->nrows) );
657  }
658  else
659  (*subroot)->rows = NULL;
660 
661  /* capture the rows of the subroot */
662  for( i = 0; i < (*subroot)->nrows; ++i )
663  SCIProwCapture((*subroot)->rows[i]);
664 
665  /* capture the LPI state for the children */
666  subrootCaptureLPIState(*subroot, tree->nchildren);
667 
668  return SCIP_OKAY;
669 }
670 #endif
671 
672 /** frees subroot */
673 static
675  SCIP_SUBROOT** subroot, /**< subroot data */
676  BMS_BLKMEM* blkmem, /**< block memory */
677  SCIP_SET* set, /**< global SCIP settings */
678  SCIP_LP* lp /**< current LP data */
679  )
680 {
681  int i;
682 
683  assert(subroot != NULL);
684  assert(*subroot != NULL);
685  assert((*subroot)->nchildren == 0);
686  assert((*subroot)->nlpistateref == 0);
687  assert((*subroot)->lpistate == NULL);
688  assert(blkmem != NULL);
689  assert(set != NULL);
690  assert(lp != NULL);
691 
692  /* release the rows of the subroot */
693  for( i = 0; i < (*subroot)->nrows; ++i )
694  {
695  SCIP_CALL( SCIProwRelease(&(*subroot)->rows[i], blkmem, set, lp) );
696  }
697 
698  BMSfreeBlockMemoryArrayNull(blkmem, &(*subroot)->cols, (*subroot)->ncols);
699  BMSfreeBlockMemoryArrayNull(blkmem, &(*subroot)->rows, (*subroot)->nrows);
700  BMSfreeBlockMemory(blkmem, subroot);
701 
702  return SCIP_OKAY;
703 }
704 
705 /** removes given sibling node from the siblings array */
706 static
708  SCIP_TREE* tree, /**< branch and bound tree */
709  SCIP_NODE* sibling /**< sibling node to remove */
710  )
711 {
712  int delpos;
713 
714  assert(tree != NULL);
715  assert(sibling != NULL);
716  assert(SCIPnodeGetType(sibling) == SCIP_NODETYPE_SIBLING);
717  assert(sibling->data.sibling.arraypos >= 0 && sibling->data.sibling.arraypos < tree->nsiblings);
718  assert(tree->siblings[sibling->data.sibling.arraypos] == sibling);
719  assert(SCIPnodeGetType(tree->siblings[tree->nsiblings-1]) == SCIP_NODETYPE_SIBLING);
720 
721  delpos = sibling->data.sibling.arraypos;
722 
723  /* move last sibling in array to position of removed sibling */
724  tree->siblings[delpos] = tree->siblings[tree->nsiblings-1];
725  tree->siblingsprio[delpos] = tree->siblingsprio[tree->nsiblings-1];
726  tree->siblings[delpos]->data.sibling.arraypos = delpos;
727  sibling->data.sibling.arraypos = -1;
728  tree->nsiblings--;
729 }
730 
731 /** adds given child node to children array of focus node */
732 static
734  SCIP_TREE* tree, /**< branch and bound tree */
735  SCIP_SET* set, /**< global SCIP settings */
736  SCIP_NODE* child, /**< child node to add */
737  SCIP_Real nodeselprio /**< node selection priority of child node */
738  )
739 {
740  assert(tree != NULL);
741  assert(child != NULL);
742  assert(SCIPnodeGetType(child) == SCIP_NODETYPE_CHILD);
743  assert(child->data.child.arraypos == -1);
744 
745  SCIP_CALL( treeEnsureChildrenMem(tree, set, tree->nchildren+1) );
746  tree->children[tree->nchildren] = child;
747  tree->childrenprio[tree->nchildren] = nodeselprio;
748  child->data.child.arraypos = tree->nchildren;
749  tree->nchildren++;
750 
751  return SCIP_OKAY;
752 }
753 
754 /** removes given child node from the children array */
755 static
757  SCIP_TREE* tree, /**< branch and bound tree */
758  SCIP_NODE* child /**< child node to remove */
759  )
760 {
761  int delpos;
762 
763  assert(tree != NULL);
764  assert(child != NULL);
765  assert(SCIPnodeGetType(child) == SCIP_NODETYPE_CHILD);
766  assert(child->data.child.arraypos >= 0 && child->data.child.arraypos < tree->nchildren);
767  assert(tree->children[child->data.child.arraypos] == child);
768  assert(SCIPnodeGetType(tree->children[tree->nchildren-1]) == SCIP_NODETYPE_CHILD);
769 
770  delpos = child->data.child.arraypos;
771 
772  /* move last child in array to position of removed child */
773  tree->children[delpos] = tree->children[tree->nchildren-1];
774  tree->childrenprio[delpos] = tree->childrenprio[tree->nchildren-1];
775  tree->children[delpos]->data.child.arraypos = delpos;
776  child->data.child.arraypos = -1;
777  tree->nchildren--;
778 }
779 
780 /** makes node a child of the given parent node, which must be the focus node; if the child is a probing node,
781  * the parent node can also be a refocused node or a probing node
782  */
783 static
785  SCIP_NODE* node, /**< child node */
786  BMS_BLKMEM* blkmem, /**< block memory buffers */
787  SCIP_SET* set, /**< global SCIP settings */
788  SCIP_TREE* tree, /**< branch and bound tree */
789  SCIP_NODE* parent, /**< parent (= focus) node (or NULL, if node is root) */
790  SCIP_Real nodeselprio /**< node selection priority of child node */
791  )
792 {
793  assert(node != NULL);
794  assert(node->parent == NULL);
796  assert(node->conssetchg == NULL);
797  assert(node->domchg == NULL);
798  assert(SCIPsetIsInfinity(set, -node->lowerbound)); /* node was just created */
799  assert(blkmem != NULL);
800  assert(set != NULL);
801  assert(tree != NULL);
802  assert(SCIPtreeIsPathComplete(tree));
803  assert(tree->pathlen == 0 || tree->path[tree->pathlen-1] == parent);
804  assert(parent == tree->focusnode || SCIPnodeGetType(parent) == SCIP_NODETYPE_PROBINGNODE);
805  assert(parent == NULL || SCIPnodeGetType(parent) == SCIP_NODETYPE_FOCUSNODE
809 
810  /* link node to parent */
811  node->parent = parent;
812  if( parent != NULL )
813  {
814  assert(parent->lowerbound <= parent->estimate);
815  node->lowerbound = parent->lowerbound;
816  node->estimate = parent->estimate;
817  node->depth = parent->depth+1; /*lint !e732*/
818  if( parent->depth >= SCIP_MAXTREEDEPTH )
819  {
820  SCIPerrorMessage("maximal depth level exceeded\n");
821  return SCIP_MAXDEPTHLEVEL;
822  }
823  }
824  SCIPsetDebugMsg(set, "assigning parent #%" SCIP_LONGINT_FORMAT " to node #%" SCIP_LONGINT_FORMAT " at depth %d\n",
825  parent != NULL ? SCIPnodeGetNumber(parent) : -1, SCIPnodeGetNumber(node), SCIPnodeGetDepth(node));
826 
827  /* register node in the childlist of the focus (the parent) node */
828  if( SCIPnodeGetType(node) == SCIP_NODETYPE_CHILD )
829  {
830  assert(parent == NULL || SCIPnodeGetType(parent) == SCIP_NODETYPE_FOCUSNODE);
831  SCIP_CALL( treeAddChild(tree, set, node, nodeselprio) );
832  }
833 
834  return SCIP_OKAY;
835 }
836 
837 /** decreases number of children of the parent, frees it if no children are left */
838 static
840  SCIP_NODE* node, /**< child node */
841  BMS_BLKMEM* blkmem, /**< block memory buffer */
842  SCIP_SET* set, /**< global SCIP settings */
843  SCIP_STAT* stat, /**< problem statistics */
844  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
845  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
846  SCIP_TREE* tree, /**< branch and bound tree */
847  SCIP_LP* lp /**< current LP data */
848  )
849 {
850  SCIP_NODE* parent;
851 
852  assert(node != NULL);
853  assert(blkmem != NULL);
854  assert(tree != NULL);
855 
856  SCIPsetDebugMsg(set, "releasing parent-child relationship of node #%" SCIP_LONGINT_FORMAT " at depth %d of type %d with parent #%" SCIP_LONGINT_FORMAT " of type %d\n",
858  node->parent != NULL ? SCIPnodeGetNumber(node->parent) : -1,
859  node->parent != NULL ? (int)SCIPnodeGetType(node->parent) : -1);
860  parent = node->parent;
861  if( parent != NULL )
862  {
863  SCIP_Bool freeParent;
864  SCIP_Bool singleChild;
865 
866  freeParent = FALSE;
867  singleChild = FALSE;
868  switch( SCIPnodeGetType(parent) )
869  {
871  assert(parent->active);
873  || SCIPnodeGetType(node) == SCIP_NODETYPE_LEAF);
874  if( SCIPnodeGetType(node) == SCIP_NODETYPE_CHILD )
875  treeRemoveChild(tree, node);
876  /* don't kill the focus node at this point => freeParent = FALSE */
877  break;
879  assert(SCIPtreeProbing(tree));
880  /* probing nodes have to be freed individually => freeParent = FALSE */
881  break;
883  SCIPerrorMessage("sibling cannot be a parent node\n");
884  return SCIP_INVALIDDATA;
885  case SCIP_NODETYPE_CHILD:
886  SCIPerrorMessage("child cannot be a parent node\n");
887  return SCIP_INVALIDDATA;
888  case SCIP_NODETYPE_LEAF:
889  SCIPerrorMessage("leaf cannot be a parent node\n");
890  return SCIP_INVALIDDATA;
892  SCIPerrorMessage("dead-end cannot be a parent node\n");
893  return SCIP_INVALIDDATA;
895  assert(parent->data.junction.nchildren > 0);
896  parent->data.junction.nchildren--;
897  freeParent = (parent->data.junction.nchildren == 0); /* free parent if it has no more children */
898  singleChild = (parent->data.junction.nchildren == 1);
899  break;
901  assert(parent->data.pseudofork != NULL);
902  assert(parent->data.pseudofork->nchildren > 0);
903  parent->data.pseudofork->nchildren--;
904  freeParent = (parent->data.pseudofork->nchildren == 0); /* free parent if it has no more children */
905  singleChild = (parent->data.pseudofork->nchildren == 1);
906  break;
907  case SCIP_NODETYPE_FORK:
908  assert(parent->data.fork != NULL);
909  assert(parent->data.fork->nchildren > 0);
910  parent->data.fork->nchildren--;
911  freeParent = (parent->data.fork->nchildren == 0); /* free parent if it has no more children */
912  singleChild = (parent->data.fork->nchildren == 1);
913  break;
915  assert(parent->data.subroot != NULL);
916  assert(parent->data.subroot->nchildren > 0);
917  parent->data.subroot->nchildren--;
918  freeParent = (parent->data.subroot->nchildren == 0); /* free parent if it has no more children */
919  singleChild = (parent->data.subroot->nchildren == 1);
920  break;
922  /* the only possible child a refocused node can have in its refocus state is the probing root node;
923  * we don't want to free the refocused node, because we first have to convert it back to its original
924  * type (where it possibly has children) => freeParent = FALSE
925  */
927  assert(!SCIPtreeProbing(tree));
928  break;
929  default:
930  SCIPerrorMessage("unknown node type %d\n", SCIPnodeGetType(parent));
931  return SCIP_INVALIDDATA;
932  }
933 
934  /* free parent, if it is not on the current active path */
935  if( freeParent && !parent->active )
936  {
937  SCIP_CALL( SCIPnodeFree(&node->parent, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
938  }
939 
940  /* update the effective root depth
941  * in reoptimization we must not increase the effective root depth
942  */
943  assert(tree->effectiverootdepth >= 0);
944  if( singleChild && SCIPnodeGetDepth(parent) == tree->effectiverootdepth && !set->reopt_enable )
945  {
946  tree->effectiverootdepth++;
947  SCIPsetDebugMsg(set, "unlinked node #%" SCIP_LONGINT_FORMAT " in depth %d -> new effective root depth: %d\n",
949  }
950  }
951 
952  return SCIP_OKAY;
953 }
954 
955 /** creates a node data structure */
956 static
958  SCIP_NODE** node, /**< pointer to node data structure */
959  BMS_BLKMEM* blkmem, /**< block memory */
960  SCIP_SET* set /**< global SCIP settings */
961  )
962 {
963  assert(node != NULL);
964 
965  SCIP_ALLOC( BMSallocBlockMemory(blkmem, node) );
966  (*node)->parent = NULL;
967  (*node)->conssetchg = NULL;
968  (*node)->domchg = NULL;
969  (*node)->number = 0;
970  (*node)->lowerbound = -SCIPsetInfinity(set);
971  (*node)->estimate = -SCIPsetInfinity(set);
972  (*node)->reoptid = 0;
973  (*node)->reopttype = (unsigned int) SCIP_REOPTTYPE_NONE;
974  (*node)->depth = 0;
975  (*node)->active = FALSE;
976  (*node)->cutoff = FALSE;
977  (*node)->reprop = FALSE;
978  (*node)->repropsubtreemark = 0;
979 
980  return SCIP_OKAY;
981 }
982 
983 /** creates a child node of the focus node */
985  SCIP_NODE** node, /**< pointer to node data structure */
986  BMS_BLKMEM* blkmem, /**< block memory */
987  SCIP_SET* set, /**< global SCIP settings */
988  SCIP_STAT* stat, /**< problem statistics */
989  SCIP_TREE* tree, /**< branch and bound tree */
990  SCIP_Real nodeselprio, /**< node selection priority of new node */
991  SCIP_Real estimate /**< estimate for (transformed) objective value of best feasible solution in subtree */
992  )
993 {
994  assert(node != NULL);
995  assert(blkmem != NULL);
996  assert(set != NULL);
997  assert(stat != NULL);
998  assert(tree != NULL);
999  assert(SCIPtreeIsPathComplete(tree));
1000  assert(tree->pathlen == 0 || tree->path != NULL);
1001  assert((tree->pathlen == 0) == (tree->focusnode == NULL));
1002  assert(tree->focusnode == NULL || tree->focusnode == tree->path[tree->pathlen-1]);
1003  assert(tree->focusnode == NULL || SCIPnodeGetType(tree->focusnode) == SCIP_NODETYPE_FOCUSNODE);
1004 
1005  stat->ncreatednodes++;
1006  stat->ncreatednodesrun++;
1007 
1008  /* create the node data structure */
1009  SCIP_CALL( nodeCreate(node, blkmem, set) );
1010  (*node)->number = stat->ncreatednodesrun;
1011 
1012  /* mark node to be a child node */
1013  (*node)->nodetype = SCIP_NODETYPE_CHILD; /*lint !e641*/
1014  (*node)->data.child.arraypos = -1;
1015 
1016  /* make focus node the parent of the new child */
1017  SCIP_CALL( nodeAssignParent(*node, blkmem, set, tree, tree->focusnode, nodeselprio) );
1018 
1019  /* update the estimate of the child */
1020  SCIPnodeSetEstimate(*node, set, estimate);
1021 
1022  tree->lastbranchparentid = tree->focusnode == NULL ? -1L : SCIPnodeGetNumber(tree->focusnode);
1023 
1024  /* output node creation to visualization file */
1025  SCIP_CALL( SCIPvisualNewChild(stat->visual, set, stat, *node) );
1026 
1027  SCIPsetDebugMsg(set, "created child node #%" SCIP_LONGINT_FORMAT " at depth %u (prio: %g)\n", SCIPnodeGetNumber(*node), (*node)->depth, nodeselprio);
1028 
1029  return SCIP_OKAY;
1030 }
1031 
1032 /** query if focus node was already branched on */
1034  SCIP_TREE* tree, /**< branch and bound tree */
1035  SCIP_NODE* node /**< tree node, or NULL to check focus node */
1036  )
1037 {
1038  node = node == NULL ? tree->focusnode : node;
1039  if( node != NULL && node->number == tree->lastbranchparentid )
1040  return TRUE;
1041 
1042  return FALSE;
1043 }
1044 
1045 /** frees node */
1047  SCIP_NODE** node, /**< node data */
1048  BMS_BLKMEM* blkmem, /**< block memory buffer */
1049  SCIP_SET* set, /**< global SCIP settings */
1050  SCIP_STAT* stat, /**< problem statistics */
1051  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1052  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1053  SCIP_TREE* tree, /**< branch and bound tree */
1054  SCIP_LP* lp /**< current LP data */
1055  )
1056 {
1057  SCIP_Bool isroot;
1058 
1059  assert(node != NULL);
1060  assert(*node != NULL);
1061  assert(!(*node)->active);
1062  assert(blkmem != NULL);
1063  assert(tree != NULL);
1064 
1065  SCIPsetDebugMsg(set, "free node #%" SCIP_LONGINT_FORMAT " at depth %d of type %d\n", SCIPnodeGetNumber(*node), SCIPnodeGetDepth(*node), SCIPnodeGetType(*node));
1066 
1067  /* check lower bound w.r.t. debugging solution */
1068  SCIP_CALL( SCIPdebugCheckGlobalLowerbound(blkmem, set) );
1069 
1071  {
1072  SCIP_EVENT event;
1073 
1074  /* trigger a node deletion event */
1076  SCIP_CALL( SCIPeventChgNode(&event, *node) );
1077  SCIP_CALL( SCIPeventProcess(&event, set, NULL, NULL, NULL, eventfilter) );
1078  }
1079 
1080  /* inform solution debugger, that the node has been freed */
1081  SCIP_CALL( SCIPdebugRemoveNode(blkmem, set, *node) );
1082 
1083  /* check, if the node to be freed is the root node */
1084  isroot = (SCIPnodeGetDepth(*node) == 0);
1085 
1086  /* free nodetype specific data, and release no longer needed LPI states */
1087  switch( SCIPnodeGetType(*node) )
1088  {
1090  assert(tree->focusnode == *node);
1091  assert(!SCIPtreeProbing(tree));
1092  SCIPerrorMessage("cannot free focus node - has to be converted into a dead end first\n");
1093  return SCIP_INVALIDDATA;
1095  assert(SCIPtreeProbing(tree));
1096  assert(SCIPnodeGetDepth(tree->probingroot) <= SCIPnodeGetDepth(*node));
1097  assert(SCIPnodeGetDepth(*node) > 0);
1098  SCIP_CALL( probingnodeFree(&((*node)->data.probingnode), blkmem, lp) );
1099  break;
1100  case SCIP_NODETYPE_SIBLING:
1101  assert((*node)->data.sibling.arraypos >= 0);
1102  assert((*node)->data.sibling.arraypos < tree->nsiblings);
1103  assert(tree->siblings[(*node)->data.sibling.arraypos] == *node);
1104  if( tree->focuslpstatefork != NULL )
1105  {
1108  SCIP_CALL( SCIPnodeReleaseLPIState(tree->focuslpstatefork, blkmem, lp) );
1109  }
1110  treeRemoveSibling(tree, *node);
1111  break;
1112  case SCIP_NODETYPE_CHILD:
1113  assert((*node)->data.child.arraypos >= 0);
1114  assert((*node)->data.child.arraypos < tree->nchildren);
1115  assert(tree->children[(*node)->data.child.arraypos] == *node);
1116  /* The children capture the LPI state at the moment, where the focus node is
1117  * converted into a junction, pseudofork, fork, or subroot, and a new node is focused.
1118  * At the same time, they become siblings or leaves, such that freeing a child
1119  * of the focus node doesn't require to release the LPI state;
1120  * we don't need to call treeRemoveChild(), because this is done in nodeReleaseParent()
1121  */
1122  break;
1123  case SCIP_NODETYPE_LEAF:
1124  if( (*node)->data.leaf.lpstatefork != NULL )
1125  {
1126  SCIP_CALL( SCIPnodeReleaseLPIState((*node)->data.leaf.lpstatefork, blkmem, lp) );
1127  }
1128  break;
1129  case SCIP_NODETYPE_DEADEND:
1131  break;
1133  SCIP_CALL( pseudoforkFree(&((*node)->data.pseudofork), blkmem, set, lp) );
1134  break;
1135  case SCIP_NODETYPE_FORK:
1136 
1137  /* release special root LPI state capture which is used to keep the root LPI state over the whole solving
1138  * process
1139  */
1140  if( isroot )
1141  {
1142  SCIP_CALL( SCIPnodeReleaseLPIState(*node, blkmem, lp) );
1143  }
1144  SCIP_CALL( forkFree(&((*node)->data.fork), blkmem, set, lp) );
1145  break;
1146  case SCIP_NODETYPE_SUBROOT:
1147  SCIP_CALL( subrootFree(&((*node)->data.subroot), blkmem, set, lp) );
1148  break;
1150  SCIPerrorMessage("cannot free node as long it is refocused\n");
1151  return SCIP_INVALIDDATA;
1152  default:
1153  SCIPerrorMessage("unknown node type %d\n", SCIPnodeGetType(*node));
1154  return SCIP_INVALIDDATA;
1155  }
1156 
1157  /* free common data */
1158  SCIP_CALL( SCIPconssetchgFree(&(*node)->conssetchg, blkmem, set) );
1159  SCIP_CALL( SCIPdomchgFree(&(*node)->domchg, blkmem, set, eventqueue, lp) );
1160  SCIP_CALL( nodeReleaseParent(*node, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
1161 
1162  /* check, if the node is the current probing root */
1163  if( *node == tree->probingroot )
1164  {
1165  assert(SCIPnodeGetType(*node) == SCIP_NODETYPE_PROBINGNODE);
1166  tree->probingroot = NULL;
1167  }
1168 
1169  BMSfreeBlockMemory(blkmem, node);
1170 
1171  /* delete the tree's root node pointer, if the freed node was the root */
1172  if( isroot )
1173  tree->root = NULL;
1174 
1175  return SCIP_OKAY;
1176 }
1177 
1178 /** cuts off node and whole sub tree from branch and bound tree */
1180  SCIP_NODE* node, /**< node that should be cut off */
1181  SCIP_SET* set, /**< global SCIP settings */
1182  SCIP_STAT* stat, /**< problem statistics */
1183  SCIP_TREE* tree, /**< branch and bound tree */
1184  SCIP_PROB* transprob, /**< transformed problem after presolve */
1185  SCIP_PROB* origprob, /**< original problem */
1186  SCIP_REOPT* reopt, /**< reoptimization data structure */
1187  SCIP_LP* lp, /**< current LP */
1188  BMS_BLKMEM* blkmem /**< block memory */
1189  )
1190 {
1191  SCIP_Real oldbound;
1192 
1193  assert(node != NULL);
1194  assert(set != NULL);
1195  assert(stat != NULL);
1196  assert(tree != NULL);
1197 
1198  if( set->reopt_enable )
1199  {
1200  assert(reopt != NULL);
1201  /* check if the node should be stored for reoptimization */
1203  tree->root == node, tree->focusnode == node, node->lowerbound, tree->effectiverootdepth) );
1204  }
1205 
1206  oldbound = node->lowerbound;
1207  node->cutoff = TRUE;
1208  node->lowerbound = SCIPsetInfinity(set);
1209  node->estimate = SCIPsetInfinity(set);
1210  if( node->active )
1211  tree->cutoffdepth = MIN(tree->cutoffdepth, (int)node->depth);
1212 
1213  /* update primal integral */
1214  if( node->depth == 0 )
1215  {
1216  stat->rootlowerbound = SCIPsetInfinity(set);
1217  if( set->misc_calcintegral )
1218  SCIPstatUpdatePrimalDualIntegrals(stat, set, transprob, origprob, SCIPsetInfinity(set), SCIPsetInfinity(set));
1219  }
1220  else if( set->misc_calcintegral && SCIPsetIsEQ(set, oldbound, stat->lastlowerbound) )
1221  {
1222  SCIP_Real lowerbound;
1223  lowerbound = SCIPtreeGetLowerbound(tree, set);
1224 
1225  /* updating the primal integral is only necessary if dual bound has increased since last evaluation */
1226  if( lowerbound > stat->lastlowerbound )
1227  SCIPstatUpdatePrimalDualIntegrals(stat, set, transprob, origprob, SCIPsetInfinity(set), SCIPsetInfinity(set));
1228  }
1229 
1230  SCIPvisualCutoffNode(stat->visual, set, stat, node, TRUE);
1231 
1232  SCIPsetDebugMsg(set, "cutting off %s node #%" SCIP_LONGINT_FORMAT " at depth %d (cutoffdepth: %d)\n",
1233  node->active ? "active" : "inactive", SCIPnodeGetNumber(node), SCIPnodeGetDepth(node), tree->cutoffdepth);
1234 
1235  return SCIP_OKAY;
1236 }
1237 
1238 /** marks node, that propagation should be applied again the next time, a node of its subtree is focused */
1240  SCIP_NODE* node, /**< node that should be propagated again */
1241  SCIP_SET* set, /**< global SCIP settings */
1242  SCIP_STAT* stat, /**< problem statistics */
1243  SCIP_TREE* tree /**< branch and bound tree */
1244  )
1245 {
1246  assert(node != NULL);
1247  assert(set != NULL);
1248  assert(stat != NULL);
1249  assert(tree != NULL);
1250 
1251  if( !node->reprop )
1252  {
1253  node->reprop = TRUE;
1254  if( node->active )
1255  tree->repropdepth = MIN(tree->repropdepth, (int)node->depth);
1256 
1257  SCIPvisualMarkedRepropagateNode(stat->visual, stat, node);
1258 
1259  SCIPsetDebugMsg(set, "marked %s node #%" SCIP_LONGINT_FORMAT " at depth %d to be propagated again (repropdepth: %d)\n",
1260  node->active ? "active" : "inactive", SCIPnodeGetNumber(node), SCIPnodeGetDepth(node), tree->repropdepth);
1261  }
1262 }
1263 
1264 /** marks node, that it is completely propagated in the current repropagation subtree level */
1266  SCIP_NODE* node, /**< node that should be marked to be propagated */
1267  SCIP_TREE* tree /**< branch and bound tree */
1268  )
1269 {
1270  assert(node != NULL);
1271  assert(tree != NULL);
1272 
1273  if( node->parent != NULL )
1274  node->repropsubtreemark = node->parent->repropsubtreemark; /*lint !e732*/
1275  node->reprop = FALSE;
1276 
1277  /* if the node was the highest repropagation node in the path, update the repropdepth in the tree data */
1278  if( node->active && node->depth == tree->repropdepth )
1279  {
1280  do
1281  {
1282  assert(tree->repropdepth < tree->pathlen);
1283  assert(tree->path[tree->repropdepth]->active);
1284  assert(!tree->path[tree->repropdepth]->reprop);
1285  tree->repropdepth++;
1286  }
1287  while( tree->repropdepth < tree->pathlen && !tree->path[tree->repropdepth]->reprop );
1288  if( tree->repropdepth == tree->pathlen )
1289  tree->repropdepth = INT_MAX;
1290  }
1291 }
1292 
1293 /** moves the subtree repropagation counter to the next value */
1294 static
1296  SCIP_TREE* tree /**< branch and bound tree */
1297  )
1298 {
1299  assert(tree != NULL);
1300 
1301  tree->repropsubtreecount++;
1302  tree->repropsubtreecount %= (MAXREPROPMARK+1);
1303 }
1304 
1305 /** applies propagation on the node, that was marked to be propagated again */
1306 static
1308  SCIP_NODE* node, /**< node to apply propagation on */
1309  BMS_BLKMEM* blkmem, /**< block memory buffers */
1310  SCIP_SET* set, /**< global SCIP settings */
1311  SCIP_STAT* stat, /**< dynamic problem statistics */
1312  SCIP_PROB* transprob, /**< transformed problem */
1313  SCIP_PROB* origprob, /**< original problem */
1314  SCIP_PRIMAL* primal, /**< primal data */
1315  SCIP_TREE* tree, /**< branch and bound tree */
1316  SCIP_REOPT* reopt, /**< reoptimization data structure */
1317  SCIP_LP* lp, /**< current LP data */
1318  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
1319  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1320  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1321  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1322  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
1323  SCIP_Bool* cutoff /**< pointer to store whether the node can be cut off */
1324  )
1325 {
1326  SCIP_NODETYPE oldtype;
1327  SCIP_NODE* oldfocusnode;
1328  SCIP_NODE* oldfocuslpfork;
1329  SCIP_NODE* oldfocuslpstatefork;
1330  SCIP_NODE* oldfocussubroot;
1331  SCIP_Longint oldfocuslpstateforklpcount;
1332  int oldnchildren;
1333  int oldnsiblings;
1334  SCIP_Bool oldfocusnodehaslp;
1335  SCIP_Longint oldnboundchgs;
1336  SCIP_Bool initialreprop;
1337  SCIP_Bool clockisrunning;
1338 
1339  assert(node != NULL);
1345  assert(node->active);
1346  assert(node->reprop || node->repropsubtreemark != node->parent->repropsubtreemark);
1347  assert(stat != NULL);
1348  assert(tree != NULL);
1349  assert(SCIPeventqueueIsDelayed(eventqueue));
1350  assert(cutoff != NULL);
1351 
1352  SCIPsetDebugMsg(set, "propagating again node #%" SCIP_LONGINT_FORMAT " at depth %d\n", SCIPnodeGetNumber(node), SCIPnodeGetDepth(node));
1353  initialreprop = node->reprop;
1354 
1355  SCIPvisualRepropagatedNode(stat->visual, stat, node);
1356 
1357  /* process the delayed events in order to flush the problem changes */
1358  SCIP_CALL( SCIPeventqueueProcess(eventqueue, blkmem, set, primal, lp, branchcand, eventfilter) );
1359 
1360  /* stop node activation timer */
1361  clockisrunning = SCIPclockIsRunning(stat->nodeactivationtime);
1362  if( clockisrunning )
1363  SCIPclockStop(stat->nodeactivationtime, set);
1364 
1365  /* mark the node refocused and temporarily install it as focus node */
1366  oldtype = (SCIP_NODETYPE)node->nodetype;
1367  oldfocusnode = tree->focusnode;
1368  oldfocuslpfork = tree->focuslpfork;
1369  oldfocuslpstatefork = tree->focuslpstatefork;
1370  oldfocussubroot = tree->focussubroot;
1371  oldfocuslpstateforklpcount = tree->focuslpstateforklpcount;
1372  oldnchildren = tree->nchildren;
1373  oldnsiblings = tree->nsiblings;
1374  oldfocusnodehaslp = tree->focusnodehaslp;
1375  node->nodetype = SCIP_NODETYPE_REFOCUSNODE; /*lint !e641*/
1376  tree->focusnode = node;
1377  tree->focuslpfork = NULL;
1378  tree->focuslpstatefork = NULL;
1379  tree->focussubroot = NULL;
1380  tree->focuslpstateforklpcount = -1;
1381  tree->nchildren = 0;
1382  tree->nsiblings = 0;
1383  tree->focusnodehaslp = FALSE;
1384 
1385  /* propagate the domains again */
1386  oldnboundchgs = stat->nboundchgs;
1387  SCIP_CALL( SCIPpropagateDomains(blkmem, set, stat, transprob, origprob, tree, reopt, lp, branchcand,
1388  eventqueue, conflict, cliquetable, SCIPnodeGetDepth(node), 0, SCIP_PROPTIMING_ALWAYS, cutoff) );
1389  assert(!node->reprop || *cutoff);
1390  assert(node->parent == NULL || node->repropsubtreemark == node->parent->repropsubtreemark);
1392  assert(tree->focusnode == node);
1393  assert(tree->focuslpfork == NULL);
1394  assert(tree->focuslpstatefork == NULL);
1395  assert(tree->focussubroot == NULL);
1396  assert(tree->focuslpstateforklpcount == -1);
1397  assert(tree->nchildren == 0);
1398  assert(tree->nsiblings == 0);
1399  assert(tree->focusnodehaslp == FALSE);
1400  assert(stat->nboundchgs >= oldnboundchgs);
1401  stat->nreprops++;
1402  stat->nrepropboundchgs += stat->nboundchgs - oldnboundchgs;
1403  if( *cutoff )
1404  stat->nrepropcutoffs++;
1405 
1406  SCIPsetDebugMsg(set, "repropagation %" SCIP_LONGINT_FORMAT " at depth %u changed %" SCIP_LONGINT_FORMAT " bounds (total reprop bound changes: %" SCIP_LONGINT_FORMAT "), cutoff: %u\n",
1407  stat->nreprops, node->depth, stat->nboundchgs - oldnboundchgs, stat->nrepropboundchgs, *cutoff);
1408 
1409  /* if a propagation marked with the reprop flag was successful, we want to repropagate the whole subtree */
1410  /**@todo because repropsubtree is only a bit flag, we cannot mark a whole subtree a second time for
1411  * repropagation; use a (small) part of the node's bits to be able to store larger numbers,
1412  * and update tree->repropsubtreelevel with this number
1413  */
1414  if( initialreprop && !(*cutoff) && stat->nboundchgs > oldnboundchgs )
1415  {
1417  node->repropsubtreemark = tree->repropsubtreecount; /*lint !e732*/
1418  SCIPsetDebugMsg(set, "initial repropagation at depth %u changed %" SCIP_LONGINT_FORMAT " bounds -> repropagating subtree (new mark: %d)\n",
1419  node->depth, stat->nboundchgs - oldnboundchgs, tree->repropsubtreecount);
1420  assert((int)(node->repropsubtreemark) == tree->repropsubtreecount); /* bitfield must be large enough */
1421  }
1422 
1423  /* reset the node's type and reinstall the old focus node */
1424  node->nodetype = oldtype; /*lint !e641*/
1425  tree->focusnode = oldfocusnode;
1426  tree->focuslpfork = oldfocuslpfork;
1427  tree->focuslpstatefork = oldfocuslpstatefork;
1428  tree->focussubroot = oldfocussubroot;
1429  tree->focuslpstateforklpcount = oldfocuslpstateforklpcount;
1430  tree->nchildren = oldnchildren;
1431  tree->nsiblings = oldnsiblings;
1432  tree->focusnodehaslp = oldfocusnodehaslp;
1433 
1434  /* make the domain change data static again to save memory */
1436  {
1437  SCIP_CALL( SCIPdomchgMakeStatic(&node->domchg, blkmem, set, eventqueue, lp) );
1438  }
1439 
1440  /* start node activation timer again */
1441  if( clockisrunning )
1442  SCIPclockStart(stat->nodeactivationtime, set);
1443 
1444  /* delay events in path switching */
1445  SCIP_CALL( SCIPeventqueueDelay(eventqueue) );
1446 
1447  /* mark the node to be cut off if a cutoff was detected */
1448  if( *cutoff )
1449  {
1450  SCIP_CALL( SCIPnodeCutoff(node, set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
1451  }
1452 
1453  return SCIP_OKAY;
1454 }
1455 
1456 /** informs node, that it is now on the active path and applies any domain and constraint set changes */
1457 static
1459  SCIP_NODE* node, /**< node to activate */
1460  BMS_BLKMEM* blkmem, /**< block memory buffers */
1461  SCIP_SET* set, /**< global SCIP settings */
1462  SCIP_STAT* stat, /**< problem statistics */
1463  SCIP_PROB* transprob, /**< transformed problem */
1464  SCIP_PROB* origprob, /**< original problem */
1465  SCIP_PRIMAL* primal, /**< primal data */
1466  SCIP_TREE* tree, /**< branch and bound tree */
1467  SCIP_REOPT* reopt, /**< reotimization data structure */
1468  SCIP_LP* lp, /**< current LP data */
1469  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
1470  SCIP_CONFLICT* conflict, /**< conflict analysis data */
1471  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1472  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1473  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
1474  SCIP_Bool* cutoff /**< pointer to store whether the node can be cut off */
1475  )
1476 {
1477  assert(node != NULL);
1478  assert(!node->active);
1479  assert(stat != NULL);
1480  assert(tree != NULL);
1481  assert(!SCIPtreeProbing(tree));
1482  assert(cutoff != NULL);
1483 
1484  SCIPsetDebugMsg(set, "activate node #%" SCIP_LONGINT_FORMAT " at depth %d of type %d (reprop subtree mark: %u)\n",
1486 
1487  /* apply domain and constraint set changes */
1488  SCIP_CALL( SCIPconssetchgApply(node->conssetchg, blkmem, set, stat, (int) node->depth,
1490  SCIP_CALL( SCIPdomchgApply(node->domchg, blkmem, set, stat, lp, branchcand, eventqueue, (int) node->depth, cutoff) );
1491 
1492  /* mark node active */
1493  node->active = TRUE;
1494  stat->nactivatednodes++;
1495 
1496  /* check if the domain change produced a cutoff */
1497  if( *cutoff )
1498  {
1499  /* try to repropagate the node to see, if the propagation also leads to a conflict and a conflict constraint
1500  * could be generated; if propagation conflict analysis is turned off, repropagating the node makes no
1501  * sense, since it is already cut off
1502  */
1503  node->reprop = set->conf_enable && set->conf_useprop;
1504 
1505  /* mark the node to be cut off */
1506  SCIP_CALL( SCIPnodeCutoff(node, set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
1507  }
1508 
1509  /* propagate node again, if the reprop flag is set; in the new focus node, no repropagation is necessary, because
1510  * the focus node is propagated anyways
1511  */
1513  && (node->reprop || (node->parent != NULL && node->repropsubtreemark != node->parent->repropsubtreemark)) )
1514  {
1515  SCIP_Bool propcutoff;
1516 
1517  SCIP_CALL( nodeRepropagate(node, blkmem, set, stat, transprob, origprob, primal, tree, reopt, lp, branchcand, conflict,
1518  eventfilter, eventqueue, cliquetable, &propcutoff) );
1519  *cutoff = *cutoff || propcutoff;
1520  }
1521 
1522  return SCIP_OKAY;
1523 }
1524 
1525 /** informs node, that it is no longer on the active path and undoes any domain and constraint set changes */
1526 static
1528  SCIP_NODE* node, /**< node to deactivate */
1529  BMS_BLKMEM* blkmem, /**< block memory buffers */
1530  SCIP_SET* set, /**< global SCIP settings */
1531  SCIP_STAT* stat, /**< problem statistics */
1532  SCIP_TREE* tree, /**< branch and bound tree */
1533  SCIP_LP* lp, /**< current LP data */
1534  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
1535  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1536  SCIP_EVENTQUEUE* eventqueue /**< event queue */
1537  )
1538 {
1539  SCIP_Bool freeNode;
1540 
1541  assert(node != NULL);
1542  assert(node->active);
1543  assert(tree != NULL);
1544  assert(SCIPnodeGetType(node) != SCIP_NODETYPE_FOCUSNODE);
1545 
1546  SCIPsetDebugMsg(set, "deactivate node #%" SCIP_LONGINT_FORMAT " at depth %d of type %d (reprop subtree mark: %u)\n",
1548 
1549  /* undo domain and constraint set changes */
1550  SCIP_CALL( SCIPdomchgUndo(node->domchg, blkmem, set, stat, lp, branchcand, eventqueue) );
1551  SCIP_CALL( SCIPconssetchgUndo(node->conssetchg, blkmem, set, stat) );
1552 
1553  /* mark node inactive */
1554  node->active = FALSE;
1555 
1556  /* count number of deactivated nodes (ignoring probing switches) */
1557  if( !SCIPtreeProbing(tree) )
1558  stat->ndeactivatednodes++;
1559 
1560  /* free node if it is a dead-end node, i.e., has no children */
1561  switch( SCIPnodeGetType(node) )
1562  {
1565  case SCIP_NODETYPE_SIBLING:
1566  case SCIP_NODETYPE_CHILD:
1567  case SCIP_NODETYPE_LEAF:
1568  case SCIP_NODETYPE_DEADEND:
1570  freeNode = FALSE;
1571  break;
1573  freeNode = (node->data.junction.nchildren == 0);
1574  break;
1576  freeNode = (node->data.pseudofork->nchildren == 0);
1577  break;
1578  case SCIP_NODETYPE_FORK:
1579  freeNode = (node->data.fork->nchildren == 0);
1580  break;
1581  case SCIP_NODETYPE_SUBROOT:
1582  freeNode = (node->data.subroot->nchildren == 0);
1583  break;
1584  default:
1585  SCIPerrorMessage("unknown node type %d\n", SCIPnodeGetType(node));
1586  return SCIP_INVALIDDATA;
1587  }
1588  if( freeNode )
1589  {
1590  SCIP_CALL( SCIPnodeFree(&node, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
1591  }
1592 
1593  return SCIP_OKAY;
1594 }
1595 
1596 /** adds constraint locally to the node and captures it; activates constraint, if node is active;
1597  * if a local constraint is added to the root node, it is automatically upgraded into a global constraint
1598  */
1600  SCIP_NODE* node, /**< node to add constraint to */
1601  BMS_BLKMEM* blkmem, /**< block memory */
1602  SCIP_SET* set, /**< global SCIP settings */
1603  SCIP_STAT* stat, /**< problem statistics */
1604  SCIP_TREE* tree, /**< branch and bound tree */
1605  SCIP_CONS* cons /**< constraint to add */
1606  )
1607 {
1608  assert(node != NULL);
1609  assert(cons != NULL);
1610  assert(cons->validdepth <= SCIPnodeGetDepth(node));
1611  assert(tree != NULL);
1612  assert(tree->effectiverootdepth >= 0);
1613  assert(tree->root != NULL);
1614  assert(SCIPconsIsGlobal(cons) || SCIPnodeGetDepth(node) > tree->effectiverootdepth);
1615 
1616 #ifndef NDEBUG
1617  /* check if we add this constraint to the same scip, where we create the constraint */
1618  if( cons->scip != set->scip )
1619  {
1620  SCIPerrorMessage("try to add a constraint of another scip instance\n");
1621  return SCIP_INVALIDDATA;
1622  }
1623 #endif
1624 
1625  /* add constraint addition to the node's constraint set change data, and activate constraint if node is active */
1626  SCIP_CALL( SCIPconssetchgAddAddedCons(&node->conssetchg, blkmem, set, stat, cons, (int) node->depth,
1627  (SCIPnodeGetType(node) == SCIP_NODETYPE_FOCUSNODE), node->active) );
1628  assert(node->conssetchg != NULL);
1629  assert(node->conssetchg->addedconss != NULL);
1630  assert(!node->active || SCIPconsIsActive(cons));
1631 
1632  /* if the constraint is added to an active node which is not a probing node, increment the corresponding counter */
1633  if( node->active && SCIPnodeGetType(node) != SCIP_NODETYPE_PROBINGNODE )
1634  stat->nactiveconssadded++;
1635 
1636  return SCIP_OKAY;
1637 }
1638 
1639 /** locally deletes constraint at the given node by disabling its separation, enforcing, and propagation capabilities
1640  * at the node; captures constraint; disables constraint, if node is active
1641  */
1643  SCIP_NODE* node, /**< node to add constraint to */
1644  BMS_BLKMEM* blkmem, /**< block memory */
1645  SCIP_SET* set, /**< global SCIP settings */
1646  SCIP_STAT* stat, /**< problem statistics */
1647  SCIP_TREE* tree, /**< branch and bound tree */
1648  SCIP_CONS* cons /**< constraint to locally delete */
1649  )
1650 {
1651  assert(node != NULL);
1652  assert(tree != NULL);
1653  assert(cons != NULL);
1654 
1655  SCIPsetDebugMsg(set, "disabling constraint <%s> at node at depth %u\n", cons->name, node->depth);
1656 
1657  /* add constraint disabling to the node's constraint set change data */
1658  SCIP_CALL( SCIPconssetchgAddDisabledCons(&node->conssetchg, blkmem, set, cons) );
1659  assert(node->conssetchg != NULL);
1660  assert(node->conssetchg->disabledconss != NULL);
1661 
1662  /* disable constraint, if node is active */
1663  if( node->active && cons->enabled && !cons->updatedisable )
1664  {
1665  SCIP_CALL( SCIPconsDisable(cons, set, stat) );
1666  }
1667 
1668  return SCIP_OKAY;
1669 }
1670 
1671 /** returns all constraints added to a given node */
1673  SCIP_NODE* node, /**< node */
1674  SCIP_CONS** addedconss, /**< array to store the constraints */
1675  int* naddedconss, /**< number of added constraints */
1676  int addedconsssize /**< size of the constraint array */
1677  )
1678 {
1679  int cons;
1680 
1681  assert(node != NULL );
1682  assert(node->conssetchg != NULL);
1683  assert(node->conssetchg->addedconss != NULL);
1684  assert(node->conssetchg->naddedconss >= 1);
1685 
1686  *naddedconss = node->conssetchg->naddedconss;
1687 
1688  /* check the size and return if the array is not large enough */
1689  if( addedconsssize < *naddedconss )
1690  return;
1691 
1692  /* fill the array */
1693  for( cons = 0; cons < *naddedconss; cons++ )
1694  {
1695  addedconss[cons] = node->conssetchg->addedconss[cons];
1696  }
1697 
1698  return;
1699 }
1700 
1701 /** returns the number of added constraints to the given node */
1703  SCIP_NODE* node /**< node */
1704  )
1705 {
1706  assert(node != NULL);
1707 
1708  if( node->conssetchg == NULL )
1709  return 0;
1710  else
1711  return node->conssetchg->naddedconss;
1712 }
1713 
1714 /** adds the given bound change to the list of pending bound changes */
1715 static
1717  SCIP_TREE* tree, /**< branch and bound tree */
1718  SCIP_SET* set, /**< global SCIP settings */
1719  SCIP_NODE* node, /**< node to add bound change to */
1720  SCIP_VAR* var, /**< variable to change the bounds for */
1721  SCIP_Real newbound, /**< new value for bound */
1722  SCIP_BOUNDTYPE boundtype, /**< type of bound: lower or upper bound */
1723  SCIP_CONS* infercons, /**< constraint that deduced the bound change, or NULL */
1724  SCIP_PROP* inferprop, /**< propagator that deduced the bound change, or NULL */
1725  int inferinfo, /**< user information for inference to help resolving the conflict */
1726  SCIP_Bool probingchange /**< is the bound change a temporary setting due to probing? */
1727  )
1728 {
1729  assert(tree != NULL);
1730 
1731  /* make sure that enough memory is allocated for the pendingbdchgs array */
1732  SCIP_CALL( treeEnsurePendingbdchgsMem(tree, set, tree->npendingbdchgs+1) );
1733 
1734  /* capture the variable */
1735  SCIPvarCapture(var);
1736 
1737  /* add the bound change to the pending list */
1738  tree->pendingbdchgs[tree->npendingbdchgs].node = node;
1739  tree->pendingbdchgs[tree->npendingbdchgs].var = var;
1740  tree->pendingbdchgs[tree->npendingbdchgs].newbound = newbound;
1741  tree->pendingbdchgs[tree->npendingbdchgs].boundtype = boundtype;
1742  tree->pendingbdchgs[tree->npendingbdchgs].infercons = infercons;
1743  tree->pendingbdchgs[tree->npendingbdchgs].inferprop = inferprop;
1744  tree->pendingbdchgs[tree->npendingbdchgs].inferinfo = inferinfo;
1745  tree->pendingbdchgs[tree->npendingbdchgs].probingchange = probingchange;
1746  tree->npendingbdchgs++;
1747 
1748  /* check global pending boundchanges against debug solution */
1749  if( node->depth == 0 )
1750  {
1751 #ifndef NDEBUG
1752  SCIP_Real bound = newbound;
1753 
1754  /* get bound adjusted for integrality(, this should already be done) */
1755  SCIPvarAdjustBd(var, set, boundtype, &bound);
1756 
1757  if( boundtype == SCIP_BOUNDTYPE_LOWER )
1758  {
1759  /* check that the bound is feasible */
1760  if( bound > SCIPvarGetUbGlobal(var) )
1761  {
1762  /* due to numerics we only want to be feasible in feasibility tolerance */
1763  assert(SCIPsetIsFeasLE(set, bound, SCIPvarGetUbGlobal(var)));
1764  bound = SCIPvarGetUbGlobal(var);
1765  }
1766  }
1767  else
1768  {
1769  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
1770 
1771  /* check that the bound is feasible */
1772  if( bound < SCIPvarGetLbGlobal(var) )
1773  {
1774  /* due to numerics we only want to be feasible in feasibility tolerance */
1775  assert(SCIPsetIsFeasGE(set, bound, SCIPvarGetLbGlobal(var)));
1776  bound = SCIPvarGetLbGlobal(var);
1777  }
1778  }
1779  /* check that the given bound was already adjusted for integrality */
1780  assert(SCIPsetIsEQ(set, newbound, bound));
1781 #endif
1782  if( boundtype == SCIP_BOUNDTYPE_LOWER )
1783  {
1784  /* check bound on debugging solution */
1785  SCIP_CALL( SCIPdebugCheckLbGlobal(set->scip, var, newbound) ); /*lint !e506 !e774*/
1786  }
1787  else
1788  {
1789  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
1790 
1791  /* check bound on debugging solution */
1792  SCIP_CALL( SCIPdebugCheckUbGlobal(set->scip, var, newbound) ); /*lint !e506 !e774*/
1793  }
1794  }
1795 
1796  return SCIP_OKAY;
1797 }
1798 
1799 /** adds bound change with inference information to focus node, child of focus node, or probing node;
1800  * if possible, adjusts bound to integral value;
1801  * at most one of infercons and inferprop may be non-NULL
1802  */
1804  SCIP_NODE* node, /**< node to add bound change to */
1805  BMS_BLKMEM* blkmem, /**< block memory */
1806  SCIP_SET* set, /**< global SCIP settings */
1807  SCIP_STAT* stat, /**< problem statistics */
1808  SCIP_PROB* transprob, /**< transformed problem after presolve */
1809  SCIP_PROB* origprob, /**< original problem */
1810  SCIP_TREE* tree, /**< branch and bound tree */
1811  SCIP_REOPT* reopt, /**< reoptimization data structure */
1812  SCIP_LP* lp, /**< current LP data */
1813  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
1814  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1815  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
1816  SCIP_VAR* var, /**< variable to change the bounds for */
1817  SCIP_Real newbound, /**< new value for bound */
1818  SCIP_BOUNDTYPE boundtype, /**< type of bound: lower or upper bound */
1819  SCIP_CONS* infercons, /**< constraint that deduced the bound change, or NULL */
1820  SCIP_PROP* inferprop, /**< propagator that deduced the bound change, or NULL */
1821  int inferinfo, /**< user information for inference to help resolving the conflict */
1822  SCIP_Bool probingchange /**< is the bound change a temporary setting due to probing? */
1823  )
1824 {
1825  SCIP_VAR* infervar;
1826  SCIP_BOUNDTYPE inferboundtype;
1827  SCIP_Real oldlb;
1828  SCIP_Real oldub;
1829  SCIP_Real oldbound;
1830  SCIP_Bool useglobal;
1831 
1832  useglobal = (int) node->depth <= tree->effectiverootdepth;
1833  if( useglobal )
1834  {
1835  oldlb = SCIPvarGetLbGlobal(var);
1836  oldub = SCIPvarGetUbGlobal(var);
1837  }
1838  else
1839  {
1840  oldlb = SCIPvarGetLbLocal(var);
1841  oldub = SCIPvarGetUbLocal(var);
1842  }
1843 
1844  assert(node != NULL);
1849  || node->depth == 0);
1850  assert(set != NULL);
1851  assert(tree != NULL);
1852  assert(tree->effectiverootdepth >= 0);
1853  assert(tree->root != NULL);
1854  assert(var != NULL);
1855  assert(node->active || (infercons == NULL && inferprop == NULL));
1856  assert((SCIP_NODETYPE)node->nodetype == SCIP_NODETYPE_PROBINGNODE || !probingchange);
1857  assert((boundtype == SCIP_BOUNDTYPE_LOWER && SCIPsetIsGT(set, newbound, oldlb))
1858  || (boundtype == SCIP_BOUNDTYPE_LOWER && newbound > oldlb && newbound * oldlb <= 0.0)
1859  || (boundtype == SCIP_BOUNDTYPE_UPPER && SCIPsetIsLT(set, newbound, oldub))
1860  || (boundtype == SCIP_BOUNDTYPE_UPPER && newbound < oldub && newbound * oldub <= 0.0));
1861 
1862  SCIPsetDebugMsg(set, "adding boundchange at node %llu at depth %u to variable <%s>: old bounds=[%g,%g], new %s bound: %g (infer%s=<%s>, inferinfo=%d)\n",
1863  node->number, node->depth, SCIPvarGetName(var), SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var),
1864  boundtype == SCIP_BOUNDTYPE_LOWER ? "lower" : "upper", newbound, infercons != NULL ? "cons" : "prop",
1865  infercons != NULL ? SCIPconsGetName(infercons) : (inferprop != NULL ? SCIPpropGetName(inferprop) : "-"), inferinfo);
1866 
1867  /* remember variable as inference variable, and get corresponding active variable, bound and bound type */
1868  infervar = var;
1869  inferboundtype = boundtype;
1870 
1871  SCIP_CALL( SCIPvarGetProbvarBound(&var, &newbound, &boundtype) );
1872 
1874  {
1875  SCIPerrorMessage("cannot change bounds of multi-aggregated variable <%s>\n", SCIPvarGetName(var));
1876  SCIPABORT();
1877  return SCIP_INVALIDDATA; /*lint !e527*/
1878  }
1880 
1881  /* the variable may have changed, make sure we have the correct bounds */
1882  if( useglobal )
1883  {
1884  oldlb = SCIPvarGetLbGlobal(var);
1885  oldub = SCIPvarGetUbGlobal(var);
1886  }
1887  else
1888  {
1889  oldlb = SCIPvarGetLbLocal(var);
1890  oldub = SCIPvarGetUbLocal(var);
1891  }
1892  assert(SCIPsetIsLE(set, oldlb, oldub));
1893 
1894  if( boundtype == SCIP_BOUNDTYPE_LOWER )
1895  {
1896  /* adjust lower bound w.r.t. to integrality */
1897  SCIPvarAdjustLb(var, set, &newbound);
1898  assert(SCIPsetIsFeasLE(set, newbound, oldub));
1899  oldbound = oldlb;
1900  newbound = MIN(newbound, oldub);
1901 
1902  if ( set->stage == SCIP_STAGE_SOLVING && SCIPsetIsInfinity(set, newbound) )
1903  {
1904  SCIPerrorMessage("cannot change lower bound of variable <%s> to infinity.\n", SCIPvarGetName(var));
1905  SCIPABORT();
1906  return SCIP_INVALIDDATA; /*lint !e527*/
1907  }
1908  }
1909  else
1910  {
1911  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
1912 
1913  /* adjust the new upper bound */
1914  SCIPvarAdjustUb(var, set, &newbound);
1915  assert(SCIPsetIsFeasGE(set, newbound, oldlb));
1916  oldbound = oldub;
1917  newbound = MAX(newbound, oldlb);
1918 
1919  if ( set->stage == SCIP_STAGE_SOLVING && SCIPsetIsInfinity(set, -newbound) )
1920  {
1921  SCIPerrorMessage("cannot change upper bound of variable <%s> to minus infinity.\n", SCIPvarGetName(var));
1922  SCIPABORT();
1923  return SCIP_INVALIDDATA; /*lint !e527*/
1924  }
1925  }
1926 
1927  /* after switching to the active variable, the bounds might become redundant
1928  * if this happens, ignore the bound change
1929  */
1930  if( (boundtype == SCIP_BOUNDTYPE_LOWER && !SCIPsetIsGT(set, newbound, oldlb))
1931  || (boundtype == SCIP_BOUNDTYPE_UPPER && !SCIPsetIsLT(set, newbound, oldub)) )
1932  return SCIP_OKAY;
1933 
1934  SCIPsetDebugMsg(set, " -> transformed to active variable <%s>: old bounds=[%g,%g], new %s bound: %g, obj: %g\n",
1935  SCIPvarGetName(var), oldlb, oldub, boundtype == SCIP_BOUNDTYPE_LOWER ? "lower" : "upper", newbound,
1936  SCIPvarGetObj(var));
1937 
1938  /* if the bound change takes place at an active node but is conflicting with the current local bounds,
1939  * we cannot apply it immediately because this would introduce inconsistencies to the bound change data structures
1940  * in the tree and to the bound change information data in the variable;
1941  * instead we have to remember the bound change as a pending bound change and mark the affected nodes on the active
1942  * path to be infeasible
1943  */
1944  if( node->active )
1945  {
1946  int conflictingdepth;
1947 
1948  conflictingdepth = SCIPvarGetConflictingBdchgDepth(var, set, boundtype, newbound);
1949 
1950  if( conflictingdepth >= 0 )
1951  {
1952  /* 0 would mean the bound change conflicts with a global bound */
1953  assert(conflictingdepth > 0);
1954  assert(conflictingdepth < tree->pathlen);
1955 
1956  SCIPsetDebugMsg(set, " -> bound change <%s> %s %g violates current local bounds [%g,%g] since depth %d: remember for later application\n",
1957  SCIPvarGetName(var), boundtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", newbound,
1958  SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var), conflictingdepth);
1959 
1960  /* remember the pending bound change */
1961  SCIP_CALL( treeAddPendingBdchg(tree, set, node, var, newbound, boundtype, infercons, inferprop, inferinfo,
1962  probingchange) );
1963 
1964  /* mark the node with the conflicting bound change to be cut off */
1965  SCIP_CALL( SCIPnodeCutoff(tree->path[conflictingdepth], set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
1966 
1967  return SCIP_OKAY;
1968  }
1969  }
1970 
1971  SCIPstatIncrement(stat, set, nboundchgs);
1972 
1973  /* if we are in probing mode we have to additionally count the bound changes for the probing statistic */
1974  if( tree->probingroot != NULL )
1975  SCIPstatIncrement(stat, set, nprobboundchgs);
1976 
1977  /* if the node is the root node: change local and global bound immediately */
1978  if( SCIPnodeGetDepth(node) <= tree->effectiverootdepth )
1979  {
1980  assert(node->active || tree->focusnode == NULL );
1981  assert(SCIPnodeGetType(node) != SCIP_NODETYPE_PROBINGNODE);
1982  assert(!probingchange);
1983 
1984  SCIPsetDebugMsg(set, " -> bound change in root node: perform global bound change\n");
1985  SCIP_CALL( SCIPvarChgBdGlobal(var, blkmem, set, stat, lp, branchcand, eventqueue, cliquetable, newbound, boundtype) );
1986 
1987  if( set->stage == SCIP_STAGE_SOLVING )
1988  {
1989  /* the root should be repropagated due to the bound change */
1990  SCIPnodePropagateAgain(tree->root, set, stat, tree);
1991  SCIPsetDebugMsg(set, "marked root node to be repropagated due to global bound change <%s>:[%g,%g] -> [%g,%g] found in depth %u\n",
1992  SCIPvarGetName(var), oldlb, oldub, boundtype == SCIP_BOUNDTYPE_LOWER ? newbound : oldlb,
1993  boundtype == SCIP_BOUNDTYPE_LOWER ? oldub : newbound, node->depth);
1994  }
1995 
1996  return SCIP_OKAY;
1997  }
1998 
1999  /* if the node is a child, or the bound is a temporary probing bound
2000  * - the bound change is a branching decision
2001  * - the child's lower bound can be updated due to the changed pseudo solution
2002  * otherwise:
2003  * - the bound change is an inference
2004  */
2005  if( SCIPnodeGetType(node) == SCIP_NODETYPE_CHILD || probingchange )
2006  {
2007  SCIP_Real newpseudoobjval;
2008  SCIP_Real lpsolval;
2009 
2010  assert(!node->active || SCIPnodeGetType(node) == SCIP_NODETYPE_PROBINGNODE);
2011 
2012  /* get the solution value of variable in last solved LP on the active path:
2013  * - if the LP was solved at the current node, the LP values of the columns are valid
2014  * - if the last solved LP was the one in the current lpstatefork, the LP value in the columns are still valid
2015  * - otherwise, the LP values are invalid
2016  */
2017  if( SCIPtreeHasCurrentNodeLP(tree)
2019  {
2020  lpsolval = SCIPvarGetLPSol(var);
2021  }
2022  else
2023  lpsolval = SCIP_INVALID;
2024 
2025  /* remember the bound change as branching decision (infervar/infercons/inferprop are not important: use NULL) */
2026  SCIP_CALL( SCIPdomchgAddBoundchg(&node->domchg, blkmem, set, var, newbound, boundtype, SCIP_BOUNDCHGTYPE_BRANCHING,
2027  lpsolval, NULL, NULL, NULL, 0, inferboundtype) );
2028 
2029  /* update the child's lower bound */
2030  if( set->misc_exactsolve )
2031  newpseudoobjval = SCIPlpGetModifiedProvedPseudoObjval(lp, set, var, oldbound, newbound, boundtype);
2032  else
2033  newpseudoobjval = SCIPlpGetModifiedPseudoObjval(lp, set, transprob, var, oldbound, newbound, boundtype);
2034  SCIPnodeUpdateLowerbound(node, stat, set, tree, transprob, origprob, newpseudoobjval);
2035  }
2036  else
2037  {
2038  /* check the infered bound change on the debugging solution */
2039  SCIP_CALL( SCIPdebugCheckInference(blkmem, set, node, var, newbound, boundtype) ); /*lint !e506 !e774*/
2040 
2041  /* remember the bound change as inference (lpsolval is not important: use 0.0) */
2042  SCIP_CALL( SCIPdomchgAddBoundchg(&node->domchg, blkmem, set, var, newbound, boundtype,
2044  0.0, infervar, infercons, inferprop, inferinfo, inferboundtype) );
2045  }
2046 
2047  assert(node->domchg != NULL);
2048  assert(node->domchg->domchgdyn.domchgtype == SCIP_DOMCHGTYPE_DYNAMIC); /*lint !e641*/
2049  assert(node->domchg->domchgdyn.boundchgs != NULL);
2050  assert(node->domchg->domchgdyn.nboundchgs > 0);
2051  assert(node->domchg->domchgdyn.boundchgs[node->domchg->domchgdyn.nboundchgs-1].var == var);
2052  assert(node->domchg->domchgdyn.boundchgs[node->domchg->domchgdyn.nboundchgs-1].newbound == newbound); /*lint !e777*/
2053 
2054  /* if node is active, apply the bound change immediately */
2055  if( node->active )
2056  {
2057  SCIP_Bool cutoff;
2058 
2059  /**@todo if the node is active, it currently must either be the effective root (see above) or the current node;
2060  * if a bound change to an intermediate active node should be added, we must make sure, the bound change
2061  * information array of the variable stays sorted (new info must be sorted in instead of putting it to
2062  * the end of the array), and we should identify now redundant bound changes that are applied at a
2063  * later node on the active path
2064  */
2065  assert(SCIPtreeGetCurrentNode(tree) == node);
2067  blkmem, set, stat, lp, branchcand, eventqueue, (int) node->depth, node->domchg->domchgdyn.nboundchgs-1, &cutoff) );
2068  assert(node->domchg->domchgdyn.boundchgs[node->domchg->domchgdyn.nboundchgs-1].var == var);
2069  assert(!cutoff);
2070  }
2071 
2072  return SCIP_OKAY;
2073 }
2074 
2075 /** adds bound change to focus node, or child of focus node, or probing node;
2076  * if possible, adjusts bound to integral value
2077  */
2079  SCIP_NODE* node, /**< node to add bound change to */
2080  BMS_BLKMEM* blkmem, /**< block memory */
2081  SCIP_SET* set, /**< global SCIP settings */
2082  SCIP_STAT* stat, /**< problem statistics */
2083  SCIP_PROB* transprob, /**< transformed problem after presolve */
2084  SCIP_PROB* origprob, /**< original problem */
2085  SCIP_TREE* tree, /**< branch and bound tree */
2086  SCIP_REOPT* reopt, /**< reoptimization data structure */
2087  SCIP_LP* lp, /**< current LP data */
2088  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
2089  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2090  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
2091  SCIP_VAR* var, /**< variable to change the bounds for */
2092  SCIP_Real newbound, /**< new value for bound */
2093  SCIP_BOUNDTYPE boundtype, /**< type of bound: lower or upper bound */
2094  SCIP_Bool probingchange /**< is the bound change a temporary setting due to probing? */
2095  )
2096 {
2097  SCIP_CALL( SCIPnodeAddBoundinfer(node, blkmem, set, stat, transprob, origprob, tree, reopt, lp, branchcand, eventqueue,
2098  cliquetable, var, newbound, boundtype, NULL, NULL, 0, probingchange) );
2099 
2100  return SCIP_OKAY;
2101 }
2102 
2103 /** adds hole with inference information to focus node, child of focus node, or probing node;
2104  * if possible, adjusts bound to integral value;
2105  * at most one of infercons and inferprop may be non-NULL
2106  */
2108  SCIP_NODE* node, /**< node to add bound change to */
2109  BMS_BLKMEM* blkmem, /**< block memory */
2110  SCIP_SET* set, /**< global SCIP settings */
2111  SCIP_STAT* stat, /**< problem statistics */
2112  SCIP_TREE* tree, /**< branch and bound tree */
2113  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2114  SCIP_VAR* var, /**< variable to change the bounds for */
2115  SCIP_Real left, /**< left bound of open interval defining the hole (left,right) */
2116  SCIP_Real right, /**< right bound of open interval defining the hole (left,right) */
2117  SCIP_CONS* infercons, /**< constraint that deduced the bound change, or NULL */
2118  SCIP_PROP* inferprop, /**< propagator that deduced the bound change, or NULL */
2119  int inferinfo, /**< user information for inference to help resolving the conflict */
2120  SCIP_Bool probingchange, /**< is the bound change a temporary setting due to probing? */
2121  SCIP_Bool* added /**< pointer to store whether the hole was added, or NULL */
2122  )
2123 {
2124 #if 0
2125  SCIP_VAR* infervar;
2126 #endif
2127 
2128  assert(node != NULL);
2133  || node->depth == 0);
2134  assert(blkmem != NULL);
2135  assert(set != NULL);
2136  assert(tree != NULL);
2137  assert(tree->effectiverootdepth >= 0);
2138  assert(tree->root != NULL);
2139  assert(var != NULL);
2140  assert(node->active || (infercons == NULL && inferprop == NULL));
2141  assert((SCIP_NODETYPE)node->nodetype == SCIP_NODETYPE_PROBINGNODE || !probingchange);
2142 
2143  /* the interval should not be empty */
2144  assert(SCIPsetIsLT(set, left, right));
2145 
2146 #ifndef NDEBUG
2147  {
2148  SCIP_Real adjustedleft;
2149  SCIP_Real adjustedright;
2150 
2151  adjustedleft = left;
2152  adjustedright = right;
2153 
2154  SCIPvarAdjustUb(var, set, &adjustedleft);
2155  SCIPvarAdjustLb(var, set, &adjustedright);
2156 
2157  assert(SCIPsetIsEQ(set, left, adjustedleft));
2158  assert(SCIPsetIsEQ(set, right, adjustedright));
2159  }
2160 #endif
2161 
2162  /* the hole should lay within the lower and upper bounds */
2163  assert(SCIPsetIsGE(set, left, SCIPvarGetLbLocal(var)));
2164  assert(SCIPsetIsLE(set, right, SCIPvarGetUbLocal(var)));
2165 
2166  SCIPsetDebugMsg(set, "adding hole (%g,%g) at node at depth %u to variable <%s>: bounds=[%g,%g], (infer%s=<%s>, inferinfo=%d)\n",
2167  left, right, node->depth, SCIPvarGetName(var), SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var), infercons != NULL ? "cons" : "prop",
2168  infercons != NULL ? SCIPconsGetName(infercons) : (inferprop != NULL ? SCIPpropGetName(inferprop) : "-"), inferinfo);
2169 
2170 #if 0
2171  /* remember variable as inference variable, and get corresponding active variable, bound and bound type */
2172  infervar = var;
2173 #endif
2174  SCIP_CALL( SCIPvarGetProbvarHole(&var, &left, &right) );
2175 
2177  {
2178  SCIPerrorMessage("cannot change bounds of multi-aggregated variable <%s>\n", SCIPvarGetName(var));
2179  SCIPABORT();
2180  return SCIP_INVALIDDATA; /*lint !e527*/
2181  }
2183 
2184  SCIPsetDebugMsg(set, " -> transformed to active variable <%s>: hole (%g,%g), obj: %g\n", SCIPvarGetName(var), left, right, SCIPvarGetObj(var));
2185 
2186  stat->nholechgs++;
2187 
2188  /* if we are in probing mode we have to additionally count the bound changes for the probing statistic */
2189  if( tree->probingroot != NULL )
2190  stat->nprobholechgs++;
2191 
2192  /* if the node is the root node: change local and global bound immediately */
2193  if( SCIPnodeGetDepth(node) <= tree->effectiverootdepth )
2194  {
2195  assert(node->active || tree->focusnode == NULL );
2196  assert(SCIPnodeGetType(node) != SCIP_NODETYPE_PROBINGNODE);
2197  assert(!probingchange);
2198 
2199  SCIPsetDebugMsg(set, " -> hole added in root node: perform global domain change\n");
2200  SCIP_CALL( SCIPvarAddHoleGlobal(var, blkmem, set, stat, eventqueue, left, right, added) );
2201 
2202  if( set->stage == SCIP_STAGE_SOLVING && (*added) )
2203  {
2204  /* the root should be repropagated due to the bound change */
2205  SCIPnodePropagateAgain(tree->root, set, stat, tree);
2206  SCIPsetDebugMsg(set, "marked root node to be repropagated due to global added hole <%s>: (%g,%g) found in depth %u\n",
2207  SCIPvarGetName(var), left, right, node->depth);
2208  }
2209 
2210  return SCIP_OKAY;
2211  }
2212 
2213  /**@todo add adding of local domain holes */
2214 
2215  (*added) = FALSE;
2216  SCIPerrorMessage("WARNING: currently domain holes can only be handled globally!\n");
2217 
2218  stat->nholechgs--;
2219 
2220  /* if we are in probing mode we have to additionally count the bound changes for the probing statistic */
2221  if( tree->probingroot != NULL )
2222  stat->nprobholechgs--;
2223 
2224  return SCIP_OKAY;
2225 }
2226 
2227 /** adds hole change to focus node, or child of focus node */
2229  SCIP_NODE* node, /**< node to add bound change to */
2230  BMS_BLKMEM* blkmem, /**< block memory */
2231  SCIP_SET* set, /**< global SCIP settings */
2232  SCIP_STAT* stat, /**< problem statistics */
2233  SCIP_TREE* tree, /**< branch and bound tree */
2234  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2235  SCIP_VAR* var, /**< variable to change the bounds for */
2236  SCIP_Real left, /**< left bound of open interval defining the hole (left,right) */
2237  SCIP_Real right, /**< right bound of open interval defining the hole (left,right) */
2238  SCIP_Bool probingchange, /**< is the bound change a temporary setting due to probing? */
2239  SCIP_Bool* added /**< pointer to store whether the hole was added, or NULL */
2240  )
2241 {
2242  assert(node != NULL);
2246  assert(blkmem != NULL);
2247 
2248  SCIPsetDebugMsg(set, "adding hole (%g,%g) at node at depth %u of variable <%s>\n",
2249  left, right, node->depth, SCIPvarGetName(var));
2250 
2251  SCIP_CALL( SCIPnodeAddHoleinfer(node, blkmem, set, stat, tree, eventqueue, var, left, right,
2252  NULL, NULL, 0, probingchange, added) );
2253 
2254  /**@todo apply hole change on active nodes and issue event */
2255 
2256  return SCIP_OKAY;
2257 }
2258 
2259 /** applies the pending bound changes */
2260 static
2262  SCIP_TREE* tree, /**< branch and bound tree */
2263  SCIP_REOPT* reopt, /**< reoptimization data structure */
2264  BMS_BLKMEM* blkmem, /**< block memory */
2265  SCIP_SET* set, /**< global SCIP settings */
2266  SCIP_STAT* stat, /**< problem statistics */
2267  SCIP_PROB* transprob, /**< transformed problem after presolve */
2268  SCIP_PROB* origprob, /**< original problem */
2269  SCIP_LP* lp, /**< current LP data */
2270  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
2271  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2272  SCIP_CLIQUETABLE* cliquetable /**< clique table data structure */
2273  )
2274 {
2275  SCIP_VAR* var;
2276  int npendingbdchgs;
2277  int conflictdepth;
2278  int i;
2279 
2280  assert(tree != NULL);
2281 
2282  npendingbdchgs = tree->npendingbdchgs;
2283  for( i = 0; i < npendingbdchgs; ++i )
2284  {
2285  var = tree->pendingbdchgs[i].var;
2286  assert(SCIPnodeGetDepth(tree->pendingbdchgs[i].node) < tree->cutoffdepth);
2287 
2288  conflictdepth = SCIPvarGetConflictingBdchgDepth(var, set, tree->pendingbdchgs[i].boundtype,
2289  tree->pendingbdchgs[i].newbound);
2290 
2291  /* It can happen, that a pending bound change conflicts with the global bounds, because when it was collected, it
2292  * just conflicted with the local bounds, but a conflicting global bound change was applied afterwards. In this
2293  * case, we can cut off the node where the pending bound change should be applied.
2294  */
2295  if( conflictdepth == 0 )
2296  {
2297  SCIP_CALL( SCIPnodeCutoff(tree->pendingbdchgs[i].node, set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
2298 
2299  if( ((int) tree->pendingbdchgs[i].node->depth) <= tree->effectiverootdepth )
2300  break; /* break here to clear all pending bound changes */
2301  else
2302  continue;
2303  }
2304 
2305  assert(conflictdepth == -1);
2306 
2307  SCIPsetDebugMsg(set, "applying pending bound change <%s>[%g,%g] %s %g\n", SCIPvarGetName(var),
2309  tree->pendingbdchgs[i].boundtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
2310  tree->pendingbdchgs[i].newbound);
2311 
2312  /* ignore bounds that are now redundant (for example, multiple entries in the pendingbdchgs for the same
2313  * variable)
2314  */
2315  if( tree->pendingbdchgs[i].boundtype == SCIP_BOUNDTYPE_LOWER )
2316  {
2317  SCIP_Real lb;
2318 
2319  lb = SCIPvarGetLbLocal(var);
2320  if( !SCIPsetIsGT(set, tree->pendingbdchgs[i].newbound, lb) )
2321  continue;
2322  }
2323  else
2324  {
2325  SCIP_Real ub;
2326 
2327  assert(tree->pendingbdchgs[i].boundtype == SCIP_BOUNDTYPE_UPPER);
2328  ub = SCIPvarGetUbLocal(var);
2329  if( !SCIPsetIsLT(set, tree->pendingbdchgs[i].newbound, ub) )
2330  continue;
2331  }
2332 
2333  SCIP_CALL( SCIPnodeAddBoundinfer(tree->pendingbdchgs[i].node, blkmem, set, stat, transprob, origprob, tree, reopt,
2334  lp, branchcand, eventqueue, cliquetable, var, tree->pendingbdchgs[i].newbound, tree->pendingbdchgs[i].boundtype,
2336  tree->pendingbdchgs[i].probingchange) );
2337  assert(tree->npendingbdchgs == npendingbdchgs); /* this time, the bound change can be applied! */
2338  }
2339 
2340  /* clear pending bound changes */
2341  for( i = 0; i < tree->npendingbdchgs; ++i )
2342  {
2343  var = tree->pendingbdchgs[i].var;
2344  assert(var != NULL);
2345 
2346  /* release the variable */
2347  SCIP_CALL( SCIPvarRelease(&var, blkmem, set, eventqueue, lp) );
2348  }
2349 
2350  tree->npendingbdchgs = 0;
2351 
2352  return SCIP_OKAY;
2353 }
2354 
2355 /** if given value is larger than the node's lower bound, sets the node's lower bound to the new value */
2357  SCIP_NODE* node, /**< node to update lower bound for */
2358  SCIP_STAT* stat, /**< problem statistics */
2359  SCIP_SET* set, /**< global SCIP settings */
2360  SCIP_TREE* tree, /**< branch and bound tree */
2361  SCIP_PROB* transprob, /**< transformed problem after presolve */
2362  SCIP_PROB* origprob, /**< original problem */
2363  SCIP_Real newbound /**< new lower bound for the node (if it's larger than the old one) */
2364  )
2365 {
2366  assert(node != NULL);
2367  assert(stat != NULL);
2368 
2369  if( newbound > node->lowerbound )
2370  {
2371  SCIP_Real oldbound;
2372 
2373  oldbound = node->lowerbound;
2374  node->lowerbound = newbound;
2375  node->estimate = MAX(node->estimate, newbound);
2376 
2377  if( node->depth == 0 )
2378  {
2379  stat->rootlowerbound = newbound;
2380  if( set->misc_calcintegral )
2381  SCIPstatUpdatePrimalDualIntegrals(stat, set, transprob, origprob, SCIPsetInfinity(set), newbound);
2382  SCIPvisualLowerbound(stat->visual, set, stat, newbound);
2383  }
2384  else if ( SCIPnodeGetType(node) != SCIP_NODETYPE_PROBINGNODE )
2385  {
2386  SCIP_Real lowerbound;
2387 
2388  lowerbound = SCIPtreeGetLowerbound(tree, set);
2389  assert(newbound >= lowerbound);
2390  SCIPvisualLowerbound(stat->visual, set, stat, lowerbound);
2391 
2392  /* updating the primal integral is only necessary if dual bound has increased since last evaluation */
2393  if( set->misc_calcintegral && SCIPsetIsEQ(set, oldbound, stat->lastlowerbound) && lowerbound > stat->lastlowerbound )
2394  SCIPstatUpdatePrimalDualIntegrals(stat, set, transprob, origprob, SCIPsetInfinity(set), lowerbound);
2395  }
2396  }
2397 }
2398 
2399 /** updates lower bound of node using lower bound of LP */
2401  SCIP_NODE* node, /**< node to set lower bound for */
2402  SCIP_SET* set, /**< global SCIP settings */
2403  SCIP_STAT* stat, /**< problem statistics */
2404  SCIP_TREE* tree, /**< branch and bound tree */
2405  SCIP_PROB* transprob, /**< transformed problem after presolve */
2406  SCIP_PROB* origprob, /**< original problem */
2407  SCIP_LP* lp /**< LP data */
2408  )
2409 {
2410  SCIP_Real lpobjval;
2411 
2412  assert(set != NULL);
2413  assert(lp->flushed);
2414 
2415  /* in case of iteration or time limit, the LP value may not be a valid dual bound */
2416  /* @todo check for dual feasibility of LP solution and use sub-optimal solution if they are dual feasible */
2418  return SCIP_OKAY;
2419 
2420  if( set->misc_exactsolve )
2421  {
2422  SCIP_CALL( SCIPlpGetProvedLowerbound(lp, set, &lpobjval) );
2423  }
2424  else
2425  lpobjval = SCIPlpGetObjval(lp, set, transprob);
2426 
2427  SCIPnodeUpdateLowerbound(node, stat, set, tree, transprob, origprob, lpobjval);
2428 
2429  return SCIP_OKAY;
2430 }
2431 
2432 
2433 /** change the node selection priority of the given child */
2435  SCIP_TREE* tree, /**< branch and bound tree */
2436  SCIP_NODE* child, /**< child to update the node selection priority */
2437  SCIP_Real priority /**< node selection priority value */
2438  )
2439 {
2440  int pos;
2441 
2442  assert( SCIPnodeGetType(child) == SCIP_NODETYPE_CHILD );
2443 
2444  pos = child->data.child.arraypos;
2445  assert( pos >= 0 );
2446 
2447  tree->childrenprio[pos] = priority;
2448 }
2449 
2450 
2451 /** sets the node's estimated bound to the new value */
2453  SCIP_NODE* node, /**< node to update lower bound for */
2454  SCIP_SET* set, /**< global SCIP settings */
2455  SCIP_Real newestimate /**< new estimated bound for the node */
2456  )
2457 {
2458  assert(node != NULL);
2459  assert(set != NULL);
2460  assert(SCIPsetIsRelGE(set, newestimate, node->lowerbound));
2461 
2462  /* due to numerical reasons we need this check, see https://git.zib.de/integer/scip/issues/2866 */
2463  if( node->lowerbound <= newestimate )
2464  node->estimate = newestimate;
2465 }
2466 
2467 /** propagates implications of binary fixings at the given node triggered by the implication graph and the clique table */
2469  SCIP_NODE* node, /**< node to propagate implications on */
2470  BMS_BLKMEM* blkmem, /**< block memory */
2471  SCIP_SET* set, /**< global SCIP settings */
2472  SCIP_STAT* stat, /**< problem statistics */
2473  SCIP_PROB* transprob, /**< transformed problem after presolve */
2474  SCIP_PROB* origprob, /**< original problem */
2475  SCIP_TREE* tree, /**< branch and bound tree */
2476  SCIP_REOPT* reopt, /**< reoptimization data structure */
2477  SCIP_LP* lp, /**< current LP data */
2478  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
2479  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
2480  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
2481  SCIP_Bool* cutoff /**< pointer to store whether the node can be cut off */
2482  )
2483 {
2484  int nboundchgs;
2485  int i;
2486 
2487  assert(node != NULL);
2488  assert(SCIPnodeIsActive(node));
2492  assert(cutoff != NULL);
2493 
2494  SCIPsetDebugMsg(set, "implication graph propagation of node #%" SCIP_LONGINT_FORMAT " in depth %d\n",
2495  SCIPnodeGetNumber(node), SCIPnodeGetDepth(node));
2496 
2497  *cutoff = FALSE;
2498 
2499  /* propagate all fixings of binary variables performed at this node */
2500  nboundchgs = SCIPdomchgGetNBoundchgs(node->domchg);
2501  for( i = 0; i < nboundchgs && !(*cutoff); ++i )
2502  {
2503  SCIP_BOUNDCHG* boundchg;
2504  SCIP_VAR* var;
2505 
2506  boundchg = SCIPdomchgGetBoundchg(node->domchg, i);
2507 
2508  /* ignore redundant bound changes */
2509  if( SCIPboundchgIsRedundant(boundchg) )
2510  continue;
2511 
2512  var = SCIPboundchgGetVar(boundchg);
2513  if( SCIPvarIsBinary(var) )
2514  {
2515  SCIP_Bool varfixing;
2516  int nimpls;
2517  SCIP_VAR** implvars;
2518  SCIP_BOUNDTYPE* impltypes;
2519  SCIP_Real* implbounds;
2520  SCIP_CLIQUE** cliques;
2521  int ncliques;
2522  int j;
2523 
2524  varfixing = (SCIPboundchgGetBoundtype(boundchg) == SCIP_BOUNDTYPE_LOWER);
2525  nimpls = SCIPvarGetNImpls(var, varfixing);
2526  implvars = SCIPvarGetImplVars(var, varfixing);
2527  impltypes = SCIPvarGetImplTypes(var, varfixing);
2528  implbounds = SCIPvarGetImplBounds(var, varfixing);
2529 
2530  /* apply implications */
2531  for( j = 0; j < nimpls; ++j )
2532  {
2533  SCIP_Real lb;
2534  SCIP_Real ub;
2535 
2536  /* @note should this be checked here (because SCIPnodeAddBoundinfer fails for multi-aggregated variables)
2537  * or should SCIPnodeAddBoundinfer() just return for multi-aggregated variables?
2538  */
2539  if( SCIPvarGetStatus(implvars[j]) == SCIP_VARSTATUS_MULTAGGR ||
2541  continue;
2542 
2543  /* check for infeasibility */
2544  lb = SCIPvarGetLbLocal(implvars[j]);
2545  ub = SCIPvarGetUbLocal(implvars[j]);
2546  if( impltypes[j] == SCIP_BOUNDTYPE_LOWER )
2547  {
2548  if( SCIPsetIsFeasGT(set, implbounds[j], ub) )
2549  {
2550  *cutoff = TRUE;
2551  return SCIP_OKAY;
2552  }
2553  if( SCIPsetIsFeasLE(set, implbounds[j], lb) )
2554  continue;
2555  }
2556  else
2557  {
2558  if( SCIPsetIsFeasLT(set, implbounds[j], lb) )
2559  {
2560  *cutoff = TRUE;
2561  return SCIP_OKAY;
2562  }
2563  if( SCIPsetIsFeasGE(set, implbounds[j], ub) )
2564  continue;
2565  }
2566 
2567  /* @note the implication might affect a fixed variable (after resolving (multi-)aggregations);
2568  * normally, the implication should have been deleted in that case, but this is only possible
2569  * if the implied variable has the reverse implication stored as a variable bound;
2570  * due to numerics, the variable bound may not be present and so the implication is not deleted
2571  */
2573  continue;
2574 
2575  /* apply the implication */
2576  SCIP_CALL( SCIPnodeAddBoundinfer(node, blkmem, set, stat, transprob, origprob, tree, reopt, lp, branchcand,
2577  eventqueue, cliquetable, implvars[j], implbounds[j], impltypes[j], NULL, NULL, 0, FALSE) );
2578  }
2579 
2580  /* apply cliques */
2581  ncliques = SCIPvarGetNCliques(var, varfixing);
2582  cliques = SCIPvarGetCliques(var, varfixing);
2583  for( j = 0; j < ncliques; ++j )
2584  {
2585  SCIP_VAR** vars;
2586  SCIP_Bool* values;
2587  int nvars;
2588  int k;
2589 
2590  nvars = SCIPcliqueGetNVars(cliques[j]);
2591  vars = SCIPcliqueGetVars(cliques[j]);
2592  values = SCIPcliqueGetValues(cliques[j]);
2593  for( k = 0; k < nvars; ++k )
2594  {
2595  SCIP_Real lb;
2596  SCIP_Real ub;
2597 
2598  assert(SCIPvarIsBinary(vars[k]));
2599 
2600  if( SCIPvarGetStatus(vars[k]) == SCIP_VARSTATUS_MULTAGGR ||
2602  continue;
2603 
2604  if( vars[k] == var && values[k] == varfixing )
2605  continue;
2606 
2607  /* check for infeasibility */
2608  lb = SCIPvarGetLbLocal(vars[k]);
2609  ub = SCIPvarGetUbLocal(vars[k]);
2610  if( values[k] == FALSE )
2611  {
2612  if( ub < 0.5 )
2613  {
2614  *cutoff = TRUE;
2615  return SCIP_OKAY;
2616  }
2617  if( lb > 0.5 )
2618  continue;
2619  }
2620  else
2621  {
2622  if( lb > 0.5 )
2623  {
2624  *cutoff = TRUE;
2625  return SCIP_OKAY;
2626  }
2627  if( ub < 0.5 )
2628  continue;
2629  }
2630 
2632  continue;
2633 
2634  /* apply the clique implication */
2635  SCIP_CALL( SCIPnodeAddBoundinfer(node, blkmem, set, stat, transprob, origprob, tree, reopt, lp, branchcand,
2636  eventqueue, cliquetable, vars[k], (SCIP_Real)(!values[k]), values[k] ? SCIP_BOUNDTYPE_UPPER : SCIP_BOUNDTYPE_LOWER,
2637  NULL, NULL, 0, FALSE) );
2638  }
2639  }
2640  }
2641  }
2642 
2643  return SCIP_OKAY;
2644 }
2645 
2646 
2647 
2648 
2649 /*
2650  * Path Switching
2651  */
2652 
2653 /** updates the LP sizes of the active path starting at the given depth */
2654 static
2656  SCIP_TREE* tree, /**< branch and bound tree */
2657  int startdepth /**< depth to start counting */
2658  )
2659 {
2660  SCIP_NODE* node;
2661  int ncols;
2662  int nrows;
2663  int i;
2664 
2665  assert(tree != NULL);
2666  assert(startdepth >= 0);
2667  assert(startdepth <= tree->pathlen);
2668 
2669  if( startdepth == 0 )
2670  {
2671  ncols = 0;
2672  nrows = 0;
2673  }
2674  else
2675  {
2676  ncols = tree->pathnlpcols[startdepth-1];
2677  nrows = tree->pathnlprows[startdepth-1];
2678  }
2679 
2680  for( i = startdepth; i < tree->pathlen; ++i )
2681  {
2682  node = tree->path[i];
2683  assert(node != NULL);
2684  assert(node->active);
2685  assert((int)(node->depth) == i);
2686 
2687  switch( SCIPnodeGetType(node) )
2688  {
2690  assert(i == tree->pathlen-1 || SCIPtreeProbing(tree));
2691  break;
2693  assert(SCIPtreeProbing(tree));
2694  assert(i >= 1);
2695  assert(SCIPnodeGetType(tree->path[i-1]) == SCIP_NODETYPE_FOCUSNODE
2696  || (ncols == node->data.probingnode->ninitialcols && nrows == node->data.probingnode->ninitialrows));
2697  assert(ncols <= node->data.probingnode->ncols || !tree->focuslpconstructed);
2698  assert(nrows <= node->data.probingnode->nrows || !tree->focuslpconstructed);
2699  if( i < tree->pathlen-1 )
2700  {
2701  ncols = node->data.probingnode->ncols;
2702  nrows = node->data.probingnode->nrows;
2703  }
2704  else
2705  {
2706  /* for the current probing node, the initial LP size is stored in the path */
2707  ncols = node->data.probingnode->ninitialcols;
2708  nrows = node->data.probingnode->ninitialrows;
2709  }
2710  break;
2711  case SCIP_NODETYPE_SIBLING:
2712  SCIPerrorMessage("sibling cannot be in the active path\n");
2713  SCIPABORT();
2714  return SCIP_INVALIDDATA; /*lint !e527*/
2715  case SCIP_NODETYPE_CHILD:
2716  SCIPerrorMessage("child cannot be in the active path\n");
2717  SCIPABORT();
2718  return SCIP_INVALIDDATA; /*lint !e527*/
2719  case SCIP_NODETYPE_LEAF:
2720  SCIPerrorMessage("leaf cannot be in the active path\n");
2721  SCIPABORT();
2722  return SCIP_INVALIDDATA; /*lint !e527*/
2723  case SCIP_NODETYPE_DEADEND:
2724  SCIPerrorMessage("dead-end cannot be in the active path\n");
2725  SCIPABORT();
2726  return SCIP_INVALIDDATA; /*lint !e527*/
2728  break;
2730  assert(node->data.pseudofork != NULL);
2731  ncols += node->data.pseudofork->naddedcols;
2732  nrows += node->data.pseudofork->naddedrows;
2733  break;
2734  case SCIP_NODETYPE_FORK:
2735  assert(node->data.fork != NULL);
2736  ncols += node->data.fork->naddedcols;
2737  nrows += node->data.fork->naddedrows;
2738  break;
2739  case SCIP_NODETYPE_SUBROOT:
2740  assert(node->data.subroot != NULL);
2741  ncols = node->data.subroot->ncols;
2742  nrows = node->data.subroot->nrows;
2743  break;
2745  SCIPerrorMessage("node cannot be of type REFOCUSNODE at this point\n");
2746  SCIPABORT();
2747  return SCIP_INVALIDDATA; /*lint !e527*/
2748  default:
2749  SCIPerrorMessage("unknown node type %d\n", SCIPnodeGetType(node));
2750  SCIPABORT();
2751  return SCIP_INVALIDDATA; /*lint !e527*/
2752  }
2753  tree->pathnlpcols[i] = ncols;
2754  tree->pathnlprows[i] = nrows;
2755  }
2756  return SCIP_OKAY;
2757 }
2758 
2759 /** finds the common fork node, the new LP state defining fork, and the new focus subroot, if the path is switched to
2760  * the given node
2761  */
2762 static
2764  SCIP_TREE* tree, /**< branch and bound tree */
2765  SCIP_NODE* node, /**< new focus node, or NULL */
2766  SCIP_NODE** commonfork, /**< pointer to store common fork node of old and new focus node */
2767  SCIP_NODE** newlpfork, /**< pointer to store the new LP defining fork node */
2768  SCIP_NODE** newlpstatefork, /**< pointer to store the new LP state defining fork node */
2769  SCIP_NODE** newsubroot, /**< pointer to store the new subroot node */
2770  SCIP_Bool* cutoff /**< pointer to store whether the given node can be cut off and no path switching
2771  * should be performed */
2772  )
2773 {
2774  SCIP_NODE* fork;
2775  SCIP_NODE* lpfork;
2776  SCIP_NODE* lpstatefork;
2777  SCIP_NODE* subroot;
2778 
2779  assert(tree != NULL);
2780  assert(tree->root != NULL);
2781  assert((tree->focusnode == NULL) == !tree->root->active);
2782  assert(tree->focuslpfork == NULL || tree->focusnode != NULL);
2783  assert(tree->focuslpfork == NULL || tree->focuslpfork->depth < tree->focusnode->depth);
2784  assert(tree->focuslpstatefork == NULL || tree->focuslpfork != NULL);
2785  assert(tree->focuslpstatefork == NULL || tree->focuslpstatefork->depth <= tree->focuslpfork->depth);
2786  assert(tree->focussubroot == NULL || tree->focuslpstatefork != NULL);
2787  assert(tree->focussubroot == NULL || tree->focussubroot->depth <= tree->focuslpstatefork->depth);
2788  assert(tree->cutoffdepth >= 0);
2789  assert(tree->cutoffdepth == INT_MAX || tree->cutoffdepth < tree->pathlen);
2790  assert(tree->cutoffdepth == INT_MAX || tree->path[tree->cutoffdepth]->cutoff);
2791  assert(tree->repropdepth >= 0);
2792  assert(tree->repropdepth == INT_MAX || tree->repropdepth < tree->pathlen);
2793  assert(tree->repropdepth == INT_MAX || tree->path[tree->repropdepth]->reprop);
2794  assert(commonfork != NULL);
2795  assert(newlpfork != NULL);
2796  assert(newlpstatefork != NULL);
2797  assert(newsubroot != NULL);
2798  assert(cutoff != NULL);
2799 
2800  *commonfork = NULL;
2801  *newlpfork = NULL;
2802  *newlpstatefork = NULL;
2803  *newsubroot = NULL;
2804  *cutoff = FALSE;
2805 
2806  /* if the new focus node is NULL, there is no common fork node, and the new LP fork, LP state fork, and subroot
2807  * are NULL
2808  */
2809  if( node == NULL )
2810  {
2811  tree->cutoffdepth = INT_MAX;
2812  tree->repropdepth = INT_MAX;
2813  return;
2814  }
2815 
2816  /* check if the new node is marked to be cut off */
2817  if( node->cutoff )
2818  {
2819  *cutoff = TRUE;
2820  return;
2821  }
2822 
2823  /* if the old focus node is NULL, there is no common fork node, and we have to search the new LP fork, LP state fork
2824  * and subroot
2825  */
2826  if( tree->focusnode == NULL )
2827  {
2828  assert(!tree->root->active);
2829  assert(tree->pathlen == 0);
2830  assert(tree->cutoffdepth == INT_MAX);
2831  assert(tree->repropdepth == INT_MAX);
2832 
2833  lpfork = node;
2834  while( SCIPnodeGetType(lpfork) != SCIP_NODETYPE_PSEUDOFORK
2836  {
2837  lpfork = lpfork->parent;
2838  if( lpfork == NULL )
2839  return;
2840  if( lpfork->cutoff )
2841  {
2842  *cutoff = TRUE;
2843  return;
2844  }
2845  }
2846  *newlpfork = lpfork;
2847 
2848  lpstatefork = lpfork;
2849  while( SCIPnodeGetType(lpstatefork) != SCIP_NODETYPE_FORK && SCIPnodeGetType(lpstatefork) != SCIP_NODETYPE_SUBROOT )
2850  {
2851  lpstatefork = lpstatefork->parent;
2852  if( lpstatefork == NULL )
2853  return;
2854  if( lpstatefork->cutoff )
2855  {
2856  *cutoff = TRUE;
2857  return;
2858  }
2859  }
2860  *newlpstatefork = lpstatefork;
2861 
2862  subroot = lpstatefork;
2863  while( SCIPnodeGetType(subroot) != SCIP_NODETYPE_SUBROOT )
2864  {
2865  subroot = subroot->parent;
2866  if( subroot == NULL )
2867  return;
2868  if( subroot->cutoff )
2869  {
2870  *cutoff = TRUE;
2871  return;
2872  }
2873  }
2874  *newsubroot = subroot;
2875 
2876  fork = subroot;
2877  while( fork->parent != NULL )
2878  {
2879  fork = fork->parent;
2880  if( fork->cutoff )
2881  {
2882  *cutoff = TRUE;
2883  return;
2884  }
2885  }
2886  return;
2887  }
2888 
2889  /* find the common fork node, the new LP defining fork, the new LP state defining fork, and the new focus subroot */
2890  fork = node;
2891  lpfork = NULL;
2892  lpstatefork = NULL;
2893  subroot = NULL;
2894  assert(fork != NULL);
2895 
2896  while( !fork->active )
2897  {
2898  fork = fork->parent;
2899  assert(fork != NULL); /* because the root is active, there must be a common fork node */
2900 
2901  if( fork->cutoff )
2902  {
2903  *cutoff = TRUE;
2904  return;
2905  }
2906  if( lpfork == NULL
2909  lpfork = fork;
2910  if( lpstatefork == NULL
2912  lpstatefork = fork;
2913  if( subroot == NULL && SCIPnodeGetType(fork) == SCIP_NODETYPE_SUBROOT )
2914  subroot = fork;
2915  }
2916  assert(lpfork == NULL || !lpfork->active || lpfork == fork);
2917  assert(lpstatefork == NULL || !lpstatefork->active || lpstatefork == fork);
2918  assert(subroot == NULL || !subroot->active || subroot == fork);
2919  SCIPdebugMessage("find switch forks: forkdepth=%u\n", fork->depth);
2920 
2921  /* if the common fork node is below the current cutoff depth, the cutoff node is an ancestor of the common fork
2922  * and thus an ancestor of the new focus node, s.t. the new node can also be cut off
2923  */
2924  assert((int)fork->depth != tree->cutoffdepth);
2925  if( (int)fork->depth > tree->cutoffdepth )
2926  {
2927 #ifndef NDEBUG
2928  while( !fork->cutoff )
2929  {
2930  fork = fork->parent;
2931  assert(fork != NULL);
2932  }
2933  assert((int)fork->depth >= tree->cutoffdepth);
2934 #endif
2935  *cutoff = TRUE;
2936  return;
2937  }
2938  tree->cutoffdepth = INT_MAX;
2939 
2940  /* if not already found, continue searching the LP defining fork; it cannot be deeper than the common fork */
2941  if( lpfork == NULL )
2942  {
2943  if( tree->focuslpfork != NULL && (int)(tree->focuslpfork->depth) > fork->depth )
2944  {
2945  /* focuslpfork is not on the same active path as the new node: we have to continue searching */
2946  lpfork = fork;
2947  while( lpfork != NULL
2949  && SCIPnodeGetType(lpfork) != SCIP_NODETYPE_FORK
2950  && SCIPnodeGetType(lpfork) != SCIP_NODETYPE_SUBROOT )
2951  {
2952  assert(lpfork->active);
2953  lpfork = lpfork->parent;
2954  }
2955  }
2956  else
2957  {
2958  /* focuslpfork is on the same active path as the new node: old and new node have the same lpfork */
2959  lpfork = tree->focuslpfork;
2960  }
2961  assert(lpfork == NULL || (int)(lpfork->depth) <= fork->depth);
2962  assert(lpfork == NULL || lpfork->active);
2963  }
2964  assert(lpfork == NULL
2966  || SCIPnodeGetType(lpfork) == SCIP_NODETYPE_FORK
2967  || SCIPnodeGetType(lpfork) == SCIP_NODETYPE_SUBROOT);
2968  SCIPdebugMessage("find switch forks: lpforkdepth=%d\n", lpfork == NULL ? -1 : (int)(lpfork->depth));
2969 
2970  /* if not already found, continue searching the LP state defining fork; it cannot be deeper than the
2971  * LP defining fork and the common fork
2972  */
2973  if( lpstatefork == NULL )
2974  {
2975  if( tree->focuslpstatefork != NULL && (int)(tree->focuslpstatefork->depth) > fork->depth )
2976  {
2977  /* focuslpstatefork is not on the same active path as the new node: we have to continue searching */
2978  if( lpfork != NULL && lpfork->depth < fork->depth )
2979  lpstatefork = lpfork;
2980  else
2981  lpstatefork = fork;
2982  while( lpstatefork != NULL
2983  && SCIPnodeGetType(lpstatefork) != SCIP_NODETYPE_FORK
2984  && SCIPnodeGetType(lpstatefork) != SCIP_NODETYPE_SUBROOT )
2985  {
2986  assert(lpstatefork->active);
2987  lpstatefork = lpstatefork->parent;
2988  }
2989  }
2990  else
2991  {
2992  /* focuslpstatefork is on the same active path as the new node: old and new node have the same lpstatefork */
2993  lpstatefork = tree->focuslpstatefork;
2994  }
2995  assert(lpstatefork == NULL || (int)(lpstatefork->depth) <= fork->depth);
2996  assert(lpstatefork == NULL || lpstatefork->active);
2997  }
2998  assert(lpstatefork == NULL
2999  || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_FORK
3000  || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_SUBROOT);
3001  assert(lpstatefork == NULL || (lpfork != NULL && lpstatefork->depth <= lpfork->depth));
3002  SCIPdebugMessage("find switch forks: lpstateforkdepth=%d\n", lpstatefork == NULL ? -1 : (int)(lpstatefork->depth));
3003 
3004  /* if not already found, continue searching the subroot; it cannot be deeper than the LP defining fork, the
3005  * LP state fork and the common fork
3006  */
3007  if( subroot == NULL )
3008  {
3009  if( tree->focussubroot != NULL && (int)(tree->focussubroot->depth) > fork->depth )
3010  {
3011  /* focussubroot is not on the same active path as the new node: we have to continue searching */
3012  if( lpstatefork != NULL && lpstatefork->depth < fork->depth )
3013  subroot = lpstatefork;
3014  else if( lpfork != NULL && lpfork->depth < fork->depth )
3015  subroot = lpfork;
3016  else
3017  subroot = fork;
3018  while( subroot != NULL && SCIPnodeGetType(subroot) != SCIP_NODETYPE_SUBROOT )
3019  {
3020  assert(subroot->active);
3021  subroot = subroot->parent;
3022  }
3023  }
3024  else
3025  subroot = tree->focussubroot;
3026  assert(subroot == NULL || subroot->depth <= fork->depth);
3027  assert(subroot == NULL || subroot->active);
3028  }
3029  assert(subroot == NULL || SCIPnodeGetType(subroot) == SCIP_NODETYPE_SUBROOT);
3030  assert(subroot == NULL || (lpstatefork != NULL && subroot->depth <= lpstatefork->depth));
3031  SCIPdebugMessage("find switch forks: subrootdepth=%d\n", subroot == NULL ? -1 : (int)(subroot->depth));
3032 
3033  /* if a node prior to the common fork should be repropagated, we select the node to be repropagated as common
3034  * fork in order to undo all bound changes up to this node, repropagate the node, and redo the bound changes
3035  * afterwards
3036  */
3037  if( (int)fork->depth > tree->repropdepth )
3038  {
3039  fork = tree->path[tree->repropdepth];
3040  assert(fork->active);
3041  assert(fork->reprop);
3042  }
3043 
3044  *commonfork = fork;
3045  *newlpfork = lpfork;
3046  *newlpstatefork = lpstatefork;
3047  *newsubroot = subroot;
3048 
3049 #ifndef NDEBUG
3050  while( fork != NULL )
3051  {
3052  assert(fork->active);
3053  assert(!fork->cutoff);
3054  assert(fork->parent == NULL || !fork->parent->reprop);
3055  fork = fork->parent;
3056  }
3057 #endif
3058  tree->repropdepth = INT_MAX;
3059 }
3060 
3061 /** switches the active path to the new focus node, applies domain and constraint set changes */
3062 static
3064  SCIP_TREE* tree, /**< branch and bound tree */
3065  SCIP_REOPT* reopt, /**< reoptimization data structure */
3066  BMS_BLKMEM* blkmem, /**< block memory buffers */
3067  SCIP_SET* set, /**< global SCIP settings */
3068  SCIP_STAT* stat, /**< problem statistics */
3069  SCIP_PROB* transprob, /**< transformed problem after presolve */
3070  SCIP_PROB* origprob, /**< original problem */
3071  SCIP_PRIMAL* primal, /**< primal data */
3072  SCIP_LP* lp, /**< current LP data */
3073  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
3074  SCIP_CONFLICT* conflict, /**< conflict analysis data */
3075  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
3076  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3077  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
3078  SCIP_NODE* fork, /**< common fork node of old and new focus node, or NULL */
3079  SCIP_NODE* focusnode, /**< new focus node, or NULL */
3080  SCIP_Bool* cutoff /**< pointer to store whether the new focus node can be cut off */
3081  )
3082 {
3083  int focusnodedepth; /* depth of the new focus node, or -1 if focusnode == NULL */
3084  int forkdepth; /* depth of the common subroot/fork/pseudofork/junction node, or -1 if no common fork exists */
3085  int i;
3086 
3087  assert(tree != NULL);
3088  assert(fork == NULL || (fork->active && !fork->cutoff));
3089  assert(fork == NULL || focusnode != NULL);
3090  assert(focusnode == NULL || (!focusnode->active && !focusnode->cutoff));
3091  assert(focusnode == NULL || SCIPnodeGetType(focusnode) == SCIP_NODETYPE_FOCUSNODE);
3092  assert(cutoff != NULL);
3093 
3094  *cutoff = FALSE;
3095 
3096  SCIPsetDebugMsg(set, "switch path: old pathlen=%d\n", tree->pathlen);
3097 
3098  /* get the nodes' depths */
3099  focusnodedepth = (focusnode != NULL ? (int)focusnode->depth : -1);
3100  forkdepth = (fork != NULL ? (int)fork->depth : -1);
3101  assert(forkdepth <= focusnodedepth);
3102  assert(forkdepth < tree->pathlen);
3103 
3104  /* delay events in path switching */
3105  SCIP_CALL( SCIPeventqueueDelay(eventqueue) );
3106 
3107  /* undo the domain and constraint set changes of the old active path by deactivating the path's nodes */
3108  for( i = tree->pathlen-1; i > forkdepth; --i )
3109  {
3110  SCIP_CALL( nodeDeactivate(tree->path[i], blkmem, set, stat, tree, lp, branchcand, eventfilter, eventqueue) );
3111  }
3112  tree->pathlen = forkdepth+1;
3113 
3114  /* apply the pending bound changes */
3115  SCIP_CALL( treeApplyPendingBdchgs(tree, reopt, blkmem, set, stat, transprob, origprob, lp, branchcand, eventqueue, cliquetable) );
3116 
3117  /* create the new active path */
3118  SCIP_CALL( treeEnsurePathMem(tree, set, focusnodedepth+1) );
3119 
3120  while( focusnode != fork )
3121  {
3122  assert(focusnode != NULL);
3123  assert(!focusnode->active);
3124  assert(!focusnode->cutoff);
3125  /* coverity[var_deref_op] */
3126  tree->path[focusnode->depth] = focusnode;
3127  focusnode = focusnode->parent;
3128  }
3129 
3130  /* fork might be cut off when applying the pending bound changes */
3131  if( fork != NULL && fork->cutoff )
3132  *cutoff = TRUE;
3133  else if( fork != NULL && fork->reprop )
3134  {
3135  /* propagate common fork again, if the reprop flag is set */
3136  assert(tree->path[forkdepth] == fork);
3137  assert(fork->active);
3138  assert(!fork->cutoff);
3139 
3140  SCIP_CALL( nodeRepropagate(fork, blkmem, set, stat, transprob, origprob, primal, tree, reopt, lp, branchcand, conflict,
3141  eventfilter, eventqueue, cliquetable, cutoff) );
3142  }
3143  assert(fork != NULL || !(*cutoff));
3144 
3145  /* Apply domain and constraint set changes of the new path by activating the path's nodes;
3146  * on the way, domain propagation might be applied again to the path's nodes, which can result in the cutoff of
3147  * the node (and its subtree).
3148  * We only activate all nodes down to the parent of the new focus node, because the events in this process are
3149  * delayed, which means that multiple changes of a bound of a variable are merged (and might even be cancelled out,
3150  * if the bound is first relaxed when deactivating a node on the old path and then tightened to the same value
3151  * when activating a node on the new path).
3152  * This is valid for all nodes down to the parent of the new focus node, since they have already been propagated.
3153  * Bound change events on the new focus node, however, must not be cancelled out, since they need to be propagated
3154  * and thus, the event must be thrown and catched by the constraint handlers to mark constraints for propagation.
3155  */
3156  for( i = forkdepth+1; i < focusnodedepth && !(*cutoff); ++i )
3157  {
3158  assert(!tree->path[i]->cutoff);
3159  assert(tree->pathlen == i);
3160 
3161  /* activate the node, and apply domain propagation if the reprop flag is set */
3162  tree->pathlen++;
3163  SCIP_CALL( nodeActivate(tree->path[i], blkmem, set, stat, transprob, origprob, primal, tree, reopt, lp, branchcand,
3164  conflict, eventfilter, eventqueue, cliquetable, cutoff) );
3165  }
3166 
3167  /* process the delayed events */
3168  SCIP_CALL( SCIPeventqueueProcess(eventqueue, blkmem, set, primal, lp, branchcand, eventfilter) );
3169 
3170  /* activate the new focus node; there is no need to delay these events */
3171  if( !(*cutoff) && (i == focusnodedepth) )
3172  {
3173  assert(!tree->path[focusnodedepth]->cutoff);
3174  assert(tree->pathlen == focusnodedepth);
3175 
3176  /* activate the node, and apply domain propagation if the reprop flag is set */
3177  tree->pathlen++;
3178  SCIP_CALL( nodeActivate(tree->path[focusnodedepth], blkmem, set, stat, transprob, origprob, primal, tree, reopt, lp, branchcand,
3179  conflict, eventfilter, eventqueue, cliquetable, cutoff) );
3180  }
3181 
3182  /* mark last node of path to be cut off, if a cutoff was found */
3183  if( *cutoff )
3184  {
3185  assert(tree->pathlen > 0);
3186  assert(tree->path[tree->pathlen-1]->active);
3187  SCIP_CALL( SCIPnodeCutoff(tree->path[tree->pathlen-1], set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
3188  }
3189 
3190  /* count the new LP sizes of the path */
3191  SCIP_CALL( treeUpdatePathLPSize(tree, forkdepth+1) );
3192 
3193  SCIPsetDebugMsg(set, "switch path: new pathlen=%d\n", tree->pathlen);
3194 
3195  return SCIP_OKAY;
3196 }
3197 
3198 /** loads the subroot's LP data */
3199 static
3201  SCIP_NODE* subroot, /**< subroot node to construct LP for */
3202  BMS_BLKMEM* blkmem, /**< block memory buffers */
3203  SCIP_SET* set, /**< global SCIP settings */
3204  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3205  SCIP_EVENTFILTER* eventfilter, /**< global event filter */
3206  SCIP_LP* lp /**< current LP data */
3207  )
3208 {
3209  SCIP_COL** cols;
3210  SCIP_ROW** rows;
3211  int ncols;
3212  int nrows;
3213  int c;
3214  int r;
3215 
3216  assert(subroot != NULL);
3217  assert(SCIPnodeGetType(subroot) == SCIP_NODETYPE_SUBROOT);
3218  assert(subroot->data.subroot != NULL);
3219  assert(blkmem != NULL);
3220  assert(set != NULL);
3221  assert(lp != NULL);
3222 
3223  cols = subroot->data.subroot->cols;
3224  rows = subroot->data.subroot->rows;
3225  ncols = subroot->data.subroot->ncols;
3226  nrows = subroot->data.subroot->nrows;
3227 
3228  assert(ncols == 0 || cols != NULL);
3229  assert(nrows == 0 || rows != NULL);
3230 
3231  for( c = 0; c < ncols; ++c )
3232  {
3233  SCIP_CALL( SCIPlpAddCol(lp, set, cols[c], (int) subroot->depth) );
3234  }
3235  for( r = 0; r < nrows; ++r )
3236  {
3237  SCIP_CALL( SCIPlpAddRow(lp, blkmem, set, eventqueue, eventfilter, rows[r], (int) subroot->depth) );
3238  }
3239 
3240  return SCIP_OKAY;
3241 }
3242 
3243 /** loads the fork's additional LP data */
3244 static
3246  SCIP_NODE* fork, /**< fork node to construct additional LP for */
3247  BMS_BLKMEM* blkmem, /**< block memory buffers */
3248  SCIP_SET* set, /**< global SCIP settings */
3249  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3250  SCIP_EVENTFILTER* eventfilter, /**< global event filter */
3251  SCIP_LP* lp /**< current LP data */
3252  )
3253 {
3254  SCIP_COL** cols;
3255  SCIP_ROW** rows;
3256  int ncols;
3257  int nrows;
3258  int c;
3259  int r;
3260 
3261  assert(fork != NULL);
3262  assert(SCIPnodeGetType(fork) == SCIP_NODETYPE_FORK);
3263  assert(fork->data.fork != NULL);
3264  assert(blkmem != NULL);
3265  assert(set != NULL);
3266  assert(lp != NULL);
3267 
3268  cols = fork->data.fork->addedcols;
3269  rows = fork->data.fork->addedrows;
3270  ncols = fork->data.fork->naddedcols;
3271  nrows = fork->data.fork->naddedrows;
3272 
3273  assert(ncols == 0 || cols != NULL);
3274  assert(nrows == 0 || rows != NULL);
3275 
3276  for( c = 0; c < ncols; ++c )
3277  {
3278  SCIP_CALL( SCIPlpAddCol(lp, set, cols[c], (int) fork->depth) );
3279  }
3280  for( r = 0; r < nrows; ++r )
3281  {
3282  SCIP_CALL( SCIPlpAddRow(lp, blkmem, set, eventqueue, eventfilter, rows[r], (int) fork->depth) );
3283  }
3284 
3285  return SCIP_OKAY;
3286 }
3287 
3288 /** loads the pseudofork's additional LP data */
3289 static
3291  SCIP_NODE* pseudofork, /**< pseudofork node to construct additional LP for */
3292  BMS_BLKMEM* blkmem, /**< block memory buffers */
3293  SCIP_SET* set, /**< global SCIP settings */
3294  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3295  SCIP_EVENTFILTER* eventfilter, /**< global event filter */
3296  SCIP_LP* lp /**< current LP data */
3297  )
3298 {
3299  SCIP_COL** cols;
3300  SCIP_ROW** rows;
3301  int ncols;
3302  int nrows;
3303  int c;
3304  int r;
3305 
3306  assert(pseudofork != NULL);
3307  assert(SCIPnodeGetType(pseudofork) == SCIP_NODETYPE_PSEUDOFORK);
3308  assert(pseudofork->data.pseudofork != NULL);
3309  assert(blkmem != NULL);
3310  assert(set != NULL);
3311  assert(lp != NULL);
3312 
3313  cols = pseudofork->data.pseudofork->addedcols;
3314  rows = pseudofork->data.pseudofork->addedrows;
3315  ncols = pseudofork->data.pseudofork->naddedcols;
3316  nrows = pseudofork->data.pseudofork->naddedrows;
3317 
3318  assert(ncols == 0 || cols != NULL);
3319  assert(nrows == 0 || rows != NULL);
3320 
3321  for( c = 0; c < ncols; ++c )
3322  {
3323  SCIP_CALL( SCIPlpAddCol(lp, set, cols[c], (int) pseudofork->depth) );
3324  }
3325  for( r = 0; r < nrows; ++r )
3326  {
3327  SCIP_CALL( SCIPlpAddRow(lp, blkmem, set, eventqueue, eventfilter, rows[r], (int) pseudofork->depth) );
3328  }
3329 
3330  return SCIP_OKAY;
3331 }
3332 
3333 #ifndef NDEBUG
3334 /** checks validity of active path */
3335 static
3337  SCIP_TREE* tree /**< branch and bound tree */
3338  )
3339 {
3340  SCIP_NODE* node;
3341  int ncols;
3342  int nrows;
3343  int d;
3344 
3345  assert(tree != NULL);
3346  assert(tree->path != NULL);
3347 
3348  ncols = 0;
3349  nrows = 0;
3350  for( d = 0; d < tree->pathlen; ++d )
3351  {
3352  node = tree->path[d];
3353  assert(node != NULL);
3354  assert((int)(node->depth) == d);
3355  switch( SCIPnodeGetType(node) )
3356  {
3358  assert(SCIPtreeProbing(tree));
3359  assert(d >= 1);
3360  assert(SCIPnodeGetType(tree->path[d-1]) == SCIP_NODETYPE_FOCUSNODE
3361  || (ncols == node->data.probingnode->ninitialcols && nrows == node->data.probingnode->ninitialrows));
3362  assert(ncols <= node->data.probingnode->ncols || !tree->focuslpconstructed);
3363  assert(nrows <= node->data.probingnode->nrows || !tree->focuslpconstructed);
3364  if( d < tree->pathlen-1 )
3365  {
3366  ncols = node->data.probingnode->ncols;
3367  nrows = node->data.probingnode->nrows;
3368  }
3369  else
3370  {
3371  /* for the current probing node, the initial LP size is stored in the path */
3372  ncols = node->data.probingnode->ninitialcols;
3373  nrows = node->data.probingnode->ninitialrows;
3374  }
3375  break;
3377  break;
3379  ncols += node->data.pseudofork->naddedcols;
3380  nrows += node->data.pseudofork->naddedrows;
3381  break;
3382  case SCIP_NODETYPE_FORK:
3383  ncols += node->data.fork->naddedcols;
3384  nrows += node->data.fork->naddedrows;
3385  break;
3386  case SCIP_NODETYPE_SUBROOT:
3387  ncols = node->data.subroot->ncols;
3388  nrows = node->data.subroot->nrows;
3389  break;
3392  assert(d == tree->pathlen-1 || SCIPtreeProbing(tree));
3393  break;
3394  default:
3395  SCIPerrorMessage("node at depth %d on active path has to be of type JUNCTION, PSEUDOFORK, FORK, SUBROOT, FOCUSNODE, REFOCUSNODE, or PROBINGNODE, but is %d\n",
3396  d, SCIPnodeGetType(node));
3397  SCIPABORT();
3398  } /*lint !e788*/
3399  assert(tree->pathnlpcols[d] == ncols);
3400  assert(tree->pathnlprows[d] == nrows);
3401  }
3402 }
3403 #else
3404 #define treeCheckPath(tree) /**/
3405 #endif
3406 
3407 /** constructs the LP relaxation of the focus node */
3409  SCIP_TREE* tree, /**< branch and bound tree */
3410  BMS_BLKMEM* blkmem, /**< block memory buffers */
3411  SCIP_SET* set, /**< global SCIP settings */
3412  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3413  SCIP_EVENTFILTER* eventfilter, /**< global event filter */
3414  SCIP_LP* lp, /**< current LP data */
3415  SCIP_Bool* initroot /**< pointer to store whether the root LP relaxation has to be initialized */
3416  )
3417 {
3418  SCIP_NODE* lpfork;
3419  int lpforkdepth;
3420  int d;
3421 
3422  assert(tree != NULL);
3423  assert(!tree->focuslpconstructed);
3424  assert(tree->path != NULL);
3425  assert(tree->pathlen > 0);
3426  assert(tree->focusnode != NULL);
3428  assert(SCIPnodeGetDepth(tree->focusnode) == tree->pathlen-1);
3429  assert(!SCIPtreeProbing(tree));
3430  assert(tree->focusnode == tree->path[tree->pathlen-1]);
3431  assert(blkmem != NULL);
3432  assert(set != NULL);
3433  assert(lp != NULL);
3434  assert(initroot != NULL);
3435 
3436  SCIPsetDebugMsg(set, "load LP for current fork node #%" SCIP_LONGINT_FORMAT " at depth %d\n",
3437  tree->focuslpfork == NULL ? -1 : SCIPnodeGetNumber(tree->focuslpfork),
3438  tree->focuslpfork == NULL ? -1 : SCIPnodeGetDepth(tree->focuslpfork));
3439  SCIPsetDebugMsg(set, "-> old LP has %d cols and %d rows\n", SCIPlpGetNCols(lp), SCIPlpGetNRows(lp));
3440  SCIPsetDebugMsg(set, "-> correct LP has %d cols and %d rows\n",
3441  tree->correctlpdepth >= 0 ? tree->pathnlpcols[tree->correctlpdepth] : 0,
3442  tree->correctlpdepth >= 0 ? tree->pathnlprows[tree->correctlpdepth] : 0);
3443  SCIPsetDebugMsg(set, "-> old correctlpdepth: %d\n", tree->correctlpdepth);
3444 
3445  treeCheckPath(tree);
3446 
3447  lpfork = tree->focuslpfork;
3448 
3449  /* find out the lpfork's depth (or -1, if lpfork is NULL) */
3450  if( lpfork == NULL )
3451  {
3452  assert(tree->correctlpdepth == -1 || tree->pathnlpcols[tree->correctlpdepth] == 0);
3453  assert(tree->correctlpdepth == -1 || tree->pathnlprows[tree->correctlpdepth] == 0);
3454  assert(tree->focuslpstatefork == NULL);
3455  assert(tree->focussubroot == NULL);
3456  lpforkdepth = -1;
3457  }
3458  else
3459  {
3460  assert(SCIPnodeGetType(lpfork) == SCIP_NODETYPE_PSEUDOFORK
3462  assert(lpfork->active);
3463  assert(tree->path[lpfork->depth] == lpfork);
3464  lpforkdepth = (int) lpfork->depth;
3465  }
3466  assert(lpforkdepth < tree->pathlen-1); /* lpfork must not be the last (the focus) node of the active path */
3467 
3468  /* find out, if we are in the same subtree */
3469  if( tree->correctlpdepth >= 0 )
3470  {
3471  /* same subtree: shrink LP to the deepest node with correct LP */
3472  assert(lpforkdepth == -1 || tree->pathnlpcols[tree->correctlpdepth] <= tree->pathnlpcols[lpforkdepth]);
3473  assert(lpforkdepth == -1 || tree->pathnlprows[tree->correctlpdepth] <= tree->pathnlprows[lpforkdepth]);
3474  assert(lpforkdepth >= 0 || tree->pathnlpcols[tree->correctlpdepth] == 0);
3475  assert(lpforkdepth >= 0 || tree->pathnlprows[tree->correctlpdepth] == 0);
3476  SCIP_CALL( SCIPlpShrinkCols(lp, set, tree->pathnlpcols[tree->correctlpdepth]) );
3477  SCIP_CALL( SCIPlpShrinkRows(lp, blkmem, set, eventqueue, eventfilter, tree->pathnlprows[tree->correctlpdepth]) );
3478  }
3479  else
3480  {
3481  /* other subtree: fill LP with the subroot LP data */
3482  SCIP_CALL( SCIPlpClear(lp, blkmem, set, eventqueue, eventfilter) );
3483  if( tree->focussubroot != NULL )
3484  {
3485  SCIP_CALL( subrootConstructLP(tree->focussubroot, blkmem, set, eventqueue, eventfilter, lp) );
3486  tree->correctlpdepth = (int) tree->focussubroot->depth;
3487  }
3488  }
3489 
3490  assert(lpforkdepth < tree->pathlen);
3491 
3492  /* add the missing columns and rows */
3493  for( d = tree->correctlpdepth+1; d <= lpforkdepth; ++d )
3494  {
3495  SCIP_NODE* pathnode;
3496 
3497  pathnode = tree->path[d];
3498  assert(pathnode != NULL);
3499  assert((int)(pathnode->depth) == d);
3500  assert(SCIPnodeGetType(pathnode) == SCIP_NODETYPE_JUNCTION
3502  || SCIPnodeGetType(pathnode) == SCIP_NODETYPE_FORK);
3503  if( SCIPnodeGetType(pathnode) == SCIP_NODETYPE_FORK )
3504  {
3505  SCIP_CALL( forkAddLP(pathnode, blkmem, set, eventqueue, eventfilter, lp) );
3506  }
3507  else if( SCIPnodeGetType(pathnode) == SCIP_NODETYPE_PSEUDOFORK )
3508  {
3509  SCIP_CALL( pseudoforkAddLP(pathnode, blkmem, set, eventqueue, eventfilter, lp) );
3510  }
3511  }
3512  tree->correctlpdepth = MAX(tree->correctlpdepth, lpforkdepth);
3513  assert(lpforkdepth == -1 || tree->pathnlpcols[tree->correctlpdepth] == tree->pathnlpcols[lpforkdepth]);
3514  assert(lpforkdepth == -1 || tree->pathnlprows[tree->correctlpdepth] == tree->pathnlprows[lpforkdepth]);
3515  assert(lpforkdepth == -1 || SCIPlpGetNCols(lp) == tree->pathnlpcols[lpforkdepth]);
3516  assert(lpforkdepth == -1 || SCIPlpGetNRows(lp) == tree->pathnlprows[lpforkdepth]);
3517  assert(lpforkdepth >= 0 || SCIPlpGetNCols(lp) == 0);
3518  assert(lpforkdepth >= 0 || SCIPlpGetNRows(lp) == 0);
3519 
3520  /* mark the LP's size, such that we know which rows and columns were added in the new node */
3521  SCIPlpMarkSize(lp);
3522 
3523  SCIPsetDebugMsg(set, "-> new correctlpdepth: %d\n", tree->correctlpdepth);
3524  SCIPsetDebugMsg(set, "-> new LP has %d cols and %d rows\n", SCIPlpGetNCols(lp), SCIPlpGetNRows(lp));
3525 
3526  /* if the correct LP depth is still -1, the root LP relaxation has to be initialized */
3527  *initroot = (tree->correctlpdepth == -1);
3528 
3529  /* mark the LP of the focus node constructed */
3530  tree->focuslpconstructed = TRUE;
3531 
3532  return SCIP_OKAY;
3533 }
3534 
3535 /** loads LP state for fork/subroot of the focus node */
3537  SCIP_TREE* tree, /**< branch and bound tree */
3538  BMS_BLKMEM* blkmem, /**< block memory buffers */
3539  SCIP_SET* set, /**< global SCIP settings */
3540  SCIP_STAT* stat, /**< dynamic problem statistics */
3541  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3542  SCIP_LP* lp /**< current LP data */
3543  )
3544 {
3545  SCIP_NODE* lpstatefork;
3546  SCIP_Bool updatefeas;
3547  SCIP_Bool checkbdchgs;
3548  int lpstateforkdepth;
3549  int d;
3550 
3551  assert(tree != NULL);
3552  assert(tree->focuslpconstructed);
3553  assert(tree->path != NULL);
3554  assert(tree->pathlen > 0);
3555  assert(tree->focusnode != NULL);
3556  assert(tree->correctlpdepth < tree->pathlen);
3558  assert(SCIPnodeGetDepth(tree->focusnode) == tree->pathlen-1);
3559  assert(!SCIPtreeProbing(tree));
3560  assert(tree->focusnode == tree->path[tree->pathlen-1]);
3561  assert(blkmem != NULL);
3562  assert(set != NULL);
3563  assert(lp != NULL);
3564 
3565  SCIPsetDebugMsg(set, "load LP state for current fork node #%" SCIP_LONGINT_FORMAT " at depth %d\n",
3567  tree->focuslpstatefork == NULL ? -1 : SCIPnodeGetDepth(tree->focuslpstatefork));
3568 
3569  lpstatefork = tree->focuslpstatefork;
3570 
3571  /* if there is no LP state defining fork, nothing can be done */
3572  if( lpstatefork == NULL )
3573  return SCIP_OKAY;
3574 
3575  /* get the lpstatefork's depth */
3576  assert(SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_FORK || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_SUBROOT);
3577  assert(lpstatefork->active);
3578  assert(tree->path[lpstatefork->depth] == lpstatefork);
3579  lpstateforkdepth = (int) lpstatefork->depth;
3580  assert(lpstateforkdepth < tree->pathlen-1); /* lpstatefork must not be the last (the focus) node of the active path */
3581  assert(lpstateforkdepth <= tree->correctlpdepth); /* LP must have been constructed at least up to the fork depth */
3582  assert(tree->pathnlpcols[tree->correctlpdepth] >= tree->pathnlpcols[lpstateforkdepth]); /* LP can only grow */
3583  assert(tree->pathnlprows[tree->correctlpdepth] >= tree->pathnlprows[lpstateforkdepth]); /* LP can only grow */
3584 
3585  /* load LP state */
3586  if( tree->focuslpstateforklpcount != stat->lpcount )
3587  {
3588  if( SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_FORK )
3589  {
3590  assert(lpstatefork->data.fork != NULL);
3591  SCIP_CALL( SCIPlpSetState(lp, blkmem, set, eventqueue, lpstatefork->data.fork->lpistate,
3592  lpstatefork->data.fork->lpwasprimfeas, lpstatefork->data.fork->lpwasprimchecked,
3593  lpstatefork->data.fork->lpwasdualfeas, lpstatefork->data.fork->lpwasdualchecked) );
3594  }
3595  else
3596  {
3597  assert(SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_SUBROOT);
3598  assert(lpstatefork->data.subroot != NULL);
3599  SCIP_CALL( SCIPlpSetState(lp, blkmem, set, eventqueue, lpstatefork->data.subroot->lpistate,
3600  lpstatefork->data.subroot->lpwasprimfeas, lpstatefork->data.subroot->lpwasprimchecked,
3601  lpstatefork->data.subroot->lpwasdualfeas, lpstatefork->data.subroot->lpwasdualchecked) );
3602  }
3603  updatefeas = !lp->solved || !lp->solisbasic;
3604  checkbdchgs = TRUE;
3605  }
3606  else
3607  {
3608  updatefeas = TRUE;
3609 
3610  /* we do not need to check the bounds, since primalfeasible is updated anyway when flushing the LP */
3611  checkbdchgs = FALSE;
3612  }
3613 
3614  if( updatefeas )
3615  {
3616  /* check whether the size of the LP increased (destroying primal/dual feasibility) */
3617  lp->primalfeasible = lp->primalfeasible
3618  && (tree->pathnlprows[tree->correctlpdepth] == tree->pathnlprows[lpstateforkdepth]);
3619  lp->primalchecked = lp->primalchecked
3620  && (tree->pathnlprows[tree->correctlpdepth] == tree->pathnlprows[lpstateforkdepth]);
3621  lp->dualfeasible = lp->dualfeasible
3622  && (tree->pathnlpcols[tree->correctlpdepth] == tree->pathnlpcols[lpstateforkdepth]);
3623  lp->dualchecked = lp->dualchecked
3624  && (tree->pathnlpcols[tree->correctlpdepth] == tree->pathnlpcols[lpstateforkdepth]);
3625 
3626  /* check the path from LP fork to focus node for domain changes (destroying primal feasibility of LP basis) */
3627  if( checkbdchgs )
3628  {
3629  for( d = lpstateforkdepth; d < (int)(tree->focusnode->depth) && lp->primalfeasible; ++d )
3630  {
3631  assert(d < tree->pathlen);
3632  lp->primalfeasible = (tree->path[d]->domchg == NULL || tree->path[d]->domchg->domchgbound.nboundchgs == 0);
3633  lp->primalchecked = lp->primalfeasible;
3634  }
3635  }
3636  }
3637 
3638  SCIPsetDebugMsg(set, "-> primalfeasible=%u, dualfeasible=%u\n", lp->primalfeasible, lp->dualfeasible);
3639 
3640  return SCIP_OKAY;
3641 }
3642 
3643 
3644 
3645 
3646 /*
3647  * Node Conversion
3648  */
3649 
3650 /** converts node into LEAF and moves it into the array of the node queue
3651  * if node's lower bound is greater or equal than the given upper bound, the node is deleted;
3652  * otherwise, it is moved to the node queue; anyways, the given pointer is NULL after the call
3653  */
3654 static
3656  SCIP_NODE** node, /**< pointer to child or sibling node to convert */
3657  BMS_BLKMEM* blkmem, /**< block memory buffers */
3658  SCIP_SET* set, /**< global SCIP settings */
3659  SCIP_STAT* stat, /**< dynamic problem statistics */
3660  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
3661  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3662  SCIP_TREE* tree, /**< branch and bound tree */
3663  SCIP_REOPT* reopt, /**< reoptimization data structure */
3664  SCIP_LP* lp, /**< current LP data */
3665  SCIP_NODE* lpstatefork, /**< LP state defining fork of the node */
3666  SCIP_Real cutoffbound /**< cutoff bound: all nodes with lowerbound >= cutoffbound are cut off */
3667  )
3668 {
3671  assert(stat != NULL);
3672  assert(lpstatefork == NULL || lpstatefork->depth < (*node)->depth);
3673  assert(lpstatefork == NULL || lpstatefork->active || SCIPsetIsGE(set, (*node)->lowerbound, cutoffbound));
3674  assert(lpstatefork == NULL
3675  || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_FORK
3676  || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_SUBROOT);
3677 
3678  /* convert node into leaf */
3679  SCIPsetDebugMsg(set, "convert node #%" SCIP_LONGINT_FORMAT " at depth %d to leaf with lpstatefork #%" SCIP_LONGINT_FORMAT " at depth %d\n",
3680  SCIPnodeGetNumber(*node), SCIPnodeGetDepth(*node),
3681  lpstatefork == NULL ? -1 : SCIPnodeGetNumber(lpstatefork),
3682  lpstatefork == NULL ? -1 : SCIPnodeGetDepth(lpstatefork));
3683  (*node)->nodetype = SCIP_NODETYPE_LEAF; /*lint !e641*/
3684  (*node)->data.leaf.lpstatefork = lpstatefork;
3685 
3686 #ifndef NDEBUG
3687  /* check, if the LP state fork is the first node with LP state information on the path back to the root */
3688  if( !SCIPsetIsInfinity(set, -cutoffbound) ) /* if the node was cut off in SCIPnodeFocus(), the lpstatefork is invalid */
3689  {
3690  SCIP_NODE* pathnode;
3691  pathnode = (*node)->parent;
3692  while( pathnode != NULL && pathnode != lpstatefork )
3693  {
3694  assert(SCIPnodeGetType(pathnode) == SCIP_NODETYPE_JUNCTION
3695  || SCIPnodeGetType(pathnode) == SCIP_NODETYPE_PSEUDOFORK);
3696  pathnode = pathnode->parent;
3697  }
3698  assert(pathnode == lpstatefork);
3699  }
3700 #endif
3701 
3702  /* if node is good enough to keep, put it on the node queue */
3703  if( SCIPsetIsLT(set, (*node)->lowerbound, cutoffbound) )
3704  {
3705  /* insert leaf in node queue */
3706  SCIP_CALL( SCIPnodepqInsert(tree->leaves, set, *node) );
3707 
3708  /* make the domain change data static to save memory */
3709  SCIP_CALL( SCIPdomchgMakeStatic(&(*node)->domchg, blkmem, set, eventqueue, lp) );
3710 
3711  /* node is now member of the node queue: delete the pointer to forbid further access */
3712  *node = NULL;
3713  }
3714  else
3715  {
3716  if( set->reopt_enable )
3717  {
3718  assert(reopt != NULL);
3719  /* check if the node should be stored for reoptimization */
3721  tree->root == *node, tree->focusnode == *node, (*node)->lowerbound, tree->effectiverootdepth) );
3722  }
3723 
3724  /* delete node due to bound cut off */
3725  SCIPvisualCutoffNode(stat->visual, set, stat, *node, FALSE);
3726  SCIP_CALL( SCIPnodeFree(node, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
3727  }
3728  assert(*node == NULL);
3729 
3730  return SCIP_OKAY;
3731 }
3732 
3733 /** removes variables from the problem, that are marked to be deletable, and were created at the focusnode;
3734  * only removes variables that were created at the focusnode, unless inlp is TRUE (e.g., when the node is cut off, anyway)
3735  */
3736 static
3738  BMS_BLKMEM* blkmem, /**< block memory buffers */
3739  SCIP_SET* set, /**< global SCIP settings */
3740  SCIP_STAT* stat, /**< dynamic problem statistics */
3741  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3742  SCIP_PROB* transprob, /**< transformed problem after presolve */
3743  SCIP_PROB* origprob, /**< original problem */
3744  SCIP_TREE* tree, /**< branch and bound tree */
3745  SCIP_REOPT* reopt, /**< reoptimization data structure */
3746  SCIP_LP* lp, /**< current LP data */
3747  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
3748  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
3749  SCIP_Bool inlp /**< should variables in the LP be deleted, too?*/
3750  )
3751 {
3752  SCIP_VAR* var;
3753  int i;
3754  int ndelvars;
3755  SCIP_Bool needdel;
3756  SCIP_Bool deleted;
3757 
3758  assert(blkmem != NULL);
3759  assert(set != NULL);
3760  assert(stat != NULL);
3761  assert(tree != NULL);
3762  assert(!SCIPtreeProbing(tree));
3763  assert(tree->focusnode != NULL);
3765  assert(lp != NULL);
3766 
3767  /* check the settings, whether variables should be deleted */
3768  needdel = (tree->focusnode == tree->root ? set->price_delvarsroot : set->price_delvars);
3769 
3770  if( !needdel )
3771  return SCIP_OKAY;
3772 
3773  ndelvars = 0;
3774 
3775  /* also delete variables currently in the LP, thus remove all new variables from the LP, first */
3776  if( inlp )
3777  {
3778  /* remove all additions to the LP at this node */
3780 
3781  SCIP_CALL( SCIPlpFlush(lp, blkmem, set, eventqueue) );
3782  }
3783 
3784  /* mark variables as deleted */
3785  for( i = 0; i < transprob->nvars; i++ )
3786  {
3787  var = transprob->vars[i];
3788  assert(var != NULL);
3789 
3790  /* check whether variable is deletable */
3791  if( SCIPvarIsDeletable(var) )
3792  {
3793  if( !SCIPvarIsInLP(var) )
3794  {
3795  /* fix the variable to 0, first */
3796  assert(!SCIPsetIsFeasPositive(set, SCIPvarGetLbGlobal(var)));
3797  assert(!SCIPsetIsFeasNegative(set, SCIPvarGetUbGlobal(var)));
3798 
3799  if( !SCIPsetIsFeasZero(set, SCIPvarGetLbGlobal(var)) )
3800  {
3801  SCIP_CALL( SCIPnodeAddBoundchg(tree->root, blkmem, set, stat, transprob, origprob,
3802  tree, reopt, lp, branchcand, eventqueue, cliquetable, var, 0.0, SCIP_BOUNDTYPE_LOWER, FALSE) );
3803  }
3804  if( !SCIPsetIsFeasZero(set, SCIPvarGetUbGlobal(var)) )
3805  {
3806  SCIP_CALL( SCIPnodeAddBoundchg(tree->root, blkmem, set, stat, transprob, origprob,
3807  tree, reopt, lp, branchcand, eventqueue, cliquetable, var, 0.0, SCIP_BOUNDTYPE_UPPER, FALSE) );
3808  }
3809 
3810  SCIP_CALL( SCIPprobDelVar(transprob, blkmem, set, eventqueue, var, &deleted) );
3811 
3812  if( deleted )
3813  ndelvars++;
3814  }
3815  else
3816  {
3817  /* mark variable to be non-deletable, because it will be contained in the basis information
3818  * at this node and must not be deleted from now on
3819  */
3821  }
3822  }
3823  }
3824 
3825  SCIPsetDebugMsg(set, "delvars at node %" SCIP_LONGINT_FORMAT ", deleted %d vars\n", stat->nnodes, ndelvars);
3826 
3827  if( ndelvars > 0 )
3828  {
3829  /* perform the variable deletions from the problem */
3830  SCIP_CALL( SCIPprobPerformVarDeletions(transprob, blkmem, set, stat, eventqueue, cliquetable, lp, branchcand) );
3831  }
3832 
3833  return SCIP_OKAY;
3834 }
3835 
3836 /** converts the focus node into a dead-end node */
3837 static
3839  BMS_BLKMEM* blkmem, /**< block memory buffers */
3840  SCIP_SET* set, /**< global SCIP settings */
3841  SCIP_STAT* stat, /**< dynamic problem statistics */
3842  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3843  SCIP_PROB* transprob, /**< transformed problem after presolve */
3844  SCIP_PROB* origprob, /**< original problem */
3845  SCIP_TREE* tree, /**< branch and bound tree */
3846  SCIP_REOPT* reopt, /**< reoptimization data structure */
3847  SCIP_LP* lp, /**< current LP data */
3848  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
3849  SCIP_CLIQUETABLE* cliquetable /**< clique table data structure */
3850  )
3851 {
3852  assert(blkmem != NULL);
3853  assert(tree != NULL);
3854  assert(!SCIPtreeProbing(tree));
3855  assert(tree->focusnode != NULL);
3857  assert(tree->nchildren == 0);
3858 
3859  SCIPsetDebugMsg(set, "focusnode #%" SCIP_LONGINT_FORMAT " to dead-end at depth %d\n",
3861 
3862  /* remove variables from the problem that are marked as deletable and were created at this node */
3863  SCIP_CALL( focusnodeCleanupVars(blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp, branchcand, cliquetable, TRUE) );
3864 
3865  tree->focusnode->nodetype = SCIP_NODETYPE_DEADEND; /*lint !e641*/
3866 
3867  /* release LPI state */
3868  if( tree->focuslpstatefork != NULL )
3869  {
3870  SCIP_CALL( SCIPnodeReleaseLPIState(tree->focuslpstatefork, blkmem, lp) );
3871  }
3872 
3873  return SCIP_OKAY;
3874 }
3875 
3876 /** converts the focus node into a leaf node (if it was postponed) */
3877 static
3879  BMS_BLKMEM* blkmem, /**< block memory buffers */
3880  SCIP_SET* set, /**< global SCIP settings */
3881  SCIP_STAT* stat, /**< dynamic problem statistics */
3882  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
3883  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3884  SCIP_TREE* tree, /**< branch and bound tree */
3885  SCIP_REOPT* reopt, /**< reoptimization data structure */
3886  SCIP_LP* lp, /**< current LP data */
3887  SCIP_NODE* lpstatefork, /**< LP state defining fork of the node */
3888  SCIP_Real cutoffbound /**< cutoff bound: all nodes with lowerbound >= cutoffbound are cut off */
3889 
3890  )
3891 {
3892  assert(tree != NULL);
3893  assert(!SCIPtreeProbing(tree));
3894  assert(tree->focusnode != NULL);
3895  assert(tree->focusnode->active);
3897 
3898  SCIPsetDebugMsg(set, "focusnode #%" SCIP_LONGINT_FORMAT " to leaf at depth %d\n",
3900 
3901  SCIP_CALL( nodeToLeaf(&tree->focusnode, blkmem, set, stat, eventfilter, eventqueue, tree, reopt, lp, lpstatefork, cutoffbound));
3902 
3903  return SCIP_OKAY;
3904 }
3905 
3906 /** converts the focus node into a junction node */
3907 static
3909  BMS_BLKMEM* blkmem, /**< block memory buffers */
3910  SCIP_SET* set, /**< global SCIP settings */
3911  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3912  SCIP_TREE* tree, /**< branch and bound tree */
3913  SCIP_LP* lp /**< current LP data */
3914  )
3915 {
3916  assert(tree != NULL);
3917  assert(!SCIPtreeProbing(tree));
3918  assert(tree->focusnode != NULL);
3919  assert(tree->focusnode->active); /* otherwise, no children could be created at the focus node */
3921  assert(SCIPlpGetNNewcols(lp) == 0);
3922 
3923  SCIPsetDebugMsg(set, "focusnode #%" SCIP_LONGINT_FORMAT " to junction at depth %d\n",
3925 
3926  /* convert node into junction */
3927  tree->focusnode->nodetype = SCIP_NODETYPE_JUNCTION; /*lint !e641*/
3928 
3929  SCIP_CALL( junctionInit(&tree->focusnode->data.junction, tree) );
3930 
3931  /* release LPI state */
3932  if( tree->focuslpstatefork != NULL )
3933  {
3934  SCIP_CALL( SCIPnodeReleaseLPIState(tree->focuslpstatefork, blkmem, lp) );
3935  }
3936 
3937  /* make the domain change data static to save memory */
3938  SCIP_CALL( SCIPdomchgMakeStatic(&tree->focusnode->domchg, blkmem, set, eventqueue, lp) );
3939 
3940  return SCIP_OKAY;
3941 }
3942 
3943 /** converts the focus node into a pseudofork node */
3944 static
3946  BMS_BLKMEM* blkmem, /**< block memory buffers */
3947  SCIP_SET* set, /**< global SCIP settings */
3948  SCIP_STAT* stat, /**< dynamic problem statistics */
3949  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
3950  SCIP_PROB* transprob, /**< transformed problem after presolve */
3951  SCIP_PROB* origprob, /**< original problem */
3952  SCIP_TREE* tree, /**< branch and bound tree */
3953  SCIP_REOPT* reopt, /**< reoptimization data structure */
3954  SCIP_LP* lp, /**< current LP data */
3955  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
3956  SCIP_CLIQUETABLE* cliquetable /**< clique table data structure */
3957  )
3958 {
3959  SCIP_PSEUDOFORK* pseudofork;
3960 
3961  assert(blkmem != NULL);
3962  assert(tree != NULL);
3963  assert(!SCIPtreeProbing(tree));
3964  assert(tree->focusnode != NULL);
3965  assert(tree->focusnode->active); /* otherwise, no children could be created at the focus node */
3967  assert(tree->nchildren > 0);
3968  assert(lp != NULL);
3969 
3970  SCIPsetDebugMsg(set, "focusnode #%" SCIP_LONGINT_FORMAT " to pseudofork at depth %d\n",
3972 
3973  /* remove variables from the problem that are marked as deletable and were created at this node */
3974  SCIP_CALL( focusnodeCleanupVars(blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp, branchcand, cliquetable, FALSE) );
3975 
3976  /* create pseudofork data */
3977  SCIP_CALL( pseudoforkCreate(&pseudofork, blkmem, tree, lp) );
3978 
3979  tree->focusnode->nodetype = SCIP_NODETYPE_PSEUDOFORK; /*lint !e641*/
3980  tree->focusnode->data.pseudofork = pseudofork;
3981 
3982  /* release LPI state */
3983  if( tree->focuslpstatefork != NULL )
3984  {
3985  SCIP_CALL( SCIPnodeReleaseLPIState(tree->focuslpstatefork, blkmem, lp) );
3986  }
3987 
3988  /* make the domain change data static to save memory */
3989  SCIP_CALL( SCIPdomchgMakeStatic(&tree->focusnode->domchg, blkmem, set, eventqueue, lp) );
3990 
3991  return SCIP_OKAY;
3992 }
3993 
3994 /** converts the focus node into a fork node */
3995 static
3997  BMS_BLKMEM* blkmem, /**< block memory buffers */
3998  SCIP_SET* set, /**< global SCIP settings */
3999  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
4000  SCIP_STAT* stat, /**< dynamic problem statistics */
4001  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
4002  SCIP_EVENTFILTER* eventfilter, /**< global event filter */
4003  SCIP_PROB* transprob, /**< transformed problem after presolve */
4004  SCIP_PROB* origprob, /**< original problem */
4005  SCIP_TREE* tree, /**< branch and bound tree */
4006  SCIP_REOPT* reopt, /**< reoptimization data structure */
4007  SCIP_LP* lp, /**< current LP data */
4008  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
4009  SCIP_CLIQUETABLE* cliquetable /**< clique table data structure */
4010  )
4011 {
4012  SCIP_FORK* fork;
4013  SCIP_Bool lperror;
4014 
4015  assert(blkmem != NULL);
4016  assert(tree != NULL);
4017  assert(!SCIPtreeProbing(tree));
4018  assert(tree->focusnode != NULL);
4019  assert(tree->focusnode->active); /* otherwise, no children could be created at the focus node */
4021  assert(tree->nchildren > 0);
4022  assert(lp != NULL);
4023  assert(lp->flushed);
4024  assert(lp->solved || lp->resolvelperror);
4025 
4026  SCIPsetDebugMsg(set, "focusnode #%" SCIP_LONGINT_FORMAT " to fork at depth %d\n",
4028 
4029  /* usually, the LP should be solved to optimality; otherwise, numerical troubles occured,
4030  * and we have to forget about the LP and transform the node into a junction (see below)
4031  */
4032  lperror = FALSE;
4034  {
4035  /* clean up newly created part of LP to keep only necessary columns and rows */
4036  SCIP_CALL( SCIPlpCleanupNew(lp, blkmem, set, stat, eventqueue, eventfilter, (tree->focusnode->depth == 0)) );
4037 
4038  /* resolve LP after cleaning up */
4039  if( !lp->solved || !lp->flushed )
4040  {
4041  SCIPsetDebugMsg(set, "resolving LP after cleanup\n");
4042  SCIP_CALL( SCIPlpSolveAndEval(lp, set, messagehdlr, blkmem, stat, eventqueue, eventfilter, transprob, -1LL, FALSE, FALSE, TRUE, &lperror) );
4043  }
4044  }
4045  assert(lp->flushed);
4046  assert(lp->solved || lperror || lp->resolvelperror);
4047 
4048  /* There are two reasons, that the (reduced) LP is not solved to optimality:
4049  * - The primal heuristics (called after the current node's LP was solved) found a new
4050  * solution, that is better than the current node's lower bound.
4051  * (But in this case, all children should be cut off and the node should be converted
4052  * into a dead-end instead of a fork.)
4053  * - Something numerically weird happened after cleaning up or after resolving a diving or probing LP.
4054  * The only thing we can do, is to completely forget about the LP and treat the node as
4055  * if it was only a pseudo-solution node. Therefore we have to remove all additional
4056  * columns and rows from the LP and convert the node into a junction.
4057  * However, the node's lower bound is kept, thus automatically throwing away nodes that
4058  * were cut off due to a primal solution.
4059  */
4060  if( lperror || lp->resolvelperror || SCIPlpGetSolstat(lp) != SCIP_LPSOLSTAT_OPTIMAL )
4061  {
4062  SCIPmessagePrintVerbInfo(messagehdlr, set->disp_verblevel, SCIP_VERBLEVEL_FULL,
4063  "(node %" SCIP_LONGINT_FORMAT ") numerical troubles: LP %" SCIP_LONGINT_FORMAT " not optimal -- convert node into junction instead of fork\n",
4064  stat->nnodes, stat->nlps);
4065 
4066  /* remove all additions to the LP at this node */
4068  SCIP_CALL( SCIPlpShrinkRows(lp, blkmem, set, eventqueue, eventfilter, SCIPlpGetNRows(lp) - SCIPlpGetNNewrows(lp)) );
4069 
4070  /* convert node into a junction */
4071  SCIP_CALL( focusnodeToJunction(blkmem, set, eventqueue, tree, lp) );
4072 
4073  return SCIP_OKAY;
4074  }
4075  assert(lp->flushed);
4076  assert(lp->solved);
4078 
4079  /* remove variables from the problem that are marked as deletable, were created at this node and are not contained in the LP */
4080  SCIP_CALL( focusnodeCleanupVars(blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp, branchcand, cliquetable, FALSE) );
4081 
4082  assert(lp->flushed);
4083  assert(lp->solved);
4084 
4085  /* create fork data */
4086  SCIP_CALL( forkCreate(&fork, blkmem, set, transprob, tree, lp) );
4087 
4088  tree->focusnode->nodetype = SCIP_NODETYPE_FORK; /*lint !e641*/
4089  tree->focusnode->data.fork = fork;
4090 
4091  /* capture the LPI state of the root node to ensure that the LPI state of the root stays for the whole solving
4092  * process
4093  */
4094  if( tree->focusnode == tree->root )
4095  forkCaptureLPIState(fork, 1);
4096 
4097  /* release LPI state */
4098  if( tree->focuslpstatefork != NULL )
4099  {
4100  SCIP_CALL( SCIPnodeReleaseLPIState(tree->focuslpstatefork, blkmem, lp) );
4101  }
4102 
4103  /* make the domain change data static to save memory */
4104  SCIP_CALL( SCIPdomchgMakeStatic(&tree->focusnode->domchg, blkmem, set, eventqueue, lp) );
4105 
4106  return SCIP_OKAY;
4107 }
4108 
4109 #ifdef WITHSUBROOTS /** @todo test whether subroots should be created */
4110 /** converts the focus node into a subroot node */
4111 static
4112 SCIP_RETCODE focusnodeToSubroot(
4113  BMS_BLKMEM* blkmem, /**< block memory buffers */
4114  SCIP_SET* set, /**< global SCIP settings */
4115  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
4116  SCIP_STAT* stat, /**< dynamic problem statistics */
4117  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
4118  SCIP_EVENTFILTER* eventfilter, /**< global event filter */
4119  SCIP_PROB* transprob, /**< transformed problem after presolve */
4120  SCIP_PROB* origprob, /**< original problem */
4121  SCIP_TREE* tree, /**< branch and bound tree */
4122  SCIP_LP* lp, /**< current LP data */
4123  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
4124  SCIP_CLIQUETABLE* cliquetable /**< clique table data structure */
4125  )
4126 {
4127  SCIP_SUBROOT* subroot;
4128  SCIP_Bool lperror;
4129 
4130  assert(blkmem != NULL);
4131  assert(tree != NULL);
4132  assert(!SCIPtreeProbing(tree));
4133  assert(tree->focusnode != NULL);
4135  assert(tree->focusnode->active); /* otherwise, no children could be created at the focus node */
4136  assert(tree->nchildren > 0);
4137  assert(lp != NULL);
4138  assert(lp->flushed);
4139  assert(lp->solved);
4140 
4141  SCIPsetDebugMsg(set, "focusnode #%" SCIP_LONGINT_FORMAT " to subroot at depth %d\n",
4143 
4144  /* usually, the LP should be solved to optimality; otherwise, numerical troubles occured,
4145  * and we have to forget about the LP and transform the node into a junction (see below)
4146  */
4147  lperror = FALSE;
4149  {
4150  /* clean up whole LP to keep only necessary columns and rows */
4151 #ifdef SCIP_DISABLED_CODE
4152  if( tree->focusnode->depth == 0 )
4153  {
4154  SCIP_CALL( SCIPlpCleanupAll(lp, blkmem, set, stat, eventqueue, eventfilter, (tree->focusnode->depth == 0)) );
4155  }
4156  else
4157 #endif
4158  {
4159  SCIP_CALL( SCIPlpRemoveAllObsoletes(lp, blkmem, set, stat, eventqueue, eventfilter) );
4160  }
4161 
4162  /* resolve LP after cleaning up */
4163  if( !lp->solved || !lp->flushed )
4164  {
4165  SCIPsetDebugMsg(set, "resolving LP after cleanup\n");
4166  SCIP_CALL( SCIPlpSolveAndEval(lp, set, messagehdlr, blkmem, stat, eventqueue, eventfilter, transprob, -1LL, FALSE, FALSE, TRUE, &lperror) );
4167  }
4168  }
4169  assert(lp->flushed);
4170  assert(lp->solved || lperror);
4171 
4172  /* There are two reasons, that the (reduced) LP is not solved to optimality:
4173  * - The primal heuristics (called after the current node's LP was solved) found a new
4174  * solution, that is better than the current node's lower bound.
4175  * (But in this case, all children should be cut off and the node should be converted
4176  * into a dead-end instead of a subroot.)
4177  * - Something numerically weird happened after cleaning up.
4178  * The only thing we can do, is to completely forget about the LP and treat the node as
4179  * if it was only a pseudo-solution node. Therefore we have to remove all additional
4180  * columns and rows from the LP and convert the node into a junction.
4181  * However, the node's lower bound is kept, thus automatically throwing away nodes that
4182  * were cut off due to a primal solution.
4183  */
4184  if( lperror || SCIPlpGetSolstat(lp) != SCIP_LPSOLSTAT_OPTIMAL )
4185  {
4186  SCIPmessagePrintVerbInfo(messagehdlr, set->disp_verblevel, SCIP_VERBLEVEL_FULL,
4187  "(node %" SCIP_LONGINT_FORMAT ") numerical troubles: LP %" SCIP_LONGINT_FORMAT " not optimal -- convert node into junction instead of subroot\n",
4188  stat->nnodes, stat->nlps);
4189 
4190  /* remove all additions to the LP at this node */
4192  SCIP_CALL( SCIPlpShrinkRows(lp, blkmem, set, eventqueue, eventfilter, SCIPlpGetNRows(lp) - SCIPlpGetNNewrows(lp)) );
4193 
4194  /* convert node into a junction */
4195  SCIP_CALL( focusnodeToJunction(blkmem, set, eventqueue, tree, lp) );
4196 
4197  return SCIP_OKAY;
4198  }
4199  assert(lp->flushed);
4200  assert(lp->solved);
4202 
4203  /* remove variables from the problem that are marked as deletable, were created at this node and are not contained in the LP */
4204  SCIP_CALL( focusnodeCleanupVars(blkmem, set, stat, eventqueue, transprob, origprob, tree, lp, branchcand, cliquetable, FALSE) );
4205 
4206  assert(lp->flushed);
4207  assert(lp->solved);
4208 
4209  /* create subroot data */
4210  SCIP_CALL( subrootCreate(&subroot, blkmem, set, transprob, tree, lp) );
4211 
4212  tree->focusnode->nodetype = SCIP_NODETYPE_SUBROOT; /*lint !e641*/
4213  tree->focusnode->data.subroot = subroot;
4214 
4215  /* update the LP column and row counter for the converted node */
4216  SCIP_CALL( treeUpdatePathLPSize(tree, tree->focusnode->depth) );
4217 
4218  /* release LPI state */
4219  if( tree->focuslpstatefork != NULL )
4220  {
4221  SCIP_CALL( SCIPnodeReleaseLPIState(tree->focuslpstatefork, blkmem, lp) );
4222  }
4223 
4224  /* make the domain change data static to save memory */
4225  SCIP_CALL( SCIPdomchgMakeStatic(&tree->focusnode->domchg, blkmem, set, eventqueue, lp) );
4226 
4227  return SCIP_OKAY;
4228 }
4229 #endif
4230 
4231 /** puts all nodes in the array on the node queue and makes them LEAFs */
4232 static
4234  SCIP_TREE* tree, /**< branch and bound tree */
4235  SCIP_REOPT* reopt, /**< reoptimization data structure */
4236  BMS_BLKMEM* blkmem, /**< block memory buffers */
4237  SCIP_SET* set, /**< global SCIP settings */
4238  SCIP_STAT* stat, /**< dynamic problem statistics */
4239  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
4240  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
4241  SCIP_LP* lp, /**< current LP data */
4242  SCIP_NODE** nodes, /**< array of nodes to put on the queue */
4243  int* nnodes, /**< pointer to number of nodes in the array */
4244  SCIP_NODE* lpstatefork, /**< LP state defining fork of the nodes */
4245  SCIP_Real cutoffbound /**< cutoff bound: all nodes with lowerbound >= cutoffbound are cut off */
4246  )
4247 {
4248  int i;
4249 
4250  assert(tree != NULL);
4251  assert(set != NULL);
4252  assert(nnodes != NULL);
4253  assert(*nnodes == 0 || nodes != NULL);
4254 
4255  for( i = *nnodes; --i >= 0; )
4256  {
4257  /* convert node to LEAF and put it into leaves queue, or delete it if it's lower bound exceeds the cutoff bound */
4258  SCIP_CALL( nodeToLeaf(&nodes[i], blkmem, set, stat, eventfilter, eventqueue, tree, reopt, lp, lpstatefork, cutoffbound) );
4259  assert(nodes[i] == NULL);
4260  --(*nnodes);
4261  }
4262 
4263  return SCIP_OKAY;
4264 }
4265 
4266 /** converts children into siblings, clears children array */
4267 static
4269  SCIP_TREE* tree /**< branch and bound tree */
4270  )
4271 {
4272  SCIP_NODE** tmpnodes;
4273  SCIP_Real* tmpprios;
4274  int tmpnodessize;
4275  int i;
4276 
4277  assert(tree != NULL);
4278  assert(tree->nsiblings == 0);
4279 
4280  tmpnodes = tree->siblings;
4281  tmpprios = tree->siblingsprio;
4282  tmpnodessize = tree->siblingssize;
4283 
4284  tree->siblings = tree->children;
4285  tree->siblingsprio = tree->childrenprio;
4286  tree->nsiblings = tree->nchildren;
4287  tree->siblingssize = tree->childrensize;
4288 
4289  tree->children = tmpnodes;
4290  tree->childrenprio = tmpprios;
4291  tree->nchildren = 0;
4292  tree->childrensize = tmpnodessize;
4293 
4294  for( i = 0; i < tree->nsiblings; ++i )
4295  {
4296  assert(SCIPnodeGetType(tree->siblings[i]) == SCIP_NODETYPE_CHILD);
4297  tree->siblings[i]->nodetype = SCIP_NODETYPE_SIBLING; /*lint !e641*/
4298 
4299  /* because CHILD and SIBLING structs contain the same data in the same order, we do not have to copy it */
4300  assert(&(tree->siblings[i]->data.sibling.arraypos) == &(tree->siblings[i]->data.child.arraypos));
4301  }
4302 }
4303 
4304 /** installs a child, a sibling, or a leaf node as the new focus node */
4306  SCIP_NODE** node, /**< pointer to node to focus (or NULL to remove focus); the node
4307  * is freed, if it was cut off due to a cut off subtree */
4308  BMS_BLKMEM* blkmem, /**< block memory buffers */
4309  SCIP_SET* set, /**< global SCIP settings */
4310  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
4311  SCIP_STAT* stat, /**< problem statistics */
4312  SCIP_PROB* transprob, /**< transformed problem */
4313  SCIP_PROB* origprob, /**< original problem */
4314  SCIP_PRIMAL* primal, /**< primal data */
4315  SCIP_TREE* tree, /**< branch and bound tree */
4316  SCIP_REOPT* reopt, /**< reoptimization data structure */
4317  SCIP_LP* lp, /**< current LP data */
4318  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
4319  SCIP_CONFLICT* conflict, /**< conflict analysis data */
4320  SCIP_CONFLICTSTORE* conflictstore, /**< conflict store */
4321  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
4322  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
4323  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
4324  SCIP_Bool* cutoff, /**< pointer to store whether the given node can be cut off */
4325  SCIP_Bool postponed, /**< was the current focus node postponed? */
4326  SCIP_Bool exitsolve /**< are we in exitsolve stage, so we only need to loose the children */
4327  )
4328 { /*lint --e{715}*/
4329  SCIP_NODE* oldfocusnode;
4330  SCIP_NODE* fork;
4331  SCIP_NODE* lpfork;
4332  SCIP_NODE* lpstatefork;
4333  SCIP_NODE* subroot;
4334  SCIP_NODE* childrenlpstatefork;
4335  int oldcutoffdepth;
4336 
4337  assert(node != NULL);
4338  assert(*node == NULL
4341  || SCIPnodeGetType(*node) == SCIP_NODETYPE_LEAF);
4342  assert(*node == NULL || !(*node)->active);
4343  assert(stat != NULL);
4344  assert(tree != NULL);
4345  assert(!SCIPtreeProbing(tree));
4346  assert(lp != NULL);
4347  assert(conflictstore != NULL);
4348  assert(cutoff != NULL);
4349 
4350  /* check global lower bound w.r.t. debugging solution */
4351  SCIP_CALL( SCIPdebugCheckGlobalLowerbound(blkmem, set) );
4352 
4353  /* check local lower bound w.r.t. debugging solution */
4354  SCIP_CALL( SCIPdebugCheckLocalLowerbound(blkmem, set, *node) );
4355 
4356  SCIPsetDebugMsg(set, "focusing node #%" SCIP_LONGINT_FORMAT " of type %d in depth %d\n",
4357  *node != NULL ? SCIPnodeGetNumber(*node) : -1, *node != NULL ? (int)SCIPnodeGetType(*node) : 0,
4358  *node != NULL ? SCIPnodeGetDepth(*node) : -1);
4359 
4360  /* remember old cutoff depth in order to know, whether the children and siblings can be deleted */
4361  oldcutoffdepth = tree->cutoffdepth;
4362 
4363  /* find the common fork node, the new LP defining fork, and the new focus subroot,
4364  * thereby checking, if the new node can be cut off
4365  */
4366  treeFindSwitchForks(tree, *node, &fork, &lpfork, &lpstatefork, &subroot, cutoff);
4367  SCIPsetDebugMsg(set, "focus node: focusnodedepth=%d, forkdepth=%d, lpforkdepth=%d, lpstateforkdepth=%d, subrootdepth=%d, cutoff=%u\n",
4368  *node != NULL ? (*node)->depth : -1, fork != NULL ? fork->depth : -1, /*lint !e705 */
4369  lpfork != NULL ? lpfork->depth : -1, lpstatefork != NULL ? lpstatefork->depth : -1, /*lint !e705 */
4370  subroot != NULL ? subroot->depth : -1, *cutoff); /*lint !e705 */
4371 
4372  /* free the new node, if it is located in a cut off subtree */
4373  if( *cutoff )
4374  {
4375  assert(*node != NULL);
4376  assert(tree->cutoffdepth == oldcutoffdepth);
4377  if( SCIPnodeGetType(*node) == SCIP_NODETYPE_LEAF )
4378  {
4379  SCIP_CALL( SCIPnodepqRemove(tree->leaves, set, *node) );
4380  }
4381  SCIPvisualCutoffNode(stat->visual, set, stat, *node, FALSE);
4382 
4383  if( set->reopt_enable )
4384  {
4385  assert(reopt != NULL);
4386  /* check if the node should be stored for reoptimization */
4388  tree->root == (*node), tree->focusnode == (*node), (*node)->lowerbound, tree->effectiverootdepth) );
4389  }
4390 
4391  SCIP_CALL( SCIPnodeFree(node, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
4392 
4393  return SCIP_OKAY;
4394  }
4395 
4396  assert(tree->cutoffdepth == INT_MAX);
4397  assert(fork == NULL || fork->active);
4398  assert(lpstatefork == NULL || lpfork != NULL);
4399  assert(subroot == NULL || lpstatefork != NULL);
4400 
4401  /* remember the depth of the common fork node for LP updates */
4402  SCIPsetDebugMsg(set, "focus node: old correctlpdepth=%d\n", tree->correctlpdepth);
4403  if( subroot == tree->focussubroot && fork != NULL && lpfork != NULL )
4404  {
4405  /* we are in the same subtree with valid LP fork: the LP is correct at most upto the common fork depth */
4406  assert(subroot == NULL || subroot->active);
4407  tree->correctlpdepth = MIN(tree->correctlpdepth, (int)fork->depth);
4408  }
4409  else
4410  {
4411  /* we are in a different subtree, or no valid LP fork exists: the LP is completely incorrect */
4412  assert(subroot == NULL || !subroot->active
4413  || (tree->focussubroot != NULL && (int)(tree->focussubroot->depth) > subroot->depth));
4414  tree->correctlpdepth = -1;
4415  }
4416 
4417  /* if the LP state fork changed, the lpcount information for the new LP state fork is unknown */
4418  if( lpstatefork != tree->focuslpstatefork )
4419  tree->focuslpstateforklpcount = -1;
4420 
4421  /* in exitsolve we only need to take care of open children
4422  *
4423  * @note because we might do a 'newstart' and converted cuts to constraints might have rendered the LP in the current
4424  * focusnode unsolved the latter code would have resolved the LP unnecessarily
4425  */
4426  if( exitsolve && tree->nchildren > 0 )
4427  {
4428  SCIPsetDebugMsg(set, " -> deleting the %d children (in exitsolve) of the old focus node\n", tree->nchildren);
4429  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->children, &tree->nchildren, NULL, -SCIPsetInfinity(set)) );
4430  assert(tree->nchildren == 0);
4431  }
4432 
4433  /* if the old focus node was cut off, we can delete its children;
4434  * if the old focus node's parent was cut off, we can also delete the focus node's siblings
4435  */
4436  /* coverity[var_compare_op] */
4437  if( tree->focusnode != NULL && oldcutoffdepth <= (int)tree->focusnode->depth )
4438  {
4439  SCIPsetDebugMsg(set, "path to old focus node of depth %u was cut off at depth %d\n", tree->focusnode->depth, oldcutoffdepth);
4440 
4441  /* delete the focus node's children by converting them to leaves with a cutoffbound of -SCIPsetInfinity(set);
4442  * we cannot delete them directly, because in SCIPnodeFree(), the children array is changed, which is the
4443  * same array we would have to iterate over here;
4444  * the children don't have an LP fork, because the old focus node is not yet converted into a fork or subroot
4445  */
4446  SCIPsetDebugMsg(set, " -> deleting the %d children of the old focus node\n", tree->nchildren);
4447  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->children, &tree->nchildren, NULL, -SCIPsetInfinity(set)) );
4448  assert(tree->nchildren == 0);
4449 
4450  if( oldcutoffdepth < (int)tree->focusnode->depth )
4451  {
4452  /* delete the focus node's siblings by converting them to leaves with a cutoffbound of -SCIPsetInfinity(set);
4453  * we cannot delete them directly, because in SCIPnodeFree(), the siblings array is changed, which is the
4454  * same array we would have to iterate over here;
4455  * the siblings have the same LP state fork as the old focus node
4456  */
4457  SCIPsetDebugMsg(set, " -> deleting the %d siblings of the old focus node\n", tree->nsiblings);
4458  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->siblings, &tree->nsiblings, tree->focuslpstatefork,
4459  -SCIPsetInfinity(set)) );
4460  assert(tree->nsiblings == 0);
4461  }
4462  }
4463 
4464  /* convert the old focus node into a fork or subroot node, if it has children;
4465  * otherwise, convert it into a dead-end, which will be freed later in treeSwitchPath();
4466  * if the node was postponed, make it a leaf.
4467  */
4468  childrenlpstatefork = tree->focuslpstatefork;
4469 
4470  assert(!postponed || *node == NULL);
4471  assert(!postponed || tree->focusnode != NULL);
4472 
4473  if( postponed )
4474  {
4475  assert(tree->nchildren == 0);
4476  assert(*node == NULL);
4477 
4478  /* if the node is infeasible, convert it into a deadend; otherwise, put it into the LEAF queue */
4479  if( SCIPsetIsGE(set, tree->focusnode->lowerbound, primal->cutoffbound) )
4480  {
4481  /* in case the LP was not constructed (due to the parameter settings for example) we have the finally remember the
4482  * old size of the LP (if it was constructed in an earlier node) before we change the current node into a deadend
4483  */
4484  if( !tree->focuslpconstructed )
4485  SCIPlpMarkSize(lp);
4486 
4487  /* convert old focus node into deadend */
4488  SCIP_CALL( focusnodeToDeadend(blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp, branchcand,
4489  cliquetable) );
4490  }
4491  else
4492  {
4493  SCIP_CALL( focusnodeToLeaf(blkmem, set, stat, eventfilter, eventqueue, tree, reopt, lp, tree->focuslpstatefork,
4494  SCIPsetInfinity(set)) );
4495  }
4496  }
4497  else if( tree->nchildren > 0 )
4498  {
4499  SCIP_Bool selectedchild;
4500 
4501  assert(tree->focusnode != NULL);
4503  assert(oldcutoffdepth == INT_MAX);
4504 
4505  /* check whether the next focus node is a child of the old focus node */
4506  selectedchild = (*node != NULL && SCIPnodeGetType(*node) == SCIP_NODETYPE_CHILD);
4507 
4508  if( tree->focusnodehaslp && lp->isrelax )
4509  {
4510  assert(tree->focuslpconstructed);
4511 
4512 #ifdef WITHSUBROOTS /** @todo test whether subroots should be created, decide: old focus node becomes fork or subroot */
4513  if( tree->focusnode->depth > 0 && tree->focusnode->depth % 25 == 0 )
4514  {
4515  /* convert old focus node into a subroot node */
4516  SCIP_CALL( focusnodeToSubroot(blkmem, set, messagehdlr, stat, eventqueue, eventfilter, transprob, origprob, tree, lp, branchcand) );
4517  if( *node != NULL && SCIPnodeGetType(*node) == SCIP_NODETYPE_CHILD
4519  subroot = tree->focusnode;
4520  }
4521  else
4522 #endif
4523  {
4524  /* convert old focus node into a fork node */
4525  SCIP_CALL( focusnodeToFork(blkmem, set, messagehdlr, stat, eventqueue, eventfilter, transprob, origprob, tree,
4526  reopt, lp, branchcand, cliquetable) );
4527  }
4528 
4529  /* check, if the conversion into a subroot or fork was successful */
4532  {
4533  childrenlpstatefork = tree->focusnode;
4534 
4535  /* if a child of the old focus node was selected as new focus node, the old node becomes the new focus
4536  * LP fork and LP state fork
4537  */
4538  if( selectedchild )
4539  {
4540  lpfork = tree->focusnode;
4541  tree->correctlpdepth = (int) tree->focusnode->depth;
4542  lpstatefork = tree->focusnode;
4543  tree->focuslpstateforklpcount = stat->lpcount;
4544  }
4545  }
4546 
4547  /* update the path's LP size */
4548  tree->pathnlpcols[tree->focusnode->depth] = SCIPlpGetNCols(lp);
4549  tree->pathnlprows[tree->focusnode->depth] = SCIPlpGetNRows(lp);
4550  }
4551  else if( tree->focuslpconstructed && (SCIPlpGetNNewcols(lp) > 0 || SCIPlpGetNNewrows(lp) > 0) )
4552  {
4553  /* convert old focus node into pseudofork */
4554  SCIP_CALL( focusnodeToPseudofork(blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp,
4555  branchcand, cliquetable) );
4557 
4558  /* update the path's LP size */
4559  tree->pathnlpcols[tree->focusnode->depth] = SCIPlpGetNCols(lp);
4560  tree->pathnlprows[tree->focusnode->depth] = SCIPlpGetNRows(lp);
4561 
4562  /* if a child of the old focus node was selected as new focus node, the old node becomes the new focus LP fork */
4563  if( selectedchild )
4564  {
4565  lpfork = tree->focusnode;
4566  tree->correctlpdepth = (int) tree->focusnode->depth;
4567  }
4568  }
4569  else
4570  {
4571  /* in case the LP was not constructed (due to the parameter settings for example) we have the finally remember the
4572  * old size of the LP (if it was constructed in an earlier node) before we change the current node into a junction
4573  */
4574  SCIPlpMarkSize(lp);
4575 
4576  /* convert old focus node into junction */
4577  SCIP_CALL( focusnodeToJunction(blkmem, set, eventqueue, tree, lp) );
4578  }
4579  }
4580  else if( tree->focusnode != NULL )
4581  {
4582  /* in case the LP was not constructed (due to the parameter settings for example) we have the finally remember the
4583  * old size of the LP (if it was constructed in an earlier node) before we change the current node into a deadend
4584  */
4585  if( !tree->focuslpconstructed )
4586  SCIPlpMarkSize(lp);
4587 
4588  /* convert old focus node into deadend */
4589  SCIP_CALL( focusnodeToDeadend(blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp, branchcand, cliquetable) );
4590  }
4591  assert(subroot == NULL || SCIPnodeGetType(subroot) == SCIP_NODETYPE_SUBROOT);
4592  assert(lpstatefork == NULL
4593  || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_SUBROOT
4594  || SCIPnodeGetType(lpstatefork) == SCIP_NODETYPE_FORK);
4595  assert(childrenlpstatefork == NULL
4596  || SCIPnodeGetType(childrenlpstatefork) == SCIP_NODETYPE_SUBROOT
4597  || SCIPnodeGetType(childrenlpstatefork) == SCIP_NODETYPE_FORK);
4598  assert(lpfork == NULL
4600  || SCIPnodeGetType(lpfork) == SCIP_NODETYPE_FORK
4602  SCIPsetDebugMsg(set, "focus node: new correctlpdepth=%d\n", tree->correctlpdepth);
4603 
4604  /* set up the new lists of siblings and children */
4605  oldfocusnode = tree->focusnode;
4606  if( *node == NULL )
4607  {
4608  /* move siblings to the queue, make them LEAFs */
4609  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->siblings, &tree->nsiblings, tree->focuslpstatefork,
4610  primal->cutoffbound) );
4611 
4612  /* move children to the queue, make them LEAFs */
4613  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->children, &tree->nchildren, childrenlpstatefork,
4614  primal->cutoffbound) );
4615  }
4616  else
4617  {
4618  SCIP_NODE* bestleaf;
4619 
4620  switch( SCIPnodeGetType(*node) )
4621  {
4622  case SCIP_NODETYPE_SIBLING:
4623  /* reset plunging depth, if the selected node is better than all leaves */
4624  bestleaf = SCIPtreeGetBestLeaf(tree);
4625  if( bestleaf == NULL || SCIPnodepqCompare(tree->leaves, set, *node, bestleaf) <= 0 )
4626  stat->plungedepth = 0;
4627 
4628  /* move children to the queue, make them LEAFs */
4629  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->children, &tree->nchildren, childrenlpstatefork,
4630  primal->cutoffbound) );
4631 
4632  /* remove selected sibling from the siblings array */
4633  treeRemoveSibling(tree, *node);
4634 
4635  SCIPsetDebugMsg(set, "selected sibling node, lowerbound=%g, plungedepth=%d\n", (*node)->lowerbound, stat->plungedepth);
4636  break;
4637 
4638  case SCIP_NODETYPE_CHILD:
4639  /* reset plunging depth, if the selected node is better than all leaves; otherwise, increase plunging depth */
4640  bestleaf = SCIPtreeGetBestLeaf(tree);
4641  if( bestleaf == NULL || SCIPnodepqCompare(tree->leaves, set, *node, bestleaf) <= 0 )
4642  stat->plungedepth = 0;
4643  else
4644  stat->plungedepth++;
4645 
4646  /* move siblings to the queue, make them LEAFs */
4647  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->siblings, &tree->nsiblings, tree->focuslpstatefork,
4648  primal->cutoffbound) );
4649 
4650  /* remove selected child from the children array */
4651  treeRemoveChild(tree, *node);
4652 
4653  /* move remaining children to the siblings array, make them SIBLINGs */
4654  treeChildrenToSiblings(tree);
4655 
4656  SCIPsetDebugMsg(set, "selected child node, lowerbound=%g, plungedepth=%d\n", (*node)->lowerbound, stat->plungedepth);
4657  break;
4658 
4659  case SCIP_NODETYPE_LEAF:
4660  /* move siblings to the queue, make them LEAFs */
4661  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->siblings, &tree->nsiblings, tree->focuslpstatefork,
4662  primal->cutoffbound) );
4663 
4664  /* encounter an early backtrack if there is a child which does not exceed given reference bound */
4665  if( !SCIPsetIsInfinity(set, stat->referencebound) )
4666  {
4667  int c;
4668 
4669  /* loop over children and stop if we find a child with a lower bound below given reference bound */
4670  for( c = 0; c < tree->nchildren; ++c )
4671  {
4672  if( SCIPsetIsLT(set, SCIPnodeGetLowerbound(tree->children[c]), stat->referencebound) )
4673  {
4674  ++stat->nearlybacktracks;
4675  break;
4676  }
4677  }
4678  }
4679  /* move children to the queue, make them LEAFs */
4680  SCIP_CALL( treeNodesToQueue(tree, reopt, blkmem, set, stat, eventfilter, eventqueue, lp, tree->children, &tree->nchildren, childrenlpstatefork,
4681  primal->cutoffbound) );
4682 
4683  /* remove node from the queue */
4684  SCIP_CALL( SCIPnodepqRemove(tree->leaves, set, *node) );
4685 
4686  stat->plungedepth = 0;
4687  if( SCIPnodeGetDepth(*node) > 0 )
4688  stat->nbacktracks++;
4689  SCIPsetDebugMsg(set, "selected leaf node, lowerbound=%g, plungedepth=%d\n", (*node)->lowerbound, stat->plungedepth);
4690  break;
4691 
4692  default:
4693  SCIPerrorMessage("selected node is neither sibling, child, nor leaf (nodetype=%d)\n", SCIPnodeGetType(*node));
4694  return SCIP_INVALIDDATA;
4695  } /*lint !e788*/
4696 
4697  /* convert node into the focus node */
4698  (*node)->nodetype = SCIP_NODETYPE_FOCUSNODE; /*lint !e641*/
4699  }
4700  assert(tree->nchildren == 0);
4701 
4702  /* set new focus node, LP fork, LP state fork, and subroot */
4703  assert(subroot == NULL || (lpstatefork != NULL && subroot->depth <= lpstatefork->depth));
4704  assert(lpstatefork == NULL || (lpfork != NULL && lpstatefork->depth <= lpfork->depth));
4705  assert(lpfork == NULL || (*node != NULL && lpfork->depth < (*node)->depth));
4706  tree->focusnode = *node;
4707  tree->focuslpfork = lpfork;
4708  tree->focuslpstatefork = lpstatefork;
4709  tree->focussubroot = subroot;
4710  tree->focuslpconstructed = FALSE;
4711  lp->resolvelperror = FALSE;
4712 
4713  /* track the path from the old focus node to the new node, and perform domain and constraint set changes */
4714  SCIP_CALL( treeSwitchPath(tree, reopt, blkmem, set, stat, transprob, origprob, primal, lp, branchcand, conflict,
4715  eventfilter, eventqueue, cliquetable, fork, *node, cutoff) );
4716  assert(tree->pathlen >= 0);
4717  assert(*node != NULL || tree->pathlen == 0);
4718  assert(*node == NULL || tree->pathlen-1 <= (int)(*node)->depth);
4719 
4720  /* if the old focus node is a dead end (has no children), delete it */
4721  if( oldfocusnode != NULL && SCIPnodeGetType(oldfocusnode) == SCIP_NODETYPE_DEADEND )
4722  {
4723  int appliedeffectiverootdepth;
4724 
4725  appliedeffectiverootdepth = tree->appliedeffectiverootdepth;
4726  assert(appliedeffectiverootdepth <= tree->effectiverootdepth);
4727 
4728  SCIP_CALL( SCIPnodeFree(&oldfocusnode, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
4729  assert(tree->effectiverootdepth < tree->pathlen || *node == NULL || *cutoff);
4730 
4731  if( tree->effectiverootdepth > appliedeffectiverootdepth && *node != NULL && !(*cutoff) )
4732  {
4733  int d;
4734 
4735  /* promote the constraint set and bound changes up to the new effective root to be global changes */
4736  SCIPsetDebugMsg(set, "effective root is now at depth %d: applying constraint set and bound changes to global problem\n",
4737  tree->effectiverootdepth);
4738 
4739  for( d = appliedeffectiverootdepth + 1; d <= tree->effectiverootdepth; ++d )
4740  {
4741  SCIP_Bool nodecutoff;
4742 
4743  SCIPsetDebugMsg(set, " -> applying constraint set changes of depth %d\n", d);
4744  SCIP_CALL( SCIPconssetchgMakeGlobal(&tree->path[d]->conssetchg, blkmem, set, stat, transprob, reopt) );
4745  SCIPsetDebugMsg(set, " -> applying bound changes of depth %d\n", d);
4746  SCIP_CALL( SCIPdomchgApplyGlobal(tree->path[d]->domchg, blkmem, set, stat, lp, branchcand, eventqueue, cliquetable,
4747  &nodecutoff) );
4748 
4749  if( nodecutoff )
4750  {
4751  SCIP_CALL( SCIPnodeCutoff(tree->path[d], set, stat, tree, transprob, origprob, reopt, lp, blkmem) );
4752  *cutoff = TRUE;
4753  }
4754  }
4755 
4757  }
4758  }
4759  assert(*cutoff || SCIPtreeIsPathComplete(tree));
4760 
4761  return SCIP_OKAY;
4762 }
4763 
4764 
4765 
4766 
4767 /*
4768  * Tree methods
4769  */
4770 
4771 /** creates an initialized tree data structure */
4773  SCIP_TREE** tree, /**< pointer to tree data structure */
4774  BMS_BLKMEM* blkmem, /**< block memory buffers */
4775  SCIP_SET* set, /**< global SCIP settings */
4776  SCIP_NODESEL* nodesel /**< node selector to use for sorting leaves in the priority queue */
4777  )
4778 {
4779  int p;
4780 
4781  assert(tree != NULL);
4782  assert(blkmem != NULL);
4783 
4784  SCIP_ALLOC( BMSallocMemory(tree) );
4785 
4786  (*tree)->root = NULL;
4787 
4788  SCIP_CALL( SCIPnodepqCreate(&(*tree)->leaves, set, nodesel) );
4789 
4790  /* allocate one slot for the prioritized and the unprioritized bound change */
4791  for( p = 0; p <= 1; ++p )
4792  {
4793  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*tree)->divebdchgdirs[p], 1) ); /*lint !e866*/
4794  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*tree)->divebdchgvars[p], 1) ); /*lint !e866*/
4795  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*tree)->divebdchgvals[p], 1) ); /*lint !e866*/
4796  (*tree)->ndivebdchanges[p] = 0;
4797  (*tree)->divebdchgsize[p] = 1;
4798  }
4799 
4800  (*tree)->path = NULL;
4801  (*tree)->focusnode = NULL;
4802  (*tree)->focuslpfork = NULL;
4803  (*tree)->focuslpstatefork = NULL;
4804  (*tree)->focussubroot = NULL;
4805  (*tree)->children = NULL;
4806  (*tree)->siblings = NULL;
4807  (*tree)->probingroot = NULL;
4808  (*tree)->childrenprio = NULL;
4809  (*tree)->siblingsprio = NULL;
4810  (*tree)->pathnlpcols = NULL;
4811  (*tree)->pathnlprows = NULL;
4812  (*tree)->probinglpistate = NULL;
4813  (*tree)->probinglpinorms = NULL;
4814  (*tree)->pendingbdchgs = NULL;
4815  (*tree)->probdiverelaxsol = NULL;
4816  (*tree)->nprobdiverelaxsol = 0;
4817  (*tree)->pendingbdchgssize = 0;
4818  (*tree)->npendingbdchgs = 0;
4819  (*tree)->focuslpstateforklpcount = -1;
4820  (*tree)->childrensize = 0;
4821  (*tree)->nchildren = 0;
4822  (*tree)->siblingssize = 0;
4823  (*tree)->nsiblings = 0;
4824  (*tree)->pathlen = 0;
4825  (*tree)->pathsize = 0;
4826  (*tree)->effectiverootdepth = 0;
4827  (*tree)->appliedeffectiverootdepth = 0;
4828  (*tree)->lastbranchparentid = -1L;
4829  (*tree)->correctlpdepth = -1;
4830  (*tree)->cutoffdepth = INT_MAX;
4831  (*tree)->repropdepth = INT_MAX;
4832  (*tree)->repropsubtreecount = 0;
4833  (*tree)->focusnodehaslp = FALSE;
4834  (*tree)->probingnodehaslp = FALSE;
4835  (*tree)->focuslpconstructed = FALSE;
4836  (*tree)->cutoffdelayed = FALSE;
4837  (*tree)->probinglpwasflushed = FALSE;
4838  (*tree)->probinglpwassolved = FALSE;
4839  (*tree)->probingloadlpistate = FALSE;
4840  (*tree)->probinglpwasrelax = FALSE;
4841  (*tree)->probingsolvedlp = FALSE;
4842  (*tree)->forcinglpmessage = FALSE;
4843  (*tree)->sbprobing = FALSE;
4844  (*tree)->probinglpwasprimfeas = TRUE;
4845  (*tree)->probinglpwasdualfeas = TRUE;
4846  (*tree)->probdiverelaxstored = FALSE;
4847  (*tree)->probdiverelaxincludeslp = FALSE;
4848 
4849  return SCIP_OKAY;
4850 }
4851 
4852 /** frees tree data structure */
4854  SCIP_TREE** tree, /**< pointer to tree data structure */
4855  BMS_BLKMEM* blkmem, /**< block memory buffers */
4856  SCIP_SET* set, /**< global SCIP settings */
4857  SCIP_STAT* stat, /**< problem statistics */
4858  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
4859  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
4860  SCIP_LP* lp /**< current LP data */
4861  )
4862 {
4863  int p;
4864 
4865  assert(tree != NULL);
4866  assert(*tree != NULL);
4867  assert((*tree)->nchildren == 0);
4868  assert((*tree)->nsiblings == 0);
4869  assert((*tree)->focusnode == NULL);
4870  assert(!SCIPtreeProbing(*tree));
4871 
4872  SCIPsetDebugMsg(set, "free tree\n");
4873 
4874  /* free node queue */
4875  SCIP_CALL( SCIPnodepqFree(&(*tree)->leaves, blkmem, set, stat, eventfilter, eventqueue, *tree, lp) );
4876 
4877  /* free diving bound change storage */
4878  for( p = 0; p <= 1; ++p )
4879  {
4880  BMSfreeBlockMemoryArray(blkmem, &(*tree)->divebdchgdirs[p], (*tree)->divebdchgsize[p]); /*lint !e866*/
4881  BMSfreeBlockMemoryArray(blkmem, &(*tree)->divebdchgvals[p], (*tree)->divebdchgsize[p]); /*lint !e866*/
4882  BMSfreeBlockMemoryArray(blkmem, &(*tree)->divebdchgvars[p], (*tree)->divebdchgsize[p]); /*lint !e866*/
4883  }
4884 
4885  /* free pointer arrays */
4886  BMSfreeMemoryArrayNull(&(*tree)->path);
4887  BMSfreeMemoryArrayNull(&(*tree)->children);
4888  BMSfreeMemoryArrayNull(&(*tree)->siblings);
4889  BMSfreeMemoryArrayNull(&(*tree)->childrenprio);
4890  BMSfreeMemoryArrayNull(&(*tree)->siblingsprio);
4891  BMSfreeMemoryArrayNull(&(*tree)->pathnlpcols);
4892  BMSfreeMemoryArrayNull(&(*tree)->pathnlprows);
4893  BMSfreeMemoryArrayNull(&(*tree)->probdiverelaxsol);
4894  BMSfreeMemoryArrayNull(&(*tree)->pendingbdchgs);
4895 
4896  BMSfreeMemory(tree);
4897 
4898  return SCIP_OKAY;
4899 }
4900 
4901 /** clears and resets tree data structure and deletes all nodes */
4903  SCIP_TREE* tree, /**< tree data structure */
4904  BMS_BLKMEM* blkmem, /**< block memory buffers */
4905  SCIP_SET* set, /**< global SCIP settings */
4906  SCIP_STAT* stat, /**< problem statistics */
4907  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
4908  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
4909  SCIP_LP* lp /**< current LP data */
4910  )
4911 {
4912  int v;
4913 
4914  assert(tree != NULL);
4915  assert(tree->nchildren == 0);
4916  assert(tree->nsiblings == 0);
4917  assert(tree->focusnode == NULL);
4918  assert(!SCIPtreeProbing(tree));
4919 
4920  SCIPsetDebugMsg(set, "clearing tree\n");
4921 
4922  /* clear node queue */
4923  SCIP_CALL( SCIPnodepqClear(tree->leaves, blkmem, set, stat, eventfilter, eventqueue, tree, lp) );
4924  assert(tree->root == NULL);
4925 
4926  /* we have to remove the captures of the variables within the pending bound change data structure */
4927  for( v = tree->npendingbdchgs-1; v >= 0; --v )
4928  {
4929  SCIP_VAR* var;
4930 
4931  var = tree->pendingbdchgs[v].var;
4932  assert(var != NULL);
4933 
4934  /* release the variable */
4935  SCIP_CALL( SCIPvarRelease(&var, blkmem, set, eventqueue, lp) );
4936  }
4937 
4938  /* mark working arrays to be empty and reset data */
4939  tree->focuslpstateforklpcount = -1;
4940  tree->nchildren = 0;
4941  tree->nsiblings = 0;
4942  tree->pathlen = 0;
4943  tree->effectiverootdepth = 0;
4944  tree->appliedeffectiverootdepth = 0;
4945  tree->correctlpdepth = -1;
4946  tree->cutoffdepth = INT_MAX;
4947  tree->repropdepth = INT_MAX;
4948  tree->repropsubtreecount = 0;
4949  tree->npendingbdchgs = 0;
4950  tree->