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