-
Notifications
You must be signed in to change notification settings - Fork 102
/
vanillafullstrong.patch
1144 lines (1120 loc) · 46.9 KB
/
vanillafullstrong.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Makefile b/Makefile
index 4a2b4dc8c1..58d7d62fec 100644
--- a/Makefile
+++ b/Makefile
@@ -512,6 +512,7 @@ SCIPPLUGINLIBOBJ= scip/benders_default.o \
scip/branch_pscost.o \
scip/branch_random.o \
scip/branch_relpscost.o \
+ scip/branch_vanillafullstrong.o \
scip/cons_abspower.o \
scip/compr_largestrepr.o \
scip/compr_weakcompr.o \
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9bf9eec46b..c753588d0e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,6 +38,7 @@ set(scipsources
scip/branch_pscost.c
scip/branch_random.c
scip/branch_relpscost.c
+ scip/branch_vanillafullstrong.c
scip/cons_abspower.c
scip/compr_largestrepr.c
scip/compr_weakcompr.c
@@ -452,6 +453,7 @@ set(scipheaders
scip/branch_pscost.h
scip/branch_random.h
scip/branch_relpscost.h
+ scip/branch_vanillafullstrong.h
scip/clock.h
scip/compr.h
scip/compr_largestrepr.h
diff --git a/src/scip/branch_allfullstrong.c b/src/scip/branch_allfullstrong.c
index 77e301825d..d8f82ebc8b 100644
--- a/src/scip/branch_allfullstrong.c
+++ b/src/scip/branch_allfullstrong.c
@@ -397,12 +397,12 @@ SCIP_RETCODE SCIPselectVarPseudoStrongBranching(
if( integral )
{
- SCIP_CALL( SCIPgetVarStrongbranchInt(scip, pseudocands[c], INT_MAX,
+ SCIP_CALL( SCIPgetVarStrongbranchInt(scip, pseudocands[c], INT_MAX, FALSE,
skipdown[c] ? NULL : &down, skipup[c] ? NULL : &up, &downvalid, &upvalid, &downinf, &upinf, &downconflict, &upconflict, &lperror) );
}
else
{
- SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, pseudocands[c], INT_MAX,
+ SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, pseudocands[c], INT_MAX, FALSE,
skipdown[c] ? NULL : &down, skipup[c] ? NULL : &up, &downvalid, &upvalid, &downinf, &upinf, &downconflict, &upconflict, &lperror) );
}
nsbcalls++;
diff --git a/src/scip/branch_fullstrong.c b/src/scip/branch_fullstrong.c
index a94084ab86..89c4a7ba75 100644
--- a/src/scip/branch_fullstrong.c
+++ b/src/scip/branch_fullstrong.c
@@ -343,7 +343,7 @@ SCIP_RETCODE SCIPselectVarStrongBranching(
}
else
{
- SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, lpcands[c], INT_MAX,
+ SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, lpcands[c], INT_MAX, FALSE,
skipdown[i] ? NULL : &down, skipup[i] ? NULL : &up, &downvalid, &upvalid, &downinf, &upinf,
&downconflict, &upconflict, &lperror) );
}
diff --git a/src/scip/branch_relpscost.c b/src/scip/branch_relpscost.c
index 72d468e569..5385936cdb 100644
--- a/src/scip/branch_relpscost.c
+++ b/src/scip/branch_relpscost.c
@@ -1076,7 +1076,7 @@ SCIP_RETCODE execRelpscost(
else
{
/* apply strong branching */
- SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, branchcands[c], inititer,
+ SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, branchcands[c], inititer, FALSE,
&down, &up, &downvalid, &upvalid, &downinf, &upinf, &downconflict, &upconflict, &lperror) );
ndomredsdown = ndomredsup = 0;
diff --git a/src/scip/branch_vanillafullstrong.c b/src/scip/branch_vanillafullstrong.c
new file mode 100644
index 0000000000..e188291991
--- /dev/null
+++ b/src/scip/branch_vanillafullstrong.c
@@ -0,0 +1,592 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* */
+/* This file is part of the program and library */
+/* SCIP --- Solving Constraint Integer Programs */
+/* */
+/* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
+/* fuer Informationstechnik Berlin */
+/* */
+/* SCIP is distributed under the terms of the ZIB Academic License. */
+/* */
+/* You should have received a copy of the ZIB Academic License */
+/* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
+/* */
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/**@file branch_vanillafullstrong.c
+ * @ingroup DEFPLUGINS_BRANCH
+ * @brief vanilla full strong LP branching rule
+ * @author Tobias Achterberg
+ * @author Maxime Gasse
+ */
+
+/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
+
+#include "blockmemshell/memory.h"
+#include "scip/branch_vanillafullstrong.h"
+#include "scip/pub_branch.h"
+#include "scip/pub_message.h"
+#include "scip/pub_tree.h"
+#include "scip/pub_var.h"
+#include "scip/scip_branch.h"
+#include "scip/scip_general.h"
+#include "scip/scip_lp.h"
+#include "scip/scip_mem.h"
+#include "scip/scip_message.h"
+#include "scip/scip_numerics.h"
+#include "scip/scip_param.h"
+#include "scip/scip_prob.h"
+#include "scip/scip_solvingstats.h"
+#include "scip/scip_tree.h"
+#include "scip/scip_var.h"
+#include <string.h>
+
+
+#define BRANCHRULE_NAME "vanillafullstrong"
+#define BRANCHRULE_DESC "vanilla full strong branching"
+#define BRANCHRULE_PRIORITY -2000
+#define BRANCHRULE_MAXDEPTH -1
+#define BRANCHRULE_MAXBOUNDDIST 1.0
+
+#define DEFAULT_INTEGRALCANDS FALSE /**< should integral variables in the current LP solution be considered as
+ * branching candidates ? */
+#define DEFAULT_SCOREALL FALSE /**< should strong branching scores be computed for all candidates, or can
+ * we early stop when a variable has infinite score ? */
+#define DEFAULT_IDEMPOTENT FALSE /**< should strong branching side-effects be prevented (e.g., domain
+ * changes, stat updates etc.) ? */
+#define DEFAULT_COLLECTSCORES FALSE /**< should strong branching scores be collected ? */
+#define DEFAULT_DONOTBRANCH FALSE /**< should branching be done ? */
+
+
+/** branching rule data */
+struct SCIP_BranchruleData
+{
+ SCIP_Bool integralcands; /**< should integral variables in the current LP solution be considered
+ * as branching candidates ? */
+ SCIP_Bool scoreall; /**< should strong branching scores be computed for all candidates, or
+ * can we early stop when a node is detected infeasible ? */
+ SCIP_Bool idempotent; /**< should strong branching side-effects be prevented (e.g., domain
+ * changes, stat updates etc.) ? */
+ SCIP_Bool collectscores; /**< should strong branching scores be collected ? */
+ SCIP_Bool donotbranch; /**< should branching be done ? */
+ SCIP_VAR** cands; /**< candidate variables */
+ SCIP_Real* candscores; /**< candidate scores */
+ int ncands; /**< number of candidates */
+ int npriocands; /**< number of priority candidates */
+ int bestcand; /**< best branching candidate */
+ int candcapacity; /**< capacity of candidate arrays */
+};
+
+
+/*
+ * local methods
+ */
+
+
+/** selects a variable from a set of candidates by strong branching */
+static
+SCIP_RETCODE runVanillaStrongBranching(
+ SCIP* scip, /**< SCIP data structure */
+ SCIP_VAR** cands, /**< branching candidates */
+ int ncands, /**< number of branching candidates */
+ int npriocands, /**< number of branching candidates with highest priority */
+ SCIP_Bool scoreall, /**< should strong branching scores be computed for all candidates, or can
+ * we early stop when a node is detected infeasible ? */
+ SCIP_Bool idempotent, /**< should strong branching side-effects be prevented (e.g., domain
+ * changes, stat updates etc.) ? */
+ SCIP_Real* scores, /**< candidate scores */
+ int* bestcand, /**< best candidate for branching */
+ SCIP_Real* bestdown, /**< objective value of the down branch for bestcand */
+ SCIP_Real* bestup, /**< objective value of the up branch for bestcand */
+ SCIP_Real* bestscore, /**< score for bestcand */
+ SCIP_Bool* bestdownvalid, /**< is bestdown a valid dual bound for the down branch? */
+ SCIP_Bool* bestupvalid, /**< is bestup a valid dual bound for the up branch? */
+ SCIP_Real* provedbound /**< proved dual bound for current subtree */
+ )
+{ /*lint --e{715}*/
+ SCIP_Real lpobjval;
+ int nsbcalls;
+ int c;
+
+ assert(scip != NULL);
+ assert(cands != NULL);
+ assert(bestcand != NULL);
+ assert(bestdown != NULL);
+ assert(bestup != NULL);
+ assert(bestscore != NULL);
+ assert(bestdownvalid != NULL);
+ assert(bestupvalid != NULL);
+ assert(provedbound != NULL);
+ assert(ncands > 0);
+
+ /* get current LP objective bound of the local sub problem and global cutoff bound */
+ lpobjval = SCIPgetLPObjval(scip);
+ *provedbound = lpobjval;
+
+ *bestcand = 0;
+ *bestdown = lpobjval;
+ *bestup = lpobjval;
+ *bestdownvalid = TRUE;
+ *bestupvalid = TRUE;
+ *bestscore = -SCIPinfinity(scip);
+
+ if( scores != NULL )
+ for( c = 0; c < ncands; ++c )
+ scores[c] = -SCIPinfinity(scip);
+
+ /* if only one candidate exists, choose this one without applying strong branching; also, when SCIP is about to be
+ * stopped, all strongbranching evaluations will be aborted anyway, thus we can return immediately
+ */
+ if( (!scoreall && ncands == 1) || SCIPisStopped(scip) )
+ return SCIP_OKAY;
+
+ /* this assert may not hold if SCIP is stopped, thus we only check it here */
+ assert(SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_OPTIMAL);
+
+ /* initialize strong branching without propagation */
+ SCIP_CALL( SCIPstartStrongbranch(scip, FALSE) );
+
+ /* compute strong branching scores */
+ nsbcalls = 0;
+ for( c = 0; c < ncands ; ++c )
+ {
+ SCIP_VAR* var;
+ SCIP_Real val;
+ SCIP_Bool integral;
+ SCIP_Real down, up;
+ SCIP_Real downgain, upgain;
+ SCIP_Bool downvalid, upvalid;
+ SCIP_Bool downinf, upinf;
+ SCIP_Bool downconflict, upconflict;
+ SCIP_Bool lperror;
+ SCIP_Real gains[3];
+ SCIP_Real score;
+
+ var = cands[c];
+ assert(var != NULL);
+
+ val = SCIPvarGetLPSol(var);
+ integral = SCIPisFeasIntegral(scip, val);
+
+ up = -SCIPinfinity(scip);
+ down = -SCIPinfinity(scip);
+
+ SCIPdebugMsg(scip, "applying vanilla strong branching on variable <%s> with solution %g\n",
+ SCIPvarGetName(var), val);
+
+ /* apply strong branching */
+ if( integral )
+ {
+ SCIP_CALL( SCIPgetVarStrongbranchInt(scip, cands[c], INT_MAX, idempotent,
+ &down, &up, &downvalid, &upvalid, &downinf, &upinf, &downconflict, &upconflict, &lperror) );
+ }
+ else
+ {
+ SCIP_CALL( SCIPgetVarStrongbranchFrac(scip, cands[c], INT_MAX, idempotent,
+ &down, &up, &downvalid, &upvalid, &downinf, &upinf, &downconflict, &upconflict, &lperror) );
+ }
+ nsbcalls++;
+
+ /* check for an error in strong branching */
+ if( lperror )
+ {
+ SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
+ "(node %" SCIP_LONGINT_FORMAT ") error in strong branching call for variable <%s> with solution %g\n",
+ SCIPgetNNodes(scip), SCIPvarGetName(var), val);
+ break;
+ }
+
+ /* evaluate strong branching */
+ down = MAX(down, lpobjval);
+ up = MAX(up, lpobjval);
+ downgain = down - lpobjval;
+ upgain = up - lpobjval;
+
+ assert(!SCIPallColsInLP(scip) || SCIPisExactSolve(scip) || !downvalid || downinf == SCIPisGE(scip, down, SCIPgetCutoffbound(scip)));
+ assert(!SCIPallColsInLP(scip) || SCIPisExactSolve(scip) || !upvalid || upinf == SCIPisGE(scip, up, SCIPgetCutoffbound(scip)));
+ assert(downinf || !downconflict);
+ assert(upinf || !upconflict);
+
+ if( !idempotent )
+ {
+ /* display node information line */
+ if( SCIPgetDepth(scip) == 0 && nsbcalls % 100 == 0 )
+ {
+ SCIP_CALL( SCIPprintDisplayLine(scip, NULL, SCIP_VERBLEVEL_HIGH, TRUE) );
+ }
+ /* update variable pseudo cost values */
+ if( !downinf && downvalid )
+ {
+ SCIP_CALL( SCIPupdateVarPseudocost(scip, var, integral ? -1.0 : 0.0 - SCIPfrac(scip, val), downgain, 1.0) );
+ }
+ if( !upinf && upvalid )
+ {
+ SCIP_CALL( SCIPupdateVarPseudocost(scip, var, integral ? +1.0 : 1.0 - SCIPfrac(scip, val), upgain, 1.0) );
+ }
+ }
+
+ /* compute strong branching score */
+ gains[0] = downgain;
+ gains[1] = upgain;
+ gains[2] = 0.0;
+ score = SCIPgetBranchScoreMultiple(scip, var, integral ? 3 : 2, gains);
+
+ /* collect scores if requested */
+ if( scores != NULL )
+ scores[c] = score;
+
+ /* check for a better score */
+ if( score > *bestscore )
+ {
+ *bestcand = c;
+ *bestdown = down;
+ *bestup = up;
+ *bestdownvalid = downvalid;
+ *bestupvalid = upvalid;
+ *bestscore = score;
+ }
+
+ SCIPdebugMsg(scip, " -> cand %d/%d (prio:%d) var <%s> (solval=%g, downgain=%g, upgain=%g, score=%g) -- best: <%s> (%g)\n",
+ c, ncands, npriocands, SCIPvarGetName(var), val, downgain, upgain, score,
+ SCIPvarGetName(cands[*bestcand]), *bestscore);
+
+ /* node is infeasible -> early stopping (highest score) */
+ if( !integral && !scoreall && downinf && upinf )
+ {
+ /* we should only detect infeasibility if the LP is a valid relaxation */
+ assert(SCIPallColsInLP(scip));
+ assert(!SCIPisExactSolve(scip));
+
+ SCIPdebugMsg(scip, " -> variable <%s> is infeasible in both directions\n", SCIPvarGetName(var));
+ break;
+ }
+ }
+
+ /* end strong branching */
+ SCIP_CALL( SCIPendStrongbranch(scip) );
+
+ return SCIP_OKAY;
+}
+
+/*
+ * Callback methods
+ */
+
+/** copy method for branchrule plugins (called when SCIP copies plugins) */
+static
+SCIP_DECL_BRANCHCOPY(branchCopyVanillafullstrong)
+{ /*lint --e{715}*/
+ assert(scip != NULL);
+ assert(branchrule != NULL);
+ assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
+
+ /* call inclusion method of branchrule */
+ SCIP_CALL( SCIPincludeBranchruleVanillafullstrong(scip) );
+
+ return SCIP_OKAY;
+}
+
+/** destructor of branching rule to free user data (called when SCIP is exiting) */
+static
+SCIP_DECL_BRANCHFREE(branchFreeVanillafullstrong)
+{ /*lint --e{715}*/
+ SCIP_BRANCHRULEDATA* branchruledata;
+
+ /* free branching rule data */
+ branchruledata = SCIPbranchruleGetData(branchrule);
+ assert(branchruledata != NULL);
+
+ SCIPfreeBlockMemoryNull(scip, &branchruledata);
+
+ return SCIP_OKAY;
+}
+
+/** initialization method of branching rule (called after problem was transformed) */
+static
+SCIP_DECL_BRANCHINIT(branchInitVanillafullstrong)
+{ /*lint --e{715}*/
+#ifndef NDEBUG
+ SCIP_BRANCHRULEDATA* branchruledata;
+
+ /* initialize branching rule data */
+ branchruledata = SCIPbranchruleGetData(branchrule);
+#endif
+ assert(branchruledata != NULL);
+ assert(branchruledata->candscores == NULL);
+ assert(branchruledata->cands == NULL);
+
+ return SCIP_OKAY;
+}
+
+/** deinitialization method of branching rule (called before transformed problem is freed) */
+static
+SCIP_DECL_BRANCHEXIT(branchExitVanillafullstrong)
+{ /*lint --e{715}*/
+ SCIP_BRANCHRULEDATA* branchruledata;
+
+ /* initialize branching rule data */
+ branchruledata = SCIPbranchruleGetData(branchrule);
+ assert(branchruledata != NULL);
+
+ /* free candidate arrays if any */
+ if( branchruledata->candscores != NULL )
+ {
+ SCIPfreeBlockMemoryArrayNull(scip, &branchruledata->candscores, branchruledata->candcapacity);
+ }
+ if( branchruledata->cands != NULL )
+ {
+ SCIPfreeBlockMemoryArrayNull(scip, &branchruledata->cands, branchruledata->candcapacity);
+ }
+
+ branchruledata->candcapacity = -1;
+ branchruledata->ncands = -1;
+ branchruledata->npriocands = -1;
+ branchruledata->bestcand = -1;
+
+ return SCIP_OKAY;
+}
+
+/** branching execution method */
+static
+SCIP_DECL_BRANCHEXECLP(branchExeclpVanillafullstrong)
+{ /*lint --e{715}*/
+ SCIP_BRANCHRULEDATA* branchruledata;
+ SCIP_Real bestdown;
+ SCIP_Real bestup;
+ SCIP_Real bestscore;
+ SCIP_Real provedbound;
+ SCIP_Bool bestdownvalid;
+ SCIP_Bool bestupvalid;
+ SCIP_VAR** cands;
+ int ncands;
+ int npriocands;
+ int i;
+
+ assert(branchrule != NULL);
+ assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
+ assert(scip != NULL);
+ assert(result != NULL);
+
+ SCIPdebugMsg(scip, "Execlp method of vanilla fullstrong branching\n");
+
+ *result = SCIP_DIDNOTRUN;
+
+ /* get branching rule data */
+ branchruledata = SCIPbranchruleGetData(branchrule);
+ assert(branchruledata != NULL);
+
+ /* get branching candidates, either all non-fixed variables or only the
+ * fractional ones */
+ if( branchruledata->integralcands )
+ {
+ SCIP_CALL( SCIPgetPseudoBranchCands(scip, &cands, &ncands, &npriocands) );
+ }
+ else
+ {
+ SCIP_CALL( SCIPgetLPBranchCands(scip, &cands, NULL, NULL, &ncands, &npriocands, NULL) );
+ }
+
+ assert(ncands > 0);
+ assert(npriocands > 0);
+
+ /* increase candidate arrays capacity if needed */
+ if( ncands > branchruledata->candcapacity )
+ {
+ /* free previously allocated arrays if any */
+ if( branchruledata->candscores != NULL)
+ {
+ SCIPfreeBlockMemoryArrayNull(scip, &branchruledata->candscores, branchruledata->candcapacity);
+ branchruledata->candscores = NULL;
+ }
+ if( branchruledata->cands != NULL)
+ {
+ SCIPfreeBlockMemoryArrayNull(scip, &branchruledata->cands, branchruledata->candcapacity);
+ branchruledata->cands = NULL;
+ }
+
+ /* update capacity */
+ branchruledata->candcapacity = SCIPgetNBinVars(scip) + SCIPgetNIntVars(scip) + SCIPgetNImplVars(scip);
+ }
+ assert(branchruledata->candcapacity >= ncands);
+
+ /* allocate new candidate arrays if needed */
+ if( branchruledata->cands == NULL )
+ {
+ SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->cands, branchruledata->candcapacity) );
+ }
+ if( branchruledata->candscores == NULL && branchruledata->collectscores )
+ {
+ SCIP_CALL( SCIPallocBlockMemoryArray(scip, &branchruledata->candscores, branchruledata->candcapacity) );
+ }
+
+ /* copy candidates */
+ branchruledata->ncands = ncands;
+ branchruledata->npriocands = npriocands;
+
+ for( i = 0; i < ncands; i++ )
+ branchruledata->cands[i] = cands[i];
+
+ SCIP_CALL( runVanillaStrongBranching(scip, branchruledata->cands, branchruledata->ncands, branchruledata->npriocands,
+ branchruledata->scoreall, branchruledata->idempotent, branchruledata->candscores,
+ &branchruledata->bestcand, &bestdown, &bestup, &bestscore, &bestdownvalid,
+ &bestupvalid, &provedbound) );
+
+ if( !branchruledata->donotbranch )
+ {
+ SCIP_VAR* var;
+ SCIP_Real val;
+ SCIP_NODE* downchild;
+ SCIP_NODE* eqchild;
+ SCIP_NODE* upchild;
+ SCIP_Bool allcolsinlp;
+ SCIP_Bool exactsolve;
+
+ assert(0 <= branchruledata->bestcand && branchruledata->bestcand < branchruledata->ncands);
+ assert(SCIPisLT(scip, provedbound, SCIPgetCutoffbound(scip)));
+
+ var = branchruledata->cands[branchruledata->bestcand];
+ val = SCIPvarGetLPSol(var);
+
+ /* perform the branching */
+ SCIPdebugMsg(scip, " -> %d candidates, selected candidate %d: variable <%s>[%g,%g] (solval=%g, down=%g, up=%g, score=%g)\n",
+ branchruledata->ncands, branchruledata->bestcand, SCIPvarGetName(var), SCIPvarGetLbLocal(var),
+ SCIPvarGetUbLocal(var), val, bestdown, bestup, bestscore);
+ SCIP_CALL( SCIPbranchVarVal(scip, var, val, &downchild, &eqchild, &upchild) );
+
+ /* check, if we want to solve the problem exactly, meaning that strong branching information is not useful
+ * for cutting off sub problems and improving lower bounds of children
+ */
+ exactsolve = SCIPisExactSolve(scip);
+
+ /* check, if all existing columns are in LP, and thus the strong branching results give lower bounds */
+ allcolsinlp = SCIPallColsInLP(scip);
+
+ /* update the lower bounds in the children */
+ if( !branchruledata->idempotent && allcolsinlp && !exactsolve )
+ {
+ if( downchild != NULL )
+ {
+ SCIP_CALL( SCIPupdateNodeLowerbound(scip, downchild, bestdownvalid ? MAX(bestdown, provedbound) : provedbound) );
+ SCIPdebugMsg(scip, " -> down child's lowerbound: %g\n", SCIPnodeGetLowerbound(downchild));
+ }
+ if( eqchild != NULL )
+ {
+ SCIP_CALL( SCIPupdateNodeLowerbound(scip, eqchild, provedbound) );
+ SCIPdebugMsg(scip, " -> eq child's lowerbound: %g\n", SCIPnodeGetLowerbound(eqchild));
+ }
+ if( upchild != NULL )
+ {
+ SCIP_CALL( SCIPupdateNodeLowerbound(scip, upchild, bestupvalid ? MAX(bestup, provedbound) : provedbound) );
+ SCIPdebugMsg(scip, " -> up child's lowerbound: %g\n", SCIPnodeGetLowerbound(upchild));
+ }
+ }
+
+ *result = SCIP_BRANCHED;
+ }
+
+ return SCIP_OKAY;
+}
+
+
+/*
+ * branching specific interface methods
+ */
+
+/** creates the vanilla full strong LP branching rule and includes it in SCIP */
+SCIP_RETCODE SCIPincludeBranchruleVanillafullstrong(
+ SCIP* scip /**< SCIP data structure */
+ )
+{
+ SCIP_BRANCHRULEDATA* branchruledata;
+ SCIP_BRANCHRULE* branchrule;
+
+ /* create fullstrong branching rule data */
+ SCIP_CALL( SCIPallocBlockMemory(scip, &branchruledata) );
+ branchruledata->cands = NULL;
+ branchruledata->candscores = NULL;
+ branchruledata->candcapacity = -1;
+ branchruledata->ncands = -1;
+ branchruledata->npriocands = -1;
+ branchruledata->bestcand = -1;
+
+ /* include branching rule */
+ SCIP_CALL( SCIPincludeBranchruleBasic(scip, &branchrule, BRANCHRULE_NAME, BRANCHRULE_DESC, BRANCHRULE_PRIORITY,
+ BRANCHRULE_MAXDEPTH, BRANCHRULE_MAXBOUNDDIST, branchruledata) );
+
+ assert(branchrule != NULL);
+
+ /* set non-fundamental callbacks via specific setter functions*/
+ SCIP_CALL( SCIPsetBranchruleCopy(scip, branchrule, branchCopyVanillafullstrong) );
+ SCIP_CALL( SCIPsetBranchruleFree(scip, branchrule, branchFreeVanillafullstrong) );
+ SCIP_CALL( SCIPsetBranchruleInit(scip, branchrule, branchInitVanillafullstrong) );
+ SCIP_CALL( SCIPsetBranchruleExit(scip, branchrule, branchExitVanillafullstrong) );
+ SCIP_CALL( SCIPsetBranchruleExecLp(scip, branchrule, branchExeclpVanillafullstrong) );
+
+ /* fullstrong branching rule parameters */
+ SCIP_CALL( SCIPaddBoolParam(scip,
+ "branching/vanillafullstrong/integralcands",
+ "should integral variables in the current LP solution be considered as branching candidates?",
+ &branchruledata->integralcands, FALSE, DEFAULT_INTEGRALCANDS, NULL, NULL) );
+ SCIP_CALL( SCIPaddBoolParam(scip,
+ "branching/vanillafullstrong/idempotent",
+ "should strong branching side-effects be prevented (e.g., domain changes, stat updates etc.)?",
+ &branchruledata->idempotent, FALSE, DEFAULT_IDEMPOTENT, NULL, NULL) );
+ SCIP_CALL( SCIPaddBoolParam(scip,
+ "branching/vanillafullstrong/scoreall",
+ "should strong branching scores be computed for all candidates, or can we early stop when a variable has infinite score?",
+ &branchruledata->scoreall, TRUE, DEFAULT_SCOREALL, NULL, NULL) );
+ SCIP_CALL( SCIPaddBoolParam(scip,
+ "branching/vanillafullstrong/collectscores",
+ "should strong branching scores be collected?",
+ &branchruledata->collectscores, TRUE, DEFAULT_COLLECTSCORES, NULL, NULL) );
+ SCIP_CALL( SCIPaddBoolParam(scip,
+ "branching/vanillafullstrong/donotbranch",
+ "should candidates only be scored, but no branching be performed?",
+ &branchruledata->donotbranch, TRUE, DEFAULT_DONOTBRANCH, NULL, NULL) );
+
+ return SCIP_OKAY;
+}
+
+
+/** recovers candidate variables and their scores from last vanilla full strong branching call */
+SCIP_RETCODE SCIPgetVanillafullstrongData(
+ SCIP* scip, /**< SCIP data structure */
+ SCIP_VAR*** cands, /**< pointer to store candidate variables; or NULL */
+ SCIP_Real** candscores, /**< pointer to store candidate scores; or NULL */
+ int* ncands, /**< pointer to store number of candidates; or NULL */
+ int* npriocands, /**< pointer to store number of priority candidates; or NULL */
+ int* bestcand /**< pointer to store best branching candidate; or NULL */
+ )
+{
+ SCIP_BRANCHRULEDATA* branchruledata;
+ SCIP_BRANCHRULE* branchrule;
+
+ assert(scip != NULL);
+
+ branchrule = SCIPfindBranchrule(scip, BRANCHRULE_NAME);
+ branchruledata = SCIPbranchruleGetData(branchrule);
+
+ if( cands )
+ {
+ *cands = branchruledata->cands;
+ }
+ if( candscores && branchruledata->collectscores )
+ {
+ *candscores = branchruledata->candscores;
+ }
+ if( ncands )
+ {
+ *ncands = branchruledata->ncands;
+ }
+ if( npriocands )
+ {
+ *npriocands = branchruledata->npriocands;
+ }
+ if( bestcand )
+ {
+ *bestcand = branchruledata->bestcand;
+ }
+
+ return SCIP_OKAY;
+}
+
diff --git a/src/scip/branch_vanillafullstrong.h b/src/scip/branch_vanillafullstrong.h
new file mode 100644
index 0000000000..a75bf4dd26
--- /dev/null
+++ b/src/scip/branch_vanillafullstrong.h
@@ -0,0 +1,78 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* */
+/* This file is part of the program and library */
+/* SCIP --- Solving Constraint Integer Programs */
+/* */
+/* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
+/* fuer Informationstechnik Berlin */
+/* */
+/* SCIP is distributed under the terms of the ZIB Academic License. */
+/* */
+/* You should have received a copy of the ZIB Academic License */
+/* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
+/* */
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/**@file branch_vanillafullstrong.h
+ * @ingroup BRANCHINGRULES
+ * @brief vanilla full strong LP branching rule
+ * @author Tobias Achterberg
+ * @author Maxime Gasse
+ *
+ * The vanilla full strong branching rule is a purged implementation of full strong branching, for academic purposes.
+ * It implements full strong branching with the following specific features:
+ * - no cutoff or domain reduction: only branching.
+ * - idempotent (optional): leave SCIP, as much as possible, in the same state before / after the strong branching
+ * calls. Basically, do not update any statistic.
+ * - donotbranch (optional): do no perform branching. So that the brancher can be called as an oracle only (on which
+ * variable would you branch ? But do not branch please).
+ * - scoreall (optional): continue scoring variables, even if infeasibility is detected along the way.
+ * - collectscores (optional): store the candidate scores from the last call, which can then be retrieved by calling
+ * SCIPgetVanillafullstrongData().
+ * - integralcands (optional): get candidates from SCIPgetPseudoBranchCands() instead of SCIPgetLPBranchCands(), i.e.,
+ * consider all non-fixed variables as branching candidates, not only fractional ones.
+ *
+ */
+
+/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
+
+#ifndef __SCIP_BRANCH_VANILLAFULLSTRONG_H__
+#define __SCIP_BRANCH_VANILLAFULLSTRONG_H__
+
+
+#include "scip/def.h"
+#include "scip/type_result.h"
+#include "scip/type_retcode.h"
+#include "scip/type_scip.h"
+#include "scip/type_var.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** creates the vanilla full strong branching rule and includes it in SCIP
+ *
+ * @ingroup BranchingRuleIncludes
+ */
+extern
+SCIP_RETCODE SCIPincludeBranchruleVanillafullstrong(
+ SCIP* scip /**< SCIP data structure */
+ );
+
+/** recovers candidate variables and their scores from last vanilla full strong branching call */
+extern
+SCIP_RETCODE SCIPgetVanillafullstrongData(
+ SCIP* scip, /**< SCIP data structure */
+ SCIP_VAR*** cands, /**< pointer to store candidate variables; or NULL */
+ SCIP_Real** candscores, /**< pointer to store candidate scores; or NULL */
+ int* ncands, /**< pointer to store number of candidates; or NULL */
+ int* npriocands, /**< pointer to store number of priority candidates; or NULL */
+ int* bestcand /**< pointer to store best branching candidate; or NULL */
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/scip/lp.c b/src/scip/lp.c
index 9cb4adcbb1..e9d8eb5fd1 100644
--- a/src/scip/lp.c
+++ b/src/scip/lp.c
@@ -4241,6 +4241,8 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
SCIP_PROB* prob, /**< problem data */
SCIP_LP* lp, /**< LP data */
int itlim, /**< iteration limit for strong branchings */
+ SCIP_Bool updatecol, /**< should col be updated, or should it stay in its current state ? */
+ SCIP_Bool updatestat, /**< should stat be updated, or should it stay in its current state ? */
SCIP_Real* down, /**< stores dual bound after branching column down */
SCIP_Real* up, /**< stores dual bound after branching column up */
SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound, or NULL;
@@ -4250,6 +4252,17 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
SCIP_Bool* lperror /**< pointer to store whether an unresolved LP error occurred */
)
{
+ SCIP_Real sbdown;
+ SCIP_Real sbup;
+ SCIP_Bool sbdownvalid;
+ SCIP_Bool sbupvalid;
+ SCIP_Longint validsblp;
+ SCIP_Real sbsolval;
+ SCIP_Real sblpobjval;
+ SCIP_Longint sbnode;
+ int sbitlim;
+ int nsbcalls;
+
assert(col != NULL);
assert(col->var != NULL);
assert(SCIPcolIsIntegral(col));
@@ -4277,29 +4290,36 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
*lperror = FALSE;
- if( col->validsblp != stat->nlps || itlim > col->sbitlim )
- {
- col->validsblp = stat->nlps;
- col->sbsolval = col->primsol;
- col->sblpobjval = SCIPlpGetObjval(lp, set, prob);
- col->sbnode = stat->nnodes;
+ sbdown = col->sbdown;
+ sbup = col->sbup;
+ sbdownvalid = col->sbdownvalid;
+ sbupvalid = col->sbupvalid;
+ validsblp = col->validsblp;
+ sbsolval = col->sbsolval;
+ sblpobjval = col->sblpobjval;
+ sbnode = col->sbnode;
+ sbitlim = col->sbitlim;
+ nsbcalls = col->nsbcalls;
+
+ if( validsblp != stat->nlps || itlim > sbitlim )
+ {
+ validsblp = stat->nlps;
+ sbsolval = col->primsol;
+ sblpobjval = SCIPlpGetObjval(lp, set, prob);
+ sbnode = stat->nnodes;
assert(integral || !SCIPsetIsFeasIntegral(set, col->primsol));
/* if a loose variables has an infinite best bound, the LP bound is -infinity and no gain can be achieved */
if( lp->looseobjvalinf > 0 )
{
- col->sbdown = -SCIPsetInfinity(set);
- col->sbup = -SCIPsetInfinity(set);
- col->sbdownvalid = FALSE;
- col->sbupvalid = FALSE;
+ sbdown = -SCIPsetInfinity(set);
+ sbup = -SCIPsetInfinity(set);
+ sbdownvalid = FALSE;
+ sbupvalid = FALSE;
}
else
{
SCIP_RETCODE retcode;
- SCIP_Real sbdown;
- SCIP_Real sbup;
- SCIP_Bool sbdownvalid;
- SCIP_Bool sbupvalid;
int iter;
SCIPsetDebugMsg(set, "performing strong branching on variable <%s>(%g) with %d iterations\n",
@@ -4309,8 +4329,8 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
SCIPclockStart(stat->strongbranchtime, set);
/* call LPI strong branching */
- col->sbitlim = itlim;
- col->nsbcalls++;
+ sbitlim = itlim;
+ nsbcalls++;
sbdown = lp->lpobjval;
sbup = lp->lpobjval;
@@ -4327,14 +4347,14 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
if( retcode == SCIP_LPERROR )
{
*lperror = TRUE;
- col->sbdown = SCIP_INVALID;
- col->sbup = SCIP_INVALID;
- col->sbdownvalid = FALSE;
- col->sbupvalid = FALSE;
- col->validsblp = -1;
- col->sbsolval = SCIP_INVALID;
- col->sblpobjval = SCIP_INVALID;
- col->sbnode = -1;
+ sbdown = SCIP_INVALID;
+ sbup = SCIP_INVALID;
+ sbdownvalid = FALSE;
+ sbupvalid = FALSE;
+ validsblp = -1;
+ sbsolval = SCIP_INVALID;
+ sblpobjval = SCIP_INVALID;
+ sbnode = -1;
}
else
{
@@ -4344,30 +4364,30 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
SCIP_CALL( retcode );
looseobjval = getFiniteLooseObjval(lp, set, prob);
- col->sbdown = MIN(sbdown + looseobjval, lp->cutoffbound);
- col->sbup = MIN(sbup + looseobjval, lp->cutoffbound);
-
- col->sbdownvalid = sbdownvalid;
- col->sbupvalid = sbupvalid;
+ sbdown = MIN(sbdown + looseobjval, lp->cutoffbound);
+ sbup = MIN(sbup + looseobjval, lp->cutoffbound);
/* update strong branching statistics */
- if( iter == -1 )
+ if( updatestat )
{
- /* calculate average iteration number */
- iter = stat->ndualresolvelps > 0 ? (int)(2*stat->ndualresolvelpiterations / stat->ndualresolvelps)
- : stat->nduallps > 0 ? (int)((stat->nduallpiterations / stat->nduallps) / 5)
- : stat->nprimalresolvelps > 0 ? (int)(2*stat->nprimalresolvelpiterations / stat->nprimalresolvelps)
- : stat->nprimallps > 0 ? (int)((stat->nprimallpiterations / stat->nprimallps) / 5)
- : 0;
- if( iter/2 >= itlim )
- iter = 2*itlim;
- }
- SCIPstatIncrement(stat, set, nstrongbranchs);
- SCIPstatAdd(stat, set, nsblpiterations, iter);
- if( stat->nnodes == 1 )
- {
- SCIPstatIncrement(stat, set, nrootstrongbranchs);
- SCIPstatAdd(stat, set, nrootsblpiterations, iter);
+ if( iter == -1 )
+ {
+ /* calculate average iteration number */
+ iter = stat->ndualresolvelps > 0 ? (int)(2*stat->ndualresolvelpiterations / stat->ndualresolvelps)
+ : stat->nduallps > 0 ? (int)((stat->nduallpiterations / stat->nduallps) / 5)
+ : stat->nprimalresolvelps > 0 ? (int)(2*stat->nprimalresolvelpiterations / stat->nprimalresolvelps)
+ : stat->nprimallps > 0 ? (int)((stat->nprimallpiterations / stat->nprimallps) / 5)
+ : 0;
+ if( iter/2 >= itlim )
+ iter = 2*itlim;
+ }
+ SCIPstatIncrement(stat, set, nstrongbranchs);
+ SCIPstatAdd(stat, set, nsblpiterations, iter);
+ if( stat->nnodes == 1 )
+ {
+ SCIPstatIncrement(stat, set, nrootstrongbranchs);
+ SCIPstatAdd(stat, set, nrootsblpiterations, iter);
+ }
}
}
@@ -4375,17 +4395,31 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
SCIPclockStop(stat->strongbranchtime, set);
}
}
- assert(*lperror || col->sbdown < SCIP_INVALID);
- assert(*lperror || col->sbup < SCIP_INVALID);
+ assert(*lperror || sbdown < SCIP_INVALID);
+ assert(*lperror || sbup < SCIP_INVALID);
if( down != NULL)
- *down = col->sbdown;
+ *down = sbdown;
if( up != NULL )
- *up = col->sbup;
+ *up = sbup;
if( downvalid != NULL )
- *downvalid = col->sbdownvalid;
+ *downvalid = sbdownvalid;
if( upvalid != NULL )
- *upvalid = col->sbupvalid;
+ *upvalid = sbupvalid;
+
+ if( updatecol )
+ {
+ col->sbdown = sbdown;
+ col->sbup = sbup;
+ col->sbdownvalid = sbdownvalid;
+ col->sbupvalid = sbupvalid;
+ col->validsblp = validsblp;
+ col->sbsolval = sbsolval;
+ col->sblpobjval = sblpobjval;
+ col->sbnode = sbnode;
+ col->sbitlim = sbitlim;
+ col->nsbcalls = nsbcalls;
+ }
return SCIP_OKAY;
}
diff --git a/src/scip/lp.h b/src/scip/lp.h
index 65b5093f8f..0ce1622e8c 100644
--- a/src/scip/lp.h
+++ b/src/scip/lp.h
@@ -253,6 +253,8 @@ SCIP_RETCODE SCIPcolGetStrongbranch(
SCIP_PROB* prob, /**< problem data */
SCIP_LP* lp, /**< LP data */
int itlim, /**< iteration limit for strong branchings */
+ SCIP_Bool updatecol, /**< should col be updated, or should it stay in its current state ? */
+ SCIP_Bool updatestat, /**< should stat be updated, or should it stay in its current state ? */
SCIP_Real* down, /**< stores dual bound after branching column down */
SCIP_Real* up, /**< stores dual bound after branching column up */
SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound, or NULL;
diff --git a/src/scip/scip_var.c b/src/scip/scip_var.c
index 4582b02f02..263dc255f2 100644
--- a/src/scip/scip_var.c
+++ b/src/scip/scip_var.c
@@ -2910,6 +2910,7 @@ SCIP_RETCODE SCIPgetVarStrongbranchFrac(
SCIP* scip, /**< SCIP data structure */
SCIP_VAR* var, /**< variable to get strong branching values for */
int itlim, /**< iteration limit for strong branchings */
+ SCIP_Bool idempotent, /**< should scip's state remain the same after the call (statistics, column states...), or should it be updated ? */
SCIP_Real* down, /**< stores dual bound after branching column down */
SCIP_Real* up, /**< stores dual bound after branching column up */
SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound, or NULL;
@@ -2927,6 +2928,10 @@ SCIP_RETCODE SCIPgetVarStrongbranchFrac(
)
{
SCIP_COL* col;
+ SCIP_Real localdown;
+ SCIP_Real localup;
+ SCIP_Bool localdownvalid;
+ SCIP_Bool localupvalid;
assert(scip != NULL);