GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
benders_gcg.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 benders_gcg.c
30 * @brief GCG Benders' decomposition algorithm
31 * @author Stephen J. Maher
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35/* #define SCIP_DEBUG */
36#include <assert.h>
37#include <string.h>
38
39#include "gcg/benders_gcg.h"
40
41#include "gcg/gcg.h"
42
43#include "gcg/relax_gcg.h"
44#include "gcg/scip_misc.h"
45#include "gcg/pub_gcgvar.h"
46
47#include "scip/cons_linear.h"
48#include "scip/pub_var.h"
49#include "scip/pub_benders.h"
50#include "scip/bendersdefcuts.h"
51
52#define BENDERS_NAME "gcg"
53#define BENDERS_DESC "Benders' decomposition for the Generic Column Generation package"
54#define BENDERS_PRIORITY 1000
55#define BENDERS_CUTLP TRUE /**< should Benders' cut be generated for LP solutions */
56#define BENDERS_CUTPSEUDO TRUE /**< should Benders' cut be generated for pseudo solutions */
57#define BENDERS_CUTRELAX TRUE /**< should Benders' cut be generated for relaxation solutions */
58#define BENDERS_SHAREAUXVARS FALSE /**< should this Benders' share the highest priority Benders' aux vars */
59
60#define LARGE_VALUE 10000 /**< a large value that is used to create an artificial solution */
61
62/*
63 * Data structures
64 */
65
66/** Benders' decomposition data */
68{
69 GCG* gcg; /**< the GCG instance */
70 SCIP_SOL* relaxsol; /**< the solution to the original problem related to the relaxation */
71};
72
73/*
74 * Local methods
75 */
76
77/* returns the objective coefficient for the given variable */
78static
81 )
82{
83 SCIP_VAR* origvar;
84 assert(var != NULL);
85
86 origvar = GCGpricingVarGetOrigvars(var)[0];
87
88 if( GCGoriginalVarIsLinking(origvar) )
89 return 0.0;
90 else
91 return SCIPvarGetObj(origvar);
92}
93
94/* Initializes the objective function for all subproblems. */
95static
97 SCIP_BENDERS* benders, /**< the benders' decomposition constraint handler */
98 int probnumber /**< the subproblem number */
99 )
100{
101 SCIP* subproblem;
102 SCIP_VAR** probvars;
103 int nprobvars;
104 int i;
105
106 assert(benders != NULL);
107
108 /* changing the variable */
109 subproblem = SCIPbendersSubproblem(benders, probnumber);
110 assert(subproblem != NULL);
111
112 probvars = SCIPgetVars(subproblem);
113 nprobvars = SCIPgetNVars(subproblem);
114
115 for( i = 0; i < nprobvars; i++ )
116 {
117 assert(GCGvarGetBlock(probvars[i]) == probnumber);
118 assert(GCGoriginalVarIsLinking(GCGpricingVarGetOrigvars(probvars[i])[0]) || (GCGvarGetBlock(GCGpricingVarGetOrigvars(probvars[i])[0]) == probnumber));
119
120 SCIP_CALL( SCIPchgVarObj(subproblem, probvars[i], varGetObj(probvars[i])));
121
122 SCIPdebugMessage("pricingobj var <%s> %f\n", SCIPvarGetName(probvars[i]), varGetObj(probvars[i]));
123 }
124
125 return SCIP_OKAY;
126}
127
128/** sets the pricing problem variable values for the original problem using the decomposed problem solution
129 * There is a mapping between the original problem and the variables from the pricing problems. This mapping is used to
130 * identify the variables of the original problem corresponding to the pricing problem variables.
131 *
132 * An artificial solution can be constructed, which is indicated by the vals array provided as NULL. An artifical
133 * solution sets the original problem variables corresponding to pricing problems variables to their bounds. An
134 * artificial solution is created if branching candidates need to be found. Branching candidates only come from the
135 * master problem, so the variable values of the pricing problem variables does not affect the branching variable
136 * selection
137 */
138static
140 SCIP* origprob, /**< the SCIP instance of the original problem */
141 SCIP* masterprob, /**< the Benders' master problem */
142 SCIP_BENDERS* benders, /**< the Benders' decomposition structure */
143 SCIP_SOL* origsol, /**< the solution for the original problem */
144 SCIP_VAR** vars, /**< the variables from the decomposed problem */
145 SCIP_Real* vals, /**< the solution values of the given problem, can be NULL for an
146 artificial solution */
147 int nvars, /**< the number of variables */
148 SCIP_Bool* success /**< were all values set successfully? */
149 )
150{
151 SCIP_VAR** origvars;
152 SCIP_Real val;
153 int norigvars;
154 int i;
155
156 assert(origprob != NULL);
158 assert(benders != NULL);
159 assert(vars != NULL);
160
161 (*success) = TRUE;
162
163 /* looping through all variables to update the values in the original solution */
164 for( i = 0; i < nvars; i++ )
165 {
166 norigvars = GCGpricingVarGetNOrigvars(vars[i]);
167 if( norigvars > 0 )
168 {
169 SCIP_VAR* mastervar;
170
171 origvars = GCGpricingVarGetOrigvars(vars[i]);
172
173 /* all variables should be associated with a single original variable. This is because no reformulation has
174 * been performed.
175 * TODO: This appears not to be true. Need to find out why multiple original problem variables are associated
176 * with a pricing variable. Currently the first original variable is used.
177 */
178 /* assert(norigvars == 1); */
180
181 /* for all variables that are from the subproblems, they are set to their bounds if the solution is being
182 * created to identify branching candidates. */
183 if( vals == NULL )
184 {
185 if( SCIPisNegative(origprob, SCIPvarGetObj(origvars[0])) )
186 {
187 val = SCIPvarGetLbGlobal(origvars[0]);
188 if( SCIPisInfinity(origprob, -val) )
189 val = -LARGE_VALUE;
190 }
191 else
192 {
193 val = SCIPvarGetUbGlobal(origvars[0]);
194 if( SCIPisInfinity(origprob, val) )
195 val = LARGE_VALUE;
196 }
197 }
198 else
199 val = vals[i];
200
201 /* identifying whether the variable is a master problem variable. The variable is a master problem variable if
202 * there is a mapping from the subproblem to the master problem. If a mapping exists, then the variable value
203 * is not updated in the master problem
204 */
205 mastervar = NULL;
206 SCIP_CALL( SCIPgetBendersMasterVar(masterprob, benders, vars[i], &mastervar) );
207 if( SCIPisInfinity(origprob, val) || SCIPisInfinity(origprob, -val) )
208 {
209 (*success) = FALSE;
210 return SCIP_OKAY;
211 }
212
213 SCIPdebugMsg(masterprob, "setting the value of <%s> (dw variable <%s>) to %g in the original solution.\n",
214 SCIPvarGetName(origvars[0]), SCIPvarGetName(vars[i]), val);
215
216 /* only update the solution value if the master problem variable does not exist. */
217 if( mastervar == NULL )
218 {
219 SCIP_CALL( SCIPsetSolVal(origprob, origsol, origvars[0], val) );
220 }
221 }
222 }
223
224 return SCIP_OKAY;
225}
226
227/** sets the master problem values for the original problem using the decomposed problem solution */
228static
230 SCIP* origprob, /**< the SCIP instance of the original problem */
231 SCIP* masterprob, /**< the Benders' master problem */
232 SCIP_BENDERS* benders, /**< the Benders' decomposition structure */
233 SCIP_SOL* origsol, /**< the solution for the original problem */
234 SCIP_VAR** vars, /**< the variables from the decomposed problem */
235 SCIP_Real* vals, /**< the solution values of the given problem, can be NULL */
236 int nvars /**< the number of variables */
237 )
238{
239 SCIP_VAR** origvars;
240 int norigvars;
241 int i;
242
243#ifndef NDEBUG
244 SCIP_Real* origvals;
245#endif
246
247 assert(origprob != NULL);
249 assert(benders != NULL);
250 assert(vars != NULL);
251 assert(vals != NULL);
252
253 /* looping through all variables to update the values in the original solution */
254 for( i = 0; i < nvars; i++ )
255 {
256 /* the master problem also contains variables that were not created by GCG, in particular the auxiliary variables
257 * added by SCIP's Benders' framework */
258 if( !GCGvarIsMaster(vars[i]) )
259 continue;
260
261 norigvars = GCGmasterVarGetNOrigvars(vars[i]);
262 if( norigvars > 0 )
263 {
264 origvars = GCGmasterVarGetOrigvars(vars[i]);
265
266#ifndef NDEBUG
267 origvals = GCGmasterVarGetOrigvals(vars[i]);
268#endif
269
270 /* all master variables should be associated with a single original variable. This is because no reformulation has
271 * been performed. */
272 assert(norigvars == 1);
273 assert(origvals[0] == 1.0);
275
276 SCIPdebugMsg(masterprob, "setting the value of <%s> (master variable <%s>) to %g in the original solution.\n",
277 SCIPvarGetName(origvars[0]), SCIPvarGetName(vars[i]), vals[i]);
278
279 /* only update the solution value of master variables. */
280 SCIP_CALL( SCIPsetSolVal(origprob, origsol, origvars[0], vals[i]) );
281 }
282 }
283 return SCIP_OKAY;
284}
285
286/** creates an original problem solution from the master and subproblem solutions */
287static
289 SCIP* masterprob, /**< the Benders' master problem */
290 SCIP_BENDERS* benders, /**< the Benders' decomposition structure */
291 SCIP_SOL* sol, /**< the solution passed to the Benders' decomposition subproblems. */
292 SCIP_Bool artificial /**< should an artifical (possibly infeasible) solution be created to
293 generate branching candidates */
294 )
295{
296 SCIP* origprob;
297 SCIP* subproblem;
298 SCIP_BENDERSDATA* bendersdata;
299 SCIP_SOL* origsol;
300 SCIP_SOL* bestsol;
301 SCIP_VAR** vars;
302 SCIP_Real* vals;
303 int nsubproblems;
304 int nvars;
305 int i;
306 SCIP_Bool stored;
308
310 assert(benders != NULL);
311
312 bendersdata = SCIPbendersGetData(benders);
313
314 assert(bendersdata != NULL);
315
316 origprob = GCGgetOrigprob(bendersdata->gcg);
317
318 success = TRUE;
319
320 /* creating the original problem */
321 SCIP_CALL( SCIPcreateSol(origprob, &origsol, GCGrelaxGetProbingheur(bendersdata->gcg)) );
322
323 /* setting the values of the master variables in the original solution */
324
325 /* getting the variable data for the master variables */
327 assert(vars != NULL);
328
329 /* getting the best solution from the master problem */
332
333 /* setting the values using the master problem solution */
335
336 /* freeing the values buffer array for use for the pricing problems */
338
339 /* setting the values of the subproblem variables in the original solution */
340 nsubproblems = SCIPbendersGetNSubproblems(benders);
341
342 /* looping through all subproblems */
343 for( i = 0; i < nsubproblems; i++ )
344 {
345 /* it is only possible to use the subproblem solutions if the subproblems are enabled. The subproblems are
346 * disabled if they have been merged into the master problem.
347 */
348 if( SCIPbendersSubproblemIsEnabled(benders, i) )
349 {
350 subproblem = SCIPbendersSubproblem(benders, i);
351
352 /* getting the variable data for the master variables */
353 SCIP_CALL( SCIPgetVarsData(subproblem, &vars, &nvars, NULL, NULL, NULL, NULL) );
354 assert(vars != NULL);
355
356 /* getting the best solution from the master problem */
357 bestsol = SCIPgetBestSol(subproblem);
358#ifdef SCIP_DEBUG
359 SCIP_CALL( SCIPprintSol(subproblem, bestsol, NULL, FALSE) );
360#endif
361
362 /* the branching candidates come from the master problem solution. However, we need a full solution to pass to the
363 * original problem to find the branching candidate. So the subproblem variables are set to their bounds, creating
364 * a possibly infeasible solution, but with the fractional master problem variables.
365 *
366 * It may occur that the subproblem has not been solved yet, this can happen if the subproblem is independent.
367 * In this case, an artificial solution is created.
368 */
369 if( artificial || SCIPgetStage(subproblem) == SCIP_STAGE_PROBLEM )
370 {
371 /* setting the values of the subproblem variables to their bounds. */
373 }
374 else
375 {
376 SCIP_CALL( SCIPallocBufferArray(subproblem, &vals, nvars) );
377 SCIP_CALL( SCIPgetSolVals(subproblem, bestsol, nvars, vars, vals) );
378
379 /* setting the values using the master problem solution */
381
382 /* freeing the values buffer array for use for the pricing problems */
383 SCIPfreeBufferArray(subproblem, &vals);
384
385 if( !success )
386 break;
387 }
388 }
389 }
390
391 /* if the values were not set correctly, then the solution is not updated. This should only happen when the timelimit
392 * has been exceeded.
393 */
394 if( !success )
395 {
396 SCIP_CALL( SCIPfreeSol(origprob, &origsol) );
397 return SCIP_OKAY;
398 }
399
400#ifdef SCIP_DEBUG
401 SCIPdebugMsg(masterprob, "Original Solution\n");
403#endif
404
405 /* if the solution is NULL, then the solution comes from the relaxation. Thus, it should be stored in the
406 * bendersdata. When it is not NULL, then solution comes from a heuristic. So this solution should be passed to the
407 * solution storage. */
408 if( sol != NULL )
409 {
410#ifdef SCIP_DEBUG
411 SCIP_CALL( SCIPtrySol(origprob, origsol, TRUE, TRUE, TRUE, TRUE, TRUE, &stored) );
412#else
413 SCIP_CALL( SCIPtrySol(origprob, origsol, FALSE, FALSE, TRUE, TRUE, TRUE, &stored) );
414#endif
415 if( !stored )
416 {
417 SCIP_CALL( SCIPcheckSolOrig(origprob, origsol, &stored, TRUE, TRUE) );
418 }
419
420 /** @bug The solution doesn't have to be accepted, numerics might bite us, so the transformation might fail.
421 * A remedy could be: Round the values or propagate changes or call a heuristic to fix it.
422 */
423 SCIP_CALL( SCIPfreeSol(origprob, &origsol) );
424
425 if( stored )
426 SCIPdebugMessage(" updated current best primal feasible solution.\n");
427 }
428 else
429 {
430 if( bendersdata->relaxsol != NULL )
431 {
432 SCIP_CALL( SCIPfreeSol(origprob, &bendersdata->relaxsol) );
433 }
434
435 bendersdata->relaxsol = origsol;
436 }
437
438 return SCIP_OKAY;
439}
440
441/** merge a single subproblem into the master problem */
442static
444 SCIP* masterprob, /**< the Benders' master problem */
445 SCIP_BENDERS* benders, /**< the Benders' decomposition structure */
446 int probnumber /**< the index of the subproblem that will be merged */
447 )
448{
449 SCIP_BENDERSDATA* bendersdata;
450 SCIP* subproblem;
451 SCIP_HASHMAP* varmap;
452 SCIP_HASHMAP* consmap;
453 SCIP_VAR** vars;
454 int nvars;
455 int i;
456
458 assert(benders != NULL);
459
460 bendersdata = SCIPbendersGetData(benders);
461 assert(bendersdata != NULL);
462 subproblem = SCIPbendersSubproblem(benders, probnumber);
463
464 /* allocating the memory for the variable and constraint hashmaps */
467
468 SCIP_CALL( SCIPmergeBendersSubproblemIntoMaster(masterprob, benders, varmap, consmap, probnumber) );
469
470 SCIP_CALL( SCIPgetVarsData(subproblem, &vars, &nvars, NULL, NULL, NULL, NULL) );
471 /* copying the variable data from the pricing variables to the newly created master variables */
472 for( i = 0; i < nvars; i++ )
473 {
474 SCIP_VAR* mastervar;
475
476 mastervar = (SCIP_VAR*) SCIPhashmapGetImage(varmap, vars[i]);
477 SCIP_CALL( GCGcopyPricingvarDataToMastervar(bendersdata->gcg, vars[i], mastervar) );
478 }
479
480 /* freeing the variable and constraint hashmaps */
481 SCIPhashmapFree(&varmap);
482 SCIPhashmapFree(&consmap);
483
484 return SCIP_OKAY;
485}
486
487/** performs a merge of subproblems into the master problem. The subproblems are merged into the master problem if the
488 * infeasibility can not be resolved through the addition of cuts. This could be because the appropriate cuts are not
489 * available in the Benders' decomposition framework, or that the subproblem has been infeasible for a set number of
490 * iterations.
491 */
492static
494 SCIP* masterprob, /**< the Benders' master problem */
495 SCIP_BENDERS* benders, /**< the Benders' decomposition structure */
496 int* mergecands, /**< the subproblems that are merge candidates */
497 int npriomergecands, /**< the priority merge candidates, these should be merged */
498 int nmergecands, /**< the total number of merge candidates */
499 SCIP_Bool* merged /**< flag to indicate whether a subproblem has been merged into the master */
500 )
501{
502 int i;
503
505 assert(benders != NULL);
506
507 (*merged) = FALSE;
508
509 /* adding the priority merge candidates. If there are no priority candidates, then the first merge candidate is
510 * added.
511 */
512 for( i = 0; i < npriomergecands; i++ )
513 {
514 SCIP_CALL( mergeSubproblemIntoMaster(masterprob, benders, mergecands[i]) );
515 (*merged) = TRUE;
516 }
517
518 /* if there were no priority candidates and there is a merge candidate, then only a single merge candidate is
519 * merged.
520 */
521 if( !(*merged) && nmergecands > 0 )
522 {
523 assert(npriomergecands == 0);
524
525 SCIP_CALL( mergeSubproblemIntoMaster(masterprob, benders, mergecands[0]) );
526 (*merged) = TRUE;
527 }
528
529 return SCIP_OKAY;
530}
531
532/*
533 * Callback methods for Benders' decomposition
534 */
535
536/* TODO: Implement all necessary Benders' decomposition methods. The methods with an #ifdef SCIP_DISABLED_CODE ... #else #define ... are optional */
537
538/** destructor of Benders' decomposition to free user data (called when SCIP is exiting) */
539static
541{ /*lint --e{715}*/
542 SCIP_BENDERSDATA* bendersdata;
543
544 assert(scip != NULL);
545 assert(benders != NULL);
546
547 bendersdata = SCIPbendersGetData(benders);
548
549 if( bendersdata != NULL )
550 {
551 SCIPfreeMemory(scip, &bendersdata);
552 }
553
554 return SCIP_OKAY;
555}
556
557/** presolving initialization method of constraint handler (called when presolving is about to begin) */
558static
559SCIP_DECL_BENDERSINITPRE(bendersInitpreGcg)
560{ /*lint --e{715}*/
561 SCIP_BENDERSDATA* bendersdata;
562 SCIP_VAR* masterauxvar;
563 int nsubproblems;
564 int i;
565
566 assert(scip != NULL);
567 assert(benders != NULL);
568
569 bendersdata = SCIPbendersGetData(benders);
570 nsubproblems = SCIPbendersGetNSubproblems(benders);
571 masterauxvar = SCIPbenderGetMasterAuxiliaryVar(benders);
572
573 for( i = 0; i < nsubproblems; i++ )
574 {
576 }
577
578 /* set GCG vardata, @todo SCIP's dummy vardata is lost */
579 if( masterauxvar != NULL )
580 {
581 SCIP_CALL( GCGaddDataAuxiliaryVar(bendersdata->gcg, masterauxvar, -1) );
582 }
583
584 return SCIP_OKAY;
585}
586
587/** solving process deinitialization method of Benders' decomposition (called before branch and bound process data is freed) */
588static
589SCIP_DECL_BENDERSEXITSOL(bendersExitsolGcg)
590{ /*lint --e{715}*/
591 SCIP_BENDERSDATA* bendersdata;
592 SCIP* origprob;
593
594 assert(scip != NULL);
595 assert(benders != NULL);
596
597 bendersdata = SCIPbendersGetData(benders);
598 origprob = GCGgetOrigprob(bendersdata->gcg);
599
600 /* freeing the relaxation solution */
601 if( bendersdata->relaxsol != NULL )
602 {
603 SCIP_CALL( SCIPfreeSol(origprob, &bendersdata->relaxsol) );
604 }
605
606 return SCIP_OKAY;
607}
608
609/** mapping method between the master problem variables and the subproblem variables of Benders' decomposition */
610static
611SCIP_DECL_BENDERSGETVAR(bendersGetvarGcg)
612{ /*lint --e{715}*/
613 SCIP_VAR* origvar;
614
615 assert(scip != NULL);
616 assert(benders != NULL);
617 assert(var != NULL);
618 assert(mappedvar != NULL);
619
620 /* if there is no corresponding master variable for the input variable, then NULL is returned */
621 (*mappedvar) = NULL;
622
623 /* if the probnumber is -1, then the master variable is requested.
624 * if the probnumber >= 0, then the subproblem variable is requested. */
625 if( probnumber == -1 )
626 {
627 /* getting the original variable for the given pricing variable */
628 origvar = GCGpricingVarGetOrigvars(var)[0];
629
630 /* checking whether the original variable is associated with any master problem variables. This is identified by
631 * retrieving the number of master variables for the given original variable
632 * NOTE: previously, only the linking variables were master variables. As such, the following check was to find
633 * only the original variables corresponding to linking variables. Since linking constraints, and their associated
634 * variables, are also added to the master problem, then the previous check is not valid.
635 */
636 if( GCGoriginalVarGetNMastervars(origvar) > 0 )
637 {
638 (*mappedvar) = GCGoriginalVarGetMastervars(origvar)[0];
639 }
640 }
641 else
642 {
643 assert(probnumber >= 0 && probnumber < SCIPbendersGetNSubproblems(benders));
644
645 /* getting the original variable for the given pricing variable */
646 origvar = GCGmasterVarGetOrigvars(var)[0];
647
648 /* checking whether the original variable is associated with any master problem variables. This is identified by
649 * retrieving the number of master variables for the given original variable
650 * NOTE: previously, only the linking variables were master variables. As such, the following check was to find
651 * only the original variables corresponding to linking variables. Since linking constraints, and their associated
652 * variables, are also added to the master problem, then the previous check is not valid.
653 */
654 /* checking whether the original variable is associated with any master problem variables. This is identified by
655 * retrieving the number of master variables for the given original variable.
656 *
657 * If the pricing variable is requested, then there are two options. The first is that the pricing variable is a
658 * linking variable. The second is that the pricing variable has been directly copied to the master problem since
659 * it was part of the linking constraints.
660 */
661 if( GCGoriginalVarGetNMastervars(origvar) > 0 )
662 {
663 /* if the original variable is a linking variable, then the linking pricing variable is retrieved */
664 if( GCGoriginalVarIsLinking(origvar) )
665 (*mappedvar) = GCGlinkingVarGetPricingVars(origvar)[probnumber];
666 else
667 (*mappedvar) = GCGoriginalVarGetPricingVar(origvar);
668 }
669 }
670
671 return SCIP_OKAY;
672}
673
674/** the post-execution method for Benders' decomposition */
675static
676SCIP_DECL_BENDERSPOSTSOLVE(bendersPostsolveGcg)
677{ /*lint --e{715}*/
678 SCIP_BENDERSDATA* bendersdata;
679 assert(benders != NULL);
680
681 bendersdata = SCIPbendersGetData(benders);
682 assert(bendersdata != NULL);
683
684 (*merged) = FALSE;
685
686 /* creates a solution to the original problem */
687#ifdef SCIP_DEBUG
688 SCIPdebugMessage("The master problem solution.\n");
690#endif
691
692 /* if there are merge candidates, then they will be merged into the master problem.
693 * TODO: maybe check to see whether the merge could be avoided
694 */
695 if( nmergecands > 0 && type != SCIP_BENDERSENFOTYPE_CHECK )
696 {
697 SCIP_CALL( mergeSubproblemsIntoMaster(scip, benders, mergecands, npriomergecands, nmergecands, merged) );
698 }
699
700 if( !infeasible && !(*merged) )
701 {
702 /* if the problem was found to be infeasible, then an artificial solution is created. */
703 SCIP_CALL( createOriginalProblemSolution(scip, benders, sol, infeasible) );
704 if( type == SCIP_BENDERSENFOTYPE_LP )
705 SCIP_CALL( GCGrelaxUpdateCurrentSol(bendersdata->gcg) );
706 }
707
708 return SCIP_OKAY;
709}
710
711/** the method for creating the Benders' decomposition subproblem. This method is called during the initialization stage
712 * (after the master problem was transformed)
713 *
714 * This method must create the SCIP instance for the subproblem and add the required variables and constraints. In
715 * addition, the settings required for the solving the problem must be set here. However, some settings will be
716 * overridden by the standard solving method included in the Benders' decomposition framework. If a special solving
717 * method is desired, the user can implement the bendersSolvesubDefault callback.
718 */
719static
720SCIP_DECL_BENDERSCREATESUB(bendersCreatesubGcg)
721{ /*lint --e{715}*/
722 SCIP_BENDERSDATA* bendersdata;
723
724 assert(scip != NULL);
725 assert(benders != NULL);
726
727 bendersdata = SCIPbendersGetData(benders);
728 assert(bendersdata != NULL);
729
730 SCIP_CALL( SCIPaddBendersSubproblem(scip, benders, GCGgetPricingprob(bendersdata->gcg, probnumber)) );
731
732 /* setting the objective coefficients for the subproblems.
733 * This is required because the variables are added to the pricing problems with a zero coefficient. In the DW
734 * context, this is appropriate because the objective coefficients are constantly changing. In the BD context, the
735 * objective coefficients are static, so they only need to be updated once. */
736 SCIP_CALL( setSubproblemObjs(benders, probnumber) );
737
738
739 return SCIP_OKAY;
740}
741
742/*
743 * Benders' decomposition specific interface methods
744 */
745
746/** creates the gcg Benders' decomposition and includes it in SCIP */
748 GCG* gcg /**< GCG data structure */
749 )
750{
751 SCIP_BENDERSDATA* bendersdata;
752 SCIP_BENDERS* benders;
753 SCIP* bendersmasterprob;
754
755 bendersmasterprob = GCGgetBendersMasterprob(gcg);
756
757 /* create gcg Benders' decomposition data */
758 SCIP_CALL( SCIPallocMemory(bendersmasterprob, &bendersdata) );
759 bendersdata->gcg = gcg;
760 bendersdata->relaxsol = NULL;
761
762 benders = NULL;
763
764 /* include Benders' decomposition */
767 bendersCreatesubGcg, bendersdata) );
768 assert(benders != NULL);
769
770 /* set non fundamental callbacks via setter functions */
771 SCIP_CALL( SCIPsetBendersFree(bendersmasterprob, benders, bendersFreeGcg) );
772 SCIP_CALL( SCIPsetBendersInitpre(bendersmasterprob, benders, bendersInitpreGcg) );
773 SCIP_CALL( SCIPsetBendersExitsol(bendersmasterprob, benders, bendersExitsolGcg) );
774 SCIP_CALL( SCIPsetBendersPostsolve(bendersmasterprob, benders, bendersPostsolveGcg) );
775
776 /* including the default cuts for Benders' decomposition */
777 SCIP_CALL( SCIPincludeBendersDefaultCuts(bendersmasterprob, benders) );
778
779 return SCIP_OKAY;
780}
781
782/** returns the last relaxation solution */
784 SCIP_BENDERS* benders /**< the Benders' decomposition structure */
785 )
786{
787 SCIP_BENDERSDATA* bendersdata;
788
789 assert(benders != NULL);
790 assert(strcmp(SCIPbendersGetName(benders), BENDERS_NAME) == 0);
791
792 bendersdata = SCIPbendersGetData(benders);
793
794 return bendersdata->relaxsol;
795}
796
797/** returns the GCG data structure */
799 SCIP_BENDERS* benders /**< the Benders' decomposition structure */
800 )
801{
802 SCIP_BENDERSDATA* bendersdata;
803
804 assert(benders != NULL);
805 assert(strcmp(SCIPbendersGetName(benders), BENDERS_NAME) == 0);
806
807 bendersdata = SCIPbendersGetData(benders);
808 return bendersdata->gcg;
809}
static SCIP_DECL_BENDERSPOSTSOLVE(bendersPostsolveGcg)
static SCIP_RETCODE createOriginalProblemSolution(SCIP *masterprob, SCIP_BENDERS *benders, SCIP_SOL *sol, SCIP_Bool artificial)
SCIP_RETCODE GCGincludeBendersGcg(GCG *gcg)
static SCIP_RETCODE setOriginalProblemPricingValues(SCIP *origprob, SCIP *masterprob, SCIP_BENDERS *benders, SCIP_SOL *origsol, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Bool *success)
static SCIP_DECL_BENDERSEXITSOL(bendersExitsolGcg)
static SCIP_RETCODE mergeSubproblemsIntoMaster(SCIP *masterprob, SCIP_BENDERS *benders, int *mergecands, int npriomergecands, int nmergecands, SCIP_Bool *merged)
static SCIP_RETCODE setSubproblemObjs(SCIP_BENDERS *benders, int probnumber)
Definition benders_gcg.c:96
static SCIP_RETCODE mergeSubproblemIntoMaster(SCIP *masterprob, SCIP_BENDERS *benders, int probnumber)
#define BENDERS_DESC
Definition benders_gcg.c:53
static SCIP_DECL_BENDERSGETVAR(bendersGetvarGcg)
#define BENDERS_CUTLP
Definition benders_gcg.c:55
static SCIP_RETCODE setOriginalProblemMasterValues(SCIP *origprob, SCIP *masterprob, SCIP_BENDERS *benders, SCIP_SOL *origsol, SCIP_VAR **vars, SCIP_Real *vals, int nvars)
#define BENDERS_NAME
Definition benders_gcg.c:52
static SCIP_Real varGetObj(SCIP_VAR *var)
Definition benders_gcg.c:79
#define BENDERS_PRIORITY
Definition benders_gcg.c:54
static SCIP_DECL_BENDERSCREATESUB(bendersCreatesubGcg)
#define LARGE_VALUE
Definition benders_gcg.c:60
static SCIP_DECL_BENDERSFREE(bendersFreeGcg)
#define BENDERS_CUTRELAX
Definition benders_gcg.c:57
#define BENDERS_CUTPSEUDO
Definition benders_gcg.c:56
static SCIP_DECL_BENDERSINITPRE(bendersInitpreGcg)
#define BENDERS_SHAREAUXVARS
Definition benders_gcg.c:58
GCG Benders' decomposition.
SCIP_RETCODE SCIPincludeBendersDefaultCuts(SCIP *scip, SCIP_BENDERS *benders)
#define SCIP_Bool
#define SCIP_Real
#define TRUE
#define FALSE
GCG interface methods.
SCIP_VAR ** GCGlinkingVarGetPricingVars(SCIP_VAR *var)
Definition gcgvar.c:488
int GCGmasterVarGetNOrigvars(SCIP_VAR *var)
Definition gcgvar.c:971
SCIP_VAR ** GCGoriginalVarGetMastervars(SCIP_VAR *var)
Definition gcgvar.c:666
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
SCIP_VAR ** GCGmasterVarGetOrigvars(SCIP_VAR *var)
Definition gcgvar.c:993
SCIP_RETCODE GCGaddDataAuxiliaryVar(GCG *gcg, SCIP_VAR *auxiliaryvar, int probnumber)
Definition gcgvar.c:1709
int GCGpricingVarGetNOrigvars(SCIP_VAR *var)
Definition gcgvar.c:1082
SCIP_Bool GCGvarIsMaster(SCIP_VAR *var)
Definition gcgvar.c:176
SCIP_Real * GCGmasterVarGetOrigvals(SCIP_VAR *var)
Definition gcgvar.c:1017
SCIP_RETCODE GCGcopyPricingvarDataToMastervar(GCG *gcg, SCIP_VAR *pricingvar, SCIP_VAR *mastervar)
Definition gcgvar.c:443
int GCGoriginalVarGetNMastervars(SCIP_VAR *var)
Definition gcgvar.c:648
int GCGvarGetBlock(SCIP_VAR *var)
Definition gcgvar.c:1118
SCIP_SOL * GCGbendersGetRelaxSol(SCIP_BENDERS *benders)
GCG * GCGbendersGetGcg(SCIP_BENDERS *benders)
GCG_EXPORT SCIP * GCGgetPricingprob(GCG *gcg, int pricingprobnr)
Definition relax_gcg.c:4075
SCIP * GCGgetBendersMasterprob(GCG *gcg)
Definition gcg.cpp:111
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
#define SCIPdebugMsg
SCIP_RETCODE SCIPsetBendersFree(SCIP *scip, SCIP_BENDERS *benders, SCIP_DECL_BENDERSFREE((*bendersfree)))
SCIP_RETCODE SCIPsetBendersExitsol(SCIP *scip, SCIP_BENDERS *benders, SCIP_DECL_BENDERSEXITSOL((*bendersexitsol)))
SCIP_RETCODE SCIPaddBendersSubproblem(SCIP *scip, SCIP_BENDERS *benders, SCIP *subproblem)
SCIP_RETCODE SCIPsetBendersInitpre(SCIP *scip, SCIP_BENDERS *benders, SCIP_DECL_BENDERSINITPRE((*bendersinitpre)))
SCIP_VAR * SCIPbendersGetAuxiliaryVar(SCIP_BENDERS *benders, int probnumber)
SCIP_RETCODE SCIPsetBendersPostsolve(SCIP *scip, SCIP_BENDERS *benders, SCIP_DECL_BENDERSPOSTSOLVE((*benderspostsolve)))
SCIP_Bool SCIPbendersSubproblemIsEnabled(SCIP_BENDERS *benders, int probnumber)
SCIP_RETCODE SCIPgetBendersMasterVar(SCIP *scip, SCIP_BENDERS *benders, SCIP_VAR *var, SCIP_VAR **mappedvar)
SCIP_RETCODE SCIPincludeBendersBasic(SCIP *scip, SCIP_BENDERS **bendersptr, const char *name, const char *desc, int priority, SCIP_Bool cutlp, SCIP_Bool cutpseudo, SCIP_Bool cutrelax, SCIP_Bool shareauxvars, SCIP_DECL_BENDERSGETVAR((*bendersgetvar)), SCIP_DECL_BENDERSCREATESUB((*benderscreatesub)), SCIP_BENDERSDATA *bendersdata)
SCIP_BENDERSDATA * SCIPbendersGetData(SCIP_BENDERS *benders)
const char * SCIPbendersGetName(SCIP_BENDERS *benders)
int SCIPbendersGetNSubproblems(SCIP_BENDERS *benders)
SCIP * SCIPbendersSubproblem(SCIP_BENDERS *benders, int probnumber)
SCIP_RETCODE SCIPmergeBendersSubproblemIntoMaster(SCIP *scip, SCIP_BENDERS *benders, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, int probnumber)
SCIP_VAR * SCIPbenderGetMasterAuxiliaryVar(SCIP_BENDERS *benders)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
SCIP_RETCODE SCIPcheckSolOrig(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *feasible, SCIP_Bool printreason, SCIP_Bool completely)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition gcgvar.c:159
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
SCIP_VAR * var
SCIP_VAR ** vars
SCIP_Bool success
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
int nvars
SCIPfreeBufferArray(scip, &cycles)
SCIP_SOL * sol
#define NULL
public methods for GCG variables
SCIP_RETCODE GCGrelaxUpdateCurrentSol(GCG *gcg)
Definition relax_gcg.c:4964
SCIP_HEUR * GCGrelaxGetProbingheur(GCG *gcg)
Definition relax_gcg.c:4437
GCG relaxator.
various SCIP helper methods
SCIP_SOL * relaxsol
Definition benders_gcg.c:70
struct SCIP_Benders SCIP_BENDERS
SCIP_BENDERSENFOTYPE_LP
SCIP_BENDERSENFOTYPE_CHECK
struct SCIP_BendersData SCIP_BENDERSDATA
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HashMap SCIP_HASHMAP
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_PROBLEM
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR