Scippy

GCG

Branch-and-Price & Column Generation for Everyone

branch_generic.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 branch_generic.c
30 *
31 * @brief branching rule based on vanderbeck's generic branching scheme
32 * @author Marcel Schmickerath
33 * @author Martin Bergner
34 * @author Jonas Witt
35 */
36
37/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
38
39/*#define SCIP_DEBUG*/
40
41#include "gcg/branch_generic.h"
42#include "gcg/pub_gcgvar.h"
44#include "gcg/relax_gcg.h"
46#include "gcg/cons_origbranch.h"
47#include "gcg/pricer_gcg.h"
48#include "gcg/type_branchgcg.h"
49#include "gcg/gcg.h"
51#include "gcg/gcgsort.h"
52
53#include "scip/cons_linear.h"
54#include "scip/nodesel_bfs.h"
55#include "scip/nodesel_dfs.h"
62#include "scip/branch_mostinf.h"
64#include "scip/branch_pscost.h"
65#include "scip/branch_random.h"
67
68#include <assert.h>
69#include <string.h>
70
71
72#define BRANCHRULE_NAME "generic"
73#define BRANCHRULE_DESC "generic branching rule by Vanderbeck"
74#define BRANCHRULE_PRIORITY -100
75#define BRANCHRULE_MAXDEPTH -1
76#define BRANCHRULE_MAXBOUNDDIST 1.0
77
78
79#define EVENTHDLR_NAME "genericbranchvaradd"
80#define EVENTHDLR_DESC "event handler for adding a new generated mastervar into the right branching constraints by using Vanderbecks generic branching scheme"
81
82/** branching data */
83struct GCG_BranchData
84{
85 GCG_COMPSEQUENCE** C; /**< S[k] bound sequence for block k */ /* !!! sort of each C[i] = S is important !!! */
86 SCIP_Real lhs; /**< lefthandside of the constraint corresponding to the bound sequence C */
87 SCIP_CONS* mastercons; /**< constraint enforcing the branching restriction in the master problem */
88 GCG_COMPSEQUENCE* consS; /**< component bound sequence which induce the current branching constraint */
89 int consSsize; /**< size of the component bound sequence */
90 int maxconsS; /**< size of consS */
91 int consblocknr; /**< id of the pricing problem (or block) to which this branching constraint belongs */
92};
93
94/** set of component bounds in separate */
96{
97 GCG_COMPSEQUENCE** record; /**< array of component bound sequences in record */
98 int recordsize; /**< number of component bound sequences in record */
99 int recordcapacity; /**< capacity of record */
100 int* sequencesizes; /**< array of sizes of component bound sequences */
101 int* capacities; /**< array of capacities of component bound sequences */
102};
103typedef struct GCG_Record GCG_RECORD;
104
106{
107 GCG* gcg; /**< GCG data structure */
108 GCG_BRANCHRULE* gcgbranchrule; /**< GCG branchrule structure */
109};
110
112{
113 GCG* gcg; /**< GCG data structure */
114};
115
116static
118 GCG* gcg, /**< GCG data structure */
119 GCG_BRANCHRULE* branchrule, /**< branching rule */
120 SCIP_RESULT* result, /**< pointer to store the result of the branching call */
121 int** checkedblocks, /**< blocks that have been checked */
122 int* ncheckedblocks, /**< number of checked blocks */
123 GCG_STRIP**** checkedblockssortstrips, /**< sorted strips of checked blocks */
124 int** checkedblocksnsortstrips /**< sizes of the strips */
125 );
126
127/*
128 * Callback methods
129 */
130
131/* define not used callback as NULL*/
132#define branchExitGeneric NULL
133#define branchInitsolGeneric NULL
134#define branchExitsolGeneric NULL
135
136/** computes the generator of mastervar for the entry in origvar
137 * @return entry of the generator corresponding to origvar */
138static
140 SCIP_VAR* mastervar, /**< current mastervariable */
141 SCIP_VAR* origvar /**< corresponding origvar */
142 )
143{
144 SCIP_Real entry = GCGmasterVarGetOrigval(mastervar, origvar);
145
146 return entry != SCIP_INVALID ? entry : 0.;
147}
148
149/** determine the coefficient for a column */
150static
152 SCIP* scip, /**< SCIP data structure */
153 GCG_BRANCHDATA* branchdata, /**< branching data structure where the variable should be added */
154 SCIP_VAR* mastervar, /**< cmaster variable */
155 int probnr /**< number of the pricing problem */
156 )
157{
158 int p;
159 SCIP_Bool varinS = TRUE;
160
161 assert(scip != NULL);
162 assert(GCGisMaster(scip));
163 assert(branchdata != NULL);
164 assert(branchdata->mastercons != NULL);
165
166 if( probnr == -1 || GCGbranchGenericBranchdataGetConsblocknr(branchdata) == -3 || probnr != GCGbranchGenericBranchdataGetConsblocknr(branchdata) )
167 return 0.;
168
169 SCIPdebugMessage("consSsize = %d\n", GCGbranchGenericBranchdataGetConsSsize(branchdata));
170
171 for( p = 0; p < GCGbranchGenericBranchdataGetConsSsize(branchdata); ++p )
172 {
173 SCIP_Real generatorentry;
174
175 generatorentry = getGeneratorEntry(mastervar, GCGbranchGenericBranchdataGetConsS(branchdata)[p].component);
176
177 if( GCGbranchGenericBranchdataGetConsS(branchdata)[p].sense == GCG_COMPSENSE_GE )
178 {
179 if( SCIPisLT(scip, generatorentry, GCGbranchGenericBranchdataGetConsS(branchdata)[p].bound) )
180 {
181 varinS = FALSE;
182 break;
183 }
184 }
185 else
186 {
187 if( SCIPisGE(scip, generatorentry, GCGbranchGenericBranchdataGetConsS(branchdata)[p].bound) )
188 {
189 varinS = FALSE;
190 break;
191 }
192 }
193 }
194
195 if( varinS )
196 return 1.;
197 else
198 return 0.;
199}
200
201/** initialize branchdata at the node */
202static
204 SCIP* scip, /**< SCIP data structure */
205 GCG_BRANCHDATA** nodebranchdata, /**< branching data to set */
206 int blocknr /**< block we are branching in */
207 )
208{
209 SCIP_CALL( SCIPallocBlockMemory(scip, nodebranchdata) );
210
211 (*nodebranchdata)->consblocknr = blocknr;
212 (*nodebranchdata)->mastercons = NULL;
213 (*nodebranchdata)->consS = NULL;
214 (*nodebranchdata)->C = NULL;
215 (*nodebranchdata)->maxconsS = 0;
216 (*nodebranchdata)->consSsize = 0;
217
218 return SCIP_OKAY;
219}
220
221/** adds a variable to a branching constraint */
222static
224 SCIP* masterprob, /**< SCIP data structure */
225 SCIP_VAR* mastervar, /**< the variable to add */
226 GCG_BRANCHDATA* branchdata, /**< branching data structure where the variable should be added */
227 SCIP_Bool* added /**< whether the variable was added */
228 )
229{
230 SCIP_Real coef;
231
232 assert(masterprob != NULL);
233 assert(mastervar != NULL);
234 assert(branchdata != NULL);
235 assert(added != NULL);
236
237 *added = FALSE;
238
239 coef = getColCoefficient(masterprob, branchdata, mastervar, GCGvarGetBlock(mastervar));
240
241 if( !SCIPisZero(masterprob, coef) )
242 {
243 SCIPdebugMessage("mastervar is added\n");
244 SCIP_CALL( SCIPaddCoefLinear(masterprob, GCGbranchGenericBranchdataGetMastercons(branchdata), mastervar, coef) );
245 *added = TRUE;
246 }
247
248 return SCIP_OKAY;
249}
250
251/** creates the constraint for branching directly on a master variable */
252static
254 SCIP* scip, /**< SCIP data structure */
255 SCIP_NODE* node, /**< node to add constraint */
256 GCG_BRANCHDATA* branchdata /**< branching data structure */
257 )
258{
259 char name[SCIP_MAXSTRLEN];
260
261 assert(scip != NULL);
262 assert(node != NULL);
263 assert(branchdata->consblocknr == -3);
264 assert(branchdata->consSsize == 1);
265
266 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "directchild(%d, %g) sense = %d", branchdata->consSsize, branchdata->consS[0].bound, branchdata->consS[0].sense);
267
268 /* create constraint for child */
269 if( branchdata->consS[0].sense == GCG_COMPSENSE_GE )
270 {
271 SCIP_CALL( SCIPcreateConsLinear(scip, &(branchdata->mastercons), name, 0, NULL, NULL, branchdata->consS[0].bound, SCIPinfinity(scip), TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
272 } else
273 {
274 SCIP_CALL( SCIPcreateConsLinear(scip, &(branchdata->mastercons), name, 0, NULL, NULL, -SCIPinfinity(scip), branchdata->consS[0].bound-1, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
275 }
276 assert(GCGvarIsMaster(branchdata->consS[0].component));
277 SCIP_CALL( SCIPaddCoefLinear(scip, branchdata->mastercons, branchdata->consS[0].component, 1.0) );
278
279 /* add constraint to the master problem that enforces the branching decision */
280 SCIP_CALL( SCIPaddConsNode(scip, node, branchdata->mastercons, NULL) );
281
282 return SCIP_OKAY;
283}
284
285/** creates the constraint for branching directly on a master variable */
286static
288 GCG* gcg, /**< GCG data structure */
289 SCIP_NODE* node, /**< node to add constraint */
290 GCG_BRANCHDATA* branchdata /**< branching data structure */
291 )
292{
293 char name[SCIP_MAXSTRLEN];
294 SCIP_Bool added = FALSE;
295 SCIP* masterprob = GCGgetMasterprob(gcg);
296
297 assert(masterprob != NULL);
298 assert(node != NULL);
299 assert(branchdata != NULL);
300
301 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "child(%d, %g)", branchdata->consSsize, branchdata->lhs);
302
303 assert(branchdata->mastercons == NULL);
304
305 /* create constraint for child */
306 SCIP_CALL( SCIPcreateConsLinear(masterprob, &(branchdata->mastercons), name, 0, NULL, NULL,
307 branchdata->lhs, SCIPinfinity(masterprob), TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
308
309 SCIP_CALL( SCIPaddConsNode(masterprob, node, branchdata->mastercons, NULL) );
310
312 int nvars = GCGmasterGetNPricedvars(gcg);
313
314 for( int i = 0; i < nvars; ++i )
315 {
316 SCIP_CALL( addVarToMasterbranch(masterprob, vars[i], branchdata, &added) );
317 }
318
319 return SCIP_OKAY;
320}
321
322/** solving process initialization method of event handler (called when branch and bound process is about to begin) */
323static
324SCIP_DECL_EVENTINITSOL(eventInitsolGenericbranchvaradd)
325{ /*lint --e{715}*/
326 assert(scip != NULL);
327 assert(eventhdlr != NULL);
328 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
329
330 /* notify SCIP that your event handler wants to react on the event type */
332
333 return SCIP_OKAY;
334}
335
336/** solving process deinitialization method of event handler (called before branch and bound process data is freed) */
337static
338SCIP_DECL_EVENTEXITSOL(eventExitsolGenericbranchvaradd)
339{ /*lint --e{715}*/
340 assert(scip != NULL);
341 assert(eventhdlr != NULL);
342 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
343
344 /* notify SCIP that your event handler wants to drop the event type */
346
347 return SCIP_OKAY;
348}
349
350/** destructor method of event handler (called when SCIP is exiting) */
351static
352SCIP_DECL_EVENTFREE(eventFreeGenericbranchvaradd)
353{ /*lint --e{715}*/
354 SCIP_EVENTHDLRDATA* eventhdlrdata;
355 assert(scip != NULL);
356 assert(eventhdlr != NULL);
357 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
358
359 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
360 assert(eventhdlrdata != NULL);
361
362 SCIPfreeBlockMemory(scip, &eventhdlrdata);
363
364 return SCIP_OKAY;
365}
366
367/** execution method of event handler */
368static
369SCIP_DECL_EVENTEXEC(eventExecGenericbranchvaradd)
370{ /*lint --e{715}*/
371 SCIP* origprob;
372 SCIP_CONS* masterbranchcons;
373 SCIP_CONS* parentcons;
374 SCIP_VAR* mastervar;
375 SCIP_VAR** allorigvars;
376 SCIP_VAR** mastervars;
377 GCG_BRANCHDATA* branchdata;
378 SCIP_EVENTHDLRDATA* eventhdlrdata;
379 int allnorigvars;
380 int nmastervars;
381
382 assert(eventhdlr != NULL);
383 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
384 assert(event != NULL);
385 assert(scip != NULL);
387
388 mastervar = SCIPeventGetVar(event);
389 if( !GCGvarIsMaster(mastervar) )
390 return SCIP_OKAY;
391
392 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
393 assert(eventhdlrdata != NULL);
394 origprob = GCGgetOrigprob(eventhdlrdata->gcg);
395 assert(origprob != NULL);
396
397 /* SCIPdebugMessage("exec method of event_genericbranchvaradd\n"); */
398
399 masterbranchcons = GCGconsMasterbranchGetActiveCons(eventhdlrdata->gcg);
400 assert(masterbranchcons != NULL);
401
402 /* if branch rule is not generic, abort */
404 return SCIP_OKAY;
405
406 SCIP_CALL( SCIPgetVarsData(origprob, &allorigvars, &allnorigvars, NULL, NULL, NULL, NULL) );
407 SCIP_CALL( SCIPgetVarsData(scip, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
408
409 parentcons = masterbranchcons;
410 branchdata = GCGconsMasterbranchGetBranchdata(parentcons);
411
412
413 if( GCGvarIsMaster(mastervar) && GCGconsMasterbranchGetBranchrule(parentcons) != NULL )
414 {
415 SCIP_Bool added = FALSE;
416 SCIPdebugMessage("Mastervar <%s>\n", SCIPvarGetName(mastervar));
417 while( parentcons != NULL && branchdata != NULL
419 {
421 break;
422
423 assert(branchdata != NULL);
424
425
426 if( (GCGbranchGenericBranchdataGetConsblocknr(branchdata) != GCGvarGetBlock(mastervar) && GCGvarGetBlock(mastervar) != -1 )
427 || (GCGvarGetBlock(mastervar) == -1 && !GCGmasterVarIsLinking(mastervar)) )
428 {
429 parentcons = GCGconsMasterbranchGetParentcons(parentcons);
430
431 if( parentcons != NULL )
432 branchdata = GCGconsMasterbranchGetBranchdata(parentcons);
433
434 continue;
435 }
436
437 SCIP_CALL( addVarToMasterbranch(scip, mastervar, branchdata, &added) );
438
439 parentcons = GCGconsMasterbranchGetParentcons(parentcons);
440 branchdata = GCGconsMasterbranchGetBranchdata(parentcons);
441 }
442 }
443
444 return SCIP_OKAY;
445}
446
447
448/*
449 * branching specific interface methods
450 */
451
452/** method for initializing the set of respected indices */
453static
455 SCIP* scip, /**< SCIP data structure */
456 SCIP_VAR** F, /**< array of fractional mastervars */
457 int Fsize, /**< number of fractional mastervars */
458 SCIP_VAR*** IndexSet, /**< set to initialize */
459 int* IndexSetSize /**< size of the index set */
460 )
461{
462 int i;
463
464 assert( scip != NULL);
465 assert( F != NULL);
466 assert( Fsize > 0);
467 assert( IndexSet != NULL);
468 assert( IndexSetSize != NULL);
469
470 *IndexSet = NULL;
471 *IndexSetSize = 0;
472
473
474 for( i = 0; i < Fsize; ++i )
475 {
476 int j;
477 SCIP_VAR** origvars = GCGmasterVarGetOrigvars(F[i]);
478 int norigvars = GCGmasterVarGetNOrigvars(F[i]);
479
480 if( *IndexSetSize == 0 && norigvars > 0 )
481 {
482 /* TODO: allocate memory for norigvars although there might be slots for continuous variables which are not needed? */
483 SCIP_CALL( SCIPallocBufferArray(scip, IndexSet, 1) );
484 for( j = 0; j < norigvars; ++j )
485 {
486 if( SCIPvarGetType(origvars[j]) > SCIP_VARTYPE_INTEGER )
487 continue;
488
489 if( *IndexSetSize > 0 )
490 SCIP_CALL( SCIPreallocBufferArray(scip, IndexSet, *IndexSetSize + 1) );
491
492 (*IndexSet)[*IndexSetSize] = origvars[j];
493 ++(*IndexSetSize);
494 }
495 }
496 else
497 {
498 for( j = 0; j < norigvars; ++j )
499 {
500 int k;
501 int oldsize = *IndexSetSize;
502
503 if( SCIPvarGetType(origvars[j]) > SCIP_VARTYPE_INTEGER )
504 continue;
505
506 for( k = 0; k < oldsize; ++k )
507 {
508 /* if variable already in union */
509 if( (*IndexSet)[k] == origvars[j] )
510 {
511 break;
512 }
513 if( k == oldsize-1 )
514 {
515 /* add variable to the end */
516 ++(*IndexSetSize);
517 SCIP_CALL( SCIPreallocBufferArray(scip, IndexSet, *IndexSetSize) );
518 (*IndexSet)[*IndexSetSize-1] = origvars[j];
519 }
520 }
521 }
522 }
523 }
524
525 return SCIP_OKAY;
526}
527
528/** method for calculating the median over all fractional components values using
529 * the quickselect algorithm (or a variant of it)
530 *
531 * This method will change the array
532 *
533 * @return median or if the median is the minimum return ceil(arithm middle)
534 */
535static
537 SCIP* scip, /**< SCIP data structure */
538 SCIP_Real* array, /**< array to find the median in (will be destroyed) */
539 int arraysize, /**< size of the array */
540 SCIP_Real min /**< minimum of array */
541 )
542{
543 SCIP_Real Median;
544 SCIP_Real swap;
545 int l;
546 int r;
547 int i;
548 int MedianIndex;
549 SCIP_Real arithmMiddle;
550
551 assert(scip != NULL);
552 assert(array != NULL);
553 assert(arraysize > 0);
554
555 r = arraysize -1;
556 l = 0;
557 arithmMiddle = 0;
558
559 if( arraysize & 1 )
560 MedianIndex = arraysize/2;
561 else
562 MedianIndex = arraysize/2 -1;
563
564 while( l < r-1 )
565 {
566 int j = r;
567 Median = array[MedianIndex];
568 i = l;
569
570 do
571 {
572 while( SCIPisLT(scip, array[i], Median) )
573 ++i;
574 while( SCIPisGT(scip, array[j], Median) )
575 --j;
576 if( i <=j )
577 {
578 swap = array[i];
579 array[i] = array[j];
580 array[j] = swap;
581 ++i;
582 --j;
583 }
584 } while( i <=j );
585 if( j < MedianIndex )
586 l = i;
587 if( i > MedianIndex )
588 r = j;
589 }
590 Median = array[MedianIndex];
591
592 if( SCIPisEQ(scip, Median, min) )
593 {
594 for( i=0; i<arraysize; ++i )
595 arithmMiddle += 1.0*array[i]/arraysize;
596
597 Median = SCIPceil(scip, arithmMiddle);
598 }
599
600 return Median;
601}
602
603/** comparefunction for lexicographical sort */
604static
606{
607 SCIP* origprob = (SCIP *) userdata;
608 GCG_STRIP* strip1;
609 GCG_STRIP* strip2;
610 SCIP_VAR* mastervar1;
611 SCIP_VAR* mastervar2;
612 SCIP_VAR** origvars;
613 int norigvars;
614 int i;
615
616 strip1 = (GCG_STRIP*) elem1;
617 strip2 = (GCG_STRIP*) elem2;
618
619 mastervar1 = strip1->mastervar;
620 mastervar2 = strip2->mastervar;
621
622 assert(mastervar1 != NULL);
623 assert(mastervar2 != NULL);
624
625 if( GCGvarGetBlock(mastervar1) == -1 )
626 {
627 SCIPdebugMessage("linkingvar\n");
628 assert(GCGmasterVarIsLinking(mastervar1));
629 }
630 if( GCGvarGetBlock(mastervar2) == -1 )
631 {
632 SCIPdebugMessage("linkingvar\n");
633 assert(GCGmasterVarIsLinking(mastervar2));
634 }
635
636 origvars = SCIPgetVars(origprob);
637 norigvars = SCIPgetNVars(origprob);
638
639 for( i = 0; i < norigvars; ++i )
640 {
641 if( SCIPvarGetType(origvars[i]) > SCIP_VARTYPE_INTEGER )
642 continue;
643
644 if( SCIPisFeasGT(origprob, getGeneratorEntry(mastervar1, origvars[i]), getGeneratorEntry(mastervar2, origvars[i])) )
645 return -1;
646
647 if( SCIPisFeasLT(origprob, getGeneratorEntry(mastervar1, origvars[i]), getGeneratorEntry(mastervar2, origvars[i])) )
648 return 1;
649 }
650
651 return 0;
652}
653
654/** lexicographical sort using scipsort
655 * This method will change the array
656 */
657static
659 SCIP* scip, /**< SCIP data structure */
660 GCG_STRIP** array, /**< array to sort (will be changed) */
661 int arraysize /**< size of the array */
662 )
663{
664
665 assert(array != NULL);
666 assert(arraysize > 0);
667
668 SCIPdebugMessage("Lexicographic sorting\n");
669
670 GCGsortPtr((void**)array, ptrcomp, scip, arraysize );
671
672 return SCIP_OKAY;
673}
674
675
676/** compare function for ILO: returns 1 if bd1 < bd2 else -1 with respect to bound sequence */
677static
679 SCIP* scip, /**< SCIP data structure */
680 SCIP_VAR* mastervar1, /**< first strip */
681 SCIP_VAR* mastervar2, /**< second strip */
682 GCG_COMPSEQUENCE** C, /**< component bound sequence to compare with */
683 int NBoundsequences, /**< size of the bound sequence */
684 int* sequencesizes, /**< sizes of the bound sequences */
685 int p /**< current depth in C*/
686 )
687{
688 SCIP_Real ivalue;
689 int j;
690 int k;
691 int Nupper;
692 int Nlower;
693 int returnvalue;
694 GCG_COMPSEQUENCE** CopyC;
695 SCIP_VAR* origvar;
696 int* newsequencesizes;
697 GCG_STRIP* strip1;
698 GCG_STRIP* strip2;
699
700 k = 0;
701 Nupper = 0;
702 Nlower = 0;
703 newsequencesizes = NULL;
704 strip1 = NULL;
705 strip2 = NULL;
706
707 /* lexicographic Order? */
708 if( C == NULL || NBoundsequences <= 1 )
709 {
712
713 strip1->scip = scip;
714 strip2->scip = scip;
715 strip1->C = NULL;
716 strip2->C = NULL;
717 strip1->Csize = 0;
718 strip2->Csize = 0;
719 strip1->sequencesizes = NULL;
720 strip2->sequencesizes = NULL;
721 strip1->mastervar = mastervar1;
722 strip2->mastervar = mastervar2;
723
724 returnvalue = (*ptrcomp)(scip, strip1, strip2);
725
726 SCIPfreeBuffer(scip, &strip1);
727 SCIPfreeBuffer(scip, &strip2);
728
729 return returnvalue;
730 }
731
732 assert(C != NULL);
733 assert(NBoundsequences > 0);
734
735 /* find i which is in all S in C on position p */
736 while( sequencesizes[k] < p )
737 {
738 ++k;
739 assert(k < NBoundsequences);
740 }
741 origvar = C[k][p-1].component;
742 assert(origvar != NULL);
743 assert(SCIPvarGetType(origvar) <= SCIP_VARTYPE_INTEGER);
744 ivalue = C[k][p-1].bound;
745
746 /* calculate subset of C */
747 for( j=0; j< NBoundsequences; ++j )
748 {
749 if( sequencesizes[j] >= p )
750 {
751 assert(C[j][p-1].component == origvar);
752 if( C[j][p-1].sense == GCG_COMPSENSE_GE )
753 ++Nupper;
754 else
755 ++Nlower;
756 }
757 }
758
759 if( SCIPisGE(scip, getGeneratorEntry(mastervar1, origvar), ivalue) && SCIPisGE(scip, getGeneratorEntry(mastervar2, origvar), ivalue) )
760 {
761 k = 0;
762 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &CopyC, Nupper) );
763 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &newsequencesizes, Nupper) );
764 for( j = 0; j < NBoundsequences; ++j )
765 {
766 if( sequencesizes[j] >= p )
767 assert(C[j][p-1].component == origvar);
768
769 if( sequencesizes[j] >= p && C[j][p-1].sense == GCG_COMPSENSE_GE )
770 {
771 int l;
772 CopyC[k] = NULL;
773 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &(CopyC[k]), sequencesizes[j]) ); /*lint !e866*/
774 for( l = 0; l < sequencesizes[j]; ++l )
775 {
776 CopyC[k][l] = C[j][l];
777 }
778 newsequencesizes[k] = sequencesizes[j];
779 ++k;
780 }
781 }
782
783 if( k != Nupper )
784 {
785 SCIPdebugMessage("k = %d, Nupper+1 =%d\n", k, Nupper+1);
786 }
787
788 if( Nupper != 0 )
789 assert( k == Nupper );
790
791 returnvalue = ILOcomp(scip, mastervar1, mastervar2, CopyC, Nupper, newsequencesizes, p+1);
792
793 for( j = Nupper - 1; j >= 0; --j )
794 {
795 SCIPfreeBufferArray(scip, &(CopyC[j]) );
796 }
797 SCIPfreeBufferArray(scip, &newsequencesizes);
798 SCIPfreeBufferArray(scip, &CopyC);
799
800 return returnvalue;
801 }
802
803
804 if( SCIPisLT(scip, getGeneratorEntry(mastervar1, origvar), ivalue) && SCIPisLT(scip, getGeneratorEntry(mastervar2, origvar), ivalue) )
805 {
806 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &CopyC, Nlower) );
807 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &newsequencesizes, Nlower) );
808
809 k = 0;
810 for( j = 0; j < NBoundsequences; ++j )
811 {
812 if( sequencesizes[j] >= p )
813 assert(C[j][p-1].component == origvar);
814
815 if( sequencesizes[j] >= p && C[j][p-1].sense != GCG_COMPSENSE_GE )
816 {
817 int l;
818 CopyC[k] = NULL;
819 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &(CopyC[k]), sequencesizes[j]) ); /*lint !e866*/
820 for( l = 0; l < sequencesizes[j]; ++l )
821 {
822 CopyC[k][l] = C[j][l];
823 }
824 newsequencesizes[k] = sequencesizes[j];
825 ++k;
826 }
827 }
828
829 if( k != Nlower )
830 {
831 SCIPdebugMessage("k = %d, Nlower+1 =%d\n", k, Nlower+1);
832 }
833
834 if( Nlower != 0 )
835 assert( k == Nlower);
836
837 returnvalue = ILOcomp( scip, mastervar1, mastervar2, CopyC, Nlower, newsequencesizes, p+1);
838
839 for( j = Nlower - 1; j >= 0; --j )
840 {
841
842 SCIPfreeBufferArray(scip, &(CopyC[j]) );
843 }
844 SCIPfreeBufferArray(scip, &newsequencesizes);
845 SCIPfreeBufferArray(scip, &CopyC);
846
847 return returnvalue;
848 }
849 if( SCIPisGT(scip, getGeneratorEntry(mastervar1, origvar), getGeneratorEntry(mastervar2, origvar)) )
850 return 1;
851 else
852 return -1;
853}
854
855/** comparefunction for induced lexicographical sort */
856static
858{
859 GCG_STRIP* strip1;
860 GCG_STRIP* strip2;
861 int returnvalue;
862
863 strip1 = (GCG_STRIP*) elem1;
864 strip2 = (GCG_STRIP*) elem2;
865
866 returnvalue = ILOcomp(strip1->scip, strip1->mastervar, strip2->mastervar, strip1->C, strip1->Csize, strip1->sequencesizes, 1);
867
868 return returnvalue;
869}
870
871/** induced lexicographical sort */
872static
874 SCIP* scip, /**< SCIP ptr*/
875 GCG_STRIP** array, /**< array of strips to sort in ILO*/
876 int arraysize, /**< size of the array */
877 GCG_COMPSEQUENCE** C, /**< current set o comp bound sequences*/
878 int NBoundsequences, /**< size of C */
879 int* sequencesizes /**< sizes of the sequences in C */
880 )
881{
882 int i;
883
884 SCIPdebugMessage("Induced Lexicographic sorting\n");
885
886 if( NBoundsequences == 0 )
887 return LexicographicSort( scip, array, arraysize );
888 assert( C!= NULL );
889
890 assert(arraysize > 0);
891 if( arraysize <= 1 )
892 return SCIP_OKAY;
893
894 assert(array != NULL);
895 for( i = 0; i < arraysize; ++i )
896 {
897 array[i]->scip = scip;
898 array[i]->Csize = NBoundsequences;
899 array[i]->sequencesizes = sequencesizes;
900 array[i]->C = C;
901 }
902
903 SCIPsortPtr((void**)array, ptrilocomp, arraysize);
904
905 return SCIP_OKAY;
906}
907
908/** partitions the strip according to the priority */
909static
911 SCIP* scip, /**< SCIP data structure */
912 SCIP_VAR** J, /**< array of variables which belong to the discriminating components */
913 int* Jsize, /**< pointer to the number of discriminating components */
914 SCIP_Longint* priority, /**< branching priorities */
915 SCIP_VAR** F, /**< set of fractional solutions satisfying bounds */
916 int Fsize, /**< size of list of fractional solutions satisfying bounds */
917 SCIP_VAR** origvar, /**< pointer to store the variable which belongs to a discriminating component with maximum priority */
918 SCIP_Real* median /**< pointer to store the median of fractional solutions satisfying bounds */
919 )
920{
921 int j;
922 int l;
924 SCIP_Real* compvalues;
925
926 do
927 {
928 SCIP_Longint maxPriority = SCIP_LONGINT_MIN;
930
931 /* max-min priority */
932 for ( j = 0; j < *Jsize; ++j )
933 {
934 assert(SCIPvarGetType(J[j]) <= SCIP_VARTYPE_INTEGER);
935
936 if ( priority[j] > maxPriority )
937 {
938 maxPriority = priority[j];
939 *origvar = J[j];
940 }
941 }
942 SCIP_CALL( SCIPallocBufferArray(scip, &compvalues, Fsize) );
943 for ( l = 0; l < Fsize; ++l )
944 {
945 compvalues[l] = getGeneratorEntry(F[l], *origvar);
946 if ( SCIPisLT(scip, compvalues[l], min) )
947 min = compvalues[l];
948 }
949 *median = GetMedian(scip, compvalues, Fsize, min);
950 SCIPfreeBufferArray(scip, &compvalues);
951
952 assert(!SCIPisInfinity(scip, min));
953
954 if ( !SCIPisEQ(scip, *median, 0.0) )
955 {
956 SCIPdebugMessage("median = %g\n", *median);
957 SCIPdebugMessage("min = %g\n", min);
958 SCIPdebugMessage("Jsize = %d\n", *Jsize);
959 }
960
961 if ( SCIPisEQ(scip, *median, min) )
962 {
963 /* here with max-min priority */
964 for ( j = 0; j < *Jsize; ++j )
965 {
966 if ( *origvar == J[j] )
967 {
968 assert(priority[j] == 0);
969 J[j] = J[*Jsize - 1];
970 priority[j] = priority[*Jsize - 1];
971 break;
972 }
973 }
974 if( j < *Jsize )
975 *Jsize = *Jsize-1;
976 }
977 assert(*Jsize >= 0);
978
979 }while ( SCIPisEQ(scip, *median, min) && *Jsize > 0);
980
981 return SCIP_OKAY;
982}
983
984/** add identified sequence to record */
985static
987 SCIP* scip, /**< SCIP data structure */
988 GCG_RECORD* record, /**< record of identified sequences */
989 GCG_COMPSEQUENCE* S, /**< bound restriction sequence */
990 int Ssize /**< size of bound restriction sequence */
991)
992{
993 int i;
994
995 SCIPdebugMessage("recordsize=%d, Ssize=%d\n", record->recordsize, Ssize);
996
997 if(record->recordcapacity < record->recordsize + 1)
998 {
999 i = SCIPcalcMemGrowSize(scip, record->recordsize + 1);
1003 record->recordcapacity = i;
1004 }
1005
1006 i = SCIPcalcMemGrowSize(scip, Ssize);
1007 record->capacities[record->recordsize] = i;
1008 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(record->record[record->recordsize]), i) ); /*lint !e866*/
1009 for( i=0; i<Ssize;++i )
1010 {
1011 record->record[record->recordsize][i].component = S[i].component;
1012 record->record[record->recordsize][i].sense = S[i].sense;
1013 record->record[record->recordsize][i].bound = S[i].bound;
1014 }
1015
1016 record->sequencesizes[record->recordsize] = Ssize; /* +1 ? */
1017
1018 record->recordsize++;
1019
1020 return SCIP_OKAY;
1021}
1022
1023
1024/** separation at the root node */
1025static
1027 SCIP* origprob, /**< SCIP data structure */
1028 SCIP* masterprob, /**< master problem */
1029 SCIP_VAR** F, /**< fractional strips respecting bound restrictions */
1030 int Fsize, /**< size of the strips */
1031 SCIP_VAR** IndexSet, /**< index set */
1032 int IndexSetSize, /**< size of index set */
1033 GCG_COMPSEQUENCE* S, /**< ordered set of bound restrictions */
1034 int Ssize, /**< size of the ordered set */
1035 GCG_RECORD* record /**< identified bound sequences */
1036 )
1037{
1038 int j;
1039 int k;
1040 int l;
1041 int Jsize;
1042 SCIP_VAR** J;
1043 SCIP_Real median;
1044 int Fupper;
1045 int Flower;
1046 SCIP_Longint* priority;
1047 SCIP_VAR* origvar;
1048 SCIP_VAR** copyF;
1049 GCG_COMPSEQUENCE* upperLowerS;
1050 GCG_COMPSEQUENCE* upperS;
1051 SCIP_Real* alpha;
1052 SCIP_Real* compvalues;
1053 SCIP_Real muF;
1054 SCIP_Bool found;
1055
1056 assert(origprob != NULL);
1057 assert((Fsize == 0) == (F == NULL));
1058
1059 Jsize = 0;
1060 Fupper = 0;
1061 Flower = 0;
1062 found = FALSE;
1063 priority = NULL;
1064 compvalues = NULL;
1065 J = NULL;
1066 origvar = NULL;
1067 copyF = NULL;
1068 upperLowerS = NULL;
1069 upperS = NULL;
1070 alpha = NULL;
1071
1072 SCIPdebugMessage("Separate with ");
1073
1074 /* if there are no fractional columns or potential columns, return */
1075 if( Fsize == 0 || IndexSetSize == 0 )
1076 {
1077 SCIPdebugPrintf("nothing, no fractional columns\n");
1078 return SCIP_OKAY;
1079 }
1080
1081 assert( F != NULL );
1082 assert( IndexSet != NULL );
1083
1084 muF = 0.0;
1085 for( j = 0; j < Fsize; ++j )
1086 muF += SCIPgetSolVal(masterprob, NULL, F[j]);
1087
1088 SCIPdebugPrintf("Fsize = %d; Ssize = %d, IndexSetSize = %d, nuF=%.6g \n", Fsize, Ssize, IndexSetSize, muF);
1089
1090 /* detect fractional alpha_i */
1091 SCIP_CALL( SCIPallocBufferArray(origprob, &alpha, IndexSetSize) );
1092
1093 for( k = 0; k < IndexSetSize; ++k )
1094 {
1095 GCG_COMPSEQUENCE* copyS;
1096 SCIP_Real min;
1097 min = SCIPinfinity(origprob);
1098
1099 origvar = IndexSet[k];
1100 copyS = NULL;
1101 alpha[k] = 0.0;
1102
1103 if( SCIPvarGetType(origvar) > SCIP_VARTYPE_INTEGER )
1104 continue;
1105
1106 SCIP_CALL( SCIPallocBufferArray(origprob, &compvalues, Fsize) );
1107 for( l=0; l<Fsize; ++l )
1108 {
1109 compvalues[l] = getGeneratorEntry(F[l], origvar);
1110 if( SCIPisLT(origprob, compvalues[l], min) )
1111 min = compvalues[l];
1112 }
1113
1114 median = GetMedian(origprob, compvalues, Fsize, min);
1115 SCIPfreeBufferArray(origprob, &compvalues);
1116 compvalues = NULL;
1117
1118 for( j = 0; j < Fsize; ++j )
1119 {
1120 SCIP_Real generatorentry;
1121
1122 generatorentry = getGeneratorEntry(F[j], origvar);
1123
1124 if( SCIPisGE(origprob, generatorentry, median) )
1125 {
1126 alpha[k] += SCIPgetSolVal(masterprob, NULL, F[j]);
1127 }
1128 }
1129
1130 if( SCIPisGT(origprob, alpha[k], 0.0) && SCIPisLT(origprob, alpha[k], muF) )
1131 {
1132 ++Jsize;
1133 }
1134
1135 if( !SCIPisFeasIntegral(origprob, alpha[k]) )
1136 {
1137 SCIPdebugMessage("alpha[%d] = %g\n", k, alpha[k]);
1138 found = TRUE;
1139
1140 /* ********************************** *
1141 * add the current pair to record *
1142 * ********************************** */
1143
1144 /* copy S */
1145 SCIP_CALL( SCIPallocBufferArray(origprob, &copyS, (size_t)Ssize+1) );
1146
1147 for( l = 0; l < Ssize; ++l )
1148 {
1149 copyS[l] = S[l];
1150 }
1151
1152 /* create temporary array to compute median */
1153 SCIP_CALL( SCIPallocBufferArray(origprob, &compvalues, Fsize) );
1154
1155 for( l = 0; l < Fsize; ++l )
1156 {
1157 compvalues[l] = getGeneratorEntry(F[l], origvar);
1158
1159 if( SCIPisLT(origprob, compvalues[l], min) )
1160 min = compvalues[l];
1161 }
1162
1163 assert( SCIPisEQ(origprob, median, GetMedian(origprob, compvalues, Fsize, min)));
1164 median = GetMedian(origprob, compvalues, Fsize, min);
1165 SCIPfreeBufferArray(origprob, &compvalues);
1166 compvalues = NULL;
1167
1168 SCIPdebugMessage("new median is %g, comp=%s, Ssize=%d\n", median, SCIPvarGetName(origvar), Ssize);
1169
1170 /* add last bound change to the copy of S */
1171 copyS[Ssize].component = origvar;
1172 copyS[Ssize].sense = GCG_COMPSENSE_GE;
1173 copyS[Ssize].bound = median;
1174
1175 /* add identified sequence to record */
1176 SCIP_CALL( addToRecord(origprob, record, copyS, Ssize+1) );
1177
1178
1179 /* ********************************** *
1180 * end adding to record *
1181 * ********************************** */
1182 SCIPfreeBufferArrayNull(origprob, &copyS);
1183 }
1184 }
1185
1186 if( found )
1187 {
1188 SCIPfreeBufferArrayNull(origprob, &alpha);
1189
1190 SCIPdebugMessage("one S found with size %d\n", record->sequencesizes[record->recordsize-1]);
1191
1192 return SCIP_OKAY;
1193 }
1194
1195
1196 /* ********************************** *
1197 * discriminating components *
1198 * ********************************** */
1199
1200 /** @todo mb: this is a filter */
1201 SCIP_CALL( SCIPallocBufferArray(origprob, &J, Jsize) );
1202 j=0;
1203 for( k = 0; k < IndexSetSize; ++k )
1204 {
1205 if( SCIPisGT(origprob, alpha[k], 0.0) && SCIPisLT(origprob, alpha[k], muF) )
1206 {
1207 J[j] = IndexSet[k];
1208 ++j;
1209 }
1210 }
1211 assert( j == Jsize );
1212
1213 /* ********************************** *
1214 * compute priority (max-min) *
1215 * ********************************** */
1216
1217 SCIP_CALL( SCIPallocBufferArray(origprob, &priority, Jsize) );
1218
1219 for( j = 0; j < Jsize; ++j )
1220 {
1221 SCIP_Longint maxcomp;
1222 SCIP_Longint mincomp;
1223
1224 maxcomp = SCIP_LONGINT_MIN;
1225 mincomp = SCIP_LONGINT_MAX;
1226
1227 origvar = J[j];
1228
1229 for( l = 0; l < Fsize; ++l )
1230 {
1231 SCIP_Longint generatorentry;
1232
1233 assert(SCIPisIntegral(origprob, getGeneratorEntry(F[l], origvar)));
1234
1235 generatorentry = (SCIP_Longint) (getGeneratorEntry(F[l], origvar) + 0.5);
1236
1237 if( generatorentry > maxcomp )
1238 maxcomp = generatorentry;
1239
1240 if( generatorentry < mincomp )
1241 mincomp = generatorentry;
1242 }
1243
1244 priority[j] = maxcomp -mincomp;
1245 }
1246
1247 SCIP_CALL( partition(origprob, J, &Jsize, priority, F, Fsize, &origvar, &median) );
1248
1249 /* this is a copy of S for the recursive call below */
1250 SCIP_CALL( SCIPallocBufferArray(origprob, &upperLowerS, (size_t)Ssize+1) );
1251 SCIP_CALL( SCIPallocBufferArray(origprob, &upperS, (size_t)Ssize+1) );
1252
1253 for( l = 0; l < Ssize; ++l )
1254 {
1255 upperLowerS[l] = S[l];
1256 upperS[l] = S[l];
1257 }
1258
1259 upperLowerS[Ssize].component = origvar;/* i; */
1260 upperS[Ssize].component = origvar;
1261 upperLowerS[Ssize].sense = GCG_COMPSENSE_LT;
1262 upperS[Ssize].sense = GCG_COMPSENSE_GE;
1263 upperLowerS[Ssize].bound = median;
1264 upperS[Ssize].bound = median;
1265
1266 for( k = 0; k < Fsize; ++k )
1267 {
1268 if( SCIPisGE(origprob, getGeneratorEntry(F[k], origvar), median) )
1269 ++Fupper;
1270 else
1271 ++Flower;
1272 }
1273
1274 /* ********************************** *
1275 * choose smallest partition *
1276 * ********************************** */
1277
1278 SCIP_CALL( SCIPallocBufferArray(origprob, &copyF, Fsize) );
1279
1280 if( Flower > 0 )
1281 {
1282 j = 0;
1283
1284 for( k = 0; k < Fsize; ++k )
1285 {
1286 if( SCIPisLT(origprob, getGeneratorEntry(F[k], origvar), median) )
1287 {
1288 copyF[j] = F[k];
1289 ++j;
1290 }
1291 }
1292
1293 /*Fsize = Flower;*/
1294 assert(j < Fsize+1);
1295
1296 SCIP_CALL( Separate(origprob, masterprob, copyF, Flower, J, Jsize, upperLowerS, Ssize+1, record) );
1297 }
1298
1299 if( Fupper > 0 )
1300 {
1301 upperLowerS[Ssize].sense = GCG_COMPSENSE_GE;
1302 j = 0;
1303
1304 for( k = 0; k < Fsize; ++k )
1305 {
1306 if( SCIPisGE(origprob, getGeneratorEntry(F[k], origvar), median) )
1307 {
1308 copyF[j] = F[k];
1309 ++j;
1310 }
1311 }
1312
1313 /*Fsize = Fupper;*/
1314 assert(j < Fsize+1);
1315
1316 SCIP_CALL( Separate(origprob, masterprob, copyF, Fupper, J, Jsize, upperS, Ssize+1, record) );
1317 }
1318
1319 SCIPfreeBufferArrayNull(origprob, &copyF);
1320 SCIPfreeBufferArrayNull(origprob, &upperS);
1321 SCIPfreeBufferArrayNull(origprob, &upperLowerS);
1322 SCIPfreeBufferArray(origprob, &priority);
1323 SCIPfreeBufferArrayNull(origprob, &J);
1324 SCIPfreeBufferArray(origprob, &alpha);
1325
1326 return SCIP_OKAY;
1327}
1328
1329/** choose a component bound sequence to create branching */
1330static
1332 SCIP* scip, /**< SCIP data structure */
1333 GCG_RECORD** record, /**< candidate of bound sequences */
1334 GCG_COMPSEQUENCE** S, /**< pointer to return chosen bound sequence */
1335 int* Ssize /**< size of the chosen bound sequence */
1336 )
1337{
1338 int minSizeOfMaxPriority; /* needed if the last comp priority is equal to the one in other bound sequences */
1339 SCIP_Longint maxPriority;
1340 int i;
1341 int Index;
1342
1343 minSizeOfMaxPriority = INT_MAX;
1344 maxPriority = SCIP_LONGINT_MIN;
1345 Index = -1;
1346
1347 SCIPdebugMessage("Chose S \n");
1348
1349 assert((*record)->recordsize > 0);
1350
1351 for( i = 0; i < (*record)->recordsize; ++i )
1352 {
1353 assert((*record)->sequencesizes != NULL );
1354 assert((*record)->sequencesizes[i] > 0);
1355
1356 if( maxPriority <= 1 ) /* later by pseudocosts e.g. */
1357 {
1358 if( maxPriority < 1 )
1359 {
1360 maxPriority = 1; /* only choose here first smallest S */
1361 minSizeOfMaxPriority = (*record)->sequencesizes[i];
1362 Index = i;
1363 }
1364 else if( (*record)->sequencesizes[i] < minSizeOfMaxPriority )
1365 {
1366 minSizeOfMaxPriority = (*record)->sequencesizes[i];
1367 Index = i;
1368 }
1369 }
1370 }
1371 assert(maxPriority > SCIP_LONGINT_MIN);
1372 assert(minSizeOfMaxPriority < INT_MAX);
1373 assert(Index >= 0);
1374
1375 *Ssize = minSizeOfMaxPriority;
1376 SCIP_CALL( SCIPallocBufferArray(scip, S, *Ssize) );
1377
1378 for( i = 0; i < *Ssize; ++i )
1379 {
1380 (*S)[i] = (*record)->record[Index][i];
1381 }
1382
1383 assert(S!=NULL);
1384 assert(*S!=NULL);
1385
1386 /* free record */
1387 for( i = 0; i < (*record)->recordsize; ++i )
1388 {
1389 SCIPfreeBlockMemoryArray(scip, &((*record)->record[i]), (*record)->capacities[i] );
1390 }
1391 SCIPfreeBlockMemoryArray(scip, &((*record)->record), (*record)->recordcapacity );
1392
1393 SCIPdebugMessage("with size %d \n", *Ssize);
1394
1395 assert(*S!=NULL);
1396
1397 return SCIP_OKAY;
1398}
1399
1400/** updates the new set of sequences C in CopyC and the corresponding size array newsequencesizes
1401 * returns the size of CopyC */
1402static
1404 int Csize, /**< size of the sequence */
1405 int p, /**< index of node */
1406 SCIP_VAR* origvar, /**< another index generatorentry */
1407 int* sequencesizes, /**< size of the sequences */
1408 GCG_COMPSEQUENCE** C, /**< original sequence */
1409 GCG_COMPSEQUENCE** CopyC, /**< new sequence */
1410 int* newsequencesizes, /**< output parameter for the new sequence */
1411 GCG_COMPSENSE sense /**< sense of the comparison */
1412 )
1413{
1414 int j;
1415 int k;
1416
1417 for( k = 0, j = 0; j < Csize; ++j )
1418 {
1419 if ( sequencesizes[j] >= p )
1420 assert(C[j][p-1].component == origvar);
1421
1422 if ( sequencesizes[j] >= p && C[j][p-1].sense == sense )
1423 {
1424 CopyC[k] = C[j];
1425 newsequencesizes[k] = sequencesizes[j];
1426 ++k;
1427 }
1428 }
1429
1430 return k;
1431}
1432
1433/** auxilary function to compute alpha for given index */
1434static
1436 SCIP* origprob, /**< SCIP data structure */
1437 SCIP* masterprob, /**< master problem */
1438 int Fsize, /**< size of F */
1439 GCG_COMPSENSE isense, /**< sense of the bound for origvar */
1440 double ivalue, /**< value of the bound for origvar */
1441 SCIP_VAR* origvar, /**< index of the variable */
1442 SCIP_VAR** F /**< current fractional mastervars*/
1443 )
1444{
1445 int j;
1446 SCIP_Real alpha_i = 0.0;
1447
1448 for ( j = 0; j < Fsize; ++j )
1449 {
1450 SCIP_Real generatorentry;
1451
1452 generatorentry = getGeneratorEntry(F[j], origvar);
1453
1454 if ( (isense == GCG_COMPSENSE_GE && SCIPisGE(origprob, generatorentry, ivalue)) ||
1455 (isense == GCG_COMPSENSE_LT && SCIPisLT(origprob, generatorentry, ivalue)) )
1456 {
1457 alpha_i += SCIPgetSolVal(masterprob, NULL, F[j]);
1458 }
1459 }
1460
1461 return alpha_i;
1462}
1463
1464/** separation at a node other than the root node */
1465static
1467 SCIP* origprob, /**< SCIP data structure */
1468 SCIP* masterprob, /**< master problem */
1469 GCG_COMPSEQUENCE** C, /**< array of component bounds sequences*/
1470 int Csize, /**< number of component bounds sequences*/
1471 int* sequencesizes, /**< array of sizes of component bounds sequences */
1472 int p, /**< depth of recursive call */
1473 SCIP_VAR** F, /**< strip of fractional columns */
1474 int Fsize, /**< size of the strips */
1475 SCIP_VAR** IndexSet, /**< array of original variables which belong to the fractional master columns */
1476 int IndexSetSize, /**< number of original variables which belong to fractional master columns. Note that IndexSetSize >= Fsize */
1477 GCG_COMPSEQUENCE** S, /**< component sequences */
1478 int* Ssize, /**< length of component sequences */
1479 GCG_RECORD* record /**< array of sets of component bounds which we might use for separation */
1480 )
1481{
1482 int j;
1483 int k;
1484 SCIP_Real ivalue;
1485 GCG_COMPSENSE isense;
1486 SCIP_Real median;
1487 int Fupper;
1488 int Flower;
1489 int Cupper;
1490 int Clower;
1491 int lowerSsize;
1492 SCIP_VAR** copyF;
1493 GCG_COMPSEQUENCE* copyS;
1494 GCG_COMPSEQUENCE* lowerS;
1495 GCG_COMPSEQUENCE** CopyC;
1496 int* newsequencesizes;
1497 SCIP_VAR* origvar;
1498 SCIP_Real alpha_i;
1499 SCIP_Real muF;
1500 SCIP_Bool found;
1501
1502 k = 0;
1503 muF = 0;
1504 Fupper = 0;
1505 Flower = 0;
1506 Cupper = 0;
1507 Clower = 0;
1508 newsequencesizes = NULL;
1509 copyF = NULL;
1510 CopyC = NULL;
1511 copyS = NULL;
1512 lowerS = NULL;
1513 found = FALSE;
1514
1515 SCIPdebugMessage("Explore\n");
1516
1517 SCIPdebugMessage("with Fsize = %d, Csize = %d, Ssize = %d, p = %d\n", Fsize, Csize, *Ssize, p);
1518
1519 /* *************************************** *
1520 * if C=Ø, call separate and return that *
1521 * *************************************** */
1522
1523 if( C == NULL || Fsize==0 || IndexSetSize==0 || Csize == 0 )
1524 {
1525 /* SCIPdebugMessage("go to Separate\n"); */
1526 assert(S != NULL);
1527
1528 SCIP_CALL( Separate(origprob, masterprob, F, Fsize, IndexSet, IndexSetSize, *S, *Ssize, record) );
1529
1530 if( *Ssize > 0 && *S != NULL )
1531 {
1532 SCIPfreeBufferArrayNull(origprob, S);
1533 *S = NULL;
1534 *Ssize = 0;
1535 }
1536 return SCIP_OKAY;
1537 }
1538
1539 assert(C != NULL);
1540 assert(Csize > 0);
1541 assert(F != NULL);
1542 assert(IndexSet != NULL);
1543 assert(sequencesizes != NULL);
1544
1545 /* ******************************************* *
1546 * find i which is in all S in C on position p *
1547 * ******************************************* */
1548
1549 while( sequencesizes[k] < p )
1550 {
1551 /* SCIPdebugMessage("sequencesizes[%d] = %d\n", k, sequencesizes[k]); */
1552 ++k;
1553
1554 if( k >= Csize )
1555 {
1556 SCIPdebugMessage("no %dth element bounded\n", p);
1557 assert(S != NULL);
1558 SCIP_CALL( Separate(origprob, masterprob, F, Fsize, IndexSet, IndexSetSize, *S, *Ssize, record) );
1559
1560 if( *Ssize > 0 && *S != NULL )
1561 {
1562 SCIPfreeBufferArrayNull(origprob, S);
1563 *S = NULL;
1564 *Ssize = 0;
1565 }
1566
1567 return SCIP_OKAY;
1568 }
1569
1570 assert( k < Csize );
1571 }
1572
1573 origvar = C[k][p-1].component;
1574 isense = C[k][p-1].sense;
1575 ivalue = C[k][p-1].bound;
1576
1577 assert(origvar != NULL);
1578 assert(SCIPvarGetType(origvar) <= SCIP_VARTYPE_INTEGER);
1579
1580 SCIPdebugMessage("orivar = %s; ivalue = %g\n", SCIPvarGetName(origvar), ivalue);
1581
1582 for( j = 0; j < Fsize; ++j )
1583 {
1584 muF += SCIPgetSolVal(masterprob, NULL, F[j]);
1585 }
1586
1587 SCIPdebugMessage("muF = %g\n", muF);
1588
1589 /* ******************************************* *
1590 * compute alpha_i *
1591 * ******************************************* */
1592
1593 alpha_i = computeAlpha(origprob, masterprob, Fsize, isense, ivalue, origvar, F);
1594
1595 SCIPdebugMessage("alpha(%s) = %g\n", SCIPvarGetName(origvar), alpha_i);
1596
1597 /* ******************************************* *
1598 * if f > 0, add pair to record *
1599 * ******************************************* */
1600
1601 if( !SCIPisFeasIntegral(origprob, alpha_i) )
1602 {
1603 int l;
1604
1605 found = TRUE;
1606 SCIPdebugMessage("fractional alpha(%s) = %g\n", SCIPvarGetName(origvar), alpha_i);
1607
1608 /* ******************************************* *
1609 * add to record *
1610 * ******************************************* */
1611
1612 SCIP_CALL( SCIPallocBufferArray(origprob, &copyS, (size_t)*Ssize+1) );
1613 for( l = 0; l < *Ssize; ++l )
1614 {
1615 copyS[l] = (*S)[l];
1616 }
1617 copyS[*Ssize].component = origvar;
1618 copyS[*Ssize].sense = isense;
1619 copyS[*Ssize].bound = ivalue;
1620 SCIP_CALL( addToRecord(origprob, record, copyS, *Ssize+1) );
1621 }
1622
1623 if( found )
1624 {
1625 SCIPdebugMessage("found fractional alpha\n");
1626 SCIPfreeBufferArrayNull(origprob, &copyS);
1627 return SCIP_OKAY;
1628 }
1629
1630 /* add bound to the end of S */
1631 ++(*Ssize);
1632 assert(S != NULL );
1633
1634 SCIP_CALL( SCIPreallocBufferArray(origprob, S, *Ssize) );
1635
1636 median = ivalue;
1637 (*S)[*Ssize-1].component = origvar;
1638 (*S)[*Ssize-1].sense = GCG_COMPSENSE_GE;
1639 (*S)[*Ssize-1].bound = median;
1640
1641 SCIP_CALL( SCIPallocBufferArray(origprob, &lowerS, *Ssize) );
1642
1643 for( k = 0; k < *Ssize-1; ++k )
1644 {
1645 lowerS[k].component = (*S)[k].component;
1646 lowerS[k].sense = (*S)[k].sense;
1647 lowerS[k].bound = (*S)[k].bound;
1648 }
1649
1650 lowerSsize = *Ssize;
1651 lowerS[lowerSsize-1].component = origvar;
1652 lowerS[lowerSsize-1].sense = GCG_COMPSENSE_LT;
1653 lowerS[lowerSsize-1].bound = median;
1654
1655 for( k = 0; k < Fsize; ++k )
1656 {
1657 if( SCIPisGE(origprob, getGeneratorEntry(F[k], origvar), median) )
1658 ++Fupper;
1659 else
1660 ++Flower;
1661 }
1662
1663 /* calculate subset of C */
1664 for( j = 0; j < Csize; ++j )
1665 {
1666 if( sequencesizes[j] >= p )
1667 {
1668 if( C[j][p-1].sense == GCG_COMPSENSE_GE )
1669 {
1670 ++Cupper;
1671 }
1672 else
1673 {
1674 ++Clower;
1675 assert( C[j][p-1].sense == GCG_COMPSENSE_LT );
1676 }
1677 }
1678 }
1679
1680 SCIPdebugMessage("Cupper = %d, Clower = %d\n", Cupper, Clower);
1681
1682 if( SCIPisLE(origprob, alpha_i, 0.0) && Fupper != 0 )
1683 Flower = INT_MAX;
1684 if( SCIPisEQ(origprob, alpha_i, muF) && Flower != 0 )
1685 Fupper = INT_MAX;
1686
1687 if( Fupper > 0 && Fupper != INT_MAX )
1688 {
1689 SCIPdebugMessage("chose upper bound Fupper = %d, Cupper = %d\n", Fupper, Cupper);
1690
1691 SCIP_CALL( SCIPallocBufferArray(origprob, &copyF, Fupper) );
1692 for( j = 0, k = 0; k < Fsize; ++k )
1693 {
1694 if( SCIPisGE(origprob, getGeneratorEntry(F[k], origvar), median) )
1695 {
1696 copyF[j] = F[k];
1697 ++j;
1698 }
1699 }
1700
1701 /* new C */
1702 if( Fupper > 0 )
1703 {
1704 SCIP_CALL( SCIPallocBufferArray(origprob, &CopyC, Cupper) );
1705 SCIP_CALL( SCIPallocBufferArray(origprob, &newsequencesizes, Cupper) );
1706 k = computeNewSequence(Csize, p, origvar, sequencesizes, C, CopyC, newsequencesizes, GCG_COMPSENSE_GE);
1707 if( k != Cupper )
1708 {
1709 SCIPdebugMessage("k = %d, p = %d\n", k, p);
1710 }
1711 assert(k == Cupper);
1712 }
1713 else
1714 {
1715 CopyC = NULL;
1716 }
1717
1718 SCIP_CALL( Explore( origprob, masterprob, CopyC, Cupper, newsequencesizes, p+1, copyF, Fupper, IndexSet, IndexSetSize, S, Ssize, record) );
1719 }
1720
1721 if( Flower > 0 && Flower != INT_MAX )
1722 {
1723 SCIPdebugMessage("chose lower bound Flower = %d Clower = %d\n", Flower, Clower);
1724
1725 SCIP_CALL( SCIPreallocBufferArray(origprob, &copyF, Flower) );
1726
1727 j = 0;
1728 for( k = 0; k < Fsize; ++k )
1729 {
1730 if( SCIPisLT(origprob, getGeneratorEntry(F[k], origvar), median) )
1731 {
1732 copyF[j] = F[k];
1733 ++j;
1734 }
1735 }
1736
1737 /* new C */
1738 if( Flower > 0 )
1739 {
1740 SCIP_CALL( SCIPreallocBufferArray(origprob, &CopyC, Clower) );
1741 SCIP_CALL( SCIPreallocBufferArray(origprob, &newsequencesizes, Clower) );
1742 k = computeNewSequence(Csize, p, origvar, sequencesizes, C, CopyC, newsequencesizes, GCG_COMPSENSE_LT);
1743 if( k != Clower )
1744 {
1745 SCIPdebugMessage("k = %d, p = %d\n", k, p);
1746 }
1747 assert(k == Clower);
1748 }
1749 else
1750 {
1751 CopyC = NULL;
1752 }
1753
1754 SCIP_CALL( Explore( origprob, masterprob, CopyC, Clower, newsequencesizes, p+1, copyF, Flower, IndexSet, IndexSetSize, &lowerS, &lowerSsize, record) );
1755 }
1756
1757 SCIPfreeBufferArrayNull(origprob, &newsequencesizes);
1758 SCIPfreeBufferArrayNull(origprob, &CopyC);
1759 SCIPfreeBufferArrayNull(origprob, &copyF);
1760 SCIPfreeBufferArrayNull(origprob, &lowerS);
1761 SCIPfreeBufferArrayNull(origprob, &copyS);
1762
1763 if( *Ssize > 0 && *S != NULL )
1764 {
1765 SCIPfreeBufferArrayNull(origprob, S);
1766
1767 *Ssize = 0;
1768 }
1769
1770 return SCIP_OKAY;
1771}
1772
1773/** branching on copied origvar directly in master */
1774static
1776 GCG* gcg, /**< GCG data structure */
1777 SCIP_VAR* mastervar, /**< master variable */
1778 GCG_BRANCHRULE* branchrule /**< branching rule */
1779 )
1780{
1781 SCIP* origprob;
1782 SCIP* masterscip;
1783 GCG_BRANCHDATA* branchupchilddata;
1784 GCG_BRANCHDATA* branchdownchilddata;
1785 SCIP_NODE* upchild;
1786 SCIP_NODE* downchild;
1787 SCIP_CONS* upchildcons;
1788 SCIP_CONS* downchildcons;
1789 char upchildname[SCIP_MAXSTRLEN];
1790 char downchildname[SCIP_MAXSTRLEN];
1791 int bound;
1792
1793 origprob = GCGgetOrigprob(gcg);
1794 masterscip = GCGgetMasterprob(gcg);
1795 assert(masterscip != NULL);
1796
1797 bound = (int) (SCIPceil( origprob, SCIPgetSolVal(masterscip, NULL, mastervar)) + 0.5); /*lint -e524*/
1798
1799 /* allocate branchdata for child and store information */
1800 SCIP_CALL( initNodeBranchdata(origprob, &branchupchilddata, -3) );
1801 SCIP_CALL( initNodeBranchdata(origprob, &branchdownchilddata, -3) );
1802
1803 branchupchilddata->maxconsS = SCIPcalcMemGrowSize(origprob, 1);
1804 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &(branchupchilddata->consS), branchupchilddata->maxconsS) ); /*lint !e506*/
1805 branchupchilddata->consSsize = 1;
1806
1807 branchdownchilddata->maxconsS = branchupchilddata->maxconsS;
1808 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &(branchdownchilddata->consS), branchdownchilddata->maxconsS) ); /*lint !e506*/
1809 branchdownchilddata->consSsize = 1;
1810
1811 branchupchilddata->consS[0].component = mastervar;
1812 branchupchilddata->consS[0].sense = GCG_COMPSENSE_GE;
1813 branchupchilddata->consS[0].bound = bound;
1814
1815 branchdownchilddata->consS[0].component = mastervar;
1816 branchdownchilddata->consS[0].sense = GCG_COMPSENSE_LT;
1817 branchdownchilddata->consS[0].bound = bound;
1818
1819
1820 assert(branchupchilddata != NULL);
1821 assert(branchdownchilddata != NULL);
1822
1823 (void) SCIPsnprintf(upchildname, SCIP_MAXSTRLEN, "node(-3, %f) direct up on comp=%s", branchupchilddata->consS[0].bound,
1824 SCIPvarGetName(branchupchilddata->consS[branchupchilddata->consSsize-1].component));
1825 (void) SCIPsnprintf(downchildname, SCIP_MAXSTRLEN, "node(-3, %f) direct up on comp=%s", branchdownchilddata->consS[0].bound,
1826 SCIPvarGetName(branchdownchilddata->consS[branchdownchilddata->consSsize-1].component));
1827
1828 SCIP_CALL( SCIPcreateChild(masterscip, &upchild, 0.0, SCIPgetLocalTransEstimate(masterscip)) );
1829 SCIP_CALL( GCGcreateConsMasterbranch(gcg, &upchildcons, upchildname, upchild,
1830 GCGconsMasterbranchGetActiveCons(gcg), branchrule, branchupchilddata, NULL, 0, 0) );
1831 SCIP_CALL( SCIPaddConsNode(masterscip, upchild, upchildcons, NULL) );
1832
1833 SCIP_CALL( SCIPcreateChild(masterscip, &downchild, 0.0, SCIPgetLocalTransEstimate(masterscip)) );
1834 SCIP_CALL( GCGcreateConsMasterbranch(gcg, &downchildcons, downchildname, downchild,
1835 GCGconsMasterbranchGetActiveCons(gcg), branchrule, branchdownchilddata, NULL, 0, 0) );
1836 SCIP_CALL( SCIPaddConsNode(masterscip, downchild, downchildcons, NULL) );
1837
1838 /* create branching constraint in master */
1839 SCIP_CALL( createDirectBranchingCons(masterscip, upchild, branchupchilddata) );
1840 SCIP_CALL( createDirectBranchingCons(masterscip, downchild, branchdownchilddata) );
1841
1842 /* release constraints */
1843 SCIP_CALL( SCIPreleaseCons(masterscip, &upchildcons) );
1844 SCIP_CALL( SCIPreleaseCons(masterscip, &downchildcons) );
1845
1846 return SCIP_OKAY;
1847}
1848
1849/** callup method for seperate
1850 * decides whether Separate or Explore should be done */
1851static
1853 GCG* gcg, /**< GCG data structure */
1854 SCIP_VAR** F /**< strip of fractional columns */,
1855 int Fsize, /**< size of the strips */
1856 GCG_COMPSEQUENCE** S, /**< array of existing bound sequences */
1857 int* Ssize, /**< size of existing bound sequences */
1858 GCG_COMPSEQUENCE** C, /**< array of component bounds sequences*/
1859 int Csize, /**< number of component bounds sequences*/
1860 int* CompSizes, /**< array of sizes of component bounds sequences */
1861 int blocknr, /**< id of the pricing problem (or block) in which we want to branch */
1862 GCG_BRANCHRULE* branchrule, /**< branching rule */
1863 SCIP_RESULT* result, /**< pointer to store the result of the branching call */
1864 int** checkedblocks, /**< array to store which blocks have been checked */
1865 int* ncheckedblocks, /**< number of blocks that have beend checked */
1866 GCG_STRIP**** checkedblockssortstrips, /**< sorted strips of checked blocks */
1867 int** checkedblocksnsortstrips /**< size of the strips */
1868 )
1869{
1870 SCIP* origprob;
1871 SCIP* masterprob;
1872 int i;
1873 SCIP_VAR** IndexSet;
1874 SCIP_VAR** mastervars;
1875 int IndexSetSize;
1876 GCG_RECORD* record;
1877 int exploreSsize;
1878 GCG_COMPSEQUENCE* exploreS;
1879 GCG_STRIP** strips;
1880 int nstrips;
1881 int nmastervars;
1882
1883 origprob = GCGgetOrigprob(gcg);
1884 masterprob = GCGgetMasterprob(gcg);
1885 assert(Fsize > 0);
1886 assert(F != NULL);
1887 IndexSetSize = 0;
1888 exploreSsize = 0;
1889 exploreS = NULL;
1890 record = NULL;
1891 IndexSet = NULL;
1892 strips = NULL;
1893 nstrips = 0;
1894
1895 SCIPdebugMessage("Calling Separate\n");
1896
1897 SCIP_CALL( SCIPallocBuffer(origprob, &record) );
1898 record->recordsize = 0;
1899 record->record = NULL;
1900 record->sequencesizes = NULL;
1901 record->capacities = NULL;
1902 record->recordcapacity = 0;
1903
1904 /* calculate IndexSet */
1905 SCIP_CALL( InitIndexSet(origprob, F, Fsize, &IndexSet, &IndexSetSize) );
1906 assert(IndexSetSize > 0);
1907 assert(IndexSet != NULL);
1908
1909 /* rootnode? */
1910 if( Csize<=0 )
1911 SCIP_CALL( Separate(origprob, masterprob, F, Fsize, IndexSet, IndexSetSize, NULL, 0, record) );
1912 else
1913 {
1914 assert( C!=NULL );
1915 SCIP_CALL( Explore(origprob, masterprob, C, Csize, CompSizes, 1, F, Fsize, IndexSet, IndexSetSize, &exploreS, &exploreSsize, record) );
1916
1917 SCIPfreeBufferArrayNull(origprob, &exploreS);
1918 }
1919
1920 assert(record != NULL);
1921
1922 if( record->recordsize <= 0 )
1923 {
1924 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
1925
1926 ++(*ncheckedblocks);
1927 assert((*ncheckedblocks) <= GCGgetNPricingprobs(gcg)+1);
1928
1929 if( (*ncheckedblocks) > 1 )
1930 {
1931 SCIP_CALL( SCIPreallocBufferArray(origprob, checkedblocks, *ncheckedblocks) );
1932 SCIP_CALL( SCIPreallocBufferArray(origprob, checkedblocksnsortstrips, *ncheckedblocks) );
1933 SCIP_CALL( SCIPreallocBufferArray(origprob, checkedblockssortstrips, *ncheckedblocks) );
1934 }
1935 else
1936 {
1937 SCIP_CALL( SCIPallocBufferArray(origprob, checkedblocks, *ncheckedblocks) );
1938 SCIP_CALL( SCIPallocBufferArray(origprob, checkedblocksnsortstrips, *ncheckedblocks) );
1939 SCIP_CALL( SCIPallocBufferArray(origprob, checkedblockssortstrips, *ncheckedblocks) );
1940 }
1941
1942 (*checkedblocks)[(*ncheckedblocks)-1] = blocknr;
1943
1944 for( i=0; i<nmastervars; ++i )
1945 {
1946 if( GCGisMasterVarInBlock(mastervars[i], blocknr) )
1947 {
1948 ++nstrips;
1949
1950 SCIP_CALL( SCIPreallocBufferArray(origprob, &strips, nstrips) );
1951
1952 assert(strips != NULL);
1953
1954 SCIP_CALL( SCIPallocBuffer(origprob, &(strips[nstrips-1])) ); /*lint !e866*/
1955 assert(strips[nstrips-1] != NULL);
1956
1957 strips[nstrips-1]->C = NULL;
1958 strips[nstrips-1]->mastervar = mastervars[i];
1959 strips[nstrips-1]->Csize = 0;
1960 strips[nstrips-1]->sequencesizes = NULL;
1961 strips[nstrips-1]->scip = NULL;
1962 }
1963 }
1964
1965 SCIP_CALL( InducedLexicographicSort(origprob, strips, nstrips, C, Csize, CompSizes) );
1966
1967 (*checkedblocksnsortstrips)[(*ncheckedblocks)-1] = nstrips;
1968
1969 SCIP_CALL( SCIPallocBufferArray(origprob, &((*checkedblockssortstrips)[(*ncheckedblocks)-1]), nstrips) ); /*lint !e866*/
1970
1971 /* sort the direct copied origvars at the end */
1972
1973 for( i = 0; i < nstrips; ++i )
1974 {
1975 assert(strips != NULL);
1976
1977 SCIP_CALL( SCIPallocBuffer(origprob, &((*checkedblockssortstrips)[(*ncheckedblocks)-1][i])) ); /*lint !e866*/
1978 (*checkedblockssortstrips)[(*ncheckedblocks)-1][i] = strips[i];
1979 }
1980
1981 for( i=0; i<nstrips; ++i )
1982 {
1983 assert(strips != NULL);
1984 SCIPfreeBuffer(origprob, &(strips[i]));
1985 strips[i] = NULL;
1986 }
1987 SCIPfreeBufferArrayNull(origprob, &strips);
1988
1989 /*choose new block */
1990 SCIP_CALL( initBranch(gcg, branchrule, result, checkedblocks, ncheckedblocks, checkedblockssortstrips, checkedblocksnsortstrips) );
1991
1992 }
1993 else
1994 {
1995 if( ncheckedblocks != NULL && (*ncheckedblocks) > 0 )
1996 {
1997 for( i = (*ncheckedblocks) - 1; i >= 0; --i )
1998 {
1999 int j;
2000
2001 for( j = (*checkedblocksnsortstrips)[i] - 1; j >= 0; --j )
2002 {
2003 SCIPfreeBuffer(origprob, &((*checkedblockssortstrips)[i][j]) );
2004 }
2005
2006 SCIPfreeBufferArray(origprob, &((*checkedblockssortstrips)[i]) );
2007 }
2008
2009 SCIPfreeBufferArray(origprob, checkedblockssortstrips);
2010 SCIPfreeBufferArray(origprob, checkedblocksnsortstrips);
2011 SCIPfreeBufferArray(origprob, checkedblocks);
2012 *ncheckedblocks = 0;
2013 }
2014 }
2015
2016 if( record->recordsize > 0 )
2017 {
2018 SCIP_CALL( ChoseS( origprob, &record, S, Ssize) );
2019 assert(*S != NULL);
2020 }
2021
2022
2023 SCIPfreeBufferArray(origprob, &IndexSet);
2024 if( record != NULL )
2025 {
2026 SCIPfreeBlockMemoryArrayNull(origprob, &record->capacities, record->recordcapacity);
2027 SCIPfreeBlockMemoryArrayNull(origprob, &record->sequencesizes, record->recordcapacity);
2028 SCIPfreeBlockMemoryArrayNull(origprob, &record->record, record->recordcapacity);
2029 SCIPfreeBuffer(origprob, &record);
2030 }
2031 return SCIP_OKAY;
2032}
2033
2034/** callback deletion method for branching data*/
2035static
2036GCG_DECL_BRANCHDATADELETE(branchDataDeleteGeneric)
2037{
2038 SCIP* origprob;
2039 SCIP* masterprob;
2040
2041 origprob = GCGgetOrigprob(gcg);
2042 masterprob = GCGgetMasterprob(gcg);
2043
2044 assert(origprob != NULL);
2045 assert(masterprob != NULL);
2046 assert(branchdata != NULL);
2047
2048 if( origbranch && !force )
2049 return SCIP_OKAY;
2050
2051 if( *branchdata == NULL )
2052 {
2053 SCIPdebugMessage("branchDataDeleteGeneric: cannot delete empty branchdata\n");
2054
2055 return SCIP_OKAY;
2056 }
2057
2058 if( (*branchdata)->mastercons != NULL )
2059 {
2060 SCIPdebugMessage("branchDataDeleteGeneric: child blocknr %d, %s\n", (*branchdata)->consblocknr,
2061 SCIPconsGetName((*branchdata)->mastercons) );
2062 }
2063 else
2064 {
2065 SCIPdebugMessage("branchDataDeleteGeneric: child blocknr %d, empty mastercons\n", (*branchdata)->consblocknr);
2066 }
2067
2068 /* release constraint that enforces the branching decision */
2069 if( (*branchdata)->mastercons != NULL )
2070 {
2071 SCIP_CALL( SCIPreleaseCons(masterprob, &(*branchdata)->mastercons) );
2072 (*branchdata)->mastercons = NULL;
2073 }
2074
2075 if( (*branchdata)->consS != NULL && (*branchdata)->consSsize > 0 )
2076 {
2077 SCIPfreeBlockMemoryArrayNull(origprob, &((*branchdata)->consS), (*branchdata)->maxconsS);
2078 (*branchdata)->consS = NULL;
2079 (*branchdata)->consSsize = 0;
2080 }
2081
2082 SCIPfreeBlockMemoryNull(origprob, branchdata);
2083 *branchdata = NULL;
2084
2085 return SCIP_OKAY;
2086}
2087
2088/** check method for pruning ChildS directly on childnodes
2089 * @returns TRUE if node is pruned */
2090static
2092 SCIP* scip, /**< SCIP data structure */
2093 SCIP_Real lhs, /**< lhs for childnode which is checkes to be pruned */
2094 GCG_COMPSEQUENCE* childS, /**< component bound sequence defining the childnode */
2095 int childSsize, /**< size of component bound sequence */
2096 SCIP_CONS* parentcons, /**< constraint of parent node in B&B tree */
2097 int childBlocknr /**< number of the block for the child node */
2098 )
2099{
2100 int i;
2101 int nchildren;
2102
2103 nchildren = GCGconsMasterbranchGetNChildconss(parentcons);
2104 assert(nchildren>0);
2105
2106 for( i=0; i<nchildren; ++i )
2107 {
2108 SCIP_CONS* childcons;
2109 GCG_BRANCHDATA* branchdata;
2110 SCIP_Bool same;
2111 int j;
2112
2113 same = TRUE;
2114 childcons = GCGconsMasterbranchGetChildcons(parentcons, i);
2115 if( childcons == NULL )
2116 continue;
2117
2119 continue;
2120
2121 branchdata = GCGconsMasterbranchGetBranchdata(childcons);
2122 assert(branchdata != NULL);
2123
2124 if( childBlocknr != branchdata->consblocknr || childSsize != branchdata->consSsize || !SCIPisEQ(scip, lhs, branchdata->lhs) )
2125 continue;
2126
2127 assert(childSsize > 0 && branchdata->consSsize > 0);
2128
2129 for( j=0; j< childSsize; ++j )
2130 {
2131 if( childS[j].component != branchdata->consS[j].component
2132 || childS[j].sense != branchdata->consS[j].sense
2133 || !SCIPisEQ(scip, childS[j].bound, branchdata->consS[j].bound) )
2134 {
2135 same = FALSE;
2136 break;
2137 }
2138 }
2139
2140 if( same )
2141 {
2142 SCIPdebugMessage("child pruned \n");
2143 return TRUE;
2144 }
2145 }
2146 return FALSE;
2147}
2148
2149/** check method for pruning ChildS indirectly by parentnodes
2150 * retrun TRUE if node is pruned */
2151static
2153 SCIP* scip, /**< SCIP data structure */
2154 SCIP_Real lhs, /**< lhs for childnode which is checkes to be pruned */
2155 GCG_COMPSEQUENCE* childS, /**< Component Bound Sequence defining the childnode */
2156 int childSsize, /**< size of component bound sequence */
2157 SCIP_CONS* masterbranchcons, /**< master branching constraint */
2158 int childBlocknr /**< number of the block for the childnode */
2159 )
2160{
2161 SCIP_CONS* cons;
2162
2163 SCIPdebugMessage("Prune by dominance\n");
2164 cons = GCGconsMasterbranchGetParentcons(masterbranchcons);
2165
2166 if( cons == NULL )
2167 {
2168 SCIPdebugMessage("cons == NULL, not pruned\n");
2169 return FALSE;
2170 }
2171 while( cons != NULL )
2172 {
2173 GCG_BRANCHDATA* parentdata;
2174 SCIP_Bool ispruned;
2175
2176 parentdata = GCGconsMasterbranchGetBranchdata(cons);
2177 if( parentdata == NULL )
2178 {
2179 /* root node: check children for pruning */
2180 return checkchildconsS(scip, lhs, childS, childSsize, cons, childBlocknr);
2181 }
2183 return checkchildconsS(scip, lhs, childS, childSsize, cons, childBlocknr);
2184
2185 ispruned = checkchildconsS(scip, lhs, childS, childSsize, cons, childBlocknr);
2186
2187 if( ispruned )
2188 {
2189 return TRUE;
2190 }
2191
2193 }
2194
2195 SCIPdebugMessage("child not pruned\n");
2196 return FALSE;
2197}
2198
2199/** for given component bound sequence S, create |S|+1 Vanderbeck branching nodes */
2200static
2202 GCG* gcg, /**< GCG data structure */
2203 GCG_BRANCHRULE* branchrule, /**< branching rule */
2204 GCG_COMPSEQUENCE* S, /**< Component Bound Sequence defining the nodes */
2205 int Ssize, /**< size of S */
2206 int blocknr, /**< number of the block */
2207 SCIP_CONS* masterbranchcons, /**< current masterbranchcons*/
2208 SCIP_RESULT* result /**< pointer to store the result of the branching call */
2209 )
2210{
2211 SCIP* origprob;
2212 SCIP* masterprob;
2213#ifdef SCIP_DEBUG
2214 SCIP_Real identicalcontrol = 0;
2215#endif
2216 int i;
2217 int p;
2218 SCIP_Real pL;
2219 SCIP_Real L;
2220 SCIP_Real lhsSum;
2221 int nmastervars;
2222 int nmastervars2;
2223 int ncopymastervars;
2224 int nbranchcands;
2225 int nchildnodes;
2226 SCIP_VAR** mastervars;
2227 SCIP_VAR** mastervars2;
2228 SCIP_VAR** branchcands;
2229
2230 origprob = GCGgetOrigprob(gcg);
2231 masterprob = GCGgetMasterprob(gcg);
2232
2233 assert(origprob != NULL);
2234 assert(Ssize > 0);
2235 assert(S != NULL);
2236
2237 lhsSum = 0;
2238 nchildnodes = 0;
2239 L = 0;
2240
2241 pL = GCGgetNIdenticalBlocks(gcg, blocknr);
2242 SCIPdebugMessage("Vanderbeck branching rule Node creation for blocknr %d with %.1f identical blocks \n", blocknr, pL);
2243
2244
2245 /* get variable data of the master problem */
2246 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
2247 nmastervars2 = nmastervars;
2248 assert(nmastervars >= 0);
2249 SCIP_CALL( SCIPduplicateBufferArray(origprob, &mastervars2, mastervars, nmastervars) );
2250
2251 SCIP_CALL( SCIPgetLPBranchCands(masterprob, &branchcands, NULL, NULL, &nbranchcands, NULL, NULL) );
2252
2253 SCIPdebugMessage("Vanderbeck branching rule: creating %d nodes\n", Ssize+1);
2254
2255 for( p=0; p<Ssize+1; ++p )
2256 {
2257 GCG_BRANCHDATA* branchchilddata;
2258 SCIP_NODE* child;
2259 SCIP_CONS* childcons;
2260 int k;
2261
2262 SCIP_Real lhs;
2263 branchchilddata = NULL;
2264
2265 /* allocate branchdata for child and store information */
2266 SCIP_CALL( initNodeBranchdata(origprob, &branchchilddata, blocknr) );
2267
2268 if( p == Ssize )
2269 {
2270 branchchilddata->maxconsS = SCIPcalcMemGrowSize(origprob, Ssize);
2271 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &(branchchilddata->consS), branchchilddata->maxconsS) );
2272 branchchilddata->consSsize = Ssize;
2273 }
2274 else
2275 {
2276 branchchilddata->maxconsS = SCIPcalcMemGrowSize(origprob, p+1);
2277 SCIP_CALL( SCIPallocBlockMemoryArray(origprob, &(branchchilddata->consS), branchchilddata->maxconsS) );
2278 branchchilddata->consSsize = p+1;
2279 }
2280 for( k = 0; k <= p; ++k )
2281 {
2282 GCG_COMPSEQUENCE compBound;
2283
2284 if( k == Ssize )
2285 {
2286 assert( p == Ssize );
2287 compBound = S[k-1];
2288 branchchilddata->consS[k-1] = compBound;
2289 }
2290 else
2291 {
2292 compBound = S[k];
2293 if( k >= p )
2294 {
2295 if( S[p].sense == GCG_COMPSENSE_GE )
2296 compBound.sense = GCG_COMPSENSE_LT;
2297 else
2298 compBound.sense = GCG_COMPSENSE_GE;
2299 }
2300 branchchilddata->consS[k] = compBound;
2301 }
2302 }
2303
2304 /* last node? */
2305 if( p == Ssize )
2306 {
2307 lhs = pL;
2308 }
2309 else
2310 {
2311 /* calculate mu */
2312 SCIP_Real mu = 0.0;
2313
2314 ncopymastervars = nmastervars2;
2315 for( i = 0; i < ncopymastervars; ++i )
2316 {
2317 SCIP_VAR* swap;
2318
2319 if( i >= nmastervars2 )
2320 break;
2321
2322 if( GCGisMasterVarInBlock(mastervars2[i], blocknr) )
2323 {
2324 SCIP_Real generator_i = getGeneratorEntry(mastervars2[i], S[p].component);
2325
2326 if( (S[p].sense == GCG_COMPSENSE_GE && SCIPisGE(origprob, generator_i, S[p].bound)) ||
2327 (S[p].sense == GCG_COMPSENSE_LT && SCIPisLT(origprob, generator_i, S[p].bound) ) )
2328 {
2329 mu += SCIPgetSolVal(masterprob, NULL, mastervars2[i]);
2330 }
2331 else if( ncopymastervars > 0 )
2332 {
2333 swap = mastervars2[i];
2334 mastervars2[i] = mastervars2[nmastervars2-1];
2335 mastervars2[nmastervars2-1] = swap;
2336 --nmastervars2;
2337 --i;
2338 }
2339 }
2340 else if( nmastervars2 > 0 )
2341 {
2342 swap = mastervars2[i];
2343 mastervars2[i] = mastervars2[nmastervars2-1];
2344 mastervars2[nmastervars2-1] = swap;
2345 --nmastervars2;
2346 --i;
2347 }
2348 }
2349
2350 if( p == Ssize-1 ) /*lint !e866 !e850*/
2351 {
2352 L = SCIPceil(origprob, mu);
2353 SCIPdebugMessage("mu = %g, \n", mu);
2354 assert(!SCIPisFeasIntegral(origprob,mu));
2355 }
2356 else
2357 {
2358 L = mu;
2359 SCIPdebugMessage("mu = %g should be integer, \n", mu);
2360 assert(SCIPisFeasIntegral(origprob,mu));
2361 }
2362 lhs = pL-L+1;
2363 }
2364 SCIPdebugMessage("pL = %g \n", pL);
2365 pL = L;
2366
2367 branchchilddata->lhs = lhs;
2368 SCIPdebugMessage("L = %g, \n", L);
2369 SCIPdebugMessage("lhs set to %g \n", lhs);
2370 assert(SCIPisFeasIntegral(origprob, lhs));
2371 lhsSum += lhs;
2372
2373
2374 if( masterbranchcons == NULL || !pruneChildNodeByDominanceGeneric(origprob, lhs, branchchilddata->consS, branchchilddata->consSsize, masterbranchcons, blocknr) )
2375 {
2376 if( masterbranchcons != NULL )
2377 {
2378 char childname[SCIP_MAXSTRLEN];
2379 ++nchildnodes;
2380
2381 assert(branchchilddata != NULL);
2382
2383 /* define names for origbranch constraints */
2384 (void) SCIPsnprintf(childname, SCIP_MAXSTRLEN, "node(%d, %d) (last comp=%s %s %g) >= %g", blocknr, p+1,
2385 SCIPvarGetName(branchchilddata->consS[branchchilddata->consSsize-1].component),
2386 branchchilddata->consS[branchchilddata->consSsize-1].sense == GCG_COMPSENSE_GE? ">=": "<",
2387 branchchilddata->consS[branchchilddata->consSsize-1].bound,
2388 branchchilddata->lhs);
2389
2390 SCIP_CALL( SCIPcreateChild(masterprob, &child, 0.0, SCIPgetLocalTransEstimate(masterprob)) );
2391 SCIP_CALL( GCGcreateConsMasterbranch(gcg, &childcons, childname, child,
2392 GCGconsMasterbranchGetActiveCons(gcg), branchrule, branchchilddata, NULL, 0, 0) );
2393 SCIP_CALL( SCIPaddConsNode(masterprob, child, childcons, NULL) );
2394
2395 SCIP_CALL( createBranchingCons(gcg, child, branchchilddata) );
2396
2397 /* release constraints */
2398 SCIP_CALL( SCIPreleaseCons(masterprob, &childcons) );
2399 }
2400 }
2401 else
2402 {
2403 SCIPfreeBlockMemoryArrayNull(origprob, &(branchchilddata->consS), branchchilddata->maxconsS);
2404 SCIPfreeBlockMemoryNull(origprob, &branchchilddata);
2405 }
2406 }
2407 SCIPdebugMessage("lhsSum = %g\n", lhsSum);
2408
2409#ifdef SCIP_DEBUG
2410 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
2411
2412 for( i = 0; i < nmastervars; ++i )
2413 {
2414 SCIP_VAR* mastervar = mastervars[i];
2415
2416 if( GCGisMasterVarInBlock(mastervar, blocknr) )
2417 {
2418 identicalcontrol += SCIPgetSolVal(masterprob, NULL, mastervar);
2419 }
2420
2421 }
2422 if( !SCIPisEQ(origprob, identicalcontrol, GCGgetNIdenticalBlocks(gcg, blocknr)) )
2423 {
2424 SCIPdebugMessage("width of the block is only %g\n", identicalcontrol);
2425 }
2426
2427 assert( SCIPisEQ(origprob, identicalcontrol, GCGgetNIdenticalBlocks(gcg, blocknr)) );
2428#endif
2429
2430 assert( SCIPisEQ(origprob, lhsSum, 1.0*(GCGgetNIdenticalBlocks(gcg, blocknr) + Ssize)) );
2431
2432 SCIPfreeBufferArray(origprob, &mastervars2);
2433
2434 if( nchildnodes <= 0 )
2435 {
2436 SCIPdebugMessage("node cut off, since all childnodes have been pruned\n");
2437
2438 *result = SCIP_CUTOFF;
2439 }
2440
2441 return SCIP_OKAY;
2442}
2443
2444/* from branch_master */
2445static
2447 SCIP* scip /**< SCIP data structure */
2448 )
2449{
2463 return SCIP_OKAY;
2464}
2465/** copy method for master branching rule */
2466static
2467SCIP_DECL_BRANCHCOPY(branchCopyGeneric)
2468{
2469 assert(branchrule != NULL);
2470 assert(scip != NULL);
2472 return SCIP_OKAY;
2473}
2474
2475/** callback new column method */
2476static
2477GCG_DECL_BRANCHNEWCOL(branchNewColGeneric)
2478{
2479 SCIP* masterprob = GCGgetMasterprob(gcg);
2480 assert(masterprob != NULL);
2481 assert(GCGisMaster(masterprob));
2482 assert(mastervar != NULL);
2483 assert(GCGvarIsMaster(mastervar));
2484 assert(branchdata != NULL);
2485 assert(branchdata->mastercons != NULL);
2486
2487 SCIP_Bool added = FALSE;
2488 SCIP_CALL( addVarToMasterbranch(masterprob, mastervar, branchdata, &added) );
2489
2490 return SCIP_OKAY;
2491}
2492
2493/** callback propagation method */
2494static
2495GCG_DECL_BRANCHPROPMASTER(branchPropMasterGeneric)
2496{
2497 assert(branchdata != NULL);
2498 assert(branchdata->mastercons != NULL);
2499 assert(branchdata->consS != NULL);
2500
2501 /* SCIPdebugMessage("branchPropMasterGeneric: Block %d ,Ssize %d)\n", branchdata->consblocknr, branchdata->consSsize); */
2502 *result = SCIP_DIDNOTFIND;
2503 return SCIP_OKAY;
2504}
2505
2506/** branching execution method for fractional LP solutions */
2507static
2508SCIP_DECL_BRANCHEXECLP(branchExeclpGeneric)
2509{ /*lint --e{715}*/
2510 SCIP* origprob;
2511 SCIP_BRANCHRULEDATA* branchruledata;
2512 SCIP_Bool discretization;
2513
2514 int* checkedblocks;
2515 int ncheckedblocks;
2516 GCG_STRIP*** checkedblockssortstrips;
2517 int* checkedblocksnsortstrips;
2518
2519 assert(branchrule != NULL);
2520 assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
2521 assert(result != NULL);
2522
2523 branchruledata = SCIPbranchruleGetData(branchrule);
2524 assert(branchruledata != NULL);
2525
2526 origprob = GCGgetOrigprob(branchruledata->gcg);
2527 assert(origprob != NULL);
2528
2529 SCIPdebugMessage("Execrel method of Vanderbecks generic branching\n");
2530
2531 *result = SCIP_DIDNOTRUN;
2532
2533 /* the branching scheme only works for the discretization approach */
2534 SCIP_CALL( SCIPgetBoolParam(origprob, "relaxing/gcg/discretization", &discretization) );
2535 if( !discretization )
2536 {
2537 SCIPdebugMessage("Generic branching only for discretization approach\n");
2538 return SCIP_OKAY;
2539 }
2540
2541 if( GCGisMasterSetCovering(branchruledata->gcg) || GCGisMasterSetPartitioning(branchruledata->gcg) )
2542 {
2543 SCIPdebugMessage("Generic branching executed on a set covering or set partitioning problem\n");
2544 }
2545
2546 if( GCGrelaxIsOrigSolFeasible(branchruledata->gcg) )
2547 {
2548 SCIPdebugMessage("node cut off, since origsol was feasible, solval = %f\n",
2549 SCIPgetSolOrigObj(origprob, GCGrelaxGetCurrentOrigSol(branchruledata->gcg)));
2550
2551 *result = SCIP_DIDNOTFIND;
2552 return SCIP_OKAY;
2553 }
2554
2555 *result = SCIP_BRANCHED;
2556
2557 checkedblocks = NULL;
2558 ncheckedblocks = 0;
2559 checkedblockssortstrips = NULL;
2560 checkedblocksnsortstrips = NULL;
2561
2562 SCIP_CALL( initBranch(branchruledata->gcg, branchruledata->gcgbranchrule, result, &checkedblocks, &ncheckedblocks, &checkedblockssortstrips, &checkedblocksnsortstrips) );
2563
2564 return SCIP_OKAY;
2565}
2566
2567/** prepares information for using the generic branching scheme */
2568static
2570 GCG* gcg, /**< GCG data structure */
2571 GCG_BRANCHRULE* branchrule, /**< branching rule */
2572 SCIP_RESULT* result, /**< pointer to store the result of the branching call */
2573 int** checkedblocks, /**< blocks that have been checked */
2574 int* ncheckedblocks, /**< number of checked blocks */
2575 GCG_STRIP**** checkedblockssortstrips, /**< sorted strips of checked blocks */
2576 int** checkedblocksnsortstrips /**< sizes of the strips */
2577 )
2578{
2579 SCIP* origprob;
2580 SCIP* masterprob;
2581 SCIP_VAR** branchcands;
2582 SCIP_VAR** allorigvars;
2583 SCIP_VAR** mastervars;
2584 int nmastervars;
2585 SCIP_CONS* masterbranchcons;
2586 int nbranchcands;
2587 GCG_BRANCHDATA* branchdata;
2588 SCIP_VAR* mastervar;
2589 SCIP_Real mastervarValue;
2591 GCG_COMPSEQUENCE** C;
2592 SCIP_VAR** F;
2593 int Ssize;
2594 int Fsize;
2595 int* sequencesizes;
2596 int blocknr;
2597 int i;
2598 int j;
2599 int allnorigvars;
2600#ifndef NDEBUG
2601 SCIP_Bool foundblocknr = FALSE;
2602#endif
2603
2604 SCIP_Bool discretization;
2605
2606 origprob = GCGgetOrigprob(gcg);
2607 masterprob = GCGgetMasterprob(gcg);
2608
2609 blocknr = -2;
2610 Ssize = 0;
2611 Fsize = 0;
2612 S = NULL;
2613 C = NULL;
2614 F = NULL;
2615 sequencesizes = NULL;
2616
2617 assert(masterprob != NULL);
2618
2619 SCIPdebugMessage("get information for Vanderbecks generic branching\n");
2620
2621 SCIP_CALL( SCIPgetBoolParam(origprob, "relaxing/gcg/discretization", &discretization) );
2622
2623 assert(origprob != NULL);
2624 SCIP_CALL( SCIPgetLPBranchCands(masterprob, &branchcands, NULL, NULL, &nbranchcands, NULL, NULL) );
2625
2626 SCIP_CALL( SCIPgetVarsData(origprob, &allorigvars, &allnorigvars, NULL, NULL, NULL, NULL) );
2627 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
2628
2629 /* in case original problem contains continuous variables, there are no branching cands */
2630 assert(nbranchcands > 0 || (discretization && SCIPgetNContVars(origprob) > 0));
2631 mastervar = NULL;
2632
2633 /* loop over all branching candidates */
2634 for( i = 0; i < nbranchcands && (!discretization || SCIPgetNContVars(origprob) == 0); ++i )
2635 {
2636 int k;
2637 mastervar = branchcands[i];
2638 assert(GCGvarIsMaster(mastervar));
2639
2640 /* if we have a master variable, we branch on it */
2641 if( GCGvarGetBlock(mastervar) == -1 )
2642 {
2643 assert(!GCGmasterVarIsArtificial(mastervar));
2644#ifndef NDEBUG
2645 foundblocknr = TRUE;
2646#endif
2647 blocknr = -1;
2648 break;
2649 }
2650
2651 /* else, check if the candidate is in an unchecked block */
2652 for( j = 0; j < GCGgetNPricingprobs(gcg); ++j )
2653 {
2654 SCIP_Bool checked = FALSE;
2655 for( k = 0; ncheckedblocks != NULL && k < (*ncheckedblocks); ++k )
2656 {
2657 /* if the block has been checked, no need to check master variable */
2658 if( (*checkedblocks)[k] == j )
2659 {
2660 checked = TRUE;
2661 break;
2662 }
2663 }
2664
2665 if( checked )
2666 continue;
2667 /* else the block has not been checked and the variable is in it , we have a candidate */
2668 else if( GCGisMasterVarInBlock(mastervar, j) )
2669 {
2670#ifndef NDEBUG
2671 foundblocknr = TRUE;
2672#endif
2673 blocknr = j;
2674 break;
2675 }
2676 }
2677 }
2678 assert(foundblocknr || blocknr == -1 || (discretization && SCIPgetNContVars(origprob) > 0));
2679 assert(i <= nbranchcands); /* else all blocks has been checked and we can observe an integer solution */
2680
2681 /* in case of continuous origvar look for "fractional" blocks using the representation (currentorigsol) in the original problem */
2682 if(discretization && SCIPgetNContVars(origprob) > 0)
2683 {
2684 int norigvars;
2685 SCIP_VAR** origvars;
2686 SCIP_VAR* origvar;
2687
2688 norigvars = SCIPgetNVars(origprob);
2689 origvars = SCIPgetVars(origprob);
2690
2691 nbranchcands = SCIPgetNVars(masterprob);
2692 branchcands = SCIPgetVars(masterprob);
2693
2694 assert(nbranchcands > 0);
2695
2696 for( i = 0; i < norigvars; ++i )
2697 {
2698 int k;
2699 SCIP_Bool checked;
2700 origvar = origvars[i];
2701
2702 if( SCIPvarGetType(origvar) > SCIP_VARTYPE_INTEGER )
2703 continue;
2704
2705 if( SCIPisIntegral(origprob, SCIPgetSolVal(origprob, GCGrelaxGetCurrentOrigSol(gcg), origvar)) )
2706 continue;
2707
2708 blocknr = GCGgetBlockRepresentative(gcg, GCGvarGetBlock(origvar));
2709
2710 SCIPdebugMessage("Variable %s belonging to block %d with representative %d is not integral!\n", SCIPvarGetName(origvar), GCGvarGetBlock(origvar), blocknr);
2711
2712 if( blocknr == -1 )
2713 {
2714 assert(GCGoriginalVarGetNMastervars(origvar) == 1);
2715 mastervar = GCGoriginalVarGetMastervars(origvar)[0];
2716 break;
2717 }
2718
2719 checked = FALSE;
2720 for( k = 0; ncheckedblocks != NULL && k < (*ncheckedblocks); ++k )
2721 {
2722 /* if the block has been checked, no need to check master variable */
2723 if( (*checkedblocks)[k] == blocknr )
2724 {
2725 checked = TRUE;
2726 break;
2727 }
2728 }
2729
2730 if( checked )
2731 {
2732 continue;
2733 }
2734 else
2735 {
2736 break;
2737 }
2738 }
2739 }
2740
2741 if( blocknr < -1 )
2742 {
2743 SCIP_Bool rays;
2744
2745 SCIPerrorMessage("Generic branching rule could not find variables to branch on!\n");
2746
2747 SCIP_CALL( GCGpricerExistRays(gcg, &rays) );
2748
2749 if( rays )
2750 SCIPerrorMessage("Generic branching is not compatible with unbounded problems!\n");
2751
2752 return SCIP_ERROR;
2753 }
2754
2755 /* a special case; branch on copy of an origvar directly */
2756 if( blocknr == -1 )
2757 {
2758 assert(!GCGmasterVarIsLinking(mastervar));
2759 SCIPdebugMessage("branching on master variable\n");
2760 SCIP_CALL( branchDirectlyOnMastervar(gcg, mastervar, branchrule) );
2761 return SCIP_OKAY;
2762 }
2763
2764 masterbranchcons = GCGconsMasterbranchGetActiveCons(gcg);
2765 SCIPdebugMessage("branching in block %d \n", blocknr);
2766
2767 /* calculate F and the strips */
2768 for( i = 0; i < nbranchcands; ++i )
2769 {
2770 mastervar = branchcands[i];
2771 assert(GCGvarIsMaster(mastervar));
2772
2773 if( GCGisMasterVarInBlock(mastervar, blocknr) )
2774 {
2775 mastervarValue = SCIPgetSolVal(masterprob, NULL, mastervar);
2776 if( !SCIPisFeasIntegral(masterprob, mastervarValue) )
2777 {
2778
2779 SCIP_CALL( SCIPreallocBufferArray(origprob, &F, (size_t)Fsize+1) );
2780
2781 F[Fsize] = mastervar;
2782 ++Fsize;
2783 }
2784 }
2785 }
2786
2787 /* old data to regard? */
2788 if( masterbranchcons != NULL && GCGconsMasterbranchGetBranchdata(masterbranchcons) != NULL )
2789 {
2790 /* calculate C */
2791 int c;
2792 int Csize = 0;
2793 SCIP_CONS* parentcons = masterbranchcons;
2794
2795 while( parentcons != NULL && GCGconsMasterbranchGetBranchrule(parentcons) != NULL
2797 {
2798 branchdata = GCGconsMasterbranchGetBranchdata(parentcons);
2799 if( branchdata == NULL )
2800 {
2801 SCIPdebugMessage("branchdata is NULL\n");
2802 break;
2803 }
2804 if( branchdata->consS == NULL || branchdata->consSsize == 0 )
2805 break;
2806 if( branchdata->consblocknr != blocknr )
2807 {
2808 parentcons = GCGconsMasterbranchGetParentcons(parentcons);
2809 continue;
2810 }
2811
2812 if( Csize == 0 )
2813 {
2814 assert(branchdata != NULL);
2815 assert(branchdata->consSsize > 0);
2816 Csize = 1;
2817 SCIP_CALL( SCIPallocBufferArray(origprob, &C, Csize) );
2818 SCIP_CALL( SCIPallocBufferArray(origprob, &sequencesizes, Csize) );
2819 assert(sequencesizes != NULL);
2820 C[0] = NULL;
2821 SCIP_CALL( SCIPallocBufferArray(origprob, &(C[0]), branchdata->consSsize) );
2822 for( i = 0; i < branchdata->consSsize; ++i )
2823 {
2824 C[0][i] = branchdata->consS[i];
2825 }
2826 sequencesizes[0] = branchdata->consSsize;
2827 parentcons = GCGconsMasterbranchGetParentcons(parentcons);
2828 }
2829 else
2830 {
2831 /* S not yet in C ? */
2832 SCIP_Bool SinC = FALSE;
2833 for( c = 0; c < Csize && !SinC; ++c )
2834 {
2835 SinC = TRUE;
2836 assert(sequencesizes != NULL);
2837 if( branchdata->consSsize == sequencesizes[c] )
2838 {
2839 for( i = 0; i < branchdata->consSsize; ++i )
2840 {
2841 assert(C != NULL);
2842 if( branchdata->consS[i].component != C[c][i].component || branchdata->consS[i].sense != C[c][i].sense || !SCIPisEQ(origprob, branchdata->consS[i].bound, C[c][i].bound) )
2843 {
2844 SinC = FALSE;
2845 break;
2846 }
2847 }
2848 }
2849 else
2850 SinC = FALSE;
2851 }
2852 if( !SinC )
2853 {
2854 ++Csize;
2855 SCIP_CALL( SCIPreallocBufferArray(origprob, &C, Csize) );
2856 SCIP_CALL( SCIPreallocBufferArray(origprob, &sequencesizes, Csize) );
2857 assert(sequencesizes != NULL);
2858 C[Csize-1] = NULL;
2859 SCIP_CALL( SCIPallocBufferArray(origprob, &(C[Csize-1]), branchdata->consSsize) ); /*lint !e866*/
2860
2861 /** @todo copy memory */
2862 for( i = 0; i < branchdata->consSsize; ++i )
2863 {
2864 C[Csize-1][i] = branchdata->consS[i];
2865 }
2866 sequencesizes[Csize-1] = branchdata->consSsize;
2867 }
2868 parentcons = GCGconsMasterbranchGetParentcons(parentcons);
2869 }
2870 }
2871
2872 if( C != NULL )
2873 {
2874 SCIPdebugMessage("Csize = %d\n", Csize);
2875
2876 for( i = 0; i < Csize; ++i )
2877 {
2878 assert(sequencesizes != NULL);
2879
2880 for( c = 0; c < sequencesizes[i]; ++c )
2881 {
2882 SCIPdebugMessage("C[%d][%d].component = %s\n", i, c, SCIPvarGetName(C[i][c].component) );
2883 SCIPdebugMessage("C[%d][%d].sense = %d\n", i, c, C[i][c].sense);
2884 SCIPdebugMessage("C[%d][%d].bound = %.6g\n", i, c, C[i][c].bound);
2885 }
2886 }
2887 /* SCIP_CALL( InducedLexicographicSort(scip, F, Fsize, C, Csize, sequencesizes) ); */
2888 SCIP_CALL( ChooseSeparateMethod(gcg, F, Fsize, &S, &Ssize, C, Csize, sequencesizes, blocknr, branchrule, result, checkedblocks,
2889 ncheckedblocks, checkedblockssortstrips, checkedblocksnsortstrips) );
2890 }
2891 else
2892 {
2893 SCIPdebugMessage("C == NULL\n");
2894 /* SCIP_CALL( InducedLexicographicSort( scip, F, Fsize, NULL, 0, NULL ) ); */
2895 SCIP_CALL( ChooseSeparateMethod(gcg, F, Fsize, &S, &Ssize, NULL, 0, NULL, blocknr, branchrule, result,
2896 checkedblocks, ncheckedblocks, checkedblockssortstrips, checkedblocksnsortstrips) );
2897 }
2898 if( sequencesizes != NULL )
2899 {
2900 assert(Csize > 0);
2901 SCIPfreeBufferArray(origprob, &sequencesizes);
2902 }
2903 for( i = Csize - 1; i >= 0; --i )
2904 {
2905 assert(C != NULL );
2906 SCIPfreeBufferArrayNull(origprob, &(C[i]));
2907 }
2908 if( C != NULL )
2909 {
2910 assert( Csize > 0);
2911 SCIPfreeBufferArrayNull(origprob, &C);
2912 }
2913 }
2914 else
2915 {
2916 SCIPdebugMessage("root node\n");
2917 /* SCIP_CALL( InducedLexicographicSort( scip, F, Fsize, NULL, 0, NULL ) ); */
2918 SCIP_CALL( ChooseSeparateMethod(gcg, F, Fsize, &S, &Ssize, NULL, 0, NULL, blocknr, branchrule, result, checkedblocks,
2919 ncheckedblocks, checkedblockssortstrips, checkedblocksnsortstrips) );
2920 }
2921
2922 /* create the |S|+1 child nodes in the branch-and-bound tree */
2923 if( S != NULL && Ssize > 0 )
2924 {
2925 SCIP_CALL( createChildNodesGeneric(gcg, branchrule, S, Ssize, blocknr, masterbranchcons, result) );
2926 }
2927
2928 SCIPfreeBufferArrayNull(origprob, &S);
2929 SCIPdebugMessage("free F\n");
2930 SCIPfreeBufferArray(origprob, &F);
2931
2932 return SCIP_OKAY;
2933}
2934
2935/** branching execution method for relaxation solutions */
2936static
2937SCIP_DECL_BRANCHEXECEXT(branchExecextGeneric)
2938{ /*lint --e{715}*/
2939 SCIPdebugMessage("Execext method of generic branching\n");
2940
2941 *result = SCIP_DIDNOTRUN;
2942
2943 return SCIP_OKAY;
2944}
2945
2946/** branching execution method for not completely fixed pseudo solutions
2947 * @bug this needs to be implemented: #32
2948 */
2949
2950static
2951SCIP_DECL_BRANCHEXECPS(branchExecpsGeneric)
2952{ /*lint --e{715}*/
2953 assert(branchrule != NULL);
2954 assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
2955 assert(scip != NULL);
2956 assert(result != NULL);
2957
2958 SCIPdebugMessage("Execps method of Vanderbecks generic branching\n");
2959
2960 if( SCIPisStopped(scip) )
2961 {
2962 SCIPwarningMessage(scip, "No branching could be created, solving process cannot be restarted...\n" );
2963
2964 *result = SCIP_DIDNOTRUN;
2965 return SCIP_OKAY;
2966 }
2967 else
2968 {
2969 SCIPerrorMessage("This method is not implemented, aborting since we cannot recover!\n");
2970 SCIPdialogMessage(scip, NULL, "Due to numerical issues, the problem could not be solved.\n");
2971 SCIPdialogMessage(scip, NULL, "You can try to disable discretization and aggregation and resolve the problem.\n");
2972
2973 *result = SCIP_DIDNOTRUN;
2974 return SCIP_ERROR;
2975 }
2976}
2977
2978/** initialization method of branching rule (called after problem was transformed) */
2979static
2980SCIP_DECL_BRANCHINIT(branchInitGeneric)
2981{
2982 SCIPdebugMessage("Init method of Vanderbecks generic branching\n");
2983
2984 return SCIP_OKAY;
2985}
2986
2987/** destructor method of branching rule (called when SCIP is exiting) */
2988static
2989SCIP_DECL_BRANCHFREE(branchFreeGeneric)
2990{
2991 SCIP_BRANCHRULEDATA* branchruledata;
2992 SCIPdebugMessage("Free method of Vanderbecks generic branching\n");
2993
2994 branchruledata = SCIPbranchruleGetData(branchrule);
2995 assert(branchruledata != NULL);
2996 SCIPfreeBlockMemory(scip, &branchruledata);
2997
2998 return SCIP_OKAY;
2999}
3000
3001/** creates the generic branching rule and includes it in SCIP */
3003 GCG* gcg /**< GCG data structure */
3004 )
3005{
3006 SCIP* masterprob;
3007 SCIP_BRANCHRULEDATA* branchruledata;
3008 SCIP_BRANCHRULE* branchrule;
3009 GCG_BRANCHRULE* gcgbranchrule;
3010 SCIP_EVENTHDLRDATA* eventhdlrdata;
3011
3012 masterprob = GCGgetMasterprob(gcg);
3013 assert(masterprob != NULL);
3014
3015 /* create branching rule data */
3016 SCIP_CALL( SCIPallocBlockMemory(masterprob, &branchruledata) );
3017 SCIP_CALL( SCIPallocBlockMemory(masterprob, &eventhdlrdata) );
3018
3019 branchruledata->gcg = gcg;
3020 eventhdlrdata->gcg = gcg;
3021
3022 SCIPdebugMessage("Include method of Vanderbecks generic branching\n");
3023
3024 /* include branching rule */
3025 SCIP_CALL( GCGrelaxIncludeBranchrule(branchruledata->gcg, &branchrule, &gcgbranchrule, BRANCHRULE_NAME,
3027 NULL, branchPropMasterGeneric, NULL, branchDataDeleteGeneric, branchNewColGeneric, NULL, NULL) );
3028 SCIP_CALL( SCIPsetBranchruleInit(masterprob, branchrule, branchInitGeneric) );
3029 SCIP_CALL( SCIPsetBranchruleFree(masterprob, branchrule, branchFreeGeneric) );
3030 SCIP_CALL( SCIPsetBranchruleExecLp(masterprob, branchrule, branchExeclpGeneric) );
3031 SCIP_CALL( SCIPsetBranchruleExecExt(masterprob, branchrule, branchExecextGeneric) );
3032 SCIP_CALL( SCIPsetBranchruleExecPs(masterprob, branchrule, branchExecpsGeneric) );
3033 SCIP_CALL( SCIPsetBranchruleCopy(masterprob, branchrule, branchCopyGeneric) );
3034 branchruledata->gcgbranchrule = gcgbranchrule;
3035
3036 /* include event handler for adding generated mastervars to the branching constraints */
3038 NULL, eventFreeGenericbranchvaradd, NULL, NULL, eventInitsolGenericbranchvaradd, eventExitsolGenericbranchvaradd,
3039 NULL, eventExecGenericbranchvaradd,
3040 eventhdlrdata) );
3041
3042 branchrule = SCIPfindBranchrule(masterprob, BRANCHRULE_NAME);
3043 assert(branchrule != NULL);
3044
3045 return SCIP_OKAY;
3046}
3047
3048/** get component bound sequence */
3050 GCG_BRANCHDATA* branchdata /**< branching data */
3051 )
3052{
3053 assert(branchdata != NULL);
3054 return branchdata->consS;
3055}
3056
3057/** get size of component bound sequence */
3059 GCG_BRANCHDATA* branchdata /**< branching data */
3060 )
3061{
3062 assert(branchdata != NULL);
3063 return branchdata->consSsize;
3064}
3065
3066/** get id of pricing problem (or block) to which the constraint belongs */
3068 GCG_BRANCHDATA* branchdata /**< branching data */
3069 )
3070{
3071 assert(branchdata != NULL);
3072 return branchdata->consblocknr;
3073}
3074
3075/** get master constraint */
3077 GCG_BRANCHDATA* branchdata /**< branching data */
3078 )
3079{
3080 assert(branchdata != NULL);
3081 return branchdata->mastercons;
3082}
3083
3084/** returns true when the branch rule is the generic branchrule */
3086 GCG_BRANCHRULE* branchrule /**< branchrule to check */
3087)
3088{
3089 return (branchrule != NULL) && (strcmp(BRANCHRULE_NAME, SCIPbranchruleGetName(GCGbranchGetScipBranchrule(branchrule))) == 0);
3090}
SCIP_RETCODE SCIPincludeBranchruleAllfullstrong(SCIP *scip)
#define BRANCHRULE_DESC
static GCG_DECL_BRANCHPROPMASTER(branchPropMasterGeneric)
static GCG_DECL_SORTPTRCOMP(ptrcomp)
static SCIP_RETCODE initNodeBranchdata(SCIP *scip, GCG_BRANCHDATA **nodebranchdata, int blocknr)
static GCG_DECL_BRANCHDATADELETE(branchDataDeleteGeneric)
static SCIP_DECL_BRANCHFREE(branchFreeGeneric)
#define BRANCHRULE_PRIORITY
static SCIP_Real GetMedian(SCIP *scip, SCIP_Real *array, int arraysize, SCIP_Real min)
static GCG_DECL_BRANCHNEWCOL(branchNewColGeneric)
static SCIP_Bool pruneChildNodeByDominanceGeneric(SCIP *scip, SCIP_Real lhs, GCG_COMPSEQUENCE *childS, int childSsize, SCIP_CONS *masterbranchcons, int childBlocknr)
static int computeNewSequence(int Csize, int p, SCIP_VAR *origvar, int *sequencesizes, GCG_COMPSEQUENCE **C, GCG_COMPSEQUENCE **CopyC, int *newsequencesizes, GCG_COMPSENSE sense)
static SCIP_RETCODE createChildNodesGeneric(GCG *gcg, GCG_BRANCHRULE *branchrule, GCG_COMPSEQUENCE *S, int Ssize, int blocknr, SCIP_CONS *masterbranchcons, SCIP_RESULT *result)
static SCIP_RETCODE Explore(SCIP *origprob, SCIP *masterprob, GCG_COMPSEQUENCE **C, int Csize, int *sequencesizes, int p, SCIP_VAR **F, int Fsize, SCIP_VAR **IndexSet, int IndexSetSize, GCG_COMPSEQUENCE **S, int *Ssize, GCG_RECORD *record)
static SCIP_DECL_BRANCHEXECPS(branchExecpsGeneric)
static SCIP_RETCODE branchDirectlyOnMastervar(GCG *gcg, SCIP_VAR *mastervar, GCG_BRANCHRULE *branchrule)
int GCGbranchGenericBranchdataGetConsSsize(GCG_BRANCHDATA *branchdata)
static SCIP_RETCODE partition(SCIP *scip, SCIP_VAR **J, int *Jsize, SCIP_Longint *priority, SCIP_VAR **F, int Fsize, SCIP_VAR **origvar, SCIP_Real *median)
static double computeAlpha(SCIP *origprob, SCIP *masterprob, int Fsize, GCG_COMPSENSE isense, double ivalue, SCIP_VAR *origvar, SCIP_VAR **F)
static SCIP_RETCODE ChoseS(SCIP *scip, GCG_RECORD **record, GCG_COMPSEQUENCE **S, int *Ssize)
static SCIP_DECL_EVENTFREE(eventFreeGenericbranchvaradd)
int GCGbranchGenericBranchdataGetConsblocknr(GCG_BRANCHDATA *branchdata)
static int ILOcomp(SCIP *scip, SCIP_VAR *mastervar1, SCIP_VAR *mastervar2, GCG_COMPSEQUENCE **C, int NBoundsequences, int *sequencesizes, int p)
#define BRANCHRULE_NAME
static SCIP_RETCODE initBranch(GCG *gcg, GCG_BRANCHRULE *branchrule, SCIP_RESULT *result, int **checkedblocks, int *ncheckedblocks, GCG_STRIP ****checkedblockssortstrips, int **checkedblocksnsortstrips)
static SCIP_DECL_BRANCHEXECLP(branchExeclpGeneric)
static SCIP_RETCODE InducedLexicographicSort(SCIP *scip, GCG_STRIP **array, int arraysize, GCG_COMPSEQUENCE **C, int NBoundsequences, int *sequencesizes)
static SCIP_RETCODE addToRecord(SCIP *scip, GCG_RECORD *record, GCG_COMPSEQUENCE *S, int Ssize)
static SCIP_RETCODE LexicographicSort(SCIP *scip, GCG_STRIP **array, int arraysize)
static SCIP_DECL_EVENTEXEC(eventExecGenericbranchvaradd)
SCIP_RETCODE GCGincludeBranchruleGeneric(GCG *gcg)
static SCIP_DECL_BRANCHINIT(branchInitGeneric)
static SCIP_DECL_BRANCHCOPY(branchCopyGeneric)
static SCIP_DECL_EVENTINITSOL(eventInitsolGenericbranchvaradd)
static SCIP_RETCODE Separate(SCIP *origprob, SCIP *masterprob, SCIP_VAR **F, int Fsize, SCIP_VAR **IndexSet, int IndexSetSize, GCG_COMPSEQUENCE *S, int Ssize, GCG_RECORD *record)
static SCIP_DECL_EVENTEXITSOL(eventExitsolGenericbranchvaradd)
GCG_COMPSEQUENCE * GCGbranchGenericBranchdataGetConsS(GCG_BRANCHDATA *branchdata)
static SCIP_RETCODE ChooseSeparateMethod(GCG *gcg, SCIP_VAR **F, int Fsize, GCG_COMPSEQUENCE **S, int *Ssize, GCG_COMPSEQUENCE **C, int Csize, int *CompSizes, int blocknr, GCG_BRANCHRULE *branchrule, SCIP_RESULT *result, int **checkedblocks, int *ncheckedblocks, GCG_STRIP ****checkedblockssortstrips, int **checkedblocksnsortstrips)
static SCIP_RETCODE GCGincludeMasterCopyPlugins(SCIP *scip)
static SCIP_RETCODE InitIndexSet(SCIP *scip, SCIP_VAR **F, int Fsize, SCIP_VAR ***IndexSet, int *IndexSetSize)
static SCIP_DECL_SORTPTRCOMP(ptrilocomp)
static SCIP_RETCODE createDirectBranchingCons(SCIP *scip, SCIP_NODE *node, GCG_BRANCHDATA *branchdata)
SCIP_CONS * GCGbranchGenericBranchdataGetMastercons(GCG_BRANCHDATA *branchdata)
#define EVENTHDLR_DESC
static SCIP_Bool checkchildconsS(SCIP *scip, SCIP_Real lhs, GCG_COMPSEQUENCE *childS, int childSsize, SCIP_CONS *parentcons, int childBlocknr)
static SCIP_Real getColCoefficient(SCIP *scip, GCG_BRANCHDATA *branchdata, SCIP_VAR *mastervar, int probnr)
static SCIP_RETCODE createBranchingCons(GCG *gcg, SCIP_NODE *node, GCG_BRANCHDATA *branchdata)
SCIP_Bool GCGisBranchruleGeneric(GCG_BRANCHRULE *branchrule)
static SCIP_DECL_BRANCHEXECEXT(branchExecextGeneric)
#define EVENTHDLR_NAME
static SCIP_RETCODE addVarToMasterbranch(SCIP *masterprob, SCIP_VAR *mastervar, GCG_BRANCHDATA *branchdata, SCIP_Bool *added)
#define BRANCHRULE_MAXDEPTH
#define BRANCHRULE_MAXBOUNDDIST
static SCIP_Real getGeneratorEntry(SCIP_VAR *mastervar, SCIP_VAR *origvar)
branching rule based on vanderbeck's generic branching scheme
GCG_COMPSENSE
@ GCG_COMPSENSE_LT
@ GCG_COMPSENSE_GE
SCIP_BRANCHRULE * GCGbranchGetScipBranchrule(GCG_BRANCHRULE *branchrule)
Definition: branchgcg.c:102
SCIP_Real * r
constraint handler for the integrality constraint
GCG_BRANCHRULE * GCGconsMasterbranchGetBranchrule(SCIP_CONS *cons)
SCIP_CONS * GCGconsMasterbranchGetParentcons(SCIP_CONS *cons)
GCG_BRANCHDATA * GCGconsMasterbranchGetBranchdata(SCIP_CONS *cons)
SCIP_CONS * GCGconsMasterbranchGetActiveCons(GCG *gcg)
int GCGconsMasterbranchGetNChildconss(SCIP_CONS *cons)
SCIP_CONS * GCGconsMasterbranchGetChildcons(SCIP_CONS *cons, int childnr)
SCIP_RETCODE GCGcreateConsMasterbranch(GCG *gcg, SCIP_CONS **cons, const char *name, SCIP_NODE *node, SCIP_CONS *parentcons, GCG_BRANCHRULE *branchrule, GCG_BRANCHDATA *branchdata, SCIP_CONS **origbranchconss, int norigbranchconss, int maxorigbranchconss)
constraint handler for storing the branching decisions at each node of the tree
constraint handler for storing the branching decisions at each node of the tree
#define SCIP_MAXSTRLEN
#define SCIP_Longint
#define SCIP_INVALID
#define SCIP_Bool
#define SCIP_Real
#define SCIP_CALL_ABORT(x)
#define SCIP_LONGINT_MIN
#define SCIP_LONGINT_MAX
#define SCIP_CALL(x)
#define TRUE
#define FALSE
GCG interface methods.
sorting functions, adapted from SCIP's sorttpl to include userdata
GCG_EXPORT void GCGsortPtr(void **ptrarray, GCG_DECL_SORTPTRCOMP((*ptrcomp)), void *userdata, int len)
SCIP_Bool GCGmasterVarIsArtificial(SCIP_VAR *var)
Definition: gcgvar.c:954
int GCGmasterVarGetNOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:971
SCIP_VAR ** GCGoriginalVarGetMastervars(SCIP_VAR *var)
Definition: gcgvar.c:666
SCIP_Bool GCGisMasterVarInBlock(SCIP_VAR *mastervar, int block)
Definition: gcgvar.c:1169
SCIP_Bool GCGmasterVarIsLinking(SCIP_VAR *var)
Definition: gcgvar.c:913
SCIP_VAR ** GCGmasterVarGetOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:993
SCIP_Bool GCGvarIsMaster(SCIP_VAR *var)
Definition: gcgvar.c:176
SCIP_Real GCGmasterVarGetOrigval(SCIP_VAR *mastervar, SCIP_VAR *origvar)
Definition: gcgvar.c:1034
int GCGoriginalVarGetNMastervars(SCIP_VAR *var)
Definition: gcgvar.c:648
int GCGvarGetBlock(SCIP_VAR *var)
Definition: gcgvar.c:1118
SCIP_RETCODE SCIPincludeBranchruleInference(SCIP *scip)
SCIP_RETCODE SCIPincludeBranchruleRandom(SCIP *scip)
SCIP_RETCODE SCIPincludeBranchruleLeastinf(SCIP *scip)
SCIP_RETCODE SCIPincludeBranchruleFullstrong(SCIP *scip)
SCIP_RETCODE SCIPincludeBranchruleMostinf(SCIP *scip)
SCIP_RETCODE SCIPincludeBranchruleRelpscost(SCIP *scip)
SCIP_RETCODE SCIPincludeBranchrulePscost(SCIP *scip)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, 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)
int GCGmasterGetNPricedvars(GCG *gcg)
SCIP_RETCODE GCGpricerExistRays(GCG *gcg, SCIP_Bool *exist)
SCIP_VAR ** GCGmasterGetPricedvars(GCG *gcg)
GCG_EXPORT SCIP_Bool GCGisMasterSetPartitioning(GCG *gcg)
Definition: relax_gcg.c:4366
GCG_EXPORT SCIP_Bool GCGisMasterSetCovering(GCG *gcg)
Definition: relax_gcg.c:4347
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
GCG_EXPORT int GCGgetNIdenticalBlocks(GCG *gcg, int pricingprobnr)
Definition: relax_gcg.c:4185
SCIP_Bool GCGisMaster(SCIP *scip)
Definition: misc.c:709
GCG_EXPORT int GCGgetNPricingprobs(GCG *gcg)
Definition: relax_gcg.c:4113
GCG_EXPORT int GCGgetBlockRepresentative(GCG *gcg, int pricingprobnr)
Definition: relax_gcg.c:4155
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP_Bool SCIPisStopped(SCIP *scip)
int SCIPgetNContVars(SCIP *scip)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
int SCIPgetNVars(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
SCIP_RETCODE SCIPaddConsNode(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode)
SCIP_Real SCIPgetLocalTransEstimate(SCIP *scip)
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPincludeNodeselDfs(SCIP *scip)
SCIP_RETCODE SCIPincludeNodeselEstimate(SCIP *scip)
SCIP_RETCODE SCIPincludeNodeselRestartdfs(SCIP *scip)
SCIP_RETCODE SCIPincludeNodeselHybridestim(SCIP *scip)
SCIP_RETCODE SCIPincludeNodeselBfs(SCIP *scip)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_RETCODE SCIPsetBranchruleExecExt(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECEXT((*branchexecext)))
SCIP_RETCODE SCIPsetBranchruleExecLp(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECLP((*branchexeclp)))
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
SCIP_RETCODE SCIPsetBranchruleCopy(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHCOPY((*branchcopy)))
SCIP_RETCODE SCIPsetBranchruleExecPs(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECPS((*branchexecps)))
const char * SCIPbranchruleGetName(SCIP_BRANCHRULE *branchrule)
SCIP_BRANCHRULEDATA * SCIPbranchruleGetData(SCIP_BRANCHRULE *branchrule)
SCIP_RETCODE SCIPsetBranchruleFree(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHFREE((*branchfree)))
SCIP_RETCODE SCIPsetBranchruleInit(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHINIT((*branchinit)))
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
SCIP_RETCODE SCIPcreateChild(SCIP *scip, SCIP_NODE **node, SCIP_Real nodeselprio, SCIP_Real estimate)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_RETCODE SCIPincludeEventhdlr(SCIP *scip, const char *name, const char *desc, SCIP_DECL_EVENTCOPY((*eventcopy)), SCIP_DECL_EVENTFREE((*eventfree)), SCIP_DECL_EVENTINIT((*eventinit)), SCIP_DECL_EVENTEXIT((*eventexit)), SCIP_DECL_EVENTINITSOL((*eventinitsol)), SCIP_DECL_EVENTEXITSOL((*eventexitsol)), SCIP_DECL_EVENTDELETE((*eventdelete)), SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
SCIP_VAR * SCIPeventGetVar(SCIP_EVENT *event)
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
#define SCIPfreeBuffer(scip, ptr)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPreallocBufferArray(scip, ptr, num)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPallocBuffer(scip, ptr)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPfreeBlockMemoryNull(scip, ptr)
#define SCIPfreeBufferArrayNull(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
int SCIPsnprintf(char *t, int len, const char *s,...)
#define NULL
INLINE Rational & min(Rational &r1, Rational &r2)
GCG variable pricer.
public methods for interacting with GCG_EXTENDEDMASTERCONSDATA
public methods for GCG variables
#define SCIPerrorMessage
#define SCIPdebugMessage
#define SCIPdebugPrintf
SCIP_RETCODE GCGrelaxIncludeBranchrule(GCG *gcg, SCIP_BRANCHRULE **branchrule, GCG_BRANCHRULE **gcgbranchrule, const char *name, const char *desc, int priority, int maxdepth, SCIP_Real maxbounddist, SCIP_BRANCHRULEDATA *branchruledata, GCG_DECL_BRANCHACTIVEMASTER((*branchactivemaster)), GCG_DECL_BRANCHDEACTIVEMASTER((*branchdeactivemaster)), GCG_DECL_BRANCHPROPMASTER((*branchpropmaster)), GCG_DECL_BRANCHMASTERSOLVED((*branchmastersolved)), GCG_DECL_BRANCHDATADELETE((*branchdatadelete)), GCG_DECL_BRANCHNEWCOL((*branchnewcol)), GCG_DECL_BRANCHGETEXTENDEDMASTERCONS((*branchgetextendedmastercons)), GCG_DECL_BRANCHGETEXTENDEDMASTERCONSCOEFF((*branchgetextendedmasterconscoeff)))
Definition: relax_gcg.c:3717
SCIP_SOL * GCGrelaxGetCurrentOrigSol(GCG *gcg)
Definition: relax_gcg.c:4309
SCIP_Bool GCGrelaxIsOrigSolFeasible(GCG *gcg)
Definition: relax_gcg.c:4328
GCG relaxator.
GCG_COMPSEQUENCE ** C
GCG_COMPSEQUENCE * consS
GCG_EXTENDEDMASTERCONSDATA * mastercons
SCIP_CONS * mastercons
int recordcapacity
int * sequencesizes
int * capacities
GCG_COMPSEQUENCE ** record
SCIP * scip
SCIP_VAR * mastervar
GCG_COMPSEQUENCE ** C
int * sequencesizes
Definition: struct_gcg.h:55
GCG_BRANCHRULE * gcgbranchrule
type definitions for branching rules in GCG projects
#define SCIP_EVENTTYPE_VARADDED
SCIP_DIDNOTRUN
SCIP_CUTOFF
SCIP_DIDNOTFIND
SCIP_BRANCHED
enum SCIP_Result SCIP_RESULT
SCIP_OKAY
SCIP_ERROR
enum SCIP_Retcode SCIP_RETCODE
SCIP_VARTYPE_INTEGER