GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
cons_origbranch.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* GCG --- Generic Column Generation */
5/* a Dantzig-Wolfe decomposition based extension */
6/* of the branch-cut-and-price framework */
7/* SCIP --- Solving Constraint Integer Programs */
8/* */
9/* Copyright (C) 2010-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file cons_origbranch.c
30 *
31 * @brief constraint handler for storing the branching decisions at each node of the tree
32 * @author Gerald Gamrath
33 * @author Martin Bergner
34 */
35
36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37/* #define SCIP_DEBUG */
38/* #define CHECKCONSISTENCY */
39#include <assert.h>
40#include <string.h>
41
42#include "gcg/gcg.h"
43#include "gcg/branch_generic.h"
45#include "gcg/cons_origbranch.h"
46
47#include "scip/nodesel_bfs.h"
48#include "scip/nodesel_dfs.h"
55#include "scip/branch_mostinf.h"
57#include "scip/branch_pscost.h"
58#include "scip/branch_random.h"
60#include "scip/cons_linear.h"
61
62/* constraint handler properties */
63#define CONSHDLR_NAME "origbranch"
64#define CONSHDLR_DESC "store branching decision at nodes of the tree constraint handler"
65#define CONSHDLR_ENFOPRIORITY 0 /**< priority of the constraint handler for constraint enforcing */
66#define CONSHDLR_CHECKPRIORITY 2000000 /**< priority of the constraint handler for checking feasibility */
67#define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
68 * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
69#define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
70
71
72/** constraint data for branch orig constraints */
73struct SCIP_ConsData
74{
75 SCIP_NODE* node; /**< the node at which the cons is sticking */
76 SCIP_CONS* parentcons; /**< the origbranch constraint of the parent node */
77 SCIP_CONS** childconss; /**< array of the masterbranch constraints of child nodes */
78 int nchildconss; /**< number of the masterbranch constraints of child nodes */
79 int maxchildconss; /**< capacity of childconss */
80 SCIP_CONS* probingtmpcons; /**< pointer to save the last child in the childconss array if it is overwritten in probing mode */
81 SCIP_CONS* mastercons; /**< the masterbranch constraint of the corresponding node
82 * in the master program */
83 GCG_BRANCHDATA* branchdata; /**< branching data stored by the branching rule containing information
84 * about the branching restrictions */
85 GCG_BRANCHRULE* branchrule; /**< branching rule that created the corresponding node and imposed
86 * branching restrictions */
87};
88
89/** constraint handler data */
91{
92 GCG* gcg; /**< GCG data structure */
93 SCIP_CONS** stack; /**< stack for storing active constraints */
94 int nstack; /**< number of elements on the stack */
95 int maxstacksize; /**< maximum size of the stack */
96 SCIP_CONS* rootcons; /**< constraint in the root node */
97};
98
99
100/*
101 * Callback methods of constraint handler
102 */
103
104/** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
105static
106SCIP_DECL_CONSFREE(consFreeOrigbranch)
107{ /*lint --e{715}*/
108 SCIP_CONSHDLRDATA* conshdlrData;
109
110 assert(scip != NULL);
111 assert(conshdlr != NULL);
112 assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
113
114 conshdlrData = SCIPconshdlrGetData(conshdlr);
115 assert(conshdlrData != NULL);
116
117 SCIPdebugMessage("freeing branch orig constraint handler (nconss = %d)\n", SCIPconshdlrGetNConss(conshdlr));
118
119 /* free constraint handler storage */
120 assert(conshdlrData->stack == NULL);
121 if( conshdlrData->rootcons != NULL )
122 {
123 SCIP_CALL( SCIPreleaseCons(scip, &conshdlrData->rootcons) );
124 }
125
126 SCIPfreeMemory(scip, &conshdlrData);
127
128 return SCIP_OKAY;
129}
130
131
132/** solving process initialization method of constraint handler (called when branch and bound process is about to begin) */
133static
134SCIP_DECL_CONSINITSOL(consInitsolOrigbranch)
135{ /*lint --e{715}*/
136 SCIP_CONSHDLRDATA* conshdlrData;
137
138 assert(scip != NULL);
139 assert(conshdlr != NULL);
140 assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
141
142 conshdlrData = SCIPconshdlrGetData(conshdlr);
143 assert(conshdlrData != NULL);
144
145 /* prepare stack */
146 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &conshdlrData->stack, conshdlrData->maxstacksize) );
147 assert(conshdlrData->nstack >= 0);
148
149 /* check consistency */
150 if( conshdlrData->rootcons != NULL )
151 {
152 SCIP_CALL( SCIPreleaseCons(scip, &conshdlrData->rootcons) );
153 conshdlrData->rootcons = NULL;
154 --(conshdlrData->nstack);
155 }
156
158
159 return SCIP_OKAY;
160}
161
162
163/** solving process deinitialization method of constraint handler (called before branch and bound process data is freed) */
164static
165SCIP_DECL_CONSEXITSOL(consExitsolOrigbranch)
166{ /*lint --e{715}*/
167 SCIP_CONSHDLRDATA* conshdlrdata;
168 GCG_BRANCHDATA* branchdata;
169
170 assert(scip != NULL);
171 assert(conshdlr != NULL);
172 assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
173
174 conshdlrdata = SCIPconshdlrGetData(conshdlr);
175 assert(conshdlrdata != NULL);
176 assert(conshdlrdata->nstack <= 1);
177
178 SCIPdebugMessage("exiting solution process branch orig constraint handler (nconss = %d)\n", SCIPconshdlrGetNConss(conshdlr));
179
180 /* check for root */
181 if( conshdlrdata->rootcons != NULL )
182 {
183 branchdata = GCGconsOrigbranchGetBranchdata(conshdlrdata->rootcons);
184
185 SCIPfreeMemoryNull(scip, &branchdata );
186
187 SCIP_CALL( SCIPreleaseCons(scip, &conshdlrdata->rootcons) );
188 conshdlrdata->rootcons = NULL;
189 }
190
191 /* free stack */
192 SCIPfreeBlockMemoryArray(scip, &conshdlrdata->stack, conshdlrdata->maxstacksize);
193 conshdlrdata->stack = NULL;
194
195 return SCIP_OKAY;
196}
197
198/** exit method of constraint handler (called before problem is free transformed) */
199static
200SCIP_DECL_CONSEXIT(consExitOrigbranch)
201{ /*lint --e{715}*/
202 SCIP_CONSHDLRDATA* conshdlrdata;
203 assert(conshdlr != NULL);
204 assert(scip != NULL);
205 conshdlrdata = SCIPconshdlrGetData(conshdlr);
206 assert(conshdlrdata != NULL);
207
208 SCIPdebugMessage("exiting transformed branch orig constraint handler (nconss = %d)\n", SCIPconshdlrGetNConss(conshdlr));
209
210 if( conshdlrdata->rootcons != NULL )
211 {
212 SCIP_CALL( SCIPreleaseCons(scip, &conshdlrdata->rootcons) );
213 conshdlrdata->rootcons = NULL;
214 }
215 return SCIP_OKAY;
216}
217
218/** frees specific constraint data */
219static
220SCIP_DECL_CONSDELETE(consDeleteOrigbranch)
221{ /*lint --e{715}*/
222 SCIP_CONSDATA* parentdata;
223 int i;
224
225 assert(scip != NULL);
226 assert(conshdlr != NULL);
227 assert(cons != NULL);
228 assert(consdata != NULL);
229 assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
230 assert(*consdata != NULL);
231
232 SCIPdebugMessage("Deleting branch orig constraint: <%s>.\n", SCIPconsGetName(cons));
233
234 /* set the origcons pointer of the corresponding mastercons to NULL */
235 if( (*consdata)->mastercons != NULL )
236 {
237 assert(GCGconsMasterbranchGetOrigcons((*consdata)->mastercons) == cons);
238 GCGconsMasterbranchSetOrigcons((*consdata)->mastercons, NULL);
239 }
240
241 /* set the pointer in the parent constraint to NULL */
242 if( (*consdata)->parentcons != NULL )
243 {
244#ifndef NDEBUG
245 SCIP_Bool childdeleted = FALSE;
246#endif
247 parentdata = SCIPconsGetData((*consdata)->parentcons);
248
249 if( SCIPinProbing(scip) )
250 parentdata->probingtmpcons = NULL;
251
252 for( i = 0; i < parentdata->nchildconss; ++i )
253 {
254 if( parentdata->childconss[i] == cons )
255 {
256
257 parentdata->childconss[i] = parentdata->childconss[parentdata->nchildconss-1];
258 parentdata->childconss[parentdata->nchildconss-1] = NULL;
259#ifndef NDEBUG
260 childdeleted = TRUE;
261#endif
262 (parentdata->nchildconss) -= 1;
263 break;
264 }
265 }
266 assert(childdeleted || SCIPinProbing(scip));
267 }
268
269 /* no child nodes may exist */
270 for( i = 0; i < (*consdata)->nchildconss; ++i )
271 assert((*consdata)->childconss[i] == NULL);
272
273 /* allow the correspondig branchrule to delete the branch data */
274 if( (*consdata)->branchdata != NULL && (*consdata)->branchrule != NULL )
275 {
276 SCIP_Bool force = ((*consdata)->mastercons == NULL);
277 SCIP_CALL( GCGrelaxBranchDataDelete(GCGorigGetGcg(scip), (*consdata)->branchrule, &(*consdata)->branchdata, TRUE, force) );
278 if( (*consdata)->mastercons != NULL && (*consdata)->branchdata == NULL )
279 GCGconsMasterbranchSetBranchdata((*consdata)->mastercons, NULL);
280 }
281
282 (*consdata)->branchdata = NULL;
283
284 SCIPfreeBlockMemoryArrayNull(scip, &(*consdata)->childconss, (*consdata)->maxchildconss);
285 (*consdata)->childconss = NULL;
286 (*consdata)->nchildconss = 0;
287 (*consdata)->maxchildconss = 0;
288
289 /* free constraint data */
290 SCIPfreeBlockMemory(scip, consdata);
291 *consdata = NULL;
292
293 return SCIP_OKAY;
294}
295
296
297/** constraint activation notification method of constraint handler */
298static
299SCIP_DECL_CONSACTIVE(consActiveOrigbranch)
300{ /*lint --e{715}*/
301 SCIP_CONSHDLRDATA* conshdlrData;
302
303 assert(scip != NULL);
304 assert(conshdlr != NULL);
305 assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
306 assert(cons != NULL);
307
308 conshdlrData = SCIPconshdlrGetData(conshdlr);
309 assert(conshdlrData != NULL);
310 assert(conshdlrData->stack != NULL);
311
312 assert(SCIPconsGetData(cons) != NULL);
313
314 if( SCIPconsGetData(cons)->node == NULL )
316
317 SCIPdebugMessage("Activating branch orig constraint: <%s>[stack size: %d].\n", SCIPconsGetName(cons),
318 conshdlrData->nstack+1);
319
320 /* put constraint on the stack */
321 if( conshdlrData->nstack >= conshdlrData->maxstacksize )
322 {
323 int newsize = SCIPcalcMemGrowSize(scip, conshdlrData->nstack+1);
324 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(conshdlrData->stack), conshdlrData->maxstacksize, newsize) );
325 SCIPdebugMessage("reallocating Memory for stack! %d --> %d\n", conshdlrData->maxstacksize, newsize);
326 conshdlrData->maxstacksize = newsize;
327 }
328
329 /* put constraint on the stack */
330 assert(conshdlrData->stack != NULL);
331 conshdlrData->stack[conshdlrData->nstack] = cons;
332 ++(conshdlrData->nstack);
333
334 return SCIP_OKAY;
335}
336
337
338/** constraint deactivation notification method of constraint handler */
339static
340SCIP_DECL_CONSDEACTIVE(consDeactiveOrigbranch)
341{ /*lint --e{715}*/
342 SCIP_CONSHDLRDATA* conshdlrData;
343
344 assert(scip != NULL);
345 assert(conshdlr != NULL);
346 assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
347 assert(cons != NULL);
348
349 conshdlrData = SCIPconshdlrGetData(conshdlr);
350 assert(conshdlrData != NULL);
351 assert(conshdlrData->stack != NULL || conshdlrData->nstack <= 1);
352 assert(conshdlrData->nstack <= 1 || cons == conshdlrData->stack[conshdlrData->nstack-1]);
353
354 assert(SCIPconsGetData(cons) != NULL);
355
356 SCIPdebugMessage("Deactivating branch orig constraint: <%s> [stack size: %d].\n",
357 SCIPconsGetName(cons), conshdlrData->nstack-1);
358
359 /* remove constraint from the stack */
360 if( conshdlrData->nstack > 0 )
361 --(conshdlrData->nstack);
362
363 return SCIP_OKAY;
364}
365
366/** lp solution enforcement method */
367static
368SCIP_DECL_CONSENFOLP(consEnfolpOrigbranch)
369{ /*lint --e{715}*/
371
372 return SCIP_OKAY;
373}
374
375/** lp solution enforcement method */
376static
377SCIP_DECL_CONSENFORELAX(consEnforeOrigbranch)
378{ /*lint --e{715}*/
380
381 return SCIP_OKAY;
382}
383
384
385/** pseudo solution enforcement method */
386static
387SCIP_DECL_CONSENFOPS(consEnfopsOrigbranch)
388{ /*lint --e{715}*/
390
391 return SCIP_OKAY;
392}
393
394/** solution check method */
395static
396SCIP_DECL_CONSCHECK(consCheckOrigbranch)
397{ /*lint --e{715}*/
399
400 return SCIP_OKAY;
401}
402
403/** variable lock method */
404static
405SCIP_DECL_CONSLOCK(consLockOrigbranch)
406{ /*lint --e{715}*/
407 return SCIP_OKAY;
408}
409
410/*
411 * interface methods
412 */
413
414
415/** creates the handler for origbranch constraints and includes it in SCIP */
417 GCG* gcg /**< GCG data structure */
418 )
419{
420 SCIP_CONSHDLRDATA* conshdlrData;
421 SCIP_CONSHDLR* conshdlr;
423 assert(origprob != NULL);
424
425 SCIP_CALL( SCIPallocMemory(origprob, &conshdlrData) );
426 conshdlrData->gcg = gcg;
427 conshdlrData->stack = NULL;
428 conshdlrData->nstack = 0;
429 conshdlrData->maxstacksize = 25;
430 conshdlrData->rootcons = NULL;
431
432 /* include constraint handler */
435 consEnfolpOrigbranch, consEnfopsOrigbranch, consCheckOrigbranch,
436 consLockOrigbranch, conshdlrData) );
437 assert(conshdlr != NULL);
438
439 SCIP_CALL( SCIPsetConshdlrEnforelax(origprob, conshdlr, consEnforeOrigbranch) );
440 SCIP_CALL( SCIPsetConshdlrFree(origprob, conshdlr, consFreeOrigbranch) );
441 SCIP_CALL( SCIPsetConshdlrExit(origprob, conshdlr, consExitOrigbranch) );
442 SCIP_CALL( SCIPsetConshdlrInitsol(origprob, conshdlr, consInitsolOrigbranch) );
443 SCIP_CALL( SCIPsetConshdlrExitsol(origprob, conshdlr, consExitsolOrigbranch) );
444 SCIP_CALL( SCIPsetConshdlrDelete(origprob, conshdlr, consDeleteOrigbranch) );
445 SCIP_CALL( SCIPsetConshdlrActive(origprob, conshdlr, consActiveOrigbranch) );
446 SCIP_CALL( SCIPsetConshdlrDeactive(origprob, conshdlr, consDeactiveOrigbranch) );
447
448 return SCIP_OKAY;
449}
450
451
452/** creates and captures a origbranch constraint */
454 GCG* gcg, /**< GCG data structure */
455 SCIP_CONS** cons, /**< pointer to hold the created constraint */
456 const char* name, /**< name of constraint */
457 SCIP_NODE* node, /**< the node to which this origbranch constraint belongs */
458 SCIP_CONS* parentcons, /**< origbranch constraint associated with the father node */
459 GCG_BRANCHRULE* branchrule, /**< the branching rule that created the b&b node the constraint belongs to */
460 GCG_BRANCHDATA* branchdata /**< branching data storing information about the branching restrictions at the
461 * corresponding node */
462 )
463{
464 SCIP* scip;
465 SCIP_CONSHDLR* conshdlr;
466 SCIP_CONSDATA* consdata;
467
468 assert(gcg != NULL);
469 assert((parentcons == NULL) == (node == NULL));
470
472 /* find the origbranch constraint handler */
474 assert(conshdlr != NULL);
475
476 /* create constraint data */
477 SCIP_CALL( SCIPallocBlockMemory(scip, &consdata) );
478
479 /* initialize the fields in the constraint data */
480 consdata->node = node;
481 consdata->parentcons = parentcons;
482 consdata->childconss = NULL;
483 consdata->nchildconss = 0;
484 consdata->maxchildconss = 0;
485 consdata->probingtmpcons = NULL;
486 consdata->mastercons = NULL;
487 consdata->branchdata = branchdata;
488 consdata->branchrule = branchrule;
489
490 SCIPdebugMessage("Creating branch orig constraint: <%s> (nconss = %d).\n", name, SCIPconshdlrGetNConss(conshdlr));
491
492 /* create constraint */
493 SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, FALSE, FALSE, FALSE, FALSE, FALSE,
494 TRUE, FALSE, FALSE, FALSE, TRUE) );
495
496 /* store the pointer to the new constraint in the origbranch constraint of the parent node */
497 if( parentcons != NULL )
498 {
499 SCIP_CONSDATA* parentdata;
500
501 parentdata = SCIPconsGetData(parentcons);
502 assert(parentdata != NULL);
503
504 if( SCIPinProbing(scip) )
505 {
506 parentdata->probingtmpcons = *cons;
507 }
508 else
509 {
510 int newsize;
511 ++parentdata->nchildconss;
512 newsize = SCIPcalcMemGrowSize(scip, parentdata->nchildconss);
513 if( parentdata->nchildconss == 1 )
514 {
515 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(parentdata->childconss), newsize) );
516 parentdata->childconss[0] = NULL;
517 }
518 else
519 {
520 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(parentdata->childconss), parentdata->maxchildconss, newsize) );
521 parentdata->childconss[parentdata->nchildconss - 1] = NULL;
522 }
523 parentdata->maxchildconss = newsize;
524 parentdata->childconss[parentdata->nchildconss-1] = *cons;
525 }
526 }
527
528 return SCIP_OKAY;
529}
530
531/** returns the branch orig constraint of the current node, only needs the pointer to scip */
533 GCG* gcg /**< GCG data structure */
534 )
535{
536 SCIP* scip;
537 SCIP_CONSHDLR* conshdlr;
538 SCIP_CONSHDLRDATA* conshdlrData;
539
540 assert(gcg != NULL);
543 assert(conshdlr != NULL);
544
545 conshdlrData = SCIPconshdlrGetData(conshdlr);
546 assert(conshdlrData != NULL);
547 assert(conshdlrData->stack != NULL);
548 assert(conshdlrData->nstack > 0);
549
550 return conshdlrData->stack[conshdlrData->nstack-1];
551}
552
553/** returns the stack and the number of elements on it */
555 GCG* gcg, /**< GCG data structure */
556 SCIP_CONS*** stack, /**< return value: pointer to the stack */
557 int* nstackelements /**< return value: pointer to int, for number of elements on the stack */
558 )
559{
560 SCIP* scip;
561 SCIP_CONSHDLR* conshdlr;
562 SCIP_CONSHDLRDATA* conshdlrData;
563
564 assert(gcg != NULL);
567 assert(conshdlr != NULL);
568
569 conshdlrData = SCIPconshdlrGetData(conshdlr);
570 assert(conshdlrData != NULL);
571 assert(conshdlrData->stack != NULL);
572
573 *stack = conshdlrData->stack;
574 *nstackelements = conshdlrData->nstack;
575}
576
577/** sets the branching data for a given origbranch constraint */
579 SCIP_CONS* cons, /**< origbranch constraint for which the branching data is requested */
580 GCG_BRANCHDATA* branchdata /**< branching data */
581 )
582{
583 SCIP_CONSDATA* consdata;
584
585 consdata = SCIPconsGetData(cons);
586 assert(consdata != NULL);
587
588 consdata->branchdata = branchdata;
589}
590
591/** returns the branching data for a given origbranch constraint */
593 SCIP_CONS* cons /**< origbranch constraint for which the branching data is requested */
594 )
595{
596 SCIP_CONSDATA* consdata;
597
598 consdata = SCIPconsGetData(cons);
599 assert(consdata != NULL);
600
601 return consdata->branchdata;
602}
603
604/** returns the branching rule for a given origbranch constraint */
606 SCIP_CONS* cons /**< origbranch constraint for which the branchrule is requested */
607 )
608{
609 SCIP_CONSDATA* consdata;
610 assert(cons != NULL);
611
612 consdata = SCIPconsGetData(cons);
613 assert(consdata != NULL);
614
615 return consdata->branchrule;
616}
617
618/** returns the node in the B&B tree at which the given origbranch constraint is sticking */
620 SCIP_CONS* cons /**< origbranch constraint for which the corresponding node is requested */
621 )
622{
623 SCIP_CONSDATA* consdata;
624 assert(cons != NULL);
625
626 consdata = SCIPconsGetData(cons);
627 assert(consdata != NULL);
628
629 return consdata->node;
630}
631
632/** returns the origbranch constraint of the B&B father of the node at which the
633 * given origbranch constraint is sticking
634 */
636 SCIP_CONS* cons /**< origbranch constraint for which the origbranch constraint of
637 * the father node is requested */
638 )
639{
640 SCIP_CONSDATA* consdata;
641 assert(cons != NULL);
642
643 consdata = SCIPconsGetData(cons);
644 assert(consdata != NULL);
645
646 return consdata->parentcons;
647}
648
649/** returns the number of origbranch constraints of the children of the node at which the
650 * given origbranch constraint is sticking
651 */
653 SCIP_CONS* cons /**< constraint */
654 )
655{
656 SCIP_CONSDATA* consdata;
657
658 consdata = SCIPconsGetData(cons);
659 assert(consdata != NULL);
660
661 return consdata->nchildconss;
662}
663
664/** returns an origbranch constraint of a child of the node at which the
665 * given origbranch constraint is sticking
666 */
668 SCIP_CONS* cons, /**< constraint */
669 int childnr /**< number of child */
670 )
671{
672 SCIP_CONSDATA* consdata;
673
674 consdata = SCIPconsGetData(cons);
675 assert(consdata != NULL);
676 assert(consdata->childconss != NULL);
677 assert(consdata->nchildconss > childnr);
678
679 return consdata->childconss[childnr];
680}
681
682/** sets the masterbranch constraint of the node in the master program corresponding to the node
683 * at which the given origbranchbranch constraint is sticking
684 */
686 SCIP_CONS* cons, /**< origbranch constraint for which the masterbranch constraint should be set */
687 SCIP_CONS* mastercons /**< masterbranch constraint corresponding to the given origbranch constraint */
688 )
689{
690 SCIP_CONSDATA* consdata;
691 assert(cons != NULL);
692
693 consdata = SCIPconsGetData(cons);
694 assert(consdata != NULL);
695
696 consdata->mastercons = mastercons;
697}
698
699/** returns the masterbranch constraint of the node in the master program corresponding to the node
700 * at which the given origbranchbranch constraint is sticking
701 */
703 SCIP_CONS* cons /**< origbranch constraint for which the corresponding masterbranch
704 * constraint is requested */
705 )
706{
707 SCIP_CONSDATA* consdata;
708 assert(cons != NULL);
709
710 consdata = SCIPconsGetData(cons);
711 assert(consdata != NULL);
712
713 return consdata->mastercons;
714}
715
716/** adds initial constraint to root node */
718 GCG* gcg /**< GCG data structure */
719 )
720{
721 SCIP* scip;
722 SCIP_CONSHDLR* conshdlr;
723 SCIP_CONSHDLRDATA* conshdlrdata;
724 SCIP_CONS* cons;
725 SCIP_CONS** conss;
726 int nconss;
727 int i;
728
729 assert(gcg != NULL);
730
733 assert(conshdlr != NULL);
734
735 nconss = SCIPconshdlrGetNConss(conshdlr);
736 assert(nconss <= 1);
737 conss = SCIPconshdlrGetConss(conshdlr);
738 for( i = 0; i < nconss; ++i )
739 {
740 SCIP_CALL( SCIPdelCons(scip, conss[i]) );
741 }
742
743 conshdlrdata = SCIPconshdlrGetData(conshdlr);
744 assert(conshdlrdata != NULL);
745 assert(SCIPconshdlrGetNConss(conshdlr) == 0);
746 if( conshdlrdata->rootcons == NULL )
747 {
748 SCIP_CALL( GCGcreateConsOrigbranch(gcg, &cons, "root-origbranch", NULL, NULL, NULL, NULL) );
750 conshdlrdata->rootcons = cons;
751 }
752
753 /* check consistency */
755
756 return SCIP_OKAY;
757}
758
759/** checks the consistency of the origbranch constraints in the problem */
761 GCG* gcg /**< GCG data structure */
762 )
763{
764#ifdef CHECKCONSISTENCY
765 SCIP* scip;
766 SCIP_CONSHDLR* conshdlr;
767
768#ifndef NDEBUG
769 SCIP_CONS** conss;
770 int nconss;
771 int i;
772#endif
773
774 assert(gcg != NULL);
777 if( conshdlr == NULL )
778 {
779 SCIPerrorMessage("origbranch constraint handler not found\n");
780 return;
781 }
782#ifndef NDEBUG
783 conss = SCIPconshdlrGetConss(conshdlr);
784 nconss = SCIPconshdlrGetNConss(conshdlr);
785
786 for( i = 0; i < nconss; i++ )
787 {
788 SCIP_CONSDATA* consdata = SCIPconsGetData(conss[i]);
789 assert(consdata != NULL);
790 assert(consdata->node != NULL);
791 assert((consdata->parentcons == NULL) == (SCIPnodeGetDepth(consdata->node) == 0));
792 /** todo assertions for all nchildcons */
793 if( consdata->nchildconss == 2 )
794 assert(consdata->parentcons == NULL || SCIPconsGetData(consdata->parentcons)->childconss[0] == conss[i]
795 || SCIPconsGetData(consdata->parentcons)->childconss[1] == conss[i]
796 || ( SCIPinProbing(scip) && SCIPconsGetData(consdata->parentcons)->probingtmpcons == conss[i]));
797 if( consdata->nchildconss == 2 )
798 assert(consdata->childconss[0] == NULL || SCIPconsGetData(consdata->childconss[0])->parentcons == conss[i]);
799 if( consdata->nchildconss == 2 )
800 assert(consdata->childconss[1] == NULL || SCIPconsGetData(consdata->childconss[1])->parentcons == conss[i]);
801 assert(consdata->probingtmpcons == NULL || SCIPinProbing(scip));
802 assert(consdata->probingtmpcons == NULL || SCIPconsGetData(consdata->probingtmpcons)->parentcons == conss[i]);
803 assert(consdata->mastercons == NULL || GCGconsMasterbranchGetOrigcons(consdata->mastercons) == conss[i]);
804 }
805#endif
806#endif
807}
SCIP_DECL_CONSENFOPS(ConshdlrSubtour::scip_enfops)
SCIP_DECL_CONSLOCK(ConshdlrSubtour::scip_lock)
SCIP_DECL_CONSDELETE(ConshdlrSubtour::scip_delete)
SCIP_DECL_CONSCHECK(ConshdlrSubtour::scip_check)
SCIP_DECL_CONSENFOLP(ConshdlrSubtour::scip_enfolp)
branching rule based on vanderbeck's generic branching scheme
#define CONSHDLR_NEEDSCONS
#define CONSHDLR_CHECKPRIORITY
#define CONSHDLR_DESC
#define CONSHDLR_EAGERFREQ
#define CONSHDLR_ENFOPRIORITY
#define CONSHDLR_NAME
static SCIP_DECL_CONSFREE(consFreeIntegralOrig)
void GCGconsMasterbranchSetBranchdata(SCIP_CONS *cons, GCG_BRANCHDATA *branchdata)
SCIP_CONS * GCGconsMasterbranchGetOrigcons(SCIP_CONS *cons)
void GCGconsMasterbranchSetOrigcons(SCIP_CONS *cons, SCIP_CONS *origcons)
static SCIP_DECL_CONSEXITSOL(consExitSolMasterbranch)
static SCIP_DECL_CONSINITSOL(consInitsolMasterbranch)
static SCIP_DECL_CONSEXIT(consExitMasterbranch)
static SCIP_DECL_CONSDEACTIVE(consDeactiveMasterbranch)
static SCIP_DECL_CONSACTIVE(consActiveMasterbranch)
constraint handler for storing the branching decisions at each node of the tree
int GCGconsOrigbranchGetNChildconss(SCIP_CONS *cons)
SCIP_CONS * GCGconsOrigbranchGetParentcons(SCIP_CONS *cons)
SCIP_CONS * GCGconsOrigbranchGetMastercons(SCIP_CONS *cons)
SCIP_CONS * GCGconsOrigbranchGetChildcons(SCIP_CONS *cons, int childnr)
SCIP_NODE * GCGconsOrigbranchGetNode(SCIP_CONS *cons)
void GCGconsOrigbranchCheckConsistency(GCG *gcg)
static SCIP_DECL_CONSENFORELAX(consEnforeOrigbranch)
void GCGconsOrigbranchSetBranchdata(SCIP_CONS *cons, GCG_BRANCHDATA *branchdata)
SCIP_CONS * GCGconsOrigbranchGetActiveCons(GCG *gcg)
GCG_BRANCHRULE * GCGconsOrigbranchGetBranchrule(SCIP_CONS *cons)
SCIP_RETCODE GCGconsOrigbranchAddRootCons(GCG *gcg)
GCG_BRANCHDATA * GCGconsOrigbranchGetBranchdata(SCIP_CONS *cons)
void GCGconsOrigbranchSetMastercons(SCIP_CONS *cons, SCIP_CONS *mastercons)
void GCGconsOrigbranchGetStack(GCG *gcg, SCIP_CONS ***stack, int *nstackelements)
SCIP_RETCODE GCGcreateConsOrigbranch(GCG *gcg, SCIP_CONS **cons, const char *name, SCIP_NODE *node, SCIP_CONS *parentcons, GCG_BRANCHRULE *branchrule, GCG_BRANCHDATA *branchdata)
SCIP_RETCODE GCGincludeConshdlrOrigbranch(GCG *gcg)
constraint handler for storing the branching decisions at each node of the tree
#define SCIP_Bool
#define TRUE
#define FALSE
GCG interface methods.
GCG * GCGorigGetGcg(SCIP *origprob)
Definition gcg.cpp:165
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddConsNode(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode)
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
SCIP_RETCODE SCIPsetConshdlrDeactive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDEACTIVE((*consdeactive)))
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
int SCIPconshdlrGetNConss(SCIP_CONSHDLR *conshdlr)
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
SCIP_RETCODE SCIPsetConshdlrExit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXIT((*consexit)))
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
SCIP_RETCODE SCIPsetConshdlrExitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITSOL((*consexitsol)))
SCIP_RETCODE SCIPsetConshdlrInitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITSOL((*consinitsol)))
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
SCIP_RETCODE SCIPsetConshdlrActive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSACTIVE((*consactive)))
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONSHDLR *conshdlr, SCIP_CONSDATA *consdata, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeMemoryNull(scip, ptr)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPallocBlockMemory(scip, ptr)
int SCIPnodeGetDepth(SCIP_NODE *node)
SCIP_Bool SCIPinProbing(SCIP *scip)
SCIP_NODE * SCIPgetRootNode(SCIP *scip)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
* result
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
#define NULL
#define SCIPerrorMessage
SCIP_RETCODE GCGrelaxBranchDataDelete(GCG *gcg, GCG_BRANCHRULE *branchrule, GCG_BRANCHDATA **branchdata, SCIP_Bool origbranch, SCIP_Bool force)
Definition relax_gcg.c:3858
SCIP_CONS ** childconss
SCIP_CONS * mastercons
GCG_BRANCHDATA * branchdata
GCG_BRANCHRULE * branchrule
SCIP_CONS * parentcons
SCIP_CONS * probingtmpcons
struct GCG_BranchData GCG_BRANCHDATA
struct GCG_Branchrule GCG_BRANCHRULE
struct SCIP_Cons SCIP_CONS
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
struct SCIP_Conshdlr SCIP_CONSHDLR
struct SCIP_ConsData SCIP_CONSDATA
struct Gcg GCG
Definition type_gcg.h:44
SCIP_FEASIBLE
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Node SCIP_NODE