Scippy

GCG

Branch-and-Price & Column Generation for Everyone

branch_compbnd.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_compbnd.h
30 *
31 * @brief component bound branching rule
32 * @author Til Mohr
33 *
34 * This is an implementation of the component bound branching rule based on the papers:
35 *
36 * F. Vanderbeck.
37 * On Dantzig-Wolfe decomposition in integer programming and ways to perform branching in a branch-and-price algorithm.
38 * Oper. Res. 48(1):111-128 (2000)
39 *
40 * J. Desrosiers, M. L¨ubbecke, G. Desaulniers,
41 * J. B. Gauthier (Juin 2024). Branch-and-Price, Technical report,
42 * Les Cahiers du GERAD G–2024–36, GERAD, HEC Montr´eal, Canada.
43 *
44 * Vanderbeck, François, and Laurence A. Wolsey. "An exact algorithm for IP column generation."
45 * Operations research letters 19.4 (1996): 151-159.
46 */
47
48/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
49
50// will write information about the component bound sequences to a file (slow!)
51//#define COMPBND_STATS
52
53#include "gcg/branch_compbnd.h"
56#include "gcg/gcg.h"
57#include "gcg/pricer_gcg.h"
58#include "gcg/relax_gcg.h"
61#include "gcg/pub_gcgvar.h"
63#include "gcg/type_branchgcg.h"
64#include "scip/cons_linear.h"
65#include "scip/cons_varbound.h"
66
67#define BRANCHRULE_NAME "compbnd" /**< name of branching rule */
68#define BRANCHRULE_DESC "component bound branching" /**< short description of branching rule */
69#define BRANCHRULE_PRIORITY -200 /**< priority of this branching rule */
70#define BRANCHRULE_MAXDEPTH -1 /**< maximal depth level of the branching rule */
71#define BRANCHRULE_MAXBOUNDDIST 1.0 /**< maximal relative distance from current node's
72 dual bound to primal bound compared to best node's
73 dual bound for applying branching */
74
75/*
76 * Data structures
77 */
78
79/** branching rule data */
81{
82 GCG* gcg; /**< GCG data structure */
83 GCG_BRANCHRULE* gcgbranchrule; /**< GCG branchrule structure */
84 SCIP_Bool useMaxRangeMidrangeHeuristic; /** should the MaxRangeMidrangeHeuristic be used */
85 SCIP_Bool useMostDistinctMedianHeuristic; /** should the MostDistinctMedianHeuristic be used */
86#ifdef COMPBND_STATS
87 FILE* statsfile; /**< file to write statistics to */
88#endif
89};
90
91/** branching data */
92struct GCG_BranchData
93{
94 GCG_BRANCH_TYPE branchtype; /**< type of branching, up or down */
95 int constant; /**< constant value of the branching constraint in the master problem - either lhs or rhs, depending on branchtype */
96 GCG_COMPBND* compBndSeq; /**< component bound sequence which induce the current branching constraint */
97 int compBndSeqSize; /**< size of the component bound sequence compBndSeq */
98 int blocknr; /**< id of the pricing problem (or block) to which this branching constraint belongs */
99 int nvars; /**< number of master variables the last time the node has been visited - neccessary to later include newly generated master variables */
100 GCG_EXTENDEDMASTERCONSDATA* mastercons; /**< master constraint along with its corresponding inferred pricing modifications */
101};
102
103
104
105/** define the signature of functions to choose the component bound */
106#define CHOOSE_COMPBND(x) SCIP_RETCODE x (GCG* gcg, SCIP_VAR** satisfyingMastervars, int satisfyingMastervarsSize, SCIP_VAR** indexSet, int indexSetSize, GCG_COMPBND* compBndSeq, int compBndSeqSize, int blocknr, SCIP_VAR** selectedOrigvar, SCIP_Real* value)
107
108/** define the signature of functions that chose one component bound sequence out of many */
109#define CHOOSE_COMPBNDSEQ(x) SCIP_RETCODE x (GCG* gcg, GCG_COMPBND** compBndSeqList, int* compBndSeqSizeList, int compBndListSize, int blocknr, GCG_COMPBND** selectedCompBndSeq, int* selectedCompBndSeqSize)
110
111/*
112 * Local methods
113 */
114
115/* floor and ceil returning int */
116#define FLOOR(scip, x) (SCIPconvertRealToInt((scip), SCIPfloor((scip), (x))))
117#define CEIL(scip, x) (SCIPconvertRealToInt((scip), SCIPceil((scip), (x))))
118
119/** set components of componentbound sequence to NULL */
120static
122 SCIP* scip, /**< SCIP data structure */
123 GCG_COMPBND** compBndSeq, /**< component bound sequence to set to NULL */
124 int* compBndSeqSize /**< size of the component bound sequence compBndSeq */
125 )
126{
127 assert(scip != NULL);
128 assert(GCGisMaster(scip));
129
130 SCIPfreeBlockMemoryArrayNull(scip, compBndSeq, *compBndSeqSize);
131 assert(*compBndSeq == NULL);
132 *compBndSeqSize = 0;
133}
134
135/** initialize branchdata at the node */
136static
138 SCIP* scip, /**< SCIP data structure */
139 GCG_BRANCHDATA** nodebranchdata, /**< branching data to set */
140 GCG_BRANCH_TYPE branchtype, /**< type of branch to generate */
141 int constant, /**< constant value of the branching constraint in the master problem - either lhs or rhs, depending on branchtype */
142 GCG_COMPBND* compBndSeq, /**< component bound sequence which induce the current branching constraint */
143 int compBndSeqSize, /**< size of the component bound sequence compBndSeq */
144 int blocknr /**< block we are branching in */
145 )
146{
147 assert(GCGisMaster(scip));
148
149 SCIP_CALL( SCIPallocBlockMemory(scip, nodebranchdata) );
150
151 (*nodebranchdata)->branchtype = branchtype;
152 (*nodebranchdata)->blocknr = blocknr;
153 (*nodebranchdata)->constant = constant;
154 (*nodebranchdata)->compBndSeqSize = compBndSeqSize;
155 (*nodebranchdata)->nvars = 0;
156 (*nodebranchdata)->mastercons = NULL;
157
158 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &((*nodebranchdata)->compBndSeq), compBndSeq, compBndSeqSize));
159
160 return SCIP_OKAY;
161}
162
163/** simplify a component bound sequence by strengthening bounds of the same sense on the same component */
164static
166 SCIP* scip, /**< SCIP data structure */
167 GCG_COMPBND** compBndSeq, /**< Component Bound Sequence defining the nodes */
168 int* compBndSeqSize /**< size of compBndSeq */
169 )
170{
171 GCG_COMPBND* newCompBndSeq;
172 int newCompBndSeqSize;
173 SCIP_Bool* alreadyAdded;
174 int i;
175 int j;
176
177 assert(GCGisMaster(scip));
178
179 newCompBndSeq = NULL;
180 newCompBndSeqSize = 0;
181 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &alreadyAdded, *compBndSeqSize) );
182 for( i = 0; i < *compBndSeqSize; ++i )
183 {
184 alreadyAdded[i] = FALSE;
185 }
186
187
188 for( i=0; i<*compBndSeqSize; ++i )
189 {
190 if( alreadyAdded[i] )
191 continue;
192
193 SCIP_VAR* component = (*compBndSeq)[i].component;
194 GCG_COMPBND_SENSE sense = (*compBndSeq)[i].sense;
195 SCIP_Real bound = (*compBndSeq)[i].bound;
196
197 for( j=i+1; j<*compBndSeqSize; ++j )
198 {
199 if( component != (*compBndSeq)[j].component )
200 continue;
201 if( (*compBndSeq)[i].sense != (*compBndSeq)[j].sense )
202 continue;
203
204 alreadyAdded[j] = TRUE;
205
206 if( (*compBndSeq)[i].sense == GCG_COMPBND_SENSE_LE )
207 {
208 bound = MIN((*compBndSeq)[j].bound, bound);
209 }
210 else if( (*compBndSeq)[i].sense == GCG_COMPBND_SENSE_GE )
211 {
212 bound = MAX((*compBndSeq)[j].bound, bound);
213 }
214 }
215
216 alreadyAdded[i] = TRUE;
217
218 if( newCompBndSeqSize == 0 )
219 {
220 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &newCompBndSeq, 1) );
221 }
222 else
223 {
224 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &newCompBndSeq, newCompBndSeqSize, newCompBndSeqSize+1) );
225 }
226
227 newCompBndSeq[newCompBndSeqSize].component = component;
228 newCompBndSeq[newCompBndSeqSize].sense = sense;
229 newCompBndSeq[newCompBndSeqSize].bound = bound;
230 newCompBndSeqSize += 1;
231 }
232
233 assert(1 <= newCompBndSeqSize && newCompBndSeqSize <= *compBndSeqSize);
234 SCIPdebugMessage("Simplified compBndSeq from %d to %d\n", *compBndSeqSize, newCompBndSeqSize);
235 for (i = 0; i < newCompBndSeqSize; ++i)
236 {
237 SCIPdebugMessage("compBndSeq[%d]: %s %s %d\n", i, SCIPvarGetName(newCompBndSeq[i].component),
238 newCompBndSeq[i].sense == GCG_COMPBND_SENSE_LE ? "<=" : ">=",
239 newCompBndSeq[i].bound);
240 }
241
242 SCIPfreeBlockMemoryArray(scip, &alreadyAdded, *compBndSeqSize);
243 assert(alreadyAdded == NULL);
244
245 // free old compBndSeq and replace it with newB
246 freeComponentBoundSequence(scip, compBndSeq, compBndSeqSize);
247 assert(*compBndSeq == NULL);
248 *compBndSeq = newCompBndSeq;
249 *compBndSeqSize = newCompBndSeqSize;
250
251 return SCIP_OKAY;
252}
253
254/** computes the generator of mastervar for the entry in origvar
255 * @return entry of the generator corresponding to origvar */
256static
258 SCIP_VAR** solvars, /**< column solution variables */
259 SCIP_Real* solvals, /**< column solution values */
260 int nsolvars, /**< number of column solution variables */
261 SCIP_VAR* origvar /**< corresponding origvar */
262 )
263{
264 int i;
265 SCIP_VAR* pricingvar;
266 SCIP_VAR* cmp;
267
268 assert(origvar != NULL);
269 assert(GCGvarIsOriginal(origvar));
270
271 pricingvar = GCGoriginalVarGetPricingVar(origvar);
272
273 for( i = 0; i < nsolvars; ++i )
274 {
275 if( GCGvarIsOriginal(solvars[i]) )
276 cmp = origvar;
277 else
278 cmp = pricingvar;
279
280 if( solvars[i] == cmp )
281 {
282 return solvals[i];
283 }
284 }
285
286 return 0.0;
287}
288
289/** computes the generator of mastervar for the entry in origvar
290 * @return entry of the generator corresponding to origvar */
291static
293 SCIP_VAR* mastervar, /**< current mastervariable */
294 SCIP_VAR* origvar /**< corresponding origvar */
295 )
296{
297 SCIP_Real entry = GCGmasterVarGetOrigval(mastervar, origvar);
298
299 return entry != SCIP_INVALID ? entry : 0.;
300}
301
302/** whether a master variable is in the component bound sequence or not */
303static
305 SCIP* scip, /**< SCIP data structure */
306 SCIP_VAR** solvars, /**< column solution variables */
307 SCIP_Real* solvals, /**< column solution values */
308 int nsolvars, /**< number of column solution variables */
309 GCG_COMPBND* compBndSeq, /**< component bound sequence to check */
310 int compBndSeqSize /**< size of compBndSeq */
311 )
312{
313 int i;
314 SCIP_Real generatorentry;
315
316 assert(compBndSeqSize > 0);
317 assert(compBndSeq != NULL);
318
319 for( i = 0; i < compBndSeqSize; ++i )
320 {
321 generatorentry = getGeneratorEntryCol(solvars, solvals, nsolvars, compBndSeq[i].component);
322 if ( (compBndSeq[i].sense == GCG_COMPBND_SENSE_GE && !SCIPisGE(scip, generatorentry, compBndSeq[i].bound)) ||
323 (compBndSeq[i].sense == GCG_COMPBND_SENSE_LE && !SCIPisLE(scip, generatorentry, compBndSeq[i].bound)) )
324 {
325 return FALSE;
326 }
327 }
328
329 return TRUE;
330}
331
332/** whether a master variable is in compBndSeq or not */
333static
335 SCIP* scip, /**< SCIP data structure */
336 SCIP_VAR* mastervar, /**< master variable to check */
337 GCG_COMPBND* compBndSeq, /**< component bound sequence to check */
338 int compBndSeqSize, /**< size of compBndSeq */
339 int blocknr /**< block we are branching in */
340 )
341{
342 int i;
343 SCIP_Real generatorentry;
344
345 assert(mastervar != NULL);
346 assert(compBndSeqSize > 0);
347 assert(compBndSeq != NULL);
348
349 if( !GCGisMasterVarInBlock(mastervar, blocknr) )
350 return FALSE;
351
352 for( i = 0; i < compBndSeqSize; ++i )
353 {
354 generatorentry = getGeneratorEntry(mastervar, compBndSeq[i].component);
355 if ( (compBndSeq[i].sense == GCG_COMPBND_SENSE_GE && !SCIPisGE(scip, generatorentry, compBndSeq[i].bound)) ||
356 (compBndSeq[i].sense == GCG_COMPBND_SENSE_LE && !SCIPisLE(scip, generatorentry, compBndSeq[i].bound)) )
357 {
358 return FALSE;
359 }
360 }
361
362 return TRUE;
363}
364
365/** adds a variable to a branching constraint */
366static
368 GCG* gcg, /**< GCG data structure */
369 SCIP_VAR* mastervar, /**< the variable to add */
370 GCG_BRANCHDATA* branchdata /**< branching data structure where the variable should be added */
371 )
372{
373 SCIP_Real coef;
374 SCIP_VAR** origvars;
375 SCIP_Real* origvals;
376 int norigvars;
377 SCIP* masterprob = GCGgetMasterprob(gcg);
378
379 assert(masterprob != NULL);
380 assert(mastervar != NULL);
381 assert(branchdata != NULL);
382
383 origvars = GCGmasterVarGetOrigvars(mastervar);
384 norigvars = GCGmasterVarGetNOrigvars(mastervar);
385 origvals = GCGmasterVarGetOrigvals(mastervar);
386
387 SCIP_CALL( GCGbranchGetExtendedmasterconsCoeff(gcg, branchdata->mastercons, origvars, origvals, norigvars, GCGvarGetBlock(mastervar), NULL, &coef) );
388
389 if( !SCIPisZero(masterprob, coef) )
390 {
391 SCIPdebugMessage("Adding variable %s to branching constraint: %s %d\n", SCIPvarGetName(mastervar), branchdata->branchtype == GCG_BRANCH_DOWN ? "<=" : ">=", branchdata->constant);
392 SCIP_CALL( GCGextendedmasterconsAddMasterVar(gcg, branchdata->mastercons, mastervar, coef) );
393 }
394
395 return SCIP_OKAY;
396}
397
398/** callback new column method */
399static
400GCG_DECL_BRANCHGETEXTENDEDMASTERCONSCOEFF(branchGetExtendedmasterconsCoeffCompBnd)
401{
402 SCIP* masterprob;
403
404 masterprob = GCGgetMasterprob(gcg);
405
406 assert(masterprob != NULL);
407 assert(GCGisMaster(masterprob));
408
409 assert(branchdata != NULL);
410 assert(branchdata->mastercons == extendedmasterconsdata);
411
412 *coef = 0.0;
413
414 if( probnr == -1 || probnr != branchdata->blocknr )
415 return SCIP_OKAY;
416
417 if( !isColInCompBndSeq(masterprob, solvars, solvals, nsolvars, branchdata->compBndSeq, branchdata->compBndSeqSize) )
418 return SCIP_OKAY;
419
420 *coef = 1.0;
421
422 return SCIP_OKAY;
423}
424
425/** creates the constraint for branching directly on a master variable */
426static
428 GCG* gcg, /**< GCG data structure */
429 GCG_BRANCHRULE* branchrule, /**< branch rule structure */
430 SCIP_NODE* node, /**< node to add constraint */
431 GCG_BRANCHDATA* branchdata /**< branching data structure */
432 )
433{
434 SCIP_Longint uuid;
435
436 SCIP* pricingscip;
437 SCIP* masterprob;
438 SCIP_BRANCHRULEDATA* branchruledata;
439
440 SCIP_VAR** mastervars;
441 int nmastervars;
442 int i;
443
444 SCIP_CONS* branchcons;
445
446 SCIP_VAR* coefvar;
447 SCIP_VAR** additionalvars;
448 int nadditionalvars;
449 SCIP_CONS** additionalcons;
450 int nadditionalcons;
451 GCG_PRICINGMODIFICATION** pricingmods; // will always only contain one element in this branching rule
452
453 char name[SCIP_MAXSTRLEN];
454
455 masterprob = GCGgetMasterprob(gcg);
456
457 assert(masterprob != NULL);
458 assert(GCGisMaster(masterprob));
459 assert(node != NULL);
460 assert(branchdata != NULL);
461 assert(branchdata->mastercons == NULL);
462
463 branchruledata = GCGbranchGetScipBranchruledata(branchrule);
464 assert(branchruledata != NULL);
465
466 uuid = SCIPnodeGetNumber(node);
467
468 mastervars = SCIPgetVars(masterprob);
469 nmastervars = SCIPgetNVars(masterprob);
470 assert(nmastervars >= 0);
471 assert(nmastervars == 0 || mastervars != NULL);
472
473 /* create constraint for child */
474 if (branchdata->branchtype == GCG_BRANCH_DOWN)
475 {
476 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "compbnd_%d_child(%d_LE_%d)", uuid, branchdata->compBndSeqSize, branchdata->constant);
477 SCIP_CALL( SCIPcreateConsLinear(masterprob, &branchcons, name, 0, NULL, NULL,
478 -SCIPinfinity(masterprob), (SCIP_Real) branchdata->constant, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
479 }
480 else
481 {
482 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "compbnd_%d_child(%d_GE_%d)", uuid, branchdata->compBndSeqSize, branchdata->constant);
483 SCIP_CALL( SCIPcreateConsLinear(masterprob, &branchcons, name, 0, NULL, NULL,
484 (SCIP_Real) branchdata->constant, SCIPinfinity(masterprob), TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
485 }
486
487 SCIP_CALL( SCIPaddConsNode(masterprob, node, branchcons, NULL) );
488
489 pricingscip = GCGgetPricingprob(gcg, branchdata->blocknr);
490 assert(pricingscip != NULL);
491
492 assert(branchdata->mastercons == NULL);
493
494 if( branchdata->branchtype == GCG_BRANCH_DOWN )
495 {
496 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "compbnd_%d_down", uuid);
497 }
498 else
499 {
500 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "compbnd_%d_up", uuid);
501 }
502
503 char pricingvarname[SCIP_MAXSTRLEN];
504 (void) SCIPsnprintf(pricingvarname, SCIP_MAXSTRLEN, "g(%s)", name);
505
506 // create the g_x variable
507 SCIP_CALL( GCGcreateInferredPricingVar(pricingscip, &coefvar, pricingvarname, 0.0, 1.0, TRUE, 0.0, SCIP_VARTYPE_BINARY, branchdata->blocknr) );
508
509 // create the y_j variables
510
511 /* @todo: when the pricing problem only contains binary variables, simplifications apply:
512 * we may not even need extra y_j variables to enforce the correct value of the y variable
513 */
514
515 nadditionalvars = branchdata->compBndSeqSize;
516 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &additionalvars, nadditionalvars) );
517 for (i = 0; i < branchdata->compBndSeqSize; ++i)
518 {
519 (void) SCIPsnprintf(pricingvarname, SCIP_MAXSTRLEN, "y(%s,%s_%s_%d)", name, SCIPvarGetName(branchdata->compBndSeq[i].component), branchdata->compBndSeq[i].sense == GCG_COMPBND_SENSE_GE ? "GE" : "LE", branchdata->compBndSeq[i].bound);
520 SCIP_CALL( GCGcreateInferredPricingVar(pricingscip, &additionalvars[i], pricingvarname, 0.0, 1.0, FALSE, 0.0, SCIP_VARTYPE_BINARY, branchdata->blocknr) );
521 }
522
523 // create the pricing constraints
524 if( branchdata->branchtype == GCG_BRANCH_DOWN )
525 {
526 nadditionalcons = branchdata->compBndSeqSize + 1;
527 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &additionalcons, nadditionalcons) );
528
529 /* g_x >= 1 + sum_{j=1}^{n} y_j - n
530 * 1 - n <= g_x - sum_{j=1}^{n} y_j */
531 char consname[SCIP_MAXSTRLEN];
532 (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "c(g(%s))", name);
533 SCIP_CALL( SCIPcreateConsLinear(pricingscip, &additionalcons[0], consname, 0, NULL, NULL, (SCIP_Real) (1 - branchdata->compBndSeqSize), SCIPinfinity(pricingscip),
535 SCIP_CALL( SCIPaddCoefLinear(pricingscip, additionalcons[0], coefvar, 1.0) );
536 for( i = 0; i < branchdata->compBndSeqSize; ++i)
537 {
538 SCIP_CALL( SCIPaddCoefLinear(pricingscip, additionalcons[0], additionalvars[i], -1.0) );
539 }
540
541 for( i = 0; i < branchdata->compBndSeqSize; ++i)
542 {
543 (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "c(y(%s,%s_%s_%d))", name, SCIPvarGetName(branchdata->compBndSeq[i].component), branchdata->compBndSeq[i].sense == GCG_COMPBND_SENSE_GE ? "GE" : "LE", branchdata->compBndSeq[i].bound);
544
545 if( branchdata->compBndSeq[i].sense == GCG_COMPBND_SENSE_LE )
546 {
547 /* y_j >= ((bound + 1) - x_j) / ((bound + 1) - l_j)
548 * ((bound + 1) - l_j) * y_j >= (bound + 1) - x_j
549 * (bound + 1) <= x_j + ((bound + 1) - l_j) * y_j */
550 SCIP_VAR* pricing_var = GCGoriginalVarGetPricingVar(branchdata->compBndSeq[i].component);
551 SCIP_Real bound = (SCIP_Real) (branchdata->compBndSeq[i].bound + 1);
552 SCIP_Real lowerbound = SCIPvarGetLbGlobal(branchdata->compBndSeq[i].component);
553 assert(SCIPisPositive(pricingscip, bound - lowerbound));
554 SCIP_CALL( SCIPcreateConsVarbound(pricingscip, &additionalcons[i+1], consname, pricing_var, additionalvars[i], bound - lowerbound, bound, SCIPinfinity(pricingscip),
556 }
557 else
558 {
559 /* y_j >= (x_j - (bound - 1)) / (u_j - (bound - 1))
560 * (u_j - (bound - 1)) * y_j >= x_j - (bound - 1)
561 * -(bound - 1) <= (u_j - (bound - 1)) * y_j - x_j
562 * x_j + ((bound - 1) - u_j) * y_j <= (bound - 1) */
563 SCIP_VAR* pricing_var = GCGoriginalVarGetPricingVar(branchdata->compBndSeq[i].component);
564 SCIP_Real bound = (SCIP_Real) (branchdata->compBndSeq[i].bound - 1);
565 SCIP_Real upperbound = SCIPvarGetUbGlobal(branchdata->compBndSeq[i].component);
566 assert(SCIPisPositive(pricingscip, upperbound - bound));
567 SCIP_CALL( SCIPcreateConsVarbound(pricingscip, &additionalcons[i+1], consname, pricing_var, additionalvars[i], bound - upperbound, -SCIPinfinity(pricingscip), bound,
569 }
570 }
571 }
572 else
573 {
574 nadditionalcons = branchdata->compBndSeqSize * 2;
575 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &additionalcons, nadditionalcons) );
576
577 /* g_x <= y_j
578 * 0 <= y_j - g_y*/
579 char consname[SCIP_MAXSTRLEN];
580 for( i = 0; i < branchdata->compBndSeqSize; ++i )
581 {
582 (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "c(g(%s,%s))", name, SCIPvarGetName(additionalvars[i]));
583 SCIP_CALL( SCIPcreateConsVarbound(pricingscip, &additionalcons[i], consname, additionalvars[i], coefvar, -1.0, 0.0, SCIPinfinity(pricingscip),
585 }
586
587 for( i = 0; i < branchdata->compBndSeqSize; ++i )
588 {
589 (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "c1(y(%s,%s_%s_%d))", name, SCIPvarGetName(branchdata->compBndSeq[i].component), branchdata->compBndSeq[i].sense == GCG_COMPBND_SENSE_GE ? "GE" : "LE", branchdata->compBndSeq[i].bound);
590
591 if( branchdata->compBndSeq[i].sense == GCG_COMPBND_SENSE_LE )
592 {
593 /* y_j <= (u_j - x_j) / (u_j - bound)
594 * (u_j - bound) * y_j <= u_j - x_j
595 * x_j + (u_j - bound) * y_j <= u_j */
596 SCIP_VAR* pricing_var = GCGoriginalVarGetPricingVar(branchdata->compBndSeq[i].component);
597 SCIP_Real bound = (SCIP_Real) branchdata->compBndSeq[i].bound;
598 SCIP_Real upperbound = SCIPvarGetUbGlobal(branchdata->compBndSeq[i].component);
599 assert(SCIPisPositive(pricingscip, upperbound - bound));
600 SCIP_CALL( SCIPcreateConsVarbound(pricingscip, &additionalcons[i+branchdata->compBndSeqSize], consname, pricing_var, additionalvars[i], upperbound - bound, -SCIPinfinity(pricingscip), upperbound,
602 }
603 else
604 {
605 /* y_j <= (x_j - l_j) / (bound - l_j)
606 * (bound - l_j) * y_j <= x_j - l_j
607 * (bound - l_j) * y_j - x_j <= -l_j
608 * l_j <= x_j + (l_j - bound) * y_j */
609 SCIP_VAR* pricing_var = GCGoriginalVarGetPricingVar(branchdata->compBndSeq[i].component);
610 SCIP_Real bound = (SCIP_Real) branchdata->compBndSeq[i].bound;
611 SCIP_Real lowerbound = SCIPvarGetLbGlobal(branchdata->compBndSeq[i].component);
612 assert(SCIPisPositive(pricingscip, bound - lowerbound));
613 SCIP_CALL( SCIPcreateConsVarbound(pricingscip, &additionalcons[i+branchdata->compBndSeqSize], consname, pricing_var, additionalvars[i], lowerbound - bound, lowerbound, SCIPinfinity(pricingscip),
615 }
616 }
617 }
618
619 // create the pricing modification
620 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &pricingmods, 1) );
621 assert(pricingmods != NULL);
623 gcg,
624 &(pricingmods[0]),
625 branchdata->blocknr,
626 coefvar,
627 additionalvars,
628 nadditionalvars,
629 additionalcons,
630 nadditionalcons
631 ) );
632
633 // create the master constraint
634 SCIP_CALL( GCGbranchCreateExtendedmastercons(gcg, branchruledata->gcgbranchrule, &branchdata->mastercons, branchcons, pricingmods, 1, branchdata) );
635
636 // add the variables to the constraint
637 for( i = 0; i < nmastervars; i++ )
638 {
639 SCIP_CALL( addVarToMasterbranch(gcg, mastervars[i], branchdata) );
640 }
641
642 return SCIP_OKAY;
643}
644
645/** for given component bound sequence create the 2 child nodes */
646static
648 GCG* gcg, /**< GCG data structure */
649 GCG_BRANCHRULE* branchrule, /**< branching rule */
650 GCG_COMPBND* compBndSeq, /**< Component Bound Sequence defining the nodes */
651 int compBndSeqSize, /**< size of compBndSeq */
652 int blocknr /**< number of the block */
653 )
654{
655 SCIP* origprob;
656 SCIP* masterprob;
657 int i;
658 SCIP_Real constantSum;
659 int nmastervars;
660 SCIP_VAR** mastervars;
661 GCG_BRANCHDATA* downBranchData;
662 GCG_BRANCHDATA* upBranchData;
663 char downChildname[SCIP_MAXSTRLEN];
664 char upChildname[SCIP_MAXSTRLEN];
665 SCIP_NODE* downChild;
666 SCIP_CONS* downChildcons;
667 SCIP_NODE* upChild;
668 SCIP_CONS* upChildcons;
669
670 assert(gcg != NULL);
671 assert(compBndSeqSize > 0);
672 assert(compBndSeq != NULL);
673
674 origprob = GCGgetOrigprob(gcg);
675 masterprob = GCGgetMasterprob(gcg);
676
677 SCIPdebugMessage("Component bound branching rule Node creation for blocknr %d with %d identical blocks \n", blocknr, GCGgetNIdenticalBlocks(gcg, blocknr));
678
679 /* get variable data of the master problem */
680 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
681 assert(nmastervars >= 0);
682 /* determine the constant value of the master constraint, i.e. the rhs for the down branch, and lhs for the up branch */
683 constantSum = 0.0;
684 for( i = 0; i < nmastervars; ++i )
685 {
686 if(
688 mastervars[i],
690 )
691 && isMasterVarInCompBndSeq(origprob, mastervars[i], compBndSeq, compBndSeqSize, blocknr)
692 )
693 {
694 constantSum += SCIPgetSolVal(masterprob, NULL, mastervars[i]);
695 }
696 }
697 // sanity check: the sum must be fractional, otherwise something went wrong during separation, i.e. compBndSeq is incorrect
698 assert(!SCIPisFeasIntegral(origprob, constantSum));
699
700 /* create two nodes */
701 SCIPdebugMessage("Component bound branching rule: creating 2 nodes\n");
702 SCIP_CALL( initNodeBranchdata(masterprob, &downBranchData, GCG_BRANCH_DOWN, FLOOR(origprob, constantSum), compBndSeq, compBndSeqSize, blocknr) );
703 SCIP_CALL( initNodeBranchdata(masterprob, &upBranchData, GCG_BRANCH_UP, CEIL(origprob, constantSum), compBndSeq, compBndSeqSize, blocknr) );
704 freeComponentBoundSequence(masterprob, &compBndSeq, &compBndSeqSize);
705 assert(downBranchData != NULL);
706 assert(upBranchData != NULL);
707 assert(compBndSeq == NULL);
708 assert(compBndSeqSize == 0);
709
710 /* define names for origbranch constraints */
711 (void) SCIPsnprintf(downChildname, SCIP_MAXSTRLEN, "node(%d) (last comp=%s %s %d) <= %d", blocknr,
712 SCIPvarGetName(downBranchData->compBndSeq[downBranchData->compBndSeqSize-1].component),
713 downBranchData->compBndSeq[downBranchData->compBndSeqSize-1].sense == GCG_COMPBND_SENSE_GE ? ">=": "<=",
714 downBranchData->compBndSeq[downBranchData->compBndSeqSize-1].bound,
715 downBranchData->constant);
716 (void) SCIPsnprintf(upChildname, SCIP_MAXSTRLEN, "node(%d) (last comp=%s %s %d) >= %d", blocknr,
717 SCIPvarGetName(upBranchData->compBndSeq[upBranchData->compBndSeqSize-1].component),
718 upBranchData->compBndSeq[upBranchData->compBndSeqSize-1].sense == GCG_COMPBND_SENSE_GE ? ">=": "<=",
719 upBranchData->compBndSeq[upBranchData->compBndSeqSize-1].bound,
720 upBranchData->constant);
721
722 /* add the nodes to the tree */
723 SCIP_CALL( SCIPcreateChild(masterprob, &downChild, 0.0, SCIPgetLocalTransEstimate(masterprob)) );
724 SCIP_CALL( GCGcreateConsMasterbranch(gcg, &downChildcons, downChildname, downChild,
725 GCGconsMasterbranchGetActiveCons(gcg), branchrule, downBranchData, NULL, 0, 0) );
726 SCIP_CALL( SCIPaddConsNode(masterprob, downChild, downChildcons, NULL) );
727 SCIP_CALL( createBranchingCons(gcg, branchrule, downChild, downBranchData) );
728
729 SCIP_CALL( SCIPcreateChild(masterprob, &upChild, 0.0, SCIPgetLocalTransEstimate(masterprob)) );
730 SCIP_CALL( GCGcreateConsMasterbranch(gcg, &upChildcons, upChildname, upChild,
731 GCGconsMasterbranchGetActiveCons(gcg), branchrule, upBranchData, NULL, 0, 0) );
732 SCIP_CALL( SCIPaddConsNode(masterprob, upChild, upChildcons, NULL) );
733 SCIP_CALL( createBranchingCons(gcg, branchrule, upChild, upBranchData) );
734
735 /* release constraints */
736 SCIP_CALL( SCIPreleaseCons(masterprob, &upChildcons) );
737 SCIP_CALL( SCIPreleaseCons(masterprob, &downChildcons) );
738
739 return SCIP_OKAY;
740}
741
742/** determine fractionality of a set of mastervariables */
743static
745 SCIP* masterscip, /**< SCIP data structure */
746 SCIP_VAR** mastervars, /**< mastervariables */
747 int nmastervars /**< number of mastervariables */
748 )
749{
750 int i;
751 SCIP_Real fractionality;
752
753 assert(masterscip != NULL);
754 assert(GCGisMaster(masterscip));
755
756 assert((mastervars != NULL) || (nmastervars == 0));
757
758 if( nmastervars == 0 )
759 return 0.0;
760
761 fractionality = 0.0;
762
763 for( i = 0; i < nmastervars; ++i )
764 {
765 SCIP_Real solval = SCIPgetSolVal(masterscip, NULL, mastervars[i]);
766 fractionality += SCIPfrac(masterscip, solval);
767 }
768
769 return fractionality;
770}
771
772/** method for initializing the indexSet for a given set of master variables
773 *
774 * the index set denotes the set of all integral original variables contained in the provided master variables
775 */
776static
778 SCIP* scip, /**< SCIP data structure */
779 SCIP_VAR*** indexSet, /**< set to initialize */
780 int* indexSetSize, /**< size of the index set */
781 SCIP_VAR** mastervars, /**< mastervariables currently satisfying the component bound sequence in the specified block */
782 int mastervarsSize /**< size of mastervars */
783 )
784{
785 int i;
786 int j;
787 SCIP_VAR** origvars;
788 int norigvars;
789
790 assert( scip != NULL);
791 assert(GCGisMaster(scip));
792 assert( indexSet != NULL);
793 assert( indexSetSize != NULL);
794
795 *indexSet = NULL;
796 *indexSetSize = 0;
797
798 for( i = 0; i < mastervarsSize; ++i )
799 {
800 origvars = GCGmasterVarGetOrigvars(mastervars[i]);
801 norigvars = GCGmasterVarGetNOrigvars(mastervars[i]);
802
803 if( *indexSetSize == 0 && norigvars > 0 )
804 {
805 for( j = 0; j < norigvars; ++j )
806 {
807 if( SCIPvarGetType(origvars[j]) > SCIP_VARTYPE_INTEGER )
808 continue;
809
810 if( *indexSetSize == 0 )
811 {
813 }
814 else
815 {
816 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, indexSet, *indexSetSize, *indexSetSize + 1) );
817 }
818
819 (*indexSet)[*indexSetSize] = origvars[j];
820 *indexSetSize += 1;
821 }
822 }
823 else
824 {
825 for( j = 0; j < norigvars; ++j )
826 {
827 int k;
828 int oldsize = *indexSetSize;
829
830 if( SCIPvarGetType(origvars[j]) > SCIP_VARTYPE_INTEGER )
831 continue;
832
833 for( k = 0; k < oldsize; ++k )
834 {
835 /* if variable already in set */
836 if( (*indexSet)[k] == origvars[j] )
837 break;
838
839 if( k == oldsize-1 )
840 {
841 /* add variable to the end */
842 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, indexSet, *indexSetSize, *indexSetSize + 1) );
843 (*indexSet)[*indexSetSize] = origvars[j];
844 *indexSetSize += 1;
845 }
846 }
847 }
848 }
849 }
850
851 assert(*indexSetSize > 0 && *indexSet != NULL);
852
853 return SCIP_OKAY;
854}
855
856#ifndef NDEBUG
857/** get the lower bound of a original variable from the component bound sequence, or the lb */
858static
860 SCIP* scip, /**< SCIP data structure */
861 SCIP_VAR* origvar, /**< original variable */
862 GCG_COMPBND* compBndSeq, /**< component bound sequence */
863 int compBndSeqSize /**< size of compBndSeq */
864 )
865{
866 int i;
867 SCIP_Real lb;
868
869 assert(scip != NULL);
870 assert(origvar != NULL);
871
872 lb = SCIPvarGetLbGlobal(origvar);
873
874 for( i = 0; i < compBndSeqSize; ++i )
875 {
876 if(
877 compBndSeq[i].sense == GCG_COMPBND_SENSE_GE
878 && origvar == compBndSeq[i].component
879 && SCIPisLT(scip, lb, compBndSeq[i].bound)
880 )
881 {
882 lb = (SCIP_Real) compBndSeq[i].bound;
883 }
884 }
885
886 return lb;
887}
888
889/** get the upper bound of a original variable from the component bound sequence, or the ub */
890static
892 SCIP* scip, /**< SCIP data structure */
893 SCIP_VAR* origvar, /**< original variable */
894 GCG_COMPBND* compBndSeq, /**< component bound sequence */
895 int compBndSeqSize /**< size of compBndSeq */
896 )
897{
898 int i;
899 SCIP_Real ub;
900
901 assert(scip != NULL);
902 assert(origvar != NULL);
903
904 ub = SCIPvarGetUbGlobal(origvar);
905
906 for( i = 0; i < compBndSeqSize; ++i )
907 {
908 if(
909 compBndSeq[i].sense == GCG_COMPBND_SENSE_LE
910 && origvar == compBndSeq[i].component
911 && SCIPisLT(scip, compBndSeq[i].bound, ub)
912 )
913 {
914 ub = (SCIP_Real) compBndSeq[i].bound;
915 }
916 }
917
918 return ub;
919}
920#endif
921
922/** separation algorithm determining multiple component bound sequences one could branch on */
923static
925 GCG* gcg, /**< GCG data structure */
926 SCIP_VAR** satisfyingMastervars, /**< mastervariables currently satisfying the component bound sequence in the specified block */
927 int satisfyingMastervarsSize,/**< size of mastervars */
928 GCG_COMPBND* compBndSeq, /**< current Component Bound Sequence defining the nodes */
929 int compBndSeqSize, /**< size of compBndSeq */
930 int blocknr, /**< number of the block */
931 CHOOSE_COMPBND((*chooseCompBnd)), /**< method for choosing the variable to branch on */
932 GCG_COMPBND*** foundCompBndSeqList, /**< list of component bound sequences */
933 int** foundCompBndSeqSizeList, /**< sizes of the component bound sequences */
934 int* foundCompBndSeqListSize, /**< size of Blist */
935 SCIP_RESULT* result /**< pointer to store the result of the branching call */
936 )
937{
938 SCIP_Real fractionality;
939 int i;
940 SCIP* masterprob;
941
942 masterprob = GCGgetMasterprob(gcg);
943
944 assert(masterprob != NULL);
945 assert(GCGisMaster(masterprob));
946
947 // Sanity check: All variables in satisfyingMastervars must satisfy the component bound sequence
948 if( compBndSeqSize > 0 ) {
949 for( i = 0; i < satisfyingMastervarsSize; ++i )
950 {
951 assert(isMasterVarInCompBndSeq(masterprob, satisfyingMastervars[i], compBndSeq, compBndSeqSize, blocknr));
952 }
953 }
954
955 fractionality = calcFractionality(masterprob, satisfyingMastervars, satisfyingMastervarsSize);
956 assert(fractionality >= 0.0);
957
958 if( SCIPisEQ(masterprob, fractionality, 0.0) ) // should never happen - the branching scheme is sound and complete
959 {
960 // all variables are integral, nothing to do
961 SCIPdebugMessage("All variables are integral, nothing to do\n");
962
963 *result = SCIP_DIDNOTFIND;
964
965 return SCIP_ERROR;
966 }
967
968 if( compBndSeqSize > 0 && !SCIPisFeasIntegral(masterprob, fractionality) )
969 {
970 /* now we branch on <= floor(fractionality) and >= ceil(fractionality)
971 * this is handled by the createChildNodesCompBnd method
972 */
973 SCIPdebugMessage("fractionality is fractional, we need to branch\n");
974
975 *result = SCIP_BRANCHED;
976
977 // add current compBndSeq to Blist
978 if( *foundCompBndSeqListSize == 0 )
979 {
980 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, foundCompBndSeqList, 1) );
981 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, foundCompBndSeqSizeList, 1) );
982 }
983 else
984 {
985 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, foundCompBndSeqList, *foundCompBndSeqListSize, *foundCompBndSeqListSize + 1) );
986 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, foundCompBndSeqSizeList, *foundCompBndSeqListSize, *foundCompBndSeqListSize + 1) );
987 }
988 (*foundCompBndSeqList)[*foundCompBndSeqListSize] = compBndSeq;
989 (*foundCompBndSeqSizeList)[*foundCompBndSeqListSize] = compBndSeqSize;
990 *foundCompBndSeqListSize += 1;
991
992 return SCIP_OKAY;
993 }
994
995 // the fractionality is integral, we need to impose an additional bound
996 SCIP_VAR** indexSet = NULL;
997 int indexSetSize = 0;
998 SCIP_CALL( initIndexSet(masterprob, &indexSet, &indexSetSize, satisfyingMastervars, satisfyingMastervarsSize) );
999
1000 SCIP_VAR* selectedOrigvar = NULL;
1001 SCIP_Real value = 0.0;
1002 SCIP_CALL( chooseCompBnd(gcg, satisfyingMastervars, satisfyingMastervarsSize, indexSet, indexSetSize, compBndSeq, compBndSeqSize, blocknr, &selectedOrigvar, &value) );
1003 assert(selectedOrigvar != NULL);
1004 assert(SCIPvarGetLbGlobal(selectedOrigvar) < value && value < SCIPvarGetUbGlobal(selectedOrigvar));
1005
1006 SCIPfreeBlockMemoryArray(masterprob, &indexSet, indexSetSize);
1007 indexSetSize = 0;
1008
1009 // create two component bound options, xj <= floor(value) and xj >= floor(value)+1
1010 GCG_COMPBND* lowCompBndSeq;
1011 GCG_COMPBND* highCompBndSeq;
1012 int newCompBndSeqSize = compBndSeqSize + 1;
1013 // allocate memory for lowCompBndSeq and highCompBndSeq
1014 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &lowCompBndSeq, newCompBndSeqSize) );
1015
1016 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &highCompBndSeq, newCompBndSeqSize) );
1017 // copy the old component bounds to lowCompBndSeq and highCompBndSeq
1018 for(i = 0; i < compBndSeqSize; ++i)
1019 {
1020 lowCompBndSeq[i] = compBndSeq[i];
1021 highCompBndSeq[i] = compBndSeq[i];
1022 }
1023 // add the new component bounds to lowCompBndSeq and highCompBndSeq
1024 lowCompBndSeq[compBndSeqSize] = (GCG_COMPBND){selectedOrigvar, GCG_COMPBND_SENSE_LE, FLOOR(masterprob, value)};
1025 highCompBndSeq[compBndSeqSize] = (GCG_COMPBND){selectedOrigvar, GCG_COMPBND_SENSE_GE, FLOOR(masterprob, value) + 1};
1026
1027 freeComponentBoundSequence(masterprob, &compBndSeq, &compBndSeqSize);
1028 assert(compBndSeq == NULL);
1029
1030 SCIPdebugMessage("lowCompBndSeq and highCompBndSeq after adding the new component bounds\n");
1031 for (i = 0; i < newCompBndSeqSize; ++i)
1032 {
1033 SCIPdebugMessage("lowCompBndSeq[%d]: %s %s %d\n", i, SCIPvarGetName(lowCompBndSeq[i].component),
1034 lowCompBndSeq[i].sense == GCG_COMPBND_SENSE_LE ? "<=" : ">=",
1035 lowCompBndSeq[i].bound);
1036 SCIPdebugMessage("highCompBndSeq[%d]: %s %s %d\n", i, SCIPvarGetName(highCompBndSeq[i].component),
1037 highCompBndSeq[i].sense == GCG_COMPBND_SENSE_LE ? "<=" : ">=",
1038 highCompBndSeq[i].bound);
1039 }
1040
1041 // assign the master variables to lowMastervars and highMastervars, depending on whether they satisfy the new component bound sequences
1042 SCIP_VAR** lowMastervars = NULL;
1043 SCIP_VAR** highMastervars = NULL;
1044 int lowMastervarsSize = 0;
1045 int highMastervarsSize = 0;
1046 for( i=0; i<satisfyingMastervarsSize; ++i )
1047 {
1048#ifndef NDEBUG
1049 SCIP_Bool satisfiesLowCompBndSeq = FALSE;
1050 SCIP_Bool satisfiesHighCompBndSeq = FALSE;
1051#endif
1052 if( isMasterVarInCompBndSeq(masterprob, satisfyingMastervars[i], lowCompBndSeq, newCompBndSeqSize, blocknr) )
1053 {
1054 // increase the size of lowMastervars by 1, and add the current variable to lowMastervars
1055 if( lowMastervarsSize == 0 )
1056 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &lowMastervars, lowMastervarsSize+1) );
1057 else
1058 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &lowMastervars, lowMastervarsSize, lowMastervarsSize+1) );
1059
1060 lowMastervars[lowMastervarsSize] = satisfyingMastervars[i];
1061 lowMastervarsSize += 1;
1062#ifndef NDEBUG
1063 satisfiesLowCompBndSeq = TRUE;
1064#endif
1065 }
1066 if( isMasterVarInCompBndSeq(masterprob, satisfyingMastervars[i], highCompBndSeq, newCompBndSeqSize, blocknr) )
1067 {
1068 // increase the size of highMastervars by 1, and add the current variable to highMastervars
1069 if( highMastervarsSize == 0 )
1070 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &highMastervars, highMastervarsSize+1) );
1071 else
1072 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &highMastervars, highMastervarsSize, highMastervarsSize+1) );
1073
1074 highMastervars[highMastervarsSize] = satisfyingMastervars[i];
1075 highMastervarsSize += 1;
1076#ifndef NDEBUG
1077 satisfiesHighCompBndSeq = TRUE;
1078#endif
1079 }
1080#ifndef NDEBUG
1081 assert(satisfiesLowCompBndSeq + satisfiesHighCompBndSeq <= 1);
1082#endif
1083 }
1084 SCIPdebugMessage("lowMastervarsSize: %d, highMastervarsSize: %d\n", lowMastervarsSize, highMastervarsSize);
1085 assert(lowMastervarsSize > 0);
1086 assert(highMastervarsSize > 0);
1087
1088#ifndef NDEBUG
1089 // determine the fractionality of lowMastervars and highMastervars
1090 SCIP_Real fractionality1 = calcFractionality(masterprob, lowMastervars, lowMastervarsSize);
1091 SCIP_Real fractionality2 = calcFractionality(masterprob, highMastervars, highMastervarsSize);
1092
1093 assert(SCIPisPositive(masterprob, fractionality1));
1094 assert(SCIPisPositive(masterprob, fractionality2));
1095 assert(SCIPisLE(masterprob, fractionality / 2, fractionality1) || SCIPisLE(masterprob, fractionality / 2, fractionality2));
1096 assert(
1097 (SCIPisFeasIntegral(masterprob, fractionality1) && SCIPisFeasIntegral(masterprob, fractionality2)) ||
1098 (!SCIPisFeasIntegral(masterprob, fractionality1) && !SCIPisFeasIntegral(masterprob, fractionality2))
1099 );
1100#endif
1101
1102 // recursive call
1103 SCIP_CALL( separation_helper(gcg, lowMastervars, lowMastervarsSize, lowCompBndSeq, newCompBndSeqSize, blocknr, chooseCompBnd, foundCompBndSeqList, foundCompBndSeqSizeList, foundCompBndSeqListSize, result) );
1104
1105 SCIPfreeBlockMemoryArray(masterprob, &lowMastervars, lowMastervarsSize);
1106 lowMastervarsSize = 0;
1107 assert(lowMastervars == NULL);
1108
1109 SCIP_CALL( separation_helper(gcg, highMastervars, highMastervarsSize, highCompBndSeq, newCompBndSeqSize, blocknr, chooseCompBnd, foundCompBndSeqList, foundCompBndSeqSizeList, foundCompBndSeqListSize, result) );
1110
1111 SCIPfreeBlockMemoryArray(masterprob, &highMastervars, highMastervarsSize);
1112 highMastervarsSize = 0;
1113 assert(highMastervars == NULL);
1114
1115 return SCIP_OKAY;
1116}
1117
1118/** collects all currently mastervariables in the given block that satisfy the given component bound sequence */
1119static
1121 SCIP* masterscip, /**< SCIP data structure */
1122 SCIP_VAR*** satisfyingMastervars, /**< mastervariables in the given block satisfying the compBndSeq */
1123 int* satisfyingMastervarsSize,/**< size of mastervars */
1124 int blocknr, /**< number of the block */
1125 GCG_COMPBND* compBndSeq, /**< Component Bound Sequence defining the nodes */
1126 int compBndSeqSize /**< size of compBndSeq */
1127 )
1128{
1129 SCIP_VAR** allMastervars;
1130 int allMastervarsSize;
1131 int i;
1132
1133 assert(masterscip != NULL);
1134 assert(GCGisMaster(masterscip));
1135 assert(satisfyingMastervars != NULL);
1136 assert(satisfyingMastervarsSize != NULL);
1137
1138 allMastervars = NULL;
1139 allMastervarsSize = 0;
1140
1141 assert(masterscip != NULL);
1142
1143 SCIP_CALL( SCIPgetVarsData(masterscip, &allMastervars, &allMastervarsSize, NULL, NULL, NULL, NULL) );
1144
1145 if(*satisfyingMastervarsSize > 0)
1146 {
1147 assert(*satisfyingMastervars != NULL);
1148 SCIPfreeBlockMemoryArray(masterscip, satisfyingMastervars, *satisfyingMastervarsSize);
1149 *satisfyingMastervarsSize = 0;
1150 }
1151
1152 assert(*satisfyingMastervarsSize == 0 && *satisfyingMastervars == NULL);
1153
1154 for( i = 0; i < allMastervarsSize; ++i )
1155 {
1156 if( !GCGisMasterVarInBlock(allMastervars[i], blocknr) )
1157 continue;
1158
1159 if( compBndSeqSize > 0 && !isMasterVarInCompBndSeq(masterscip, allMastervars[i], compBndSeq, compBndSeqSize, blocknr) )
1160 continue;
1161
1162 if( *satisfyingMastervarsSize == 0 )
1163 {
1164 SCIP_CALL( SCIPallocBlockMemoryArray(masterscip, satisfyingMastervars, 1) );
1165 }
1166 else
1167 {
1168 SCIP_CALL( SCIPreallocBlockMemoryArray(masterscip, satisfyingMastervars, *satisfyingMastervarsSize, *satisfyingMastervarsSize+1) );
1169 }
1170 (*satisfyingMastervars)[*satisfyingMastervarsSize] = allMastervars[i];
1171 (*satisfyingMastervarsSize) += 1;
1172 }
1173
1174 return SCIP_OKAY;
1175}
1176
1177/* @todo: Vanderbeck (2000) suggests other (also optimal?) algorithms to find a good (best?) component bound sequence; we should check that */
1178
1179/** choose to separate on original variable where max-min is maximal */
1180static
1181CHOOSE_COMPBND(chooseMaxMin)
1182{
1183 // Task: Find fractional mastervarMin, mastervarMax, indexed by x1, x2, s.t. for some j, xj1 < xj2
1184 SCIP_VAR* currentMastervar;
1185 SCIP_Real currentSolutionValue; // of the currMastervar
1186 SCIP_VAR* currentOrigvar;
1187 SCIP_Real currentMin;
1188 SCIP_Real currentMax;
1189 SCIP_Real currentDiff;
1190 SCIP_Real largestDiffMin;
1191 SCIP_Real largestDiffMax;
1192 SCIP_Real largestDiff;
1193 int i;
1194 int j;
1195 SCIP_Real generatorentry;
1196 SCIP_Bool found = FALSE;
1197 SCIP* masterprob;
1198
1199#ifndef NDEBUG
1200 SCIP_Real givenMin;
1201 SCIP_Real givenMax;
1202#endif
1203
1204 masterprob = GCGgetMasterprob(gcg);
1205 largestDiff = -SCIPinfinity(masterprob);
1206
1207 for( j=0; j<indexSetSize; ++j )
1208 {
1209 currentOrigvar = indexSet[j];
1210#ifndef NDEBUG
1211 givenMin = getLowerBound(masterprob, currentOrigvar, compBndSeq, compBndSeqSize);
1212 givenMax = getUpperBound(masterprob, currentOrigvar, compBndSeq, compBndSeqSize);
1213 assert(SCIPisFeasLE(masterprob, givenMin, givenMax));
1214#endif
1215 currentMin = SCIPinfinity(masterprob);
1216 currentMax = -SCIPinfinity(masterprob);
1217 for( i=0; i<satisfyingMastervarsSize; ++i )
1218 {
1219 currentMastervar = satisfyingMastervars[i];
1220
1221 // Current solution value of the master variable must be fractional and > 0
1222 currentSolutionValue = SCIPgetSolVal(masterprob, NULL, currentMastervar);
1223 if ( !SCIPisFeasPositive(masterprob, currentSolutionValue) || SCIPisFeasIntegral(masterprob, currentSolutionValue) ) {
1224 // skip
1225 continue;
1226 }
1227
1228 generatorentry = getGeneratorEntry(currentMastervar, currentOrigvar);
1229
1230 // first, check if we can update the min and max values
1231 if( SCIPisInfinity(masterprob, currentMin) )
1232 {
1233 assert(SCIPisInfinity(masterprob, -currentMax));
1234 currentMin = generatorentry;
1235 currentMax = generatorentry;
1236 }
1237 else if( SCIPisLT(masterprob, generatorentry, currentMin) )
1238 currentMin = generatorentry;
1239 else if( SCIPisLT(masterprob, currentMax, generatorentry) )
1240 currentMax = generatorentry;
1241
1242 // now could be that min<max
1243 if( SCIPisLT(masterprob, currentMin, currentMax) )
1244 {
1245 found = TRUE;
1246 currentDiff = currentMax - currentMin;
1247 if( SCIPisGT(masterprob, currentDiff, largestDiff) )
1248 {
1249 largestDiffMin = currentMin;
1250 largestDiffMax = currentMax;
1251 largestDiff = currentDiff;
1252 *selectedOrigvar = currentOrigvar;
1253 }
1254 }
1255 }
1256 }
1257
1258 if( !found ) // should always be able to find - the branching scheme is sound and complete
1259 {
1260 return SCIP_ERROR;
1261 }
1262
1263 assert(largestDiffMin < largestDiffMax);
1264 assert(largestDiff > 0);
1265 assert(SCIPisFeasLE(masterprob, SCIPvarGetLbGlobal(*selectedOrigvar), largestDiffMin));
1266 assert(SCIPisFeasLE(masterprob, largestDiffMax, SCIPvarGetUbGlobal(*selectedOrigvar)));
1267 SCIPdebugMessage("Found %d for origvar %s, j=%d, min=%f, max=%f\n", found, SCIPvarGetName(*selectedOrigvar), j, largestDiffMin, largestDiffMax);
1268
1269 // j and origivar are still set to the correct values after execution of the loop
1270 *value = (largestDiffMin+largestDiffMax)/2;
1271
1272 return SCIP_OKAY;
1273}
1274
1275/** choose to separate on original variable which has the largest number of distinct numbers, and find the median value */
1276static
1277CHOOSE_COMPBND(chooseMostDistinctValuesMedian)
1278{
1279 SCIP* masterprob;
1280 int selectedNumDistinctValues = 0;
1281 SCIP_VAR* currentOrigvar;
1282 int currentNumDistinctValues;
1283 SCIP_Real* distinctValues = NULL;
1284 int distinctValuesSize = 0;
1285 SCIP_Bool inserted;
1286 SCIP_Bool duplicate;
1287 int i;
1288 int j;
1289 int k;
1290 int l;
1291
1292 masterprob = GCGgetMasterprob(gcg);
1293 assert(*selectedOrigvar == NULL);
1294
1295 SCIP_Real generatorentry;
1296
1297 for( j=0; j<indexSetSize; ++j )
1298 {
1299 currentOrigvar = indexSet[j];
1300 currentNumDistinctValues = 0;
1301
1302 for( i=0; i<satisfyingMastervarsSize; ++i )
1303 {
1304 SCIP_VAR* current_mastervar = satisfyingMastervars[i];
1305
1306 // Current solution value of the master variable must be fractional and > 0
1307 SCIP_Real current_solution_value = SCIPgetSolVal(masterprob, NULL, current_mastervar);
1308 if ( !SCIPisFeasPositive(masterprob, current_solution_value) || SCIPisFeasIntegral(masterprob, current_solution_value) ) {
1309 // skip
1310 continue;
1311 }
1312
1313 generatorentry = getGeneratorEntry(current_mastervar, currentOrigvar);
1314
1315 // insert sorted, if the value is not already in the array
1316 if( distinctValuesSize == 0 )
1317 {
1318 assert(distinctValues == NULL);
1319 assert(currentNumDistinctValues == 0);
1320 distinctValuesSize = SCIPcalcMemGrowSize(masterprob, 1);
1321 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &distinctValues, distinctValuesSize) );
1322 distinctValues[0] = generatorentry;
1323 currentNumDistinctValues = 1;
1324 }
1325 else
1326 {
1327 // current_distinctValues is sorted ascendingly
1328 inserted = FALSE;
1329 duplicate = FALSE;
1330 for( k=0; k<currentNumDistinctValues; ++k )
1331 {
1332 if( SCIPisEQ(masterprob, generatorentry, distinctValues[k]) )
1333 {
1334 duplicate = TRUE;
1335 break;
1336 }
1337
1338 if( SCIPisLT(masterprob, generatorentry, distinctValues[k]) )
1339 {
1340 // insert at position k
1341 if( currentNumDistinctValues == distinctValuesSize )
1342 {
1343 int new_current_distinctValuesSize = SCIPcalcMemGrowSize(masterprob, currentNumDistinctValues + 1);
1344 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &distinctValues, distinctValuesSize, new_current_distinctValuesSize) );
1345 distinctValuesSize = new_current_distinctValuesSize;
1346 }
1347
1348 for( l = currentNumDistinctValues; l > k; --l )
1349 {
1350 distinctValues[l] = distinctValues[l-1];
1351 }
1352
1353 distinctValues[k] = generatorentry;
1354 currentNumDistinctValues += 1;
1355
1356 inserted = TRUE;
1357 break;
1358 }
1359 }
1360
1361 if( !inserted && !duplicate )
1362 {
1363 // insert at the end
1364 if( currentNumDistinctValues == distinctValuesSize )
1365 {
1366 int new_current_distinctValuesSize = SCIPcalcMemGrowSize(masterprob, currentNumDistinctValues + 1);
1367 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &distinctValues, distinctValuesSize, new_current_distinctValuesSize) );
1368 distinctValuesSize = new_current_distinctValuesSize;
1369 }
1370
1371 distinctValues[currentNumDistinctValues] = generatorentry;
1372 currentNumDistinctValues += 1;
1373 }
1374 }
1375 }
1376
1377 if( currentNumDistinctValues > 1 && currentNumDistinctValues > selectedNumDistinctValues )
1378 {
1379 assert(currentNumDistinctValues > 1);
1380 *selectedOrigvar = currentOrigvar;
1381 selectedNumDistinctValues = currentNumDistinctValues;
1382
1383 // calculate median
1384 if( currentNumDistinctValues % 2 == 0 )
1385 {
1386 *value = 0.5 * (distinctValues[currentNumDistinctValues / 2] + distinctValues[currentNumDistinctValues / 2 - 1]);
1387 }
1388 else
1389 {
1390 *value = distinctValues[currentNumDistinctValues / 2];
1391 }
1392 }
1393 }
1394
1395 assert(*selectedOrigvar != NULL);
1396
1397 SCIPfreeBlockMemoryArrayNull(masterprob, &distinctValues, distinctValuesSize);
1398
1399 return SCIP_OKAY;
1400}
1401
1402/** calculate sum of component bound sequence */
1403static
1405 SCIP* masterscip, /**< SCIP data structure */
1406 GCG_COMPBND* compBndSeq, /**< Component Bound Sequence defining the nodes */
1407 int compBndSeqSize, /**< size of compBndSeq */
1408 int blocknr /**< number of the block */
1409 )
1410{
1411 int i;
1412 SCIP_Real sum = 0.0;
1413 SCIP_VAR** satisfyingMastervars = NULL;
1414 int satisfyingMastervarsSize = 0;
1415
1416 assert(masterscip != NULL);
1417 assert(GCGisMaster(masterscip));
1418
1419 assert(satisfyingMastervars == NULL && satisfyingMastervarsSize == 0);
1420 findSatisfyingMastervars(masterscip, &satisfyingMastervars, &satisfyingMastervarsSize, blocknr, compBndSeq, compBndSeqSize);
1421 assert((satisfyingMastervarsSize > 0) == (satisfyingMastervars != NULL));
1422
1423 sum = 0;
1424 for( i = 0; i < satisfyingMastervarsSize; ++i )
1425 {
1426 sum += SCIPgetSolVal(masterscip, NULL, satisfyingMastervars[i]);
1427 }
1428
1429 SCIPfreeBlockMemoryArrayNull(masterscip, &satisfyingMastervars, satisfyingMastervarsSize);
1430
1431 return sum;
1432}
1433
1434/** choose the component bound of which the sum is closest to K/2, where K is the number of identical subproblems in the current block */
1435static
1436CHOOSE_COMPBNDSEQ(chooseClosestToKHalf)
1437{
1438 SCIP* masterprob;
1439 int i;
1440 SCIP_Real sum;
1441 SCIP_Real kHalf;
1442
1443 int bestIndex = -1;
1444 SCIP_Real best;
1445
1446 masterprob = GCGgetMasterprob(gcg);
1447
1448 assert(masterprob != NULL);
1449 assert(GCGisMaster(masterprob));
1450 assert(compBndSeqList != NULL);
1451 assert(compBndSeqSizeList != NULL);
1452 assert(compBndListSize > 0);
1453
1454 best = SCIPinfinity(masterprob);
1455 kHalf = GCGgetNIdenticalBlocks(gcg, blocknr) * 0.5;
1456
1457 for( i = 0; i < compBndListSize; ++i )
1458 {
1459 sum = ABS(calcSum(masterprob, compBndSeqList[i], compBndSeqSizeList[i], blocknr) - kHalf);
1460
1461 if( sum < best )
1462 {
1463 best = sum;
1464 bestIndex = i;
1465 }
1466 }
1467
1468 assert(bestIndex >= 0);
1469
1470 *selectedCompBndSeq = compBndSeqList[bestIndex];
1471 *selectedCompBndSeqSize = compBndSeqSizeList[bestIndex];
1472
1473 return SCIP_OKAY;
1474}
1475
1476/** choose the component bound of which the sum is most fractional */
1477static
1478CHOOSE_COMPBNDSEQ(chooseMostFractional)
1479{
1480 int i;
1481 SCIP_Real sum;
1482 SCIP_Real fractionality;
1483 SCIP* masterprob;
1484
1485 int bestIndex = -1;
1486 SCIP_Real best = 0.0;
1487
1488 masterprob = GCGgetMasterprob(gcg);
1489 assert(masterprob != NULL);
1490 assert(GCGisMaster(masterprob));
1491 assert(compBndSeqList != NULL);
1492 assert(compBndSeqSizeList != NULL);
1493 assert(compBndListSize > 0);
1494
1495 for( i = 0; i < compBndListSize; ++i )
1496 {
1497 sum = calcSum(masterprob, compBndSeqList[i], compBndSeqSizeList[i], blocknr);
1498 fractionality = SCIPfrac(masterprob, sum);
1499
1500 fractionality = MIN(fractionality, 1.0 - fractionality);
1501
1502 if( best < fractionality )
1503 {
1504 best = fractionality;
1505 bestIndex = i;
1506 }
1507 }
1508
1509 assert(bestIndex >= 0);
1510
1511 *selectedCompBndSeq = compBndSeqList[bestIndex];
1512 *selectedCompBndSeqSize = compBndSeqSizeList[bestIndex];
1513
1514 return SCIP_OKAY;
1515}
1516
1517/** choose the component bound sequence with the smallest size */
1518static
1519CHOOSE_COMPBNDSEQ(chooseSmallestSize)
1520{
1521 int i;
1522 int smallestSize = INT_MAX;
1523 SCIP* masterprob;
1524
1525 GCG_COMPBND** newCompBndSeqList = NULL;
1526 int* newCompBndSeqSizeList = NULL;
1527 int newCompBndSeqListSize = 0;
1528
1529 masterprob = GCGgetMasterprob(gcg);
1530 assert(masterprob != NULL);
1531 assert(GCGisMaster(masterprob));
1532 assert(compBndSeqList != NULL);
1533 assert(compBndSeqSizeList != NULL);
1534 assert(compBndListSize > 0);
1535
1536 // step 1: find smallest size
1537 for( i = 0; i < compBndListSize; ++i )
1538 {
1539 if( compBndSeqSizeList[i] < smallestSize )
1540 {
1541 smallestSize = compBndSeqSizeList[i];
1542 }
1543 }
1544 assert(smallestSize > 0);
1545
1546 // step 2: create new Blist with smallest size
1547 for( i = 0; i < compBndListSize; ++i )
1548 {
1549 if( compBndSeqSizeList[i] == smallestSize )
1550 {
1551 if( newCompBndSeqListSize == 0 )
1552 {
1553 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &newCompBndSeqList, 1) );
1554 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &newCompBndSeqSizeList, 1) );
1555 }
1556 else
1557 {
1558 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &newCompBndSeqList, newCompBndSeqListSize, newCompBndSeqListSize + 1) );
1559 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &newCompBndSeqSizeList, newCompBndSeqListSize, newCompBndSeqListSize + 1) );
1560 }
1561
1562 newCompBndSeqList[newCompBndSeqListSize] = compBndSeqList[i];
1563 newCompBndSeqSizeList[newCompBndSeqListSize] = compBndSeqSizeList[i];
1564 newCompBndSeqListSize += 1;
1565 }
1566 }
1567
1568 assert(newCompBndSeqListSize > 0);
1569
1570 // step 3: refine the selection
1571 //SCIP_CALL( chooseClosestToKHalf(masterscip, newCompBndSeqList, newCompBndSeqSizeList, newCompBndSeqListSize, blocknr, selectedCompBndSeq, selectedCompBndSeqSize) );
1572 SCIP_CALL( chooseMostFractional(gcg, newCompBndSeqList, newCompBndSeqSizeList, newCompBndSeqListSize, blocknr, selectedCompBndSeq, selectedCompBndSeqSize) );
1573
1574 // step 4: free memory
1575 SCIPfreeBlockMemoryArray(masterprob, &newCompBndSeqList, newCompBndSeqListSize);
1576 SCIPfreeBlockMemoryArray(masterprob, &newCompBndSeqSizeList, newCompBndSeqListSize);
1577
1578 return SCIP_OKAY;
1579}
1580
1581/** separation algorithm determining a component bound sequence to branch on */
1582static
1584 GCG* gcg, /**< GCG data structure */
1585 GCG_BRANCHRULE* branchrule, /**< branching rule */
1586 GCG_COMPBND** compBndSeq, /**< Component Bound Sequence defining the nodes */
1587 int* compBndSeqSize, /**< size of compBndSeq */
1588 int blocknr, /**< number of the block */
1589 SCIP_RESULT* result /**< pointer to store the result of the branching call */
1590 )
1591{
1592 // a list of component bound sequences (also lists)
1593 GCG_COMPBND** compBndSeqList;
1594 int* compBndSeqSizeList;
1595 int compBndSeqListSize;
1596 SCIP* masterprob;
1597 SCIP_BRANCHRULEDATA* branchruledata;
1598 SCIP_VAR** satisfyingMastervars;
1599 int satisfyingMastervarsSize;
1600 int i;
1601
1602 compBndSeqList = NULL;
1603 compBndSeqSizeList = NULL;
1604 compBndSeqListSize = 0;
1605
1606 satisfyingMastervars = NULL;
1607 satisfyingMastervarsSize = 0;
1608
1609 branchruledata = SCIPbranchruleGetData(GCGbranchGetScipBranchrule(branchrule));
1610 assert(branchruledata != NULL);
1611
1612 masterprob = GCGgetMasterprob(gcg);
1613
1614 findSatisfyingMastervars(masterprob, &satisfyingMastervars, &satisfyingMastervarsSize, blocknr, NULL, 0);
1615#ifndef NDEBUG
1616 int satisfyingMastervarsSizeCopy = satisfyingMastervarsSize;
1617 int BlistsizeCopy = compBndSeqListSize;
1618#endif
1619
1620 // call the separation algorithm with all chooseVars functions
1621 assert(branchruledata->useMaxRangeMidrangeHeuristic || branchruledata->useMostDistinctMedianHeuristic);
1622
1623 if( branchruledata->useMaxRangeMidrangeHeuristic )
1624 {
1625 SCIP_CALL( separation_helper(gcg, satisfyingMastervars, satisfyingMastervarsSize, NULL, 0, blocknr, chooseMaxMin, &compBndSeqList, &compBndSeqSizeList, &compBndSeqListSize, result) );
1626#ifndef NDEBUG
1627 assert(satisfyingMastervarsSize == satisfyingMastervarsSizeCopy);
1628 assert(compBndSeqListSize > BlistsizeCopy);
1629 BlistsizeCopy = compBndSeqListSize;
1630#endif
1631 }
1632
1633 if( branchruledata->useMostDistinctMedianHeuristic )
1634 {
1635 SCIP_CALL( separation_helper(gcg, satisfyingMastervars, satisfyingMastervarsSize, NULL, 0, blocknr, chooseMostDistinctValuesMedian, &compBndSeqList, &compBndSeqSizeList, &compBndSeqListSize, result) );
1636#ifndef NDEBUG
1637 assert(satisfyingMastervarsSize == satisfyingMastervarsSizeCopy);
1638 assert(compBndSeqListSize > BlistsizeCopy);
1639 BlistsizeCopy = compBndSeqListSize;
1640#endif
1641 }
1642
1643 SCIPfreeBlockMemoryArray(masterprob, &satisfyingMastervars, satisfyingMastervarsSize);
1644 satisfyingMastervarsSize = 0;
1645 assert(satisfyingMastervars == NULL);
1646
1647 assert(compBndSeqListSize > 0);
1648 assert(compBndSeqList != NULL);
1649 assert(compBndSeqSizeList != NULL);
1650
1651 SCIP_CALL( chooseSmallestSize(gcg, compBndSeqList, compBndSeqSizeList, compBndSeqListSize, blocknr, compBndSeq, compBndSeqSize) );
1652
1653 assert(*compBndSeqSize > 0);
1654 assert(*compBndSeq != NULL);
1655
1656 // free others, as well as Blist
1657 for( i = 0; i < compBndSeqListSize; ++i )
1658 {
1659 if( compBndSeqList[i] != *compBndSeq )
1660 {
1661 freeComponentBoundSequence(masterprob, &compBndSeqList[i], &compBndSeqSizeList[i]);
1662 }
1663 }
1664
1665 SCIPfreeBlockMemoryArray(masterprob, &compBndSeqList, compBndSeqListSize);
1666 SCIPfreeBlockMemoryArray(masterprob, &compBndSeqSizeList, compBndSeqListSize);
1667
1668 return SCIP_OKAY;
1669}
1670
1671/** prepares information for using the generic branching scheme */
1672static
1674 GCG* gcg, /**< GCG data structure */
1675 GCG_BRANCHRULE* branchrule, /**< branching rule */
1676 SCIP_RESULT* result /**< pointer to store the result of the branching call */
1677 )
1678{
1679#ifdef COMPBND_STATS
1680 SCIP_BRANCHRULEDATA* branchruledata;
1681#endif
1682 SCIP* masterprob;
1683 SCIP_VAR** branchcands;
1684 int nbranchcands;
1685 GCG_COMPBND* compBndSeq;
1686 int compBndSeqSize;
1687 int blocknr;
1688 SCIP_Bool foundBlock;
1689 SCIP_VAR** satisfyingMastervars;
1690 int satisfyingMastervarsSize;
1691 SCIP_Real fractionality;
1692
1693 blocknr = -2;
1694 compBndSeq = NULL;
1695 compBndSeqSize = 0;
1696
1697 masterprob = GCGgetMasterprob(gcg);
1698
1699 assert(masterprob != NULL);
1700
1701 SCIPdebugMessage("get information for component bound branching\n");
1702
1703 SCIP_CALL( SCIPgetLPBranchCands(masterprob, &branchcands, NULL, NULL, &nbranchcands, NULL, NULL) );
1704
1705#ifdef COMPBND_STATS
1706 branchruledata = SCIPbranchruleGetData(branchrule);
1707#endif
1708
1709 /* in case original problem contains continuous variables, there are no branching cands */
1710 assert(nbranchcands > 0);
1711
1712 foundBlock = FALSE;
1713 satisfyingMastervarsSize = 0;
1714 satisfyingMastervars = NULL;
1715
1716 /* 1. Determine in what block we are branching. We select the first available block,
1717 * i.e. the first block that contains a branching candidate, starting from the master block.
1718 */
1719 for( blocknr = 0; blocknr < GCGgetNPricingprobs(gcg); blocknr++ )
1720 {
1721 if( !GCGisPricingprobRelevant(gcg, blocknr) )
1722 continue;
1723
1724 SCIPdebugMessage("\nTrying to branch in block %d:\n", blocknr);
1725
1726 /* 2. Check whether the fractionality of all master variables in this block is not 0. */
1727 findSatisfyingMastervars(masterprob, &satisfyingMastervars, &satisfyingMastervarsSize, blocknr, NULL, 0);
1728 assert((satisfyingMastervarsSize > 0) == (satisfyingMastervars != NULL));
1729 fractionality = calcFractionality(masterprob, satisfyingMastervars, satisfyingMastervarsSize);
1730 assert(SCIPisFeasIntegral(masterprob, fractionality));
1731 SCIPfreeBlockMemoryArray(masterprob, &satisfyingMastervars, satisfyingMastervarsSize);
1732 satisfyingMastervarsSize = 0;
1733 assert(satisfyingMastervars == NULL);
1734 if( SCIPisZero(masterprob, fractionality) )
1735 {
1736 SCIPdebugMessage("No fractional integer variables in block %d\n", blocknr);
1737 continue;
1738 }
1739
1740 /* 3. Call to separation algorithm to find a suitable compBndSeq to branch on in the current block. */
1741 SCIP_CALL( separation(gcg, branchrule, &compBndSeq, &compBndSeqSize, blocknr, result) );
1742
1743 if( *result == SCIP_BRANCHED )
1744 {
1745 assert(compBndSeqSize > 0);
1746 assert(compBndSeq != NULL);
1747 SCIPdebugMessage("Branching in block %d\n", blocknr);
1748 foundBlock = TRUE;
1749 break;
1750 }
1751 else
1752 {
1753 if( compBndSeqSize > 0 )
1754 {
1755 freeComponentBoundSequence(masterprob, &compBndSeq, &compBndSeqSize);
1756 compBndSeqSize = 0;
1757 }
1758 }
1759 }
1760
1761 if( !foundBlock )
1762 {
1763 assert(compBndSeqSize == 0);
1764 assert(compBndSeq == NULL);
1765 SCIPdebugMessage("No block found to branch on\n");
1766 *result = SCIP_CUTOFF;
1767 return SCIP_OKAY;
1768 }
1769
1770 SCIPdebugMessage("Component bound sequence to branch on:\n");
1771 SCIPdebugMessage("compBndSeqSize: %d\n", compBndSeqSize);
1772 for (int i = 0; i < compBndSeqSize; ++i)
1773 {
1774 SCIPdebugMessage("compBndSeq[%d]: %s %s %d\n", i, SCIPvarGetName((compBndSeq)[i].component),
1775 (compBndSeq)[i].sense == GCG_COMPBND_SENSE_LE ? "<=" : ">=",
1776 (compBndSeq)[i].bound);
1777 }
1778
1779 /* 4. Remove component bounds that are strengthened by others */
1780 SCIP_CALL( simplifyComponentBoundSequence(masterprob, &compBndSeq, &compBndSeqSize) );
1781 assert(compBndSeqSize > 0);
1782 assert(compBndSeq != NULL);
1783
1784#ifdef COMPBND_STATS
1785 int depth = SCIPgetDepth(masterprob);
1786 SCIP_Real sum = calcSum(masterprob, compBndSeq, compBndSeqSize, blocknr);
1787 int K = GCGgetNIdenticalBlocks(origprob, blocknr);
1788 fprintf(branchruledata->statsfile, "%d,%d,%f,%d\n", depth, compBndSeqSize, sum, K);
1789#endif
1790
1791 /* 5. Create the child nodes. */
1792 SCIP_CALL( createChildNodesCompBndSeq(gcg, branchrule, compBndSeq, compBndSeqSize, blocknr) );
1793
1794 return SCIP_OKAY;
1795}
1796
1797/*
1798 * Callback methods of branching rule
1799 */
1800
1801/** destructor of branching rule to free user data (called when SCIP is exiting) */
1802static
1803SCIP_DECL_BRANCHFREE(branchFreeCompBnd)
1804{ /*lint --e{715}*/
1805 SCIP_BRANCHRULEDATA* branchruledata;
1806
1807 branchruledata = SCIPbranchruleGetData(branchrule);
1808
1809#ifdef COMPBND_STATS
1810 if( branchruledata->statsfile != NULL )
1811 {
1812 fclose(branchruledata->statsfile);
1813 branchruledata->statsfile = NULL;
1814 }
1815#endif
1816
1817 SCIPfreeBlockMemory(scip, &branchruledata);
1818 SCIPbranchruleSetData(branchrule, NULL);
1819
1820 return SCIP_OKAY;
1821}
1822
1823
1824/** deinitialization method of branching rule (called before transformed problem is freed) */
1825#define branchExitCompBnd NULL
1826
1827
1828/** solving process initialization method of branching rule (called when branch and bound process is about to begin) */
1829#define branchInitsolCompBnd NULL
1830
1831
1832/** solving process deinitialization method of branching rule (called before branch and bound process data is freed) */
1833#define branchExitsolCompBnd NULL
1834
1835
1836/** branching execution method for fractional LP solutions */
1837static
1838SCIP_DECL_BRANCHEXECLP(branchExeclpCompBnd)
1839{ /*lint --e{715}*/
1840 SCIP* origprob;
1841 SCIP_Bool discretization;
1842 SCIP_BRANCHRULEDATA* branchruledata;
1843
1844 assert(branchrule != NULL);
1845 assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
1846 assert(scip != NULL);
1847 assert(result != NULL);
1848
1849 branchruledata = SCIPbranchruleGetData(branchrule);
1850 assert(branchruledata != NULL);
1851
1852 origprob = GCGgetOrigprob(branchruledata->gcg);
1853 assert(origprob != NULL);
1854
1855 SCIPdebugMessage("Execlp method of component bound branching\n");
1856
1857 *result = SCIP_DIDNOTRUN;
1858
1859 /* the branching scheme only works for the discretization approach
1860 * actually, this branching scheme _enforces_ a discretization concept
1861 */
1862 SCIP_CALL( SCIPgetBoolParam(origprob, "relaxing/gcg/discretization", &discretization) );
1863 if( !discretization )
1864 {
1865 SCIPdebugMessage("Component bound branching only for discretization approach\n");
1866 return SCIP_OKAY;
1867 }
1868
1869 if( GCGisMasterSetCovering(branchruledata->gcg) || GCGisMasterSetPartitioning(branchruledata->gcg) )
1870 {
1871 SCIPdebugMessage("Component bound branching executed on a set covering or set partitioning problem\n");
1872 }
1873
1874 if( GCGrelaxIsOrigSolFeasible(branchruledata->gcg) )
1875 {
1876 SCIPdebugMessage("node cut off, since origsol was feasible, solval = %f\n",
1877 SCIPgetSolOrigObj(origprob, GCGrelaxGetCurrentOrigSol(branchruledata->gcg)));
1878
1879 *result = SCIP_DIDNOTFIND;
1880 return SCIP_OKAY;
1881 }
1882
1883 *result = SCIP_BRANCHED;
1884
1885 SCIP_CALL( initBranch(branchruledata->gcg, branchruledata->gcgbranchrule, result) );
1886
1887 return SCIP_OKAY;
1888}
1889
1890
1891static
1892SCIP_DECL_BRANCHEXECEXT(branchExecextCompBnd)
1893{ /*lint --e{715}*/
1894 SCIPdebugMessage("Execext method of component bound branching\n");
1895
1896 *result = SCIP_DIDNOTRUN;
1897
1898 return SCIP_OKAY;
1899}
1900
1901
1902/** copy method for branchrule plugins (called when SCIP copies plugins) */
1903#define branchCopyCompBnd NULL
1904
1905
1906/** branching execution method for not completely fixed pseudo solutions */
1907static
1908SCIP_DECL_BRANCHEXECPS(branchExecpsCompBnd)
1909{ /*lint --e{715}*/
1910
1911 assert(branchrule != NULL);
1912 assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
1913 assert(scip != NULL);
1914 assert(result != NULL);
1915
1916 SCIPdebugMessage("Execps method of component bound branching\n");
1917
1918 if( SCIPisStopped(scip) )
1919 {
1920 SCIPwarningMessage(scip, "No branching could be created, solving process cannot be restarted...\n" );
1921
1922 *result = SCIP_DIDNOTRUN;
1923 return SCIP_OKAY;
1924 }
1925 else
1926 {
1927 SCIPerrorMessage("This method is not implemented, aborting since we cannot recover!\n");
1928 SCIPdialogMessage(scip, NULL, "Due to numerical issues, the problem could not be solved.\n");
1929 SCIPdialogMessage(scip, NULL, "You can try to disable discretization and aggregation and resolve the problem.\n");
1930
1931 *result = SCIP_DIDNOTRUN;
1932 return SCIP_ERROR;
1933 }
1934}
1935
1936/*
1937 * GCG specific branching rule callbacks
1938 */
1939
1940/** activation method for branchrule, called when a node in the master problem is activated,
1941 * should perform changes to the current node's problem due to the branchdata
1942 */
1943static
1944GCG_DECL_BRANCHACTIVEMASTER(branchActiveMasterCompBnd)
1945{
1946 assert(gcg != NULL);
1947
1948 assert(branchdata != NULL);
1949 assert(branchdata->mastercons != NULL);
1950
1951 SCIPdebugMessage("branchActiveMasterCompBnd: Block %d, Ssize %d\n", branchdata->blocknr, branchdata->compBndSeqSize);
1952
1953 return SCIP_OKAY;
1954}
1955
1956
1957/** deactivation method for branchrule, called when a node in the master problem is deactivated,
1958 * should undo changes to the current node's problem due to the branchdata
1959 */
1960static
1961GCG_DECL_BRANCHDEACTIVEMASTER(branchDeactiveMasterCompBnd)
1962{
1963 assert(gcg != NULL);
1964
1965 assert(branchdata != NULL);
1966 assert(branchdata->mastercons != NULL);
1967
1968 SCIPdebugMessage("branchDeactiveMasterCompBnd: Block %d, Ssize %d\n", branchdata->blocknr, branchdata->compBndSeqSize);
1969
1970 return SCIP_OKAY;
1971}
1972
1973/** propagation method for branchrule, called when a node in the master problem is propagated,
1974 * should perform propagation at the current node due to the branchdata
1975 */
1976static
1977GCG_DECL_BRANCHPROPMASTER(branchPropMasterCompBnd)
1978{
1979 assert(gcg != NULL);
1980 assert(branchdata != NULL);
1981 assert(branchdata->mastercons != NULL);
1982 assert(branchdata->compBndSeq != NULL);
1983
1984 *result = SCIP_DIDNOTFIND;
1985 return SCIP_OKAY;
1986}
1987
1988/** method for branchrule, called when the master LP is solved at one node,
1989 * can store pseudocosts for the branching decisions
1990 */
1991#define branchMasterSolvedCompBnd NULL
1992
1993/** frees branching data of an origbranch constraint (called when the origbranch constraint is deleted) */
1994static
1995GCG_DECL_BRANCHDATADELETE(branchDataDeleteCompBnd)
1996{
1997 SCIP* masterscip;
1998
1999 assert(gcg != NULL);
2000 assert(branchdata != NULL);
2001
2002 if( origbranch && !force )
2003 return SCIP_OKAY;
2004
2005 masterscip = GCGgetMasterprob(gcg);
2006 assert(masterscip != NULL);
2007
2008 SCIPdebugMessage("branchDataDeleteCompBnd: Block %d, Ssize %d\n", (*branchdata)->blocknr, (*branchdata)->compBndSeqSize);
2009
2010 assert(*branchdata != NULL);
2011
2012 /* release constraint that enforces the branching decision */
2013 assert((*branchdata)->mastercons != NULL);
2014 SCIP_CALL( GCGbranchFreeExtendedmasterconsBranchData(gcg, &(*branchdata)->mastercons) );
2015 assert((*branchdata)->mastercons == NULL);
2016
2017 assert((*branchdata)->compBndSeq != NULL && (*branchdata)->compBndSeqSize > 0);
2018 SCIPfreeBlockMemoryArray(masterscip, &((*branchdata)->compBndSeq), (*branchdata)->compBndSeqSize);
2019 assert((*branchdata)->compBndSeq == NULL);
2020 (*branchdata)->compBndSeqSize = 0;
2021
2022 SCIPfreeBlockMemory(masterscip, branchdata);
2023 assert(*branchdata == NULL);
2024
2025 return SCIP_OKAY;
2026}
2027
2028/** callback new column method */
2029static
2030GCG_DECL_BRANCHNEWCOL(branchNewColCompBnd)
2031{
2032 assert(gcg != NULL);
2033
2034 assert(mastervar != NULL);
2035 assert(GCGvarIsMaster(mastervar));
2036 assert(branchdata != NULL);
2037 assert(branchdata->mastercons != NULL);
2038
2039 SCIP_CALL( addVarToMasterbranch(gcg, mastervar, branchdata) );
2040
2041 return SCIP_OKAY;
2042}
2043
2044static
2045GCG_DECL_BRANCHGETEXTENDEDMASTERCONS(branchGetExtendedmasterconsCompBnd)
2046{
2047 assert(gcg != NULL);
2048
2049 assert(branchdata != NULL);
2050 assert(branchdata->mastercons != NULL);
2051
2052 *extendedmasterconsdata = branchdata->mastercons;
2053
2054 return SCIP_OKAY;
2055}
2056
2057
2058/** initialization method of branching rule (called after problem was transformed) */
2059static
2060SCIP_DECL_BRANCHINIT(branchInitCompBnd)
2061{
2062#ifdef COMPBND_STATS
2063 SCIP_BRANCHRULEDATA* branchruledata;
2064 SCIP_Bool stabilization_tree;
2065
2066 assert(branchrule != NULL);
2067 branchruledata = SCIPbranchruleGetData(branchrule);
2068 assert(branchruledata != NULL);
2069
2070 branchruledata = SCIPbranchruleGetData(branchrule);
2071 assert(branchruledata != NULL);
2072 SCIP_CALL( SCIPgetBoolParam(origprob, "pricing/masterpricer/stabilizationtree", &stabilization_tree) );
2073#endif
2074
2075 SCIPdebugMessage("Init method of component bound branching\n");
2076
2077#ifdef COMPBND_STATS
2078 /* determine the filename */
2079 // "stats_compbnd" + (if useMaxRangeMidrangeHeuristic && useMostDistinctMedianHeuristic ? "" : (if useMaxRangeMidrangeHeuristic ? "-mrm" : "-mdm")) + (if stabilization_tree ? "+dvs" : "") + ".csv"
2080
2081 char filename[SCIP_MAXSTRLEN];
2082 (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "stats_compbnd%s%s.csv",
2083 branchruledata->useMaxRangeMidrangeHeuristic && branchruledata->useMostDistinctMedianHeuristic ? "" :
2084 (branchruledata->useMaxRangeMidrangeHeuristic ? "-mrm" : "-mdm"),
2085 stabilization_tree ? "+dvs" : "");
2086
2087 /* create the file with header, if not exists */
2088 branchruledata->statsfile = fopen(filename, "r");
2089 if( branchruledata->statsfile == NULL )
2090 {
2091 branchruledata->statsfile = fopen(filename, "w");
2092 assert(branchruledata->statsfile != NULL);
2093 fprintf(branchruledata->statsfile, "depth,num_bounds,sum,K\n");
2094 }
2095 else
2096 {
2097 fclose(branchruledata->statsfile);
2098 branchruledata->statsfile = fopen(filename, "a");
2099 assert(branchruledata->statsfile != NULL);
2100 }
2101#endif
2102
2103 return SCIP_OKAY;
2104}
2105
2106/*
2107 * branching rule specific interface methods
2108 */
2109
2110/** creates the compbnd branching rule and includes it in SCIP */
2112 GCG* gcg /**< GCG data structure */
2113)
2114{
2115 SCIP* masterprob;
2116 SCIP* origprob;
2117 SCIP_BRANCHRULEDATA* branchruledata;
2118 SCIP_BRANCHRULE* branchrule;
2119
2120 SCIP_UNUSED(chooseClosestToKHalf);
2121
2122 masterprob = GCGgetMasterprob(gcg);
2123 assert(masterprob != NULL);
2124 origprob = GCGgetOrigprob(gcg);
2125 assert(origprob != NULL);
2126
2127 /* create compbnd branching rule data */
2128 SCIP_CALL( SCIPallocBlockMemory(masterprob, &branchruledata) );
2129 branchruledata->gcg = gcg;
2130 branchruledata->gcgbranchrule = NULL;
2131
2132 SCIPdebugMessage("Include method of component bound branching\n");
2133
2134 /* include branching rule */
2135 SCIP_CALL( GCGrelaxIncludeBranchrule(branchruledata->gcg, &branchrule, &branchruledata->gcgbranchrule, BRANCHRULE_NAME,
2136 BRANCHRULE_DESC, BRANCHRULE_PRIORITY, BRANCHRULE_MAXDEPTH, BRANCHRULE_MAXBOUNDDIST, branchruledata, branchActiveMasterCompBnd,
2137 branchDeactiveMasterCompBnd, branchPropMasterCompBnd, branchMasterSolvedCompBnd, branchDataDeleteCompBnd,
2138 branchNewColCompBnd, branchGetExtendedmasterconsCompBnd, branchGetExtendedmasterconsCoeffCompBnd) );
2139 SCIP_CALL( SCIPsetBranchruleInit(masterprob, branchrule, branchInitCompBnd) );
2140 SCIP_CALL( SCIPsetBranchruleFree(masterprob, branchrule, branchFreeCompBnd) );
2141 SCIP_CALL( SCIPsetBranchruleExecLp(masterprob, branchrule, branchExeclpCompBnd) );
2142 SCIP_CALL( SCIPsetBranchruleExecExt(masterprob, branchrule, branchExecextCompBnd) );
2143 SCIP_CALL( SCIPsetBranchruleExecPs(masterprob, branchrule, branchExecpsCompBnd) );
2144
2145 /* add compbnd branching rule parameters */
2146 SCIP_CALL( SCIPaddBoolParam(origprob, "branching/compbnd/useMRMH",
2147 "should the max range midrange heuristic be used?", &branchruledata->useMaxRangeMidrangeHeuristic, FALSE, TRUE, NULL, NULL) );
2148 SCIP_CALL( SCIPaddBoolParam(origprob, "branching/compbnd/useMDMH",
2149 "should the most distinct median heuristic be used?", &branchruledata->useMostDistinctMedianHeuristic, FALSE, TRUE, NULL, NULL) );
2150
2151 branchrule = SCIPfindBranchrule(masterprob, BRANCHRULE_NAME);
2152 assert(branchrule != NULL);
2153
2154 return SCIP_OKAY;
2155}
2156
2157/** returns true when the branch rule is the component bound branching rule */
2159 SCIP_BRANCHRULE* branchrule /**< branchrule to check */
2160)
2161{
2162 return (branchrule != NULL) && (strcmp(BRANCHRULE_NAME, SCIPbranchruleGetName(branchrule)) == 0);
2163}
#define BRANCHRULE_DESC
static SCIP_DECL_BRANCHINIT(branchInitCompBnd)
static SCIP_Bool isMasterVarInCompBndSeq(SCIP *scip, SCIP_VAR *mastervar, GCG_COMPBND *compBndSeq, int compBndSeqSize, int blocknr)
static GCG_DECL_BRANCHPROPMASTER(branchPropMasterCompBnd)
#define BRANCHRULE_PRIORITY
static SCIP_Real calcSum(SCIP *masterscip, GCG_COMPBND *compBndSeq, int compBndSeqSize, int blocknr)
static SCIP_Real calcFractionality(SCIP *masterscip, SCIP_VAR **mastervars, int nmastervars)
SCIP_RETCODE GCGincludeBranchruleCompBnd(GCG *gcg)
static SCIP_RETCODE initIndexSet(SCIP *scip, SCIP_VAR ***indexSet, int *indexSetSize, SCIP_VAR **mastervars, int mastervarsSize)
static SCIP_RETCODE initBranch(GCG *gcg, GCG_BRANCHRULE *branchrule, SCIP_RESULT *result)
static GCG_DECL_BRANCHGETEXTENDEDMASTERCONSCOEFF(branchGetExtendedmasterconsCoeffCompBnd)
static SCIP_RETCODE separation_helper(GCG *gcg, SCIP_VAR **satisfyingMastervars, int satisfyingMastervarsSize, GCG_COMPBND *compBndSeq, int compBndSeqSize, int blocknr, CHOOSE_COMPBND((*chooseCompBnd)), GCG_COMPBND ***foundCompBndSeqList, int **foundCompBndSeqSizeList, int *foundCompBndSeqListSize, SCIP_RESULT *result)
static GCG_DECL_BRANCHNEWCOL(branchNewColCompBnd)
#define FLOOR(scip, x)
static SCIP_RETCODE findSatisfyingMastervars(SCIP *masterscip, SCIP_VAR ***satisfyingMastervars, int *satisfyingMastervarsSize, int blocknr, GCG_COMPBND *compBndSeq, int compBndSeqSize)
#define BRANCHRULE_NAME
SCIP_Bool GCGisBranchruleCompBnd(SCIP_BRANCHRULE *branchrule)
#define CHOOSE_COMPBNDSEQ(x)
static SCIP_Real getLowerBound(SCIP *scip, SCIP_VAR *origvar, GCG_COMPBND *compBndSeq, int compBndSeqSize)
static SCIP_RETCODE addVarToMasterbranch(GCG *gcg, SCIP_VAR *mastervar, GCG_BRANCHDATA *branchdata)
static SCIP_DECL_BRANCHEXECLP(branchExeclpCompBnd)
static SCIP_DECL_BRANCHFREE(branchFreeCompBnd)
#define CEIL(scip, x)
static SCIP_DECL_BRANCHEXECEXT(branchExecextCompBnd)
static GCG_DECL_BRANCHGETEXTENDEDMASTERCONS(branchGetExtendedmasterconsCompBnd)
#define branchMasterSolvedCompBnd
static SCIP_RETCODE separation(GCG *gcg, GCG_BRANCHRULE *branchrule, GCG_COMPBND **compBndSeq, int *compBndSeqSize, int blocknr, SCIP_RESULT *result)
static SCIP_DECL_BRANCHEXECPS(branchExecpsCompBnd)
static SCIP_RETCODE createBranchingCons(GCG *gcg, GCG_BRANCHRULE *branchrule, SCIP_NODE *node, GCG_BRANCHDATA *branchdata)
static SCIP_RETCODE simplifyComponentBoundSequence(SCIP *scip, GCG_COMPBND **compBndSeq, int *compBndSeqSize)
static SCIP_Real getGeneratorEntryCol(SCIP_VAR **solvars, SCIP_Real *solvals, int nsolvars, SCIP_VAR *origvar)
static GCG_DECL_BRANCHDEACTIVEMASTER(branchDeactiveMasterCompBnd)
static SCIP_Bool isColInCompBndSeq(SCIP *scip, SCIP_VAR **solvars, SCIP_Real *solvals, int nsolvars, GCG_COMPBND *compBndSeq, int compBndSeqSize)
static SCIP_Real getUpperBound(SCIP *scip, SCIP_VAR *origvar, GCG_COMPBND *compBndSeq, int compBndSeqSize)
static SCIP_RETCODE initNodeBranchdata(SCIP *scip, GCG_BRANCHDATA **nodebranchdata, GCG_BRANCH_TYPE branchtype, int constant, GCG_COMPBND *compBndSeq, int compBndSeqSize, int blocknr)
static GCG_DECL_BRANCHDATADELETE(branchDataDeleteCompBnd)
#define BRANCHRULE_MAXDEPTH
#define CHOOSE_COMPBND(x)
static GCG_DECL_BRANCHACTIVEMASTER(branchActiveMasterCompBnd)
#define BRANCHRULE_MAXBOUNDDIST
static SCIP_RETCODE createChildNodesCompBndSeq(GCG *gcg, GCG_BRANCHRULE *branchrule, GCG_COMPBND *compBndSeq, int compBndSeqSize, int blocknr)
static void freeComponentBoundSequence(SCIP *scip, GCG_COMPBND **compBndSeq, int *compBndSeqSize)
static SCIP_Real getGeneratorEntry(SCIP_VAR *mastervar, SCIP_VAR *origvar)
component bound branching rule
GCG_COMPBND_SENSE
@ GCG_COMPBND_SENSE_LE
@ GCG_COMPBND_SENSE_GE
GCG_BRANCH_TYPE
@ GCG_BRANCH_DOWN
@ GCG_BRANCH_UP
struct ComponentBound GCG_COMPBND
SCIP_BRANCHRULEDATA * GCGbranchGetScipBranchruledata(GCG_BRANCHRULE *branchrule)
Definition: branchgcg.c:113
SCIP_RETCODE GCGbranchFreeExtendedmasterconsBranchData(GCG *gcg, GCG_EXTENDEDMASTERCONSDATA **extendedmasterconsdata)
Definition: branchgcg.c:83
SCIP_RETCODE GCGbranchCreateExtendedmastercons(GCG *gcg, GCG_BRANCHRULE *branchrule, GCG_EXTENDEDMASTERCONSDATA **extendedmasterconsdata, SCIP_CONS *cons, GCG_PRICINGMODIFICATION **pricingmodifications, int npricingmodifications, GCG_BRANCHDATA *branchdata)
Definition: branchgcg.c:41
SCIP_BRANCHRULE * GCGbranchGetScipBranchrule(GCG_BRANCHRULE *branchrule)
Definition: branchgcg.c:102
SCIP_RETCODE GCGbranchGetExtendedmasterconsCoeff(GCG *gcg, GCG_EXTENDEDMASTERCONSDATA *extendedmasterconsdata, SCIP_VAR **solvars, SCIP_Real *solvals, int nsolvars, int probnr, GCG_COL *gcgcol, SCIP_Real *coeff)
Definition: branchgcg.c:61
constraint handler for the integrality constraint
SCIP_CONS * GCGconsMasterbranchGetActiveCons(GCG *gcg)
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
#define SCIP_MAXSTRLEN
#define SCIP_Longint
#define SCIP_INVALID
#define SCIP_Bool
#define MIN(x, y)
#define SCIP_Real
#define ABS(x)
#define MAX(x, y)
#define SCIP_CALL(x)
#define TRUE
#define FALSE
SCIP_RETCODE GCGextendedmasterconsAddMasterVar(GCG *gcg, GCG_EXTENDEDMASTERCONSDATA *extendedmasterconsdata, SCIP_VAR *var, SCIP_Real coef)
internal methods for interacting with GCG_EXTENDEDMASTERCONSDATA
GCG interface methods.
SCIP_Bool GCGvarIsOriginal(SCIP_VAR *var)
Definition: gcgvar.c:231
SCIP_RETCODE GCGcreateInferredPricingVar(SCIP *pricingscip, SCIP_VAR **newvar, const char *varname, SCIP_Real lb, SCIP_Real ub, SCIP_Bool iscoefvar, SCIP_Real objcoeff, SCIP_VARTYPE vartype, int prob)
Definition: gcgvar.c:1674
int GCGmasterVarGetNOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:971
SCIP_VAR * GCGoriginalVarGetPricingVar(SCIP_VAR *var)
Definition: gcgvar.c:281
SCIP_Bool GCGisMasterVarInBlock(SCIP_VAR *mastervar, int block)
Definition: gcgvar.c:1169
SCIP_VAR ** GCGmasterVarGetOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:993
SCIP_Bool GCGvarIsMaster(SCIP_VAR *var)
Definition: gcgvar.c:176
SCIP_Real * GCGmasterVarGetOrigvals(SCIP_VAR *var)
Definition: gcgvar.c:1017
SCIP_Real GCGmasterVarGetOrigval(SCIP_VAR *mastervar, SCIP_VAR *origvar)
Definition: gcgvar.c:1034
int GCGvarGetBlock(SCIP_VAR *var)
Definition: gcgvar.c:1118
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)
SCIP_RETCODE SCIPcreateConsVarbound(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *var, SCIP_VAR *vbdvar, SCIP_Real vbdcoef, 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)
SCIP_RETCODE GCGpricingmodificationCreate(GCG *gcg, GCG_PRICINGMODIFICATION **pricingmodification, int blocknr, SCIP_VAR *coefvar, SCIP_VAR **additionalvars, int nadditionalvars, SCIP_CONS **additionalconss, int nadditionalconss)
GCG_EXPORT SCIP_Bool GCGisMasterSetPartitioning(GCG *gcg)
Definition: relax_gcg.c:4366
GCG_EXPORT SCIP * GCGgetPricingprob(GCG *gcg, int pricingprobnr)
Definition: relax_gcg.c:4075
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
GCG_EXPORT SCIP_Bool GCGisPricingprobRelevant(GCG *gcg, int pricingprobnr)
Definition: relax_gcg.c:4132
SCIP_Bool SCIPisStopped(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 SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
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 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)))
void SCIPbranchruleSetData(SCIP_BRANCHRULE *branchrule, SCIP_BRANCHRULEDATA *branchruledata)
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)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPallocBlockMemory(scip, ptr)
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
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 SCIPisPositive(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 SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfrac(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisGT(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_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
int SCIPgetDepth(SCIP *scip)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
#define NULL
#define SCIP_UNUSED(x)
GCG variable pricer.
public methods for interacting with GCG_EXTENDEDMASTERCONSDATA
public methods for GCG variables
#define SCIPerrorMessage
#define SCIPdebugMessage
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.
SCIP_VAR * component
GCG_COMPBND_SENSE sense
GCG_EXTENDEDMASTERCONSDATA * mastercons
GCG_COMPBND * compBndSeq
GCG_BRANCH_TYPE branchtype
Definition: struct_gcg.h:55
SCIP_Bool useMostDistinctMedianHeuristic
SCIP_Bool useMaxRangeMidrangeHeuristic
GCG_BRANCHRULE * gcgbranchrule
type definitions for branching rules in GCG projects
type definitions for extended master conss in GCG projects
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
SCIP_VARTYPE_BINARY