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