SCIP Doxygen Documentation
Loading...
Searching...
No Matches
cutsel_dynamic.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* SCIP --- Solving Constraint Integer Programs */
5/* */
6/* Copyright (c) 2002-2026 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file cutsel_dynamic.c
26 * @ingroup DEFPLUGINS_CUTSEL
27 * @brief dynamic cut selector
28 * @author Christoph Graczyk
29 */
30
31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32
33#include <assert.h>
34
35
36#include "scip/scip_cutsel.h"
37#include "scip/scip_cut.h"
38#include "scip/scip_lp.h"
40#include "scip/cutsel_dynamic.h"
41
42
43#define CUTSEL_NAME "dynamic"
44#define CUTSEL_DESC "dynamic orthogonality for hybrid cutsel"
45#define CUTSEL_PRIORITY 7000
46
47#define RANDSEED 0x5EED
48
49#define DEFAULT_EFFICACYWEIGHT 1.0 /**< weight of efficacy in score calculation */
50#define DEFAULT_DIRCUTOFFDISTWEIGHT 0.0 /**< weight of directed cutoff distance in score calculation */
51#define DEFAULT_OBJPARALWEIGHT 0.0 /**< weight of objective parallelism in score calculation */
52#define DEFAULT_INTSUPPORTWEIGHT 0.0 /**< weight of integral support in cut score calculation */
53#define DEFAULT_MINORTHO 0.9 /**< minimal orthogonality in percent for a cut to enter the LP */
54#define DEFAULT_MINGAIN 0.01 /**< minimal efficacy gain for a cut to enter the LP */
55#define DEFAULT_MAXDEPTH (-1) /**< maximum depth at which this cutselector is used (-1 : all nodes) */
56#define DEFAULT_FILTERMODE 'd' /**< filtering strategy during cut selection (
57 * 'd'ynamic- and 'f'ull dynamic parallelism) */
58
59
60/*
61 * Data structures
62 */
63
64/** cut selector data */
65struct SCIP_CutselData
66{
67 SCIP_RANDNUMGEN* randnumgen; /**< random generator for tiebreaking */
68 SCIP_Real objparalweight; /**< weight of objective parallelism in cut score calculation */
69 SCIP_Real efficacyweight; /**< weight of efficacy in cut score calculation */
70 SCIP_Real dircutoffdistweight;/**< weight of directed cutoff distance in cut score calculation */
71 SCIP_Real intsupportweight; /**< weight of integral support in cut score calculation */
72 SCIP_Real mingain; /**< minimal projection efficacy gain for a cut to enter the LP in percent */
73 SCIP_Real minortho; /**< minimal orthogonality for a cut to enter the LP */
74 int maxdepth; /**< maximum depth at which this cutselector is used (-1 : all nodes) */
75 char filtermode; /**< filtering strategy during cut selection (
76 * 'd'ynamic- and 'f'ull dynamic parallelism) */
77};
78
79/*
80 * Local methods
81 */
82
83/* put your local methods here, and declare them static */
84
85/** returns the maximum score of cuts; if scores is not NULL, then stores the individual score of each cut in scores */
86static
88 SCIP* scip, /**< SCIP data structure */
89 SCIP_ROW** cuts, /**< array with cuts to score */
90 SCIP_RANDNUMGEN* randnumgen, /**< random number generator for tie-breaking, or NULL */
91 SCIP_Real dircutoffdistweight,/**< weight of directed cutoff distance in cut score calculation */
92 SCIP_Real efficacyweight, /**< weight of efficacy in cut score calculation */
93 SCIP_Real objparalweight, /**< weight of objective parallelism in cut score calculation */
94 SCIP_Real intsupportweight, /**< weight of integral support in cut score calculation */
95 int* currentncuts, /**< current number of cuts in cuts array */
96 SCIP_Real* scores /**< array to store the score of cuts or NULL */
97 )
98{
99 SCIP_Real maxscore = 0.0;
100 SCIP_SOL* sol;
101 int i;
102 int ncuts = *currentncuts;
103
105
106 /* if there is an incumbent and the factor is not 0.0, compute directed cutoff distances for the incumbent */
107 if( sol != NULL && dircutoffdistweight > 0.0 )
108 {
109 for( i = ncuts-1; i >= 0; --i )
110 {
111 SCIP_Real score;
112 SCIP_Real objparallelism;
113 SCIP_Real intsupport;
114 SCIP_Real efficacy;
115
116 if( intsupportweight > 0.0 )
117 intsupport = intsupportweight * SCIPgetRowNumIntCols(scip, cuts[i]) / (SCIP_Real) SCIProwGetNNonz(cuts[i]);
118 else
119 intsupport = 0.0;
120
121 if( objparalweight > 0.0 )
122 objparallelism = objparalweight * SCIPgetRowObjParallelism(scip, cuts[i]);
123 else
124 objparallelism = 0.0;
125
126 efficacy = SCIPgetCutEfficacy(scip, NULL, cuts[i]);
127
128 if( SCIProwIsLocal(cuts[i]) )
129 {
130 score = dircutoffdistweight * efficacy;
131 }
132 else
133 {
134 score = SCIPgetCutLPSolCutoffDistance(scip, sol, cuts[i]);
135 score = dircutoffdistweight * MAX(score, efficacy);
136 }
137
138 score += objparallelism + intsupport + efficacyweight * efficacy;
139
140 /* add small term to prefer global pool cuts */
141 if( SCIProwIsInGlobalCutpool(cuts[i]) )
142 score += 1e-4;
143
144 if( randnumgen != NULL)
145 {
146 score += SCIPrandomGetReal(randnumgen, 0.0, 1e-6);
147 }
148
149 maxscore = MAX(maxscore, score);
150
151 if( SCIPisLE(scip, score, 0.0) || efficacy == 0.0 ) /*lint !e777*/
152 {
153 --ncuts;
154 SCIPswapPointers((void**) &cuts[i], (void**) &cuts[ncuts]);
155 if( scores != NULL )
156 SCIPswapReals(&scores[i], &scores[ncuts]);
157 }
158 else if( scores != NULL )
159 {
160 scores[i] = score;
161 }
162 }
163 }
164 else
165 {
166 /* in case there is no solution add the directed cutoff distance weight to the efficacy weight
167 * since the efficacy underestimates the directed cuttoff distance
168 */
169 efficacyweight += dircutoffdistweight;
170
171 /*lint -e{850} i is modified in the body of the for loop */
172 for( i = ncuts-1; i >= 0; --i )
173 {
174 SCIP_Real score;
175 SCIP_Real objparallelism;
176 SCIP_Real intsupport;
177 SCIP_Real efficacy;
178
179 if( intsupportweight > 0.0 )
180 intsupport = intsupportweight * SCIPgetRowNumIntCols(scip, cuts[i]) / (SCIP_Real) SCIProwGetNNonz(cuts[i]);
181 else
182 intsupport = 0.0;
183
184 if( objparalweight > 0.0 )
185 objparallelism = objparalweight * SCIPgetRowObjParallelism(scip, cuts[i]);
186 else
187 objparallelism = 0.0;
188
189 efficacy = SCIPgetCutEfficacy(scip, NULL, cuts[i]);
190
191 score = objparallelism + intsupport + efficacyweight * efficacy;
192
193 /* add small term to prefer global pool cuts */
194 if( SCIProwIsInGlobalCutpool(cuts[i]) )
195 score += 1e-4;
196
197 if( randnumgen != NULL)
198 {
199 score += SCIPrandomGetReal(randnumgen, 0.0, 1e-6);
200 }
201
202 maxscore = MAX(maxscore, score);
203
204 if( SCIPisLE(scip, score, 0.0) || efficacy == 0.0 ) /*lint !e777*/
205 {
206 --ncuts;
207 SCIPswapPointers((void**) &cuts[i], (void**) &cuts[ncuts]);
208 if( scores != NULL )
209 SCIPswapReals(&scores[i], &scores[ncuts]);
210 }
211 else if( scores != NULL )
212 {
213 scores[i] = score;
214 }
215 }
216 }
217 *currentncuts = ncuts;
218}
219
220/** compute projectioncut score for cuts from a given bestcut. **/
221static
223 SCIP* scip, /**< SCIP data structure */
224 SCIP_ROW* bestcut, /**< cut to filter orthogonality with */
225 SCIP_ROW* cut, /**< cut to perform scoring on */
226 SCIP_Real* score /**< score for cut */
227 )
228{
229 SCIP_Real efficacy;
230 SCIP_Real currentbestefficacy;
231 SCIP_Real cosineangle;
232
233 SCIPdebugMsg(scip, "\ncomputeProjectionScore.\n\n");
234 currentbestefficacy = SCIPgetCutEfficacy(scip, NULL, bestcut);
235 SCIPdebugMsg(scip, "currentbestefficacy = %g\n", currentbestefficacy);
236
237 efficacy = SCIPgetCutEfficacy(scip, NULL, cut);
238 SCIPdebugMsg(scip, "efficacy[%s] = %g\n", SCIProwGetName(cut), efficacy);
239
240 cosineangle = SCIProwGetParallelism(bestcut, cut, 'e');
241 if( SCIPisEQ(scip, cosineangle, 1.0))
242 *score = -SCIPinfinity(scip);
243 else
244 {
245 *score = sqrt(currentbestefficacy * currentbestefficacy + efficacy * efficacy
246 - 2.0 * fabs(currentbestefficacy) * fabs(efficacy) * cosineangle)
247 / sqrt((1.0 - (cosineangle * cosineangle)));
248 *score -= currentbestefficacy;
249 }
250 SCIPdebugMsg(scip, "Projectionscore[%s] = %g\n", SCIProwGetName(cut), *score);
251 return SCIP_OKAY;
252}
253
254/** move the cut with the highest score to the first position in the array; there must be at least one cut */
255static
257 SCIP_ROW** cuts, /**< array with cuts to perform selection algorithm */
258 SCIP_Real* scores, /**< array with scores of cuts to perform selection algorithm */
259 int ncuts /**< number of cuts in given array */
260 )
261{
262 int i;
263 int bestpos;
264 SCIP_Real bestscore;
265
266 assert(ncuts > 0);
267 assert(cuts != NULL);
268 assert(scores != NULL);
269
270 bestscore = scores[0];
271 bestpos = 0;
272
273 for( i = 1; i < ncuts; ++i )
274 {
275 if( scores[i] > bestscore )
276 {
277 bestpos = i;
278 bestscore = scores[i];
279 }
280 }
281
282 SCIPswapPointers((void**) &cuts[bestpos], (void**) &cuts[0]);
283 SCIPswapReals(&scores[bestpos], &scores[0]);
284}
285
286/** filters the given array of cuts to enforce a maximum parallelism constraint
287 * w.r.t the given cut; moves filtered cuts to the end of the array and returns number of selected cuts */
288static
290 SCIP* scip, /**< SCIP data structure */
291 SCIP_ROW* bestcut, /**< cut to filter orthogonality with */
292 SCIP_ROW** cuts, /**< array with cuts to perform selection algorithm */
293 SCIP_Real* scores, /**< array with scores of cuts to perform selection algorithm */
294 SCIP_Real mingain, /**< minimum gain enforced on the two-cut efficacy */
295 SCIP_Real maxparall, /**< maximal parallelism for all cuts that are not good */
296 int ncuts /**< number of cuts in given array */
297 )
298{
299 int i;
300 SCIP_Bool filter;
301 SCIP_Real bestcutefficacy;
302
303 SCIPdebugMsg(scip, "\nfilterWithDynamicParallelism.\n\n");
304
305 assert(bestcut != NULL);
306 assert(ncuts == 0 || cuts != NULL);
307 assert(ncuts == 0 || scores != NULL);
308
309 bestcutefficacy = SCIPgetCutEfficacy(scip, NULL, bestcut);
310 assert(bestcutefficacy > 0.0); /* ensured in scoring() */
311
312 /*lint -e{850} i is modified in the body of the for loop */
313 for( i = ncuts-1; i >= 0; --i )
314 {
315 SCIP_Real thisparall;
316 SCIP_Real cosine;
317 SCIP_Real currentcutefficacy;
318 SCIP_Real minmaxparall;
319
320 currentcutefficacy = SCIPgetCutEfficacy(scip, NULL, cuts[i]);
321 assert(currentcutefficacy > 0.0); /* ensured in scoring() */
322
323 if( SCIPisGE(scip, bestcutefficacy, currentcutefficacy))
324 {
325 cosine = SCIProwGetParallelism(bestcut, cuts[i], 'e');
326 thisparall = cosine * bestcutefficacy / currentcutefficacy;
327 SCIPdebugMsg(scip, "Thisparall(%g) = cosine(%g) * (bestcutefficacy(%g)/ currentcutefficacy(%g))\n\n", thisparall,
328 cosine, bestcutefficacy, currentcutefficacy);
329 }
330 else
331 {
332 cosine = SCIProwGetParallelism(cuts[i], bestcut, 'e');
333 thisparall = cosine * currentcutefficacy / bestcutefficacy;
334 SCIPdebugMsg(scip, "Thisparall(%g) = cosine(%g) * (currentcutefficacy(%g) / bestcutefficacy(%g))\n\n", thisparall,
335 cosine, currentcutefficacy, bestcutefficacy);
336 }
337
338 /* compute the max-minimum angle for given the given cuts to enforce
339 * norm(d) >= (1+mingain)*eff1 for non-negative cosine angle */
340 minmaxparall = MAX( (bestcutefficacy * bestcutefficacy
341 + currentcutefficacy * currentcutefficacy
342 - (1 + mingain) * bestcutefficacy * (1 + mingain) * bestcutefficacy * (1 - cosine * cosine))
343 / (2 * bestcutefficacy * currentcutefficacy),
344 maxparall );
345 filter = ( SCIPisGE(scip, thisparall, 1.0) || SCIPisGT(scip, cosine, minmaxparall) );
346
347 SCIPdebugMsg(scip, "Filter = %u\n", filter);
348
349 if( filter )
350 {
351 --ncuts;
352 SCIPswapPointers((void**) &cuts[i], (void**) &cuts[ncuts]);
353 SCIPswapReals(&scores[i], &scores[ncuts]);
354 }
355 }
356
357 return ncuts;
358}
359
360
361/*
362 * Callback methods of cut selector
363 */
364
365/** copy method for cut selector plugin (called when SCIP copies plugins) */
366static
367SCIP_DECL_CUTSELCOPY(cutselCopyDynamic)
368{ /*lint --e{715}*/
369 assert(scip != NULL);
370 assert(cutsel != NULL);
371 assert(strcmp(SCIPcutselGetName(cutsel), CUTSEL_NAME) == 0);
372
373 /* call inclusion method of cut selector */
375
376 return SCIP_OKAY;
377}
378
379/** destructor of cut selector to free user data (called when SCIP is exiting) */
380/**! [SnippetCutselFreeDynamic] */
381static
382SCIP_DECL_CUTSELFREE(cutselFreeDynamic)
383{ /*lint --e{715}*/
384 SCIP_CUTSELDATA* cutseldata;
385
386 cutseldata = SCIPcutselGetData(cutsel);
387
388 SCIPfreeBlockMemory(scip, &cutseldata);
389
390 SCIPcutselSetData(cutsel, NULL);
391
392 return SCIP_OKAY;
393}
394/**! [SnippetCutselFreeDynamic] */
395
396/** initialization method of cut selector (called after problem was transformed) */
397static
398SCIP_DECL_CUTSELINIT(cutselInitDynamic)
399{ /*lint --e{715}*/
400 SCIP_CUTSELDATA* cutseldata;
401
402 cutseldata = SCIPcutselGetData(cutsel);
403 assert(cutseldata != NULL);
404
405 SCIP_CALL( SCIPcreateRandom(scip, &(cutseldata)->randnumgen, RANDSEED, TRUE) );
406
407 return SCIP_OKAY;
408}
409
410/** deinitialization method of cut selector (called before transformed problem is freed) */
411static
412SCIP_DECL_CUTSELEXIT(cutselExitDynamic)
413{ /*lint --e{715}*/
414 SCIP_CUTSELDATA* cutseldata;
415
416 cutseldata = SCIPcutselGetData(cutsel);
417 assert(cutseldata != NULL);
418 assert(cutseldata->randnumgen != NULL);
419
420 SCIPfreeRandom(scip, &cutseldata->randnumgen);
421
422 return SCIP_OKAY;
423}
424
425/** cut selection method of cut selector */
426static
427SCIP_DECL_CUTSELSELECT(cutselSelectDynamic)
428{ /*lint --e{715}*/
429 SCIP_CUTSELDATA *cutseldata;
430
431 assert(cutsel != NULL);
432 assert(result != NULL);
433
435
436 cutseldata = SCIPcutselGetData(cutsel);
437 assert(cutseldata != NULL);
438 if (cutseldata->maxdepth != -1 && cutseldata->maxdepth < SCIPgetDepth(scip))
439 {
441 return SCIP_OKAY;
442 }
443
444 SCIP_CALL( SCIPselectCutsDynamic(scip, cuts, forcedcuts, cutseldata->randnumgen, cutseldata->filtermode,
445 cutseldata->mingain, 1-cutseldata->minortho, cutseldata->dircutoffdistweight, cutseldata->efficacyweight,
446 cutseldata->objparalweight, cutseldata->intsupportweight, ncuts, nforcedcuts,
447 maxnselectedcuts, nselectedcuts) );
448
449 return SCIP_OKAY;
450}
451
452
453/*
454 * cut selector specific interface methods
455 */
456
457/** creates the dynamic cut selector and includes it in SCIP */
459 SCIP* scip /**< SCIP data structure */
460 )
461{
462 SCIP_CUTSELDATA* cutseldata;
463 SCIP_CUTSEL* cutsel;
464
465 /* create dynamic cut selector data */
466 SCIP_CALL( SCIPallocBlockMemory(scip, &cutseldata) );
467 BMSclearMemory(cutseldata);
468
469 SCIP_CALL( SCIPincludeCutselBasic(scip, &cutsel, CUTSEL_NAME, CUTSEL_DESC, CUTSEL_PRIORITY, cutselSelectDynamic, cutseldata) );
470
471 assert(cutsel != NULL);
472
473 /* set non fundamental callbacks via setter functions */
474 SCIP_CALL( SCIPsetCutselCopy(scip, cutsel, cutselCopyDynamic) );
475
476 SCIP_CALL( SCIPsetCutselFree(scip, cutsel, cutselFreeDynamic) );
477 SCIP_CALL( SCIPsetCutselInit(scip, cutsel, cutselInitDynamic) );
478 SCIP_CALL( SCIPsetCutselExit(scip, cutsel, cutselExitDynamic) );
479
480 /* add dynamic cut selector parameters */
482 "cutselection/" CUTSEL_NAME "/efficacyweight",
483 "weight of efficacy in cut score calculation",
484 &cutseldata->efficacyweight, FALSE,
486
488 "cutselection/" CUTSEL_NAME "/dircutoffdistweight",
489 "weight of directed cutoff distance in cut score calculation",
490 &cutseldata->dircutoffdistweight, FALSE,
492
494 "cutselection/" CUTSEL_NAME "/objparalweight",
495 "weight of objective parallelism in cut score calculation",
496 &cutseldata->objparalweight, FALSE,
498
500 "cutselection/" CUTSEL_NAME "/intsupportweight",
501 "weight of integral support in cut score calculation",
502 &cutseldata->intsupportweight, FALSE,
504
506 "cutselection/" CUTSEL_NAME "/mingain",
507 "minimal efficacy gain for a cut to enter the LP",
508 &cutseldata->mingain, FALSE,
509 DEFAULT_MINGAIN, 0.0, 1.0, NULL, NULL) );
510
512 "cutselection/" CUTSEL_NAME "/filtermode",
513 "filtering strategy during cut selection",
514 &cutseldata->filtermode, FALSE,
515 DEFAULT_FILTERMODE, "df", NULL, NULL) );
516
518 "cutselection/" CUTSEL_NAME "/minortho",
519 "minimal orthogonality for a cut to enter the LP",
520 &cutseldata->minortho, FALSE,
521 DEFAULT_MINORTHO, 0.0, 1.0, NULL, NULL) );
522
524 "cutselection/" CUTSEL_NAME "/maxdepth",
525 "maximum depth at which this cutselector is employed",
526 &cutseldata->maxdepth, FALSE,
528
529 return SCIP_OKAY;
530}
531
532
533/** perform a cut selection algorithm for the given array of cuts
534 *
535 * This is the selection method of the dynamic cut selector which implements
536 * the dynamic orthognality filtering based on the ratio of efficacies.
537 * The input cuts array gets re-sorted s.t the selected cuts come first and the remaining
538 * ones are the end.
539 */
541 SCIP* scip, /**< SCIP data structure */
542 SCIP_ROW** cuts, /**< array with cuts to perform selection algorithm */
543 SCIP_ROW** forcedcuts, /**< array with forced cuts */
544 SCIP_RANDNUMGEN* randnumgen, /**< random number generator for tie-breaking, or NULL */
545 char filtermode, /**< filtering strategy during cut selection (
546 * 'd'ynamic- and 'f'ull dynamic parallelism) */
547 SCIP_Real mingain, /**< minimum efficacy gain in percentage to filter cuts */
548 SCIP_Real maxparall, /**< maximal parallelism for all cuts that are not good */
549 SCIP_Real dircutoffdistweight,/**< weight of directed cutoff distance in cut score calculation */
550 SCIP_Real efficacyweight, /**< weight of efficacy in cut score calculation */
551 SCIP_Real objparalweight, /**< weight of objective parallelism in cut score calculation */
552 SCIP_Real intsupportweight, /**< weight of integral support in cut score calculation */
553 int ncuts, /**< number of cuts in cuts array */
554 int nforcedcuts, /**< number of forced cuts */
555 int maxselectedcuts, /**< maximal number of cuts from cuts array to select */
556 int* nselectedcuts /**< pointer to return number of selected cuts from cuts array */
557 )
558{
559 SCIP_ROW* selectedcut;
560 SCIP_Real* scores;
561 SCIP_Real* forcedscores;
562 SCIP_Real* scoresptr;
563 int ngoodforcedcuts;
564 int i;
565
566 assert(cuts != NULL && ncuts > 0);
567 assert(forcedcuts != NULL || nforcedcuts == 0);
568 assert(nselectedcuts != NULL);
569
570 *nselectedcuts = 0;
571 ngoodforcedcuts = 0;
572
573 SCIP_CALL( SCIPallocBufferArray(scip, &scores, ncuts) );
574
575 /* compute scores of cuts and max score of cuts and forced cuts (used to define goodscore) */
576 scoring(scip, cuts, randnumgen, dircutoffdistweight, efficacyweight, objparalweight, intsupportweight, &ncuts,
577 scores);
578 scoresptr = scores;
579
580 SCIPdebugMsg(scip, "nforcedcuts = %i.\n", nforcedcuts);
581
582 /* perform cut selection algorithm for the cuts */
583
584 /* forced cuts are going to be selected so use them to filter cuts */
585 for( i = 0; i < nforcedcuts && ncuts > 0; ++i )
586 ncuts = filterWithDynamicParallelism(scip, forcedcuts[i], cuts, scores, mingain, maxparall, ncuts);
587
588 /* if all cuts are already filtered, we can stop */
589 if( ncuts <= 0 )
590 goto TERMINATE;
591
592 /* if the maximal number of cuts was selected, we can stop here */
593 if( *nselectedcuts == maxselectedcuts )
594 goto TERMINATE;
595
596 if( filtermode == 'f' && nforcedcuts > 0 )
597 {
598 SCIP_CALL( SCIPallocBufferArray(scip, &forcedscores, nforcedcuts) );
599 ngoodforcedcuts = nforcedcuts;
600 scoring(scip, forcedcuts, randnumgen, dircutoffdistweight, efficacyweight, objparalweight, intsupportweight,
601 &ngoodforcedcuts, forcedscores);
602
603 if( ngoodforcedcuts != 0 )
604 {
605 selectBestCut(forcedcuts, forcedscores, ngoodforcedcuts);
606 SCIPfreeBufferArray(scip, &forcedscores);
607 SCIPdebugMsg(scip, "best forced cut: %s.\n", SCIProwGetName(forcedcuts[0]));
608
609 for( i = 0; i < ncuts; i++ )
610 {
611 SCIP_CALL( computeProjectionScore(scip, forcedcuts[0], cuts[i], &scores[i]) );
612 SCIPdebugMsg(scip, "scores[%i] = %g\n", i, scores[i]);
613 }
614 }
615 }
616
617 if( ngoodforcedcuts == 0 )
618 {
619 assert(filtermode == 'd' || ngoodforcedcuts == 0);
620 selectBestCut(cuts, scores, ncuts);
621
622 selectedcut = cuts[0];
623 SCIPdebugMsg(scip, "selectedcut = %s.\n", SCIProwGetName(selectedcut));
624
625 ++(*nselectedcuts);
626
627 /* if the maximal number of cuts was selected, we can stop here */
628 if( *nselectedcuts == maxselectedcuts )
629 goto TERMINATE;
630
631 /* move the pointers to the next position and filter the remaining cuts to enforce the dynamic parallelism constraint */
632 ++cuts;
633 ++scores;
634 --ncuts;
635
636 ncuts = filterWithDynamicParallelism(scip, selectedcut, cuts, scores, mingain, maxparall, ncuts);
637
638 if( filtermode == 'f' )
639 {
640 for( i = 0; i < ncuts; i++ )
641 {
642 SCIP_CALL( computeProjectionScore(scip, selectedcut, cuts[i], &scores[i]) );
643 }
644 }
645 }
646
647 SCIPdebugMsg(scip, "ncuts after forced cut filter = %i.\n", ncuts);
648
649 /* now greedily select the remaining cuts */
650 while( ncuts > 0 )
651 {
652 selectBestCut(cuts, scores, ncuts);
653 selectedcut = cuts[0];
654 SCIPdebugMsg(scip, "selectedcut = %s.\n", SCIProwGetName(selectedcut));
655
656 ++(*nselectedcuts);
657
658 /* if the maximal number of cuts was selected, we can stop here */
659 if( *nselectedcuts == maxselectedcuts )
660 goto TERMINATE;
661
662 /* move the pointers to the next position and filter the remaining cuts to enforce the dynamic parallelism constraint */
663 ++cuts;
664 ++scores;
665 --ncuts;
666
667 ncuts = filterWithDynamicParallelism(scip, selectedcut, cuts, scores, mingain, maxparall, ncuts);
668
669 if( filtermode == 'f' )
670 {
671 for( i = 0; i < ncuts; i++ )
672 {
673 SCIP_CALL( computeProjectionScore(scip, selectedcut, cuts[i], &scores[i]) );
674 SCIPdebugMsg(scip, "nonforcedscores[%i] = %g\n", i, scores[i]);
675 }
676 }
677 }
678
679 TERMINATE:
680 SCIPfreeBufferArray(scip, &scoresptr);
681 return SCIP_OKAY;
682}
#define DEFAULT_EFFICACYWEIGHT
#define DEFAULT_INTSUPPORTWEIGHT
#define DEFAULT_MAXDEPTH
#define DEFAULT_MINGAIN
#define DEFAULT_OBJPARALWEIGHT
#define RANDSEED
static int filterWithDynamicParallelism(SCIP *scip, SCIP_ROW *bestcut, SCIP_ROW **cuts, SCIP_Real *scores, SCIP_Real mingain, SCIP_Real maxparall, int ncuts)
static void selectBestCut(SCIP_ROW **cuts, SCIP_Real *scores, int ncuts)
#define CUTSEL_DESC
#define DEFAULT_FILTERMODE
#define CUTSEL_PRIORITY
static SCIP_RETCODE computeProjectionScore(SCIP *scip, SCIP_ROW *bestcut, SCIP_ROW *cut, SCIP_Real *score)
#define DEFAULT_MINORTHO
#define DEFAULT_DIRCUTOFFDISTWEIGHT
static void scoring(SCIP *scip, SCIP_ROW **cuts, SCIP_RANDNUMGEN *randnumgen, SCIP_Real dircutoffdistweight, SCIP_Real efficacyweight, SCIP_Real objparalweight, SCIP_Real intsupportweight, int *currentncuts, SCIP_Real *scores)
#define CUTSEL_NAME
dynamic cut selector
#define NULL
Definition def.h:255
#define SCIP_MAXTREEDEPTH
Definition def.h:304
#define SCIP_INVALID
Definition def.h:185
#define SCIP_Bool
Definition def.h:98
#define SCIP_Real
Definition def.h:163
#define TRUE
Definition def.h:100
#define FALSE
Definition def.h:101
#define MAX(x, y)
Definition def.h:227
#define SCIP_CALL(x)
Definition def.h:362
SCIP_RETCODE SCIPselectCutsDynamic(SCIP *scip, SCIP_ROW **cuts, SCIP_ROW **forcedcuts, SCIP_RANDNUMGEN *randnumgen, char filtermode, SCIP_Real mingain, SCIP_Real maxparall, SCIP_Real dircutoffdistweight, SCIP_Real efficacyweight, SCIP_Real objparalweight, SCIP_Real intsupportweight, int ncuts, int nforcedcuts, int maxselectedcuts, int *nselectedcuts)
SCIP_RETCODE SCIPincludeCutselDynamic(SCIP *scip)
#define SCIPdebugMsg
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition scip_param.c:167
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)
Definition scip_param.c:83
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)
Definition scip_param.c:139
void SCIPswapPointers(void **pointer1, void **pointer2)
Definition misc.c:10511
void SCIPswapReals(SCIP_Real *value1, SCIP_Real *value2)
Definition misc.c:10498
SCIP_Real SCIPgetCutEfficacy(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition scip_cut.c:94
SCIP_Real SCIPgetCutLPSolCutoffDistance(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition scip_cut.c:72
SCIP_RETCODE SCIPsetCutselInit(SCIP *scip, SCIP_CUTSEL *cutsel,)
SCIP_RETCODE SCIPincludeCutselBasic(SCIP *scip, SCIP_CUTSEL **cutsel, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
Definition scip_cutsel.c:98
SCIP_RETCODE SCIPsetCutselCopy(SCIP *scip, SCIP_CUTSEL *cutsel,)
SCIP_RETCODE SCIPsetCutselExit(SCIP *scip, SCIP_CUTSEL *cutsel,)
SCIP_CUTSELDATA * SCIPcutselGetData(SCIP_CUTSEL *cutsel)
Definition cutsel.c:419
void SCIPcutselSetData(SCIP_CUTSEL *cutsel, SCIP_CUTSELDATA *cutseldata)
Definition cutsel.c:429
const char * SCIPcutselGetName(SCIP_CUTSEL *cutsel)
Definition cutsel.c:159
SCIP_RETCODE SCIPsetCutselFree(SCIP *scip, SCIP_CUTSEL *cutsel,)
#define SCIPallocBufferArray(scip, ptr, num)
Definition scip_mem.h:124
#define SCIPfreeBufferArray(scip, ptr)
Definition scip_mem.h:136
#define SCIPfreeBlockMemory(scip, ptr)
Definition scip_mem.h:108
#define SCIPallocBlockMemory(scip, ptr)
Definition scip_mem.h:89
SCIP_Real SCIProwGetParallelism(SCIP_ROW *row1, SCIP_ROW *row2, char orthofunc)
Definition lp.c:7970
int SCIProwGetNNonz(SCIP_ROW *row)
Definition lp.c:17607
SCIP_Bool SCIProwIsInGlobalCutpool(SCIP_ROW *row)
Definition lp.c:17885
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition lp.c:17795
const char * SCIProwGetName(SCIP_ROW *row)
Definition lp.c:17745
SCIP_Real SCIPgetRowObjParallelism(SCIP *scip, SCIP_ROW *row)
Definition scip_lp.c:2154
int SCIPgetRowNumIntCols(SCIP *scip, SCIP_ROW *row)
Definition scip_lp.c:1832
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition scip_sol.c:2988
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIPgetDepth(SCIP *scip)
Definition scip_tree.c:672
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
Definition misc.c:10245
return SCIP_OKAY
SCIPfreeRandom(scip, &heurdata->randnumgen)
int maxdepth
SCIPcreateRandom(scip, &heurdata->randnumgen, DEFAULT_RANDSEED, TRUE))
static SCIP_SOL * sol
assert(minobj< SCIPgetCutoffbound(scip))
#define BMSclearMemory(ptr)
Definition memory.h:129
public methods for cuts and aggregation rows
public methods for cut selector plugins
public methods for the LP relaxation, rows and columns
public methods for random numbers
#define SCIP_DECL_CUTSELEXIT(x)
Definition type_cutsel.h:86
#define SCIP_DECL_CUTSELSELECT(x)
#define SCIP_DECL_CUTSELFREE(x)
Definition type_cutsel.h:70
struct SCIP_Cutsel SCIP_CUTSEL
Definition type_cutsel.h:52
struct SCIP_CutselData SCIP_CUTSELDATA
Definition type_cutsel.h:53
#define SCIP_DECL_CUTSELINIT(x)
Definition type_cutsel.h:78
#define SCIP_DECL_CUTSELCOPY(x)
Definition type_cutsel.h:62
struct SCIP_Row SCIP_ROW
Definition type_lp.h:105
struct SCIP_RandNumGen SCIP_RANDNUMGEN
Definition type_misc.h:127
@ SCIP_DIDNOTFIND
Definition type_result.h:44
@ SCIP_SUCCESS
Definition type_result.h:58
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
Definition type_scip.h:39
struct SCIP_Sol SCIP_SOL
Definition type_sol.h:57