GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
misc.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 misc.c
30 * @brief miscellaneous methods
31 * @author Gerald Gamrath
32 * @author Martin Bergner
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include "gcg/gcg.h"
38#include "gcg/relax_gcg.h"
39#include "gcg/pricer_gcg.h"
40#include "gcg/benders_gcg.h"
41#include "gcg/pub_gcgvar.h"
42#include "gcg/cons_decomp.h"
43#include "gcg/gcgsort.h"
44#include "gcg/stat.h"
45#include <string.h>
46
47#if defined(_WIN32) || defined(_WIN64)
48#include <windows.h>
49#else
50#include <unistd.h>
51#endif
52
53/** comparefunction for lexicographical sort */
54static
56{
57 SCIP* origprob = (SCIP *) userdata; /* TODO: continue here */
58 SCIP_VAR* mastervar1;
59 SCIP_VAR* mastervar2;
60 SCIP_VAR** origvars1;
61 SCIP_VAR** origvars2;
62 SCIP_Real* origvals1;
63 SCIP_Real* origvals2;
64 int norigvars1;
65 int norigvars2;
66 int i;
67 int j;
68
69 mastervar1 = (SCIP_VAR*) elem1;
70 mastervar2 = (SCIP_VAR*) elem2;
71
72 assert(mastervar1 != NULL);
73 assert(mastervar2 != NULL);
74
75 if( GCGvarGetBlock(mastervar1) < 0 )
76 {
77 SCIPdebugMessage("linkingvar or directy transferred var\n");
78 }
79 if( GCGvarGetBlock(mastervar2) < 0 )
80 {
81 SCIPdebugMessage("linkingvar or directy transferred var\n");
82 }
83
84 origvars1 = GCGmasterVarGetOrigvars(mastervar1);
85 norigvars1 = GCGmasterVarGetNOrigvars(mastervar1);
86 origvals1 = GCGmasterVarGetOrigvals(mastervar1);
87 origvars2 = GCGmasterVarGetOrigvars(mastervar2);
88 norigvars2 = GCGmasterVarGetNOrigvars(mastervar2);
89 origvals2 = GCGmasterVarGetOrigvals(mastervar2);
90
91#ifndef NDEBUG
92 for( i = 1; i < norigvars1; ++i )
93 assert(SCIPvarGetProbindex(origvars1[i-1]) < SCIPvarGetProbindex(origvars1[i]));
94 for( j = 1; j < norigvars2; ++j )
95 assert(SCIPvarGetProbindex(origvars2[j-1]) < SCIPvarGetProbindex(origvars2[j]));
96#endif
97
98 for( i = 0, j = 0; i < norigvars1 || j < norigvars2; )
99 {
100 if( i < norigvars1 && SCIPvarGetType(origvars1[i]) > SCIP_VARTYPE_INTEGER )
101 ++i;
102 else if( j < norigvars2 && SCIPvarGetType(origvars2[j]) > SCIP_VARTYPE_INTEGER )
103 ++j;
104 else if( i < norigvars1 && (j >= norigvars2 || SCIPvarGetProbindex(origvars1[i]) < SCIPvarGetProbindex(origvars2[j])) )
105 {
106 if( SCIPisFeasGT(origprob, origvals1[i], 0.0) )
107 return -1;
108 ++i;
109 }
110 else if( j < norigvars2 && (i >= norigvars1 || SCIPvarGetProbindex(origvars1[i]) > SCIPvarGetProbindex(origvars2[j])) )
111 {
112 if( SCIPisFeasGT(origprob, origvals2[j], 0.0) )
113 return 1;
114 ++j;
115 }
116 else if( i < norigvars1 && j < norigvars2 )
117 {
118 if( SCIPisFeasGT(origprob, origvals1[i], origvals2[j]) )
119 return -1;
120 else if( SCIPisFeasGT(origprob, origvals2[j], origvals1[i]) )
121 return 1;
122 ++i;
123 ++j;
124 }
125
126 }
127
128 return 0;
129}
130
131/* transforms given solution of the master problem into solution of the original problem
132 * @todo think about types of epsilons used in this method
133 * @returns SCIP return code
134 */
136 GCG* gcg, /* GCG data structure */
137 SCIP_SOL* mastersol, /* solution of the master problem, or NULL for current LP solution */
138 SCIP_SOL** origsol, /* pointer to store the new created original problem's solution */
139 SCIP_Bool ignorelocalvarbnds, /* check global or local varbounds */
140 SCIP_Bool* violatesvarbnds /* pointer to variable to store whether the solution violates orig varbnds (can be NULL) */
141 )
142{
143 SCIP* origprob;
145 int npricingprobs;
146 int* blocknrs;
147 SCIP_Real* blockvalue;
148 SCIP_Real increaseval;
150 SCIP_VAR** mastervarsall;
151 SCIP_Real* mastervals;
152 int nmastervarsall;
153 int nmastervars;
154 SCIP_VAR** vars;
155 int nvars;
156 SCIP_Real feastol;
157 SCIP_Bool discretization;
158 int i;
159 int j;
160
161 assert(gcg != NULL);
162 assert(origsol != NULL);
163
166 npricingprobs = GCGgetNPricingprobs(gcg);
167
168 if( violatesvarbnds != NULL )
169 *violatesvarbnds = FALSE;
170
172
174 {
175 SCIP_SOL* relaxsol;
176
178
179 SCIP_CALL( SCIPcreateSolCopy(origprob, origsol, relaxsol) );
180 SCIP_CALL( SCIPunlinkSol(origprob, *origsol) );
181
182 return SCIP_OKAY;
183 }
184
186
188 {
189 if( violatesvarbnds != NULL )
190 *violatesvarbnds = TRUE;
191 return SCIP_OKAY;
192 }
193
194 SCIP_CALL( SCIPallocBufferArray(origprob, &blockvalue, npricingprobs) );
195 SCIP_CALL( SCIPallocBufferArray(origprob, &blocknrs, npricingprobs) );
196
197 SCIP_CALL( SCIPgetBoolParam(origprob, "relaxing/gcg/discretization", &discretization) );
198
199 if( discretization && (SCIPgetNContVars(origprob) > 0) )
200 {
201 SCIP_VAR** fixedvars;
202 SCIP_Real* fixedvals;
203 int nfixedvars;
204
205 /* get variables of the master problem and their solution values */
206 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervarsall, &nmastervarsall, NULL, NULL, NULL, NULL) );
207
208 /* getting the fixed variables */
209 fixedvars = SCIPgetFixedVars(masterprob);
210 nfixedvars = SCIPgetNFixedVars(masterprob);
211
212 assert(mastervarsall != NULL || nmastervarsall == 0);
213 assert(nmastervarsall >= 0);
214
215 SCIP_CALL( SCIPallocBufferArray(origprob, &mastervars, nmastervarsall + nfixedvars) );
216
217 SCIP_CALL( SCIPallocBufferArray(origprob, &mastervals, nmastervarsall + nfixedvars) );
218 SCIP_CALL( SCIPallocBufferArray(origprob, &fixedvals, nfixedvars) );
219
220 SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nmastervarsall, mastervarsall, mastervals) );
221 SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nfixedvars, fixedvars, fixedvals) );
222
223 nmastervars = 0;
224
225 for( i = 0; i < nmastervarsall; ++i )
226 {
228
229 assert( i >= nmastervars );
230 solval = mastervals[i];
231
232 if( !SCIPisZero(origprob, solval) )
233 {
234 mastervars[nmastervars] = mastervarsall[i];
235 mastervals[nmastervars] = solval;
236
237 ++nmastervars;
238 }
239 }
240
241 /* adding the fixed variables to the mastervars array */
242 for( i = 0; i < nfixedvars; i++ )
243 {
245
246 solval = fixedvals[i];
247
248 if( !SCIPisZero(origprob, solval) )
249 {
250 mastervars[nmastervars] = fixedvars[i];
251 mastervals[nmastervars] = solval;
252
253 ++nmastervars;
254 }
255 }
256
257 SCIPfreeBufferArray(origprob, &fixedvals);
258
259 /* sort mastervariables lexicographically */
260 GCGsortPtrPtr((void**)mastervars, (void**) mastervals, mastervarcomp, origprob, nmastervars );
261 }
262 else
263 {
264 SCIP_VAR** fixedvars;
265 SCIP_Real* fixedvals;
266 int nfixedvars;
267
268 /* get variables of the master problem and their solution values */
269 SCIP_CALL( SCIPgetVarsData(masterprob, &mastervarsall, &nmastervarsall, NULL, NULL, NULL, NULL) );
270
271 /* getting the fixed variables */
272 fixedvars = SCIPgetFixedVars(masterprob);
273 nfixedvars = SCIPgetNFixedVars(masterprob);
274
275 assert(mastervarsall != NULL);
276 assert(nmastervarsall >= 0);
277
278 SCIP_CALL( SCIPallocBufferArray(origprob, &mastervars, nmastervarsall + nfixedvars) );
279 SCIP_CALL( SCIPallocBufferArray(origprob, &mastervals, nmastervarsall + nfixedvars) );
280 SCIP_CALL( SCIPallocBufferArray(origprob, &fixedvals, nfixedvars) );
281
282 SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nmastervarsall, mastervarsall, mastervals) );
283 SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nfixedvars, fixedvars, fixedvals) );
284
285 nmastervars = 0;
286
287 for( i = 0; i < nmastervarsall; ++i )
288 {
290
291 assert( i >= nmastervars );
292 solval = mastervals[i];
293
294 if( !SCIPisZero(origprob, solval) )
295 {
296 mastervars[nmastervars] = mastervarsall[i];
297 mastervals[nmastervars] = solval;
298
299 ++nmastervars;
300 }
301 }
302
303 /* adding the fixed variables to the mastervars array */
304 for( i = 0; i < nfixedvars; i++ )
305 {
307
308 solval = fixedvals[i];
309
310 if( !SCIPisZero(origprob, solval) )
311 {
312 mastervars[nmastervars] = fixedvars[i];
313 mastervals[nmastervars] = solval;
314
315 ++nmastervars;
316 }
317 }
318
319 SCIPfreeBufferArray(origprob, &fixedvals);
320 }
321
322 /* initialize the block values for the pricing problems */
323 for( i = 0; i < npricingprobs; i++ )
324 {
325 blockvalue[i] = 0.0;
326 blocknrs[i] = 0;
327 }
328
329 /* loop over all given master variables */
330 for( i = 0; i < nmastervars; i++ )
331 {
332 SCIP_VAR** origvars;
333 int norigvars;
334 SCIP_Real* origvals;
335 SCIP_Bool isray;
336 int blocknr;
337
338 if( SCIPisZero(masterprob, mastervals[i]) )
339 continue;
340
344 blocknr = GCGvarGetBlock(mastervars[i]);
346
348
349 /** @todo handle infinite master solution values */
350 assert(!SCIPisInfinity(origprob, mastervals[i]));
351
352 /* first of all, handle variables representing rays */
353 if( isray )
354 {
355 assert(blocknr >= 0);
356 /* we also want to take into account variables representing rays, that have a small value (between normal and feas eps),
357 * so we do no feas comparison here */
358 if( SCIPisPositive(masterprob, mastervals[i]) )
359 {
360 /* loop over all original variables contained in the current master variable */
361 for( j = 0; j < norigvars; j++ )
362 {
363 if( SCIPisZero(origprob, origvals[j]) )
364 continue;
365
366 assert(!SCIPisZero(origprob, origvals[j]));
367
368 /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done later) */
369 if( GCGoriginalVarIsLinking(origvars[j]) )
370 continue;
371
372 SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origvars[j]), origvals[j] * mastervals[i], SCIPvarGetName(mastervars[i]));
373 /* increase the corresponding value */
374 SCIP_CALL( SCIPincSolVal(origprob, *origsol, origvars[j], origvals[j] * mastervals[i]) );
375 }
376 }
377 mastervals[i] = 0.0;
378 continue;
379 }
380
381 /* variable was directly transferred to the master problem (only in linking conss or linking variable) */
382 /** @todo this may be the wrong place for this case, handle it before the while loop
383 * and remove the similar case in the next while loop */
384 if( blocknr == -1 )
385 {
386 assert(norigvars == 1);
387 assert(origvals[0] == 1.0);
388
389 /* increase the corresponding value */
390 SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origvars[0]), origvals[0] * mastervals[i], SCIPvarGetName(mastervars[i]));
391 SCIP_CALL( SCIPincSolVal(origprob, *origsol, origvars[0], origvals[0] * mastervals[i]) );
392 mastervals[i] = 0.0;
393 continue;
394 }
395 if( blocknr == -2 )
396 {
397 assert(norigvars == 0);
398
399 mastervals[i] = 0.0;
400 continue;
401 }
402
403 /* handle the variables with value >= 1 to get integral values in original solution */
404 while( SCIPisFeasGE(masterprob, mastervals[i], 1.0) )
405 {
406 assert(blocknr >= 0);
407 /* loop over all original variables contained in the current master variable */
408 for( j = 0; j < norigvars; j++ )
409 {
410 SCIP_VAR* pricingvar;
411 int norigpricingvars;
412 SCIP_VAR** origpricingvars;
413 if( SCIPisZero(origprob, origvals[j]) )
414 continue;
415 assert(!SCIPisZero(origprob, origvals[j]));
416
417 /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done above) */
418 if( GCGoriginalVarIsLinking(origvars[j]) )
419 continue;
420
421 pricingvar = GCGoriginalVarGetPricingVar(origvars[j]);
422 assert(GCGvarIsPricing(pricingvar));
423
424 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
425 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
426
427 /* just in case a variable has a value higher than the number of blocks, it represents */
428 if( norigpricingvars <= blocknrs[blocknr] )
429 {
430 SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[norigpricingvars-1]), mastervals[i] * origvals[j], SCIPvarGetName(mastervars[i]));
431 /* increase the corresponding value */
432 SCIP_CALL( SCIPincSolVal(origprob, *origsol, origpricingvars[norigpricingvars-1], mastervals[i] * origvals[j]) );
433 mastervals[i] = 1.0;
434 }
435 /* this should be default */
436 else
437 {
438 SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[blocknrs[blocknr]]), origvals[j], SCIPvarGetName(mastervars[i]) );
439 /* increase the corresponding value */
440 SCIP_CALL( SCIPincSolVal(origprob, *origsol, origpricingvars[blocknrs[blocknr]], origvals[j]) );
441 }
442 }
443 mastervals[i] = mastervals[i] - 1.0;
444 blocknrs[blocknr]++;
445 }
446 assert(!SCIPisFeasNegative(masterprob, mastervals[i]));
447 }
448
449 /* TODO: Change order of mastervars */
450
451 /* loop over all given master variables */
452 for( i = 0; i < nmastervars; i++ )
453 {
454 SCIP_VAR** origvars;
455 int norigvars;
456 SCIP_Real* origvals;
457 int blocknr;
458
462 blocknr = GCGvarGetBlock(mastervars[i]);
463
464 if( SCIPisFeasZero(masterprob, mastervals[i]) )
465 {
466 continue;
467 }
468 assert(SCIPisFeasGE(masterprob, mastervals[i], 0.0) && SCIPisFeasLT(masterprob, mastervals[i], 1.0));
469
470 while( SCIPisFeasPositive(masterprob, mastervals[i]) )
471 {
472 assert(blocknr >= 0);
475
476 increaseval = MIN(mastervals[i], 1.0 - blockvalue[blocknr]);
477 /* loop over all original variables contained in the current master variable */
478 for( j = 0; j < norigvars; j++ )
479 {
480 SCIP_VAR* pricingvar;
481 int norigpricingvars;
482 SCIP_VAR** origpricingvars;
483
484 if( SCIPisZero(origprob, origvals[j]) )
485 continue;
486
487 /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done above) */
488 if( GCGoriginalVarIsLinking(origvars[j]) )
489 continue;
490
491 pricingvar = GCGoriginalVarGetPricingVar(origvars[j]);
492 assert(GCGvarIsPricing(pricingvar));
493
494 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
495 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
496
497 if( norigpricingvars <= blocknrs[blocknr] )
498 {
499 increaseval = mastervals[i];
500
501 SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[norigpricingvars-1]), origvals[j] * increaseval, SCIPvarGetName(mastervars[i]) );
502 /* increase the corresponding value */
503 SCIP_CALL( SCIPincSolVal(origprob, *origsol, origpricingvars[norigpricingvars-1], origvals[j] * increaseval) );
504 }
505 else
506 {
507 /* increase the corresponding value */
508 SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[blocknrs[blocknr]]), origvals[j] * increaseval, SCIPvarGetName(mastervars[i]) );
509 SCIP_CALL( SCIPincSolVal(origprob, *origsol, origpricingvars[blocknrs[blocknr]], origvals[j] * increaseval) );
510 }
511 }
512
513 mastervals[i] = mastervals[i] - increaseval;
514 if( SCIPisFeasZero(masterprob, mastervals[i]) )
515 {
516 mastervals[i] = 0.0;
517 }
518 blockvalue[blocknr] += increaseval;
519
520 /* if the value assigned to the block is equal to 1, this block is full and we take the next block */
521 if( SCIPisFeasGE(masterprob, blockvalue[blocknr], 1.0) )
522 {
523 blockvalue[blocknr] = 0.0;
524 blocknrs[blocknr]++;
525 }
526 }
527 }
528
529 SCIPfreeBufferArray(origprob, &mastervals);
531
532 SCIPfreeBufferArray(origprob, &blocknrs);
533 SCIPfreeBufferArray(origprob, &blockvalue);
534
535 /* if the solution violates one of its bounds by more than feastol
536 * and less than 10*feastol, round it and print a warning
537 */
539 SCIP_CALL( SCIPgetRealParam(origprob, "numerics/feastol", &feastol) );
540
541 for( i = 0; i < nvars; ++i )
542 {
544 SCIP_Real lb;
545 SCIP_Real ub;
546
547 solval = SCIPgetSolVal(origprob, *origsol, vars[i]);
548 lb = ignorelocalvarbnds ? SCIPvarGetLbGlobal(vars[i]) : SCIPvarGetLbLocal(vars[i]);
549 ub = ignorelocalvarbnds ? SCIPvarGetUbGlobal(vars[i]) : SCIPvarGetUbLocal(vars[i]);
550
551 if( SCIPisFeasGT(origprob, solval, ub) && EPSEQ(solval, ub, 10 * feastol) )
552 {
553 SCIP_CALL( SCIPsetSolVal(origprob, *origsol, vars[i], ub) );
554 SCIPwarningMessage(origprob, "Variable %s rounded from %g to %g in relaxation solution\n",
555 SCIPvarGetName(vars[i]), solval, ub);
556 }
557 else if( SCIPisFeasLT(origprob, solval, lb) && EPSEQ(solval, lb, 10 * feastol) )
558 {
559 SCIP_CALL( SCIPsetSolVal(origprob, *origsol, vars[i], lb) );
560 SCIPwarningMessage(origprob, "Variable %s rounded from %g to %g in relaxation solution\n",
561 SCIPvarGetName(vars[i]), solval, lb);
562 }
563 if( !SCIPisFeasGE(origprob, SCIPgetSolVal(origprob, *origsol, vars[i]), lb) || !SCIPisFeasLE(origprob, SCIPgetSolVal(origprob, *origsol, vars[i]), ub) )
564 {
565 if( violatesvarbnds != NULL )
566 *violatesvarbnds = TRUE;
567 }
568 }
569
570 return SCIP_OKAY;
571}
572
573
574/* transforms given values of the given original variables into values of the given master variables
575 * @returns the sum of the values of the corresponding master variables that are fixed */
577 GCG* gcg, /**< GCG data structure */
578 SCIP_VAR** origvars, /**< array with (subset of the) original variables */
579 SCIP_Real* origvals, /**< array with values (coefs) for the given original variables */
580 int norigvars, /**< number of given original variables */
581 SCIP_VAR** mastervars, /**< array of (all present) master variables */
582 SCIP_Real* mastervals, /**< array to store the values of the master variables */
583 int nmastervars /**< number of master variables */
584 )
585{
586 SCIP* origprob;
587 int i;
588 int j;
589 int k;
590 SCIP_Real sum;
591
592 assert(gcg != NULL);
593 assert(origvars != NULL);
594 assert(origvals != NULL);
596 assert(mastervals != NULL);
597 assert(nmastervars >= 0);
598
599 sum = 0.0;
600
602
603 /* set all values to 0 initially */
604 for( i = 0; i < nmastervars; i++ )
605 mastervals[i] = 0.0;
606
607 /* iterate over all original variables */
608 for( i = 0; i < norigvars; i++ )
609 {
610 SCIP_VAR** varmastervars;
611 SCIP_Real* varmastervals;
612 int blocknr;
613
614 assert(GCGvarIsOriginal(origvars[i]));
615 varmastervars = GCGoriginalVarGetMastervars(origvars[i]);
616 varmastervals = GCGoriginalVarGetMastervals(origvars[i]);
617 blocknr = GCGvarGetBlock(origvars[i]);
618
619 /* variable belongs to no block (or is a linking variable), so it was transferred directly to the master problem,
620 * hence, we transfer the value directly to the corresponding master variable
621 */
622 if( blocknr < 0 )
623 {
624 assert(blocknr == -1 || blocknr == -2);
625 assert(SCIPvarIsOriginal(varmastervars[0]));
626 assert(SCIPvarGetTransVar(varmastervars[0]) != NULL);
627
628 for( k = 0; k < nmastervars; k++ )
629 {
630 if( mastervars[k] == SCIPvarGetTransVar(varmastervars[0]) )
631 {
632 mastervals[k] += (varmastervals[0] * origvals[i]);
633 break;
634 }
635 }
636
637 if ( k >= nmastervars )
638 {
639 // inactive variable, check whether it is fixed
640 if ( SCIPisFeasEQ(origprob, SCIPvarGetLbGlobal(varmastervars[0]), SCIPvarGetUbGlobal(varmastervars[0])) )
641 {
642 // variable is fixed in the master problem
643 sum += (SCIPvarGetLbGlobal(varmastervars[0]) * varmastervals[0] * origvals[i]);
644 }
645 else
646 {
647#ifdef SCIP_DEBUG
650
651 SCIPdebugMessage("OrigVar %s [%f,%f]\n", SCIPvarGetName(origvars[i]), SCIPvarGetLbGlobal(origvars[i]),
652 SCIPvarGetUbGlobal(origvars[i]));
653 SCIPdebugMessage("MasterVar %s [%f,%f]\n", SCIPvarGetName(varmastervars[0]),
654 SCIPvarGetLbGlobal(varmastervars[0]), SCIPvarGetUbGlobal(varmastervars[0]));
655#endif
656 assert(FALSE);
657 }
658 }
659 }
660 /* variable belongs to exactly one block, so we have to look at all master variables and increase their values
661 * if they contain the original variable
662 */
663 else
664 {
665 SCIP_VAR* pricingvar;
666 SCIP_VAR* origvar;
667 SCIP_VAR** curmastervars;
668 SCIP_Real* curmastervals;
669 int ncurmastervars;
670
671 pricingvar = GCGoriginalVarGetPricingVar(origvars[i]);
672 assert(GCGvarIsPricing(pricingvar));
673
674 origvar = GCGpricingVarGetOriginalVar(pricingvar);
675 assert(GCGvarIsOriginal(origvar));
676 curmastervars = GCGoriginalVarGetMastervars(origvar);
677 curmastervals = GCGoriginalVarGetMastervals(origvar);
678 ncurmastervars = GCGoriginalVarGetNMastervars(origvar);
679
680 for( j = 0; j < ncurmastervars; j++ )
681 {
682 assert(SCIPvarIsTransformed(curmastervars[j]));
683 for( k = 0; k < nmastervars; k++ )
684 if( mastervars[k] == curmastervars[j] )
685 {
686 mastervals[k] += (curmastervals[j] * origvals[i]);
687 break;
688 }
689 assert(k < nmastervars);
690 }
691 }
692
693 }
694 return sum;
695}
696
697/* checks whether the scip is the original scip instance
698 * @returns whether the scip is the original scip instance */
700 SCIP* scip /* SCIP data structure */
701 )
702{
703 assert(scip != NULL);
704 return SCIPfindRelax(scip, "gcg") != NULL;
705}
706
707/* checks whether the scip is the master problem scip
708 * @returns whether the scip is the master problem scip */
710 SCIP* scip /* SCIP data structure */
711 )
712{
713 assert(scip != NULL);
714 return SCIPfindPricer(scip, "gcg") != NULL || SCIPfindBenders(scip, "gcg") != NULL;
715}
716
717/* print out GCG statistics
718 * @returns SCIP return code */
720 GCG* gcg, /* GCG data structure */
721 FILE* file /* output file or NULL for standard output */
722)
723{
724 SCIP* origprob;
726 assert(gcg != NULL);
727
730
731 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(masterprob), file, "\nMaster Program statistics:\n");
735 {
738 }
739
741 {
742 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "\nOriginal Program statistics:\n");
744 }
745 else
746 {
749 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "\nOriginal Program Solution statistics:\n");
751 }
755 {
758 }
760 {
763 }
765 {
767 if( decomp != NULL )
768 {
769 SCIP_CALL( GCGprintDecompStatistics(gcg, file, decomp) );
771 }
772 }
774 {
777 }
778 return SCIP_OKAY;
779}
780
781/* print name of current instance to given output
782 * @returns SCIP return code */
784 GCG* gcg, /* GCG data structure */
785 FILE* file /* output file or NULL for standard output */
786)
787{
788 char problemname[SCIP_MAXSTRLEN];
789 char* outputname;
791 (void) SCIPsnprintf(problemname, SCIP_MAXSTRLEN, "%s", SCIPgetProbName(origprob));
792 SCIPsplitFilename(problemname, NULL, &outputname, NULL, NULL);
793
794 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "filename: %s \n", outputname );
795 return SCIP_OKAY;
796}
797
798
799/* print out complete detection statistics
800 * @returns SCIP return code */
802 GCG* gcg, /* GCG data structure */
803 FILE* file /* output file or NULL for standard output */
804)
805{
806 SCIP* origprob;
807 assert(gcg != NULL);
808
810
812 {
813 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "\nDetection did not take place so far\n");
814 return SCIP_OKAY;
815 }
816
817 SCIPmessageFPrintInfo(SCIPgetMessagehdlr(origprob), file, "\nStart writing complete detection information:\n");
818
820
822
824
826
828
829 return SCIP_OKAY;
830}
831
832
833
834/* Checks whether the constraint belongs to GCG or not
835 * @returns whether the constraint belongs to GCG or not */
837 SCIP_CONS* cons /* constraint to check */
838 )
839{
840 SCIP_CONSHDLR* conshdlr;
841 assert(cons != NULL);
842 conshdlr = SCIPconsGetHdlr(cons);
843 if( strcmp("origbranch", SCIPconshdlrGetName(conshdlr)) == 0 )
844 return TRUE;
845 else if( strcmp("masterbranch", SCIPconshdlrGetName(conshdlr)) == 0 )
846 return TRUE;
847
848 return FALSE;
849}
GCG Benders' decomposition.
SCIP_Bool GCGdetectionTookPlace(GCG *gcg, SCIP_Bool original)
SCIP_RETCODE GCGconshdlrDecompPrintDetectorStatistics(GCG *gcg, FILE *file)
display statistics about detectors
SCIP_RETCODE GCGconshdlrDecompPrintScoreStatistics(GCG *gcg, FILE *file)
display statistics about scores
constraint handler for structure detection
SCIP_RETCODE GCGprintDecompStatistics(GCG *gcg, FILE *file, GCG_DECOMP *decomp)
Definition decomp.c:3827
#define SCIP_MAXSTRLEN
#define SCIP_Bool
#define MIN(x, y)
#define SCIP_Real
#define EPSEQ(x, y, eps)
#define TRUE
#define FALSE
GCG interface methods.
sorting functions, adapted from SCIP's sorttpl to include userdata
#define GCG_DECL_SORTPTRCOMP(x)
Definition gcgsort.h:60
GCG_EXPORT void GCGsortPtrPtr(void **ptrarray1, void **ptrarray2, GCG_DECL_SORTPTRCOMP((*ptrcomp)), void *userdata, int len)
SCIP_Bool GCGvarIsOriginal(SCIP_VAR *var)
Definition gcgvar.c:231
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_Real * GCGoriginalVarGetMastervals(SCIP_VAR *var)
Definition gcgvar.c:684
SCIP_VAR * GCGoriginalVarGetPricingVar(SCIP_VAR *var)
Definition gcgvar.c:281
SCIP_VAR ** GCGmasterVarGetOrigvars(SCIP_VAR *var)
Definition gcgvar.c:993
SCIP_VAR * GCGpricingVarGetOriginalVar(SCIP_VAR *var)
Definition gcgvar.c:590
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
int GCGoriginalVarGetNMastervars(SCIP_VAR *var)
Definition gcgvar.c:648
SCIP_Bool GCGmasterVarIsRay(SCIP_VAR *var)
Definition gcgvar.c:937
int GCGvarGetBlock(SCIP_VAR *var)
Definition gcgvar.c:1118
void SCIPsplitFilename(char *filename, char **path, char **name, char **extension, char **compression)
SCIP_RETCODE GCGmasterPrintSimplexIters(GCG *gcg, FILE *file)
SCIP_Bool GCGmasterIsSolValid(GCG *gcg, SCIP_SOL *mastersol)
void GCGpricerPrintPricingStatistics(GCG *gcg, FILE *file)
SCIP_RETCODE GCGtransformMastersolToOrigsol(GCG *gcg, SCIP_SOL *mastersol, SCIP_SOL **origsol, SCIP_Bool ignorelocalvarbnds, SCIP_Bool *violatesvarbnds)
Definition misc.c:135
SCIP_RETCODE GCGprintStatistics(GCG *gcg, FILE *file)
Definition misc.c:719
SCIP_Bool GCGisConsGCGCons(SCIP_CONS *cons)
Definition misc.c:836
SCIP_Bool GCGisOriginal(SCIP *scip)
Definition misc.c:699
SCIP_RETCODE GCGprintPartitionInformation(GCG *gcg, FILE *file)
SCIP_RETCODE GCGprintBlockcandidateInformation(GCG *gcg, FILE *file)
GCG_EXPORT GCG_DECOMP * GCGgetStructDecomp(GCG *gcg)
Definition relax_gcg.c:2331
SCIP_RETCODE GCGprintCompleteDetectionTime(GCG *gcg, FILE *file)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_Bool GCGisMaster(SCIP *scip)
Definition misc.c:709
SCIP_RETCODE GCGprintDecompInformation(GCG *gcg, FILE *file)
GCG_EXPORT SCIP_SOL * GCGgetBendersRelaxationSol(GCG *gcg)
Definition relax_gcg.c:5273
GCG_EXPORT int GCGgetNPricingprobs(GCG *gcg)
Definition relax_gcg.c:4113
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_Real GCGtransformOrigvalsToMastervals(GCG *gcg, SCIP_VAR **origvars, SCIP_Real *origvals, int norigvars, SCIP_VAR **mastervars, SCIP_Real *mastervals, int nmastervars)
Definition misc.c:576
GCG_EXPORT GCG_DECMODE GCGgetDecompositionMode(GCG *gcg)
Definition relax_gcg.c:5294
SCIP_RETCODE GCGprintCompleteDetectionStatistics(GCG *gcg, FILE *file)
Definition misc.c:801
SCIP_RETCODE GCGprintInstanceName(GCG *gcg, FILE *file)
Definition misc.c:783
SCIP_STAGE SCIPgetStage(SCIP *scip)
const char * SCIPgetProbName(SCIP *scip)
int SCIPgetNContVars(SCIP *scip)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
int SCIPgetNFixedVars(SCIP *scip)
SCIP_VAR ** SCIPgetFixedVars(SCIP *scip)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
SCIP_BENDERS * SCIPfindBenders(SCIP *scip, const char *name)
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
#define SCIPallocBufferArray(scip, ptr, num)
SCIP_PRICER * SCIPfindPricer(SCIP *scip, const char *name)
SCIP_RELAX * SCIPfindRelax(SCIP *scip, const char *name)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPcreateSolCopy(SCIP *scip, SCIP_SOL **sol, SCIP_SOL *sourcesol)
SCIP_RETCODE SCIPunlinkSol(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPincSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real incval)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
void SCIPprintSolutionStatistics(SCIP *scip, FILE *file)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
int SCIPvarGetProbindex(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIP_Bool SCIPvarIsOriginal(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetTransVar(SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition gcgvar.c:159
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
SCIP_VAR ** vars
int j
SCIP_Real solval
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
int nvars
SCIPfreeBufferArray(scip, &cycles)
SCIP_VAR ** mastervars
int nmastervars
#define NULL
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
GCG variable pricer.
public methods for GCG variables
SCIP_HEUR * GCGrelaxGetProbingheur(GCG *gcg)
Definition relax_gcg.c:4437
GCG relaxator.
SCIP_RETCODE GCGwriteSolvingDetails(GCG *gcg)
Definition stat.c:108
Prints information about the best decomposition.
struct SCIP_Cons SCIP_CONS
struct SCIP_Conshdlr SCIP_CONSHDLR
@ GCG_DECMODE_BENDERS
Definition type_decomp.h:63
@ GCG_DECMODE_DANTZIGWOLFE
Definition type_decomp.h:62
@ GCG_DECMODE_ORIGINAL
Definition type_decomp.h:64
struct GCG_Decomp GCG_DECOMP
Definition type_decomp.h:45
struct Gcg GCG
Definition type_gcg.h:44
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_PRESOLVING
SCIP_STAGE_SOLVING
SCIP_STAGE_PRESOLVED
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR
SCIP_VARTYPE_INTEGER