GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
branch_bpstrong.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_bpstrong.c
30 *
31 * @brief generic branch-and-price strong branching heuristics
32 * @author Oliver Gaul
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36/*#define SCIP_DEBUG*/
37#include <assert.h>
38
39#include "gcg/branch_bpstrong.h"
40#include "gcg/type_branchgcg.h"
41#include "gcg/branch_orig.h"
42
43#include <string.h>
44
45#include "gcg/gcg.h"
49#include "gcg/cons_origbranch.h"
50#include "gcg/relax_gcg.h"
51#include "gcg/pricer_gcg.h"
52#include "gcg/type_branchgcg.h"
53
54#include "scip/cons_linear.h"
55#include "scip/scipdefplugins.h"
56#include "scip/var.h"
57
58#define BRANCHRULE_NAME "bpstrong" /**< name of branching rule */
59#define BRANCHRULE_DESC "strong branching for branch-and-price" /**< short description of branching rule */
60#define BRANCHRULE_PRIORITY -536870912 /**< priority of this branching rule */
61#define BRANCHRULE_MAXDEPTH 0 /**< maximal depth level of the branching rule */
62#define BRANCHRULE_MAXBOUNDDIST 0.0 /**< maximal relative distance from current node's
63 * dual bound to primal bound compared to best node's
64 * dual bound for applying branching */
65#define DEFAULT_ENFORCEBYCONS FALSE
66#define DEFAULT_MOSTFRAC FALSE
67#define DEFAULT_USEPSEUDO TRUE
68#define DEFAULT_USEPSSTRONG FALSE
69
70#define DEFAULT_USESTRONG FALSE
71#define DEFAULT_STRONGLITE FALSE
72#define DEFAULT_STRONGTRAIN FALSE
73#define DEFAULT_IMMEDIATEINF TRUE
74#define DEFAULT_MAXSBLPITERS INT_MAX
75#define DEFAULT_MAXSBPRICEROUNDS INT_MAX
76
77#define DEFAULT_RFUSEPSEUDOCOSTS TRUE
78#define DEFAULT_RFUSEMOSTFRAC FALSE
79
80#define DEFAULT_REEVALAGE 1
81#define DEFAULT_MINCOLGENCANDS 4
82#define DEFAULT_HISTWEIGHT 0.5
83#define DEFAULT_MAXLOOKAHEAD 8
84#define DEFAULT_LOOKAHEADSCALES 0.5
85#define DEFAULT_MINPHASE0DEPTH 0
86#define DEFAULT_MAXPHASE1DEPTH 4
87#define DEFAULT_MAXPHASE2DEPTH 3
88#define DEFAULT_DEPTHLOGWEIGHT 0.5
89#define DEFAULT_DEPTHLOGBASE 3.5
90#define DEFAULT_DEPTHLOGPHASE0FRAC 0
91#define DEFAULT_DEPTHLOGPHASE2FRAC 0.75
92
93#define DEFAULT_CLOSEPERCENTAGE 0.90
94#define DEFAULT_MAXCONSECHEURCLOSE 4
95
96#define DEFAULT_SBPSEUDOCOSTWEIGHT 1
97
98#define DEFAULT_PHASE1RELIABLE INT_MAX
99#define DEFAULT_PHASE2RELIABLE INT_MAX
100
101#define DEFAULT_FORCEP0 FALSE
102
103#define ORIG 0
104#define RYANFOSTER 1
105#define GENERIC 2
106
107
108/** branching data for branching decisions (for Ryan-Foster branching) */
110{
111 SCIP_VAR* var1; /**< first original variable on which the branching is done */
112 SCIP_VAR* var2; /**< second original variable on which the branching is done */
113 SCIP_Bool same; /**< should each master var contain either both or none of the vars? */
114 int blocknr; /**< number of the block in which branching was performed */
115 SCIP_CONS* pricecons; /**< constraint enforcing the branching restriction in the pricing
116 problem */
117};
118
119/* stores candidates and their corresponding index to insert them into a hashtable */
125
126/** branching rule data */
128{
129 GCG* gcg; /**< GCG data structure */
130 int lastcand; /**< last evaluated candidate of last branching rule execution */
131 int nvars; /**< the number of candidates currently in the hashtable */
132 int maxvars; /**< the maximal number of cands that were in the hashtable at the same
133 * time */
134 int maxcands; /**< (realistically) the maximum total amount of candidates */
135 SCIP_HASHTABLE* candhashtable; /**< hashtable mapping candidates to their index */
136 VarTuple **vartuples; /**< all VarTuples that are in candhashtable */
137 SCIP_Real *score; /**< the candidates' last scores */
138 int *uniqueblockflags; /**< flags assigned by assignUniqueBlockFlags() */
139 SCIP_Real *strongbranchscore; /**< the candidates' last scores from strong branching with column
140 * generation */
141 SCIP_Bool *sbscoreisrecent; /**< was the score saved in strongbranchscore computed in a parent of
142 * the current node where all node on the path to the parent were
143 * created for domain reduction due to infeasibility? */
144 int *lastevalnode; /**< the last node at which the candidates were evaluated */
145
146 int nphase1lps; /**< number of phase 1 lps solved */
147 int nphase2lps; /**< number of phase 2 lps solved */
148 SCIP_Longint nsblpiterations; /**< total number of strong branching lp iterations during phase 1 */
149 int nsbpricerounds; /**< total number of strong branching pricing rounds */
150
151 int initiator; /**< the identifier of the branching rule that initiated strong
152 * branching */
153 GCG_BRANCHRULE* initiatorbranchrule; /**< the branching rule that initiated strong branching */
154
155 SCIP_Bool mostfrac; /**< should most infeasible/fractional branching be used in phase 0? */
156 SCIP_Bool usepseudocosts; /**< should pseudocost branching be used in phase 0? */
157
158 SCIP_Bool usestronglite; /**< should strong branching use column generation during variable
159 * evaluation? */
160 SCIP_Bool usestrongtrain; /**< should strong branching run as precise as possible
161 * (to generate more valuable training data, currently not
162 * implemented)? */
163 SCIP_Bool immediateinf; /**< should infeasibility detected during strong branching be handled
164 * immediately, or only if the variable is selected? */
165 SCIP_Longint maxsblpiters; /**< maximum number of strong branching lp iterations, set to 2*avg lp
166 * iterations if <= 0 */
167 int maxsbpricerounds; /**< maximum number of strong branching pricing rounds, set to 2*avg lp
168 * iterations if <= 0 */
169 int reevalage; /**< how many times can bounds be changed due to infeasibility during
170 * strong branching until an already evaluated variable needs to be
171 * reevaluated? */
172 int mincolgencands; /**< minimum number of variables for phase 2 to be executed, otherwise
173 * the best candidate from phase 1 will be chosen */
174
175 int minphase0depth; /**< minimum tree depth from which on phase 0 is performed (~ hybrid
176 * branching) */
177 int maxphase1depth; /**< maximum tree depth up to which phase 1 is performed (~ hybrid
178 * branching) */
179 int maxphase2depth; /**< maximum tree depth up to which phase 2 is performed (~ hybrid
180 * branching) */
181
182 int minphase0outcands; /**< minimum number of output candidates from phase 0 */
183 int maxphase0outcands; /**< maximum number of output candidates from phase 0 */
184 SCIP_Real maxphase0outcandsfrac; /**< maximum number of output candidates from phase 0 as fraction of
185 * total cands */
186 SCIP_Real phase1gapweight; /**< how much impact should the node gap have on the number of
187 * precisely evaluated candidates in phase 1? */
188
189 int minphase1outcands; /**< minimum number of output candidates from phase 1 */
190 int maxphase1outcands; /**< maximum number of output candidates from phase 1 */
191 SCIP_Real maxphase1outcandsfrac; /**< maximum number of output candidates from phase 0 as fraction of
192 * phase 1 candidates */
193 SCIP_Real phase2gapweight; /**< how much impact should the node gap have on the number of
194 * precisely evaluated candidates in phase 2? */
195 int maxlookahead; /**< maximum number of non-improving candidates until phase 2 is
196 * stopped */
197 SCIP_Real lookaheadscales; /**< how much should the look ahead scale with the overall evaluation
198 * effort? (0 = not at all, 1 = fully) */
199
200 SCIP_Real histweight; /**< how many candidates should be chosen based on historical strong
201 * branching scores as opposed to current heuristic scores in phase 0
202 * (e.g. 0.5 = 50%)? */
203
204 SCIP_Real closepercentage; /**< what percentage of the strong branching score of the candidate
205 * that was selected does the best candidate according to the phase 0
206 * heuristic need to have to be considered close? */
207 int consecheurclose; /**< how many times in a row the best candidate according to the phase
208 * 0 heuristic was close to that selected by SBw/CG */
209 int maxconsecheurclose; /**< how many times in a row can the heuristic be close before strong
210 * branching is stopped? */
211
212 SCIP_Bool done; /**< has any of the permanent stopping criteria been reached? */
213
214 SCIP_Real sbpseudocostweight; /**< with how much weight should strong branching scores be considered
215 * for pseudocost scores? */
216
217 int phase1reliable; /**< min count of pseudocost scores for a variable to be considered
218 * reliable in phase 1 (~ reliability branching) */
219 int phase2reliable; /**< min count of pseudocost scores for a variable to be considered
220 * reliable in phase 2 (~ reliability branching) */
221
222 SCIP_Bool forcephase0; /**< should phase 0 be performed even if the number of input candidates
223 * is already lower or equal to the number of output candidates? */
224
225 SCIP_Bool initialized; /**< has the branching rule been initialized? */
226};
227
228/* needed for compare_function (for now) */
230#pragma omp threadprivate(this_branchruledata)
231
232/*
233 * Hash functions
234 */
235
236/** gets the hash key of a variable tuple */
237static
238SCIP_DECL_HASHGETKEY(hashGetKeyVars)
239{
240 VarTuple* vars;
241
242 vars = (VarTuple*)elem;
243 assert(vars != NULL);
244
245 /* the key of a variable tuple is the variable tuple itself */
246 return vars;
247}
248
249/** returns TRUE iff both variable tuples contain the same variables (ignoring order) */
250static
252{
253 VarTuple* vars1;
254 VarTuple* vars2;
255
256 vars1 = (VarTuple*)key1;
257 vars2 = (VarTuple*)key2;
258 assert(vars1 != NULL);
259 assert(vars2 != NULL);
260
261 /* check if first variable is equal */
262 if( SCIPvarGetIndex(vars1->var1) != SCIPvarGetIndex(vars2->var1) )
263 return FALSE;
264
265 /* second variable might be NULL */
266 if( (vars1->var2 == NULL) && (vars2->var2 == NULL) )
267 return TRUE;
268
269 if( (vars1->var2 == NULL) || (vars2->var2 == NULL) )
270 return FALSE;
271
272 /* check if second variable is equal */
273 if( SCIPvarGetIndex(vars1->var2) != SCIPvarGetIndex(vars2->var2) )
274 return FALSE;
275
276 return TRUE;
277}
278
279static
280SCIP_DECL_HASHKEYVAL(hashKeyValVars)
281{
282 VarTuple* vars;
283 unsigned int hashvalue;
284 SCIP_VAR* var1;
285 SCIP_VAR* var2;
286
287 vars = (VarTuple*)key;
288 assert(vars != NULL);
289
290 var1 = vars->var1;
291 var2 = vars->var2;
292
293 /* return hashvalue of indices */
294 if( var2 == NULL )
295 hashvalue = SCIPhashSignature64( SCIPvarGetIndex(var1) );
296 else
297 hashvalue = SCIPhashTwo( MIN( SCIPvarGetIndex(var1), SCIPvarGetIndex(var2) ), MAX( SCIPvarGetIndex(var1), SCIPvarGetIndex(var2) ) );
298
299 return hashvalue;
300}
301
302/* calculates the number of needed candidates based on the min and max number of candidates as well as the node gap */
303static
305 SCIP* scip, /**< scip data structure */
306 SCIP_BRANCHRULEDATA* branchruledata, /**< strong branching branchruledata */
307 SCIP_Real nodegap, /**< node gap in current focus node */
308 int phase, /**< phase we are calculating this for */
309 int ncands /**< number of input candidates for the phase */
310)
311{
312 int min;
313 int max;
314 int dif;
315 SCIP_Real gapweight;
316 SCIP_Real candfrac;
317
318 if( phase == 0 )
319 {
320 min = branchruledata->minphase0outcands;
321 max = branchruledata->maxphase0outcands;
322 candfrac = branchruledata->maxphase0outcandsfrac;
323 gapweight = branchruledata->phase1gapweight;
324 }
325 else
326 {
327 min = branchruledata->minphase1outcands;
328 max = branchruledata->maxphase1outcands;
329 candfrac = branchruledata->maxphase1outcandsfrac;
330 gapweight = branchruledata->phase2gapweight;
331 }
332
333 dif = max-min;
334
335 assert(min >= 1);
336
337 return MIN( candfrac*ncands,
338 min + (int) SCIPceil(scip, MIN( dif, dif * nodegap * gapweight + dif * (1-gapweight) )) );
339}
340
341/* assigns a flag to the given branching candidate based on the block it is in
342 *
343 * return 1: integer variables belonging to a unique block with fractional value
344 * return 0: variables that belong to no block but were directly transferred to the
345 * master problem and which have a fractional value in the current solution
346 * return -1: neither
347 */
348static
350 GCG* gcg, /**< GCG data structure */
351 SCIP_VAR* branchcand /**< branching candidate to be considered */
352)
353{
355 assert(GCGvarIsOriginal(branchcand));
356
357 for ( int iter = 0; iter <= 1; iter++ )
358 {
359 /* continue if variable belongs to a block in second iteration*/
360 if (iter == 0)
361 {
362 /* variable belongs to no block */
363 if ( GCGvarGetBlock(branchcand) == -1 )
364 continue;
365
366 /* block is not unique (non-linking variables) */
367 if ( !GCGoriginalVarIsLinking(branchcand) && GCGgetNIdenticalBlocks(gcg, GCGvarGetBlock(branchcand)) != 1 )
368 continue;
369
370 /* check that blocks of linking variable are unique */
371 if ( GCGoriginalVarIsLinking(branchcand) )
372 {
373 int nvarblocks;
374 int *varblocks;
375 SCIP_Bool unique;
376 int j;
377
378 nvarblocks = GCGlinkingVarGetNBlocks(branchcand);
379 SCIP_CALL( SCIPallocBufferArray(origprob, &varblocks, nvarblocks) );
380 SCIP_CALL( GCGlinkingVarGetBlocks(branchcand, nvarblocks, varblocks) );
381
382 unique = TRUE;
383 for ( j = 0; j < nvarblocks; ++j )
384 if ( GCGgetNIdenticalBlocks(gcg, varblocks[j]) != 1 )
385 unique = FALSE;
386
387 SCIPfreeBufferArray(origprob, &varblocks);
388
389 if( !unique )
390 continue;
391 }
392 /* candidate is valid in first iteration */
393 return 1;
394 }
395 else /* iter == 1 */
396 {
397 if ( GCGvarGetBlock(branchcand) != -1 )
398 return -1;
399
400 /* candidate is valid in second iteration */
401 return 0;
402 }
403 }
404 return -1;
405}
406
407/** adds branching candidates to branchruledata to collect infos about it */
408static
410 GCG* gcg, /**< GCG data structure */
411 SCIP_BRANCHRULE* branchrule, /**< branching rule */
412 SCIP_VAR** var1s, /**< first parts of branching candidates */
413 SCIP_VAR** var2s, /**< second parts of branching candidates */
414 int ncands /**< number of priority branching candidates */
415 )
416{
418 SCIP_BRANCHRULEDATA* branchruledata;
419 int i;
420 VarTuple* vartuple = NULL;
421 int nvars;
422 int newsize;
423
424 /* get branching rule data */
425 branchruledata = SCIPbranchruleGetData(branchrule);
426 assert(branchruledata != NULL);
427
429
430 /* if var is not in hashtable, insert it */
431 for( i = 0; i < ncands; i++ )
432 {
433 nvars = branchruledata->nvars;
434
435 /* if variable is not in hashmtable insert it, initialize its array entries, and increase array sizes */
437 vartuple->var1 = var1s[i];
438 vartuple->var2 = var2s!=NULL? var2s[i] : NULL;
439 vartuple->index = nvars;
440
441 if( !SCIPhashtableExists(branchruledata->candhashtable, (void *) vartuple) )
442 {
443 newsize = SCIPcalcMemGrowSize(masterprob, nvars + 1);
445 branchruledata->maxvars, newsize) );
447 branchruledata->maxvars, newsize) );
448 SCIP_CALL( SCIPreallocBlockMemoryArray(masterprob, &branchruledata->lastevalnode, branchruledata->maxvars,
449 newsize) );
451 branchruledata->maxvars, newsize) );
453 branchruledata->maxvars, newsize) );
454 branchruledata->maxvars = newsize;
455
456 branchruledata->strongbranchscore[nvars] = -1;
457 branchruledata->sbscoreisrecent[nvars] = FALSE;
458 branchruledata->lastevalnode[nvars] = -1;
459 branchruledata->uniqueblockflags[nvars] = -2;
460 branchruledata->vartuples[nvars] = vartuple;
462 (void*) branchruledata->vartuples[nvars]) );
463
464 assert(SCIPhashtableExists(branchruledata->candhashtable, (void*) branchruledata->vartuples[nvars])
465 && ( (VarTuple *) SCIPhashtableRetrieve(branchruledata->candhashtable,
466 (void*) branchruledata->vartuples[nvars]) )->index == nvars);
467
468 ++(branchruledata->nvars);
469 }
470 else
471 {
473 }
474 }
475
476 return SCIP_OKAY;
477}
478
479/* compare two indices corresponding to entries in branchruledata->score, returns TRUE iff the first elements score is
480 * larger
481 */
483 const void *index1, /**< index in branchruledata->score of first element */
484 const void *index2 /**< index in branchruledata->score of first element */
485 )
486{
487 return this_branchruledata->score[*(int *)index1] > this_branchruledata->score[*(int *)index2]? -1 : 1;
488}
489
490/* compare two indices based on descending numerical order, returns TRUE iff the first index is smaller */
492 const void *index1, /**< first index */
493 const void *index2 /**< second index */
494 )
495{
496 return *(int *)index1 < *(int *)index2? -1 : 1;
497}
498
499/* creates a probing node that is "equal" to the same or differ branch of a given Ryan-Foster candidate, mostly copied
500 * from the corresponding method in branch_ryanfoster.c
501 */
502static
504 GCG* gcg, /**< GCG data structure */
505 GCG_BRANCHRULE* branchrule, /**< branching rule */
506 SCIP_VAR* ovar1, /**< first original variable */
507 SCIP_VAR* ovar2, /**< second original variable */
508 int blocknr, /**< number of the pricing block */
509 SCIP_Bool same /**< do we want to create the same (TRUE) or differ (FALSE) branch? */
510 )
511{
512 SCIP* origprob;
514 SCIP_VAR* pricingvar1;
515 SCIP_VAR* pricingvar2;
516 GCG_BRANCHDATA* branchdata;
517 char name[SCIP_MAXSTRLEN];
518
519 SCIP_VAR** origvars1;
520 SCIP_VAR** origvars2;
521 int norigvars;
522 int maxorigvars;
523 int v;
524
525 SCIP_CONS** origbranchconss;
526
528
529 assert(origprob != NULL);
530 assert(branchrule != NULL);
531 assert(ovar1 != NULL);
532 assert(ovar2 != NULL);
533 assert(GCGvarIsOriginal(ovar1));
534 assert(GCGvarIsOriginal(ovar2));
535
536 origbranchconss = NULL;
537
540
541 /* for cons_masterbranch */
542
543 /* allocate branchdata for same child and store information */
544 SCIP_CALL( SCIPallocBlockMemory(origprob, &branchdata) );
545 branchdata->var1 = ovar1;
546 branchdata->var2 = ovar2;
547 branchdata->same = same;
548 branchdata->blocknr = blocknr;
549 branchdata->pricecons = NULL;
550
551 /* define name for origbranch constraints */
552 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s(%s,%s)", same? "same" : "differ", SCIPvarGetName(branchdata->var1),
553 SCIPvarGetName(branchdata->var2));
554
555 pricingvar1 = GCGoriginalVarGetPricingVar(branchdata->var1);
556 pricingvar2 = GCGoriginalVarGetPricingVar(branchdata->var2);
557 assert(GCGvarIsPricing(pricingvar1));
558 assert(GCGvarIsPricing(pricingvar2));
559 assert(GCGvarGetBlock(pricingvar1) == GCGvarGetBlock(pricingvar2));
560 assert(GCGpricingVarGetNOrigvars(pricingvar1) == GCGpricingVarGetNOrigvars(pricingvar2));
561
562 norigvars = GCGpricingVarGetNOrigvars(pricingvar1);
563 assert(norigvars == GCGpricingVarGetNOrigvars(pricingvar2));
564
565 origvars1 = GCGpricingVarGetOrigvars(pricingvar1);
566 origvars2 = GCGpricingVarGetOrigvars(pricingvar2);
567
568 if( norigvars > 0 )
569 {
570 maxorigvars = SCIPcalcMemGrowSize(masterprob, norigvars);
571 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &origbranchconss, maxorigvars) );
572 }
573 else
574 {
575 maxorigvars = 0;
576 }
577
578 /* add branching decision as varbound constraints to original problem */
579 for( v = 0; v < norigvars; v++ )
580 {
581 SCIP_CONS* origcons;
582
583 assert(GCGvarGetBlock(origvars1[v]) == GCGvarGetBlock(origvars2[v]));
584 assert(origbranchconss != NULL);
585
586 /* create constraint for same-child */
587 SCIP_CALL( SCIPcreateConsVarbound(origprob, &origcons, name, origvars1[v], origvars2[v],
588 same? -1.0 : 1.0, same ? 0.0 : -SCIPinfinity(origprob), same? 0.0 : 1.0, TRUE, TRUE,
590
591 origbranchconss[v] = origcons;
592 }
593
594 /* create and add the masterbranch constraints */
595 SCIP_CALL( GCGrelaxNewProbingnodeMasterCons(gcg, branchrule, branchdata, origbranchconss, norigvars,
596 maxorigvars) );
597
598 return SCIP_OKAY;
599}
600
601/* executes strong branching on one variable, with or without pricing */
602static
604 GCG* gcg, /* GCG data structure */
605 SCIP_BRANCHRULE* branchrule, /* pointer to the branching rule */
606 SCIP_VAR *branchvar1, /* first variable to get strong branching values for */
607 SCIP_VAR *branchvar2, /* second variable to get strong branching values for */
608 SCIP_Real solval1, /* value of the first variable in the current solution */
609 SCIP_Real solval2, /* value of the second variable in the current solution */
610 int candinfo, /* additional intager information about the candidate */
611 SCIP_Bool pricing, /* should pricing be applied? */
612 int maxpricingrounds, /* maximal number of pricing rounds, -1 for no limit */
613 SCIP_Real *up, /* stores dual bound for up/same child */
614 SCIP_Real *down, /* stores dual bound for down/differ child */
615 SCIP_Bool *upvalid, /* stores whether the up/samebranch was solved properly */
616 SCIP_Bool *downvalid, /* stores whether the down/differbranch was solved properly */
617 SCIP_Bool *upinf, /* stores whether the up/samebranch is infeasible */
618 SCIP_Bool *downinf /* stores whether the down/differbranch is infeasible */
619 )
620{
621 /* get bound values */
622 SCIP_BRANCHRULEDATA* branchruledata;
623 SCIP* origprob;
624
628
629 branchruledata = SCIPbranchruleGetData(branchrule);
630 assert(branchruledata != NULL);
632
633 *downvalid = FALSE;
634 *upvalid = FALSE;
635 *downinf = FALSE;
636 *upinf = FALSE;
637
638 assert(origprob != NULL);
639
640 /* probe for each child node */
641 for( int cnode = 0; cnode <= 1; cnode++ )
642 {
643 /* start probing */
646
647 cutoff = FALSE;
648 lperror = FALSE;
649 lpsolved = FALSE;
650
651 if( branchruledata->initiator == ORIG )
652 {
653 if( cnode == 0 )
654 {
656 }
657 else
658 {
660 }
661 }
662
663 /* propagate the new b&b-node */
665
666 /* solve the LP with or without pricing */
667 if( !cutoff )
668 {
669 if( branchruledata->initiator == RYANFOSTER )
670 {
672 branchvar2, candinfo, cnode == 1) );
673 }
674 else
675 {
677 }
678
679 if( pricing )
680 {
681 int npricerounds;
682
684 cnode == 0? down : up, &lpsolved, &lperror, &cutoff) );
685 branchruledata->nphase2lps++;
686 branchruledata->nsbpricerounds += npricerounds;
687 }
688 else
689 {
691
693 cnode == 0? down : up, &lpsolved, &lperror, &cutoff) );
694 branchruledata->nphase1lps++;
695 branchruledata->nsblpiterations += nlpiterations;
696 }
697 }
698
699 if( cnode == 0 )
700 {
701 *downvalid = lpsolved;
702 *downinf = cutoff && pricing;
703 }
704 else
705 {
706 *upvalid = lpsolved;
707 *upinf = cutoff && pricing;
708 }
709
711 }
712 return SCIP_OKAY;
713}
714
715/* Returns true iff the second node is a k-successor of the to the first number corresponding node
716 * (i.e. iff there are at most k edges between them)
717 */
718static
720 SCIP* scip, /**< SCIP data structure */
721 int ancestornodenr, /**< number of the supposed ancestor */
722 SCIP_NODE *successornode, /**< the supposed successor */
723 int k /**< maximal allowed distance between the nodes */
724 )
725{
726 SCIP_NODE* curnode;
727 curnode = successornode;
728
729 for( int i = 0; i <= k && SCIPnodeGetNumber(curnode) >= ancestornodenr; i++ )
730 {
731 if( SCIPnodeGetNumber(curnode) == ancestornodenr )
732 return TRUE;
733
734 if( SCIPnodeGetNumber(curnode) == 1 )
735 break;
736
737 curnode = SCIPnodeGetParent(curnode);
738 }
739
740 return FALSE;
741}
742
743/* Evaluates the given variable based on a score function of choice. Higher scores are given to better variables. */
744static
746 GCG* gcg, /**< GCG data structure */
747 SCIP_BRANCHRULE* branchrule, /**< pointer to the branching rule */
748 SCIP_VAR *var1, /**< first var to be scored */
749 SCIP_VAR *var2, /**< second var to be scored */
750 SCIP_Real solval1, /**< the first var's current solution value */
751 SCIP_Real solval2, /**< the second var's current solution value */
752 int candinfo, /**< additional integer information about the candidate */
753 SCIP_Bool useheuristic, /**< should heuristics be used instead of strong branching? */
754 SCIP_Bool usehistorical, /**< should historical data from phase 2 be used as heuristic? */
755 SCIP_Bool usecolgen, /**< should column generation be used during strong branching? */
756 SCIP_Real *score, /**< stores the computed score */
757 SCIP_Bool *upinf, /**< stores whether the upbranch is infeasible */
758 SCIP_Bool *downinf /**< stores whether the downbranch is infeasible */
759 )
760{
761 SCIP* origprob;
762 SCIP_BRANCHRULEDATA* branchruledata;
763 VarTuple vartuple = {var1, var2, 0};
764
766 branchruledata = SCIPbranchruleGetData(branchrule);
767 assert(branchruledata != NULL);
768
769 /* define score functions and calculate score for all variables for sorting dependent on used heuristic */
770 /* phase 0 */
771 if( useheuristic)
772 {
773 if( usehistorical )
774 {
775 int hashindex;
776
777 assert(SCIPhashtableExists(branchruledata->candhashtable, (void *) &vartuple));
778 hashindex = ((VarTuple *) SCIPhashtableRetrieve(branchruledata->candhashtable, (void *) &vartuple))->index;
779
780 return branchruledata->strongbranchscore[hashindex];
781 }
782 else if( branchruledata->usepseudocosts )
783 {
784 *score = SCIPgetVarPseudocostScore(origprob, var1, solval1);
785 if( var2 != NULL )
786 *score = *score * SCIPgetVarPseudocostScore(origprob, var2, solval2);
787 }
788 else
789 {
790 if( !branchruledata->mostfrac )
791 return 1;
792
793 *score = solval1 - SCIPfloor(origprob, solval1);
794 *score = MIN( *score, 1.0 - *score );
795
796 if( var2 != NULL )
797 {
798 SCIP_Real frac2;
799
800 frac2 = solval2 - SCIPfloor(origprob, solval2);
801 *score = *score * MIN( frac2, 1.0 - frac2 );
802 }
803 }
804 }
805 else
806 /* phases 1 & 2 */
807 {
808 SCIP* masterscip;
809
810 int hashindex;
811 int currentnodenr;
812
813 SCIP_Real down;
814 SCIP_Real up;
815 SCIP_Real downgain;
816 SCIP_Real upgain;
817 SCIP_Bool upvalid;
818 SCIP_Bool downvalid;
819 SCIP_Real lpobjval;
820
822
823 /* get master problem */
824 masterscip = GCGgetMasterprob(gcg);
825 assert(masterscip != NULL);
826
827 assert(SCIPhashtableExists(branchruledata->candhashtable, &vartuple));
828 hashindex = ((VarTuple *) SCIPhashtableRetrieve(branchruledata->candhashtable, (void *) &vartuple))->index;
830
831 if( !usecolgen
832 || !branchruledata->sbscoreisrecent[hashindex]
833 || !isKAncestor(origprob, branchruledata->lastevalnode[hashindex], SCIPgetFocusNode(origprob),
834 branchruledata->reevalage) )
835 {
836 up = -SCIPinfinity(origprob);
837 down = -SCIPinfinity(origprob);
838
839 lpobjval = SCIPgetLPObjval(masterscip);
840
841 /* usecolgen is True for phase 1 and False for phase 2 */
842 SCIP_CALL( executeStrongBranching(gcg, branchrule, var1, var2, solval1, solval2, candinfo, usecolgen, -1,
843 &up, &down, &upvalid, &downvalid, upinf, downinf) );
844
845 down = downvalid? down : upvalid? up : 0;
846 up = upvalid? up : down;
847
848 downgain = MAX(down - lpobjval, 0.0);
849 upgain = MAX(up - lpobjval, 0.0);
850
851 *score = SCIPgetBranchScore(origprob, var1, downgain, upgain);
852
853 if( usecolgen && upvalid && downvalid )
854 {
855 frac = solval1 - SCIPfloor(origprob, solval1);
856 if( !*upinf && !*downinf )
857 {
858 branchruledata->strongbranchscore[hashindex] = *score;
859 branchruledata->sbscoreisrecent[hashindex] = TRUE;
860 branchruledata->lastevalnode[hashindex] = currentnodenr;
861 }
862
863 if( branchruledata->initiator == ORIG )
864 {
865 /* update pseudocost scores */
866 if( !*upinf )
867 {
868 SCIP_CALL( SCIPupdateVarPseudocost(origprob, var1, 1.0-frac, upgain, 1.0) );
869 }
870
871 if( !*downinf)
872 {
873 SCIP_CALL( SCIPupdateVarPseudocost(origprob, var1, 0.0-frac, downgain, 1.0) );
874 }
875 }
876 }
877 }
878 else
879 {
880 *score = branchruledata->strongbranchscore[hashindex];
881 }
882 }
883
884 return SCIP_OKAY;
885}
886
887/** branching method for relaxation solutions */
888static
890 GCG* gcg, /**< GCG data structure */
891 SCIP_BRANCHRULE* branchrule, /**< pointer to the branching rule */
892 SCIP_VAR** cand1s, /**< first variable candidates */
893 SCIP_VAR** cand2s, /**< second variable candidates (each cand2 corresponds to exactly one
894 * cand1 and vice versa) */
895 int* candinfos, /**< additional information for each candidate */
896 int ncands, /**< number of input candidates */
897 SCIP_VAR** outcand1, /**< pointer to store the pointer of the first selected variable */
898 SCIP_VAR** outcand2, /**< pointer to store the pointer of the second selected variable (if
899 * applicable) */
900 int* outcandinfo, /**< pointer to store additional (integer) info */
901 SCIP_Bool* bestupinf, /**< pointer to store whether strong branching detected infeasibility in
902 * the upbranch */
903 SCIP_Bool* bestdowninf, /**< pointer to store whether strong branching detected infeasibility in
904 * the downbranch */
905 SCIP_RESULT* result /**< pointer to store the result of the branching call */
906 )
907{
908 SCIP* origprob;
909 SCIP* masterscip;
910 SCIP_BRANCHRULEDATA* branchruledata;
911
912 /* branching candidates */
913 SCIP_VAR** branchcands;
914 SCIP_Real* branchcandssol;
915 int npriobranchcands;
916
917 SCIP_HASHMAP* solhashmap;
918
919 int hashindex;
920
921 /* values for choosing the variable to branch on */
922 SCIP_Real maxscore;
923 SCIP_Real score;
924
925 /* variables for controlling the evaluation effort */
926 int lookahead;
927 int lastimproved;
928
929 int depth;
930 int phase0nneededcands;
931
932 SCIP_Real minpscount;
933
934 SCIP_Real nodegap;
935 SCIP_Real upperbound;
936 SCIP_Real nodelowerbound;
937
938 int nneededcands;
939
940 int heurincumbentindex;
941 SCIP_Real heurincumbentsbscore;
942
943 /* infeasibility results during strong branching */
944 SCIP_Bool upinf;
945 SCIP_Bool downinf;
946
947 /* storing best candidates */
948 int *indices;
949 int nvalidcands;
950
951 /* storing best candidates based on historical strong branching scores */
952 int *histindices;
953 int nvalidhistcands;
954 int nneededhistcands;
955
956 VarTuple vartuple = {NULL,NULL,0};
957
959
960 assert(branchrule != NULL);
961 assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
962 assert(origprob != NULL);
963 assert(result != NULL);
965
966 branchruledata = SCIPbranchruleGetData(branchrule);
967
968 assert(branchruledata->maxphase1depth + 1 >= branchruledata->minphase0depth ||
969 branchruledata->maxphase2depth + 1 >= branchruledata->minphase0depth);
970
972
973 this_branchruledata = branchruledata;
974
975 /* get master problem */
976 masterscip = GCGgetMasterprob(gcg);
977 assert(masterscip != NULL);
978
979 heurincumbentindex = -1;
980
981 /* get the branching candidates */
982 SCIP_CALL( SCIPgetExternBranchCands(origprob, &branchcands, &branchcandssol, NULL, NULL,
983 &npriobranchcands, NULL, NULL, NULL) );
984
985 if( branchruledata->initiator == ORIG )
986 {
987 cand1s = branchcands;
988 ncands = npriobranchcands;
989 }
990 else if( branchruledata->initiator == RYANFOSTER && (branchruledata->usepseudocosts || branchruledata->mostfrac ) )
991 {
992 SCIP_CALL( SCIPhashmapCreate(&solhashmap, SCIPblkmem(origprob), npriobranchcands) );
993 for( int r = 0; r<npriobranchcands; r++ )
994 {
995 SCIP_CALL( SCIPhashmapInsertReal(solhashmap, branchcands[r], branchcandssol[r]) );
996 }
997 }
998
999 *outcand1 = NULL;
1000
1001 maxscore = -1.0;
1002
1003 upinf = FALSE;
1004 downinf = FALSE;
1005 *bestupinf = FALSE;
1006 *bestdowninf = FALSE;
1007
1009
1010 /* set maximum strong branching lp iterations and pricing rounds to 2 times the average unless the value is
1011 * fixed in the settings (as it is done in SCIP)
1012 */
1013 SCIP_CALL( SCIPgetLongintParam(origprob, "branching/bp_strong/maxsblpiters", &branchruledata->maxsblpiters) );
1014 if( branchruledata->maxsblpiters == 0 )
1015 {
1018 SCIP_Longint maxlpiters;
1019
1020 nlpiterations = branchruledata->nsblpiterations;
1021 nlps = branchruledata->nphase1lps;
1022 if( nlps == 0 )
1023 {
1025 nlps = SCIPgetNNodeInitLPs(masterscip);
1026 if( nlps == 0 )
1027 {
1028 nlpiterations = 1000;
1029 nlps = 1;
1030 }
1031 }
1032 assert(nlps >= 1);
1033 maxlpiters = (int)(2*nlpiterations / nlps);
1034 maxlpiters = (int)((SCIP_Real)maxlpiters * (1.0 + 10.0 / SCIPgetNNodes(masterscip)));
1035 branchruledata->maxsblpiters = maxlpiters;
1036 }
1037
1038 SCIP_CALL( SCIPgetIntParam(origprob, "branching/bp_strong/maxsbpricerounds", &branchruledata->maxsbpricerounds) );
1039 if( branchruledata->maxsbpricerounds == 0 )
1040 {
1043 SCIP_Longint maxpricerounds;
1044
1045 npricerounds = branchruledata->nsbpricerounds;
1046 nlps = branchruledata->nphase2lps;
1047 if( nlps == 0 )
1048 {
1050 nlps = SCIPgetNNodeInitLPs(masterscip);
1051 if( nlps == 0 )
1052 {
1053 npricerounds = 100000;
1054 nlps = 1;
1055 }
1056 }
1057 assert(nlps >= 1);
1058 maxpricerounds = (int)(2 * npricerounds / nlps);
1059 maxpricerounds = (int)((SCIP_Real)maxpricerounds * (1.0 + 10.0 / SCIPgetNNodes(masterscip)));
1060 branchruledata->maxsbpricerounds = maxpricerounds;
1061 }
1062
1063 upperbound = SCIPgetUpperbound(origprob);
1064 nodelowerbound = SCIPnodeGetLowerbound( SCIPgetFocusNode(origprob) );
1065 nodegap = ((upperbound >= 0) == (nodelowerbound >= 0) && MIN( ABS( upperbound ), ABS( nodelowerbound ) ) != 0)?
1066 MIN( ABS( (upperbound-nodelowerbound) / MIN( ABS( upperbound ), ABS( nodelowerbound ) ) ), 1 ) : 1;
1067 assert(0 <= nodegap && nodegap <= 1);
1068
1069 /* number of candidates we evaluate precisely should be based on the likely relevance of this branching decision
1070 * via the nodegap */
1071 nneededcands = calculateNCands(origprob, branchruledata, nodegap, 0, ncands);
1072
1073 /* insert branchcands into hashtable */
1074 SCIP_CALL( addBranchcandsToData(gcg, branchrule, cand1s, cand2s, ncands) );
1075
1076 SCIP_CALL( SCIPallocBufferArray(masterscip, &branchruledata->score, ncands) );
1077 for( int init = 0; init < ncands; ++init )
1078 {
1079 vartuple.var1 = cand1s[init];
1080 vartuple.var2 = cand2s == NULL? NULL : cand2s[init];
1081 hashindex = ((VarTuple *) SCIPhashtableRetrieve(branchruledata->candhashtable, (void *) &vartuple))->index;
1082
1083 branchruledata->score[init] = branchruledata->strongbranchscore[hashindex];
1084 }
1085
1086 /* allocate memory */
1087 SCIP_CALL( SCIPallocBufferArray(masterscip, &indices, ncands) );
1088 SCIP_CALL( SCIPallocBufferArray(masterscip, &histindices, ncands) );
1089 indices[0] = 0;
1090
1091 if( branchruledata->initiator == ORIG )
1092 {
1093 nvalidcands = 0;
1094 nvalidhistcands = 0;
1095
1096 /* iter = 0: integer variables belonging to a unique block with fractional value,
1097 * iter = 1: we did not find enough variables to branch on so far, so we look for integer variables that belong
1098 * to no block but were directly transferred to the master problem and which have a fractional value in the
1099 * current solution
1100 */
1101 for( int iter = 0; iter <= 1 && nvalidcands < nneededcands; iter++ )
1102 {
1103 for( int i = 0; i < ncands; i++ )
1104 {
1105 vartuple.var1 = cand1s[i];
1106 vartuple.var2 = NULL;
1107
1108 hashindex = ((VarTuple *) SCIPhashtableRetrieve(branchruledata->candhashtable, (void *) &vartuple))->index;
1109
1110 if (iter == 0)
1111 {
1112 if( branchruledata->uniqueblockflags[hashindex] < -1 )
1113 {
1114 branchruledata->uniqueblockflags[hashindex] = assignUniqueBlockFlags(gcg, cand1s[i]);
1115 }
1116
1117 if( branchruledata->uniqueblockflags[hashindex] == 1 )
1118 {
1119 indices[nvalidcands] = i;
1120 nvalidcands++;
1121
1122 if( branchruledata->strongbranchscore[hashindex] != -1)
1123 {
1124 histindices[nvalidhistcands] = i;
1125 nvalidhistcands++;
1126 }
1127 }
1128 }
1129 else if( nvalidcands == 0 )
1130 {
1131 if( branchruledata->uniqueblockflags[hashindex] == 0 )
1132 {
1133 indices[nvalidcands] = i;
1134 nvalidcands++;
1135 if( branchruledata->strongbranchscore[hashindex] != -1 )
1136 {
1137 histindices[nvalidhistcands] = i;
1138 nvalidhistcands++;
1139 }
1140 }
1141 }
1142 }
1143 }
1144
1145 if( nvalidcands == 0 )
1146 {
1147 SCIPfreeBufferArray(masterscip, &indices);
1148 SCIPfreeBufferArray(masterscip, &histindices);
1149 SCIPfreeBufferArray(masterscip, &branchruledata->score);
1150 return SCIP_OKAY;
1151 }
1152 }
1153 else
1154 {
1155 nvalidhistcands = 0;
1156 for( int i=0; i<ncands; i++ )
1157 {
1158 indices[i] = i;
1159 if( branchruledata->score[i] != -1 )
1160 {
1161 histindices[nvalidhistcands] = i;
1162 nvalidhistcands++;
1163 }
1164 }
1165 nvalidcands = ncands;
1166 }
1167
1168 /* the number of candidates we select based on historical strong branching scores needs to depend on the number of
1169 * candidates for which we have historical scores, otherwise some candidates would be selected simply because they
1170 * have been scored before
1171 */
1172 nneededhistcands = (int) SCIPfloor(origprob, MIN( (SCIP_Real)nvalidhistcands / (SCIP_Real)(nvalidcands+nvalidhistcands),
1173 branchruledata->histweight ) * nvalidcands);
1174 qsort(histindices, nvalidhistcands, sizeof(int), score_compare_function);
1175 qsort(histindices, nneededhistcands, sizeof(int), geq_compare_function);
1176
1177 /* go through the three phases:
1178 * - phase 0: select a first selection of candidates based on some traditional variable selection
1179 * heuristic, some (half) of the candidates are new, and some are selected based on previous calls
1180 * - phase 1: filter the best candidates by evaluating the Master LP, w/o column and cut generation
1181 * - phase 2: select the best of the candidates from phase 1 by solving the Master LP with column and cut generation
1182 */
1183 for( int phase = 0; phase <= 2; phase++ )
1184 {
1185 /* skip phase 1 if we are below its max depth */
1186 if( depth > branchruledata->maxphase1depth && phase == 1 )
1187 phase = 2;
1188
1189 switch( phase )
1190 {
1191 case 0:
1192 ncands = nvalidcands;
1193
1194 /* necessary in case we skip phase 0 */
1195 phase0nneededcands = nneededcands;
1196
1197 /* skip phase 0 we are too high in the tree, and phases 1 and 2 if we are too low */
1198 if( branchruledata->minphase0depth > depth )
1199 {
1200 nneededcands = ncands;
1201 }
1202 else if( depth > branchruledata->maxphase1depth )
1203 {
1204 if( depth > branchruledata->maxphase2depth )
1205 {
1206 nneededcands = 1;
1207
1208 /* strong branching can be fully stopped if all open nodes are below the max depth */
1209 if( SCIPgetEffectiveRootDepth(origprob) > branchruledata->maxphase1depth &&
1211 branchruledata->done = TRUE;
1212 }
1213 else
1214 {
1215 /* we only want to skip phase 1, so we need to set nneededcands to the number of output candidates
1216 * for phase 1
1217 */
1218 nneededcands = calculateNCands(origprob, branchruledata, nodegap, 1, phase0nneededcands);
1219 }
1220 }
1221
1222 break;
1223
1224 case 1:
1225 nneededcands = calculateNCands(origprob, branchruledata, nodegap, 1, phase0nneededcands);
1226
1227 /* skip phase 2 if we are in lite mode,
1228 * or if the number of available candidates is lower than the min amount for phase 2,
1229 * or if we are too low in the tree
1230 */
1231 if( branchruledata->usestronglite
1232 || nneededcands < branchruledata->mincolgencands
1233 || ncands < branchruledata->mincolgencands
1234 || depth > branchruledata->maxphase2depth )
1235 nneededcands = 1;
1236
1237 break;
1238
1239 case 2:
1240 nneededcands = 1;
1241 lastimproved = 0;
1242
1243 /* the lookahead can be partially based on the overall evaluation effort for phase 2 */
1244 lookahead = branchruledata->maxlookahead;
1245 if( lookahead && branchruledata->lookaheadscales>0 )
1246 {
1247 lookahead = MAX( 1, (int) SCIPround(origprob,
1248 (SCIP_Real) ((1-branchruledata->lookaheadscales) * lookahead) -
1249 (SCIP_Real) (branchruledata->lookaheadscales *
1250 ncands / branchruledata->maxphase1outcands) * lookahead) );
1251 }
1252 break;
1253 }
1254
1255 if( nneededcands >= ncands && (phase != 0 || !branchruledata->forcephase0) )
1256 continue;
1257
1258 /* compute scores */
1259 for( int i = 0, c=branchruledata->lastcand; i < ncands; i++, c++ )
1260 {
1261 c = c % ncands;
1262
1263 /* select the variable as new best candidate (if it is) if we look for only one candidate,
1264 * or remember its score if we look for multiple
1265 */
1266 if( branchruledata->initiator == ORIG )
1267 {
1268 minpscount = MIN( SCIPgetVarPseudocostCount(origprob, cand1s[indices[c]], 0),
1269 SCIPgetVarPseudocostCount(origprob, cand1s[indices[c]], 1) );
1270
1271 /* only call strong branching if this variable is not sufficiently reliable yet */
1272 if( phase == 0 ||
1273 (phase == 1 && minpscount < branchruledata->phase1reliable) ||
1274 (phase == 2 && minpscount < branchruledata->phase2reliable) )
1275 {
1276 SCIP_CALL( score_function(gcg, branchrule, cand1s[indices[c]], NULL, branchcandssol[indices[c]], 0, 0,
1277 phase == 0, FALSE, phase == 2 && !branchruledata->usestronglite,
1278 &score, &upinf, &downinf) );
1279 }
1280 else
1281 {
1282 score = branchruledata->score[indices[c]];
1283 }
1284 }
1285 else
1286 {
1287 SCIP_CALL( score_function(gcg, branchrule, cand1s[indices[c]], cand2s[indices[c]],
1288 SCIPhashmapGetImageReal(solhashmap, cand1s[indices[c]]),
1289 SCIPhashmapGetImageReal(solhashmap, cand2s[indices[c]]),
1290 candinfos[indices[c]], phase == 0, FALSE,
1291 phase == 2 && !branchruledata->usestronglite, &score, &upinf, &downinf) );
1292 }
1293
1294 /* variable pointers for orig candidates sometimes change during probing in strong branching */
1295 if( branchruledata->initiator == ORIG && phase >= 1 )
1296 {
1297 SCIP_CALL( SCIPgetExternBranchCands(origprob, &cand1s, &branchcandssol, NULL, NULL,
1298 NULL, NULL, NULL, NULL) );
1299 }
1300
1301 /* handle infeasibility detected during strong branching */
1302 if( phase == 2 && !branchruledata->usestronglite && branchruledata->immediateinf && (upinf || downinf) )
1303 {
1304 if( upinf && downinf )
1305 {
1306 for( int k = 0; k < branchruledata->maxvars; k++ )
1307 {
1308 branchruledata->sbscoreisrecent[k] = FALSE;
1309 }
1311
1312 SCIPfreeBufferArray(masterscip, &indices);
1313 SCIPfreeBufferArray(masterscip, &histindices);
1314 SCIPfreeBufferArray(masterscip, &branchruledata->score);
1315
1316 *bestupinf = TRUE;
1317 *bestdowninf = TRUE;
1318
1319 SCIPdebugMessage("Strong branching detected current node to be infeasible!\n");
1320 return SCIP_OKAY;
1321 }
1322
1323 branchruledata->lastcand = c;
1324 indices[0] = indices[c];
1325 *bestupinf = upinf;
1326 *bestdowninf = downinf;
1327 break;
1328 }
1329
1330 /* store strong branching score of the candidate that was selected by the heuristic */
1331 if( phase>0 && heurincumbentindex == indices[c] )
1332 heurincumbentsbscore = score;
1333
1334 if( nneededcands == 1 )
1335 {
1336 if( score > maxscore )
1337 {
1338 lastimproved = 0;
1339 indices[0] = indices[c];
1340 maxscore = score;
1341 *bestupinf = upinf;
1342 *bestdowninf = downinf;
1343 }
1344 /* if the last improving candidate is lookahead or more steps away, abort phase 2 */
1345 else
1346 {
1347 lastimproved++;
1348 if( lookahead && lastimproved >= lookahead && phase == 2 )
1349 {
1350 break;
1351 }
1352 }
1353
1354 }
1355 else
1356 {
1357 branchruledata->score[indices[c]] = score;
1358 }
1359 }
1360
1361 if( nneededcands > 1 )
1362 {
1363 qsort(indices, ncands, sizeof(int), score_compare_function);
1364 ncands = MIN( ncands, nneededcands );
1365
1366 if( phase == 0 )
1367 {
1368 heurincumbentindex = indices[0];
1369
1370 if( nneededhistcands )
1371 {
1372 /* swap out the worst performing "new" candidates with the best performing historical candidates */
1373 int *indicescopy;
1374 int pos;
1375
1376 SCIP_CALL( SCIPallocBufferArray(masterscip, &indicescopy, ncands) );
1377 pos = nneededhistcands;
1378
1379 for( int i = 0; i<ncands; i++ )
1380 {
1381 indicescopy[i] = indices[i];
1382 }
1383
1384 for( int i = 0; i<nneededhistcands; i++ )
1385 {
1386 indices[i] = histindices[i];
1387 }
1388
1389 /* concatenate the two arrays, while avoiding duplicates */
1390 for( int i = 0; i<ncands && pos<=ncands; i++ )
1391 {
1392 for( int j = 0; j <= nneededhistcands; j++ )
1393 {
1394 if( j == nneededhistcands )
1395 {
1396 indices[pos] = indicescopy[i];
1397 pos++;
1398 }
1399 else if( indices[j] == indicescopy[i] )
1400 break;
1401 }
1402 }
1403
1404 SCIPfreeBufferArray(masterscip, &indicescopy);
1405 }
1406 }
1407 }
1408 else
1409 {
1410 break;
1411 }
1412 }
1413
1414 *outcand1 = cand1s[indices[0]];
1415 if( branchruledata->initiator == RYANFOSTER )
1416 {
1417 *outcand2 = cand2s[indices[0]];
1418 *outcandinfo = candinfos[indices[0]];
1419 }
1420
1421 /* free memory */
1422 SCIPfreeBufferArray(masterscip, &indices);
1423 SCIPfreeBufferArray(masterscip, &histindices);
1424 SCIPfreeBufferArray(masterscip, &branchruledata->score);
1425
1426 if( *outcand1 == NULL )
1427 {
1428 SCIPdebugMessage("Strong branching could not find a variable to branch on!\n");
1429 return SCIP_OKAY;
1430 }
1431
1432 if( branchruledata->initiator == ORIG )
1433 {
1434 SCIPdebugMessage("Strong branching selected variable %s%s\n",
1435 SCIPvarGetName(*outcand1),
1436 (*bestupinf || *bestdowninf)? ", branching on which is infeasible in one direction" : "");
1437 }
1438 else
1439 {
1440 SCIPdebugMessage("Strong branching selected variables %s and %s%s\n",
1441 SCIPvarGetName(*outcand1), SCIPvarGetName(*outcand2),
1442 (*bestupinf || *bestdowninf)? ", branching on which is infeasible in one direction" : "");
1443 }
1444
1445 if( branchruledata->initiator == RYANFOSTER && (branchruledata->usepseudocosts || branchruledata->mostfrac) )
1446 {
1447 SCIPhashmapFree(&solhashmap);
1448 }
1449
1450 if( !*bestupinf && !*bestdowninf )
1451 {
1452 /* if the heuristic was close multiple times in a row, stop strong branching */
1453 if( branchruledata->maxconsecheurclose >= 0
1454 && heurincumbentsbscore >= branchruledata->closepercentage * maxscore )
1455 {
1456 branchruledata->consecheurclose++;
1457 if( branchruledata->consecheurclose >= branchruledata->maxconsecheurclose )
1458 branchruledata->done = TRUE;
1459 }
1460 else
1461 branchruledata->consecheurclose = 0;
1462
1463 for( int i=0; i<branchruledata->maxvars; i++ )
1464 {
1465 branchruledata->sbscoreisrecent[i] = FALSE;
1466 }
1467 }
1468
1470
1471 return SCIP_OKAY;
1472}
1473
1474/*
1475 * Callback methods
1476 */
1477#define branchDeactiveMasterBPStrong NULL
1478#define branchPropMasterBPStrong NULL
1479#define branchActiveMasterBPStrong NULL
1480#define branchMasterSolvedBPStrong NULL
1481#define branchDataDeleteBPStrong NULL
1482
1483#define branchExeclpBPStrong NULL
1484#define branchExecextBPStrong NULL
1485#define branchExecpsBPStrong NULL
1486
1487/** free remaining allocated memory */
1488static
1489SCIP_DECL_BRANCHFREE(branchFreeBPStrong)
1490{
1491 SCIP_BRANCHRULEDATA* branchruledata;
1492 SCIP_HASHTABLE* candhashtable;
1493 int i;
1494
1495 branchruledata = SCIPbranchruleGetData(branchrule);
1496
1497 if( branchruledata->initialized )
1498 {
1499 candhashtable = branchruledata->candhashtable;
1500
1501 SCIPfreeBlockMemoryArray(scip, &branchruledata->lastevalnode, branchruledata->maxvars);
1502 SCIPfreeBlockMemoryArray(scip, &branchruledata->sbscoreisrecent, branchruledata->maxvars);
1503 SCIPfreeBlockMemoryArray(scip, &branchruledata->strongbranchscore, branchruledata->maxvars);
1504 SCIPfreeBlockMemoryArray(scip, &branchruledata->uniqueblockflags, branchruledata->maxvars);
1505
1506 for( i=0; i<branchruledata->nvars; i++ )
1507 {
1508 SCIPfreeBlockMemory(scip, &(branchruledata->vartuples[i]));
1509 }
1510
1511 SCIPfreeBlockMemoryArray(scip, &branchruledata->vartuples, branchruledata->maxvars);
1512
1513 if( branchruledata->candhashtable != NULL )
1514 {
1515 SCIPhashtableFree(&candhashtable);
1516 }
1517 }
1518
1519 SCIPfreeBlockMemory(scip, &branchruledata);
1520 SCIPbranchruleSetData(branchrule, NULL);
1521
1522 return SCIP_OKAY;
1523}
1524
1525/** initialization method of branching rule (called after problem was transformed) */
1526static
1527SCIP_DECL_BRANCHINIT(branchInitBPStrong)
1528{
1529 SCIP* origprob;
1530 SCIP_BRANCHRULEDATA* branchruledata;
1531 SCIP_HASHTABLE* candhashtable;
1532
1533 int i;
1534 int maxcands;
1535
1536 SCIP_Real logweight;
1537 SCIP_Real logbase;
1538 SCIP_Real phase0frac;
1539 SCIP_Real phase2frac;
1540
1541 SCIP_Real phase1depth;
1542
1543 branchruledata = SCIPbranchruleGetData(branchrule);
1544
1545 origprob = GCGgetOrigprob(branchruledata->gcg);
1546 assert(branchrule != NULL);
1547 assert(origprob != NULL);
1548
1549 SCIPdebugMessage("Init BPStrong branching rule\n");
1550
1551 /* free data if we already solved another instance but branchFreeBPStrong was not called inbetween */
1552 if( branchruledata->initialized )
1553 {
1554 candhashtable = branchruledata->candhashtable;
1555
1556 for( i=0; i<branchruledata->nvars; i++ )
1557 {
1558 SCIPfreeBlockMemory(scip, &branchruledata->vartuples[i]);
1559 }
1560
1561 SCIPfreeBlockMemoryArray(scip, &branchruledata->vartuples, branchruledata->maxvars);
1562 SCIPfreeBlockMemoryArray(scip, &branchruledata->lastevalnode, branchruledata->maxvars);
1563 SCIPfreeBlockMemoryArray(scip, &branchruledata->sbscoreisrecent, branchruledata->maxvars);
1564 SCIPfreeBlockMemoryArray(scip, &branchruledata->strongbranchscore, branchruledata->maxvars);
1565 SCIPfreeBlockMemoryArray(scip, &branchruledata->uniqueblockflags, branchruledata->maxvars);
1566
1567 if( branchruledata->candhashtable != NULL )
1568 {
1569 SCIPhashtableFree(&candhashtable);
1570 }
1571 }
1572
1573 branchruledata->lastcand = 0;
1574 branchruledata->nvars = 0;
1575 branchruledata->maxvars = 0;
1576 branchruledata->initiator = -1;
1577
1578 branchruledata->nphase1lps = 0;
1579 branchruledata->nphase2lps = 0;
1580 branchruledata->nsblpiterations = 0;
1581 branchruledata->nsbpricerounds = 0;
1582
1583 branchruledata->consecheurclose = 0;
1584 branchruledata->done = FALSE;
1585
1586 SCIP_CALL( SCIPgetRealParam(origprob, "branching/bp_strong/depthlogweight", &logweight) );
1587 if( logweight > 0 )
1588 {
1589 SCIP_CALL( SCIPgetRealParam(origprob, "branching/bp_strong/depthlogbase", &logbase) );
1590 SCIP_CALL( SCIPgetRealParam(origprob, "branching/bp_strong/depthlogphase0frac", &phase0frac) );
1591 SCIP_CALL( SCIPgetRealParam(origprob, "branching/bp_strong/depthlogphase2frac", &phase2frac) );
1593
1594 phase1depth = log(branchruledata->maxcands)/log(logbase);
1595
1596 branchruledata->minphase0depth = (int) SCIPround(origprob, (1-logweight) * branchruledata->minphase0depth
1597 + logweight * phase0frac * phase1depth);
1598 branchruledata->maxphase1depth = (int) SCIPround(origprob, (1-logweight) * branchruledata->maxphase1depth
1599 + logweight * phase1depth);
1600 branchruledata->maxphase2depth = (int) SCIPround(origprob, (1-logweight) * branchruledata->maxphase2depth
1601 + logweight * phase2frac * phase1depth);
1602 }
1603
1604 /* create hash table TODO: better inital table sizes */
1605 maxcands = branchruledata->maxcands;
1607 branchruledata->initiator == RYANFOSTER? maxcands*2 : maxcands,
1608 hashGetKeyVars, hashKeyEqVars, hashKeyValVars, (void*) scip) );
1609
1610 assert(branchruledata->candhashtable != NULL);
1611
1612 /* create arrays */
1613 branchruledata->nvars = 0;
1614 branchruledata->maxvars = SCIPcalcMemGrowSize(scip, 0);
1615 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->uniqueblockflags, branchruledata->maxvars) );
1616 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->strongbranchscore, branchruledata->maxvars) );
1617 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->sbscoreisrecent, branchruledata->maxvars) );
1618 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->lastevalnode, branchruledata->maxvars) );
1619 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->vartuples, branchruledata->maxvars) );
1620
1621 branchruledata->initialized = TRUE;
1622
1623 return SCIP_OKAY;
1624}
1625
1626/** creates the b&p strong-branching branching rule and includes it in SCIP */
1628 GCG* gcg /**< GCG data structure */
1629 )
1630{
1631 SCIP* origscip;
1633 SCIP_BRANCHRULE* branchrule;
1634 SCIP_BRANCHRULEDATA* branchruledata;
1635
1636 SCIPdebugMessage("Include BPStrong branching rule\n");
1637
1638 /* get original problem */
1639 origscip = GCGgetOrigprob(gcg);
1640 assert(origscip != NULL);
1643
1644 /* alloc branching rule data */
1645 SCIP_CALL( SCIPallocBlockMemory(masterprob, &branchruledata) );
1646 branchruledata->gcg = gcg;
1647
1648 /* include branching rule */
1653 assert(branchrule != NULL);
1654
1655 branchruledata->initialized = FALSE;
1656
1657 /* set non fundamental callbacks via setter functions */
1658 SCIP_CALL( SCIPsetBranchruleInit(masterprob, branchrule, branchInitBPStrong) );
1659 SCIP_CALL( SCIPsetBranchruleFree(masterprob, branchrule, branchFreeBPStrong) );
1660
1661 /* add branching rule parameters */
1662 SCIP_CALL( SCIPaddBoolParam(origscip, "branching/bp_strong/stronglite",
1663 "should strong branching use column generation during variable evaluation?",
1664 &branchruledata->usestronglite, FALSE, DEFAULT_STRONGLITE, NULL, NULL) );
1665
1666 SCIP_CALL( SCIPaddBoolParam(origscip, "branching/bp_strong/strongtraining",
1667 "should strong branching run as precise as possible (to generate more valuable training data)?",
1668 &branchruledata->usestrongtrain, FALSE, DEFAULT_STRONGTRAIN, NULL, NULL) );
1669
1670 SCIP_CALL( SCIPaddBoolParam(origscip, "branching/bp_strong/immediateinf",
1671 "should infeasibility detected during strong branching be handled immediately, or only if the candidate is selected?",
1672 &branchruledata->immediateinf, FALSE, DEFAULT_IMMEDIATEINF, NULL, NULL) );
1673
1674 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/reevalage",
1675 "how many times can bounds be changed due to infeasibility during strong branching until an already evaluated variable needs to be reevaluated?",
1676 &branchruledata->reevalage, FALSE, DEFAULT_REEVALAGE, 0, INT_MAX, NULL, NULL) );
1677
1678 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/mincolgencands",
1679 "minimum number of variables for phase 2 to be executed, otherwise the best candidate from phase 1 will be chosen",
1680 &branchruledata->mincolgencands, FALSE, DEFAULT_MINCOLGENCANDS, 0, INT_MAX, NULL, NULL) );
1681
1682 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/histweight",
1683 "how many candidates should be chosen based on historical strong branching scores as opposed to current heuristic scores in phase 0 (e.g. 0.5 = 50%)?",
1684 &branchruledata->histweight, FALSE, DEFAULT_HISTWEIGHT, 0, 1, NULL, NULL) );
1685
1686 SCIP_CALL( SCIPaddLongintParam(origscip, "branching/bp_strong/maxsblpiters",
1687 "maximum number of strong branching lp iterations, set to 2*avg lp iterations if <= 0",
1688 NULL, FALSE, DEFAULT_MAXSBLPITERS, 0, INT_MAX, NULL, NULL) );
1689
1690 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/maxsbpricerounds",
1691 "maximum number of strong branching price rounds, set to 2*avg lp iterations if <= 0",
1692 NULL, FALSE, DEFAULT_MAXSBPRICEROUNDS, 0, INT_MAX, NULL, NULL) );
1693
1694 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/maxlookahead",
1695 "maximum number of non-improving candidates until phase 2 is stopped",
1696 &branchruledata->maxlookahead, FALSE, DEFAULT_MAXLOOKAHEAD, 0, INT_MAX, NULL, NULL) );
1697
1698 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/lookaheadscales",
1699 "how much should the lookahead scale with the overall evaluation effort? (0 = not at all, 1 = fully)",
1700 &branchruledata->lookaheadscales, FALSE, DEFAULT_LOOKAHEADSCALES, 0, 1, NULL, NULL) );
1701
1702 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/minphase0depth",
1703 "minimum tree depth from which on phase 0 is performed (intended for heuristics like pseudocost branching)",
1704 &branchruledata->minphase0depth, FALSE, DEFAULT_MINPHASE0DEPTH, 0, INT_MAX, NULL, NULL) );
1705
1706 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/maxphase1depth",
1707 "maximum tree depth up to which phase 1 is performed (intended for heuristics like pseudocost branching)",
1708 &branchruledata->maxphase1depth, FALSE, DEFAULT_MAXPHASE1DEPTH, 0, INT_MAX, NULL, NULL) );
1709
1710 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/maxphase2depth",
1711 "maximum tree depth up to which phase 2 is performed (intended for heuristics like pseudocost branching)",
1712 &branchruledata->maxphase2depth, FALSE, DEFAULT_MAXPHASE2DEPTH, 0, INT_MAX, NULL, NULL) );
1713
1714 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/depthlogweight",
1715 "how much should the logarithm of the number of variables influence the depth for hybrid branching? (0 = not at all, 1 = fully)",
1717
1718 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/depthlogbase",
1719 "what should be the base of the logarithm that is used to compute the depth of hybrid branching?",
1720 NULL, FALSE, DEFAULT_DEPTHLOGBASE, 0, INT_MAX, NULL, NULL) );
1721
1722 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/depthlogphase0frac",
1723 "if using a logarithm to compute the depth of hybrid branching, what should be the fraction of the depth assigned to phase 1 that is assigned to phase 0?",
1725
1726 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/depthlogphase2frac",
1727 "if using a logarithm to compute the depth of hybrid branching, what should be the fraction of the depth assigned to phase 1 that is assigned to phase 2?",
1729
1730 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/closepercentage",
1731 "what percentage of the strong branching score of the candidate that was selected does the heuristic's incumbent need to be considered close (e.g. 0.5 = 50%)?",
1732 &branchruledata->closepercentage, FALSE, DEFAULT_CLOSEPERCENTAGE, 0, 1, NULL, NULL) );
1733
1734 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/maxconsecheurclose",
1735 "how many times in a row can the heuristic be close before strong branching is stopped?",
1736 &branchruledata->maxconsecheurclose, FALSE, DEFAULT_MAXCONSECHEURCLOSE, -1, INT_MAX, NULL, NULL) );
1737
1738 SCIP_CALL( SCIPaddRealParam(origscip, "branching/bp_strong/sbpseudocostweight",
1739 "with how much weight should strong branching scores be considered for pseudocost scores?",
1740 &branchruledata->sbpseudocostweight, FALSE, DEFAULT_SBPSEUDOCOSTWEIGHT, 0, 1, NULL, NULL) );
1741
1742 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/phase1reliable",
1743 "min count of pseudocost scores for a variable to be considered reliable in phase 1",
1744 &branchruledata->phase1reliable, FALSE, DEFAULT_PHASE1RELIABLE, -1, INT_MAX, NULL, NULL) );
1745
1746 SCIP_CALL( SCIPaddIntParam(origscip, "branching/bp_strong/phase2reliable",
1747 "min count of pseudocost scores for a variable to be considered reliable in phase 2",
1748 &branchruledata->phase2reliable, FALSE, DEFAULT_PHASE2RELIABLE, -1, INT_MAX, NULL, NULL) );
1749
1750 SCIP_CALL( SCIPaddBoolParam(origscip, "branching/bp_strong/forcep0",
1751 "should phase 0 be performed even if the number of input candidates is already lower or equal to the number of output candidates?",
1752 &branchruledata->forcephase0, FALSE, DEFAULT_FORCEP0, NULL, NULL) );
1753
1754
1755 SCIP_CALL( SCIPaddBoolParam(origscip, "branching/bp_strong/ryanfoster/usepseudocosts",
1756 "should single-variable-pseudocosts be used as a heuristic for strong branching for Ryan-Foster branching?",
1758
1759 SCIP_CALL( SCIPaddBoolParam(origscip, "branching/bp_strong/ryanfoster/usemostfrac",
1760 "should single-variable-fractionality be used as a heuristic for strong branching for Ryan-Foster branching?",
1762
1763 return SCIP_OKAY;
1764}
1765
1767 GCG* gcg, /**< GCG data structure */
1768 GCG_BRANCHRULE* origbranchrule, /**< pointer storing original branching rule */
1769 SCIP_VAR** branchvar, /**< pointer to store output var pointer */
1770 SCIP_Bool* upinf, /**< pointer to store whether strong branching detected infeasibility in
1771 * the upbranch */
1772 SCIP_Bool* downinf, /**< pointer to store whether strong branching detected infeasibility in
1773 * the downbranch */
1774 SCIP_RESULT* result, /**< pointer to store result */
1775 SCIP_Bool* stillusestrong /**< pointer to store whether strong branching has reached a permanent
1776 * stopping condition for orig */
1777 )
1778{
1779 SCIP_BRANCHRULEDATA *branchruledata;
1780 SCIP_BRANCHRULE *branchrule;
1781 SCIP* origprob;
1783
1787 assert(branchrule != NULL);
1788
1789 branchruledata = SCIPbranchruleGetData(branchrule);
1790
1791 if( branchruledata->initiator != ORIG )
1792 {
1793 branchruledata->initiator = ORIG;
1794
1795 SCIP_CALL( SCIPgetBoolParam(origprob, "branching/orig/usepseudocosts", &branchruledata->usepseudocosts) );
1796 SCIP_CALL( SCIPgetBoolParam(origprob, "branching/orig/mostfrac", &branchruledata->mostfrac) );
1797
1798 SCIP_CALL( SCIPgetIntParam(origprob, "branching/orig/minphase0outcands", &branchruledata->minphase0outcands) );
1799 SCIP_CALL( SCIPgetIntParam(origprob, "branching/orig/maxphase0outcands", &branchruledata->maxphase0outcands) );
1800 SCIP_CALL( SCIPgetRealParam(origprob, "branching/orig/maxphase0outcandsfrac",
1801 &branchruledata->maxphase0outcandsfrac) );
1802 SCIP_CALL( SCIPgetRealParam(origprob, "branching/orig/phase1gapweight", &branchruledata->phase1gapweight) );
1803
1804 SCIP_CALL( SCIPgetIntParam(origprob, "branching/orig/minphase1outcands", &branchruledata->minphase1outcands) );
1805 SCIP_CALL( SCIPgetIntParam(origprob, "branching/orig/maxphase1outcands", &branchruledata->maxphase1outcands) );
1806 SCIP_CALL( SCIPgetRealParam(origprob, "branching/orig/maxphase1outcandsfrac",
1807 &branchruledata->maxphase1outcandsfrac) );
1808 SCIP_CALL( SCIPgetRealParam(origprob, "branching/orig/phase2gapweight", &branchruledata->phase2gapweight) );
1809
1810 assert(branchruledata->maxphase0outcands >= branchruledata->minphase0outcands);
1811 assert(branchruledata->maxphase1outcands >= branchruledata->minphase1outcands);
1812 }
1813
1814 selectCandidate(gcg, branchrule, NULL, NULL, NULL, 0, branchvar, NULL, NULL, upinf, downinf, result);
1815
1816 *stillusestrong = !branchruledata->done;
1817
1818 return SCIP_OKAY;
1819}
1820
1821/** interface method for Ryan-Foster branching to strong branching heuristics */
1823 GCG* gcg, /**< GCG data structure */
1824 GCG_BRANCHRULE* rfbranchrule, /**< Ryan-Foster branchrule */
1825 SCIP_VAR** ovar1s, /**< first elements of candidate pairs */
1826 SCIP_VAR** ovar2s, /**< second elements of candidate pairs */
1827 int* nspricingblock, /**< pricing block numbers corresponding to input pairs */
1828 int npairs, /**< number of input pairs */
1829 SCIP_VAR** ovar1, /**< pointer to store output var 1 pointer */
1830 SCIP_VAR** ovar2, /**< pointer to store output var 2 pointer */
1831 int* pricingblock, /**< pointer to store output pricing block number */
1832 SCIP_Bool* sameinf, /**< pointer to store whether strong branching detected infeasibility in
1833 * the same branch */
1834 SCIP_Bool* differinf, /**< pointer to store whether strong branching detected infeasibility in
1835 * the differ branch */
1836 SCIP_RESULT* result, /**< pointer to store result */
1837 SCIP_Bool* stillusestrong /**< pointer to store whether strong branching has reached a permanent
1838 * stopping condition for Ryan-Foster */
1839 )
1840{
1841 SCIP_BRANCHRULEDATA *branchruledata;
1842 SCIP_BRANCHRULE *branchrule;
1843 SCIP* masterscip;
1844 SCIP* origprob;
1845
1847 masterscip = GCGgetMasterprob(gcg);
1848 branchrule = SCIPfindBranchrule(masterscip, BRANCHRULE_NAME);
1849 assert(branchrule != NULL);
1850
1851 branchruledata = SCIPbranchruleGetData(branchrule);
1852
1853 if( branchruledata->initiator != RYANFOSTER )
1854 {
1855 branchruledata->initiator = RYANFOSTER;
1856 branchruledata->initiatorbranchrule = rfbranchrule;
1857 SCIP_CALL( SCIPgetBoolParam(origprob, "branching/bp_strong/ryanfoster/usepseudocosts",
1858 &branchruledata->usepseudocosts) );
1859 SCIP_CALL( SCIPgetBoolParam(origprob, "branching/bp_strong/ryanfoster/usemostfrac", &branchruledata->mostfrac) );
1860
1861 SCIP_CALL( SCIPgetIntParam(origprob, "branching/ryanfoster/minphase0outcands",
1862 &branchruledata->minphase0outcands) );
1863 SCIP_CALL( SCIPgetIntParam(origprob, "branching/ryanfoster/maxphase0outcands",
1864 &branchruledata->maxphase0outcands) );
1865 SCIP_CALL( SCIPgetRealParam(origprob, "branching/ryanfoster/maxphase0outcandsfrac",
1866 &branchruledata->maxphase0outcandsfrac) );
1867 SCIP_CALL( SCIPgetRealParam(origprob, "branching/ryanfoster/phase1gapweight",
1868 &branchruledata->phase1gapweight) );
1869
1870 SCIP_CALL( SCIPgetIntParam(origprob, "branching/ryanfoster/minphase1outcands",
1871 &branchruledata->minphase1outcands) );
1872 SCIP_CALL( SCIPgetIntParam(origprob, "branching/ryanfoster/maxphase1outcands",
1873 &branchruledata->maxphase1outcands) );
1874 SCIP_CALL( SCIPgetRealParam(origprob, "branching/ryanfoster/maxphase1outcandsfrac",
1875 &branchruledata->maxphase1outcandsfrac) );
1876 SCIP_CALL( SCIPgetRealParam(origprob, "branching/ryanfoster/phase2gapweight",
1877 &branchruledata->phase2gapweight) );
1878
1879 assert(branchruledata->maxphase0outcands >= branchruledata->minphase0outcands);
1880 assert(branchruledata->maxphase1outcands >= branchruledata->minphase1outcands);
1881 }
1882
1883 selectCandidate(gcg, branchrule, ovar1s, ovar2s, nspricingblock, npairs,
1884 ovar1, ovar2, pricingblock, sameinf, differinf, result);
1885
1886 *stillusestrong = !branchruledata->done;
1887
1888 assert(*ovar1 != NULL);
1889 assert(*ovar2 != NULL);
1890
1891 return SCIP_OKAY;
1892}
#define BRANCHRULE_DESC
#define DEFAULT_RFUSEMOSTFRAC
#define DEFAULT_RFUSEPSEUDOCOSTS
#define branchPropMasterBPStrong
static int assignUniqueBlockFlags(GCG *gcg, SCIP_VAR *branchcand)
#define DEFAULT_STRONGTRAIN
#define RYANFOSTER
static SCIP_RETCODE addBranchcandsToData(GCG *gcg, SCIP_BRANCHRULE *branchrule, SCIP_VAR **var1s, SCIP_VAR **var2s, int ncands)
#define BRANCHRULE_PRIORITY
static SCIP_DECL_BRANCHFREE(branchFreeBPStrong)
static SCIP_Real score_function(GCG *gcg, SCIP_BRANCHRULE *branchrule, SCIP_VAR *var1, SCIP_VAR *var2, SCIP_Real solval1, SCIP_Real solval2, int candinfo, SCIP_Bool useheuristic, SCIP_Bool usehistorical, SCIP_Bool usecolgen, SCIP_Real *score, SCIP_Bool *upinf, SCIP_Bool *downinf)
static SCIP_RETCODE newProbingNodeRyanfosterMaster(GCG *gcg, GCG_BRANCHRULE *branchrule, SCIP_VAR *ovar1, SCIP_VAR *ovar2, int blocknr, SCIP_Bool same)
#define branchDeactiveMasterBPStrong
SCIP_RETCODE GCGbranchSelectCandidateStrongBranchingRyanfoster(GCG *gcg, GCG_BRANCHRULE *rfbranchrule, SCIP_VAR **ovar1s, SCIP_VAR **ovar2s, int *nspricingblock, int npairs, SCIP_VAR **ovar1, SCIP_VAR **ovar2, int *pricingblock, SCIP_Bool *sameinf, SCIP_Bool *differinf, SCIP_RESULT *result, SCIP_Bool *stillusestrong)
SCIP_RETCODE GCGincludeBranchruleBPStrong(GCG *gcg)
#define ORIG
#define branchDataDeleteBPStrong
#define DEFAULT_MINCOLGENCANDS
#define branchMasterSolvedBPStrong
static SCIP_DECL_BRANCHINIT(branchInitBPStrong)
#define DEFAULT_REEVALAGE
#define DEFAULT_MAXPHASE2DEPTH
#define DEFAULT_MAXSBPRICEROUNDS
#define DEFAULT_PHASE1RELIABLE
#define BRANCHRULE_NAME
#define DEFAULT_DEPTHLOGBASE
SCIP_RETCODE GCGbranchSelectCandidateStrongBranchingOrig(GCG *gcg, GCG_BRANCHRULE *origbranchrule, SCIP_VAR **branchvar, SCIP_Bool *upinf, SCIP_Bool *downinf, SCIP_RESULT *result, SCIP_Bool *stillusestrong)
#define DEFAULT_MAXLOOKAHEAD
static int geq_compare_function(const void *index1, const void *index2)
#define DEFAULT_CLOSEPERCENTAGE
#define DEFAULT_IMMEDIATEINF
static SCIP_RETCODE executeStrongBranching(GCG *gcg, SCIP_BRANCHRULE *branchrule, SCIP_VAR *branchvar1, SCIP_VAR *branchvar2, SCIP_Real solval1, SCIP_Real solval2, int candinfo, SCIP_Bool pricing, int maxpricingrounds, SCIP_Real *up, SCIP_Real *down, SCIP_Bool *upvalid, SCIP_Bool *downvalid, SCIP_Bool *upinf, SCIP_Bool *downinf)
#define branchActiveMasterBPStrong
static SCIP_Bool isKAncestor(SCIP *scip, int ancestornodenr, SCIP_NODE *successornode, int k)
static int calculateNCands(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_Real nodegap, int phase, int ncands)
#define DEFAULT_MAXPHASE1DEPTH
#define DEFAULT_FORCEP0
static int score_compare_function(const void *index1, const void *index2)
#define DEFAULT_LOOKAHEADSCALES
#define DEFAULT_MAXCONSECHEURCLOSE
#define DEFAULT_HISTWEIGHT
#define DEFAULT_DEPTHLOGPHASE0FRAC
SCIP_BRANCHRULEDATA * this_branchruledata
#define DEFAULT_MAXSBLPITERS
static SCIP_RETCODE selectCandidate(GCG *gcg, SCIP_BRANCHRULE *branchrule, SCIP_VAR **cand1s, SCIP_VAR **cand2s, int *candinfos, int ncands, SCIP_VAR **outcand1, SCIP_VAR **outcand2, int *outcandinfo, SCIP_Bool *bestupinf, SCIP_Bool *bestdowninf, SCIP_RESULT *result)
#define DEFAULT_STRONGLITE
#define DEFAULT_PHASE2RELIABLE
#define DEFAULT_DEPTHLOGWEIGHT
#define BRANCHRULE_MAXDEPTH
#define DEFAULT_MINPHASE0DEPTH
#define BRANCHRULE_MAXBOUNDDIST
#define DEFAULT_SBPSEUDOCOSTWEIGHT
#define DEFAULT_DEPTHLOGPHASE2FRAC
generic branch and price strong branching as described in Pecin, D., Pessoa, A., Poggi,...
branching rule for original problem in GCG
reliable pseudo costs branching rule
SCIP_Real * r
SCIP_DECL_HASHGETKEY(SCIPhashGetKeyCons)
constraint handler for the integrality constraint
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_Bool
#define MIN(x, y)
#define SCIP_Real
#define ABS(x)
#define MAX(x, y)
#define TRUE
#define FALSE
GCG interface methods.
SCIP_Bool GCGvarIsOriginal(SCIP_VAR *var)
Definition gcgvar.c:231
int GCGlinkingVarGetNBlocks(SCIP_VAR *var)
Definition gcgvar.c:572
SCIP_VAR ** GCGpricingVarGetOrigvars(SCIP_VAR *var)
Definition gcgvar.c:1100
SCIP_Bool GCGoriginalVarIsLinking(SCIP_VAR *var)
Definition gcgvar.c:247
SCIP_VAR * GCGoriginalVarGetPricingVar(SCIP_VAR *var)
Definition gcgvar.c:281
int GCGpricingVarGetNOrigvars(SCIP_VAR *var)
Definition gcgvar.c:1082
SCIP_RETCODE GCGlinkingVarGetBlocks(SCIP_VAR *var, int nblocks, int *blocks)
Definition gcgvar.c:529
int GCGvarGetBlock(SCIP_VAR *var)
Definition gcgvar.c:1118
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 * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
GCG_EXPORT int GCGgetNIdenticalBlocks(GCG *gcg, int pricingprobnr)
Definition relax_gcg.c:4185
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
int SCIPgetNIntVars(SCIP *scip)
int SCIPgetNBinVars(SCIP *scip)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
SCIP_Real SCIPhashmapGetImageReal(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapInsertReal(SCIP_HASHMAP *hashmap, void *origin, SCIP_Real image)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
#define SCIPhashTwo(a, b)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
#define SCIPhashSignature64(a)
SCIP_DECL_HASHKEYEQ(SCIPhashKeyEqString)
SCIP_DECL_HASHKEYVAL(SCIPhashKeyValString)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *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 SCIPgetLongintParam(SCIP *scip, const char *name, SCIP_Longint *value)
SCIP_RETCODE SCIPgetIntParam(SCIP *scip, const char *name, int *value)
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
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 SCIPgetExternBranchCands(SCIP *scip, SCIP_VAR ***externcands, SCIP_Real **externcandssol, SCIP_Real **externcandsscore, int *nexterncands, int *nprioexterncands, int *nprioexternbins, int *nprioexternints, int *nprioexternimpls)
SCIP_Real SCIPgetBranchScore(SCIP *scip, SCIP_VAR *var, SCIP_Real downgain, SCIP_Real upgain)
SCIP_Real SCIPgetLPObjval(SCIP *scip)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_Real SCIPnodeGetLowerbound(SCIP_NODE *node)
SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
SCIP_NODE * SCIPnodeGetParent(SCIP_NODE *node)
int SCIPnodeGetDepth(SCIP_NODE *node)
SCIP_RETCODE SCIPchgVarUbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_RETCODE SCIPchgVarLbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Longint SCIPgetNNodeInitLPs(SCIP *scip)
SCIP_Longint SCIPgetNNodeInitLPIterations(SCIP *scip)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
int SCIPgetEffectiveRootDepth(SCIP *scip)
SCIP_NODE * SCIPgetFocusNode(SCIP *scip)
SCIP_Real SCIPgetVarPseudocostCount(SCIP *scip, SCIP_VAR *var, SCIP_BRANCHDIR dir)
int SCIPvarGetIndex(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Bool SCIPisRelaxSolValid(SCIP *scip)
SCIP_RETCODE SCIPupdateVarPseudocost(SCIP *scip, SCIP_VAR *var, SCIP_Real solvaldelta, SCIP_Real objdelta, SCIP_Real weight)
SCIP_Real SCIPgetVarPseudocostScore(SCIP *scip, SCIP_VAR *var, SCIP_Real solval)
int SCIPsnprintf(char *t, int len, const char *s,...)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition gcgvar.c:159
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
* result
SCIP_VAR ** vars
int j
SCIP_Longint nlpiterations
SCIP_Real frac
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
int nvars
SCIPfreeBufferArray(scip, &cycles)
SCIP_Longint nlps
SCIP_Bool lperror
heurdata npricerounds
int depth
SCIP_Bool cutoff
SCIP_Bool lpsolved
#define NULL
INLINE Rational & max(Rational &r1, Rational &r2)
INLINE Rational & min(Rational &r1, Rational &r2)
GCG variable pricer.
SCIP_RETCODE GCGrelaxNewProbingnodeMaster(GCG *gcg)
Definition relax_gcg.c:4508
SCIP_RETCODE GCGrelaxNewProbingnodeMasterCons(GCG *gcg, GCG_BRANCHRULE *branchrule, GCG_BRANCHDATA *branchdata, SCIP_CONS **origbranchconss, int norigbranchconss, int maxorigbranchconss)
Definition relax_gcg.c:4562
SCIP_RETCODE GCGrelaxPerformProbing(GCG *gcg, int maxlpiterations, SCIP_Longint *nlpiterations, SCIP_Real *lpobjvalue, SCIP_Bool *lpsolved, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition relax_gcg.c:4756
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)),)
Definition relax_gcg.c:3717
SCIP_RETCODE GCGrelaxStartProbing(GCG *gcg, SCIP_HEUR *probingheur)
Definition relax_gcg.c:4390
SCIP_RETCODE GCGrelaxNewProbingnodeOrig(GCG *gcg)
Definition relax_gcg.c:4459
SCIP_RETCODE GCGrelaxPerformProbingWithPricing(GCG *gcg, int maxpricerounds, SCIP_Longint *nlpiterations, int *npricerounds, SCIP_Real *lpobjvalue, SCIP_Bool *lpsolved, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition relax_gcg.c:4775
SCIP_RETCODE GCGrelaxEndProbing(GCG *gcg)
Definition relax_gcg.c:4794
GCG relaxator.
SCIP_CONS * pricecons
SCIP_Real * strongbranchscore
SCIP_Real maxphase0outcandsfrac
SCIP_Longint maxsblpiters
SCIP_HASHTABLE * candhashtable
SCIP_Bool * sbscoreisrecent
SCIP_Longint nsblpiterations
GCG_BRANCHRULE * initiatorbranchrule
SCIP_Real maxphase1outcandsfrac
SCIP_VAR * var1
SCIP_VAR * var2
struct SCIP_Branchrule SCIP_BRANCHRULE
struct SCIP_BranchruleData SCIP_BRANCHRULEDATA
type definitions for branching rules in GCG projects
struct GCG_BranchData GCG_BRANCHDATA
struct GCG_Branchrule GCG_BRANCHRULE
struct SCIP_Cons SCIP_CONS
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HashMap SCIP_HASHMAP
struct SCIP_HashTable SCIP_HASHTABLE
SCIP_DIDNOTRUN
SCIP_CUTOFF
SCIP_BRANCHED
enum SCIP_Result SCIP_RESULT
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Node SCIP_NODE
struct SCIP_Var SCIP_VAR